LevelSetWall Class Referencefinal

A infinite wall fills the half-space {point: (position_-point)*normal_<=0}. More...

#include <LevelSetWall.h>

+ Inheritance diagram for LevelSetWall:

Public Types

enum class  Shape {
  Sphere , Cube , Diamond , FourSided ,
  Cylinder
}
 

Public Member Functions

 LevelSetWall (Shape s, double radius, ParticleSpecies *sp=nullptr)
 
 ~LevelSetWall () override
 Default destructor. More...
 
LevelSetWallcopy () const override
 Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism. More...
 
bool getDistanceAndNormal (const BaseParticle &p, Mdouble &distance, Vec3D &normal_return) const override
 
void read (std::istream &is) override
 Reads LevelSetWall from a restart file. More...
 
std::string getName () const override
 Returns the name of the object, in this case the string "LevelSetWall". More...
 
void writeVTK (VTKContainer &vtk) const override
 
void writeToFile (int n, double radiusContact) const
 
- Public Member Functions inherited from BaseWall
 BaseWall ()
 Default constructor. More...
 
 BaseWall (const BaseWall &w)
 Copy constructor. More...
 
 ~BaseWall () override
 Default destructor. More...
 
void write (std::ostream &os) const override
 Function that writes a BaseWall to an output stream, usually a restart file. More...
 
virtual bool getDistanceNormalOverlap (const BaseParticle &P, Mdouble &distance, Vec3D &normal_return, Mdouble &overlap) const
 
virtual bool getDistanceNormalOverlapSuperquadric (const SuperQuadricParticle &p, Mdouble &distance, Vec3D &normal_return, Mdouble &overlap) const
 
virtual Vec3D getFurthestPointSuperQuadric (const Vec3D &normalBodyFixed, const Vec3D &axes, Mdouble eps1, Mdouble eps2) const
 
virtual void setHandler (WallHandler *handler)
 A function which sets the WallHandler for this BaseWall. More...
 
WallHandlergetHandler () const
 A function which returns the WallHandler that handles this BaseWall. More...
 
void setIndSpecies (unsigned int indSpecies) override
 Define the species of this wall using the index of the species in the SpeciesHandler in this DPMBase. More...
 
void setSpecies (const ParticleSpecies *species)
 Defines the species of the current wall. More...
 
bool isFixed () const override
 
void setForceControl (Vec3D forceGoal, Vec3D gainFactor, Vec3D baseVelocity={0, 0, 0})
 Slowly adjusts the force on a wall towards a specified goal, by adjusting (prescribing) the velocity of the wall. More...
 
virtual bool isLocal (Vec3D &min, Vec3D &max) const
 
bool getLinePlaneIntersect (Vec3D &intersect, const Vec3D &p0, const Vec3D &p1, const Vec3D &n, const Vec3D &p)
 
bool isInsideWallVTK (const Vec3D &point, const Vec3D &normal, const Vec3D &position) const
 
void projectOntoWallVTK (Vec3D &point0, const Vec3D &point1, const Vec3D &normal, const Vec3D &position) const
 
void intersectVTK (std::vector< Vec3D > &points, Vec3D normal, Vec3D position) const
 
virtual BaseInteractiongetInteractionWithSuperQuad (SuperQuadricParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler)
 
void getVTK (std::vector< Vec3D > &points, std::vector< std::vector< double >> &triangleStrips)
 
const Vec3D getAxis () const
 
BaseInteractiongetInteractionWith (BaseParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler) override
 Returns the interaction between this wall and a given particle, nullptr if there is no interaction. More...
 
virtual void actionsOnRestart ()
 No implementation but can be overidden in its derived classes. More...
 
virtual void actionsAfterParticleGhostUpdate ()
 No implementation but can be overidden in its derived classes. More...
 
virtual void handleParticleAddition (unsigned int id, BaseParticle *p)
 Handles the addition of particles to the particleHandler. More...
 
virtual void handleParticleRemoval (unsigned int id)
 Handles the addition of particles to the particleHandler. More...
 
virtual void checkInteractions (InteractionHandler *interactionHandler, unsigned int timeStamp)
 Check if all interactions are valid. More...
 
bool getVTKVisibility () const
 
void setVTKVisibility (bool vtkVisibility)
 
void addRenderedWall (BaseWall *w)
 
BaseWallgetRenderedWall (size_t i) const
 
std::vector< BaseWall * > getRenderedWalls () const
 
void removeRenderedWalls ()
 
void renderWall (VTKContainer &vtk)
 
void addParticlesAtWall (unsigned numElements=50)
 
void setVelocityControl (Vec3D forceGoal, Vec3D gainFactor, Vec3D baseVelocity)
 
virtual void writeWallDetailsVTK (VTKData &data) const
 
virtual void computeWear ()
 
- Public Member Functions inherited from BaseInteractable
 BaseInteractable ()
 Default BaseInteractable constructor. More...
 
 BaseInteractable (const BaseInteractable &p)
 Copy constructor. More...
 
 ~BaseInteractable () override
 Destructor, it simply destructs the BaseInteractable and all the objects it contains. More...
 
unsigned int getIndSpecies () const
 Returns the index of the species associated with the interactable object. More...
 
const ParticleSpeciesgetSpecies () const
 Returns a pointer to the species of this BaseInteractable. More...
 
void setSpecies (const ParticleSpecies *species)
 Sets the species of this BaseInteractable. More...
 
const Vec3DgetForce () const
 Returns the force on this BaseInteractable. More...
 
const Vec3DgetTorque () const
 Returns the torque on this BaseInteractable. More...
 
void setForce (const Vec3D &force)
 Sets the force on this BaseInteractable. More...
 
void setTorque (const Vec3D &torque)
 Sets the torque on this BaseInteractable. More...
 
void addForce (const Vec3D &addForce)
 Adds an amount to the force on this BaseInteractable. More...
 
void addTorque (const Vec3D &addTorque)
 Adds an amount to the torque on this BaseInteractable. More...
 
virtual void resetForceTorque (int numberOfOMPthreads)
 
void sumForceTorqueOMP ()
 
const Vec3DgetPosition () const
 Returns the position of this BaseInteractable. More...
 
const QuaterniongetOrientation () const
 Returns the orientation of this BaseInteractable. More...
 
virtual void setPosition (const Vec3D &position)
 Sets the position of this BaseInteractable. More...
 
void setOrientationViaNormal (Vec3D normal)
 Sets the orientation of this BaseInteractable by defining the vector that results from the rotation of the (1,0,0) vector. More...
 
void setOrientationViaEuler (Vec3D eulerAngle)
 Sets the orientation of this BaseInteractable by defining the euler angles. More...
 
virtual void setOrientation (const Quaternion &orientation)
 Sets the orientation of this BaseInteractable. More...
 
virtual void move (const Vec3D &move)
 Moves this BaseInteractable by adding an amount to the position. More...
 
virtual void rotate (const Vec3D &angularVelocityDt)
 Rotates this BaseInteractable. More...
 
const std::vector< BaseInteraction * > & getInteractions () const
 Returns a list of interactions which belong to this interactable. More...
 
void addInteraction (BaseInteraction *I)
 Adds an interaction to this BaseInteractable. More...
 
bool removeInteraction (BaseInteraction *I)
 Removes an interaction from this BaseInteractable. More...
 
void copyInteractionsForPeriodicParticles (const BaseInteractable &p)
 Copies interactions to this BaseInteractable whenever a periodic copy made. More...
 
void setVelocity (const Vec3D &velocity)
 set the velocity of the BaseInteractable. More...
 
void setAngularVelocity (const Vec3D &angularVelocity)
 set the angular velocity of the BaseInteractble. More...
 
void addVelocity (const Vec3D &velocity)
 adds an increment to the velocity. More...
 
void addAngularVelocity (const Vec3D &angularVelocity)
 add an increment to the angular velocity. More...
 
virtual const Vec3DgetVelocity () const
 Returns the velocity of this interactable. More...
 
virtual const Vec3DgetAngularVelocity () const
 Returns the angular velocity of this interactable. More...
 
void setPrescribedPosition (const std::function< Vec3D(double)> &prescribedPosition)
 Allows the position of an infinite mass interactable to be prescribed. More...
 
void applyPrescribedPosition (double time)
 Computes the position from the user defined prescribed position function. More...
 
void setPrescribedVelocity (const std::function< Vec3D(double)> &prescribedVelocity)
 Allows the velocity of an infinite mass interactable to be prescribed. More...
 
void applyPrescribedVelocity (double time)
 Computes the velocity from the user defined prescribed velocity function. More...
 
void setPrescribedOrientation (const std::function< Quaternion(double)> &prescribedOrientation)
 Allows the orientation of the infinite mass interactbale to be prescribed. More...
 
void applyPrescribedOrientation (double time)
 Computes the orientation from the user defined prescribed orientation function. More...
 
void setPrescribedAngularVelocity (const std::function< Vec3D(double)> &prescribedAngularVelocity)
 Allows the angular velocity of the infinite mass interactable to be prescribed. More...
 
void applyPrescribedAngularVelocity (double time)
 Computes the angular velocity from the user defined prescribed angular velocity. More...
 
virtual const Vec3D getVelocityAtContact (const Vec3D &contact) const
 Returns the velocity at the contact point, use by many force laws. More...
 
void integrateBeforeForceComputation (double time, double timeStep)
 This is part of integrate routine for objects with infinite mass. More...
 
void integrateAfterForceComputation (double time, double timeStep)
 This is part of the integration routine for objects with infinite mass. More...
 
virtual Mdouble getInvMass () const
 
virtual Mdouble getCurvature (const Vec3D &labFixedCoordinates) const
 
virtual bool isFaceContact (const Vec3D &normal) const
 
- Public Member Functions inherited from BaseObject
 BaseObject ()=default
 Default constructor. More...
 
 BaseObject (const BaseObject &p)=default
 Copy constructor, copies all the objects BaseObject contains. More...
 
virtual ~BaseObject ()=default
 virtual destructor More...
 
virtual void moveInHandler (unsigned int index)
 Except that it is virtual, it does the same thing as setIndex() does. More...
 
void setIndex (unsigned int index)
 Allows one to assign an index to an object in the handler/container. More...
 
void setId (unsigned long id)
 Assigns a unique identifier to each object in the handler (container) which remains constant even after the object is deleted from the container/handler. More...
 
unsigned int getIndex () const
 Returns the index of the object in the handler. More...
 
unsigned int getId () const
 Returns the unique identifier of any particular object. More...
 
