Flow123d  release_3.0.0-873-g1d64664
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  * Practical use have only instances with rank template parameters 0 and 1 (Scalar and Vector Fields, see below).
35  */
36 template<int rank, int elemdim, int spacedim, class Value>
38 public:
39 
40  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
41  {
42  ASSERT(false).error("Unsupported format of FieldFE!\n");
43  typename Value::return_type ret;
44  Value val(ret);
45  val.zeros();
46  return ret;
47  }
48 };
49 
50 
51 /// Partial template specialization of FEShapeHandler for scalar fields
52 template<int elemdim, int spacedim, class Value>
53 class FEShapeHandler<0, elemdim, spacedim, Value> {
54 public:
55  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
56  {
57  return fe_val.shape_value(i_dof, i_qp);
58  }
59 };
60 
61 
62 /// Partial template specialization of FEShapeHandler for vector fields
63 template<int elemdim, int spacedim, class Value>
64 class FEShapeHandler<1, elemdim, spacedim, Value> {
65 public:
66  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
67  {
68  return fe_val.vector_view(comp_index).value(i_dof, i_qp);
69  }
70 };
71 
72 
73 /// Partial template specialization of FEShapeHandler for tensor fields
74 template<int elemdim, int spacedim, class Value>
75 class FEShapeHandler<2, elemdim, spacedim, Value> {
76 public:
77  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
78  {
79  return fe_val.tensor_view(comp_index).value(i_dof, i_qp);
80  }
81 };
82 
83 
84 
85 template <int elemdim, int spacedim, class Value>
87 : value_(r_value_),
88  map_(nullptr)
89 {}
90 
91 
92 template <int elemdim, int spacedim, class Value>
94 {
95  if (dof_indices.size() > 0)
96  WarningOut() << "Multiple initialization of FEValueHandler!";
97 
98  dh_ = init_data.dh;
99  data_vec_ = init_data.data_vec;
100  dof_indices.resize(init_data.ndofs);
101  value_.set_n_comp(init_data.n_comp);
102  comp_index_ = init_data.comp_index;
103 
104  // temporary solution - these objects will be set through FieldCommon
105  map_ = new MappingP1<elemdim,3>();
106 }
107 
108 
109 template <int elemdim, int spacedim, class Value> inline
110 typename Value::return_type const &FEValueHandler<elemdim, spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
111 {
112  std::vector<Point> point_list;
113  point_list.push_back(p);
115  v_list.push_back(r_value_);
116  this->value_list(point_list, elm, v_list);
117  this->r_value_ = v_list[0];
118  return this->r_value_;
119 }
120 
121 
122 template <int elemdim, int spacedim, class Value>
125 {
126  ASSERT_PTR(map_).error();
127  ASSERT_EQ( point_list.size(), value_list.size() ).error();
128 
129  const DHCellAccessor cell = dh_->cell_accessor_from_element( elm.idx() );
130  if (boundary_dofs_) this->get_dof_indices( elm, dof_indices);
131  else cell.get_loc_dof_indices( dof_indices );
132 
133  arma::mat map_mat = map_->element_map(elm);
134  for (unsigned int k=0; k<point_list.size(); k++) {
135  Quadrature<elemdim> quad(1);
136  quad.set_point(0, RefElement<elemdim>::bary_to_local(map_->project_real_to_unit(point_list[k], map_mat)));
137 
138  FEValues<elemdim,3> fe_values(*this->get_mapping(), quad, *dh_->ds()->fe<elemdim>(elm), update_values);
139  fe_values.reinit( const_cast<ElementAccessor<spacedim> &>(elm) );
140 
141  Value envelope(value_list[k]);
142  envelope.zeros();
143  for (unsigned int i=0; i<dh_->ds()->fe<elemdim>(elm)->n_dofs(); i++) {
144  value_list[k] += data_vec_[dof_indices[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<elemdim> qgauss(order);
158  arma::mat map_mat = map_->element_map(ele);
159 
160  for(unsigned i=0; i<qgauss.size(); ++i) {
161  q_weights[i] = qgauss.weight(i)*weight_coefs[elemdim];
162  q_points[i] = map_->project_unit_to_real(RefElement<elemdim>::local_to_bary(qgauss.point(i)), map_mat);
163  }
164 
165  return qgauss.size();
166 }
167 
168 
169 template <int elemdim, int spacedim, class Value>
171 {
172  unsigned int ndofs = this->value_.n_rows() * this->value_.n_cols();
173  for (unsigned int k=0; k<ndofs; k++) {
174  indices[k] = (*boundary_dofs_)[ndofs*cell.idx()+k];
175  }
176  return ndofs;
177 }
178 
179 
180 template <int spacedim, class Value>
182 {
183  if (dof_indices.size() > 0)
184  WarningOut() << "Multiple initialization of FEValueHandler!";
185 
186  dh_ = init_data.dh;
187  data_vec_ = init_data.data_vec;
188  dof_indices.resize(init_data.ndofs);
189  value_.set_n_comp(init_data.n_comp);
190 }
191 
192 
193 template <int spacedim, class Value>
196 {
197  ASSERT_EQ( point_list.size(), value_list.size() ).error();
198 
199  const DHCellAccessor cell = dh_->cell_accessor_from_element( elm.idx() );
200  if (boundary_dofs_) this->get_dof_indices( elm, dof_indices);
201  else cell.get_loc_dof_indices( dof_indices );
202 
203  for (unsigned int k=0; k<point_list.size(); k++) {
204  Value envelope(value_list[k]);
205  envelope.zeros();
206  for (unsigned int i=0; i<dh_->ds()->fe<0>(elm)->n_dofs(); i++) {
207  envelope(i / envelope.n_cols(), i % envelope.n_rows()) += data_vec_[dof_indices[i]];
208  }
209  }
210 }
211 
212 
213 template <int spacedim, class Value>
215 {
216  unsigned int ndofs = this->value_.n_rows() * this->value_.n_cols();
217  for (unsigned int k=0; k<ndofs; k++) {
218  indices[k] = (*boundary_dofs_)[ndofs*cell.idx()+k];
219  }
220  return ndofs;
221 }
222 
223 
224 template <int elemdim, int spacedim, class Value>
226 {}
227 
228 
229 // Instantiations of FEValueHandler and FEShapeHandler
230 #define INSTANCE_VALUE_HANDLER_ALL(dim, spacedim) \
231 template class FEValueHandler<dim, spacedim, FieldValue<0>::Enum >; \
232 template class FEValueHandler<dim, spacedim, FieldValue<0>::Integer >; \
233 template class FEValueHandler<dim, spacedim, FieldValue<0>::Scalar >; \
234 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::VectorFixed >; \
235 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::TensorFixed >; \
236 template class FEShapeHandler<0, dim, spacedim, FieldValue<0>::Enum >; \
237 template class FEShapeHandler<0, dim, spacedim, FieldValue<0>::Integer >; \
238 template class FEShapeHandler<0, dim, spacedim, FieldValue<0>::Scalar >; \
239 template class FEShapeHandler<1, dim, spacedim, FieldValue<spacedim>::VectorFixed >; \
240 template class FEShapeHandler<2, dim, spacedim, FieldValue<spacedim>::TensorFixed >;
241 
242 #define INSTANCE_VALUE_HANDLER(dim) \
243 INSTANCE_VALUE_HANDLER_ALL(dim,3)
244 //INSTANCE_VALUE_HANDLER_ALL(dim,2) \
245 
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 comp_index_
Index of component (of vector_value/tensor_value)
RealPoint project_unit_to_real(const BaryPoint &point, const ElementMap &map) const
Definition: mapping_p1.cc:291
void initialize(FEValueInitData init_data)
Initialize data members.
BaryPoint project_real_to_unit(const RealPoint &point, const ElementMap &map) const
Definition: mapping_p1.cc:275
Space< spacedim >::Point Point
unsigned int get_loc_dof_indices(std::vector< LongIdx > &indices) const
Returns the indices of dofs associated to the cell on the local process.
static Value::return_type fe_value(FEValues< elemdim, 3 > &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
Class FEValues calculates finite element data on the actual cells such as shape function values...
const FEValuesViews::Tensor< dim, spacedim > & tensor_view(unsigned int i) const
Accessor to tensor values of multicomponent FE.
Definition: fe_values.hh:398
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:346
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: fe_values.hh:35
Symmetric Gauss-Legendre quadrature formulae on simplices.
MappingP1< elemdim, 3 > * map_
Mapping object.
static Value::return_type fe_value(FEValues< elemdim, 3 > &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
double weight(const unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:161
void value_list(const std::vector< Point > &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.
Value::return_type r_value_
Basic definitions of numerical quadrature rules.
std::vector< LongIdx > dof_indices
Array of indexes to data_vec_, used for get/set values.
std::shared_ptr< DOFHandlerMultiDim > dh_
DOF handler object.
unsigned int ndofs
number of dofs
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.
const FEValuesViews::Vector< dim, spacedim > & vector_view(unsigned int i) const
Accessor to vector values of multicomponent FE.
Definition: fe_values.hh:388
std::shared_ptr< DOFHandlerMultiDim > dh
DOF handler object.
unsigned int get_dof_indices(const ElementAccessor< 3 > &cell, std::vector< LongIdx > &indices) const
TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
double shape_value(const unsigned int function_no, const unsigned int point_no)
Return the value of the function_no-th shape function at the point_no-th quadrature point...
Definition: fe_values.cc:224
MappingP1< elemdim, 3 > * get_mapping()
Return mapping object.
Value value_
Last value, prevents passing large values (vectors) by value.
#define INSTANCE_VALUE_HANDLER(dim)
void set_point(const unsigned int i, const arma::vec::fixed< dim > &p)
Sets individual quadrature point coordinates.
Definition: quadrature.hh:155
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
Definition: asserts.hh:335
std::shared_ptr< std::vector< LongIdx > > boundary_dofs_
VectorMPI data_vec_
Store data of Field.
const unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:139
~FEValueHandler()
Destructor.
static Value::return_type fe_value(FEValues< elemdim, 3 > &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
const arma::vec::fixed< dim > & point(const unsigned int i) const
Returns the ith quadrature point.
Definition: quadrature.hh:144
Definitions of particular quadrature rules on simplices.
#define WarningOut()
Macro defining &#39;warning&#39; record of log.
Definition: logger.hh:246
Calculates finite element data on the actual cell.
Definition: fe_values.hh:532
static Value::return_type fe_value(FEValues< elemdim, 3 > &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
VectorMPI data_vec
Store data of Field.
FEValueHandler()
Constructor.
ElementMap element_map(ElementAccessor< 3 > elm) const
Definition: mapping_p1.cc:265
unsigned int n_comp
number of components
Initialization structure of FEValueHandler class.
unsigned int idx() const
Return local idx of element in boundary / bulk part of element vector.
Definition: accessors.hh:111
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:327
void reinit(ElementAccessor< 3 > &cell)
Update cell-dependent data (gradients, Jacobians etc.)
Definition: fe_values.cc:528