IgANet
IgANets - Isogeometric Analysis Networks
Loading...
Searching...
No Matches
GismoKLShellModel.hpp
Go to the documentation of this file.
1
15#pragma once
16
17#include <GismoPdeModel.hpp>
18
19namespace iganet {
20
21namespace webapp {
22
24template <short_t d, typename T>
25class GismoKLShellModel : public GismoPdeModel<d, T>,
26 public ModelEval,
27 public ModelParameters {
28
29private:
32
34 using geometryMap_type = typename gsExprAssembler<T>::geometryMap;
35
37 using variable_type = typename gsExprAssembler<T>::variable;
38
40 using space_type = typename gsExprAssembler<T>::space;
41
43 using solution_type = typename gsExprAssembler<T>::solution;
44
47
50
53
55 std::array<gsFunctionExpr<T>, 2 * d> bcFunc_;
56
59
62
64 void solve() {
65
66 // Set up expression assembler
67 auto G = assembler_.getMap(Base::geo_);
68 auto u = assembler_.getSpace(basis_);
69 auto f = assembler_.getCoeff(rhsFunc_, G);
70
71 // Impose boundary conditions
72 u.setup(bc_, gismo::dirichlet::l2Projection, 0);
73
74 // Set up system
75 assembler_.initSystem();
76 assembler_.assemble(igrad(u, G) * igrad(u, G).tr() * meas(G) // matrix
77 ,
78 u * f * meas(G) // rhs vector
79 );
80
81 // Solve system
82 typename gismo::gsSparseSolver<T>::CGDiagonal solver;
83 solver.compute(assembler_.matrix());
84
86 solution_type solution = assembler_.getSolution(u, solutionVector);
87 solutionVector = solver.solve(assembler_.rhs());
88
89 // Extract solution
90 solution.extract(solution_);
91 }
92
93public:
96
98 GismoKLShellModel(const std::array<short_t, d> degrees,
99 const std::array<int64_t, d> ncoeffs,
100 const std::array<int64_t, d> npatches)
101 : Base(degrees, ncoeffs, npatches), basis_(Base::geo_, true),
102 rhsFunc_("2*pi^2*sin(pi*x)*sin(pi*y)", d), assembler_(1, 1) {
103 // Specify assembler options
105
106 Aopt.addInt("DirichletStrategy",
107 "Method for enforcement of Dirichlet BCs [11..14]", 11);
108 Aopt.addInt("DirichletValues",
109 "Method for computation of Dirichlet DoF values [100..103]",
110 101);
111 Aopt.addInt("InterfaceStrategy",
112 "Method of treatment of patch interfaces [0..3]", 1);
113 Aopt.addReal(
114 "bdA", "Estimated nonzeros per column of the matrix: bdA*deg + bdB", 2);
115 Aopt.addInt(
116 "bdB", "Estimated nonzeros per column of the matrix: bdA*deg + bdB", 1);
117 Aopt.addReal(
118 "bdO",
119 "Overhead of sparse mem. allocation: (1+bdO)(bdA*deg + bdB) [0..1]",
120 0.333);
121 Aopt.addReal("quA", "Number of quadrature points: quA*deg + quB", 1);
122 Aopt.addInt("quB", "Number of quadrature points: quA*deg + quB", 1);
123 Aopt.addInt("quRule", "Quadrature rule [1:GaussLegendre, 2:GaussLobatto]",
124 1);
125
126 // Set assembler options
127 assembler_.setOptions(Aopt);
128
129 // Set assembler basis
130 assembler_.setIntegrationElements(basis_);
131
132 // Set boundary conditions
133 for (short_t i = 0; i < 2 * d; ++i) {
134 if constexpr (d == 1)
135 bcFunc_[i] = gismo::give(gsFunctionExpr<T>("sin(pi*x)", 1));
136 else if constexpr (d == 2)
137 bcFunc_[i] = gismo::give(gsFunctionExpr<T>("sin(pi*x)*sin(pi*y)", 2));
138 else if constexpr (d == 3)
139 bcFunc_[i] =
140 gismo::give(gsFunctionExpr<T>("sin(pi*x)*sin(pi*y)*sin(pi*z)", 3));
141 else if constexpr (d == 4)
142 bcFunc_[i] = gismo::give(
143 gsFunctionExpr<T>("sin(pi*x)*sin(pi*y)*sin(pi*z)*sin(pi*t)", 4));
144
145 bc_.addCondition(i + 1, gismo::condition_type::dirichlet, &bcFunc_[i]);
146 }
147
148 // Set geometry
149 bc_.setGeoMap(Base::geo_);
150
151 // Generate solution
152 solve();
153 }
154
157
159 std::string getName() const override {
160 return "GismoKLShell" + std::to_string(d) + "d";
161 }
162
164 std::string getDescription() const override {
165 return "G+Smo Kirchhoff-Love Shell model in " + std::to_string(d) +
166 " dimensions";
167 };
168
170 nlohmann::json getOutputs() const override {
171 return R"([{
172 "name" : "Solution",
173 "description" : "Solution of the Kirchhoff-Love shell model",
174 "type" : 1}])"_json;
175 }
176
178 nlohmann::json getParameters() const override {
179
180 if constexpr (d == 1)
181 return R"([{
182 "name" : "bc_east",
183 "description" : "Boundary condition at the east boundary",
184 "type" : "text",
185 "value" : "0",
186 "default" : "0",
187 "uiid" : 0},{
188 "name" : "bc_west",
189 "description" : "Boundary condition at the west boundary",
190 "type" : "text",
191 "value" : "0",
192 "default" : "0",
193 "uiid" : 1},{
194 "name" : "rhs",
195 "description" : "Right-hand side function",
196 "type" : "text",
197 "value" : "0",
198 "default" : "0",
199 "uiid" : 2}])"_json;
200 else if constexpr (d == 2)
201 return R"([{
202 "name" : "bc_north",
203 "description" : "Boundary condition at the north boundary",
204 "type" : "text",
205 "value" : "0",
206 "default" : "0",
207 "uiid" : 0},{
208 "name" : "bc_east",
209 "description" : "Boundary condition at the east boundary",
210 "type" : "text",
211 "value" : "0",
212 "default" : "0",
213 "uiid" : 1},{
214 "name" : "bc_south",
215 "description" : "Boundary condition at the south boundary",
216 "type" : "text",
217 "value" : "0",
218 "default" : "0",
219 "uiid" : 2},{
220 "name" : "bc_west",
221 "description" : "Boundary condition at the west boundary",
222 "type" : "text",
223 "value" : "0",
224 "default" : "0",
225 "uiid" : 3},{
226 "name" : "rhs",
227 "description" : "Right-hand side function",
228 "type" : "text",
229 "value" : "0",
230 "default" : "0",
231 "uiid" : 4}])"_json;
232 else if constexpr (d == 3)
233 return R"([{
234 "name" : "bc_north",
235 "description" : "Boundary condition at the north boundary",
236 "type" : "text",
237 "value" : "0",
238 "default" : "0",
239 "uiid" : 0},{
240 "name" : "bc_east",
241 "description" : "Boundary condition at the east boundary",
242 "type" : "text",
243 "value" : "0",
244 "default" : "0",
245 "uiid" : 1},{
246 "name" : "bc_south",
247 "description" : "Boundary condition at the south boundary",
248 "type" : "text",
249 "value" : "0",
250 "default" : "0",
251 "uiid" : 2},{
252 "name" : "bc_west",
253 "description" : "Boundary condition at the west boundary",
254 "type" : "text",
255 "value" : "0",
256 "default" : "0",
257 "uiid" : 3},{
258 "name" : "bc_front",
259 "description" : "Boundary condition at the front boundary",
260 "type" : "text",
261 "value" : "0",
262 "default" : "0",
263 "uiid" : 4},{
264 "name" : "bc_back",
265 "description" : "Boundary condition at the back boundary",
266 "type" : "text",
267 "value" : "0",
268 "default" : "0",
269 "uiid" : 5},{
270 "name" : "rhs",
271 "description" : "Right-hand side function",
272 "type" : "text",
273 "value" : "0",
274 "default" : "0",
275 "uiid" : 6}])"_json;
276 else if constexpr (d == 4)
277 return R"([{
278 "name" : "bc_north",
279 "description" : "Boundary condition at the north boundary",
280 "type" : "text",
281 "value" : "0",
282 "default" : "0",
283 "uiid" : 0},{
284 "name" : "bc_east",
285 "description" : "Boundary condition at the east boundary",
286 "type" : "text",
287 "value" : "0",
288 "default" : "0",
289 "uiid" : 1},{
290 "name" : "bc_south",
291 "description" : "Boundary condition at the south boundary",
292 "type" : "text",
293 "value" : "0",
294 "default" : "0",
295 "uiid" : 2},{
296 "name" : "bc_west",
297 "description" : "Boundary condition at the west boundary",
298 "type" : "text",
299 "value" : "0",
300 "default" : "0",
301 "uiid" : 3},{
302 "name" : "bc_front",
303 "description" : "Boundary condition at the front boundary",
304 "type" : "text",
305 "value" : "0",
306 "default" : "0",
307 "uiid" : 4},{
308 "name" : "bc_back",
309 "description" : "Boundary condition at the back boundary",
310 "type" : "text",
311 "value" : "0",
312 "default" : "0",
313 "uiid" : 5},{
314 "name" : "bc_stime",
315 "description" : "Boundary condition at the start-time boundary",
316 "type" : "text",
317 "value" : "0",
318 "default" : "0",
319 "uiid" : 6},{
320 "name" : "bc_etime",
321 "description" : "Boundary condition at the end-time boundary",
322 "type" : "text",
323 "value" : "0",
324 "default" : "0",
325 "uiid" : 7},{
326 "name" : "rhs",
327 "description" : "Right-hand side function",
328 "type" : "text",
329 "value" : "0",
330 "default" : "0",
331 "uiid" : 8}])"_json;
332 else
333 return R"({ INVALID REQUEST })"_json;
334 }
335
337 nlohmann::json updateAttribute(const std::string &component,
338 const std::string &attribute,
339 const nlohmann::json &json) override {
340
341 nlohmann::json result = R"({})"_json;
342
343 if (attribute == "bc_north") {
344 if (!json.contains("data"))
346 if (!json["data"].contains("bc_north"))
348
349 bcFunc_[gismo::boundary::north] =
350 gsFunctionExpr<T>(json["data"]["bc_north"].get<std::string>(), d);
351 }
352
353 else if (attribute == "bc_east") {
354 if (!json.contains("data"))
356 if (!json["data"].contains("bc_east"))
358
359 bcFunc_[gismo::boundary::east] =
360 gsFunctionExpr<T>(json["data"]["bc_east"].get<std::string>(), d);
361 }
362
363 else if (attribute == "bc_south") {
364 if (!json.contains("data"))
366 if (!json["data"].contains("bc_south"))
368
369 bcFunc_[gismo::boundary::south] =
370 gsFunctionExpr<T>(json["data"]["bc_south"].get<std::string>(), d);
371 }
372
373 else if (attribute == "bc_west") {
374 if (!json.contains("data"))
376 if (!json["data"].contains("bc_west"))
378
379 bcFunc_[gismo::boundary::west] =
380 gsFunctionExpr<T>(json["data"]["bc_west"].get<std::string>(), d);
381 }
382
383 else if (attribute == "bc_front") {
384 if (!json.contains("data"))
386 if (!json["data"].contains("bc_front"))
388
389 bcFunc_[gismo::boundary::front] =
390 gsFunctionExpr<T>(json["data"]["bc_front"].get<std::string>(), d);
391 }
392
393 else if (attribute == "bc_back") {
394 if (!json.contains("data"))
396 if (!json["data"].contains("bc_back"))
398
399 bcFunc_[gismo::boundary::back] =
400 gsFunctionExpr<T>(json["data"]["bc_back"].get<std::string>(), d);
401 }
402
403 else if (attribute == "bc_stime") {
404 if (!json.contains("data"))
406 if (!json["data"].contains("bc_stime"))
408
409 bcFunc_[gismo::boundary::stime] =
410 gsFunctionExpr<T>(json["data"]["bc_stime"].get<std::string>(), d);
411 }
412
413 else if (attribute == "bc_etime") {
414 if (!json.contains("data"))
416 if (!json["data"].contains("bc_etime"))
418
419 bcFunc_[gismo::boundary::etime] =
420 gsFunctionExpr<T>(json["data"]["bc_etime"].get<std::string>(), d);
421 }
422
423 else if (attribute == "rhs") {
424 if (!json.contains("data"))
426 if (!json["data"].contains("rhs"))
428
429 rhsFunc_ = gsFunctionExpr<T>(json["data"]["rhs"].get<std::string>(), d);
430 }
431
432 else
434
435 // Solve updated problem
436 solve();
437
438 return result;
439 }
440
442 nlohmann::json eval(const std::string &component,
443 const nlohmann::json &json) const override {
444
445 // Create uniform grid
446 gsMatrix<T> ab = Base::geo_.patch(0).support();
447 gsVector<T> a = ab.col(0);
448 gsVector<T> b = ab.col(1);
449
451 np.setConstant(25);
452
453 if (json.contains("data"))
454 if (json["data"].contains("resolution")) {
455 auto res = json["data"]["resolution"].get<std::array<int64_t, d>>();
456
457 for (std::size_t i = 0; i < d; ++i)
458 np(i) = res[i];
459 }
460
461 // Uniform parameters for evaluation
463 gsMatrix<T> eval = solution_.patch(0).eval(pts);
464
465 return utils::to_json(eval, true);
466 }
467
469 void refine(const nlohmann::json &json = NULL) override {
470
471 // Refine geometry
473
474 // Set geometry
475 bc_.setGeoMap(Base::geo_);
476
477 int num = 1, dim = -1;
478
479 if (json.contains("data")) {
480 if (json["data"].contains("num"))
481 num = json["data"]["num"].get<int>();
482
483 if (json["data"].contains("dim"))
484 dim = json["data"]["dim"].get<int>();
485 }
486
487 // Refine basis of solution space
488 basis_.basis(0).uniformRefine(num, 1, dim);
489
490 // Set assembler basis
491 assembler_.setIntegrationElements(basis_);
492 }
493};
494
495} // namespace webapp
496} // namespace iganet
G+Smo PDE model.
Model evaluator.
Definition model.hpp:98
virtual nlohmann::json updateAttribute(const std::string &patch, const std::string &component, const std::string &attribute, const nlohmann::json &json)
Updates the attributes of the model.
Definition model.hpp:297
virtual void refine(const nlohmann::json &json)=0
Refines model.
gismo::gsMultiPatch< T > geo_
Multi-patch geometry.
Definition GismoGeometryModel.hpp:39
G+Smo Kirchhoff-Love shell model.
Definition GismoKLShellModel.hpp:27
gsMultiBasis< T > basis_
Multi-patch basis.
Definition GismoKLShellModel.hpp:46
nlohmann::json getParameters() const override
Returns the model's parameters.
Definition GismoKLShellModel.hpp:178
gsMultiPatch< T > solution_
Solution.
Definition GismoKLShellModel.hpp:61
void solve()
Solve the Poisson problem.
Definition GismoKLShellModel.hpp:64
GismoKLShellModel(const std::array< short_t, d > degrees, const std::array< int64_t, d > ncoeffs, const std::array< int64_t, d > npatches)
Constructor for equidistant knot vectors.
Definition GismoKLShellModel.hpp:98
typename gsExprAssembler< T >::space space_type
Type of the function space.
Definition GismoKLShellModel.hpp:40
gsBoundaryConditions< T > bc_
Boundary conditions.
Definition GismoKLShellModel.hpp:49
typename gsExprAssembler< T >::geometryMap geometryMap_type
Type of the geometry mapping.
Definition GismoKLShellModel.hpp:34
typename gsExprAssembler< T >::variable variable_type
Type of the variable.
Definition GismoKLShellModel.hpp:37
nlohmann::json eval(const std::string &component, const nlohmann::json &json) const override
Evaluates the model.
Definition GismoKLShellModel.hpp:442
~GismoKLShellModel()
Destructor.
Definition GismoKLShellModel.hpp:156
gsFunctionExpr< T > rhsFunc_
Right-hand side values.
Definition GismoKLShellModel.hpp:52
typename gsExprAssembler< T >::solution solution_type
Type of the solution.
Definition GismoKLShellModel.hpp:43
gsExprAssembler< T > assembler_
Expression assembler.
Definition GismoKLShellModel.hpp:58
std::string getDescription() const override
Returns the model's description.
Definition GismoKLShellModel.hpp:164
nlohmann::json updateAttribute(const std::string &component, const std::string &attribute, const nlohmann::json &json) override
Updates the attributes of the model.
Definition GismoKLShellModel.hpp:337
nlohmann::json getOutputs() const override
Returns the model's outputs.
Definition GismoKLShellModel.hpp:170
std::array< gsFunctionExpr< T >, 2 *d > bcFunc_
Boundary values.
Definition GismoKLShellModel.hpp:55
void refine(const nlohmann::json &json=NULL) override
Refines the model.
Definition GismoKLShellModel.hpp:469
std::string getName() const override
Returns the model's name.
Definition GismoKLShellModel.hpp:159
GismoKLShellModel()=delete
Default constructor.
G+Smo PDE model.
Definition GismoPdeModel.hpp:58
auto to_json(const torch::TensorAccessor< T, N > &accessor)
Converts a torch::TensorAccessor object to a JSON object.
Definition serialize.hpp:41
Definition boundary.hpp:22
constexpr bool is_SplineType_v
Alias to the value of is_SplineType.
Definition bspline.hpp:3243
short int short_t
Definition core.hpp:74
InvalidModelAttribute exception.
Definition model.hpp:42