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
20#include <splines/bspline.hpp>
21#include <utils/fqn.hpp>
22
23namespace iganet {
24
26template <typename T>
28public:
30 void pretty_print(std::ostream &os) const noexcept override = 0;
31};
32
34template <typename T>
35inline std::ostream &operator<<(std::ostream &os, const CreatorCore<T> &obj) {
36 obj.pretty_print(os);
37 return os;
38}
39
44template <typename T> class IntervalCreator : public CreatorCore<T> {
45public:
47 IntervalCreator() : x0min_(0.0), x0max_(0.1), x1min_(0.9), x1max_(1.0) {
48 std::srand(std::time(0));
49 }
50
52 IntervalCreator(const T &x0min, const T &x0max, const T &x1min,
53 const T &x1max)
54 : x0min_(x0min), x0max_(x0max), x1min_(x1min), x1max_(x1max) {
55 std::srand(std::time(0));
56 }
57
58 template <typename Spline>
59 requires SplineType<Spline>
60 auto &next(Spline &obj) const {
61 static_assert(Spline::parDim() == 1 && Spline::geoDim() == 1,
62 "Interval creator requires parDim=1 and geoDim=1");
63
64 T x0 = x0min_ + (x0max_ - x0min_) * T(std::rand()) / T(RAND_MAX);
65 T x1 = x1min_ + (x1max_ - x1min_) * T(std::rand()) / T(RAND_MAX);
66 T xmin = std::min(x0, x1);
67 T xmax = std::max(x0, x1);
68
69 obj.transform([xmin, xmax](const std::array<T, 1> X) {
70 return std::array<T, 1>{
71 static_cast<T>(xmax * X[0] + xmin * (X[0] - T(1)))};
72 });
73
74 return obj;
75 }
76
78 void pretty_print(std::ostream &os) const noexcept override {
79 os << CreatorCore<T>::name() << "\n"
80 << "(x0min = " << x0min_ << ", x0max = " << x0max_
81 << "; x1min = " << x1min_ << ", x1max = " << x1max_ << ")";
82 }
83
84private:
86};
87
92template <typename T> class RectangleCreator : public CreatorCore<T> {
93public:
96 : x0min_(0.0), x0max_(0.1), x1min_(0.9), x1max_(1.0), y0min_(0.0),
97 y0max_(0.1), y1min_(0.9), y1max_(1.0) {
98 std::srand(std::time(0));
99 }
100
102 RectangleCreator(const T &x0min, const T &x0max, const T &x1min,
103 const T &x1max, const T &y0min, const T &y0max,
104 const T &y1min, const T &y1max)
105 : x0min_(x0min), x0max_(x0max), x1min_(x1min), x1max_(x1max),
106 y0min_(y0min), y0max_(y0max), y1min_(y1min), y1max_(y1max) {
107 std::srand(std::time(0));
108 }
109
110 template <typename Spline>
111 requires SplineType<Spline>
112 auto &next(Spline &obj) const {
113 static_assert(Spline::parDim() == 2 && Spline::geoDim() == 2,
114 "Rectangle creator requires parDim=2 and geoDim=2");
115
116 T x0 = x0min_ + (x0max_ - x0min_) * T(std::rand()) / T(RAND_MAX);
117 T x1 = x1min_ + (x1max_ - x1min_) * T(std::rand()) / T(RAND_MAX);
118 T xmin = std::min(x0, x1);
119 T xmax = std::max(x0, x1);
120
121 T y0 = y0min_ + (y0max_ - y0min_) * T(std::rand()) / T(RAND_MAX);
122 T y1 = y1min_ + (y1max_ - y1min_) * T(std::rand()) / T(RAND_MAX);
123 T ymin = std::min(y0, y1);
124 T ymax = std::max(y0, y1);
125
126 obj.transform([xmin, xmax, ymin, ymax](const std::array<T, 2> X) {
127 return std::array<T, 2>{
128 static_cast<T>(xmax * X[0] + xmin * (X[0] - T(1))),
129 static_cast<T>(ymax * X[1] + ymin * (X[1] - T(1)))};
130 });
131
132 return obj;
133 }
134
136 void pretty_print(std::ostream &os) const noexcept override {
137 os << CreatorCore<T>::name() << "\n"
138 << "(x0min = " << x0min_ << ", x0max = " << x0max_
139 << "; x1min = " << x1min_ << ", x1max = " << x1max_
140 << "; y0min = " << y0min_ << ", y0max = " << y0max_
141 << "; y1min = " << y1min_ << ", y1max = " << y1max_ << ")";
142 }
143
144private:
146};
147
152template <typename T> class CuboidCreator : public CreatorCore<T> {
153public:
156 : x0min_(0.0), x0max_(0.1), x1min_(0.9), x1max_(1.0), y0min_(0.0),
157 y0max_(0.1), y1min_(0.9), y1max_(1.0), z0min_(0.0), z0max_(0.1),
158 z1min_(0.9), z1max_(1.0) {
159 std::srand(std::time(0));
160 }
161
163 CuboidCreator(const T &x0min, const T &x0max, const T &x1min, const T &x1max,
164 const T &y0min, const T &y0max, const T &y1min, const T &y1max,
165 const T &z0min, const T &z0max, const T &z1min, const T &z1max)
166 : x0min_(x0min), x0max_(x0max), x1min_(x1min), x1max_(x1max),
167 y0min_(y0min), y0max_(y0max), y1min_(y1min), y1max_(y1max),
168 z0min_(z0min), z0max_(z0max), z1min_(z1min), z1max_(z1max) {
169 std::srand(std::time(0));
170 }
171
172 template <typename Spline>
173 requires SplineType<Spline>
174 auto &next(Spline &obj) const {
175 static_assert(Spline::parDim() == 3 && Spline::geoDim() == 3,
176 "Cuboid creator requires parDim=3 and geoDim=3");
177
178 T x0 = x0min_ + (x0max_ - x0min_) * T(std::rand()) / T(RAND_MAX);
179 T x1 = x1min_ + (x1max_ - x1min_) * T(std::rand()) / T(RAND_MAX);
180 T xmin = std::min(x0, x1);
181 T xmax = std::max(x0, x1);
182
183 T y0 = y0min_ + (y0max_ - y0min_) * T(std::rand()) / T(RAND_MAX);
184 T y1 = y1min_ + (y1max_ - y1min_) * T(std::rand()) / T(RAND_MAX);
185 T ymin = std::min(y0, y1);
186 T ymax = std::max(y0, y1);
187
188 T z0 = z0min_ + (z0max_ - z0min_) * T(std::rand()) / T(RAND_MAX);
189 T z1 = z1min_ + (z1max_ - z1min_) * T(std::rand()) / T(RAND_MAX);
190 T zmin = std::min(z0, z1);
191 T zmax = std::max(z0, z1);
192
193 obj.transform(
194 [xmin, xmax, ymin, ymax, zmin, zmax](const std::array<T, 3> X) {
195 return std::array<T, 3>{
196 static_cast<T>(xmax * X[0] + xmin * (X[0] - T(1))),
197 static_cast<T>(ymax * X[1] + ymin * (X[1] - T(1))),
198 static_cast<T>(zmax * X[2] + zmin * (X[2] - T(1)))};
199 });
200
201 return obj;
202 }
203
205 void pretty_print(std::ostream &os) const noexcept override {
206 os << CreatorCore<T>::name() << "\n"
207 << "(x0min = " << x0min_ << ", x0max = " << x0max_
208 << "; x1min = " << x1min_ << ", x1max = " << x1max_
209 << "; y0min = " << y0min_ << ", y0max = " << y0max_
210 << "; y1min = " << y1min_ << ", y1max = " << y1max_
211 << "; z0min = " << z0min_ << ", z0max = " << z0max_
212 << "; z1min = " << z1min_ << ", z1max = " << z1max_ << ")";
213 }
214
215private:
218};
219
220} // namespace iganet
Multivariate B-splines.
Abstract creator class.
Definition creator.hpp:27
void pretty_print(std::ostream &os) const noexcept override=0
Returns a string representation of the CreatorCore object.
Cuboid creator class.
Definition creator.hpp:152
T z0min_
Definition creator.hpp:216
T z1min_
Definition creator.hpp:217
T y0max_
Definition creator.hpp:216
T z0max_
Definition creator.hpp:217
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the RectangleCreator object.
Definition creator.hpp:205
CuboidCreator()
Default constructor.
Definition creator.hpp:155
T y0min_
Definition creator.hpp:216
T z1max_
Definition creator.hpp:217
T y1min_
Definition creator.hpp:216
T x1max_
Definition creator.hpp:216
T x1min_
Definition creator.hpp:216
T x0max_
Definition creator.hpp:216
T y1max_
Definition creator.hpp:216
auto & next(Spline &obj) const
Definition creator.hpp:174
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:163
T x0min_
Definition creator.hpp:216
Interval creator class.
Definition creator.hpp:44
T x1max_
Definition creator.hpp:85
IntervalCreator()
Default constructor.
Definition creator.hpp:47
T x0min_
Definition creator.hpp:85
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the IntervalCreator object.
Definition creator.hpp:78
auto & next(Spline &obj) const
Definition creator.hpp:60
T x1min_
Definition creator.hpp:85
IntervalCreator(const T &x0min, const T &x0max, const T &x1min, const T &x1max)
Bounds constructor.
Definition creator.hpp:52
T x0max_
Definition creator.hpp:85
Rectangle creator class.
Definition creator.hpp:92
T y0min_
Definition creator.hpp:145
T y0max_
Definition creator.hpp:145
T x1min_
Definition creator.hpp:145
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:102
T y1min_
Definition creator.hpp:145
T x0min_
Definition creator.hpp:145
auto & next(Spline &obj) const
Definition creator.hpp:112
T x1max_
Definition creator.hpp:145
RectangleCreator()
Default constructor.
Definition creator.hpp:95
T y1max_
Definition creator.hpp:145
T x0max_
Definition creator.hpp:145
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the RectangleCreator object.
Definition creator.hpp:136
Full qualified name descriptor.
Definition fqn.hpp:22
Concept to identify template parameters that are derived from iganet::Spline_.
Definition bspline.hpp:3582
Full qualified name utility functions.
Definition core.hpp:72
std::ostream & operator<<(std::ostream &os, const MemoryDebugger< id > &obj)
Print (as string) a memory debugger object.
Definition memory.hpp:125