ASL  0.1.7
Advanced Simulation Library
aslBlocks.h
Go to the documentation of this file.
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 
40  class Box
41  {
42  public:
43  typedef AVec<> V;
46 
48  inline explicit Box(unsigned int nd);
49  };
50 
51 
56  class Block
57  {
58  public:
59  typedef AVec<int> DV;
60  private:
61  DV size;
62  public:
63  typedef AVec<> V;
64 
66  double dx;
68 
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);
77  int c2i(const Block::DV & c) const;
78  inline void setSize(const DV & s);
79  inline const DV & getSize() const;
82  inline const V getBPosition() const;
85 
88  };
89 
90 
93  const Block offset(const Block & bl, int a = 1);
94 
95 
98  inline const unsigned int nD(const Block & b);
99 
102  inline const bool in(const Block & b, AVec<> a);
103 
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 
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;
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());
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 
AVec V
Type of a vector.
Definition: aslBlocks.h:43
void setSize(const DV &s)
Definition: aslBlocks.h:199
acl::VectorOfElements getACLPosition()
Advanced Simulation Library.
Definition: aslDataInc.h:30
Advanced Computational Language.
Definition: acl.h:40
const DV & getSize() const
Definition: aslBlocks.h:208
Block()
the size is taken 1, the position is taken to be 0
Definition: aslBlocks.h:141
const AVec< int > continiousToDiscret(const Block &b, AVec<> a)
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
DV c2iTransformVector
Definition: aslBlocks.h:67
const unsigned int nD(const Block &b)
Definition: aslBlocks.h:220
double dx
Definition: aslBlocks.h:66
bool in(const T &xx, const T &x1, const T &x2)
Checks the belonging to a closed interval [x1,x2], .
Definition: aslUtilities.h:84
AVec< int > castTransformVector(AVec< int > s)
Definition: aslBlocks.h:118
AVec< int > DV
Discrete Vector.
Definition: aslBlocks.h:59
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
const Block offset(const Block &bl, int a=1)
Box(unsigned int nd)
the size and position are taken 0
Definition: aslBlocks.h:113
acl::VectorOfElements initACLPosition()
V position
Definition: aslBlocks.h:45
The class represents several Element.
acl::VectorOfElements initACLPositionDiscrete()
const Block & operator=(const Block &b)
Definition: aslBlocks.h:179
const unsigned int & getSize() const
The block without discretization (size and position are float)
Definition: aslBlocks.h:40
const bool positive(const AVec< T > &a)
const V getBPosition() const
Definition: aslBlocks.h:214
acl::VectorOfElements getACLPositionDiscrete()
int c2i(const Block::DV &c) const
defines convertion rule of 1D/2D/3D index i into container one
Definition: aslBlocks.h:189
AVec V
Type of the position.
Definition: aslBlocks.h:63