Skip to content

Commit

Permalink
Merge branch 'trm-data-in-tuples' into 'master'
Browse files Browse the repository at this point in the history
[PL/TRM] Hold data in tuples, not structs

See merge request ogs/ogs!4921
  • Loading branch information
bilke committed Feb 28, 2024
2 parents 5ae2e3a + 60a8e46 commit d67dca7
Show file tree
Hide file tree
Showing 27 changed files with 569 additions and 871 deletions.
26 changes: 26 additions & 0 deletions ProcessLib/ConstitutiveRelations/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#pragma once

#include <boost/mp11.hpp>

#include "ParameterLib/SpatialPosition.h"

namespace ProcessLib::ConstitutiveRelations
Expand Down Expand Up @@ -43,6 +45,30 @@ struct PrevState
T t;
};

//! Applies PrevState to a tuple of constitutive data.
template <typename Tuple>
using PrevStateOf = boost::mp11::mp_transform<PrevState, Tuple>;

namespace detail
{
template <typename... Ts, std::size_t... Idcs>
void assign(std::tuple<PrevState<Ts>...>& prev_states,
std::tuple<Ts...> const& current_states,
std::index_sequence<Idcs...>)
{
((std::get<Idcs>(prev_states) = std::get<Idcs>(current_states)), ...);
}
} // namespace detail

//! Assigns a tuple of current states to a tuple of previous states.
template <typename... Ts>
void assign(std::tuple<PrevState<Ts>...>& prev_states,
std::tuple<Ts...> const& current_states)
{
detail::assign(prev_states, current_states,
std::make_index_sequence<sizeof...(Ts)>{});
}

struct SpaceTimeData
{
ParameterLib::SpatialPosition x;
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/Graph/Get.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#pragma once

#include "boost/mp11.hpp"
#include <boost/mp11.hpp>

namespace ProcessLib::Graph
{
Expand Down
3 changes: 3 additions & 0 deletions ProcessLib/Reflection/ReflectionIPData.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ struct is_raw_data<Eigen::Matrix<double, N, M, Eigen::RowMajor, N, M>>
{
};

template <typename T>
constexpr bool is_raw_data_v = is_raw_data<T>::value;

template <typename T>
struct NumberOfRows;

Expand Down
4 changes: 2 additions & 2 deletions ProcessLib/Reflection/ReflectionSetIPData.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void setIPData(double const* values,
using AccessorResult = std::invoke_result_t<Accessor, IPData&>;
using AccessorResultStripped = std::remove_cvref_t<AccessorResult>;

static_assert(is_raw_data<AccessorResultStripped>::value,
static_assert(is_raw_data_v<AccessorResultStripped>,
"This method only deals with raw data. The given "
"AccessorResultStripped is not raw data.");

Expand Down Expand Up @@ -112,7 +112,7 @@ bool setIPDataIfNameMatches(std::string_view const name, double const* values,
}
else
{
static_assert(detail::is_raw_data<Member>::value,
static_assert(detail::is_raw_data_v<Member>,
"The current member is not reflectable, so we "
"expect it to be raw data.");

Expand Down
20 changes: 18 additions & 2 deletions ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/Bishops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

namespace ProcessLib::ThermoRichardsMechanics
{
void BishopsModel::eval(SpaceTimeData const& x_t, MediaData const& media_data,
SaturationData const& S_L_data, BishopsData& out) const
static void bishopsModelEvalImpl(SpaceTimeData const& x_t,
MediaData const& media_data,
SaturationData const& S_L_data,
BishopsData& out)
{
namespace MPL = MaterialPropertyLib;
MPL::VariableArray variables;
Expand All @@ -29,4 +31,18 @@ void BishopsModel::eval(SpaceTimeData const& x_t, MediaData const& media_data,
variables, MPL::Variable::liquid_saturation, x_t.x,
x_t.t, x_t.dt);
}

void BishopsModel::eval(SpaceTimeData const& x_t, MediaData const& media_data,
SaturationData const& S_L_data, BishopsData& out) const
{
bishopsModelEvalImpl(x_t, media_data, S_L_data, out);
}

void BishopsPrevModel::eval(SpaceTimeData const& x_t,
MediaData const& media_data,
PrevState<SaturationData> const& S_L_data,
PrevState<BishopsData>& out) const
{
bishopsModelEvalImpl(x_t, media_data, *S_L_data, *out);
}
} // namespace ProcessLib::ThermoRichardsMechanics
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ struct BishopsModel
void eval(SpaceTimeData const& x_t, MediaData const& media_data,
SaturationData const& S_L_data, BishopsData& out) const;
};

struct BishopsPrevModel
{
void eval(SpaceTimeData const& x_t, MediaData const& media_data,
PrevState<SaturationData> const& S_L_data,
PrevState<BishopsData>& out) const;
};
} // namespace ProcessLib::ThermoRichardsMechanics
55 changes: 0 additions & 55 deletions ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/Invoke.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* \file
* \copyright
* Copyright (c) 2012-2024, 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 "Base.h"

namespace ProcessLib::ThermoRichardsMechanics
{
template <int DisplacementDim>
struct MechanicalStrainData
{
// TODO it seems fragile that some data have to be initialized that way.
KelvinVector<DisplacementDim> eps_m = KV::KVzero<DisplacementDim>();

static auto reflect()
{
using Self = MechanicalStrainData<DisplacementDim>;

return ProcessLib::Reflection::reflectWithName("eps_m", &Self::eps_m);
}
};
} // namespace ProcessLib::ThermoRichardsMechanics
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* \file
* \copyright
* Copyright (c) 2012-2024, 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 "Base.h"

namespace ProcessLib::ThermoRichardsMechanics
{
template <int DisplacementDim>
struct SolidMechanicsDataStateless
{
KelvinMatrix<DisplacementDim> stiffness_tensor =
KV::KMnan<DisplacementDim>();
KelvinVector<DisplacementDim> J_uT_BT_K_N = KV::KVnan<DisplacementDim>();
KelvinVector<DisplacementDim> J_up_BT_K_N = KV::KVnan<DisplacementDim>();
};
} // namespace ProcessLib::ThermoRichardsMechanics
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/EqT.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/EquivalentPlasticStrainData.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/Gravity.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/MechanicalStrainData.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/Porosity.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/Saturation.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/SolidDensity.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/SolidMechanicsDataStateless.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/Swelling.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/TRMHeatStorageAndFlux.h"
#include "ProcessLib/ThermoRichardsMechanics/ConstitutiveCommon/TRMStorage.h"
Expand All @@ -31,113 +33,50 @@ namespace ProcessLib::ThermoRichardsMechanics
{
namespace ConstitutiveStressSaturation_StrainPressureTemperature
{
// TODO directly declare these type aliases in Traits.h
/// Data whose state must be tracked by the TRM process.
template <int DisplacementDim>
struct StatefulData
{
SaturationData S_L_data;
PorosityData poro_data;
TransportPorosityData transport_poro_data;
StrainData<DisplacementDim> eps_data;
// TODO swelling is not used in this constitutive setting, but the stateful
// data is set in setInitialConditionsConcrete()
// Once this has been refactored, the swelling code can be moved from the
// common to the original subdirectory for constitutive settings
SwellingDataStateful<DisplacementDim> swelling_data;
SolidMechanicsDataStateful<DisplacementDim> s_mech_data;
TotalStressData<DisplacementDim> total_stress_data;

static auto reflect()
{
using Self = StatefulData<DisplacementDim>;

return Reflection::reflectWithoutName(&Self::S_L_data,
&Self::poro_data,
&Self::transport_poro_data,
&Self::eps_data,
&Self::swelling_data,
&Self::total_stress_data);
}
};
using StatefulData =
std::tuple<SaturationData, PorosityData, TransportPorosityData,
StrainData<DisplacementDim>,
// TODO swelling is not used in this constitutive setting, but
// the stateful data is set in setInitialConditionsConcrete()
// Once this has been refactored, the swelling code can be moved
// from the common to the original subdirectory for constitutive
// settings
SwellingDataStateful<DisplacementDim>,
// TODO get rid of that
MechanicalStrainData<DisplacementDim>,
TotalStressData<DisplacementDim>>;

/// Data whose state must be tracked by the TRM process.
template <int DisplacementDim>
struct StatefulDataPrev
{
PrevState<SaturationData> S_L_data;
PrevState<PorosityData> poro_data;
PrevState<TransportPorosityData> transport_poro_data;
PrevState<StrainData<DisplacementDim>> eps_data;
PrevState<SwellingDataStateful<DisplacementDim>> swelling_data;
PrevState<SolidMechanicsDataStateful<DisplacementDim>> s_mech_data;
PrevState<TotalStressData<DisplacementDim>> total_stress_data;

StatefulDataPrev<DisplacementDim>& operator=(
StatefulData<DisplacementDim> const& state)
{
S_L_data = state.S_L_data;
poro_data = state.poro_data;
transport_poro_data = state.transport_poro_data;
eps_data = state.eps_data;
swelling_data = state.swelling_data;
s_mech_data = state.s_mech_data;
total_stress_data = state.total_stress_data;

return *this;
}
};
using StatefulDataPrev = PrevStateOf<StatefulData<DisplacementDim>>;

/// Data that is needed for output purposes, but not directly for the assembly.
template <int DisplacementDim>
struct OutputData
{
DarcyLawData<DisplacementDim> darcy_data;
LiquidDensityData rho_L_data;
LiquidViscosityData mu_L_data;
SolidDensityData rho_S_data;
PermeabilityData<DisplacementDim> perm_data;

static auto reflect()
{
using Self = OutputData<DisplacementDim>;

return Reflection::reflectWithoutName(&Self::darcy_data,
&Self::rho_L_data,
&Self::mu_L_data,
&Self::rho_S_data,
&Self::perm_data);
}
};
using OutputData = std::tuple<DarcyLawData<DisplacementDim>, LiquidDensityData,
LiquidViscosityData, SolidDensityData,
PermeabilityData<DisplacementDim>>;

/// Data that is needed for the equation system assembly.
template <int DisplacementDim>
struct ConstitutiveData
{
SolidMechanicsDataStateless<DisplacementDim> s_mech_data;
GravityData<DisplacementDim> grav_data;
TRMHeatStorageAndFluxData<DisplacementDim> heat_data;
TRMVaporDiffusionData<DisplacementDim> vap_data;
TRMStorageData storage_data;
EqPData<DisplacementDim> eq_p_data;
EqTData<DisplacementDim> eq_T_data;
ThermoOsmosisData<DisplacementDim> th_osmosis_data;
};
using ConstitutiveData =
std::tuple<SolidMechanicsDataStateless<DisplacementDim>,
GravityData<DisplacementDim>,
TRMHeatStorageAndFluxData<DisplacementDim>,
TRMVaporDiffusionData<DisplacementDim>, TRMStorageData,
EqPData<DisplacementDim>, EqTData<DisplacementDim>,
ThermoOsmosisData<DisplacementDim>>;

/// Data that stores intermediate values, which are not needed outside the
/// constitutive setting.
template <int DisplacementDim>
struct ConstitutiveTempData
{
ElasticTangentStiffnessData<DisplacementDim> C_el_data;
BiotData biot_data;
SolidCompressibilityData solid_compressibility_data;
SaturationDataDeriv dS_L_data;
BishopsData bishops_data;
// TODO why not usual state tracking for that?
PrevState<BishopsData> bishops_data_prev;
SolidThermalExpansionData<DisplacementDim> s_therm_exp_data;
FluidThermalExpansionData f_therm_exp_data;
EquivalentPlasticStrainData equiv_plast_strain_data;
};
using ConstitutiveTempData =
std::tuple<ElasticTangentStiffnessData<DisplacementDim>, BiotData,
SolidCompressibilityData, SaturationDataDeriv, BishopsData,
// TODO why not usual state tracking for that?
PrevState<BishopsData>,
SolidThermalExpansionData<DisplacementDim>,
FluidThermalExpansionData, EquivalentPlasticStrainData>;
} // namespace ConstitutiveStressSaturation_StrainPressureTemperature
} // namespace ProcessLib::ThermoRichardsMechanics
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct ConstitutiveModels
SolidConstitutiveRelation<DisplacementDim>>
solid_compressibility_model;
BishopsModel bishops_model;
BishopsPrevModel bishops_prev_model;
PorosityModel<DisplacementDim> poro_model;
TransportPorosityModel<DisplacementDim> transport_poro_model;
SwellingModel<DisplacementDim> swelling_model;
Expand Down
Loading

0 comments on commit d67dca7

Please sign in to comment.