duffell.cpp
1 #include <boost/foreach.hpp>
2 #include "duffell.hpp"
3 
5 (const double alpha,
6  const int iter):
7  alpha_(alpha),
8  iter_(iter) {}
9 
10 namespace {
11  vector<Vector2D> extract_velocity
12  (const vector<ComputationalCell>& cells,size_t N)
13  {
14  vector<Vector2D> res(N);
15  for(size_t i=0;i<res.size();++i)
16  res.at(i) = cells.at(i).velocity;
17  return res;
18  }
19 
20  Vector2D neighbor_average
21  (const Tessellation& tess,
22  const vector<Vector2D>& previous,
23  const size_t i)
24  {
25  Vector2D res(0,0);
26  double circumference = 0;
27  const vector<int> edge_indices =
28  tess.GetCellEdges(static_cast<int>(i));
29  BOOST_FOREACH(int index, edge_indices){
30  const Edge edge = tess.GetEdge(index);
31  const int other =
32  edge.neighbors.first +
33  edge.neighbors.second -
34  static_cast<int>(i);
35  const double edge_length =
36  abs(edge.vertices.first-
37  edge.vertices.second);
38  circumference += edge_length;
39  if(other<tess.GetPointNo())
40  res += edge_length*
41  previous.at(static_cast<size_t>(other));
42  }
43  return (1.0/circumference)*res;
44  }
45 
46  vector<Vector2D> smooth
47  (const Tessellation& tess,
48  const vector<Vector2D>& previous,
49  const double alpha)
50  {
51  vector<Vector2D> res(previous.size());
52  for(size_t i=0;i<res.size();++i)
53  res.at(i) = previous.at(i)*(1-alpha)+
54  alpha*neighbor_average(tess,previous,i);
55  return res;
56  }
57 }
58 
59 vector<Vector2D> Duffell::operator()
60 (const Tessellation& tess,
61  const vector<ComputationalCell>& cells,
62  double /*time*/,TracerStickerNames const& /*tracerstickernames*/) const
63 {
64  vector<Vector2D> res = extract_velocity(cells,static_cast<size_t>(tess.GetPointNo()));
65  for(int i=0;i<iter_;++i)
66  res = smooth(tess,res,alpha_);
67  return res;
68 }
Abstract class for tessellation.
virtual int GetPointNo(void) const =0
Get Total number of mesh generating points.
Interface between two cells.
Definition: Edge.hpp:13
Duffell(const double alpha, const int iter)
Class constructor.
Definition: duffell.cpp:5
virtual Edge const & GetEdge(int index) const =0
Returns edge (interface between cells)
std::pair< Vector2D, Vector2D > vertices
Points at the ends of the edge.
Definition: Edge.hpp:18
Class for keeping the names of the tracers and stickers.
std::pair< int, int > neighbors
Neighboring cells.
Definition: Edge.hpp:21
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44
virtual vector< int > const & GetCellEdges(int index) const =0
Returns the indexes of a cell&#39;s edges.
2D Mathematical vector
Definition: geometry.hpp:15