MeshTriangle.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef MeshTriangle_H
6 #define MeshTriangle_H
7 
8 #include <vector>
9 #include <Walls/BaseWall.h>
10 #include <Walls/InfiniteWall.h>
11 #include "Math/Vector.h"
12 
53 class MeshTriangle : public BaseWall
54 {
55 public:
56 
57  // TODO write proper constructors (also copy constructors)
61  MeshTriangle() = default;
62 
66  MeshTriangle(const MeshTriangle& other) = default;
67 
71  ~MeshTriangle() override = default;
72 
76  MeshTriangle* copy() const override
77  { return new MeshTriangle(*this); }
78 
82  std::string getName() const override
83  { return "MeshTriangle"; }
84 
88  void read(std::istream& is) override;
89 
93  void write(std::ostream& os) const override;
94 
100  void setVertices(Vec3D A, Vec3D B, Vec3D C);
101 
106  void setVertices(Vec3D A, Vec3D B, Vec3D C, Vec3D position);
107 
112 
116  std::array<Vec3D,3> getVertices() const {return vertex_;}
117 
121  Vec3D getFaceNormal() const {return faceNormal_;}
122 
126  Mdouble getArea() const {return area_;}
127 
128 
129  void move(const Vec3D& move) override;
130 
134  void setVertexIds(unsigned int i, unsigned int j, unsigned int k);
135 
139  std::array<unsigned int, 3> getVertexIds() const { return vertexIds_; }
140 
141  //
142  void writeVTK(VTKContainer& vtk) const override;
143 
144 
145 
146  BaseInteraction* getInteractionWith(BaseParticle* p, unsigned timeStamp, InteractionHandler* interactionHandler) override;
147 
151  void checkInteractions(InteractionHandler* interactionHandler, unsigned int timeStamp) override;
152 
157  bool getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const override;
158  bool getDistanceNormalOverlapType(const BaseParticle& p, Mdouble& distance, Vec3D& normal, Mdouble& overlap, unsigned int& type) const;
159 
163  const Vec3D getVelocityAtContact(const Vec3D& contact) const override;
164 
168  const Vec3D getBaricentricWeight(const Vec3D& contact) const;
169 
170  void rotate(const Vec3D& angularVelocity) override;
171 
175  bool isLocal(Vec3D& min, Vec3D& max) const override;
176 
180  bool isInsideTriangle(const Vec3D &point) const;
181 
182  Mdouble getInvMass() const override;
183  void setMass(Mdouble mass);
184 
188  void actionsOnRestart() override;
189 
193  void actionsAfterParticleGhostUpdate() override;
194 
198  void handleParticleRemoval(unsigned int id) override;
199 
203  void handleParticleAddition(unsigned int id, BaseParticle* p) override;
204 
209 
213  void checkActive();
214 
215  bool getActive() { return isActive; }
216 
220  void setHandler(WallHandler* handler) override;
221 
225  void applyPressure(Mdouble presure);
226 
230  void applyForce(Vec3D force);
231 
232 
236  std::array<MeshTriangle*, 3> neighbor = {{nullptr}};
237 
241  std::vector<std::vector<unsigned int>> vertexNeighbors;
242 
243 private:
244 
248  void updateVertexAndNormal();
249 
254 
259  std::array<Vec3D, 3> vertex_;
260  std::array<Vec3D, 3> vertexVelocity_;
261  std::array<BaseParticle*, 3> vertexParticle_ = {{nullptr}};
262 
268 
272  std::array<Vec3D, 3> edgeNormal_;
273  std::array<Vec3D, 3> edge_;
274  // Used to ignore certain contacts
275  std::array<unsigned int, 3> vertexIds_;
276  std::array<double, 3> edgeLength_;
277 
278 
284 
285  // TODO: replace defualt value by default value in proper constructor
287 
288  bool isActive = 0;
289 };
290 
291 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
double Mdouble
Definition: GeneralDefine.h:13
float * p
Definition: Tutorial_Map_using.cpp:9
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:39
Definition: BaseParticle.h:33
Basic class for walls.
Definition: BaseWall.h:28
Container to store Interaction objects.
Definition: InteractionHandler.h:25
MeshTriangle implements a triangle whose vertex positions are defined by three particles.
Definition: MeshTriangle.h:54
std::array< Vec3D, 3 > getVertices() const
Returns an array of the vertex coordinates.
Definition: MeshTriangle.h:116
void read(std::istream &is) override
Reads an MeshTriangle from an input stream, for example a restart file.
Definition: MeshTriangle.cc:343
std::vector< std::vector< unsigned int > > vertexNeighbors
Definition: MeshTriangle.h:241
std::array< Vec3D, 3 > vertex_
Definition: MeshTriangle.h:259
void checkInteractions(InteractionHandler *interactionHandler, unsigned int timeStamp) override
Checks, if the forces of all interctions should be applied.
Definition: MeshTriangle.cc:89
const Vec3D getVelocityAtContact(const Vec3D &contact) const override
Calculates the local velocity at a specified point.
Definition: MeshTriangle.cc:304
void setMass(Mdouble mass)
Definition: MeshTriangle.cc:668
Vec3D faceNormal_
Definition: MeshTriangle.h:282
void setVertexVelocities(Vec3D A, Vec3D B, Vec3D C)
Sets the velocity of the vertex points.
Definition: MeshTriangle.cc:458
Mdouble getInvMass() const override
Definition: MeshTriangle.cc:658
Mdouble getArea() const
Returns the area of the triangle.
Definition: MeshTriangle.h:126
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:532
BaseInteraction * getInteractionWith(BaseParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler) override
Definition: MeshTriangle.cc:27
void setHandler(WallHandler *handler) override
Set the handler.
Definition: MeshTriangle.cc:480
void rotate(const Vec3D &angularVelocity) override
Rotates this BaseInteractable.
Definition: MeshTriangle.cc:331
std::array< unsigned int, 3 > getVertexIds() const
Returns an array containing the ids of the vertex particles.
Definition: MeshTriangle.h:139
void write(std::ostream &os) const override
Writes an MeshTriangle to an output stream, for example a restart file.
Definition: MeshTriangle.cc:390
std::array< MeshTriangle *, 3 > neighbor
Definition: MeshTriangle.h:236
std::array< Vec3D, 3 > vertexVelocity_
Definition: MeshTriangle.h:260
const Vec3D getBaricentricWeight(const Vec3D &contact) const
Calculates the barycentric weight of a specified point.
Definition: MeshTriangle.cc:315
Vec3D vertexMin_
Definition: MeshTriangle.h:266
std::array< unsigned int, 3 > vertexIds_
Definition: MeshTriangle.h:275
bool isActive
Definition: MeshTriangle.h:288
void retrieveVertexParticles()
Tries to get pointers to all vertex particles from the handler.
Definition: MeshTriangle.cc:550
Vec3D vertexMax_
Definition: MeshTriangle.h:267
bool getDistanceNormalOverlapType(const BaseParticle &p, Mdouble &distance, Vec3D &normal, Mdouble &overlap, unsigned int &type) const
Definition: MeshTriangle.cc:223
std::array< double, 3 > edgeLength_
Definition: MeshTriangle.h:276
void applyPressure(Mdouble presure)
Apply a force pointing in normal direction corresponding to the specified pressure.
Definition: MeshTriangle.cc:681
bool isInsideTriangle(const Vec3D &point) const
Determines if a given point is within the triangle.
Definition: MeshTriangle.cc:647
void actionsOnRestart() override
Actions executed on restart.
Definition: MeshTriangle.cc:576
void updateVerticesFromParticles()
Retrieve new positions from updated vertex particles.
Definition: MeshTriangle.cc:497
std::array< Vec3D, 3 > edgeNormal_
Definition: MeshTriangle.h:272
void handleParticleRemoval(unsigned int id) override
Handles the removal of particles to the particle Handler.
Definition: MeshTriangle.cc:512
MeshTriangle * copy() const override
Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism.
Definition: MeshTriangle.h:76
bool isLocal(Vec3D &min, Vec3D &max) const override
Determines if the triangle is considered local.
Definition: MeshTriangle.cc:636
void checkActive()
Check if the triangle is considered active.
Definition: MeshTriangle.cc:568
bool getActive()
Definition: MeshTriangle.h:215
std::array< BaseParticle *, 3 > vertexParticle_
Definition: MeshTriangle.h:261
void actionsAfterParticleGhostUpdate() override
actionsPerformed after the position update of (ghost-) particles.
Definition: MeshTriangle.cc:586
std::string getName() const override
Returns the name of the object, here the string "MeshTriangle".
Definition: MeshTriangle.h:82
void applyForce(Vec3D force)
Apply the given force to the triangle.
Definition: MeshTriangle.cc:700
Mdouble area_
Definition: MeshTriangle.h:283
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:443
void updateVertexAndNormal()
Update vertexMin_, vertexMax_ and faceNormal_ for an updated position.
Definition: MeshTriangle.cc:609
~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:468
MeshTriangle()=default
Default constructor.
void move(const Vec3D &move) override
Definition: MeshTriangle.cc:597
std::array< Vec3D, 3 > edge_
Definition: MeshTriangle.h:273
Mdouble invMass_
Definition: MeshTriangle.h:286
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:197
Vec3D getFaceNormal() const
Returns the face normal.
Definition: MeshTriangle.h:121
void writeVTK(VTKContainer &vtk) const override
Definition: MeshTriangle.cc:425
Definition: Kernel/Math/Vector.h:30
Container to store all BaseWall.
Definition: WallHandler.h:22
Definition: matrices.h:74
#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
type
Definition: compute_granudrum_aor.py:141
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
Definition: BaseWall.h:17
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2