Flow123d  JS_constraints-e651b99
assembly_hm.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_hm.hh
15  * @brief
16  */
17 
18 #ifndef ASSEMBLY_HM_HH_
19 #define ASSEMBLY_HM_HH_
20 
23 #include "coupling/hm_iterative.hh"
24 #include "fem/fe_p.hh"
25 #include "fem/patch_op_impl.hh"
27 #include "coupling/balance.hh"
28 #include "fem/element_cache_map.hh"
29 
30 
31 /**
32  * Auxiliary container class for Finite element and related objects of given dimension.
33  */
34 template <unsigned int dim, class TEqData>
36 {
37 public:
38  typedef typename TEqData::EqFields EqFields;
39  typedef TEqData EqData;
40  typedef typename DarcyLMH::EqFields FlowEqFields;
41 
42  static constexpr const char * name() { return "HM_FlowPotential_Assembly"; }
43 
44  /// Constructor.
46  : AssemblyBasePatch<dim>(1, asm_internals), eq_fields_(eq_data->eq_fields_.get()), eq_data_(eq_data),
48  JxW_bdr_( bdr_integral_->JxW() ) {
49  this->used_fields_ += eq_fields_->alpha;
50  this->used_fields_ += eq_fields_->density;
51  this->used_fields_ += eq_fields_->gravity;
52  this->used_fields_ += eq_data_->flow_->eq_fields().bc_type;
53  this->used_fields_ += eq_data_->flow_->eq_fields().bc_pressure;
54  }
55 
56  /// Destructor.
58 
59  /// Initialize auxiliary vectors and other data members
60  void initialize() {
61  shared_ptr<FE_P<dim>> fe_p = std::make_shared< FE_P<dim> >(1);
62  shared_ptr<FiniteElement<dim>> fe_ = std::make_shared<FESystem<dim>>(fe_p, FEVector, 3);
63 
64  dof_indices_.resize(fe_->n_dofs());
65 
66  ref_potential_vec_ = eq_fields_->ref_potential_ptr_->vec();
67  }
68 
69 
70  /// Assemble integral over element
71  inline void boundary_side_integral(DHCellSide dh_side)
72  {
74 
75  double ref_pot = 0;
76  if (dh_side.side().is_boundary())
77  {
78  auto p_side = *bdr_integral_->points(dh_side).begin();
79  auto p_bdr = p_side.point_bdr( dh_side.cond().element_accessor() );
80  unsigned int flow_bc_type = eq_data_->flow_->eq_fields().bc_type(p_bdr);
81  if (flow_bc_type == DarcyLMH::EqFields::dirichlet || flow_bc_type == DarcyLMH::EqFields::total_flux)
82  {
83  unsigned int k=0;
84  for ( auto p : bdr_integral_->points(dh_side) )
85  {
86  // The reference potential is applied only on dirichlet and total_flux b.c.,
87  // i.e. where only mechanical traction is prescribed.
88  auto p_bdr = p.point_bdr(dh_side.cond().element_accessor());
89  double alpha = eq_fields_->alpha(p);
90  double density = eq_fields_->density(p);
91  double gravity = eq_fields_->gravity(p);
92  double bc_pressure = eq_data_->flow_->eq_fields().bc_pressure(p_bdr);
93  ref_pot += -alpha*density*gravity*bc_pressure * JxW_bdr_(p) / dh_side.measure();
94  ++k;
95  }
96  }
97  }
98  ref_potential_vec_.set(dof_indices_[dh_side.side_idx()], ref_pot);
99  }
100 
101 
102 
103 private:
104 
105  EqFields *eq_fields_; ///< Fields shared with HM_Iterative
106  EqData *eq_data_; ///< Data objects shared with HM_Iterative
107 
108  /// Sub field set contains fields used in calculation.
110 
111  LocDofVec dof_indices_; ///< Vector of global DOF indices
112  VectorMPI ref_potential_vec_; ///< Vector of dofs of field ref_potential
113  std::shared_ptr<BoundaryIntegralAcc<dim>> bdr_integral_; ///< Boundary integral of assembly class
114 
115  /// Following data members represent Element quantities and FE quantities
117 
118  template < template<IntDim...> class DimAssembly>
119  friend class GenericAssembly;
120 
121 };
122 
123 
124 template <unsigned int dim, class TEqData>
126 {
127 public:
128  typedef typename TEqData::EqFields EqFields;
129  typedef TEqData EqData;
130 
131  static constexpr const char * name() { return "HM_Residual_Assembly"; }
132 
133  /// Constructor.
134  ResidualAssemblyHM(EqData *eq_data, AssemblyInternals *asm_internals)
135  : AssemblyBasePatch<dim>(1, asm_internals), eq_fields_(eq_data->eq_fields_.get()), eq_data_(eq_data),
137  JxW_( bulk_integral_->JxW() ) {
138  this->used_fields_ += eq_data_->flow_->eq_fields().field_ele_pressure;
139  this->used_fields_ += eq_fields_->old_iter_pressure;
140  }
141 
142  /// Destructor.
144 
145  /// Initialize auxiliary vectors and other data members
146  void initialize() {}
147 
148 
149  /// Assemble integral over element
150  inline void cell_integral(DHCellAccessor cell, unsigned int element_patch_idx)
151  {
152  if (cell.dim() != dim) return;
153  if (!cell.is_own()) return;
154 
155  // compute pressure error
156  for (auto p : bulk_integral_->points(element_patch_idx) )
157  {
158  double new_p = eq_data_->flow_->eq_fields().field_ele_pressure(p);
159  double old_p = eq_fields_->old_iter_pressure(p);
160  eq_data_->p_dif2 += (new_p - old_p)*(new_p - old_p) * JxW_(p);
161  eq_data_->p_norm2 += old_p*old_p * JxW_(p);
162  }
163  }
164 
165 
166 
167 private:
168  /// Data objects shared with Elasticity
171 
172  /// Sub field set contains fields used in calculation.
174 
175  std::shared_ptr<BulkIntegralAcc<dim>> bulk_integral_; ///< Bulk integral of assembly class
176 
177  /// Following data members represent Element quantities and FE quantities
179 
180  template < template<IntDim...> class DimAssembly>
181  friend class GenericAssembly;
182 
183 };
184 
185 
186 #endif /* ASSEMBLY_HM_HH_ */
187 
std::shared_ptr< BulkIntegralAcc< dim > > create_bulk_integral(Quadrature *quad)
Quadrature * quad_low_
Quadrature used in assembling methods (dim-1).
Quadrature * quad_
Quadrature used in assembling methods.
std::shared_ptr< BoundaryIntegralAcc< dim > > create_boundary_integral(Quadrature *quad)
ElementAccessor< 3 > element_accessor()
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.
unsigned int dim() const
Return dimension of element appropriate to cell.
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.
double measure() const
unsigned int side_idx() const
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:160
FeQ< Scalar > JxW_bdr_
Following data members represent Element quantities and FE quantities.
Definition: assembly_hm.hh:116
DarcyLMH::EqFields FlowEqFields
Definition: assembly_hm.hh:40
FieldSet used_fields_
Sub field set contains fields used in calculation.
Definition: assembly_hm.hh:109
std::shared_ptr< BoundaryIntegralAcc< dim > > bdr_integral_
Boundary integral of assembly class.
Definition: assembly_hm.hh:113
LocDofVec dof_indices_
Vector of global DOF indices.
Definition: assembly_hm.hh:111
TEqData::EqFields EqFields
Definition: assembly_hm.hh:38
FlowPotentialAssemblyHM(EqData *eq_data, AssemblyInternals *asm_internals)
Constructor.
Definition: assembly_hm.hh:45
VectorMPI ref_potential_vec_
Vector of dofs of field ref_potential.
Definition: assembly_hm.hh:112
~FlowPotentialAssemblyHM()
Destructor.
Definition: assembly_hm.hh:57
static constexpr const char * name()
Definition: assembly_hm.hh:42
void initialize()
Initialize auxiliary vectors and other data members.
Definition: assembly_hm.hh:60
void boundary_side_integral(DHCellSide dh_side)
Assemble integral over element.
Definition: assembly_hm.hh:71
EqFields * eq_fields_
Fields shared with HM_Iterative.
Definition: assembly_hm.hh:105
EqData * eq_data_
Data objects shared with HM_Iterative.
Definition: assembly_hm.hh:106
Generic class of assemblation.
ResidualAssemblyHM(EqData *eq_data, AssemblyInternals *asm_internals)
Constructor.
Definition: assembly_hm.hh:134
~ResidualAssemblyHM()
Destructor.
Definition: assembly_hm.hh:143
FieldSet used_fields_
Sub field set contains fields used in calculation.
Definition: assembly_hm.hh:173
void initialize()
Initialize auxiliary vectors and other data members.
Definition: assembly_hm.hh:146
static constexpr const char * name()
Definition: assembly_hm.hh:131
EqFields * eq_fields_
Data objects shared with Elasticity.
Definition: assembly_hm.hh:169
void cell_integral(DHCellAccessor cell, unsigned int element_patch_idx)
Assemble integral over element.
Definition: assembly_hm.hh:150
FeQ< Scalar > JxW_
Following data members represent Element quantities and FE quantities.
Definition: assembly_hm.hh:178
TEqData::EqFields EqFields
Definition: assembly_hm.hh:128
std::shared_ptr< BulkIntegralAcc< dim > > bulk_integral_
Bulk integral of assembly class.
Definition: assembly_hm.hh:175
bool is_boundary() const
Returns true for side on the boundary.
void set(unsigned int pos, double val)
Set value on given position.
Definition: vector_mpi.hh:111
Definitions of basic Lagrangean finite elements with polynomial shape functions.
@ FEVector
arma::Col< IntIdx > LocDofVec
Definition: index_types.hh:28
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.