IgANet
IGAnets - Isogeometric Analysis Networks
Loading...
Searching...
No Matches
ezsolver.hpp
Go to the documentation of this file.
1
15#pragma once
16
17#include <net/igabase.hpp>
18#include <solver/igasolver.hpp>
19#include <splines/bspline.hpp>
20#include <utils/matrix.hpp>
21
22namespace iganet {
23
30template <FunctionSpaceType GeometryMap, FunctionSpaceType Variable>
31class EZSolverBase : public iganet::IgASolver<std::tuple<GeometryMap>, std::tuple<Variable>>,
32 public iganet::IgANetCustomizable<std::tuple<GeometryMap>, std::tuple<Variable>> {
33
34protected:
36 using Base = iganet::IgASolver<std::tuple<GeometryMap>, std::tuple<Variable>>;
37
39 Base::template collPts_t<0> collPts_;
40
43
45 Customizable::template input_interior_knot_indices_t<0> G_knot_indices_;
46
48 Customizable::template input_boundary_knot_indices_t<0> G_knot_indices_boundary_;
49
51 Customizable::template output_interior_knot_indices_t<0> var_knot_indices_;
52
54 Customizable::template output_boundary_knot_indices_t<0> var_knot_indices_boundary_;
55
56public:
58 template <std::size_t GeometryMapNumCoeffs, std::size_t VariableNumCoeffs>
59 EZSolverBase(const std::array<int64_t, GeometryMapNumCoeffs> &geometryMapNumCoeffs,
60 const std::array<int64_t, VariableNumCoeffs> &variableNumCoeffs)
61 : Base(std::make_tuple(geometryMapNumCoeffs),
62 std::make_tuple(variableNumCoeffs)) {}
63
65 auto const &collPts() const { return collPts_; }
66
67
69 auto const &G() const { return Base::template input<0>(); }
70
72 auto &G() { return Base::template input<0>(); }
73
75 auto const &u() const { return Base::template output<0>(); }
76
78 auto &u() { return Base::template output<0>(); }
79
81 void init() override {
82 collPts_ =
85 G().template find_knot_indices<iganet::functionspace::interior>(collPts_.first);
87 G().template find_knot_indices<iganet::functionspace::boundary>(collPts_.second);
89 u().template find_knot_indices<iganet::functionspace::interior>(collPts_.first);
91 u().template find_knot_indices<iganet::functionspace::boundary>(collPts_.second);
92 }
93};
94
99template <FunctionSpaceType GeometryMap, FunctionSpaceType Variable>
100class EZSolver : public EZSolverBase<GeometryMap, Variable> {
101private:
104
106 std::function<
107 std::array<torch::Tensor, Variable::template geoDim<0>()>(
108 const std::array<torch::Tensor, Variable::template parDim<0>()>&
109 )
111
112public:
114 EZSolver(const GeometryMap& geometryMap, const Variable& variable,
115 const std::function<
116 std::array<torch::Tensor, Variable::template geoDim<0>()>(
117 const std::array<torch::Tensor, Variable::template parDim<0>()>&
118 )
119 >& rhs)
120 : EZSolverBase<GeometryMap, Variable>(geometryMap.template space<0>().ncoeffs(), variable.template space<0>().ncoeffs()),
121 rhs_(rhs) {}
122
124 void assembleLhs() override {
125
126 auto S_xx = this->u().template eval_basfunc<functionspace::interior,
127 (deriv::dx^2)>(Base::collPts_.first,
129 auto S_yy = this->u().template eval_basfunc<functionspace::interior,
130 (deriv::dy^2)>(Base::collPts_.first,
132
133 auto M = this->u().template eval_basfunc(Base::collPts_.first,Base::var_knot_indices_);
134
135 //M = torch::zeros({16, 100});
136
137 auto mask = (Base::collPts_.first[0] == 0.0) | (Base::collPts_.first[0] == 1.0) | (Base::collPts_.first[1] == 0.0) | (Base::collPts_.first[1] == 1.0);
138
140 this->u().template space<0>().degrees(),
141 this->u().template space<0>().ncoeffs(),
142 torch::where(mask, M, S_xx+S_yy).t(),
143 { this->u().template space<0>().ncumcoeffs(),
144 this->u().template space<0>().ncumcoeffs() });
145 }
146
148 void assembleRhs() override {
149 Base::rhs_ = rhs_(Base::collPts().first)[0];
150 }
151};
152
157template <FunctionSpaceType GeometryMap, FunctionSpaceType Variable>
158class EZInterpolation : public EZSolverBase<GeometryMap, Variable> {
159private:
162
164 std::function<
165 std::array<torch::Tensor, Variable::template geoDim<0>()>(
166 const std::array<torch::Tensor, Variable::template parDim<0>()>&
167 )
169
170public:
172 EZInterpolation(const GeometryMap& geometryMap, const Variable& variable,
173 const std::function<
174 std::array<torch::Tensor, Variable::template geoDim<0>()>(
175 const std::array<torch::Tensor, Variable::template parDim<0>()>&
176 )
177 >& rhs)
178 : EZSolverBase<GeometryMap, Variable>(geometryMap.template space<0>().ncoeffs(), variable.template space<0>().ncoeffs()), rhs_(rhs) {}
179
181 void assembleLhs() override {
183 this->u().template space<0>().degrees(),
184 this->u().template space<0>().ncoeffs(),
185 this->u().template eval_basfunc(Base::collPts_.first, Base::var_knot_indices_).t(),
186 { this->u().template space<0>().ncumcoeffs(),
187 this->u().template space<0>().ncumcoeffs() });
188 }
189
191 void assembleRhs() override {
192 Base::rhs_ = rhs_(Base::collPts().first)[0];
193 }
194};
195
200template <FunctionSpaceType GeometryMap, FunctionSpaceType Variable>
201auto ezinterp(const GeometryMap& geometryMap,
202 const Variable& variable,
203 const std::function<std::array<torch::Tensor, Variable::template geoDim<0>()>(const std::array<torch::Tensor, Variable::template parDim<0>()> &)>
204 mapping) {
205
206 EZInterpolation interp(geometryMap, variable, mapping);
207 interp.init();
208 interp.assemble();
209 return interp.solve().clone();
210}
211
213template <FunctionSpaceType GeometryMap, FunctionSpaceType Variable>
214auto ezpoisson(const GeometryMap& geometryMap,
215 const Variable& variable,
216 const std::function<std::array<torch::Tensor, Variable::template geoDim<0>()>(const std::array<torch::Tensor, Variable::template parDim<0>()> &)>
217 rhs) {
218
219 EZSolver solver(geometryMap, variable, rhs);
220 solver.init();
221 solver.assemble();
222 return solver.solve().clone();
223}
224
225} // namespace iganet
Multivariate B-splines.
Easy-to-use interpolation class.
Definition ezsolver.hpp:158
std::function< std::array< torch::Tensor, Variable::template geoDim< 0 >()>(const std::array< torch::Tensor, Variable::template parDim< 0 >()> &) > rhs_
Right-hand side function.
Definition ezsolver.hpp:168
void assembleLhs() override
Assembles the left-hand side as the mass matrix.
Definition ezsolver.hpp:181
EZInterpolation(const GeometryMap &geometryMap, const Variable &variable, const std::function< std::array< torch::Tensor, Variable::template geoDim< 0 >()>(const std::array< torch::Tensor, Variable::template parDim< 0 >()> &) > &rhs)
Constructor.
Definition ezsolver.hpp:172
void assembleRhs() override
Assembles the right-hand side from the given function.
Definition ezsolver.hpp:191
Easy-to-use solver base class.
Definition ezsolver.hpp:32
Customizable::template output_boundary_knot_indices_t< 0 > var_knot_indices_boundary_
Knot indices of variables at the boundary.
Definition ezsolver.hpp:54
auto const & G() const
Returns a constant reference to the geometry.
Definition ezsolver.hpp:69
Customizable::template input_boundary_knot_indices_t< 0 > G_knot_indices_boundary_
Knot indices of the geometry map at the boundary.
Definition ezsolver.hpp:48
Customizable::template input_interior_knot_indices_t< 0 > G_knot_indices_
Knot indices of the geometry map.
Definition ezsolver.hpp:45
auto const & u() const
Returns a constant reference to the variable.
Definition ezsolver.hpp:75
Base::template collPts_t< 0 > collPts_
Collocation points.
Definition ezsolver.hpp:39
auto & G()
Returns a non-constant reference to the geometry.
Definition ezsolver.hpp:72
Customizable::template output_interior_knot_indices_t< 0 > var_knot_indices_
Knot indices of variables.
Definition ezsolver.hpp:51
void init() override
Initializes the solver.
Definition ezsolver.hpp:81
auto & u()
Returns a non-constant reference to the variable.
Definition ezsolver.hpp:78
EZSolverBase(const std::array< int64_t, GeometryMapNumCoeffs > &geometryMapNumCoeffs, const std::array< int64_t, VariableNumCoeffs > &variableNumCoeffs)
Constructor.
Definition ezsolver.hpp:59
auto const & collPts() const
Returns a constant reference to the collocation points.
Definition ezsolver.hpp:65
Easy-to-use solver class.
Definition ezsolver.hpp:100
void assembleRhs() override
Assembles the right-hand side from the given function.
Definition ezsolver.hpp:148
std::function< std::array< torch::Tensor, Variable::template geoDim< 0 >()>(const std::array< torch::Tensor, Variable::template parDim< 0 >()> &) > rhs_
Right-hand side function.
Definition ezsolver.hpp:110
void assembleLhs() override
Assembles the left-hand side as the mass matrix.
Definition ezsolver.hpp:124
EZSolver(const GeometryMap &geometryMap, const Variable &variable, const std::function< std::array< torch::Tensor, Variable::template geoDim< 0 >()>(const std::array< torch::Tensor, Variable::template parDim< 0 >()> &) > &rhs)
Constructor.
Definition ezsolver.hpp:114
IgA solver.
Definition igasolver.hpp:29
torch::Tensor lhs_
Left-hand side tensor.
Definition igasolver.hpp:33
torch::Tensor rhs_
Right-hand side tensor.
Definition igasolver.hpp:36
constexpr const auto & rhs() const
Returns a constant reference to the right-hand side object.
Definition igasolver.hpp:52
virtual void assemble()
Assembles the solver.
Definition igasolver.hpp:61
torch::Tensor solve() const
Computes the solution vector.
Definition igasolver.hpp:73
Isogeometric analysis solver.
Matrix utility functions.
torch::Tensor to_sparseCsrTensor(const torch::Tensor &col_indices, const torch::Tensor &values, const torch::IntArrayRef &size)
Constructs a sparse-CSR matrix from the column indices, matrix values and the matrix size.
Definition matrix.hpp:30
Definition core.hpp:72
auto ezpoisson(const GeometryMap &geometryMap, const Variable &variable, const std::function< std::array< torch::Tensor, Variable::template geoDim< 0 >()>(const std::array< torch::Tensor, Variable::template parDim< 0 >()> &)> rhs)
Easy-to-use Poisson solver function.
Definition ezsolver.hpp:214
collPts
Enumerator for the collocation point specifier.
Definition collocation.hpp:21
auto ezinterp(const GeometryMap &geometryMap, const Variable &variable, const std::function< std::array< torch::Tensor, Variable::template geoDim< 0 >()>(const std::array< torch::Tensor, Variable::template parDim< 0 >()> &)> mapping)
Easy-to-use interpolation function.
Definition ezsolver.hpp:201
IgANetCustomizable.
Definition iganet.hpp:1125
STL namespace.