IgANet
IGAnets - Isogeometric Analysis Networks
Loading...
Searching...
No Matches
creator.hpp
Go to the documentation of this file.
1
15#pragma once
16
17#include <cstdlib>
18#include <ctime>
19
21#include <iganet/utils/fqn.hpp>
22
23namespace iganet {
24
27template <typename T>
29public:
32 void pretty_print(std::ostream &os) const noexcept override = 0;
33};
34
40template <typename T>
41inline std::ostream &operator<<(std::ostream &os, const CreatorCore<T> &obj) {
42 obj.pretty_print(os);
43 return os;
44}
45
52template <typename T> class IntervalCreator : public CreatorCore<T> {
53public:
58 IntervalCreator() : x0min_(0.0), x0max_(0.1), x1min_(0.9), x1max_(1.0) {
59 std::srand(std::time(0));
60 }
61
67 IntervalCreator(const T &x0min, const T &x0max, const T &x1min,
68 const T &x1max)
69 : x0min_(x0min), x0max_(x0max), x1min_(x1min), x1max_(x1max) {
70 std::srand(std::time(0));
71 }
72
78 template <typename Spline>
79 requires SplineType<Spline>
80 auto &next(Spline &obj) const {
81 static_assert(Spline::parDim() == 1 && Spline::geoDim() == 1,
82 "Interval creator requires parDim=1 and geoDim=1");
83
84 T x0 = x0min_ + (x0max_ - x0min_) * T(std::rand()) / T(RAND_MAX);
85 T x1 = x1min_ + (x1max_ - x1min_) * T(std::rand()) / T(RAND_MAX);
86 T xmin = std::min(x0, x1);
87 T xmax = std::max(x0, x1);
88
89 obj.transform([xmin, xmax](const std::array<T, 1> X) {
90 return std::array<T, 1>{
91 static_cast<T>(xmin + (xmax - xmin) * X[0])};
92 });
93
94 return obj;
95 }
96
99 void pretty_print(std::ostream &os) const noexcept override {
100 os << CreatorCore<T>::name() << "\n"
101 << "(x0min = " << x0min_ << ", x0max = " << x0max_
102 << "; x1min = " << x1min_ << ", x1max = " << x1max_ << ")";
103 }
104
105private:
108};
109
116template <typename T> class RectangleCreator : public CreatorCore<T> {
117public:
124 : x0min_(0.0), x0max_(0.1), x1min_(0.9), x1max_(1.0), y0min_(0.0),
125 y0max_(0.1), y1min_(0.9), y1max_(1.0) {
126 std::srand(std::time(0));
127 }
128
138 RectangleCreator(const T &x0min, const T &x0max, const T &x1min,
139 const T &x1max, const T &y0min, const T &y0max,
140 const T &y1min, const T &y1max)
141 : x0min_(x0min), x0max_(x0max), x1min_(x1min), x1max_(x1max),
142 y0min_(y0min), y0max_(y0max), y1min_(y1min), y1max_(y1max) {
143 std::srand(std::time(0));
144 }
145
151 template <typename Spline>
152 requires SplineType<Spline>
153 auto &next(Spline &obj) const {
154 static_assert(Spline::parDim() == 2 && Spline::geoDim() == 2,
155 "Rectangle creator requires parDim=2 and geoDim=2");
156
157 T x0 = x0min_ + (x0max_ - x0min_) * T(std::rand()) / T(RAND_MAX);
158 T x1 = x1min_ + (x1max_ - x1min_) * T(std::rand()) / T(RAND_MAX);
159 T xmin = std::min(x0, x1);
160 T xmax = std::max(x0, x1);
161
162 T y0 = y0min_ + (y0max_ - y0min_) * T(std::rand()) / T(RAND_MAX);
163 T y1 = y1min_ + (y1max_ - y1min_) * T(std::rand()) / T(RAND_MAX);
164 T ymin = std::min(y0, y1);
165 T ymax = std::max(y0, y1);
166
167 obj.transform([xmin, xmax, ymin, ymax](const std::array<T, 2> X) {
168 return std::array<T, 2>{
169 static_cast<T>(xmin + (xmax - xmin) * X[0]),
170 static_cast<T>(ymin + (ymax - ymin) * X[1])};
171 });
172
173 return obj;
174 }
175
178 void pretty_print(std::ostream &os) const noexcept override {
179 os << CreatorCore<T>::name() << "\n"
180 << "(x0min = " << x0min_ << ", x0max = " << x0max_
181 << "; x1min = " << x1min_ << ", x1max = " << x1max_
182 << "; y0min = " << y0min_ << ", y0max = " << y0max_
183 << "; y1min = " << y1min_ << ", y1max = " << y1max_ << ")";
184 }
185
186private:
189};
190
197template <typename T> class CuboidCreator : public CreatorCore<T> {
198public:
205 : x0min_(0.0), x0max_(0.1), x1min_(0.9), x1max_(1.0), y0min_(0.0),
206 y0max_(0.1), y1min_(0.9), y1max_(1.0), z0min_(0.0), z0max_(0.1),
207 z1min_(0.9), z1max_(1.0) {
208 std::srand(std::time(0));
209 }
210
224 CuboidCreator(const T &x0min, const T &x0max, const T &x1min, const T &x1max,
225 const T &y0min, const T &y0max, const T &y1min, const T &y1max,
226 const T &z0min, const T &z0max, const T &z1min, const T &z1max)
227 : x0min_(x0min), x0max_(x0max), x1min_(x1min), x1max_(x1max),
228 y0min_(y0min), y0max_(y0max), y1min_(y1min), y1max_(y1max),
229 z0min_(z0min), z0max_(z0max), z1min_(z1min), z1max_(z1max) {
230 std::srand(std::time(0));
231 }
232
238 template <typename Spline>
239 requires SplineType<Spline>
240 auto &next(Spline &obj) const {
241 static_assert(Spline::parDim() == 3 && Spline::geoDim() == 3,
242 "Cuboid creator requires parDim=3 and geoDim=3");
243
244 T x0 = x0min_ + (x0max_ - x0min_) * T(std::rand()) / T(RAND_MAX);
245 T x1 = x1min_ + (x1max_ - x1min_) * T(std::rand()) / T(RAND_MAX);
246 T xmin = std::min(x0, x1);
247 T xmax = std::max(x0, x1);
248
249 T y0 = y0min_ + (y0max_ - y0min_) * T(std::rand()) / T(RAND_MAX);
250 T y1 = y1min_ + (y1max_ - y1min_) * T(std::rand()) / T(RAND_MAX);
251 T ymin = std::min(y0, y1);
252 T ymax = std::max(y0, y1);
253
254 T z0 = z0min_ + (z0max_ - z0min_) * T(std::rand()) / T(RAND_MAX);
255 T z1 = z1min_ + (z1max_ - z1min_) * T(std::rand()) / T(RAND_MAX);
256 T zmin = std::min(z0, z1);
257 T zmax = std::max(z0, z1);
258
259 obj.transform(
260 [xmin, xmax, ymin, ymax, zmin, zmax](const std::array<T, 3> X) {
261 return std::array<T, 3>{
262 static_cast<T>(xmin + (xmax - xmin) * X[0]),
263 static_cast<T>(ymin + (ymax - ymin) * X[1]),
264 static_cast<T>(zmin + (zmax - zmin) * X[2])};
265 });
266
267 return obj;
268 }
269
273 void pretty_print(std::ostream &os) const noexcept override {
274 os << CreatorCore<T>::name() << "\n"
275 << "(x0min = " << x0min_ << ", x0max = " << x0max_
276 << "; x1min = " << x1min_ << ", x1max = " << x1max_
277 << "; y0min = " << y0min_ << ", y0max = " << y0max_
278 << "; y1min = " << y1min_ << ", y1max = " << y1max_
279 << "; z0min = " << z0min_ << ", z0max = " << z0max_
280 << "; z1min = " << z1min_ << ", z1max = " << z1max_ << ")";
281 }
282
283private:
287};
288
289} // namespace iganet
Multivariate B-splines.
Abstract creator class.
Definition creator.hpp:28
void pretty_print(std::ostream &os) const noexcept override=0
Returns a string representation of the CreatorCore object.
Cuboid creator class.
Definition creator.hpp:197
T z0min_
Definition creator.hpp:285
T z1min_
Definition creator.hpp:286
T y0max_
Definition creator.hpp:285
T z0max_
Definition creator.hpp:286
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the RectangleCreator object.
Definition creator.hpp:273
CuboidCreator()
Default constructor.
Definition creator.hpp:204
T y0min_
Definition creator.hpp:285
T z1max_
Definition creator.hpp:286
T y1min_
Definition creator.hpp:285
T x1max_
Definition creator.hpp:285
T x1min_
Definition creator.hpp:285
T x0max_
Definition creator.hpp:285
T y1max_
Definition creator.hpp:285
auto & next(Spline &obj) const
Transforms a spline into the next randomly generated cuboid.
Definition creator.hpp:240
CuboidCreator(const T &x0min, const T &x0max, const T &x1min, const T &x1max, const T &y0min, const T &y0max, const T &y1min, const T &y1max, const T &z0min, const T &z0max, const T &z1min, const T &z1max)
Bounds constructor.
Definition creator.hpp:224
T x0min_
Bounds of the x-, y-, and z-coordinate sampling ranges.
Definition creator.hpp:285
Interval creator class.
Definition creator.hpp:52
T x1max_
Definition creator.hpp:107
IntervalCreator()
Default constructor.
Definition creator.hpp:58
T x0min_
Bounds of the two endpoint sampling ranges.
Definition creator.hpp:107
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the IntervalCreator object.
Definition creator.hpp:99
auto & next(Spline &obj) const
Transforms a spline into the next randomly generated interval.
Definition creator.hpp:80
T x1min_
Definition creator.hpp:107
IntervalCreator(const T &x0min, const T &x0max, const T &x1min, const T &x1max)
Bounds constructor.
Definition creator.hpp:67
T x0max_
Definition creator.hpp:107
Rectangle creator class.
Definition creator.hpp:116
T y0min_
Definition creator.hpp:188
T y0max_
Definition creator.hpp:188
T x1min_
Definition creator.hpp:188
RectangleCreator(const T &x0min, const T &x0max, const T &x1min, const T &x1max, const T &y0min, const T &y0max, const T &y1min, const T &y1max)
Bounds constructor.
Definition creator.hpp:138
T y1min_
Definition creator.hpp:188
T x0min_
Bounds of the x- and y-coordinate sampling ranges.
Definition creator.hpp:188
auto & next(Spline &obj) const
Transforms a spline into the next randomly generated rectangle.
Definition creator.hpp:153
T x1max_
Definition creator.hpp:188
RectangleCreator()
Default constructor.
Definition creator.hpp:123
T y1max_
Definition creator.hpp:188
T x0max_
Definition creator.hpp:188
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the RectangleCreator object.
Definition creator.hpp:178
Full qualified name descriptor.
Definition fqn.hpp:22
Concept to identify template parameters that are derived from iganet::Spline_.
Definition bspline.hpp:3858
Full qualified name utility functions.
Definition core.hpp:73
std::ostream & operator<<(std::ostream &os, const MemoryDebugger< id > &obj)
Prints a memory debugger object.
Definition memory.hpp:145