Commit 08dd5073 authored by Dmitry Yu. Naumov's avatar Dmitry Yu. Naumov
Browse files

Merge branch 'ImproveCodeQualityInMeshComponentMap' into 'master'

Readability improvements in MeshComponentMap.

See merge request ogs/ogs!3577
parents c9a93be4 79ac3d62
......@@ -39,66 +39,9 @@ MeshComponentMap::MeshComponentMap(
createSerialMeshComponentMap(components, order);
return;
}
// Use PETSc with multi-thread
// get number of unknowns
GlobalIndexType num_unknowns = 0;
for (auto const& c : components)
else
{
// PETSc always works with MeshLib::NodePartitionedMesh.
const MeshLib::NodePartitionedMesh& p_mesh =
static_cast<const MeshLib::NodePartitionedMesh&>(c.getMesh());
num_unknowns += p_mesh.getNumberOfGlobalNodes();
}
// construct dict (and here we number global_index by component type)
int comp_id = 0;
_num_global_dof = 0;
_num_local_dof = 0;
for (auto const& c : components)
{
assert(dynamic_cast<MeshLib::NodePartitionedMesh const*>(
&c.getMesh()) != nullptr);
std::size_t const mesh_id = c.getMeshID();
const MeshLib::NodePartitionedMesh& p_mesh =
static_cast<const MeshLib::NodePartitionedMesh&>(c.getMesh());
// mesh items are ordered first by node, cell, ....
for (std::size_t j = 0; j < c.getNumberOfNodes(); j++)
{
GlobalIndexType global_id = 0;
if (order != ComponentOrder::BY_LOCATION)
{
// Deactivated since this case is not suitable to
// arrange non ghost entries of a partition within
// a rank in the parallel computing.
OGS_FATAL(
"Global index in the system of equations"
" can only be numbered by the order type of "
"ComponentOrder::BY_LOCATION");
}
global_id = static_cast<GlobalIndexType>(
components.size() * p_mesh.getGlobalNodeID(j) + comp_id);
const bool is_ghost =
p_mesh.isGhostNode(p_mesh.getNode(j)->getID());
if (is_ghost)
{
_ghosts_indices.push_back(global_id);
global_id = -global_id;
// If the ghost entry has an index of 0,
// its index is set to the negative value of unknowns.
if (global_id == 0)
global_id = -num_unknowns;
}
else
_num_local_dof++;
_dict.insert(Line(Location(mesh_id, MeshLib::MeshItemType::Node, j),
comp_id, global_id));
}
_num_global_dof += p_mesh.getNumberOfGlobalNodes();
comp_id++;
createParallelMeshComponentMap(components, order);
}
}
#else
......@@ -115,7 +58,7 @@ MeshComponentMap MeshComponentMap::getSubset(
std::vector<int> const& new_global_component_ids) const
{
{ // Testing first an assumption met later in the code that the meshes for
// the all bulk_mesh_subsets are equal.
// all the bulk_mesh_subsets are equal.
auto const first_mismatch =
std::adjacent_find(begin(bulk_mesh_subsets), end(bulk_mesh_subsets),
[](auto const& a, auto const& b) {
......@@ -159,7 +102,7 @@ MeshComponentMap MeshComponentMap::getSubset(
MeshLib::Location const new_location{
new_mesh_id, MeshLib::MeshItemType::Node, node_id};
// Assuming the meshes for the all bulk_mesh_subsets are equal.
// Assuming the meshes for all the bulk_mesh_subsets are equal.
MeshLib::Location const bulk_location{
bulk_mesh_subsets.front().getMeshID(), MeshLib::MeshItemType::Node,
bulk_node_ids_map[node_id]};
......@@ -378,4 +321,73 @@ void MeshComponentMap::createSerialMeshComponentMap(
}
}
#ifdef USE_PETSC
void MeshComponentMap::createParallelMeshComponentMap(
std::vector<MeshLib::MeshSubset> const& components, ComponentOrder order)
{
if (order != ComponentOrder::BY_LOCATION)
{
// Not allowed in parallel case since this is not suitable to
// arrange non ghost entries of a partition within
// a rank in the parallel computing.
OGS_FATAL(
"Global index in the system of equations can only be numbered by "
"the order type of ComponentOrder::BY_LOCATION");
}
// get number of unknowns
GlobalIndexType num_unknowns = 0;
for (auto const& c : components)
{
const MeshLib::NodePartitionedMesh& partitioned_mesh =
static_cast<const MeshLib::NodePartitionedMesh&>(c.getMesh());
num_unknowns += partitioned_mesh.getNumberOfGlobalNodes();
}
// construct dict (and here we number global_index by component type)
int comp_id = 0;
_num_global_dof = 0;
_num_local_dof = 0;
for (auto const& c : components)
{
assert(dynamic_cast<MeshLib::NodePartitionedMesh const*>(
&c.getMesh()) != nullptr);
std::size_t const mesh_id = c.getMeshID();
const MeshLib::NodePartitionedMesh& partitioned_mesh =
static_cast<const MeshLib::NodePartitionedMesh&>(c.getMesh());
// mesh items are ordered first by node, cell, ....
for (std::size_t j = 0; j < c.getNumberOfNodes(); j++)
{
GlobalIndexType global_index = static_cast<GlobalIndexType>(
components.size() * partitioned_mesh.getGlobalNodeID(j) +
comp_id);
const bool is_ghost = partitioned_mesh.isGhostNode(
partitioned_mesh.getNode(j)->getID());
if (is_ghost)
{
_ghosts_indices.push_back(global_index);
global_index = -global_index;
// If the ghost entry has an index of 0,
// its index is set to the negative value of unknowns.
if (global_index == 0)
{
global_index = -num_unknowns;
}
}
else
{
_num_local_dof++;
}
_dict.insert(Line(Location(mesh_id, MeshLib::MeshItemType::Node, j),
comp_id, global_index));
}
_num_global_dof += partitioned_mesh.getNumberOfGlobalNodes();
comp_id++;
}
}
#endif
} // namespace NumLib
......@@ -188,6 +188,14 @@ private:
void createSerialMeshComponentMap(
std::vector<MeshLib::MeshSubset> const& components,
ComponentOrder order);
#ifdef USE_PETSC
/// \param components a vector of components
/// \param order type of ordering values in a vector
void createParallelMeshComponentMap(
std::vector<MeshLib::MeshSubset> const& components,
ComponentOrder order);
#endif
};
} // namespace NumLib
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment