Flow123d  release_3.0.0-506-g34af125
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 "fem/mapping_p1.hh"
20 #include "fem/fe_values.hh"
21 #include "quadrature/quadrature.hh"
22 #include "mesh/bounding_box.hh"
23 #include "mesh/accessors.hh"
24 #include "fem/fe_values_views.hh"
25 
26 
27 /**
28  * Helper class, allow to simplify computing value of FieldFE.
29  *
30  * Use correct method FEValues<...>::shape_xxx given with Value::rank_.
31  * Practical use have only instances with rank template parameters 0 and 1 (Scalar and Vector Fields, see below).
32  */
33 template<int rank, int elemdim, int spacedim, class Value>
35 public:
36 
37  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp)
38  {
39  ASSERT(false).error("Unsupported format of FieldFE!\n");
40  typename Value::return_type ret;
41  Value val(ret);
42  val.zeros();
43  return ret;
44  }
45 };
46 
47 
48 /// Partial template specialization of FEShapeHandler for scalar fields
49 template<int elemdim, int spacedim, class Value>
50 class FEShapeHandler<0, elemdim, spacedim, Value> {
51 public:
52  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp)
53  {
54  return fe_val.shape_value(i_dof, i_qp);
55  }
56 };
57 
58 
59 /// Partial template specialization of FEShapeHandler for vector fields
60 template<int elemdim, int spacedim, class Value>
61 class FEShapeHandler<1, elemdim, spacedim, Value> {
62 public:
63  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp)
64  {
65  return fe_val.vector_view(0).value(i_dof, i_qp);
66  }
67 };
68 
69 
70 /// Partial template specialization of FEShapeHandler for tensor fields
71 template<int elemdim, int spacedim, class Value>
72 class FEShapeHandler<2, elemdim, spacedim, Value> {
73 public:
74  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp)
75  {
76  return fe_val.tensor_view(0).value(i_dof, i_qp);
77  }
78 };
79 
80 
81 
82 template <int elemdim, int spacedim, class Value>
84 : value_(r_value_),
85  map_(nullptr)
86 {}
87 
88 
89 template <int elemdim, int spacedim, class Value>
91 {
92  if (dof_indices.size() > 0)
93  WarningOut() << "Multiple initialization of FEValueHandler!";
94 
95  dh_ = init_data.dh;
96  data_vec_ = init_data.data_vec;
97  dof_indices.resize(init_data.ndofs);
98  value_.set_n_comp(init_data.n_comp);
99 
100  if (map == nullptr) {
101  // temporary solution - these objects will be set through FieldCommon
102  map_ = new MappingP1<elemdim,3>();
103  } else {
104  map_ = map;
105  }
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  ElementAccessor<3> cell = dh_->mesh()->element_accessor( elm.mesh_idx() );
130  dh_->get_dof_indices(cell, dof_indices);
131 
132  arma::mat map_mat = map_->element_map(elm);
133  for (unsigned int k=0; k<point_list.size(); k++) {
134  Quadrature<elemdim> quad(1);
135  quad.set_point(0, RefElement<elemdim>::bary_to_local(map_->project_real_to_unit(point_list[k], map_mat)));
136 
137  FEValues<elemdim,3> fe_values(*this->get_mapping(), quad, *dh_->fe<elemdim>(elm), update_values);
138  fe_values.reinit(cell);
139 
140  Value envelope(value_list[k]);
141  envelope.zeros();
142  for (unsigned int i=0; i<dh_->fe<elemdim>(elm)->n_dofs(); i++) {
143  value_list[k] += (*data_vec_)[dof_indices[i]]
145  }
146  }
147 }
148 
149 
150 template <int spacedim, class Value>
152 {
153  if (dof_indices.size() > 0)
154  WarningOut() << "Multiple initialization of FEValueHandler!";
155 
156  dh_ = init_data.dh;
157  data_vec_ = init_data.data_vec;
158  dof_indices.resize(init_data.ndofs);
159  value_.set_n_comp(init_data.n_comp);
160 }
161 
162 
163 template <int spacedim, class Value>
166 {
167  ASSERT_EQ( point_list.size(), value_list.size() ).error();
168 
169  ElementAccessor<3> cell = dh_->mesh()->element_accessor( elm.mesh_idx() );
170  dh_->get_dof_indices(cell, dof_indices);
171 
172  for (unsigned int k=0; k<point_list.size(); k++) {
173  Value envelope(value_list[k]);
174  envelope.zeros();
175  for (unsigned int i=0; i<dh_->fe<0>(elm)->n_dofs(); i++) {
176  envelope(i / envelope.n_cols(), i % envelope.n_rows()) += (*data_vec_)[dof_indices[i]];
177  }
178  }
179 }
180 
181 
182 template <int elemdim, int spacedim, class Value>
184 {}
185 
186 
187 // Instantiations of FEValueHandler and FEShapeHandler
188 #define INSTANCE_VALUE_HANDLER_ALL(dim, spacedim) \
189 template class FEValueHandler<dim, spacedim, FieldValue<0>::Enum >; \
190 template class FEValueHandler<dim, spacedim, FieldValue<0>::Integer >; \
191 template class FEValueHandler<dim, spacedim, FieldValue<0>::Scalar >; \
192 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::VectorFixed >; \
193 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::TensorFixed >; \
194 template class FEShapeHandler<0, dim, spacedim, FieldValue<0>::Enum >; \
195 template class FEShapeHandler<0, dim, spacedim, FieldValue<0>::Integer >; \
196 template class FEShapeHandler<0, dim, spacedim, FieldValue<0>::Scalar >; \
197 template class FEShapeHandler<1, dim, spacedim, FieldValue<spacedim>::VectorFixed >; \
198 template class FEShapeHandler<2, dim, spacedim, FieldValue<spacedim>::TensorFixed >;
199 
200 #define INSTANCE_VALUE_HANDLER(dim) \
201 INSTANCE_VALUE_HANDLER_ALL(dim,3)
202 //INSTANCE_VALUE_HANDLER_ALL(dim,2) \
203 
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell...
Shape function values.
Definition: update_flags.hh:87
BaryPoint project_real_to_unit(const RealPoint &point, const ElementMap &map) const
Definition: mapping_p1.cc:275
void initialize(FEValueInitData init_data, MappingP1< elemdim, 3 > *map=nullptr)
Initialize data members.
Space< spacedim >::Point Point
unsigned int mesh_idx() const
Return global idx of element in full element vector.
Definition: accessors.hh:117
static Value::return_type fe_value(FEValues< elemdim, 3 > &fe_val, unsigned int i_dof, unsigned int i_qp)
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
MappingP1< elemdim, 3 > * map_
Mapping object.
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_
VectorSeqDouble * data_vec
Store data of Field.
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
const FEValuesViews::Vector< dim, spacedim > & vector_view(unsigned int i) const
Accessor to vector values of multicomponent FE.
Definition: fe_values.hh:388
VectorSeqDouble * data_vec_
Store data of Field.
std::shared_ptr< DOFHandlerMultiDim > dh
DOF handler object.
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
static Value::return_type fe_value(FEValues< elemdim, 3 > &fe_val, unsigned int i_dof, unsigned int i_qp)
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
~FEValueHandler()
Destructor.
#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)
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.
static Value::return_type fe_value(FEValues< elemdim, 3 > &fe_val, unsigned int i_dof, unsigned int i_qp)
#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