OGS
SmallDeformationLocalAssemblerMatrixNearFracture-impl.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <Eigen/Core>
7#include <range/v3/range/conversion.hpp>
8#include <range/v3/view/transform.hpp>
9#include <vector>
10
16#include "MathLib/Point3d.h"
17#include "MeshLib/Node.h"
26#include "SecondaryData.h"
29
30namespace ProcessLib
31{
32namespace LIE
33{
34namespace SmallDeformation
35{
36template <typename ShapeFunction,
37
38 int DisplacementDim>
40
41 DisplacementDim>::
42 SmallDeformationLocalAssemblerMatrixNearFracture(
43 MeshLib::Element const& e,
44 std::size_t const n_variables,
45 std::size_t const /*local_matrix_size*/,
46 std::vector<unsigned> const& dofIndex_to_localIndex,
47 NumLib::GenericIntegrationMethod const& integration_method,
48 bool const is_axially_symmetric,
51 n_variables * ShapeFunction::NPOINTS * DisplacementDim,
52 dofIndex_to_localIndex),
53 _process_data(process_data),
54 _integration_method(integration_method),
55 _element(e),
56 _is_axially_symmetric(is_axially_symmetric)
57{
58 std::vector<ShapeMatrices, Eigen::aligned_allocator<
60 shape_matrices =
62 DisplacementDim>(e, is_axially_symmetric,
64
65 unsigned const n_integration_points =
66 _integration_method.getNumberOfPoints();
67
68 _ip_data.reserve(n_integration_points);
69 _secondary_data.N.resize(n_integration_points);
70
72 _process_data.solid_materials, _process_data.material_ids, e.getID());
73
74 for (unsigned ip = 0; ip < n_integration_points; ip++)
75 {
76 _ip_data.emplace_back(solid_material);
77 auto& ip_data = _ip_data[ip];
78 auto const& sm = shape_matrices[ip];
79 ip_data.N_u = sm.N;
80 ip_data.dNdx_u = sm.dNdx;
81 ip_data.integration_weight =
82 _integration_method.getWeightedPoint(ip).getWeight() *
83 sm.integralMeasure * sm.detJ;
84
85 // Initialize current time step values
86 static const int kelvin_vector_size =
88 ip_data._sigma.setZero(kelvin_vector_size);
89 ip_data._eps.setZero(kelvin_vector_size);
90
91 // Previous time step values are not initialized and are set later.
92 ip_data._sigma_prev.resize(kelvin_vector_size);
93 ip_data._eps_prev.resize(kelvin_vector_size);
94
95 ip_data._C.resize(kelvin_vector_size, kelvin_vector_size);
96
97 _secondary_data.N[ip] = sm.N;
98 }
99
100 for (auto fid : process_data.vec_ele_connected_fractureIDs[e.getID()])
101 {
102 _fracID_to_local.insert({fid, _fracture_props.size()});
103 _fracture_props.push_back(&_process_data.fracture_properties[fid]);
104 }
105
107 ranges::views::transform(
108 [&](auto const jid)
109 { return &_process_data.junction_properties[jid]; }) |
110 ranges::to<std::vector>;
111}
112
113template <typename ShapeFunction, int DisplacementDim>
116 DisplacementDim>::assembleWithJacobian(double const t, double const dt,
117 Eigen::VectorXd const& local_u,
118 Eigen::VectorXd& local_b,
119 Eigen::MatrixXd& local_J)
120{
121 assert(_element.getDimension() == DisplacementDim);
122
123 auto const N_DOF_PER_VAR = ShapeFunction::NPOINTS * DisplacementDim;
124 auto const n_fractures = _fracture_props.size();
125 auto const n_junctions = _junction_props.size();
126 auto const n_enrich_var = n_fractures + n_junctions;
127
128 using BlockVectorType =
129 typename Eigen::VectorXd::FixedSegmentReturnType<N_DOF_PER_VAR>::Type;
130 using BlockMatrixType =
131 Eigen::Block<Eigen::MatrixXd, N_DOF_PER_VAR, N_DOF_PER_VAR>;
132
133 //--------------------------------------------------------------------------------------
134 // prepare sub vectors, matrices for regular displacement (u) and
135 // displacement jumps (g)
136 //
137 // example with two fractures with one intersection:
138 // |b(u)|
139 // b = |b(g1)|
140 // |b(g2)|
141 // |b(j1)|
142 //
143 // |J(u,u) J(u,g1) J(u,g2) J(u,j1) |
144 // J = |J(g1,u) J(g1,g1) J(g1,g2) J(g1,j1)|
145 // |J(g2,u) J(g2,g1) J(g2,g2) J(g2,j1)|
146 // |J(j1,u) J(j1,g1) J(j1,g2) J(j1,j1)|
147 //--------------------------------------------------------------------------------------
148 auto local_b_u = local_b.segment<N_DOF_PER_VAR>(0);
149 std::vector<BlockVectorType> vec_local_b_g;
150 for (unsigned i = 0; i < n_enrich_var; i++)
151 {
152 vec_local_b_g.push_back(
153 local_b.segment<N_DOF_PER_VAR>(N_DOF_PER_VAR * (i + 1)));
154 }
155
156 auto local_J_uu = local_J.block<N_DOF_PER_VAR, N_DOF_PER_VAR>(0, 0);
157 std::vector<BlockMatrixType> vec_local_J_ug;
158 std::vector<BlockMatrixType> vec_local_J_gu;
159 std::vector<std::vector<BlockMatrixType>> vec_local_J_gg(n_enrich_var);
160 for (unsigned i = 0; i < n_enrich_var; i++)
161 {
162 auto sub_ug = local_J.block<N_DOF_PER_VAR, N_DOF_PER_VAR>(
163 0, N_DOF_PER_VAR * (i + 1));
164 vec_local_J_ug.push_back(sub_ug);
165
166 auto sub_gu = local_J.block<N_DOF_PER_VAR, N_DOF_PER_VAR>(
167 N_DOF_PER_VAR * (i + 1), 0);
168 vec_local_J_gu.push_back(sub_gu);
169
170 for (unsigned j = 0; j < n_enrich_var; j++)
171 {
172 auto sub_gg = local_J.block<N_DOF_PER_VAR, N_DOF_PER_VAR>(
173 N_DOF_PER_VAR * (i + 1), N_DOF_PER_VAR * (j + 1));
174 vec_local_J_gg[i].push_back(sub_gg);
175 }
176 }
177
178 auto const nodal_u = local_u.segment<N_DOF_PER_VAR>(0);
179 std::vector<BlockVectorType> vec_nodal_g;
180 for (unsigned i = 0; i < n_enrich_var; i++)
181 {
182 auto sub = const_cast<Eigen::VectorXd&>(local_u).segment<N_DOF_PER_VAR>(
183 N_DOF_PER_VAR * (i + 1));
184 vec_nodal_g.push_back(sub);
185 }
186
187 //------------------------------------------------
188 // integration
189 //------------------------------------------------
190 unsigned const n_integration_points =
191 _integration_method.getNumberOfPoints();
192
193 MPL::VariableArray variables;
194 MPL::VariableArray variables_prev;
195
196 auto const B_dil_bar = getDilatationalBBarMatrix();
197
198 for (unsigned ip = 0; ip < n_integration_points; ip++)
199 {
200 auto& ip_data = _ip_data[ip];
201 auto const& w = _ip_data[ip].integration_weight;
202
203 auto const& N = ip_data.N_u;
204 auto const& dNdx = ip_data.dNdx_u;
205
206 // levelset functions
207 Eigen::Vector3d const ip_physical_coords(
209 std::vector<double> const levelsets(
211 _fracID_to_local, ip_physical_coords));
212
213 // u = u^hat + sum_i(enrich^br_i(x) * [u]_i) + sum_i(enrich^junc_i(x) *
214 // [u]_i)
215 NodalDisplacementVectorType nodal_total_u = nodal_u;
216 for (unsigned i = 0; i < n_enrich_var; i++)
217 {
218 nodal_total_u += levelsets[i] * vec_nodal_g[i];
219 }
220
221 ParameterLib::SpatialPosition const x_position{
222 std::nullopt, this->_element.getID(),
225 this->_element, N))};
226
227 auto const x_coord =
228 x_position.getCoordinates().value()[0]; // r for axisymmetry
230 DisplacementDim, ShapeFunction::NPOINTS, BBarMatrixType,
231 typename BMatricesType::BMatrixType>(dNdx, N, B_dil_bar, x_coord,
233
234 // strain, stress
235 auto const& eps_prev = ip_data._eps_prev;
236 auto const& sigma_prev = ip_data._sigma_prev;
237
238 auto& eps = ip_data._eps;
239 auto& sigma = ip_data._sigma;
240 auto& state = ip_data._material_state_variables;
241
242 eps.noalias() = B * nodal_total_u;
243
244 variables.mechanical_strain
246 eps);
247
248 variables_prev.stress
250 sigma_prev);
251 variables_prev.mechanical_strain
253 eps_prev);
254 variables_prev.temperature = _process_data.reference_temperature;
255
256 auto&& solution = _ip_data[ip]._solid_material.integrateStress(
257 variables_prev, variables, t, x_position, dt, *state);
258
259 if (!solution)
260 {
261 OGS_FATAL("Computation of local constitutive relation failed.");
262 }
263
265 std::tie(sigma, state, C) = std::move(*solution);
266
267 // r_u = B^T * Sigma = B^T * C * B * (u+phi*[u])
268 // r_[u] = (phi*B)^T * Sigma = (phi*B)^T * C * B * (u+phi*[u])
269 local_b_u.noalias() -= B.transpose() * sigma * w;
270 for (unsigned i = 0; i < n_enrich_var; i++)
271 {
272 vec_local_b_g[i].noalias() -=
273 levelsets[i] * B.transpose() * sigma * w;
274 }
275
276 // J_uu += B^T * C * B
277 local_J_uu.noalias() += B.transpose() * C * B * w;
278
279 for (unsigned i = 0; i < n_enrich_var; i++)
280 {
281 // J_u[u] += B^T * C * (levelset * B)
282 vec_local_J_ug[i].noalias() +=
283 B.transpose() * C * (levelsets[i] * B) * w;
284
285 // J_[u]u += (levelset * B)^T * C * B
286 vec_local_J_gu[i].noalias() +=
287 (levelsets[i] * B.transpose()) * C * B * w;
288
289 for (unsigned j = 0; j < n_enrich_var; j++)
290 {
291 // J_[u][u] += (levelset * B)^T * C * (levelset * B)
292 vec_local_J_gg[i][j].noalias() +=
293 (levelsets[i] * B.transpose()) * C * (levelsets[j] * B) * w;
294 }
295 }
296 }
297}
298
299template <typename ShapeFunction,
300
301 int DisplacementDim>
303
304 DisplacementDim>::
305 computeSecondaryVariableConcreteWithVector(
306 double const /*t*/, Eigen::VectorXd const& /*local_x*/)
307{
308 // Compute average value per element
310 KV sigma_avg = KV::Zero();
311 auto const e_id = _element.getID();
312
313 unsigned const n_integration_points =
314 _integration_method.getNumberOfPoints();
315 for (unsigned ip = 0; ip < n_integration_points; ip++)
316 {
317 sigma_avg += _ip_data[ip]._sigma;
318 }
319 sigma_avg /= n_integration_points;
320
321 Eigen::Map<KV>(
322 &(*_process_data.element_stresses)[e_id * KV::RowsAtCompileTime]) =
324}
325
326template <typename ShapeFunction, int DisplacementDim>
327std::vector<double> const& SmallDeformationLocalAssemblerMatrixNearFracture<
328 ShapeFunction, DisplacementDim>::
329 getIntPtSigma(
330 const double /*t*/,
331 std::vector<GlobalVector*> const& /*x*/,
332 std::vector<NumLib::LocalToGlobalIndexMap const*> const& /*dof_table*/,
333 std::vector<double>& cache) const
334{
337}
338template <typename ShapeFunction, int DisplacementDim>
339std::vector<double> const& SmallDeformationLocalAssemblerMatrixNearFracture<
340 ShapeFunction, DisplacementDim>::
341 getIntPtEpsilon(
342 const double /*t*/,
343 std::vector<GlobalVector*> const& /*x*/,
344 std::vector<NumLib::LocalToGlobalIndexMap const*> const& /*dof_table*/,
345 std::vector<double>& cache) const
346{
349}
350
351} // namespace SmallDeformation
352} // namespace LIE
353} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:80
std::optional< MathLib::Point3d > const getCoordinates() const
MatrixType< _kelvin_vector_size, _number_of_dof > BMatrixType
void assembleWithJacobian(double const t, double const dt, Eigen::VectorXd const &local_u, Eigen::VectorXd &local_b, Eigen::MatrixXd &local_J) override
std::vector< IntegrationPointDataType, Eigen::aligned_allocator< IntegrationPointDataType > > _ip_data
auto & selectSolidConstitutiveRelation(SolidMaterialsMap const &constitutive_relations, MeshLib::PropertyVector< int > const *const material_ids, std::size_t const element_id)
Eigen::Matrix< double, 4, 1 > kelvinVectorToSymmetricTensor(Eigen::Matrix< double, 4, 1, Eigen::ColMajor, 4, 1 > const &v)
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, kelvin_vector_dimensions(DisplacementDim), kelvin_vector_dimensions(DisplacementDim), Eigen::RowMajor > KelvinMatrixType
std::vector< typename ShapeMatricesType::ShapeMatrices, Eigen::aligned_allocator< typename ShapeMatricesType::ShapeMatrices > > initShapeMatrices(MeshLib::Element const &e, bool const is_axially_symmetric, IntegrationMethod const &integration_method)
std::array< double, 3 > interpolateCoordinates(MeshLib::Element const &e, typename ShapeMatricesType::ShapeMatrices::ShapeType const &N)
Eigen::Vector3d computePhysicalCoordinates(MeshLib::Element const &e, Eigen::MatrixBase< Derived > const &shape)
std::vector< double > uGlobalEnrichments(std::vector< FractureProperty * > const &frac_props, std::vector< JunctionProperty * > const &junction_props, std::unordered_map< int, int > const &fracID_to_local, Eigen::Vector3d const &x)
BMatrixType computeBMatrixPossiblyWithBbar(DNDX_Type const &dNdx, N_Type const &N, std::optional< BBarMatrixType > const &B_dil_bar, const double radius, const bool is_axially_symmetric)
Fills a B matrix, or a B bar matrix if required.
std::vector< double > const & getIntegrationPointKelvinVectorData(IntegrationPointDataVector const &ip_data_vector, MemberType IpData::*const member, std::vector< double > &cache)
NumLib::ShapeMatrices< NodalRowVectorType, DimNodalMatrixType, DimMatrixType, GlobalDimNodalMatrixType > ShapeMatrices