OGS
SmallDeformationLocalAssemblerMatrixNearFracture-impl.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <Eigen/Eigen>
14 #include <valarray>
15 #include <vector>
16 
19 #include "MathLib/KelvinVector.h"
21 #include "MathLib/Point3d.h"
22 #include "MeshLib/Node.h"
30 #include "SecondaryData.h"
33 
34 namespace ProcessLib
35 {
36 namespace LIE
37 {
38 namespace SmallDeformation
39 {
40 template <typename ShapeFunction,
41  typename IntegrationMethod,
42  int DisplacementDim>
43 SmallDeformationLocalAssemblerMatrixNearFracture<ShapeFunction,
44  IntegrationMethod,
45  DisplacementDim>::
46  SmallDeformationLocalAssemblerMatrixNearFracture(
47  MeshLib::Element const& e,
48  std::size_t const n_variables,
49  std::size_t const /*local_matrix_size*/,
50  std::vector<unsigned> const& dofIndex_to_localIndex,
51  bool const is_axially_symmetric,
52  unsigned const integration_order,
55  n_variables * ShapeFunction::NPOINTS * DisplacementDim,
56  dofIndex_to_localIndex),
57  _process_data(process_data),
58  _integration_method(integration_order),
59  _element(e),
60  _is_axially_symmetric(is_axially_symmetric)
61 {
62  std::vector<ShapeMatrices, Eigen::aligned_allocator<
64  shape_matrices =
66  DisplacementDim>(e, is_axially_symmetric,
68 
69  unsigned const n_integration_points =
70  _integration_method.getNumberOfPoints();
71 
72  _ip_data.reserve(n_integration_points);
73  _secondary_data.N.resize(n_integration_points);
74 
76  _process_data.solid_materials, _process_data.material_ids, e.getID());
77 
78  for (unsigned ip = 0; ip < n_integration_points; ip++)
79  {
80  _ip_data.emplace_back(solid_material);
81  auto& ip_data = _ip_data[ip];
82  auto const& sm = shape_matrices[ip];
83  ip_data.N = sm.N;
84  ip_data.dNdx = sm.dNdx;
85  ip_data.integration_weight =
86  _integration_method.getWeightedPoint(ip).getWeight() *
87  sm.integralMeasure * sm.detJ;
88 
89  // Initialize current time step values
90  static const int kelvin_vector_size =
92  ip_data._sigma.setZero(kelvin_vector_size);
93  ip_data._eps.setZero(kelvin_vector_size);
94 
95  // Previous time step values are not initialized and are set later.
96  ip_data._sigma_prev.resize(kelvin_vector_size);
97  ip_data._eps_prev.resize(kelvin_vector_size);
98 
99  ip_data._C.resize(kelvin_vector_size, kelvin_vector_size);
100 
101  _secondary_data.N[ip] = sm.N;
102  }
103 
104  for (auto fid : process_data._vec_ele_connected_fractureIDs[e.getID()])
105  {
106  _fracID_to_local.insert({fid, _fracture_props.size()});
107  _fracture_props.push_back(&_process_data.fracture_properties[fid]);
108  }
109 
110  for (auto jid : process_data._vec_ele_connected_junctionIDs[e.getID()])
111  {
112  _junction_props.push_back(&_process_data.junction_properties[jid]);
113  }
114 }
115 
116 template <typename ShapeFunction, typename IntegrationMethod,
117  int DisplacementDim>
119  ShapeFunction, IntegrationMethod,
120  DisplacementDim>::assembleWithJacobian(double const t, double const dt,
121  Eigen::VectorXd const& local_u,
122  Eigen::VectorXd& local_b,
123  Eigen::MatrixXd& local_J)
124 {
125  assert(_element.getDimension() == DisplacementDim);
126 
127  auto const N_DOF_PER_VAR = ShapeFunction::NPOINTS * DisplacementDim;
128  auto const n_fractures = _fracture_props.size();
129  auto const n_junctions = _junction_props.size();
130  auto const n_enrich_var = n_fractures + n_junctions;
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  //--------------------------------------------------------------------------------------
138  // prepare sub vectors, matrices for regular displacement (u) and
139  // displacement jumps (g)
140  //
141  // example with two fractures with one intersection:
142  // |b(u)|
143  // b = |b(g1)|
144  // |b(g2)|
145  // |b(j1)|
146  //
147  // |J(u,u) J(u,g1) J(u,g2) J(u,j1) |
148  // J = |J(g1,u) J(g1,g1) J(g1,g2) J(g1,j1)|
149  // |J(g2,u) J(g2,g1) J(g2,g2) J(g2,j1)|
150  // |J(j1,u) J(j1,g1) J(j1,g2) J(j1,j1)|
151  //--------------------------------------------------------------------------------------
152  auto local_b_u = local_b.segment<N_DOF_PER_VAR>(0);
153  std::vector<BlockVectorType> vec_local_b_g;
154  for (unsigned i = 0; i < n_enrich_var; i++)
155  {
156  vec_local_b_g.push_back(
157  local_b.segment<N_DOF_PER_VAR>(N_DOF_PER_VAR * (i + 1)));
158  }
159 
160  auto local_J_uu = local_J.block<N_DOF_PER_VAR, N_DOF_PER_VAR>(0, 0);
161  std::vector<BlockMatrixType> vec_local_J_ug;
162  std::vector<BlockMatrixType> vec_local_J_gu;
163  std::vector<std::vector<BlockMatrixType>> vec_local_J_gg(n_enrich_var);
164  for (unsigned i = 0; i < n_enrich_var; i++)
165  {
166  auto sub_ug = local_J.block<N_DOF_PER_VAR, N_DOF_PER_VAR>(
167  0, N_DOF_PER_VAR * (i + 1));
168  vec_local_J_ug.push_back(sub_ug);
169 
170  auto sub_gu = local_J.block<N_DOF_PER_VAR, N_DOF_PER_VAR>(
171  N_DOF_PER_VAR * (i + 1), 0);
172  vec_local_J_gu.push_back(sub_gu);
173 
174  for (unsigned j = 0; j < n_enrich_var; j++)
175  {
176  auto sub_gg = local_J.block<N_DOF_PER_VAR, N_DOF_PER_VAR>(
177  N_DOF_PER_VAR * (i + 1), N_DOF_PER_VAR * (j + 1));
178  vec_local_J_gg[i].push_back(sub_gg);
179  }
180  }
181 
182  auto const nodal_u = local_u.segment<N_DOF_PER_VAR>(0);
183  std::vector<BlockVectorType> vec_nodal_g;
184  for (unsigned i = 0; i < n_enrich_var; i++)
185  {
186  auto sub = const_cast<Eigen::VectorXd&>(local_u).segment<N_DOF_PER_VAR>(
187  N_DOF_PER_VAR * (i + 1));
188  vec_nodal_g.push_back(sub);
189  }
190 
191  //------------------------------------------------
192  // integration
193  //------------------------------------------------
194  unsigned const n_integration_points =
195  _integration_method.getNumberOfPoints();
196 
197  MPL::VariableArray variables;
198  MPL::VariableArray variables_prev;
200  x_position.setElementID(_element.getID());
201 
202  for (unsigned ip = 0; ip < n_integration_points; ip++)
203  {
204  x_position.setIntegrationPoint(ip);
205 
206  auto& ip_data = _ip_data[ip];
207  auto const& w = _ip_data[ip].integration_weight;
208 
209  auto const& N = ip_data.N;
210  auto const& dNdx = ip_data.dNdx;
211 
212  // levelset functions
213  Eigen::Vector3d const ip_physical_coords(
214  computePhysicalCoordinates(_element, N).getCoords());
215  std::vector<double> const levelsets(
216  uGlobalEnrichments(_fracture_props, _junction_props,
217  _fracID_to_local, ip_physical_coords));
218 
219  // u = u^hat + sum_i(enrich^br_i(x) * [u]_i) + sum_i(enrich^junc_i(x) *
220  // [u]_i)
221  NodalDisplacementVectorType nodal_total_u = nodal_u;
222  for (unsigned i = 0; i < n_enrich_var; i++)
223  {
224  nodal_total_u += levelsets[i] * vec_nodal_g[i];
225  }
226 
227  auto const x_coord =
228  NumLib::interpolateXCoordinate<ShapeFunction, ShapeMatricesType>(
229  _element, N);
230  auto const B =
231  LinearBMatrix::computeBMatrix<DisplacementDim,
232  ShapeFunction::NPOINTS,
233  typename BMatricesType::BMatrixType>(
234  dNdx, N, x_coord, _is_axially_symmetric);
235 
236  // strain, stress
237  auto const& eps_prev = ip_data._eps_prev;
238  auto const& sigma_prev = ip_data._sigma_prev;
239 
240  auto& eps = ip_data._eps;
241  auto& sigma = ip_data._sigma;
242  auto& state = ip_data._material_state_variables;
243 
244  eps.noalias() = B * nodal_total_u;
245 
246  variables[static_cast<int>(
249  eps);
250 
251  variables_prev[static_cast<int>(MaterialPropertyLib::Variable::stress)]
253  sigma_prev);
254  variables_prev[static_cast<int>(
257  eps_prev);
258  variables_prev[static_cast<int>(
260  .emplace<double>(_process_data._reference_temperature);
261 
262  auto&& solution = _ip_data[ip]._solid_material.integrateStress(
263  variables_prev, variables, t, x_position, dt, *state);
264 
265  if (!solution)
266  {
267  OGS_FATAL("Computation of local constitutive relation failed.");
268  }
269 
271  std::tie(sigma, state, C) = std::move(*solution);
272 
273  // r_u = B^T * Sigma = B^T * C * B * (u+phi*[u])
274  // r_[u] = (phi*B)^T * Sigma = (phi*B)^T * C * B * (u+phi*[u])
275  local_b_u.noalias() -= B.transpose() * sigma * w;
276  for (unsigned i = 0; i < n_enrich_var; i++)
277  {
278  vec_local_b_g[i].noalias() -=
279  levelsets[i] * B.transpose() * sigma * w;
280  }
281 
282  // J_uu += B^T * C * B
283  local_J_uu.noalias() += B.transpose() * C * B * w;
284 
285  for (unsigned i = 0; i < n_enrich_var; i++)
286  {
287  // J_u[u] += B^T * C * (levelset * B)
288  vec_local_J_ug[i].noalias() +=
289  B.transpose() * C * (levelsets[i] * B) * w;
290 
291  // J_[u]u += (levelset * B)^T * C * B
292  vec_local_J_gu[i].noalias() +=
293  (levelsets[i] * B.transpose()) * C * B * w;
294 
295  for (unsigned j = 0; j < n_enrich_var; j++)
296  {
297  // J_[u][u] += (levelset * B)^T * C * (levelset * B)
298  vec_local_J_gg[i][j].noalias() +=
299  (levelsets[i] * B.transpose()) * C * (levelsets[j] * B) * w;
300  }
301  }
302  }
303 }
304 
305 template <typename ShapeFunction,
306  typename IntegrationMethod,
307  int DisplacementDim>
309  IntegrationMethod,
310  DisplacementDim>::
311  computeSecondaryVariableConcreteWithVector(
312  double const /*t*/, Eigen::VectorXd const& /*local_x*/)
313 {
314  // Compute average value per element
315  const int n = DisplacementDim == 2 ? 4 : 6;
316  Eigen::VectorXd ele_stress = Eigen::VectorXd::Zero(n);
317  Eigen::VectorXd ele_strain = Eigen::VectorXd::Zero(n);
318 
319  unsigned const n_integration_points =
320  _integration_method.getNumberOfPoints();
321  for (unsigned ip = 0; ip < n_integration_points; ip++)
322  {
323  auto& ip_data = _ip_data[ip];
324 
325  ele_stress += ip_data._sigma;
326  ele_strain += ip_data._eps;
327  }
328  ele_stress /= n_integration_points;
329  ele_strain /= n_integration_points;
330 
331  (*_process_data._mesh_prop_stress_xx)[_element.getID()] = ele_stress[0];
332  (*_process_data._mesh_prop_stress_yy)[_element.getID()] = ele_stress[1];
333  (*_process_data._mesh_prop_stress_zz)[_element.getID()] = ele_stress[2];
334  (*_process_data._mesh_prop_stress_xy)[_element.getID()] = ele_stress[3];
335  if (DisplacementDim == 3)
336  {
337  (*_process_data._mesh_prop_stress_yz)[_element.getID()] = ele_stress[4];
338  (*_process_data._mesh_prop_stress_xz)[_element.getID()] = ele_stress[5];
339  }
340 
341  (*_process_data._mesh_prop_strain_xx)[_element.getID()] = ele_strain[0];
342  (*_process_data._mesh_prop_strain_yy)[_element.getID()] = ele_strain[1];
343  (*_process_data._mesh_prop_strain_zz)[_element.getID()] = ele_strain[2];
344  (*_process_data._mesh_prop_strain_xy)[_element.getID()] = ele_strain[3];
345  if (DisplacementDim == 3)
346  {
347  (*_process_data._mesh_prop_strain_yz)[_element.getID()] = ele_strain[4];
348  (*_process_data._mesh_prop_strain_xz)[_element.getID()] = ele_strain[5];
349  }
350 }
351 
352 } // namespace SmallDeformation
353 } // namespace LIE
354 } // namespace ProcessLib
#define OGS_FATAL(...)
Definition: Error.h:26
Definition of the Node class.
Definition of the Point3d class.
virtual std::size_t getID() const final
Returns the ID of the element.
Definition: Element.h:82
void setElementID(std::size_t element_id)
void setIntegrationPoint(unsigned integration_point)
MatrixType< _kelvin_vector_size, _number_of_dof > BMatrixType
Definition: BMatrixPolicy.h:55
std::vector< IntegrationPointDataMatrix< ShapeMatricesType, BMatricesType, DisplacementDim >, Eigen::aligned_allocator< IntegrationPointDataMatrix< ShapeMatricesType, BMatricesType, DisplacementDim > > > _ip_data
MechanicsBase< DisplacementDim > & selectSolidConstitutiveRelation(std::map< int, std::unique_ptr< MechanicsBase< DisplacementDim >>> const &constitutive_relations, MeshLib::PropertyVector< int > const *const material_ids, std::size_t const element_id)
std::array< VariableType, static_cast< int >(Variable::number_of_variables)> VariableArray
Definition: VariableType.h:108
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), 1, Eigen::ColMajor > KelvinVectorType
Definition: KelvinVector.h:48
constexpr int kelvin_vector_dimensions(int const displacement_dim)
Kelvin vector dimensions for given displacement dimension.
Definition: KelvinVector.h:23
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), kelvin_vector_dimensions(DisplacementDim), Eigen::RowMajor > KelvinMatrixType
Definition: KelvinVector.h:56
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)
MathLib::Point3d computePhysicalCoordinates(MeshLib::Element const &e, Eigen::MatrixBase< Derived > const &shape)
Definition: Utils.h:24
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 computeBMatrix(DNDX_Type const &dNdx, N_Type const &N, const double radius, const bool is_axially_symmetric)
Fills a B-matrix based on given shape function dN/dx values.
Definition: LinearBMatrix.h:42
Coordinates mapping matrices at particular location.
Definition: ShapeMatrices.h:43
std::vector< ShapeMatrixType, Eigen::aligned_allocator< ShapeMatrixType > > N
Definition: SecondaryData.h:28