mantaflow  0.10
A framework for fluid simulation
shapes.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  *
4  * MantaFlow fluid solver framework
5  * Copyright 2011 Tobias Pfaff, Nils Thuerey
6  *
7  * This program is free software, distributed under the terms of the
8  * GNU General Public License (GPL)
9  * http://www.gnu.org/licenses
10  *
11  * shapes classes
12  *
13  ******************************************************************************/
14 
15 #ifndef _SHAPES_H
16 #define _SHAPES_H
17 
18 #include "manta.h"
19 #include "vectorbase.h"
20 #include "levelset.h"
21 
22 namespace Manta {
23 
24 // forward declaration
25 class Mesh;
26 
29 PYTHON class Shape : public PbClass {
30 public:
31  enum GridType { TypeNone = 0, TypeBox = 1, TypeSphere = 2, TypeCylinder = 3, TypeSlope = 4 };
32 
33  PYTHON() Shape(FluidSolver* parent);
34 
36  inline GridType getType() const { return mType; }
37 
39  PYTHON() void applyToGrid(GridBase* grid, FlagGrid* respectFlags=0);
40  PYTHON() void applyToGridSmooth(GridBase* grid, Real sigma=1.0, Real shift=0, FlagGrid* respectFlags=0);
41  PYTHON() LevelsetGrid computeLevelset();
42  PYTHON() void collideMesh(Mesh& mesh);
43  PYTHON() virtual Vec3 getCenter() const { return Vec3::Zero; }
44  PYTHON() virtual void setCenter(const Vec3& center) {}
45  PYTHON() virtual Vec3 getExtent() const { return Vec3::Zero; }
46 
48  virtual bool isInside(const Vec3& pos) const;
49  inline bool isInsideGrid(int i, int j, int k) const { return isInside(Vec3(i+0.5,j+0.5,k+0.5)); };
50 
51  virtual void generateMesh(Mesh* mesh) {} ;
52  virtual void generateLevelset(Grid<Real>& phi) {};
53 
54 protected:
55  GridType mType;
56 };
57 
60 PYTHON class NullShape : public Shape {
61 public:
62  PYTHON() NullShape (FluidSolver* parent) : Shape(parent) {}
63 
64  virtual bool isInside(const Vec3& pos) const { return false; }
65  virtual void generateMesh(Mesh* mesh) {}
66 
67 protected:
68  virtual void generateLevelset(Grid<Real>& phi) { gridSetConst<Real>( phi , 1000.0f ); }
69 };
70 
73 PYTHON class Box : public Shape {
74 public:
75  PYTHON() Box(FluidSolver* parent, Vec3 center = Vec3::Invalid, Vec3 p0 = Vec3::Invalid, Vec3 p1 = Vec3::Invalid, Vec3 size = Vec3::Invalid);
76 
77  inline Vec3 getSize() const { return mP1-mP0; }
78  inline Vec3 getP0() const { return mP0; }
79  inline Vec3 getP1() const { return mP1; }
80  virtual void setCenter(const Vec3& center) { Vec3 dh=0.5*(mP1-mP0); mP0 = center-dh; mP1 = center+dh;}
81  virtual Vec3 getCenter() const { return 0.5*(mP1+mP0); }
82  virtual Vec3 getExtent() const { return getSize(); }
83  virtual bool isInside(const Vec3& pos) const;
84  virtual void generateMesh(Mesh* mesh);
85  virtual void generateLevelset(Grid<Real>& phi);
86 
87 protected:
88  Vec3 mP0, mP1;
89 };
90 
93 PYTHON class Sphere : public Shape {
94 public:
95  PYTHON() Sphere (FluidSolver* parent, Vec3 center, Real radius, Vec3 scale=Vec3(1,1,1));
96 
97  virtual void setCenter(const Vec3& center) { mCenter = center; }
98  virtual Vec3 getCenter() const { return mCenter; }
99  inline Real getRadius() const { return mRadius; }
100  virtual Vec3 getExtent() const { return Vec3(2.0*mRadius); }
101  virtual bool isInside(const Vec3& pos) const;
102  virtual void generateMesh(Mesh* mesh);
103  virtual void generateLevelset(Grid<Real>& phi);
104 
105 protected:
106  Vec3 mCenter, mScale;
107  Real mRadius;
108 };
109 
112 PYTHON class Cylinder : public Shape {
113 public:
114  PYTHON() Cylinder (FluidSolver* parent, Vec3 center, Real radius, Vec3 z);
115 
116  PYTHON() void setRadius(Real r) { mRadius = r; }
117  PYTHON() void setZ(Vec3 z) { mZDir=z; mZ=normalize(mZDir); }
118 
119  virtual void setCenter(const Vec3& center) { mCenter=center; }
120  virtual Vec3 getCenter() const { return mCenter; }
121  inline Real getRadius() const { return mRadius; }
122  inline Vec3 getZ() const { return mZ*mZDir; }
123  virtual Vec3 getExtent() const { return Vec3(2.0*sqrt(square(mZ)+square(mRadius))); }
124  virtual bool isInside(const Vec3& pos) const;
125  virtual void generateMesh(Mesh* mesh);
126  virtual void generateLevelset(Grid<Real>& phi);
127 
128 protected:
129  Vec3 mCenter, mZDir;
130  Real mRadius, mZ;
131 };
132 
134 // generates a levelset based on a plane
135 // plane is specified by two angles and an offset on the y axis in (offset vector would be ( 0, offset, 0) )
136 // the two angles are specified in degrees, between: y-axis and x-axis
137 // y-axis and z-axis
139 PYTHON class Slope : public Shape {
140 public:
141  PYTHON() Slope (FluidSolver* parent, Real anglexy, Real angleyz, Real origin, Vec3 gs);
142 
143  virtual void setOrigin (const Real& origin) { mOrigin=origin; }
144  virtual void setAnglexy(const Real& anglexy) { mAnglexy=anglexy; }
145  virtual void setAngleyz(const Real& angleyz) { mAnglexy=angleyz; }
146 
147  inline Real getOrigin() const { return mOrigin; }
148  inline Real getmAnglexy() const { return mAnglexy; }
149  inline Real getmAngleyz() const { return mAngleyz; }
150  virtual bool isInside(const Vec3& pos) const;
151  virtual void generateMesh(Mesh* mesh);
152  virtual void generateLevelset(Grid<Real>& phi);
153 
154 protected:
155  Real mAnglexy, mAngleyz;
156  Real mOrigin;
157  Vec3 mGs;
158 };
159 
160 } //namespace
161 #endif
162 
163 
Definition: shapes.h:60
Definition: commonkernels.h:22
Definition: grid.h:267
Basic inlined vector class.
Definition: vectorbase.h:71
static const Vector3D< S > Zero
zero element
Definition: vectorbase.h:212
Definition: shapes.h:73
Definition: shapes.h:112
Triangle mesh class.
Definition: mesh.h:126
Definition: levelset.h:25
GridType getType() const
Get the type of grid.
Definition: shapes.h:36
Definition: shapes.h:29
virtual bool isInside(const Vec3 &pos) const
Inside test of the shape.
Definition: shapes.cpp:37
virtual bool isInside(const Vec3 &pos) const
Inside test of the shape.
Definition: shapes.h:64
Definition: shapes.h:93
Slope shape.
Definition: shapes.h:139
Definition: grid.h:29
Definition: fluidsolver.h:28