1 #include <libmesh/petsc_vector.h> 3 #ifdef LIBMESH_HAVE_PETSC 15 this->libmesh_suite_name =
"NumericVectorTest";
17 this->libmesh_suite_name =
"PetscVectorTest";
24 CPPUNIT_TEST( testGetArray );
26 CPPUNIT_TEST( testPetscOperations );
28 CPPUNIT_TEST_SUITE_END();
34 unsigned int min_block_size = 2;
37 unsigned int my_p = my_comm->rank();
38 unsigned int local_size = (min_block_size + my_p);
39 unsigned int global_size = 0;
40 unsigned int my_offset = 0;
44 const unsigned int p_size =
45 (min_block_size +
static_cast<unsigned int>(p));
46 global_size += p_size;
55 for (
unsigned int i=0; i<local_size; i++)
63 for (
unsigned int i=0; i<local_size; i++)
69 for (
unsigned int i=0; i<local_size; i++)
77 CPPUNIT_ASSERT_EQUAL(read_only_values, const_cast<const PetscScalar *>(values));
82 for (
unsigned int i = 0; i < local_size; i++)
83 v.
set(my_offset + i, i * 2.0);
85 for (
unsigned int i = 0; i < local_size; i++)
89 for (
unsigned int i = 0; i < local_size; i++)
92 LIBMESH_ASSERT_FP_EQUAL(i * 2.0, std::abs(read_only_values[i]),
TOLERANCE *
TOLERANCE);
100 auto v2 = v1.
clone();
108 v1.
set (n, static_cast<libMesh::Number>(n+1));
109 v2->set (n, static_cast<libMesh::Number>(2*(n+1)));
114 auto v_working_ptr = v1.
clone();
115 auto & v_working = *v_working_ptr;
117 v_working.pointwise_mult(v1, *v2);
120 LIBMESH_ASSERT_NUMBERS_EQUAL
124 v_working.pointwise_divide(v1, *v2);
127 LIBMESH_ASSERT_NUMBERS_EQUAL
136 #endif // #ifdef LIBMESH_HAVE_PETSC This class provides a nice interface to PETSc's Vec object.
static constexpr Real TOLERANCE
virtual numeric_index_type first_local_index() const override
The libMesh namespace provides an interface to certain functionality in the library.
uint8_t processor_id_type
CPPUNIT_TEST_SUITE_REGISTRATION(PetscVectorTest)
bool summarized_logs_enabled()
const PetscScalar * get_array_read() const
Get read only access to the raw PETSc Vector data array.
virtual numeric_index_type last_local_index() const override
void restore_array()
Restore the data array.
virtual void set(const numeric_index_type i, const T value) override
Sets v(i) = value.
virtual std::unique_ptr< NumericVector< T > > clone() const override
libMesh::PerfLog * unitlog
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void testPetscOperations()
PetscScalar * get_array()
Get read/write access to the raw PETSc Vector data array.
virtual void close() override
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...