b2api
B2000++ API Reference Manual, VERSION 4.6
 
Loading...
Searching...
No Matches
b2boundary_condition_database.H
1//------------------------------------------------------------------------
2// b2boundary_condition_database.H --
3//
4//
5// written by Mathias Doreille
6// Harald Klimach <harald.klimach@dlr.de>
7// Neda Ebrahimi Pour <neda.ebrahimipour@dlr.de>
8//
9// (c) 2004-2012,2017 SMR Engineering & Development SA
10// 2502 Bienne, Switzerland
11//
12// (c) 2023 Deutsches Zentrum für Luft- und Raumfahrt (DLR) e.V.
13// Linder Höhe, 51147 Köln
14//
15// All Rights Reserved. Proprietary source code. The contents of
16// this file may not be disclosed to third parties, copied or
17// duplicated in any form, in whole or in part, without the prior
18// written permission of SMR.
19//------------------------------------------------------------------------
20
21#ifndef B2BOUNDARY_CONDITION_DATABASE_H_
22#define B2BOUNDARY_CONDITION_DATABASE_H_
23
24#include <complex>
25#include <vector>
26
27#include "b2domain_database.H"
28#include "b2model_database.H"
29#include "b2ppconfig.h"
30#include "elements/smr/b2element_continuum_integrate.H"
31#include "model/b2domain.H"
32#include "model/b2solver.H"
33#include "model_imp/b2boundary_condition_component.H"
34#include "model_imp/b2heat_radiation_component.H"
35#include "model_imp/b2hnode.H"
36#include "utils/b2database.H"
37#include "utils/b2linear_algebra.H"
38#include "utils/b2logging.H"
39#include "utils/b2object.H"
40#include "utils/b2subprocess.H"
41
42namespace b2000::b2dbv3 {
43
44struct bc_type_properties {
45 bool is_symmetric = false;
46 bool is_complex = false;
47 bool is_csda = false;
48
49 bc_type_properties(bool is_symmetric, bool is_complex, bool is_csda)
50 : is_symmetric(is_symmetric), is_complex(is_complex), is_csda(is_csda) {}
51};
52
53std::string bc_type_name(std::string basename, bc_type_properties properties);
54
55template <typename T, typename MATRIX_TYPE>
56class NBC_NBC : public TypedNaturalBoundaryConditionComponent<T, MATRIX_TYPE> {
57public:
58 NBC_NBC() : scalef(nullptr), model(nullptr), subcase_id(0) {}
59
60 void init(
61 const std::string& id_, TimeFunction* scalef_, b2000::Model& model_,
62 const b2000::Case& case_, const int subcase_id_) override {
63 id = id_;
64 scalef = scalef_;
65 model = &model_;
66 subcase_id = subcase_id_;
67 }
68
69 void set_case(b2000::Case& case_) override { scalef->set_case(case_); }
70
71 std::string get_id() const override { return id; }
72
73 int get_subcase_id() const override { return subcase_id; }
74
75 NaturalBoundaryCondition::Type get_nbc_type() const override {
77 }
78
79 void add_linear_nbc_value(
80 double sfactor, b2linalg::Vector<T, b2linalg::Vdense_ref> value_,
81 b2linalg::Matrix<T, MATRIX_TYPE>& d_value_d_dof)
82 override { // d_value_d_dof is never used inside the function (TB)
83 init_lazy(b2linalg::Vector<T, b2linalg::Vdense_ref>::null, 1);
84 if (!value_.is_null()) { value_ += static_cast<T>(scalef->value(sfactor)) * value; }
85 }
86
87 void add_nonlinear_nbc_value(
88 const b2linalg::Vector<T, b2linalg::Vdense_constref>& dof, double time,
89 EquilibriumSolution equal, b2linalg::Vector<T, b2linalg::Vdense_ref> value_,
90 b2linalg::Matrix<T, MATRIX_TYPE>& d_value_d_dof,
91 b2linalg::Vector<T, b2linalg::Vdense_ref> d_value_d_time,
92 SolverHints* solver_hints) override {
93 init_lazy(dof, time);
94 if (!value_.is_null()) { value_ += static_cast<T>(scalef->value(time)) * value; }
95 if (!d_value_d_time.is_null()) {
96 d_value_d_time += static_cast<T>(scalef->d_value(time)) * value;
97 }
98 }
99
100 typedef ObjectTypeComplete<
101 NBC_NBC, typename TypedNaturalBoundaryConditionComponent<T, MATRIX_TYPE>::type_t>
102 type_t;
103 static type_t type;
104
105protected:
106 virtual void init_lazy(const b2linalg::Vector<T, b2linalg::Vdense_constref>& dof, double time);
107 std::string id;
108 TimeFunction* scalef;
109 b2000::Model* model;
110 b2linalg::Vector<T, b2linalg::Vcompressed> value;
111 int subcase_id;
112};
113
114template <typename T, typename MATRIX_TYPE>
115typename NBC_NBC<T, MATRIX_TYPE>::type_t NBC_NBC<T, MATRIX_TYPE>::type(
116 "NBC_NBC", type_name<T, MATRIX_TYPE>(), StringList(), b2000::b2dbv3::module,
117 &b2000::TypedNaturalBoundaryConditionComponent<T, MATRIX_TYPE>::type);
118
119template <typename T, typename MATRIX_TYPE>
120class NBC_NBC_EEDGE : public NBC_NBC<T, MATRIX_TYPE> {
121public:
122 void init(
123 const std::string& id_, TimeFunction* scalef_, b2000::Model& model_,
124 const b2000::Case& case_, const int subcase_id_) override;
125
126 NaturalBoundaryCondition::Type get_nbc_type() const override { return nbc_type; }
127
128 void add_nonlinear_nbc_value(
129 const b2linalg::Vector<T, b2linalg::Vdense_constref>& dof, double time,
130 EquilibriumSolution equal, b2linalg::Vector<T, b2linalg::Vdense_ref> value_,
131 b2linalg::Matrix<T, MATRIX_TYPE>& d_value_d_dof,
132 b2linalg::Vector<T, b2linalg::Vdense_ref> d_value_d_time,
133 SolverHints* solver_hints) override;
134
135 typedef ObjectTypeComplete<NBC_NBC_EEDGE, typename NBC_NBC<T, MATRIX_TYPE>::type_t> type_t;
136 static type_t type;
137
138protected:
139 bool init_lazy_done;
141
142 void init_lazy(const b2linalg::Vector<T, b2linalg::Vdense_constref>& dof, double time) override;
143};
144
145template <typename T, typename MATRIX_TYPE>
146typename NBC_NBC_EEDGE<T, MATRIX_TYPE>::type_t NBC_NBC_EEDGE<T, MATRIX_TYPE>::type(
147 "NBC_NBC_EEDGE", type_name<T, MATRIX_TYPE>(), StringList(), b2000::b2dbv3::module,
148 &b2000::TypedNaturalBoundaryConditionComponent<T, MATRIX_TYPE>::type);
149
150template <typename T, typename MATRIX_TYPE>
151class NBC_NBC_EFACE : public NBC_NBC<T, MATRIX_TYPE> {
152public:
153 void init(
154 const std::string& id_, TimeFunction* scalef_, b2000::Model& model_,
155 const b2000::Case& case_, const int subcase_id_) override;
156
157 NaturalBoundaryCondition::Type get_nbc_type() const override { return nbc_type; }
158
159 typedef ObjectTypeComplete<NBC_NBC_EFACE, typename NBC_NBC<T, MATRIX_TYPE>::type_t> type_t;
160 static type_t type;
161
162protected:
164 void init_lazy(const b2linalg::Vector<T, b2linalg::Vdense_constref>& dof, double time) override;
165};
166
167template <typename T, typename MATRIX_TYPE>
168typename NBC_NBC_EFACE<T, MATRIX_TYPE>::type_t NBC_NBC_EFACE<T, MATRIX_TYPE>::type(
169 "NBC_NBC_EFACE", type_name<T, MATRIX_TYPE>(), StringList(), b2000::b2dbv3::module,
170 &b2000::TypedNaturalBoundaryConditionComponent<T, MATRIX_TYPE>::type);
171
172template <typename T, typename MATRIX_TYPE>
173class NBC_NBC_EBODY : public NBC_NBC<T, MATRIX_TYPE> {
174public:
175 void init(
176 const std::string& id_, TimeFunction* scalef_, b2000::Model& model_,
177 const b2000::Case& case_, const int subcase_id_) override;
178
179 NaturalBoundaryCondition::Type get_nbc_type() const override { return nbc_type; }
180
181 typedef ObjectTypeComplete<NBC_NBC_EBODY, typename NBC_NBC<T, MATRIX_TYPE>::type_t> type_t;
182 static type_t type;
183
184protected:
186 void init_lazy(const b2linalg::Vector<T, b2linalg::Vdense_constref>& dof, double time) override;
187};
188
189template <typename T, typename MATRIX_TYPE>
190typename NBC_NBC_EBODY<T, MATRIX_TYPE>::type_t NBC_NBC_EBODY<T, MATRIX_TYPE>::type(
191 "NBC_NBC_EBODY", type_name<T, MATRIX_TYPE>(), StringList(), b2000::b2dbv3::module,
192 &b2000::TypedNaturalBoundaryConditionComponent<T, MATRIX_TYPE>::type);
193
194template <typename T, typename MATRIX_TYPE>
195class EBC_LINC : public TypedAffineModelReductionBoundaryConditionComponent<T> {
196public:
197 EBC_LINC() : constant_and_init(false), scalef(nullptr), model(nullptr) {}
198
199 void init(
200 const std::string& id_, TimeFunction* scalef_, b2000::Model& model_,
201 const b2000::Case& case_, const int subcase_id_) override {
202 constant_and_init = false;
203 id = id_;
204 scalef = scalef_;
205 model = &model_;
206 }
207
208 void set_case(b2000::Case& case_) override { scalef->set_case(case_); }
209
210 std::string get_id() const override { return id; }
211
212 int get_subcase_id() const override { return 0; }
213
214 size_t get_size() override {
215 init_lazy();
216 return value.size();
217 }
218
219 double get_scale(double time) override { return scalef->value(time); }
220
221 double get_d_scale(double time, int order) override { return scalef->d_value(time, order); }
222
223 std::string get_name_of_entry(size_t pos) override;
224
225 void add_linear_value(
226 b2linalg::Vector<T, b2linalg::Vdense_ref> value_,
227 b2linalg::Matrix<T, MATRIX_TYPE>& d_value_d_dof_trans_) override {
228 init_lazy();
229 if (!value_.is_null()) { value_ = value; }
230 if (!d_value_d_dof_trans_.is_null()) {
231 d_value_d_dof_trans_.push_back(
232 0, static_cast<b2linalg::Matrix<T, MATRIX_TYPE>>(d_value_d_dof_trans));
233 }
234 }
235
236 typedef ObjectTypeComplete<
237 EBC_LINC, typename TypedAffineModelReductionBoundaryConditionComponent<T>::type_t>
238 type_t;
239 static type_t type;
240
241private:
242 void init_lazy();
243
244 bool constant_and_init;
245 std::string id;
246 TimeFunction* scalef;
247 b2000::Model* model;
248 b2linalg::Vector<double, b2linalg::Vdense> value;
249 b2linalg::Matrix<double, b2linalg::Mcompressed_col> d_value_d_dof_trans;
250};
251
252template <typename T, typename MATRIX_TYPE>
253typename EBC_LINC<T, MATRIX_TYPE>::type_t EBC_LINC<T, MATRIX_TYPE>::type(
254 "EBC_LINC", type_name<T, MATRIX_TYPE>(), StringList(), b2000::b2dbv3::module,
255 &b2000::TypedAffineModelReductionBoundaryConditionComponent<T>::type);
256
257template <typename T, typename MATRIX_TYPE>
258class EBC_EBC : public TypedAffineModelReductionBoundaryConditionComponent<T> {
259public:
260 EBC_EBC() : constant_and_init(false), scalef(nullptr), model(nullptr) {}
261
262 void init(
263 const std::string& id_, TimeFunction* scalef_, b2000::Model& model_,
264 const b2000::Case& case_, const int subcase_id_) override {
265 constant_and_init = false;
266 id = id_;
267 scalef = scalef_;
268 model = &model_;
269 }
270
271 void set_case(b2000::Case& case_) override { scalef->set_case(case_); }
272
273 std::string get_id() const override { return id; }
274
275 int get_subcase_id() const override { return 0; }
276
277 size_t get_size() override {
278 init_lazy();
279 return value.size();
280 }
281
282 std::string get_name_of_entry(size_t pos) override;
283
284 double get_scale(double time) override { return scalef->value(time); }
285
286 double get_d_scale(double time, int order) override { return scalef->d_value(time, order); }
287
288 void add_linear_value(
289 b2linalg::Vector<T, b2linalg::Vdense_ref> value_,
290 b2linalg::Matrix<T, MATRIX_TYPE>& d_value_d_dof_trans_) override {
291 init_lazy();
292 if (!value_.is_null()) { value_ = value; }
293 if (!d_value_d_dof_trans_.is_null()) {
294 d_value_d_dof_trans_.push_back(
295 0, static_cast<b2linalg::Matrix<T, MATRIX_TYPE>>(d_value_d_dof_trans));
296 }
297 }
298
299 typedef ObjectTypeComplete<
300 EBC_EBC, typename TypedAffineModelReductionBoundaryConditionComponent<T>::type_t>
301 type_t;
302 static type_t type;
303
304private:
305 void init_lazy();
306 bool constant_and_init;
307 std::string id;
308 TimeFunction* scalef;
309 b2000::Model* model;
310 b2linalg::Vector<double, b2linalg::Vdense> value;
311 b2linalg::Matrix<double, b2linalg::Mcompressed_col> d_value_d_dof_trans;
312};
313
314template <typename T, typename MATRIX_TYPE>
315typename EBC_EBC<T, MATRIX_TYPE>::type_t EBC_EBC<T, MATRIX_TYPE>::type(
316 "EBC_EBC", type_name<T, MATRIX_TYPE>(), StringList(), b2000::b2dbv3::module,
317 &b2000::TypedAffineModelReductionBoundaryConditionComponent<T>::type);
318
319template <typename T, typename MATRIX_TYPE>
320class EBC_JOIN : public TypedAffineModelReductionBoundaryConditionComponent<T> {
321public:
322 EBC_JOIN() : constant_and_init(false), scalef(nullptr), model(nullptr) {}
323
324 void init(
325 const std::string& id_, TimeFunction* scalef_, b2000::Model& model_,
326 const b2000::Case& case_, const int subcase_id_) override {
327 constant_and_init = false;
328 id = id_;
329 scalef = scalef_;
330 model = &model_;
331 }
332
333 std::string get_id() const override { return id; }
334
335 int get_subcase_id() const override { return 0; }
336
337 void set_case(b2000::Case& case_) override { scalef->set_case(case_); }
338
339 size_t get_size() override {
340 init_lazy();
341 return d_value_d_dof_trans.size2();
342 }
343
344 std::string get_name_of_entry(size_t pos) override;
345
346 double get_scale(double time) override { return scalef->value(time); }
347
348 double get_d_scale(double time, int order) override { return scalef->d_value(time, order); }
349
350 void add_linear_value(
351 b2linalg::Vector<T, b2linalg::Vdense_ref> value_,
352 b2linalg::Matrix<T, MATRIX_TYPE>& d_value_d_dof_trans_) override {
353 init_lazy();
354 if (!d_value_d_dof_trans_.is_null()) {
355 d_value_d_dof_trans_.push_back(
356 0, static_cast<b2linalg::Matrix<T, MATRIX_TYPE>>(d_value_d_dof_trans));
357 }
358 }
359
360 typedef ObjectTypeComplete<
361 EBC_JOIN, typename TypedAffineModelReductionBoundaryConditionComponent<T>::type_t>
362 type_t;
363 static type_t type;
364
365private:
366 void init_lazy();
367 bool constant_and_init;
368 std::string id;
369 TimeFunction* scalef;
370 b2000::Model* model;
371 b2linalg::Matrix<double, b2linalg::Mcompressed_col> d_value_d_dof_trans;
372};
373template <typename T, typename MATRIX_TYPE>
374typename EBC_JOIN<T, MATRIX_TYPE>::type_t EBC_JOIN<T, MATRIX_TYPE>::type(
375 "EBC_JOIN", type_name<T, MATRIX_TYPE>(), StringList(), b2000::b2dbv3::module,
376 &b2000::TypedAffineModelReductionBoundaryConditionComponent<T>::type);
377
378template <typename T, typename MATRIX_TYPE>
379class NBC_TABULATED : public TypedNaturalBoundaryConditionComponent<T, MATRIX_TYPE> {
380public:
381 NBC_TABULATED() : model(nullptr), subcase_id(0) {}
382
383 void init(
384 const std::string& id_, TimeFunction* scalef_, b2000::Model& model_,
385 const b2000::Case& case_, const int subcase_id_) override {
386 id = id_;
387 model = &model_;
388 subcase_id = subcase_id_;
389 }
390
391 std::string get_id() const override { return id; }
392
393 int get_subcase_id() const override { return subcase_id; }
394
395 NaturalBoundaryCondition::Type get_nbc_type() const override {
397 }
398
399 void add_nonlinear_nbc_value(
400 const b2linalg::Vector<T, b2linalg::Vdense_constref>& dof, double time,
401 EquilibriumSolution equal, b2linalg::Vector<T, b2linalg::Vdense_ref> value_,
402 b2linalg::Matrix<T, MATRIX_TYPE>& d_value_d_dof,
403 b2linalg::Vector<T, b2linalg::Vdense_ref> d_value_d_time,
404 SolverHints* solver_hints) override {
405 double f = init_lazy(time);
406 if (!value_.is_null()) {
407 value_ += static_cast<T>(f) * value1;
408 value_ += static_cast<T>(1 - f) * value2;
409 }
410 if (!d_value_d_time.is_null()) {
411 f = 1 / (equal_range.second->first - equal_range.first->first);
412 d_value_d_time += static_cast<T>(-f) * value1;
413 d_value_d_time += static_cast<T>(f) * value2;
414 }
415 }
416
417 typedef ObjectTypeComplete<
418 NBC_TABULATED, typename TypedNaturalBoundaryConditionComponent<T, MATRIX_TYPE>::type_t>
419 type_t;
420 static type_t type;
421
422protected:
423 double init_lazy(double time);
424 void load(int cycle, b2linalg::Vector<T, b2linalg::Vcompressed>& v);
425
426 std::string id;
427 b2000::Model* model;
428 std::map<double, int> list_set_time_to_cycle;
429 std::pair<std::map<double, int>::const_iterator, std::map<double, int>::const_iterator>
430 equal_range;
431 b2linalg::Vector<T, b2linalg::Vcompressed> value1;
432 b2linalg::Vector<T, b2linalg::Vcompressed> value2;
433 int subcase_id;
434};
435template <typename T, typename MATRIX_TYPE>
436typename NBC_TABULATED<T, MATRIX_TYPE>::type_t NBC_TABULATED<T, MATRIX_TYPE>::type(
437 "NBC_TABULATED", type_name<T, MATRIX_TYPE>(), StringList(), b2000::b2dbv3::module,
438 &b2000::TypedNaturalBoundaryConditionComponent<T, MATRIX_TYPE>::type);
439
440class NBC_RadiationHeat : public b2000::NBC_RadiationHeat {
441public:
442 typedef ObjectTypeComplete<
443 NBC_RadiationHeat, TypedNaturalBoundaryConditionComponent<double>::type_t>
444 type_t;
445 static type_t type;
446};
447
448} // namespace b2000::b2dbv3
449
450#endif // B2BOUNDARY_CONDITION_DATABASE_H_
Interface to C++ representations of FE solvers.
Definition b2case.H:110
Definition b2model.H:69
virtual void set_case(Case &case_)=0
Type
Definition b2boundary_condition.H:49
@ constant
Definition b2boundary_condition.H:55