| 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 |
|
|---|
| 19 | namespace VMG
|
|---|
| 20 | {
|
|---|
| 21 |
|
|---|
| 22 | class Displacement
|
|---|
| 23 | {
|
|---|
| 24 | public:
|
|---|
| 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 |
|
|---|
| 38 | private:
|
|---|
| 39 | Index disp;
|
|---|
| 40 | vmg_float val;
|
|---|
| 41 | };
|
|---|
| 42 |
|
|---|
| 43 | class Stencil
|
|---|
| 44 | {
|
|---|
| 45 | public:
|
|---|
| 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 |
|
|---|
| 105 | void Apply(Grid& grid) const;
|
|---|
| 106 |
|
|---|
| 107 | private:
|
|---|
| 108 | std::vector<Displacement> disp;
|
|---|
| 109 | vmg_float diag;
|
|---|
| 110 | };
|
|---|
| 111 |
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | #endif /* STENCIL_HPP_ */
|
|---|