OGS
ApplicationUtils Namespace Reference

Classes

struct  ConfigOffsets
 
class  NodeWiseMeshPartitioner
 Mesh partitioner. More...
 
struct  Partition
 A subdomain mesh. More...
 
struct  PartitionOffsets
 

Functions

template<typename ElementType >
int getNumberOfElementIntegrationPointsGeneral (MeshLib::IntegrationPointMetaData const &ip_meta_data)
 
int getNumberOfElementIntegrationPoints (MeshLib::IntegrationPointMetaData const &ip_meta_data, MeshLib::Element const &e)
 
std::vector< std::size_t > getIntegrationPointDataOffsetsOfMeshElements (std::vector< MeshLib::Element * > const &mesh_elements, MeshLib::PropertyVectorBase const &pv, MeshLib::Properties const &properties)
 
void writeMETIS (std::vector< MeshLib::Element * > const &elements, const std::string &file_name)
 
std::vector< std::size_t > readMetisData (const std::string &file_name_base, long const number_of_partitions, std::size_t const number_of_nodes)
 
void removeMetisPartitioningFiles (std::string const &file_name_base, long const number_of_partitions)
 
NodeWiseMeshPartitioner::IntegerType getNumberOfIntegerVariablesOfElements (std::vector< const MeshLib::Element * > const &elements)
 
std::size_t nodeIdBulkMesh (MeshLib::Node const &node, std::vector< std::size_t > const *node_id_mapping=nullptr)
 
std::size_t partitionLookup (MeshLib::Node const &node, std::vector< std::size_t > const &partition_ids, std::vector< std::size_t > const *node_id_mapping=nullptr)
 
std::pair< std::vector< MeshLib::Node * >, std::vector< MeshLib::Node * > > findRegularNodesInPartition (std::size_t const part_id, std::vector< MeshLib::Node * > const &nodes, std::vector< std::size_t > const &partition_ids, MeshLib::Mesh const &mesh, std::vector< std::size_t > const *node_id_mapping=nullptr)
 
std::ptrdiff_t numberOfRegularNodes (MeshLib::Element const &e, std::size_t const part_id, std::vector< std::size_t > const &partition_ids, std::vector< std::size_t > const *node_id_mapping=nullptr)
 
std::tuple< std::vector< MeshLib::Element const * >, std::vector< MeshLib::Element const * > > findElementsInPartition (std::size_t const part_id, std::vector< MeshLib::Element * > const &elements, std::vector< std::size_t > const &partition_ids, std::vector< std::size_t > const *node_id_mapping=nullptr)
 
std::tuple< std::vector< MeshLib::Node * >, std::vector< MeshLib::Node * > > findGhostNodesInPartition (std::size_t const part_id, std::vector< MeshLib::Node * > const &nodes, std::vector< MeshLib::Element const * > const &ghost_elements, std::vector< std::size_t > const &partition_ids, MeshLib::Mesh const &mesh, std::vector< std::size_t > const *node_id_mapping=nullptr)
 
template<typename T >
std::size_t copyNodePropertyVectorValues (Partition const &p, std::size_t const offset, MeshLib::PropertyVector< T > const &pv, MeshLib::PropertyVector< T > &partitioned_pv)
 
template<typename T >
std::size_t copyCellPropertyVectorValues (Partition const &p, std::size_t const offset, MeshLib::PropertyVector< T > const &pv, MeshLib::PropertyVector< T > &partitioned_pv)
 
template<typename T >
std::size_t copyFieldPropertyDataToPartitions (MeshLib::Properties const &properties, Partition const &p, std::size_t const id_offset_partition, std::vector< std::size_t > const &element_ip_data_offsets, MeshLib::PropertyVector< T > const &pv, MeshLib::PropertyVector< T > &partitioned_pv)
 
void setIntegrationPointNumberOfPartition (MeshLib::Properties const &properties, std::vector< Partition > &partitions)
 
template<typename T >
bool copyPropertyVector (std::vector< MeshLib::Element * > const &global_mesh_elements, MeshLib::Properties &partitioned_properties, MeshLib::Properties const &properties, std::vector< Partition > const &partitions, MeshLib::PropertyVector< T > const *const pv, std::map< MeshLib::MeshItemType, std::size_t > const &total_number_of_tuples)
 
void addVtkGhostTypeProperty (MeshLib::Properties &partitioned_properties, std::vector< Partition > const &partitions, std::size_t const total_number_of_cells)
 
MeshLib::Properties partitionProperties (std::unique_ptr< MeshLib::Mesh > const &mesh, std::vector< Partition > &partitions)
 Partition existing properties and add vtkGhostType cell data array property.
 
void markDuplicateGhostCells (MeshLib::Mesh const &mesh, std::vector< Partition > &partitions)
 
void checkFieldPropertyVectorSize (std::vector< MeshLib::Element * > const &global_mesh_elements, MeshLib::Properties const &properties)
 
template<typename T >
void writePropertyVectorValues (std::ostream &os, MeshLib::PropertyVector< T > const &pv)
 
template<typename T >
bool writePropertyVector (MeshLib::PropertyVector< T > const *const pv, MeshLib::MeshItemType const mesh_item_type, std::ostream &out_val, std::ostream &out_meta)
 
void writeProperties (const std::string &file_name_base, MeshLib::Properties const &partitioned_properties, std::vector< Partition > const &partitions, MeshLib::MeshItemType const mesh_item_type)
 
PartitionOffsets computePartitionOffsets (Partition const &partition)
 
ConfigOffsets incrementConfigOffsets (ConfigOffsets const &oldConfig, PartitionOffsets const &offsets)
 
std::tuple< std::vector< long >, std::vector< long > > writeConfigData (const std::string &file_name_base, std::vector< Partition > const &partitions)
 
void getElementIntegerVariables (const MeshLib::Element &elem, const std::unordered_map< std::size_t, long > &local_node_ids, std::vector< long > &elem_info, long &counter)
 
std::unordered_map< std::size_t, long > enumerateLocalNodeIds (std::vector< MeshLib::Node * > const &nodes)
 Generates a mapping of given node ids to a new local (renumbered) node ids.
 
void writeElements (std::string const &file_name_base, std::vector< Partition > const &partitions, std::vector< long > const &regular_element_offsets, std::vector< long > const &ghost_element_offsets)
 
void writeNodes (const std::string &file_name_base, std::vector< Partition > const &partitions, std::vector< std::size_t > const &global_node_ids)
 

Function Documentation

◆ addVtkGhostTypeProperty()

void ApplicationUtils::addVtkGhostTypeProperty ( MeshLib::Properties partitioned_properties,
std::vector< Partition > const &  partitions,
std::size_t const  total_number_of_cells 
)

Definition at line 523 of file NodeWiseMeshPartitioner.cpp.

526{
527 auto* vtk_ghost_type =
528 partitioned_properties.createNewPropertyVector<unsigned char>(
529 "vtkGhostType", MeshLib::MeshItemType::Cell);
530 if (vtk_ghost_type == nullptr)
531 {
532 OGS_FATAL("Could not create vtkGhostType cell data array.");
533 }
534
535 vtk_ghost_type->resize(total_number_of_cells);
536 std::size_t offset = 0;
537 for (auto const& partition : partitions)
538 {
539 offset += partition.regular_elements.size();
540 for (std::size_t i = 0; i < partition.ghost_elements.size(); ++i)
541 {
542 if (partition.duplicate_ghost_cell[i])
543 {
544 (*vtk_ghost_type)[offset + i] |=
545 vtkDataSetAttributes::DUPLICATECELL;
546 }
547 }
548 offset += partition.ghost_elements.size();
549 }
550}
#define OGS_FATAL(...)
Definition: Error.h:26
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)

