OGS
anonymous_namespace{ProjectData.cpp} Namespace Reference

Functions

void readGeometry (std::string const &fname, GeoLib::GEOObjects &geo_objects, std::string const &dir_first, std::string const &dir_second)
std::unique_ptr< MeshLib::MeshreadSingleMesh (BaseLib::ConfigTree const &mesh_config_parameter, std::string const &directory)
std::vector< std::unique_ptr< MeshLib::Mesh > > readMeshes (BaseLib::ConfigTree const &config, std::string const &directory)
std::vector< GeoLib::NamedRasterreadRasters (BaseLib::ConfigTree const &config, GeoLib::MinMaxPoints const &min_max_points)

Function Documentation

◆ readGeometry()

void anonymous_namespace{ProjectData.cpp}::readGeometry ( std::string const & fname,
GeoLib::GEOObjects & geo_objects,
std::string const & dir_first,
std::string const & dir_second )

Definition at line 138 of file ProjectData.cpp.

140{
141 DBUG("Reading geometry file '{:s}'.", fname);
142 GeoLib::IO::BoostXmlGmlInterface gml_reader(geo_objects);
143 std::string geometry_file = BaseLib::joinPaths(dir_first, fname);
144 if (!BaseLib::IsFileExisting(geometry_file))
145 {
146 // Fallback to reading gml from prj-file directory
147 geometry_file = BaseLib::joinPaths(dir_second, fname);
148 WARN("File {:s} not found in {:s}! Trying reading from {:s}.", fname,
149 dir_first, dir_second);
150 if (!BaseLib::IsFileExisting(geometry_file))
151 {
152 OGS_FATAL("Could not read geometry file {:s} in {:s}.", fname,
153 dir_second);
154 }
155 }
156 gml_reader.readFile(geometry_file);
157}
#define OGS_FATAL(...)
Definition Error.h:19
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
bool IsFileExisting(const std::string &strFilename)
Returns true if given file exists.
Definition FileTools.cpp:23
std::string joinPaths(std::string const &pathA, std::string const &pathB)

References DBUG(), BaseLib::IsFileExisting(), BaseLib::joinPaths(), OGS_FATAL, GeoLib::IO::BoostXmlGmlInterface::readFile(), and WARN().

Referenced by readMeshes().

◆ readMeshes()

std::vector< std::unique_ptr< MeshLib::Mesh > > anonymous_namespace{ProjectData.cpp}::readMeshes ( BaseLib::ConfigTree const & config,
std::string const & directory )
Input File Parameter
prj__meshes
Input File Parameter
prj__meshes__mesh
Input File Parameter
prj__geometry
Input File Parameter
prj__mesh
Input File Parameter
prj__geometry
Input File Parameter
prj__zero_mesh_field_data_by_material_ids

Definition at line 206 of file ProjectData.cpp.

208{
209 std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
210
211 GeoLib::GEOObjects geoObjects;
212
214 auto optional_meshes = config.getConfigSubtreeOptional("meshes");
215 if (optional_meshes)
216 {
217 DBUG("Reading multiple meshes.");
219 auto const configs = optional_meshes->getConfigParameterList("mesh");
220 std::transform(configs.begin(), configs.end(),
221 std::back_inserter(meshes),
222 [&directory](auto const& mesh_config)
223 { return readSingleMesh(mesh_config, directory); });
224 if (auto const geometry_file_name =
226 config.getConfigParameterOptional<std::string>("geometry"))
227 {
228 readGeometry(*geometry_file_name, geoObjects, directory,
229 config.projectDirectory().string());
230 }
231 }
232 else
233 { // Read single mesh with geometry.
234 meshes.push_back(
236 readSingleMesh(config.getConfigParameter("mesh"), directory));
237
238 auto const geometry_file_name =
240 config.getConfigParameter<std::string>("geometry");
241 readGeometry(geometry_file_name, geoObjects, directory,
242 config.projectDirectory().string());
243 }
244
245 if (!geoObjects.getPoints().empty() || !geoObjects.getPolylines().empty() ||
246 !geoObjects.getSurfaces().empty())
247 { // generate meshes from geometries
248 std::unique_ptr<MeshGeoToolsLib::SearchLength> search_length_algorithm =
250 bool const multiple_nodes_allowed = false;
251 auto additional_meshes =
253 geoObjects, *meshes[0], std::move(search_length_algorithm),
254 multiple_nodes_allowed);
255
256 std::move(begin(additional_meshes), end(additional_meshes),
257 std::back_inserter(meshes));
258 }
259
260 auto mesh_names = MeshLib::views::names | ranges::to<std::vector>() |
261 ranges::actions::sort;
262 auto const sorted_names = meshes | mesh_names;
263 auto const unique_names = meshes | mesh_names | ranges::actions::unique;
264 if (unique_names.size() < sorted_names.size())
265 {
266 WARN(
267 "Mesh names aren't unique. From project file read mesh names are:");
268 for (auto const& name : meshes | MeshLib::views::names)
269 {
270 INFO("- {}", name);
271 }
272 }
273
274 auto const zero_mesh_field_data_by_material_ids =
276 config.getConfigParameterOptional<std::vector<int>>(
277 "zero_mesh_field_data_by_material_ids");
278 if (zero_mesh_field_data_by_material_ids)
279 {
280 WARN(
281 "Tag 'zero_mesh_field_data_by_material_ids` is experimental. Its "
282 "name may be changed, or it may be removed due to its "
283 "corresponding feature becomes a single tool. Please use it with "
284 "care!");
286 *meshes[0], *zero_mesh_field_data_by_material_ids);
287 }
288
290
291 return meshes;
292}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
Container class for geometric objects.
Definition GEOObjects.h:46
std::vector< PolylineVec * > const & getPolylines() const
Read access to polylines w/o using a name.
Definition GEOObjects.h:288
std::vector< PointVec * > const & getPoints() const
Read access to points w/o using a name.
Definition GEOObjects.h:286
std::vector< SurfaceVec * > const & getSurfaces() const
Read access to surfaces w/o using a name.
Definition GEOObjects.h:290
std::unique_ptr< MeshGeoToolsLib::SearchLength > createSearchLengthAlgorithm(BaseLib::ConfigTree const &external_config, MeshLib::Mesh const &mesh)
std::vector< std::unique_ptr< MeshLib::Mesh > > constructAdditionalMeshesFromGeoObjects(GeoLib::GEOObjects const &geo_objects, MeshLib::Mesh const &mesh, std::unique_ptr< SearchLength > search_length_algorithm, bool const multiple_nodes_allowed)
constexpr ranges::views::view_closure names
For an element of a range view return its name.
Definition Mesh.h:220
void setMeshSpaceDimension(std::vector< std::unique_ptr< Mesh > > const &meshes)
void zeroMeshFieldDataByMaterialIDs(MeshLib::Mesh &mesh, std::vector< int > const &selected_material_ids)
void readGeometry(std::string const &fname, GeoLib::GEOObjects &geo_objects, std::string const &dir_first, std::string const &dir_second)
std::unique_ptr< MeshLib::Mesh > readSingleMesh(BaseLib::ConfigTree const &mesh_config_parameter, std::string const &directory)

References MeshGeoToolsLib::constructAdditionalMeshesFromGeoObjects(), MeshGeoToolsLib::createSearchLengthAlgorithm(), DBUG(), BaseLib::ConfigTree::getConfigParameter(), BaseLib::ConfigTree::getConfigParameterOptional(), BaseLib::ConfigTree::getConfigSubtreeOptional(), GeoLib::GEOObjects::getPoints(), GeoLib::GEOObjects::getPolylines(), GeoLib::GEOObjects::getSurfaces(), INFO(), MeshLib::views::names, BaseLib::ConfigTree::projectDirectory(), readGeometry(), readSingleMesh(), MeshLib::setMeshSpaceDimension(), WARN(), and MeshToolsLib::zeroMeshFieldDataByMaterialIDs().

◆ readRasters()

std::vector< GeoLib::NamedRaster > anonymous_namespace{ProjectData.cpp}::readRasters ( BaseLib::ConfigTree const & config,
GeoLib::MinMaxPoints const & min_max_points )
Input File Parameter
prj__rasters
Input File Parameter
prj__rasters__raster

Definition at line 294 of file ProjectData.cpp.

297{
298 INFO("readRasters ...");
299 std::vector<GeoLib::NamedRaster> named_rasters;
300
302 auto optional_rasters = config.getConfigSubtreeOptional("rasters");
303 if (optional_rasters)
304 {
306 auto const configs = optional_rasters->getConfigSubtreeList("raster");
307 std::transform(
308 configs.begin(), configs.end(), std::back_inserter(named_rasters),
309 [&min_max_points](auto const& raster_config)
310 { return GeoLib::IO::readRaster(raster_config, min_max_points); });
311 }
312 INFO("readRasters done");
313 return named_rasters;
314}

References BaseLib::ConfigTree::getConfigSubtreeOptional(), and INFO().

◆ readSingleMesh()

std::unique_ptr< MeshLib::Mesh > anonymous_namespace{ProjectData.cpp}::readSingleMesh ( BaseLib::ConfigTree const & mesh_config_parameter,
std::string const & directory )
Input File Parameter
prj__meshes__mesh__axially_symmetric
Input File Parameter
prj__mesh__axially_symmetric

Definition at line 159 of file ProjectData.cpp.

162{
163 std::string const mesh_file = BaseLib::joinPaths(
164 directory, mesh_config_parameter.getValue<std::string>());
165 DBUG("Reading mesh file '{:s}'.", mesh_file);
166
167 auto mesh = std::unique_ptr<MeshLib::Mesh>(MeshLib::IO::readMeshFromFile(
168 mesh_file, true /* compute_element_neighbors */));
169 if (!mesh)
170 {
171 std::filesystem::path abspath{mesh_file};
172 try
173 {
174 abspath = std::filesystem::absolute(mesh_file);
175 }
176 catch (std::filesystem::filesystem_error const& e)
177 {
178 ERR("Determining the absolute path of '{}' failed: {}", mesh_file,
179 e.what());
180 }
181
182 OGS_FATAL("Could not read mesh from '{:s}' file. No mesh added.",
183 abspath.string());
184 }
185
186#ifdef DOXYGEN_DOCU_ONLY
188 mesh_config_parameter.getConfigAttributeOptional<bool>("axially_symmetric");
189#endif // DOXYGEN_DOCU_ONLY
190
191 if (auto const axially_symmetric =
193 mesh_config_parameter.getConfigAttributeOptional<bool>(
194 "axially_symmetric"))
195 {
196 mesh->setAxiallySymmetric(*axially_symmetric);
197 if (mesh->getDimension() == 3 && mesh->isAxiallySymmetric())
198 {
199 OGS_FATAL("3D mesh cannot be axially symmetric.");
200 }
201 }
202
203 return mesh;
204}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)

References DBUG(), ERR(), BaseLib::ConfigTree::getConfigAttributeOptional(), BaseLib::ConfigTree::getValue(), BaseLib::joinPaths(), OGS_FATAL, and MeshLib::IO::readMeshFromFile().

Referenced by readMeshes().