cache_data.cpp
1 #include "cache_data.hpp"
2 #include "../../tessellation/ConvexHull.hpp"
3 #include "../../misc/lazy_list.hpp"
4 
5 namespace {
6  class CellEdgesGetter: public LazyList<Edge>
7  {
8  public:
9 
10  CellEdgesGetter(const Tessellation& tess, int n):
11  tess_(tess), edge_indices_(tess.GetCellEdges(n)) {}
12 
13  size_t size(void) const
14  {
15  return edge_indices_.size();
16  }
17 
18  Edge operator[](size_t i) const
19  {
20  return tess_.GetEdge(edge_indices_[i]);
21  }
22 
23  private:
24  const Tessellation& tess_;
25  const vector<int> edge_indices_;
26  };
27 }
28 
29 CacheData::VolumeCalculator::VolumeCalculator
30 (const Tessellation& tess,
31  const PhysicalGeometry& pg):
32  tess_(tess), pg_(pg) {}
33 
34 size_t CacheData::VolumeCalculator::size(void) const
35 {
36  return static_cast<size_t>(tess_.GetPointNo());
37 }
38 
39 double CacheData::VolumeCalculator::operator[](const size_t i) const
40 {
41  return pg_.calcVolume
42  (serial_generate(CellEdgesGetter(tess_,static_cast<int>(i))));
43 }
44 
45 CacheData::AreaCalculator::AreaCalculator
46 (const Tessellation& tess,
47  const PhysicalGeometry& pg):
48  tess_(tess), pg_(pg) {}
49 
50 size_t CacheData::AreaCalculator::size(void) const
51 {
52  return tess_.getAllEdges().size();
53 }
54 
55 double CacheData::AreaCalculator::operator[](const size_t i) const
56 {
57  return pg_.calcArea(tess_.getAllEdges()[i]);
58 }
59 
61  const PhysicalGeometry& pg):
62  volume_func_(tess,pg), area_func_(tess,pg),cm_func_(tess,pg),
63  volumes(volume_func_), areas(area_func_),CMs(cm_func_) {}
64 
65 void CacheData::reset(void) const
66 {
67  volumes.reset();
68  areas.reset();
69  CMs.reset();
70 }
71 
72 CacheData::CMCalculator::CMCalculator
73 (const Tessellation& tess,
74  const PhysicalGeometry& pg) :
75  tess_(tess), pg_(pg) {}
76 
77 size_t CacheData::CMCalculator::size(void) const
78 {
79  return static_cast<size_t>(tess_.GetPointNo());
80 }
81 
82 Vector2D CacheData::CMCalculator::operator[](const size_t i) const
83 {
84  vector<Vector2D> chull;
85  ConvexHull(chull, tess_, static_cast<int>(i));
86  return pg_.calcCentroid(chull);
87 }
CacheData(const Tessellation &tess, const PhysicalGeometry &pg)
Class constructor.
Definition: cache_data.cpp:60
void reset(void) const
Marks all items for recalculation.
Definition: cache_data.cpp:65
Abstract class for tessellation.
void reset(void) const
Marks all terms for recalculation.
const CachedLazyList< Vector2D > CMs
List of center of masses of the cells.
Definition: cache_data.hpp:87
vector< T > serial_generate(const LazyList< T > &ll)
Creates a vector from an LazyList.
Definition: lazy_list.hpp:49
Interface between two cells.
Definition: Edge.hpp:13
const CachedLazyList< double > areas
List of areas of interfaces.
Definition: cache_data.hpp:84
Ordered list whose terms are evaluated lazily.
Definition: lazy_list.hpp:17
virtual T operator[](const size_t i) const =0
Returns a single member of the list.
void ConvexHull(vector< Vector2D > &result, Tessellation const &tess, int index)
Returns the ConvexHull for a set of points.
Definition: ConvexHull.cpp:31
const CachedLazyList< double > volumes
List of cell volumes.
Definition: cache_data.hpp:81
Geometrical cache data for optimisation.
2D Mathematical vector
Definition: geometry.hpp:15
Base class for physical geometry.
virtual size_t size(void) const =0
Returns the length of the list.