OGS
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
ipDataToPointCloud.cpp File Reference

Detailed Description

Definition in file ipDataToPointCloud.cpp.

#include <tclap/CmdLine.h>
#include <unordered_map>
#include "BaseLib/MPI.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Utils/IntegrationPointWriter.h"
#include "NumLib/Fem/InitShapeMatrices.h"
#include "NumLib/Fem/ShapeMatrixCache.h"
Include dependency graph for ipDataToPointCloud.cpp:

Go to the source code of this file.

Classes

struct  CellTypeOfTemplateElement< MeshLib::TemplateElement< ElementRule > >
 

Functions

template<typename MeshElement >
std::vector< std::array< double, 3 > > interpolateElementCoords (MeshLib::Element const &e, NumLib::ShapeMatrixCache const &sm_cache)
 
std::unordered_map< MeshLib::CellType, std::vector< std::array< double, 3 > >(*)(MeshLib::Element const &, NumLib::ShapeMatrixCache const &)> createElementCoordInterpolatorsForAllElementTypes ()
 
std::vector< MeshLib::Node * > computePointCloudNodes (MeshLib::Mesh const &mesh, unsigned const integration_order)
 
unsigned determineIntegrationOrder (MeshLib::Mesh const &mesh)
 
void copyDoubleValuedFieldDataToPointCloud (MeshLib::Properties const &props_in, MeshLib::Properties &props_out, std::size_t const num_ips)
 
int main (int argc, char **argv)
 

Function Documentation

◆ computePointCloudNodes()

std::vector< MeshLib::Node * > computePointCloudNodes ( MeshLib::Mesh const & mesh,
unsigned const integration_order )

Definition at line 92 of file ipDataToPointCloud.cpp.

94{
95 NumLib::ShapeMatrixCache sm_cache{integration_order};
96 auto const map_cell_type_to_element_coords_interpolator =
98
99 std::vector<MeshLib::Node*> nodes;
100
101 for (auto const* element : mesh.getElements())
102 {
103 auto const cell_type = element->getCellType();
104
105 auto const it =
106 map_cell_type_to_element_coords_interpolator.find(cell_type);
107 if (it == map_cell_type_to_element_coords_interpolator.end())
108 {
109 OGS_FATAL("Unsupported cell type {} for element #{}",
110 MeshLib::CellType2String(cell_type), element->getID());
111 }
112
113 auto const& element_coords_interpolator = it->second;
114 auto const coords = element_coords_interpolator(*element, sm_cache);
115
116 for (auto& cs : coords)
117 {
118 nodes.push_back(new MeshLib::Node(cs, nodes.size()));
119 }
120 }
121
122 return nodes;
123}
#define OGS_FATAL(...)
Definition Error.h:26
std::unordered_map< MeshLib::CellType, std::vector< std::array< double, 3 > >(*)(MeshLib::Element const &, NumLib::ShapeMatrixCache const &)> createElementCoordInterpolatorsForAllElementTypes()
constexpr ranges::views::view_closure coords
Definition Mesh.h:234
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.

References MeshLib::CellType2String(), createElementCoordInterpolatorsForAllElementTypes(), MeshLib::Mesh::getElements(), and OGS_FATAL.

Referenced by main().

◆ copyDoubleValuedFieldDataToPointCloud()

void copyDoubleValuedFieldDataToPointCloud ( MeshLib::Properties const & props_in,
MeshLib::Properties & props_out,
std::size_t const num_ips )

Definition at line 168 of file ipDataToPointCloud.cpp.

