39 #ifndef GETFEM_MODELS_H__
40 #define GETFEM_MODELS_H__
51 typedef std::shared_ptr<const virtual_brick>
pbrick;
54 typedef std::shared_ptr<const virtual_dispatcher> pdispatcher;
57 typedef std::shared_ptr<const virtual_time_scheme> ptime_scheme;
89 typedef model_real_plain_vector modeling_standard_plain_vector;
91 typedef model_real_sparse_matrix modeling_standard_sparse_matrix;
92 typedef model_complex_plain_vector modeling_standard_complex_plain_vector;
94 typedef model_complex_sparse_matrix modeling_standard_complex_sparse_matrix;
99 const auto PREFIX_OLD_LENGTH = 4;
102 bool is_old(
const std::string &name);
107 std::string sup_previous_and_dot_to_varname(std::string v);
120 bool complex_version;
124 mutable model_real_sparse_matrix
127 mutable model_complex_sparse_matrix cTM;
128 mutable model_real_plain_vector
132 mutable model_complex_plain_vector crhs;
133 mutable bool act_size_to_be_done;
134 dim_type leading_dim;
135 getfem::lock_factory locks_;
139 enum var_description_filter {
141 VDESCRFILTER_REGION = 1,
143 VDESCRFILTER_INFSUP = 2,
146 VDESCRFILTER_CTERM = 4,
149 VDESCRFILTER_REGION_CTERM = 5,
152 struct var_description {
157 bool is_affine_dependent;
168 var_description_filter filter;
171 std::string filter_var;
176 ppartial_mesh_fem partial_mf;
179 bgeot::multi_index qdims;
182 gmm::uint64_type v_num;
183 std::vector<gmm::uint64_type> v_num_data;
188 std::vector<model_real_plain_vector> real_value;
189 std::vector<model_complex_plain_vector> complex_value;
190 std::vector<gmm::uint64_type> v_num_var_iter;
191 std::vector<gmm::uint64_type> v_num_iter;
194 model_real_plain_vector affine_real_value;
195 model_complex_plain_vector affine_complex_value;
197 std::string org_name;
200 var_description(
bool is_var =
false,
bool is_compl =
false,
203 var_description_filter filter_ = VDESCRFILTER_NO,
205 const std::string &filter_var_ = std::string(
""),
206 mesh_im const *filter_mim_ = 0)
207 : is_variable(is_var), is_disabled(
false), is_complex(is_compl),
208 is_affine_dependent(
false), is_internal(
false),
209 is_fem_dofs(mf_ != 0),
210 n_iter(std::max(
size_type(1), n_it)), n_temp_iter(0),
211 default_iter(0), ptsc(0),
212 filter(filter_), filter_region(filter_reg), filter_var(filter_var_),
213 filter_mim(filter_mim_), mf(mf_), imd(imd_), qdims(),
214 v_num(0), v_num_data(n_iter, act_counter()), I(0,0), alpha(1)
216 if (filter != VDESCRFILTER_NO && mf != 0)
217 partial_mf = std::make_shared<partial_mesh_fem>(*mf);
219 if (qdims.size() == 0) qdims.push_back(1);
220 GMM_ASSERT1(qdim(),
"Attempt to create a null size variable");
223 size_type qdim()
const {
return qdims.total_size(); }
228 size_type add_temporary(gmm::uint64_type id_num);
230 void clear_temporaries();
232 const mesh_fem &associated_mf()
const {
233 GMM_ASSERT1(is_fem_dofs,
"This variable is not linked to a fem");
234 return (filter == VDESCRFILTER_NO) ? *mf : *partial_mf;
237 const mesh_fem *passociated_mf()
const {
239 return (filter == VDESCRFILTER_NO || partial_mf.get() == 0)
240 ? mf : partial_mf.get();
246 {
return is_complex ? complex_value[0].size() : real_value[0].size(); }
253 typedef std::vector<std::string> varnamelist;
254 typedef std::vector<const mesh_im *> mimlist;
255 typedef std::vector<model_real_sparse_matrix> real_matlist;
256 typedef std::vector<model_complex_sparse_matrix> complex_matlist;
257 typedef std::vector<model_real_plain_vector> real_veclist;
258 typedef std::vector<model_complex_plain_vector> complex_veclist;
260 struct term_description {
264 std::string var1, var2;
266 term_description(
const std::string &v)
267 : is_matrix_term(
false), is_symmetric(
false),
268 is_global(
false), var1(sup_previous_and_dot_to_varname(v)) {}
269 term_description(
const std::string &v1,
const std::string &v2,
271 : is_matrix_term(
true), is_symmetric(issym), is_global(
false),
272 var1(sup_previous_and_dot_to_varname(v1)), var2(v2) {}
273 term_description(
bool ism,
bool issym)
274 : is_matrix_term(ism), is_symmetric(issym), is_global(
true) {}
277 typedef std::vector<term_description> termlist;
283 BUILD_ON_DATA_CHANGE = 4,
285 BUILD_RHS_WITH_LIN = 9,
286 BUILD_WITH_INTERNAL = 16,
287 BUILD_RHS_WITH_INTERNAL = 17,
288 BUILD_MATRIX_CONDENSED = 18,
289 BUILD_ALL_CONDENSED = 19,
296 struct brick_description {
297 mutable bool terms_to_be_computed;
298 mutable gmm::uint64_type v_num;
300 pdispatcher pdispatch;
307 bool is_update_brick;
309 mutable scalar_type external_load;
311 mutable model_real_plain_vector coeffs;
312 mutable scalar_type matrix_coeff = scalar_type(0);
314 mutable real_matlist rmatlist;
316 mutable std::vector<real_veclist> rveclist;
318 mutable std::vector<real_veclist> rveclist_sym;
320 mutable complex_matlist cmatlist;
322 mutable std::vector<complex_veclist> cveclist;
324 mutable std::vector<complex_veclist> cveclist_sym;
326 brick_description() : v_num(0) {}
328 brick_description(
pbrick p,
const varnamelist &vl,
329 const varnamelist &dl,
const termlist &tl,
331 : terms_to_be_computed(
true), v_num(0), pbr(p), pdispatch(0), nbrhs(1),
332 vlist(vl), dlist(dl), tlist(tl), mims(mms), region(reg),
333 is_update_brick(
false), external_load(0),
334 rveclist(1), rveclist_sym(1), cveclist(1),
338 typedef std::map<std::string, var_description> VAR_SET;
339 mutable VAR_SET variables;
340 std::vector<brick_description> bricks;
341 dal::bit_vector valid_bricks, active_bricks;
342 std::map<std::string, pinterpolate_transformation> transformations;
343 std::map<std::string, pelementary_transformation> elem_transformations;
344 std::map<std::string, psecondary_domain> secondary_domains;
347 int time_integration;
349 scalar_type time_step;
350 scalar_type init_time_step;
353 typedef std::map<size_type, scalar_type> real_dof_constraints_var;
354 typedef std::map<size_type, complex_type> complex_dof_constraints_var;
355 mutable std::map<std::string, real_dof_constraints_var>
356 real_dof_constraints;
357 mutable std::map<std::string, complex_dof_constraints_var>
358 complex_dof_constraints;
359 void clear_dof_constraints()
360 { real_dof_constraints.clear(); complex_dof_constraints.clear(); }
367 std::string secondary_domain;
368 gen_expr(
const std::string &expr_,
const mesh_im &mim_,
369 size_type region_,
const std::string &secdom)
370 : expr(expr_), mim(mim_), region(region_), secondary_domain(secdom) {}
374 struct assignement_desc {
382 std::list<assignement_desc> assignments;
384 mutable std::list<gen_expr> generic_expressions;
388 std::map<std::string, std::vector<std::string> > variable_groups;
390 ga_macro_dictionary macro_dict;
393 virtual void actualize_sizes()
const;
394 bool check_name_validity(
const std::string &name,
bool assert=
true)
const;
395 void brick_init(
size_type ib, build_version version,
398 void init() { complex_version =
false; act_size_to_be_done =
false; }
400 void resize_global_system()
const;
403 virtual void post_to_variables_step();
405 scalar_type approx_external_load_;
408 VAR_SET::const_iterator find_variable(
const std::string &name)
const;
409 const var_description &variable_description(
const std::string &name)
const;
413 void add_generic_expression(
const std::string &expr,
const mesh_im &mim,
415 const std::string &secondary_domain =
"")
const {
416 generic_expressions.push_back(gen_expr(expr, mim, region,
419 void add_external_load(
size_type ib, scalar_type e)
const
420 { bricks[ib].external_load = e; }
421 scalar_type approx_external_load() {
return approx_external_load_; }
423 void update_brick(
size_type ib, build_version version)
const;
426 void update_affine_dependent_variables();
427 void brick_call(
size_type ib, build_version version,
429 model_real_plain_vector &rhs_coeffs_of_brick(
size_type ib)
const
430 {
return bricks[ib].coeffs; }
431 scalar_type &matrix_coeff_of_brick(
size_type ib)
const
432 {
return bricks[ib].matrix_coeff; }
433 bool is_var_newer_than_brick(
const std::string &varname,
435 bool is_var_mf_newer_than_brick(
const std::string &varname,
437 bool is_mim_newer_than_brick(
const mesh_im &mim,
441 GMM_ASSERT1(valid_bricks[ib],
"Inexistent brick");
442 return bricks[ib].pbr;
445 void variable_list(varnamelist &vl)
const
446 {
for (
const auto &v : variables) vl.push_back(v.first); }
448 void define_variable_group(
const std::string &group_name,
449 const std::vector<std::string> &nl);
450 bool variable_group_exists(
const std::string &group_name)
const
451 {
return variable_groups.count(group_name) > 0; }
453 const std::vector<std::string> &
454 variable_group(
const std::string &group_name)
const {
455 GMM_ASSERT1(variable_group_exists(group_name),
456 "Undefined variable group " << group_name);
457 return (variable_groups.find(group_name))->second;
460 void clear_assembly_assignments(
void) { assignments.clear(); }
461 void add_assembly_assignments(
const std::string &dataname,
462 const std::string &expr,
465 bool before =
false);
468 void add_real_dof_constraint(
const std::string &varname,
size_type dof,
469 scalar_type val)
const
470 { real_dof_constraints[varname][dof] = val; }
472 void add_complex_dof_constraint(
const std::string &varname,
size_type dof,
473 complex_type val)
const
474 { complex_dof_constraints[varname][dof] = val; }
477 void add_temporaries(
const varnamelist &vl, gmm::uint64_type id_num)
const;
479 const mimlist &mimlist_of_brick(
size_type ib)
const
480 {
return bricks[ib].mims; }
482 const varnamelist &varnamelist_of_brick(
size_type ib)
const
483 {
return bricks[ib].vlist; }
485 const varnamelist &datanamelist_of_brick(
size_type ib)
const
486 {
return bricks[ib].dlist; }
489 {
return bricks[ib].region; }
491 bool temporary_uptodate(
const std::string &varname,
492 gmm::uint64_type id_num,
size_type &ind)
const;
494 size_type n_iter_of_variable(
const std::string &name)
const {
495 return variables.count(name) == 0 ?
size_type(0)
496 : variables[name].n_iter;
499 void set_default_iter_of_variable(
const std::string &varname,
501 void reset_default_iter_of_variables(
const varnamelist &vl)
const;
505 const model_real_sparse_matrix &linear_real_matrix_term
508 const model_complex_sparse_matrix &linear_complex_matrix_term
513 GMM_ASSERT1(valid_bricks[ib],
"Inexistent brick");
514 active_bricks.del(ib);
519 GMM_ASSERT1(valid_bricks[ib],
"Inexistent brick");
520 active_bricks.add(ib);
524 void disable_variable(
const std::string &name);
527 void enable_variable(
const std::string &name,
bool enabled=
true);
530 bool variable_exists(
const std::string &name)
const;
533 bool is_disabled_variable(
const std::string &name)
const;
536 bool is_data(
const std::string &name)
const;
539 bool is_true_data(
const std::string &name)
const;
542 bool is_internal_variable(
const std::string &name)
const;
544 bool is_affine_dependent_variable(
const std::string &name)
const;
546 const std::string &org_variable(
const std::string &name)
const;
548 const scalar_type &factor_of_variable(
const std::string &name)
const;
550 void set_factor_of_variable(
const std::string &name, scalar_type a);
552 bool is_im_data(
const std::string &name)
const;
554 const im_data *pim_data_of_variable(
const std::string &name)
const;
556 const gmm::uint64_type &
557 version_number_of_data_variable(
const std::string &varname,
570 for (
const auto &v : variables)
571 if (v.second.is_internal && !v.second.is_disabled)
return true;
583 size_type nb_dof(
bool with_internal=
false)
const;
592 dim_type leading_dimension()
const {
return leading_dim; }
595 std::string new_name(
const std::string &name);
597 const gmm::sub_interval &
598 interval_of_variable(
const std::string &name)
const;
602 const model_real_plain_vector &
603 real_variable(
const std::string &name,
size_type niter)
const;
607 const model_real_plain_vector &
608 real_variable(
const std::string &name)
const;
612 const model_complex_plain_vector &
613 complex_variable(
const std::string &name,
size_type niter)
const;
617 const model_complex_plain_vector &
618 complex_variable(
const std::string &name)
const;
622 model_real_plain_vector &
623 set_real_variable(
const std::string &name,
size_type niter)
const;
627 model_real_plain_vector &
628 set_real_variable(
const std::string &name)
const;
632 model_complex_plain_vector &
633 set_complex_variable(
const std::string &name,
size_type niter)
const;
637 model_complex_plain_vector &
638 set_complex_variable(
const std::string &name)
const;
640 model_real_plain_vector &
641 set_real_constant_part(
const std::string &name)
const;
643 model_complex_plain_vector &
644 set_complex_constant_part(
const std::string &name)
const;
647 template<
typename VECTOR,
typename T>
648 void from_variables(VECTOR &V,
bool with_internal, T)
const {
649 for (
const auto &v : variables)
650 if (v.second.is_variable && !v.second.is_affine_dependent
651 && !v.second.is_disabled
652 && (with_internal || !v.second.is_internal))
653 gmm::copy(v.second.real_value[0], gmm::sub_vector(V, v.second.I));
656 template<
typename VECTOR,
typename T>
657 void from_variables(VECTOR &V,
bool with_internal, std::complex<T>)
const {
658 for (
const auto &v : variables)
659 if (v.second.is_variable && !v.second.is_affine_dependent
660 && !v.second.is_disabled
661 && (with_internal || !v.second.is_internal))
662 gmm::copy(v.second.complex_value[0], gmm::sub_vector(V, v.second.I));
666 template<
typename VECTOR>
667 void from_variables(VECTOR &V,
bool with_internal=
false)
const {
668 typedef typename gmm::linalg_traits<VECTOR>::value_type T;
669 context_check();
if (act_size_to_be_done) actualize_sizes();
670 from_variables(V, with_internal, T());
674 template<
typename VECTOR,
typename T>
675 void to_variables(
const VECTOR &V,
bool with_internal, T) {
676 for (
auto &&v : variables)
677 if (v.second.is_variable && !v.second.is_affine_dependent
678 && !v.second.is_disabled
679 && (with_internal || !v.second.is_internal)) {
680 gmm::copy(gmm::sub_vector(V, v.second.I), v.second.real_value[0]);
681 v.second.v_num_data[0] = act_counter();
683 update_affine_dependent_variables();
684 this->post_to_variables_step();
687 template<
typename VECTOR,
typename T>
688 void to_variables(
const VECTOR &V,
bool with_internal, std::complex<T>) {
689 for (
auto &&v : variables)
690 if (v.second.is_variable && !v.second.is_affine_dependent
691 && !v.second.is_disabled
692 && (with_internal || !v.second.is_internal)) {
693 gmm::copy(gmm::sub_vector(V, v.second.I), v.second.complex_value[0]);
694 v.second.v_num_data[0] = act_counter();
696 update_affine_dependent_variables();
697 this->post_to_variables_step();
701 template<
typename VECTOR>
702 void to_variables(
const VECTOR &V,
bool with_internal=
false) {
703 typedef typename gmm::linalg_traits<VECTOR>::value_type T;
704 context_check();
if (act_size_to_be_done) actualize_sizes();
705 to_variables(V, with_internal, T());
710 void add_fixed_size_variable(
const std::string &name,
size_type size,
715 void add_fixed_size_variable(
const std::string &name,
716 const bgeot::multi_index &sizes,
721 void add_fixed_size_data(
const std::string &name,
size_type size,
726 void add_fixed_size_data(
const std::string &name,
727 const bgeot::multi_index &sizes,
731 void resize_fixed_size_variable(
const std::string &name,
size_type size);
734 void resize_fixed_size_variable(
const std::string &name,
735 const bgeot::multi_index &sizes);
739 template <
typename VECT>
742 this->add_fixed_size_data(name, gmm::vect_size(v));
743 if (this->is_complex())
744 gmm::copy(v, this->set_complex_variable(name));
746 gmm::copy(gmm::real_part(v), this->set_real_variable(name));
751 template <
typename VECT>
754 const bgeot::multi_index &sizes) {
755 this->add_fixed_size_data(name, sizes);
756 if (this->is_complex())
757 gmm::copy(v, this->set_complex_variable(name));
759 gmm::copy(gmm::real_part(v), this->set_real_variable(name));
764 void add_initialized_matrix_data(
const std::string &name,
765 const base_matrix &M);
766 void add_initialized_matrix_data(
const std::string &name,
767 const base_complex_matrix &M);
771 void add_initialized_tensor_data(
const std::string &name,
772 const base_tensor &t);
773 void add_initialized_tensor_data(
const std::string &name,
774 const base_complex_tensor &t);
778 template <
typename T>
780 this->add_fixed_size_data(name, 1, 1);
781 if (this->is_complex())
782 this->set_complex_variable(name)[0] = e;
784 this->set_real_variable(name)[0] = gmm::real(e);
789 void add_im_variable(
const std::string &name,
const im_data &imd,
792 void add_internal_im_variable(
const std::string &name,
795 void add_im_data(
const std::string &name,
const im_data &imd,
801 void add_fem_variable(
const std::string &name,
const mesh_fem &mf,
808 void add_filtered_fem_variable(
const std::string &name,
const mesh_fem &mf,
816 void add_affine_dependent_variable(
const std::string &name,
817 const std::string &org_name,
818 scalar_type alpha = scalar_type(1));
821 void add_fem_data(
const std::string &name,
const mesh_fem &mf,
825 void add_fem_data(
const std::string &name,
const mesh_fem &mf,
826 const bgeot::multi_index &sizes,
size_type niter = 1);
831 template <
typename VECT>
834 this->add_fem_data(name, mf,
835 dim_type(gmm::vect_size(v) / mf.
nb_dof()), 1);
836 if (this->is_complex())
837 gmm::copy(v, this->set_complex_variable(name));
839 gmm::copy(gmm::real_part(v), this->set_real_variable(name));
844 template <
typename VECT>
847 const bgeot::multi_index &sizes) {
848 this->add_fem_data(name, mf, sizes, 1);
849 if (this->is_complex())
850 gmm::copy(v, this->set_complex_variable(name));
852 gmm::copy(gmm::real_part(v), this->set_real_variable(name));
861 void add_multiplier(
const std::string &name,
const mesh_fem &mf,
862 const std::string &primal_name,
872 void add_multiplier(
const std::string &name,
const mesh_fem &mf,
873 size_type region,
const std::string &primal_name,
882 void add_multiplier(
const std::string &name,
const mesh_fem &mf,
883 const std::string &primal_name,
const mesh_im &mim,
892 void add_macro(
const std::string &name,
const std::string &expr);
895 void del_macro(
const std::string &name);
899 {
return macro_dict.macro_exists(name); }
902 void delete_variable(
const std::string &varname);
906 const mesh_fem &mesh_fem_of_variable(
const std::string &name)
const;
909 const mesh_fem *pmesh_fem_of_variable(
const std::string &name)
const;
912 bgeot::multi_index qdims_of_variable(
const std::string &name)
const;
913 size_type qdim_of_variable(
const std::string &name)
const;
916 const model_real_sparse_matrix &
918 GMM_ASSERT1(!complex_version,
"This model is a complex one");
919 context_check();
if (act_size_to_be_done) actualize_sizes();
920 return internal ? internal_rTM : rTM;
925 GMM_ASSERT1(complex_version,
"This model is a real one");
926 context_check();
if (act_size_to_be_done) actualize_sizes();
932 const model_real_plain_vector &
real_rhs(
bool with_internal=
false)
const {
933 GMM_ASSERT1(!complex_version,
"This model is a complex one");
934 context_check();
if (act_size_to_be_done) actualize_sizes();
935 return (with_internal && gmm::vect_size(full_rrhs)) ? full_rrhs : rrhs;
941 model_real_plain_vector &
set_real_rhs(
bool with_internal=
false)
const {
942 GMM_ASSERT1(!complex_version,
"This model is a complex one");
943 context_check();
if (act_size_to_be_done) actualize_sizes();
944 return (with_internal && gmm::vect_size(full_rrhs)) ? full_rrhs : rrhs;
950 GMM_ASSERT1(!complex_version,
"This model is a complex one");
951 context_check();
if (act_size_to_be_done) actualize_sizes();
959 const model_real_plain_vector &real_brick_term_rhs
963 GMM_ASSERT1(!complex_version,
"This model is a complex one");
964 context_check();
if (act_size_to_be_done) actualize_sizes();
965 GMM_ASSERT1(valid_bricks[ib],
"Inexistent brick");
966 GMM_ASSERT1(ind_term < bricks[ib].tlist.size(),
"Inexistent term");
967 GMM_ASSERT1(ind_iter < bricks[ib].nbrhs,
"Inexistent iter");
968 GMM_ASSERT1(!sym || bricks[ib].tlist[ind_term].is_symmetric,
969 "Term is not symmetric");
971 return bricks[ib].rveclist_sym[ind_iter][ind_term];
973 return bricks[ib].rveclist[ind_iter][ind_term];
979 GMM_ASSERT1(complex_version,
"This model is a real one");
980 context_check();
if (act_size_to_be_done) actualize_sizes();
988 GMM_ASSERT1(complex_version,
"This model is a real one");
989 context_check();
if (act_size_to_be_done) actualize_sizes();
997 const model_complex_plain_vector &complex_brick_term_rhs
1001 GMM_ASSERT1(!complex_version,
"This model is a complex one");
1002 context_check();
if (act_size_to_be_done) actualize_sizes();
1003 GMM_ASSERT1(valid_bricks[ib],
"Inexistent brick");
1004 GMM_ASSERT1(ind_term < bricks[ib].tlist.size(),
"Inexistent term");
1005 GMM_ASSERT1(ind_iter < bricks[ib].nbrhs,
"Inexistent iter");
1006 GMM_ASSERT1(!sym || bricks[ib].tlist[ind_term].is_symmetric,
1007 "Term is not symmetric");
1009 return bricks[ib].cveclist_sym[ind_iter][ind_term];
1011 return bricks[ib].cveclist[ind_iter][ind_term];
1015 void listvar(std::ostream &ost)
const;
1017 void listresiduals(std::ostream &ost)
const;
1020 void listbricks(std::ostream &ost,
size_type base_id = 0)
const;
1024 return active_bricks;
1029 GMM_ASSERT1(valid_bricks[ib],
"Inexistent brick");
1030 bricks[ib].terms_to_be_computed =
true;
1038 const varnamelist &datanames,
1039 const termlist &terms,
const mimlist &mims,
1049 void change_terms_of_brick(
size_type ib,
const termlist &terms);
1053 void change_variables_of_brick(
size_type ib,
const varnamelist &vl);
1057 void change_data_of_brick(
size_type ib,
const varnamelist &vl);
1061 void change_mims_of_brick(
size_type ib,
const mimlist &ml);
1065 void change_update_flag_of_brick(
size_type ib,
bool flag);
1067 void set_time(scalar_type t = scalar_type(0),
bool to_init =
true);
1069 scalar_type get_time();
1071 void set_time_step(scalar_type dt) { time_step = dt; }
1072 scalar_type get_time_step()
const {
return time_step; }
1073 scalar_type get_init_time_step()
const {
return init_time_step; }
1074 int is_time_integration()
const {
return time_integration; }
1075 void set_time_integration(
int ti) { time_integration = ti; }
1076 bool is_init_step()
const {
return init_step; }
1077 void cancel_init_step() { init_step =
false; }
1078 void call_init_affine_dependent_variables(
int version);
1079 void shift_variables_for_time_integration();
1080 void copy_init_time_derivative();
1081 void add_time_integration_scheme(
const std::string &varname,
1083 void perform_init_time_derivative(scalar_type ddt)
1084 { init_step =
true; init_time_step = ddt; }
1088 void add_time_dispatcher(
size_type ibrick, pdispatcher pdispatch);
1090 void set_dispatch_coeff();
1093 virtual void first_iter();
1098 virtual void next_iter();
1104 pinterpolate_transformation ptrans) {
1105 if (secondary_domain_exists(name))
1106 GMM_ASSERT1(
false,
"An secondary domain with the same "
1107 "name already exists");
1108 if (transformations.count(name) > 0)
1109 GMM_ASSERT1(name.compare(
"neighbor_element"),
"neighbor_element is a "
1110 "reserved interpolate transformation name");
1111 transformations[name] = ptrans;
1116 pinterpolate_transformation
1118 std::map<std::string, pinterpolate_transformation>::const_iterator
1119 it = transformations.find(name);
1120 GMM_ASSERT1(it != transformations.end(),
"Inexistent transformation " << name);
1127 {
return transformations.count(name) > 0; }
1133 pelementary_transformation ptrans) {
1134 elem_transformations[name] = ptrans;
1139 pelementary_transformation
1141 std::map<std::string, pelementary_transformation>::const_iterator
1142 it = elem_transformations.find(name);
1143 GMM_ASSERT1(it != elem_transformations.end(),
1144 "Inexistent elementary transformation " << name);
1151 {
return elem_transformations.count(name) > 0; }
1158 psecondary_domain ptrans) {
1159 if (interpolate_transformation_exists(name))
1160 GMM_ASSERT1(
false,
"An interpolate transformation with the same "
1161 "name already exists");secondary_domains[name] = ptrans;
1168 auto it = secondary_domains.find(name);
1169 GMM_ASSERT1(it != secondary_domains.end(),
1170 "Inexistent transformation " << name);
1177 {
return secondary_domains.count(name) > 0; }
1181 const std::string &varname_of_brick(
size_type ind_brick,
1186 const std::string &dataname_of_brick(
size_type ind_brick,
1191 virtual void assembly(build_version version);
1201 std::string Neumann_term(
const std::string &varname,
size_type region);
1203 virtual void clear();
1205 explicit model(
bool comp_version =
false);
1210 void check_brick_stiffness_rhs(
size_type ind_brick)
const;
1229 virtual void init_affine_dependent_variables(
model &md)
const = 0;
1230 virtual void init_affine_dependent_variables_precomputation(
model &md)
1232 virtual void time_derivative_to_be_initialized
1233 (std::string &name_v, std::string &name_previous_v)
const = 0;
1234 virtual void shift_variables(
model &md)
const = 0;
1238 void add_theta_method_for_first_order(
model &md,
const std::string &varname,
1241 void add_theta_method_for_second_order(
model &md,
const std::string &varname,
1244 void add_Newmark_scheme(
model &md,
const std::string &varname,
1245 scalar_type beta, scalar_type gamma);
1247 void add_Houbolt_scheme(
model &md,
const std::string &varname);
1265 std::vector<std::string> param_names;
1269 size_type nbrhs()
const {
return nbrhs_; }
1271 typedef model::build_version build_version;
1274 { GMM_ASSERT1(
false,
"Time dispatcher with not set_dispatch_coeff !"); }
1276 virtual void next_real_iter
1278 const model::varnamelist &,
1279 model::real_matlist &,
1280 std::vector<model::real_veclist> &,
1281 std::vector<model::real_veclist> &,
1283 GMM_ASSERT1(
false,
"Time dispatcher with not defined first real iter !");
1286 virtual void next_complex_iter
1288 const model::varnamelist &,
1289 model::complex_matlist &,
1290 std::vector<model::complex_veclist> &,
1291 std::vector<model::complex_veclist> &,
1293 GMM_ASSERT1(
false,
"Time dispatcher with not defined first comples iter");
1296 virtual void asm_real_tangent_terms
1298 model::real_matlist &, std::vector<model::real_veclist> &,
1299 std::vector<model::real_veclist> &,
1300 build_version)
const {
1301 GMM_ASSERT1(
false,
"Time dispatcher with not defined real tangent "
1305 virtual void asm_complex_tangent_terms
1307 model::complex_matlist &, std::vector<model::complex_veclist> &,
1308 std::vector<model::complex_veclist> &,
1309 build_version)
const {
1310 GMM_ASSERT1(
false,
"Time dispatcher with not defined complex tangent "
1315 GMM_ASSERT1(_nbrhs > 0,
"Time dispatcher with no rhs");
1331 typedef model::build_version build_version;
1335 template <
typename MATLIST,
typename VECTLIST>
1337 const model::varnamelist &,
1338 const model::varnamelist &,
1340 VECTLIST &vectl, VECTLIST &vectl_sym,
1341 bool first_iter)
const {
1342 if (first_iter) md.update_brick(ib, model::BUILD_RHS);
1345 for (
size_type i = 0; i < vectl[0].size(); ++i)
1346 gmm::copy(vectl[0][i], vectl[1][i]);
1347 for (
size_type i = 0; i < vectl_sym[0].size(); ++i)
1348 gmm::copy(vectl_sym[0][i], vectl_sym[1][i]);
1352 md.linear_brick_add_to_rhs(ib, 1, 0);
1356 (
const model &md,
size_type ib,
const model::varnamelist &vl,
1357 const model::varnamelist &dl, model::real_matlist &matl,
1358 std::vector<model::real_veclist> &vectl,
1359 std::vector<model::real_veclist> &vectl_sym,
bool first_iter)
const;
1361 void next_complex_iter
1362 (
const model &md,
size_type ib,
const model::varnamelist &vl,
1363 const model::varnamelist &dl,
1364 model::complex_matlist &matl,
1365 std::vector<model::complex_veclist> &vectl,
1366 std::vector<model::complex_veclist> &vectl_sym,
1367 bool first_iter)
const;
1369 void asm_real_tangent_terms
1370 (
const model &md,
size_type ib, model::real_matlist &,
1371 std::vector<model::real_veclist> &,
1372 std::vector<model::real_veclist> &,
1373 build_version version)
const;
1375 virtual void asm_complex_tangent_terms
1376 (
const model &md,
size_type ib, model::complex_matlist &,
1377 std::vector<model::complex_veclist> &,
1378 std::vector<model::complex_veclist> &,
1379 build_version version)
const;
1381 theta_method_dispatcher(
const std::string &THETA);
1395 const std::string &THETA);
1403 (model &md,
const std::string &U,
const std::string &V,
1404 const std::string &pdt,
const std::string &ptheta);
1420 (model &md,
size_type id2dt2b,
const std::string &U,
const std::string &V,
1421 const std::string &pdt,
const std::string &ptwobeta,
1422 const std::string &pgamma);
1446 bool compute_each_time;
1454 typedef model::build_version build_version;
1458 void set_flags(
const std::string &bname,
bool islin,
bool issym,
1459 bool iscoer,
bool ire,
bool isco,
bool each_time =
false) {
1461 islinear = islin; issymmetric = issym; iscoercive = iscoer;
1462 isreal = ire; iscomplex = isco; isinit =
true;
1463 compute_each_time = each_time;
1466 # define BRICK_NOT_INIT GMM_ASSERT1(isinit, "Set brick flags !")
1467 bool is_linear()
const { BRICK_NOT_INIT;
return islinear; }
1468 bool is_symmetric()
const { BRICK_NOT_INIT;
return issymmetric; }
1469 bool is_coercive()
const { BRICK_NOT_INIT;
return iscoercive; }
1470 bool is_real()
const { BRICK_NOT_INIT;
return isreal; }
1471 bool is_complex()
const { BRICK_NOT_INIT;
return iscomplex; }
1472 bool is_to_be_computed_each_time()
const
1473 { BRICK_NOT_INIT;
return compute_each_time; }
1474 const std::string &brick_name()
const { BRICK_NOT_INIT;
return name; }
1491 const model::varnamelist &,
1492 const model::varnamelist &,
1493 const model::mimlist &,
1494 model::real_matlist &,
1495 model::real_veclist &,
1496 model::real_veclist &,
1517 const model::varnamelist &,
1518 const model::varnamelist &,
1519 const model::mimlist &,
1520 model::complex_matlist &,
1521 model::complex_veclist &,
1522 model::complex_veclist &,
1535 const model::varnamelist &,
1536 const model::varnamelist &,
1537 const model::mimlist &,
1538 model::real_matlist &,
1539 model::real_veclist &,
1540 model::real_veclist &,
1549 const model::varnamelist &,
1550 const model::varnamelist &,
1551 const model::mimlist &,
1552 model::complex_matlist &,
1553 model::complex_veclist &,
1554 model::complex_veclist &,
1563 const model::varnamelist &,
1564 const model::varnamelist &,
1565 const model::mimlist &,
1566 model::real_matlist &,
1567 model::real_veclist &,
1568 model::real_veclist &,
1577 const model::varnamelist &,
1578 const model::varnamelist &,
1579 const model::mimlist &,
1580 model::complex_matlist &,
1581 model::complex_veclist &,
1582 model::complex_veclist &,
1588 const model::termlist& tlist,
1589 const model::varnamelist &,
1590 const model::varnamelist &,
1591 const model::mimlist &,
1592 model::real_matlist &,
1593 model::real_veclist &,
1595 const scalar_type delta = 1e-8)
const;
1599 virtual std::string declare_volume_assembly_string
1601 const model::varnamelist &)
const {
1602 GMM_ASSERT1(
false,
"No assemby string declared, computation of Neumann "
1603 "term impossible for brick " << name);
1610 const model::varnamelist &,
1611 const model::varnamelist &,
1612 const model::mimlist &,
1613 model::real_matlist &,
1614 model::real_veclist &,
1615 model::real_veclist &,
1643 (model &md,
const mesh_im &mim,
const std::string &expr,
1645 bool is_coercive =
false,
const std::string &brickname =
"",
1646 bool return_if_nonlin =
false);
1648 inline size_type APIDECL add_linear_generic_assembly_brick
1649 (model &md,
const mesh_im &mim,
const std::string &expr,
1651 bool is_coercive =
false,
const std::string &brickname =
"",
1652 bool return_if_nonlin =
false) {
1654 is_coercive, brickname, return_if_nonlin);
1670 (model &md,
const mesh_im &mim,
const std::string &expr,
1672 bool is_coercive =
false,
const std::string &brickname =
"");
1674 inline size_type APIDECL add_nonlinear_generic_assembly_brick
1675 (model &md,
const mesh_im &mim,
const std::string &expr,
1677 bool is_coercive =
false,
const std::string &brickname =
"") {
1679 is_sym, is_coercive, brickname);
1692 (model &md,
const mesh_im &mim,
const std::string &expr,
1694 const std::string &brickname = std::string(),
1695 const std::string &directvarname = std::string(),
1696 const std::string &directdataname = std::string(),
1697 bool return_if_nonlin =
false);
1698 inline size_type APIDECL add_source_term_generic_assembly_brick
1699 (model &md,
const mesh_im &mim,
const std::string &expr,
1701 const std::string &brickname = std::string(),
1702 const std::string &directvarname = std::string(),
1703 const std::string &directdataname = std::string(),
1704 bool return_if_nonlin =
false) {
1706 directvarname, directdataname, return_if_nonlin);
1716 (model &md,
const mesh_im &mim,
const std::string &expr,
1717 size_type region,
const std::string &secondary_domain,
1718 bool is_sym =
false,
bool is_coercive =
false,
1719 const std::string &brickname =
"",
bool return_if_nonlin =
false);
1728 (model &md,
const mesh_im &mim,
const std::string &expr,
1729 size_type region,
const std::string &secondary_domain,
1730 bool is_sym =
false,
bool is_coercive =
false,
1731 const std::string &brickname =
"");
1740 (model &md,
const mesh_im &mim,
const std::string &expr,
1741 size_type region,
const std::string &secondary_domain,
1742 const std::string &brickname = std::string(),
1743 const std::string &directvarname = std::string(),
1744 const std::string &directdataname = std::string(),
1745 bool return_if_nonlin =
false);
1755 (model &md,
const mesh_im &mim,
const std::string &varname,
1781 (model &md,
const mesh_im &mim,
const std::string &varname,
1795 (model &md,
const mesh_im &mim,
const std::string &varname,
1797 const std::string &directdataname = std::string());
1810 (model &md,
const mesh_im &mim,
const std::string &varname,
1811 const std::string &dataexpr,
size_type region);
1833 (model &md,
const std::string &varname,
size_type region,
1834 const std::string &dataname = std::string());
1848 (model &md,
const mesh_im &mim,
const std::string &varname,
1849 const std::string &multname,
size_type region,
1850 const std::string &dataname = std::string());
1859 (model &md,
const mesh_im &mim,
const std::string &varname,
1860 const mesh_fem &mf_mult,
size_type region,
1861 const std::string &dataname = std::string());
1868 (model &md,
const mesh_im &mim,
const std::string &varname,
1870 const std::string &dataname = std::string());
1892 (model &md,
const mesh_im &mim,
const std::string &varname,
1893 scalar_type penalization_coeff,
size_type region,
1894 const std::string &dataname = std::string(),
1895 const mesh_fem *mf_mult = 0);
1915 (model &md,
const mesh_im &mim,
const std::string &varname,
1916 const std::string &Neumannterm,
1917 const std::string &datagamma0,
size_type region,
1918 scalar_type theta = scalar_type(0),
1919 const std::string &datag = std::string());
1936 (model &md,
const mesh_im &mim,
const std::string &varname,
1937 const std::string &multname,
size_type region,
1938 const std::string &dataname = std::string());
1947 (model &md,
const mesh_im &mim,
const std::string &varname,
1948 const mesh_fem &mf_mult,
size_type region,
1949 const std::string &dataname = std::string());
1956 (model &md,
const mesh_im &mim,
const std::string &varname,
1958 const std::string &dataname = std::string());
1975 (model &md,
const mesh_im &mim,
const std::string &varname,
1976 scalar_type penalization_coeff,
size_type region,
1977 const std::string &dataname = std::string(),
1978 const mesh_fem *mf_mult = 0);
2001 (model &md,
const mesh_im &mim,
const std::string &varname,
2002 const std::string &Neumannterm,
const std::string &datagamma0,
2003 size_type region, scalar_type theta = scalar_type(0),
2004 const std::string &datag = std::string());
2024 (model &md,
const std::string &varname,
2025 scalar_type penalisation_coeff,
const std::string &dataname_pt,
2026 const std::string &dataname_unitv = std::string(),
2027 const std::string &dataname_val = std::string());
2049 (model &md,
const std::string &varname,
2050 const std::string &multname,
const std::string &dataname_pt,
2051 const std::string &dataname_unitv = std::string(),
2052 const std::string &dataname_val = std::string());
2071 (model &md,
const std::string &varname,
const std::string &dataname_pt,
2072 const std::string &dataname_unitv = std::string(),
2073 const std::string &dataname_val = std::string());
2081 scalar_type penalisation_coeff);
2097 (model &md,
const mesh_im &mim,
const std::string &varname,
2098 const std::string &multname,
size_type region,
2099 const std::string &dataname,
const std::string &Hname);
2108 (model &md,
const mesh_im &mim,
const std::string &varname,
2109 const mesh_fem &mf_mult,
size_type region,
2110 const std::string &dataname,
const std::string &Hname);
2117 (model &md,
const mesh_im &mim,
const std::string &varname,
2119 const std::string &dataname,
const std::string &Hname);
2138 (model &md,
const mesh_im &mim,
const std::string &varname,
2139 scalar_type penalization_coeff,
size_type region,
2140 const std::string &dataname,
const std::string &Hname,
2141 const mesh_fem *mf_mult = 0);
2164 (model &md,
const mesh_im &mim,
const std::string &varname,
2165 const std::string &Neumannterm,
const std::string &datagamma0,
2167 const std::string &datag,
const std::string &dataH);
2178 const std::string &varname,
2179 const std::string &dataexpr,
2195 const std::string &varname,
2196 const std::string &dataexpr,
2201 model_real_sparse_matrix APIDECL &set_private_data_brick_real_matrix
2203 model_real_plain_vector APIDECL &set_private_data_brick_real_rhs
2205 model_complex_sparse_matrix APIDECL &set_private_data_brick_complex_matrix
2207 model_complex_plain_vector APIDECL &set_private_data_brick_complex_rhs
2209 size_type APIDECL add_constraint_with_penalization
2210 (model &md,
const std::string &varname, scalar_type penalisation_coeff);
2211 size_type APIDECL add_constraint_with_multipliers
2212 (model &md,
const std::string &varname,
const std::string &multname);
2214 void set_private_data_rhs
2215 (model &md,
size_type indbrick,
const std::string &varname);
2217 template <
typename VECT,
typename T>
2218 void set_private_data_rhs(model &md,
size_type ind,
2220 model_real_plain_vector &LL = set_private_data_brick_real_rhs(md, ind);
2225 template <
typename VECT,
typename T>
2226 void set_private_data_rhs(model &md,
size_type ind,
const VECT &L,
2228 model_complex_plain_vector &LL = set_private_data_brick_complex_rhs(md, ind);
2237 template <
typename VECT>
2239 typedef typename gmm::linalg_traits<VECT>::value_type T;
2240 set_private_data_rhs(md, indbrick, L, T());
2243 template <
typename MAT,
typename T>
2244 void set_private_data_matrix(model &md,
size_type ind,
2246 model_real_sparse_matrix &BB = set_private_data_brick_real_matrix(md, ind);
2247 gmm::resize(BB, gmm::mat_nrows(B), gmm::mat_ncols(B));
2251 template <
typename MAT,
typename T>
2252 void set_private_data_matrix(model &md,
size_type ind,
const MAT &B,
2254 model_complex_sparse_matrix &BB
2255 = set_private_data_brick_complex_matrix(md, ind);
2256 gmm::resize(BB, gmm::mat_nrows(B), gmm::mat_ncols(B));
2263 template <
typename MAT>
2266 typedef typename gmm::linalg_traits<MAT>::value_type T;
2267 set_private_data_matrix(md, indbrick, B, T());
2278 template <
typename MAT,
typename VECT>
2279 size_type add_constraint_with_penalization
2280 (
model &md,
const std::string &varname, scalar_type penalisation_coeff,
2281 const MAT &B,
const VECT &L) {
2283 = add_constraint_with_penalization(md, varname, penalisation_coeff);
2284 size_type n = gmm::mat_nrows(B), m = gmm::mat_ncols(B);
2285 set_private_data_rhs(md, ind, L);
2286 set_private_data_matrix(md, ind, B);
2298 template <
typename MAT,
typename VECT>
2299 size_type add_constraint_with_multipliers
2300 (
model &md,
const std::string &varname,
const std::string &multname,
2301 const MAT &B,
const VECT &L) {
2302 size_type ind = add_constraint_with_multipliers(md, varname, multname);
2303 set_private_data_rhs(md, ind, L);
2304 set_private_data_matrix(md, ind, B);
2308 template <
typename MAT>
2309 size_type add_constraint_with_multipliers
2310 (model &md,
const std::string &varname,
const std::string &multname,
2311 const MAT &B,
const std::string &Lname) {
2312 size_type ind = add_constraint_with_multipliers(md, varname, multname);
2313 set_private_data_rhs(md, ind, Lname);
2314 set_private_data_matrix(md, ind, B);
2318 size_type APIDECL add_explicit_matrix(model &md,
const std::string &varname1,
2319 const std::string &varname2,
2320 bool issymmetric,
bool iscoercive);
2321 size_type APIDECL add_explicit_rhs(model &md,
const std::string &varname);
2333 template <
typename MAT>
2335 const std::string &varname2,
const MAT &B,
2336 bool issymmetric =
false,
2337 bool iscoercive =
false) {
2338 size_type ind = add_explicit_matrix(md, varname1, varname2,
2339 issymmetric, iscoercive);
2340 set_private_data_matrix(md, ind, B);
2350 template <
typename VECT>
2353 size_type ind = add_explicit_rhs(md, varname);
2354 set_private_data_rhs(md, ind, L);
2364 (model &md,
const mesh_im &mim,
const std::string &varname,
2365 const std::string &dataname_lambda,
const std::string &dataname_mu,
2367 const std::string &dataname_preconstraint = std::string());
2377 (model &md,
const mesh_im &mim,
const std::string &varname,
2378 const std::string &data_E,
const std::string &data_nu,
2390 (model &md,
const mesh_im &mim,
const std::string &varname,
2391 const std::string &data_E,
const std::string &data_nu,
2394 void APIDECL compute_isotropic_linearized_Von_Mises_or_Tresca
2395 (model &md,
const std::string &varname,
const std::string &dataname_lambda,
2396 const std::string &dataname_mu,
const mesh_fem &mf_vm,
2397 model_real_plain_vector &VM,
bool tresca);
2404 template <
class VECTVM>
2405 void compute_isotropic_linearized_Von_Mises_or_Tresca
2406 (
model &md,
const std::string &varname,
const std::string &dataname_lambda,
2407 const std::string &dataname_mu,
const mesh_fem &mf_vm,
2408 VECTVM &VM,
bool tresca) {
2409 model_real_plain_vector VMM(mf_vm.
nb_dof());
2410 compute_isotropic_linearized_Von_Mises_or_Tresca
2411 (md, varname, dataname_lambda, dataname_mu, mf_vm, VMM, tresca);
2421 (model &md,
const std::string &varname,
const std::string &data_E,
2422 const std::string &data_nu,
const mesh_fem &mf_vm,
2423 model_real_plain_vector &VM);
2431 (model &md,
const std::string &varname,
const std::string &data_E,
2432 const std::string &data_nu,
const mesh_fem &mf_vm,
2433 model_real_plain_vector &VM);
2456 (model &md,
const mesh_im &mim,
const std::string &varname,
2458 const std::string &dataexpr_penal_coeff = std::string());
2465 (model &md,
const mesh_im &mim,
const std::string &varname,
2466 const std::string &dataexpr_rho = std::string(),
2474 (model &md,
const mesh_im &mim,
const std::string &varname,
2475 const std::string &dataexpr_rho = std::string(),
2485 (model &md,
const mesh_im &mim,
const std::string &varname,
2486 const std::string &dataname_dt,
2487 const std::string &dataname_rho = std::string(),
2498 (model &md,
const mesh_im &mim,
const std::string &varnameU,
2499 const std::string &datanameV,
2500 const std::string &dataname_dt,
2501 const std::string &dataname_alpha,
2502 const std::string &dataname_rho = std::string(),