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

Public Member Functions

void setUp ()
 
void tearDown ()
 
 LaspackVectorTest ()
 
 CPPUNIT_TEST_SUITE (LaspackVectorTest)
 
NUMERICVECTORTEST CPPUNIT_TEST_SUITE_END ()
 
void Operations ()
 
void Norms ()
 
void Localize (bool to_one=false)
 
void LocalizeIndices ()
 
void testLocalize ()
 
void testLocalizeBase ()
 
void testLocalizeToOne ()
 
void testLocalizeToOneBase ()
 
void testLocalizeIndices ()
 
void testLocalizeIndicesBase ()
 
void testNorms ()
 
void testNormsBase ()
 
void testOperations ()
 
void testOperationsBase ()
 

Protected Attributes

libMesh::Parallel::Communicatormy_comm
 
std::string libmesh_suite_name
 
unsigned int block_size
 
unsigned int local_size
 
unsigned int global_size
 

Private Attributes

std::unique_ptr< Parallel::Communicator_managed_comm
 

Detailed Description

Definition at line 10 of file laspack_vector_test.C.

Constructor & Destructor Documentation

◆ LaspackVectorTest()

LaspackVectorTest::LaspackVectorTest ( )
inline

Definition at line 33 of file laspack_vector_test.C.

References libMesh::PerfLog::summarized_logs_enabled(), and unitlog.

33  :
36  this->libmesh_suite_name = "NumericVectorTest";
37  else
38  this->libmesh_suite_name = "LaspackVectorTest";
39  }
bool summarized_logs_enabled()
Definition: perf_log.h:202
libMesh::PerfLog * unitlog
Definition: driver.C:161

Member Function Documentation

◆ CPPUNIT_TEST_SUITE()

LaspackVectorTest::CPPUNIT_TEST_SUITE ( LaspackVectorTest  )

◆ CPPUNIT_TEST_SUITE_END()

NUMERICVECTORTEST LaspackVectorTest::CPPUNIT_TEST_SUITE_END ( )

◆ Localize()

void NumericVectorTest< LaspackVector< Number > >::Localize ( bool  to_one = false)
inlineinherited

Definition at line 201 of file numeric_vector_test.h.

