From b2208f32ad904cb171be2ac218c6dcd82685d7d4 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Thu, 25 Mar 2021 10:33:07 +0100
Subject: [PATCH] [PL/THM] Add initial_stress input.

---
 .../t_initial_stress.md                       |  1 +
 .../CreateThermoHydroMechanicsProcess.cpp     |  9 ++++++++
 .../ThermoHydroMechanicsFEM.h                 | 22 ++++++++++++++++++-
 .../ThermoHydroMechanicsProcessData.h         |  5 +++++
 4 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ProjectFile/prj/processes/process/THERMO_HYDRO_MECHANICS/t_initial_stress.md

diff --git a/Documentation/ProjectFile/prj/processes/process/THERMO_HYDRO_MECHANICS/t_initial_stress.md b/Documentation/ProjectFile/prj/processes/process/THERMO_HYDRO_MECHANICS/t_initial_stress.md
new file mode 100644
index 00000000000..8703e9b2202
--- /dev/null
+++ b/Documentation/ProjectFile/prj/processes/process/THERMO_HYDRO_MECHANICS/t_initial_stress.md
@@ -0,0 +1 @@
+\copydoc ProcessLib::ThermoHydroMechanics::ThermoHydroMechanicsProcessData::initial_stress
diff --git a/ProcessLib/ThermoHydroMechanics/CreateThermoHydroMechanicsProcess.cpp b/ProcessLib/ThermoHydroMechanics/CreateThermoHydroMechanicsProcess.cpp
index 918f079d730..f445ed53554 100644
--- a/ProcessLib/ThermoHydroMechanics/CreateThermoHydroMechanicsProcess.cpp
+++ b/ProcessLib/ThermoHydroMechanics/CreateThermoHydroMechanicsProcess.cpp
@@ -158,10 +158,19 @@ std::unique_ptr<Process> createThermoHydroMechanicsProcess(
     auto media_map =
         MaterialPropertyLib::createMaterialSpatialDistributionMap(media, mesh);
 
+    // Initial stress conditions
+    auto const initial_stress = ParameterLib::findOptionalTagParameter<double>(
+        //! \ogs_file_param_special{prj__processes__process__THERMO_HYDRO_MECHANICS__initial_stress}
+        config, "initial_stress", parameters,
+        // Symmetric tensor size, 4 or 6, not a Kelvin vector.
+        MathLib::KelvinVector::kelvin_vector_dimensions(DisplacementDim),
+        &mesh);
+
     ThermoHydroMechanicsProcessData<DisplacementDim> process_data{
         materialIDs(mesh),
         std::move(media_map),
         std::move(solid_constitutive_relations),
+        initial_stress,
         reference_temperature,
         specific_body_force};
 
diff --git a/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsFEM.h b/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsFEM.h
index fe534aa867b..cc5bf02afb0 100644
--- a/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsFEM.h
+++ b/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsFEM.h
@@ -107,7 +107,27 @@ public:
 
         for (unsigned ip = 0; ip < n_integration_points; ip++)
         {
-            _ip_data[ip].pushBackState();
+            auto& ip_data = _ip_data[ip];
+
+            /// Set initial stress from parameter.
+            if (_process_data.initial_stress != nullptr)
+            {
+                ParameterLib::SpatialPosition const x_position{
+                    std::nullopt, _element.getID(), ip,
+                    MathLib::Point3d(NumLib::interpolateCoordinates<
+                                     ShapeFunctionDisplacement,
+                                     ShapeMatricesTypeDisplacement>(
+                        _element, ip_data.N_u))};
+
+                ip_data.sigma_eff =
+                    MathLib::KelvinVector::symmetricTensorToKelvinVector<
+                        DisplacementDim>((*_process_data.initial_stress)(
+                        std::numeric_limits<
+                            double>::quiet_NaN() /* time independent */,
+                        x_position));
+            }
+
+            ip_data.pushBackState();
         }
     }
 
diff --git a/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsProcessData.h b/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsProcessData.h
index f749490bbac..318a299339f 100644
--- a/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsProcessData.h
+++ b/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsProcessData.h
@@ -45,6 +45,11 @@ struct ThermoHydroMechanicsProcessData
         int,
         std::unique_ptr<MaterialLib::Solids::MechanicsBase<DisplacementDim>>>
         solid_materials;
+
+    /// Optional, initial stress field. A symmetric tensor, short vector
+    /// representation of length 4 or 6, ParameterLib::Parameter<double>.
+    ParameterLib::Parameter<double> const* const initial_stress;
+
     ParameterLib::Parameter<double> const& reference_temperature;
     /// Specific body forces applied to solid and fluid.
     /// It is usually used to apply gravitational forces.
-- 
GitLab