This is an example of how to use the netdem library.
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
void SDFDemo(int argc, char **argv) {
int shape_case;
if (argc == 2) {
shape_case = -1;
} else {
shape_case = atof(argv[2]);
}
switch (shape_case) {
case 0: {
} break;
case 1: {
1.0, 1.2, 0.8);
} break;
case 10: {
} break;
case 11: {
2.0, 2.2, 1.8);
} break;
case 2: {
sh->InitFromSTL("data/particle_template.stl");
sh->SetSize(1.0);
shape = sh;
} break;
case 3: {
trimesh->InitFromSTL("data/copyleft/bolt_nut/bolt.stl");
trimesh->AlignAxes();
trimesh->SetSize(1.0);
shape = trimesh;
} break;
case 4: {
level_set->InitFromSTL("data/particle_template.stl");
level_set->AlignAxes();
level_set->SetSize(1.0);
shape = level_set;
} break;
default: {
trimesh->InitFromSTL("data/copyleft/bolt_nut/bolt.stl");
trimesh->AlignAxes();
trimesh->SetSize(1.0);
shape = trimesh;
} break;
}
string root_dir = "tmp/examples/sdf_dem/sdf_demo/";
filesystem::create_directories(root_dir);
auto stl_model = shape->GetSTLModel(1000);
stl_model.SaveAsSTL(root_dir + "surface.stl");
double mesh_size =
pow(stl_model.GetVolume() / Math::PI * 6.0, 1.0 / 3.0) / 20.0;
TetMesh tetmesh(stl_model.vertices, stl_model.facets, mesh_size);
stl_model.SaveAsSTL(root_dir + "surface_mesh.stl");
for (
auto &node : tetmesh.
nodes) {
dist_list.push_back(shape->SignedDistance(node));
}
dem_profiler.
StartTimer(DEMProfiler::TimerType::custom);
auto [bound_aabb_min, bound_aabb_max] = shape->GetBoundAABB();
int num_trials = 1e3;
auto pos_x_list = uniform_dist_x.
Get(num_trials);
auto pos_y_list = uniform_dist_y.
Get(num_trials);
auto pos_z_list = uniform_dist_z.
Get(num_trials);
for (int i = 0; i < num_trials; i++) {
for (
auto &node : tetmesh.
nodes) {
Vec3d pos{pos_x_list[i], pos_y_list[i], pos_z_list[i]};
shape->SignedDistance(pos);
}
if ((i + 1) % 100 == 0) {
cout << i + 1 << endl;
}
}
dem_profiler.
EndTimer(DEMProfiler::TimerType::custom);
cout <<
"no. nodes queried: " << tetmesh.
nodes.size() << endl;
printf("cost: %f microsecond \n",
dem_profiler.
timer_list[DEMProfiler::TimerType::custom] / 1.0 /
num_trials / tetmesh.
nodes.size());
stringbuf buf;
ostream os(&buf);
os << "POINT_DATA " << dist_list.size() << endl;
os << "SCALARS SDF float 1" << endl;
os << "LOOKUP_TABLE default" << endl;
for (int i = 0; i < dist_list.size(); i++) {
os << dist_list[i] << endl;
}
ofstream outfile;
outfile.open(root_dir + "tetmesh.vtk", ios::app);
if (!outfile) {
cout << "cannot open file: " << root_dir + "tetmesh.vtk" << endl;
}
outfile << buf.str();
outfile.close();
delete shape;
}
A profiler class for measuring performance metrics in a DEM simulation.
Definition dem_profiler.hpp:22
int64t timer_list[TimerType::num_timers]
Definition dem_profiler.hpp:46
void Clear()
Definition dem_profiler.cpp:40
void EndTimer(TimerType t_type)
End a timer for measuring elapsed time.
Definition dem_profiler.cpp:32
void StartTimer(TimerType t_type)
Start a timer for measuring elapsed time.
Definition dem_profiler.cpp:27
A class for representing a level set function as a Shape object.
Definition shape_level_set.hpp:25
A class representing a poly superellipsoid with two different orders and three different axes.
Definition shape_poly_super_ellipsoid.hpp:27
A class representing a poly superquadric with three different axes and orders.
Definition shape_poly_super_quadrics.hpp:30
This class represents different types of shapes and performs various calculations on them.
Definition shape.hpp:15
A class representing a spherical harmonics object.
Definition shape_spherical_harmonics.hpp:24
A class that represents a tetrahedral mesh.
Definition tetmesh.hpp:17
void SaveAsVTK(std::string const &file)
Saves the tetrahedral mesh as a VTK file.
Definition tetmesh.cpp:49
VecXT< Vec3d > surface_nodes
The surface nodes in the mesh.
Definition tetmesh.hpp:35
VecXT< Vec3d > nodes
The nodes in the tetrahedral mesh.
Definition tetmesh.hpp:20
VecXT< Vec3i > surface_facets
The surface facets in the mesh.
Definition tetmesh.hpp:38
A class representing a triangular mesh in 3D space.
Definition shape_trimesh.hpp:23
Definition bond_entry.hpp:7
std::vector< T > VecXT
Definition utils_macros.hpp:31
std::array< double, 3 > Vec3d
Definition utils_macros.hpp:18