Flow123d  JS_before_hm-1602-g5680f2c
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.
77  ~FEValueHandler();
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_ */
VectorMPI data_vec_
Store data of Field.
std::shared_ptr< std::vector< IntIdx > > boundary_dofs_
arma::Col< IntIdx > LocDofVec
Definition: index_types.hh:28
LocDofVec get_loc_dof_indices(unsigned int cell_idx) const
TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
LocDofVec get_loc_dof_indices(unsigned int cell_idx) const
TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
Armor::ArmaVec< double, spacedim > Point
Definition: point.hh:42
int IntIdx
Definition: index_types.hh:25
Space< spacedim >::Point Point
unsigned int range_end
Holds end of component range of evaluation.
Value value_
Last value, prevents passing large values (vectors) by value.
Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
Returns one value in one given point.
static constexpr bool value
Definition: json.hpp:87
MixedPtr< FiniteElement > mixed_fe
FiniteElement objects of all dimensions.
Value::return_type r_value_
Provides the numbering of the finite element degrees of freedom on the computational mesh...
Definition: dofhandler.hh:151
unsigned int range_end_
End of dof range of actual component.
std::shared_ptr< FiniteElement< elemdim > > fe_
Pointer to FiniteElement object used to computing values.
ArrayMatSet set(uint index)
Definition: armor.hh:838
std::shared_ptr< DOFHandlerMultiDim > dh_
DOF handler object.
unsigned int ndofs
number of dofs
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. Will be removed in future.
std::shared_ptr< DOFHandlerMultiDim > dh
DOF handler object.
unsigned int range_begin_
Begin of dof range of actual component.
typename arma::Col< Type >::template fixed< nr > ArmaVec
Definition: armor.hh:505
Value value_
Last value, prevents passing large values (vectors) by value.
unsigned int range_end_
End of dof range of actual component.
VectorMPI data_vec_
Store data of Field.
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. Will be removed in future.
std::shared_ptr< std::vector< IntIdx > > boundary_dofs_
unsigned int range_begin_
Begin of dof range of actual component.
VectorMPI data_vec
Store data of Field.
Abstract class for description of finite elements.
std::shared_ptr< DOFHandlerMultiDim > dh_
DOF handler object.
unsigned int n_comp
number of components
Initialization structure of FEValueHandler class.
unsigned int range_begin
Holds begin of component range of evaluation.