OGS
SmallDeformationLocalAssemblerFracture-impl.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <Eigen/Core>
14#include <range/v3/range/conversion.hpp>
15#include <range/v3/view/transform.hpp>
16
22
23namespace ProcessLib
24{
25namespace LIE
26{
27namespace SmallDeformation
28{
29template <typename ShapeFunction, int DisplacementDim>
32 MeshLib::Element const& e,
33 std::size_t const n_variables,
34 std::size_t const /*local_matrix_size*/,
35 std::vector<unsigned> const& dofIndex_to_localIndex,
36 NumLib::GenericIntegrationMethod const& integration_method,
37 bool const is_axially_symmetric,
40 n_variables * ShapeFunction::NPOINTS * DisplacementDim,
41 dofIndex_to_localIndex),
42 _process_data(process_data),
43 _integration_method(integration_method),
44 _shape_matrices(
45 NumLib::initShapeMatrices<ShapeFunction, ShapeMatricesType,
46 DisplacementDim>(e, is_axially_symmetric,
47 _integration_method)),
48 _element(e)
49{
50 assert(_element.getDimension() == DisplacementDim - 1);
51
52 unsigned const n_integration_points =
54
55 _ip_data.reserve(n_integration_points);
56 _secondary_data.N.resize(n_integration_points);
57
58 auto mat_id = (*_process_data._mesh_prop_materialIDs)[e.getID()];
59 auto frac_id = _process_data._map_materialID_to_fractureID[mat_id];
60 _fracture_property = &_process_data.fracture_properties[frac_id];
61 for (auto fid : process_data._vec_ele_connected_fractureIDs[e.getID()])
62 {
63 _fracID_to_local.insert({fid, _fracture_props.size()});
64 _fracture_props.push_back(&_process_data.fracture_properties[fid]);
65 }
66
68 ranges::views::transform(
69 [&](auto const jid)
70 { return &_process_data.junction_properties[jid]; }) |
71 ranges::to<std::vector>;
72
74 x_position.setElementID(_element.getID());
75 for (unsigned ip = 0; ip < n_integration_points; ip++)
76 {
77 x_position.setIntegrationPoint(ip);
78
79 _ip_data.emplace_back(*_process_data._fracture_model);
80 auto const& sm = _shape_matrices[ip];
81 auto& ip_data = _ip_data[ip];
82 ip_data.integration_weight =
84 sm.integralMeasure * sm.detJ;
85 ip_data.h_matrices.setZero(DisplacementDim,
86 ShapeFunction::NPOINTS * DisplacementDim);
87
88 computeHMatrix<DisplacementDim, ShapeFunction::NPOINTS,
90 HMatrixType>(sm.N, ip_data.h_matrices);
91
92 // Initialize current time step values
93 ip_data.w.setZero(DisplacementDim);
94 ip_data.sigma.setZero(DisplacementDim);
95
96 // Previous time step values are not initialized and are set later.
97 ip_data.sigma_prev.resize(DisplacementDim);
98 ip_data.w_prev.resize(DisplacementDim);
99
100 ip_data.C.resize(DisplacementDim, DisplacementDim);
101
102 ip_data.aperture0 = _fracture_property->aperture0(0, x_position)[0];
103 ip_data.aperture_prev = ip_data.aperture0;
104
105 _secondary_data.N[ip] = sm.N;
106 }
107}
108
109template <typename ShapeFunction, int DisplacementDim>
111 assembleWithJacobian(double const t, double const /*dt*/,
112 Eigen::VectorXd const& local_u,
113 Eigen::VectorXd& local_b, Eigen::MatrixXd& local_J)
114{
115 auto const N_DOF_PER_VAR = ShapeFunction::NPOINTS * DisplacementDim;
116 auto const n_fractures = _fracture_props.size();
117 auto const n_junctions = _junction_props.size();
118 auto const n_enrich_var = n_fractures + n_junctions;
119
120 //--------------------------------------------------------------------------------------
121 // prepare sub vectors, matrices for regular displacement (u) and
122 // displacement jumps (g)
123 //
124 // example with two fractures with one intersection:
125 // b = |b(g1)|
126 // |b(g2)|
127 //
128 // J = |J(g1,g1) J(g1,g2)|
129 // |J(g2,g1) J(g2,g2)|
130 //--------------------------------------------------------------------------------------
131
132 using BlockVectorType =
133 typename Eigen::VectorXd::FixedSegmentReturnType<N_DOF_PER_VAR>::Type;
134 using BlockMatrixType =
135 Eigen::Block<Eigen::MatrixXd, N_DOF_PER_VAR, N_DOF_PER_VAR>;
136
137 std::vector<BlockVectorType> vec_local_b_g;
138 for (unsigned i = 0; i < n_enrich_var; i++)
139 {
140 vec_local_b_g.push_back(
141 local_b.segment<N_DOF_PER_VAR>(N_DOF_PER_VAR * i));
142 }
143 std::vector<std::vector<BlockMatrixType>> vec_local_J_gg(n_enrich_var);
144 for (unsigned i = 0; i < n_enrich_var; i++)
145 {
146 for (unsigned j = 0; j < n_enrich_var; j++)
147 {
148 auto sub_gg = local_J.block<N_DOF_PER_VAR, N_DOF_PER_VAR>(
149 N_DOF_PER_VAR * i, N_DOF_PER_VAR * j);
150 vec_local_J_gg[i].push_back(sub_gg);
151 }
152 }
153
154 std::vector<Eigen::VectorXd> vec_nodal_g;
155 for (unsigned i = 0; i < n_enrich_var; i++)
156 {
157 auto sub = const_cast<Eigen::VectorXd&>(local_u).segment<N_DOF_PER_VAR>(
158 N_DOF_PER_VAR * i);
159 vec_nodal_g.push_back(sub);
160 }
161
162 //------------------------------------------------
163 // integration
164 //------------------------------------------------
165 // the index of a normal (normal to a fracture plane) component
166 // in a displacement vector
167 int const index_normal = DisplacementDim - 1;
168 auto const& R = _fracture_property->R;
169
170 unsigned const n_integration_points =
171 _integration_method.getNumberOfPoints();
172
174 x_position.setElementID(_element.getID());
175
176 for (unsigned ip = 0; ip < n_integration_points; ip++)
177 {
178 x_position.setIntegrationPoint(ip);
179
180 auto& ip_data = _ip_data[ip];
181 auto const& integration_weight = ip_data.integration_weight;
182 auto const& H = ip_data.h_matrices;
183 auto& mat = ip_data.fracture_material;
184 auto& sigma = ip_data.sigma;
185 auto const& sigma_prev = ip_data.sigma_prev;
186 auto& w = ip_data.w;
187 auto const& w_prev = ip_data.w_prev;
188 auto& C = ip_data.C;
189 auto& state = *ip_data.material_state_variables;
190 auto const& N = _secondary_data.N[ip];
191
192 auto const ip_physical_coords(computePhysicalCoordinates(_element, N));
193 std::vector<double> const levelsets(duGlobalEnrichments(
194 _fracture_property->fracture_id, _fracture_props, _junction_props,
195 _fracID_to_local, ip_physical_coords));
196
197 // du = du^hat + sum_i(enrich^br_i(x) * [u]_i) + sum_i(enrich^junc_i(x)
198 // * [u]_i)
199 Eigen::VectorXd nodal_gap(N_DOF_PER_VAR);
200 nodal_gap.setZero();
201 for (unsigned i = 0; i < n_enrich_var; i++)
202 {
203 nodal_gap += levelsets[i] * vec_nodal_g[i];
204 }
205
206 // displacement jumps
207 w.noalias() = R * H * nodal_gap;
208
209 // total aperture
210 ip_data.aperture = ip_data.aperture0 + w[index_normal];
211
212 // local C, local stress
213 mat.computeConstitutiveRelation(
214 t, x_position, ip_data.aperture0,
215 Eigen::Matrix<double, DisplacementDim, 1>::Zero(), // TODO (naumov)
216 // Replace with
217 // initial
218 // stress values
219 w_prev, w, sigma_prev, sigma, C, state);
220
221 // r_[u] += H^T*Stress
222 for (unsigned i = 0; i < n_enrich_var; i++)
223 {
224 vec_local_b_g[i].noalias() -= levelsets[i] * H.transpose() *
225 R.transpose() * sigma *
226 integration_weight;
227 }
228
229 // J_[u][u] += H^T*C*H
230 for (unsigned i = 0; i < n_enrich_var; i++)
231 {
232 for (unsigned j = 0; j < n_enrich_var; j++)
233 {
234 // J_[u][u] += (levelset * B)^T * C * (levelset * B)
235 vec_local_J_gg[i][j].noalias() +=
236 (levelsets[i] * H.transpose() * R.transpose()) * C *
237 (levelsets[j] * R * H) * integration_weight;
238 }
239 }
240 }
241}
242
243template <typename ShapeFunction, int DisplacementDim>
246 Eigen::VectorXd const& local_u)
247{
248 auto const N_DOF_PER_VAR = ShapeFunction::NPOINTS * DisplacementDim;
249 auto const n_fractures = _fracture_props.size();
250 auto const n_junctions = _junction_props.size();
251 auto const n_enrich_var = n_fractures + n_junctions;
252
253 auto const& R = _fracture_property->R;
254
255 // the index of a normal (normal to a fracture plane) component
256 // in a displacement vector
257 int const index_normal = DisplacementDim - 1;
258
259 unsigned const n_integration_points =
260 _integration_method.getNumberOfPoints();
261
263 x_position.setElementID(_element.getID());
264
265 std::vector<Eigen::VectorXd> vec_nodal_g;
266 for (unsigned i = 0; i < n_enrich_var; i++)
267 {
268 auto sub = const_cast<Eigen::VectorXd&>(local_u).segment<N_DOF_PER_VAR>(
269 N_DOF_PER_VAR * i);
270 vec_nodal_g.push_back(sub);
271 }
272
273 for (unsigned ip = 0; ip < n_integration_points; ip++)
274 {
275 x_position.setIntegrationPoint(ip);
276
277 auto& ip_data = _ip_data[ip];
278 auto const& H = ip_data.h_matrices;
279 auto& mat = ip_data.fracture_material;
280 auto& sigma = ip_data.sigma;
281 auto const& sigma_prev = ip_data.sigma_prev;
282 auto& w = ip_data.w;
283 auto const& w_prev = ip_data.w_prev;
284 auto& C = ip_data.C;
285 auto& state = *ip_data.material_state_variables;
286 auto& b_m = ip_data.aperture;
287 auto const& N = _secondary_data.N[ip];
288
289 auto const ip_physical_coords(computePhysicalCoordinates(_element, N));
290 std::vector<double> const levelsets(duGlobalEnrichments(
291 _fracture_property->fracture_id, _fracture_props, _junction_props,
292 _fracID_to_local, ip_physical_coords));
293
294 // du = du^hat + sum_i(enrich^br_i(x) * [u]_i) + sum_i(enrich^junc_i(x)
295 // * [u]_i)
296 Eigen::VectorXd nodal_gap(N_DOF_PER_VAR);
297 nodal_gap.setZero();
298 for (unsigned i = 0; i < n_enrich_var; i++)
299 {
300 nodal_gap += levelsets[i] * vec_nodal_g[i];
301 }
302
303 // displacement jumps in local coordinates
304 w.noalias() = R * H * nodal_gap;
305
306 // aperture
307 b_m = ip_data.aperture0 + w[index_normal];
308 if (b_m < 0.0)
309 {
310 OGS_FATAL(
311 "Element {:d}, gp {:d}: Fracture aperture is {:g}, but it must "
312 "be non-negative.",
313 _element.getID(), ip, b_m);
314 }
315
316 // local C, local stress
317 mat.computeConstitutiveRelation(
318 t, x_position, ip_data.aperture0,
319 Eigen::Matrix<double, DisplacementDim, 1>::Zero(), // TODO (naumov)
320 // Replace with
321 // initial
322 // stress values
323 w_prev, w, sigma_prev, sigma, C, state);
324 }
325
326 double ele_b = 0;
327 typename HMatricesType::ForceVectorType ele_sigma =
328 HMatricesType::ForceVectorType::Zero(DisplacementDim);
329 typename HMatricesType::ForceVectorType ele_w =
330 HMatricesType::ForceVectorType::Zero(DisplacementDim);
331
332 for (unsigned ip = 0; ip < n_integration_points; ip++)
333 {
334 auto const& ip_data = _ip_data[ip];
335 ele_b += ip_data.aperture;
336 ele_w += ip_data.w;
337 ele_sigma += ip_data.sigma;
338 }
339 ele_b /= n_integration_points;
340 ele_w /= n_integration_points;
341 ele_sigma /= n_integration_points;
342 (*_process_data._mesh_prop_b)[_element.getID()] = ele_b;
343 (*_process_data._mesh_prop_w_n)[_element.getID()] = ele_w[index_normal];
344 (*_process_data._mesh_prop_w_s)[_element.getID()] = ele_w[0];
345 (*_process_data._mesh_prop_fracture_stress_normal)[_element.getID()] =
346 ele_sigma[index_normal];
347 (*_process_data._mesh_prop_fracture_stress_shear)[_element.getID()] =
348 ele_sigma[0];
349}
350
351} // namespace SmallDeformation
352} // namespace LIE
353} // namespace ProcessLib
#define OGS_FATAL(...)
Definition: Error.h:26
double getWeight() const
Definition: WeightedPoint.h:80
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
virtual std::size_t getID() const final
Returns the ID of the element.
Definition: Element.h:89
MathLib::WeightedPoint const & getWeightedPoint(unsigned const igp) const
void setElementID(std::size_t element_id)
void setIntegrationPoint(unsigned integration_point)
VectorType< DisplacementDim > ForceVectorType
Definition: HMatrixUtils.h:45
std::vector< IntegrationPointDataFracture< HMatricesType, DisplacementDim >, Eigen::aligned_allocator< IntegrationPointDataFracture< HMatricesType, DisplacementDim > > > _ip_data
void computeSecondaryVariableConcreteWithVector(const double t, Eigen::VectorXd const &local_u) override
void assembleWithJacobian(double const t, double const dt, Eigen::VectorXd const &local_u, Eigen::VectorXd &local_b, Eigen::MatrixXd &local_J) override
SmallDeformationLocalAssemblerFracture(SmallDeformationLocalAssemblerFracture const &)=delete
std::vector< ShapeMatrices, Eigen::aligned_allocator< typename ShapeMatricesType::ShapeMatrices > > _shape_matrices
std::vector< double > duGlobalEnrichments(std::size_t this_frac_id, 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)
Eigen::Vector3d computePhysicalCoordinates(MeshLib::Element const &e, Eigen::MatrixBase< Derived > const &shape)
Definition: Utils.h:24
void computeHMatrix(N_Type const &N, HMatrixType &H)
Fills a H-matrix based on given shape function.
Definition: HMatrixUtils.h:53
RowVectorType< ShapeFunction::NPOINTS > NodalRowVectorType
std::vector< ShapeMatrixType, Eigen::aligned_allocator< ShapeMatrixType > > N
Definition: SecondaryData.h:27
ParameterLib::Parameter< double > const & aperture0
Initial aperture.