WaveBlocksND
shape_extension_cache.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 
5 #include "shape_enum_union.hpp"
7 
8 
9 namespace waveblocks {
10  namespace wavepackets {
11  namespace shapes {
12 
13  template<dim_t D, class MultiIndex>
14  using ShapeEnumSharedPtr = std::shared_ptr< ShapeEnum<D, MultiIndex> >;
15 
16  // template<dim_t D>
17  // class AbstractScalarWavepacket
18  // {
19  // public:
20  // virtual Eigen::Array<complex_t,1,Eigen::Dynamic> evaluate(ComplexGrid<D,Eigen::Dynamic> const& grid) const = 0;
21  // virtual HaWpBasisVector<Eigen::Dynamic> evaluate_basis(ComplexGrid<D,Eigen::Dynamic> const& grid) const = 0;
22  // };
23 
24 
25  template<dim_t D, class MultiIndex>
27  {
28  public:
34  {
35  if (shape.get() != cached_extended_shape_source_)
36  update_extended_shape(shape); // this function is not thread-safe
37 
39  }
40 
47  void set_extended_shape(std::shared_ptr< ShapeEnum<D,MultiIndex> > shape,
48  std::shared_ptr< ShapeEnum<D,MultiIndex> > extension)
49  {
50  cached_extended_shape_source_ = shape.get();
51  cached_extended_shape_ = extension;
52  }
53 
59  void update_extended_shape(std::shared_ptr< ShapeEnum<D,MultiIndex> > shape) const
60  {
61  if (shape.get() != cached_extended_shape_source_) {
62  cached_extended_shape_source_ = shape.get();
63  cached_extended_shape_ = std::make_shared< ShapeEnum<D,MultiIndex> >(shapes::shape_enum::extend(shape.get()));
64  }
65  }
66 
67  private:
69  mutable ShapeEnum<D,MultiIndex> * cached_extended_shape_source_; // source of the cached extended shape
70  };
71  }
72  }
73 }
Definition: coefficients_file_parser.cpp:10
std::shared_ptr< ShapeEnum< D, MultiIndex > > ShapeEnumSharedPtr
Definition: shape_extension_cache.hpp:14
A shape enumeration is a complete, ordered list of all lattice nodes that are part of the basis shape...
Definition: shape_enum.hpp:353
void update_extended_shape(std::shared_ptr< ShapeEnum< D, MultiIndex > > shape) const
Recomputes extended shape if source shape changed.
Definition: shape_extension_cache.hpp:59
ShapeEnumSharedPtr< D, MultiIndex > get_extended_shape(std::shared_ptr< ShapeEnum< D, MultiIndex > > shape) const
shape reference to shape to check actuality of cache
Definition: shape_extension_cache.hpp:33
ShapeEnum< D, MultiIndex > extend(const ShapeEnum< D, MultiIndex > *source)
For a given enumerated shape, enumerate its extension.
Definition: shape_enum_extended.hpp:55
Definition: shape_extension_cache.hpp:26
ShapeEnumSharedPtr< D, MultiIndex > cached_extended_shape_
Definition: shape_extension_cache.hpp:68
ShapeEnum< D, MultiIndex > * cached_extended_shape_source_
Definition: shape_extension_cache.hpp:69
void set_extended_shape(std::shared_ptr< ShapeEnum< D, MultiIndex > > shape, std::shared_ptr< ShapeEnum< D, MultiIndex > > extension)
Manually sets extended shape.
Definition: shape_extension_cache.hpp:47