NetDEM v1.0
Loading...
Searching...
No Matches
92_angle_of_repose.cpp

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

#include "data_dumper.hpp"
#include "gen_pack.hpp"
#include "gravity.hpp"
#include "simulation.hpp"
#include <iostream>
#include <unordered_map>
using namespace netdem;
using namespace std;
void AngleOfRepose(int argc, char **argv) {
// new simulation
Simulation *sim = new Simulation();
// domain settings
sim->domain_manager.SetBound(-0.1, -0.1, -0.05, 0.1, 0.1, 0.13);
auto domain = sim->domain_manager.GetSelfSubDomain();
domain->cell_manager.SetSpacing(0.02, 0.02, 0.02);
// define contact model
VolumeBased cnt_model = VolumeBased(1.0e16, 1.0e5, 0.5, 0.0);
sim->scene.InsertContactModel(&cnt_model);
sim->scene.SetCollisionModel(0, 0, cnt_model.label);
// shape template
TriMesh tri_mesh;
tri_mesh.InitFromSTL("data/particle_template.stl");
tri_mesh.Decimate(200);
tri_mesh.AlignAxes();
tri_mesh.SetSize(0.003);
sim->scene.InsertShape(&tri_mesh);
// get a pack of particles
VecXT<Particle> particle_list = PackGenerator::GetGridPack(
0.04, 0.04, 0.04, 0, 0, 0.10, 8, 8, 8, sim->scene.GetShapes());
for (auto &p : particle_list) {
p.SetDensity(265000);
p.damp_numerical = 0.7;
}
// get a box of wall with plane shapes, and insert the wall and shapes into
// the scene
WallBoxPlane wall_box(0.04, 0.04, 0.16, 0, 0, 0.04);
wall_box.ImportToScene(&(sim->scene));
// manipulate the solver settings
string root_dir = "local/examples/netdem/ann_models/";
SolverANNPP cnt_solver_pp;
cnt_solver_pp.Init(root_dir + "trimesh_trimesh/ann_classifier.xml",
root_dir + "trimesh_trimesh/ann_regressor.xml");
SolverANNPPlane cnt_solver_pw;
cnt_solver_pw.Init(root_dir + "trimesh_plane/ann_classifier.xml",
root_dir + "trimesh_plane/ann_regressor.xml");
int solver_id_pp =
int solver_id_pw =
auto shape_list = sim->scene.GetShapes();
for (auto shape_ptr_1 : shape_list) {
for (auto shape_ptr_2 : shape_list) {
if (shape_ptr_1->shape_type == Shape::Type::trimesh &&
shape_ptr_2->shape_type == Shape::Type::trimesh) {
shape_ptr_1->use_customized_solver = true;
shape_ptr_2->use_customized_solver = true;
shape_ptr_1->id, shape_ptr_2->id, solver_id_pp);
} else if (shape_ptr_1->shape_type == Shape::Type::trimesh &&
shape_ptr_2->shape_type == Shape::Type::plane) {
shape_ptr_1->use_customized_solver = true;
shape_ptr_2->use_customized_solver = true;
shape_ptr_1->id, shape_ptr_2->id, solver_id_pw);
}
}
}
// add a gravity modifier
Gravity grav;
grav.Init(sim);
sim->modifier_manager.Insert(&grav);
// add a data dumper modifier
DataDumper data_dumper;
data_dumper.Init(sim);
data_dumper.SetRootPath("tmp/netdem/angle_repose/");
data_dumper.SetSaveByCycles(1000);
data_dumper.SaveShapeInfoAsSTL();
data_dumper.dump_wall_info = true;
data_dumper.dump_contact_info = true;
sim->modifier_manager.Insert(&data_dumper);
sim->modifier_manager.Enable(data_dumper.label);
// random packing
sim->dem_solver.timestep = 1e-4;
for (int i = 0; i < 10; i++) {
sim->scene.InsertParticle(particle_list);
sim->Run(0.1);
}
sim->Run(0.5);
// remove the side and top walls
// reposing process
sim->Run(20);
delete sim;
MPI_Finalize();
}
void SetSpacing(double s_x, double s_y, double s_z)
Set the spacing between adjacent cells in the simulation grid.
Definition cell_manager.cpp:94
std::string label
Definition contact_model.hpp:34
void CustomizeSolverPP(int shape_id1, int shape_id2, int solver_id)
Customize the collision solver used for a given pair of particle shapes.
Definition contact_solver_factory.cpp:204
void CustomizeSolverPW(int shape_id1, int shape_id2, int solver_id)
Customize the collision solver used for a given pair of particle and wall shapes.
Definition contact_solver_factory.cpp:209
int InsertSolver(CollisionSolverPP *const cnt_solver)
Insert a custom collision solver into the factory.
Definition contact_solver_factory.cpp:195
double timestep
Definition dem_solver.hpp:42
ContactSolverFactory contact_solver_factory
Definition dem_solver.hpp:50
A class used to dump particle data into vtk files. This is a post-modifier, which will be executed at...
Definition data_dumper.hpp:12
void Init(Simulation *sim) override
Initializes the DataDumper instance.
Definition data_dumper.cpp:24
bool dump_wall_info
A flag that determines whether to dump wall information.
Definition data_dumper.hpp:21
bool dump_contact_info
A flag that determines whether to dump contact information.
Definition data_dumper.hpp:25
void SaveShapeInfoAsSTL()
Saves shape information as an STL file.
Definition data_dumper.cpp:2245
void SetSaveByCycles(double interval)
Sets the interval for saving data by cycles.
Definition data_dumper.cpp:39
void SetRootPath(std::string const &root_path)
Sets the root directory path for the output file.
Definition data_dumper.cpp:26
CellManager cell_manager
Manages the cells, which are used in the borad-phase contact detection.
Definition domain.hpp:58
void SetBound(double bmin_x, double bmin_y, double bmin_z, double bmax_x, double bmax_y, double bmax_z)
Sets the lower and upper bounds of the domain.
Definition domain_manager.cpp:83
Domain * GetSelfSubDomain()
Returns a pointer to the sub-domain that belongs to this process.
Definition domain_manager.cpp:124
A class used to apply gravity to particles in a DEM simulation.
Definition gravity.hpp:10
void Init(Simulation *sim) override
Initializes the Gravity instance.
Definition gravity.cpp:14
std::string label
Definition modifier.hpp:20
Modifier * Insert(Modifier *e)
Inserts new modifier into the simulation.
Definition modifier_manager.cpp:17
void Enable(std::string const &label)
Enables a modifier in the simulation.
ContactModel * InsertContactModel(const ContactModel *const cm_ptr)
Insert a contact model into this scene.
Definition scene.cpp:290
void SetNumberOfMaterials(int num)
Set the number of materials in this scene and initialize the contact lookup table accordingly.
Definition scene.cpp:346
Shape * InsertShape(const Shape *const s_ptr)
Insert a single shape into this scene.
Definition scene.cpp:19
void SetCollisionModel(int mat_type_1, int mat_type_2, ContactModel *const cnt_model)
Set the collision model between two materials.
Definition scene.cpp:397
void RemoveWall(Wall *w_ptr)
Remove the given wall from this scene.
Definition scene.cpp:262
Particle * InsertParticle(const Particle *const p_ptr)
Insert a single particle into this scene.
Definition scene.cpp:76
VecXT< Shape * > GetShapes()
Return a vector of pointers to all shapes in this scene.
Definition scene.cpp:316
VecXT< Wall * > wall_list
A list of pointers to all walls assumed to exist in this scene. No MPI transfer is performed on wall ...
Definition scene.hpp:71
Class for managing a DEM simulation.
Definition simulation.hpp:21
DEMSolver dem_solver
Implements DEM algorithms to solve the scene.
Definition simulation.hpp:47
void Run(double time)
Runs the simulation for a specified period of time.
Definition simulation.cpp:28
DomainManager domain_manager
Manager for domain and sub-domain calculations.
Definition simulation.hpp:31
ModifierManager modifier_manager
Manages add-on features (i.e., customized evaluations not hard-coded in the DEM calculation cycle).
Definition simulation.hpp:53
Scene scene
Contains and manages basic DEM objects (e.g., shapes, particles, walls) for a DEM simulation.
Definition simulation.hpp:42
A class that represents a collision solver using artificial neural networks.
Definition solver_ann_pp.hpp:28
void Init(std::string const &classifier_file, std::string const &regressor_file)
Initializes the collision solver with neural network models from disk.
A class that represents a collision solver between a particle and a plane using artificial neural net...
Definition solver_ann_pplane.hpp:28
void Init(std::string const &classifier_file, std::string const &regressor_file)
Initializes the collision solver with neural network models from disk.
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 Decimate(int num_nodes)
Decimate the TriMesh object.
Definition shape_trimesh.cpp:121
void AlignAxes()
Align the axes of the TriMesh object.
Definition shape_trimesh.cpp:107
void SetSize(double d) override
Set the size of the TriMesh object.
Definition shape_trimesh.cpp:207
Contact model that evaluates forces and moments based on volume overlap and relative velocity.
Definition model_volume_based.hpp:13
A class for generating a box of six walls.
Definition gen_wall_box_plane.hpp:23
void ImportToScene(Scene *scene)
Imports the shapes and walls generated by the wall box into a scene.
Definition gen_wall_box_plane.hpp:102
Definition bond_entry.hpp:7
std::vector< T > VecXT
Definition utils_macros.hpp:31