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::string const &project_directory)
 
std::vector< GeoLib::NamedRasterreadRasters (BaseLib::ConfigTree const &config, std::string const &raster_directory, 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 162 of file ProjectData.cpp.

164{
165 DBUG("Reading geometry file '{:s}'.", fname);
166 GeoLib::IO::BoostXmlGmlInterface gml_reader(geo_objects);
167 std::string geometry_file = BaseLib::joinPaths(dir_first, fname);
168 if (!BaseLib::IsFileExisting(geometry_file))
169 {
170 // Fallback to reading gml from prj-file directory
171 geometry_file = BaseLib::joinPaths(dir_second, fname);
172 WARN("File {:s} not found in {:s}! Trying reading from {:s}.", fname,
173 dir_first, dir_second);
174 if (!BaseLib::IsFileExisting(geometry_file))
175 {
176 OGS_FATAL("Could not read geometry file {:s} in {:s}.", fname,
177 dir_second);
178 }
179 }
180 gml_reader.readFile(geometry_file);
181}
#define OGS_FATAL(...)
Definition Error.h:26
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 IsFileExisting(const std::string &strFilename)
Returns true if given file exists.
Definition FileTools.cpp:50
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,
std::string const & project_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 230 of file ProjectData.cpp.

233{
234 std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
235
236 GeoLib::GEOObjects geoObjects;
237
239 auto optional_meshes = config.getConfigSubtreeOptional("meshes");
240 if (optional_meshes)
241 {
242 DBUG("Reading multiple meshes.");
244 auto const configs = optional_meshes->getConfigParameterList("mesh");
245 std::transform(configs.begin(), configs.end(),
246 std::back_inserter(meshes),
247 [&directory](auto const& mesh_config)
248 { return readSingleMesh(mesh_config, directory); });
249 if (auto const geometry_file_name =
251 config.getConfigParameterOptional<std::string>("geometry"))
252 {
253 readGeometry(*geometry_file_name, geoObjects, directory,
254 project_directory);
255 }
256 }
257 else
258 { // Read single mesh with geometry.
259 meshes.push_back(
261 readSingleMesh(config.getConfigParameter("mesh"), directory));
262
263 auto const geometry_file_name =
265 config.getConfigParameter<std::string>("geometry");
266 readGeometry(geometry_file_name, geoObjects, directory,
267 project_directory);
268 }
269
270 { // generate meshes from geometries
271 std::unique_ptr<MeshGeoToolsLib::SearchLength> search_length_algorithm =
273 bool const multiple_nodes_allowed = false;
274 auto additional_meshes =
276 geoObjects, *meshes[0], std::move(search_length_algorithm),
277 multiple_nodes_allowed);
278
279 std::move(begin(additional_meshes), end(additional_meshes),
280 std::back_inserter(meshes));
281 }
282
283 auto mesh_names = MeshLib::views::names | ranges::to<std::vector>() |
284 ranges::actions::sort;
285 auto const sorted_names = meshes | mesh_names;
286 auto const unique_names = meshes | mesh_names | ranges::actions::unique;
287 if (unique_names.size() < sorted_names.size())
288 {
289 WARN(
290 "Mesh names aren't unique. From project file read mesh names are:");
291 for (auto const& name : meshes | MeshLib::views::names)
292 {
293 INFO("- {}", name);
294 }
295 }
296
297 auto const zero_mesh_field_data_by_material_ids =
299 config.getConfigParameterOptional<std::vector<int>>(
300 "zero_mesh_field_data_by_material_ids");
301 if (zero_mesh_field_data_by_material_ids)
302 {
303 WARN(
304 "Tag 'zero_mesh_field_data_by_material_ids` is experimental. Its "
305 "name may be changed, or it may be removed due to its "
306 "corresponding feature becomes a single tool. Please use it with "
307 "care!");
309 *meshes[0], *zero_mesh_field_data_by_material_ids);
310 }
311
313
314 return meshes;
315}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Container class for geometric objects.
Definition GEOObjects.h:57
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:229
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(), INFO(), MeshLib::views::names, readGeometry(), readSingleMesh(), MeshLib::setMeshSpaceDimension(), WARN(), and MeshToolsLib::zeroMeshFieldDataByMaterialIDs().

◆ readRasters()

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

Definition at line 317 of file ProjectData.cpp.

320{
321 INFO("readRasters ...");
322 std::vector<GeoLib::NamedRaster> named_rasters;
323
325 auto optional_rasters = config.getConfigSubtreeOptional("rasters");
326 if (optional_rasters)
327 {
329 auto const configs = optional_rasters->getConfigSubtreeList("raster");
330 std::transform(
331 configs.begin(), configs.end(), std::back_inserter(named_rasters),
332 [&raster_directory, &min_max_points](auto const& raster_config)
333 {
334 return GeoLib::IO::readRaster(raster_config, raster_directory,
335 min_max_points);
336 });
337 }
338 INFO("readRasters done");
339 return named_rasters;
340}

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

186{
187 std::string const mesh_file = BaseLib::joinPaths(
188 directory, mesh_config_parameter.getValue<std::string>());
189 DBUG("Reading mesh file '{:s}'.", mesh_file);
190
191 auto mesh = std::unique_ptr<MeshLib::Mesh>(MeshLib::IO::readMeshFromFile(
192 mesh_file, true /* compute_element_neighbors */));
193 if (!mesh)
194 {
195 std::filesystem::path abspath{mesh_file};
196 try
197 {
198 abspath = std::filesystem::absolute(mesh_file);
199 }
200 catch (std::filesystem::filesystem_error const& e)
201 {
202 ERR("Determining the absolute path of '{}' failed: {}", mesh_file,
203 e.what());
204 }
205
206 OGS_FATAL("Could not read mesh from '{:s}' file. No mesh added.",
207 abspath.string());
208 }
209
210#ifdef DOXYGEN_DOCU_ONLY
212 mesh_config_parameter.getConfigAttributeOptional<bool>("axially_symmetric");
213#endif // DOXYGEN_DOCU_ONLY
214
215 if (auto const axially_symmetric =
217 mesh_config_parameter.getConfigAttributeOptional<bool>(
218 "axially_symmetric"))
219 {
220 mesh->setAxiallySymmetric(*axially_symmetric);
221 if (mesh->getDimension() == 3 && mesh->isAxiallySymmetric())
222 {
223 OGS_FATAL("3D mesh cannot be axially symmetric.");
224 }
225 }
226
227 return mesh;
228}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
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().