libMesh
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ParsedFEMFunctionTest Class Reference
Inheritance diagram for ParsedFEMFunctionTest:
[legend]

Public Member Functions

void setUp ()
 
void tearDown ()
 
 CPPUNIT_TEST_SUITE (ParsedFEMFunctionTest)
 
 CPPUNIT_TEST (testValues)
 
 CPPUNIT_TEST (testGradients)
 
 CPPUNIT_TEST (testHessians)
 
 CPPUNIT_TEST (testInlineGetter)
 
 CPPUNIT_TEST (testInlineSetter)
 
 CPPUNIT_TEST (testNormals)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Member Functions

void testValues ()
 
void testGradients ()
 
void testHessians ()
 
void testInlineGetter ()
 
void testInlineSetter ()
 
void testNormals ()
 

Private Attributes

UniquePtr< UnstructuredMeshmesh
 
UniquePtr< EquationSystemses
 
Systemsys
 
UniquePtr< FEMContextc
 
UniquePtr< FEMContexts
 

Detailed Description

Definition at line 32 of file parsed_fem_function_test.C.

Member Function Documentation

ParsedFEMFunctionTest::CPPUNIT_TEST ( testValues  )
ParsedFEMFunctionTest::CPPUNIT_TEST ( testGradients  )
ParsedFEMFunctionTest::CPPUNIT_TEST ( testHessians  )
ParsedFEMFunctionTest::CPPUNIT_TEST ( testInlineGetter  )
ParsedFEMFunctionTest::CPPUNIT_TEST ( testInlineSetter  )
ParsedFEMFunctionTest::CPPUNIT_TEST ( testNormals  )
ParsedFEMFunctionTest::CPPUNIT_TEST_SUITE ( ParsedFEMFunctionTest  )
ParsedFEMFunctionTest::CPPUNIT_TEST_SUITE_END ( )
void ParsedFEMFunctionTest::setUp ( )

Definition at line 35 of file parsed_fem_function_test.C.

References libMesh::System::add_variable(), libMesh::MeshTools::Generation::build_cube(), libMesh::NumericVector< T >::close(), libMesh::DofObject::dof_number(), mesh, libMesh::Elem::node_ref(), libMesh::DofObject::processor_id(), libMesh::MeshBase::query_elem_ptr(), libMesh::Parallel::Communicator::rank(), libMesh::NumericVector< T >::set(), libMesh::System::solution, libMesh::sys, TestCommWorld, and libMesh::System::update().

