Skip to content
Snippets Groups Projects
Commit 7caa07de authored by wenqing's avatar wenqing
Browse files

[PETSc] Some minor changes according to the comments by Diam and Tom

parent 049da77e
No related branches found
No related tags found
No related merge requests found
...@@ -213,7 +213,7 @@ namespace LinAlg ...@@ -213,7 +213,7 @@ namespace LinAlg
/** /**
Set local accessible vector in order to get entries. Call this Set local accessible vector in order to get entries. Call this
before call operator[] or get(...) of x. before call operator[] or get(...) of x.
The function only has computation if DDC is appied, The function only has computation if DDC is enabled,
e.g. parallel computing. Up to now, Eigen vector is not used for e.g. parallel computing. Up to now, Eigen vector is not used for
global vectors in parallel computing. Therefore this function is global vectors in parallel computing. Therefore this function is
empty in the current status. empty in the current status.
......
...@@ -66,8 +66,8 @@ PETScVector::PETScVector(const PetscInt vec_size, ...@@ -66,8 +66,8 @@ PETScVector::PETScVector(const PetscInt vec_size,
config(); config();
for (PetscInt i=0; i<nghosts; i++) for (PetscInt i=0; i<nghosts; i++)
_global_ids2local_ids_ghost.insert _global_ids2local_ids_ghost.emplace(ghost_ids[i],
(std::make_pair(ghost_ids[i], _size_loc + i)); _size_loc + i);
} }
PETScVector::PETScVector(const PETScVector &existing_vec, const bool deep_copy) PETScVector::PETScVector(const PETScVector &existing_vec, const bool deep_copy)
...@@ -146,10 +146,12 @@ void PETScVector::getGlobalVector(std::vector<PetscScalar>& u) const ...@@ -146,10 +146,12 @@ void PETScVector::getGlobalVector(std::vector<PetscScalar>& u) const
PetscMemoryGetCurrentUsage(&mem1); PetscMemoryGetCurrentUsage(&mem1);
#endif #endif
assert(u.size() == _size);
PetscScalar *xp = nullptr; PetscScalar *xp = nullptr;
VecGetArray(_v, &xp); VecGetArray(_v, &xp);
gatherLocalVectors(xp, &u[0]); gatherLocalVectors(xp, u.data());
//This following line may be needed late on //This following line may be needed late on
// for a communication load balance: // for a communication load balance:
...@@ -166,17 +168,17 @@ void PETScVector::getGlobalVector(std::vector<PetscScalar>& u) const ...@@ -166,17 +168,17 @@ void PETScVector::getGlobalVector(std::vector<PetscScalar>& u) const
void PETScVector::setLocalAccessibleVector() const void PETScVector::setLocalAccessibleVector() const
{ {
if (_entry_array.size() == 0) if (_entry_array.empty())
{ {
const PetscInt array_size const PetscInt array_size
= _global_ids2local_ids_ghost.size() > 0 ? = _global_ids2local_ids_ghost.size() > 0 ?
_size_loc + _size_ghosts: _size; _size_loc + _size_ghosts: _size;
_entry_array.resize(array_size); _entry_array.resize(array_size);
} }
if (_global_ids2local_ids_ghost.size() > 0) if ( !_global_ids2local_ids_ghost.empty() )
{ {
double* loc_x = getLocalVector(); PetscScalar* loc_x = getLocalVector();
std::copy_n(loc_x, _size_loc + _size_ghosts, std::copy_n(loc_x, _size_loc + _size_ghosts,
_entry_array.begin()); _entry_array.begin());
restoreArray(loc_x); restoreArray(loc_x);
...@@ -185,11 +187,11 @@ void PETScVector::setLocalAccessibleVector() const ...@@ -185,11 +187,11 @@ void PETScVector::setLocalAccessibleVector() const
getGlobalVector(_entry_array); getGlobalVector(_entry_array);
} }
void PETScVector::copyValues(std::vector<double>& u) const void PETScVector::copyValues(std::vector<PetscScalar>& u) const
{ {
assert(u.size() == (std::size_t) (getLocalSize() + getGhostSize())); assert(u.size() == (std::size_t) (getLocalSize() + getGhostSize()));
double* loc_x = getLocalVector(); PetscScalar* loc_x = getLocalVector();
std::copy_n(loc_x, getLocalSize() + getGhostSize(), u.begin()); std::copy_n(loc_x, getLocalSize() + getGhostSize(), u.begin());
restoreArray(loc_x); restoreArray(loc_x);
} }
...@@ -207,9 +209,9 @@ PetscScalar PETScVector::get(const PetscInt idx) const ...@@ -207,9 +209,9 @@ PetscScalar PETScVector::get(const PetscInt idx) const
} }
std::vector<double> PETScVector::get(std::vector<IndexType> const& indices) const std::vector<PetscScalar> PETScVector::get(std::vector<IndexType> const& indices) const
{ {
std::vector<double> local_x(indices.size()); std::vector<PetscScalar> local_x(indices.size());
// If VecGetValues can get values from different processors, // If VecGetValues can get values from different processors,
// use VecGetValues(_v, indices.size(), indices.data(), // use VecGetValues(_v, indices.size(), indices.data(),
// local_x.data()); // local_x.data());
......
...@@ -170,11 +170,11 @@ class PETScVector ...@@ -170,11 +170,11 @@ class PETScVector
/// Get several entries. setLocalAccessibleVector() must be /// Get several entries. setLocalAccessibleVector() must be
/// called beforehand. /// called beforehand.
std::vector<double> get(std::vector<IndexType> const& indices) const; std::vector<PetscScalar> get(std::vector<IndexType> const& indices) const;
/// Get the value of an entry by [] operator. /// Get the value of an entry by [] operator.
/// setLocalAccessibleVector() must be called beforehand. /// setLocalAccessibleVector() must be called beforehand.
double operator[] (PetscInt idx) const PetscScalar operator[] (PetscInt idx) const
{ {
return get(idx); return get(idx);
} }
...@@ -207,7 +207,7 @@ class PETScVector ...@@ -207,7 +207,7 @@ class PETScVector
Copy local entries including ghost ones to an array Copy local entries including ghost ones to an array
\param u Preallocated vector for the values of local entries. \param u Preallocated vector for the values of local entries.
*/ */
void copyValues(std::vector<double>& u) const; void copyValues(std::vector<PetscScalar>& u) const;
/*! View the global vector for test purpose. Do not use it for output a big vector. /*! View the global vector for test purpose. Do not use it for output a big vector.
\param file_name File name for output \param file_name File name for output
......
...@@ -71,12 +71,7 @@ MeshComponentMap::MeshComponentMap( ...@@ -71,12 +71,7 @@ MeshComponentMap::MeshComponentMap(
for (std::size_t j = 0; j < mesh_subset.getNumberOfNodes(); j++) for (std::size_t j = 0; j < mesh_subset.getNumberOfNodes(); j++)
{ {
GlobalIndexType global_id = 0; GlobalIndexType global_id = 0;
if (order == ComponentOrder::BY_LOCATION) if (order != ComponentOrder::BY_LOCATION)
{
global_id = static_cast<GlobalIndexType>(
components.size() * mesh.getGlobalNodeID(j) + comp_id);
}
else
{ {
// Deactivated since this case is not suitable to // Deactivated since this case is not suitable to
// arrange non ghost entries of a partition within // arrange non ghost entries of a partition within
...@@ -85,6 +80,9 @@ MeshComponentMap::MeshComponentMap( ...@@ -85,6 +80,9 @@ MeshComponentMap::MeshComponentMap(
" can only be numbered by the oder type" " can only be numbered by the oder type"
" of ComponentOrder::BY_LOCATION"); " of ComponentOrder::BY_LOCATION");
} }
global_id = static_cast<GlobalIndexType>(
components.size() * mesh.getGlobalNodeID(j)
+ comp_id);
const bool is_ghost = const bool is_ghost =
mesh.isGhostNode(mesh.getNode(j)->getID()); mesh.isGhostNode(mesh.getNode(j)->getID());
if (is_ghost) if (is_ghost)
......
...@@ -54,7 +54,6 @@ GlobalVector const& GlobalVectorFromNamedFunction::call( ...@@ -54,7 +54,6 @@ GlobalVector const& GlobalVectorFromNamedFunction::call(
_context.index = node_id; _context.index = node_id;
auto const value = _function_caller.call(args); auto const value = _function_caller.call(args);
// Problems with PETSc also uses global index.
result->set(node_id, value); result->set(node_id, value);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment