OGS
DirectConditionGenerator.cpp
Go to the documentation of this file.
1
16
17#include <cmath>
18#include <fstream>
19#include <limits>
20#include <memory>
21
23#include "BaseLib/Logging.h"
24#include "GeoLib/Raster.h"
25#include "MeshLib/Mesh.h"
27#include "MeshLib/Node.h"
28
29const std::vector<std::pair<std::size_t, double>>&
31 const std::string& filename)
32{
33 if (_direct_values.empty())
34 {
35 GeoLib::Raster* raster(
37 if (!raster)
38 {
39 ERR("Error in DirectConditionGenerator::directToSurfaceNodes() - "
40 "could not load raster file.");
41 return _direct_values;
42 }
43
44 Eigen::Vector3d const dir = -Eigen::Vector3d::UnitZ();
45 const std::vector<MeshLib::Node*> surface_nodes(
47 const double no_data(raster->getHeader().no_data);
48 _direct_values.reserve(surface_nodes.size());
49 for (auto const* surface_node : surface_nodes)
50 {
51 double val(raster->getValueAtPoint(*surface_node));
52 val = (val == no_data) ? 0 : val;
53 _direct_values.emplace_back(surface_node->getID(), val);
54 }
55 delete raster;
56
57 std::for_each(surface_nodes.begin(), surface_nodes.end(),
58 std::default_delete<MeshLib::Node>());
59 }
60 else
61 ERR("Error in DirectConditionGenerator::directToSurfaceNodes() - Data "
62 "vector contains outdated values.");
63
64 return _direct_values;
65}
66
67const std::vector<std::pair<std::size_t, double>>&
69 MeshLib::Mesh& mesh, const std::string& filename, double scaling)
70{
71 if (!_direct_values.empty())
72 {
73 ERR("Error in DirectConditionGenerator::directWithSurfaceIntegration()"
74 "- Data vector contains outdated values...");
75 return _direct_values;
76 }
77
78 std::unique_ptr<GeoLib::Raster> raster(
80 if (!raster)
81 {
82 ERR("Error in DirectConditionGenerator::directWithSurfaceIntegration()"
83 "- could not load raster file.");
84 return _direct_values;
85 }
86
87 Eigen::Vector3d const dir({0.0, 0.0, -1.0});
88 double const angle(90);
89 std::string const prop_name("bulk_node_ids");
90 std::unique_ptr<MeshLib::Mesh> surface_mesh(
92 prop_name));
93
94 std::vector<double> node_area_vec =
96 const std::vector<MeshLib::Node*>& surface_nodes(surface_mesh->getNodes());
97 const std::size_t nNodes(surface_mesh->getNumberOfNodes());
98 const double no_data(raster->getHeader().no_data);
99
100 MeshLib::PropertyVector<int> const* node_id_pv = nullptr;
101 try
102 {
103 node_id_pv = surface_mesh->getProperties().getPropertyVector<int>(
104 prop_name, MeshLib::MeshItemType::Node, 1);
105 }
106 catch (std::runtime_error const& e)
107 {
108 WARN("{:s}", e.what());
109 return _direct_values;
110 }
111
112 _direct_values.reserve(nNodes);
113 for (std::size_t i = 0; i < nNodes; ++i)
114 {
115 double val(raster->getValueAtPoint(*surface_nodes[i]));
116 val = (val == no_data) ? 0 : ((val * node_area_vec[i]) / scaling);
117 _direct_values.emplace_back((*node_id_pv)[i], val);
118 }
119
120 return _direct_values;
121}
122
123int DirectConditionGenerator::writeToFile(const std::string& name) const
124{
125 std::ofstream out(name.c_str(), std::ios::out);
126
127 if (out)
128 {
129 for (const auto& direct_value : _direct_values)
130 {
131 out << direct_value.first << "\t" << direct_value.second << "\n";
132 }
133
134 out.close();
135 }
136 return 0;
137}
Definition of the AsciiRasterInterface class.
Definition of the DirectConditionGenerator class.
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:44
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:39
Definition of the MeshSurfaceExtraction class.
Definition of the Mesh class.
Definition of the Node class.
Definition of the GeoLib::Raster class.
const std::vector< std::pair< std::size_t, double > > & directToSurfaceNodes(const MeshLib::Mesh &mesh, const std::string &filename)
std::vector< std::pair< std::size_t, double > > _direct_values
int writeToFile(const std::string &name) const
const std::vector< std::pair< std::size_t, double > > & directWithSurfaceIntegration(MeshLib::Mesh &mesh, const std::string &filename, double scaling)
static GeoLib::Raster * readRaster(std::string const &fname)
Reads raster file by detecting type based on extension and then calling the appropriate method.
Class Raster is used for managing raster data.
Definition: Raster.h:45
double getValueAtPoint(const MathLib::Point3d &pnt) const
Definition: Raster.cpp:63
RasterHeader const & getHeader() const
Returns the complete header information.
Definition: Raster.h:83
static MeshLib::Mesh * getMeshSurface(const MeshLib::Mesh &subsfc_mesh, Eigen::Vector3d const &dir, double angle, std::string const &subsfc_node_id_prop_name="", std::string const &subsfc_element_id_prop_name="", std::string const &face_id_prop_name="")
static std::vector< MeshLib::Node * > getSurfaceNodes(const MeshLib::Mesh &mesh, Eigen::Vector3d const &dir, double angle)
Returns the surface nodes of a mesh.
static std::vector< double > getSurfaceAreaForNodes(const MeshLib::Mesh &mesh)
Returns a vector of the areas assigned to each node on a surface mesh.