CreateHydroMechanicsProcess.cpp
/**
* \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
*
*/
#include "CreateHydroMechanicsProcess.h"
#include <cassert>
#include "HydroMechanicsProcess.h"
#include "HydroMechanicsProcessData.h"
#include "MaterialLib/MPL/CreateMaterialSpatialDistributionMap.h"
#include "MaterialLib/MPL/MaterialSpatialDistributionMap.h"
#include "MaterialLib/MPL/Medium.h"
#include "MaterialLib/SolidModels/CreateConstitutiveRelation.h"
#include "MaterialLib/SolidModels/MechanicsBase.h"
#include "ParameterLib/Utils.h"
#include "ProcessLib/Output/CreateSecondaryVariables.h"
#include "ProcessLib/Utils/ProcessUtils.h"
namespace ProcessLib
{
namespace HydroMechanics
{
template <int DisplacementDim>
std::unique_ptr<Process> createHydroMechanicsProcess(
std::string name, MeshLib::Mesh& mesh,
std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
std::vector<ProcessVariable> const& variables,
std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
std::optional<ParameterLib::CoordinateSystem> const&
local_coordinate_system,
unsigned const integration_order, BaseLib::ConfigTree const& config,
std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
{
//! \ogs_file_param{prj__processes__process__type}
config.checkConfigParameter("type", "HYDRO_MECHANICS");
DBUG("Create HydroMechanicsProcess.");
auto const staggered_scheme =
//! \ogs_file_param{prj__processes__process__HYDRO_MECHANICS__coupling_scheme}
config.getConfigParameterOptional<std::string>("coupling_scheme");
const bool use_monolithic_scheme =
!(staggered_scheme && (*staggered_scheme == "staggered"));
// Process variable.
//! \ogs_file_param{prj__processes__process__HYDRO_MECHANICS__process_variables}
auto const pv_config = config.getConfigSubtree("process_variables");
ProcessVariable* variable_p;
ProcessVariable* variable_u;
std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
process_variables;
int const hydraulic_process_id = 0;
int mechanics_related_process_id = 0;
if (use_monolithic_scheme) // monolithic scheme.
{
auto per_process_variables = findProcessVariables(
variables, pv_config,
{//! \ogs_file_param_special{prj__processes__process__HYDRO_MECHANICS__process_variables__pressure}
"pressure",
//! \ogs_file_param_special{prj__processes__process__HYDRO_MECHANICS__process_variables__displacement}
"displacement"});
variable_p = &per_process_variables[0].get();
variable_u = &per_process_variables[1].get();
process_variables.push_back(std::move(per_process_variables));
}
else // staggered scheme.
{
using namespace std::string_literals;
for (auto const& variable_name : {"pressure"s, "displacement"s})
{
auto per_process_variables =
findProcessVariables(variables, pv_config, {variable_name});
process_variables.push_back(std::move(per_process_variables));
}
mechanics_related_process_id = 1;
variable_p = &process_variables[hydraulic_process_id][0].get();
variable_u = &process_variables[mechanics_related_process_id][0].get();
}
DBUG("Associate displacement with process variable '{:s}'.",
variable_u->getName());
if (variable_u->getNumberOfGlobalComponents() != DisplacementDim)
{
OGS_FATAL(
"Number of components of the process variable '{:s}' is different "
"from the displacement dimension: got {:d}, expected {:d}",
variable_u->getName(),
variable_u->getNumberOfGlobalComponents(),
DisplacementDim);
}
DBUG("Associate pressure with process variable '{:s}'.",
variable_p->getName());
if (variable_p->getNumberOfGlobalComponents() != 1)
{
OGS_FATAL(
"Pressure process variable '{:s}' is not a scalar variable but has "
"{:d} components.",
variable_p->getName(),
variable_p->getNumberOfGlobalComponents());
}
auto solid_constitutive_relations =
MaterialLib::Solids::createConstitutiveRelations<DisplacementDim>(
parameters, local_coordinate_system, config);
// Specific body force
Eigen::Matrix<double, DisplacementDim, 1> specific_body_force;
{
std::vector<double> const b =
//! \ogs_file_param{prj__processes__process__HYDRO_MECHANICS__specific_body_force}
config.getConfigParameter<std::vector<double>>(
"specific_body_force");
if (b.size() != DisplacementDim)
{
OGS_FATAL(
"The size of the specific body force vector does not match the "
"displacement dimension. Vector size is {:d}, displacement "
"dimension is {:d}",
b.size(), DisplacementDim);
}
std::copy_n(b.data(), b.size(), specific_body_force.data());
}
//! \ogs_file_param{prj__processes__process__HYDRO_MECHANICS__mass_lumping}
auto mass_lumping = config.getConfigParameter<bool>("mass_lumping", false);
auto media_map =
MaterialPropertyLib::createMaterialSpatialDistributionMap(media, mesh);
std::array const requiredMediumProperties = {
MaterialPropertyLib::reference_temperature,
MaterialPropertyLib::permeability, MaterialPropertyLib::porosity,
MaterialPropertyLib::biot_coefficient};
std::array const requiredFluidProperties = {MaterialPropertyLib::viscosity,
MaterialPropertyLib::density};
std::array const requiredSolidProperties = {MaterialPropertyLib::density};
for (auto const& element : mesh.getElements())
{
auto const element_id = element->getID();
media_map->checkElementHasMedium(element_id);
auto const& medium = *media_map->getMedium(element_id);
checkRequiredProperties(medium, requiredMediumProperties);
checkRequiredProperties(fluidPhase(medium), requiredFluidProperties);
checkRequiredProperties(medium.phase("Solid"), requiredSolidProperties);
}
DBUG("Media properties verified.");
// Initial stress conditions
auto const initial_stress = ParameterLib::findOptionalTagParameter<double>(
//! \ogs_file_param_special{prj__processes__process__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);
HydroMechanicsProcessData<DisplacementDim> process_data{
materialIDs(mesh),
std::move(media_map),
std::move(solid_constitutive_relations),
initial_stress,
specific_body_force,
mass_lumping,
hydraulic_process_id,
mechanics_related_process_id};
SecondaryVariableCollection secondary_variables;
ProcessLib::createSecondaryVariables(config, secondary_variables);
return std::make_unique<HydroMechanicsProcess<DisplacementDim>>(
std::move(name), mesh, std::move(jacobian_assembler), parameters,
integration_order, std::move(process_variables),
std::move(process_data), std::move(secondary_variables),
use_monolithic_scheme);
}
template std::unique_ptr<Process> createHydroMechanicsProcess<2>(
std::string name,
MeshLib::Mesh& mesh,
std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
std::vector<ProcessVariable> const& variables,
std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
std::optional<ParameterLib::CoordinateSystem> const&
local_coordinate_system,
unsigned const integration_order,
BaseLib::ConfigTree const& config,
std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media);
template std::unique_ptr<Process> createHydroMechanicsProcess<3>(
std::string name,
MeshLib::Mesh& mesh,
std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
std::vector<ProcessVariable> const& variables,
std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
std::optional<ParameterLib::CoordinateSystem> const&
local_coordinate_system,
unsigned const integration_order,
BaseLib::ConfigTree const& config,
std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media);
} // namespace HydroMechanics
} // namespace ProcessLib