11 std::vector<double>& data,
22 "data.size() < N, " + std::to_string(data.size()) +
23 " < " + std::to_string(N));
26 VecGetArrayRead(x, &x_ref);
28 std::copy(x_ref, x_ref + N, data.begin());
30 VecRestoreArrayRead(x, &x_ref);
37 Vec x, std::vector<double>& data,
size_t N,
bool resize_STL )
46 "data.size() != N, " + std::to_string(data.size()) +
47 " < " + std::to_string(N));
50 const double* x_ref = info.x_localized_raw;
52 std::copy(x_ref, x_ref + N, data.begin());
62 VecGetArray(x, &x_ref);
64 std::copy(data.begin(), data.end(), x_ref);
66 VecRestoreArray(x, &x_ref);
72 const double* y_data = y.
Data();
74 VecGetArray(x, &x_data);
75 std::copy(y_data, y_data + y.
LocalSize(), x_data);
76 VecRestoreArray(x, &x_data);
82 Vec x,
const std::vector<int64_t>& global_indices, std::vector<double>& data)
85 size_t N = global_indices.size();
86 std::vector<int64_t> local_indices(N, 0);
88 for (
auto val : global_indices)
90 local_indices[counter] = counter;
96 VecCreateSeq(PETSC_COMM_SELF, global_indices.size() + 1, &local_vec);
97 VecSet(local_vec, 0.0);
103 PETSC_COMM_SELF, N, global_indices.data(), PETSC_COPY_VALUES, &global_set);
105 PETSC_COMM_SELF, N, local_indices.data(), PETSC_COPY_VALUES, &local_set);
107 VecScatterCreate(x, global_set, local_vec, local_set, &scat);
108 VecScatterBegin(scat, x, local_vec, INSERT_VALUES, SCATTER_FORWARD);
109 VecScatterEnd(scat, x, local_vec, INSERT_VALUES, SCATTER_FORWARD);
115 VecGetArrayRead(local_vec, &x_ref);
117 std::copy(x_ref, x_ref + N, data.begin());
119 VecRestoreArrayRead(x, &x_ref);
122 ISDestroy(&global_set);
123 ISDestroy(&local_set);
125 VecDestroy(&local_vec);
136 VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
137 VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
146 VecGhostGetLocalForm(x, &x_localized);
147 const double* x_localized_raw;
149 VecGetArrayRead(x_localized, &x_localized_raw);
165 VecGhostRestoreLocalForm(x, &local_data.
x_localized);
#define ChiLogicalErrorIf(condition, message)
virtual double * Data()=0
uint64_t LocalSize() const
Return the size of the locally owned portion of the parallel vector.
void RestoreGhostVectorLocalViewRead(Vec x, GhostVecLocalRaw &local_data)
GhostVecLocalRaw GetGhostVectorLocalViewRead(Vec x)
void CopyVecToSTLvectorWithGhosts(Vec x, std::vector< double > &data, size_t N, bool resize_STL=true)
void CopyGlobalVecToSTLvector(Vec x, const std::vector< int64_t > &global_indices, std::vector< double > &data)
void CopyParallelVectorToVec(const ParallelVector &y, Vec x)
void CopyVecToSTLvector(Vec x, std::vector< double > &data, size_t N, bool resize_STL=true)
void CommunicateGhostEntries(Vec x)
void CopySTLvectorToVec(const std::vector< double > &data, Vec x, size_t N)