Flow123d  intersections_paper-476-gbe68821
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 
24 
25 /**
26  * Helper class, allow to simplify computing value of FieldFE.
27  *
28  * Use correct method FEValues<...>::shape_xxx given with Value::rank_.
29  * Practical use have only instances with rank template parameters 0 and 1 (Scalar and Vector Fields, see below).
30  */
31 template<int rank, int elemdim, int spacedim, class Value>
33 public:
34  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp)
35  {
36  ASSERT(false).error("Unsupported format of FieldFE!\n");
37  typename Value::return_type ret;
38  Value val(ret);
39  val.zeros();
40  return ret;
41  }
42 };
43 
44 
45 /// Partial template specialization of FEShapeHandler for scalar fields
46 template<int elemdim, int spacedim, class Value>
47 class FEShapeHandler<0, elemdim, spacedim, Value> {
48 public:
49  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp)
50  {
51  return fe_val.shape_value(i_dof, i_qp);
52  }
53 };
54 
55 
56 /// Partial template specialization of FEShapeHandler for vector fields
57 template<int elemdim, int spacedim, class Value>
58 class FEShapeHandler<1, elemdim, spacedim, Value> {
59 public:
60  inline static typename Value::return_type fe_value(FEValues<elemdim,3> &fe_val, unsigned int i_dof, unsigned int i_qp)
61  {
62  return fe_val.shape_vector(i_dof, i_qp);
63  }
64 };
65 
66 
67 
68 template <int elemdim, int spacedim, class Value>
70 : dof_indices(nullptr),
71  value_(r_value_),
72  map_(nullptr)
73 {}
74 
75 
76 template <int elemdim, int spacedim, class Value>
78 {
79  ASSERT(dof_indices == nullptr).error("Multiple initialization.");
80 
81  dh_ = init_data.dh;
82  data_vec_ = init_data.data_vec;
83  dof_indices = new unsigned int[init_data.ndofs];
84  value_.set_n_comp(init_data.n_comp);
85 
86  if (map == nullptr) {
87  // temporary solution - these objects will be set through FieldCommon
88  map_ = new MappingP1<elemdim,3>();
89  } else {
90  map_ = map;
91  }
92 }
93 
94 
95 template <int elemdim, int spacedim, class Value> inline
96 typename Value::return_type const &FEValueHandler<elemdim, spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
97 {
98  std::vector<Point> point_list;
99  point_list.push_back(p);
101  v_list.push_back(r_value_);
102  this->value_list(point_list, elm, v_list);
103  this->r_value_ = v_list[0];
104  return this->r_value_;
105 }
106 
107 
108 template <int elemdim, int spacedim, class Value>
111 {
112  ASSERT_PTR(map_).error();
113  ASSERT_EQ( point_list.size(), value_list.size() ).error();
114 
115  DOFHandlerBase::CellIterator cell = dh_->mesh()->element( elm.idx() );
116  dh_->get_loc_dof_indices(cell, dof_indices);
117 
118  arma::mat::fixed<3,elemdim> m;
119  for (unsigned i=0; i<elemdim; ++i) {
120  m.col(i) = elm.element()->node[i+1]->point() - elm.element()->node[0]->point();
121  }
122  arma::mat::fixed<elemdim,3> im = pinv(m);
123 
124  for (unsigned int k=0; k<point_list.size(); k++) {
125  Point p_rel = point_list[k] - elm.element()->node[0]->point();
126  Quadrature<elemdim> quad(1);
127  quad.set_point(0, im*p_rel);
128 
129  FEValues<elemdim,3> fe_values(*this->get_mapping(), quad, *dh_->fe<elemdim>(), update_values);
130  fe_values.reinit(cell);
131 
132  Value envelope(value_list[k]);
133  envelope.zeros();
134  for (unsigned int i=0; i<dh_->fe<elemdim>()->n_dofs(); i++)
135  value_list[k] += (*data_vec_)[dof_indices[i]]
137  }
138 }
139 
140 
141 template <int elemdim, int spacedim, class Value>
143 {
144  ASSERT_PTR(map_).error();
145 
146  arma::vec projection = map_->project_point(point, map_->element_map(elm));
147  return (projection.min() >= -BoundingBox::epsilon);
148 }
149 
150 
151 template <int elemdim, int spacedim, class Value>
153 {
154  if (dof_indices != nullptr) delete[] dof_indices;
155 }
156 
157 
158 // Instantiations of FEValueHandler and FEShapeHandler
159 #define INSTANCE_VALUE_HANDLER_ALL(dim, spacedim) \
160 template class FEValueHandler<dim, spacedim, FieldValue<0>::Enum >; \
161 template class FEValueHandler<dim, spacedim, FieldValue<0>::Integer >; \
162 template class FEValueHandler<dim, spacedim, FieldValue<0>::Scalar >; \
163 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::VectorFixed >; \
164 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::TensorFixed >; \
165 template class FEShapeHandler<0, dim, spacedim, FieldValue<0>::Enum >; \
166 template class FEShapeHandler<0, dim, spacedim, FieldValue<0>::Integer >; \
167 template class FEShapeHandler<0, dim, spacedim, FieldValue<0>::Scalar >; \
168 template class FEShapeHandler<1, dim, spacedim, FieldValue<spacedim>::VectorFixed >; \
169 template class FEShapeHandler<2, dim, spacedim, FieldValue<spacedim>::TensorFixed >;
170 
171 #define INSTANCE_VALUE_HANDLER(dim) \
172 INSTANCE_VALUE_HANDLER_ALL(dim,2) \
173 INSTANCE_VALUE_HANDLER_ALL(dim,3)
174 
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell...
Shape function values.
Definition: update_flags.hh:87
const Element * element() const
Definition: accessors.hh:86
unsigned int * dof_indices
Array of indexes to data_vec_, used for get/set values.
void initialize(FEValueInitData init_data, MappingP1< elemdim, 3 > *map=nullptr)
Initialize data members.
Space< spacedim >::Point Point
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...
static const double epsilon
stabilization parameter
Definition: bounding_box.hh:57
Node ** node
Definition: elements.h:90
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
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:31
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::shared_ptr< DOFHandlerMultiDim > dh_
DOF handler object.
unsigned int ndofs
number of dofs
arma::vec::fixed< spacedim > shape_vector(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.hh:254
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.hh:226
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.
arma::mat::fixed< 3, dim+1 > element_map(Element &elm) const
Definition: mapping_p1.hh:113
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:146
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
Definition: asserts.hh:336
void reinit(ElementFullIter &cell)
Update cell-dependent data (gradients, Jacobians etc.)
Definition: fe_values.cc:157
~FEValueHandler()
Destructor.
Calculates finite element data on the actual cell.
Definition: fe_values.hh:416
bool contains_point(arma::vec point, Element &elm)
Test if element contains given point.
FEValueHandler()
Constructor.
unsigned int n_comp
number of components
arma::vec3 & point()
Definition: nodes.hh:68
Initialization structure of FEValueHandler class.
unsigned int idx() const
Definition: accessors.hh:113
static Value::return_type fe_value(FEValues< elemdim, 3 > &fe_val, unsigned int i_dof, unsigned int i_qp)
arma::vec::fixed< dim+1 > project_point(const arma::vec3 &point, const arma::mat::fixed< 3, dim+1 > &map) const
Definition: mapping_p1.cc:281
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:328