getfem-commits
[Top][All Lists]
Advanced

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

[Getfem-commits] r4981 - in /trunk/getfem/src: ./ getfem/


From: Yves . Renard
Subject: [Getfem-commits] r4981 - in /trunk/getfem/src: ./ getfem/
Date: Thu, 30 Apr 2015 07:50:29 -0000

Author: renard
Date: Thu Apr 30 09:50:28 2015
New Revision: 4981

URL: http://svn.gna.org/viewcvs/getfem?rev=4981&view=rev
Log:
tensor dimensions for fem data and fixed size variables of a model

Modified:
    trunk/getfem/src/getfem/getfem_generic_assembly.h
    trunk/getfem/src/getfem/getfem_models.h
    trunk/getfem/src/getfem_generic_assembly.cc
    trunk/getfem/src/getfem_models.cc

Modified: trunk/getfem/src/getfem/getfem_generic_assembly.h
URL: 
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem/getfem_generic_assembly.h?rev=4981&r1=4980&r2=4981&view=diff
==============================================================================
--- trunk/getfem/src/getfem/getfem_generic_assembly.h   (original)
+++ trunk/getfem/src/getfem/getfem_generic_assembly.h   Thu Apr 30 09:50:28 2015
@@ -130,16 +130,27 @@
       gmm::sub_interval I;
       const model_real_plain_vector *V;
       const im_data *imd;
-
-      var_description(bool is_var,
-                      bool is_fem, 
-                      const mesh_fem *mmf,
-                      gmm::sub_interval I_,
-                      const model_real_plain_vector *v, const im_data *imd_)
+      bgeot::multi_index qdims;  // For data having a qdim != of the fem
+                                 // (dim per dof for dof data)
+                                 // and for constant variables.
+
+      size_type qdim(void) const {
+        size_type q = 1;
+        for (size_type i = 0; i < qdims.size(); ++i) q *= qdims[i];
+        return q;
+      }
+
+      var_description(bool is_var, bool is_fem, 
+                      const mesh_fem *mmf, gmm::sub_interval I_,
+                      const model_real_plain_vector *v, const im_data *imd_,
+                      size_type Q)
         : is_variable(is_var), is_fem_dofs(is_fem), mf(mmf), I(I_), V(v),
-          imd(imd_) {}
+          imd(imd_), qdims(1) { 
+        GMM_ASSERT1(Q > 0, "Bad dimension");
+        qdims[0] = Q;
+      }
       var_description() : is_variable(false), is_fem_dofs(false),
-                          mf(0), V(0), imd(0) {}
+                          mf(0), V(0), imd(0), qdims(1) { qdims[0] = 1; }
     };
 
   public:
@@ -300,29 +311,34 @@
     void add_fem_variable(const std::string &name, const mesh_fem &mf,
                           const gmm::sub_interval &I,
                           const model_real_plain_vector &VV)
-    { variables[name] = var_description(true, true, &mf, I, &VV, 0); }
+    { variables[name] = var_description(true, true, &mf, I, &VV, 0, 1); }
     
     void add_fixed_size_variable(const std::string &name,
                                  const gmm::sub_interval &I,
-                                 const model_real_plain_vector &VV)
-    { variables[name] = var_description(true, false, 0, I, &VV, 0); }
+                                 const model_real_plain_vector &VV) {
+      variables[name] = var_description(true, false, 0, I, &VV, 0,
+                                        dim_type(gmm::vect_size(VV)));
+    }
 
     void add_fem_constant(const std::string &name, const mesh_fem &mf,
                           const model_real_plain_vector &VV) { 
       variables[name] = var_description(false, true, &mf,
-                                        gmm::sub_interval(), &VV, 0);
+                                        gmm::sub_interval(), &VV, 0,
+                                        gmm::vect_size(VV)/(mf.nb_dof()));
     }
     
     void add_fixed_size_constant(const std::string &name,
                                  const model_real_plain_vector &VV) {
       variables[name] = var_description(false, false, 0,
-                                        gmm::sub_interval(), &VV, 0);
+                                        gmm::sub_interval(), &VV, 0,
+                                        gmm::vect_size(VV));
     }
 
     void add_im_data(const std::string &name, const im_data &imd,
                      const model_real_plain_vector &VV) {
-      variables[name] = var_description(false, false, 0,
-                                        gmm::sub_interval(), &VV, &imd);
+      variables[name] = var_description
+        (false, false, 0, gmm::sub_interval(), &VV, &imd,
+         gmm::vect_size(VV)/(imd.nb_filtered_index() * imd.nb_tensor_elem()));
     }
 
     std::string extract_constant_term(const mesh &m);
@@ -543,33 +559,7 @@
       return n;
     }
 
-    bgeot::multi_index qdims(const std::string &name) const {
-      const mesh_fem *mf = associated_mf(name);
-      const im_data *imd = associated_im_data(name);
-      size_type n = gmm::vect_size(value(name));
-      if (mf) {
-        size_type ndof = mf->nb_dof();
-        GMM_ASSERT1(ndof, "Variable " << name << " with no dof. You probably "
-                    "made a wrong initialization of a mesh_fem object");
-        bgeot::multi_index mi = mf->get_qdims();
-        size_type qmult = n / ndof;
-        if (qmult > 1) {
-          if (mi.back() == 1) mi.back() *= qmult; else mi.push_back(qmult);
-        }
-        return mi;
-      } else if (imd) {
-        bgeot::multi_index mi = imd->tensor_size();
-        size_type q = n / imd->nb_filtered_index();
-        GMM_ASSERT1(q % imd->nb_tensor_elem() == 0,
-                    "Invalid mesh im data vector");
-        size_type qmult = q / imd->nb_tensor_elem();
-        if (qmult > 1) {
-          if (mi.back() == 1) mi.back() *= qmult; else mi.push_back(qmult);
-        }
-        return mi;
-      }
-      bgeot::multi_index mi(1); mi[0] = n; return mi;
-    }
+    bgeot::multi_index qdims(const std::string &name) const;
 
     const model_real_plain_vector &value(const std::string &name) const {
       VAR_SET::const_iterator it = variables.find(name);

Modified: trunk/getfem/src/getfem/getfem_models.h
URL: 
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem/getfem_models.h?rev=4981&r1=4980&r2=4981&view=diff
==============================================================================
--- trunk/getfem/src/getfem/getfem_models.h     (original)
+++ trunk/getfem/src/getfem/getfem_models.h     Thu Apr 30 09:50:28 2015
@@ -105,11 +105,6 @@
   typedef std::vector<scalar_type> model_real_plain_vector;
   typedef std::vector<complex_type> model_complex_plain_vector;
 
-  // utiliser le même type que l'interface matlab/python pour représenter
-  // les vecteurs/matrices ?
-  // Cela faciliterait les échanges et réduirait les composantes de la
-  // classe model.
-
   typedef gmm::col_matrix<model_real_sparse_vector> model_real_sparse_matrix;
   typedef gmm::col_matrix<model_complex_sparse_vector>
   model_complex_sparse_matrix;
@@ -119,7 +114,7 @@
   typedef gmm::row_matrix<model_complex_sparse_vector>
   model_complex_row_sparse_matrix;
   
-  // For backward compatibility
+  // For backward compatibility with version 3.0
   typedef model_real_plain_vector modeling_standard_plain_vector;
   typedef model_real_sparse_vector modeling_standard_sparse_vector;
   typedef model_real_sparse_matrix modeling_standard_sparse_matrix;
@@ -179,8 +174,8 @@
       bool is_variable;  // This is a variable or a parameter.
       bool is_disabled;  // For a variable, to be solved or not
       bool is_complex;   // The variable is complex numbers
-      bool is_affine_dependent;   // The variable depends in an affine way to 
another
-                                  // variable. 
+      bool is_affine_dependent;   // The variable depends in an affine way 
+                                  // to another variable. 
       bool is_fem_dofs;  // The variable is the dofs of a fem
       var_description_filter filter; // A filter on the dofs is applied or not.
       size_type n_iter; //  Number of versions of the variable stored for time
@@ -197,14 +192,14 @@
       ppartial_mesh_fem partial_mf; // Filter with respect to mf.
       std::string filter_var;       // Optional variable name for the filter
 
-      dim_type qdim;  // A data could have a qdim != of the fem.
-      // dim per dof for dof data.
+      bgeot::multi_index qdims;  // For data having a qdim != of the fem
+                                 // (dim per dof for dof data)
+                                 // and for constant variables.
       gmm::uint64_type v_num, v_num_data;
 
       gmm::sub_interval I; // For a variable : indices on the whole system.
       // For an affine dependent variable, should be the same than the 
orgininal
       // variable
-
       std::vector<model_real_plain_vector> real_value;
       std::vector<model_complex_plain_vector> complex_value;
       std::vector<gmm::uint64_type> v_num_var_iter;
@@ -214,28 +209,36 @@
       model_real_plain_vector affine_real_value;
       model_complex_plain_vector affine_complex_value;
       scalar_type alpha;    // Factor for the affine dependent variables
-      std::string org_name; // Name of the original variable for affine 
dependent
-                            // variables
+      std::string org_name; // Name of the original variable for affine
+                            //  dependent variables
 
       // im data description
       const im_data *pim_data;
+
+      size_type qdim(void) const {
+        size_type q = 1;
+        for (size_type i = 0; i < qdims.size(); ++i) q *= qdims[i];
+        return q;
+      }
 
       var_description(bool is_var = false, bool is_com = false,
                       bool is_fem = false, size_type n_it = 1,
                       var_description_filter fil = VDESCRFILTER_NO,
                       const mesh_fem *mmf = 0,
-                      size_type m_reg = size_type(-1), dim_type Q = 1,
+                      size_type m_reg = size_type(-1), size_type Q = 1,
                       const std::string &filter_v = std::string(""),
                       const mesh_im *mim_ = 0, const im_data *pimd = 0)
         : is_variable(is_var), is_disabled(false), is_complex(is_com),
           is_affine_dependent(false), is_fem_dofs(is_fem), filter(fil),
           n_iter(std::max(size_type(1), n_it)), n_temp_iter(0),
           default_iter(0), ptsc(0), mf(mmf), m_region(m_reg), mim(mim_),
-          filter_var(filter_v), qdim(Q), v_num(0), v_num_data(act_counter()),
+          filter_var(filter_v), qdims(1), v_num(0), v_num_data(act_counter()),
           alpha(1), pim_data(pimd) {
         if (filter != VDESCRFILTER_NO && mf != 0)
           partial_mf = new partial_mesh_fem(*mf);
-        // v_num_data = v_num;
+        // v_num_data = v_num; 
+        GMM_ASSERT1(Q > 0, "Bad dimension");
+        qdims[0] = Q;
       }
 
       // add a temporary version for time integration schemes. Automatically
@@ -794,7 +797,7 @@
     void add_fem_variable(const std::string &name, const mesh_fem &mf,
                           size_type niter = 1);
 
-    /**Add a data that is described by integration points.*/
+    /** Add a data that is described by integration points.*/
     void add_im_data(const std::string &name, const im_data &im_data, 
size_type niter = 1);
 
     /** Adds a variable linked to a fem with the dof filtered with respect
@@ -884,6 +887,8 @@
     /** Gives a pointer to the mesh_fem of a variable if any. 0 otherwise.*/
     const mesh_fem *pmesh_fem_of_variable(const std::string &name) const;
 
+    
+    bgeot::multi_index qdims_of_variable(const std::string &name) const;
 
     /** Gives the access to the tangent matrix. For the real version. */
     const model_real_sparse_matrix &real_tangent_matrix(void) const {

Modified: trunk/getfem/src/getfem_generic_assembly.cc
URL: 
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem_generic_assembly.cc?rev=4981&r1=4980&r2=4981&view=diff
==============================================================================
--- trunk/getfem/src/getfem_generic_assembly.cc (original)
+++ trunk/getfem/src/getfem_generic_assembly.cc Thu Apr 30 09:50:28 2015
@@ -4446,6 +4446,48 @@
     return lmr.back();
   }
 
+  bgeot::multi_index ga_workspace::qdims(const std::string &name) const {
+      VAR_SET::const_iterator it = variables.find(name);
+      if (it != variables.end()) {
+        const mesh_fem *mf =  it->second.is_fem_dofs ? it->second.mf : 0;
+        const im_data *imd = it->second.imd;
+        size_type n = it->second.qdim();
+        if (mf) {
+          size_type ndof = mf->nb_dof();
+          GMM_ASSERT1(ndof, "Variable " << name << " with no dof. You probably 
"
+                      "made a wrong initialization of a mesh_fem object");
+          bgeot::multi_index mi = mf->get_qdims();
+          if (n > 1 || it->second.qdims.size() > 1) {
+            size_type i = 0;
+            if (mi.back() == 1) { mi.back() *= it->second.qdims[0]; ++i; }
+            for (; i < it->second.qdims.size(); ++i)
+              mi.push_back(it->second.qdims[i]);
+          }
+          return mi;
+        } else if (imd) {
+          bgeot::multi_index mi = imd->tensor_size();
+          size_type q = n / imd->nb_filtered_index();
+          GMM_ASSERT1(q % imd->nb_tensor_elem() == 0,
+                      "Invalid mesh im data vector");
+          if (n > 1 || it->second.qdims.size() > 1) {
+            size_type i = 0;
+            if (mi.back() == 1) { mi.back() *= it->second.qdims[0]; ++i; }
+            for (; i < it->second.qdims.size(); ++i)
+              mi.push_back(it->second.qdims[i]);
+          }
+          return mi;
+        }
+        return it->second.qdims;
+      }
+      if (md && md->variable_exists(name))
+        return md->qdims_of_variable(name);
+      if (parent_workspace && parent_workspace->variable_exists(name))
+        return parent_workspace->qdims(name);
+      if (variable_group_exists(name))
+        return qdims(first_variable_of_group(name));
+      GMM_ASSERT1(false, "Undefined variable or group " << name);
+    }
+
 
   typedef std::pair<std::string, std::string> var_trans_pair;
 

Modified: trunk/getfem/src/getfem_models.cc
URL: 
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem_models.cc?rev=4981&r1=4980&r2=4981&view=diff
==============================================================================
--- trunk/getfem/src/getfem_models.cc   (original)
+++ trunk/getfem/src/getfem_models.cc   Thu Apr 30 09:50:28 2015
@@ -255,7 +255,7 @@
         case VDESCRFILTER_NO:
           if (it->second.v_num < it->second.mf->version_number()) {
             size_type s = it->second.mf->nb_dof();
-            if (!it->second.is_variable) s *= it->second.qdim;
+            if (!it->second.is_variable) s *= it->second.qdim();
             it->second.set_size(s);
             it->second.v_num = act_counter();
           }
@@ -2600,6 +2600,40 @@
     return it->second.passociated_mf();
   }
 
+  bgeot::multi_index model::qdims_of_variable(const std::string &name) const {
+    VAR_SET::const_iterator it = variables.find(name);
+    GMM_ASSERT1(it!=variables.end(), "Undefined variable " << name);
+    const mesh_fem *mf = it->second.passociated_mf();
+    const im_data *imd = it->second.pim_data;
+    size_type n = it->second.qdim();
+    if (mf) {
+      size_type ndof = mf->nb_dof();
+      GMM_ASSERT1(ndof, "Variable " << name << " with no dof. You probably "
+                  "made a wrong initialization of a mesh_fem object");
+      bgeot::multi_index mi = mf->get_qdims();
+      if (n > 1 || it->second.qdims.size() > 1) {
+        size_type i = 0;
+        if (mi.back() == 1) { mi.back() *= it->second.qdims[0]; ++i; }
+        for (; i < it->second.qdims.size(); ++i)
+          mi.push_back(it->second.qdims[i]);
+      }
+      return mi;
+    } else if (imd) {
+      bgeot::multi_index mi = imd->tensor_size();
+      size_type q = n / imd->nb_filtered_index();
+      GMM_ASSERT1(q % imd->nb_tensor_elem() == 0,
+                  "Invalid mesh im data vector");
+      if (n > 1 || it->second.qdims.size() > 1) {
+        size_type i = 0;
+        if (mi.back() == 1) { mi.back() *= it->second.qdims[0]; ++i; }
+        for (; i < it->second.qdims.size(); ++i)
+          mi.push_back(it->second.qdims[i]);
+      }
+      return mi;
+    }
+    return it->second.qdims;
+  }
+  
   const model_real_plain_vector &
   model::real_variable(const std::string &name, size_type niter) const {
     GMM_ASSERT1(!complex_version, "This model is a complex one");
@@ -2610,7 +2644,7 @@
       if (it->second.filter != VDESCRFILTER_NO)
         actualize_sizes();
       else
-        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim);
+        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim());
     }
     if (niter == size_type(-1)) niter = it->second.default_iter;
     GMM_ASSERT1(it->second.n_iter + it->second.n_temp_iter > niter,
@@ -2629,7 +2663,7 @@
       if (it->second.filter != VDESCRFILTER_NO)
         actualize_sizes();
       else
-        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim);
+        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim());
     }
     if (niter == size_type(-1)) niter = it->second.default_iter;
     GMM_ASSERT1(it->second.n_iter + it->second.n_temp_iter  > niter,
@@ -2648,7 +2682,7 @@
       if (it->second.filter != VDESCRFILTER_NO)
         actualize_sizes();
       else
-        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim);
+        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim());
     }
     it->second.v_num_data = act_counter();
     if (niter == size_type(-1)) niter = it->second.default_iter;
@@ -2668,7 +2702,7 @@
       if (it->second.filter != VDESCRFILTER_NO)
         actualize_sizes();
       else
-        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim);
+        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim());
     }
     it->second.v_num_data = act_counter();
     if (niter == size_type(-1)) niter = it->second.default_iter;
@@ -2690,7 +2724,7 @@
       if (it->second.filter != VDESCRFILTER_NO)
         actualize_sizes();
       else
-        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim);
+        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim());
     }
     it->second.v_num_data = act_counter();
     return it->second.affine_real_value;
@@ -2706,7 +2740,7 @@
       if (it->second.filter != VDESCRFILTER_NO)
         actualize_sizes();
       else
-        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim);
+        it->second.set_size(it->second.mf->nb_dof()*it->second.qdim());
     }
     it->second.v_num_data = act_counter();
     return it->second.affine_complex_value;




reply via email to

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