202  {
203  const libMesh::processor_id_type root_pid = 0;
204 
205  {
206  auto v_ptr = std::make_unique<Derived>(*my_comm, global_size, local_size);
207  Base & v = *v_ptr;
208  std::vector<libMesh::Number> l(global_size);
209 
211  first = v.first_local_index(),
212  last = v.last_local_index();
213 
214  for (libMesh::dof_id_type n=first; n != last; n++)
215  v.set (n, static_cast<libMesh::Number>(n));
216  v.close();
217  for (libMesh::dof_id_type n=first; n != last; n++)
218  v.add (n, static_cast<libMesh::Number>(n));
219  v.close();
220 
221  if (!to_one)
222  v.localize(l);
223  else
224  v.localize_to_one(l,root_pid);
225 
226  if (!to_one || my_comm->rank() == root_pid)
227  // Yes I really mean v.size()
228  for (libMesh::dof_id_type i=0; i<v.size(); i++)
229  LIBMESH_ASSERT_FP_EQUAL(2.*libMesh::libmesh_real(i),
230  libMesh::libmesh_real(l[i]),
232 
233  for (libMesh::dof_id_type n=first; n != last; n++)
234  {
235  const auto value = static_cast<libMesh::Number>(n);
236  v.insert (&value, std::vector<libMesh::numeric_index_type>({n}));
237  }
238  v.close();
239 
240  if (!to_one)
241  v.localize(l);
242  else
243  v.localize_to_one(l,root_pid);
244 
245  if (!to_one || my_comm->rank() == root_pid)
246  // Yes I really mean v.size()
247  for (libMesh::dof_id_type i=0; i<v.size(); i++)
248  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(i),
249  libMesh::libmesh_real(l[i]),
251  }
252  }
T libmesh_real(T a)
static constexpr Real TOLERANCE
processor_id_type rank() const
uint8_t processor_id_type
Definition: id_types.h:104
libMesh::Parallel::Communicator * my_comm
static const bool value
Definition: xdr_io.C:54
uint8_t dof_id_type
Definition: id_types.h:67

◆ LocalizeIndices()

void NumericVectorTest< LaspackVector< Number > >::LocalizeIndices ( )
inlineinherited

Definition at line 256 of file numeric_vector_test.h.

257  {
258  {
259  auto v_ptr = std::make_unique<Derived>(*my_comm, global_size, local_size);
260  Base & v = *v_ptr;
261 
262  // Let's try pulling the same number of entries from each processor
263  std::vector<libMesh::Number> values(block_size * my_comm->size());
264  std::vector<libMesh::dof_id_type> indices;
265  indices.reserve(block_size * my_comm->size());
266 
268  first = v.first_local_index(),
269  last = v.last_local_index();
270 
271  for (libMesh::dof_id_type n=first; n != last; n++)
272  v.set (n, static_cast<libMesh::Number>(n));
273  v.close();
274 
275  libMesh::dof_id_type end_index = 0;
276  for (libMesh::processor_id_type p=0; p<my_comm->size(); p++)
277  {
278  end_index += block_size + p;
279  for (unsigned int j = 0; j != block_size; ++j)
280  indices.push_back(end_index-j-1);
281  }
282 
283  v.localize(values, indices);
284 
285  end_index = 0;
286  for (libMesh::processor_id_type p=0; p<my_comm->size(); p++)
287  {
288  end_index += block_size + p;
289  for (unsigned int j = 0; j != block_size; ++j)
290  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(values[p*block_size+j]),
291  libMesh::libmesh_real(end_index-j-1),
293  }
294  }
295  }
T libmesh_real(T a)
static constexpr Real TOLERANCE
uint8_t processor_id_type
Definition: id_types.h:104
processor_id_type size() const
libMesh::Parallel::Communicator * my_comm
uint8_t dof_id_type
Definition: id_types.h:67

◆ Norms()

void NumericVectorTest< LaspackVector< Number > >::Norms ( )
inlineinherited

Definition at line 147 of file numeric_vector_test.h.

148  {
149  auto v_ptr = std::make_unique<Derived>(*my_comm, global_size, local_size);
150  Base & v = *v_ptr;
151 
153  first = v.first_local_index(),
154  last = v.last_local_index();
155 
156  for (libMesh::dof_id_type n=first; n != last; n++)
157  v.set (n, -static_cast<libMesh::Number>(n));
158  v.close();
159  for (libMesh::dof_id_type n=first; n != last; n++)
160  v.add (n, -static_cast<libMesh::Number>(n));
161  v.close();
162 
163  const libMesh::Real exact_l1 =
165  const libMesh::Real exact_l2 =
167  (2*global_size) *
168  (2*global_size-1) / 3);
169  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v.sum()), -exact_l1,
171  LIBMESH_ASSERT_FP_EQUAL(v.l1_norm(), exact_l1,
173  LIBMESH_ASSERT_FP_EQUAL(v.l2_norm(), exact_l2,
175  LIBMESH_ASSERT_FP_EQUAL(v.linfty_norm(), 2*(global_size-libMesh::Real(1)),
177 
178  auto u_ptr = std::make_unique<Derived>(*my_comm, global_size, local_size);
179  Base & u = *u_ptr;
180  for (libMesh::dof_id_type n=first; n != last; n++)
181  u.set (n, -static_cast<libMesh::Number>(n * n));
182  u.close();
183 
184  Derived diff_derived(*my_comm, global_size, local_size);
185  Base & diff = diff_derived;
186  diff = u;
187  diff -= v;
188  diff.close();
189 
190  // Use a relative tolerance here; the norms are O(1e5) when our
191  // processor count gets big enough, at which point O(1e-12) is
192  // testing for exact equality...
193  const auto diff_norm = diff.l2_norm();
194  const auto norm_diff = u.l2_norm_diff(v);
195  LIBMESH_ASSERT_FP_EQUAL(diff_norm, norm_diff,
196  (std::abs(diff_norm)+std::abs(norm_diff)) *
198  }
T libmesh_real(T a)
static constexpr Real TOLERANCE
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:53
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:57
libMesh::Parallel::Communicator * my_comm
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t dof_id_type
Definition: id_types.h:67

◆ Operations()

void NumericVectorTest< LaspackVector< Number > >::Operations ( )
inlineinherited

Definition at line 61 of file numeric_vector_test.h.

62  {
63  auto v_ptr = std::make_unique<Derived>(*my_comm, global_size, local_size);
64  Base & v = *v_ptr;
65 
67  first = v.first_local_index(),
68  last = v.last_local_index();
69 
70  for (libMesh::dof_id_type n=first; n != last; n++)
71  v.set (n, static_cast<libMesh::Number>(n+1));
72  v.close();
73 
74  auto v_clone = v.clone();
75  auto & vorig = *v_clone;
76 
77  v += v;
78 
79  for (libMesh::dof_id_type n=first; n != last; n++)
80  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v(n)),
81  libMesh::Real(2*n+2),
83 
84  v *= v;
85 
86  for (libMesh::dof_id_type n=first; n != last; n++)
87  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v(n)),
88  libMesh::Real(4*n*n+8*n+4),
90 
91  v -= vorig;
92 
93  for (libMesh::dof_id_type n=first; n != last; n++)
94  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v(n)),
95  libMesh::Real(4*n*n+7*n+3),
97 
98  v /= vorig;
99 
100  for (libMesh::dof_id_type n=first; n != last; n++)
101  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v(n)),
102  libMesh::Real(4*n+3),
104 
105  v.add(1);
106  for (libMesh::dof_id_type n=first; n != last; n++)
107  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v(n)),
108  libMesh::Real(4*n+4),
110 
111  v.add(2, vorig);
112  for (libMesh::dof_id_type n=first; n != last; n++)
113  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v(n)),
114  libMesh::Real(6*n+6),
116 
117  v.scale(1/libMesh::Real(3));
118  for (libMesh::dof_id_type n=first; n != last; n++)
119  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v(n)),
120  libMesh::Real(2*n+2),
122 
123  v = 4;
124  for (libMesh::dof_id_type n=first; n != last; n++)
125  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v(n)),
126  libMesh::Real(4),
128 
129  v = vorig;
130  for (libMesh::dof_id_type n=first; n != last; n++)
131  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v(n)),
132  libMesh::Real(n+1),
134 
135  v.reciprocal();
136  for (libMesh::dof_id_type n=first; n != last; n++)
137  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v(n)),
138  1/libMesh::Real(n+1),
140 
141  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(v.dot(vorig)),
144  }
T libmesh_real(T a)
static constexpr Real TOLERANCE
libMesh::Parallel::Communicator * my_comm
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t dof_id_type
Definition: id_types.h:67

