NetDEM v1.0
Loading...
Searching...
No Matches
00_hertz_contact.cpp

This is an example of how to use the netdem library.

#include "shape_sphere.hpp"
#include <filesystem>
#include <string>
using namespace netdem;
using namespace std;
void HertzContact() {
TriMesh trimesh;
trimesh.InitFromSTL("data/sphere.stl");
trimesh.SetSize(1.0);
p.SetShape(&trimesh);
Plane plane_1(0, 0, -0.45, 0, 0, 1);
Wall w_1 = Wall(&plane_1);
Plane plane_2(0, 0, 0.45, 0, 0, -1);
Wall w_2 = Wall(&plane_2);
LinearSpring cnt_model = LinearSpring(2.0e6, 0.0, 0.0, 0.0);
SolverSDFPW cnt_solver(&p, &w_1);
cnt_solver.potential_type = 0;
double dt = 1.0e-4;
p.fem_simulator.timestep = 1.0e-5;
string root_dir = "tmp/examples/deformable_particle/hertz_contact/";
filesystem::create_directories(root_dir);
p.SaveAsVTK(root_dir + "particle_000.vtk");
double fz = 0;
for (int ti = 0; ti < 100; ti++) {
for (int tj = 0; tj < 50; tj++) {
cnt_solver.Init(&p, &w_1);
if (cnt_solver.Detect()) {
ContactPW cnt = ContactPW(&p, &w_1);
cnt.SetCollisionModel(&cnt_model);
cnt_solver.ResolveInit(&cnt, dt);
cnt.EvaluateForces(dt);
for (int ii = 0; ii < cnt.collision_entries.size(); ii++) {
p.AddForce(cnt.collision_entries[ii].cnt_geoms.node_id,
cnt.collision_entries[ii].cnt_forces.force);
}
}
cnt_solver.Init(&p, &w_2);
fz = 0;
if (cnt_solver.Detect()) {
ContactPW cnt = ContactPW(&p, &w_2);
cnt.SetCollisionModel(&cnt_model);
cnt_solver.ResolveInit(&cnt, dt);
cnt.EvaluateForces(dt);
for (int ii = 0; ii < cnt.collision_entries.size(); ii++) {
p.AddForce(cnt.collision_entries[ii].cnt_geoms.node_id,
cnt.collision_entries[ii].cnt_forces.force);
fz += cnt.collision_entries[ii].cnt_forces.force[2];
}
}
p.UpdateMotion(dt);
}
cout << "contact force z:" << abs(fz) << endl;
char filename[128];
snprintf(filename, 128, "particle_%03d.vtk", ti + 1);
p.SaveAsVTK(root_dir + filename);
}
}
A class representing a contact between a particle and a wall.
Definition contact_pw.hpp:22
VecXT< CollisionEntry > collision_entries
A list of CollisionEntry objects representing the collision geometries used by the contact model.
Definition contact_pw.hpp:49
void SetCollisionModel(ContactModel *const cnt_model)
Set the collision model used to calculate collision forces between the particle and the wall.
Definition contact_pw.cpp:22
void EvaluateForces(double dt)
Calculate and apply the contact forces and moments between the particle and the wall.
Definition contact_pw.cpp:30
A class representing a deformable particle simulated using the Finite Element Method (FEM).
Definition deformable_particle.hpp:21
void ClearForce() override
Clears all forces on the particle's mesh.
Definition deformable_particle.cpp:150
void UpdateMotion(double dt) override
Updates the motion of the particle.
Definition deformable_particle.cpp:183
void SetShape(Shape *s) override
Sets the shape of the particle.
Definition deformable_particle.cpp:21
void SaveAsVTK(std::string const &filename) override
Saves the particle as a VTK file.
Definition deformable_particle.cpp:269
void AddForce(int node_id, Vec3d const &f)
Adds a force to a node on the particle's mesh.
Definition deformable_particle.cpp:135
FEMSimulator fem_simulator
The FEM simulator object used to simulate the particle.
Definition deformable_particle.hpp:30
double timestep
The time step used in the simulation.
Definition fem_simulator.hpp:36
Vec3d gravity_coef
The gravitational force acting on the object.
Definition fem_simulator.hpp:33
Contact model that uses linear spring elements to evaluate contact forces and moments.
Definition model_linear_spring.hpp:16
A class for representing a plane with a center point and normal vector.
Definition shape_plane.hpp:22
A class used to solve collisions between a particle and a wall using a signed distance field.
Definition solver_sdf_pw.hpp:18
bool Detect() override
Detects if there is a collision between the particle and the wall.
Definition solver_sdf_pw.cpp:71
void ResolveInit(ContactPW *const cnt, double timestep) override
Resolves the collision based on the initial contact information and timestep.
Definition solver_sdf_pw.cpp:171
void Init(Particle *const p, Wall *const w) override
Initializes the SolverSDFPW instance with the given particles and walls.
Definition solver_sdf_pw.cpp:16
int potential_type
Whether to solve both sides of the collision.
Definition solver_sdf_pw.hpp:30
A class representing a triangular mesh in 3D space.
Definition shape_trimesh.hpp:23
void InitFromSTL(std::string const &file)
Initialize the TriMesh object from an STL file.
void SetSize(double d) override
Set the size of the TriMesh object.
Definition shape_trimesh.cpp:207
A class representing a wall object in a physics simulation.
Definition wall.hpp:32
Definition bond_entry.hpp:7