MPM-Geomechanics
Material Point Method for simulating geo-materials under large deformation conditions
Loading...
Searching...
No Matches
TerrainContact.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2021-2025 MPM-Geomechanics Development Team
3
4#ifndef TERRAIN_CONTACT_H
5#define TERRAIN_CONTACT_H
6
7#include "Mesh/STLReader.h"
8#include "Mesh/Mesh.h"
9
12
13private:
14
16
18
19 std::vector<double> densityLevelSet;
20
21 std::vector<std::pair<Particle*, Triangle*>> contactPairs;
22
23 double scalingFactor = 2.0;
24
25 bool usePenaltyContact = false;
26
27 double penaltyStiffness = 0.0;
28
29public:
30
31 inline std::vector<std::pair<Particle*, Triangle*>> getContactPairs() const { return contactPairs; }
32
33 TerrainContact(STLReader* mesh, double friction)
34 : stlMesh(mesh), frictionCoefficient(friction) {
35 // initialize density level set
36 size_t npoints = mesh->getTriangles().size();
37 densityLevelSet.resize(npoints, 0.0);
38 }
39
43
46 void particleDistanceLevelSet(Mesh* mesh, vector< Particle* >* particles);
47
51 void nodalDensityLevelSet(Mesh* mesh, vector< Particle* >* particles);
52
57
59 void determineContactPotentialPairs(Mesh* mesh, std::vector< Particle* >* particles);
60
63
65 const std::vector<double>& getTriangleDensityLevelSet() const { return densityLevelSet; }
66
67 // \brief Compute the contact forces
68 // \f$ f_n = -m_p \frac{v_p^n}{dt} e_n \f$
69 // \f$ f_t = -m_p \frac{v_p - v_p^n e_n}{dt} \f$
70 void computeContactForces(double dt);
71
72 // \brief Project particles that have penetrated the STL mesh
73 // If a particle is inside the STL mesh, move it to the surface
74 // \f$ x_projected = x_p - d * e_n \f$
75 void projectParticles(Mesh *mesh, std::vector<Particle *> *particles);
76
79 void setDistanceThreshold(double threshold) { scalingFactor = threshold > 0.0 ? threshold : 2.0; };
80
82 void apply(Mesh* mesh, std::vector<Particle*>* particles, double dt);
83
85 void enablePenaltyContact(bool enable);
86
88 void setPenaltyStiffness(double k);
89};
90
91#endif // TERRAINCONTACT_H
Class representing a rectangular grid mesh.
Definition Mesh.h:26
Class to read STL files.
Definition STLReader.h:57
const std::vector< Triangle > & getTriangles() const
Get the triangles of the STL mesh.
Class to compute terrain contact.
Definition TerrainContact.h:11
void enablePenaltyContact(bool enable)
Enable the penalty contact method.
void nodalDensityLevelSet(Mesh *mesh, vector< Particle * > *particles)
Calculate the nodal density level set function It allows to know the boundary of the body for a cert...
void computeDistanceLevelSetFunction(Mesh *mesh)
compute the distance level set function in nodes It is the distance from the node to the STL mesh
bool usePenaltyContact
Use penalty contact method.
Definition TerrainContact.h:25
void setDistanceThreshold(double threshold)
Set the distance threshold for contact detection.
Definition TerrainContact.h:79
void apply(Mesh *mesh, std::vector< Particle * > *particles, double dt)
Apply the terrain contact algorithm.
double penaltyStiffness
Penalty stiffness for contact forces.
Definition TerrainContact.h:27
const std::vector< double > & getTriangleDensityLevelSet() const
Get the density level set values at triangle centroids.
Definition TerrainContact.h:65
STLReader * getSTLMesh()
Get the triangular mesh.
Definition TerrainContact.h:62
STLReader * stlMesh
triangular mesh for terrain contact
Definition TerrainContact.h:15
std::vector< double > densityLevelSet
density level set function interpolated in centroids of triangles
Definition TerrainContact.h:19
void computeContactForces(double dt)
TerrainContact(STLReader *mesh, double friction)
Definition TerrainContact.h:33
std::vector< std::pair< Particle *, Triangle * > > contactPairs
contact potential pairs
Definition TerrainContact.h:21
double scalingFactor
scaling factor for the distance threshold in contact detection
Definition TerrainContact.h:23
std::vector< std::pair< Particle *, Triangle * > > getContactPairs() const
Definition TerrainContact.h:31
void determineContactPotentialPairs(Mesh *mesh, std::vector< Particle * > *particles)
Determine the contact potential pairs.
void particleDistanceLevelSet(Mesh *mesh, vector< Particle * > *particles)
Interpolate distance level set function value of particle .
double frictionCoefficient
Friction coefficient .
Definition TerrainContact.h:17
void trianglesDensityLevelSet(Mesh *mesh)
Interpolate the density level set function in the centroids of triangles It allows to know the bound...
void setPenaltyStiffness(double k)
Set the penalty stiffness for contact forces.
void projectParticles(Mesh *mesh, std::vector< Particle * > *particles)