getfem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getfem-commits] (no subject)


From: Konstantinos Poulios
Subject: [Getfem-commits] (no subject)
Date: Thu, 2 Jan 2020 12:43:22 -0500 (EST)

branch: devel-logari81-internal-variables
commit 79df5e1c2c7b53417298e9d2041d6d414cc049d5
Author: Konstantinos Poulios <address@hidden>
Date:   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 3f47eaa..ddd7266 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 610921d..771105c 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 330d1db..7b8ede8 100644
--- a/src/getfem_generic_assembly_workspace.cc
+++ b/src/getfem_generic_assembly_workspace.cc
@@ -171,9 +171,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);
   }
@@ -904,14 +905,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)
@@ -935,13 +937,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 d782fd3..b0554a8 100644
--- a/src/getfem_models.cc
+++ b/src/getfem_models.cc
@@ -3168,7 +3168,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);
@@ -3323,7 +3324,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);
@@ -3394,8 +3396,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;
@@ -4891,9 +4893,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);
@@ -4926,8 +4928,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);
@@ -4959,8 +4961,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);
@@ -5897,7 +5899,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);
@@ -5966,8 +5969,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);
@@ -6001,8 +6004,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);
     }
@@ -6036,8 +6039,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);
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]