void setGroupId (unsigned groupId)
 
unsigned getGroupId () const
 

Private Member Functions

bool getDistanceAndNormalLabCoordinates (Vec3D position, Mdouble interactionRadius, Mdouble &distance, Vec3D &normal) const
 
void setShapeSphere ()
 
void setShapeCube ()
 
void setShapeDiamond ()
 
void setShapeCylinder ()
 
void setShapeFourSided ()
 
void createVTKSphere ()
 
void createVTKCube ()
 
void createVTKDiamond ()
 
void createVTK ()
 

Private Attributes

double levelSet_ [2 *N+1][2 *N+1][2 *N+1]
 
double radius_ = 1
 
VTKContainer vtkLabFrame_
 

Static Private Attributes

static const int N = 10
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseWall
static void addToVTK (const std::vector< Vec3D > &points, VTKContainer &vtk)
 Takes the points provided and adds a triangle strip connecting these points to the vtk container. More...
 

Detailed Description

A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.

This is a class defining walls. It defines the interaction of regular walls and periodic walls with particles as defined in Particle Modifications:

Thus, the surface of the wall is a plane through position position_ with normal_ the outward unit normal vector of the wall (pointing away from the particles, into the wall). Please note that this wall is infinite and straight.

A particle touches an infinite wall if (position_-point)*normal_<=radius.

Member Enumeration Documentation

◆ Shape

enum LevelSetWall::Shape
strong
Enumerator
Sphere 
Cube 
Diamond 
FourSided 
Cylinder 
53  {
54  Sphere,
55  Cube,
56  Diamond,
57  FourSided,
58  Cylinder
59  };
Definition: Sphere.h:35

Constructor & Destructor Documentation

◆ LevelSetWall()

