OGS
HydroMechanicsFEM.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <memory>
14#include <vector>
15
32
33namespace ProcessLib
34{
35namespace HydroMechanics
36{
37namespace MPL = MaterialPropertyLib;
38
39template <typename BMatricesType, typename ShapeMatricesTypeDisplacement,
40 typename ShapeMatricesTypePressure, int DisplacementDim, int NPoints>
42{
51
52 typename BMatricesType::KelvinVectorType sigma_eff, sigma_eff_prev;
53 typename BMatricesType::KelvinVectorType eps, eps_prev;
54
55 typename ShapeMatricesTypeDisplacement::NodalRowVectorType N_u;
56 typename ShapeMatricesTypeDisplacement::GlobalDimNodalMatrixType dNdx_u;
57
58 typename ShapeMatricesTypePressure::NodalRowVectorType N_p;
59 typename ShapeMatricesTypePressure::GlobalDimNodalMatrixType dNdx_p;
60
62 std::unique_ptr<typename MaterialLib::Solids::MechanicsBase<
63 DisplacementDim>::MaterialStateVariables>
66
67 // previous pressure rate for the fixed stress splitting
68 // approach in the staggered scheme.
69 // TODO: disable in monolithic scheme to save memory.
71
73 {
74 eps_prev = eps;
76 material_state_variables->pushBackState();
77 }
78
81 double const t,
82 ParameterLib::SpatialPosition const& x_position,
83 double const dt,
84 double const temperature)
85 {
86 namespace MPL = MaterialPropertyLib;
87
88 MPL::VariableArray variable_array;
89 MPL::VariableArray variable_array_prev;
90
91 auto const null_state = solid_material.createMaterialStateVariables();
92 solid_material.initializeInternalStateVariables(t, x_position,
93 *null_state);
94
96
97 variable_array.stress.emplace<KV>(KV::Zero());
98 variable_array.mechanical_strain.emplace<KV>(KV::Zero());
99 variable_array.temperature = temperature;
100
101 variable_array_prev.stress.emplace<KV>(KV::Zero());
102 variable_array_prev.mechanical_strain.emplace<KV>(KV::Zero());
103 variable_array_prev.temperature = temperature;
104
105 auto&& solution =
106 solid_material.integrateStress(variable_array_prev, variable_array,
107 t, x_position, dt, *null_state);
108
109 if (!solution)
110 {
111 OGS_FATAL("Computation of elastic tangent stiffness failed.");
112 }
113
115 std::move(std::get<2>(*solution));
116
117 return C;
118 }
119
120 template <typename DisplacementVectorType>
121 typename BMatricesType::KelvinMatrixType updateConstitutiveRelation(
122 MPL::VariableArray const& variable_array,
123 double const t,
124 ParameterLib::SpatialPosition const& x_position,
125 double const dt,
126 DisplacementVectorType const& /*u*/,
127 double const T)
128 {
129 MaterialPropertyLib::VariableArray variable_array_prev;
130 variable_array_prev.stress
133 variable_array_prev.mechanical_strain
135 eps_prev);
136 variable_array_prev.temperature = T;
137
138 auto&& solution = solid_material.integrateStress(
139 variable_array_prev, variable_array, t, x_position, dt,
141
142 if (!solution)
143 {
144 OGS_FATAL("Computation of local constitutive relation failed.");
145 }
146
148 std::tie(sigma_eff, material_state_variables, C) = std::move(*solution);
149
150 return C;
151 }
152
154};
155
158template <typename ShapeMatrixType>
160{
161 std::vector<ShapeMatrixType, Eigen::aligned_allocator<ShapeMatrixType>> N_u;
162};
163
164template <typename ShapeFunctionDisplacement, typename ShapeFunctionPressure,
165 int DisplacementDim>
167 : public LocalAssemblerInterface<DisplacementDim>
168{
169public:
172
173 // Types for pressure.
176
177 static int const KelvinVectorSize =
180
181 using SymmetricTensor = Eigen::Matrix<double, KelvinVectorSize, 1>;
182
183 static constexpr auto& N_u_op = MathLib::eigenBlockMatrixView<
184 DisplacementDim,
186
189
191 MeshLib::Element const& e,
192 std::size_t const /*local_matrix_size*/,
193 NumLib::GenericIntegrationMethod const& integration_method,
194 bool const is_axially_symmetric,
196
198 std::size_t setIPDataInitialConditions(
199 std::string_view const name,
200 double const* values,
201 int const integration_order) override;
202
203 void assemble(double const /*t*/, double const /*dt*/,
204 std::vector<double> const& /*local_x*/,
205 std::vector<double> const& /*local_x_prev*/,
206 std::vector<double>& /*local_M_data*/,
207 std::vector<double>& /*local_K_data*/,
208 std::vector<double>& /*local_rhs_data*/) override
209 {
210 OGS_FATAL(
211 "HydroMechanicsLocalAssembler: assembly without jacobian is not "
212 "implemented.");
213 }
214
215 void assembleWithJacobian(double const t, double const dt,
216 std::vector<double> const& local_x,
217 std::vector<double> const& local_x_prev,
218 std::vector<double>& local_rhs_data,
219 std::vector<double>& local_Jac_data) override;
220
222 const double t, double const dt, Eigen::VectorXd const& local_x,
223 Eigen::VectorXd const& local_x_prev, int const process_id,
224 std::vector<double>& local_b_data,
225 std::vector<double>& local_Jac_data) override;
226
227 void initializeConcrete() override
228 {
229 unsigned const n_integration_points =
231
232 for (unsigned ip = 0; ip < n_integration_points; ip++)
233 {
234 auto& ip_data = _ip_data[ip];
235
236 ParameterLib::SpatialPosition const x_position{
237 std::nullopt, _element.getID(), ip,
239 NumLib::interpolateCoordinates<ShapeFunctionPressure,
241 _element, ip_data.N_p))};
242
244 if (_process_data.initial_stress.value)
245 {
246 ip_data.sigma_eff =
248 DisplacementDim>((*_process_data.initial_stress.value)(
249 std::numeric_limits<
250 double>::quiet_NaN() /* time independent */,
251 x_position));
252 }
253
254 double const t = 0; // TODO (naumov) pass t from top
255 ip_data.solid_material.initializeInternalStateVariables(
256 t, x_position, *ip_data.material_state_variables);
257
258 ip_data.pushBackState();
259 }
260 }
261
262 void postTimestepConcrete(Eigen::VectorXd const& local_x,
263 Eigen::VectorXd const& local_x_prev,
264 double const t, double const dt,
265 int const process_id) override;
266
268 double const t, double const dt, Eigen::VectorXd const& local_xs,
269 Eigen::VectorXd const& local_x_prev) override;
270
271 void postNonLinearSolverConcrete(Eigen::VectorXd const& local_x,
272 Eigen::VectorXd const& local_x_prev,
273 double const t, double const dt,
274 int const process_id) override;
275
276 void setInitialConditionsConcrete(Eigen::VectorXd const local_x,
277 double const t,
278 int const process_id) override;
279
280 Eigen::Map<const Eigen::RowVectorXd> getShapeMatrix(
281 const unsigned integration_point) const override
282 {
283 auto const& N_u = _secondary_data.N_u[integration_point];
284
285 // assumes N is stored contiguously in memory
286 return Eigen::Map<const Eigen::RowVectorXd>(N_u.data(), N_u.size());
287 }
288
289 // TODO (naumov) This method is same as getIntPtSigma but for arguments and
290 // the ordering of the cache_mat.
291 // There should be only one.
292 std::vector<double> getSigma() const override;
293
294 std::vector<double> getEpsilon() const override;
295
296 std::vector<double> getStrainRateVariable() const override;
297
298 std::vector<double> const& getIntPtDarcyVelocity(
299 const double t,
300 std::vector<GlobalVector*> const& x,
301 std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
302 std::vector<double>& cache) const override;
303
304 std::vector<double> const& getIntPtSigma(
305 const double /*t*/,
306 std::vector<GlobalVector*> const& /*x*/,
307 std::vector<NumLib::LocalToGlobalIndexMap const*> const& /*dof_table*/,
308 std::vector<double>& cache) const override
309 {
311 _ip_data, &IpData::sigma_eff, cache);
312 }
313
314 std::vector<double> const& getIntPtEpsilon(
315 const double /*t*/,
316 std::vector<GlobalVector*> const& /*x*/,
317 std::vector<NumLib::LocalToGlobalIndexMap const*> const& /*dof_table*/,
318 std::vector<double>& cache) const override
319 {
321 _ip_data, &IpData::eps, cache);
322 }
323
324private:
344 const double t, double const dt, Eigen::VectorXd const& local_x,
345 std::vector<double>& local_b_data, std::vector<double>& local_Jac_data);
346
371 const double t, double const dt, Eigen::VectorXd const& local_x,
372 Eigen::VectorXd const& local_x_prev, std::vector<double>& local_b_data,
373 std::vector<double>& local_Jac_data);
374
375 unsigned getNumberOfIntegrationPoints() const override;
376
377 int getMaterialID() const override;
378
380 DisplacementDim>::MaterialStateVariables const&
381 getMaterialStateVariablesAt(unsigned integration_point) const override;
382
383private:
385
388 using IpData =
390 ShapeMatricesTypePressure, DisplacementDim,
391 ShapeFunctionDisplacement::NPOINTS>;
392 std::vector<IpData, Eigen::aligned_allocator<IpData>> _ip_data;
393
398 typename ShapeMatricesTypeDisplacement::ShapeMatrices::ShapeType>
400
401 static const int pressure_index = 0;
402 static const int pressure_size = ShapeFunctionPressure::NPOINTS;
403 static const int displacement_index = ShapeFunctionPressure::NPOINTS;
404 static const int displacement_size =
405 ShapeFunctionDisplacement::NPOINTS * DisplacementDim;
406};
407
408} // namespace HydroMechanics
409} // namespace ProcessLib
410
#define OGS_FATAL(...)
Definition Error.h:26
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:89
void assembleWithJacobian(double const t, double const dt, std::vector< double > const &local_x, std::vector< double > const &local_x_prev, std::vector< double > &local_rhs_data, std::vector< double > &local_Jac_data) override
Eigen::Map< const Eigen::RowVectorXd > getShapeMatrix(const unsigned integration_point) const override
Provides the shape matrix at the given integration point.
NumLib::GenericIntegrationMethod const & _integration_method
void assemble(double const, double const, std::vector< double > const &, std::vector< double > const &, std::vector< double > &, std::vector< double > &, std::vector< double > &) override
HydroMechanicsLocalAssembler(HydroMechanicsLocalAssembler &&)=delete
Eigen::Matrix< double, KelvinVectorSize, 1 > SymmetricTensor
void postNonLinearSolverConcrete(Eigen::VectorXd const &local_x, Eigen::VectorXd const &local_x_prev, double const t, double const dt, int const process_id) override
void postTimestepConcrete(Eigen::VectorXd const &local_x, Eigen::VectorXd const &local_x_prev, double const t, double const dt, int const process_id) override
void assembleWithJacobianForPressureEquations(const double t, double const dt, Eigen::VectorXd const &local_x, Eigen::VectorXd const &local_x_prev, std::vector< double > &local_b_data, std::vector< double > &local_Jac_data)
std::size_t setIPDataInitialConditions(std::string_view const name, double const *values, int const integration_order) override
Returns number of read integration points.
ShapeMatrixPolicyType< ShapeFunctionDisplacement, DisplacementDim > ShapeMatricesTypeDisplacement
void computeSecondaryVariableConcrete(double const t, double const dt, Eigen::VectorXd const &local_xs, Eigen::VectorXd const &local_x_prev) override
ShapeMatrixPolicyType< ShapeFunctionPressure, DisplacementDim > ShapeMatricesTypePressure
void assembleWithJacobianForStaggeredScheme(const double t, double const dt, Eigen::VectorXd const &local_x, Eigen::VectorXd const &local_x_prev, int const process_id, std::vector< double > &local_b_data, std::vector< double > &local_Jac_data) override
MaterialLib::Solids::MechanicsBase< DisplacementDim >::MaterialStateVariables const & getMaterialStateVariablesAt(unsigned integration_point) const override
void assembleWithJacobianForDeformationEquations(const double t, double const dt, Eigen::VectorXd const &local_x, std::vector< double > &local_b_data, std::vector< double > &local_Jac_data)
std::vector< double > const & getIntPtDarcyVelocity(const double t, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_table, std::vector< double > &cache) const override
void setInitialConditionsConcrete(Eigen::VectorXd const local_x, double const t, int const process_id) override
HydroMechanicsLocalAssembler(HydroMechanicsLocalAssembler const &)=delete
std::vector< double > const & getIntPtEpsilon(const double, std::vector< GlobalVector * > const &, std::vector< NumLib::LocalToGlobalIndexMap const * > const &, std::vector< double > &cache) const override
HydroMechanicsProcessData< DisplacementDim > & _process_data
SecondaryData< typename ShapeMatricesTypeDisplacement::ShapeMatrices::ShapeType > _secondary_data
BMatrixPolicyType< ShapeFunctionDisplacement, DisplacementDim > BMatricesType
std::vector< IpData, Eigen::aligned_allocator< IpData > > _ip_data
std::vector< double > const & getIntPtSigma(const double, std::vector< GlobalVector * > const &, std::vector< NumLib::LocalToGlobalIndexMap const * > const &, std::vector< double > &cache) const override
constexpr int kelvin_vector_dimensions(int const displacement_dim)
Kelvin vector dimensions for given displacement dimension.
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), 1, Eigen::ColMajor > KelvinVectorType
Eigen::Matrix< double, Eigen::MatrixBase< Derived >::RowsAtCompileTime, 1 > symmetricTensorToKelvinVector(Eigen::MatrixBase< Derived > const &v)
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), kelvin_vector_dimensions(DisplacementDim), Eigen::RowMajor > KelvinMatrixType
constexpr Eigen::CwiseNullaryOp< EigenBlockMatrixViewFunctor< D, M >, typename EigenBlockMatrixViewFunctor< D, M >::Matrix > eigenBlockMatrixView(const Eigen::MatrixBase< M > &matrix)
std::array< double, 3 > interpolateCoordinates(MeshLib::Element const &e, typename ShapeMatricesType::ShapeMatrices::ShapeType const &N)
std::vector< double > const & getIntegrationPointKelvinVectorData(IntegrationPointDataVector const &ip_data_vector, MemberType IpData::*const member, std::vector< double > &cache)
RowVectorType< ShapeFunction::NPOINTS > NodalRowVectorType
BMatricesType::KelvinMatrixType updateConstitutiveRelation(MPL::VariableArray const &variable_array, double const t, ParameterLib::SpatialPosition const &x_position, double const dt, DisplacementVectorType const &, double const T)
ShapeMatricesTypeDisplacement::GlobalDimNodalMatrixType dNdx_u
std::unique_ptr< typename MaterialLib::Solids::MechanicsBase< DisplacementDim >::MaterialStateVariables > material_state_variables
ShapeMatricesTypeDisplacement::NodalRowVectorType N_u
MathLib::KelvinVector::KelvinMatrixType< DisplacementDim > computeElasticTangentStiffness(double const t, ParameterLib::SpatialPosition const &x_position, double const dt, double const temperature)
ShapeMatricesTypePressure::GlobalDimNodalMatrixType dNdx_p
ShapeMatricesTypePressure::NodalRowVectorType N_p
MaterialLib::Solids::MechanicsBase< DisplacementDim > const & solid_material
IntegrationPointData(MaterialLib::Solids::MechanicsBase< DisplacementDim > const &solid_material)
std::vector< ShapeMatrixType, Eigen::aligned_allocator< ShapeMatrixType > > N_u