Flow123d  DF_patch_fe_darcy_complete-579fe1e
assembly_elasticity.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file assembly_elasticity.hh
15  * @brief
16  */
17 
18 #ifndef ASSEMBLY_ELASTICITY_HH_
19 #define ASSEMBLY_ELASTICITY_HH_
20 
23 #include "mechanics/elasticity.hh"
24 #include "fem/fe_p.hh"
25 #include "fem/fe_values.hh"
26 #include "fem/patch_op_impl.hh"
28 #include "coupling/balance.hh"
29 #include "fem/element_cache_map.hh"
30 
31 
32 /**
33  * Auxiliary container class for Finite element and related objects of given dimension.
34  */
35 template <unsigned int dim, class TEqData>
37 {
38 public:
39  typedef typename TEqData::EqFields EqFields;
40  typedef TEqData EqData;
41 
42  static constexpr const char * name() { return "Elasticity_Stiffness_Assembly"; }
43 
44  /// Constructor.
46  : AssemblyBasePatch<dim>(eq_data->quad_order(), asm_internals), eq_fields_(eq_data->eq_fields_.get()), eq_data_(eq_data), // quad_order = 1
50  JxW_( bulk_integral_->JxW() ),
51  JxW_side_( bdr_integral_->JxW() ),
52  JxW_join_( coupling_integral_->JxW() ),
53  normal_( bdr_integral_->normal_vector() ),
54  normal_join_( coupling_integral_->normal_vector() ),
55  deform_side_( bdr_integral_->vector_shape() ),
56  grad_deform_( bulk_integral_->grad_vector_shape() ),
57  sym_grad_deform_( bulk_integral_->vector_sym_grad() ),
58  deform_join_( coupling_integral_->vector_join_shape() ),
59  deform_join_grad_( coupling_integral_->gradient_vector_join_shape() ) {
60  this->used_fields_ += eq_fields_->cross_section;
61  this->used_fields_ += eq_fields_->lame_mu;
62  this->used_fields_ += eq_fields_->lame_lambda;
63  this->used_fields_ += eq_fields_->dirichlet_penalty;
64  this->used_fields_ += eq_fields_->bc_type;
65  this->used_fields_ += eq_fields_->fracture_sigma;
66  }
67 
68  /// Destructor.
70 
71  /// Initialize auxiliary vectors and other data members
72  void initialize() {
73  //this->balance_ = eq_data_->balance_;
74  shared_ptr<FE_P<dim-1>> fe_p_low = std::make_shared< FE_P<dim-1> >(1);
75  shared_ptr<FiniteElement<dim-1>> fe_low = std::make_shared<FESystem<dim-1>>(fe_p_low, FEVector, 3);
76 
77  n_dofs_ = this->n_dofs();
78  n_dofs_high_ = this->n_dofs_high();
80  dof_indices_.resize(n_dofs_high_);
83  }
84 
85 
86  /// Assemble integral over element
87  inline void cell_integral(DHCellAccessor cell, unsigned int element_patch_idx)
88  {
89  if (cell.dim() != dim) return;
90 
91  // Fracture stiffness is assembled in dimjoin_integral.
92  if (cell.elm()->n_neighs_vb() > 0) return;
93 
95 
96  // assemble the local stiffness matrix
97  for (unsigned int i=0; i<n_dofs_; i++)
98  for (unsigned int j=0; j<n_dofs_; j++)
99  local_matrix_[i*n_dofs_+j] = 0;
100 
101  for (auto p : bulk_integral_->points(element_patch_idx) )
102  {
103  for (unsigned int i=0; i<n_dofs_; i++)
104  {
105  for (unsigned int j=0; j<n_dofs_; j++)
106  local_matrix_[i*n_dofs_+j] += eq_fields_->cross_section(p)*(
107  arma::dot(eq_fields_->stress_tensor(p,sym_grad_deform_.shape(j)(p)), sym_grad_deform_.shape(i)(p))
108  )*JxW_(p);
109  }
110  }
111  eq_data_->ls->mat_set_values(n_dofs_, dof_indices_.data(), n_dofs_, dof_indices_.data(), &(local_matrix_[0]));
112  }
113 
114  /// Assembles boundary integral.
115  inline void boundary_side_integral(DHCellSide cell_side)
116  {
117  ASSERT_EQ(cell_side.dim(), dim).error("Dimension of element mismatch!");
118  if (!cell_side.cell().is_own()) return;
119 
120  Side side = cell_side.side();
121  const DHCellAccessor &dh_cell = cell_side.cell();
122  dh_cell.get_dof_indices(dof_indices_);
123 
124  for (unsigned int i=0; i<n_dofs_; i++)
125  for (unsigned int j=0; j<n_dofs_; j++)
126  local_matrix_[i*n_dofs_+j] = 0;
127 
128  auto p_side = *( bdr_integral_->points(cell_side).begin() );
129  auto p_bdr = p_side.point_bdr( side.cond().element_accessor() );
130  unsigned int bc_type = eq_fields_->bc_type(p_bdr);
131  double side_measure = cell_side.measure();
132  if (bc_type == EqFields::bc_type_displacement)
133  {
134  for (auto p : bdr_integral_->points(cell_side) ) {
135  for (unsigned int i=0; i<n_dofs_; i++)
136  for (unsigned int j=0; j<n_dofs_; j++)
137  local_matrix_[i*n_dofs_+j] += (eq_fields_->dirichlet_penalty(p) / side_measure) *
138  arma::dot(deform_side_.shape(i)(p),deform_side_.shape(j)(p)) * JxW_side_(p);
139  }
140  }
141  else if (bc_type == EqFields::bc_type_displacement_normal)
142  {
143  for (auto p : bdr_integral_->points(cell_side) ) {
144  for (unsigned int i=0; i<n_dofs_; i++)
145  for (unsigned int j=0; j<n_dofs_; j++)
146  local_matrix_[i*n_dofs_+j] += (eq_fields_->dirichlet_penalty(p) / side_measure) *
147  arma::dot(deform_side_.shape(i)(p), normal_(p)) *
148  arma::dot(deform_side_.shape(j)(p), normal_(p)) * JxW_side_(p);
149  }
150  }
151 
152  eq_data_->ls->mat_set_values(n_dofs_, dof_indices_.data(), n_dofs_, dof_indices_.data(), &(local_matrix_[0]));
153  }
154 
155 
156  /// Assembles between elements of different dimensions.
157  inline void dimjoin_intergral(DHCellAccessor cell_lower_dim, DHCellSide neighb_side) {
158  if (dim == 3) return;
159  ASSERT_EQ(cell_lower_dim.dim(), dim).error("Dimension of element mismatch!");
160 
161  unsigned int n_indices = cell_lower_dim.get_dof_indices(dof_indices_);
162  for(unsigned int i=0; i<n_indices; ++i) {
164  }
165 
166  DHCellAccessor cell_higher_dim = eq_data_->dh_->cell_accessor_from_element( neighb_side.element().idx() );
167  n_indices = cell_higher_dim.get_dof_indices(dof_indices_);
168  for(unsigned int i=0; i<n_indices; ++i) {
170  }
171 
172  // Element id's for testing if they belong to local partition.
173  bool own_element_id[2];
174  own_element_id[0] = cell_lower_dim.is_own();
175  own_element_id[1] = cell_higher_dim.is_own();
176 
177  unsigned int n_neighs = cell_lower_dim.elm()->n_neighs_vb();
178 
179  for (unsigned int i=0; i<n_dofs_ngh_[0]+n_dofs_ngh_[1]; i++)
180  for (unsigned int j=0; j<n_dofs_ngh_[0]+n_dofs_ngh_[1]; j++)
181  local_matrix_[i*(n_dofs_ngh_[0]+n_dofs_ngh_[1])+j] = 0;
182 
183  // set transmission conditions
184  for (auto p_high : coupling_integral_->points(neighb_side) )
185  {
186  auto p_low = p_high.lower_dim(cell_lower_dim);
187  arma::vec3 nv = normal_join_(p_high);
188 
189  for (uint i=0; i<deform_join_.n_dofs_both(); ++i) {
190  uint is_high_i = deform_join_.is_high_dim(i);
191  if (!own_element_id[is_high_i]) continue;
192  arma::vec3 diff_deform_i = deform_join_.shape(i)(p_low) - deform_join_.shape(i)(p_high);
193  arma::mat33 grad_deform_i = deform_join_grad_.shape(i)(p_low); // low dim element
194  arma::mat33 semi_grad_i = grad_deform_i + n_neighs/eq_fields_->cross_section(p_low)*arma::kron(diff_deform_i,nv.t());
195  arma::mat33 semi_sym_grad_i = 0.5*(semi_grad_i + semi_grad_i.t());
196 
197  for (uint j=0; j<deform_join_.n_dofs_both(); ++j) {
198  arma::vec3 deform_j_high = deform_join_.shape(j)(p_high);
199  arma::vec3 diff_deform_j = deform_join_.shape(j)(p_low) - deform_j_high;
200  arma::mat33 grad_deform_j = deform_join_grad_.shape(j)(p_low); // low dim element
201  arma::mat33 semi_grad_j = grad_deform_j + n_neighs/eq_fields_->cross_section(p_low)*arma::kron(diff_deform_j,nv.t());
202  arma::mat33 semi_sym_grad_j = 0.5*(semi_grad_j + semi_grad_j.t());
203 
204  local_matrix_[i * (n_dofs_ngh_[0]+n_dofs_ngh_[1]) + j] +=
205  (
206  eq_fields_->fracture_sigma(p_low)*eq_fields_->cross_section(p_low) / n_neighs
207  * arma::dot(semi_sym_grad_i, eq_fields_->stress_tensor(p_low,semi_sym_grad_j))
208 
209  // This term corrects the tangential part of the above product so that there is no
210  // dependence on fracture_sigma.
211  // TODO: Fracture_sigma should be possibly removed and replaced by anisotropic elasticity.
212  + (1-eq_fields_->fracture_sigma(p_low))*eq_fields_->cross_section(p_low) / n_neighs
213  * arma::dot(0.5*(grad_deform_i+grad_deform_i.t()), eq_fields_->stress_tensor(p_low,0.5*(grad_deform_j+grad_deform_j.t())))
214  )*JxW_join_(p_high);
215  }
216  }
217 
218  }
219 
220  eq_data_->ls->mat_set_values(n_dofs_ngh_[0]+n_dofs_ngh_[1], &(side_dof_indices_[0]), n_dofs_ngh_[0]+n_dofs_ngh_[1], &(side_dof_indices_[0]), &(local_matrix_[0]));
221  }
222 
223 
224 
225 private:
226  inline arma::mat33 mat_t(const arma::mat33 &m, const arma::vec3 &n)
227  {
228  arma::mat33 mt = m - m*arma::kron(n,n.t());
229  return mt;
230  }
231 
232 
233  /// Data objects shared with Elasticity
236 
237  /// Sub field set contains fields used in calculation.
239 
240  unsigned int n_dofs_; ///< Number of dofs
241  unsigned int n_dofs_high_; ///< Number of dofs (on lower dim element)
242  std::vector<unsigned int> n_dofs_ngh_; ///< Number of dofs on lower and higher dimension element (vector of 2 items)
243 
244  vector<LongIdx> dof_indices_; ///< Vector of global DOF indices
245  vector<LongIdx> side_dof_indices_; ///< vector of DOF indices in neighbour calculation.
246  vector<PetscScalar> local_matrix_; ///< Auxiliary vector for assemble methods
247 
248  std::shared_ptr<BulkIntegralAcc<dim>> bulk_integral_; ///< Bulk integral of assembly class
249  std::shared_ptr<BoundaryIntegralAcc<dim>> bdr_integral_; ///< Boundary integral of assembly class
250  std::shared_ptr<CouplingIntegralAcc<dim>> coupling_integral_; ///< Coupling integral of assembly class
251 
252  /// Following data members represent Element quantities and FE quantities
263 
264  template < template<IntDim...> class DimAssembly>
265  friend class GenericAssembly;
266 
267 };
268 
269 
270 template <unsigned int dim, class TEqData>
272 {
273 public:
274  typedef typename TEqData::EqFields EqFields;
275  typedef TEqData EqData;
276 
277  static constexpr const char * name() { return "Elasticity_Rhs_Assembly"; }
278 
279  /// Constructor.
281  : AssemblyBasePatch<dim>(eq_data->quad_order(), asm_internals), eq_fields_(eq_data->eq_fields_.get()), eq_data_(eq_data),
285  JxW_( bulk_integral_->JxW() ),
286  JxW_side_( bdr_integral_->JxW() ),
287  JxW_join_( coupling_integral_->JxW() ),
288  normal_( bdr_integral_->normal_vector() ),
289  normal_join_( coupling_integral_->normal_vector() ),
290  deform_( bulk_integral_->vector_shape() ),
291  deform_side_( bdr_integral_->vector_shape() ),
292  grad_deform_( bulk_integral_->grad_vector_shape() ),
293  div_deform_( bulk_integral_->vector_divergence() ),
294  deform_join_( coupling_integral_->vector_join_shape() ) {
295  this->used_fields_ += eq_fields_->cross_section;
296  this->used_fields_ += eq_fields_->load;
297  this->used_fields_ += eq_fields_->potential_load;
298  this->used_fields_ += eq_fields_->ref_potential_load;
299  this->used_fields_ += eq_fields_->fracture_sigma;
300  this->used_fields_ += eq_fields_->dirichlet_penalty;
301  this->used_fields_ += eq_fields_->bc_type;
302  this->used_fields_ += eq_fields_->bc_displacement;
303  this->used_fields_ += eq_fields_->bc_traction;
304  this->used_fields_ += eq_fields_->bc_stress;
305  this->used_fields_ += eq_fields_->initial_stress;
306  }
307 
308  /// Destructor.
310 
311  /// Initialize auxiliary vectors and other data members
312  void initialize() {
313  //this->balance_ = eq_data_->balance_;
314  shared_ptr<FE_P<dim-1>> fe_p_low = std::make_shared< FE_P<dim-1> >(1);
315  shared_ptr<FiniteElement<dim-1>> fe_low = std::make_shared<FESystem<dim-1>>(fe_p_low, FEVector, 3);
316 
317  n_dofs_ = this->n_dofs();
318  n_dofs_high_ = this->n_dofs_high();
320  dof_indices_.resize(n_dofs_high_);
321  side_dof_indices_.resize(n_dofs_ + n_dofs_high_);
322  local_rhs_.resize(2*n_dofs_high_);
323  }
324 
325 
326  /// Assemble integral over element
327  inline void cell_integral(DHCellAccessor cell, unsigned int element_patch_idx)
328  {
329  if (cell.dim() != dim) return;
330  if (!cell.is_own()) return;
331 
333 
334  // assemble the local stiffness matrix
335  fill_n(&(local_rhs_[0]), n_dofs_, 0);
336  //local_source_balance_vector.assign(n_dofs_, 0);
337  //local_source_balance_rhs.assign(n_dofs_, 0);
338 
339  // compute sources
340  for (auto p : bulk_integral_->points(element_patch_idx) )
341  {
342  for (unsigned int i=0; i<n_dofs_; i++)
343  local_rhs_[i] += (
344  arma::dot(eq_fields_->load(p), deform_.shape(i)(p))
345  -eq_fields_->potential_load(p)*div_deform_.shape(i)(p)
346  -arma::dot(eq_fields_->initial_stress(p), grad_deform_.shape(i)(p))
347  )*eq_fields_->cross_section(p)*JxW_(p);
348  }
349  eq_data_->ls->rhs_set_values(n_dofs_, dof_indices_.data(), &(local_rhs_[0]));
350 
351 // for (unsigned int i=0; i<n_dofs_; i++)
352 // {
353 // for (unsigned int k=0; k<qsize_; k++) // point range
354 // local_source_balance_vector[i] -= 0;//sources_sigma[k]*fe_vals_[vec_view_].value(i,k)*JxW_(k);
355 //
356 // local_source_balance_rhs[i] += local_rhs_[i];
357 // }
358 // balance_->add_source_matrix_values(subst_idx, elm_acc.region().bulk_idx(), dof_indices_, local_source_balance_vector);
359 // balance_->add_source_vec_values(subst_idx, elm_acc.region().bulk_idx(), dof_indices_, local_source_balance_rhs);
360  }
361 
362  /// Assembles boundary integral.
363  inline void boundary_side_integral(DHCellSide cell_side)
364  {
365  ASSERT_EQ(cell_side.dim(), dim).error("Dimension of element mismatch!");
366  if (!cell_side.cell().is_own()) return;
367 
368  const DHCellAccessor &dh_cell = cell_side.cell();
369  dh_cell.get_dof_indices(dof_indices_);
370 
371  auto p_side = *( bdr_integral_->points(cell_side).begin() );
372  auto p_bdr = p_side.point_bdr( cell_side.cond().element_accessor() );
373  unsigned int bc_type = eq_fields_->bc_type(p_bdr);
374 
375  fill_n(&(local_rhs_[0]), n_dofs_, 0);
376  // local_flux_balance_vector.assign(n_dofs_, 0);
377  // local_flux_balance_rhs = 0;
378 
379  // addtion from initial stress
380  for (auto p : bdr_integral_->points(cell_side) )
381  {
382  for (unsigned int i=0; i<n_dofs_; i++)
383  local_rhs_[i] += eq_fields_->cross_section(p) *
384  arma::dot(( eq_fields_->initial_stress(p) * normal_(p)),
385  deform_side_.shape(i)(p)) *
386  JxW_side_(p);
387  }
388 
389  if (bc_type == EqFields::bc_type_displacement)
390  {
391  double side_measure = cell_side.measure();
392  for (auto p : bdr_integral_->points(cell_side) )
393  {
394  auto p_bdr = p.point_bdr( cell_side.cond().element_accessor() );
395  for (unsigned int i=0; i<n_dofs_; i++)
396  local_rhs_[i] += (eq_fields_->dirichlet_penalty(p) / side_measure) *
397  arma::dot(eq_fields_->bc_displacement(p_bdr), deform_side_.shape(i)(p)) *
398  JxW_side_(p);
399  }
400  }
401  else if (bc_type == EqFields::bc_type_displacement_normal)
402  {
403  double side_measure = cell_side.measure();
404  for (auto p : bdr_integral_->points(cell_side) )
405  {
406  auto p_bdr = p.point_bdr( cell_side.cond().element_accessor() );
407  for (unsigned int i=0; i<n_dofs_; i++)
408  local_rhs_[i] += (eq_fields_->dirichlet_penalty(p) / side_measure) *
409  arma::dot(eq_fields_->bc_displacement(p_bdr), normal_(p)) *
410  arma::dot(deform_side_.shape(i)(p), normal_(p)) *
411  JxW_side_(p);
412  }
413  }
414  else if (bc_type == EqFields::bc_type_traction)
415  {
416  for (auto p : bdr_integral_->points(cell_side) )
417  {
418  auto p_bdr = p.point_bdr( cell_side.cond().element_accessor() );
419  for (unsigned int i=0; i<n_dofs_; i++)
420  local_rhs_[i] += eq_fields_->cross_section(p) *
421  arma::dot(deform_side_.shape(i)(p), eq_fields_->bc_traction(p_bdr) + eq_fields_->ref_potential_load(p) * normal_(p)) *
422  JxW_side_(p);
423  }
424  }
425  else if (bc_type == EqFields::bc_type_stress)
426  {
427  for (auto p : bdr_integral_->points(cell_side) )
428  {
429  auto p_bdr = p.point_bdr( cell_side.cond().element_accessor() );
430  for (unsigned int i=0; i<n_dofs_; i++)
431  // stress is multiplied by inward normal to obtain traction
432  local_rhs_[i] += eq_fields_->cross_section(p) *
433  arma::dot(deform_side_.shape(i)(p), -eq_fields_->bc_stress(p_bdr)*normal_(p)
434  + eq_fields_->ref_potential_load(p) * normal_(p))
435  * JxW_side_(p);
436  }
437  }
438  eq_data_->ls->rhs_set_values(n_dofs_, dof_indices_.data(), &(local_rhs_[0]));
439 
440 
441 // balance_->add_flux_matrix_values(subst_idx, loc_b, side_dof_indices, local_flux_balance_vector);
442 // balance_->add_flux_vec_value(subst_idx, loc_b, local_flux_balance_rhs);
443  // ++loc_b;
444  }
445 
446 
447  /// Assembles between elements of different dimensions.
448  inline void dimjoin_intergral(DHCellAccessor cell_lower_dim, DHCellSide neighb_side) {
449  if (dim == 3) return;
450  ASSERT_EQ(cell_lower_dim.dim(), dim).error("Dimension of element mismatch!");
451 
452  unsigned int n_indices = cell_lower_dim.get_dof_indices(dof_indices_);
453  for(unsigned int i=0; i<n_indices; ++i) {
455  }
456 
457  DHCellAccessor cell_higher_dim = eq_data_->dh_->cell_accessor_from_element( neighb_side.element().idx() );
458  n_indices = cell_higher_dim.get_dof_indices(dof_indices_);
459  for(unsigned int i=0; i<n_indices; ++i) {
461  }
462 
463  // Element id's for testing if they belong to local partition.
464  bool own_element_id[2];
465  own_element_id[0] = cell_lower_dim.is_own();
466  own_element_id[1] = cell_higher_dim.is_own();
467 
468  for (unsigned int i=0; i<2*n_dofs_; i++)
469  local_rhs_[i] = 0;
470 
471  // set transmission conditions
472  for (auto p_high : coupling_integral_->points(neighb_side) )
473  {
474  auto p_low = p_high.lower_dim(cell_lower_dim);
475  arma::vec3 nv = normal_join_(p_high);
476 
477  for (uint i=0; i<deform_join_.n_dofs_both(); ++i) {
478  uint is_high_i = deform_join_.is_high_dim(i);
479  if (!own_element_id[is_high_i]) continue;
480 
481  arma::vec3 vi = deform_join_.shape(i)(p_high);
482  arma::vec3 vf = deform_join_.shape(i)(p_low);
483 
484  local_rhs_[i] -= eq_fields_->fracture_sigma(p_low) * eq_fields_->cross_section(p_high) *
485  arma::dot(vf-vi, eq_fields_->potential_load(p_high) * nv) * JxW_join_(p_high);
486  }
487  }
488 
489  eq_data_->ls->rhs_set_values(n_dofs_ngh_[0]+n_dofs_ngh_[1], side_dof_indices_.data(), &(local_rhs_[0]));
490  }
491 
492 
493 
494 private:
495  /// Data objects shared with Elasticity
498 
499  /// Sub field set contains fields used in calculation.
501 
502  unsigned int n_dofs_; ///< Number of dofs
503  unsigned int n_dofs_high_; ///< Number of dofs (on higher dim element)
504  std::vector<unsigned int> n_dofs_ngh_; ///< Number of dofs on lower and higher dimension element (vector of 2 items)
505 
506  vector<LongIdx> dof_indices_; ///< Vector of global DOF indices
507  vector<LongIdx> side_dof_indices_; ///< 2 items vector of DOF indices in neighbour calculation.
508  vector<PetscScalar> local_rhs_; ///< Auxiliary vector for assemble methods
509 
510  std::shared_ptr<BulkIntegralAcc<dim>> bulk_integral_; ///< Bulk integral of assembly class
511  std::shared_ptr<BoundaryIntegralAcc<dim>> bdr_integral_; ///< Boundary integral of assembly class
512  std::shared_ptr<CouplingIntegralAcc<dim>> coupling_integral_; ///< Coupling integral of assembly class
513 
514  /// Following data members represent Element quantities and FE quantities
525 
526 
527  template < template<IntDim...> class DimAssembly>
528  friend class GenericAssembly;
529 
530 };
531 
532 template <unsigned int dim, class TEqData>
534 {
535 public:
536  typedef typename TEqData::EqFields EqFields;
537  typedef TEqData EqData;
538 
539  static constexpr const char * name() { return "Elasticity_OutpuFields_Assembly"; }
540 
541  /// Constructor.
543  : AssemblyBasePatch<dim>(eq_data->quad_order(), asm_internals), eq_fields_(eq_data->eq_fields_.get()), eq_data_(eq_data),
546  normal_join_( coupling_integral_->normal_vector() ),
547  deform_join_( coupling_integral_->vector_shape() ),
548  grad_deform_( bulk_integral_->grad_vector_shape() ),
549  sym_grad_deform_( bulk_integral_->vector_sym_grad() ),
550  div_deform_( bulk_integral_->vector_divergence() ) {
551  this->used_fields_ += eq_fields_->cross_section;
552  this->used_fields_ += eq_fields_->lame_mu;
553  this->used_fields_ += eq_fields_->lame_lambda;
554  this->used_fields_ += eq_fields_->initial_stress;
555  }
556 
557  /// Destructor.
559 
560  /// Initialize auxiliary vectors and other data members
561  void initialize() {
562  //this->balance_ = eq_data_->balance_;
563 
564  n_dofs_ = this->n_dofs();
565  n_dofs_high_ = this->n_dofs_high();
566 
567  output_vec_ = eq_fields_->output_field_ptr->vec();
568  output_stress_vec_ = eq_fields_->output_stress_ptr->vec();
569  output_von_mises_stress_vec_ = eq_fields_->output_von_mises_stress_ptr->vec();
570  output_mean_stress_vec_ = eq_fields_->output_mean_stress_ptr->vec();
571  output_cross_sec_vec_ = eq_fields_->output_cross_section_ptr->vec();
572  output_div_vec_ = eq_fields_->output_div_ptr->vec();
573  }
574 
575 
576  /// Assemble integral over element
577  inline void cell_integral(DHCellAccessor cell, unsigned int element_patch_idx)
578  {
579  if (cell.dim() != dim) return;
580  if (!cell.is_own()) return;
581  DHCellAccessor cell_tensor = cell.cell_with_other_dh(eq_data_->dh_tensor_.get());
582  DHCellAccessor cell_scalar = cell.cell_with_other_dh(eq_data_->dh_scalar_.get());
583 
587 
588  auto p = *( bulk_integral_->points(element_patch_idx).begin() );
589 
590  arma::mat33 stress = eq_fields_->initial_stress(p);
591  double div = 0;
592  for (unsigned int i=0; i<n_dofs_; i++)
593  {
594  stress += eq_fields_->stress_tensor(p,sym_grad_deform_.shape(i)(p))
596  div += div_deform_.shape(i)(p)*output_vec_.get(dof_indices_[i]);
597  }
598 
599  arma::mat33 stress_dev = stress - arma::trace(stress)/3*arma::eye(3,3);
600  double von_mises_stress = sqrt(1.5*arma::dot(stress_dev, stress_dev));
601  double mean_stress = arma::trace(stress) / 3;
603 
604  for (unsigned int i=0; i<3; i++)
605  for (unsigned int j=0; j<3; j++)
606  output_stress_vec_.add( dof_indices_tensor_[i*3+j], stress(i,j) );
607  output_von_mises_stress_vec_.set( dof_indices_scalar_[0], von_mises_stress );
609 
610  output_cross_sec_vec_.add( dof_indices_scalar_[0], eq_fields_->cross_section(p) );
611  }
612 
613 
614  /// Assembles between elements of different dimensions.
615  inline void dimjoin_intergral(DHCellAccessor cell_lower_dim, DHCellSide neighb_side) {
616  if (dim == 3) return;
617  ASSERT_EQ(cell_lower_dim.dim(), dim).error("Dimension of element mismatch!");
618 
620  normal_stress_.zeros();
621 
622  DHCellAccessor cell_higher_dim = neighb_side.cell();
623  DHCellAccessor cell_tensor = cell_lower_dim.cell_with_other_dh(eq_data_->dh_tensor_.get());
624  DHCellAccessor cell_scalar = cell_lower_dim.cell_with_other_dh(eq_data_->dh_scalar_.get());
625 
626  dof_indices_ = cell_higher_dim.get_loc_dof_indices();
627  auto p_high = *( coupling_integral_->points(neighb_side).begin() );
628  auto p_low = p_high.lower_dim(cell_lower_dim);
629 
630  for (unsigned int i=0; i<n_dofs_high_; i++)
631  {
632  normal_displacement_ -= arma::dot(deform_join_.shape(i)(p_high)*output_vec_.get(dof_indices_[i]), normal_join_(p_high));
633  arma::mat33 grad = -arma::kron(deform_join_.shape(i)(p_high)*output_vec_.get(dof_indices_[i]), normal_join_(p_high).t()) / eq_fields_->cross_section(p_low);
634  normal_stress_ += eq_fields_->stress_tensor(p_low, 0.5*(grad+grad.t()));
635  }
636 
639  for (unsigned int i=0; i<3; i++)
640  for (unsigned int j=0; j<3; j++)
644  }
645 
646 
647 
648 private:
649  /// Data objects shared with Elasticity
652 
653  /// Sub field set contains fields used in calculation.
655 
656  unsigned int n_dofs_; ///< Number of dofs
657  unsigned int n_dofs_high_; ///< Number of dofs of higher dim element
658  LocDofVec dof_indices_; ///< Vector of local DOF indices of vector fields
659  LocDofVec dof_indices_scalar_; ///< Vector of local DOF indices of scalar fields
660  LocDofVec dof_indices_tensor_; ///< Vector of local DOF indices of tensor fields
661 
662  double normal_displacement_; ///< Holds constributions of normal displacement.
663  arma::mat33 normal_stress_; ///< Holds constributions of normal stress.
664 
665  std::shared_ptr<BulkIntegralAcc<dim>> bulk_integral_; ///< Bulk integral of assembly class
666  std::shared_ptr<CouplingIntegralAcc<dim>> coupling_integral_; ///< Coupling integral of assembly class
667 
668  /// Following data members represent Element quantities and FE quantities
674 
675  /// Data vectors of output fields (FieldFE).
682 
683  template < template<IntDim...> class DimAssembly>
684  friend class GenericAssembly;
685 
686 };
687 
688 
689 
690 /**
691  * Container class for assembly of constraint matrix for contact condition.
692  */
693 template <unsigned int dim, class TEqData>
695 {
696 public:
697  typedef typename TEqData::EqFields EqFields;
698  typedef TEqData EqData;
699 
700  static constexpr const char * name() { return "Elasticity_Constraint_Assembly"; }
701 
702  /// Constructor.
704  : AssemblyBasePatch<dim>(eq_data->quad_order(), asm_internals), eq_fields_(eq_data->eq_fields_.get()), eq_data_(eq_data),
706  JxW_join_( coupling_integral_->JxW() ),
707  normal_join_( coupling_integral_->normal_vector() ),
708  deform_join_( coupling_integral_->vector_shape() ) {
709  this->used_fields_ += eq_fields_->cross_section;
710  this->used_fields_ += eq_fields_->cross_section_min;
711  }
712 
713  /// Destructor.
715 
716  /// Initialize auxiliary vectors and other data members
717  void initialize() {
718  n_dofs_ = this->n_dofs_high();
719  dof_indices_.resize(n_dofs_);
720  local_matrix_.resize(n_dofs_*n_dofs_);
721  }
722 
723 
724  /// Assembles between elements of different dimensions.
725  inline void dimjoin_intergral(DHCellAccessor cell_lower_dim, DHCellSide neighb_side) {
726  if (dim == 3) return;
727  if (!cell_lower_dim.is_own()) return;
728 
729  ASSERT_EQ(cell_lower_dim.dim(), dim).error("Dimension of element mismatch!");
730 
731  DHCellAccessor cell_higher_dim = eq_data_->dh_->cell_accessor_from_element( neighb_side.element().idx() );
732  cell_higher_dim.get_dof_indices(dof_indices_);
733 
734  for (unsigned int i=0; i<n_dofs_; i++)
735  local_matrix_[i] = 0;
736 
737  // Assemble matrix and vector for contact conditions in the form B*x <= c,
738  // where B*x is the average jump of normal displacements and c is the average cross-section on element.
739  // Positive value means that the fracture closes.
740  double local_vector = 0;
741  for (auto p_high : coupling_integral_->points(neighb_side) )
742  {
743  auto p_low = p_high.lower_dim(cell_lower_dim);
744  arma::vec3 nv = normal_join_(p_high);
745 
746  local_vector += (eq_fields_->cross_section(p_low) - eq_fields_->cross_section_min(p_low))*JxW_join_(p_high) / cell_lower_dim.elm().measure() / cell_lower_dim.elm()->n_neighs_vb();
747 
748  for (unsigned int i=0; i<n_dofs_; i++)
749  {
750  local_matrix_[i] += eq_fields_->cross_section(p_high)*arma::dot(deform_join_.shape(i)(p_high), nv)*JxW_join_(p_high) / cell_lower_dim.elm().measure();
751  }
752  }
753 
754  int arow[1] = { eq_data_->constraint_idx[cell_lower_dim.elm_idx()] };
755  MatSetValues(eq_data_->constraint_matrix, 1, arow, n_dofs_, dof_indices_.data(), &(local_matrix_[0]), ADD_VALUES);
756  VecSetValue(eq_data_->constraint_vec, arow[0], local_vector, ADD_VALUES);
757  }
758 
759 
760 
761 private:
762 
763 
764  /// Data objects shared with Elasticity
767 
768  /// Sub field set contains fields used in calculation.
770 
771  unsigned int n_dofs_; ///< Number of dofs
772  vector<LongIdx> dof_indices_; ///< Vector of global DOF indices
773  vector<vector<LongIdx> > side_dof_indices_; ///< 2 items vector of DOF indices in neighbour calculation.
774  vector<PetscScalar> local_matrix_; ///< Auxiliary vector for assemble methods
775 
776  std::shared_ptr<CouplingIntegralAcc<dim>> coupling_integral_; ///< Coupling integral of assembly class
777 
778  /// Following data members represent Element quantities and FE quantities
782 
783 
784  template < template<IntDim...> class DimAssembly>
785  friend class GenericAssembly;
786 
787 };
788 
789 
790 #endif /* ASSEMBLY_ELASTICITY_HH_ */
791 
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:333
unsigned int n_dofs_high()
Return number of DOFs of higher dim element.
unsigned int n_dofs()
Return number of DOFs.
Quadrature * quad_
Quadrature used in assembling methods.
std::shared_ptr< CouplingIntegralAcc< dim > > create_coupling_integral(Quadrature *quad)
std::shared_ptr< BoundaryIntegralAcc< dim > > create_boundary_integral(Quadrature *quad)
std::shared_ptr< BulkIntegralAcc< dim > > create_bulk_integral(Quadrature *quad)
Quadrature * quad_low_
Quadrature used in assembling methods (dim-1).
ElementAccessor< 3 > element_accessor()
static constexpr const char * name()
FieldSet used_fields_
Sub field set contains fields used in calculation.
vector< LongIdx > dof_indices_
Vector of global DOF indices.
vector< vector< LongIdx > > side_dof_indices_
2 items vector of DOF indices in neighbour calculation.
unsigned int n_dofs_
Number of dofs.
EqFields * eq_fields_
Data objects shared with Elasticity.
void dimjoin_intergral(DHCellAccessor cell_lower_dim, DHCellSide neighb_side)
Assembles between elements of different dimensions.
void initialize()
Initialize auxiliary vectors and other data members.
std::shared_ptr< CouplingIntegralAcc< dim > > coupling_integral_
Coupling integral of assembly class.
vector< PetscScalar > local_matrix_
Auxiliary vector for assemble methods.
FeQ< Scalar > JxW_join_
Following data members represent Element quantities and FE quantities.
ConstraintAssemblyElasticity(EqData *eq_data, AssemblyInternals *asm_internals)
Constructor.
Cell accessor allow iterate over DOF handler cells.
bool is_own() const
Return true if accessor represents own element (false for ghost element)
LocDofVec get_loc_dof_indices() const
Returns the local indices of dofs associated to the cell on the local process.
DHCellAccessor cell_with_other_dh(const DOFHandlerMultiDim *dh) const
Create new accessor with same local idx and given DOF handler. Actual and given DOF handler must be c...
unsigned int get_dof_indices(std::vector< LongIdx > &indices) const
Fill vector of the global indices of dofs associated to the cell.
unsigned int dim() const
Return dimension of element appropriate to cell.
unsigned int elm_idx() const
Return serial idx to element of loc_ele_idx_.
ElementAccessor< 3 > elm() const
Return ElementAccessor to element of loc_ele_idx_.
Side accessor allows to iterate over sides of DOF handler cell.
Side side() const
Return Side of given cell and side_idx.
Boundary cond() const
const DHCellAccessor & cell() const
Return DHCellAccessor appropriate to the side.
unsigned int dim() const
Return dimension of element appropriate to the side.
double measure() const
ElementAccessor< 3 > element() const
double measure() const
Computes the measure of the element.
unsigned int idx() const
We need this method after replacing Region by RegionIdx, and movinf RegionDB instance into particular...
Definition: accessors.hh:215
unsigned int n_neighs_vb() const
Return number of neighbours.
Definition: elements.h:65
Compound finite element on dim dimensional simplex.
Definition: fe_system.hh:102
Conforming Lagrangean finite element on dim dimensional simplex.
Definition: fe_p.hh:86
FeQ< ValueType > shape(unsigned int i_shape_fn_idx) const
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
Generic class of assemblation.
LocDofVec dof_indices_tensor_
Vector of local DOF indices of tensor fields.
std::shared_ptr< BulkIntegralAcc< dim > > bulk_integral_
Bulk integral of assembly class.
static constexpr const char * name()
FieldSet used_fields_
Sub field set contains fields used in calculation.
double normal_displacement_
Holds constributions of normal displacement.
OutpuFieldsAssemblyElasticity(EqData *eq_data, AssemblyInternals *asm_internals)
Constructor.
LocDofVec dof_indices_
Vector of local DOF indices of vector fields.
EqFields * eq_fields_
Data objects shared with Elasticity.
void initialize()
Initialize auxiliary vectors and other data members.
LocDofVec dof_indices_scalar_
Vector of local DOF indices of scalar fields.
std::shared_ptr< CouplingIntegralAcc< dim > > coupling_integral_
Coupling integral of assembly class.
arma::mat33 normal_stress_
Holds constributions of normal stress.
unsigned int n_dofs_
Number of dofs.
ElQ< Vector > normal_join_
Following data members represent Element quantities and FE quantities.
VectorMPI output_vec_
Data vectors of output fields (FieldFE).
void cell_integral(DHCellAccessor cell, unsigned int element_patch_idx)
Assemble integral over element.
void dimjoin_intergral(DHCellAccessor cell_lower_dim, DHCellSide neighb_side)
Assembles between elements of different dimensions.
unsigned int n_dofs_high_
Number of dofs of higher dim element.
TEqData::EqFields EqFields
void boundary_side_integral(DHCellSide cell_side)
Assembles boundary integral.
FeQ< Scalar > JxW_
Following data members represent Element quantities and FE quantities.
FeQArray< Tensor > grad_deform_
std::shared_ptr< BoundaryIntegralAcc< dim > > bdr_integral_
Boundary integral of assembly class.
void dimjoin_intergral(DHCellAccessor cell_lower_dim, DHCellSide neighb_side)
Assembles between elements of different dimensions.
RhsAssemblyElasticity(EqData *eq_data, AssemblyInternals *asm_internals)
Constructor.
vector< LongIdx > dof_indices_
Vector of global DOF indices.
FeQArray< Vector > deform_
EqFields * eq_fields_
Data objects shared with Elasticity.
void cell_integral(DHCellAccessor cell, unsigned int element_patch_idx)
Assemble integral over element.
FeQArray< Scalar > div_deform_
void initialize()
Initialize auxiliary vectors and other data members.
std::shared_ptr< CouplingIntegralAcc< dim > > coupling_integral_
Coupling integral of assembly class.
std::shared_ptr< BulkIntegralAcc< dim > > bulk_integral_
Bulk integral of assembly class.
FieldSet used_fields_
Sub field set contains fields used in calculation.
vector< LongIdx > side_dof_indices_
2 items vector of DOF indices in neighbour calculation.
FeQJoin< Vector > deform_join_
static constexpr const char * name()
vector< PetscScalar > local_rhs_
Auxiliary vector for assemble methods.
std::vector< unsigned int > n_dofs_ngh_
Number of dofs on lower and higher dimension element (vector of 2 items)
unsigned int n_dofs_high_
Number of dofs (on higher dim element)
FeQArray< Vector > deform_side_
unsigned int n_dofs_
Number of dofs.
Boundary cond() const
FieldSet used_fields_
Sub field set contains fields used in calculation.
vector< PetscScalar > local_matrix_
Auxiliary vector for assemble methods.
static constexpr const char * name()
void cell_integral(DHCellAccessor cell, unsigned int element_patch_idx)
Assemble integral over element.
vector< LongIdx > side_dof_indices_
vector of DOF indices in neighbour calculation.
void initialize()
Initialize auxiliary vectors and other data members.
std::shared_ptr< BulkIntegralAcc< dim > > bulk_integral_
Bulk integral of assembly class.
arma::mat33 mat_t(const arma::mat33 &m, const arma::vec3 &n)
unsigned int n_dofs_
Number of dofs.
StiffnessAssemblyElasticity(EqData *eq_data, AssemblyInternals *asm_internals)
Constructor.
std::vector< unsigned int > n_dofs_ngh_
Number of dofs on lower and higher dimension element (vector of 2 items)
vector< LongIdx > dof_indices_
Vector of global DOF indices.
unsigned int n_dofs_high_
Number of dofs (on lower dim element)
EqFields * eq_fields_
Data objects shared with Elasticity.
void dimjoin_intergral(DHCellAccessor cell_lower_dim, DHCellSide neighb_side)
Assembles between elements of different dimensions.
std::shared_ptr< BoundaryIntegralAcc< dim > > bdr_integral_
Boundary integral of assembly class.
void boundary_side_integral(DHCellSide cell_side)
Assembles boundary integral.
FeQ< Scalar > JxW_
Following data members represent Element quantities and FE quantities.
std::shared_ptr< CouplingIntegralAcc< dim > > coupling_integral_
Coupling integral of assembly class.
double get(unsigned int pos) const
Return value on given position.
Definition: vector_mpi.hh:105
void set(unsigned int pos, double val)
Set value on given position.
Definition: vector_mpi.hh:111
void add(unsigned int pos, double val)
Add value to item on given position.
Definition: vector_mpi.hh:125
FEM for linear elasticity.
Definitions of basic Lagrangean finite elements with polynomial shape functions.
Class FEValues calculates finite element data on the actual cells such as shape function values,...
@ FEVector
arma::Col< IntIdx > LocDofVec
Definition: index_types.hh:28
unsigned int uint
unsigned int IntDim
A dimension index type.
Definition: mixed.hh:19
Store finite element reinit functions.
Definitions of particular quadrature rules on simplices.
Holds common data shared between GenericAssemblz and Assembly<dim> classes.