171{
172 for (auto const& [prop_name, prop_in] : props_in)
173 {
174 auto const mesh_item_type = prop_in->getMeshItemType();
175
176 if (mesh_item_type != MeshLib::MeshItemType::IntegrationPoint)
177 {
178 continue;
179 }
180
181 auto const num_comp = prop_in->getNumberOfGlobalComponents();
182 auto const* prop_in_double =
183 dynamic_cast<MeshLib::PropertyVector<double> const*>(prop_in);
184
185 if (prop_in_double == nullptr)
186 {
187 INFO(
188 "Ignoring non-double-valued property '{}' with {} components "
189 "on {}",
190 prop_name, num_comp, toString(mesh_item_type));
191 continue;
192 }
193
194 DBUG("Converting property '{}' with {} components on {}", prop_name,
195 num_comp, toString(mesh_item_type));
196
197 if (props_out.existsPropertyVector<double>(prop_name))
198 {
199 OGS_FATAL(
200 "A property vector with name '{}' already exists. Not "
201 "adding it again",
202 prop_name);
203 }
204
205 if (auto const num_ips_actual = prop_in_double->getNumberOfTuples();
206 num_ips_actual != num_ips)
207 {
208 WARN(
209 "Property vector '{}' has {} tuples, which differs from "
210 "the number of integration points ({}). Skipping this "
211 "property.",
212 prop_name, num_ips_actual, num_ips);
213 }
214
215 auto* prop_out = props_out.createNewPropertyVector<double>(
216 prop_name, MeshLib::MeshItemType::Node, num_comp);
217
218 prop_out->assign(prop_in_double->begin(), prop_in_double->end());
219 }
220}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
bool existsPropertyVector(std::string_view name) const
Definition Properties.h:74
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
Definition Properties.h:17
const char * toString(mgis::behaviour::Behaviour::Kinematic kin)

References MeshLib::Properties::createNewPropertyVector(), DBUG(), MeshLib::Properties::existsPropertyVector(), INFO(), MeshLib::IntegrationPoint, MeshLib::Node, OGS_FATAL, and WARN().

Referenced by main().

◆ createElementCoordInterpolatorsForAllElementTypes()

std::unordered_map< MeshLib::CellType, std::vector< std::array< double, 3 > >(*)( MeshLib::Element const &, NumLib::ShapeMatrixCache const &)> createElementCoordInterpolatorsForAllElementTypes ( )

Definition at line 58 of file ipDataToPointCloud.cpp.

