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)
56 std::srand(std::time(0));
57 }
58
59 template <typename 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 {
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)
107 std::srand(std::time(0));
108 }
109
110 template <typename Spline> auto &next(Spline &obj) const {
111 static_assert(Spline::parDim() == 2 && Spline::geoDim() == 2,
112 "Interval 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 });
128
129 return obj;
130 }
131
133 virtual void
134 pretty_print(std::ostream &os = Log(log::info)) const noexcept override {
136 << "(x0min = " << x0min_ << ", x0max = " << x0max_
137 << "; x1min = " << x1min_ << ", x1max = " << x1max_
138 << "; y0min = " << y0min_ << ", y0max = " << y0max_
139 << "; y1min = " << y1min_ << ", y1max = " << y1max_ << ")";
140 }
141
142private:
144};
145
146} // 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.
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
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
auto & next(Spline &obj) const
Definition creator.hpp:59
T x0max_
Definition creator.hpp:85
Rectangle creator class.
Definition creator.hpp:92
T y0min_
Definition creator.hpp:143
T y0max_
Definition creator.hpp:143
virtual void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the RectangleCreator object.
Definition creator.hpp:134
T x1min_
Definition creator.hpp:143
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:143
T x0min_
Definition creator.hpp:143
T x1max_
Definition creator.hpp:143
RectangleCreator()
Default constructor.
Definition creator.hpp:95
T y1max_
Definition creator.hpp:143
auto & next(Spline &obj) const
Definition creator.hpp:110
T x0max_
Definition creator.hpp:143
Full qualified name descriptor.
Definition fqn.hpp:26
Full qualified name utility functions.
Definition boundary.hpp:22
constexpr bool is_SplineType_v
Alias to the value of is_SplineType.
Definition bspline.hpp:3243
std::ostream & operator<<(std::ostream &os, const Boundary< Spline > &obj)
Print (as string) a Boundary object.
Definition boundary.hpp:1978
struct iganet::@0 Log
Logger.