This is an automated email from the git hooks/post-receive script. logari81 pushed a commit to branch master in repository getfem.
The following commit(s) were added to refs/heads/master by this push: new 7afd1f5 Clean variable inheritance model for ga_workspace 7afd1f5 is described below commit 7afd1f596b1e290d98c8f3de498c13835faece24 Author: Konstantinos Poulios <logar...@gmail.com> AuthorDate: Thu Jan 2 18:43:14 2020 +0100 Clean variable inheritance model for ga_workspace - Now it is possible to create a ga_workspace linked to a model or another workspace without inheriting its variables at all ga_workspace::inherit::NONE - Temporary enabling disabled variables of the parent model is now done with ga_workspace::inherit::ALL instead of ga_workspace::inherit::ENABLED --- src/getfem/getfem_generic_assembly.h | 9 ++++-- src/getfem_contact_and_friction_integral.cc | 2 +- ...fem_generic_assembly_functions_and_operators.cc | 3 +- src/getfem_generic_assembly_interpolation.cc | 4 +-- src/getfem_generic_assembly_workspace.cc | 32 ++++++++++++------- src/getfem_models.cc | 37 ++++++++++++---------- 6 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/getfem/getfem_generic_assembly.h b/src/getfem/getfem_generic_assembly.h index f3bd9a7..453e34e 100644 --- a/src/getfem/getfem_generic_assembly.h +++ b/src/getfem/getfem_generic_assembly.h @@ -264,6 +264,7 @@ namespace getfem { const model *md; const ga_workspace *parent_workspace; + bool with_parent_variables; size_type nb_prim_dof, nb_tmp_dof; void init(); @@ -566,8 +567,12 @@ namespace getfem { return (it != tmp_var_intervals.end()) ? it->second : empty_interval; } - ga_workspace(const getfem::model &md_, bool enable_disabled_variables=false); - ga_workspace(bool, const ga_workspace &gaw); + enum class inherit { NONE, ENABLED, ALL }; + + ga_workspace(const getfem::model &md_, + const inherit var_inherit=inherit::ENABLED); + ga_workspace(const ga_workspace &gaw, // compulsory 2nd arg to avoid + const inherit var_inherit); // conflict with copy constructor ga_workspace(); ~ga_workspace(); diff --git a/src/getfem_contact_and_friction_integral.cc b/src/getfem_contact_and_friction_integral.cc index 58d2f65..9d838e5 100644 --- a/src/getfem_contact_and_friction_integral.cc +++ b/src/getfem_contact_and_friction_integral.cc @@ -2551,7 +2551,7 @@ namespace getfem { size_type region) { std::string theta = std::to_string(theta_); - ga_workspace workspace(md, true); + ga_workspace workspace(md, ga_workspace::inherit::ALL); // reenables vars size_type order = workspace.add_expression(Neumannterm, mim, region, 1); GMM_ASSERT1(order == 0, "Wrong expression of the Neumann term"); // model::varnamelist vl, vl_test1, vl_test2, dl; diff --git a/src/getfem_generic_assembly_functions_and_operators.cc b/src/getfem_generic_assembly_functions_and_operators.cc index d0cf80e..7e5a00b 100644 --- a/src/getfem_generic_assembly_functions_and_operators.cc +++ b/src/getfem_generic_assembly_functions_and_operators.cc @@ -678,7 +678,8 @@ namespace getfem { ga_function::ga_function(const ga_workspace &workspace_, const std::string &e) - : local_workspace(true, workspace_), expr(e), gis(0) {} + : local_workspace(workspace_, ga_workspace::inherit::ALL), + expr(e), gis(0) {} ga_function::ga_function(const model &md, const std::string &e) : local_workspace(md), expr(e), gis(0) {} diff --git a/src/getfem_generic_assembly_interpolation.cc b/src/getfem_generic_assembly_interpolation.cc index 967f595..439dbd8 100644 --- a/src/getfem_generic_assembly_interpolation.cc +++ b/src/getfem_generic_assembly_interpolation.cc @@ -533,7 +533,7 @@ namespace getfem { used_vars.clear(); else used_data.clear(); - ga_workspace aux_workspace(true, workspace); + ga_workspace aux_workspace(workspace, ga_workspace::inherit::ALL); aux_workspace.clear_expressions(); aux_workspace.add_interpolation_expression(expr, source_mesh); for (size_type i = 0; i < aux_workspace.nb_trees(); ++i) @@ -556,7 +556,7 @@ namespace getfem { size_type N = target_mesh.dim(); // Expression compilation - local_workspace = ga_workspace(true, workspace); + local_workspace = ga_workspace(workspace, ga_workspace::inherit::ALL); local_workspace.clear_expressions(); local_workspace.add_interpolation_expression(expr, source_mesh); diff --git a/src/getfem_generic_assembly_workspace.cc b/src/getfem_generic_assembly_workspace.cc index 27583c2..6cd17db 100644 --- a/src/getfem_generic_assembly_workspace.cc +++ b/src/getfem_generic_assembly_workspace.cc @@ -198,9 +198,10 @@ namespace getfem { if (it != variables.end()) return it->second.I; const auto it2 = reenabled_var_intervals.find(name); if (it2 != reenabled_var_intervals.end()) return it2->second; - if (md && md->variable_exists(name)) + if (with_parent_variables && md && md->variable_exists(name)) return md->interval_of_variable(name); - else if (parent_workspace && parent_workspace->variable_exists(name)) + else if (with_parent_variables && + parent_workspace && parent_workspace->variable_exists(name)) return parent_workspace->interval_of_variable(name); GMM_ASSERT1(false, "Undefined variable " << name); } @@ -933,14 +934,15 @@ namespace getfem { { if (ptree) delete ptree; ptree = 0; } ga_workspace::ga_workspace(const getfem::model &md_, - bool enable_disabled_variables) + const inherit var_inherit) : md(&md_), parent_workspace(0), - nb_prim_dof(0), nb_tmp_dof(0), - macro_dict(md_.macro_dictionary()) + with_parent_variables(var_inherit == inherit::ENABLED || + var_inherit == inherit::ALL), + nb_tmp_dof(0), macro_dict(md_.macro_dictionary()) { init(); - nb_prim_dof = md->nb_dof(); - if (enable_disabled_variables) { + nb_prim_dof = with_parent_variables ? md->nb_dof() : 0; + if (var_inherit == inherit::ALL) { // enable model's disabled variables model::varnamelist vlmd; md->variable_list(vlmd); for (const auto &varname : vlmd) @@ -964,13 +966,19 @@ namespace getfem { } } } - ga_workspace::ga_workspace(bool, const ga_workspace &gaw) + ga_workspace::ga_workspace(const ga_workspace &gaw, + const inherit var_inherit) : md(0), parent_workspace(&gaw), - nb_prim_dof(gaw.nb_primary_dof()), nb_tmp_dof(0), - macro_dict(gaw.macro_dictionary()) - { init(); } + with_parent_variables(var_inherit == inherit::ENABLED || + var_inherit == inherit::ALL), + nb_tmp_dof(0), macro_dict(gaw.macro_dictionary()) + { + init(); + nb_prim_dof = with_parent_variables ? gaw.nb_primary_dof() : 0; + } ga_workspace::ga_workspace() - : md(0), parent_workspace(0), nb_prim_dof(0), nb_tmp_dof(0) + : md(0), parent_workspace(0), with_parent_variables(false), + nb_prim_dof(0), nb_tmp_dof(0) { init(); } ga_workspace::~ga_workspace() { clear_expressions(); } diff --git a/src/getfem_models.cc b/src/getfem_models.cc index 03b9896..725094b 100644 --- a/src/getfem_models.cc +++ b/src/getfem_models.cc @@ -3196,7 +3196,8 @@ namespace getfem { gmm::clear(vecl[0]); if (expr.size()) { - ga_workspace workspace(md, true); + // reenables disabled variables + ga_workspace workspace(md, ga_workspace::inherit::ALL); GMM_TRACE2(name << ": generic source term assembly"); workspace.add_expression(expr, *(mims[0]), region, 1, secondary_domain); workspace.assembly(1); @@ -3351,7 +3352,8 @@ namespace getfem { md.is_var_newer_than_brick(dl[i], ib); if (recompute_matrix) { - ga_workspace workspace(md, true); + // reenables disabled variables + ga_workspace workspace(md, ga_workspace::inherit::ALL); workspace.add_expression(expr, *(mims[0]), region, 2, secondary_domain); GMM_TRACE2(name << ": generic matrix assembly"); workspace.assembly(2); @@ -3422,8 +3424,8 @@ namespace getfem { (model &md, const mesh_im &mim, const std::string &expr, size_type region, bool is_sym, bool is_coercive, const std::string &brickname, bool return_if_nonlin, const std::string &secondary_domain) { - - ga_workspace workspace(md, true); + // reenables disabled variables + ga_workspace workspace(md, ga_workspace::inherit::ALL); size_type order = workspace.add_expression(expr, mim, region, 2, secondary_domain); model::varnamelist vl, vl_test1, vl_test2, dl; @@ -4919,9 +4921,9 @@ namespace getfem { const std::string &Neumannterm, const std::string &datagamma0, size_type region, scalar_type theta_, const std::string &datag) { - std::string theta = std::to_string(theta_); - ga_workspace workspace(md, true); + // reenables disabled variables + ga_workspace workspace(md, ga_workspace::inherit::ALL); size_type order = workspace.add_expression(Neumannterm, mim, region, 1); GMM_ASSERT1(order == 0, "Wrong expression of the Neumann term"); bool is_lin = workspace.is_linear(1); @@ -4954,8 +4956,8 @@ namespace getfem { const std::string &datagamma0, size_type region, scalar_type theta_, const std::string &datag) { std::string theta = std::to_string(theta_); - - ga_workspace workspace(md, true); + // reenables disabled variables + ga_workspace workspace(md, ga_workspace::inherit::ALL); size_type order = workspace.add_expression(Neumannterm, mim, region, 1); GMM_ASSERT1(order == 0, "Wrong expression of the Neumann term"); bool is_lin = workspace.is_linear(1); @@ -4987,8 +4989,8 @@ namespace getfem { const std::string &datagamma0, size_type region, scalar_type theta_, const std::string &datag, const std::string &dataH) { std::string theta = std::to_string(theta_); - - ga_workspace workspace(md, true); + // reenables disabled variables + ga_workspace workspace(md, ga_workspace::inherit::ALL); size_type order = workspace.add_expression(Neumannterm, mim, region, 1); GMM_ASSERT1(order == 0, "Wrong expression of the Neumann term"); bool is_lin = workspace.is_linear(1); @@ -5925,7 +5927,8 @@ namespace getfem { } if (recompute_matrix) { - ga_workspace workspace(md, true); + // reenables disabled variables + ga_workspace workspace(md, ga_workspace::inherit::ALL); workspace.add_expression(expr, *(mims[0]), region); GMM_TRACE2(name << ": generic matrix assembly"); workspace.assembly(2); @@ -5994,8 +5997,8 @@ namespace getfem { bool is_lin; model::varnamelist vl, dl; - { - ga_workspace workspace(md, true); + { // reenables disabled variables + ga_workspace workspace(md, ga_workspace::inherit::ALL); workspace.add_expression(expr2, mim, region); model::varnamelist vl_test1, vl_test2; is_lin = workspace.used_variables(vl, vl_test1, vl_test2, dl, 2); @@ -6029,8 +6032,8 @@ namespace getfem { + "+"+mu+"*(Grad_"+varname+"+Grad_"+varname+"'):Grad_"+test_varname; bool is_lin; - { - ga_workspace workspace(md, true); + { // reenables disabled variables + ga_workspace workspace(md, ga_workspace::inherit::ALL); workspace.add_expression(expr, mim, region); is_lin = workspace.is_linear(2); } @@ -6064,8 +6067,8 @@ namespace getfem { + "+"+mu+"*(Grad_"+varname+"+Grad_"+varname+"'):Grad_"+test_varname; bool is_lin; - { - ga_workspace workspace(md, true); + { // reenables disabled variables + ga_workspace workspace(md, ga_workspace::inherit::ALL); workspace.add_expression(expr, mim, region); is_lin = workspace.is_linear(2); }