OGS
GMSHAdaptiveMeshDensity.cpp
Go to the documentation of this file.
1
15
16#include <list>
17
18#include "BaseLib/Logging.h"
19#include "GeoLib/Point.h"
20#include "GeoLib/Polygon.h"
21#ifndef NDEBUG
22#include "GeoLib/GEOObjects.h"
23#include "GeoLib/Polyline.h"
24#endif
25#include "GeoLib/QuadTree.h"
26#include "MathLib/MathTools.h"
27
28namespace FileIO
29{
30namespace GMSH
31{
33 double station_density,
34 std::size_t max_pnts_per_leaf)
35 : _pnt_density(pnt_density),
36 _station_density(station_density),
37 _max_pnts_per_leaf(max_pnts_per_leaf),
38 _quad_tree(nullptr)
39{
40}
41
46
48 std::vector<GeoLib::Point const*> const& pnts)
49{
50 // *** QuadTree - determining bounding box
51 DBUG(
52 "GMSHAdaptiveMeshDensity::init(): computing axis aligned bounding box "
53 "(2D) for quadtree.");
54
55 GeoLib::Point min(*pnts[0]);
56 GeoLib::Point max(*pnts[0]);
57 std::size_t n_pnts(pnts.size());
58 for (std::size_t k(1); k < n_pnts; k++)
59 {
60 for (std::size_t j(0); j < 2; j++)
61 {
62 if ((*(pnts[k]))[j] < min[j])
63 {
64 min[j] = (*(pnts[k]))[j];
65 }
66 }
67 for (std::size_t j(0); j < 2; j++)
68 {
69 if ((*(pnts[k]))[j] > max[j])
70 {
71 max[j] = (*(pnts[k]))[j];
72 }
73 }
74 }
75 min[2] = 0.0;
76 max[2] = 0.0;
77 DBUG("GMSHAdaptiveMeshDensity::init(): \tok");
78
79 // *** QuadTree - create object
80 DBUG("GMSHAdaptiveMeshDensity::init(): Creating quadtree.");
83 DBUG("GMSHAdaptiveMeshDensity::init(): \tok.");
84
85 // *** QuadTree - insert points
86 addPoints(pnts);
87}
88
90 std::vector<GeoLib::Point const*> const& pnts)
91{
92 // *** QuadTree - insert points
93 const std::size_t n_pnts(pnts.size());
94 DBUG(
95 "GMSHAdaptiveMeshDensity::addPoints(): Inserting {:d} points into "
96 "quadtree.",
97 n_pnts);
98 for (std::size_t k(0); k < n_pnts; k++)
99 {
100 _quad_tree->addPoint(pnts[k]);
101 }
102 DBUG("GMSHAdaptiveMeshDensity::addPoints(): \tok.");
104}
105
107 GeoLib::Point const* const pnt) const
108{
109 GeoLib::Point ll;
110 GeoLib::Point ur;
111 _quad_tree->getLeaf(*pnt, ll, ur);
112 return _pnt_density * (ur[0] - ll[0]);
113}
114
116 GeoLib::Point const* const pnt) const
117{
118 GeoLib::Point ll;
119 GeoLib::Point ur;
120 _quad_tree->getLeaf(*pnt, ll, ur);
121 return _station_density * (ur[0] - ll[0]);
122}
123
125 std::vector<GeoLib::Point*>& pnts, std::size_t additional_levels) const
126{
127 // get Steiner points
128 std::size_t max_depth(0);
129 _quad_tree->getMaxDepth(max_depth);
130
131 std::list<GeoLib::QuadTree<GeoLib::Point>*> leaf_list;
132 _quad_tree->getLeafs(leaf_list);
133
134 for (std::list<GeoLib::QuadTree<GeoLib::Point>*>::const_iterator it(
135 leaf_list.begin());
136 it != leaf_list.end();
137 ++it)
138 {
139 if ((*it)->getPoints().empty())
140 {
141 // compute point from square
142 GeoLib::Point ll;
143 GeoLib::Point ur;
144 (*it)->getSquarePoints(ll, ur);
145 if ((*it)->getDepth() + additional_levels > max_depth)
146 {
147 additional_levels = max_depth - (*it)->getDepth();
148 }
149 const std::size_t n_pnts_per_quad_dim = static_cast<std::size_t>(1)
150 << additional_levels;
151 const double delta((ur[0] - ll[0]) / (2 * n_pnts_per_quad_dim));
152 for (std::size_t i(0); i < n_pnts_per_quad_dim; i++)
153 {
154 for (std::size_t j(0); j < n_pnts_per_quad_dim; j++)
155 {
156 pnts.push_back(new GeoLib::Point(
157 ll[0] + (2 * i + 1) * delta,
158 ll[1] + (2 * j + 1) * delta, 0.0, pnts.size()));
159 }
160 }
161 }
162 }
163}
164
165#ifndef NDEBUG
167 GeoLib::GEOObjects& geo_objs) const
168{
169 std::list<GeoLib::QuadTree<GeoLib::Point>*> leaf_list;
170 _quad_tree->getLeafs(leaf_list);
171
172 std::string quad_tree_geo("QuadTree");
173 {
174 std::vector<GeoLib::Point*> points{};
175 for (auto const leaf : leaf_list)
176 {
177 // fetch corner points from leaf
178 GeoLib::Point ll;
179 GeoLib::Point ur;
180 leaf->getSquarePoints(ll, ur);
181 std::size_t const pnt_offset(points.size());
182 points.push_back(new GeoLib::Point(ll, pnt_offset));
183 points.push_back(
184 new GeoLib::Point(ur[0], ll[1], 0.0, pnt_offset + 1));
185 points.push_back(new GeoLib::Point(ur, pnt_offset + 2));
186 points.push_back(
187 new GeoLib::Point(ll[0], ur[1], 0.0, pnt_offset + 3));
188 }
189 geo_objs.addPointVec(std::move(points), quad_tree_geo,
191 }
192 auto& points = geo_objs.getPointVecObj(quad_tree_geo)->getVector();
193
194 std::vector<GeoLib::Polyline*> polylines{};
195 for (std::size_t l = 0; l < leaf_list.size(); ++l)
196 {
197 auto* polyline = new GeoLib::Polyline(points);
198 for (std::size_t p = 0; p < 4; ++p)
199 {
200 polyline->addPoint(4 * l + p);
201 }
202 polyline->closePolyline();
203 polylines.push_back(polyline);
204 }
205 geo_objs.addPolylineVec(std::move(polylines), quad_tree_geo,
207
208 return quad_tree_geo;
209}
210#endif
211} // namespace GMSH
212
213} // end namespace FileIO
Definition of the GEOObjects class.
Definition of the Point class.
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Definition of the Polygon class.
Definition of the PolyLine class.
Definition of the QuadTree class.
double getMeshDensityAtPoint(GeoLib::Point const *const pnt) const override
double getMeshDensityAtStation(GeoLib::Point const *const) const override
std::string getQuadTreeGeometry(GeoLib::GEOObjects &geo_objs) const
void getSteinerPoints(std::vector< GeoLib::Point * > &pnts, std::size_t additional_levels=0) const
void initialize(std::vector< GeoLib::Point const * > const &pnts) override
GMSHAdaptiveMeshDensity(double pnt_density, double station_density, std::size_t max_pnts_per_leaf)
void addPoints(std::vector< GeoLib::Point const * > const &pnts)
GeoLib::QuadTree< GeoLib::Point > * _quad_tree
Container class for geometric objects.
Definition GEOObjects.h:57
void addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
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()))
const PointVec * getPointVecObj(const std::string &name) const
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:40
void getMaxDepth(std::size_t &max_depth) const
Definition QuadTree.h:316
void getLeafs(std::list< QuadTree< POINT > * > &leaf_list)
Definition QuadTree.h:242
void getLeaf(const POINT &pnt, POINT &ll, POINT &ur)
Definition QuadTree.h:265
bool addPoint(POINT const *pnt)
Definition QuadTree.h:101
std::map< std::string, std::size_t > NameIdMap
Definition TemplateVec.h:41
std::vector< T * > const & getVector() const