Flow123d  DF_patch_fe_mechanics-5faa023
patch_op.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 patch_op.hh
15  * @brief Base class of FE operations.
16  * @author David Flanderka
17  */
18 
19 #ifndef PATCH_OP_HH_
20 #define PATCH_OP_HH_
21 
22 #include <Eigen/Dense>
23 
24 #include "fem/eigen_tools.hh"
25 #include "fem/arena_resource.hh"
26 #include "fem/arena_vec.hh"
27 #include "mesh/ref_element.hh"
28 
29 
30 template<unsigned int spacedim> class PatchFEValues;
31 
32 
33 /// Distinguishes bulk and side domain
35 {
38 };
39 
40 
41 /**
42  * @brief Class represents element or FE operations.
43  */
44 template<unsigned int spacedim = 3>
45 class PatchOp {
46 public:
47  /**
48  * Constructor
49  *
50  * Set all data members.
51  */
52  PatchOp(uint dim, PatchFEValues<spacedim> &pfev, std::initializer_list<uint> shape, OpSizeType size_type, uint n_dofs = 1)
54  {
55  ASSERT_GT(n_dofs, 0);
56  result_ = Eigen::Vector<ArenaVec<double>, Eigen::Dynamic>(shape_[0] * shape_[1] * n_dofs_);
57  }
58 
59  /// Destructor
60  virtual ~PatchOp()
61  {}
62 
63 
64  /// Aligns shape_vec to 2 items (equal to matrix number of dimensions)
65  std::vector<uint> set_shape_vec(std::initializer_list<uint> shape) const {
66  std::vector<uint> shape_vec(shape);
67  if (shape_vec.size() == 1) shape_vec.push_back(1);
68  ASSERT_EQ(shape_vec.size(), 2);
69  return shape_vec;
70  }
71 
72  /**
73  * Return number of operation components
74  *
75  * Value is computed from shape_ vector
76  */
77  inline uint n_comp() const {
78  return shape_[0] * shape_[1];
79  }
80 
81 // /// Getter for dimension
82 // inline uint dimension() const { // dim is in conflict with template of some descendants
83 // return dim_;
84 // }
85 
86  /// Getter for bulk_side flag
87  inline ElemDomain domain() const {
88  return domain_;
89  }
90 
91  /// Getter for size_type_
93  return size_type_;
94  }
95 
96  /// Getter for n_dofs_
97  inline uint n_dofs() const {
98  return n_dofs_;
99  }
100 
101  /// Return pointer to operation of i_op index in input operation vector.
102  inline PatchOp<spacedim> *input_ops(uint i_op) const {
103  return input_ops_[i_op];
104  }
105 
106  /// Getter for shape_
107  inline const std::vector<uint> &shape() const {
108  return shape_;
109  }
110 
111  /**
112  * Format shape to string
113  *
114  * Method is used in output development method.
115  */
116  std::string format_shape() const {
117  std::stringstream ss;
118  ss << shape_[0] << "x" << shape_[1];
119  return ss.str();
120  }
121 
122  inline void allocate_result(size_t data_size, PatchArena &arena) {
123  for (uint i=0; i<n_comp()*n_dofs_; ++i)
124  result_(i) = ArenaVec<double>(data_size, arena);
125  }
126 
127  inline void allocate_const_result(ArenaVec<double> &value_vec) {
128  for (uint i=0; i<n_comp()*n_dofs_; ++i)
129  result_(i) = value_vec;
130  }
131 
132  /// Return map referenced result as Eigen::Vector
133  inline Eigen::Map<Eigen::Matrix<ArenaVec<double>, Eigen::Dynamic, Eigen::Dynamic>> result_matrix() {
134  return Eigen::Map<Eigen::Matrix<ArenaVec<double>, Eigen::Dynamic, Eigen::Dynamic>>(result_.data(), shape_[0], shape_[1] * n_dofs_);
135  }
136 
137  /// Return map referenced result of DOF values as Eigen::Matrix
138  inline Eigen::Map<Eigen::Matrix<ArenaVec<double>, Eigen::Dynamic, Eigen::Dynamic>> result_sub_matrix(uint i_dof) {
139  ASSERT_LT(i_dof, n_dofs_);
140  uint n_dof_comps = shape_[0] * shape_[1];
141  return Eigen::Map<Eigen::Matrix<ArenaVec<double>, Eigen::Dynamic, Eigen::Dynamic>>(result_.data()+i_dof*n_dof_comps, shape_[0], shape_[1]);
142  }
143 
144  /// Return map referenced result as Eigen::Vector
145  inline Eigen::Vector<ArenaVec<double>, Eigen::Dynamic> &raw_result() {
146  return result_;
147  }
148 
149  /// Same as previous but return const reference
150  inline const Eigen::Vector<ArenaVec<double>, Eigen::Dynamic> &raw_result() const {
151  return result_;
152  }
153 
154  /// Return reference of PatchPointValues
155  inline PatchPointValues<spacedim> &ppv() const {
156  return patch_fe_->patch_point_vals_[domain_][this->dim_-1];
157  }
158 
159  /// Reinit function of operation. Implementation in descendants.
160  virtual void eval() =0;
161 
162  /**
163  * Returns output value of data stored by elements.
164  *
165  * @param point_idx Index of quadrature point in ElementCacheMap
166  */
167  template <class ValueType>
168  inline ValueType elem_value(uint point_idx) const;
169 
170  /**
171  * Returns output value on quadrature point.
172  *
173  * @param point_idx Index of quadrature point in ElementCacheMap
174  * @param i_dof Index of DOF
175  */
176  template <class ValueType>
177  inline ValueType point_value(uint point_idx, uint i_dof=0) const;
178 
179 
180 protected:
181  uint dim_; ///< Dimension
182  ElemDomain domain_; ///< Flag: BulkOp = 0, SideOp = 1
183  std::vector<uint> shape_; ///< Shape of stored data (size of vector or number of rows and cols of matrix)
184  Eigen::Vector<ArenaVec<double>, Eigen::Dynamic> result_; ///< Result matrix of operation
185  OpSizeType size_type_; ///< Type of operation by size of vector (element, point or fixed size)
186  std::vector<PatchOp<spacedim> *> input_ops_; ///< Indices of operations in PatchPointValues::operations_ vector on which PatchOp is depended
187  uint n_dofs_; ///< Number of DOFs of FE operations (or 1 in case of element operations)
188  PatchFEValues<spacedim> *patch_fe_; ///< Pointer to PatchFEValues object
189 
190  friend class PatchFEValues<spacedim>;
191 };
192 
193 
194 #endif /* PATCH_OP_HH_ */
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:301
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:333
#define ASSERT_GT(a, b)
Definition of comparative assert macro (Greater Than) only for debug mode.
Definition: asserts.hh:317
Class represents element or FE operations.
Definition: patch_op.hh:45
Eigen::Vector< ArenaVec< double >, Eigen::Dynamic > result_
Result matrix of operation.
Definition: patch_op.hh:184
Eigen::Map< Eigen::Matrix< ArenaVec< double >, Eigen::Dynamic, Eigen::Dynamic > > result_sub_matrix(uint i_dof)
Return map referenced result of DOF values as Eigen::Matrix.
Definition: patch_op.hh:138
uint n_dofs() const
Getter for n_dofs_.
Definition: patch_op.hh:97
uint n_comp() const
Definition: patch_op.hh:77
virtual ~PatchOp()
Destructor.
Definition: patch_op.hh:60
std::vector< PatchOp< spacedim > * > input_ops_
Indices of operations in PatchPointValues::operations_ vector on which PatchOp is depended.
Definition: patch_op.hh:186
PatchOp< spacedim > * input_ops(uint i_op) const
Return pointer to operation of i_op index in input operation vector.
Definition: patch_op.hh:102
ElemDomain domain() const
Getter for bulk_side flag.
Definition: patch_op.hh:87
Eigen::Vector< ArenaVec< double >, Eigen::Dynamic > & raw_result()
Return map referenced result as Eigen::Vector.
Definition: patch_op.hh:145
uint dim_
Dimension.
Definition: patch_op.hh:181
OpSizeType size_type_
Type of operation by size of vector (element, point or fixed size)
Definition: patch_op.hh:185
PatchOp(uint dim, PatchFEValues< spacedim > &pfev, std::initializer_list< uint > shape, OpSizeType size_type, uint n_dofs=1)
Definition: patch_op.hh:52
const std::vector< uint > & shape() const
Getter for shape_.
Definition: patch_op.hh:107
ValueType point_value(uint point_idx, uint i_dof=0) const
std::string format_shape() const
Definition: patch_op.hh:116
std::vector< uint > set_shape_vec(std::initializer_list< uint > shape) const
Aligns shape_vec to 2 items (equal to matrix number of dimensions)
Definition: patch_op.hh:65
OpSizeType size_type() const
Getter for size_type_.
Definition: patch_op.hh:92
Eigen::Map< Eigen::Matrix< ArenaVec< double >, Eigen::Dynamic, Eigen::Dynamic > > result_matrix()
Return map referenced result as Eigen::Vector.
Definition: patch_op.hh:133
std::vector< uint > shape_
Shape of stored data (size of vector or number of rows and cols of matrix)
Definition: patch_op.hh:183
void allocate_const_result(ArenaVec< double > &value_vec)
Definition: patch_op.hh:127
ElemDomain domain_
Flag: BulkOp = 0, SideOp = 1.
Definition: patch_op.hh:182
void allocate_result(size_t data_size, PatchArena &arena)
Definition: patch_op.hh:122
const Eigen::Vector< ArenaVec< double >, Eigen::Dynamic > & raw_result() const
Same as previous but return const reference.
Definition: patch_op.hh:150
PatchPointValues< spacedim > & ppv() const
Return reference of PatchPointValues.
Definition: patch_op.hh:155
virtual void eval()=0
Reinit function of operation. Implementation in descendants.
uint n_dofs_
Number of DOFs of FE operations (or 1 in case of element operations)
Definition: patch_op.hh:187
ValueType elem_value(uint point_idx) const
PatchFEValues< spacedim > * patch_fe_
Pointer to PatchFEValues object.
Definition: patch_op.hh:188
Store finite element data on the actual patch such as shape function values, gradients,...
unsigned int uint
ElemDomain
Distinguishes bulk and side domain.
Definition: patch_op.hh:35
@ domain_side
Definition: patch_op.hh:37
@ domain_bulk
Definition: patch_op.hh:36
OpSizeType
Distinguishes operations by type and size of output rows.
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.