MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LevelSetWall.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
30 
31 #ifndef LevelSetWall_H
32 #define LevelSetWall_H
33 
34 #include "BaseWall.h"
35 #include "Math/Vector.h"
36 
47 class LevelSetWall final : public BaseWall
48 {
49 public:
50 
51  // a set of predefined shapes for which level set values can be set easily
52  enum class Shape
53  {
54  Sphere,
55  Cube,
56  Diamond,
57  FourSided,
58  Cylinder
59  };
60 
61  // Constructor; currently only allows predefined shapes
62  LevelSetWall(Shape s, double radius, ParticleSpecies* sp = nullptr);
63 
67  ~LevelSetWall() override;
68 
72  LevelSetWall* copy() const override;
73 
74  using BaseWall::move;
75 
76 // /*!
77 // * \brief Returns the distance of the wall to the particle.
78 // */
79 // Mdouble getDistance(Vec3D position) const;
80 
84  bool getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const override;
85 
89  void read(std::istream& is) override;
90 
94  std::string getName() const override;
95 
99  void writeVTK(VTKContainer& vtk) const override;
100 
105  void writeToFile(int n, double radiusContact) const;
106 
107 private:
108 
109  // Evaluates the distance and normal direction to the surface defined by the level set. Needed for contact detection.
110  // If distance is bigger than radius_+radiusContact, no normal & distance is returned because no contact is possible.
111  // Else, it returns the overlap (level set value) and normal direction (-gradient).
112  bool getDistanceAndNormalLabCoordinates(Vec3D position, Mdouble interactionRadius, Mdouble& distance,
113  Vec3D& normal) const;
114 
115  void setShapeSphere();
116 
117  void setShapeCube();
118 
119  //Better interpolated than a square as the edges of the level set align with the mesh.
120  void setShapeDiamond();
121 
122  void setShapeCylinder();
123 
124  void setShapeFourSided();
125 
126  void createVTKSphere();
127 
128  void createVTKCube();
129 
130  void createVTKDiamond();
131 
132  void createVTK();
133 
134 
135  // N determines the number of level set values (2N+1)^3;
136  // \todo template the level set with N.
137  static const int N = 10;
138 
139  // discrete set of level-set values; levelSet_[i,j,k] is the value of the level set at (x,y,z)=(i,j,k)/N*radius_.
140  double levelSet_[2 * N + 1][2 * N + 1][2 * N + 1];
141 
142  // the radius of a sphere that envelopes the object
143  double radius_ = 1;
144 
146 };
147 
148 #endif
void writeToFile(int n, double radiusContact) const
LevelSetWall * copy() const override
Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism.
Definition: LevelSetWall.cc:78
void createVTKDiamond()
~LevelSetWall() override
Default destructor.
Definition: LevelSetWall.cc:70
double levelSet_[2 *N+1][2 *N+1][2 *N+1]
Definition: LevelSetWall.h:140
double Mdouble
Definition: GeneralDefine.h:34
void setShapeSphere()
void createVTK()
void setShapeDiamond()
void createVTKCube()
VTKContainer vtkLabFrame_
Definition: LevelSetWall.h:145
LevelSetWall(Shape s, double radius, ParticleSpecies *sp=nullptr)
Definition: LevelSetWall.cc:36
bool getDistanceAndNormalLabCoordinates(Vec3D position, Mdouble interactionRadius, Mdouble &distance, Vec3D &normal) const
void setShapeFourSided()
void createVTKSphere()
Basic class for walls.
Definition: BaseWall.h:47
This is a class defining walls.
Definition: LevelSetWall.h:47
bool getDistanceAndNormal(const BaseParticle &p, Mdouble &distance, Vec3D &normal_return) const override
Returns the distance of the wall to the particle.
static const int N
Definition: LevelSetWall.h:137
void read(std::istream &is) override
Reads LevelSetWall from a restart file.
std::string getName() const override
Returns the name of the object, in this case the string "LevelSetWall".
void setShapeCube()
double radius_
Definition: LevelSetWall.h:143
void setShapeCylinder()
Definition: Vector.h:49
virtual void move(const Vec3D &move)
Moves this BaseInteractable by adding an amount to the position.
void writeVTK(VTKContainer &vtk) const override