1/*
2 * Ghost.hpp
3 *
4 * Created on: Apr 28, 2015
5 * Author: Pietro Incardona
6 */
7
8#ifndef GHOST_HPP_
9#define GHOST_HPP_
10
11#include "SpaceBox.hpp"
12
13#define INVALID_GHOST 9223372036854775807
14
15/*! Ghost
16 *
17 * it indicate the ghost extension
18 *
19 * Ghost margins for each dimensions (p1 negative part) (p2 positive part)
20 ^ p2[1]
21 |
22 |
23 +----+----+
24 | |
25 | |
26p1[0]<-----+ +----> p2[0]
27 | |
28 | |
29 +----+----+
30 |
31 v p1[1]
32
33
34 \warning p1[0] and p1[1] must be negative hile p2[1] and p2[0] must be positive
35 *
36 */
37
38template<unsigned int dim, typename T>
39class Ghost : public Box<dim,T>
40{
41public:
42
43 /*! constructor from another Ghost
44 *
45 * \param g ghost
46 *
47 */
48 template <typename S> inline Ghost(const Ghost<dim,S> & g)
49 {
50 for (size_t i = 0 ; i < dim ; i++)
51 {
52 this->setLow(i,g.getLow(i));
53 this->setHigh(i,g.getHigh(i));
54 }
55 }
56
57 /*! \brief Constructor from initializer list
58 *
59 * \param p1 Low point, initialize as a list example {0.0,0.0,0.0}
60 * \param p2 High point, initialized as a list example {1.0,1.0,1.0}
61 *
62 */
63 Ghost(std::initializer_list<T> p1, std::initializer_list<T> p2)
64 :Box<dim,T>(p1,p2)
65 {}
66
67 // construct a ghost based on interaction radius
68 inline Ghost(T r)
69 {
70 for (size_t i = 0 ; i < dim ; i++)
71 {
72 this->setLow(i,-r);
73 this->setHigh(i,r);
74 }
75 }
76
77 // Basic constructor
78 inline Ghost()
79 {
80 for (size_t i = 0 ; i < dim ; i++)
81 {
82 this->setLow(i,0);
83 this->setHigh(i,0);
84 }
85 }
86
87 /*! \brief Divide component wise the ghost box with a point
88 *
89 * \param p point
90 *
91 * \return itself
92 *
93 */
94 inline Ghost<dim,T> & operator/=(const Point<dim,T> & p)
95 {
96 Box<dim,T>::operator/=(p);
97
98 return *this;
99 }
100
101 /*! \brief check if the Ghost is valid
102 *
103 *
104 *
105 */
106 inline bool isInvalidGhost()
107 {
108 for (size_t i = 0 ; i < dim ; i++)
109 {
110 if (this->getLow(i) == -INVALID_GHOST) return true;
111 if (this->getHigh(i) == INVALID_GHOST) return true;
112 }
113
114 return false;
115 }
116};
117
118/*! \brief Class that contain Padding information on each direction positive and Negative direction
119 *
120 * It is equivalent to a Ghost<dim,size_t>
121 *
122 * \see Ghost
123 *
124 */
125template<unsigned int dim>
126class Padding : public Ghost<dim,long int>
127{
128public:
129 /*! \brief Constructor from initializer list
130 *
131 * \param p1 Padding left, initialize as a list example {0.0,0.0,0.0}
132 * \param p2 Padding right, initialized as a list example {1.0,1.0,1.0}
133 *
134 */
135 Padding(std::initializer_list<long int> p1, std::initializer_list<long int> p2)
136 {
137 Box<dim,long int>::set(p1,p2);
138 }
139};
140
141#endif /* GHOST_HPP_ */
142