59{
60 std::unordered_map<MeshLib::CellType,
61 std::vector<std::array<double, 3>> (*)(
62 MeshLib::Element const&,
64 map_cell_type_to_element_coords_interpolator;
65
66 map_cell_type_to_element_coords_interpolator.reserve(
67 boost::mp11::mp_size<NumLib::AllElementTraitsLagrange>::value);
68
69 boost::mp11::mp_for_each<NumLib::AllElementTraitsLagrange>(
70 [&map_cell_type_to_element_coords_interpolator]<typename ETL>(ETL)
71 {
72 using MeshElement = typename ETL::Element;
73 auto constexpr cell_type =
75
76 auto const [it, newly_inserted] =
77 map_cell_type_to_element_coords_interpolator.emplace(
79
80 if (!newly_inserted)
81 {
83 "Coordinate interpolator for cell type {} is already "
84 "present",
85 MeshLib::CellType2String(cell_type));
86 }
87 });
88
89 return map_cell_type_to_element_coords_interpolator;
90}
std::vector< std::array< double, 3 > > interpolateElementCoords(MeshLib::Element const &e, NumLib::ShapeMatrixCache const &sm_cache)
CellType
Types of mesh elements supported by OpenGeoSys.
Definition MeshEnums.h:64

References MeshLib::CellType2String(), interpolateElementCoords(), and OGS_FATAL.

Referenced by computePointCloudNodes().

◆ determineIntegrationOrder()

unsigned determineIntegrationOrder ( MeshLib::Mesh const & mesh)

Definition at line 125 of file ipDataToPointCloud.cpp.

126{
127 auto const& properties = mesh.getProperties();
128 auto const ip_meta_data = MeshLib::getIntegrationPointMetaData(properties);
129
130 std::optional<unsigned> integration_order;
131
132 for (auto const& [name, property] : properties)
133 {
134 if (property->getMeshItemType() !=
136 {
137 continue;
138 }
139
140 if (name == "IntegrationPointMetaData" || name == "OGS_VERSION")
141 {
142 continue;
143 }
144
145 auto const order =
148
149 if (!integration_order)
150 {
151 integration_order = order;
152 }
153 else if (integration_order != order)
154 {
155 OGS_FATAL("Integration orders differ: {} != {}", *integration_order,
156 order);
157 }
158 }
159
160 if (!integration_order)
161 {
162 OGS_FATAL("Integration order could not be determined.");
163 }
164
165 return *integration_order;
166}
std::optional< IntegrationPointMetaData > getIntegrationPointMetaData(MeshLib::Properties const &properties)
IntegrationPointMetaDataSingleField getIntegrationPointMetaDataSingleField(std::optional< IntegrationPointMetaData > const &ip_meta_data, std::string const &field_name)

References MeshLib::getIntegrationPointMetaData(), MeshLib::getIntegrationPointMetaDataSingleField(), MeshLib::Mesh::getProperties(), MeshLib::IntegrationPointMetaDataSingleField::integration_order, MeshLib::IntegrationPoint, and OGS_FATAL.

Referenced by main().

◆ interpolateElementCoords()

template<typename MeshElement >
std::vector< std::array< double, 3 > > interpolateElementCoords ( MeshLib::Element const & e,
NumLib::ShapeMatrixCache const & sm_cache )

Definition at line 24 of file ipDataToPointCloud.cpp.

26{
27 constexpr int dim = MeshElement::dimension;
28 using ShapeFunction =
31
32 auto const& Ns = sm_cache.NsHigherOrder<MeshElement>();
33 std::vector<std::array<double, 3>> coords;
34 coords.reserve(Ns.size());
35
36 for (auto const& N : Ns)
37 {
38 coords.push_back(
40 }
41
42 return coords;
43}
boost::mp11::mp_at< ShapeFunctionsHigherOrder, boost::mp11::mp_find< MeshElements, MeshElement > > ShapeFunctionHigherOrder
std::array< double, 3 > interpolateCoordinates(MeshLib::Element const &e, typename ShapeMatricesType::ShapeMatrices::ShapeType const &N)

References NumLib::interpolateCoordinates(), and NumLib::ShapeMatrixCache::NsHigherOrder().

Referenced by createElementCoordInterpolatorsForAllElementTypes().

◆ main()

int main ( int argc,
char ** argv )

Definition at line 222 of file ipDataToPointCloud.cpp.

223{
224 // TODO future additions to this tool might include:
225 // -C --copy-cell-data
226 // -N --interpolate-node-data
227 // -I --add-cell-ids
228 // -O --integration-order
229 // --natural-coords add natural coordinates of integration points, or better
230 // not?
231 // --no-data
232 // --linear-shape-functions={pressure, ...} for the interpolation of nodal
233 // data
234 // PVD support
235 // handle other data than only double data
236
237 TCLAP::CmdLine cmd(
238 "Creates a point cloud mesh for the integration point data existing on "
239 "a given input mesh.\n\n"
240 "OpenGeoSys-6 software, version " +
242 ".\n"
243 "Copyright (c) 2012-2025, OpenGeoSys Community "
244 "(http://www.opengeosys.org)",
246 TCLAP::ValueArg<std::string> arg_out_file(
247 "o", "output-file", "the output mesh (point cloud, VTU file)", true, "",
248 "path");
249 cmd.add(arg_out_file);
250 TCLAP::ValueArg<std::string> arg_in_file(
251 "i", "input-file", "the input mesh (VTU file)", true, "", "path");
252 cmd.add(arg_in_file);
253
254 cmd.parse(argc, argv);
255
256 BaseLib::MPI::Setup mpi_setup(argc, argv);
257
258 std::unique_ptr<MeshLib::Mesh const> mesh_in(
259 MeshLib::IO::readMeshFromFile(arg_in_file.getValue()));
260
261 auto const integration_order = determineIntegrationOrder(*mesh_in);
262 auto nodes = computePointCloudNodes(*mesh_in, integration_order);
263
264 MeshLib::Mesh point_cloud("point_cloud", std::move(nodes), {});
265
266 copyDoubleValuedFieldDataToPointCloud(mesh_in->getProperties(),
267 point_cloud.getProperties(),
268 point_cloud.getNumberOfNodes());
269
270 MeshLib::IO::writeMeshToFile(point_cloud, arg_out_file.getValue());
271
272 return EXIT_SUCCESS;
273}
unsigned determineIntegrationOrder(MeshLib::Mesh const &mesh)
std::vector< MeshLib::Node * > computePointCloudNodes(MeshLib::Mesh const &mesh, unsigned const integration_order)
void copyDoubleValuedFieldDataToPointCloud(MeshLib::Properties const &props_in, MeshLib::Properties &props_out, std::size_t const num_ips)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)

References computePointCloudNodes(), copyDoubleValuedFieldDataToPointCloud(), determineIntegrationOrder(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), and MeshLib::IO::writeMeshToFile().