References MeshLib::Cell, MeshLib::Properties::createNewPropertyVector(), and OGS_FATAL.

Referenced by partitionProperties().

◆ checkFieldPropertyVectorSize()

void ApplicationUtils::checkFieldPropertyVectorSize ( std::vector< MeshLib::Element * > const &  global_mesh_elements,
MeshLib::Properties const &  properties 
)

Definition at line 629 of file NodeWiseMeshPartitioner.cpp.

632{
633 for (auto const& [name, property] : properties)
634 {
635 auto const item_type = property->getMeshItemType();
636
638 {
639 continue;
640 }
641
642 // For special field data such as OGS_VERSION, IntegrationPointMetaData,
643 // etc., which are not "real" integration points:
644 if (property->getPropertyName().find("_ip") == std::string::npos)
645 {
646 continue;
647 }
648
649 std::size_t number_of_total_integration_points = 0;
650 auto const ip_meta_data = MeshLib::getIntegrationPointMetaData(
651 properties, property->getPropertyName());
652 for (auto const element : global_mesh_elements)
653 {
654 int const number_of_integration_points =
655 getNumberOfElementIntegrationPoints(ip_meta_data, *element);
656 number_of_total_integration_points += number_of_integration_points;
657 }
658
659 const auto pv =
660 dynamic_cast<MeshLib::PropertyVector<double> const*>(property);
661 std::size_t const component_number = pv->getNumberOfGlobalComponents();
662 if (pv->size() != number_of_total_integration_points * component_number)
663 {
664 OGS_FATAL(
665 "The property vector's size {:d} for integration point data "
666 "{:s} does not match its actual size {:d}. The field data in "
667 "the vtu file are wrong.",
668 pv->size(), name,
669 number_of_total_integration_points * component_number);
670 }
671 }
672}
int getNumberOfGlobalComponents() const
int getNumberOfElementIntegrationPoints(MeshLib::IntegrationPointMetaData const &ip_meta_data, MeshLib::Element const &e)
IntegrationPointMetaData getIntegrationPointMetaData(MeshLib::Properties const &properties, std::string const &name)

References MeshLib::getIntegrationPointMetaData(), getNumberOfElementIntegrationPoints(), MeshLib::PropertyVectorBase::getNumberOfGlobalComponents(), MeshLib::IntegrationPoint, and OGS_FATAL.

Referenced by ApplicationUtils::NodeWiseMeshPartitioner::partitionByMETIS().

◆ computePartitionOffsets()

PartitionOffsets ApplicationUtils::computePartitionOffsets ( Partition const &  partition)

Definition at line 1008 of file NodeWiseMeshPartitioner.cpp.

1009{
1010 return {static_cast<long>(partition.nodes.size()),
1011 static_cast<long>(partition.regular_elements.size() +
1013 partition.regular_elements)),
1014 static_cast<long>(partition.ghost_elements.size() +
1016 partition.ghost_elements))};
1017}
NodeWiseMeshPartitioner::IntegerType getNumberOfIntegerVariablesOfElements(std::vector< const MeshLib::Element * > const &elements)

References getNumberOfIntegerVariablesOfElements(), ApplicationUtils::Partition::ghost_elements, ApplicationUtils::Partition::nodes, and ApplicationUtils::Partition::regular_elements.

Referenced by writeConfigData().

◆ copyCellPropertyVectorValues()

template<typename T >
std::size_t ApplicationUtils::copyCellPropertyVectorValues ( Partition const &  p,
std::size_t const  offset,
MeshLib::PropertyVector< T > const &  pv,
MeshLib::PropertyVector< T > &  partitioned_pv 
)

Copies the properties from global property vector pv to the partition-local one partitioned_pv. Regular elements' and ghost elements' values are copied.

Definition at line 326 of file NodeWiseMeshPartitioner.cpp.

331{
332 std::size_t const n_regular(p.regular_elements.size());
333 auto const n_components = pv.getNumberOfGlobalComponents();
334 for (std::size_t i = 0; i < n_regular; ++i)
335 {
336 const auto id = p.regular_elements[i]->getID();
337 std::copy_n(&pv[n_components * id], n_components,
338 &partitioned_pv[offset + n_components * i]);
339 }
340
341 std::size_t const n_ghost(p.ghost_elements.size());
342 for (std::size_t i = 0; i < n_ghost; ++i)
343 {
344 const auto id = p.ghost_elements[i]->getID();
345 std::copy_n(&pv[n_components * id], n_components,
346 &partitioned_pv[offset + n_components * (n_regular + i)]);
347 }
348 return n_components * (n_regular + n_ghost);
349}

References MeshLib::PropertyVectorBase::getNumberOfGlobalComponents().

Referenced by copyPropertyVector().

◆ copyFieldPropertyDataToPartitions()

template<typename T >
std::size_t ApplicationUtils::copyFieldPropertyDataToPartitions ( MeshLib::Properties const &  properties,
Partition const &  p,
std::size_t const  id_offset_partition,
std::vector< std::size_t > const &  element_ip_data_offsets,
MeshLib::PropertyVector< T > const &  pv,
MeshLib::PropertyVector< T > &  partitioned_pv 
)

Copies the data from the property vector pv belonging to the given Partition p to the property vector partitioned_pv. partitioned_pv is ordered by partition. Regular elements' and ghost elements' values are copied.

Definition at line 356 of file NodeWiseMeshPartitioner.cpp.

363{
364 // Special field data such as OGS_VERSION, IntegrationPointMetaData,
365 // etc., which are not "real" integration points, are copied "as is"
366 // (i.e. fully) for every partition.
367 if (pv.getPropertyName().find("_ip") == std::string::npos)
368 {
369 std::copy_n(&pv[0], pv.size(), &partitioned_pv[id_offset_partition]);
370 return pv.size();
371 }
372
373 auto const n_components = pv.getNumberOfGlobalComponents();
374
375 std::size_t id_offset = 0;
376
377 auto copyFieldData =
378 [&](std::vector<const MeshLib::Element*> const& elements)
379 {
380 auto const ip_meta_data = MeshLib::getIntegrationPointMetaData(
381 properties, pv.getPropertyName());
382
383 for (auto const element : elements)
384 {
385 int const number_of_element_field_data =
386 getNumberOfElementIntegrationPoints(ip_meta_data, *element) *
387 n_components;
388 // The original element ID is not changed.
389 auto const element_id = element->getID();
390 int const begin_pos = element_ip_data_offsets[element_id];
391 int const end_pos = element_ip_data_offsets[element_id + 1];
392
393 std::copy(pv.begin() + begin_pos, pv.begin() + end_pos,
394 &partitioned_pv[id_offset + id_offset_partition]);
395 id_offset += number_of_element_field_data;
396 }
397 };
398
399 copyFieldData(p.regular_elements);
400 copyFieldData(p.ghost_elements);
401
402 return id_offset;
403}
std::string const & getPropertyName() const
std::size_t size() const

References MeshLib::getIntegrationPointMetaData(), getNumberOfElementIntegrationPoints(), MeshLib::PropertyVectorBase::getNumberOfGlobalComponents(), MeshLib::PropertyVectorBase::getPropertyName(), and MeshLib::PropertyVector< PROP_VAL_TYPE >::size().

Referenced by copyPropertyVector().

◆ copyNodePropertyVectorValues()

template<typename T >
std::size_t ApplicationUtils::copyNodePropertyVectorValues ( Partition const &  p,
std::size_t const  offset,
MeshLib::PropertyVector< T > const &  pv,
MeshLib::PropertyVector< T > &  partitioned_pv 
)

Copies the properties from global property vector pv to the partition-local one partitioned_pv.

Definition at line 304 of file NodeWiseMeshPartitioner.cpp.

309{
310 auto const& nodes = p.nodes;
311 auto const nnodes = nodes.size();
312 auto const n_components = pv.getNumberOfGlobalComponents();
313 for (std::size_t i = 0; i < nnodes; ++i)
314 {
315 const auto global_id = nodes[i]->getID();
316 std::copy_n(&pv[n_components * global_id], n_components,
317 &partitioned_pv[offset + n_components * i]);
318 }
319 return n_components * nnodes;
320}

References MeshLib::PropertyVectorBase::getNumberOfGlobalComponents().

Referenced by copyPropertyVector().

◆ copyPropertyVector()

template<typename T >
bool ApplicationUtils::copyPropertyVector ( std::vector< MeshLib::Element * > const &  global_mesh_elements,
MeshLib::Properties partitioned_properties,
MeshLib::Properties const &  properties,
std::vector< Partition > const &  partitions,
MeshLib::PropertyVector< T > const *const  pv,
std::map< MeshLib::MeshItemType, std::size_t > const &  total_number_of_tuples 
)

Definition at line 451 of file NodeWiseMeshPartitioner.cpp.

458{
459 if (pv == nullptr)
460 {
461 return false;
462 }
463 auto const item_type = pv->getMeshItemType();
464
465 std::size_t partitioned_pv_size = total_number_of_tuples.at(item_type) *
467
468 std::vector<std::size_t> element_ip_data_offsets;
470 {
471 // Special field data such as OGS_VERSION, IntegrationPointMetaData,
472 // etc., which are not "real" integration points, are copied "as is"
473 // (i.e. fully) for every partition.
474 if (pv->getPropertyName().find("_ip") == std::string::npos)
475 {
476 partitioned_pv_size = pv->size() * partitions.size();
477 }
478
479 element_ip_data_offsets = getIntegrationPointDataOffsetsOfMeshElements(
480 global_mesh_elements, *pv, properties);
481 }
482
483 auto partitioned_pv = partitioned_properties.createNewPropertyVector<T>(
484 pv->getPropertyName(), pv->getMeshItemType(),
486 partitioned_pv->resize(partitioned_pv_size);
487
488 auto copy_property_vector_values =
489 [&](Partition const& p, std::size_t offset)
490 {
492 {
493 return copyFieldPropertyDataToPartitions(properties, p, offset,
494 element_ip_data_offsets,
495 *pv, *partitioned_pv);
496 }
497
498 if (item_type == MeshLib::MeshItemType::Node)
499 {
500 return copyNodePropertyVectorValues(p, offset, *pv,
501 *partitioned_pv);
502 }
503 if (item_type == MeshLib::MeshItemType::Cell)
504 {
505 return copyCellPropertyVectorValues(p, offset, *pv,
506 *partitioned_pv);
507 }
508
509 OGS_FATAL(
510 "Copying of property vector values for mesh item type {:s} is not "
511 "implemented.",
512 toString(item_type));
513 };
514
515 std::size_t position_offset(0);
516 for (auto p : partitions)
517 {
518 position_offset += copy_property_vector_values(p, position_offset);
519 }
520 return true;
521}
MeshItemType getMeshItemType() const
std::size_t copyCellPropertyVectorValues(Partition const &p, std::size_t const offset, MeshLib::PropertyVector< T > const &pv, MeshLib::PropertyVector< T > &partitioned_pv)
std::vector< std::size_t > getIntegrationPointDataOffsetsOfMeshElements(std::vector< MeshLib::Element * > const &mesh_elements, MeshLib::PropertyVectorBase const &pv, MeshLib::Properties const &properties)
std::size_t copyFieldPropertyDataToPartitions(MeshLib::Properties const &properties, Partition const &p, std::size_t const id_offset_partition, std::vector< std::size_t > const &element_ip_data_offsets, MeshLib::PropertyVector< T > const &pv, MeshLib::PropertyVector< T > &partitioned_pv)
std::size_t copyNodePropertyVectorValues(Partition const &p, std::size_t const offset, MeshLib::PropertyVector< T > const &pv, MeshLib::PropertyVector< T > &partitioned_pv)
const char * toString(mgis::behaviour::Behaviour::Kinematic kin)

References MeshLib::Cell, copyCellPropertyVectorValues(), copyFieldPropertyDataToPartitions(), copyNodePropertyVectorValues(), MeshLib::Properties::createNewPropertyVector(), getIntegrationPointDataOffsetsOfMeshElements(), MeshLib::PropertyVectorBase::getMeshItemType(), MeshLib::PropertyVectorBase::getNumberOfGlobalComponents(), MeshLib::PropertyVectorBase::getPropertyName(), MeshLib::IntegrationPoint, MeshLib::Node, OGS_FATAL, and MeshLib::PropertyVector< PROP_VAL_TYPE >::size().

◆ enumerateLocalNodeIds()

std::unordered_map< std::size_t, long > ApplicationUtils::enumerateLocalNodeIds ( std::vector< MeshLib::Node * > const &  nodes)

Generates a mapping of given node ids to a new local (renumbered) node ids.

Definition at line 1105 of file NodeWiseMeshPartitioner.cpp.

1107{
1108 std::unordered_map<std::size_t, long> local_ids;
1109 local_ids.reserve(nodes.size());
1110
1111 long local_node_id = 0;
1112 for (const auto* node : nodes)
1113 {
1114 local_ids[node->getID()] = local_node_id++;
1115 }
1116 return local_ids;
1117}

Referenced by writeElements().

◆ findElementsInPartition()

std::tuple< std::vector< MeshLib::Element const * >, std::vector< MeshLib::Element const * > > ApplicationUtils::findElementsInPartition ( std::size_t const  part_id,
std::vector< MeshLib::Element * > const &  elements,
std::vector< std::size_t > const &  partition_ids,
std::vector< std::size_t > const *  node_id_mapping = nullptr 
)

1 find elements belonging to the partition part_id: fills vector partition.regular_elements 2 find ghost elements belonging to the partition part_id fills vector partition.ghost_elements

Definition at line 182 of file NodeWiseMeshPartitioner.cpp.

187{
188 std::vector<MeshLib::Element const*> regular_elements;
189 std::vector<MeshLib::Element const*> ghost_elements;
190
191 for (auto elem : elements)
192 {
193 auto const regular_nodes = numberOfRegularNodes(
194 *elem, part_id, partition_ids, node_id_mapping);
195
196 if (regular_nodes == 0)
197 {
198 continue;
199 }
200
201 if (regular_nodes ==
202 static_cast<std::ptrdiff_t>(elem->getNumberOfNodes()))
203 {
204 regular_elements.push_back(elem);
205 }
206 else
207 {
208 ghost_elements.push_back(elem);
209 }
210 }
211 return std::tuple<std::vector<MeshLib::Element const*>,
212 std::vector<MeshLib::Element const*>>{regular_elements,
213 ghost_elements};
214}
std::ptrdiff_t numberOfRegularNodes(MeshLib::Element const &e, std::size_t const part_id, std::vector< std::size_t > const &partition_ids, std::vector< std::size_t > const *node_id_mapping=nullptr)

References numberOfRegularNodes().

Referenced by ApplicationUtils::NodeWiseMeshPartitioner::partitionOtherMesh(), and ApplicationUtils::NodeWiseMeshPartitioner::processPartition().

◆ findGhostNodesInPartition()

std::tuple< std::vector< MeshLib::Node * >, std::vector< MeshLib::Node * > > ApplicationUtils::findGhostNodesInPartition ( std::size_t const  part_id,
std::vector< MeshLib::Node * > const &  nodes,
std::vector< MeshLib::Element const * > const &  ghost_elements,
std::vector< std::size_t > const &  partition_ids,
MeshLib::Mesh const &  mesh,
std::vector< std::size_t > const *  node_id_mapping = nullptr 
)

Prerequisite: the ghost elements has to be found (using findElementsInPartition). Finds ghost nodes and non-linear element ghost nodes by walking over ghost elements.

Definition at line 221 of file NodeWiseMeshPartitioner.cpp.

228{
229 std::vector<MeshLib::Node*> base_nodes;
230 std::vector<MeshLib::Node*> ghost_nodes;
231
232 std::vector<bool> is_ghost_node(nodes.size(), false);
233 for (const auto* ghost_elem : ghost_elements)
234 {
235 for (unsigned i = 0; i < ghost_elem->getNumberOfNodes(); i++)
236 {
237 auto const& n = ghost_elem->getNode(i);
238 if (is_ghost_node[n->getID()])
239 {
240 continue;
241 }
242
243 if (partitionLookup(*n, partition_ids, node_id_mapping) != part_id)
244 {
245 if (isBaseNode(*n, mesh.getElementsConnectedToNode(*n)))
246 {
247 base_nodes.push_back(nodes[n->getID()]);
248 }
249 else
250 {
251 ghost_nodes.push_back(nodes[n->getID()]);
252 }
253 is_ghost_node[n->getID()] = true;
254 }
255 }
256 }
257 return std::tuple<std::vector<MeshLib::Node*>, std::vector<MeshLib::Node*>>{
258 base_nodes, ghost_nodes};
259}

References MeshLib::Mesh::getElementsConnectedToNode(), and partitionLookup().

Referenced by ApplicationUtils::NodeWiseMeshPartitioner::partitionOtherMesh(), and ApplicationUtils::NodeWiseMeshPartitioner::processPartition().

◆ findRegularNodesInPartition()

std::pair< std::vector< MeshLib::Node * >, std::vector< MeshLib::Node * > > ApplicationUtils::findRegularNodesInPartition ( std::size_t const  part_id,
std::vector< MeshLib::Node * > const &  nodes,
std::vector< std::size_t > const &  partition_ids,
MeshLib::Mesh const &  mesh,
std::vector< std::size_t > const *  node_id_mapping = nullptr 
)

1 copy pointers to nodes belonging to the partition part_id into base nodes vector, and 2 collect non-linear element nodes belonging to the partition part_id in extra nodes vector. If node_id_mapping is given, it will be used to map the mesh node ids to other ids; used by boundary meshes, for example.

Returns
a pair of base node and extra nodes.

Definition at line 128 of file NodeWiseMeshPartitioner.cpp.

134{
135 // Find nodes belonging to a given partition id.
136 std::vector<MeshLib::Node*> partition_nodes;
137 copy_if(begin(nodes), end(nodes), std::back_inserter(partition_nodes),
138 [&](auto const& n) {
139 return partitionLookup(*n, partition_ids, node_id_mapping) ==
140 part_id;
141 });
142
143 // Space for resulting vectors.
144 std::vector<MeshLib::Node*> base_nodes;
145 base_nodes.reserve(partition_nodes.size() /
146 2); // if linear mesh, then one reallocation, no realloc
147 // for higher order elements meshes.
148 std::vector<MeshLib::Node*> higher_order_nodes;
149 higher_order_nodes.reserve(
150 partition_nodes.size() /
151 2); // if linear mesh, then wasted space, good estimate for quadratic
152 // order mesh, and realloc needed for higher order element meshes.
153
154 // Split the nodes into base nodes and extra nodes.
155 std::partition_copy(
156 begin(partition_nodes), end(partition_nodes),
157 std::back_inserter(base_nodes), std::back_inserter(higher_order_nodes),
158 [&](MeshLib::Node* const n)
159 { return isBaseNode(*n, mesh.getElementsConnectedToNode(*n)); });
160
161 return {base_nodes, higher_order_nodes};
162}
std::size_t partitionLookup(MeshLib::Node const &node, std::vector< std::size_t > const &partition_ids, std::vector< std::size_t > const *node_id_mapping=nullptr)

References MeshLib::Mesh::getElementsConnectedToNode(), and partitionLookup().

Referenced by ApplicationUtils::NodeWiseMeshPartitioner::partitionOtherMesh(), and ApplicationUtils::NodeWiseMeshPartitioner::processPartition().

◆ getElementIntegerVariables()

void ApplicationUtils::getElementIntegerVariables ( const MeshLib::Element elem,
const std::unordered_map< std::size_t, long > &  local_node_ids,
std::vector< long > &  elem_info,
long &  counter 
)

Get integer variables, which are used to define an element

Parameters
elemElement
local_node_idsLocal node indices of a partition
elem_infoA vector holds all integer variables of element definitions
counterRecorder of the number of integer variables.

Definition at line 1084 of file NodeWiseMeshPartitioner.cpp.

1089{
1090 constexpr unsigned mat_id =
1091 0; // TODO: Material ID to be set from the mesh data
1092 const long nn = elem.getNumberOfNodes();
1093 elem_info[counter++] = mat_id;
1094 elem_info[counter++] = static_cast<long>(elem.getCellType());
1095 elem_info[counter++] = nn;
1096
1097 for (long i = 0; i < nn; i++)
1098 {
1099 auto const& n = *elem.getNode(i);
1100 elem_info[counter++] = local_node_ids.at(n.getID());
1101 }
1102}
virtual CellType getCellType() const =0
virtual unsigned getNumberOfNodes() const =0
virtual const Node * getNode(unsigned idx) const =0

References MeshLib::Element::getCellType(), MeshLib::Element::getNode(), and MeshLib::Element::getNumberOfNodes().

Referenced by writeElements().

◆ getIntegrationPointDataOffsetsOfMeshElements()

std::vector< std::size_t > ApplicationUtils::getIntegrationPointDataOffsetsOfMeshElements ( std::vector< MeshLib::Element * > const &  mesh_elements,
MeshLib::PropertyVectorBase const &  pv,
MeshLib::Properties const &  properties 
)

Definition at line 98 of file IntegrationPointDataTools.cpp.

102{
103 // For special field data such as OGS_VERSION, IntegrationPointMetaData,
104 // etc., which are not "real" integration points:
105 if (pv.getPropertyName().find("_ip") == std::string::npos)
106 {
107 return {};
108 }
109
110 auto const n_components = pv.getNumberOfGlobalComponents();
111
112 std::vector<std::size_t> element_ip_data_offsets(mesh_elements.size() + 1);
113 std::size_t counter = 0;
114 auto const ip_meta_data =
115 MeshLib::getIntegrationPointMetaData(properties, pv.getPropertyName());
116 for (std::size_t i = 0; i < mesh_elements.size(); i++)
117 {
118 auto const element = mesh_elements[i];
119
120 // Assuming that the order of elements in mesh_elements is not touched.
121 element_ip_data_offsets[i] = counter;
122 counter += getNumberOfElementIntegrationPoints(ip_meta_data, *element) *
123 n_components;
124 }
125 element_ip_data_offsets[mesh_elements.size()] = counter;
126
127 return element_ip_data_offsets;
128}

References MeshLib::getIntegrationPointMetaData(), getNumberOfElementIntegrationPoints(), MeshLib::PropertyVectorBase::getNumberOfGlobalComponents(), and MeshLib::PropertyVectorBase::getPropertyName().

Referenced by copyPropertyVector(), and createPropertyVector().

◆ getNumberOfElementIntegrationPoints()

int ApplicationUtils::getNumberOfElementIntegrationPoints ( MeshLib::IntegrationPointMetaData const &  ip_meta_data,
MeshLib::Element const &  e 
)

Definition at line 36 of file IntegrationPointDataTools.cpp.

39{
40 switch (e.getCellType())
41 {
43 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Line>(
44 ip_meta_data);
46 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Line3>(
47 ip_meta_data);
49 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Tri>(
50 ip_meta_data);
52 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Tri6>(
53 ip_meta_data);
55 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Quad>(
56 ip_meta_data);
58 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Quad8>(
59 ip_meta_data);
61 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Quad9>(
62 ip_meta_data);
64 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Tet>(
65 ip_meta_data);
67 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Tet10>(
68 ip_meta_data);
70 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Hex>(
71 ip_meta_data);
73 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Hex20>(
74 ip_meta_data);
76 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Prism>(
77 ip_meta_data);
79 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Prism15>(
80 ip_meta_data);
82 return getNumberOfElementIntegrationPointsGeneral<MeshLib::Pyramid>(
83 ip_meta_data);
86 MeshLib::Pyramid13>(ip_meta_data);
89 OGS_FATAL("Mesh element type {:s} is not supported",
90 MeshLib::CellType2String(e.getCellType()));
92 default:
93 OGS_FATAL("Invalid Element Type");
94 }
95 return 0;
96}
int getNumberOfElementIntegrationPointsGeneral(MeshLib::IntegrationPointMetaData const &ip_meta_data)
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.
Definition: MeshEnums.cpp:157

References MeshLib::CellType2String(), MeshLib::Element::getCellType(), getNumberOfElementIntegrationPointsGeneral(), MeshLib::HEX20, MeshLib::HEX27, MeshLib::HEX8, MeshLib::INVALID, MeshLib::LINE2, MeshLib::LINE3, OGS_FATAL, MeshLib::PRISM15, MeshLib::PRISM18, MeshLib::PRISM6, MeshLib::PYRAMID13, MeshLib::PYRAMID5, MeshLib::QUAD4, MeshLib::QUAD8, MeshLib::QUAD9, MeshLib::TET10, MeshLib::TET4, MeshLib::TRI3, and MeshLib::TRI6.

Referenced by checkFieldPropertyVectorSize(), copyFieldPropertyDataToPartitions(), createPropertyVector(), getIntegrationPointDataOffsetsOfMeshElements(), and setIntegrationPointNumberOfPartition().

◆ getNumberOfElementIntegrationPointsGeneral()

template<typename ElementType >
int ApplicationUtils::getNumberOfElementIntegrationPointsGeneral ( MeshLib::IntegrationPointMetaData const &  ip_meta_data)

Definition at line 24 of file IntegrationPointDataTools.cpp.

26{
27 using IntegrationPolicy =
29 using NonGenericIntegrationMethod =
31 NonGenericIntegrationMethod int_met{
32 (unsigned int)ip_meta_data.integration_order};
33 return int_met.getNumberOfPoints();
34}
NumLib::IntegrationGaussLegendreRegular< MeshElement::dimension > IntegrationMethod

References MeshLib::IntegrationPointMetaData::integration_order.

Referenced by getNumberOfElementIntegrationPoints().

◆ getNumberOfIntegerVariablesOfElements()

NodeWiseMeshPartitioner::IntegerType ApplicationUtils::getNumberOfIntegerVariablesOfElements ( std::vector< const MeshLib::Element * > const &  elements)

Calculate the total number of integer variables of an element vector. Each element has three integer variables for element ID, element type, number of nodes of the element. Therefore the total number of the integers in elements is 3 * elements.size() + sum (number of nodes of each element).

Definition at line 73 of file NodeWiseMeshPartitioner.cpp.

75{
76 return 3 * elements.size() +
77 std::accumulate(begin(elements), end(elements), 0,
78 [](auto const nnodes, auto const* e)
79 { return nnodes + e->getNumberOfNodes(); });
80}

Referenced by computePartitionOffsets(), and ApplicationUtils::Partition::writeConfig().

◆ incrementConfigOffsets()

ConfigOffsets ApplicationUtils::incrementConfigOffsets ( ConfigOffsets const &  oldConfig,
PartitionOffsets const &  offsets 
)

Definition at line 1019 of file NodeWiseMeshPartitioner.cpp.

1021{
1022 return {
1023 static_cast<long>(oldConfig.node_rank_offset +
1024 offsets.node * sizeof(MeshLib::IO::NodeData)),
1025 // Offset the ending entry of the element integer variables of
1026 // the non-ghost elements of this partition in the vector of elem_info.
1027 static_cast<long>(oldConfig.element_rank_offset +
1028 offsets.regular_elements * sizeof(long)),
1029
1030 // Offset the ending entry of the element integer variables of
1031 // the ghost elements of this partition in the vector of elem_info.
1032 static_cast<long>(oldConfig.ghost_element_rank_offset +
1033 offsets.ghost_elements * sizeof(long))};
1034}
struct NodeData used for parallel reading and also partitioning
Definition: NodeData.h:18

References ApplicationUtils::ConfigOffsets::element_rank_offset, ApplicationUtils::ConfigOffsets::ghost_element_rank_offset, ApplicationUtils::PartitionOffsets::ghost_elements, ApplicationUtils::PartitionOffsets::node, ApplicationUtils::ConfigOffsets::node_rank_offset, and ApplicationUtils::PartitionOffsets::regular_elements.

Referenced by writeConfigData().

◆ markDuplicateGhostCells()

void ApplicationUtils::markDuplicateGhostCells ( MeshLib::Mesh const &  mesh,
std::vector< Partition > &  partitions 
)

Definition at line 607 of file NodeWiseMeshPartitioner.cpp.

609{
610 std::vector<bool> cell_visited(mesh.getElements().size(), false);
611
612 for (auto& partition : partitions)
613 {
614 partition.duplicate_ghost_cell.resize(partition.ghost_elements.size(),
615 true);
616
617 for (std::size_t i = 0; i < partition.ghost_elements.size(); i++)
618 {
619 const auto& ghost_element = *partition.ghost_elements[i];
620 if (!cell_visited[ghost_element.getID()])
621 {
622 cell_visited[ghost_element.getID()] = true;
623 partition.duplicate_ghost_cell[i] = false;
624 }
625 }
626 }
627}

References MeshLib::Mesh::getElements().

Referenced by ApplicationUtils::NodeWiseMeshPartitioner::partitionByMETIS(), and ApplicationUtils::NodeWiseMeshPartitioner::partitionOtherMesh().

◆ nodeIdBulkMesh()

std::size_t ApplicationUtils::nodeIdBulkMesh ( MeshLib::Node const &  node,
std::vector< std::size_t > const *  node_id_mapping = nullptr 
)

Definition at line 102 of file NodeWiseMeshPartitioner.cpp.

105{
106 return node_id_mapping ? (*node_id_mapping)[node.getID()] : node.getID();
107}

References MathLib::Point3dWithID::getID().

Referenced by partitionLookup().

◆ numberOfRegularNodes()

std::ptrdiff_t ApplicationUtils::numberOfRegularNodes ( MeshLib::Element const &  e,
std::size_t const  part_id,
std::vector< std::size_t > const &  partition_ids,
std::vector< std::size_t > const *  node_id_mapping = nullptr 
)

Definition at line 164 of file NodeWiseMeshPartitioner.cpp.

168{
169 return std::count_if(e.getNodes(), e.getNodes() + e.getNumberOfNodes(),
170 [&](MeshLib::Node* const n) {
171 return partitionLookup(*n, partition_ids,
172 node_id_mapping) == part_id;
173 });
174}

References MeshLib::Element::getNodes(), and MeshLib::Element::getNumberOfNodes().

Referenced by findElementsInPartition().

◆ partitionLookup()

std::size_t ApplicationUtils::partitionLookup ( MeshLib::Node const &  node,
std::vector< std::size_t > const &  partition_ids,
std::vector< std::size_t > const *  node_id_mapping = nullptr 
)

Definition at line 109 of file NodeWiseMeshPartitioner.cpp.

113{
114 auto node_id = [&node_id_mapping](MeshLib::Node const& n)
115 { return nodeIdBulkMesh(n, node_id_mapping); };
116
117 return partition_ids[node_id(node)];
118}
std::size_t nodeIdBulkMesh(MeshLib::Node const &node, std::vector< std::size_t > const *node_id_mapping=nullptr)

References nodeIdBulkMesh().

Referenced by findGhostNodesInPartition(), and findRegularNodesInPartition().

◆ partitionProperties()

MeshLib::Properties ApplicationUtils::partitionProperties ( std::unique_ptr< MeshLib::Mesh > const &  mesh,
std::vector< Partition > &  partitions 
)

Partition existing properties and add vtkGhostType cell data array property.

Creates partitioned mesh properties for nodes and cells.

Definition at line 553 of file NodeWiseMeshPartitioner.cpp.

556{
557 using namespace MeshLib;
558
559 MeshLib::Properties const& properties = mesh->getProperties();
560
561 // Count the number of integration point data of all partitions:
562 setIntegrationPointNumberOfPartition(properties, partitions);
563
564 Properties partitioned_properties;
565 auto count_tuples = [&](MeshItemType const mesh_item_type)
566 {
567 return std::accumulate(
568 begin(partitions), end(partitions), 0,
569 [&](std::size_t const sum, Partition const& p)
570 { return sum + p.numberOfMeshItems(mesh_item_type); });
571 };
572
573 std::map<MeshItemType, std::size_t> const total_number_of_tuples = {
574 {MeshItemType::Cell, count_tuples(MeshItemType::Cell)},
575 {MeshItemType::Node, count_tuples(MeshItemType::Node)},
576 {MeshItemType::IntegrationPoint,
577 count_tuples(MeshItemType::IntegrationPoint)}};
578
579 DBUG(
580 "total number of tuples after partitioning defined for cells is {:d} "
581 "and for nodes {:d} and for integration points {:d}.",
582 total_number_of_tuples.at(MeshItemType::Cell),
583 total_number_of_tuples.at(MeshItemType::Node),
584 total_number_of_tuples.at(MeshItemType::IntegrationPoint));
585
586 // 1 create new PV
587 // 2 resize the PV with total_number_of_tuples
588 // 3 copy the values according to the partition info
590 properties,
591 [&](auto type, auto const property)
592 {
593 return copyPropertyVector<decltype(type)>(
594 mesh->getElements(), partitioned_properties, properties,
595 partitions,
596 dynamic_cast<PropertyVector<decltype(type)> const*>(property),
597 total_number_of_tuples);
598 });
599
600 addVtkGhostTypeProperty(partitioned_properties,
601 partitions,
602 total_number_of_tuples.at(MeshItemType::Cell));
603
604 return partitioned_properties;
605}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:30
void applyToPropertyVectors(Properties const &properties, Function f)
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition: Properties.h:36
void addVtkGhostTypeProperty(MeshLib::Properties &partitioned_properties, std::vector< Partition > const &partitions, std::size_t const total_number_of_cells)
void setIntegrationPointNumberOfPartition(MeshLib::Properties const &properties, std::vector< Partition > &partitions)
MeshItemType
Definition: Location.h:21

References addVtkGhostTypeProperty(), applyToPropertyVectors(), DBUG(), and setIntegrationPointNumberOfPartition().

Referenced by main(), and ApplicationUtils::NodeWiseMeshPartitioner::partitionByMETIS().

◆ readMetisData()

std::vector< std::size_t > ApplicationUtils::readMetisData ( const std::string &  file_name_base,
long  number_of_partitions,
std::size_t  number_of_nodes 
)

Read metis data

Parameters
file_name_baseThe prefix of the filename.
number_of_partitionsThe number is used to compose the full filename and forms the postfix.
number_of_nodesExpected/required number of nodes to be read.

Definition at line 45 of file Metis.cpp.

48{
49 const std::string npartitions_str = std::to_string(number_of_partitions);
50
51 // Read partitioned mesh data from METIS
52 const std::string fname_parts =
53 file_name_base + ".mesh.npart." + npartitions_str;
54
55 std::ifstream npart_in(fname_parts);
56 if (!npart_in.is_open())
57 {
59 "Error: cannot open file {:s}. It may not exist!\n"
60 "Run mpmetis beforehand or use option -m",
61 fname_parts.data());
62 }
63
64 std::vector<std::size_t> partition_ids(number_of_nodes);
65
66 std::size_t counter = 0;
67 while (!npart_in.eof())
68 {
69 npart_in >> partition_ids[counter++] >> std::ws;
70 if (counter == number_of_nodes)
71 {
72 break;
73 }
74 }
75
76 if (npart_in.bad())
77 {
78 OGS_FATAL("Error while reading file {:s}.", fname_parts.data());
79 }
80
81 if (counter != number_of_nodes)
82 {
83 OGS_FATAL("Error: data in {:s} are less than expected.",
84 fname_parts.data());
85 }
86
87 return partition_ids;
88}

References OGS_FATAL.

Referenced by main().

◆ removeMetisPartitioningFiles()

void ApplicationUtils::removeMetisPartitioningFiles ( std::string const &  file_name_base,
long  number_of_partitions 
)

Removes the F.mesh.npart.P and F.mesh.epart.P files, where F is file name base and P is the number of partitions.

Definition at line 90 of file Metis.cpp.

92{
93 const std::string npartitions_str = std::to_string(number_of_partitions);
94
95 std::remove((file_name_base + ".mesh.npart." + npartitions_str).c_str());
96 std::remove((file_name_base + ".mesh.epart." + npartitions_str).c_str());
97}

Referenced by main().

◆ setIntegrationPointNumberOfPartition()

void ApplicationUtils::setIntegrationPointNumberOfPartition ( MeshLib::Properties const &  properties,
std::vector< Partition > &  partitions 
)

Definition at line 405 of file NodeWiseMeshPartitioner.cpp.

407{
408 for (auto const& [name, property] : properties)
409 {
410 auto const item_type = property->getMeshItemType();
411
413 {
414 continue;
415 }
416
417 // For special field data such as OGS_VERSION, IntegrationPointMetaData,
418 // etc., which are not "real" integration points:
419 if (property->getPropertyName().find("_ip") == std::string::npos)
420 {
421 continue;
422 }
423
424 std::string const property_name = property->getPropertyName();
425 auto countIntegrationPoints =
426 [&](std::vector<const MeshLib::Element*> const& elements)
427 {
428 auto const ip_meta_data =
429 MeshLib::getIntegrationPointMetaData(properties, property_name);
430 std::size_t counter = 0;
431 for (auto const element : elements)
432 {
433 int const number_of_integration_points =
434 getNumberOfElementIntegrationPoints(ip_meta_data, *element);
435 counter += number_of_integration_points;
436 }
437 return counter;
438 };
439
440 for (auto& p : partitions)
441 {
442 p.number_of_integration_points =
443 countIntegrationPoints(p.regular_elements) +
444 countIntegrationPoints(p.ghost_elements);
445 }
446 return;
447 }
448}

References MeshLib::getIntegrationPointMetaData(), getNumberOfElementIntegrationPoints(), and MeshLib::IntegrationPoint.

Referenced by partitionProperties().

◆ writeConfigData()

std::tuple< std::vector< long >, std::vector< long > > ApplicationUtils::writeConfigData ( const std::string &  file_name_base,
std::vector< Partition > const &  partitions 
)

Write the configuration data of the partition data in binary files.

Returns
a pair of vectors for:
  1. The number of all non-ghost element integer variables for each partition.
  2. The number of all ghost element integer variables for each partition.

Definition at line 1041 of file NodeWiseMeshPartitioner.cpp.

1043{
1044 auto const file_name_cfg = file_name_base + "_partitioned_msh_cfg" +
1045 std::to_string(partitions.size()) + ".bin";
1046 std::ofstream of_bin_cfg(file_name_cfg, std::ios::binary);
1047 if (!of_bin_cfg)
1048 {
1049 OGS_FATAL("Could not open file '{:s}' for output.", file_name_cfg);
1050 }
1051
1052 std::vector<long> partitions_element_offsets;
1053 partitions_element_offsets.reserve(partitions.size());
1054 std::vector<long> partitions_ghost_element_offsets;
1055 partitions_ghost_element_offsets.reserve(partitions.size());
1056
1057 ConfigOffsets config_offsets = {0, 0, 0}; // 0 for first partition.
1058 for (const auto& partition : partitions)
1059 {
1060 partition.writeConfig(of_bin_cfg);
1061
1062 config_offsets.writeConfig(of_bin_cfg);
1063 auto const& partition_offsets = computePartitionOffsets(partition);
1064 config_offsets =
1065 incrementConfigOffsets(config_offsets, partition_offsets);
1066
1067 partitions_element_offsets.push_back(
1068 partition_offsets.regular_elements);
1069 partitions_ghost_element_offsets.push_back(
1070 partition_offsets.ghost_elements);
1071 }
1072
1073 return std::make_tuple(partitions_element_offsets,
1074 partitions_ghost_element_offsets);
1075}
ConfigOffsets incrementConfigOffsets(ConfigOffsets const &oldConfig, PartitionOffsets const &offsets)
PartitionOffsets computePartitionOffsets(Partition const &partition)

References computePartitionOffsets(), incrementConfigOffsets(), OGS_FATAL, and ApplicationUtils::ConfigOffsets::writeConfig().

Referenced by ApplicationUtils::NodeWiseMeshPartitioner::write(), and ApplicationUtils::NodeWiseMeshPartitioner::writeOtherMesh().

◆ writeElements()

void ApplicationUtils::writeElements ( std::string const &  file_name_base,
std::vector< Partition > const &  partitions,
std::vector< long > const &  regular_element_offsets,
std::vector< long > const &  ghost_element_offsets 
)

Write the element integer variables of all partitions into binary files.

Parameters
file_name_baseThe prefix of the file name.
partitionsPartitions vector.
regular_element_offsetsThe numbers of all non-ghost element integer variables of each partitions.
ghost_element_offsetsThe numbers of all ghost element

Definition at line 1125 of file NodeWiseMeshPartitioner.cpp.

1129{
1130 const std::string npartitions_str = std::to_string(partitions.size());
1131
1132 auto const file_name_ele =
1133 file_name_base + "_partitioned_msh_ele" + npartitions_str + ".bin";
1134 std::ofstream element_info_os(file_name_ele, std::ios::binary);
1135 if (!element_info_os)
1136 {
1137 OGS_FATAL("Could not open file '{:s}' for output.", file_name_ele);
1138 }
1139
1140 auto const file_name_ele_g =
1141 file_name_base + "_partitioned_msh_ele_g" + npartitions_str + ".bin";
1142 std::ofstream ghost_element_info_os(file_name_ele_g, std::ios::binary);
1143 if (!ghost_element_info_os)
1144 {
1145 OGS_FATAL("Could not open file '{:s}' for output.", file_name_ele_g);
1146 }
1147
1148 for (std::size_t i = 0; i < partitions.size(); i++)
1149 {
1150 const auto& partition = partitions[i];
1151 auto const local_node_ids = enumerateLocalNodeIds(partition.nodes);
1152
1153 // Vector containing the offsets of the regular elements of this
1154 // partition
1155 std::vector<long> ele_info(regular_element_offsets[i]);
1156
1157 auto writeElementData =
1158 [&local_node_ids](
1159 std::vector<MeshLib::Element const*> const& elements,
1160 long const element_offsets,
1161 std::ofstream& output_stream)
1162 {
1163 long counter = elements.size();
1164 std::vector<long> ele_info(element_offsets);
1165
1166 for (std::size_t j = 0; j < elements.size(); j++)
1167 {
1168 const auto* elem = elements[j];
1169 ele_info[j] = counter;
1170 getElementIntegerVariables(*elem, local_node_ids, ele_info,
1171 counter);
1172 }
1173 // Write vector data of regular elements
1174 output_stream.write(reinterpret_cast<const char*>(ele_info.data()),
1175 ele_info.size() * sizeof(long));
1176 };
1177
1178 // regular elements.
1179 writeElementData(partition.regular_elements, regular_element_offsets[i],
1180 element_info_os);
1181 // Ghost elements
1182 writeElementData(partition.ghost_elements, ghost_element_offsets[i],
1183 ghost_element_info_os);
1184 }
1185}
void getElementIntegerVariables(const MeshLib::Element &elem, const std::unordered_map< std::size_t, long > &local_node_ids, std::vector< long > &elem_info, long &counter)
std::unordered_map< std::size_t, long > enumerateLocalNodeIds(std::vector< MeshLib::Node * > const &nodes)
Generates a mapping of given node ids to a new local (renumbered) node ids.

References enumerateLocalNodeIds(), getElementIntegerVariables(), and OGS_FATAL.

