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 
32  {
33  Sphere,
34  Cube,
35  Diamond,
36  FourSided,
37  Cylinder
38  };
Definition: Sphere.h:15

Constructor & Destructor Documentation

◆ LevelSetWall()

LevelSetWall::LevelSetWall ( Shape  s,
double  radius,
ParticleSpecies sp = nullptr 
)
15  : radius_(radius)
16 {
17  setSpecies(sp);
18  if (s == Shape::Sphere)
19  {
22  }
23  else if (s == Shape::Cube)
24  {
25  setShapeCube();
26  createVTKCube();
27  }
28  else if (s == Shape::Diamond)
29  {
31  createVTK();
32  }
33  else if (s == Shape::Cylinder)
34  {
36  createVTK();
37  }
38  else if (s == Shape::FourSided)
39  {
41  createVTK();
42  }
43  else
44  {
45  logger(ERROR, "Shape unknown");
46  }
47 }
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:148
void createVTK()
Definition: LevelSetWall.cc:169
void createVTKCube()
Definition: LevelSetWall.cc:128
double radius_
Definition: LevelSetWall.h:122
void setShapeCube()
Definition: LevelSetWall.cc:375
void setShapeFourSided()
Definition: LevelSetWall.cc:427
void setShapeDiamond()
Definition: LevelSetWall.cc:412
void createVTKSphere()
Definition: LevelSetWall.cc:195
void setShapeSphere()
Definition: LevelSetWall.cc:345
void setShapeCylinder()
Definition: LevelSetWall.cc:360
RealScalar s
Definition: level1_cplx_impl.h:130
radius
Definition: UniformPSDSelfTest.py:15

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

Referenced by copy().

◆ ~LevelSetWall()

LevelSetWall::~LevelSetWall ( )
override

Default destructor.

50 {
51  logger(DEBUG, "LevelSetWall::~LevelSetWall finished");
52 }
@ 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.

58 {
59  return new LevelSetWall(*this);
60 }
LevelSetWall(Shape s, double radius, ParticleSpecies *sp=nullptr)
Definition: LevelSetWall.cc:15

References LevelSetWall().

◆ createVTK()

void LevelSetWall::createVTK ( )
private
170 {
171  Mdouble distance;
172  Vec3D normal;
173  InfiniteWall wall;
174 
175  Mdouble interactionRadius = radius_/(2*N);
176  for (int i=-N; i<N; ++i) {
177  for (int j=-N; j<N; ++j) {
178  for (int k=-N; k<N; ++k) {
179  Vec3D min = interactionRadius*Vec3D(2*i,2*j,2*k);
180  Vec3D max = min + interactionRadius*Vec3D(2,2,2);
181  Vec3D position = min + interactionRadius*Vec3D(1,1,1);
182  if (getDistanceAndNormalLabCoordinates(position, 2*interactionRadius, distance, normal)) {
183  wall.set(normal,position+distance*normal);
184  std::vector<Vec3D> points;
185  wall.createVTK(points,min,max);
186  if (!points.empty()) {
187  wall.addToVTK(points, vtkLabFrame_);
188  }
189  }
190  }
191  }
192  }
193 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
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:453
A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.
Definition: InfiniteWall.h:27
void createVTK(std::vector< Vec3D > &myPoints) const
Definition: InfiniteWall.cc:203
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:97
VTKContainer vtkLabFrame_
Definition: LevelSetWall.h:124
bool getDistanceAndNormalLabCoordinates(Vec3D position, Mdouble interactionRadius, Mdouble &distance, Vec3D &normal) const
Definition: LevelSetWall.cc:287
static const int N
Definition: LevelSetWall.h:116
Definition: Kernel/Math/Vector.h:30
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
char char char int int * k
Definition: level2_impl.h:374
void normal(const Vector< double > &x, Vector< double > &normal)
Definition: free_surface_rotation.cc:65
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References BaseWall::addToVTK(), InfiniteWall::createVTK(), getDistanceAndNormalLabCoordinates(), i, j, k, max, min, N, WallFunction::normal(), radius_, InfiniteWall::set(), and vtkLabFrame_.

Referenced by LevelSetWall().

◆ createVTKCube()

void LevelSetWall::createVTKCube ( )
private
129 {
130  Mdouble r = radius_ * (N - 1) / N;
131  vtkLabFrame_.points.resize(8);
132  vtkLabFrame_.points[0] = r * Vec3D(-1, -1, -1);
133  vtkLabFrame_.points[1] = r * Vec3D(-1, -1, 1);
134  vtkLabFrame_.points[2] = r * Vec3D(-1, 1, -1);
135  vtkLabFrame_.points[3] = r * Vec3D(-1, 1, 1);
136  vtkLabFrame_.points[4] = r * Vec3D(1, -1, -1);
137  vtkLabFrame_.points[5] = r * Vec3D(1, -1, 1);
138  vtkLabFrame_.points[6] = r * Vec3D(1, 1, -1);
139  vtkLabFrame_.points[7] = r * Vec3D(1, 1, 1);
140  vtkLabFrame_.triangleStrips.resize(6);
141  vtkLabFrame_.triangleStrips[0] = {0, 1, 2, 3};
142  vtkLabFrame_.triangleStrips[1] = {4, 5, 6, 7};
143  vtkLabFrame_.triangleStrips[2] = {0, 1, 4, 5};
144  vtkLabFrame_.triangleStrips[3] = {2, 3, 6, 7};
145  vtkLabFrame_.triangleStrips[4] = {0, 2, 4, 6};
146  vtkLabFrame_.triangleStrips[5] = {1, 3, 5, 7};
147 }
r
Definition: UniformPSDSelfTest.py:20
std::vector< std::vector< double > > triangleStrips
Definition: BaseWall.h:19
std::vector< Vec3D > points
Definition: BaseWall.h:18

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

Referenced by LevelSetWall().

◆ createVTKDiamond()

void LevelSetWall::createVTKDiamond ( )
private
150 {
151  vtkLabFrame_.points.resize(6);
152  vtkLabFrame_.points[0] = radius_ * Vec3D(-1, 0, 0);
153  vtkLabFrame_.points[1] = radius_ * Vec3D(1, 0, 0);
154  vtkLabFrame_.points[2] = radius_ * Vec3D(0, -1, 0);
155  vtkLabFrame_.points[3] = radius_ * Vec3D(0, 1, 0);
156  vtkLabFrame_.points[4] = radius_ * Vec3D(0, 0, -1);
157  vtkLabFrame_.points[5] = radius_ * Vec3D(0, 0, 1);
158  vtkLabFrame_.triangleStrips.resize(8);
159  vtkLabFrame_.triangleStrips[0] = {0, 3, 4};
160  vtkLabFrame_.triangleStrips[1] = {0, 3, 5};
161  vtkLabFrame_.triangleStrips[2] = {0, 2, 4};
162  vtkLabFrame_.triangleStrips[3] = {0, 2, 5};
163  vtkLabFrame_.triangleStrips[4] = {1, 3, 4};
164  vtkLabFrame_.triangleStrips[5] = {1, 3, 5};
165  vtkLabFrame_.triangleStrips[6] = {1, 2, 4};
166  vtkLabFrame_.triangleStrips[7] = {1, 2, 5};
167 }

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

◆ createVTKSphere()

void LevelSetWall::createVTKSphere ( )
private
196 {
197  vtkLabFrame_.points.clear();
199 
200  const unsigned nr = 40;
201  const unsigned nz = 40;
202 
203  std::array<Mdouble, nr> s, c;
204  for (unsigned i = 0; i < nr; ++i)
205  {
206  s[i] = sin(2.0 * constants::pi * i / nr);
207  c[i] = cos(2.0 * constants::pi * i / nr);
208  }
209  std::array<Mdouble, nz> h, r;
210  for (unsigned j = 0; j < nz; ++j)
211  {
212  r[j] = radius_ * sin(2.0 * constants::pi * j / nz);
213  h[j] = radius_ * cos(2.0 * constants::pi * j / nz);
214  }
215 
216  for (unsigned j = 0; j < nz; ++j)
217  {
218  for (unsigned i = 0; i < nr; ++i)
219  {
220  vtkLabFrame_.points.emplace_back(r[j] * s[i], r[j] * c[i], h[j]);
221  }
222  }
223 
224  vtkLabFrame_.triangleStrips.reserve(nz - 1);
225  for (unsigned j = 0; j < nz - 1; ++j)
226  {
227  std::vector<double> cell;
228  cell.reserve(2 * nr + 2);
229  for (unsigned i = 0; i < nr; ++i)
230  {
231  cell.push_back(i + j * nr);
232  cell.push_back(i + (j + 1) * nr);
233  }
234  cell.push_back(j * nr);
235  cell.push_back((j + 1) * nr);
236  vtkLabFrame_.triangleStrips.push_back(cell);
237  }
238 }
AnnoyingScalar cos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:136
AnnoyingScalar sin(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:137
const unsigned nz
Definition: ConstraintElementsUnitTest.cpp:32
int c
Definition: calibrate.py:100
const Mdouble pi
Definition: ExtendedMath.h:23

References calibrate::c, cos(), i, j, Mesh_Parameters::nz, constants::pi, VTKContainer::points, UniformPSDSelfTest::r, radius_, s, 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.

84 {
85  //transform coordinates into position-orientation frame
86  Vec3D position = p.getPosition() - getPosition();
87  getOrientation().rotateBack(position);
89  if (getDistanceAndNormalLabCoordinates(position, p.getWallInteractionRadius(this), distance, normal_return))
90  {
91  getOrientation().rotate(normal_return);
92  return true;
93  }
94  return false;
95  //return getDistanceAndNormal(p.getPosition(), distance, normal_return, p.getRadius(), p.getInteractionRadius());
96 }
float * p
Definition: Tutorial_Map_using.cpp:9
const Quaternion & getOrientation() const
Returns the orientation of this BaseInteractable.
Definition: BaseInteractable.h:209
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:197
void rotate(Vec3D &position) const
Definition: Quaternion.cc:550
void rotateBack(Vec3D &position) const
Definition: Quaternion.cc:597

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

◆ getDistanceAndNormalLabCoordinates()

bool LevelSetWall::getDistanceAndNormalLabCoordinates ( Vec3D  position,
Mdouble  interactionRadius,
Mdouble distance,
Vec3D normal 
) const
private
289 {
290  //scale values [-radius,radius] to [0,2*N]
291  Vec3D positionScaled = position / radius_ * static_cast<double>(N) + Vec3D(1, 1, 1) * static_cast<double>(N);
292  // index of level set value used for interpolation (the discrete level-set value left of the interpolation point)
293  int i = std::max(std::min((int) positionScaled.X, 2 * N - 1), 0);
294  int j = std::max(std::min((int) positionScaled.Y, 2 * N - 1), 0);
295  int k = std::max(std::min((int) positionScaled.Z, 2 * N - 1), 0);
296  // scaled difference between position and discrete level-set value, in [0,1) for interpolation
297  double x = positionScaled.X - i;
298  double y = positionScaled.Y - j;
299  double z = positionScaled.Z - k;
300  // trilinear interpolation
301  distance = levelSet_[i][j][k] * (1 - x) * (1 - y) * (1 - z)
302  + levelSet_[i + 1][j][k] * x * (1 - y) * (1 - z)
303  + levelSet_[i][j + 1][k] * (1 - x) * y * (1 - z)
304  + levelSet_[i + 1][j + 1][k] * x * y * (1 - z)
305  + levelSet_[i][j][k + 1] * (1 - x) * (1 - y) * z
306  + levelSet_[i + 1][j][k + 1] * x * (1 - y) * z
307  + levelSet_[i][j + 1][k + 1] * (1 - x) * y * z
308  + levelSet_[i + 1][j + 1][k + 1] * x * y * z;
309  if (distance < interactionRadius)
310  {
311  normal.X = -levelSet_[i][j][k] * (1 - y) * (1 - z)
312  + levelSet_[i + 1][j][k] * (1 - y) * (1 - z)
313  - levelSet_[i][j + 1][k] * y * (1 - z)
314  + levelSet_[i + 1][j + 1][k] * y * (1 - z)
315  - levelSet_[i][j][k + 1] * (1 - y) * z
316  + levelSet_[i + 1][j][k + 1] * (1 - y) * z
317  - levelSet_[i][j + 1][k + 1] * y * z
318  + levelSet_[i + 1][j + 1][k + 1] * y * z;
319  normal.Y = -levelSet_[i][j][k] * (1 - x) * (1 - z)
320  - levelSet_[i + 1][j][k] * x * (1 - z)
321  + levelSet_[i][j + 1][k] * (1 - x) * (1 - z)
322  + levelSet_[i + 1][j + 1][k] * x * (1 - z)
323  - levelSet_[i][j][k + 1] * (1 - x) * z
324  - levelSet_[i + 1][j][k + 1] * x * z
325  + levelSet_[i][j + 1][k + 1] * (1 - x) * z
326  + levelSet_[i + 1][j + 1][k + 1] * x * z;
327  normal.Z = -levelSet_[i][j][k] * (1 - x) * (1 - y)
328  - levelSet_[i + 1][j][k] * x * (1 - y)
329  - levelSet_[i][j + 1][k] * (1 - x) * y
330  - levelSet_[i + 1][j + 1][k] * x * y
331  + levelSet_[i][j][k + 1] * (1 - x) * (1 - y)
332  + levelSet_[i + 1][j][k + 1] * x * (1 - y)
333  + levelSet_[i][j + 1][k + 1] * (1 - x) * y
334  + levelSet_[i + 1][j + 1][k + 1] * x * y;
335  Mdouble length = normal.getLength();
336  if (length != 0)
337  normal /= -length;
338  else
339  normal = {1,0,0};
340  return true;
341  }
342  return false;
343 }
double levelSet_[2 *N+1][2 *N+1][2 *N+1]
Definition: LevelSetWall.h:119
Mdouble Y
Definition: Kernel/Math/Vector.h:45
Mdouble Z
Definition: Kernel/Math/Vector.h:45
Mdouble X
the vector components
Definition: Kernel/Math/Vector.h:45
Scalar * y
Definition: level1_cplx_impl.h:128
list x
Definition: plotDoE.py:28

References i, j, k, levelSet_, max, min, N, WallFunction::normal(), radius_, plotDoE::x, Vec3D::X, y, 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.

113 {
114  return "LevelSetWall";
115 }

◆ 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.

102 {
103  BaseWall::read(is);
104  std::string dummy;
105  is >> dummy;
107 }
void read(std::istream &is) override
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:57
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References BaseWall::read(), and oomph::Global_string_for_annotation::string().

◆ setShapeCube()

void LevelSetWall::setShapeCube ( )
private
376 {
377  logger(INFO, "Creating a cube");
378  radius_ *= N / (N - 1);
379  Mdouble h = radius_ / N;
380  for (int k = -N; k <= N; ++k)
381  {
382  for (int j = -N; j <= N; ++j)
383  {
384  for (int i = -N; i <= N; ++i)
385  {
386  std::array<int, 3> sort;
387  sort[0] = abs(i);
388  sort[1] = abs(j);
389  sort[2] = abs(k);
390  std::sort(sort.begin(), sort.end());
391  if (sort[1] < N)
392  {
393  // face
394  levelSet_[i + N][j + N][k + N] = h * (sort[2] - (N - 1));
395  }
396  else if (sort[0] < N)
397  {
398  // edge
399  levelSet_[i + N][j + N][k + N] = h * 2;
400  }
401  else
402  {
403  //vertex
404  levelSet_[i + N][j + N][k + N] = h * 3;
405  }
406  //edge and vertex distances longer than real, otherwise trilinear extrapolation is problematic.
407  }
408  }
409  }
410 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
@ INFO

References abs(), i, INFO, j, k, levelSet_, logger, N, and radius_.

Referenced by LevelSetWall().

◆ setShapeCylinder()

void LevelSetWall::setShapeCylinder ( )
private
361 {
362  logger(INFO, "Creating a cylinder");
363  for (int k = -N; k <= N; ++k)
364  {
365  for (int j = -N; j <= N; ++j)
366  {
367  for (int i = -N; i <= N; ++i)
368  {
369  levelSet_[i + N][j + N][k + N] = radius_*std::fmax(sqrt(i * i + j * j) / N - 1,fabs(k)/N-1);
370  }
371  }
372  }
373 }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmax(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:670
Real fabs(const Real &a)
Definition: boostmultiprec.cpp:117

References boost::multiprecision::fabs(), Eigen::bfloat16_impl::fmax(), i, INFO, j, k, levelSet_, logger, N, radius_, and sqrt().

Referenced by LevelSetWall().

◆ setShapeDiamond()

void LevelSetWall::setShapeDiamond ( )
private
413 {
414  logger(INFO, "Creating a diamond square");
415  for (int k = -N; k <= N; ++k)
416  {
417  for (int j = -N; j <= N; ++j)
418  {
419  for (int i = -N; i <= N; ++i)
420  {
421  levelSet_[i + N][j + N][k + N] = radius_ / sqrt(3) / N * ((double) (abs(i) + abs(j) + abs(k)) - N);
422  }
423  }
424  }
425 }

References abs(), i, INFO, j, k, levelSet_, logger, N, radius_, and sqrt().

Referenced by LevelSetWall().

◆ setShapeFourSided()

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

References ERROR, UniformPSDSelfTest::fileName, i, j, k, levelSet_, logger, n, N, radius_, oomph::Global_string_for_annotation::string(), and helpers::writeToFile().

Referenced by LevelSetWall().

◆ setShapeSphere()

void LevelSetWall::setShapeSphere ( )
private
346 {
347  logger(INFO, "Creating a sphere");
348  for (int k = -N; k <= N; ++k)
349  {
350  for (int j = -N; j <= N; ++j)
351  {
352  for (int i = -N; i <= N; ++i)
353  {
354  levelSet_[i + N][j + N][k + N] = radius_ * sqrt(i * i + j * j + k * k) / N - radius_;
355  }
356  }
357  }
358 }

References i, INFO, j, k, levelSet_, logger, N, radius_, and sqrt().

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
241 {
242  std::stringstream s;
243  s << "Values of level set function\n";
244  Vec3D normal;
245  Mdouble distance;
246  double meshSize = (radius_ + extraRadius) / n;
247  for (int k = -n; k <= n; ++k)
248  {
249  for (int j = -n; j <= n; ++j)
250  {
251  for (int i = -n; i <= n; ++i)
252  {
253  Vec3D position = meshSize * Vec3D(i, j, k);
254  getDistanceAndNormalLabCoordinates(position, radius_ + extraRadius, distance, normal);
255  s << position << ' '
256  << distance << ' '
257  << normal << '\n';
258  }
259  }
260  }
261  helpers::writeToFile("LevelSet.txt", s.str());
262  helpers::writeToFile("LevelSet.m", "close all\n"
263  "data=importdata('LevelSet.txt');\n"
264  "N = nthroot(size(data.data,1),3);\n"
265  "x = reshape(data.data(:,1),N,N,N);\n"
266  "y = reshape(data.data(:,2),N,N,N);\n"
267  "z = reshape(data.data(:,3),N,N,N);\n"
268  "d = reshape(data.data(:,4),N,N,N);\n"
269  "nx= reshape(data.data(:,5),N,N,N);\n"
270  "ny= reshape(data.data(:,6),N,N,N);\n"
271  "nz= reshape(data.data(:,7),N,N,N);\n"
272  "mid = (N-1)/2;\n"
273  "surf(x(:,:,mid),y(:,:,mid),d(:,:,mid),'FaceColor','none')\n"
274  "hold on\n"
275  "quiver(x(:,:,mid),y(:,:,mid),nx(:,:,mid),ny(:,:,mid))\n"
276  "legend('distance','normal');\n"
277  "if (min(min(d(:,:,mid)))<0 && max(max(d(:,:,mid)))>0)\n"
278  " contourf(x(:,:,mid),y(:,:,mid),d(:,:,mid),[0 0])\n"
279  " legend('distance','normal','distance>=0'); set(legend,'Location','best');\n"
280  "end\n"
281  "hold off\n"
282  "xlabel('x'); ylabel('y'); title('cross-section at z=0');\n"
283  "view(0,0); axis equal;");
284  logger(INFO, "Run LevelSet.m to view level set");
285 }

References getDistanceAndNormalLabCoordinates(), i, INFO, j, k, logger, n, WallFunction::normal(), radius_, s, and helpers::writeToFile().

◆ writeVTK()

void LevelSetWall::writeVTK ( VTKContainer vtk) const
overridevirtual

Adds the vtk wall representation to the VTK container

Reimplemented from BaseWall.

118 {
120  vtk.points = vtkLabFrame_.points;
121  for (Vec3D& p : vtk.points)
122  {
124  p += getPosition();
125  }
126 }

References BaseInteractable::getOrientation(), BaseInteractable::getPosition(), p, 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: