1 #ifndef NUMERIC_VECTOR_TEST_H 2 #define NUMERIC_VECTOR_TEST_H 8 #include <libmesh/parallel.h> 9 #include <libmesh/fuzzy_equals.h> 10 #include <libmesh/int_range.h> 16 #define NUMERICVECTORTEST \ 17 CPPUNIT_TEST( testLocalize ); \ 18 CPPUNIT_TEST( testLocalizeBase ); \ 19 CPPUNIT_TEST( testLocalizeIndices ); \ 20 CPPUNIT_TEST( testLocalizeIndicesBase ); \ 21 CPPUNIT_TEST( testLocalizeToOne ); \ 22 CPPUNIT_TEST( testLocalizeToOneBase ); \ 23 CPPUNIT_TEST( testNorms ); \ 24 CPPUNIT_TEST( testNormsBase ); \ 25 CPPUNIT_TEST( testOperations ); \ 26 CPPUNIT_TEST( testOperationsBase ); \ 27 CPPUNIT_TEST( testWriteAndRead ); \ 28 CPPUNIT_TEST( testWriteAndReadBase ); 35 template <
class DerivedClass>
68 template <
class Base,
class Derived>
75 first = v.first_local_index(),
76 last = v.last_local_index();
79 v.set (n, static_cast<libMesh::Number>(n+1));
82 auto v_clone = v.clone();
83 auto & vorig = *v_clone;
92 LIBMESH_ASSERT_NUMBERS_EQUAL
99 LIBMESH_ASSERT_NUMBERS_EQUAL
106 LIBMESH_ASSERT_NUMBERS_EQUAL
113 LIBMESH_ASSERT_NUMBERS_EQUAL
119 LIBMESH_ASSERT_NUMBERS_EQUAL
125 LIBMESH_ASSERT_NUMBERS_EQUAL
131 LIBMESH_ASSERT_NUMBERS_EQUAL
137 LIBMESH_ASSERT_NUMBERS_EQUAL
143 LIBMESH_ASSERT_NUMBERS_EQUAL
149 LIBMESH_ASSERT_NUMBERS_EQUAL
153 LIBMESH_ASSERT_NUMBERS_EQUAL
159 template <
class Base,
class Derived>
166 first = v.first_local_index(),
167 last = v.last_local_index();
169 const unsigned int sub_local_size =
block_size/2;
170 const unsigned int sub_global_size = sub_local_size *
my_comm->
size();
172 for (
auto supplying_global_rows : {
false,
true})
173 for (
auto get_not_create : {
false,
true})
176 if (get_not_create && supplying_global_rows)
180 v.set (n, static_cast<libMesh::Number>(n+1));
183 std::unique_ptr<Base> s_ptr =
184 std::make_unique<Derived>(*
my_comm, sub_global_size,
188 sub_first = s_ptr->first_local_index(),
189 sub_last = s_ptr->last_local_index();
199 std::vector<libMesh::dof_id_type> rows;
201 rows.push_back(first+2*i);
203 if (supplying_global_rows)
210 s_ptr.reset(dynamic_cast<Base *>(subvec_ptr));
213 v.create_subvector(*s_ptr, rows, supplying_global_rows);
218 LIBMESH_ASSERT_NUMBERS_EQUAL
231 v.restore_subvector(std::move(s_ptr), rows);
236 if (offset < 2*sub_local_size && !(offset%2))
237 LIBMESH_ASSERT_NUMBERS_EQUAL
240 ((offset/2) + sub_first)),
243 LIBMESH_ASSERT_NUMBERS_EQUAL
250 template <
class Base,
class Derived>
257 first = v.first_local_index(),
258 last = v.last_local_index();
261 v.set (n, static_cast<libMesh::Number>(n+1));
272 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 278 Base & v_new = *v_new_ptr;
284 CPPUNIT_ASSERT_EQUAL(v.l1_norm_diff(v_new),
libMesh::Real(0));
287 template <
class Base,
class Derived>
294 first = v.first_local_index(),
295 last = v.last_local_index();
298 v.set (n, -static_cast<libMesh::Number>(n));
301 v.add (n, -static_cast<libMesh::Number>(n));
310 LIBMESH_ASSERT_NUMBERS_EQUAL(v.sum(), -exact_l1,
312 LIBMESH_ASSERT_FP_EQUAL(v.l1_norm(), exact_l1,
314 LIBMESH_ASSERT_FP_EQUAL(v.l2_norm(), exact_l2,
322 u.set (n, -static_cast<libMesh::Number>(n * n));
326 Base & diff = diff_derived;
334 const auto diff_norm = diff.l2_norm();
335 const auto norm_diff = u.l2_norm_diff(v);
336 LIBMESH_ASSERT_FP_EQUAL(diff_norm, norm_diff,
337 (std::abs(diff_norm)+std::abs(norm_diff)) *
341 template <
class Base,
class Derived>
352 first = v.first_local_index(),
353 last = v.last_local_index();
356 v.set (n, static_cast<libMesh::Number>(n));
359 v.add (n, static_cast<libMesh::Number>(n));
365 v.localize_to_one(l,root_pid);
370 LIBMESH_ASSERT_NUMBERS_EQUAL
376 v.insert (&
value, std::vector<libMesh::numeric_index_type>({n}));
383 v.localize_to_one(l,root_pid);
388 LIBMESH_ASSERT_NUMBERS_EQUAL
394 template <
class Base,
class Derived>
403 std::vector<libMesh::dof_id_type> indices;
407 first = v.first_local_index(),
408 last = v.last_local_index();
411 v.set (n, static_cast<libMesh::Number>(n));
418 for (
unsigned int j = 0; j !=
block_size; ++j)
419 indices.push_back(end_index-j-1);
422 v.localize(values, indices);
428 for (
unsigned int j = 0; j !=
block_size; ++j)
429 LIBMESH_ASSERT_NUMBERS_EQUAL
440 Localize<DerivedClass,DerivedClass>();
447 Localize<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
454 Localize<DerivedClass,DerivedClass >(
true);
461 Localize<libMesh::NumericVector<libMesh::Number>,DerivedClass>(
true);
468 LocalizeIndices<DerivedClass,DerivedClass >();
475 LocalizeIndices<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
482 Norms<DerivedClass,DerivedClass >();
489 Norms<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
496 Operations<DerivedClass,DerivedClass >();
503 Operations<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
510 Subvectors<DerivedClass,DerivedClass >();
517 Subvectors<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
524 WriteAndRead<DerivedClass,DerivedClass >();
531 WriteAndRead<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
void testLocalizeIndices()
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
libMesh::Parallel::Communicator * TestCommWorld
static constexpr Real TOLERANCE
processor_id_type rank() const
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
void testSubvectorsBase()
uint8_t processor_id_type
void Localize(bool to_one=false)
processor_id_type size() const
libMesh::Parallel::Communicator * my_comm
virtual std::unique_ptr< NumericVector< T > > get_subvector(const std::vector< numeric_index_type > &)
Creates a view into this vector using the indices in rows.
void testLocalizeIndicesBase()
void testOperationsBase()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void testLocalizeToOneBase()
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
void testWriteAndReadBase()
bool relative_fuzzy_equals(const T &var1, const T2 &var2, const Real tol=TOLERANCE *TOLERANCE)
Function to check whether two variables are equal within a relative tolerance.
std::string libmesh_suite_name