libMesh
Loading...
Searching...
No Matches
parsed_function_test.C
Go to the documentation of this file.
1// libmesh includes
2#include "libmesh/elem.h"
3#include "libmesh/equation_systems.h"
4#include "libmesh/mesh.h"
5#include "libmesh/mesh_generation.h"
6#include "libmesh/numeric_vector.h"
7#include "libmesh/parsed_function.h"
8#include "libmesh/system.h"
9
10#ifdef LIBMESH_HAVE_FPARSER
11
12// test includes
13#include "test_comm.h"
14#include "libmesh_cppunit.h"
15
16
17using namespace libMesh;
18
19class ParsedFunctionTest : public CppUnit::TestCase
20{
21public:
22 void setUp() {}
23
24 void tearDown() {}
25
27
28#if LIBMESH_DIM > 2
33#endif
34
36
37
38private:
39
41 {
42 LOG_UNIT_TEST;
43
44 // Test that we can copy these into vectors
45 std::vector<ParsedFunction<Number>> pfvec;
46
47 {
48 ParsedFunction<Number> xy8("x*y*8");
49
50 // Test that the move ctor works
51 ParsedFunction<Number> xy8_stolen(std::move(xy8));
52
53 pfvec.push_back(xy8_stolen);
54
55 LIBMESH_ASSERT_NUMBERS_EQUAL
56 (6.0, xy8_stolen(Point(0.5,1.5,2.5)), TOLERANCE*TOLERANCE);
57 }
58 LIBMESH_ASSERT_NUMBERS_EQUAL
59 (6.0, pfvec[0](Point(0.5,1.5,2.5)), TOLERANCE*TOLERANCE);
60 }
61
63 {
64 LOG_UNIT_TEST;
65
66 ParsedFunction<Number> ax2("a:=4.5;a*x*2");
67
68 // Test whether move assignment works.
69 ParsedFunction<Number> ax2_stolen("x");
70 ax2_stolen = std::move(ax2);
71
72 LIBMESH_ASSERT_NUMBERS_EQUAL
73 (2.25, ax2_stolen(Point(0.25,0.25,0.25)), TOLERANCE*TOLERANCE);
74
75 LIBMESH_ASSERT_NUMBERS_EQUAL
76 (4.5, ax2_stolen.get_inline_value("a"), TOLERANCE*TOLERANCE);
77
79 ("a := 4 ; b := a/2+1; c:=b-a+3.5; c*x*2*y*4");
80
81 LIBMESH_ASSERT_NUMBERS_EQUAL
82 (5.0, cxy8(Point(0.5,0.5,0.5)), TOLERANCE*TOLERANCE);
83
84 LIBMESH_ASSERT_NUMBERS_EQUAL
85 (3.0, cxy8.get_inline_value("b"), TOLERANCE*TOLERANCE);
86
87 LIBMESH_ASSERT_NUMBERS_EQUAL
88 (2.5, cxy8.get_inline_value("c"), TOLERANCE*TOLERANCE);
89 }
90
92 {
93 LOG_UNIT_TEST;
94
95 ParsedFunction<Number> ax2("a:=4.5;a*x*2");
96 ax2.set_inline_value("a", 2.5);
97
98 LIBMESH_ASSERT_NUMBERS_EQUAL
99 (1.25, ax2(Point(0.25,0.25,0.25)), TOLERANCE*TOLERANCE);
100
101 LIBMESH_ASSERT_NUMBERS_EQUAL
102 (2.5, ax2.get_inline_value("a"), TOLERANCE*TOLERANCE);
103
105 ("a := 4 ; b := a/2+1; c:=b-a+3.5; c*x*2*y*4");
106 cxy8.set_inline_value("a", 2);
107
108 LIBMESH_ASSERT_NUMBERS_EQUAL
109 (7.0, cxy8(Point(0.5,0.5,0.5)), TOLERANCE*TOLERANCE);
110
111 LIBMESH_ASSERT_NUMBERS_EQUAL
112 (2.0, cxy8.get_inline_value("b"), TOLERANCE*TOLERANCE);
113
114 LIBMESH_ASSERT_NUMBERS_EQUAL
115 (3.5, cxy8.get_inline_value("c"), TOLERANCE*TOLERANCE);
116 }
117
119 {
120 LOG_UNIT_TEST;
121
122 ParsedFunction<Number> no_t("x*2+y^2-tanh(z)+atan(x-y)");
123 CPPUNIT_ASSERT(!no_t.is_time_dependent());
124
125 ParsedFunction<Number> xyt("x+y+t");
126 CPPUNIT_ASSERT(xyt.is_time_dependent());
127
128 ParsedFunction<Number> x2y2t2("x*2+y^2+t^2");
129 CPPUNIT_ASSERT(x2y2t2.is_time_dependent());
130
131 ParsedFunction<Number> ztanht("z*tanh(t)");
132 CPPUNIT_ASSERT(ztanht.is_time_dependent());
133 }
134
135};
136
138
139#endif // #ifdef LIBMESH_HAVE_FPARSER
CPPUNIT_TEST(testValues)
CPPUNIT_TEST(testInlineSetter)
CPPUNIT_TEST(testInlineGetter)
LIBMESH_CPPUNIT_TEST_SUITE(ParsedFunctionTest)
CPPUNIT_TEST(testTimeDependence)
bool is_time_dependent() const
A Function generated (via FParser) by parsing a mathematical expression.
void set_inline_value(std::string_view inline_var_name, Output newval)
Changes the value of an inline variable.
Output get_inline_value(std::string_view inline_var_name) const
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
The libMesh namespace provides an interface to certain functionality in the library.
static constexpr Real TOLERANCE
CPPUNIT_TEST_SUITE_REGISTRATION(ParsedFunctionTest)