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::Communicatormy_comm
 

Detailed Description

template<class DerivedClass>
class NumericVectorTest< DerivedClass >

Definition at line 30 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)

Definition at line 48 of file numeric_vector_test.h.

References libMesh::libmesh_real(), NumericVectorTest< DerivedClass >::my_comm, libMesh::Parallel::Communicator::rank(), libMesh::Parallel::Communicator::size(), and libMesh::TOLERANCE.

49  {
50  const libMesh::processor_id_type root_pid = 0;
51  unsigned int block_size = 10;
52 
53  // a different size on each processor.
54  unsigned int local_size = block_size +
55  static_cast<unsigned int>(my_comm->rank());
56  unsigned int global_size = 0;
57 
58  for (libMesh::processor_id_type p=0; p<my_comm->size(); p++)
59  global_size += (block_size + static_cast<unsigned int>(p));
60 
61  {
62  auto v_ptr = libmesh_make_unique<Derived>(*my_comm, global_size, local_size);
63  Base & v = *v_ptr;
64  std::vector<libMesh::Number> l(global_size);
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));
72  v.close();
73 
74  if (!to_one)
75  v.localize(l);
76  else
77  v.localize_to_one(l,root_pid);
78 
79  if (!to_one || my_comm->rank() == root_pid)
80  // Yes I really mean v.size()
81  for (libMesh::dof_id_type i=0; i<v.size(); i++)
82  CPPUNIT_ASSERT_DOUBLES_EQUAL(libMesh::libmesh_real(i),
85  }
86  }
T libmesh_real(T a)
processor_id_type size() const
Definition: communicator.h:175
uint8_t processor_id_type
Definition: id_types.h:99
static const Real TOLERANCE
processor_id_type rank() const
Definition: communicator.h:173
libMesh::Parallel::Communicator * my_comm
uint8_t dof_id_type
Definition: id_types.h:64

◆ LocalizeIndices()

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

Definition at line 90 of file numeric_vector_test.h.

References libMesh::libmesh_real(), NumericVectorTest< DerivedClass >::my_comm, libMesh::Parallel::Communicator::rank(), libMesh::Parallel::Communicator::size(), and libMesh::TOLERANCE.

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

◆ setUp()

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

Definition at line 36 of file numeric_vector_test.h.

References NumericVectorTest< DerivedClass >::my_comm, and TestCommWorld.

37  {
38  // By default we'll use the whole communicator in parallel;
39  // Serial-only NumericVector subclasses will need to override
40  // this.
42  }
libMesh::Parallel::Communicator * TestCommWorld
libMesh::Parallel::Communicator * my_comm

◆ tearDown()

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

Definition at line 44 of file numeric_vector_test.h.

45  {}

◆ testLocalize()

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

Definition at line 141 of file numeric_vector_test.h.

142  {
143  Localize<DerivedClass,DerivedClass>();
144  }

◆ testLocalizeBase()

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

Definition at line 146 of file numeric_vector_test.h.

147  {
148  Localize<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
149  }

◆ testLocalizeIndices()

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

Definition at line 161 of file numeric_vector_test.h.

162  {
163  LocalizeIndices<DerivedClass,DerivedClass >();
164  }

◆ testLocalizeIndicesBase()

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

Definition at line 166 of file numeric_vector_test.h.

167  {
168  LocalizeIndices<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
169  }

◆ testLocalizeToOne()

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

Definition at line 151 of file numeric_vector_test.h.

152  {
153  Localize<DerivedClass,DerivedClass >(true);
154  }

◆ testLocalizeToOneBase()

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

Definition at line 156 of file numeric_vector_test.h.

157  {
158  Localize<libMesh::NumericVector<libMesh::Number>,DerivedClass>(true);
159  }

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: