Flow123d  master-7bf36fe
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_PERMANENT(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>
108 unsigned int FEValueHandler<elemdim, spacedim, Value>::compute_quadrature(std::vector<arma::vec::fixed<3>> & q_points, std::vector<double> & q_weights,
109  const ElementAccessor<spacedim> &ele, unsigned int order)
110 {
111  static const double weight_coefs[] = { 1., 1., 2., 6. };
112 
113  QGauss qgauss(elemdim, order);
115 
116  for(unsigned i=0; i<qgauss.size(); ++i) {
117  q_weights[i] = qgauss.weight(i)*weight_coefs[elemdim];
119  }
120 
121  return qgauss.size();
122 }
123 
124 
125 template <int spacedim, class Value>
127 {
128  if (dh_)
129  WarningOut() << "Multiple initialization of FEValueHandler!";
130 
131  dh_ = init_data.dh;
132  data_vec_ = init_data.data_vec;
133  value_.set_n_comp(init_data.n_comp);
134  range_begin_ = init_data.range_begin;
135  range_end_ = init_data.range_end;
136 }
137 
138 
139 template <int spacedim, class Value>
142 {
143  ASSERT_EQ( point_list.size(), value_list.size() ).error();
144 
145  const DHCellAccessor cell = dh_->cell_accessor_from_element( elm.idx() );
146  LocDofVec loc_dofs = cell.get_loc_dof_indices();
147 
148  for (unsigned int k=0; k<point_list.size(); k++) {
149  Value envelope(value_list[k]);
150  envelope.zeros();
151  for (unsigned int i=this->range_begin_; i<this->range_end_; i++) {
152  envelope(i / envelope.n_cols(), i % envelope.n_rows()) += data_vec_.get(loc_dofs[i]);
153  }
154  }
155 }
156 
157 
158 template <int elemdim, int spacedim, class Value>
160 {
161 }
162 
163 
164 // Instantiations of FEValueHandler and FEShapeHandler
165 #define INSTANCE_VALUE_HANDLER_ALL(dim, spacedim) \
166 template class FEValueHandler<dim, spacedim, FieldValue<0>::Enum >; \
167 template class FEValueHandler<dim, spacedim, FieldValue<0>::Integer >; \
168 template class FEValueHandler<dim, spacedim, FieldValue<0>::Scalar >; \
169 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::VectorFixed >; \
170 template class FEValueHandler<dim, spacedim, FieldValue<spacedim>::TensorFixed >;
171 
172 #define INSTANCE_VALUE_HANDLER(dim) \
173 INSTANCE_VALUE_HANDLER_ALL(dim,3)
174 //INSTANCE_VALUE_HANDLER_ALL(dim,2)
175 
180 
181 template class FEShapeHandler<0, 3, FieldValue<0>::Enum >;
182 template class FEShapeHandler<0, 3, FieldValue<0>::Integer >;
183 template class FEShapeHandler<0, 3, FieldValue<0>::Scalar >;
184 template class FEShapeHandler<1, 3, FieldValue<3>::VectorFixed >;
185 template class FEShapeHandler<2, 3, FieldValue<3>::TensorFixed >;
FEValueHandler::~FEValueHandler
~FEValueHandler()
Destructor.
Definition: fe_value_handler.cc:159
LocDofVec
arma::Col< IntIdx > LocDofVec
Definition: index_types.hh:28
FEValueInitData::range_end
unsigned int range_end
Holds end of component range of evaluation.
Definition: fe_value_handler.hh:48
FEShapeHandler
Definition: fe_value_handler.cc:38
FEValues::vector_view
const FEValuesViews::Vector< spacedim > & vector_view(unsigned int i) const
Accessor to vector values of multicomponent FE.
Definition: fe_values.hh:277
fe_values_views.hh
vector_mpi.hh
RefElement
Definition: ref_element.hh:339
FEValueHandler::initialize
void initialize(FEValueInitData init_data)
Initialize data members.
Definition: fe_value_handler.cc:93
fe_values.hh
Class FEValues calculates finite element data on the actual cells such as shape function values,...
Quadrature::size
unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:86
std::vector
Definition: doxy_dummy_defs.hh:7
ElementAccessor
Definition: dh_cell_accessor.hh:32
Dim
Definition: mixed.hh:25
FEValues
Calculates finite element data on the actual cell.
Definition: fe_values.hh:66
FEValueInitData::mixed_fe
MixedPtr< FiniteElement > mixed_fe
FiniteElement objects of all dimensions.
Definition: fe_value_handler.hh:50
MappingP1::project_unit_to_real
static RealPoint project_unit_to_real(const BaryPoint &point, const ElementMap &map)
Definition: mapping_p1.cc:85
FEValueHandler::dh_
std::shared_ptr< DOFHandlerMultiDim > dh_
DOF handler object.
Definition: fe_value_handler.hh:76
dh_cell_accessor.hh
Armor::mat
ArmaMat< double, N, M > mat
Definition: armor.hh:888
accessors.hh
FEValueInitData::dh
std::shared_ptr< DOFHandlerMultiDim > dh
DOF handler object.
Definition: fe_value_handler.hh:38
ASSERT_PERMANENT
#define ASSERT_PERMANENT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:348
quadrature_lib.hh
Definitions of particular quadrature rules on simplices.
FEValueHandler::range_end_
unsigned int range_end_
End of dof range of actual component.
Definition: fe_value_handler.hh:85
Quadrature::weight
double weight(unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:103
FEShapeHandler< 0, spacedim, Value >::fe_value
static Value::return_type fe_value(FEValues< 3 > &fe_val, unsigned int i_dof, unsigned int i_qp, FMT_UNUSED unsigned int comp_index)
Definition: fe_value_handler.cc:56
ASSERT_EQ
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:333
FEShapeHandler< 1, spacedim, Value >::fe_value
static Value::return_type fe_value(FEValues< 3 > &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
Definition: fe_value_handler.cc:67
FEValueHandler::data_vec_
VectorMPI data_vec_
Store data of Field.
Definition: fe_value_handler.hh:78
FEShapeHandler< 2, spacedim, Value >::fe_value
static Value::return_type fe_value(FEValues< 3 > &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
Definition: fe_value_handler.cc:78
FEValueHandler::value_
Value value_
Last value, prevents passing large values (vectors) by value.
Definition: fe_value_handler.hh:80
FEValueHandler::compute_quadrature
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.
Definition: fe_value_handler.cc:108
bounding_box.hh
Armor::Array::size
unsigned int size() const
Definition: armor.hh:728
FEValueInitData
Initialization structure of FEValueHandler class.
Definition: fe_value_handler.hh:35
FEValues::tensor_view
const FEValuesViews::Tensor< spacedim > & tensor_view(unsigned int i) const
Accessor to tensor values of multicomponent FE.
Definition: fe_values.hh:287
QGauss
Symmetric Gauss-Legendre quadrature formulae on simplices.
Definition: quadrature_lib.hh:34
Value
@ Value
Definition: finite_element.hh:43
FEValueHandler::FEValueHandler
FEValueHandler()
Constructor.
Definition: fe_value_handler.cc:87
MappingP1::element_map
static ElementMap element_map(ElementAccessor< 3 > elm)
Definition: mapping_p1.cc:48
DHCellAccessor
Cell accessor allow iterate over DOF handler cells.
Definition: dh_cell_accessor.hh:43
FEValueHandler
Definition: fe_value_handler.hh:57
WarningOut
#define WarningOut()
Macro defining 'warning' record of log.
Definition: logger.hh:278
Quadrature::point
Armor::ArmaVec< double, point_dim > point(unsigned int i) const
Returns the ith quadrature point.
Definition: quadrature.hh:151
fe_value_handler.hh
FEValues::scalar_view
const FEValuesViews::Scalar< spacedim > & scalar_view(unsigned int i) const
Accessor to scalar values of multicomponent FE.
Definition: fe_values.hh:267
quadrature.hh
Basic definitions of numerical quadrature rules.
FEValueHandler::range_begin_
unsigned int range_begin_
Begin of dof range of actual component.
Definition: fe_value_handler.hh:83
DHCellAccessor::get_loc_dof_indices
LocDofVec get_loc_dof_indices() const
Returns the local indices of dofs associated to the cell on the local process.
Definition: dh_cell_accessor.hh:88
Armor::Array< double >
FEValueInitData::data_vec
VectorMPI data_vec
Store data of Field.
Definition: fe_value_handler.hh:40
ElementAccessor::idx
unsigned int idx() const
We need this method after replacing Region by RegionIdx, and movinf RegionDB instance into particular...
Definition: accessors.hh:215
FEShapeHandler::fe_value
static Value::return_type fe_value(FEValues< spacedim > &fe_val, unsigned int i_dof, unsigned int i_qp, unsigned int comp_index)
Definition: fe_value_handler.cc:41
mapping_p1.hh
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell.
VectorMPI::get
double get(unsigned int pos) const
Return value on given position.
Definition: vector_mpi.hh:105
FEValueInitData::range_begin
unsigned int range_begin
Holds begin of component range of evaluation.
Definition: fe_value_handler.hh:46
INSTANCE_VALUE_HANDLER
#define INSTANCE_VALUE_HANDLER(dim)
Definition: fe_value_handler.cc:172
FEValueInitData::n_comp
unsigned int n_comp
number of components
Definition: fe_value_handler.hh:44
FieldValue
Definition: field_values.hh:645
FMT_UNUSED
#define FMT_UNUSED
Definition: posix.h:75