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 <bspline.hpp>
21#include <utils/fqn.hpp>
22
23namespace iganet {
24
26template <typename T>
28public:
30 virtual void
31 pretty_print(std::ostream &os = Log(log::info)) const noexcept = 0;
32};
33
35template <typename T>
36inline std::ostream &operator<<(std::ostream &os, const CreatorCore<T> &obj) {
37 obj.pretty_print(os);
38 return os;
39}
40
45template <typename T> class IntervalCreator : public CreatorCore<T> {
46public:
48 IntervalCreator() : x0min_(0.0), x0max_(0.1), x1min_(0.9), x1max_(1.0) {
49 std::srand(std::time(0));
50 }
51
53 IntervalCreator(const T &x0min, const T &x0max, const T &x1min,
54 const T &x1max)
55 : x0min_(x0min), x0max_(x0max), x1min_(x1min), x1max_(x1max) {
56 std::srand(std::time(0));
57 }
58
59 template <typename Spline> requires SplineType<Spline> auto &next(Spline &obj) const {
60 static_assert(Spline::parDim() == 1 && Spline::geoDim() == 1,
61 "Interval creator requires parDim=1 and geoDim=1");
62
63 T x0 = x0min_ + (x0max_ - x0min_) * T(std::rand()) / T(RAND_MAX);
64 T x1 = x1min_ + (x1max_ - x1min_) * T(std::rand()) / T(RAND_MAX);
65 T xmin = std::min(x0, x1);
66 T xmax = std::max(x0, x1);
67
68 obj.transform([xmin, xmax](const std::array<T, 1> X) {
69 return std::array<T, 1>{
70 static_cast<T>(xmax * X[0] + xmin * (X[0] - T(1)))};
71 });
72
73 return obj;
74 }
75
77 virtual void
78 pretty_print(std::ostream &os = Log(log::info)) 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),
97 y0min_(0.0), 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> requires SplineType<Spline> auto &next(Spline &obj) const {
111 static_assert(Spline::parDim() == 2 && Spline::geoDim() == 2,
112 "Rectangle creator requires parDim=2 and geoDim=2");
113
114 T x0 = x0min_ + (x0max_ - x0min_) * T(std::rand()) / T(RAND_MAX);
115 T x1 = x1min_ + (x1max_ - x1min_) * T(std::rand()) / T(RAND_MAX);
116 T xmin = std::min(x0, x1);
117 T xmax = std::max(x0, x1);
118
119 T y0 = y0min_ + (y0max_ - y0min_) * T(std::rand()) / T(RAND_MAX);
120 T y1 = y1min_ + (y1max_ - y1min_) * T(std::rand()) / T(RAND_MAX);
121 T ymin = std::min(y0, y1);
122 T ymax = std::max(y0, y1);
123
124 obj.transform([xmin, xmax, ymin, ymax](const std::array<T, 2> X) {
125 return std::array<T, 2>{
126 static_cast<T>(xmax * X[0] + xmin * (X[0] - T(1))),
127 static_cast<T>(ymax * X[1] + ymin * (X[1] - T(1)))
128 };
129 });
130
131 return obj;
132 }
133
135 virtual void
136 pretty_print(std::ostream &os = Log(log::info)) 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),
157 y0min_(0.0), y0max_(0.1), y1min_(0.9), y1max_(1.0),
158 z0min_(0.0), z0max_(0.1), 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,
164 const T &x1max, const T &y0min, const T &y0max,
165 const T &y1min, const T &y1max, const T &z0min,
166 const T &z0max, const T &z1min, const T &z1max)
167 : x0min_(x0min), x0max_(x0max), x1min_(x1min), x1max_(x1max),
168 y0min_(y0min), y0max_(y0max), y1min_(y1min), y1max_(y1max),
169 z0min_(z0min), z0max_(z0max), z1min_(z1min), z1max_(z1max) {
170 std::srand(std::time(0));
171 }
172
173 template <typename Spline> requires SplineType<Spline> auto &next(Spline &obj) const {
174 static_assert(Spline::parDim() == 3 && Spline::geoDim() == 3,
175 "Cuboid creator requires parDim=3 and geoDim=3");
176
177 T x0 = x0min_ + (x0max_ - x0min_) * T(std::rand()) / T(RAND_MAX);
178 T x1 = x1min_ + (x1max_ - x1min_) * T(std::rand()) / T(RAND_MAX);
179 T xmin = std::min(x0, x1);
180 T xmax = std::max(x0, x1);
181
182 T y0 = y0min_ + (y0max_ - y0min_) * T(std::rand()) / T(RAND_MAX);
183 T y1 = y1min_ + (y1max_ - y1min_) * T(std::rand()) / T(RAND_MAX);
184 T ymin = std::min(y0, y1);
185 T ymax = std::max(y0, y1);
186
187 T z0 = z0min_ + (z0max_ - z0min_) * T(std::rand()) / T(RAND_MAX);
188 T z1 = z1min_ + (z1max_ - z1min_) * T(std::rand()) / T(RAND_MAX);
189 T zmin = std::min(z0, z1);
190 T zmax = std::max(z0, z1);
191
192 obj.transform([xmin, xmax, ymin, ymax, zmin, zmax](const std::array<T, 3> X) {
193 return std::array<T, 3>{
194 static_cast<T>(xmax * X[0] + xmin * (X[0] - T(1))),
195 static_cast<T>(ymax * X[1] + ymin * (X[1] - T(1))),
196 static_cast<T>(zmax * X[2] + zmin * (X[2] - T(1)))
197 };
198 });
199
200 return obj;
201 }
202
204 virtual void
205 pretty_print(std::ostream &os = Log(log::info)) 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:
217};
218
219} // namespace iganet
Multivariate B-splines.
Abstract creator class.
Definition creator.hpp:27
virtual void pretty_print(std::ostream &os=Log(log::info)) const noexcept=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:216
T y0max_
Definition creator.hpp:216
T z0max_
Definition creator.hpp:216
CuboidCreator()
Default constructor.
Definition creator.hpp:155
T y0min_
Definition creator.hpp:216
T z1max_
Definition creator.hpp:216
virtual void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the RectangleCreator object.
Definition creator.hpp:205
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:173
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:45
T x1max_
Definition creator.hpp:85
IntervalCreator()
Default constructor.
Definition creator.hpp:48
virtual void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the IntervalCreator object.
Definition creator.hpp:78
T x0min_
Definition creator.hpp:85
auto & next(Spline &obj) const
Definition creator.hpp:59
T x1min_
Definition creator.hpp:85
IntervalCreator(const T &x0min, const T &x0max, const T &x1min, const T &x1max)
Bounds constructor.
Definition creator.hpp:53
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
virtual void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the RectangleCreator object.
Definition creator.hpp:136
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:110
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
Full qualified name descriptor.
Definition fqn.hpp:26
Concept to identify template parameters that are derived from iganet::Spline_.
Definition bspline.hpp:3259
Full qualified name utility functions.
Definition boundary.hpp:22
struct iganet::@0 Log
Logger.
std::ostream & operator<<(std::ostream &os, const Boundary< Spline > &obj)
Print (as string) a Boundary object.
Definition boundary.hpp:1963