LevelSetWall.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
9 
10 #ifndef LevelSetWall_H
11 #define LevelSetWall_H
12 
13 #include "BaseWall.h"
14 #include "Math/Vector.h"
15 
26 class LevelSetWall final : public BaseWall
27 {
28 public:
29 
30  // a set of predefined shapes for which level set values can be set easily
31  enum class Shape
32  {
33  Sphere,
34  Cube,
35  Diamond,
36  FourSided,
37  Cylinder
38  };
39 
40  // Constructor; currently only allows predefined shapes
41  LevelSetWall(Shape s, double radius, ParticleSpecies* sp = nullptr);
42 
46  ~LevelSetWall() override;
47 
51  LevelSetWall* copy() const override;
52 
53  using BaseWall::move;
54 
55 // /*!
56 // * \brief Returns the distance of the wall to the particle.
57 // */
58 // Mdouble getDistance(Vec3D position) const;
59 
63  bool getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const override;
64 
68  void read(std::istream& is) override;
69 
73  std::string getName() const override;
74 
78  void writeVTK(VTKContainer& vtk) const override;
79 
84  void writeToFile(int n, double radiusContact) const;
85 
86 private:
87 
88  // Evaluates the distance and normal direction to the surface defined by the level set. Needed for contact detection.
89  // If distance is bigger than radius_+radiusContact, no normal & distance is returned because no contact is possible.
90  // Else, it returns the overlap (level set value) and normal direction (-gradient).
91  bool getDistanceAndNormalLabCoordinates(Vec3D position, Mdouble interactionRadius, Mdouble& distance,
92  Vec3D& normal) const;
93 
94  void setShapeSphere();
95 
96  void setShapeCube();
97 
98  //Better interpolated than a square as the edges of the level set align with the mesh.
99  void setShapeDiamond();
100 
101  void setShapeCylinder();
102 
103  void setShapeFourSided();
104 
105  void createVTKSphere();
106 
107  void createVTKCube();
108 
109  void createVTKDiamond();
110 
111  void createVTK();
112 
113 
114  // N determines the number of level set values (2N+1)^3;
115  // \todo template the level set with N.
116  static const int N = 10;
117 
118  // 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_.
119  double levelSet_[2 * N + 1][2 * N + 1][2 * N + 1];
120 
121  // the radius of a sphere that envelopes the object
122  double radius_ = 1;
123 
125 };
126 
127 #endif
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
double Mdouble
Definition: GeneralDefine.h:13
float * p
Definition: Tutorial_Map_using.cpp:9
virtual void move(const Vec3D &move)
Moves this BaseInteractable by adding an amount to the position.
Definition: BaseInteractable.cc:193
Definition: BaseParticle.h:33
Basic class for walls.
Definition: BaseWall.h:28
A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.
Definition: LevelSetWall.h:27
void createVTK()
Definition: LevelSetWall.cc:169
void read(std::istream &is) override
Reads LevelSetWall from a restart file.
Definition: LevelSetWall.cc:101
void createVTKCube()
Definition: LevelSetWall.cc:128
void createVTKDiamond()
Definition: LevelSetWall.cc:149
Shape
Definition: LevelSetWall.h:32
LevelSetWall(Shape s, double radius, ParticleSpecies *sp=nullptr)
Definition: LevelSetWall.cc:15
std::string getName() const override
Returns the name of the object, in this case the string "LevelSetWall".
Definition: LevelSetWall.cc:112
LevelSetWall * copy() const override
Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism.
Definition: LevelSetWall.cc:57
double levelSet_[2 *N+1][2 *N+1][2 *N+1]
Definition: LevelSetWall.h:119
double radius_
Definition: LevelSetWall.h:122
void setShapeCube()
Definition: LevelSetWall.cc:375
VTKContainer vtkLabFrame_
Definition: LevelSetWall.h:124
bool getDistanceAndNormal(const BaseParticle &p, Mdouble &distance, Vec3D &normal_return) const override
Definition: LevelSetWall.cc:83
bool getDistanceAndNormalLabCoordinates(Vec3D position, Mdouble interactionRadius, Mdouble &distance, Vec3D &normal) const
Definition: LevelSetWall.cc:287
void writeToFile(int n, double radiusContact) const
Definition: LevelSetWall.cc:240
void writeVTK(VTKContainer &vtk) const override
Definition: LevelSetWall.cc:117
void setShapeFourSided()
Definition: LevelSetWall.cc:427
~LevelSetWall() override
Default destructor.
Definition: LevelSetWall.cc:49
void setShapeDiamond()
Definition: LevelSetWall.cc:412
void createVTKSphere()
Definition: LevelSetWall.cc:195
static const int N
Definition: LevelSetWall.h:116
void setShapeSphere()
Definition: LevelSetWall.cc:345
void setShapeCylinder()
Definition: LevelSetWall.cc:360
Definition: ParticleSpecies.h:16
Definition: Kernel/Math/Vector.h:30
RealScalar s
Definition: level1_cplx_impl.h:130
radius
Definition: UniformPSDSelfTest.py:15
void normal(const Vector< double > &x, Vector< double > &normal)
Definition: free_surface_rotation.cc:65
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
Definition: BaseWall.h:17