aslBlocks.h
Go to the documentation of this file.
/*
* Advanced Simulation Library <http://asl.org.il>
*
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
*
*
* This file is part of Advanced Simulation Library (ASL).
*
* ASL is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* ASL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ASLBLOCKS_H
#define ASLBLOCKS_H
#include <iostream>
#include <fstream>
#include "../math/aslVectors.h"
namespace acl
{
class VectorOfElements;
}
namespace asl
{
class Box
{
public:
typedef AVec<> V;
V size;
V position;
inline explicit Box(unsigned int nd);
};
class Block
{
public:
typedef AVec<int> DV;
private:
DV size;
public:
typedef AVec<> V;
V position;
double dx;
DV c2iTransformVector;
inline Block();
inline explicit Block(unsigned int nd);
inline Block(const DV & s, double dx, const V & p);
inline explicit Block(const DV & s, double dx = 1);
inline Block(const Block & b);
inline const Block& operator=(const Block & b);
int c2i(const Block::DV & c) const;
inline void setSize(const DV & s);
inline const DV & getSize() const;
inline const V getBPosition() const;
acl::VectorOfElements initACLPositionDiscrete();
acl::VectorOfElements initACLPosition();
acl::VectorOfElements getACLPositionDiscrete();
acl::VectorOfElements getACLPosition();
};
const Block offset(const Block & bl, int a = 1);
inline const unsigned int nD(const Block & b);
inline const bool in(const Block & b, AVec<> a);
inline const bool in(const Block & b, AVec<int> a);
inline const AVec<int> continiousToDiscret(const Block & b, AVec<> a);
//--------------- Implementation----------------
inline Box::Box(unsigned int nd):size(nd),position(nd)
{
}
inline AVec<int> castTransformVector(AVec<int> s)
{
unsigned int n(s.getSize());
AVec<int> r(n, 1);
int a(1);
for (unsigned int i = 0; i < n - 1; ++i)
{
a *= s[n - 1 - i];
r[n - 2 - i] = a;
}
return r;
}
inline Block::Block(unsigned int nd):
size(nd),
position(nd),
dx(1),
c2iTransformVector(castTransformVector(size))
{
}
inline Block::Block():
size(1),
position(1,0.),
dx(1),
c2iTransformVector(castTransformVector(size))
{
}
inline Block::Block(const Block::DV & s, double d):
size(s),
position(V(s.getSize())),
dx(d),
c2iTransformVector(castTransformVector(s))
{
}
inline Block::Block(const Block::DV & s, double d, const Block::V & p):
size(s),
position(p),
dx(d),
c2iTransformVector(castTransformVector(s))
{
if (p.getSize() != s.getSize())
errorMessage ("Block::Block() Size and Position dimensionalities are different");
}
inline Block::Block(const Block & b):
size(b.size),
position(b.position),
dx(b.dx),
c2iTransformVector(b.c2iTransformVector)
{
}
inline const Block & Block::operator=(const Block & b)
{
position=b.position;
size = b.size;
dx = b.dx;
c2iTransformVector = b.c2iTransformVector;
return *this;
}
inline int Block::c2i(const DV & c) const
{
unsigned int n(c2iTransformVector.getSize());
if (c.getSize() != n)
errorMessage("Block::c2i() - The input vector size does not correspond to the block dimensionality");
return c * c2iTransformVector;
}
inline void Block::setSize(const DV & s)
{
size = s;
if(position.getSize()!= s.getSize())
position=V(s.getSize());
c2iTransformVector = castTransformVector(s);
}
inline const Block::DV & Block::getSize() const
{
return size;
}
inline const Block::V Block::getBPosition() const
{
return position + (V(size - DV(size.getSize(), 1.)) ) * dx;
}
inline const unsigned int nD(const Block & b)
{
return b.position.getSize();
}
inline const bool in(const Block & b, AVec<> a)
{
return positive(a-b.position) && positive(b.getBPosition() - a);
}
inline const bool in(const Block & b, AVec<int> a)
{
return positive(a) && positive(b.getSize() - a);
}
} //asl
#endif //ASLBLOCKS_H
acl::VectorOfElements
The class represents several Element.
Definition: aclVectorOfElementsDef.h:92
asl::AVec
Definition: aslVectorsDynamicLength.h:40
asl::AVec::getSize
const unsigned int & getSize() const
Definition: aslVectorsDynamicLength.h:171
asl::Block
Definition: aslBlocks.h:57
asl::Block::getACLPositionDiscrete
acl::VectorOfElements getACLPositionDiscrete()
asl::Block::dx
double dx
Definition: aslBlocks.h:66
asl::Block::DV
AVec< int > DV
Discrete Vector.
Definition: aslBlocks.h:59
asl::Block::getBPosition
const V getBPosition() const
Definition: aslBlocks.h:214
asl::Block::getSize
const DV & getSize() const
Definition: aslBlocks.h:208
asl::Block::initACLPosition
acl::VectorOfElements initACLPosition()
asl::Block::setSize
void setSize(const DV &s)
Definition: aslBlocks.h:199
asl::Block::Block
Block()
the size is taken 1, the position is taken to be 0
Definition: aslBlocks.h:141
asl::Block::c2i
int c2i(const Block::DV &c) const
defines convertion rule of 1D/2D/3D index i into container one
Definition: aslBlocks.h:189
asl::Block::position
V position
Definition: aslBlocks.h:65
asl::Block::operator=
const Block & operator=(const Block &b)
Definition: aslBlocks.h:179
asl::Block::getACLPosition
acl::VectorOfElements getACLPosition()
asl::Block::initACLPositionDiscrete
acl::VectorOfElements initACLPositionDiscrete()
asl::Block::V
AVec V
Type of the position.
Definition: aslBlocks.h:63
asl::Block::c2iTransformVector
DV c2iTransformVector
Definition: aslBlocks.h:67
asl::Box
The block without discretization (size and position are float)
Definition: aslBlocks.h:41
asl::Box::V
AVec V
Type of a vector.
Definition: aslBlocks.h:43
asl::Box::Box
Box(unsigned int nd)
the size and position are taken 0
Definition: aslBlocks.h:113
asl::Box::position
V position
Definition: aslBlocks.h:45
asl::Box::size
V size
Definition: aslBlocks.h:44
asl::nD
const unsigned int nD(const Block &b)
Definition: aslBlocks.h:220
asl::offset
const Block offset(const Block &bl, int a=1)
asl::dx
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
asl::errorMessage
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
acl
Advanced Computational Language.
Definition: acl.h:41
asl
Advanced Simulation Library.
Definition: aslDataInc.h:31
asl::in
bool in(const T &xx, const T &x1, const T &x2)
Checks the belonging to a closed interval [x1,x2], .
Definition: aslUtilities.h:84
asl::castTransformVector
AVec< int > castTransformVector(AVec< int > s)
Definition: aslBlocks.h:118
asl::continiousToDiscret
const AVec< int > continiousToDiscret(const Block &b, AVec<> a)
asl::positive
const bool positive(const AVec< T > &a)
Definition: aslVectorsDynamicLengthOperations.h:345