◆ setUp()

void LaspackVectorTest::setUp ( )
inline

Definition at line 19 of file laspack_vector_test.C.

20  {
21  // Laspack doesn't support distributed parallel vectors, but we
22  // can build a serial vector on each processor
23  _managed_comm = std::make_unique<Parallel::Communicator>();
24 
25  // Base class communicator points to our managed communicator
26  my_comm = _managed_comm.get();
27 
29  }
libMesh::Parallel::Communicator * my_comm
std::unique_ptr< Parallel::Communicator > _managed_comm

◆ tearDown()

void LaspackVectorTest::tearDown ( )
inline

Definition at line 31 of file laspack_vector_test.C.

31 {}

◆ testLocalize()

void NumericVectorTest< LaspackVector< Number > >::testLocalize ( )
inlineinherited

Definition at line 297 of file numeric_vector_test.h.

298  {
299  LOG_UNIT_TEST;
300 
301  Localize<DerivedClass,DerivedClass>();
302  }

◆ testLocalizeBase()

void NumericVectorTest< LaspackVector< Number > >::testLocalizeBase ( )
inlineinherited

Definition at line 304 of file numeric_vector_test.h.

305  {
306  LOG_UNIT_TEST;
307 
308  Localize<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
309  }

◆ testLocalizeIndices()

