Flow123d  JS_before_hm-1621-g63a12c7
fe_value_handler.cc
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 fe_value_handler.cc
15  * @brief
16  */
17 
19 #include "la/vector_mpi.hh"
20 #include "fem/mapping_p1.hh"
21 #include "fem/fe_values.hh"
22 #include "quadrature/quadrature.hh"
24 #include "mesh/bounding_box.hh"
25 #include "mesh/accessors.hh"
26 #include "fem/fe_values_views.hh"
27 #include "fem/dh_cell_accessor.hh"
28 
29 
30 /**
31  * Helper class, allow to simplify computing value of FieldFE.
32  *
33  * Use correct method FEValues<...>::shape_xxx given with Value::rank_.
34  * Is done by class partial specialization as, we were not able to do this using function overloading (since
35  * they differ only by return value) and partial specialization of the function templates is not supported in C++.
36  */
37 template<int rank, int spacedim, class Value>
39 public:
40 
41  inline static typename Value::return_type fe_value(FEValues<spacedim> &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
42  {
43  ASSERT(false).error("Unsupported format of FieldFE!\n");
44  typename Value::return_type ret;
45  Value val(ret);
46  val.zeros();
47  return ret;
48  }
49 };
50 
51 
52 /// Partial template specialization of FEShapeHandler for scalar fields
53 template<int spacedim, class Value>
54 class FEShapeHandler<0, spacedim, Value> {
55 public:
56  inline static typename Value::return_type fe_value(FEValues<3> &fe_val, unsigned int i_dof, unsigned int i_qp, FMT_UNUSED unsigned int comp_index)
57  {
58  return fe_val.scalar_view(comp_index).value(i_dof, i_qp);
59  }
60 };
61 
62 
63 /// Partial template specialization of FEShapeHandler for vector fields
64 template<int spacedim, class Value>
65 class FEShapeHandler<1, spacedim, Value> {
66 public:
67  inline static typename Value::return_type fe_value(FEValues<3> &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
68  {
69  return fe_val.vector_view(comp_index).value(i_dof, i_qp);
70  }
71 };
72 
73 
74 /// Partial template specialization of FEShapeHandler for tensor fields
75 template<int spacedim, class Value>
76 class FEShapeHandler<2, spacedim, Value> {
77 public:
78  inline static typename Value::return_type fe_value(FEValues<3> &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
79  {
80  return fe_val.tensor_view(comp_index).value(i_dof, i_qp);
81  }
82 };
83 
84 
85 
86 template <int elemdim, int spacedim, class Value>
88 : value_(r_value_)
89 {}
90 
91 
92 template <int elemdim, int spacedim, class Value>
94 {
95  if (dh_)
96  WarningOut() << "Multiple initialization of FEValueHandler!";
97 
98  dh_ = init_data.dh;
99  data_vec_ = init_data.data_vec;
100  value_.set_n_comp(init_data.n_comp);
101  range_begin_ = init_data.range_begin;
102  range_end_ = init_data.range_end;
103  fe_ = init_data.mixed_fe[Dim<elemdim>{}];
104 }
105 
106 
107 template <int elemdim, int spacedim, class Value> inline
108 typename Value::return_type const &FEValueHandler<elemdim, spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
109 {
110  Armor::array point_list(spacedim, 1, 1);
111  point_list.set(0) = Armor::ArmaVec<double,spacedim>( p );
113  v_list.push_back(r_value_);
114  this->value_list(point_list, elm, v_list);
115  this->r_value_ = v_list[0];
116  return this->r_value_;
117 }
118 
119 
120 template <int elemdim, int spacedim, class Value>
123 {
124  ASSERT_EQ( point_list.size(), value_list.size() ).error();
125 
126  const DHCellAccessor cell = dh_->cell_accessor_from_element( elm.idx() );
127  LocDofVec loc_dofs;
128  if (boundary_dofs_) loc_dofs = this->get_loc_dof_indices(elm.idx());
129  else loc_dofs = cell.get_loc_dof_indices();
130 
131  // map points to reference cell, create quadrature and FEValues object
133  Quadrature quad(elemdim, point_list.size());
134  for (unsigned int k=0; k<point_list.size(); k++)
136 
137  FEValues<spacedim> fe_values(quad, *fe_, update_values);
138  fe_values.reinit( elm );
139 
140  for (unsigned int k=0; k<point_list.size(); k++) {
141  Value envelope(value_list[k]);
142  envelope.zeros();
143  for (unsigned int i=this->range_begin_, i_dof=0; i<this->range_end_; i++, i_dof++) {
144  value_list[k] += data_vec_.get(loc_dofs[i])
146  }
147  }
148 }
149 
150 
151 template <int elemdim, int spacedim, class Value>
152 unsigned int FEValueHandler<elemdim, spacedim, Value>::compute_quadrature(std::vector<arma::vec::fixed<3>> & q_points, std::vector<double> & q_weights,
153  const ElementAccessor<spacedim> &ele, unsigned int order)
154 {
155  static const double weight_coefs[] = { 1., 1., 2., 6. };
156 
157  QGauss qgauss(elemdim, order);
159 
160  for(unsigned i=0; i<qgauss.size(); ++i) {
161  q_weights[i] = qgauss.weight(i)*weight_coefs[elemdim];
163  }
164 
165  return qgauss.size();
166 }
167 
168 
169 template <int spacedim, class Value>
171 {
172  if (dh_)
173  WarningOut() << "Multiple initialization of FEValueHandler!";
174 
175  dh_ = init_data.dh;
176  data_vec_ = init_data.data_vec;
177  value_.set_n_comp(init_data.n_comp);
178  range_begin_ = init_data.range_begin;
179  range_end_ = init_data.range_end;
180 }
181 
182 
183 template <int spacedim, class Value>
186 {
187  ASSERT_EQ( point_list.size(), value_list.size() ).error();
188 
189  const DHCellAccessor cell = dh_->cell_accessor_from_element( elm.idx() );
190  LocDofVec loc_dofs;
191  if (boundary_dofs_) loc_dofs = this->get_loc_dof_indices(elm.idx());
192  else loc_dofs = cell.get_loc_dof_indices();
193 
194  for (unsigned int k=0; k<point_list.size(); k++) {
195  Value envelope(value_list[k]);
196  envelope.zeros();
197  for (unsigned int i=this->range_begin_; i<this->range_end_; i++) {
198  envelope(i / envelope.n_cols(), i % envelope.n_rows()) += data_vec_.get(loc_dofs[i]);
199  }
200  }
201 }
202 
203 
204 template <int elemdim, int spacedim, class Value>
206 {
207 }
208 
209 
210 // Instantiations of FEValueHandler and FEShapeHandler
211 #define INSTANCE_VALUE_HANDLER_ALL(dim, spacedim) \
212 template class FEValueHandler<dim, spacedim, FieldValue<0>::Enum >; \
213 template class FEValueHandler<dim, spacedim, FieldValue<0>::Integer >; \
214 template class FEValueHandler<dim, spacedim, FieldValue<0>::Scalar >; \
215 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::VectorFixed >; \
216 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::TensorFixed >;
217 
218 #define INSTANCE_VALUE_HANDLER(dim) \
219 INSTANCE_VALUE_HANDLER_ALL(dim,3)
220 //INSTANCE_VALUE_HANDLER_ALL(dim,2)
221 
226 
227 template class FEShapeHandler<0, 3, FieldValue<0>::Enum >;
228 template class FEShapeHandler<0, 3, FieldValue<0>::Integer >;
229 template class FEShapeHandler<0, 3, FieldValue<0>::Scalar >;
230 template class FEShapeHandler<1, 3, FieldValue<3>::VectorFixed >;
231 template class FEShapeHandler<2, 3, FieldValue<3>::TensorFixed >;
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell...
Shape function values.
Definition: update_flags.hh:87
Definition: mixed.hh:25
unsigned int size() const
Definition: armor.hh:728
Armor::Array< double >::ArrayMatSet set(uint i)
Definition: quadrature.hh:98
static Value::return_type fe_value(FEValues< 3 > &fe_val, unsigned int i_dof, unsigned int i_qp, FMT_UNUSED unsigned int comp_index)
const FEValuesViews::Vector< spacedim > & vector_view(unsigned int i) const
Accessor to vector values of multicomponent FE.
Definition: fe_values.hh:277
arma::Col< IntIdx > LocDofVec
Definition: index_types.hh:28
Armor::ArmaVec< double, point_dim > point(unsigned int i) const
Returns the ith quadrature point.
Definition: quadrature.hh:92
void initialize(FEValueInitData init_data)
Initialize data members.
LocDofVec get_loc_dof_indices(unsigned int cell_idx) const
TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
Space< spacedim >::Point Point
unsigned int range_end
Holds end of component range of evaluation.
double weight(unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:108
Cell accessor allow iterate over DOF handler cells.
Class FEValues calculates finite element data on the actual cells such as shape function values...
LocDofVec get_loc_dof_indices() const
Returns the local indices of dofs associated to the cell on the local process.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:821
Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
Returns one value in one given point.
void reinit(const ElementAccessor< spacedim > &cell)
Update cell-dependent data (gradients, Jacobians etc.)
Definition: fe_values.cc:541
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: quadrature.hh:48
Symmetric Gauss-Legendre quadrature formulae on simplices.
static LocalPoint bary_to_local(const BaryPoint &bp)
Converts from barycentric to local coordinates.
Definition: ref_element.cc:319
MixedPtr< FiniteElement > mixed_fe
FiniteElement objects of all dimensions.
ArmaMat< double, N, M > mat
Definition: armor.hh:888
#define FMT_UNUSED
Definition: posix.h:75
static Value::return_type fe_value(FEValues< 3 > &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
Value::return_type r_value_
unsigned int range_end_
End of dof range of actual component.
Basic definitions of numerical quadrature rules.
std::shared_ptr< FiniteElement< elemdim > > fe_
Pointer to FiniteElement object used to computing values.
ArrayMatSet set(uint index)
Definition: armor.hh:838
Affine mapping between reference and actual cell.
Definition: mapping_p1.hh:58
std::shared_ptr< DOFHandlerMultiDim > dh_
DOF handler object.
static Value::return_type fe_value(FEValues< spacedim > &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
static Value::return_type fe_value(FEValues< 3 > &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
unsigned int compute_quadrature(std::vector< arma::vec::fixed< 3 >> &q_points, std::vector< double > &q_weights, const ElementAccessor< spacedim > &elm, unsigned int order=3)
Compute real coordinates and weights (use QGauss) for given element.
std::shared_ptr< DOFHandlerMultiDim > dh
DOF handler object.
const FEValuesViews::Tensor< spacedim > & tensor_view(unsigned int i) const
Accessor to tensor values of multicomponent FE.
Definition: fe_values.hh:287
typename arma::Col< Type >::template fixed< nr > ArmaVec
Definition: armor.hh:505
double get(unsigned int pos) const
Return value on given position.
Definition: vector_mpi.hh:105
Value value_
Last value, prevents passing large values (vectors) by value.
#define INSTANCE_VALUE_HANDLER(dim)
void value_list(const Armor::array &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
Returns std::vector of scalar values in several points at once.
VectorMPI data_vec_
Store data of Field.
~FEValueHandler()
Destructor.
Definitions of particular quadrature rules on simplices.
#define WarningOut()
Macro defining &#39;warning&#39; record of log.
Definition: logger.hh:270
Calculates finite element data on the actual cell.
Definition: fe_values.hh:66
std::shared_ptr< std::vector< IntIdx > > boundary_dofs_
unsigned int range_begin_
Begin of dof range of actual component.
VectorMPI data_vec
Store data of Field.
static ElementMap element_map(ElementAccessor< 3 > elm)
Definition: mapping_p1.cc:48
FEValueHandler()
Constructor.
static RealPoint project_unit_to_real(const BaryPoint &point, const ElementMap &map)
Definition: mapping_p1.cc:85
unsigned int n_comp
number of components
unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:87
Initialization structure of FEValueHandler class.
const FEValuesViews::Scalar< spacedim > & scalar_view(unsigned int i) const
Accessor to scalar values of multicomponent FE.
Definition: fe_values.hh:267
unsigned int idx() const
Return local idx of element in boundary / bulk part of element vector.
Definition: accessors.hh:181
unsigned int range_begin
Holds begin of component range of evaluation.
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:328