MeshTriangle.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 MeshTriangle_H
27 #define MeshTriangle_H
28 
29 #include <vector>
30 #include <Walls/BaseWall.h>
31 #include <Walls/InfiniteWall.h>
32 #include "Math/Vector.h"
33 
74 class MeshTriangle : public BaseWall
75 {
76 public:
77 
78  // TODO write proper constructors (also copy constructors)
82  MeshTriangle() = default;
83 
87  MeshTriangle(const MeshTriangle& other) = default;
88 
92  ~MeshTriangle() override = default;
93 
97  MeshTriangle* copy() const override
98  { return new MeshTriangle(*this); }
99 
103  std::string getName() const override
104  { return "MeshTriangle"; }
105 
109  void read(std::istream& is) override;
110 
114  void write(std::ostream& os) const override;
115 
121  void setVertices(Vec3D A, Vec3D B, Vec3D C);
122 
127  void setVertices(Vec3D A, Vec3D B, Vec3D C, Vec3D position);
128 
132  void setVertexVelocities(Vec3D A, Vec3D B, Vec3D C);
133 
137  std::array<Vec3D,3> getVertices() const {return vertex_;}
138 
142  Vec3D getFaceNormal() const {return faceNormal_;}
143 
147  Mdouble getArea() const {return area_;}
148 
149 
150  void move(const Vec3D& move) override;
151 
155  void setVertexIds(unsigned int i, unsigned int j, unsigned int k);
156 
160  std::array<unsigned int, 3> getVertexIds() const { return vertexIds_; }
161 
162  //
163  void writeVTK(VTKContainer& vtk) const override;
164 
165 
166 
167  BaseInteraction* getInteractionWith(BaseParticle* p, unsigned timeStamp, InteractionHandler* interactionHandler) override;
168 
172  void checkInteractions(InteractionHandler* interactionHandler, unsigned int timeStamp) override;
173 
178  bool getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const override;
179  bool getDistanceNormalOverlapType(const BaseParticle& p, Mdouble& distance, Vec3D& normal, Mdouble& overlap, unsigned int& type) const;
180 
184  const Vec3D getVelocityAtContact(const Vec3D& contact) const override;
185 
189  const Vec3D getBaricentricWeight(const Vec3D& contact) const;
190 
191  void rotate(const Vec3D& angularVelocity) override;
192 
196  bool isLocal(Vec3D& min, Vec3D& max) const override;
197 
201  bool isInsideTriangle(const Vec3D &point) const;
202 
203  Mdouble getInvMass() const override;
204  void setMass(Mdouble mass);
205 
209  void actionsOnRestart() override;
210 
214  void actionsAfterParticleGhostUpdate() override;
215 
219  void handleParticleRemoval(unsigned int id) override;
220 
224  void handleParticleAddition(unsigned int id, BaseParticle* p) override;
225 
230 
234  void checkActive();
235 
236  bool getActive() { return isActive; }
237 
241  void setHandler(WallHandler* handler) override;
242 
246  void applyPressure(Mdouble presure);
247 
251  void applyForce(Vec3D force);
252 
253 
257  std::array<MeshTriangle*, 3> neighbor = {{nullptr}};
258 
262  std::vector<std::vector<unsigned int>> vertexNeighbors;
263 
264 private:
265 
269  void updateVertexAndNormal();
270 
275 
280  std::array<Vec3D, 3> vertex_;
281  std::array<Vec3D, 3> vertexVelocity_;
282  std::array<BaseParticle*, 3> vertexParticle_ = {{nullptr}};
283 
289 
293  std::array<Vec3D, 3> edgeNormal_;
294  std::array<Vec3D, 3> edge_;
295  // Used to ignore certain contacts
296  std::array<unsigned int, 3> vertexIds_;
297  std::array<double, 3> edgeLength_;
298 
299 
305 
306  // TODO: replace defualt value by default value in proper constructor
308 
309  bool isActive = 0;
310 };
311 
312 #endif
double Mdouble
Definition: GeneralDefine.h:34
@ A
Definition: StatisticsVector.h:42
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
Container to store Interaction objects.
Definition: InteractionHandler.h:45
MeshTriangle implements a triangle whose vertex positions are defined by three particles.
Definition: MeshTriangle.h:75
std::array< Vec3D, 3 > getVertices() const
Returns an array of the vertex coordinates.
Definition: MeshTriangle.h:137
void read(std::istream &is) override
Reads an MeshTriangle from an input stream, for example a restart file.
Definition: MeshTriangle.cc:354
std::vector< std::vector< unsigned int > > vertexNeighbors
Definition: MeshTriangle.h:262
std::array< Vec3D, 3 > vertex_
Definition: MeshTriangle.h:280
void checkInteractions(InteractionHandler *interactionHandler, unsigned int timeStamp) override
Checks, if the forces of all interctions should be applied.
Definition: MeshTriangle.cc:110
const Vec3D getVelocityAtContact(const Vec3D &contact) const override
Calculates the local velocity at a specified point.
Definition: MeshTriangle.cc:315
void setMass(Mdouble mass)
Definition: MeshTriangle.cc:681
Vec3D faceNormal_
Definition: MeshTriangle.h:303
void setVertexVelocities(Vec3D A, Vec3D B, Vec3D C)
Sets the velocity of the vertex points.
Definition: MeshTriangle.cc:471
Mdouble getInvMass() const override
Definition: MeshTriangle.cc:671
Mdouble getArea() const
Returns the area of the triangle.
Definition: MeshTriangle.h:147
MeshTriangle(const MeshTriangle &other)=default
Copy constructor.
void handleParticleAddition(unsigned int id, BaseParticle *p) override
Handles the addition of particles to the particle Handler.
Definition: MeshTriangle.cc:545
BaseInteraction * getInteractionWith(BaseParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler) override
Definition: MeshTriangle.cc:48
void setHandler(WallHandler *handler) override
Set the handler.
Definition: MeshTriangle.cc:493
void rotate(const Vec3D &angularVelocity) override
Rotates this BaseInteractable.
Definition: MeshTriangle.cc:342
std::array< unsigned int, 3 > getVertexIds() const
Returns an array containing the ids of the vertex particles.
Definition: MeshTriangle.h:160
void write(std::ostream &os) const override
Writes an MeshTriangle to an output stream, for example a restart file.
Definition: MeshTriangle.cc:403
std::array< MeshTriangle *, 3 > neighbor
Definition: MeshTriangle.h:257
std::array< Vec3D, 3 > vertexVelocity_
Definition: MeshTriangle.h:281
const Vec3D getBaricentricWeight(const Vec3D &contact) const
Calculates the barycentric weight of a specified point.
Definition: MeshTriangle.cc:326
Vec3D vertexMin_
Definition: MeshTriangle.h:287
std::array< unsigned int, 3 > vertexIds_
Definition: MeshTriangle.h:296
bool isActive
Definition: MeshTriangle.h:309
void retrieveVertexParticles()
Tries to get pointers to all vertex particles from the handler.
Definition: MeshTriangle.cc:563
Vec3D vertexMax_
Definition: MeshTriangle.h:288
bool getDistanceNormalOverlapType(const BaseParticle &p, Mdouble &distance, Vec3D &normal, Mdouble &overlap, unsigned int &type) const
Definition: MeshTriangle.cc:225
std::array< double, 3 > edgeLength_
Definition: MeshTriangle.h:297
void applyPressure(Mdouble presure)
Apply a force pointing in normal direction corresponding to the specified pressure.
Definition: MeshTriangle.cc:694
bool isInsideTriangle(const Vec3D &point) const
Determines if a given point is within the triangle.
Definition: MeshTriangle.cc:660
void actionsOnRestart() override
Actions executed on restart.
Definition: MeshTriangle.cc:589
void updateVerticesFromParticles()
Retrieve new positions from updated vertex particles.
Definition: MeshTriangle.cc:510
std::array< Vec3D, 3 > edgeNormal_
Definition: MeshTriangle.h:293
void handleParticleRemoval(unsigned int id) override
Handles the removal of particles to the particle Handler.
Definition: MeshTriangle.cc:525
MeshTriangle * copy() const override
Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism.
Definition: MeshTriangle.h:97
bool isLocal(Vec3D &min, Vec3D &max) const override
Determines if the triangle is considered local.
Definition: MeshTriangle.cc:649
void checkActive()
Check if the triangle is considered active.
Definition: MeshTriangle.cc:581
bool getActive()
Definition: MeshTriangle.h:236
std::array< BaseParticle *, 3 > vertexParticle_
Definition: MeshTriangle.h:282
void actionsAfterParticleGhostUpdate() override
actionsPerformed after the position update of (ghost-) particles.
Definition: MeshTriangle.cc:599
std::string getName() const override
Returns the name of the object, here the string "MeshTriangle".
Definition: MeshTriangle.h:103
void applyForce(Vec3D force)
Apply the given force to the triangle.
Definition: MeshTriangle.cc:713
Mdouble area_
Definition: MeshTriangle.h:304
void setVertices(Vec3D A, Vec3D B, Vec3D C)
Sets member variables such that the wall represents a triangle with vertices A, B,...
Definition: MeshTriangle.cc:456
void updateVertexAndNormal()
Update vertexMin_, vertexMax_ and faceNormal_ for an updated position.
Definition: MeshTriangle.cc:622
~MeshTriangle() override=default
Destructor.
void setVertexIds(unsigned int i, unsigned int j, unsigned int k)
sets the ids of the vertex particles. Calls retrieveVertexParticles.
Definition: MeshTriangle.cc:481
MeshTriangle()=default
Default constructor.
void move(const Vec3D &move) override
Definition: MeshTriangle.cc:610
std::array< Vec3D, 3 > edge_
Definition: MeshTriangle.h:294
Mdouble invMass_
Definition: MeshTriangle.h:307
bool getDistanceAndNormal(const BaseParticle &p, Mdouble &distance, Vec3D &normal_return) const override
Compute the distance from the wall for a given BaseParticle and return if there is a collision....
Definition: MeshTriangle.cc:199
Vec3D getFaceNormal() const
Returns the face normal.
Definition: MeshTriangle.h:142
void writeVTK(VTKContainer &vtk) const override
Definition: MeshTriangle.cc:438
Definition: Vector.h:51
Container to store all BaseWall.
Definition: WallHandler.h:44
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
Definition: BaseWall.h:38