Debian Codegraph @

src/data/aslBlocks.h

raw
1 /*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
24 #ifndef ASLBLOCKS_H
25 #define ASLBLOCKS_H
26
27 #include <iostream>
28 #include <fstream>
29 #include "../math/aslVectors.h"
30
31 namespace acl
32 {
33 class VectorOfElements;
34 }
35
36 namespace asl
37 {
38
39 /// The block without discretization (size and position are float)
40 class Box
41 {
42 public:
43 typedef AVec<> V; ///< Type of a vector
44 V size;
45 V position;
46
47 /// the size and position are taken 0
48 inline explicit Box(unsigned int nd);
49 };
50
51
52 /// Simple block with position
53 /// \ingroup DataFields
54 /// The Block describes the simulation grid
55 /// and is defined by the position and by the size.
56 class Block
57 {
58 public:
59 typedef AVec<int> DV; ///<Discrete Vector
60 private:
61 DV size;
62 public:
63 typedef AVec<> V; ///<Type of the position
64
65 V position;
66 double dx;
67 DV c2iTransformVector;
68
69 /// the size is taken 1, the position is taken to be 0
70 inline Block();
71 inline explicit Block(unsigned int nd);
72 inline Block(const DV & s, double dx, const V & p);
73 inline explicit Block(const DV & s, double dx = 1);
74 inline Block(const Block & b);
75 inline const Block& operator=(const Block & b);
76 /// defines convertion rule of 1D/2D/3D index \p i into container one
77 int c2i(const Block::DV & c) const;
78 inline void setSize(const DV & s);
79 inline const DV & getSize() const;
80 /// returns position of the point diagonal to (0) one
81 /// returns Body Diagonal (or space diagonal) that starts at (0)
82 inline const V getBPosition() const;
83 acl::VectorOfElements initACLPositionDiscrete();
84 acl::VectorOfElements initACLPosition();
85
86 acl::VectorOfElements getACLPositionDiscrete();
87 acl::VectorOfElements getACLPosition();
88 };
89
90
91 /// results Block which is inset or outset of the \p bl on value of a
92 /// \ingroup DataFields
93 const Block offset(const Block & bl, int a = 1);
94
95
96 /// Dimensionality of the block \ingroup DataFields
97 /// \todo rename here and everywhere to dimNum???
98 inline const unsigned int nD(const Block & b);
99
100 /// Checks whether \p a inside of \p b
101 /// \ingroup DataFields
102 inline const bool in(const Block & b, AVec<> a);
103
104 /// Checks whether \p a inside of \p b
105 /// \ingroup DataFields
106 inline const bool in(const Block & b, AVec<int> a);
107
108
109 inline const AVec<int> continiousToDiscret(const Block & b, AVec<> a);
110
111 //--------------- Implementation----------------
112
113 inline Box::Box(unsigned int nd):size(nd),position(nd)
114 {
115 }
116
117
118 inline AVec<int> castTransformVector(AVec<int> s)
119 {
120 unsigned int n(s.getSize());
121 AVec<int> r(n, 1);
122 int a(1);
123 for (unsigned int i = 0; i < n - 1; ++i)
124 {
125 a *= s[n - 1 - i];
126 r[n - 2 - i] = a;
127 }
128 return r;
129 }
130
131
132 inline Block::Block(unsigned int nd):
133 size(nd),
134 position(nd),
135 dx(1),
136 c2iTransformVector(castTransformVector(size))
137 {
138 }
139
140
141 inline Block::Block():
142 size(1),
143 position(1,0.),
144 dx(1),
145 c2iTransformVector(castTransformVector(size))
146 {
147 }
148
149
150 inline Block::Block(const Block::DV & s, double d):
151 size(s),
152 position(V(s.getSize())),
153 dx(d),
154 c2iTransformVector(castTransformVector(s))
155 {
156 }
157
158
159 inline Block::Block(const Block::DV & s, double d, const Block::V & p):
160 size(s),
161 position(p),
162 dx(d),
163 c2iTransformVector(castTransformVector(s))
164 {
165 if (p.getSize() != s.getSize())
166 errorMessage ("Block::Block() Size and Position dimensionalities are different");
167 }
168
169
170 inline Block::Block(const Block & b):
171 size(b.size),
172 position(b.position),
173 dx(b.dx),
174 c2iTransformVector(b.c2iTransformVector)
175 {
176 }
177
178
179 inline const Block & Block::operator=(const Block & b)
180 {
181 position=b.position;
182 size = b.size;
183 dx = b.dx;
184 c2iTransformVector = b.c2iTransformVector;
185 return *this;
186 }
187
188
189 inline int Block::c2i(const DV & c) const
190 {
191 unsigned int n(c2iTransformVector.getSize());
192 if (c.getSize() != n)
193 errorMessage("Block::c2i() - The input vector size does not correspond to the block dimensionality");
194
195 return c * c2iTransformVector;
196 }
197
198
199 inline void Block::setSize(const DV & s)
200 {
201 size = s;
202 if(position.getSize()!= s.getSize())
203 position=V(s.getSize());
204 c2iTransformVector = castTransformVector(s);
205 }
206
207
208 inline const Block::DV & Block::getSize() const
209 {
210 return size;
211 }
212
213
214 inline const Block::V Block::getBPosition() const
215 {
216 return position + (V(size - DV(size.getSize(), 1.)) ) * dx;
217 }
218
219
220 inline const unsigned int nD(const Block & b)
221 {
222 return b.position.getSize();
223 }
224
225
226 inline const bool in(const Block & b, AVec<> a)
227 {
228 return positive(a-b.position) && positive(b.getBPosition() - a);
229 }
230
231
232 inline const bool in(const Block & b, AVec<int> a)
233 {
234 return positive(a) && positive(b.getSize() - a);
235 }
236
237 } //asl
238
239 #endif //ASLBLOCKS_H
240