From 8743175134e07ec9b2a28b68d0a0756c1250fb5c Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Tue, 31 Aug 2021 12:24:31 +0200
Subject: [PATCH] [PL/TH2M] Extract constitutive variables.

A class of variables similar to those stored in the
integration point data but needed only temporary for
the assembly process.
---
 ProcessLib/TH2M/ConstitutiveVariables.h | 29 +++++++++++++++++++++++++
 ProcessLib/TH2M/TH2MFEM-impl.h          | 15 ++++++++++---
 ProcessLib/TH2M/TH2MFEM.h               |  8 ++++---
 3 files changed, 46 insertions(+), 6 deletions(-)
 create mode 100644 ProcessLib/TH2M/ConstitutiveVariables.h

diff --git a/ProcessLib/TH2M/ConstitutiveVariables.h b/ProcessLib/TH2M/ConstitutiveVariables.h
new file mode 100644
index 00000000000..b8d6276fc7d
--- /dev/null
+++ b/ProcessLib/TH2M/ConstitutiveVariables.h
@@ -0,0 +1,29 @@
+/**
+ * \file
+ * \copyright
+ * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ */
+
+#pragma once
+
+#include "MathLib/KelvinVector.h"
+
+namespace ProcessLib::TH2M
+{
+/// Variables needed only for the assembly process. The values are not preserved
+/// throughout the iterations contrary to the variables in IntegrationPointData.
+template <int DisplacementDim>
+struct ConstitutiveVariables
+{
+    using KelvinMatrixType =
+        MathLib::KelvinVector::KelvinMatrixType<DisplacementDim>;
+
+    KelvinMatrixType C;
+
+    EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
+};
+
+}  // namespace ProcessLib::TH2M
diff --git a/ProcessLib/TH2M/TH2MFEM-impl.h b/ProcessLib/TH2M/TH2MFEM-impl.h
index d92709e1367..99e366ac04d 100644
--- a/ProcessLib/TH2M/TH2MFEM-impl.h
+++ b/ProcessLib/TH2M/TH2MFEM-impl.h
@@ -93,8 +93,9 @@ TH2MLocalAssembler<ShapeFunctionDisplacement, ShapeFunctionPressure,
 
 template <typename ShapeFunctionDisplacement, typename ShapeFunctionPressure,
           typename IntegrationMethod, int DisplacementDim>
-void TH2MLocalAssembler<ShapeFunctionDisplacement, ShapeFunctionPressure,
-                        IntegrationMethod, DisplacementDim>::
+std::vector<ConstitutiveVariables<DisplacementDim>>
+TH2MLocalAssembler<ShapeFunctionDisplacement, ShapeFunctionPressure,
+                   IntegrationMethod, DisplacementDim>::
     updateConstitutiveVariables(Eigen::VectorXd const& local_x,
                                 Eigen::VectorXd const& local_x_dot,
                                 double const t, double const dt)
@@ -127,10 +128,15 @@ void TH2MLocalAssembler<ShapeFunctionDisplacement, ShapeFunctionPressure,
 
     unsigned const n_integration_points =
         _integration_method.getNumberOfPoints();
+
+    std::vector<ConstitutiveVariables<DisplacementDim>>
+        ip_constitutive_variables(n_integration_points);
+
     for (unsigned ip = 0; ip < n_integration_points; ip++)
     {
         pos.setIntegrationPoint(ip);
         auto& ip_data = _ip_data[ip];
+        auto& ip_cv = ip_constitutive_variables[ip];
 
         auto const& Np = ip_data.N_p;
         auto const& NT = Np;
@@ -260,7 +266,8 @@ void TH2MLocalAssembler<ShapeFunctionDisplacement, ShapeFunctionPressure,
         auto const rhoSR = rho_ref_SR;
 #endif  // NON_CONSTANT_SOLID_PHASE_VOLUME_FRACTION
 
-        ip_data.updateConstitutiveRelation(vars, t, pos, dt, T - T_dot * dt);
+        ip_cv.C = ip_data.updateConstitutiveRelation(vars, t, pos, dt,
+                                                     T - T_dot * dt);
 
         // constitutive model object as specified in process creation
         auto& ptm = *_process_data.phase_transition_model_;
@@ -330,6 +337,8 @@ void TH2MLocalAssembler<ShapeFunctionDisplacement, ShapeFunctionPressure,
         ip_data.h_L = c.hL;
         ip_data.pWGR = c.pWGR;
     }
+
+    return ip_constitutive_variables;
 }
 
 template <typename ShapeFunctionDisplacement, typename ShapeFunctionPressure,
diff --git a/ProcessLib/TH2M/TH2MFEM.h b/ProcessLib/TH2M/TH2MFEM.h
index d93b5a2af7b..81ac52237b9 100644
--- a/ProcessLib/TH2M/TH2MFEM.h
+++ b/ProcessLib/TH2M/TH2MFEM.h
@@ -13,6 +13,7 @@
 #include <memory>
 #include <vector>
 
+#include "ConstitutiveVariables.h"
 #include "IntegrationPointData.h"
 #include "LocalAssemblerInterface.h"
 #include "MaterialLib/PhysicalConstant.h"
@@ -169,9 +170,10 @@ private:
         std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
         std::vector<double>& cache) const override;
 
-    void updateConstitutiveVariables(Eigen::VectorXd const& local_x,
-                                     Eigen::VectorXd const& local_x_dot,
-                                     double const t, double const dt);
+    std::vector<ConstitutiveVariables<DisplacementDim>>
+    updateConstitutiveVariables(Eigen::VectorXd const& local_x,
+                                Eigen::VectorXd const& local_x_dot,
+                                double const t, double const dt);
 
     std::size_t setSigma(double const* values)
     {
-- 
GitLab