Skip to content
Snippets Groups Projects
Commit 6f45d508 authored by Lars Bilke's avatar Lars Bilke
Browse files

Merge branch 'FixGhostNodeIssue' into 'master'

Fix ghost node issue

Closes #3035

See merge request ogs/ogs!3299
parents 7c992be2 01158b1c
No related branches found
No related tags found
No related merge requests found
...@@ -287,8 +287,8 @@ void NodeWiseMeshPartitioner::processPartition( ...@@ -287,8 +287,8 @@ void NodeWiseMeshPartitioner::processPartition(
std::vector<MeshLib::Node*> higher_order_regular_nodes; std::vector<MeshLib::Node*> higher_order_regular_nodes;
std::tie(partition.nodes, higher_order_regular_nodes) = std::tie(partition.nodes, higher_order_regular_nodes) =
findRegularNodesInPartition(part_id, is_mixed_high_order_linear_elems, findRegularNodesInPartition(part_id, is_mixed_high_order_linear_elems,
_mesh->getNumberOfBaseNodes(), _mesh->getNumberOfBaseNodes(),
_mesh->getNodes(), _nodes_partition_ids); _mesh->getNodes(), _nodes_partition_ids);
partition.number_of_regular_base_nodes = partition.nodes.size(); partition.number_of_regular_base_nodes = partition.nodes.size();
partition.number_of_regular_nodes = partition.number_of_regular_nodes =
...@@ -470,16 +470,19 @@ void addVtkGhostTypeProperty(MeshLib::Properties& partitioned_properties, ...@@ -470,16 +470,19 @@ void addVtkGhostTypeProperty(MeshLib::Properties& partitioned_properties,
} }
vtk_ghost_type->resize(total_number_of_cells); vtk_ghost_type->resize(total_number_of_cells);
for(auto const& p : partitions) std::size_t offset = 0;
for(auto const& partition : partitions)
{ {
for (std::size_t i = 0; i < p.duplicate_ghost_cell.size(); ++i) offset += partition.regular_elements.size();
for (std::size_t i = 0; i < partition.ghost_elements.size(); ++i)
{ {
if (p.duplicate_ghost_cell[i]) if (partition.duplicate_ghost_cell[i])
{ {
(*vtk_ghost_type)[p.ghost_elements[i]->getID()] |= (*vtk_ghost_type)[offset + i] |=
vtkDataSetAttributes::DUPLICATECELL; vtkDataSetAttributes::DUPLICATECELL;
} }
} }
offset += partition.ghost_elements.size();
} }
} }
...@@ -877,7 +880,7 @@ struct PartitionOffsets ...@@ -877,7 +880,7 @@ struct PartitionOffsets
long ghost_elements; long ghost_elements;
}; };
PartitionOffsets computePartitionElementOffsets(Partition const& partition) PartitionOffsets computePartitionOffsets(Partition const& partition)
{ {
return {static_cast<long>(partition.nodes.size()), return {static_cast<long>(partition.nodes.size()),
static_cast<long>(partition.regular_elements.size() + static_cast<long>(partition.regular_elements.size() +
...@@ -921,10 +924,10 @@ std::tuple<std::vector<long>, std::vector<long>> writeConfigData( ...@@ -921,10 +924,10 @@ std::tuple<std::vector<long>, std::vector<long>> writeConfigData(
OGS_FATAL("Could not open file '{:s}' for output.", file_name_cfg); OGS_FATAL("Could not open file '{:s}' for output.", file_name_cfg);
} }
std::vector<long> num_elem_integers; std::vector<long> partitions_element_offsets;
num_elem_integers.reserve(partitions.size()); partitions_element_offsets.reserve(partitions.size());
std::vector<long> num_g_elem_integers; std::vector<long> partitions_ghost_element_offsets;
num_g_elem_integers.reserve(partitions.size()); partitions_ghost_element_offsets.reserve(partitions.size());
ConfigOffsets config_offsets = {0, 0, 0}; // 0 for first partition. ConfigOffsets config_offsets = {0, 0, 0}; // 0 for first partition.
for (const auto& partition : partitions) for (const auto& partition : partitions)
...@@ -932,14 +935,18 @@ std::tuple<std::vector<long>, std::vector<long>> writeConfigData( ...@@ -932,14 +935,18 @@ std::tuple<std::vector<long>, std::vector<long>> writeConfigData(
partition.writeConfig(of_bin_cfg); partition.writeConfig(of_bin_cfg);
config_offsets.writeConfig(of_bin_cfg); config_offsets.writeConfig(of_bin_cfg);
auto const& new_offsets = computePartitionElementOffsets(partition); auto const& partition_offsets = computePartitionOffsets(partition);
config_offsets = incrementConfigOffsets(config_offsets, new_offsets); config_offsets =
incrementConfigOffsets(config_offsets, partition_offsets);
num_elem_integers.push_back(new_offsets.regular_elements);
num_g_elem_integers.push_back(new_offsets.ghost_elements); partitions_element_offsets.push_back(
partition_offsets.regular_elements);
partitions_ghost_element_offsets.push_back(
partition_offsets.ghost_elements);
} }
return std::make_tuple(num_elem_integers, num_g_elem_integers); return std::make_tuple(partitions_element_offsets,
partitions_ghost_element_offsets);
} }
/// Get integer variables, which are used to define an element /// Get integer variables, which are used to define an element
...@@ -955,7 +962,7 @@ void getElementIntegerVariables( ...@@ -955,7 +962,7 @@ void getElementIntegerVariables(
std::vector<long>& elem_info, std::vector<long>& elem_info,
long& counter) long& counter)
{ {
unsigned mat_id = 0; // TODO: Material ID to be set from the mesh data constexpr unsigned mat_id = 0; // TODO: Material ID to be set from the mesh data
const long nn = elem.getNumberOfNodes(); const long nn = elem.getNumberOfNodes();
elem_info[counter++] = mat_id; elem_info[counter++] = mat_id;
elem_info[counter++] = static_cast<long>(elem.getCellType()); elem_info[counter++] = static_cast<long>(elem.getCellType());
...@@ -986,13 +993,13 @@ std::unordered_map<std::size_t, long> enumerateLocalNodeIds( ...@@ -986,13 +993,13 @@ std::unordered_map<std::size_t, long> enumerateLocalNodeIds(
/// Write the element integer variables of all partitions into binary files. /// Write the element integer variables of all partitions into binary files.
/// \param file_name_base The prefix of the file name. /// \param file_name_base The prefix of the file name.
/// \param partitions Partitions vector. /// \param partitions Partitions vector.
/// \param num_elem_integers The numbers of all non-ghost element /// \param regular_element_offsets The numbers of all non-ghost element
/// integer variables of each partitions. /// integer variables of each partitions.
/// \param num_g_elem_integers The numbers of all ghost element /// \param ghost_element_offsets The numbers of all ghost element
void writeElements(std::string const& file_name_base, void writeElements(std::string const& file_name_base,
std::vector<Partition> const& partitions, std::vector<Partition> const& partitions,
std::vector<long> const& num_elem_integers, std::vector<long> const& regular_element_offsets,
std::vector<long> const& num_g_elem_integers) std::vector<long> const& ghost_element_offsets)
{ {
const std::string npartitions_str = std::to_string(partitions.size()); const std::string npartitions_str = std::to_string(partitions.size());
...@@ -1017,40 +1024,37 @@ void writeElements(std::string const& file_name_base, ...@@ -1017,40 +1024,37 @@ void writeElements(std::string const& file_name_base,
const auto& partition = partitions[i]; const auto& partition = partitions[i];
auto const local_node_ids = enumerateLocalNodeIds(partition.nodes); auto const local_node_ids = enumerateLocalNodeIds(partition.nodes);
// A vector contains all element integer variables of // Vector containing the offsets of the regular elements of this
// the non-ghost elements of this partition // partition
std::vector<long> ele_info(num_elem_integers[i]); std::vector<long> ele_info(regular_element_offsets[i]);
// Non-ghost elements. auto writeElementData =
long counter = partition.regular_elements.size(); [&local_node_ids](
std::vector<MeshLib::Element const*> const& elements,
long const element_offsets,
std::ofstream& output_stream) {
long counter = elements.size();
std::vector<long> ele_info(element_offsets);
for (std::size_t j = 0; j < partition.regular_elements.size(); j++) for (std::size_t j = 0; j < elements.size(); j++)
{ {
const auto* elem = partition.regular_elements[j]; const auto* elem = elements[j];
ele_info[j] = counter; ele_info[j] = counter;
getElementIntegerVariables(*elem, local_node_ids, ele_info, getElementIntegerVariables(*elem, local_node_ids, ele_info,
counter); counter);
} }
// Write vector data of non-ghost elements // Write vector data of regular elements
element_info_os.write(reinterpret_cast<const char*>(ele_info.data()), output_stream.write(
ele_info.size() * sizeof(long)); reinterpret_cast<const char*>(ele_info.data()),
ele_info.size() * sizeof(long));
};
// regular elements.
writeElementData(partition.regular_elements, regular_element_offsets[i],
element_info_os);
// Ghost elements // Ghost elements
ele_info.resize(num_g_elem_integers[i]); writeElementData(partition.ghost_elements, ghost_element_offsets[i],
ghost_element_info_os);
counter = partition.ghost_elements.size();
for (std::size_t j = 0; j < partition.ghost_elements.size(); j++)
{
const auto* elem = partition.ghost_elements[j];
ele_info[j] = counter;
getElementIntegerVariables(*elem, local_node_ids, ele_info,
counter);
}
// Write vector data of ghost elements
ghost_element_info_os.write(
reinterpret_cast<const char*>(ele_info.data()),
ele_info.size() * sizeof(long));
} }
} }
...@@ -1083,14 +1087,14 @@ void NodeWiseMeshPartitioner::write(const std::string& file_name_base) ...@@ -1083,14 +1087,14 @@ void NodeWiseMeshPartitioner::write(const std::string& file_name_base)
writeProperties(file_name_base, _partitioned_properties, _partitions, writeProperties(file_name_base, _partitioned_properties, _partitions,
MeshLib::MeshItemType::Cell); MeshLib::MeshItemType::Cell);
const auto elem_integers = writeConfigData(file_name_base, _partitions); const auto elements_offsets = writeConfigData(file_name_base, _partitions);
const std::vector<IntegerType>& num_elem_integers = const std::vector<IntegerType>& regular_element_offsets =
std::get<0>(elem_integers); std::get<0>(elements_offsets);
const std::vector<IntegerType>& num_g_elem_integers = const std::vector<IntegerType>& ghost_element_offsets =
std::get<1>(elem_integers); std::get<1>(elements_offsets);
writeElements(file_name_base, _partitions, num_elem_integers, writeElements(file_name_base, _partitions, regular_element_offsets,
num_g_elem_integers); ghost_element_offsets);
writeNodes(file_name_base, _partitions, _nodes_global_ids); writeNodes(file_name_base, _partitions, _nodes_global_ids);
} }
......
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