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

Public Member Functions

 CPPUNIT_TEST_SUITE (PetscVectorTest)
 
NUMERICVECTORTEST CPPUNIT_TEST (testGetArray)
 
 CPPUNIT_TEST_SUITE_END ()
 
void testGetArray ()
 
void setUp ()
 
void tearDown ()
 
void Localize (bool to_one=false)
 
void testLocalize ()
 
void testLocalizeBase ()
 
void testLocalizeToOne ()
 
void testLocalizeToOneBase ()
 

Protected Attributes

libMesh::Parallel::Communicatormy_comm
 

Detailed Description

Definition at line 24 of file petsc_vector_test.C.

Member Function Documentation

NUMERICVECTORTEST PetscVectorTest::CPPUNIT_TEST ( testGetArray  )
PetscVectorTest::CPPUNIT_TEST_SUITE ( PetscVectorTest  )
PetscVectorTest::CPPUNIT_TEST_SUITE_END ( )
void NumericVectorTest< PetscVector< Number > >::Localize ( bool  to_one = false)
inherited

Definition at line 42 of file numeric_vector_test.h.

43  {
44  const libMesh::processor_id_type root_pid = 0;
45  unsigned int block_size = 10;
46 
47  // a different size on each processor.
48  unsigned int local_size = block_size +
49  static_cast<unsigned int>(my_comm->rank());
50  unsigned int global_size = 0;
51 
52  for (libMesh::processor_id_type p=0; p<my_comm->size(); p++)
53  global_size += (block_size + static_cast<unsigned int>(p));
54 
55  {
56  libMesh::UniquePtr<Base> v_ptr(new Derived(*my_comm, global_size, local_size));
57  Base & v = *v_ptr;
58  std::vector<libMesh::Number> l(global_size);
59 
61  first = v.first_local_index(),
62  last = v.last_local_index();
63 
64  for (libMesh::dof_id_type n=first; n != last; n++)
65  v.set (n, static_cast<libMesh::Number>(n));
66  v.close();
67 
68  if (!to_one)
69  v.localize(l);
70  else
71  v.localize_to_one(l,root_pid);
72 
73  if (!to_one || my_comm->rank() == root_pid)
74  // Yes I really mean v.size()
75  for (libMesh::dof_id_type i=0; i<v.size(); i++)
76  CPPUNIT_ASSERT_DOUBLES_EQUAL(libMesh::libmesh_real(i),
79  }
80  }
T libmesh_real(T a)
unsigned int size() const
Definition: parallel.h:726
uint8_t processor_id_type
Definition: id_types.h:99
static const Real TOLERANCE
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
libMesh::Parallel::Communicator * my_comm
unsigned int rank() const
Definition: parallel.h:724
uint8_t dof_id_type
Definition: id_types.h:64
void NumericVectorTest< PetscVector< Number > >::setUp ( )
inherited

Definition at line 30 of file numeric_vector_test.h.

31  {
32  // By default we'll use the whole communicator in parallel;
33  // Serial-only NumericVector subclasses will need to override
34  // this.
36  }
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
libMesh::Parallel::Communicator * my_comm
void NumericVectorTest< PetscVector< Number > >::tearDown ( )
inherited

Definition at line 38 of file numeric_vector_test.h.

39  {}
void PetscVectorTest::testGetArray ( )

Definition at line 34 of file petsc_vector_test.C.

References std::abs(), CPPUNIT_TEST_SUITE_REGISTRATION(), and libMesh::TOLERANCE.

35  {
36  unsigned int block_size = 2;
37 
38  // a different size on each processor.
39  unsigned int local_size = block_size;
40  unsigned int global_size = 0;
41 
42  for (libMesh::processor_id_type p=0; p<my_comm->size(); p++)
43  global_size += (block_size + static_cast<unsigned int>(p));
44 
45  PetscVector<Number> v(*my_comm, global_size, local_size);
46 
47  PetscScalar * values = v.get_array();
48 
49  for (unsigned int i=0; i<local_size; i++)
50  values[i] = i;
51 
52  v.restore_array();
53 
54  v.close();
55 
56  // Check the values through the interface
57  for (unsigned int i=0; i<local_size; i++)
58  CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(v(my_comm->rank()*2 + i)), i, TOLERANCE*TOLERANCE);
59 
60  // Check that we can see the same thing with get_array_read
61  const PetscScalar * read_only_values = v.get_array_read();
62 
63  for (unsigned int i=0; i<local_size; i++)
64  CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(read_only_values[i]), i, TOLERANCE*TOLERANCE);
65 
66  v.restore_array();
67 
68  // Test getting a read only array after getting a writable array
69  values = v.get_array();
70  read_only_values = v.get_array_read();
71  CPPUNIT_ASSERT_EQUAL((intptr_t)read_only_values, (intptr_t)values);
72 
73  v.restore_array();
74  }
double abs(double a)
unsigned int size() const
Definition: parallel.h:726
uint8_t processor_id_type
Definition: id_types.h:99
static const Real TOLERANCE
libMesh::Parallel::Communicator * my_comm
unsigned int rank() const
Definition: parallel.h:724
void NumericVectorTest< PetscVector< Number > >::testLocalize ( )
inherited

Definition at line 82 of file numeric_vector_test.h.

83  {
84  Localize<DerivedClass,DerivedClass>();
85  }
void NumericVectorTest< PetscVector< Number > >::testLocalizeBase ( )
inherited

Definition at line 87 of file numeric_vector_test.h.

88  {
89  Localize<libMesh::NumericVector<libMesh::Number>,DerivedClass>();
90  }
void NumericVectorTest< PetscVector< Number > >::testLocalizeToOne ( )
inherited

Definition at line 92 of file numeric_vector_test.h.

93  {
94  Localize<DerivedClass,DerivedClass >(true);
95  }
void NumericVectorTest< PetscVector< Number > >::testLocalizeToOneBase ( )
inherited

Definition at line 97 of file numeric_vector_test.h.

98  {
99  Localize<libMesh::NumericVector<libMesh::Number>,DerivedClass>(true);
100  }

Member Data Documentation

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

Definition at line 27 of file numeric_vector_test.h.


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