Skip to content

Commit

Permalink
Merge branch 'StatesInSmallDeformations' into 'master'
Browse files Browse the repository at this point in the history
Extract constitutive relations in SmallDeformation process

See merge request ogs/ogs!4763
  • Loading branch information
endJunction committed Oct 18, 2023
2 parents f997d0c + 69bbd6f commit 467d052
Show file tree
Hide file tree
Showing 22 changed files with 1,109 additions and 387 deletions.
1 change: 1 addition & 0 deletions ProcessLib/SmallDeformation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
get_source_files(SOURCES)
append_source_files(SOURCES ConstitutiveRelations)

ogs_add_library(SmallDeformation ${SOURCES})
target_link_libraries(SmallDeformation PUBLIC ProcessLib PRIVATE ParameterLib)
Expand Down
117 changes: 117 additions & 0 deletions ProcessLib/SmallDeformation/ConstitutiveRelations/Base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* \file
* \copyright
* Copyright (c) 2012-2023, 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 "BaseLib/StrongType.h"
#include "MaterialLib/MPL/Medium.h"
#include "MathLib/KelvinVector.h"
#include "ParameterLib/SpatialPosition.h"
#include "ProcessLib/Reflection/ReflectionData.h"

namespace ProcessLib::SmallDeformation
{
template <int DisplacementDim>
using KelvinVector = MathLib::KelvinVector::KelvinVectorType<DisplacementDim>;

template <int DisplacementDim>
using KelvinMatrix = MathLib::KelvinVector::KelvinMatrixType<DisplacementDim>;

template <int DisplacementDim>
using GlobalDimVector = Eigen::Vector<double, DisplacementDim>;

/// Convenience alias for not a number.
static constexpr double nan = std::numeric_limits<double>::quiet_NaN();

/// Used to set a Kelvin vector to all not-a-number.
template <int DisplacementDim>
constexpr KelvinVector<DisplacementDim> KVnan()
{
return KelvinVector<DisplacementDim>::Constant(nan);
}

/// Used to set a Kelvin matrix to all not-a-number.
template <int DisplacementDim>
constexpr KelvinMatrix<DisplacementDim> KMnan()
{
return KelvinMatrix<DisplacementDim>::Constant(nan);
}

/// Used to set a Kelvin vector to all zero.
template <int DisplacementDim>
constexpr KelvinVector<DisplacementDim> KVzero()
{
return KelvinVector<DisplacementDim>::Zero();
}

/// Represents a previous state of type T.
template <typename T>
struct PrevState
{
PrevState() = default;
explicit PrevState(T const& t) : t{t} {}
explicit PrevState(T&& t) : t{std::move(t)} {}

PrevState<T>& operator=(T const& u)
{
t = u;
return *this;
}

PrevState<T>& operator=(T&& u)
{
t = std::move(u);
return *this;
}

T& operator*() { return t; }
T const& operator*() const { return t; }

T* operator->() { return &t; }
T const* operator->() const { return &t; }

private:
T t;
};

struct SpaceTimeData
{
ParameterLib::SpatialPosition x;
double t;
double dt;
};

struct MediaData
{
explicit MediaData(MaterialPropertyLib::Medium const& medium)
: medium{medium}, solid{medium.phase("Solid")}
{
}

MaterialPropertyLib::Medium const& medium;
MaterialPropertyLib::Phase const& solid;
};

using Temperature = BaseLib::StrongType<double, struct TemperatureTag>;

template <int DisplacementDim>
struct StrainData
{
// TODO Move initialization to the local assembler.
KelvinVector<DisplacementDim> eps = KVnan<DisplacementDim>();

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

return ProcessLib::Reflection::reflectWithName("epsilon", &Self::eps);
}
};

} // namespace ProcessLib::SmallDeformation
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* \file
* \copyright
* Copyright (c) 2012-2023, 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 "FreeEnergyDensity.h"
#include "Gravity.h"
#include "ProcessLib/Reflection/ReflectionData.h"
#include "SolidDensity.h"
#include "SolidMechanics.h"

namespace ProcessLib::SmallDeformation
{
namespace ConstitutiveRelations
{
/// Data whose state must be tracked by the process.
template <int DisplacementDim>
struct StatefulData
{
StressData<DisplacementDim> stress_data;

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

return Reflection::reflectWithoutName(&Self::stress_data);
}
};

/// Data whose state must be tracked by the process.
template <int DisplacementDim>
struct StatefulDataPrev
{
PrevState<StressData<DisplacementDim>> stress_data;

StatefulDataPrev<DisplacementDim>& operator=(
StatefulData<DisplacementDim> const& state)
{
stress_data = state.stress_data;

return *this;
}
};

/// Data that is needed for output purposes, but not directly for the assembly.
template <int DisplacementDim>
struct OutputData
{
StrainData<DisplacementDim> eps_data;
FreeEnergyDensityData free_energy_density_data;

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

return Reflection::reflectWithoutName(&Self::eps_data,
&Self::free_energy_density_data);
}
};

/// Data that is needed for the equation system assembly.
template <int DisplacementDim>
struct ConstitutiveData
{
SolidMechanicsDataStateless<DisplacementDim> s_mech_data;
VolumetricBodyForce<DisplacementDim> volumetric_body_force;
};

