Flow123d  JS_before_hm-883-gc471082
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  comp_index_ = init_data.comp_index;
102 }
103 
104 
105 template <int elemdim, int spacedim, class Value> inline
106 typename Value::return_type const &FEValueHandler<elemdim, spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
107 {
108  Armor::array point_list(spacedim, 1, 1);
109  point_list.set(0) = Armor::ArmaVec<double,spacedim>( p );
111  v_list.push_back(r_value_);
112  this->value_list(point_list, elm, v_list);
113  this->r_value_ = v_list[0];
114  return this->r_value_;
115 }
116 
117 
118 template <int elemdim, int spacedim, class Value>
121 {
122  ASSERT_EQ( point_list.size(), value_list.size() ).error();
123 
124  const DHCellAccessor cell = dh_->cell_accessor_from_element( elm.idx() );
125  LocDofVec loc_dofs;
126  if (boundary_dofs_) loc_dofs = this->get_loc_dof_indices(elm.idx());
127  else loc_dofs = cell.get_loc_dof_indices();
128 
129  // map points to reference cell, create quadrature and FEValues object
131  Quadrature quad(elemdim, point_list.size());
132  for (unsigned int k=0; k<point_list.size(); k++)
134 
135  MixedPtr<FiniteElement> fe_mixed_ptr = dh_->ds()->fe(elm);
136  std::shared_ptr<FiniteElement<elemdim>> fe_ptr = fe_mixed_ptr.get<elemdim>();
137  FEValues<spacedim> fe_values(quad, *fe_ptr, 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=0; i<loc_dofs.n_elem; i++) {
144  value_list[k] += data_vec_[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 }
179 
180 
181 template <int spacedim, class Value>
184 {
185  ASSERT_EQ( point_list.size(), value_list.size() ).error();
186 
187  const DHCellAccessor cell = dh_->cell_accessor_from_element( elm.idx() );
188  LocDofVec loc_dofs;
189  if (boundary_dofs_) loc_dofs = this->get_loc_dof_indices(elm.idx());
190  else loc_dofs = cell.get_loc_dof_indices();
191 
192  for (unsigned int k=0; k<point_list.size(); k++) {
193  Value envelope(value_list[k]);
194  envelope.zeros();
195  for (unsigned int i=0; i<loc_dofs.n_elem; i++) {
196  envelope(i / envelope.n_cols(), i % envelope.n_rows()) += data_vec_[loc_dofs[i]];
197  }
198  }
199 }
200 
201 
202 template <int elemdim, int spacedim, class Value>
204 {
205 }
206 
207 
208 // Instantiations of FEValueHandler and FEShapeHandler
209 #define INSTANCE_VALUE_HANDLER_ALL(dim, spacedim) \
210 template class FEValueHandler<dim, spacedim, FieldValue<0>::Enum >; \
211 template class FEValueHandler<dim, spacedim, FieldValue<0>::Integer >; \
212 template class FEValueHandler<dim, spacedim, FieldValue<0>::Scalar >; \
213 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::VectorFixed >; \
214 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::TensorFixed >;
215 
216 #define INSTANCE_VALUE_HANDLER(dim) \
217 INSTANCE_VALUE_HANDLER_ALL(dim,3)
218 //INSTANCE_VALUE_HANDLER_ALL(dim,2)
219 
224 
225 template class FEShapeHandler<0, 3, FieldValue<0>::Enum >;
226 template class FEShapeHandler<0, 3, FieldValue<0>::Integer >;
227 template class FEShapeHandler<0, 3, FieldValue<0>::Scalar >;
228 template class FEShapeHandler<1, 3, FieldValue<3>::VectorFixed >;
229 template class FEShapeHandler<2, 3, FieldValue<3>::TensorFixed >;
unsigned int comp_index
index of component (of vector_value/tensor_value)
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell...
Shape function values.
Definition: update_flags.hh:87
unsigned int size() const
Definition: armor.hh:718
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:254
unsigned int comp_index_
Index of component (of vector_value/tensor_value)
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
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:807
Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
Returns one value in one given point.
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
ArmaMat< double, N, M > mat
Definition: armor.hh:864
#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_
Basic definitions of numerical quadrature rules.
ArrayMatSet set(uint index)
Definition: armor.hh:821
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:264
typename arma::Col< Type >::template fixed< nr > ArmaVec
Definition: armor.hh:505
Value value_
Last value, prevents passing large values (vectors) by value.
#define INSTANCE_VALUE_HANDLER(dim)
std::shared_ptr< std::vector< Idx > > boundary_dofs_
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:258
Calculates finite element data on the actual cell.
Definition: fe_values.hh:59
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:244
unsigned int idx() const
Return local idx of element in boundary / bulk part of element vector.
Definition: accessors.hh:181
arma::Col< Idx > LocDofVec
Definition: index_types.hh:28
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:328
std::shared_ptr< T< i_dim > > get()
Definition: mixed.hh:244