changeset 44:fca8c3d75036

register_type is called before every type is used. * A new static variable for every class has been defined. It is named class_type_loaded, and it specify if the corresponding type have yet been loaded or not. If not, it proceed with the registration. This should be only a temporary solution.
author gedeone-octave <marco.vassallo@outlook.com>
date Mon, 22 Jul 2013 11:33:50 +0200
parents de8427de316e
children a965f4a3c8d8
files src/boundarycondition.h src/coefficient.h src/fem_bc.cc src/fem_coeff.cc src/fem_fs.cc src/fem_get_mesh.cc src/fem_init_env.cc src/fem_init_mesh.cc src/fem_lhs.cc src/fem_rhs.cc src/functionspace.h src/mesh.h
diffstat 12 files changed, 134 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/boundarycondition.h	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/boundarycondition.h	Mon Jul 22 11:33:50 2013 +0200
@@ -63,4 +63,5 @@
 
 };
 
+  static bool boundarycondition_type_loaded = false;
 #endif
--- a/src/coefficient.h	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/coefficient.h	Mon Jul 22 11:33:50 2013 +0200
@@ -53,5 +53,5 @@
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
 
 };
-
+  static bool coefficient_type_loaded = false;
 #endif
--- a/src/fem_bc.cc	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/fem_bc.cc	Mon Jul 22 11:33:50 2013 +0200
@@ -42,6 +42,14 @@
     print_usage ();
   else
     {
+
+      if (! functionspace_type_loaded)
+        {
+          functionspace::register_type ();
+          functionspace_type_loaded = true;
+          mlock ();
+        }
+
       if (args(0).type_id () == functionspace::static_type_id ())
         {
           const functionspace & fspo = static_cast<const functionspace&> (args(0).get_rep ());
@@ -53,14 +61,18 @@
               const boost::shared_ptr <const dolfin::FunctionSpace> & V (fspo.get_pfsp ());
               const expression * pf = new expression (*fh);
               boost::shared_ptr<const expression> f (pf);
+
+              if (! boundarycondition_type_loaded)
+                {
+                  boundarycondition::register_type ();
+                  boundarycondition_type_loaded = true;
+                  mlock ();
+                }
+
               boundarycondition * pbc = new boundarycondition ();
 
               for (octave_idx_type i = 0; i < side.length (); ++i)
-                {
-//                  dolfin::DirichletBC my_bc (V, f, side(i));
-//                  pbc->add_bc (my_bc);
                   pbc->add_bc (V, f, side(i));
-                }
 
               retval = octave_value (pbc);
             }
--- a/src/fem_coeff.cc	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/fem_coeff.cc	Mon Jul 22 11:33:50 2013 +0200
@@ -39,6 +39,13 @@
       std::string str = args(0).string_value ();
       octave_fcn_handle * fh = args(1).fcn_handle_value ();
 
+      if (! coefficient_type_loaded)
+        {
+          coefficient::register_type ();
+          coefficient_type_loaded = true;
+          mlock ();
+        }
+
       if (!error_state)
         retval = new coefficient (str, *fh);
 
--- a/src/fem_fs.cc	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/fem_fs.cc	Mon Jul 22 11:33:50 2013 +0200
@@ -29,11 +29,27 @@
     print_usage ();
   else
     {
+
+      if (! mesh_type_loaded)
+        {
+          mesh::register_type ();
+          mesh_type_loaded = true;
+          mlock ();
+        }
+
       if (args(0).type_id () == mesh::static_type_id ())
         {
           const mesh & msho = static_cast<const mesh&> (args(0).get_rep ());
           const dolfin::Mesh & mshd = msho.get_msh ();
           boost::shared_ptr <const dolfin::FunctionSpace> g (new Laplace::FunctionSpace (mshd));
+
+          if (! functionspace_type_loaded)
+            {
+              functionspace::register_type ();
+              functionspace_type_loaded = true;
+              mlock ();
+            }
+
           retval = new functionspace(g);
         }
     }
--- a/src/fem_get_mesh.cc	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/fem_get_mesh.cc	Mon Jul 22 11:33:50 2013 +0200
@@ -35,6 +35,14 @@
     print_usage ();
   else
     {
+
+      if (! mesh_type_loaded)
+        {
+          mesh::register_type ();
+          mesh_type_loaded = true;
+          mlock ();
+        }
+
       if (args(0).type_id () == mesh::static_type_id ())
         {
           const mesh & msh = static_cast<const mesh&> (args(0).get_rep ());
--- a/src/fem_init_env.cc	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/fem_init_env.cc	Mon Jul 22 11:33:50 2013 +0200
@@ -46,15 +46,19 @@
     print_usage ();
   else
     {
-       mesh::register_type ();
-       std::cout << "mesh_type_loaded" << std::endl;
-       functionspace::register_type ();
-       std::cout << "functionspace_type_loaded" << std::endl;
-       boundarycondition::register_type ();
-       std::cout << "boundarycondition_type_loaded" << std::endl;
-       coefficient::register_type ();
-       std::cout << "coefficient_type_loaded" << std::endl;
-       mlock ();
+      mesh::register_type ();
+      mesh_type_loaded = true;
+      std::cout << "mesh_type_loaded" << std::endl;
+      functionspace::register_type ();
+      functionspace_type_loaded = true;
+      std::cout << "functionspace_type_loaded" << std::endl;
+      boundarycondition::register_type ();
+      boundarycondition_type_loaded = true;
+      std::cout << "boundarycondition_type_loaded" << std::endl;
+      coefficient::register_type ();
+      coefficient_type_loaded = true;
+      std::cout << "coefficient_type_loaded" << std::endl;
+      mlock ();
     }
   return retval;
 }
--- a/src/fem_init_mesh.cc	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/fem_init_mesh.cc	Mon Jul 22 11:33:50 2013 +0200
@@ -45,23 +45,37 @@
             {
               std::string filename = args(0).string_value ();
               //if the filename is not valid, dolfin takes care of it
+
+              if (! mesh_type_loaded)
+                {
+                  mesh::register_type ();
+                  mesh_type_loaded = true;
+                  mlock ();
+                }
               retval = new mesh (filename);
             }
 
-           else
-             {
-               octave_scalar_map a = args(0).scalar_map_value ();
-               Array<double> p = a.contents ("p").matrix_value ();
-               Array<octave_idx_type> t = a.contents ("t").matrix_value ();
-               Array<octave_idx_type> e = a.contents ("e").matrix_value ();
+          else
+            {
+              octave_scalar_map a = args(0).scalar_map_value ();
+              Array<double> p = a.contents ("p").matrix_value ();
+              Array<octave_idx_type> t = a.contents ("t").matrix_value ();
+              Array<octave_idx_type> e = a.contents ("e").matrix_value ();
 
-               if (! error_state)
-                 {
-                   retval = new mesh (p, e, t);
-                 }
-               else
-                 error ("fem_init_mesh: the argument you provide is invalid");
-             }
+              if (! error_state)
+                {
+                  if (! mesh_type_loaded)
+                    {
+                      mesh::register_type ();
+                      mesh_type_loaded = true;
+                      mlock ();
+                    }
+
+                  retval = new mesh (p, e, t);
+                }
+              else
+               error ("fem_init_mesh: the argument you provide is invalid");
+            }
         }
     }
   return retval;
--- a/src/fem_lhs.cc	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/fem_lhs.cc	Mon Jul 22 11:33:50 2013 +0200
@@ -45,6 +45,13 @@
     print_usage ();
   else
     {
+
+      if (! functionspace_type_loaded)
+        {
+          functionspace::register_type ();
+          functionspace_type_loaded = true;
+          mlock ();
+        }
       if (args(0).type_id () == functionspace::static_type_id ())
         {
           const functionspace & fspo
@@ -56,7 +63,13 @@
               Laplace::LinearForm L (V);
               std::size_t ncoef = L.num_coefficients (), nc = 0;
 
-              for (std::size_t i = 1; i < ncoef + 1; ++i)
+              if (! coefficient_type_loaded)
+                {
+                  coefficient::register_type ();
+                  coefficient_type_loaded = true;
+                  mlock ();
+                }
+              for (std::size_t i = 1; i < nargin; ++i)
                 {
                   if (args(i).type_id () == coefficient::static_type_id ())
                     {
@@ -78,7 +91,13 @@
                   dolfin::Vector b;
                   dolfin::assemble (b, L);
 
-                  for (std::size_t i = 1 + nc; i < nargin; ++i)
+                  if (! boundarycondition_type_loaded)
+                    {
+                      boundarycondition::register_type ();
+                      boundarycondition_type_loaded = true;
+                      mlock ();
+                    }
+                  for (std::size_t i = 1; i < nargin; ++i)
                     {
                       if (args(i).type_id () == boundarycondition::static_type_id ())
                         {
--- a/src/fem_rhs.cc	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/fem_rhs.cc	Mon Jul 22 11:33:50 2013 +0200
@@ -45,6 +45,12 @@
     print_usage ();
   else
     {
+      if (! functionspace_type_loaded)
+        {
+          functionspace::register_type ();
+          functionspace_type_loaded = true;
+          mlock ();
+        }
       if (args(0).type_id () == functionspace::static_type_id ())
         {
           const functionspace & fspo
@@ -56,7 +62,14 @@
               Laplace::BilinearForm a (V, V);
               std::size_t ncoef = a.num_coefficients (), nc = 0;
 
-              for (std::size_t i = 1; i < ncoef + 1; ++i)
+              if (! coefficient_type_loaded)
+                {
+                  coefficient::register_type ();
+                  coefficient_type_loaded = true;
+                  mlock ();
+                }
+
+              for (std::size_t i = 1; i < nargin; ++i)
                 {
                   if (args(i).type_id () == coefficient::static_type_id ())
                     {
@@ -78,7 +91,14 @@
                   dolfin::Matrix A;
                   dolfin::assemble (A, a);
 
-                  for (std::size_t i = 1 + nc; i < nargin; ++i)
+                  if (! boundarycondition_type_loaded)
+                    {
+                      boundarycondition::register_type ();
+                      boundarycondition_type_loaded = true;
+                      mlock ();
+                    }
+
+                  for (std::size_t i = 1; i < nargin; ++i)
                     {
                       if (args(i).type_id () == boundarycondition::static_type_id ())
                         {
--- a/src/functionspace.h	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/functionspace.h	Mon Jul 22 11:33:50 2013 +0200
@@ -60,4 +60,5 @@
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
 
 };
+  static bool functionspace_type_loaded = false;
 #endif
--- a/src/mesh.h	Sat Jul 20 23:53:31 2013 +0200
+++ b/src/mesh.h	Mon Jul 22 11:33:50 2013 +0200
@@ -61,5 +61,5 @@
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
 
 };
-
+  static bool mesh_type_loaded = false;
 #endif