/// Data that stores intermediate values, which are not needed outside the
/// constitutive setting.
template <int DisplacementDim>
struct ConstitutiveTempData
{
PrevState<StrainData<DisplacementDim>> eps_data_prev;
SolidDensity rho_SR;
};
} // namespace ConstitutiveRelations
} // namespace ProcessLib::SmallDeformation
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* \file
* \copyright
* Copyright (c) 2012-2023, 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 "Gravity.h"
#include "SolidDensity.h"
#include "SolidMechanics.h"

namespace ProcessLib::SmallDeformation
{
namespace ConstitutiveRelations
{
/// Constitutive models used for assembly.
template <int DisplacementDim>
struct ConstitutiveModels
{
template <typename TRMProcessData>
explicit ConstitutiveModels(
TRMProcessData const& process_data,
SolidConstitutiveRelation<DisplacementDim> const& solid_material)
: s_mech_model(solid_material),
gravity_model(process_data.specific_body_force)
{
}

SolidMechanicsModel<DisplacementDim> s_mech_model;
SolidDensityModel rho_S_model;
GravityModel<DisplacementDim> gravity_model;
};
} // namespace ConstitutiveRelations
} // namespace ProcessLib::SmallDeformation
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* \file
* \copyright
* Copyright (c) 2012-2023, 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 "ConstitutiveSetting.h"

#include "Invoke.h"

namespace ProcessLib::SmallDeformation
{
namespace ConstitutiveRelations
{
template <int DisplacementDim>
void ConstitutiveSetting<DisplacementDim>::eval(
ConstitutiveModels<DisplacementDim>& models, double const t,
double const dt, ParameterLib::SpatialPosition const& x_position,
MaterialPropertyLib::Medium const& medium, double const T_ref,
KelvinVector<DisplacementDim> const& eps,
KelvinVector<DisplacementDim> const& eps_prev,
StatefulData<DisplacementDim>& state,
StatefulDataPrev<DisplacementDim> const& prev_state,
MaterialStateData<DisplacementDim>& mat_state,
ConstitutiveTempData<DisplacementDim>& tmp,
OutputData<DisplacementDim>& out,
ConstitutiveData<DisplacementDim>& cd) const
{
namespace MPL = MaterialPropertyLib;

auto& eps_data = out.eps_data;
eps_data.eps = eps;
auto& eps_data_prev = tmp.eps_data_prev;
eps_data_prev->eps = eps_prev;
auto& rho_SR = tmp.rho_SR;

auto& s_mech_data = cd.s_mech_data;
auto& volumetric_body_force = cd.volumetric_body_force;

auto& free_energy_density_data = out.free_energy_density_data;

Temperature const T{T_ref};
SpaceTimeData const x_t{x_position, t, dt};
MediaData const media_data{medium};

assertEvalArgsUnique(models.s_mech_model);
models.s_mech_model.eval(x_t, T, eps_data, eps_data_prev, mat_state,
prev_state.stress_data, state.stress_data,
s_mech_data, free_energy_density_data);

assertEvalArgsUnique(models.rho_S_model);
models.rho_S_model.eval(x_t, media_data, T, rho_SR);

assertEvalArgsUnique(models.gravity_model);
models.gravity_model.eval(rho_SR, volumetric_body_force);
}

template struct ConstitutiveSetting<2>;
template struct ConstitutiveSetting<3>;
} // namespace ConstitutiveRelations
} // namespace ProcessLib::SmallDeformation
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* \file
* \copyright
* Copyright (c) 2012-2023, 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 "ConstitutiveData.h"
#include "ConstitutiveModels.h"

namespace ProcessLib::SmallDeformation
{
namespace ConstitutiveRelations
{
template <int DisplacementDim>
struct ConstitutiveSetting
{
/// Evaluate the constitutive setting.
void eval(ConstitutiveModels<DisplacementDim>& models, double const t,
double const dt, ParameterLib::SpatialPosition const& x_position,
MaterialPropertyLib::Medium const& medium, double const T_ref,
KelvinVector<DisplacementDim> const& eps,
KelvinVector<DisplacementDim> const& eps_prev,
StatefulData<DisplacementDim>& state,
StatefulDataPrev<DisplacementDim> const& prev_state,
MaterialStateData<DisplacementDim>& mat_state,
ConstitutiveTempData<DisplacementDim>& tmp,
OutputData<DisplacementDim>& out,
ConstitutiveData<DisplacementDim>& cd) const;
};

extern template struct ConstitutiveSetting<2>;
extern template struct ConstitutiveSetting<3>;
} // namespace ConstitutiveRelations
} // namespace ProcessLib::SmallDeformation
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* \file
* \copyright
* Copyright (c) 2012-2023, 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 "CreateConstitutiveSetting.h"

#include "MaterialLib/SolidModels/CreateConstitutiveRelation.h"

namespace ProcessLib::SmallDeformation
{
namespace ConstitutiveRelations
{
template <int DisplacementDim>
std::map<int, std::unique_ptr<SolidConstitutiveRelation<DisplacementDim>>>
CreateConstitutiveSetting<DisplacementDim>::createSolidConstitutiveRelations(
std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
std::optional<ParameterLib::CoordinateSystem> const&
local_coordinate_system,
BaseLib::ConfigTree const& config)
{
return MaterialLib::Solids::createConstitutiveRelations<DisplacementDim>(
parameters, local_coordinate_system, config);
}

template struct CreateConstitutiveSetting<2>;
template struct CreateConstitutiveSetting<3>;
} // namespace ConstitutiveRelations
} // namespace ProcessLib::SmallDeformation
Loading

0 comments on commit 467d052

Please sign in to comment.