BaseWall.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, 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 
26 #ifndef BASEWALL_H
27 #define BASEWALL_H
28 
29 #include "BaseInteractable.h"
31 #include "VTKWriter/VTKData.h"
32 
33 class WallHandler;
34 
35 class BaseParticle;
36 
38 {
39  std::vector<Vec3D> points;
40  std::vector<std::vector<double>> triangleStrips;
41 };
42 
48 class BaseWall : public BaseInteractable
49 {
50 public:
54  BaseWall();
55 
59  BaseWall(const BaseWall& w);
60 
64  ~BaseWall() override;
65 
70  virtual BaseWall* copy() const = 0;
71 
75  void read(std::istream& is) override;
76 
80  void write(std::ostream& os) const override;
81 
90  virtual bool getDistanceAndNormal(const BaseParticle& P, Mdouble& distance, Vec3D& normal_return) const = 0;
91 
92 
93  virtual bool
94  getDistanceNormalOverlap(const BaseParticle& P, Mdouble& distance, Vec3D& normal_return, Mdouble& overlap) const;
95 
96  virtual bool getDistanceNormalOverlapSuperquadric(const SuperQuadricParticle& p, Mdouble& distance, Vec3D& normal_return,
97  Mdouble& overlap) const;
98 
99  virtual Vec3D
100  getFurthestPointSuperQuadric(const Vec3D& normalBodyFixed, const Vec3D& axes, Mdouble eps1, Mdouble eps2) const;
101 
105  virtual void setHandler(WallHandler* handler);
106 
110  WallHandler* getHandler() const;
111 
116  void setIndSpecies(unsigned int indSpecies) override;
117 
122  void setSpecies(const ParticleSpecies* species);
123 
128  bool isFixed() const override;
129 
133  void setForceControl(Vec3D forceGoal, Vec3D gainFactor, Vec3D baseVelocity={0,0,0});
134 
138  virtual bool isLocal(Vec3D& min, Vec3D& max) const
139  { return false; }
140 
141  // returns the point intersecting a wall (x-p).n=0 and a line x=p0+t(p1-p0)
142  bool getLinePlaneIntersect(Vec3D& intersect, const Vec3D& p0, const Vec3D& p1, const Vec3D& n, const Vec3D& p);
143  bool isInsideWallVTK(const Vec3D& point, const Vec3D& normal, const Vec3D& position) const;
147 
151  void projectOntoWallVTK(Vec3D& point0, const Vec3D& point1, const Vec3D& normal, const Vec3D& position) const;
152 
157  void intersectVTK(std::vector<Vec3D>& points, Vec3D normal, Vec3D position) const;
158 
159 
160  virtual BaseInteraction*
161  getInteractionWithSuperQuad(SuperQuadricParticle* p, unsigned timeStamp, InteractionHandler* interactionHandler);
162 
168  virtual void writeVTK(VTKContainer& vtk) const;
169 
170  void getVTK(std::vector<Vec3D>& points, std::vector<std::vector<double>>& triangleStrips)
171  {}
172 
173  const Vec3D getAxis() const;
174 
177  getInteractionWith(BaseParticle* p, unsigned timeStamp, InteractionHandler* interactionHandler) override;
178 
184  virtual void actionsOnRestart() {}
185 
194 
203  virtual void handleParticleAddition(unsigned int id, BaseParticle* p) {}
204 
212  virtual void handleParticleRemoval(unsigned int id) {}
213 
220  virtual void checkInteractions(InteractionHandler* interactionHandler, unsigned int timeStamp) {}
221 
222  bool getVTKVisibility() const;
223 
224  void setVTKVisibility(bool vtkVisibility);
225 
229  static void addToVTK(const std::vector<Vec3D>& points, VTKContainer& vtk);
230 
231  //todo how do i write a copy and add function?
232  void addRenderedWall(BaseWall* w);
233 
234  BaseWall* getRenderedWall(size_t i) const;
235 
236  std::vector<BaseWall*> getRenderedWalls() const;
237 
238  void removeRenderedWalls();
239 
240  void renderWall(VTKContainer& vtk);
241 
242  void addParticlesAtWall(unsigned numElements = 50);
243 
244  void setVelocityControl(Vec3D forceGoal, Vec3D gainFactor, Vec3D baseVelocity);
245 
246  virtual void writeWallDetailsVTK(VTKData& data) const { };
247 
248  virtual void computeWear() { };
249 
250 private:
255 
256  bool vtkVisibility_ = true;
257 
261  std::vector<BaseWall*> renderedWalls_;
262 
263 };
264 
265 #endif
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:55
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:60
Definition: BaseParticle.h:54
Basic class for walls.
Definition: BaseWall.h:49
virtual void actionsOnRestart()
No implementation but can be overidden in its derived classes.
Definition: BaseWall.h:184
void renderWall(VTKContainer &vtk)
Definition: BaseWall.cc:605
std::vector< BaseWall * > getRenderedWalls() const
Definition: BaseWall.cc:600
virtual BaseWall * copy() const =0
Pure virtual function that can be overwritten in inherited classes in order to copy a BaseWall.
virtual void writeWallDetailsVTK(VTKData &data) const
Definition: BaseWall.h:246
virtual void actionsAfterParticleGhostUpdate()
No implementation but can be overidden in its derived classes.
Definition: BaseWall.h:193
void setIndSpecies(unsigned int indSpecies) override
Define the species of this wall using the index of the species in the SpeciesHandler in this DPMBase.
Definition: BaseWall.cc:142
virtual bool getDistanceNormalOverlapSuperquadric(const SuperQuadricParticle &p, Mdouble &distance, Vec3D &normal_return, Mdouble &overlap) const
Definition: BaseWall.cc:570
void addParticlesAtWall(unsigned numElements=50)
Definition: BaseWall.cc:645
void setVTKVisibility(bool vtkVisibility)
Definition: BaseWall.cc:548
void intersectVTK(std::vector< Vec3D > &points, Vec3D normal, Vec3D position) const
Definition: BaseWall.cc:241
void projectOntoWallVTK(Vec3D &point0, const Vec3D &point1, const Vec3D &normal, const Vec3D &position) const
Definition: BaseWall.cc:231
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
void addRenderedWall(BaseWall *w)
Definition: BaseWall.cc:584
virtual void checkInteractions(InteractionHandler *interactionHandler, unsigned int timeStamp)
Check if all interactions are valid.
Definition: BaseWall.h:220
void setVelocityControl(Vec3D forceGoal, Vec3D gainFactor, Vec3D baseVelocity)
Definition: BaseWall.cc:638
WallHandler * getHandler() const
A function which returns the WallHandler that handles this BaseWall.
Definition: BaseWall.cc:134
void write(std::ostream &os) const override
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: BaseWall.cc:100
virtual void handleParticleRemoval(unsigned int id)
Handles the addition of particles to the particleHandler.
Definition: BaseWall.h:212
void removeRenderedWalls()
Definition: BaseWall.cc:589
virtual void setHandler(WallHandler *handler)
A function which sets the WallHandler for this BaseWall.
Definition: BaseWall.cc:125
virtual Vec3D getFurthestPointSuperQuadric(const Vec3D &normalBodyFixed, const Vec3D &axes, Mdouble eps1, Mdouble eps2) const
Definition: BaseWall.cc:577
const Vec3D getAxis() const
Definition: BaseWall.cc:533
virtual void handleParticleAddition(unsigned int id, BaseParticle *p)
Handles the addition of particles to the particleHandler.
Definition: BaseWall.h:203
bool isInsideWallVTK(const Vec3D &point, const Vec3D &normal, const Vec3D &position) const
Definition: BaseWall.cc:220
virtual void writeVTK(VTKContainer &vtk) const
Definition: BaseWall.cc:496
virtual bool isLocal(Vec3D &min, Vec3D &max) const
Definition: BaseWall.h:138
std::vector< BaseWall * > renderedWalls_
Definition: BaseWall.h:261
bool vtkVisibility_
Definition: BaseWall.h:256
~BaseWall() override
Default destructor.
Definition: BaseWall.cc:66
WallHandler * handler_
Definition: BaseWall.h:248
void read(std::istream &is) override
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:78
bool getLinePlaneIntersect(Vec3D &intersect, const Vec3D &p0, const Vec3D &p1, const Vec3D &n, const Vec3D &p)
Definition: BaseWall.cc:204
virtual BaseInteraction * getInteractionWithSuperQuad(SuperQuadricParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler)
Definition: BaseWall.cc:524
BaseWall()
Default constructor.
Definition: BaseWall.cc:36
bool isFixed() const override
Definition: BaseWall.cc:186
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 ...
Definition: BaseWall.cc:196
void setSpecies(const ParticleSpecies *species)
Defines the species of the current wall.
Definition: BaseWall.cc:169
bool getVTKVisibility() const
Definition: BaseWall.cc:543
virtual void computeWear()
Definition: BaseWall.h:248
BaseWall * getRenderedWall(size_t i) const
Definition: BaseWall.cc:595
BaseInteraction * getInteractionWith(BaseParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler) override
Returns the interaction between this wall and a given particle, nullptr if there is no interaction.
Definition: BaseWall.cc:367
virtual bool getDistanceAndNormal(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return) const =0
Pure virtual function that computes the distance of a BaseParticle to this wall and returns the norma...
virtual bool getDistanceNormalOverlap(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return, Mdouble &overlap) const
Definition: BaseWall.cc:553
void getVTK(std::vector< Vec3D > &points, std::vector< std::vector< double >> &triangleStrips)
Definition: BaseWall.h:170
Container to store Interaction objects.
Definition: InteractionHandler.h:45
Definition: ParticleSpecies.h:37
Definition: SuperQuadricParticle.h:57
Definition: Kernel/VTKWriter/VTKData.h:36
Definition: Vector.h:51
Container to store all BaseWall.
Definition: WallHandler.h:44
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
Definition: BaseWall.h:38
std::vector< std::vector< double > > triangleStrips
Definition: BaseWall.h:40
std::vector< Vec3D > points
Definition: BaseWall.h:39