OGS
PetrelInterface.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "PetrelInterface.h"
5
6#include <fstream>
7
8#include "BaseLib/Logging.h"
10#include "GeoLib/GEOObjects.h"
12
13namespace FileIO
14{
15PetrelInterface::PetrelInterface(std::list<std::string> const& sfc_fnames,
16 std::list<std::string> const& well_path_fnames,
17 std::string& unique_model_name,
18 GeoLib::GEOObjects* geo_obj)
19 : _unique_name(unique_model_name)
20{
21 for (auto const& surface_fname : sfc_fnames)
22 {
23 INFO("PetrelInterface::PetrelInterface(): open surface file.");
24 std::ifstream in(surface_fname);
25 if (in)
26 {
27 INFO("PetrelInterface::PetrelInterface(): \tdone.");
29 in.close();
30 }
31 else
32 {
33 WARN(
34 "PetrelInterface::PetrelInterface(): \tCould not open file "
35 "{:s}.",
36 surface_fname);
37 }
38 }
39
40 for (auto const& well_path_fname : well_path_fnames)
41 {
42 INFO("PetrelInterface::PetrelInterface(): open well path file.");
43 std::ifstream in(well_path_fname);
44 if (in)
45 {
46 INFO("PetrelInterface::PetrelInterface(): \tdone.");
48 in.close();
49 }
50 else
51 {
52 WARN(
53 "PetrelInterface::PetrelInterface(): \tCould not open well "
54 "path file {:s}.",
55 well_path_fname);
56 }
57 }
58
59 // move data to GEOObject
60 geo_obj->addPointVec(std::move(pnt_vec), _unique_name);
61 if (!well_vec.empty())
62 {
63 geo_obj->addStationVec(std::move(well_vec), _unique_name);
64 }
65}
66
67static std::string readLine(std::istream& in)
68{
69 std::string line;
70 std::getline(in, line);
71 return line;
72}
73
74static std::list<std::string> split(std::string const& line)
75{
76 return BaseLib::splitString(line, ' ');
77}
78
80{
81 std::string line = readLine(in);
82
83 if (line.find("# Petrel Points with attributes") != std::string::npos)
84 {
85 // read header
86 // read Version string
87 readLine(in);
88 // read string BEGIN HEADER
89 readLine(in);
90
91 line = readLine(in);
92 while (line.find("END HEADER") == std::string::npos)
93 {
94 line = readLine(in);
95 }
96
97 // read points
98 while (in)
99 {
100 auto point = std::make_unique<GeoLib::Point>();
101 in >> (*point)[0] >> (*point)[1] >> (*point)[2];
102 if (in)
103 {
104 pnt_vec.push_back(point.release());
105 }
106 }
107 }
108 else
109 {
110 WARN(
111 "PetrelInterface::readPetrelSurface(): problem reading petrel "
112 "points from line\n'{:s}'.",
113 line);
114 }
115}
116
117static void printListInfo(const std::list<std::string>& str_list,
118 std::string_view const prefix,
119 std::string_view const message)
120{
121 for (auto const& str : str_list)
122 {
123 INFO("PetrelInterface::{:s}(): {:s}: {:s}.", prefix, message, str);
124 }
125}
126
127static double getLastNumberFromList(const std::list<std::string>& str_list)
128{
129 return std::stod(*(--str_list.end()));
130}
131
133{
134 std::string line = readLine(in);
135
136 if (line.find("# WELL TRACE FROM PETREL") == std::string::npos)
137 {
138 return;
139 }
140
141 auto printInfo = [](auto const& list, std::string_view const message)
142 { printListInfo(list, "readPetrelWellTrace", message); };
143
144 {
145 // read header
146 // read well name
147 printInfo(split(readLine(in)), "well name");
148
149 // read well head x coordinate
150 auto str_list = split(readLine(in));
151 printInfo(str_list, "well head x coord");
152 double const well_head_x = getLastNumberFromList(str_list);
153
154 // read well head y coordinate
155 str_list = split(readLine(in));
156 printInfo(str_list, "well head y coord");
157 double const well_head_y = getLastNumberFromList(str_list);
158
159 // read well KB
160 str_list = split(readLine(in));
161 printInfo(str_list, "well kb entry");
162 double const well_kb = getLastNumberFromList(str_list);
163
164 INFO("PetrelInterface::readPetrelWellTrace(): {:f}, {:f}, {:f}.",
165 well_head_x,
166 well_head_y,
167 well_kb);
168 double const depth = 0.0;
169 std::string const borehole_name = "";
170 int const date = 0;
171 well_vec.push_back(new GeoLib::StationBorehole(
172 well_head_x, well_head_y, well_kb, depth, borehole_name, date));
173
174 // read well type
175 readLine(in);
176 // std::string type(*((str_list.end())--));
177
179 }
180}
181
183{
184 readLine(in);
185
186 // read yet another header line
187 std::string line = readLine(in);
188 while (line[0] == '#')
189 {
190 line = readLine(in);
191 }
192
193 // read column information
194 printListInfo(split(line), "readPetrelWellTraceData", "column information");
195
196 // read points
197 double md;
198 double x;
199 double y;
200 double z;
201 double tvd;
202 double dx;
203 double dy;
204 double azim;
205 double incl;
206 double dls;
207 line = readLine(in);
208 while (in)
209 {
210 if (line.size() > 1 && line[0] != '#')
211 {
212 std::stringstream stream(line);
213 stream >> md;
214 stream >> x >> y >> z;
215 // pnt_vec->push_back (new GeoLib::Point (x,y,z));
216 static_cast<GeoLib::StationBorehole*>(well_vec.back())
217 ->addSoilLayer(x, y, z, "unknown");
218 stream >> tvd >> dx >> dy >> azim >> incl >> dls;
219 }
220 line = readLine(in);
221 }
222}
223} // end namespace FileIO
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
std::vector< GeoLib::Point * > pnt_vec
void readPetrelSurfacePoints(std::istream &in)
void readPetrelWellTrace(std::istream &in)
void readPetrelWellTraceData(std::istream &in)
PetrelInterface(std::list< std::string > const &sfc_fnames, std::list< std::string > const &well_path_fnames, std::string &unique_model_name, GeoLib::GEOObjects *geo_obj)
std::vector< GeoLib::Point * > well_vec
Container class for geometric objects.
Definition GEOObjects.h:46
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
A borehole as a geometric object.
void addSoilLayer(double thickness, const std::string &soil_name)
Add a soil layer to the boreholes stratigraphy.
std::vector< std::string > splitString(std::string const &str)
static void printListInfo(const std::list< std::string > &str_list, std::string_view const prefix, std::string_view const message)
static std::string readLine(std::istream &in)
static double getLastNumberFromList(const std::list< std::string > &str_list)
static std::list< std::string > split(std::string const &line)