LevelSetWall::LevelSetWall ( Shape  s,
double  radius,
ParticleSpecies sp = nullptr 
)
36  : radius_(radius)
37 {
38  setSpecies(sp);
39  if (s == Shape::Sphere)
40  {
43  }
44  else if (s == Shape::Cube)
45  {
46  setShapeCube();
47  createVTKCube();
48  }
49  else if (s == Shape::Diamond)
50  {
52  createVTK();
53  }
54  else if (s == Shape::Cylinder)
55  {
57  createVTK();
58  }
59  else if (s == Shape::FourSided)
60  {
62  createVTK();
63  }
64  else
65  {
66  logger(ERROR, "Shape unknown");
67  }
68 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ ERROR
void setSpecies(const ParticleSpecies *species)
Defines the species of the current wall.
Definition: BaseWall.cc:169
void createVTK()
Definition: LevelSetWall.cc:190
void createVTKCube()
Definition: LevelSetWall.cc:149
double radius_
Definition: LevelSetWall.h:143
void setShapeCube()
Definition: LevelSetWall.cc:396
void setShapeFourSided()
Definition: LevelSetWall.cc:448
void setShapeDiamond()
Definition: LevelSetWall.cc:433
void createVTKSphere()
Definition: LevelSetWall.cc:216
void setShapeSphere()
Definition: LevelSetWall.cc:366
void setShapeCylinder()
Definition: LevelSetWall.cc:381

References createVTK(), createVTKCube(), createVTKSphere(), Cube, Cylinder, Diamond, ERROR, FourSided, logger, setShapeCube(), setShapeCylinder(), setShapeDiamond(), setShapeFourSided(), setShapeSphere(), BaseWall::setSpecies(), and Sphere.

Referenced by copy().

◆ ~LevelSetWall()

LevelSetWall::~LevelSetWall ( )
override

Default destructor.

71 {
72  logger(DEBUG, "LevelSetWall::~LevelSetWall finished");
73 }
@ DEBUG

References DEBUG, and logger.

Member Function Documentation

◆ copy()

LevelSetWall * LevelSetWall::copy ( ) const
overridevirtual

Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism.

Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism

Implements BaseWall.

79 {
80  return new LevelSetWall(*this);
81 }
LevelSetWall(Shape s, double radius, ParticleSpecies *sp=nullptr)
Definition: LevelSetWall.cc:36

References LevelSetWall().

◆ createVTK()

void LevelSetWall::createVTK ( )
private
191 {
192  Mdouble distance;
193  Vec3D normal;
194  InfiniteWall wall;
195 
196  Mdouble interactionRadius = radius_/(2*N);
197  for (int i=-N; i<N; ++i) {
198  for (int j=-N; j<N; ++j) {
199  for (int k=-N; k<N; ++k) {
200  Vec3D min = interactionRadius*Vec3D(2*i,2*j,2*k);
201  Vec3D max = min + interactionRadius*Vec3D(2,2,2);
202  Vec3D position = min + interactionRadius*Vec3D(1,1,1);
203  if (getDistanceAndNormalLabCoordinates(position, 2*interactionRadius, distance, normal)) {
204  wall.set(normal,position+distance*normal);
205  std::vector<Vec3D> points;
206  wall.createVTK(points,min,max);
207  if (!points.empty()) {
208  wall.addToVTK(points, vtkLabFrame_);
209  }
210  }
211  }
212  }
213  }
214 }
double Mdouble
Definition: GeneralDefine.h:34
static void addToVTK(const std::vector< Vec3D > &points, VTKContainer &vtk)
Takes the points provided and adds a triangle strip connecting these points to the vtk container.
Definition: BaseWall.cc:501
A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.
Definition: InfiniteWall.h:48
void createVTK(std::vector< Vec3D > &myPoints) const
Definition: InfiniteWall.cc:224
void set(Vec3D normal, Vec3D point)
Defines a standard wall, given an outward normal vector s.t. normal*x=normal*point for all x of the w...
Definition: InfiniteWall.cc:118
VTKContainer vtkLabFrame_
Definition: LevelSetWall.h:145
bool getDistanceAndNormalLabCoordinates(Vec3D position, Mdouble interactionRadius, Mdouble &distance, Vec3D &normal) const
Definition: LevelSetWall.cc:308
static const int N
Definition: LevelSetWall.h:137
Definition: Vector.h:51
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References BaseWall::addToVTK(), InfiniteWall::createVTK(), getDistanceAndNormalLabCoordinates(), constants::i, N, radius_, InfiniteWall::set(), and vtkLabFrame_.

Referenced by LevelSetWall().

◆ createVTKCube()

void LevelSetWall::createVTKCube ( )
private
150 {
151  Mdouble r = radius_ * (N - 1) / N;
152  vtkLabFrame_.points.resize(8);
153  vtkLabFrame_.points[0] = r * Vec3D(-1, -1, -1);
154  vtkLabFrame_.points[1] = r * Vec3D(-1, -1, 1);
155  vtkLabFrame_.points[2] = r * Vec3D(-1, 1, -1);
156  vtkLabFrame_.points[3] = r * Vec3D(-1, 1, 1);
157  vtkLabFrame_.points[4] = r * Vec3D(1, -1, -1);
158  vtkLabFrame_.points[5] = r * Vec3D(1, -1, 1);
159  vtkLabFrame_.points[6] = r * Vec3D(1, 1, -1);
160  vtkLabFrame_.points[7] = r * Vec3D(1, 1, 1);
161  vtkLabFrame_.triangleStrips.resize(6);
162  vtkLabFrame_.triangleStrips[0] = {0, 1, 2, 3};
163  vtkLabFrame_.triangleStrips[1] = {4, 5, 6, 7};
164  vtkLabFrame_.triangleStrips[2] = {0, 1, 4, 5};
165  vtkLabFrame_.triangleStrips[3] = {2, 3, 6, 7};
166  vtkLabFrame_.triangleStrips[4] = {0, 2, 4, 6};
167  vtkLabFrame_.triangleStrips[5] = {1, 3, 5, 7};
168 }
std::vector< std::vector< double > > triangleStrips
Definition: BaseWall.h:40
std::vector< Vec3D > points
Definition: BaseWall.h:39

References N, VTKContainer::points, radius_, VTKContainer::triangleStrips, and vtkLabFrame_.

Referenced by LevelSetWall().

◆ createVTKDiamond()

void LevelSetWall::createVTKDiamond ( )
private
171 {
172  vtkLabFrame_.points.resize(6);
173  vtkLabFrame_.points[0] = radius_ * Vec3D(-1, 0, 0);
174  vtkLabFrame_.points[1] = radius_ * Vec3D(1, 0, 0);
175  vtkLabFrame_.points[2] = radius_ * Vec3D(0, -1, 0);
176  vtkLabFrame_.points[3] = radius_ * Vec3D(0, 1, 0);
177  vtkLabFrame_.points[4] = radius_ * Vec3D(0, 0, -1);
178  vtkLabFrame_.points[5] = radius_ * Vec3D(0, 0, 1);
179  vtkLabFrame_.triangleStrips.resize(8);
180  vtkLabFrame_.triangleStrips[0] = {0, 3, 4};
181  vtkLabFrame_.triangleStrips[1] = {0, 3, 5};
182  vtkLabFrame_.triangleStrips[2] = {0, 2, 4};
183  vtkLabFrame_.triangleStrips[3] = {0, 2, 5};
184  vtkLabFrame_.triangleStrips[4] = {1, 3, 4};
185  vtkLabFrame_.triangleStrips[5] = {1, 3, 5};
186  vtkLabFrame_.triangleStrips[6] = {1, 2, 4};
187  vtkLabFrame_.triangleStrips[7] = {1, 2, 5};
188 }

References VTKContainer::points, radius_, VTKContainer::triangleStrips, and vtkLabFrame_.

◆ createVTKSphere()

void LevelSetWall::createVTKSphere ( )
private
217 {
218  vtkLabFrame_.points.clear();
220 
221  const unsigned nr = 40;
222  const unsigned nz = 40;
223 
224  std::array<Mdouble, nr> s, c;
225  for (unsigned i = 0; i < nr; ++i)
226  {
227  s[i] = sin(2.0 * constants::pi * i / nr);
228  c[i] = cos(2.0 * constants::pi * i / nr);
229  }
230  std::array<Mdouble, nz> h, r;
231  for (unsigned j = 0; j < nz; ++j)
232  {
233  r[j] = radius_ * sin(2.0 * constants::pi * j / nz);
234  h[j] = radius_ * cos(2.0 * constants::pi * j / nz);
235  }
236 
237  for (unsigned j = 0; j < nz; ++j)
238  {
239  for (unsigned i = 0; i < nr; ++i)
240  {
241  vtkLabFrame_.points.emplace_back(r[j] * s[i], r[j] * c[i], h[j]);
242  }
243  }
244 
245  vtkLabFrame_.triangleStrips.reserve(nz - 1);
246  for (unsigned j = 0; j < nz - 1; ++j)
247  {
248  std::vector<double> cell;
249  cell.reserve(2 * nr + 2);
250  for (unsigned i = 0; i < nr; ++i)
251  {
252  cell.push_back(i + j * nr);
253  cell.push_back(i + (j + 1) * nr);
254  }
255  cell.push_back(j * nr);
256  cell.push_back((j + 1) * nr);
257  vtkLabFrame_.triangleStrips.push_back(cell);
258  }
259 }
const Mdouble pi
Definition: ExtendedMath.h:45
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:64
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:44

References mathsFunc::cos(), constants::i, constants::pi, VTKContainer::points, radius_, mathsFunc::sin(), VTKContainer::triangleStrips, and vtkLabFrame_.

Referenced by LevelSetWall().

◆ getDistanceAndNormal()

bool LevelSetWall::getDistanceAndNormal ( const BaseParticle p,
Mdouble distance,
Vec3D normal_return 
) const
overridevirtual
     \brief Returns the distance of the wall to the particle.
    &zwj;/

Mdouble getDistance(Vec3D position) const;

/*!
   \brief Compute the distance from the wall for a given BaseParticle and return if there is a collision. If there is a collision, also return the normal vector.
 \param[in] otherPosition The position to which the distance must be computed to.
 \return The distance of the wall to the particle.
&zwj;/

Mdouble LevelSetWall::getDistance(Vec3D otherPosition) const { return getOrientation().getDistance(otherPosition,getPosition()); }

/*!

Parameters
[in]pBaseParticle for which the distance to the wall must be computed.
[out]distanceDistance between the particle and the wall.
[out]normal_returnThe normal of this wall, will only be set if there is a collision.
Returns
A boolean value for whether or not there is a collision.

First the distance is checked. If there is no collision, this function will return false and give the distance. If there is a collision, the function will return true and give the distance and the normal vector of this wall. Since this function should be called before calculating any Particle-Wall interactions, it can also be used to set the normal vector in case of curved walls.

Todo:
do this for all walls

Implements BaseWall.

105 {
106  //transform coordinates into position-orientation frame
107  Vec3D position = p.getPosition() - getPosition();
108  getOrientation().rotateBack(position);
110  if (getDistanceAndNormalLabCoordinates(position, p.getWallInteractionRadius(this), distance, normal_return))
111  {
112  getOrientation().rotate(normal_return);
113  return true;
114  }
115  return false;
116  //return getDistanceAndNormal(p.getPosition(), distance, normal_return, p.getRadius(), p.getInteractionRadius());
117 }
const Quaternion & getOrientation() const
Returns the orientation of this BaseInteractable.
Definition: BaseInteractable.h:230
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:218
Mdouble getWallInteractionRadius(const BaseWall *wall) const
returns the radius plus the interactionDistance
Definition: BaseParticle.h:386
void rotate(Vec3D &position) const
Definition: Quaternion.cc:563
void rotateBack(Vec3D &position) const
Definition: Quaternion.cc:610

References getDistanceAndNormalLabCoordinates(), BaseInteractable::getOrientation(), BaseInteractable::getPosition(), BaseParticle::getWallInteractionRadius(), Quaternion::rotate(), and Quaternion::rotateBack().

Referenced by main().

◆ getDistanceAndNormalLabCoordinates()

bool LevelSetWall::getDistanceAndNormalLabCoordinates ( Vec3D  position,
Mdouble  interactionRadius,
Mdouble distance,
Vec3D normal 
) const
private
310 {
311  //scale values [-radius,radius] to [0,2*N]
312  Vec3D positionScaled = position / radius_ * static_cast<double>(N) + Vec3D(1, 1, 1) * static_cast<double>(N);
313  // index of level set value used for interpolation (the discrete level-set value left of the interpolation point)
314  int i = std::max(std::min((int) positionScaled.X, 2 * N - 1), 0);
315  int j = std::max(std::min((int) positionScaled.Y, 2 * N - 1), 0);
316  int k = std::max(std::min((int) positionScaled.Z, 2 * N - 1), 0);
317  // scaled difference between position and discrete level-set value, in [0,1) for interpolation
318  double x = positionScaled.X - i;
319  double y = positionScaled.Y - j;
320  double z = positionScaled.Z - k;
321  // trilinear interpolation
322  distance = levelSet_[i][j][k] * (1 - x) * (1 - y) * (1 - z)
323  + levelSet_[i + 1][j][k] * x * (1 - y) * (1 - z)
324  + levelSet_[i][j + 1][k] * (1 - x) * y * (1 - z)
325  + levelSet_[i + 1][j + 1][k] * x * y * (1 - z)
326  + levelSet_[i][j][k + 1] * (1 - x) * (1 - y) * z
327  + levelSet_[i + 1][j][k + 1] * x * (1 - y) * z
328  + levelSet_[i][j + 1][k + 1] * (1 - x) * y * z
329  + levelSet_[i + 1][j + 1][k + 1] * x * y * z;
330  if (distance < interactionRadius)
331  {
332  normal.X = -levelSet_[i][j][k] * (1 - y) * (1 - z)
333  + levelSet_[i + 1][j][k] * (1 - y) * (1 - z)
334  - levelSet_[i][j + 1][k] * y * (1 - z)
335  + levelSet_[i + 1][j + 1][k] * y * (1 - z)
336  - levelSet_[i][j][k + 1] * (1 - y) * z
337  + levelSet_[i + 1][j][k + 1] * (1 - y) * z
338  - levelSet_[i][j + 1][k + 1] * y * z
339  + levelSet_[i + 1][j + 1][k + 1] * y * z;
340  normal.Y = -levelSet_[i][j][k] * (1 - x) * (1 - z)
341  - levelSet_[i + 1][j][k] * x * (1 - z)
342  + levelSet_[i][j + 1][k] * (1 - x) * (1 - z)
343  + levelSet_[i + 1][j + 1][k] * x * (1 - z)
344  - levelSet_[i][j][k + 1] * (1 - x) * z
345  - levelSet_[i + 1][j][k + 1] * x * z
346  + levelSet_[i][j + 1][k + 1] * (1 - x) * z
347  + levelSet_[i + 1][j + 1][k + 1] * x * z;
348  normal.Z = -levelSet_[i][j][k] * (1 - x) * (1 - y)
349  - levelSet_[i + 1][j][k] * x * (1 - y)
350  - levelSet_[i][j + 1][k] * (1 - x) * y
351  - levelSet_[i + 1][j + 1][k] * x * y
352  + levelSet_[i][j][k + 1] * (1 - x) * (1 - y)
353  + levelSet_[i + 1][j][k + 1] * x * (1 - y)
354  + levelSet_[i][j + 1][k + 1] * (1 - x) * y
355  + levelSet_[i + 1][j + 1][k + 1] * x * y;
356  Mdouble length = normal.getLength();
357  if (length != 0)
358  normal /= -length;
359  else
360  normal = {1,0,0};
361  return true;
362  }
363  return false;
364 }
double levelSet_[2 *N+1][2 *N+1][2 *N+1]
Definition: LevelSetWall.h:140
Mdouble Y
Definition: Vector.h:66
Mdouble Z
Definition: Vector.h:66
Mdouble X
the vector components
Definition: Vector.h:66
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:331

References Vec3D::getLength(), constants::i, levelSet_, N, radius_, Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by createVTK(), getDistanceAndNormal(), and writeToFile().

◆ getName()

std::string LevelSetWall::getName ( ) const
overridevirtual

Returns the name of the object, in this case the string "LevelSetWall".

Returns
The string "LevelSetWall", which is the name of this class.

Implements BaseObject.

134 {
135  return "LevelSetWall";
136 }

◆ read()

void LevelSetWall::read ( std::istream &  is)
overridevirtual

Reads LevelSetWall from a restart file.

Parameters
[in]isThe input stream from which the LevelSetWall is read. Only needed for backward compatibility.
Todo:

Reimplemented from BaseWall.

123 {
124  BaseWall::read(is);
125  std::string dummy;
126  is >> dummy;
128 }
void read(std::istream &is) override
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:78

References BaseWall::read().

◆ setShapeCube()

void LevelSetWall::setShapeCube ( )
private
397 {
398  logger(INFO, "Creating a cube");
399  radius_ *= N / (N - 1);
400  Mdouble h = radius_ / N;
401  for (int k = -N; k <= N; ++k)
402  {
403  for (int j = -N; j <= N; ++j)
404  {
405  for (int i = -N; i <= N; ++i)
406  {
407  std::array<int, 3> sort;
408  sort[0] = abs(i);
409  sort[1] = abs(j);
410  sort[2] = abs(k);
411  std::sort(sort.begin(), sort.end());
412  if (sort[1] < N)
413  {
414  // face
415  levelSet_[i + N][j + N][k + N] = h * (sort[2] - (N - 1));
416  }
417  else if (sort[0] < N)
418  {
419  // edge
420  levelSet_[i + N][j + N][k + N] = h * 2;
421  }
422  else
423  {
424  //vertex
425  levelSet_[i + N][j + N][k + N] = h * 3;
426  }
427  //edge and vertex distances longer than real, otherwise trilinear extrapolation is problematic.
428  }
429  }
430  }
431 }
@ INFO

References constants::i, INFO, levelSet_, logger, N, and radius_.

Referenced by LevelSetWall().

◆ setShapeCylinder()

void LevelSetWall::setShapeCylinder ( )
private
382 {
383  logger(INFO, "Creating a cylinder");
384  for (int k = -N; k <= N; ++k)
385  {
386  for (int j = -N; j <= N; ++j)
387  {
388  for (int i = -N; i <= N; ++i)
389  {
390  levelSet_[i + N][j + N][k + N] = radius_*std::fmax(sqrt(i * i + j * j) / N - 1,fabs(k)/N-1);
391  }
392  }
393  }
394 }

References constants::i, INFO, levelSet_, logger, N, and radius_.

Referenced by LevelSetWall().

◆ setShapeDiamond()

void LevelSetWall::setShapeDiamond ( )
private
434 {
435  logger(INFO, "Creating a diamond square");
436  for (int k = -N; k <= N; ++k)
437  {
438  for (int j = -N; j <= N; ++j)
439  {
440  for (int i = -N; i <= N; ++i)
441  {
442  levelSet_[i + N][j + N][k + N] = radius_ / sqrt(3) / N * ((double) (abs(i) + abs(j) + abs(k)) - N);
443  }
444  }
445  }
446 }

References constants::i, INFO, levelSet_, logger, N, and radius_.

Referenced by LevelSetWall().

◆ setShapeFourSided()

void LevelSetWall::setShapeFourSided ( )
private
449 {
450  //open filestream
451  std::string fileName = "fourSided.txt";
452  std::ifstream is(fileName.c_str(), std::ios::in);
453  if (is.fail())
454  {
455  helpers::writeToFile("fourSided.m",
456  "%% parameters\n"
457  "n=10; % 2n+1 is the number of cells in the level set per dimension\n"
458  "w=1; % [-w,w] is the width of the shape in z-direction\n"
459  "% define a few points on the xy-cross section of the shape that will be interpolated\n"
460  "% we define a quarter of the cross section only; thus the first point has differ \n"
461  "% from the last point by a quarter rotation around the origin\n"
462  "x0=[1 1.8 1.8 1.4 1];\n"
463  "y0=[-1 0 1 1.4 1];\n"
464  "\n"
465  "%% create curve, and plot\n"
466  "% define a parameter t0, such that the parametrisation is x0(t0), y0(t0)\n"
467  "t0=1:length(x0);\n"
468  "% define a more fine-grained parameter t1, and interpolate, obtaining a \n"
469  "% finer parametrisation x1(t1), y1(t1)\n"
470  "t1= linspace(1,length(x0));\n"
471  "x1=interpn(t0,x0,t1,'spline');\n"
472  "y1=interpn(t0,y0,t1,'spline');\n"
473  "% complete the shape by repeating it four times, each rotated by 90 deg\n"
474  "% the points (x,y) are on the shape \n"
475  "x=[x1 -y1 -x1 y1];\n"
476  "y=[y1 x1 -y1 -x1];\n"
477  "% plot the resulting shape\n"
478  "figure(1)\n"
479  "plot(x,y,'-',x0,y0,'o')\n"
480  "axis equal\n"
481  "\n"
482  "%% create level set, and plot\n"
483  "% compute the size of the domain needed to contain the shape ...\n"
484  "radius = max([max(abs(x)),max(abs(y)),abs(w)]);\n"
485  "% .. then divide by the number of cells to get the cell size\n"
486  "radius = n/floor(n/radius);\n"
487  "% create xLS,yLS,zLS values of the level set function dist(xLS,yLS,zLS)\n"
488  "LS = linspace(-radius,radius,2*n+1);\n"
489  "[xLS,yLS,zLS]=meshgrid(LS);\n"
490  "% define the level set function by computing the distance of (xLS,yLS,zLS)\n"
491  "% to the nearest point on the shape (x,y,+-w)\n"
492  "dist = zeros(size(xLS));\n"
493  "for i=1:length(xLS(:))\n"
494  " dist(i) = sqrt(min((x-xLS(i)).^2+(y-yLS(i)).^2));\n"
495  " % make it a signed distance\n"
496  " if inpolygon(xLS(i),yLS(i),x,y)\n"
497  " dist(i) = -dist(i);\n"
498  " end\n"
499  " % compute the signed distance as the max of signed distances in xy and z\n"
500  " dist(i) = max(dist(i),abs(zLS(i))-w);\n"
501  "end\n"
502  "% rescale the distance\n"
503  "dist = dist/radius;\n"
504  "\n"
505  "% plot the i-th cross-section in xy (i=n+1 is in the center)\n"
506  "figure(2)\n"
507  "i=n+4\n"
508  "mesh(xLS(:,:,i),yLS(:,:,i),dist(:,:,i),'FaceColor','none')\n"
509  "hold on\n"
510  "contourf(xLS(:,:,i),yLS(:,:,i),dist(:,:,i),[0 0])\n"
511  "plot(x0,y0,'ro')\n"
512  "hold off\n"
513  "view(0,90)\n"
514  "axis equal\n"
515  "title(['z=' num2str(unique(zLS(:,:,i)))])\n"
516  "xlabel('x'), ylabel('y'), zlabel('dist')\n"
517  "\n"
518  "% plot the i-th cross-section in yz (i=n+1 is in the center)\n"
519  "figure(3)\n"
520  "mesh(squeeze(yLS(:,i,:)),squeeze(zLS(:,i,:)),squeeze(dist(:,i,:)),'FaceColor','none')\n"
521  "hold on\n"
522  "contourf(squeeze(yLS(:,i,:)),squeeze(zLS(:,i,:)),squeeze(dist(:,i,:)),[0 0])\n"
523  "hold off\n"
524  "view(90,0)\n"
525  "axis equal\n"
526  "title(['x=' num2str(unique(xLS(:,i,:)))])\n"
527  "xlabel('y'), ylabel('z'), zlabel('dist')\n"
528  "\n"
529  "% plot the i-th cross-section in xz (i=n+1 is in the center)\n"
530  "figure(4)\n"
531  "mesh(squeeze(xLS(i,:,:)),squeeze(zLS(i,:,:)),squeeze(dist(i,:,:)),'FaceColor','none')\n"
532  "hold on\n"
533  "contourf(squeeze(xLS(i,:,:)),squeeze(zLS(i,:,:)),squeeze(dist(i,:,:)),[0 0])\n"
534  "hold off\n"
535  "view(90,0)\n"
536  "axis equal\n"
537  "title(['y=' num2str(unique(yLS(i,:,:)))])\n"
538  "xlabel('x'), ylabel('z'), zlabel('dist')\n"
539  "\n"
540  "%% write n and dist values to file (read into MercuryDPM)\n"
541  "fid = fopen('fourSided.txt','w');\n"
542  "fprintf(fid,'%d\\n',n);\n"
543  "fprintf(fid,'%f ',dist);\n"
544  "fclose(fid);");
545  logger(ERROR, "readFromFile: file % could not be opened; make sure you run fourSided.m first.", fileName);
546  }
547 
548  int n;
549  is >> n;
550  if (n != N)
551  {
552  logger(ERROR, "readFromFile: level set size does not match %", n);
553  }
554 
555  Mdouble unitDistance;
556  for (int k = -N; k <= N; ++k)
557  {
558  for (int j = -N; j <= N; ++j)
559  {
560  for (int i = -N; i <= N; ++i)
561  {
562  is >> unitDistance;
563  levelSet_[i + N][j + N][k + N] = radius_ * unitDistance;
564  }
565  }
566  }
567 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Definition: FileIOHelpers.cc:58

References ERROR, constants::i, levelSet_, logger, n, N, radius_, and helpers::writeToFile().

Referenced by LevelSetWall().

◆ setShapeSphere()

void LevelSetWall::setShapeSphere ( )
private
367 {
368  logger(INFO, "Creating a sphere");
369  for (int k = -N; k <= N; ++k)
370  {
371  for (int j = -N; j <= N; ++j)
372  {
373  for (int i = -N; i <= N; ++i)
374  {
375  levelSet_[i + N][j + N][k + N] = radius_ * sqrt(i * i + j * j + k * k) / N - radius_;
376  }
377  }
378  }
379 }

References constants::i, INFO, levelSet_, logger, N, and radius_.

Referenced by LevelSetWall().

◆ writeToFile()

void LevelSetWall::writeToFile ( int  n,
double  radiusContact 
) const
Parameters
nhow many points should be used to interpolate
radiusContacthow much should be added to the radius
262 {
263  std::stringstream s;
264  s << "Values of level set function\n";
265  Vec3D normal;
266  Mdouble distance;
267  double meshSize = (radius_ + extraRadius) / n;
268  for (int k = -n; k <= n; ++k)
269  {
270  for (int j = -n; j <= n; ++j)
271  {
272  for (int i = -n; i <= n; ++i)
273  {
274  Vec3D position = meshSize * Vec3D(i, j, k);
275  getDistanceAndNormalLabCoordinates(position, radius_ + extraRadius, distance, normal);
276  s << position << ' '
277  << distance << ' '
278  << normal << '\n';
279  }
280  }
281  }
282  helpers::writeToFile("LevelSet.txt", s.str());
283  helpers::writeToFile("LevelSet.m", "close all\n"
284  "data=importdata('LevelSet.txt');\n"
285  "N = nthroot(size(data.data,1),3);\n"
286  "x = reshape(data.data(:,1),N,N,N);\n"
287  "y = reshape(data.data(:,2),N,N,N);\n"
288  "z = reshape(data.data(:,3),N,N,N);\n"
289  "d = reshape(data.data(:,4),N,N,N);\n"
290  "nx= reshape(data.data(:,5),N,N,N);\n"
291  "ny= reshape(data.data(:,6),N,N,N);\n"
292  "nz= reshape(data.data(:,7),N,N,N);\n"
293  "mid = (N-1)/2;\n"
294  "surf(x(:,:,mid),y(:,:,mid),d(:,:,mid),'FaceColor','none')\n"
295  "hold on\n"
296  "quiver(x(:,:,mid),y(:,:,mid),nx(:,:,mid),ny(:,:,mid))\n"
297  "legend('distance','normal');\n"
298  "if (min(min(d(:,:,mid)))<0 && max(max(d(:,:,mid)))>0)\n"
299  " contourf(x(:,:,mid),y(:,:,mid),d(:,:,mid),[0 0])\n"
300  " legend('distance','normal','distance>=0'); set(legend,'Location','best');\n"
301  "end\n"
302  "hold off\n"
303  "xlabel('x'); ylabel('y'); title('cross-section at z=0');\n"
304  "view(0,0); axis equal;");
305  logger(INFO, "Run LevelSet.m to view level set");
306 }

References getDistanceAndNormalLabCoordinates(), constants::i, INFO, logger, n, radius_, and helpers::writeToFile().

Referenced by main().

◆ writeVTK()

void LevelSetWall::writeVTK ( VTKContainer vtk) const
overridevirtual

Adds the vtk wall representation to the VTK container

Reimplemented from BaseWall.

139 {
141  vtk.points = vtkLabFrame_.points;
142  for (Vec3D& p : vtk.points)
143  {
144  getOrientation().rotate(p);
145  p += getPosition();
146  }
147 }

References BaseInteractable::getOrientation(), BaseInteractable::getPosition(), VTKContainer::points, Quaternion::rotate(), VTKContainer::triangleStrips, and vtkLabFrame_.

Member Data Documentation

◆ levelSet_

◆ N

◆ radius_

◆ vtkLabFrame_

VTKContainer LevelSetWall::vtkLabFrame_
private

The documentation for this class was generated from the following files: