libMesh
Public Member Functions | Protected Attributes | List of all members
NumericVectorTest< DerivedClass > Class Template Reference

#include <numeric_vector_test.h>

Inheritance diagram for NumericVectorTest< DerivedClass >:
[legend]

Public Member Functions

void setUp ()
 
void tearDown ()
 
template<class Base , class Derived >
void Localize (bool to_one=false)
 
template<class Base , class Derived >
void LocalizeIndices ()
 
void testLocalize ()
 
void testLocalizeBase ()
 
void testLocalizeToOne ()
 
void testLocalizeToOneBase ()
 
void testLocalizeIndices ()
 
void testLocalizeIndicesBase ()
 

Protected Attributes

libMesh::Parallel::Communicator * my_comm
 

Detailed Description

template<class DerivedClass>
class NumericVectorTest< DerivedClass >

Definition at line 27 of file numeric_vector_test.h.

Member Function Documentation

◆ Localize()

template<class DerivedClass>
template<class Base , class Derived >
void NumericVectorTest< DerivedClass >::Localize ( bool  to_one = false)
inline

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()

template<class DerivedClass>
template<class Base , class Derived >
void NumericVectorTest< DerivedClass >::LocalizeIndices ( )
inline

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()

template<class DerivedClass>
void NumericVectorTest< DerivedClass >::setUp ( )
inline

Definition at line 33 of file numeric_vector_test.h.

34  {
35  // By default we'll use the whole communicator in parallel;
36  // Serial-only NumericVector subclasses will need to override
37  // this.
39  }

◆ tearDown()

template<class DerivedClass>
void NumericVectorTest< DerivedClass >::tearDown ( )
inline

Definition at line 41 of file numeric_vector_test.h.

42  {}

◆ testLocalize()

template<class DerivedClass>
void NumericVectorTest< DerivedClass >::testLocalize ( )
inline

Definition at line 138 of file numeric_vector_test.h.

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

◆ testLocalizeBase()

template<class DerivedClass>
void NumericVectorTest< DerivedClass >::testLocalizeBase ( )
inline

Definition at line 143 of file numeric_vector_test.h.

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

◆ testLocalizeIndices()

template<class DerivedClass>
void NumericVectorTest< DerivedClass >::testLocalizeIndices ( )
inline

Definition at line 158 of file numeric_vector_test.h.

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

◆ testLocalizeIndicesBase()

template<class DerivedClass>
void NumericVectorTest< DerivedClass >::testLocalizeIndicesBase ( )
inline

Definition at line 163 of file numeric_vector_test.h.

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

◆ testLocalizeToOne()

template<class DerivedClass>
void NumericVectorTest< DerivedClass >::testLocalizeToOne ( )
inline

Definition at line 148 of file numeric_vector_test.h.

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

◆ testLocalizeToOneBase()

template<class DerivedClass>
void NumericVectorTest< DerivedClass >::testLocalizeToOneBase ( )
inline

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

template<class DerivedClass>
libMesh::Parallel::Communicator* NumericVectorTest< DerivedClass >::my_comm
protected

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
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::processor_id_type
uint8_t processor_id_type
Definition: id_types.h:104
NumericVectorTest::my_comm
libMesh::Parallel::Communicator * my_comm
Definition: numeric_vector_test.h:30