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

Public Member Functions

void setUp ()
 
void tearDown ()
 
 CPPUNIT_TEST_SUITE (EigenSparseVectorTest)
 
NUMERICVECTORTEST CPPUNIT_TEST_SUITE_END ()
 
void Localize (bool to_one=false)
 
void LocalizeIndices ()
 
void testLocalize ()
 
void testLocalizeBase ()
 
void testLocalizeToOne ()
 
void testLocalizeToOneBase ()
 
void testLocalizeIndices ()
 
void testLocalizeIndicesBase ()
 

Protected Attributes

libMesh::Parallel::Communicator * my_comm
 

Detailed Description

Definition at line 10 of file eigen_sparse_vector_test.C.

Member Function Documentation

◆ CPPUNIT_TEST_SUITE()

EigenSparseVectorTest::CPPUNIT_TEST_SUITE ( EigenSparseVectorTest  )

◆ CPPUNIT_TEST_SUITE_END()

NUMERICVECTORTEST EigenSparseVectorTest::CPPUNIT_TEST_SUITE_END ( )

◆ Localize()

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

Definition at line 45 of file numeric_vector_test.h.

46  {
47  const libMesh::processor_id_type root_pid = 0;
48  unsigned int block_size = 10;
49 
50  // a different size on each processor.
51  unsigned int local_size = block_size +
52  static_cast<unsigned int>(my_comm->rank());
53  unsigned int global_size = 0;
54 
55  for (libMesh::processor_id_type p=0; p<my_comm->size(); p++)
56  global_size += (block_size + static_cast<unsigned int>(p));
57 
58  {
59  auto v_ptr = libmesh_make_unique<Derived>(*my_comm, global_size, local_size);
60  Base & v = *v_ptr;
61  std::vector<libMesh::Number> l(global_size);
62 
64  first = v.first_local_index(),
65  last = v.last_local_index();
66 
67  for (libMesh::dof_id_type n=first; n != last; n++)
68  v.set (n, static_cast<libMesh::Number>(n));
69  v.close();
70 
71  if (!to_one)
72  v.localize(l);
73  else
74  v.localize_to_one(l,root_pid);
75 
76  if (!to_one || my_comm->rank() == root_pid)
77  // Yes I really mean v.size()
78  for (libMesh::dof_id_type i=0; i<v.size(); i++)
79  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(i),
82  }
83  }

◆ LocalizeIndices()

void NumericVectorTest< EigenSparseVector< libMesh::Number > >::LocalizeIndices ( )
inlineinherited

Definition at line 87 of file numeric_vector_test.h.

88  {
89  unsigned int block_size = 10;
90 
91  // a different size on each processor.
92  unsigned int local_size = block_size +
93  static_cast<unsigned int>(my_comm->rank());
94  unsigned int global_size = 0;
95 
96  for (libMesh::processor_id_type p=0; p<my_comm->size(); p++)
97  global_size += (block_size + static_cast<unsigned int>(p));
98 
99  {
100  auto v_ptr = libmesh_make_unique<Derived>(*my_comm, global_size, local_size);
101  Base & v = *v_ptr;
102 
103  // Let's try pulling the same number of entries from each processor
104  std::vector<libMesh::Number> values(block_size * my_comm->size());
105  std::vector<libMesh::dof_id_type> indices;
106  indices.reserve(block_size * my_comm->size());
107 
109  first = v.first_local_index(),
110  last = v.last_local_index();
111 
112  for (libMesh::dof_id_type n=first; n != last; n++)
113  v.set (n, static_cast<libMesh::Number>(n));
114  v.close();
115 
116  libMesh::dof_id_type end_index = 0;
117  for (libMesh::processor_id_type p=0; p<my_comm->size(); p++)
118  {
119  end_index += block_size + p;
120  for (unsigned int j = 0; j != block_size; ++j)
121  indices.push_back(end_index-j-1);
122  }
123 
124  v.localize(values, indices);
125 
126  end_index = 0;
127  for (libMesh::processor_id_type p=0; p<my_comm->size(); p++)
128  {
129  end_index += block_size + p;
130  for (unsigned int j = 0; j != block_size; ++j)
131  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(values[p*block_size+j]),
132  libMesh::libmesh_real(end_index-j-1),
134  }
135  }
136  }

◆ setUp()

void EigenSparseVectorTest::setUp ( )
inline

Definition at line 12 of file eigen_sparse_vector_test.C.

13  {
14  // Eigen doesn't support distributed parallel vectors, but we can
15  // build a serial vector on each processor
16  my_comm = new Parallel::Communicator();
17  }

◆ tearDown()

void EigenSparseVectorTest::tearDown ( )
inline

Definition at line 19 of file eigen_sparse_vector_test.C.

20  {
21  delete my_comm;
22  }

◆ testLocalize()

void NumericVectorTest< EigenSparseVector< libMesh::Number > >::testLocalize ( )
inlineinherited

Definition at line 138 of file numeric_vector_test.h.

139  {
140  Localize<DerivedClass,DerivedClass>();
141  }

◆ testLocalizeBase()

void NumericVectorTest< EigenSparseVector< libMesh::Number > >::testLocalizeBase ( )
inlineinherited

Definition at line 143 of file numeric_vector_test.h.

144  {
145  Localize<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
146  }

◆ testLocalizeIndices()

void NumericVectorTest< EigenSparseVector< libMesh::Number > >::testLocalizeIndices ( )
inlineinherited

Definition at line 158 of file numeric_vector_test.h.

159  {
160  LocalizeIndices<DerivedClass,DerivedClass >();
161  }

◆ testLocalizeIndicesBase()

void NumericVectorTest< EigenSparseVector< libMesh::Number > >::testLocalizeIndicesBase ( )
inlineinherited

Definition at line 163 of file numeric_vector_test.h.

164  {
165  LocalizeIndices<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
166  }

◆ testLocalizeToOne()

void NumericVectorTest< EigenSparseVector< libMesh::Number > >::testLocalizeToOne ( )
inlineinherited

Definition at line 148 of file numeric_vector_test.h.

149  {
150  Localize<DerivedClass,DerivedClass >(true);
151  }

◆ testLocalizeToOneBase()

void NumericVectorTest< EigenSparseVector< libMesh::Number > >::testLocalizeToOneBase ( )
inlineinherited

Definition at line 153 of file numeric_vector_test.h.

154  {
155  Localize<libMesh::NumericVector<libMesh::Number>,DerivedClass>(true);
156  }

Member Data Documentation

◆ my_comm

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

Definition at line 30 of file numeric_vector_test.h.


The documentation for this class was generated from the following file:
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::processor_id_type
uint8_t processor_id_type
Definition: id_types.h:104
NumericVectorTest< EigenSparseVector< libMesh::Number > >::my_comm
libMesh::Parallel::Communicator * my_comm
Definition: numeric_vector_test.h:30