From 4c5eb4c46460c2d2cac0f85b683adef2fc7ec9b8 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Tue, 25 Jul 2017 14:16:43 +0200
Subject: [PATCH] [PL] LIE/SD: Use getOrCreateMeshProperty.

---
 .../SmallDeformationProcess.cpp               | 108 +++++++-----------
 1 file changed, 43 insertions(+), 65 deletions(-)

diff --git a/ProcessLib/LIE/SmallDeformation/SmallDeformationProcess.cpp b/ProcessLib/LIE/SmallDeformation/SmallDeformationProcess.cpp
index f941b944508..89854b68d2f 100644
--- a/ProcessLib/LIE/SmallDeformation/SmallDeformationProcess.cpp
+++ b/ProcessLib/LIE/SmallDeformation/SmallDeformationProcess.cpp
@@ -263,111 +263,90 @@ void SmallDeformationProcess<DisplacementDim>::initializeConcreteProcess(
                 &SmallDeformationLocalAssemblerInterface::getIntPtEpsilonYZ));
     }
 
-    auto mesh_prop_sigma_xx = const_cast<MeshLib::Mesh&>(mesh)
-                                  .getProperties()
-                                  .template createNewPropertyVector<double>(
-                                      "stress_xx", MeshLib::MeshItemType::Cell);
+    auto mesh_prop_sigma_xx = MeshLib::getOrCreateMeshProperty<double>(
+        const_cast<MeshLib::Mesh&>(mesh), "stress_xx",
+        MeshLib::MeshItemType::Cell, 1);
     mesh_prop_sigma_xx->resize(mesh.getNumberOfElements());
     _process_data._mesh_prop_stress_xx = mesh_prop_sigma_xx;
 
-    auto mesh_prop_sigma_yy = const_cast<MeshLib::Mesh&>(mesh)
-                                  .getProperties()
-                                  .template createNewPropertyVector<double>(
-                                      "stress_yy", MeshLib::MeshItemType::Cell);
+    auto mesh_prop_sigma_yy = MeshLib::getOrCreateMeshProperty<double>(
+        const_cast<MeshLib::Mesh&>(mesh), "stress_yy",
+        MeshLib::MeshItemType::Cell, 1);
     mesh_prop_sigma_yy->resize(mesh.getNumberOfElements());
     _process_data._mesh_prop_stress_yy = mesh_prop_sigma_yy;
 
-    auto mesh_prop_sigma_zz = const_cast<MeshLib::Mesh&>(mesh)
-                                  .getProperties()
-                                  .template createNewPropertyVector<double>(
-                                      "stress_zz", MeshLib::MeshItemType::Cell);
+    auto mesh_prop_sigma_zz = MeshLib::getOrCreateMeshProperty<double>(
+        const_cast<MeshLib::Mesh&>(mesh), "stress_zz",
+        MeshLib::MeshItemType::Cell, 1);
     mesh_prop_sigma_zz->resize(mesh.getNumberOfElements());
     _process_data._mesh_prop_stress_zz = mesh_prop_sigma_zz;
 
-    auto mesh_prop_sigma_xy = const_cast<MeshLib::Mesh&>(mesh)
-                                  .getProperties()
-                                  .template createNewPropertyVector<double>(
-                                      "stress_xy", MeshLib::MeshItemType::Cell);
+    auto mesh_prop_sigma_xy = MeshLib::getOrCreateMeshProperty<double>(
+        const_cast<MeshLib::Mesh&>(mesh), "stress_xy",
+        MeshLib::MeshItemType::Cell, 1);
     mesh_prop_sigma_xy->resize(mesh.getNumberOfElements());
     _process_data._mesh_prop_stress_xy = mesh_prop_sigma_xy;
 
     if (DisplacementDim == 3)
     {
-        auto mesh_prop_sigma_xz =
-            const_cast<MeshLib::Mesh&>(mesh)
-                .getProperties()
-                .template createNewPropertyVector<double>(
-                    "stress_xz", MeshLib::MeshItemType::Cell);
+        auto mesh_prop_sigma_xz = MeshLib::getOrCreateMeshProperty<double>(
+            const_cast<MeshLib::Mesh&>(mesh), "stress_xz",
+            MeshLib::MeshItemType::Cell, 1);
         mesh_prop_sigma_xz->resize(mesh.getNumberOfElements());
         _process_data._mesh_prop_stress_xz = mesh_prop_sigma_xz;
 
-        auto mesh_prop_sigma_yz =
-            const_cast<MeshLib::Mesh&>(mesh)
-                .getProperties()
-                .template createNewPropertyVector<double>(
-                    "stress_yz", MeshLib::MeshItemType::Cell);
+        auto mesh_prop_sigma_yz = MeshLib::getOrCreateMeshProperty<double>(
+            const_cast<MeshLib::Mesh&>(mesh), "stress_yz",
+            MeshLib::MeshItemType::Cell, 1);
         mesh_prop_sigma_yz->resize(mesh.getNumberOfElements());
         _process_data._mesh_prop_stress_yz = mesh_prop_sigma_yz;
     }
 
-    auto mesh_prop_epsilon_xx =
-        const_cast<MeshLib::Mesh&>(mesh)
-            .getProperties()
-            .template createNewPropertyVector<double>(
-                "strain_xx", MeshLib::MeshItemType::Cell);
+    auto mesh_prop_epsilon_xx = MeshLib::getOrCreateMeshProperty<double>(
+        const_cast<MeshLib::Mesh&>(mesh), "strain_xx",
+        MeshLib::MeshItemType::Cell, 1);
     mesh_prop_epsilon_xx->resize(mesh.getNumberOfElements());
     _process_data._mesh_prop_strain_xx = mesh_prop_epsilon_xx;
 
-    auto mesh_prop_epsilon_yy =
-        const_cast<MeshLib::Mesh&>(mesh)
-            .getProperties()
-            .template createNewPropertyVector<double>(
-                "strain_yy", MeshLib::MeshItemType::Cell);
+    auto mesh_prop_epsilon_yy = MeshLib::getOrCreateMeshProperty<double>(
+        const_cast<MeshLib::Mesh&>(mesh), "strain_yy",
+        MeshLib::MeshItemType::Cell, 1);
     mesh_prop_epsilon_yy->resize(mesh.getNumberOfElements());
     _process_data._mesh_prop_strain_yy = mesh_prop_epsilon_yy;
 
-    auto mesh_prop_epsilon_zz =
-        const_cast<MeshLib::Mesh&>(mesh)
-            .getProperties()
-            .template createNewPropertyVector<double>(
-                "strain_zz", MeshLib::MeshItemType::Cell);
+    auto mesh_prop_epsilon_zz = MeshLib::getOrCreateMeshProperty<double>(
+        const_cast<MeshLib::Mesh&>(mesh), "strain_zz",
+        MeshLib::MeshItemType::Cell, 1);
     mesh_prop_epsilon_zz->resize(mesh.getNumberOfElements());
     _process_data._mesh_prop_strain_zz = mesh_prop_epsilon_zz;
 
-    auto mesh_prop_epsilon_xy =
-        const_cast<MeshLib::Mesh&>(mesh)
-            .getProperties()
-            .template createNewPropertyVector<double>(
-                "strain_xy", MeshLib::MeshItemType::Cell);
+    auto mesh_prop_epsilon_xy = MeshLib::getOrCreateMeshProperty<double>(
+        const_cast<MeshLib::Mesh&>(mesh), "strain_xy",
+        MeshLib::MeshItemType::Cell, 1);
     mesh_prop_epsilon_xy->resize(mesh.getNumberOfElements());
     _process_data._mesh_prop_strain_xy = mesh_prop_epsilon_xy;
 
     if (DisplacementDim == 3)
     {
-        auto mesh_prop_epsilon_xz =
-            const_cast<MeshLib::Mesh&>(mesh)
-                .getProperties()
-                .template createNewPropertyVector<double>(
-                    "strain_xz", MeshLib::MeshItemType::Cell);
+        auto mesh_prop_epsilon_xz = MeshLib::getOrCreateMeshProperty<double>(
+            const_cast<MeshLib::Mesh&>(mesh), "strain_xz",
+            MeshLib::MeshItemType::Cell, 1);
         mesh_prop_epsilon_xz->resize(mesh.getNumberOfElements());
         _process_data._mesh_prop_strain_xz = mesh_prop_epsilon_xz;
 
-        auto mesh_prop_epsilon_yz =
-            const_cast<MeshLib::Mesh&>(mesh)
-                .getProperties()
-                .template createNewPropertyVector<double>(
-                    "strain_yz", MeshLib::MeshItemType::Cell);
+        auto mesh_prop_epsilon_yz = MeshLib::getOrCreateMeshProperty<double>(
+            const_cast<MeshLib::Mesh&>(mesh), "strain_yz",
+            MeshLib::MeshItemType::Cell, 1);
         mesh_prop_epsilon_yz->resize(mesh.getNumberOfElements());
         _process_data._mesh_prop_strain_yz = mesh_prop_epsilon_yz;
     }
 
     for (auto const& fracture_prop : _process_data._vec_fracture_property)
     {
-        auto mesh_prop_levelset = const_cast<MeshLib::Mesh&>(mesh)
-                                      .getProperties()
-                                      .template createNewPropertyVector<double>(
-                                          "levelset" + std::to_string(fracture_prop->fracture_id + 1),
-                                          MeshLib::MeshItemType::Cell);
+        auto mesh_prop_levelset = MeshLib::getOrCreateMeshProperty<double>(
+            const_cast<MeshLib::Mesh&>(mesh),
+            "levelset" + std::to_string(fracture_prop->fracture_id + 1),
+            MeshLib::MeshItemType::Cell, 1);
         mesh_prop_levelset->resize(mesh.getNumberOfElements());
         for (MeshLib::Element const* e : _mesh.getElements())
         {
@@ -381,10 +360,9 @@ void SmallDeformationProcess<DisplacementDim>::initializeConcreteProcess(
         }
     }
 
-    auto mesh_prop_b = const_cast<MeshLib::Mesh&>(mesh)
-                           .getProperties()
-                           .template createNewPropertyVector<double>(
-                               "aperture", MeshLib::MeshItemType::Cell);
+    auto mesh_prop_b = MeshLib::getOrCreateMeshProperty<double>(
+        const_cast<MeshLib::Mesh&>(mesh), "aperture",
+        MeshLib::MeshItemType::Cell, 1);
     mesh_prop_b->resize(mesh.getNumberOfElements());
     auto const& mesh_prop_matid = *_process_data._mesh_prop_materialIDs;
     for (auto const& fracture_prop : _process_data._vec_fracture_property)
-- 
GitLab