void NumericVectorTest< LaspackVector< Number > >::testLocalizeIndices ( )
inlineinherited

Definition at line 325 of file numeric_vector_test.h.

326  {
327  LOG_UNIT_TEST;
328 
329  LocalizeIndices<DerivedClass,DerivedClass >();
330  }

◆ testLocalizeIndicesBase()

void NumericVectorTest< LaspackVector< Number > >::testLocalizeIndicesBase ( )
inlineinherited

Definition at line 332 of file numeric_vector_test.h.

333  {
334  LOG_UNIT_TEST;
335 
336  LocalizeIndices<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
337  }

◆ testLocalizeToOne()

void NumericVectorTest< LaspackVector< Number > >::testLocalizeToOne ( )
inlineinherited

Definition at line 311 of file numeric_vector_test.h.

312  {
313  LOG_UNIT_TEST;
314 
315  Localize<DerivedClass,DerivedClass >(true);
316  }

◆ testLocalizeToOneBase()

void NumericVectorTest< LaspackVector< Number > >::testLocalizeToOneBase ( )
inlineinherited

Definition at line 318 of file numeric_vector_test.h.

319  {
320  LOG_UNIT_TEST;
321 
322  Localize<libMesh::NumericVector<libMesh::Number>,DerivedClass>(true);
323  }

◆ testNorms()

void NumericVectorTest< LaspackVector< Number > >::testNorms ( )
inlineinherited

Definition at line 339 of file numeric_vector_test.h.

340  {
341  LOG_UNIT_TEST;
342 
343  Norms<DerivedClass,DerivedClass >();
344  }

◆ testNormsBase()

void NumericVectorTest< LaspackVector< Number > >::testNormsBase ( )
inlineinherited

Definition at line 346 of file numeric_vector_test.h.

347  {
348  LOG_UNIT_TEST;
349 
350  Norms<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
351  }

◆ testOperations()

void NumericVectorTest< LaspackVector< Number > >::testOperations ( )
inlineinherited

Definition at line 353 of file numeric_vector_test.h.

354  {
355  LOG_UNIT_TEST;
356 
357  Operations<DerivedClass,DerivedClass >();
358  }

◆ testOperationsBase()

void NumericVectorTest< LaspackVector< Number > >::testOperationsBase ( )
inlineinherited

Definition at line 360 of file numeric_vector_test.h.

361  {
362  LOG_UNIT_TEST;
363 
364  Operations<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
365  }

Member Data Documentation

◆ _managed_comm

std::unique_ptr<Parallel::Communicator> LaspackVectorTest::_managed_comm
private

Definition at line 16 of file laspack_vector_test.C.

◆ block_size

unsigned int NumericVectorTest< LaspackVector< Number > >::block_size
protectedinherited

Definition at line 35 of file numeric_vector_test.h.

◆ global_size

unsigned int NumericVectorTest< LaspackVector< Number > >::global_size
protectedinherited

Definition at line 35 of file numeric_vector_test.h.

◆ libmesh_suite_name

std::string NumericVectorTest< LaspackVector< Number > >::libmesh_suite_name
protectedinherited

Definition at line 33 of file numeric_vector_test.h.

◆ local_size

unsigned int NumericVectorTest< LaspackVector< Number > >::local_size
protectedinherited

Definition at line 35 of file numeric_vector_test.h.

◆ my_comm

libMesh::Parallel::Communicator* NumericVectorTest< LaspackVector< Number > >::my_comm
protectedinherited

Definition at line 31 of file numeric_vector_test.h.


The documentation for this class was generated from the following file: