OGS
MeshToolsLib::anonymous_namespace{OverwriteMeshFieldDataByMaterialIDs.cpp} Namespace Reference

Classes

struct  WriteGroup

Functions

std::vector< WriteGroupcollectWriteGroups (InitialConditionDataSet const &initial_condition, MeshLib::PropertyVector< double > const &pv, MeshLib::Properties const &properties)

Function Documentation

◆ collectWriteGroups()

std::vector< WriteGroup > MeshToolsLib::anonymous_namespace{OverwriteMeshFieldDataByMaterialIDs.cpp}::collectWriteGroups ( InitialConditionDataSet const & initial_condition,
MeshLib::PropertyVector< double > const & pv,
MeshLib::Properties const & properties )

Collects the write groups for initial_condition according to its mesh item type. The three supported item types (integration point, cell, node) differ only in which slots are written and where a parameter is evaluated; everything else is shared by overwriteMeshFieldDataByMaterialIDs().

Definition at line 37 of file OverwriteMeshFieldDataByMaterialIDs.cpp.

41{
42 auto const& mesh = *initial_condition.mesh;
43 auto const& element_ids =
44 initial_condition.element_ids_for_selected_materials;
45
46 std::vector<WriteGroup> groups;
47
48 switch (initial_condition.mesh_item_type)
49 {
51 {
52 auto const element_ip_data_offsets =
54 pv, properties);
55 // getIntegrationPointDataOffsetsOfMeshElements() returns an empty
56 // vector for a property whose name does not contain "_ip" (it is
57 // then not treated as integration-point data). Indexing it by
58 // element id below would be an out-of-bounds access.
59 if (element_ip_data_offsets.empty())
60 {
62 "overwrite_mesh_data: integration-point property '{:s}' "
63 "carries no integration-point data offsets. Only fields "
64 "whose name contains '_ip' are treated as "
65 "integration-point data.",
66 initial_condition.variable_name);
67 }
68 auto const n = pv.getNumberOfGlobalComponents();
69 groups.reserve(element_ids.size());
70 for (auto const element_id : element_ids)
71 {
72 // A parameter is evaluated once per element at the centroid and
73 // written to all of the element's integration points (a single
74 // write group spanning them). This is exact for the intended
75 // constant-per-material use case. Do not turn this into a
76 // per-integration-point evaluation without also reproducing the
77 // exact integration rule and point ordering used by the process
78 // local assembler that wrote this field: computing the points
79 // in a different order would associate values with the wrong
80 // slots.
82 pos.setElementID(element_id);
84 MeshLib::getCenterOfGravity(*mesh.getElement(element_id)));
85 // The offsets are flat (already multiplied by the number of
86 // components); divide to obtain slot (integration point)
87 // indices.
88 groups.push_back({pos, element_ip_data_offsets[element_id] / n,
89 element_ip_data_offsets[element_id + 1] / n});
90 }
91 break;
92 }
94 {
95 groups.reserve(element_ids.size());
96 for (auto const element_id : element_ids)
97 {
98 ParameterLib::SpatialPosition pos;
99 pos.setElementID(element_id);
100 pos.setCoordinates(
101 MeshLib::getCenterOfGravity(*mesh.getElement(element_id)));
102 groups.push_back({pos, element_id, element_id + 1});
103 }
104 break;
105 }
107 {
108 for (auto const element_id : element_ids)
109 {
110 for (auto const* node : mesh.getElement(element_id)->nodes())
111 {
112 std::size_t const node_id = node->getID();
113 // Evaluate the parameter at the node position, not the
114 // element centre.
115 groups.push_back(
116 {ParameterLib::SpatialPosition{node_id, {}, *node},
117 node_id, node_id + 1});
118 }
119 }
120 break;
121 }
122 default:
123 OGS_FATAL(
124 "The mesh item type of the initial condition for property "
125 "'{:s}' is not supported. Only integration point, cell, and "
126 "node data are supported.",
127 initial_condition.variable_name);
128 }
129
130 return groups;
131}
#define OGS_FATAL(...)
Definition Error.h:10
int getNumberOfGlobalComponents() const
void setCoordinates(MathLib::Point3d const &coordinates)
void setElementID(std::size_t element_id)
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition Element.cpp:131
std::vector< std::size_t > getIntegrationPointDataOffsetsOfMeshElements(std::vector< MeshLib::Element * > const &mesh_elements, MeshLib::PropertyVectorBase const &pv, MeshLib::Properties const &properties)

References MeshLib::Cell, collectWriteGroups(), MeshToolsLib::InitialConditionDataSet::element_ids_for_selected_materials, MeshLib::getCenterOfGravity(), MeshToolsLib::getIntegrationPointDataOffsetsOfMeshElements(), MeshLib::PropertyVectorBase::getNumberOfGlobalComponents(), MeshLib::IntegrationPoint, MeshToolsLib::InitialConditionDataSet::mesh, MeshToolsLib::InitialConditionDataSet::mesh_item_type, MeshLib::Node, OGS_FATAL, ParameterLib::SpatialPosition::setCoordinates(), ParameterLib::SpatialPosition::setElementID(), and MeshToolsLib::InitialConditionDataSet::variable_name.

Referenced by collectWriteGroups().