Skip to content

Commit 3d9bab8

Browse files
authored
Merge pull request #3494 from zachmprince/petsc_vector
Moving _values_manually_retrieved to after _get_array in PetscVector
2 parents 7523403 + 95a66d9 commit 3d9bab8

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

include/numerics/petsc_vector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,8 @@ template <typename T>
11101110
inline
11111111
PetscScalar * PetscVector<T>::get_array()
11121112
{
1113-
_values_manually_retrieved = true;
11141113
_get_array(false);
1114+
_values_manually_retrieved = true;
11151115

11161116
return _values;
11171117
}
@@ -1121,8 +1121,8 @@ template <typename T>
11211121
inline
11221122
const PetscScalar * PetscVector<T>::get_array_read() const
11231123
{
1124-
_values_manually_retrieved = true;
11251124
_get_array(true);
1125+
_values_manually_retrieved = true;
11261126

11271127
return _read_only_values;
11281128
}

tests/numerics/petsc_vector_test.C

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ public:
7777
CPPUNIT_ASSERT_EQUAL((intptr_t)read_only_values, (intptr_t)values);
7878

7979
v.restore_array();
80+
81+
// Test to make sure we can get arrays after other operators
82+
for (unsigned int i = 0; i < local_size; i++)
83+
v.set(my_offset + i, i * 2.0);
84+
v.close();
85+
for (unsigned int i = 0; i < local_size; i++)
86+
LIBMESH_ASSERT_FP_EQUAL(i * 2.0, std::abs(v(my_offset + i)), TOLERANCE * TOLERANCE);
87+
values = v.get_array();
88+
read_only_values = v.get_array_read();
89+
for (unsigned int i = 0; i < local_size; i++)
90+
{
91+
LIBMESH_ASSERT_FP_EQUAL(i * 2.0, std::abs(values[i]), TOLERANCE * TOLERANCE);
92+
LIBMESH_ASSERT_FP_EQUAL(i * 2.0, std::abs(read_only_values[i]), TOLERANCE * TOLERANCE);
93+
}
94+
v.restore_array();
8095
}
8196

8297
void testPetscOperations()

0 commit comments

Comments
 (0)