source: src/base/stencil.hpp@ a40eea

Last change on this file since a40eea was ac6d04, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1666 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 * @file stencil.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Apr 18 12:25:05 2011
5 *
6 * @brief VMG::Stencil
7 *
8 */
9
10#ifndef STENCIL_HPP_
11#define STENCIL_HPP_
12
13#include <cstddef>
14#include <vector>
15
16#include "grid/grid.hpp"
17#include "base/index.hpp"
18
19namespace VMG
20{
21
22class Displacement
23{
24public:
25 Displacement() :
26 disp(0),
27 val(0.0)
28 {}
29
30 Displacement(const Index& disp_, const vmg_float& val_) :
31 disp(disp_),
32 val(val_)
33 {}
34
35 const Index& Disp() const {return disp;}
36 const vmg_float& Val() const {return val;}
37
38private:
39 Index disp;
40 vmg_float val;
41};
42
43class Stencil
44{
45public:
46 typedef std::vector<Displacement>::const_iterator iterator;
47
48 Stencil(const vmg_float& diag_) :
49 diag(diag_)
50 {}
51
52 Stencil(const Stencil& stencil_)
53 {
54 this->diag = stencil_.GetDiag();
55
56 for (Stencil::iterator iter=stencil_.begin(); iter!=stencil_.end(); iter++)
57 this->push_back(*iter);
58 }
59
60 const vmg_float& GetDiag() const {return diag;}
61 void SetDiag(const vmg_float& diag_) {diag = diag_;}
62
63 const Displacement& operator[](const int& index) const {return disp[index];}
64
65 void push_back(const int& x, const int& y, const int& z, const vmg_float& val)
66 {
67 disp.push_back(Displacement(Index(x,y,z), val));
68 }
69
70 void push_back(const Displacement& displacement)
71 {
72 disp.push_back(displacement);
73 }
74
75 iterator begin() const
76 {
77 return disp.begin();
78 }
79
80 iterator end() const
81 {
82 return disp.end();
83 }
84
85 size_t size() const
86 {
87 return disp.size();
88 }
89
90 void clear()
91 {
92 disp.clear();
93 }
94
95 vmg_float Apply(const Grid& grid, const Index& index) const
96 {
97 vmg_float result = diag * grid.GetVal(index);
98 for (Stencil::iterator iter=disp.begin(); iter!=disp.end(); ++iter)
99 result += iter->Val() * grid.GetVal(index.X() + iter->Disp().X(),
100 index.Y() + iter->Disp().Y(),
101 index.Z() + iter->Disp().Z());
102 return result;
103 }
104
105private:
106 std::vector<Displacement> disp;
107 vmg_float diag;
108};
109
110}
111
112#endif /* STENCIL_HPP_ */
Note: See TracBrowser for help on using the repository browser.