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

157{
158 DBUG("Reading geometry file '{:s}'.", fname);
159 GeoLib::IO::BoostXmlGmlInterface gml_reader(geo_objects);
160 std::string geometry_file = BaseLib::copyPathToFileName(fname, dir_first);
161 if (!BaseLib::IsFileExisting(geometry_file))
162 {
163 // Fallback to reading gml from prj-file directory
164 geometry_file = BaseLib::copyPathToFileName(fname, dir_second);
165 WARN("File {:s} not found in {:s}! Trying reading from {:s}.", fname,
166 dir_first, dir_second);
167 if (!BaseLib::IsFileExisting(geometry_file))
168 {
169 OGS_FATAL("Could not read geometry file {:s} in {:s}.", fname,
170 dir_second);
171 }
172 }
173 gml_reader.readFile(geometry_file);
174}
#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:47
std::string copyPathToFileName(const std::string &file_name, const std::string &source)

References BaseLib::copyPathToFileName(), DBUG(), BaseLib::IsFileExisting(), 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 208 of file ProjectData.cpp.

211{
212 std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
213
214 GeoLib::GEOObjects geoObjects;
215
217 auto optional_meshes = config.getConfigSubtreeOptional("meshes");
218 if (optional_meshes)
219 {
220 DBUG("Reading multiple meshes.");
222 auto const configs = optional_meshes->getConfigParameterList("mesh");
223 std::transform(configs.begin(), configs.end(),
224 std::back_inserter(meshes),
225 [&directory](auto const& mesh_config)
226 { return readSingleMesh(mesh_config, directory); });
227 if (auto const geometry_file_name =
229 config.getConfigParameterOptional<std::string>("geometry"))
230 {
231 readGeometry(*geometry_file_name, geoObjects, directory,
232 project_directory);
233 }
234 }
235 else
236 { // Read single mesh with geometry.
237 meshes.push_back(
239 readSingleMesh(config.getConfigParameter("mesh"), directory));
240
241 auto const geometry_file_name =
243 config.getConfigParameter<std::string>("geometry");
244 readGeometry(geometry_file_name, geoObjects, directory,
245 project_directory);
246 }
247
248 { // generate meshes from geometries
249 std::unique_ptr<MeshGeoToolsLib::SearchLength> search_length_algorithm =
251 bool const multiple_nodes_allowed = false;
252 auto additional_meshes =
254 geoObjects, *meshes[0], std::move(search_length_algorithm),
255 multiple_nodes_allowed);
256
257 std::move(begin(additional_meshes), end(additional_meshes),
258 std::back_inserter(meshes));
259 }
260
261 auto mesh_names = MeshLib::views::names | ranges::to<std::vector>() |
262 ranges::actions::sort;
263 auto const sorted_names = meshes | mesh_names;
264 auto const unique_names = meshes | mesh_names | ranges::actions::unique;
265 if (unique_names.size() < sorted_names.size())
266 {
267 WARN(
268 "Mesh names aren't unique. From project file read mesh names are:");
269 for (auto const& name : meshes | MeshLib::views::names)
270 {
271 INFO("- {}", name);
272 }
273 }
274
275 auto const zero_mesh_field_data_by_material_ids =
277 config.getConfigParameterOptional<std::vector<int>>(
278 "zero_mesh_field_data_by_material_ids");
279 if (zero_mesh_field_data_by_material_ids)
280 {
281 WARN(
282 "Tag 'zero_mesh_field_data_by_material_ids` is experimental. Its "
283 "name may be changed, or it may be removed due to its "
284 "corresponding feature becomes a single tool. Please use it with "
285 "care!");
287 *meshes[0], *zero_mesh_field_data_by_material_ids);
288 }
289
291
292 return meshes;
293}
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 295 of file ProjectData.cpp.

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

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

179{
180 std::string const mesh_file = BaseLib::copyPathToFileName(
181 mesh_config_parameter.getValue<std::string>(), directory);
182 DBUG("Reading mesh file '{:s}'.", mesh_file);
183
184 auto mesh = std::unique_ptr<MeshLib::Mesh>(MeshLib::IO::readMeshFromFile(
185 mesh_file, true /* compute_element_neighbors */));
186 if (!mesh)
187 {
188 OGS_FATAL("Could not read mesh from '{:s}' file. No mesh added.",
189 mesh_file);
190 }
191
192#ifdef DOXYGEN_DOCU_ONLY
194 mesh_config_parameter.getConfigAttributeOptional<bool>("axially_symmetric");
195#endif // DOXYGEN_DOCU_ONLY
196
197 if (auto const axially_symmetric =
199 mesh_config_parameter.getConfigAttributeOptional<bool>(
200 "axially_symmetric"))
201 {
202 mesh->setAxiallySymmetric(*axially_symmetric);
203 }
204
205 return mesh;
206}
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)

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

Referenced by readMeshes().