TriangleMeshWall.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 MERCURYDPM_TRIANGLEMESHWALL_H
27 #define MERCURYDPM_TRIANGLEMESHWALL_H
28 
29 #include "BaseWall.h"
30 #include "TriangleWall.h"
31 
32 class TriangleMeshWall : public BaseWall
33 {
34 public:
35 
39  TriangleMeshWall() = default;
40 
45  TriangleMeshWall(const TriangleMeshWall& other);
46 
53  TriangleMeshWall(const std::vector<Vec3D>& points, const std::vector<std::array<unsigned, 3>>& cells, const ParticleSpecies* species = nullptr);
54 
64  TriangleMeshWall(const Vec3D& P0, const Vec3D& P1, const Vec3D& P, Mdouble resolutionU, Mdouble resolutionV,
65  const ParticleSpecies* species = nullptr, bool periodicInU = false, bool periodicInV = false);
66 
70  ~TriangleMeshWall() override = default;
71 
78 
83  TriangleMeshWall* copy() const override;
84 
88  void read(std::istream& is) override;
89 
93  void write(std::ostream& os) const override;
94 
99  std::string getName() const override;
100 
106  void set(const std::vector<Vec3D>& points, const std::vector<std::array<unsigned, 3>>& cells);
107 
116  bool getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const override;
117 
128  BaseInteraction* getInteractionWith(BaseParticle* p, unsigned timeStamp, InteractionHandler* interactionHandler) override;
129 
130  void resetForceTorque(int numberOfOMPthreads) override;
131 
132  void writeVTK(VTKContainer& vtk) const override;
133 
134  void setSpecies(const ParticleSpecies* species);
135 
141  void moveVertex(unsigned index, const Vec3D& dP);
142 
148  void removeTriangle(unsigned index, bool removeFreeVertex = true);
149 
158  void refineTriangle(unsigned index, unsigned numberOfTimes = 1);
159 
166  void setPeriodicCompanions(const std::vector<std::pair<unsigned, unsigned>>& periodicCompanions);
167 
177  void moveVerticesToMatchVolume(std::vector<Vec3D> displacements, Mdouble targetVolume, int maxNumRecursiveCalls = 15);
178 
183  Mdouble getVolumeTetrahedron(const Vec3D& a, const Vec3D& b, const Vec3D& c, const Vec3D& d);
184 
190  void addToMesh(TriangleMeshWall mesh);
191 
200  void createParallelogramMesh(const Vec3D& P0, const Vec3D& P1, const Vec3D& P2, Mdouble resolutionU, Mdouble resolutionV, bool periodicInU = false, bool periodicInV = false);
201 
209  void createFourPointMesh(const Vec3D& P0, const Vec3D& P1, const Vec3D& P2, const Vec3D& P3, int numSegmentsU, int numSegmentsV);
210 
211  bool isLocal(Vec3D& min, Vec3D& max) const override;
212 
213  void setPosition(const Vec3D& position) override;
214  void setOrientation(const Quaternion& orientation) override;
215  void move(const Vec3D& move) override;
216  void rotate(const Vec3D& angularVelocity) override;
217 
218 protected:
219  struct Triangle
220  {
224  Triangle() = default;
225 
231  Triangle(const TriangleWall& w, std::array<unsigned, 3> vi) : wall(w), vertexIndices(vi) {};
232 
235 
237  std::array<unsigned, 3> vertexIndices{};
238  };
239 
240  struct Vertex
241  {
245  Vertex() = default;
246 
247  explicit Vertex(Vec3D P) : position(P) {};
248 
251 
254  std::vector<std::pair<unsigned, unsigned>> triangleIndices;
255  };
256 
257 protected:
258  std::vector<Triangle> triangles_;
259  std::vector<Vertex> vertices_;
260 
261 private:
262  std::vector<std::pair<unsigned, unsigned>> periodicCompanions_;
263 
269  std::vector<unsigned> getPeriodicCompanions(unsigned index);
270 
274 
281  bool isWithinBoundingBox(const Vec3D& position, Mdouble radius) const;
282 
286  void updateBoundingBox();
287 
293 
300  int getNumberOfSegmentsAndResolution(Mdouble length, Mdouble& resolution);
301 
310  void addZigZagDiagonalCells(std::vector<std::array<unsigned, 3>>& cells, int numU, int numV, int i, int j);
311 };
312 
313 
314 #endif //MERCURYDPM_TRIANGLEMESHWALL_H
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
Definition: ParticleSpecies.h:37
This class contains the 4 components of a quaternion and the standard operators and functions needed ...
Definition: Quaternion.h:63
Definition: TriangleMeshWall.h:33
void updateBoundingBox()
Sets the local and global bounding boxes. This method should be called any time a vertex is updated i...
Definition: TriangleMeshWall.cc:869
void write(std::ostream &os) const override
Writes a TriangleMeshWall to an output stream, for example a restart file.
Definition: TriangleMeshWall.cc:113
void setSpecies(const ParticleSpecies *species)
Definition: TriangleMeshWall.cc:319
void set(const std::vector< Vec3D > &points, const std::vector< std::array< unsigned, 3 >> &cells)
Set function creating triangles.
Definition: TriangleMeshWall.cc:133
void move(const Vec3D &move) override
Moves this BaseInteractable by adding an amount to the position.
Definition: TriangleMeshWall.cc:936
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:427
int getNumberOfSegmentsAndResolution(Mdouble length, Mdouble &resolution)
Finds the number of segments and the resolution needed to perfectly fit a length.
Definition: TriangleMeshWall.cc:783
void removeTriangle(unsigned index, bool removeFreeVertex=true)
Removes a single triangle from the mesh.
Definition: TriangleMeshWall.cc:351
std::string getName() const override
Returns the name of the object.
Definition: TriangleMeshWall.cc:128
std::vector< unsigned > getPeriodicCompanions(unsigned index)
Looks up the companions belonging to a vertex index, if it has any.
Definition: TriangleMeshWall.cc:537
TriangleMeshWall * copy() const override
Wall copy method.
Definition: TriangleMeshWall.cc:68
void rotate(const Vec3D &angularVelocity) override
Rotates this BaseInteractable.
Definition: TriangleMeshWall.cc:942
Vec3D boundingBoxMax_
Definition: TriangleMeshWall.h:272
TriangleMeshWall & operator=(const TriangleMeshWall &other)
Copy assignment operator.
Definition: TriangleMeshWall.cc:59
Vec3D boundingBoxMinGlobal_
Definition: TriangleMeshWall.h:273
void resetForceTorque(int numberOfOMPthreads) override
Definition: TriangleMeshWall.cc:294
void writeVTK(VTKContainer &vtk) const override
Definition: TriangleMeshWall.cc:302
Vec3D boundingBoxMaxGlobal_
Definition: TriangleMeshWall.h:273
void moveVertex(unsigned index, const Vec3D &dP)
Updates a vertex by a given change in position.
Definition: TriangleMeshWall.cc:328
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:791
void setPosition(const Vec3D &position) override
Sets the position of this BaseInteractable.
Definition: TriangleMeshWall.cc:924
void updateBoundingBoxGlobal()
Sets the global bounding box, using the bounding box in lab frame. This method should be called when ...
Definition: TriangleMeshWall.cc:889
std::vector< std::pair< unsigned, unsigned > > periodicCompanions_
Definition: TriangleMeshWall.h:262
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:666
Vec3D boundingBoxMin_
Bounding box corners in lab frame and global frame. Used to speed up contact detection....
Definition: TriangleMeshWall.h:272
~TriangleMeshWall() override=default
Destructor.
TriangleMeshWall()=default
Default constructor.
std::vector< Triangle > triangles_
Definition: TriangleMeshWall.h:258
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:862
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:192
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:553
std::vector< Vertex > vertices_
Definition: TriangleMeshWall.h:259
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:661
bool isLocal(Vec3D &min, Vec3D &max) const override
Definition: TriangleMeshWall.cc:855
void read(std::istream &is) override
Reads a TriangleMeshWall from an input stream, for example a restart file.
Definition: TriangleMeshWall.cc:73
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:819
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:532
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:731
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:173
void setOrientation(const Quaternion &orientation) override
Sets the orientation of this BaseInteractable.
Definition: TriangleMeshWall.cc:930
A TriangleWall is convex polygon defined as an intersection of InfiniteWall's.
Definition: TriangleWall.h:57
Definition: Vector.h:51
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
Definition: TriangleMeshWall.h:220
std::array< unsigned, 3 > vertexIndices
Array of indices to the vertices vector of the 3 vertices the triangle is made of.
Definition: TriangleMeshWall.h:237
Triangle(const TriangleWall &w, std::array< unsigned, 3 > vi)
Constructor setting values.
Definition: TriangleMeshWall.h:231
TriangleWall wall
The TriangleWall.
Definition: TriangleMeshWall.h:231
Triangle()=default
Default constructor.
Definition: TriangleMeshWall.h:241
Vertex()=default
Default constructor.
std::vector< std::pair< unsigned, unsigned > > triangleIndices
Definition: TriangleMeshWall.h:254
Vertex(Vec3D P)
Definition: TriangleMeshWall.h:247
Vec3D position
The vertex position.
Definition: TriangleMeshWall.h:247
Definition: BaseWall.h:38