libMesh
Loading...
Searching...
No Matches
vector_value_test.C
Go to the documentation of this file.
1#include <libmesh/vector_value.h>
2
3#include "type_vector_test.h"
4
5#include <type_traits>
6
7#ifdef LIBMESH_HAVE_METAPHYSICL
8#include <metaphysicl/dualnumber.h>
9#endif
10
11
12using namespace libMesh;
13
14#define VECTORVALUETEST \
15 TYPEVECTORTEST \
16 CPPUNIT_TEST( testScalarInit ); \
17
18class RealVectorValueTest : public TypeVectorTestBase<VectorValue<Real>> {
19public:
23 this->libmesh_suite_name = "TypeVectorTest";
24 else
25 this->libmesh_suite_name = "RealVectorValueTest";
26 }
27
29
30 VECTORVALUETEST
31
33};
34
35class NumberVectorValueTest : public TypeVectorTestBase<VectorValue<Number>> {
36public:
39 this->libmesh_suite_name = "NumberVectorValueTest";
40 }
41
43
44 VECTORVALUETEST
45
47};
48
49class ComplexVectorValueTest : public TypeVectorTestBase<VectorValue<Complex>> {
50public:
53 this->libmesh_suite_name = "ComplexVectorValueTest";
54 }
55
57
58 VECTORVALUETEST
59
61};
62
63class VectorCompareTypesTest : public CppUnit::TestCase {
64public:
66
68
70
71private:
72 template <typename T, typename T2>
74 average(const T & val1, const T2 & val2)
75 {
76 return (val1 + val2) / 2;
77 }
78
79public:
80 void
82 {
83 LOG_UNIT_TEST;
84
87
88 [[maybe_unused]] auto ftype = fvec * 1;
89 [[maybe_unused]] auto dtype = dvec * 1;
90
91 {
92 bool assertion = std::is_same<decltype(ftype), TypeVector<float>>::value;
93 CPPUNIT_ASSERT(assertion);
94 }
95 {
96 bool assertion = std::is_same<decltype(dtype), TypeVector<double>>::value;
97 CPPUNIT_ASSERT(assertion);
98 }
99 {
100 bool assertion = std::is_same<decltype(average(ftype, ftype)), TypeVector<float>>::value;
101 CPPUNIT_ASSERT(assertion);
102 }
103 {
104 bool assertion = std::is_same<decltype(average(ftype, dtype)), TypeVector<double>>::value;
105 CPPUNIT_ASSERT(assertion);
106 }
107 {
108 bool assertion = std::is_same<decltype(average(fvec, fvec)), VectorValue<float>>::value;
109 CPPUNIT_ASSERT(assertion);
110 }
111 {
112 bool assertion = std::is_same<decltype(average(fvec, dvec)), VectorValue<double>>::value;
113 CPPUNIT_ASSERT(assertion);
114 }
115 {
116 bool assertion = std::is_same<decltype(average(fvec, dtype)), VectorValue<double>>::value;
117 CPPUNIT_ASSERT(assertion);
118 }
119 {
120 bool assertion = std::is_same<decltype(average(ftype, dvec)), VectorValue<double>>::value;
121 CPPUNIT_ASSERT(assertion);
122 }
123#ifdef LIBMESH_HAVE_METAPHYSICL
124 {
125 typedef typename MetaPhysicL::ReplaceAlgebraicType<
126 std::vector<double>,
128 typename MetaPhysicL::ValueType<std::vector<double>>::type>::type>::type
129 ReplacedType;
130 constexpr bool assertion =
131 std::is_same<ReplacedType, std::vector<VectorValue<double>>>::value;
132 CPPUNIT_ASSERT(assertion);
133 }
134 {
135 typedef typename MetaPhysicL::ReplaceAlgebraicType<
136 std::vector<VectorValue<double>>,
138 typename MetaPhysicL::ValueType<std::vector<VectorValue<double>>>::type>::type>::type
139 ReplacedType;
140 constexpr bool assertion =
141 std::is_same<ReplacedType, std::vector<TensorValue<double>>>::value;
142 CPPUNIT_ASSERT(assertion);
143 }
144#endif
145 }
146};
147
148
149#ifdef LIBMESH_HAVE_METAPHYSICL
150class ADVectorValueTest : public CppUnit::TestCase {
151public:
153
156
158
159private:
160 typedef MetaPhysicL::DualNumber<Real> ADReal;
161
162public:
164 {
165 LOG_UNIT_TEST;
166
167 VectorValue<ADReal> avector(ADReal(0, 1));
168#if LIBMESH_DIM > 1
169 avector(1) = ADReal(0, 1);
170#endif
171#if LIBMESH_DIM > 2
172 avector(2) = ADReal(0, 1);
173#endif
174
175 const ADReal result = avector.norm();
176
177 LIBMESH_ASSERT_FP_EQUAL( Real(0), result.value(), TOLERANCE*TOLERANCE );
178 LIBMESH_ASSERT_FP_EQUAL( Real(0), result.derivatives(), TOLERANCE*TOLERANCE );
179 }
180
182 {
183 LOG_UNIT_TEST;
184
185 VectorValue<ADReal> avector(ADReal(1, 1));
186#if LIBMESH_DIM > 1
187 avector(1) = ADReal(1, 1);
188#endif
189#if LIBMESH_DIM > 2
190 avector(2) = ADReal(1, 1);
191#endif
192
193 const ADReal result = avector.norm();
194
195 LIBMESH_ASSERT_FP_EQUAL( std::sqrt(Real(LIBMESH_DIM)), result.value(), TOLERANCE*TOLERANCE );
196 LIBMESH_ASSERT_FP_EQUAL( std::sqrt(Real(LIBMESH_DIM)), result.derivatives(), TOLERANCE*TOLERANCE );
197 }
198};
199#endif // LIBMESH_HAVE_METAPHYSICL
200
201
206#ifdef LIBMESH_HAVE_METAPHYSICL
208#endif
MetaPhysicL::DualNumber< Real > ADReal
LIBMESH_CPPUNIT_TEST_SUITE(ADVectorValueTest)
CPPUNIT_TEST(testNormDerivative)
CPPUNIT_TEST(testNormAtZeroDerivative)
CPPUNIT_TEST_SUITE(ComplexVectorValueTest)
VECTORVALUETEST CPPUNIT_TEST_SUITE_END()
VECTORVALUETEST CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST_SUITE(NumberVectorValueTest)
CPPUNIT_TEST_SUITE(RealVectorValueTest)
VECTORVALUETEST CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST(testCompareTypes)
LIBMESH_CPPUNIT_TEST_SUITE(VectorCompareTypesTest)
CompareTypes< T, T2 >::supertype average(const T &val1, const T2 &val2)
bool summarized_logs_enabled()
Definition perf_log.h:210
This class defines a vector in LIBMESH_DIM dimensional space of type T.
Definition type_vector.h:64
auto norm() const
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
libMesh::PerfLog * unitlog
Definition driver.C:272
The libMesh namespace provides an interface to certain functionality in the library.
std::complex< Real > Complex
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CPPUNIT_TEST_SUITE_REGISTRATION(RealVectorValueTest)
static const bool value
Definition xdr_io.C:55