Flow123d  JS_before_hm-983-gccfd4b3
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 
29 class DOFHandlerMultiDim;
30 template <int spacedim> class ElementAccessor;
31 
32 
33 /// Initialization structure of FEValueHandler class.
35 {
36  /// DOF handler object
37  std::shared_ptr<DOFHandlerMultiDim> dh;
38  /// Store data of Field
40  /// number of dofs
41  unsigned int ndofs;
42  /// number of components
43  unsigned int n_comp;
44  /// index of component (of vector_value/tensor_value)
45  unsigned int comp_index;
46 };
47 
48 /**
49  * Helper class that allows compute finite element values specified by element dimension.
50  */
51 template <int elemdim, int spacedim, class Value>
53 {
54 public:
55  typedef typename Space<spacedim>::Point Point;
56 
57  /// Constructor.
59 
60  /// Initialize data members
61  void initialize(FEValueInitData init_data);
62  /// Returns one value in one given point.
63  typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm);
64  /// Returns std::vector of scalar values in several points at once.
65  void value_list (const Armor::array &point_list, const ElementAccessor<spacedim> &elm,
67  /// Compute real coordinates and weights (use QGauss) for given element
68  unsigned int compute_quadrature(std::vector<arma::vec::fixed<3>> & q_points, std::vector<double> & q_weights,
69  const ElementAccessor<spacedim> &elm, unsigned int order=3);
70 
71  /// Destructor.
72  ~FEValueHandler();
73 
74  /// TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
75  inline void set_boundary_dofs_vector(std::shared_ptr< std::vector<IntIdx> > boundary_dofs) {
76  this->boundary_dofs_ = boundary_dofs;
77  }
78 
79  /// TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
80  inline LocDofVec get_loc_dof_indices(unsigned int cell_idx) const
81  {
82  unsigned int ndofs = this->value_.n_rows() * this->value_.n_cols();
83  // create armadillo vector on top of existing array
84  // vec(ptr_aux_mem, number_of_elements, copy_aux_mem = true, strict = false)
85  IntIdx* mem_ptr = const_cast<IntIdx*>(&((*boundary_dofs_)[ndofs*cell_idx]));
86  return LocDofVec(mem_ptr, ndofs, false, false);
87  }
88 private:
89  /// DOF handler object
90  std::shared_ptr<DOFHandlerMultiDim> dh_;
91  /// Store data of Field
93  /// Last value, prevents passing large values (vectors) by value.
95  typename Value::return_type r_value_;
96  /// Index of component (of vector_value/tensor_value)
97  unsigned int comp_index_;
98 
99  /**
100  * Hold dofs of boundary elements.
101  *
102  * TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
103  */
104  std::shared_ptr< std::vector<IntIdx> > boundary_dofs_;
105 };
106 
107 
108 /**
109  * Specialization for elements with dim==0.
110  */
111 template <int spacedim, class Value>
112 class FEValueHandler<0, spacedim, Value>
113 {
114 public:
115  typedef typename Space<spacedim>::Point Point;
116 
117  /// Constructor.
119  : value_(r_value_) {}
120 
121  /// Initialize data members
122  void initialize(FEValueInitData init_data);
123  /// Returns one value in one given point.
124  typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm) {
125  Armor::array point_list(spacedim, 1, 1);
126  point_list.set(0) = Armor::ArmaVec<double,spacedim>( p );
128  v_list.push_back(r_value_);
129  this->value_list(point_list, elm, v_list);
130  this->r_value_ = v_list[0];
131  return this->r_value_;
132  }
133 
134  /// Returns std::vector of scalar values in several points at once.
135  void value_list (const Armor::array &point_list, const ElementAccessor<spacedim> &elm,
137 
138  /// Destructor.
140 
141  /// TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
142  inline void set_boundary_dofs_vector(std::shared_ptr< std::vector<IntIdx> > boundary_dofs) {
143  this->boundary_dofs_ = boundary_dofs;
144  }
145 
146  /// TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
147  inline LocDofVec get_loc_dof_indices(unsigned int cell_idx) const
148  {
149  unsigned int ndofs = this->value_.n_rows() * this->value_.n_cols();
150  // create armadillo vector on top of existing array
151  // vec(ptr_aux_mem, number_of_elements, copy_aux_mem = true, strict = false)
152  IntIdx* mem_ptr = const_cast<IntIdx*>(&((*boundary_dofs_)[ndofs*cell_idx]));
153  return LocDofVec(mem_ptr, ndofs, false, false);
154  }
155 
156 private:
157  /// DOF handler object
158  std::shared_ptr<DOFHandlerMultiDim> dh_;
159  /// Store data of Field
161  /// Last value, prevents passing large values (vectors) by value.
163  typename Value::return_type r_value_;
164 
165  /**
166  * Hold dofs of boundary elements.
167  *
168  * TODO: Temporary solution. Fix problem with merge new DOF handler and boundary Mesh. Will be removed in future.
169  */
170  std::shared_ptr< std::vector<IntIdx> > boundary_dofs_;
171 };
172 
173 
174 
175 #endif /* FE_VALUE_HANDLER_HH_ */
unsigned int comp_index
index of component (of vector_value/tensor_value)
VectorMPI data_vec_
Store data of Field.
std::shared_ptr< std::vector< IntIdx > > boundary_dofs_
unsigned int comp_index_
Index of component (of vector_value/tensor_value)
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
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
Value::return_type r_value_
Provides the numbering of the finite element degrees of freedom on the computational mesh...
Definition: dofhandler.hh:151
ArrayMatSet set(uint index)
Definition: armor.hh:821
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.
typename arma::Col< Type >::template fixed< nr > ArmaVec
Definition: armor.hh:505
Value value_
Last value, prevents passing large values (vectors) by value.
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_
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.