35  {
36  mesh.reset(new Mesh(*TestCommWorld));
38  es.reset(new EquationSystems(*mesh));
39  sys = &(es->add_system<System> ("SimpleSystem"));
40  sys->add_variable("x2");
41  sys->add_variable("x3");
42  sys->add_variable("c05");
43  sys->add_variable("y4");
44  sys->add_variable("xy");
45  sys->add_variable("yz");
46  sys->add_variable("xyz");
47 
48  es->init();
49 
51  Elem *elem = mesh->query_elem_ptr(0);
52 
53  if (elem && elem->processor_id() == TestCommWorld->rank())
54  {
55  // Set x2 = 2*x
56  sol.set(elem->node_ref(1).dof_number(0,0,0), 2);
57  sol.set(elem->node_ref(2).dof_number(0,0,0), 2);
58  sol.set(elem->node_ref(5).dof_number(0,0,0), 2);
59  sol.set(elem->node_ref(6).dof_number(0,0,0), 2);
60 
61  // Set x3 = 3*x
62  sol.set(elem->node_ref(1).dof_number(0,1,0), 3);
63  sol.set(elem->node_ref(2).dof_number(0,1,0), 3);
64  sol.set(elem->node_ref(5).dof_number(0,1,0), 3);
65  sol.set(elem->node_ref(6).dof_number(0,1,0), 3);
66 
67  // Set c05 = 0.5
68  sol.set(elem->node_ref(0).dof_number(0,2,0), 0.5);
69  sol.set(elem->node_ref(1).dof_number(0,2,0), 0.5);
70  sol.set(elem->node_ref(2).dof_number(0,2,0), 0.5);
71  sol.set(elem->node_ref(3).dof_number(0,2,0), 0.5);
72  sol.set(elem->node_ref(4).dof_number(0,2,0), 0.5);
73  sol.set(elem->node_ref(5).dof_number(0,2,0), 0.5);
74  sol.set(elem->node_ref(6).dof_number(0,2,0), 0.5);
75  sol.set(elem->node_ref(7).dof_number(0,2,0), 0.5);
76 
77  // Set y4 = 4*y
78  sol.set(elem->node_ref(2).dof_number(0,3,0), 4);
79  sol.set(elem->node_ref(3).dof_number(0,3,0), 4);
80  sol.set(elem->node_ref(6).dof_number(0,3,0), 4);
81  sol.set(elem->node_ref(7).dof_number(0,3,0), 4);
82 
83  // Set xy = x*y
84  sol.set(elem->node_ref(2).dof_number(0,4,0), 1);
85  sol.set(elem->node_ref(6).dof_number(0,4,0), 1);
86 
87  // Set yz = y*z
88  sol.set(elem->node_ref(6).dof_number(0,5,0), 1);
89  sol.set(elem->node_ref(7).dof_number(0,5,0), 1);
90 
91  // Set xyz = x*y*z
92  sol.set(elem->node_ref(6).dof_number(0,6,0), 1);
93  }
94 
95  sol.close();
96  sys->update();
97 
98  c.reset(new FEMContext(*sys));
99  s.reset(new FEMContext(*sys));
100  if (elem && elem->processor_id() == TestCommWorld->rank())
101  {
102  c->pre_fe_reinit(*sys, elem);
103  c->elem_fe_reinit();
104  s->pre_fe_reinit(*sys, elem);
105  s->side = 3;
106  s->side_fe_reinit();
107  }
108  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1101
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
Definition: dof_object.h:810
This is the base class for classes which contain information related to any physical process that mig...
Definition: system.h:76
const Node & node_ref(const unsigned int i) const
Definition: elem.h:1896
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:61
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
UniquePtr< UnstructuredMesh > mesh
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:425
UniquePtr< FEMContext > s
UniquePtr< FEMContext > c
unsigned int rank() const
Definition: parallel.h:724
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
processor_id_type processor_id() const
Definition: dof_object.h:694
UniquePtr< EquationSystems > es
void ParsedFEMFunctionTest::tearDown ( )

Definition at line 110 of file parsed_fem_function_test.C.

References mesh.

110  {
111  c.reset();
112  s.reset();
113  es.reset();
114  mesh.reset();
115  }
UniquePtr< UnstructuredMesh > mesh
UniquePtr< FEMContext > s
UniquePtr< FEMContext > c
UniquePtr< EquationSystems > es
void ParsedFEMFunctionTest::testGradients ( )
private

Definition at line 153 of file parsed_fem_function_test.C.

References libMesh::libmesh_real(), libMesh::Parallel::Communicator::rank(), TestCommWorld, and libMesh::TOLERANCE.

154  {
155  if (c->has_elem() &&
156  c->get_elem().processor_id() == TestCommWorld->rank())
157  {
158  ParsedFEMFunction<Number> c2(*sys, "grad_x_x2");
159 
160  CPPUNIT_ASSERT_DOUBLES_EQUAL
161  (libmesh_real(c2(*c,Point(0.35,0.45,0.55))), 2.0, TOLERANCE*TOLERANCE);
162 
163  ParsedFEMFunction<Number> xz(*sys, "grad_y_xyz");
164 
165  CPPUNIT_ASSERT_DOUBLES_EQUAL
166  (libmesh_real(xz(*c,Point(0.25,0.35,0.75))), 0.1875, TOLERANCE*TOLERANCE);
167 
168  ParsedFEMFunction<Number> xyz(*sys, "grad_y_xyz*grad_x_xy");
169 
170  CPPUNIT_ASSERT_DOUBLES_EQUAL
171  (libmesh_real(xyz(*c,Point(0.25,0.5,0.75))), 0.09375, TOLERANCE*TOLERANCE);
172  }
173  }
T libmesh_real(T a)
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
static const Real TOLERANCE
ParsedFEMFunction provides support for FParser-based parsed functions in FEMSystem.
UniquePtr< FEMContext > c
unsigned int rank() const
Definition: parallel.h:724
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
void ParsedFEMFunctionTest::testHessians ( )
private

Definition at line 176 of file parsed_fem_function_test.C.

References libMesh::libmesh_real(), libMesh::Parallel::Communicator::rank(), TestCommWorld, libMesh::TOLERANCE, and libMesh::x.

177  {
178  if (c->has_elem() &&
179  c->get_elem().processor_id() == TestCommWorld->rank())
180  {
181  ParsedFEMFunction<Number> c1(*sys, "hess_xy_xy");
182 
183  CPPUNIT_ASSERT_DOUBLES_EQUAL
184  (libmesh_real(c1(*c,Point(0.35,0.45,0.55))), 1.0, TOLERANCE*TOLERANCE);
185 
186  ParsedFEMFunction<Number> x(*sys, "hess_yz_xyz");
187 
188  CPPUNIT_ASSERT_DOUBLES_EQUAL
189  (libmesh_real(x(*c,Point(0.25,0.35,0.55))), 0.25, TOLERANCE*TOLERANCE);
190 
191  ParsedFEMFunction<Number> xz(*sys, "hess_yz_xyz*grad_y_yz");
192 
193  CPPUNIT_ASSERT_DOUBLES_EQUAL
194  (libmesh_real(xz(*c,Point(0.25,0.4,0.75))), 0.1875, TOLERANCE*TOLERANCE);
195  }
196  }
T libmesh_real(T a)
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
static const Real TOLERANCE
PetscErrorCode Vec x
ParsedFEMFunction provides support for FParser-based parsed functions in FEMSystem.
UniquePtr< FEMContext > c
unsigned int rank() const
Definition: parallel.h:724
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
void ParsedFEMFunctionTest::testInlineGetter ( )
private

Definition at line 198 of file parsed_fem_function_test.C.

References libMesh::ParsedFEMFunction< Output >::get_inline_value(), libMesh::libmesh_real(), libMesh::Parallel::Communicator::rank(), TestCommWorld, and libMesh::TOLERANCE.

199  {
200  if (c->has_elem() &&
201  c->get_elem().processor_id() == TestCommWorld->rank())
202  {
203  ParsedFEMFunction<Number> ax2(*sys, "a:=4.5;a*x2");
204 
205  CPPUNIT_ASSERT_DOUBLES_EQUAL
206  (libmesh_real(ax2(*c,Point(0.25,0.25,0.25))), 2.25, TOLERANCE*TOLERANCE);
207 
208  CPPUNIT_ASSERT_DOUBLES_EQUAL
209  (libmesh_real(ax2.get_inline_value("a")), 4.5, TOLERANCE*TOLERANCE);
210 
212  (*sys, "a := 4 ; b := a/2+1; c:=b-a+3.5; c*x2*y4");
213 
214  CPPUNIT_ASSERT_DOUBLES_EQUAL
215  (libmesh_real(cxy8(*c,Point(0.5,0.5,0.5))), 5.0, TOLERANCE*TOLERANCE);
216 
217  CPPUNIT_ASSERT_DOUBLES_EQUAL
218  (libmesh_real(cxy8.get_inline_value("b")), 3.0, TOLERANCE*TOLERANCE);
219 
220  CPPUNIT_ASSERT_DOUBLES_EQUAL
221  (libmesh_real(cxy8.get_inline_value("c")), 2.5, TOLERANCE*TOLERANCE);
222  }
223  }
T libmesh_real(T a)
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
static const Real TOLERANCE
ParsedFEMFunction provides support for FParser-based parsed functions in FEMSystem.
UniquePtr< FEMContext > c
unsigned int rank() const
Definition: parallel.h:724
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
void ParsedFEMFunctionTest::testInlineSetter ( )
private

Definition at line 225 of file parsed_fem_function_test.C.

References libMesh::ParsedFEMFunction< Output >::get_inline_value(), libMesh::libmesh_real(), libMesh::Parallel::Communicator::rank(), libMesh::ParsedFEMFunction< Output >::set_inline_value(), TestCommWorld, and libMesh::TOLERANCE.

226  {
227  if (c->has_elem() &&
228  c->get_elem().processor_id() == TestCommWorld->rank())
229  {
230  ParsedFEMFunction<Number> ax2(*sys, "a:=4.5;a*x2");
231  ax2.set_inline_value("a", 2.5);
232 
233  CPPUNIT_ASSERT_DOUBLES_EQUAL
234  (libmesh_real(ax2(*c,Point(0.25,0.25,0.25))), 1.25, TOLERANCE*TOLERANCE);
235 
236  CPPUNIT_ASSERT_DOUBLES_EQUAL
237  (libmesh_real(ax2.get_inline_value("a")), 2.5, TOLERANCE*TOLERANCE);
238 
240  (*sys, "a := 4 ; b := a/2+1; c:=b-a+3.5; c*x2*y4");
241 
242  cxy8.set_inline_value("a", 2);
243 
244  CPPUNIT_ASSERT_DOUBLES_EQUAL
245  (libmesh_real(cxy8(*c,Point(0.5,0.5,0.5))), 7.0, TOLERANCE*TOLERANCE);
246 
247  CPPUNIT_ASSERT_DOUBLES_EQUAL
248  (libmesh_real(cxy8.get_inline_value("b")), 2.0, TOLERANCE*TOLERANCE);
249 
250  CPPUNIT_ASSERT_DOUBLES_EQUAL
251  (libmesh_real(cxy8.get_inline_value("c")), 3.5, TOLERANCE*TOLERANCE);
252 
253  }
254  }
T libmesh_real(T a)
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
static const Real TOLERANCE
ParsedFEMFunction provides support for FParser-based parsed functions in FEMSystem.
UniquePtr< FEMContext > c
unsigned int rank() const
Definition: parallel.h:724
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
void ParsedFEMFunctionTest::testNormals ( )
private

Definition at line 256 of file parsed_fem_function_test.C.

References CPPUNIT_TEST_SUITE_REGISTRATION(), libMesh::libmesh_real(), libMesh::Parallel::Communicator::rank(), TestCommWorld, and libMesh::TOLERANCE.

257  {
258  if (s->has_elem() &&
259  s->get_elem().processor_id() == TestCommWorld->rank())
260  {
261  ParsedFEMFunction<Number> nx(*sys, "n_x");
262 
263  ParsedFEMFunction<Number> ny(*sys, "n_y");
264 
265  ParsedFEMFunction<Number> nz(*sys, "n_z");
266 
267  const std::vector<Point> & xyz = s->get_side_fe(0)->get_xyz();
268 
269  // On side 3 of a hex the normal direction is +y
270  for (std::size_t qp=0; qp != xyz.size(); ++qp)
271  {
272  CPPUNIT_ASSERT_DOUBLES_EQUAL
273  (libmesh_real(nx(*s,xyz[qp])), 0.0, TOLERANCE*TOLERANCE);
274  CPPUNIT_ASSERT_DOUBLES_EQUAL
275  (libmesh_real(ny(*s,xyz[qp])), 1.0, TOLERANCE*TOLERANCE);
276  CPPUNIT_ASSERT_DOUBLES_EQUAL
277  (libmesh_real(nz(*s,xyz[qp])), 0.0, TOLERANCE*TOLERANCE);
278  }
279  }
280  }
T libmesh_real(T a)
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
static const Real TOLERANCE
ParsedFEMFunction provides support for FParser-based parsed functions in FEMSystem.
UniquePtr< FEMContext > s
unsigned int rank() const
Definition: parallel.h:724
void ParsedFEMFunctionTest::testValues ( )
private

Definition at line 135 of file parsed_fem_function_test.C.

References libMesh::libmesh_real(), libMesh::Parallel::Communicator::rank(), TestCommWorld, and libMesh::TOLERANCE.

136  {
137  if (c->has_elem() &&
138  c->get_elem().processor_id() == TestCommWorld->rank())
139  {
140  ParsedFEMFunction<Number> x2(*sys, "x2");
141 
142  CPPUNIT_ASSERT_DOUBLES_EQUAL
143  (libmesh_real(x2(*c,Point(0.5,0.5,0.5))), 1.0, TOLERANCE*TOLERANCE);
144 
145  ParsedFEMFunction<Number> xy8(*sys, "x2*y4");
146 
147  CPPUNIT_ASSERT_DOUBLES_EQUAL
148  (libmesh_real(xy8(*c,Point(0.5,0.5,0.5))), 2.0, TOLERANCE*TOLERANCE);
149  }
150  }
T libmesh_real(T a)
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
static const Real TOLERANCE
ParsedFEMFunction provides support for FParser-based parsed functions in FEMSystem.
UniquePtr< FEMContext > c
unsigned int rank() const
Definition: parallel.h:724
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38

Member Data Documentation

UniquePtr<FEMContext> ParsedFEMFunctionTest::c
private

Definition at line 133 of file parsed_fem_function_test.C.

UniquePtr<EquationSystems> ParsedFEMFunctionTest::es
private

Definition at line 131 of file parsed_fem_function_test.C.

UniquePtr<UnstructuredMesh> ParsedFEMFunctionTest::mesh
private

Definition at line 130 of file parsed_fem_function_test.C.

UniquePtr<FEMContext> ParsedFEMFunctionTest::s
private

Definition at line 133 of file parsed_fem_function_test.C.

System* ParsedFEMFunctionTest::sys
private

Definition at line 132 of file parsed_fem_function_test.C.


The documentation for this class was generated from the following file: