branch: master commit cd0c759ebcd3f70d3d8174cf3efece0e2e8e8ee3 Author: Konstantinos Poulios <logar...@gmail.com> Date: Wed Feb 20 18:55:15 2019 +0100
Coding style changes and simplifications --- src/getfem/getfem_models.h | 27 +++- src/getfem_generic_assembly_compile_and_exec.cc | 143 +++++++++--------- src/getfem_generic_assembly_interpolation.cc | 3 +- src/getfem_models.cc | 193 +++++++++++------------- 4 files changed, 181 insertions(+), 185 deletions(-) diff --git a/src/getfem/getfem_models.h b/src/getfem/getfem_models.h index b8b697c..c414862 100644 --- a/src/getfem/getfem_models.h +++ b/src/getfem/getfem_models.h @@ -393,6 +393,7 @@ namespace getfem { // with BUILD_RHS option. VAR_SET::const_iterator find_variable(const std::string &name) const; + const var_description &variable_description(const std::string &name) const; public: @@ -515,6 +516,7 @@ namespace getfem { /** States if a name corresponds to a declared variable. */ bool variable_exists(const std::string &name) const; + /** States if a variable is disabled (treated as data). */ bool is_disabled_variable(const std::string &name) const; /** States if a name corresponds to a declared data or disabled variable. */ @@ -749,7 +751,8 @@ namespace getfem { /** Add data, defined at integration points.*/ - void add_im_data(const std::string &name, const im_data &im_data, size_type niter = 1); + void add_im_data(const std::string &name, const im_data &im_data, + size_type niter = 1); /** Add a variable being the dofs of a finite element method to the model. niter is the number of version of the variable stored, for time @@ -890,8 +893,14 @@ namespace getfem { return rrhs; } - /** Gives the access to the part of the right hand side of a term of a particular nonlinear brick. Does not account of the eventual time dispatcher. An assembly of the rhs has to be done first. For the real version. */ - const model_real_plain_vector &real_brick_term_rhs(size_type ib, size_type ind_term = 0, bool sym = false, size_type ind_iter = 0) const { + /** Gives access to the part of the right hand side of a term of + a particular nonlinear brick. Does not account of the eventual time + dispatcher. An assembly of the rhs has to be done first. + For the real version. */ + const model_real_plain_vector &real_brick_term_rhs + (size_type ib, size_type ind_term = 0, bool sym = false, + size_type ind_iter = 0) const + { GMM_ASSERT1(!complex_version, "This model is a complex one"); context_check(); if (act_size_to_be_done) actualize_sizes(); GMM_ASSERT1(valid_bricks[ib], "Inexistent brick"); @@ -899,7 +908,6 @@ namespace getfem { GMM_ASSERT1(ind_iter < bricks[ib].nbrhs, "Inexistent iter"); GMM_ASSERT1(!sym || bricks[ib].tlist[ind_term].is_symmetric, "Term is not symmetric"); - if (sym) return bricks[ib].rveclist_sym[ind_iter][ind_term]; else @@ -914,8 +922,14 @@ namespace getfem { return crhs; } - /** Gives access to the part of the right hand side of a term of a particular nonlinear brick. Does not account of the eventual time dispatcher. An assembly of the rhs has to be done first. For the real version. */ - const model_complex_plain_vector &complex_brick_term_rhs(size_type ib, size_type ind_term = 0, bool sym = false, size_type ind_iter = 0) const { + /** Gives access to the part of the right hand side of a term of a + particular nonlinear brick. Does not account of the eventual time + dispatcher. An assembly of the rhs has to be done first. + For the complex version. */ + const model_complex_plain_vector &complex_brick_term_rhs + (size_type ib, size_type ind_term = 0, bool sym = false, + size_type ind_iter = 0) const + { GMM_ASSERT1(!complex_version, "This model is a complex one"); context_check(); if (act_size_to_be_done) actualize_sizes(); GMM_ASSERT1(valid_bricks[ib], "Inexistent brick"); @@ -923,7 +937,6 @@ namespace getfem { GMM_ASSERT1(ind_iter < bricks[ib].nbrhs, "Inexistent iter"); GMM_ASSERT1(!sym || bricks[ib].tlist[ind_term].is_symmetric, "Term is not symmetric"); - if (sym) return bricks[ib].cveclist_sym[ind_iter][ind_term]; else diff --git a/src/getfem_generic_assembly_compile_and_exec.cc b/src/getfem_generic_assembly_compile_and_exec.cc index aa189c6..6f96e86 100644 --- a/src/getfem_generic_assembly_compile_and_exec.cc +++ b/src/getfem_generic_assembly_compile_and_exec.cc @@ -4051,14 +4051,13 @@ namespace getfem { // ? ctx.convex_num() : mf.convex_index().first_true(); GA_DEBUG_ASSERT(V.size() >= I.first() + mf.nb_basic_dof(), "Bad assembly vector size"); - auto &ct = mf.ind_scalar_basic_dof_of_element(cv_1); size_type qmult = mf.get_qdim(); if (qmult > 1) qmult /= mf.fem_of_element(cv_1)->target_dim(); size_type ifirst = I.first(); auto ite = elem.begin(); - for (auto itc = ct.begin(); itc != ct.end(); ++itc) + for (const auto &dof : mf.ind_scalar_basic_dof_of_element(cv_1)) for (size_type q = 0; q < qmult; ++q) - V[ifirst+(*itc)+q] += *ite++; + V[ifirst+dof+q] += *ite++; GMM_ASSERT1(ite == elem.end(), "Internal error"); } return 0; @@ -4076,7 +4075,7 @@ namespace getfem { }; struct ga_instruction_vector_assembly : public ga_instruction { - base_tensor &t; + const base_tensor &t; base_vector &V; const gmm::sub_interval &I; scalar_type &coeff; @@ -4085,15 +4084,15 @@ namespace getfem { "fixed size variable"); gmm::add(gmm::scaled(t.as_vector(), coeff), gmm::sub_vector(V, I)); return 0; - } - ga_instruction_vector_assembly(base_tensor &t_, base_vector &V_, + } + ga_instruction_vector_assembly(const base_tensor &t_, base_vector &V_, const gmm::sub_interval &I_, scalar_type &coeff_) : t(t_), V(V_), I(I_), coeff(coeff_) {} }; struct ga_instruction_assignment : public ga_instruction { - base_tensor &t; + const base_tensor &t; base_vector &V; const fem_interpolation_context &ctx; const im_data *imd; @@ -4101,8 +4100,8 @@ namespace getfem { GA_DEBUG_INFO("Instruction: Assignement to im_data"); imd->set_tensor(V, ctx.convex_num(), ctx.ii(), t); return 0; - } - ga_instruction_assignment(base_tensor &t_, base_vector &V_, + } + ga_instruction_assignment(const base_tensor &t_, base_vector &V_, const fem_interpolation_context &ctx_, const im_data *imd_) : t(t_), V(V_), ctx(ctx_), imd(imd_) {} @@ -4160,25 +4159,36 @@ namespace getfem { if (nb == 0) { col.reserve(maxest); for (size_type i = 0; i < s1; ++i) { - size_type k = dofs1_sort[i]; ev.e = *(it+k); - if (gmm::abs(ev.e) > threshold) { ev.c=dofs1[k]; col.push_back(ev); } + size_type k = dofs1_sort[i]; + ev.e = *(it+k); + if (gmm::abs(ev.e) > threshold) { + ev.c=dofs1[k]; + col.push_back(ev); + } } } else { // column merge size_type ind = 0; for (size_type i = 0; i < s1; ++i) { - size_type k = dofs1_sort[i]; ev.e = *(it+k); + size_type k = dofs1_sort[i]; + ev.e = *(it+k); if (gmm::abs(ev.e) > threshold) { ev.c = dofs1[k]; size_type count = nb - ind, step, l; while (count > 0) { - step = count / 2; l = ind + step; - if (col[l].c < ev.c) { ind = ++l; count -= step + 1; } - else count = step; + step = count / 2; + l = ind + step; + if (col[l].c < ev.c) { + ind = ++l; + count -= step + 1; + } + else + count = step; } auto itc = col.begin() + ind; - if (ind != nb && itc->c == ev.c) itc->e += ev.e; + if (ind != nb && itc->c == ev.c) + itc->e += ev.e; else { if (nb - ind > 1300) GMM_WARNING2("Inefficient addition of element in rsvector with " @@ -4186,7 +4196,9 @@ namespace getfem { col.push_back(ev); if (ind != nb) { itc = col.begin() + ind; - auto ite = col.end(); --ite; auto itee = ite; + auto ite = col.end(); + --ite; + auto itee = ite; for (; ite != itc; --ite) { --itee; *ite = *itee; } *itc = ev; } @@ -4205,10 +4217,8 @@ namespace getfem { const base_tensor &t; MAT &Kr, &Kn; const fem_interpolation_context &ctx1, &ctx2; - const gmm::sub_interval &Ir1, &Ir2; - const gmm::sub_interval &In1, &In2; - const mesh_fem *mfn1, *mfn2; - const mesh_fem **mfg1, **mfg2; + const gmm::sub_interval &Ir1, &Ir2, &In1, &In2; + const mesh_fem *mfn1, *mfn2, **mfg1, **mfg2; const scalar_type &coeff, &alpha1, &alpha2; const size_type &nbpt, &ipt; base_vector elem; @@ -4321,13 +4331,12 @@ namespace getfem { const gmm::sub_interval &Ir2_, const gmm::sub_interval &In2_, const mesh_fem *mfn1_, const mesh_fem **mfg1_, const mesh_fem *mfn2_, const mesh_fem **mfg2_, - const scalar_type &coeff_, - const scalar_type &alpha2_, const scalar_type &alpha1_, + const scalar_type &coeff_, const scalar_type &a1, const scalar_type &a2, const size_type &nbpt_, const size_type &ipt_, bool interpolate_) : t(t_), Kr(Kr_), Kn(Kn_), ctx1(ctx1_), ctx2(ctx2_), Ir1(Ir1_), Ir2(Ir2_), In1(In1_), In2(In2_), mfn1(mfn1_), mfn2(mfn2_), mfg1(mfg1_), mfg2(mfg2_), - coeff(coeff_), alpha1(alpha1_), alpha2(alpha2_), + coeff(coeff_), alpha1(a1), alpha2(a2), nbpt(nbpt_), ipt(ipt_), interpolate(interpolate_), dofs1(0), dofs2(0) {} }; @@ -4410,13 +4419,11 @@ namespace getfem { const fem_interpolation_context &ctx2_, const gmm::sub_interval &In1_, const gmm::sub_interval &In2_, const mesh_fem *mfn1_, const mesh_fem *mfn2_, - const scalar_type &coeff_, const scalar_type &alpha2_, - const scalar_type &alpha1_, + const scalar_type &coeff_, const scalar_type &a1, const scalar_type &a2, const size_type &nbpt_, const size_type &ipt_) : t(t_), K(Kn_), ctx1(ctx1_), ctx2(ctx2_), I1(In1_), I2(In2_), pmf1(mfn1_), pmf2(mfn2_), - coeff(coeff_), alpha1(alpha1_), alpha2(alpha2_), - nbpt(nbpt_), ipt(ipt_) {} + coeff(coeff_), alpha1(a1), alpha2(a2), nbpt(nbpt_), ipt(ipt_) {} }; template <class MAT = model_real_sparse_matrix> @@ -4509,12 +4516,11 @@ namespace getfem { const fem_interpolation_context &ctx2_, const gmm::sub_interval &In1_, const gmm::sub_interval &In2_, const mesh_fem *mfn1_, const mesh_fem *mfn2_, - const scalar_type &coeff_, const scalar_type &alpha2_, - const scalar_type &alpha1_, const size_type &nbpt_, - const size_type &ipt_) + const scalar_type &coeff_, const scalar_type &a1, const scalar_type &a2, + const size_type &nbpt_, const size_type &ipt_) : t(t_), K(Kn_), ctx1(ctx1_), ctx2(ctx2_), I1(In1_), I2(In2_), pmf1(mfn1_), pmf2(mfn2_), - coeff(coeff_), alpha1(alpha1_), alpha2(alpha2_), + coeff(coeff_), alpha1(a1), alpha2(a2), nbpt(nbpt_), ipt(ipt_), dofs1(0), dofs2(0) {} }; @@ -4596,12 +4602,11 @@ namespace getfem { const fem_interpolation_context &ctx2_, const gmm::sub_interval &In1_, const gmm::sub_interval &In2_, const mesh_fem *mfn1_, const mesh_fem *mfn2_, - const scalar_type &coeff_, const scalar_type &alpha2_, - const scalar_type &alpha1_, const size_type &nbpt_, - const size_type &ipt_) + const scalar_type &coeff_, const scalar_type &a1, const scalar_type &a2, + const size_type &nbpt_, const size_type &ipt_) : t(t_), K(Kn_), ctx1(ctx1_), ctx2(ctx2_), I1(In1_), I2(In2_), pmf1(mfn1_), pmf2(mfn2_), - coeff(coeff_), alpha1(alpha1_), alpha2(alpha2_), + coeff(coeff_), alpha1(a1), alpha2(a2), nbpt(nbpt_), ipt(ipt_), dofs1(0), dofs2(0) {} }; @@ -4691,12 +4696,11 @@ namespace getfem { const fem_interpolation_context &ctx2_, const gmm::sub_interval &In1_, const gmm::sub_interval &In2_, const mesh_fem *mfn1_, const mesh_fem *mfn2_, - const scalar_type &coeff_, const scalar_type &alpha2_, - const scalar_type &alpha1_, const size_type &nbpt_, - const size_type &ipt_) + const scalar_type &coeff_, const scalar_type &a1, const scalar_type &a2, + const size_type &nbpt_, const size_type &ipt_) : t(t_), K(Kn_), ctx1(ctx1_), ctx2(ctx2_), I1(In1_), I2(In2_), pmf1(mfn1_), pmf2(mfn2_), - coeff(coeff_), alpha1(alpha1_), alpha2(alpha2_), + coeff(coeff_), alpha1(a1), alpha2(a2), nbpt(nbpt_), ipt(ipt_), dofs1(0), dofs2(0) {} }; @@ -4716,7 +4720,7 @@ namespace getfem { for (const std::string &v : workspace.variable_group(varname)) add_interval_to_gis(workspace, v, gis); } else { - if (gis.var_intervals.find(varname) == gis.var_intervals.end()) { + if (gis.var_intervals.count(varname) == 0) { const mesh_fem *mf = workspace.associated_mf(varname); size_type nd = mf ? mf->nb_basic_dof() : gmm::vect_size(workspace.value(varname)); @@ -4734,7 +4738,7 @@ namespace getfem { if (workspace.variable_group_exists(varname)) { for (const std::string &v : workspace.variable_group(varname)) extend_variable_in_gis(workspace, v, gis); - } else if (gis.extended_vars.find(varname)==gis.extended_vars.end()) { + } else if (gis.extended_vars.count(varname) == 0) { const mesh_fem *mf = workspace.associated_mf(varname); if (mf->is_reduced()) { auto n = (mf->get_qdim() == 1) ? workspace.qdim(varname) : 1; @@ -6808,9 +6812,9 @@ namespace getfem { workspace.secondary_domain_exists(intn1); if (intn1.size() && !secondary && workspace.variable_group_exists(root->name_test1)) { - ga_instruction_set::variable_group_info &vgi = - rmi.interpolate_infos[intn1] - .groups_info[root->name_test1]; + ga_instruction_set::variable_group_info + &vgi = rmi.interpolate_infos[intn1] + .groups_info[root->name_test1]; Ir = &(vgi.Ir); In = &(vgi.In); mfg = &(vgi.mf); @@ -6819,14 +6823,12 @@ namespace getfem { Ir = &(gis.var_intervals[root->name_test1]); In = &(workspace.interval_of_variable(root->name_test1)); } - fem_interpolation_context &ctx - = intn1.size() - ? (secondary ? rmi.secondary_domain_infos.ctx - : rmi.interpolate_infos[intn1].ctx) - : gis.ctx; - bool interpolate = !(intn1.empty() || - intn1 == "neighbour_elt" || - secondary); + fem_interpolation_context + &ctx = intn1.empty() ? gis.ctx + : (secondary ? rmi.secondary_domain_infos.ctx + : rmi.interpolate_infos[intn1].ctx); + bool interpolate = + !(intn1.empty() || intn1 == "neighbour_elt" || secondary); pgai = std::make_shared<ga_instruction_fem_vector_assembly> (root->tensor(), workspace.unreduced_vector(), workspace.assembled_vector(), ctx, *Ir, *In, mf, mfg, @@ -6844,10 +6846,9 @@ namespace getfem { GMM_ASSERT1(root->tensor_proper_size() == 1, "Invalid vector or tensor quantity. An order 2 " "weak form has to be a scalar quantity"); - const mesh_fem - *mf1=workspace.associated_mf(root->name_test1), - *mf2=workspace.associated_mf(root->name_test2), - **mfg1 = 0, **mfg2 = 0; + const mesh_fem *mf1=workspace.associated_mf(root->name_test1), + *mf2=workspace.associated_mf(root->name_test2), + **mfg1 = 0, **mfg2 = 0; const std::string &intn1 = root->interpolate_name_test1, &intn2 = root->interpolate_name_test2; bool secondary1 = intn1.size() && @@ -6855,14 +6856,12 @@ namespace getfem { bool secondary2 = intn2.size() && workspace.secondary_domain_exists(intn2); fem_interpolation_context - &ctx1 = intn1.size() - ? (secondary1 ? rmi.secondary_domain_infos.ctx - : rmi.interpolate_infos[intn1].ctx) - : gis.ctx, - &ctx2 = intn2.size() - ? (secondary2 ? rmi.secondary_domain_infos.ctx - : rmi.interpolate_infos[intn2].ctx) - : gis.ctx; + &ctx1 = intn1.empty() ? gis.ctx + : (secondary1 ? rmi.secondary_domain_infos.ctx + : rmi.interpolate_infos[intn1].ctx), + &ctx2 = intn2.empty() ? gis.ctx + : (secondary2 ? rmi.secondary_domain_infos.ctx + : rmi.interpolate_infos[intn2].ctx); bool interpolate = !(intn1.empty() || intn1 == "neighbour_elt" || secondary1) || !(intn2.empty() || intn2 == "neighbour_elt" @@ -6876,9 +6875,9 @@ namespace getfem { if (!intn1.empty() && !secondary1 && workspace.variable_group_exists(root->name_test1)) { - ga_instruction_set::variable_group_info &vgi = - rmi.interpolate_infos[intn1] - .groups_info[root->name_test1]; + ga_instruction_set::variable_group_info + &vgi = rmi.interpolate_infos[intn1] + .groups_info[root->name_test1]; Ir1 = &(vgi.Ir); In1 = &(vgi.In); mfg1 = &(vgi.mf); @@ -6892,9 +6891,9 @@ namespace getfem { if (!intn2.empty() && !secondary2 && workspace.variable_group_exists(root->name_test2)) { - ga_instruction_set::variable_group_info &vgi = - rmi.interpolate_infos[intn2] - .groups_info[root->name_test2]; + ga_instruction_set::variable_group_info + &vgi = rmi.interpolate_infos[intn2] + .groups_info[root->name_test2]; Ir2 = &(vgi.Ir); In2 = &(vgi.In); mfg2 = &(vgi.mf); @@ -7347,7 +7346,7 @@ namespace getfem { } auto ipt_coeff = pai1->coeff(first_ind1+ipt1) - * pai2->coeff(first_ind2+ipt2); + * pai2->coeff(first_ind2+ipt2); gis.coeff = J1 * J2 * ipt_coeff; bool enable_ipt = (gmm::abs(ipt_coeff) > 0.0 || workspace.include_empty_int_points()); diff --git a/src/getfem_generic_assembly_interpolation.cc b/src/getfem_generic_assembly_interpolation.cc index 60951cd..8696ca8 100644 --- a/src/getfem_generic_assembly_interpolation.cc +++ b/src/getfem_generic_assembly_interpolation.cc @@ -519,8 +519,7 @@ namespace getfem { used_vars.clear(); else used_data.clear(); - ga_workspace aux_workspace; - aux_workspace = ga_workspace(true, workspace); + ga_workspace aux_workspace(true, workspace); aux_workspace.clear_expressions(); aux_workspace.add_interpolation_expression(expr, source_mesh); for (size_type i = 0; i < aux_workspace.nb_trees(); ++i) diff --git a/src/getfem_models.cc b/src/getfem_models.cc index e7c9315..b65c468 100644 --- a/src/getfem_models.cc +++ b/src/getfem_models.cc @@ -100,26 +100,20 @@ namespace getfem { } bool model::check_name_validity(const std::string &name, bool assert) const { - VAR_SET::const_iterator it = variables.find(name); - if (it != variables.end()) { + + if (variables.count(name) != 0) { GMM_ASSERT1(!assert, "Variable " << name << " already exists"); return false; - } - - if (variable_groups.find(name) != variable_groups.end()) { + } else if (variable_groups.count(name) != 0) { GMM_ASSERT1(!assert, name << " corresponds to an already existing group of " "variables name"); return false; - } - - if (macro_exists(name)) { + } else if (macro_exists(name)) { GMM_ASSERT1(!assert, name << " corresponds to an already existing macro"); return false; - } - - if (name.compare("X") == 0) { + } else if (name.compare("X") == 0) { GMM_ASSERT1(!assert, "X is a reserved keyword of the generic " "assembly language"); return false; @@ -130,15 +124,11 @@ namespace getfem { GMM_ASSERT1(!assert, "Invalid variable name, corresponds to an " "operator or function name of the generic assembly language"); return false; - } - - if (ga_valid == 2) { + } else if (ga_valid == 2) { GMM_ASSERT1(!assert, "Invalid variable name having a reserved " "prefix used by the generic assembly language"); return false; - } - - if (ga_valid == 3) { + } else if (ga_valid == 3) { std::string org_name = sup_previous_and_dot_to_varname(name); if (org_name.size() < name.size() && variables.find(org_name) != variables.end()) { @@ -149,13 +139,10 @@ namespace getfem { } } - bool valid = true; - if (name.size() == 0) valid = false; - else { - if (!isalpha(name[0])) valid = false; + bool valid = !name.empty() && isalpha(name[0]); + if (valid) for (size_type i = 1; i < name.size(); ++i) if (!(isalnum(name[i]) || name[i] == '_')) valid = false; - } GMM_ASSERT1(!assert || valid, "Illegal variable name : \"" << name << "\""); return valid; @@ -188,6 +175,11 @@ namespace getfem { return it; } + const model::var_description & + model::variable_description(const std::string &name) const { + return find_variable(name)->second; + } + std::string sup_previous_and_dot_to_varname(std::string v) { if (!(v.compare(0, 8, "Previous")) && (v[8] == '_' || v[9] == '_')) { v = v.substr((v[8] == '_') ? 9 : 10); @@ -221,36 +213,31 @@ namespace getfem { VAR_SET::const_iterator it = find_variable(name); if (it->second.is_affine_dependent) it = variables.find(it->second.org_name); - return (!(it->second.is_variable) || it->second.is_disabled); + return !(it->second.is_variable) || it->second.is_disabled; } bool model::is_true_data(const std::string &name) const { - if (is_old(name)) return true; - VAR_SET::const_iterator it = find_variable(name); - return (!(it->second.is_variable)); + return is_old(name) ? true : !variable_description(name).is_variable; } bool model::is_affine_dependent_variable(const std::string &name) const { - if (is_old(name)) return false; - VAR_SET::const_iterator it = find_variable(name); - return (it->second.is_affine_dependent); + return is_old(name) ? false + : variable_description(name).is_affine_dependent; } - const std::string &model::org_variable(const std::string &name) const { - VAR_SET::const_iterator it = variables.find(name); + const std::string & + model::org_variable(const std::string &name) const { GMM_ASSERT1(is_affine_dependent_variable(name), "For affine dependent variables only"); - return (it->second.org_name); + return variable_description(name).org_name; } const scalar_type & model::factor_of_variable(const std::string &name) const { - VAR_SET::const_iterator it = find_variable(name); - return (it->second.alpha); + return variable_description(name).alpha; } - void model::set_factor_of_variable(const std::string &name, - scalar_type a) { + void model::set_factor_of_variable(const std::string &name, scalar_type a) { VAR_SET::iterator it = variables.find(name); GMM_ASSERT1(it != variables.end(), "Undefined variable " << name); if (it->second.alpha != a) { @@ -260,8 +247,7 @@ namespace getfem { } bool model::is_im_data(const std::string &name) const { - auto it = find_variable(no_old_prefix_name(name)); - return (it->second.pim_data != 0); + return variable_description(no_old_prefix_name(name)).pim_data != 0; } const im_data * @@ -271,7 +257,8 @@ namespace getfem { } const gmm::uint64_type & - model::version_number_of_data_variable(const std::string &name, size_type niter) const { + model::version_number_of_data_variable(const std::string &name, + size_type niter) const { VAR_SET::const_iterator it = find_variable(name); if (niter == size_type(-1)) niter = it->second.default_iter; return it->second.v_num_data[niter]; @@ -280,13 +267,13 @@ namespace getfem { size_type model::nb_dof() const { context_check(); if (act_size_to_be_done) actualize_sizes(); - return (complex_version) ? gmm::vect_size(crhs) : gmm::vect_size(rrhs); + return complex_version ? gmm::vect_size(crhs) : gmm::vect_size(rrhs); } void model::resize_global_system() const { size_type tot_size = 0; - for (auto && v : variables) { + for (auto &&v : variables) { if (v.second.is_variable && v.second.is_disabled) v.second.I = gmm::sub_interval(0,0); if (v.second.is_variable && !(v.second.is_affine_dependent) @@ -369,8 +356,8 @@ namespace getfem { break; case VDESCRFILTER_REGION: if (vdescr.v_num < vdescr.mf->version_number()) { - dal::bit_vector dor - = vdescr.mf->dof_on_region(vdescr.m_region); + dal::bit_vector + dor = vdescr.mf->dof_on_region(vdescr.m_region); vdescr.partial_mf->adapt(dor); vdescr.set_size(); vdescr.v_num = act_counter(); @@ -416,13 +403,13 @@ namespace getfem { // #endif const std::vector<std::string> &mults = multipliers[vname]; - const var_description &vdescr = variables.find(vname)->second; + const var_description &vdescr = variable_description(vname); gmm::col_matrix< gmm::rsvector<scalar_type> > MGLOB; if (mults.size() > 1) { size_type s = 0; for (const std::string &mult : mults) - s += variables.find(mult)->second.mf->nb_dof(); + s += variable_description(mult).mf->nb_dof(); gmm::resize(MGLOB, vdescr.mf->nb_dof(), s); } size_type s = 0; @@ -623,36 +610,37 @@ namespace getfem { ost << "Model with no variable nor data" << endl; else { ost << "List of model variables and data:" << endl; - for (auto it = variables.begin(); it != variables.end(); ++it) { - if (it->second.is_variable) ost << "Variable "; + for (const auto &v : variables) { + const var_description &vdescr = v.second; + if (vdescr.is_variable) ost << "Variable "; else ost << "Data "; - ost << std::setw(30) << std::left << it->first; - if (it->second.n_iter == 1) + ost << std::setw(30) << std::left << v.first; + if (vdescr.n_iter == 1) ost << " 1 copy "; else - ost << std::setw(2) << std::right << it->second.n_iter - << " copies "; - if (it->second.is_fem_dofs) ost << "fem dependant "; + ost << std::setw(2) << std::right << vdescr.n_iter << " copies "; + if (vdescr.is_fem_dofs) ost << "fem dependant "; else ost << "constant size "; - size_type si = it->second.size(); + size_type si = vdescr.size(); ost << std::setw(8) << std::right << si; if (is_complex()) ost << " complex"; ost << " double" << ((si > 1) ? "s." : "."); - if (it->second.is_variable && - is_disabled_variable(it->first)) ost << "\t (disabled)"; - else ost << "\t "; - if (it->second.pim_data != 0) ost << "\t (is im_data)"; - if (it->second.is_affine_dependent) ost << "\t (is affine dependent)"; + if (vdescr.is_variable && + is_disabled_variable(v.first)) ost << "\t (disabled)"; + else ost << "\t "; + if (vdescr.pim_data != 0) ost << "\t (is im_data)"; + if (vdescr.is_affine_dependent) ost << "\t (is affine dependent)"; ost << endl; } - for (auto it = variable_groups.begin(); - it != variable_groups.end(); ++it) { + for (const auto &vargroup : variable_groups) { ost << "Variable group " << std::setw(30) << std::left - << it->first; - if (it->second.size()) { - auto it2 = it->second.begin(); - ost << " " << *it2; ++it2; - for (; it2 != it->second.end(); ++it2) ost << ", " << *it2; + << vargroup.first; + if (vargroup.second.size()) { + bool first(true); + for (const std::string vname : vargroup.second) { + if (!first) ost << ","; else first = false; + ost << " " << vname; + } ost << endl; } else ost << " empty" << endl; } @@ -664,13 +652,12 @@ namespace getfem { ost << "Model with no variable nor data" << endl; else { bool firstvar(true); - for (VAR_SET::const_iterator it = variables.begin(); - it != variables.end(); ++it) { - if (it->second.is_variable) { - const gmm::sub_interval &II = interval_of_variable(it->first); + for (const auto &v : variables) { + if (v.second.is_variable) { + const gmm::sub_interval &II = interval_of_variable(v.first); scalar_type res = gmm::vect_norm2(gmm::sub_vector(rrhs, II)); if (!firstvar) cout << ", "; - ost << "res_" << it->first << "= " << std::setw(11) << res; + ost << "res_" << v.first << "= " << std::setw(11) << res; firstvar = false; } } @@ -877,16 +864,15 @@ namespace getfem { VAR_SET::iterator it = variables.find(name); GMM_ASSERT1(it != variables.end(), "Undefined variable " << name); it->second.is_disabled = true; - for (VAR_SET::iterator itv = variables.begin(); - itv != variables.end(); ++itv) { - if (((itv->second.filter & VDESCRFILTER_INFSUP) || - (itv->second.filter & VDESCRFILTER_CTERM)) - && (name.compare(itv->second.filter_var) == 0)) { - itv->second.is_disabled = true; + for (auto &&v : variables) { + if (((v.second.filter & VDESCRFILTER_INFSUP) || + (v.second.filter & VDESCRFILTER_CTERM)) + && name.compare(v.second.filter_var) == 0) { + v.second.is_disabled = true; } - if (itv->second.is_variable && itv->second.is_affine_dependent - && name.compare(itv->second.org_name) == 0) - itv->second.is_disabled = true; + if (v.second.is_variable && v.second.is_affine_dependent + && name.compare(v.second.org_name) == 0) + v.second.is_disabled = true; } if (!act_size_to_be_done) resize_global_system(); } @@ -895,16 +881,15 @@ namespace getfem { VAR_SET::iterator it = variables.find(name); GMM_ASSERT1(it != variables.end(), "Undefined variable " << name); it->second.is_disabled = false; - for (VAR_SET::iterator itv = variables.begin(); - itv != variables.end(); ++itv) { - if (((itv->second.filter & VDESCRFILTER_INFSUP) || - (itv->second.filter & VDESCRFILTER_CTERM)) - && (name.compare(itv->second.filter_var) == 0)) { - itv->second.is_disabled = false; + for (auto &&v : variables) { + if (((v.second.filter & VDESCRFILTER_INFSUP) || + (v.second.filter & VDESCRFILTER_CTERM)) + && name.compare(v.second.filter_var) == 0) { + v.second.is_disabled = false; } - if (itv->second.is_variable && itv->second.is_affine_dependent - && name.compare(itv->second.org_name) == 0) - itv->second.is_disabled = false; + if (v.second.is_variable && v.second.is_affine_dependent + && name.compare(v.second.org_name) == 0) + v.second.is_disabled = false; } if (!act_size_to_be_done) resize_global_system(); } @@ -933,11 +918,10 @@ namespace getfem { for (size_type j = 0; j < bricks[ibb].mims.size(); ++j) if (bricks[ibb].mims[j] == mim) found = true; } - for (VAR_SET::iterator it2 = variables.begin(); - it2 != variables.end(); ++it2) { - if (it2->second.is_fem_dofs && - (it2->second.filter & VDESCRFILTER_INFSUP) && - mim == it2->second.mim) found = true; + for (const auto &v : variables) { + if (v.second.is_fem_dofs && + (v.second.filter & VDESCRFILTER_INFSUP) && + mim == v.second.mim) found = true; } if (!found) sup_dependency(*mim); } @@ -948,18 +932,17 @@ namespace getfem { is_symmetric_ = is_symmetric_ && bricks[ibb].pbr->is_symmetric(); is_coercive_ = is_coercive_ && bricks[ibb].pbr->is_coercive(); } - bricks[ib] = brick_description(); } void model::delete_variable(const std::string &varname) { for (dal::bv_visitor ibb(valid_bricks); !ibb.finished(); ++ibb) { - for (size_type i = 0; i < bricks[ibb].vlist.size(); ++i) - GMM_ASSERT1(varname.compare(bricks[ibb].vlist[i]), - "Cannot delete a variable which is still use by a brick"); - for (size_type i = 0; i < bricks[ibb].dlist.size(); ++i) - GMM_ASSERT1(varname.compare(bricks[ibb].dlist[i]), - "Cannot delete a data which is still use by a brick"); + for (const auto &vname : bricks[ibb].vlist) + GMM_ASSERT1(varname.compare(vname), + "Cannot delete a variable which is still used by a brick"); + for (const auto &dname : bricks[ibb].dlist) + GMM_ASSERT1(varname.compare(dname), + "Cannot delete a data which is still used by a brick"); } VAR_SET::const_iterator it = find_variable(varname); @@ -1124,13 +1107,15 @@ namespace getfem { void model::call_init_affine_dependent_variables(int version) { for (VAR_SET::iterator it = variables.begin(); - it != variables.end(); ++it) - if (it->second.is_variable && it->second.ptsc) { + it != variables.end(); ++it) { + var_description &vdescr = it->second; + if (vdescr.is_variable && vdescr.ptsc) { if (version == 2) - it->second.ptsc->init_affine_dependent_variables_precomputation(*this); + vdescr.ptsc->init_affine_dependent_variables_precomputation(*this); else - it->second.ptsc->init_affine_dependent_variables(*this); + vdescr.ptsc->init_affine_dependent_variables(*this); } + } } void model::shift_variables_for_time_integration() {