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 330 of file ProjectData.cpp.

332{
333 DBUG("Reading geometry file '{:s}'.", fname);
334 GeoLib::IO::BoostXmlGmlInterface gml_reader(geo_objects);
335 std::string geometry_file = BaseLib::joinPaths(dir_first, fname);
336 if (!BaseLib::IsFileExisting(geometry_file))
337 {
338 // Fallback to reading gml from prj-file directory
339 geometry_file = BaseLib::joinPaths(dir_second, fname);
340 WARN("File {:s} not found in {:s}! Trying reading from {:s}.", fname,
341 dir_first, dir_second);
342 if (!BaseLib::IsFileExisting(geometry_file))
343 {
344 OGS_FATAL("Could not read geometry file {:s} in {:s}.", fname,
345 dir_second);
346 }
347 }
348 gml_reader.readFile(geometry_file);
349}
#define OGS_FATAL(...)
Definition Error.h:10
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 398 of file ProjectData.cpp.

400{
401 std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
402
403 GeoLib::GEOObjects geoObjects;
404
406 auto optional_meshes = config.getConfigSubtreeOptional("meshes");
407 if (optional_meshes)
408 {
409 DBUG("Reading multiple meshes.");
411 auto const configs = optional_meshes->getConfigParameterList("mesh");
412 std::transform(configs.begin(), configs.end(),
413 std::back_inserter(meshes),
414 [&directory](auto const& mesh_config)
415 { return readSingleMesh(mesh_config, directory); });
416 if (auto const geometry_file_name =
418 config.getConfigParameterOptional<std::string>("geometry"))
419 {
420 readGeometry(*geometry_file_name, geoObjects, directory,
421 config.projectDirectory().string());
422 }
423 }
424 else
425 { // Read single mesh with geometry.
426 meshes.push_back(
428 readSingleMesh(config.getConfigParameter("mesh"), directory));
429
430 auto const geometry_file_name =
432 config.getConfigParameter<std::string>("geometry");
433 readGeometry(geometry_file_name, geoObjects, directory,
434 config.projectDirectory().string());
435 }
436
437 if (!geoObjects.getPoints().empty() || !geoObjects.getPolylines().empty() ||
438 !geoObjects.getSurfaces().empty())
439 { // generate meshes from geometries
440 std::unique_ptr<MeshGeoToolsLib::SearchLength> search_length_algorithm =
442 bool const multiple_nodes_allowed = false;
443 auto additional_meshes =
445 geoObjects, *meshes[0], std::move(search_length_algorithm),
446 multiple_nodes_allowed);
447
448 std::move(begin(additional_meshes), end(additional_meshes),
449 std::back_inserter(meshes));
450 }
451
452 if (auto const duplicates =
454 !duplicates.empty())
455 {
456 OGS_FATAL("Mesh names aren't unique. Duplicate mesh names are:\n- {}",
457 fmt::join(duplicates, "\n- "));
458 }
459
460 if (
462 config.getConfigParameterOptional<std::vector<int>>(
463 "zero_mesh_field_data_by_material_ids"))
464 {
465 OGS_FATAL(
466 "The project file tag <zero_mesh_field_data_by_material_ids> has "
467 "been removed. Use <overwrite_mesh_data> with a <set> (or "
468 "<take_original>) sub-element and a <material_ids> entry instead.");
469 }
470
472
473 return meshes;
474}
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::vector< ranges::range_value_t< Range > > getDuplicates(Range &&range)
Definition Algorithm.h:178
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:227
void setMeshSpaceDimension(std::vector< std::unique_ptr< Mesh > > const &meshes)
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(), BaseLib::getDuplicates(), GeoLib::GEOObjects::getPoints(), GeoLib::GEOObjects::getPolylines(), GeoLib::GEOObjects::getSurfaces(), MeshLib::views::names, OGS_FATAL, BaseLib::ConfigTree::projectDirectory(), readGeometry(), readSingleMesh(), and MeshLib::setMeshSpaceDimension().

◆ 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 476 of file ProjectData.cpp.

479{
480 INFO("readRasters ...");
481 std::vector<GeoLib::NamedRaster> named_rasters;
482
484 auto optional_rasters = config.getConfigSubtreeOptional("rasters");
485 if (optional_rasters)
486 {
488 auto const configs = optional_rasters->getConfigSubtreeList("raster");
489 std::transform(
490 configs.begin(), configs.end(), std::back_inserter(named_rasters),
491 [&min_max_points](auto const& raster_config)
492 { return GeoLib::IO::readRaster(raster_config, min_max_points); });
493 }
494 INFO("readRasters done");
495 return named_rasters;
496}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28

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 351 of file ProjectData.cpp.

354{
355 std::string const mesh_file = BaseLib::joinPaths(
356 directory, mesh_config_parameter.getValue<std::string>());
357 DBUG("Reading mesh file '{:s}'.", mesh_file);
358
359 auto mesh = std::unique_ptr<MeshLib::Mesh>(MeshLib::IO::readMeshFromFile(
360 mesh_file, true /* compute_element_neighbors */));
361 if (!mesh)
362 {
363 std::filesystem::path abspath{mesh_file};
364 try
365 {
366 abspath = std::filesystem::absolute(mesh_file);
367 }
368 catch (std::filesystem::filesystem_error const& e)
369 {
370 ERR("Determining the absolute path of '{}' failed: {}", mesh_file,
371 e.what());
372 }
373
374 OGS_FATAL("Could not read mesh from '{:s}' file. No mesh added.",
375 abspath.string());
376 }
377
378#ifdef DOXYGEN_DOCU_ONLY
380 mesh_config_parameter.getConfigAttributeOptional<bool>("axially_symmetric");
381#endif // DOXYGEN_DOCU_ONLY
382
383 if (auto const axially_symmetric =
385 mesh_config_parameter.getConfigAttributeOptional<bool>(
386 "axially_symmetric"))
387 {
388 mesh->setAxiallySymmetric(*axially_symmetric);
389 if (mesh->getDimension() == 3 && mesh->isAxiallySymmetric())
390 {
391 OGS_FATAL("3D mesh cannot be axially symmetric.");
392 }
393 }
394
395 return mesh;
396}
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().