Referenced by ApplicationUtils::NodeWiseMeshPartitioner::write(), and ApplicationUtils::NodeWiseMeshPartitioner::writeOtherMesh().

◆ writeMETIS()

void ApplicationUtils::writeMETIS ( std::vector< MeshLib::Element * > const &  elements,
const std::string &  file_name 
)

Write elements as METIS graph file

Parameters
elementsThe mesh elements.
file_nameFile name with an extension of mesh.

Definition at line 19 of file Metis.cpp.

21{
22 std::ofstream os(file_name, std::ios::trunc);
23 if (!os.is_open())
24 {
25 OGS_FATAL("Error: cannot open file {:s}.", file_name.data());
26 }
27
28 if (!os.good())
29 {
30 OGS_FATAL("Error: Cannot write in file {:s}.", file_name.data());
31 }
32
33 os << elements.size() << " \n";
34 for (const auto* elem : elements)
35 {
36 os << getNodeIndex(*elem, 0) + 1;
37 for (unsigned j = 1; j < elem->getNumberOfNodes(); j++)
38 {
39 os << " " << getNodeIndex(*elem, j) + 1;
40 }
41 os << "\n";
42 }
43}
std::size_t getNodeIndex(Element const &element, unsigned const idx)
Definition: Element.cpp:219

References OGS_FATAL.

Referenced by main().

◆ writeNodes()

void ApplicationUtils::writeNodes ( const std::string &  file_name_base,
std::vector< Partition > const &  partitions,
std::vector< std::size_t > const &  global_node_ids 
)

Write the nodes of all partitions into a binary file.

Parameters
file_name_baseThe prefix of the file name.
partitionsthe list of partitions
global_node_idsglobal numbering of nodes

Definition at line 1191 of file NodeWiseMeshPartitioner.cpp.

1194{
1195 auto const file_name = file_name_base + "_partitioned_msh_nod" +
1196 std::to_string(partitions.size()) + ".bin";
1197 std::ofstream os(file_name, std::ios::binary);
1198 if (!os)
1199 {
1200 OGS_FATAL("Could not open file '{:s}' for output.", file_name);
1201 }
1202
1203 for (const auto& partition : partitions)
1204 {
1205 partition.writeNodes(os, global_node_ids);
1206 }
1207}

References OGS_FATAL.

Referenced by ApplicationUtils::NodeWiseMeshPartitioner::write(), and ApplicationUtils::NodeWiseMeshPartitioner::writeOtherMesh().

◆ writeProperties()

void ApplicationUtils::writeProperties ( const std::string &  file_name_base,
MeshLib::Properties const &  partitioned_properties,
std::vector< Partition > const &  partitions,
MeshLib::MeshItemType const  mesh_item_type 
)

Definition at line 924 of file NodeWiseMeshPartitioner.cpp.

928{
929 auto const number_of_properties =
930 partitioned_properties.size(mesh_item_type);
931 if (number_of_properties == 0)
932 {
933 return;
934 }
935
936 auto const file_name_infix = toString(mesh_item_type);
937
938 auto const file_name_cfg = file_name_base + "_partitioned_" +
939 file_name_infix + "_properties_cfg" +
940 std::to_string(partitions.size()) + ".bin";
941 std::ofstream out(file_name_cfg, std::ios::binary);
942 if (!out)
943 {
944 OGS_FATAL("Could not open file '{:s}' for output.", file_name_cfg);
945 }
946
947 auto const file_name_val = file_name_base + "_partitioned_" +
948 file_name_infix + "_properties_val" +
949 std::to_string(partitions.size()) + ".bin";
950 std::ofstream out_val(file_name_val, std::ios::binary);
951 if (!out_val)
952 {
953 OGS_FATAL("Could not open file '{:s}' for output.", file_name_val);
954 }
955
956 BaseLib::writeValueBinary(out, number_of_properties);
957
959 partitioned_properties,
960 [&](auto type, auto const& property)
961 {
962 return writePropertyVector<decltype(type)>(
963 dynamic_cast<MeshLib::PropertyVector<decltype(type)> const*>(
964 property),
965 mesh_item_type, out_val, out);
966 });
967
968 unsigned long offset = 0;
969 for (const auto& partition : partitions)
970 {
972 offset, static_cast<unsigned long>(
973 partition.numberOfMeshItems(mesh_item_type))};
974 DBUG(
975 "Write meta data for node-based PropertyVector: global offset "
976 "{:d}, number of tuples {:d}",
977 pvpmd.offset, pvpmd.number_of_tuples);
979 offset += pvpmd.number_of_tuples;
980 }
981}
void writeValueBinary(std::ostream &out, T const &val)
write value as binary into the given output stream
Definition: FileTools.cpp:323
void writePropertyVectorPartitionMetaData(std::ostream &os, PropertyVectorPartitionMetaData const &pvpmd)

References applyToPropertyVectors(), DBUG(), OGS_FATAL, MeshLib::Properties::size(), MeshLib::IO::writePropertyVectorPartitionMetaData(), and BaseLib::writeValueBinary().

Referenced by ApplicationUtils::NodeWiseMeshPartitioner::write(), and ApplicationUtils::NodeWiseMeshPartitioner::writeOtherMesh().

◆ writePropertyVector()

template<typename T >
bool ApplicationUtils::writePropertyVector ( MeshLib::PropertyVector< T > const *const  pv,
MeshLib::MeshItemType const  mesh_item_type,
std::ostream &  out_val,
std::ostream &  out_meta 
)

Definition at line 899 of file NodeWiseMeshPartitioner.cpp.

902{
903 if (pv == nullptr)
904 {
905 return false;
906 }
907 // skip property of different mesh item type. Return true, because this
908 // operation was successful.
909 if (pv->getMeshItemType() != mesh_item_type)
910 {
911 return true;
912 }
913
915 pvmd.property_name = pv->getPropertyName();
919 writePropertyVectorValues(out_val, *pv);
921 return true;
922}
std::size_t getNumberOfTuples() const
void writePropertyVectorValues(std::ostream &os, MeshLib::PropertyVector< T > const &pv)
void writePropertyVectorMetaData(std::ostream &os, PropertyVectorMetaData const &pvmd)

References MeshLib::IO::PropertyVectorMetaData::fillPropertyVectorMetaDataTypeInfo(), MeshLib::PropertyVectorBase::getMeshItemType(), MeshLib::PropertyVectorBase::getNumberOfGlobalComponents(), MeshLib::PropertyVector< PROP_VAL_TYPE >::getNumberOfTuples(), MeshLib::PropertyVectorBase::getPropertyName(), MeshLib::IO::PropertyVectorMetaData::number_of_components, MeshLib::IO::PropertyVectorMetaData::number_of_tuples, MeshLib::IO::PropertyVectorMetaData::property_name, MeshLib::IO::writePropertyVectorMetaData(), and writePropertyVectorValues().

◆ writePropertyVectorValues()

template<typename T >
void ApplicationUtils::writePropertyVectorValues ( std::ostream &  os,
MeshLib::PropertyVector< T > const &  pv 
)

Definition at line 892 of file NodeWiseMeshPartitioner.cpp.

894{
895 os.write(reinterpret_cast<const char*>(pv.data()), pv.size() * sizeof(T));
896}

References MeshLib::PropertyVector< PROP_VAL_TYPE >::size().

Referenced by writePropertyVector().