Flow123d  JS_before_hm-2198-g122e1f2e2
fe_value_handler.hh
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.hh
15  * @brief
16  */
17 
18 #ifndef FE_VALUE_HANDLER_HH_
19 #define FE_VALUE_HANDLER_HH_
20 
21 #include "system/index_types.hh"
22 #include "fields/field_values.hh"
23 #include "fem/finite_element.hh"
24 #include "mesh/point.hh"
25 #include "la/vector_mpi.hh"
26 #include <armadillo>
27 #include "system/armor.hh"
28 #include "tools/mixed.hh"
29 
30 class DOFHandlerMultiDim;
31 template <int spacedim> class ElementAccessor;
32 
33 
34 /// Initialization structure of FEValueHandler class.
36 {
37  /// DOF handler object
38  std::shared_ptr<DOFHandlerMultiDim> dh;
39  /// Store data of Field
41  /// number of dofs
42  unsigned int ndofs;
43  /// number of components
44  unsigned int n_comp;
45  /// Holds begin of component range of evaluation.
46  unsigned int range_begin;
47  /// Holds end of component range of evaluation.
48  unsigned int range_end;
49  /// FiniteElement objects of all dimensions.
51 };
52 
53 /**
54  * Helper class that allows compute finite element values specified by element dimension.
55  */
56 template <int elemdim, int spacedim, class Value>
58 {
59 public:
60  typedef typename Space<spacedim>::Point Point;
61 
62  /// Constructor.
64 
65  /// Initialize data members
66  void initialize(FEValueInitData init_data);
67  /// Returns one value in one given point.
68  typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm);
69  /// Returns std::vector of scalar values in several points at once.
70  void value_list (const Armor::array &point_list, const ElementAccessor<spacedim> &elm,
72  /// Compute real coordinates and weights (use QGauss) for given element
73  unsigned int compute_quadrature(std::vector<arma::vec::fixed<3>> & q_points, std::vector<double> & q_weights,
74  const ElementAccessor<spacedim> &elm, unsigned int order=3);
75 
76  /// Destructor.
78 
79  /// TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
80  inline void set_boundary_dofs_vector(std::shared_ptr< std::vector<IntIdx> > boundary_dofs) {
81  this->boundary_dofs_ = boundary_dofs;
82  }
83 
84  /// TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
85  inline LocDofVec get_loc_dof_indices(unsigned int cell_idx) const
86  {
87  unsigned int ndofs = this->value_.n_rows() * this->value_.n_cols();
88  // create armadillo vector on top of existing array
89  // vec(ptr_aux_mem, number_of_elements, copy_aux_mem = true, strict = false)
90  IntIdx* mem_ptr = const_cast<IntIdx*>(&((*boundary_dofs_)[ndofs*cell_idx]));
91  return LocDofVec(mem_ptr, ndofs, false, false);
92  }
93 private:
94  /// DOF handler object
95  std::shared_ptr<DOFHandlerMultiDim> dh_;
96  /// Store data of Field
98  /// Last value, prevents passing large values (vectors) by value.
100  typename Value::return_type r_value_;
101  /// Begin of dof range of actual component
102  unsigned int range_begin_;
103  /// End of dof range of actual component
104  unsigned int range_end_;
105  /// Pointer to FiniteElement object used to computing values
106  std::shared_ptr<FiniteElement<elemdim>> fe_;
107 
108  /**
109  * Hold dofs of boundary elements.
110  *
111  * TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
112  */
113  std::shared_ptr< std::vector<IntIdx> > boundary_dofs_;
114 };
115 
116 
117 /**
118  * Specialization for elements with dim==0.
119  */
120 template <int spacedim, class Value>
121 class FEValueHandler<0, spacedim, Value>
122 {
123 public:
124  typedef typename Space<spacedim>::Point Point;
125 
126  /// Constructor.
128  : value_(r_value_) {}
129 
130  /// Initialize data members
131  void initialize(FEValueInitData init_data);
132  /// Returns one value in one given point.
133  typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm) {
134  Armor::array point_list(spacedim, 1, 1);
135  point_list.set(0) = Armor::ArmaVec<double,spacedim>( p );
137  v_list.push_back(r_value_);
138  this->value_list(point_list, elm, v_list);
139  this->r_value_ = v_list[0];
140  return this->r_value_;
141  }
142 
143  /// Returns std::vector of scalar values in several points at once.
144  void value_list (const Armor::array &point_list, const ElementAccessor<spacedim> &elm,
146 
147  /// Destructor.
149 
150  /// TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
151  inline void set_boundary_dofs_vector(std::shared_ptr< std::vector<IntIdx> > boundary_dofs) {
152  this->boundary_dofs_ = boundary_dofs;
153  }
154 
155  /// TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
156  inline LocDofVec get_loc_dof_indices(unsigned int cell_idx) const
157  {
158  unsigned int ndofs = this->value_.n_rows() * this->value_.n_cols();
159  // create armadillo vector on top of existing array
160  // vec(ptr_aux_mem, number_of_elements, copy_aux_mem = true, strict = false)
161  IntIdx* mem_ptr = const_cast<IntIdx*>(&((*boundary_dofs_)[ndofs*cell_idx]));
162  return LocDofVec(mem_ptr, ndofs, false, false);
163  }
164 
165 private:
166  /// DOF handler object
167  std::shared_ptr<DOFHandlerMultiDim> dh_;
168  /// Store data of Field
170  /// Last value, prevents passing large values (vectors) by value.
172  typename Value::return_type r_value_;
173  /// Begin of dof range of actual component
174  unsigned int range_begin_;
175  /// End of dof range of actual component
176  unsigned int range_end_;
177 
178  /**
179  * Hold dofs of boundary elements.
180  *
181  * TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
182  */
183  std::shared_ptr< std::vector<IntIdx> > boundary_dofs_;
184 };
185 
186 
187 
188 #endif /* FE_VALUE_HANDLER_HH_ */
Space::Point
Armor::ArmaVec< double, spacedim > Point
Definition: point.hh:42
FEValueHandler::~FEValueHandler
~FEValueHandler()
Destructor.
Definition: fe_value_handler.cc:205
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
FEValueHandler::get_loc_dof_indices
LocDofVec get_loc_dof_indices(unsigned int cell_idx) const
TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh....
Definition: fe_value_handler.hh:85
FEValueHandler< 0, spacedim, Value >::r_value_
Value::return_type r_value_
Definition: fe_value_handler.hh:172
FEValueHandler::Point
Space< spacedim >::Point Point
Definition: fe_value_handler.hh:60
armor.hh
FEValueHandler< 0, spacedim, Value >::value_
Value value_
Last value, prevents passing large values (vectors) by value.
Definition: fe_value_handler.hh:171
vector_mpi.hh
FEValueHandler::initialize
void initialize(FEValueInitData init_data)
Initialize data members.
Definition: fe_value_handler.cc:93
FEValueHandler< 0, spacedim, Value >::Point
Space< spacedim >::Point Point
Definition: fe_value_handler.hh:124
point.hh
IntIdx
int IntIdx
Definition: index_types.hh:25
std::vector
Definition: doxy_dummy_defs.hh:7
ElementAccessor
Definition: dh_cell_accessor.hh:32
FEValueHandler< 0, spacedim, Value >::set_boundary_dofs_vector
void set_boundary_dofs_vector(std::shared_ptr< std::vector< IntIdx > > boundary_dofs)
TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh....
Definition: fe_value_handler.hh:151
FEValueHandler< 0, spacedim, Value >::range_begin_
unsigned int range_begin_
Begin of dof range of actual component.
Definition: fe_value_handler.hh:174
FEValueHandler< 0, spacedim, Value >::range_end_
unsigned int range_end_
End of dof range of actual component.
Definition: fe_value_handler.hh:176
FEValueHandler< 0, spacedim, Value >::boundary_dofs_
std::shared_ptr< std::vector< IntIdx > > boundary_dofs_
Definition: fe_value_handler.hh:183
index_types.hh
FEValueInitData::mixed_fe
MixedPtr< FiniteElement > mixed_fe
FiniteElement objects of all dimensions.
Definition: fe_value_handler.hh:50
FEValueHandler::dh_
std::shared_ptr< DOFHandlerMultiDim > dh_
DOF handler object.
Definition: fe_value_handler.hh:95
FEValueHandler< 0, spacedim, Value >::data_vec_
VectorMPI data_vec_
Store data of Field.
Definition: fe_value_handler.hh:169
FEValueInitData::dh
std::shared_ptr< DOFHandlerMultiDim > dh
DOF handler object.
Definition: fe_value_handler.hh:38
DOFHandlerMultiDim
Provides the numbering of the finite element degrees of freedom on the computational mesh.
Definition: dofhandler.hh:151
FEValueHandler::range_end_
unsigned int range_end_
End of dof range of actual component.
Definition: fe_value_handler.hh:104
finite_element.hh
Abstract class for description of finite elements.
FEValueHandler::r_value_
Value::return_type r_value_
Definition: fe_value_handler.hh:100
field_values.hh
FEValueHandler< 0, spacedim, Value >::value
const Value::return_type & value(const Point &p, const ElementAccessor< spacedim > &elm)
Returns one value in one given point.
Definition: fe_value_handler.hh:133
FEValueInitData::ndofs
unsigned int ndofs
number of dofs
Definition: fe_value_handler.hh:42
FEValueHandler::data_vec_
VectorMPI data_vec_
Store data of Field.
Definition: fe_value_handler.hh:97
FEValueHandler::value_
Value value_
Last value, prevents passing large values (vectors) by value.
Definition: fe_value_handler.hh:99
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:152
Armor::Array::set
ArrayMatSet set(uint index)
Definition: armor.hh:838
FEValueInitData
Initialization structure of FEValueHandler class.
Definition: fe_value_handler.hh:35
Value
@ Value
Definition: finite_element.hh:43
FEValueHandler::FEValueHandler
FEValueHandler()
Constructor.
Definition: fe_value_handler.cc:87
FEValueHandler::fe_
std::shared_ptr< FiniteElement< elemdim > > fe_
Pointer to FiniteElement object used to computing values.
Definition: fe_value_handler.hh:106
FEValueHandler< 0, spacedim, Value >::FEValueHandler
FEValueHandler()
Constructor.
Definition: fe_value_handler.hh:127
FEValueHandler
Definition: fe_value_handler.hh:57
FEValueHandler< 0, spacedim, Value >::~FEValueHandler
~FEValueHandler()
Destructor.
Definition: fe_value_handler.hh:148
FEValueHandler::value
const Value::return_type & value(const Point &p, const ElementAccessor< spacedim > &elm)
Returns one value in one given point.
Definition: fe_value_handler.cc:108
FEValueHandler::range_begin_
unsigned int range_begin_
Begin of dof range of actual component.
Definition: fe_value_handler.hh:102
MixedPtr< FiniteElement >
Armor::Array< double >
FEValueInitData::data_vec
VectorMPI data_vec
Store data of Field.
Definition: fe_value_handler.hh:40
FEValueHandler::set_boundary_dofs_vector
void set_boundary_dofs_vector(std::shared_ptr< std::vector< IntIdx > > boundary_dofs)
TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh....
Definition: fe_value_handler.hh:80
FEValueHandler::value_list
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.
Definition: fe_value_handler.cc:121
FEValueHandler< 0, spacedim, Value >::get_loc_dof_indices
LocDofVec get_loc_dof_indices(unsigned int cell_idx) const
TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh....
Definition: fe_value_handler.hh:156
FEValueInitData::range_begin
unsigned int range_begin
Holds begin of component range of evaluation.
Definition: fe_value_handler.hh:46
FEValueHandler< 0, spacedim, Value >::dh_
std::shared_ptr< DOFHandlerMultiDim > dh_
DOF handler object.
Definition: fe_value_handler.hh:167
VectorMPI
Definition: vector_mpi.hh:43
Armor::ArmaVec
typename arma::Col< Type >::template fixed< nr > ArmaVec
Definition: armor.hh:505
mixed.hh
FEValueHandler::boundary_dofs_
std::shared_ptr< std::vector< IntIdx > > boundary_dofs_
Definition: fe_value_handler.hh:113
FEValueInitData::n_comp
unsigned int n_comp
number of components
Definition: fe_value_handler.hh:44