Hi everyone:
I make a simulation using DEM method. In my system, there are 100000 particles and one obj container.
Only using CPU parallel is not efficient., so I want to use GPU parallel. When I run the exe file and check GPU usage, it is very strange that the GPU usage don't change and keeps to 0%.
I run the demo (demo_PAR_ballsNSC) and the GPU usage increases to 50%.
I change my project based on the demo_PAR_ballsNSC. But why happens the strange sitution?
Here is my code. Please check!
Best Wishes,
Liu
void AddContainer(ChSystemParallel* sys,std::string filePosition, float cohesion, float KinectFriction, float StaticFriction, float restitution, float damping, float stifness)
{
int binId = -200;
// Create a common material
auto mat = std::make_shared<ChMaterialSurfaceNSC>();
mat->SetCohesion(cohesion);
mat->SetSfriction(StaticFriction);
mat->SetKfriction(KinectFriction);
mat->SetRestitution(restitution);
mat->SetDampingF(damping);
mat->SetCompliance(float(1.0/stifness));
// Create the containing bin (4 x 4 x 1)
auto bin = std::make_shared<ChBody>(std::make_shared<ChCollisionModelParallel>());
bin->SetMaterialSurface(mat);
bin->SetIdentifier(binId);
bin->SetMass(1);
bin->SetDensity(2800);
bin->SetPos(ChVector<>(0, 0, 0));
bin->SetCollide(true);
bin->SetBodyFixed(true);
bin->GetCollisionModel()->ClearModel();
std::string bedFilename = filePosition + "/Slope_Bed.obj";
utils::AddTriangleMeshGeometry(bin.get(), bedFilename.data(), "Slope_Bed");
bin->GetCollisionModel()->BuildModel();
sys->AddBody(bin);
}
// -----------------------------------------------------------------------------
// Create the falling spherical objects in a uniform rectangular grid.
// -----------------------------------------------------------------------------
void AddFallingBalls(ChSystemParallel* sys,std::string filePosition, float KinectFriction, float StaticFriction, float restitution, float cohesion, float damping, float stifness)
{
// Common material
std::string spherefile = filePosition + "/SlideBody.Spheres";
std::fstream spherein(spherefile.data(), std::ios::in);
int sphereNum;
spherein >> sphereNum;
double px, py, pz, pr;
int ballId = 0;
while (spherein >> px >> py >> pz >> pr)
{
auto ballMat = std::make_shared<ChMaterialSurfaceNSC>();
ballMat->SetSfriction(StaticFriction);
ballMat->SetKfriction(KinectFriction);
ballMat->SetRestitution(restitution);
ballMat->SetCohesion(cohesion); // Magnitude of the adhesion in Constant adhesion model
//ballMat->SetAdhesionMultDMT(adhesion);
//ballMat->SetGt(damping);
//ballMat->SetCompliance(1000000);
ballMat->SetDampingF(damping);
ballMat->SetCompliance(float(1.0 / stifness));
// Create the falling balls
ChVector<> pos(px, py, pz);
auto ball = std::make_shared<ChBody>(std::make_shared<ChCollisionModelParallel>());
ball->SetMaterialSurface(ballMat);
ball->SetIdentifier(ballId++);
float density = 2800;
double mmass = density * 4.0*CH_C_PI*pr*pr*pr / 3.0;
ChVector<> inertia = (2.0 / 5.0) * mmass * pr * pr * ChVector<>(1, 1, 1);
ball->SetMass(mmass);
ball->SetInertiaXX(inertia);
ball->SetPos(pos);
ball->SetRot(ChQuaternion<>(1, 0, 0, 0));
ball->SetBodyFixed(false);
ball->SetCollide(true);
ball->GetCollisionModel()->ClearModel();
utils::AddSphereGeometry(ball.get(), pr*1.0);
ball->GetCollisionModel()->BuildModel();
sys->AddBody(ball);
}
spherein.close();
}
// -----------------------------------------------------------------------------
// Create the system, specify simulation parameters, and run simulation loop.
// -----------------------------------------------------------------------------
int main(int argc, char* argv[]) {
int threads = 32;
std::cout << "Start slope slide simulation... Please waiting and watch the tmp file..." << endl;
// Simulation parameters (I delete that for your reading)
// ---------------------
// Create system
// -------------
ChSystemParallelNSC msystem;
// Set number of threads.
int max_threads = CHOMPfunctions::GetNumProcs();
//std::cout << "Max threads: " << max_threads << std::endl;
if (threads > max_threads)
threads = max_threads;
msystem.SetParallelThreadNumber(threads);
CHOMPfunctions::SetNumThreads(threads);
// Set gravitational acceleration
msystem.Set_G_acc(ChVector<>(gravityX, gravityY, gravityZ));
// Set solver parameters
msystem.GetSettings()->solver.solver_mode = SolverMode::SLIDING;
msystem.GetSettings()->solver.max_iteration_bilateral = max_iteration;
msystem.GetSettings()->solver.tolerance = tolerance;
msystem.GetSettings()->solver.contact_recovery_speed = 10000;
msystem.GetSettings()->solver.use_full_inertia_tensor = false;
msystem.GetSettings()->collision.narrowphase_algorithm = NarrowPhaseType::NARROWPHASE_HYBRID_MPR;
msystem.GetSettings()->collision.bins_per_axis = vec3(100, 100, 100);
msystem.GetSettings()->collision.collision_envelope = dvi_evelope;
// Create the fixed and moving bodies
// ----------------------------------
AddFallingBalls(&msystem, filePosition, Kmu, Smu, restitution, cohesion1, dampCoe, stifness1);
AddContainer(&msystem, filePosition, cohesion2, Kmu, Smu, restitution, dampCoe, stifness2);
// Perform the simulation
// ----------------------
for (int i = 0; i < num_steps; i++) {
msystem.DoStepDynamics(timestep);
if (i%out_steps == 0)
{
SaveData(&msystem, out_frame,filePosition);
out_frame++;
}
if (i % change_step == 0)
{
for (int i = 0; i < msystem.data_manager->host_data.contact_pairs.size(); i++)
{
if (msystem.data_manager->host_data.dpth_rigid_rigid[i] >= 2 * dvi_evelope*0.75)
{
msystem.Get_bodylist()->at(msystem.data_manager->host_data.bids_rigid_rigid[i].x)->GetMaterialSurfaceNSC()->SetCohesion(0);
msystem.Get_bodylist()->at(msystem.data_manager->host_data.bids_rigid_rigid[i].y)->GetMaterialSurfaceNSC()->SetCohesion(0);
}
}
}
time += timestep;
}
return 0;
}