IgANet
IGAnets - Isogeometric Analysis Networks
Loading...
Searching...
No Matches
ezsolver.hpp
Go to the documentation of this file.
1
15#pragma once
16
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:
62 template <std::size_t GeometryMapNumCoeffs, std::size_t VariableNumCoeffs>
63 EZSolverBase(const std::array<int64_t, GeometryMapNumCoeffs> &geometryMapNumCoeffs,
64 const std::array<int64_t, VariableNumCoeffs> &variableNumCoeffs)
65 : Base(std::make_tuple(geometryMapNumCoeffs),
66 std::make_tuple(variableNumCoeffs)) {}
67
70 auto const &collPts() const { return collPts_; }
71
72
75 auto const &G() const { return Base::template input<0>(); }
76
79 auto &G() { return Base::template input<0>(); }
80
83 auto const &u() const { return Base::template output<0>(); }
84
87 auto &u() { return Base::template output<0>(); }
88
90 void init() override {
91 collPts_ =
94 G().template find_knot_indices<iganet::functionspace::interior>(collPts_.first);
96 G().template find_knot_indices<iganet::functionspace::boundary>(collPts_.second);
98 u().template find_knot_indices<iganet::functionspace::interior>(collPts_.first);
100 u().template find_knot_indices<iganet::functionspace::boundary>(collPts_.second);
101 }
102};
103
108template <FunctionSpaceType GeometryMap, FunctionSpaceType Variable>
109class EZSolver : public EZSolverBase<GeometryMap, Variable> {
110private:
113
115 std::function<
116 std::array<torch::Tensor, Variable::template geoDim<0>()>(
117 const std::array<torch::Tensor, Variable::template parDim<0>()>&
118 )
120
121public:
126 EZSolver(const GeometryMap& geometryMap, const Variable& variable,
127 const std::function<
128 std::array<torch::Tensor, Variable::template geoDim<0>()>(
129 const std::array<torch::Tensor, Variable::template parDim<0>()>&
130 )
131 >& rhs)
132 : EZSolverBase<GeometryMap, Variable>(geometryMap.template space<0>().ncoeffs(), variable.template space<0>().ncoeffs()),
133 rhs_(rhs) {}
134
136 void assembleLhs() override {
137
138 auto S_xx = this->u().template eval_basfunc<functionspace::interior,
139 (deriv::dx^2)>(Base::collPts_.first,
141 auto S_yy = this->u().template eval_basfunc<functionspace::interior,
142 (deriv::dy^2)>(Base::collPts_.first,
144
145 auto M = this->u().template eval_basfunc(Base::collPts_.first,Base::var_knot_indices_);
146
147 //M = torch::zeros({16, 100});
148
149 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);
150
152 this->u().template space<0>().degrees(),
153 this->u().template space<0>().ncoeffs(),
154 torch::where(mask, M, S_xx+S_yy).t(),
155 { this->u().template space<0>().ncumcoeffs(),
156 this->u().template space<0>().ncumcoeffs() });
157 }
158
160 void assembleRhs() override {
161 Base::rhs_ = rhs_(Base::collPts().first)[0];
162 }
163};
164
169template <FunctionSpaceType GeometryMap, FunctionSpaceType Variable>
170class EZInterpolation : public EZSolverBase<GeometryMap, Variable> {
171private:
174
176 std::function<
177 std::array<torch::Tensor, Variable::template geoDim<0>()>(
178 const std::array<torch::Tensor, Variable::template parDim<0>()>&
179 )
181
182public:
187 EZInterpolation(const GeometryMap& geometryMap, const Variable& variable,
188 const std::function<
189 std::array<torch::Tensor, Variable::template geoDim<0>()>(
190 const std::array<torch::Tensor, Variable::template parDim<0>()>&
191 )
192 >& rhs)
193 : EZSolverBase<GeometryMap, Variable>(geometryMap.template space<0>().ncoeffs(), variable.template space<0>().ncoeffs()), rhs_(rhs) {}
194
196 void assembleLhs() override {
198 this->u().template space<0>().degrees(),
199 this->u().template space<0>().ncoeffs(),
200 this->u().template eval_basfunc(Base::collPts_.first, Base::var_knot_indices_).t(),
201 { this->u().template space<0>().ncumcoeffs(),
202 this->u().template space<0>().ncumcoeffs() });
203 }
204
206 void assembleRhs() override {
207 Base::rhs_ = rhs_(Base::collPts().first)[0];
208 }
209};
210
215template <FunctionSpaceType GeometryMap, FunctionSpaceType Variable>
216auto ezinterp(const GeometryMap& geometryMap,
217 const Variable& variable,
218 const std::function<std::array<torch::Tensor, Variable::template geoDim<0>()>(const std::array<torch::Tensor, Variable::template parDim<0>()> &)>
219 mapping) {
220
221 EZInterpolation interp(geometryMap, variable, mapping);
222 interp.init();
223 interp.assemble();
224 return interp.solve().clone();
225}
226
228template <FunctionSpaceType GeometryMap, FunctionSpaceType Variable>
229auto ezpoisson(const GeometryMap& geometryMap,
230 const Variable& variable,
231 const std::function<std::array<torch::Tensor, Variable::template geoDim<0>()>(const std::array<torch::Tensor, Variable::template parDim<0>()> &)>
232 rhs) {
233
234 EZSolver solver(geometryMap, variable, rhs);
235 solver.init();
236 solver.assemble();
237 return solver.solve().clone();
238}
239
240} // namespace iganet
Multivariate B-splines.
Easy-to-use interpolation class.
Definition ezsolver.hpp:170
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:180
void assembleLhs() override
Assembles the left-hand side as the mass matrix.
Definition ezsolver.hpp:196
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:187
void assembleRhs() override
Assembles the right-hand side from the given function.
Definition ezsolver.hpp:206
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:75
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:83
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:79
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:90
auto & u()
Returns a non-constant reference to the variable.
Definition ezsolver.hpp:87
EZSolverBase(const std::array< int64_t, GeometryMapNumCoeffs > &geometryMapNumCoeffs, const std::array< int64_t, VariableNumCoeffs > &variableNumCoeffs)
Constructor.
Definition ezsolver.hpp:63
auto const & collPts() const
Returns a constant reference to the collocation points.
Definition ezsolver.hpp:70
Easy-to-use solver class.
Definition ezsolver.hpp:109
void assembleRhs() override
Assembles the right-hand side from the given function.
Definition ezsolver.hpp:160
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:119
void assembleLhs() override
Assembles the left-hand side as the mass matrix.
Definition ezsolver.hpp:136
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:126
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:55
virtual void assemble()
Assembles the solver.
Definition igasolver.hpp:65
torch::Tensor solve() const
Computes the solution vector.
Definition igasolver.hpp:78
IgANet base.
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:31
Definition core.hpp:73
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:229
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:216
IgANetCustomizable.
Definition iganet.hpp:1299
STL namespace.