Flow123d  DF_patch_fe_darcy_complete-579fe1e
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/fe_values.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  : AssemblyBase<dim>(1, asm_internals), eq_fields_(eq_data->eq_fields_.get()), eq_data_(eq_data),
48  this->used_fields_ += eq_fields_->alpha;
49  this->used_fields_ += eq_fields_->density;
50  this->used_fields_ += eq_fields_->gravity;
51  this->used_fields_ += eq_data_->flow_->eq_fields().bc_type;
52  this->used_fields_ += eq_data_->flow_->eq_fields().bc_pressure;
53  }
54 
55  /// Destructor.
57 
58  /// Initialize auxiliary vectors and other data members
59  void initialize() {
60  shared_ptr<FE_P<dim>> fe_p = std::make_shared< FE_P<dim> >(1);
61  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 * fe_values_side_.JxW(k) / 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  FEValues<3> fe_values_side_; ///< FEValues of side object
112  LocDofVec dof_indices_; ///< Vector of global DOF indices
113  VectorMPI ref_potential_vec_; ///< Vector of dofs of field ref_potential
114  std::shared_ptr<BoundaryIntegralAcc<dim>> bdr_integral_; ///< Boundary integral of assembly class
115 
116  template < template<IntDim...> class DimAssembly>
117  friend class GenericAssembly;
118 
119 };
120 
121 
122 template <unsigned int dim, class TEqData>
123 class ResidualAssemblyHM : public AssemblyBase<dim>
124 {
125 public:
126  typedef typename TEqData::EqFields EqFields;
127  typedef TEqData EqData;
128 
129  static constexpr const char * name() { return "HM_Residual_Assembly"; }
130 
131  /// Constructor.
132  ResidualAssemblyHM(EqData *eq_data, AssemblyInternals *asm_internals)
133  : AssemblyBase<dim>(1, asm_internals), eq_fields_(eq_data->eq_fields_.get()), eq_data_(eq_data),
134  bulk_integral_( this->create_bulk_integral(this->quad_)) {
135  this->used_fields_ += eq_data_->flow_->eq_fields().field_ele_pressure;
136  this->used_fields_ += eq_fields_->old_iter_pressure;
137  }
138 
139  /// Destructor.
141 
142  /// Initialize auxiliary vectors and other data members
143  void initialize() {
144  shared_ptr<FE_P<dim>> fe_ = std::make_shared< FE_P<dim> >(0);
146  }
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  fe_values_.reinit(cell.elm());
156 
157  // compute pressure error
158  unsigned int k=0;
159  for (auto p : bulk_integral_->points(element_patch_idx) )
160  {
161  double new_p = eq_data_->flow_->eq_fields().field_ele_pressure(p);
162  double old_p = eq_fields_->old_iter_pressure(p);
163  eq_data_->p_dif2 += (new_p - old_p)*(new_p - old_p) * fe_values_.JxW(k);
164  eq_data_->p_norm2 += old_p*old_p * fe_values_.JxW(k);
165  ++k;
166  }
167  }
168 
169 
170 
171 private:
172  /// Data objects shared with Elasticity
175 
176  /// Sub field set contains fields used in calculation.
178 
179  FEValues<3> fe_values_; ///< FEValues of cell object
180  std::shared_ptr<BulkIntegralAcc<dim>> bulk_integral_; ///< Bulk integral of assembly class
181 
182  template < template<IntDim...> class DimAssembly>
183  friend class GenericAssembly;
184 
185 };
186 
187 
188 #endif /* ASSEMBLY_HM_HH_ */
189 
Quadrature * quad_
Quadrature used in assembling methods.
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()
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.
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.
double measure() const
unsigned int side_idx() const
double JxW(const unsigned int point_no)
Return the product of Jacobian determinant and the quadrature weight at given quadrature point.
Definition: fe_values.hh:223
void initialize(Quadrature &_quadrature, FiniteElement< DIM > &_fe, UpdateFlags _flags)
Initialize structures and calculates cell-independent data.
Definition: fe_values.cc:137
void reinit(const ElementAccessor< spacedim > &cell)
Update cell-dependent data (gradients, Jacobians etc.)
Definition: fe_values.cc:537
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
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:114
LocDofVec dof_indices_
Vector of global DOF indices.
Definition: assembly_hm.hh:112
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:113
~FlowPotentialAssemblyHM()
Destructor.
Definition: assembly_hm.hh:56
static constexpr const char * name()
Definition: assembly_hm.hh:42
FEValues< 3 > fe_values_side_
FEValues of side object.
Definition: assembly_hm.hh:111
void initialize()
Initialize auxiliary vectors and other data members.
Definition: assembly_hm.hh:59
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:132
~ResidualAssemblyHM()
Destructor.
Definition: assembly_hm.hh:140
FieldSet used_fields_
Sub field set contains fields used in calculation.
Definition: assembly_hm.hh:177
void initialize()
Initialize auxiliary vectors and other data members.
Definition: assembly_hm.hh:143
static constexpr const char * name()
Definition: assembly_hm.hh:129
EqFields * eq_fields_
Data objects shared with Elasticity.
Definition: assembly_hm.hh:173
void cell_integral(DHCellAccessor cell, unsigned int element_patch_idx)
Assemble integral over element.
Definition: assembly_hm.hh:150
TEqData::EqFields EqFields
Definition: assembly_hm.hh:126
std::shared_ptr< BulkIntegralAcc< dim > > bulk_integral_
Bulk integral of assembly class.
Definition: assembly_hm.hh:180
FEValues< 3 > fe_values_
FEValues of cell object.
Definition: assembly_hm.hh:179
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.
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 IntDim
A dimension index type.
Definition: mixed.hh:19
Definitions of particular quadrature rules on simplices.
Holds common data shared between GenericAssemblz and Assembly<dim> classes.
@ update_JxW_values
Transformed quadrature weights.
@ update_side_JxW_values
Transformed quadrature weight for cell sides.