NetDEM v1.0
Loading...
Searching...
No Matches
0_plane_case.cpp

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

#include "data_dumper.hpp"
#include "gen_pack.hpp"
#include "gravity.hpp"
#include "shape_sphere.hpp"
#include "simulation.hpp"
#include <iostream>
#include <unordered_map>
using namespace netdem;
using namespace std;
int PlaneCase(int argc, char **argv) {
int self_rank, total_rank;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &self_rank);
MPI_Comm_size(MPI_COMM_WORLD, &total_rank);
Simulation *sim = new Simulation();
sim->domain_manager.SetBound(-0.6, -0.6, -1.2, 0.6, 0.6, 1.2);
sim->domain_manager.SetDecomposition(total_rank, 1, 1);
sim->domain_manager.SetCellSpacing(0.3, 0.3, 0.3);
LinearSpring cnt_model = LinearSpring(2.0e6, 1.0e6, 0.5, 0.0);
sim->scene.InsertContactModel(&cnt_model);
sim->scene.SetCollisionModel(0, 0, cnt_model.label);
Sphere sphere_1 = Sphere(0.1);
Sphere sphere_2 = Sphere(0.1);
sim->scene.InsertShape(&sphere_1);
sim->scene.InsertShape(&sphere_2);
VecXT<Particle> particle_list = PackGenerator::GetGridPack(
1, 1, 2, 0, 0, 0, 9, 9, 18, sim->scene.GetShapes());
for (auto &p : particle_list) {
p.damp_numerical = 0.7;
}
sim->scene.InsertParticle(particle_list);
WallBoxPlane wall_box(1, 1, 2, 0, 0, 0);
wall_box.ImportToScene(&(sim->scene));
Gravity grav;
grav.Init(sim);
sim->modifier_manager.Insert(&grav);
DataDumper data_dumper;
data_dumper.Init(sim);
data_dumper.SetRootPath("tmp/out/");
data_dumper.SetSaveByCycles(100);
data_dumper.dump_wall_info = true;
data_dumper.dump_shape_info = true;
sim->modifier_manager.Insert(&data_dumper);
sim->modifier_manager.Enable(data_dumper.label);
// servo control for top wall
WallServoControl servo_top(2e6, 1.0);
servo_top.label = "servo_top";
servo_top.enable_auto_area = true;
servo_top.Init(sim);
servo_top.target_pressure = 1e2;
servo_top.SetWall({5});
auto tmp = sim->modifier_manager.Insert(&servo_top);
sim->modifier_manager.Enable(servo_top.label);
auto servo_top_ptr = static_cast<WallServoControl *>(tmp);
sim->Run(2);
// servo control for lateral walls
servo_top_ptr->target_pressure = 1e5;
WallServoControl servo_lateral(2e6, 1.0);
servo_lateral.label = "servo_lateral";
servo_lateral.enable_auto_area = true;
servo_lateral.Init(sim);
servo_lateral.target_pressure = 1e5;
servo_lateral.SetWall({0, 1, 2, 3});
tmp = sim->modifier_manager.Insert(&servo_lateral);
sim->modifier_manager.Enable(servo_lateral.label);
auto servo_lateral_ptr = static_cast<WallServoControl *>(tmp);
// keep loading until target pressure is achieved
do {
sim->Run(1);
} while (!servo_top_ptr->achieved | !servo_lateral.achieved);
// disable servo control of the top wall
sim->modifier_manager.Disable(servo_top.label);
servo_lateral_ptr->enable_warning = true;
// add deformation drived loading for top wall
WallMotionControl disp_control;
disp_control.Init(sim);
disp_control.SetWall({5});
disp_control.SetVelocity(0, 0, -0.1);
sim->modifier_manager.Insert(&disp_control);
sim->modifier_manager.Enable(disp_control.label);
sim->Run(2);
delete sim;
MPI_Finalize();
return 0;
}
std::string label
Definition contact_model.hpp:34
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
bool dump_shape_info
A flag that determines whether to dump shape information.
Definition data_dumper.hpp:29
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
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
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
void SetCellSpacing(double s_x, double s_y, double s_z)
Sets the spacing between cells in each dimension.
Definition domain_manager.cpp:105
void SetDecomposition(int num_div_x, int num_div_y, int num_div_z)
Sets the number of domain divisions in each dimension.
Definition domain_manager.cpp:96
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
Contact model that uses linear spring elements to evaluate contact forces and moments.
Definition model_linear_spring.hpp:16
std::string label
Definition modifier.hpp:20
virtual void Init(Simulation *sim)
Initializes the Modifier instance.
Definition modifier.cpp:11
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.
void Disable(std::string const &label)
Disables 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
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
Class for managing a DEM simulation.
Definition simulation.hpp:21
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 representing a sphere.
Definition shape_sphere.hpp:17
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
void SetWall(int id)
Sets the walls based on a wall ID.
Definition wall_group.cpp:56
A class used to control the displacement of walls in a DEM simulation.
Definition wall_motion_control.hpp:16
void SetVelocity(double v_x, double v_y, double v_z)
Sets the velocity properties for all walls in the group.
Definition wall_motion_control.cpp:15
A class used to control the pressure of walls in a DEM simulation.
Definition wall_servo_control.hpp:17
double target_pressure
Target pressure.
Definition wall_servo_control.hpp:24
bool enable_auto_area
A flag indicating whether to automaticaly calculate the contact area from the particles.
Definition wall_servo_control.hpp:36
bool achieved
A flag indicating if target pressure is achieved.
Definition wall_servo_control.hpp:29
Definition bond_entry.hpp:7
std::vector< T > VecXT
Definition utils_macros.hpp:31