1 #ifndef SPARSE_MATRIX_TEST_H 2 #define SPARSE_MATRIX_TEST_H 8 #include <libmesh/dense_matrix.h> 9 #include <libmesh/sparse_matrix.h> 10 #include <libmesh/fuzzy_equals.h> 16 #ifdef LIBMESH_HAVE_CXX11_THREAD 22 #define SPARSEMATRIXTEST \ 23 CPPUNIT_TEST(testGetAndSet); \ 24 CPPUNIT_TEST(testReadMatlab1); \ 25 CPPUNIT_TEST(testReadMatlab2); \ 26 CPPUNIT_TEST(testReadMatlab4); \ 27 CPPUNIT_TEST(testWriteAndRead); \ 28 CPPUNIT_TEST(testClone); 32 template <
class DerivedClass>
45 matrix = std::make_unique<DerivedClass>(*my_comm);
79 std::vector<libMesh::numeric_index_type> rows(
local_m);
81 std::vector<libMesh::numeric_index_type> cols(
local_n);
88 local(i, j) = (i + 1) * (j + 1) * (
my_comm->
rank() + 1);
92 matrix->add_matrix(local, rows, cols);
99 auto functor = [
this]()
101 std::vector<libMesh::numeric_index_type> cols_to_get;
102 std::vector<libMesh::Number> values;
109 matrix->get_row(i, cols_to_get, values);
113 CPPUNIT_ASSERT_EQUAL(cols_to_get[col_j], col_start + col_j);
114 LIBMESH_ASSERT_NUMBERS_EQUAL
121 #ifdef LIBMESH_HAVE_CXX11_THREAD 122 auto num_threads = std::min(
unsigned(2),
124 std::thread::hardware_concurrency(),
126 std::vector<std::thread> threads(num_threads);
127 for (
unsigned int thread = 0; thread < num_threads; ++thread)
128 threads[thread] = std::thread(functor);
129 std::for_each(threads.begin(), threads.end(),
130 [](std::thread & x){x.join();});
154 auto matrix2 = std::make_unique<DerivedClass>(*my_comm);
158 #ifndef LIBMESH_HAVE_GZSTREAM 162 matrix2->read(std::string(filename)+
".gz");
165 CPPUNIT_ASSERT(
matrix->l1_norm() == matrix2->l1_norm());
166 CPPUNIT_ASSERT(
matrix->linfty_norm() == matrix2->linfty_norm());
199 if (
matrix->n_processors() > 1 ||
211 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 234 auto copy =
matrix->clone();
237 CPPUNIT_ASSERT_EQUAL(copy->m(),
matrix->m());
238 CPPUNIT_ASSERT_EQUAL(copy->n(),
matrix->n());
239 CPPUNIT_ASSERT_EQUAL(copy->local_m(),
matrix->local_m());
240 CPPUNIT_ASSERT_EQUAL(copy->row_start(),
matrix->row_start());
241 CPPUNIT_ASSERT_EQUAL(copy->row_stop(),
matrix->row_stop());
252 auto zero_copy =
matrix->zero_clone();
255 CPPUNIT_ASSERT_EQUAL(zero_copy->m(),
matrix->m());
256 CPPUNIT_ASSERT_EQUAL(zero_copy->n(),
matrix->n());
257 CPPUNIT_ASSERT_EQUAL(zero_copy->local_m(),
matrix->local_m());
258 CPPUNIT_ASSERT_EQUAL(zero_copy->row_start(),
matrix->row_start());
259 CPPUNIT_ASSERT_EQUAL(zero_copy->row_stop(),
matrix->row_stop());
262 LIBMESH_ASSERT_FP_EQUAL(0.0, zero_copy->l1_norm(),
_tolerance);
281 #endif // SPARSE_MATRIX_TEST_H
libMesh::Parallel::Communicator * TestCommWorld
static constexpr Real TOLERANCE
libMesh::Parallel::Communicator * my_comm
processor_id_type rank() const
libMesh::numeric_index_type local_n
void iota(ForwardIter first, ForwardIter last, T value)
Utility::iota was created back when std::iota was just an SGI STL extension.
processor_id_type size() const
dof_id_type numeric_index_type
void testReadMatlab(const std::string &filename)
std::unique_ptr< DerivedClass > matrix
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
libMesh::numeric_index_type global_m
std::string libmesh_suite_name
const libMesh::Real _tolerance
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...
libMesh::numeric_index_type nonsquare
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.
libMesh::numeric_index_type global_n
Defines a dense matrix for use in Finite Element-type computations.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
libMesh::numeric_index_type local_m