]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use shared pointer to store Material class inside PointHistory.
authorJean-Paul Pelteret <jppelteret@gmail.com>
Wed, 17 Feb 2016 10:43:03 +0000 (12:43 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Wed, 17 Feb 2016 10:53:54 +0000 (12:53 +0200)
examples/step-44/step-44.cc

index a502a3f859a22e50462697c45c160a3bd5e48258..a9800e7770c2c16a7000f2a74f018c76f204eceb 100644 (file)
@@ -706,7 +706,6 @@ namespace Step44
   public:
     PointHistory()
       :
-      material(NULL),
       F_inv(StandardTensors<dim>::I),
       tau(SymmetricTensor<2, dim>()),
       d2Psi_vol_dJ2(0.0),
@@ -714,11 +713,10 @@ namespace Step44
       Jc(SymmetricTensor<4, dim>())
     {}
 
+    // That the material is stored in a smart pointer, we don't need to worry
+    // about its memory management
     virtual ~PointHistory()
-    {
-      delete material;
-      material = NULL;
-    }
+    {}
 
     // The first function is used to create a material object and to
     // initialize all tensors correctly: The second one updates the stored
@@ -727,8 +725,8 @@ namespace Step44
     // dilation $\widetilde{J}$ field values.
     void setup_lqp (const Parameters::AllParameters &parameters)
     {
-      material = new Material_Compressible_Neo_Hook_Three_Field<dim>(parameters.mu,
-          parameters.nu);
+      material.reset(new Material_Compressible_Neo_Hook_Three_Field<dim>(parameters.mu,
+          parameters.nu));
       update_values(Tensor<2, dim>(), 0.0, 1.0);
     }
 
@@ -819,7 +817,7 @@ namespace Step44
     // materials are used in different regions of the domain, as well as the
     // inverse of the deformation gradient...
   private:
-    Material_Compressible_Neo_Hook_Three_Field<dim> *material;
+    std_cxx11::shared_ptr< Material_Compressible_Neo_Hook_Three_Field<dim> > material;
 
     Tensor<2, dim> F_inv;
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.