TriangleMeshWall.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 MERCURYDPM_TRIANGLEMESHWALL_H
6 #define MERCURYDPM_TRIANGLEMESHWALL_H
7 
8 #include "BaseWall.h"
9 #include "TriangleWall.h"
10 
11 class TriangleMeshWall : public BaseWall
12 {
13 public:
14 
18  TriangleMeshWall() = default;
19 
24  TriangleMeshWall(const TriangleMeshWall& other);
25 
32  TriangleMeshWall(const std::vector<Vec3D>& points, const std::vector<std::array<unsigned, 3>>& cells, const ParticleSpecies* species = nullptr);
33 
43  TriangleMeshWall(const Vec3D& P0, const Vec3D& P1, const Vec3D& P, Mdouble resolutionU, Mdouble resolutionV,
44  const ParticleSpecies* species = nullptr, bool periodicInU = false, bool periodicInV = false);
45 
49  ~TriangleMeshWall() override = default;
50 
57 
62  TriangleMeshWall* copy() const override;
63 
67  void read(std::istream& is) override;
68 
72  void write(std::ostream& os) const override;
73 
78  std::string getName() const override;
79 
85  void set(const std::vector<Vec3D>& points, const std::vector<std::array<unsigned, 3>>& cells);
86 
95  bool getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const override;
96 
107  BaseInteraction* getInteractionWith(BaseParticle* p, unsigned timeStamp, InteractionHandler* interactionHandler) override;
108 
109  void resetForceTorque(int numberOfOMPthreads) override;
110 
111  void writeVTK(VTKContainer& vtk) const override;
112 
113  void setSpecies(const ParticleSpecies* species);
114 
120  void moveVertex(unsigned index, const Vec3D& dP);
121 
127  void removeTriangle(unsigned index, bool removeFreeVertex = true);
128 
137  void refineTriangle(unsigned index, unsigned numberOfTimes = 1);
138 
145  void setPeriodicCompanions(const std::vector<std::pair<unsigned, unsigned>>& periodicCompanions);
146 
156  void moveVerticesToMatchVolume(std::vector<Vec3D> displacements, Mdouble targetVolume, int maxNumRecursiveCalls = 15);
157 
162  Mdouble getVolumeTetrahedron(const Vec3D& a, const Vec3D& b, const Vec3D& c, const Vec3D& d);
163 
169  void addToMesh(TriangleMeshWall mesh);
170 
179  void createParallelogramMesh(const Vec3D& P0, const Vec3D& P1, const Vec3D& P2, Mdouble resolutionU, Mdouble resolutionV, bool periodicInU = false, bool periodicInV = false);
180 
188  void createFourPointMesh(const Vec3D& P0, const Vec3D& P1, const Vec3D& P2, const Vec3D& P3, int numSegmentsU, int numSegmentsV);
189 
190  bool isLocal(Vec3D& min, Vec3D& max) const override;
191 
192  void setPosition(const Vec3D& position) override;
193  void setOrientation(const Quaternion& orientation) override;
194  void move(const Vec3D& move) override;
195  void rotate(const Vec3D& angularVelocity) override;
196 
197 protected:
198  struct Triangle
199  {
203  Triangle() = default;
204 
210  Triangle(const TriangleWall& w, std::array<unsigned, 3> vi) : wall(w), vertexIndices(vi) {};
211 
214 
216  std::array<unsigned, 3> vertexIndices{};
217  };
218 
219  struct Vertex
220  {
224  Vertex() = default;
225 
226  explicit Vertex(Vec3D P) : position(P) {};
227 
230 
233  std::vector<std::pair<unsigned, unsigned>> triangleIndices;
234  };
235 
236 protected:
237  std::vector<Triangle> triangles_;
238  std::vector<Vertex> vertices_;
239 
240 private:
241  std::vector<std::pair<unsigned, unsigned>> periodicCompanions_;
242 
248  std::vector<unsigned> getPeriodicCompanions(unsigned index);
249 
253 
260  bool isWithinBoundingBox(const Vec3D& position, Mdouble radius) const;
261 
265  void updateBoundingBox();
266 
272 
279  int getNumberOfSegmentsAndResolution(Mdouble length, Mdouble& resolution);
280 
289  void addZigZagDiagonalCells(std::vector<std::array<unsigned, 3>>& cells, int numU, int numV, int i, int j);
290 };
291 
292 
293 #endif //MERCURYDPM_TRIANGLEMESHWALL_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
RowVector3d w
Definition: Matrix_resize_int.cpp:3
float * p
Definition: Tutorial_Map_using.cpp:9
Scalar * b
Definition: benchVecAdd.cpp:17
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
Definition: ParticleSpecies.h:16
This class contains the 4 components of a quaternion and the standard operators and functions needed ...
Definition: Kernel/Math/Quaternion.h:42
Definition: TriangleMeshWall.h:12
void updateBoundingBox()
Sets the local and global bounding boxes. This method should be called any time a vertex is updated i...
Definition: TriangleMeshWall.cc:848
void write(std::ostream &os) const override
Writes a TriangleMeshWall to an output stream, for example a restart file.
Definition: TriangleMeshWall.cc:92
void setSpecies(const ParticleSpecies *species)
Definition: TriangleMeshWall.cc:298
void set(const std::vector< Vec3D > &points, const std::vector< std::array< unsigned, 3 >> &cells)
Set function creating triangles.
Definition: TriangleMeshWall.cc:112
void move(const Vec3D &move) override
Moves this BaseInteractable by adding an amount to the position.
Definition: TriangleMeshWall.cc:915
void refineTriangle(unsigned index, unsigned numberOfTimes=1)
Makes a really basic refinement by adding a vertex in the middle of the triangle to create 3 new ones...
Definition: TriangleMeshWall.cc:406
int getNumberOfSegmentsAndResolution(Mdouble length, Mdouble &resolution)
Finds the number of segments and the resolution needed to perfectly fit a length.
Definition: TriangleMeshWall.cc:762
void removeTriangle(unsigned index, bool removeFreeVertex=true)
Removes a single triangle from the mesh.
Definition: TriangleMeshWall.cc:330
std::string getName() const override
Returns the name of the object.
Definition: TriangleMeshWall.cc:107
std::vector< unsigned > getPeriodicCompanions(unsigned index)
Looks up the companions belonging to a vertex index, if it has any.
Definition: TriangleMeshWall.cc:516
TriangleMeshWall * copy() const override
Wall copy method.
Definition: TriangleMeshWall.cc:47
void rotate(const Vec3D &angularVelocity) override
Rotates this BaseInteractable.
Definition: TriangleMeshWall.cc:921
Vec3D boundingBoxMax_
Definition: TriangleMeshWall.h:251
TriangleMeshWall & operator=(const TriangleMeshWall &other)
Copy assignment operator.
Definition: TriangleMeshWall.cc:38
Vec3D boundingBoxMinGlobal_
Definition: TriangleMeshWall.h:252
void resetForceTorque(int numberOfOMPthreads) override
Definition: TriangleMeshWall.cc:273
void writeVTK(VTKContainer &vtk) const override
Definition: TriangleMeshWall.cc:281
Vec3D boundingBoxMaxGlobal_
Definition: TriangleMeshWall.h:252
void moveVertex(unsigned index, const Vec3D &dP)
Updates a vertex by a given change in position.
Definition: TriangleMeshWall.cc:307
void addZigZagDiagonalCells(std::vector< std::array< unsigned, 3 >> &cells, int numU, int numV, int i, int j)
Helper function that adds two cells (triangles) to the provided cells vector. Used by createParallelo...
Definition: TriangleMeshWall.cc:770
void setPosition(const Vec3D &position) override
Sets the position of this BaseInteractable.
Definition: TriangleMeshWall.cc:903
void updateBoundingBoxGlobal()
Sets the global bounding box, using the bounding box in lab frame. This method should be called when ...
Definition: TriangleMeshWall.cc:868
std::vector< std::pair< unsigned, unsigned > > periodicCompanions_
Definition: TriangleMeshWall.h:241
void addToMesh(TriangleMeshWall mesh)
Adds a mesh to this mesh. When vertices share a position, only the one in the current mesh is kept an...
Definition: TriangleMeshWall.cc:645
Vec3D boundingBoxMin_
Bounding box corners in lab frame and global frame. Used to speed up contact detection....
Definition: TriangleMeshWall.h:251
~TriangleMeshWall() override=default
Destructor.
TriangleMeshWall()=default
Default constructor.
std::vector< Triangle > triangles_
Definition: TriangleMeshWall.h:237
bool isWithinBoundingBox(const Vec3D &position, Mdouble radius) const
Checks whether or not a part of the particle is within the bounding box.
Definition: TriangleMeshWall.cc:841
BaseInteraction * getInteractionWith(BaseParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler) override
Gets the interaction between a given BaseParticle and all TriangleWalls in this mesh at a given time....
Definition: TriangleMeshWall.cc:171
void moveVerticesToMatchVolume(std::vector< Vec3D > displacements, Mdouble targetVolume, int maxNumRecursiveCalls=15)
Moves all vertices by given displacements and corrects to match the change in volume with the target ...
Definition: TriangleMeshWall.cc:532
std::vector< Vertex > vertices_
Definition: TriangleMeshWall.h:238
Mdouble getVolumeTetrahedron(const Vec3D &a, const Vec3D &b, const Vec3D &c, const Vec3D &d)
Calculates the volume of a tetrahedron formed by 4 vertices.
Definition: TriangleMeshWall.cc:640
bool isLocal(Vec3D &min, Vec3D &max) const override
Definition: TriangleMeshWall.cc:834
void read(std::istream &is) override
Reads a TriangleMeshWall from an input stream, for example a restart file.
Definition: TriangleMeshWall.cc:52
void createFourPointMesh(const Vec3D &P0, const Vec3D &P1, const Vec3D &P2, const Vec3D &P3, int numSegmentsU, int numSegmentsV)
Creates mesh consisting of four points, with linearly interpolated segments. The points therefore don...
Definition: TriangleMeshWall.cc:798
void setPeriodicCompanions(const std::vector< std::pair< unsigned, unsigned >> &periodicCompanions)
Sets the vector with pairs of indices of vertices which lie on a periodic boundary and are each other...
Definition: TriangleMeshWall.cc:511
void createParallelogramMesh(const Vec3D &P0, const Vec3D &P1, const Vec3D &P2, Mdouble resolutionU, Mdouble resolutionV, bool periodicInU=false, bool periodicInV=false)
Creates a parallelogram shaped mesh with a given resolution in u- and v-direction.
Definition: TriangleMeshWall.cc:710
bool getDistanceAndNormal(const BaseParticle &p, Mdouble &distance, Vec3D &normal_return) const override
Checks if a collision is happening with any of the TriangleWalls. NOTE: this does not handle actual i...
Definition: TriangleMeshWall.cc:152
void setOrientation(const Quaternion &orientation) override
Sets the orientation of this BaseInteractable.
Definition: TriangleMeshWall.cc:909
A TriangleWall is convex polygon defined as an intersection of InfiniteWall's.
Definition: TriangleWall.h:36
Definition: Kernel/Math/Vector.h:30
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
const Scalar * a
Definition: level2_cplx_impl.h:32
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
double P0
Definition: two_dim.cc:101
radius
Definition: UniformPSDSelfTest.py:15
int c
Definition: calibrate.py:100
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
Definition: TriangleMeshWall.h:199
std::array< unsigned, 3 > vertexIndices
Array of indices to the vertices vector of the 3 vertices the triangle is made of.
Definition: TriangleMeshWall.h:216
Triangle(const TriangleWall &w, std::array< unsigned, 3 > vi)
Constructor setting values.
Definition: TriangleMeshWall.h:210
TriangleWall wall
The TriangleWall.
Definition: TriangleMeshWall.h:210
Triangle()=default
Default constructor.
Definition: TriangleMeshWall.h:220
Vertex()=default
Default constructor.
std::vector< std::pair< unsigned, unsigned > > triangleIndices
Definition: TriangleMeshWall.h:233
Vertex(Vec3D P)
Definition: TriangleMeshWall.h:226
Vec3D position
The vertex position.
Definition: TriangleMeshWall.h:226
Definition: BaseWall.h:17
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2