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

Public Member Functions

void setUp ()
 
void tearDown ()
 
 CPPUNIT_TEST_SUITE (CompositeFunctionTest)
 
 CPPUNIT_TEST (testRemap)
 
 CPPUNIT_TEST (testTimeDependence)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Member Functions

void testRemap ()
 
void testTimeDependence ()
 

Detailed Description

Definition at line 14 of file composite_function_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/2]

CompositeFunctionTest::CPPUNIT_TEST ( testRemap  )

◆ CPPUNIT_TEST() [2/2]

CompositeFunctionTest::CPPUNIT_TEST ( testTimeDependence  )

◆ CPPUNIT_TEST_SUITE()

CompositeFunctionTest::CPPUNIT_TEST_SUITE ( CompositeFunctionTest  )

◆ CPPUNIT_TEST_SUITE_END()

CompositeFunctionTest::CPPUNIT_TEST_SUITE_END ( )

◆ setUp()

void CompositeFunctionTest::setUp ( )
inline

Definition at line 17 of file composite_function_test.C.

17 {}

◆ tearDown()

void CompositeFunctionTest::tearDown ( )
inline

Definition at line 19 of file composite_function_test.C.

19 {}

◆ testRemap()

void CompositeFunctionTest::testRemap ( )
inlineprivate

Definition at line 32 of file composite_function_test.C.

33  {
34  std::vector<std::vector<unsigned int>> index_sets(4);
35  index_sets[0].resize(2);
36  index_sets[0][0] = 3;
37  index_sets[0][1] = 4;
38  index_sets[1].resize(3);
39  index_sets[1][0] = 0;
40  index_sets[1][1] = 1;
41  index_sets[1][2] = 2;
42  index_sets[2].resize(3);
43  index_sets[2][0] = 0;
44  index_sets[2][1] = 2;
45  index_sets[2][2] = 4;
46  index_sets[3].resize(5);
47  index_sets[3][0] = 5;
48  index_sets[3][1] = 1;
49  index_sets[3][2] = 3;
50  index_sets[3][3] = 6;
51  index_sets[3][4] = 7;
52 
53  CompositeFunction<Real> composite_outer;
54 
55  {
56  CompositeFunction<Real> composite_inner;
57 
58  // Test that ConstFunction copy construction works.
59  ConstFunction<Real> cf_one(1);
60  ConstFunction<Real> cf_one_copy(cf_one);
61  composite_inner.attach_subfunction (cf_one_copy, index_sets[0]);
62 
63  // Test that ConstFunction move construction works.
64  ConstFunction<Real> cf_two(2);
65  ConstFunction<Real> cf_two_move(std::move(cf_two));
66  composite_inner.attach_subfunction (cf_two_move, index_sets[1]);
67 
68  composite_outer.attach_subfunction
69  (composite_inner, index_sets[3]);
70 
71  DenseVector<Real> test_one(5);
72 
73  composite_inner(Point(0), 0, test_one);
74 
75  LIBMESH_ASSERT_FP_EQUAL(test_one(0), 2, 1.e-12);
76  LIBMESH_ASSERT_FP_EQUAL(test_one(1), 2, 1.e-12);
77  LIBMESH_ASSERT_FP_EQUAL(test_one(2), 2, 1.e-12);
78  LIBMESH_ASSERT_FP_EQUAL(test_one(3), 1, 1.e-12);
79  LIBMESH_ASSERT_FP_EQUAL(test_one(4), 1, 1.e-12);
80  }
81  // Test that ConstFunction copy- and move-assignment works.
82  ConstFunction<Real> cf_three(3);
83  ConstFunction<Real> cf_three_copy_assign(0);
84  ConstFunction<Real> cf_three_move_assign(0);
85  cf_three_copy_assign = cf_three;
86  cf_three_move_assign = std::move(cf_three_copy_assign);
87  composite_outer.attach_subfunction(cf_three_move_assign, index_sets[2]);
88 
89  // Test that move ctor works. Note that composite_outer should not
90  // be used for anything once it has been moved from!
91  CompositeFunction<Real> composite_outer_copy1(std::move(composite_outer));
92 
93  // Test that move assignment also works. The first copy should not be
94  // used again after being move assigned.
95  CompositeFunction<Real> composite_outer_copy2;
96  composite_outer_copy2 = std::move(composite_outer_copy1);
97 
98  DenseVector<Real> test_two(8);
99  composite_outer_copy2(Point(0), 0, test_two);
100 
101  LIBMESH_ASSERT_FP_EQUAL(test_two(0), 3, 1.e-12);
102  LIBMESH_ASSERT_FP_EQUAL(test_two(2), 3, 1.e-12);
103  LIBMESH_ASSERT_FP_EQUAL(test_two(4), 3, 1.e-12);
104  LIBMESH_ASSERT_FP_EQUAL(test_two(5), 2, 1.e-12);
105  LIBMESH_ASSERT_FP_EQUAL(test_two(1), 2, 1.e-12);
106  LIBMESH_ASSERT_FP_EQUAL(test_two(3), 2, 1.e-12);
107  LIBMESH_ASSERT_FP_EQUAL(test_two(6), 1, 1.e-12);
108  LIBMESH_ASSERT_FP_EQUAL(test_two(7), 1, 1.e-12);
109  }

References libMesh::CompositeFunction< Output >::attach_subfunction().

◆ testTimeDependence()

void CompositeFunctionTest::testTimeDependence ( )
inlineprivate

Definition at line 111 of file composite_function_test.C.

112  {
113 #ifdef LIBMESH_HAVE_FPARSER
114  // We'll test the order of adding these functions to
115  // make sure time dependence gets detected/updated correctly
116  // for each
117  ParsedFunction<Real> no_t("x*2+y^2-tanh(z)+atan(x-y)");
118  ParsedFunction<Real> no_t2("x*2+y^2+z^2");
119 
121 
122  ParsedFunction<Real> xyt("x+y+t");
123 
124  // Test constructing AnalyticFunction with lambda.
125  auto af_lambda =
126  [](const Point & p, const Real t) -> Real
127  { return p(0)*p(0) + p(1)*p(1) + t*t; };
128  AnalyticFunction<Real> x2y2t2(af_lambda);
129 
130  std::vector<unsigned int> index_set(1,0);
131 
132  {
133  // composite should not be time dependent since this is the first subfunction
134  // added and it's not time-dependent
135  CompositeFunction<Real> composite;
136  composite.attach_subfunction(no_t, index_set);
137  CPPUNIT_ASSERT(!composite.is_time_dependent());
138 
139  // Now composite should be time-dependent since we've now added a time dependent function
140  index_set[0] = 1;
141  composite.attach_subfunction(xyt, index_set);
142  CPPUNIT_ASSERT(composite.is_time_dependent());
143 
144  // Composite should still be time-dependent
145  index_set[0] = 2;
146 
147  // Test AnalyticFunction copy ctor and copy assignment
148  AnalyticFunction<Real> x2y2t2_copy1(x2y2t2);
149  AnalyticFunction<Real> x2y2t2_copy2([](const Point &, const Real) -> Real { return 0; });
150  x2y2t2_copy2 = x2y2t2_copy1;
151  composite.attach_subfunction(x2y2t2_copy2, index_set);
152  CPPUNIT_ASSERT(composite.is_time_dependent());
153  }
154 
155 
156  {
157  CompositeFunction<Real> composite;
158 
159  // composite should be time-dependent since we've added a time dependent function
160  index_set[0] = 0;
161  composite.attach_subfunction(xyt, index_set);
162  CPPUNIT_ASSERT(composite.is_time_dependent());
163 
164  // composite should still be time-dependent since the previous function was time-dependent
165  index_set[0] = 1;
166  composite.attach_subfunction(no_t, index_set);
167  CPPUNIT_ASSERT(composite.is_time_dependent());
168 
169  // Composite should still be time-dependent
170  index_set[0] = 2;
171 
172  // Test AnalyticFunction move ctor and move assignment. Note: we
173  // first copy and then steal the copy's resources to avoid
174  // messing with any later tests of "x2y2t2".
175  AnalyticFunction<Real> x2y2t2_copy(x2y2t2);
176  AnalyticFunction<Real> x2y2t2_move1(std::move(x2y2t2_copy));
177  AnalyticFunction<Real> x2y2t2_move2([](const Point &, const Real) -> Real { return 0; });
178  x2y2t2_move2 = std::move(x2y2t2_move1);
179  composite.attach_subfunction(x2y2t2_move2, index_set);
180  CPPUNIT_ASSERT(composite.is_time_dependent());
181  }
182 
183  {
184  CompositeFunction<Real> composite;
185 
186  // composite should not be time-dependent since we've added a time independent function
187  index_set[0] = 0;
188  composite.attach_subfunction(no_t, index_set);
189  CPPUNIT_ASSERT(!composite.is_time_dependent());
190 
191  // composite should still be time-independent
192  index_set[0] = 1;
193  composite.attach_subfunction(no_t2, index_set);
194  CPPUNIT_ASSERT(!composite.is_time_dependent());
195 
196  // Composite should still be time-independent
197  index_set[0] = 2;
198  composite.attach_subfunction(zero, index_set);
199  CPPUNIT_ASSERT(!composite.is_time_dependent());
200  }
201 #endif // #ifdef LIBMESH_HAVE_FPARSER
202  }

References libMesh::CompositeFunction< Output >::attach_subfunction(), libMesh::FunctionBase< Output >::is_time_dependent(), libMesh::Real, and libMesh::zero.


The documentation for this class was generated from the following file:
libMesh::ParsedFunction
A Function generated (via FParser) by parsing a mathematical expression.
Definition: parsed_function.h:60
libMesh::CompositeFunction
A function that returns a vector whose components are defined by multiple functions.
Definition: composite_function.h:49
libMesh::FunctionBase::is_time_dependent
bool is_time_dependent() const
Definition: function_base.h:219
libMesh::zero
const Number zero
.
Definition: libmesh.h:243
libMesh::AnalyticFunction
Wraps a function pointer into a FunctionBase object.
Definition: analytic_function.h:48
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::ZeroFunction
ConstFunction that simply returns 0.
Definition: zero_function.h:36
libMesh::CompositeFunction::attach_subfunction
void attach_subfunction(const FunctionBase< Output > &f, const std::vector< unsigned int > &index_map)
Attach a new subfunction, along with a map from the indices of the attached subfunction to the indice...
Definition: composite_function.h:82
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::ConstFunction
Function that returns a single value that never changes.
Definition: const_function.h:43
libMesh::DenseVector
Defines a dense vector for use in Finite Element-type computations.
Definition: meshless_interpolation_function.h:39