Medusa  1.1
Coordinate Free Mehless Method implementation
ShapeStorage_fwd.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_OPERATORS_SHAPESTORAGE_FWD_HPP_
2 #define MEDUSA_BITS_OPERATORS_SHAPESTORAGE_FWD_HPP_
3 
9 #include <medusa/Config.hpp>
13 #include <iosfwd>
14 #include <tuple>
15 #include <Eigen/Core>
16 
17 namespace mm {
18 
19 template <class shape_storage_type>
20 class ExplicitOperators;
21 
22 template <class shape_storage_type>
23 class ExplicitVectorOperators;
24 
25 template <class shape_storage_type, class matrix_type, class rhs_type>
26 class ImplicitOperators;
27 
28 template <class shape_storage_type, class matrix_type, class rhs_type>
29 class ImplicitVectorOperators;
30 
39 template <typename Derived, typename vec_t, typename OpFamilies =
40  std::tuple<Lap<vec_t::dim>, Der1s<vec_t::dim>, Der2s<vec_t::dim>>>
41 class ShapeStorage {
42  public:
43  typedef vec_t vector_t;
44  typedef typename vec_t::scalar_t scalar_t;
45  enum { dim = vec_t::dim };
48  typedef OpFamilies op_families_tuple;
49  constexpr static int num_operators = std::tuple_size<op_families_tuple>::value;
51 
52  friend Derived;
53 
54  private:
59 
61  std::array<Range<scalar_t>, num_operators> shapes_;
62 
64  template <typename T> SINL T* access(std::vector<T>& v, int op, int node) const {
65  return static_cast<const Derived*>(this)->access(v, op, node); }
67  template <typename T> SINL T* access(std::vector<T>& v, int node) const {
68  return static_cast<const Derived*>(this)->access(v, node); }
70  template <typename T> SINL const T* access(const std::vector<T>& v, int op, int node) const {
71  return static_cast<const Derived*>(this)->access(v, op, node); }
73  template <typename T> SINL const T* access(const std::vector<T>& v, int node) const {
74  return static_cast<const Derived*>(this)->access(v, node); }
75 
78 
79  public:
81  void resize(const std::vector<int>& support_sizes) {
82  domain_size_ = support_sizes.size();
83  static_cast<Derived*>(this)->resize_(support_sizes);
84  }
85 
87  int size() const { return domain_size_; }
88 
93  SINL int support(int node, int j) const;
94 
96  SINL Eigen::Map<const Eigen::Matrix<int, Eigen::Dynamic, 1>> support(int node) const;
97 
99  void setSupport(int node_idx, const std::vector<int>& support);
100 
102  int supportSize(int node) const { return static_cast<const Derived*>(this)->supportSize(node); }
103 
110  Range<int> supportSizes() const;
111 
117  Range<int> supportSizesVec() const;
118 
119  // GENERAL GETTERS
121  const std::array<Range<scalar_t>, num_operators>& shapes() const { return shapes_; }
122 
124  template <int op_family> SINL scalar_t get(int op, int node, int j) const {
125  return access(shapes_[op_family], op, node)[j];
126  }
127 
129  template <typename op_family> SINL scalar_t get(int op, int node, int j) const {
130  return get<tuple_index<op_family, op_families_tuple>::value>(op, node, j);
131  }
132 
134  template <int op_family> SINL scalar_t get(int node, int j) const {
135  return access(shapes_[op_family], node)[j];
136  }
137 
139  template <typename op_family> SINL scalar_t get(int node, int j) const {
140  return get<tuple_index<op_family, op_families_tuple>::value>(node, j);
141  }
142 
144  template <int op_family> Eigen::Map<const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>>
145  getShape(int op, int node) const {
146  return {access(shapes_[op_family], op, node), supportSize(node)};
147  }
148 
150  template <typename op_family> Eigen::Map<const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>>
151  getShape(int op, int node) const {
152  return getShape<tuple_index<op_family, op_families_tuple>::value>(op, node);
153  }
154 
156  template <int op_family>
157  SINL Eigen::Map<const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>> getShape(int node) const {
158  return {access(shapes_[op_family], node), supportSize(node)};
159  }
160 
162  template <typename op_family>
163  SINL Eigen::Map<const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>> getShape(int node) const {
164  return getShape<tuple_index<op_family, op_families_tuple>::value>(node);
165  }
166 
167  // GENERAL SETTERS
169  template <int op_family>
170  SINL void setShape(int op, int node, const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& shape) {
171  std::memcpy(access(shapes_[op_family], op, node), shape.data(),
172  supportSize(node)*sizeof(scalar_t));
173  }
174 
176  template <typename op_family>
177  SINL void setShape(int op, int node, const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& shape) {
178  return setShape<tuple_index<op_family, op_families_tuple>::value>(op, node, shape);
179  }
180 
182  template <int op_family>
183  SINL void setShape(int node, const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& shape) {
184  std::memcpy(access(shapes_[op_family], node), shape.data(),
185  supportSize(node)*sizeof(scalar_t)); }
186 
188  template <typename op_family>
189  SINL void setShape(int node, const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& shape) {
190  return setShape<tuple_index<op_family, op_families_tuple>::value>(node, shape);
191  }
192 
193  // SPECIFIC ACCESSORS
194 
196  SINL scalar_t laplace(int node, int j) const;
197 
199  Eigen::Map<const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>> laplace(int node) const;
200 
202  SINL void setLaplace(int node, const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& shape);
203 
205  SINL scalar_t d1(int var, int node, int j) const;
206 
208  Eigen::Map<const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>> d1(int var, int node) const;
209 
211  SINL void setD1(int var, int node, const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& shape);
212 
217  SINL scalar_t d2(int varmin, int varmax, int node, int j) const;
218 
220  Eigen::Map<const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>>
221  d2(int varmin, int varmax, int node) const;
222 
224  SINL void setD2(int varmin, int varmax, int node,
225  const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& shape);
226 
228  size_t memoryUsed() const;
229 
235  template <typename M, typename R>
236  ImplicitOperators<Derived, M, R> implicitOperators(M& matrix, R& rhs) const;
238  template <typename M, typename R>
240 
242  template <typename D, typename V, typename O>
243  friend std::ostream& operator<<(std::ostream& os, const ShapeStorage<D, V, O>& shapes);
244 };
245 
246 
247 } // namespace mm
248 
249 #endif // MEDUSA_BITS_OPERATORS_SHAPESTORAGE_FWD_HPP_
mm::ShapeStorage::setD1
SINL void setD1(int var, int node, const Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > &shape)
Sets shape for derivative wrt. variable var for node to shape.
Definition: ShapeStorage.hpp:147
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
scalar_t
Scalar scalar_t
Type of the elements, alias of Scalar.
Definition: MatrixBaseAddons.hpp:16
mm::ShapeStorage::domain_size_
int domain_size_
Total number of nodes.
Definition: ShapeStorage_fwd.hpp:56
stdtypesutils.hpp
mm::ShapeStorage::resize
void resize(const std::vector< int > &support_sizes)
Resizes the storage to accommodate shapes of given sizes.
Definition: ShapeStorage_fwd.hpp:81
mm::ShapeStorage::setShape
SINL void setShape(int node, const Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > &shape)
Set the shape for node for the only operator in op_family (by index).
Definition: ShapeStorage_fwd.hpp:183
mm::ShapeStorage::operator<<
friend std::ostream & operator<<(std::ostream &os, const ShapeStorage< D, V, O > &shapes)
Output basic info about this shape storage.
Definition: ShapeStorage.hpp:176
dim
@ dim
Number of elements of this matrix.
Definition: MatrixBaseAddons.hpp:14
mm::ShapeStorage::num_operators
constexpr static int num_operators
Number of operator families in this storage.
Definition: ShapeStorage_fwd.hpp:50
mm::ShapeStorage::d1
SINL scalar_t d1(int var, int node, int j) const
Return j-th shape coefficient for derivative wrt. variable var in node.
Definition: ShapeStorage.hpp:65
mm::ShapeStorage::supportSize
int supportSize(int node) const
Returns support size of node-th node.
Definition: ShapeStorage_fwd.hpp:102
mm::ShapeStorage::ShapeStorage
ShapeStorage()
Constructs empty storage with size 0. Can be resized with resize.
Definition: ShapeStorage_fwd.hpp:77
mm::ShapeStorage::access
const SINL T * access(const std::vector< T > &v, int node) const
Returns const pointer to the start of values for node-th node.
Definition: ShapeStorage_fwd.hpp:73
mm::ShapeStorage
Shape storage base class.
Definition: ShapeStorage_fwd.hpp:41
mm::ShapeStorage::get
SINL scalar_t get(int op, int node, int j) const
Get the weight of j-th stencil node of node for operator op in op_family (by index).
Definition: ShapeStorage_fwd.hpp:124
mm::ShapeStorage::implicitOperators
ImplicitOperators< Derived, M, R > implicitOperators(M &matrix, R &rhs) const
Construct implicit operators over this storage.
mm::ExplicitVectorOperators
A class for evaluating typical operators needed in spatial discretization.
Definition: ExplicitVectorOperators_fwd.hpp:38
mm::ShapeStorage::access
SINL T * access(std::vector< T > &v, int node) const
Returns pointer to the start of values for node-th node.
Definition: ShapeStorage_fwd.hpp:67
mm::ShapeStorage::setLaplace
SINL void setLaplace(int node, const Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > &shape)
Sets the laplace shape for node to shape.
Definition: ShapeStorage.hpp:137
mm::ShapeStorage::scalar_t
vec_t::scalar_t scalar_t
Scalar type used.
Definition: ShapeStorage_fwd.hpp:44
mm::ShapeStorage::shapes_
std::array< Range< scalar_t >, num_operators > shapes_
Tuple of shape containers for given operators.
Definition: ShapeStorage_fwd.hpp:61
mm::ShapeStorage::laplace
SINL scalar_t laplace(int node, int j) const
Return j-th laplace shape coefficient for node-th node.
Definition: ShapeStorage.hpp:55
mm::ShapeStorage::support_
Range< int > support_
Local copy of support domains.
Definition: ShapeStorage_fwd.hpp:58
mm::ShapeStorage::op_families_tuple
OpFamilies op_families_tuple
Tuple of operator families.
Definition: ShapeStorage_fwd.hpp:48
Config.hpp
mm::ShapeStorage::vector_t
vec_t vector_t
Vector type used.
Definition: ShapeStorage_fwd.hpp:43
Range_fwd.hpp
mm::ShapeStorage::support
SINL int support(int node, int j) const
Returns index of j-th neighbour of node-th node, i.e. support[node][j], but possibly faster.
Definition: ShapeStorage.hpp:15
mm::ExplicitOperators
A class for evaluating typical operators needed in spatial discretization.
Definition: ExplicitOperators_fwd.hpp:35
Operators_fwd.hpp
mm::ShapeStorage::explicitVectorOperators
ExplicitVectorOperators< Derived > explicitVectorOperators() const
Construct explicit vector operators over this storage.
Definition: ExplicitVectorOperators.hpp:160
mm::ShapeStorage::supportSizes
Range< int > supportSizes() const
Returns a vector of support sizes for all nodes, useful for matrix space preallocation.
Definition: ShapeStorage.hpp:36
mm::ImplicitOperators
This class represents implicit operators that fill given matrix M and right hand side rhs with approp...
Definition: ImplicitOperators_fwd.hpp:40
mm::ShapeStorage::getShape
Eigen::Map< const Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > > getShape(int op, int node) const
Get the shape for node for operator op in op_family (by index).
Definition: ShapeStorage_fwd.hpp:145
mm::ShapeStorage::setSupport
void setSupport(int node_idx, const std::vector< int > &support)
Sets support of node-th node to support.
Definition: ShapeStorage.hpp:126
mm::ShapeStorage::setD2
SINL void setD2(int varmin, int varmax, int node, const Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > &shape)
Sets shape for mixed derivative wrt. variables varmin and varmax for node to shape.
Definition: ShapeStorage.hpp:158
mm::ShapeStorage::shapes
const std::array< Range< scalar_t >, num_operators > & shapes() const
Read access to complete shape storage.
Definition: ShapeStorage_fwd.hpp:121
mm::ShapeStorage::supportSizesVec
Range< int > supportSizesVec() const
Returns a dim*N vector of dim*support_size, useful for matrix space preallocation for vector equation...
Definition: ShapeStorage.hpp:45
mm::ShapeStorage::memoryUsed
size_t memoryUsed() const
Returns the approximate memory used (in bytes).
Definition: ShapeStorage.hpp:182
mm::ShapeStorage::d2
SINL scalar_t d2(int varmin, int varmax, int node, int j) const
Return j-th shape coefficient for mixed derivative wrt.
Definition: ShapeStorage.hpp:76
SINL
#define SINL
Strong inline macro.
Definition: Config.hpp:24
mm::ShapeStorage::Derived
friend Derived
Be friends with derived class.
Definition: ShapeStorage_fwd.hpp:52
mm::ShapeStorage::size
int size() const
Returns number of nodes.
Definition: ShapeStorage_fwd.hpp:87
mm::ShapeStorage::implicitVectorOperators
ImplicitVectorOperators< Derived, M, R > implicitVectorOperators(M &matrix, R &rhs) const
Construct implicit vector operators over this storage.
mm::ShapeStorage::access
SINL T * access(std::vector< T > &v, int op, int node) const
Returns pointer to the start of values for node-th node for op-th operator.
Definition: ShapeStorage_fwd.hpp:64
mm::ShapeStorage::dim
@ dim
Dimensionality of the domain.
Definition: ShapeStorage_fwd.hpp:47
mm::Range< int >
mm::ShapeStorage::setShape
SINL void setShape(int op, int node, const Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > &shape)
Set the shape for node for operator op in op_family (by index).
Definition: ShapeStorage_fwd.hpp:170
mm::ImplicitVectorOperators
This class represents implicit vector operators that fill given matrix M and right hand side rhs with...
Definition: ImplicitVectorOperators_fwd.hpp:44
mm::ShapeStorage::getShape
SINL Eigen::Map< const Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > > getShape(int node) const
Get the shape for node for the only operator in op_family (by index).
Definition: ShapeStorage_fwd.hpp:157
mm::ShapeStorage::access
const SINL T * access(const std::vector< T > &v, int op, int node) const
Returns const pointer to the start of values for node-th node for op-th operator.
Definition: ShapeStorage_fwd.hpp:70
mm::ShapeStorage::explicitOperators
ExplicitOperators< Derived > explicitOperators() const
Construct explicit operators over this storage.
Definition: ExplicitOperators.hpp:89
mm::ShapeStorage::get
SINL scalar_t get(int node, int j) const
Get the j-th weight of shape for node for the only operator in op_family (by index).
Definition: ShapeStorage_fwd.hpp:134