OGS
DirectConditionGenerator Class Reference

Detailed Description

Definition at line 24 of file DirectConditionGenerator.h.

#include <DirectConditionGenerator.h>

Public Member Functions

 DirectConditionGenerator ()=default
 
 ~DirectConditionGenerator ()=default
 
const std::vector< std::pair< std::size_t, double > > & directToSurfaceNodes (const MeshLib::Mesh &mesh, const std::string &filename)
 
const std::vector< std::pair< std::size_t, double > > & directWithSurfaceIntegration (MeshLib::Mesh &mesh, const std::string &filename, double scaling)
 
int writeToFile (const std::string &name) const
 

Private Attributes

std::vector< std::pair< std::size_t, double > > _direct_values
 

Constructor & Destructor Documentation

◆ DirectConditionGenerator()

DirectConditionGenerator::DirectConditionGenerator ( )
default

◆ ~DirectConditionGenerator()

DirectConditionGenerator::~DirectConditionGenerator ( )
default

Member Function Documentation

◆ directToSurfaceNodes()

const std::vector< std::pair< std::size_t, double > > & DirectConditionGenerator::directToSurfaceNodes ( const MeshLib::Mesh & mesh,
const std::string & filename )

Definition at line 30 of file DirectConditionGenerator.cpp.

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 90));
48 const double no_data(raster->getHeader().no_data);
49 _direct_values.reserve(surface_nodes.size());
50 for (auto const* surface_node : surface_nodes)
51 {
52 double val(raster->getValueAtPoint(*surface_node));
53 val = (val == no_data) ? 0 : val;
54 _direct_values.emplace_back(surface_node->getID(), val);
55 }
56 delete raster;
57
58 std::for_each(surface_nodes.begin(), surface_nodes.end(),
59 std::default_delete<MeshLib::Node>());
60 }
61 else
62 ERR("Error in DirectConditionGenerator::directToSurfaceNodes() - Data "
63 "vector contains outdated values.");
64
65 return _direct_values;
66}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
std::vector< std::pair< std::size_t, double > > _direct_values
static GeoLib::Raster * readRaster(std::string const &fname)
Class Raster is used for managing raster data.
Definition Raster.h:49
static std::vector< MeshLib::Node * > getSurfaceNodes(const MeshLib::Mesh &mesh, Eigen::Vector3d const &dir, double angle)
Returns the surface nodes of a mesh.

References _direct_values, ERR(), GeoLib::Raster::getHeader(), MeshToolsLib::MeshSurfaceExtraction::getSurfaceNodes(), GeoLib::Raster::getValueAtPoint(), GeoLib::RasterHeader::no_data, and FileIO::AsciiRasterInterface::readRaster().

Referenced by CondFromRasterDialog::accept().

◆ directWithSurfaceIntegration()

const std::vector< std::pair< std::size_t, double > > & DirectConditionGenerator::directWithSurfaceIntegration ( MeshLib::Mesh & mesh,
const std::string & filename,
double scaling )

Definition at line 69 of file DirectConditionGenerator.cpp.

71{
72 if (!_direct_values.empty())
73 {
74 ERR("Error in DirectConditionGenerator::directWithSurfaceIntegration()"
75 "- Data vector contains outdated values...");
76 return _direct_values;
77 }
78
79 std::unique_ptr<GeoLib::Raster> raster(
81 if (!raster)
82 {
83 ERR("Error in DirectConditionGenerator::directWithSurfaceIntegration()"
84 "- could not load raster file.");
85 return _direct_values;
86 }
87
88 Eigen::Vector3d const dir({0.0, 0.0, -1.0});
89 double const angle(90);
91 std::unique_ptr<MeshLib::Mesh> surface_mesh(
93 prop_name));
94
95 std::vector<double> node_area_vec =
97 *surface_mesh);
98 const std::vector<MeshLib::Node*>& surface_nodes(surface_mesh->getNodes());
99 const std::size_t nNodes(surface_mesh->getNumberOfNodes());
100 const double no_data(raster->getHeader().no_data);
101
102 MeshLib::PropertyVector<int> const* node_id_pv = nullptr;
103 try
104 {
105 node_id_pv = surface_mesh->getProperties().getPropertyVector<int>(
106 prop_name, MeshLib::MeshItemType::Node, 1);
107 }
108 catch (std::runtime_error const& e)
109 {
110 WARN("{:s}", e.what());
111 return _direct_values;
112 }
113
114 _direct_values.reserve(nNodes);
115 for (std::size_t i = 0; i < nNodes; ++i)
116 {
117 double val(raster->getValueAtPoint(*surface_nodes[i]));
118 val = (val == no_data) ? 0 : ((val * node_area_vec[i]) / scaling);
119 _direct_values.emplace_back((*node_id_pv)[i], val);
120 }
121
122 return _direct_values;
123}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
static std::vector< double > getSurfaceAreaForNodes(const MeshLib::Mesh &mesh)
Returns a vector of the areas assigned to each node on a surface mesh.
static MeshLib::Mesh * getMeshSurface(const MeshLib::Mesh &subsfc_mesh, Eigen::Vector3d const &dir, double angle, std::string_view subsfc_node_id_prop_name="", std::string_view subsfc_element_id_prop_name="", std::string_view face_id_prop_name="")
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
Definition Properties.h:188

References _direct_values, ERR(), MeshLib::getBulkIDString(), MeshToolsLib::MeshSurfaceExtraction::getMeshSurface(), MeshToolsLib::MeshSurfaceExtraction::getSurfaceAreaForNodes(), MeshLib::Node, FileIO::AsciiRasterInterface::readRaster(), and WARN().

Referenced by CondFromRasterDialog::accept().

◆ writeToFile()

int DirectConditionGenerator::writeToFile ( const std::string & name) const

Definition at line 125 of file DirectConditionGenerator.cpp.

126{
127 std::ofstream out(name.c_str(), std::ios::out);
128
129 if (out)
130 {
131 for (const auto& direct_value : _direct_values)
132 {
133 out << direct_value.first << "\t" << direct_value.second << "\n";
134 }
135
136 out.close();
137 }
138 return 0;
139}

References _direct_values.

Member Data Documentation

◆ _direct_values

std::vector< std::pair<std::size_t,double> > DirectConditionGenerator::_direct_values
private

The documentation for this class was generated from the following files: