This is an example of how to use the netdem library.
#include <filesystem>
#include <fstream>
#include <iostream>
#include <random>
#include <sstream>
#include <string>
using namespace std;
stringbuf buf;
ostream os(&buf);
int os_width = 24;
os.setf(ios::scientific);
os.precision(15);
for (auto &data_row : data) {
for (int j = 0; j < data_row.size() - 1; j++) {
os.width(os_width);
os << data_row[j] << ", ";
}
os.width(os_width);
os << data_row.back() << endl;
}
ofstream outfile;
outfile.open(filename);
if (!outfile) {
cout << "cannot open or create file: " << filename << endl;
abort();
}
outfile << buf.str();
outfile.close();
cout << "data saved to: " << filename << endl;
}
void ContactTestSphere(int potential_case, int surface_node_num) {
sh.
a_nm[0] = sqrt(Math::PI);
cout <<
"shape size: " << sh.
GetSize() << endl;
cout << "particle created ... " << endl;
double dt = 1.0e-4;
for (int i = 0; i < 61; i++) {
cnt_solver.
Init(&obj_p2, &obj_p1);
if (cnt == nullptr) {
} else {
}
<< obj_p2.
force[0] <<
", " << obj_p2.
force[1] <<
", "
}
}
for (int i = 0; i < 61; i++) {
obj_p2.
SetPosition(0, 0, 1.01 - 60 * 0.001 + i * 0.001);
cnt_solver.
Init(&obj_p2, &obj_p1);
if (cnt == nullptr) {
} else {
}
<< obj_p2.
force[0] <<
", " << obj_p2.
force[1] <<
", "
}
}
string root_dir = "tmp/examples/sdf_dem/contact_test/";
filesystem::create_directories(root_dir);
switch (potential_case) {
case SolverSDFPP::PotentialType::linear:
SaveDataset(root_dir + "sphere_linear.txt", cnt_data);
break;
case SolverSDFPP::PotentialType::hertz:
SaveDataset(root_dir + "sphere_hertz.txt", cnt_data);
break;
default:
SaveDataset(root_dir + "sphere_hertz.txt", cnt_data);
break;
}
if (cnt != nullptr) {
delete cnt;
cnt = nullptr;
}
}
Contact model that uses linear spring elements to evaluate contact forces and moments.
Definition model_linear_spring.hpp:16
Definition particle.hpp:26
virtual void ClearMoment()
Clear all moments applied to the particle.
Definition particle.cpp:180
virtual void SetRodrigues(double angle, double axis_x, double axis_y, double axis_z)
Sets the orientation of the particle using a Rodrigues rotation vector.
Definition particle.cpp:95
virtual void SetPosition(double pos_x, double pos_y, double pos_z)
Sets the position of the particle.
Definition particle.cpp:83
Vec3d pos
The position of the particle.
Definition particle.hpp:103
virtual void ClearForce()
Clear all forces applied to the particle.
Definition particle.cpp:174
Vec3d moment
The moment acting on the particle.
Definition particle.hpp:138
Vec3d force
The force acting on the particle.
Definition particle.hpp:133
virtual void EnableSurfaceNodes()
Enable the use of surface nodes.
Definition shape.cpp:284
virtual void SetSurfaceNodeNum(int num)
Set number of surface nodes of the shape.
Definition shape.cpp:298
virtual double GetSize() const
Return shape size, which is defined as the diameter of equal-volume sphere.
Definition shape.cpp:116
Signed distance field-based contact solver.
Definition solver_sdf_pp.hpp:19
void ResolveUpdate(ContactPP *const cnt, double timestep) override
Updates the contact resolution for a contact point.
Definition solver_sdf_pp.cpp:191
int potential_type
Whether to solve both sides of the collision.
Definition solver_sdf_pp.hpp:31
bool Detect() override
Detects collisions between particles.
Definition solver_sdf_pp.cpp:73
void ResolveInit(ContactPP *const cnt, double timestep) override
Initializes the contact resolution for a contact point.
Definition solver_sdf_pp.cpp:163
void Init(Particle *const p1, Particle *const p2) override
Initializes the collision solver with two particles.
Definition solver_sdf_pp.cpp:18
A class representing a spherical harmonics object.
Definition shape_spherical_harmonics.hpp:24
VecXT< double > a_nm
Definition shape_spherical_harmonics.hpp:27
void UpdateShapeProperties() override
Update the shape properties of the SphericalHarmonics object.
Definition shape_spherical_harmonics.cpp:129
Definition bond_entry.hpp:7
std::vector< T > VecXT
Definition utils_macros.hpp:31
len_n
Definition json_serilization.hpp:20