Skip to content

Commit

Permalink
[PL/RM] Use reflection for IP data input
Browse files Browse the repository at this point in the history
  • Loading branch information
chleh committed Jun 17, 2024
1 parent a361f5b commit 3c1b794
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 128 deletions.
56 changes: 53 additions & 3 deletions ProcessLib/RichardsMechanics/LocalAssemblerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#include "NumLib/Extrapolation/ExtrapolatableElement.h"
#include "NumLib/Fem/Integration/GenericIntegrationMethod.h"
#include "ProcessLib/LocalAssemblerInterface.h"
#include "ProcessLib/Reflection/ReflectionSetIPData.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/MaterialState.h"
#include "ProcessLib/Utils/SetOrGetIntegrationPointData.h"
#include "RichardsMechanicsProcessData.h"

namespace ProcessLib
Expand Down Expand Up @@ -60,9 +62,57 @@ struct LocalAssemblerInterface : public ProcessLib::LocalAssemblerInterface,
}
}

virtual std::size_t setIPDataInitialConditions(
std::string_view const name, double const* values,
int const integration_order) = 0;
std::size_t setIPDataInitialConditions(std::string_view name,
double const* values,
int const integration_order)
{
if (integration_order !=
static_cast<int>(integration_method_.getIntegrationOrder()))
{
OGS_FATAL(
"Setting integration point initial conditions; The integration "
"order of the local assembler for element {:d} is different "
"from the integration order in the initial condition.",
element_.getID());
}

if (name == "sigma" && process_data_.initial_stress != nullptr)
{
OGS_FATAL(
"Setting initial conditions for stress from integration "
"point data and from a parameter '{:s}' is not possible "
"simultaneously.",
process_data_.initial_stress->name);
}

if (name.starts_with("material_state_variable_"))
{
name.remove_prefix(24);

auto const& internal_variables =
solid_material_.getInternalVariables();
if (auto const iv = std::find_if(
begin(internal_variables), end(internal_variables),
[&name](auto const& iv) { return iv.name == name; });
iv != end(internal_variables))
{
DBUG("Setting material state variable '{:s}'", name);
return ProcessLib::
setIntegrationPointDataMaterialStateVariables(
values, material_states_,
&ProcessLib::ThermoRichardsMechanics::MaterialStateData<
DisplacementDim>::material_state_variables,
iv->reference);
}
return 0;
}

// TODO this logic could be pulled out of the local assembler into the
// process. That might lead to a slightly better performance due to less
// string comparisons.
return ProcessLib::Reflection::reflectSetIPData<DisplacementDim>(
name, values, current_states_);
}

virtual std::vector<double> getMaterialStateVariableInternalState(
std::function<std::span<double>(
Expand Down
119 changes: 0 additions & 119 deletions ProcessLib/RichardsMechanics/RichardsMechanicsFEM-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,125 +197,6 @@ RichardsMechanicsLocalAssembler<ShapeFunctionDisplacement,
}
}

template <typename ShapeFunctionDisplacement, typename ShapeFunctionPressure,
int DisplacementDim>
std::size_t RichardsMechanicsLocalAssembler<
ShapeFunctionDisplacement, ShapeFunctionPressure,
DisplacementDim>::setIPDataInitialConditions(std::string_view name,
double const* values,
int const integration_order)
{
if (integration_order !=
static_cast<int>(this->integration_method_.getIntegrationOrder()))
{
OGS_FATAL(
"Setting integration point initial conditions; The integration "
"order of the local assembler for element {:d} is different "
"from the integration order in the initial condition.",
this->element_.getID());
}

if (name == "sigma")
{
if (this->process_data_.initial_stress != nullptr)
{
OGS_FATAL(
"Setting initial conditions for stress from integration "
"point data and from a parameter '{:s}' is not possible "
"simultaneously.",
this->process_data_.initial_stress->name);
}
return ProcessLib::setIntegrationPointKelvinVectorData<DisplacementDim>(
values, this->current_states_, [](auto& tuple) -> auto& {
return std::get<ProcessLib::ThermoRichardsMechanics::
ConstitutiveStress_StrainTemperature::
EffectiveStressData<DisplacementDim>>(
tuple)
.sigma_eff;
});
}

if (name == "saturation")
{
return ProcessLib::setIntegrationPointScalarData(
values, this->current_states_,
[](auto& tuple) -> auto&
{
return std::get<
ProcessLib::ThermoRichardsMechanics::SaturationData>(
tuple)
.S_L;
});
}
if (name == "porosity")
{
return ProcessLib::setIntegrationPointScalarData(
values, this->current_states_,
[](auto& tuple) -> auto&
{
return std::get<
ProcessLib::ThermoRichardsMechanics::PorosityData>(
tuple)
.phi;
});
}
if (name == "transport_porosity")
{
return ProcessLib::setIntegrationPointScalarData(
values, this->current_states_,
[](auto& tuple) -> auto&
{
return std::get<ProcessLib::ThermoRichardsMechanics::
TransportPorosityData>(tuple)
.phi;
});
}
if (name == "swelling_stress")
{
return ProcessLib::setIntegrationPointKelvinVectorData<DisplacementDim>(
values, this->current_states_,
[](auto& tuple) -> auto&
{
return std::get<ProcessLib::ThermoRichardsMechanics::
ConstitutiveStress_StrainTemperature::
SwellingDataStateful<DisplacementDim>>(
tuple)
.sigma_sw;
});
}
if (name == "epsilon")
{
return ProcessLib::setIntegrationPointKelvinVectorData<DisplacementDim>(
values, this->current_states_, [](auto& tuple) -> auto& {
return std::get<StrainData<DisplacementDim>>(tuple).eps;
});
}
if (name.starts_with("material_state_variable_"))
{
name.remove_prefix(24);

// Using first ip data for solid material. TODO (naumov) move solid
// material into element, store only material state in IPs.
auto const& internal_variables =
_ip_data[0].solid_material.getInternalVariables();
if (auto const iv = std::find_if(
begin(internal_variables), end(internal_variables),
[&name](auto const& iv) { return iv.name == name; });
iv != end(internal_variables))
{
DBUG("Setting material state variable '{:s}'", name);
return ProcessLib::setIntegrationPointDataMaterialStateVariables(
values, _ip_data, &IpData::material_state_variables,
iv->reference);
}

ERR("Could not find variable {:s} in solid material model's internal "
"variables.",
name);
}
return 0;
}

template <typename ShapeFunctionDisplacement, typename ShapeFunctionPressure,
int DisplacementDim>
void RichardsMechanicsLocalAssembler<ShapeFunctionDisplacement,
Expand Down
6 changes: 0 additions & 6 deletions ProcessLib/RichardsMechanics/RichardsMechanicsFEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ class RichardsMechanicsLocalAssembler
bool const is_axially_symmetric,
RichardsMechanicsProcessData<DisplacementDim>& process_data);

/// \return the number of read integration points.
std::size_t setIPDataInitialConditions(
std::string_view const name,
double const* values,
int const integration_order) override;

void setInitialConditionsConcrete(Eigen::VectorXd const local_x,
double const t,
int const process_id) override;
Expand Down

0 comments on commit 3c1b794

Please sign in to comment.