void RunTimeStep(T* mSys, const int frame) { if (mSys->GetNbodies() < max_particles) { if (frame % int(100*particle_radius/.2) == 0) { layer_gen->addPerturbedVolumeMixture(R3(0, 0, 0), I3(100, 1, 100), R3(.1, 0, .1), R3(0, -5, 0)); } } ang -= CH_C_PI * timestep / 2.0; if (ang <= 0) { ang = 2 * CH_C_PI; } Quaternion q1; q1.Q_from_AngY(ang); spinner->SetPos(Vector(0, container_height - container_size.y + 2, 0)); spinner->SetPos_dt(Vector(0, 0, 0)); //spinner->SetRot(q1); //spinner->SetWvel_loc(Vector(0, -CH_C_PI / 2.0, 0)); }
int main(int argc, char* argv[]) { bool visualize = true; int threads = 8; int config = 0; real gravity = -9.81; //acceleration due to gravity real timestep = .01; //step size real time_to_run = 1; //length of simulation real current_time = 0; int num_steps = time_to_run / timestep; int max_iteration = 15; int tolerance = 0; //========================================================================================================= // Create system //========================================================================================================= ChSystemParallel * system_gpu = new ChSystemParallel; //========================================================================================================= // Populate the system with bodies/constraints/forces/etc. //========================================================================================================= ChVector<> lpos(0, 0, 0); ChQuaternion<> quat(1, 0, 0, 0); real container_width = 5; //width of area with particles real container_length = 25; //length of area that roller will go over real container_thickness = .25; //thickness of container walls real container_height = 2; //height of the outer walls real particle_radius = .58; // Create a material (will be used by both objects) ChSharedPtr<ChMaterialSurface> material; material = ChSharedPtr<ChMaterialSurface>(new ChMaterialSurface); material->SetFriction(0.4); // Create a ball ChSharedBodyPtr ball = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel)); InitObject(ball, 1, // mass ChVector<>(0, 10, 0), // position ChQuaternion<>(1, 0, 0, 0), // rotation material, // material true, // collide? false, // static? -15, -15); // collision family ball->SetPos_dt(ChVector<>(0,0,10)); AddCollisionGeometry(ball, SPHERE, particle_radius, lpos, quat); FinalizeObject(ball, (ChSystemParallel *) system_gpu); // Create a bin for the ball to fall into ChSharedBodyPtr bin = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel)); InitObject(bin, 1, // mass ChVector<>(0, 0, 0), // position ChQuaternion<>(1, 0, 0, 0), // rotation material, // material true, // collide? true, // static? -20, -20); // collision family AddCollisionGeometry(bin, BOX, ChVector<>(container_width, container_thickness, container_length), lpos, quat); AddCollisionGeometry(bin, BOX, Vector(container_thickness, container_height, container_length), Vector(-container_width + container_thickness, container_height, 0), quat); AddCollisionGeometry(bin, BOX, Vector(container_thickness, container_height, container_length), Vector(container_width - container_thickness, container_height, 0), quat); AddCollisionGeometry(bin, BOX, Vector(container_width, container_height, container_thickness), Vector(0, container_height, -container_length + container_thickness), quat); AddCollisionGeometry(bin, BOX, Vector(container_width, container_height, container_thickness), Vector(0, container_height, container_length - container_thickness), quat); FinalizeObject(bin, (ChSystemParallel *) system_gpu); //========================================================================================================= // Edit system settings //========================================================================================================= system_gpu->SetIntegrationType(ChSystem::INT_ANITESCU); system_gpu->SetParallelThreadNumber(threads); system_gpu->SetMaxiter(max_iteration); system_gpu->SetIterLCPmaxItersSpeed(max_iteration); system_gpu->SetTol(1e-3); system_gpu->SetTolSpeeds(1e-3); system_gpu->Set_G_acc(ChVector<>(0, gravity, 0)); system_gpu->SetStep(timestep); ((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetMaxIteration(max_iteration); ((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetTolerance(0); ((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetCompliance(0, 0, 0); ((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetContactRecoverySpeed(300); ((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetSolverType(ACCELERATED_PROJECTED_GRADIENT_DESCENT); ((ChCollisionSystemParallel *) (system_gpu->GetCollisionSystem()))->SetCollisionEnvelope(particle_radius * .05); ((ChCollisionSystemParallel *) (system_gpu->GetCollisionSystem()))->setBinsPerAxis(R3(10, 10, 10)); ((ChCollisionSystemParallel *) (system_gpu->GetCollisionSystem()))->setBodyPerBin(100, 50); omp_set_num_threads(threads); //========================================================================================================= // Enter the time loop and render the simulation //========================================================================================================= if (visualize) { ChOpenGLManager * window_manager = new ChOpenGLManager(); ChOpenGL openGLView(window_manager, system_gpu, 800, 600, 0, 0, "Test_Solvers"); openGLView.render_camera->camera_pos = Vector(0, 5, -20); openGLView.render_camera->look_at = Vector(0, 0, 0); openGLView.SetCustomCallback(RunTimeStep); openGLView.StartSpinning(window_manager); window_manager->CallGlutMainLoop(); } return 0; }
int main(int argc, char* argv[]) { omp_set_num_threads(4); //========================================================================================================= ChSystemGPU * system_gpu = new ChSystemGPU; ChCollisionSystemGPU *mcollisionengine = new ChCollisionSystemGPU(); system_gpu->SetIntegrationType(ChSystem::INT_ANITESCU); //========================================================================================================= system_gpu->SetMaxiter(max_iter); system_gpu->SetIterLCPmaxItersSpeed(max_iter); ((ChLcpSolverGPU *) (system_gpu->GetLcpSolverSpeed()))->SetMaxIteration(max_iter); system_gpu->SetTol(0); system_gpu->SetTolSpeeds(0); ((ChLcpSolverGPU *) (system_gpu->GetLcpSolverSpeed()))->SetTolerance(0); ((ChLcpSolverGPU *) (system_gpu->GetLcpSolverSpeed()))->SetCompliance(0, 0, 0); ((ChLcpSolverGPU *) (system_gpu->GetLcpSolverSpeed()))->SetContactRecoverySpeed(5); ((ChLcpSolverGPU *) (system_gpu->GetLcpSolverSpeed()))->SetSolverType(ACCELERATED_PROJECTED_GRADIENT_DESCENT); ((ChCollisionSystemGPU *) (system_gpu->GetCollisionSystem()))->SetCollisionEnvelope(particle_radius.x * .05); mcollisionengine->setBinsPerAxis(R3(num_per_dir.x * 2, num_per_dir.y * 2, num_per_dir.z * 2)); mcollisionengine->setBodyPerBin(100, 50); system_gpu->Set_G_acc(ChVector<>(0, gravity, 0)); system_gpu->SetStep(timestep); //========================================================================================================= cout << num_per_dir.x << " " << num_per_dir.y << " " << num_per_dir.z << " " << num_per_dir.x * num_per_dir.y * num_per_dir.z << endl; //addPerturbedLayer(R3(0, -5 +container_thickness-particle_radius.y, 0), ELLIPSOID, particle_radius, num_per_dir, R3(.01, .01, .01), 10, 1, system_gpu); addHCPCube(num_per_dir.x, num_per_dir.y, num_per_dir.z, 1, particle_radius.x, 1, true, 0, -6 +container_thickness+particle_radius.y, 0, 0, system_gpu); //========================================================================================================= ChSharedBodyPtr L = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel)); ChSharedBodyPtr R = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel)); ChSharedBodyPtr F = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel)); ChSharedBodyPtr B = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel)); ChSharedBodyPtr Bottom = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel)); InitObject(L, 100000, Vector(-container_size.x + container_thickness, container_height - container_thickness, 0), Quaternion(1, 0, 0, 0), container_friction, container_friction, 0, true, true, -20, -20); InitObject(R, 100000, Vector(container_size.x - container_thickness, container_height - container_thickness, 0), Quaternion(1, 0, 0, 0), container_friction, container_friction, 0, true, true, -20, -20); InitObject(F, 100000, Vector(0, container_height - container_thickness, -container_size.z + container_thickness), Quaternion(1, 0, 0, 0), container_friction, container_friction, 0, true, true, -20, -20); InitObject(B, 100000, Vector(0, container_height - container_thickness, container_size.z - container_thickness), Quaternion(1, 0, 0, 0), container_friction, container_friction, 0, true, true, -20, -20); InitObject(Bottom, 100000, Vector(0, container_height - container_size.y, 0), Quaternion(1, 0, 0, 0), container_friction, container_friction, 0, true, true, -20, -20); AddCollisionGeometry(L, BOX, Vector(container_thickness, container_size.y, container_size.z), Vector(0, 0, 0), Quaternion(1, 0, 0, 0)); AddCollisionGeometry(R, BOX, Vector(container_thickness, container_size.y, container_size.z), Vector(0, 0, 0), Quaternion(1, 0, 0, 0)); AddCollisionGeometry(F, BOX, Vector(container_size.x, container_size.y, container_thickness), Vector(0, 0, 0), Quaternion(1, 0, 0, 0)); AddCollisionGeometry(B, BOX, Vector(container_size.x, container_size.y, container_thickness), Vector(0, 0, 0), Quaternion(1, 0, 0, 0)); AddCollisionGeometry(Bottom, BOX, Vector(container_size.x, container_thickness, container_size.z), Vector(0, 0, 0), Quaternion(1, 0, 0, 0)); FinalizeObject(L, (ChSystemGPU *) system_gpu); FinalizeObject(R, (ChSystemGPU *) system_gpu); FinalizeObject(F, (ChSystemGPU *) system_gpu); FinalizeObject(B, (ChSystemGPU *) system_gpu); FinalizeObject(Bottom, (ChSystemGPU *) system_gpu); impactor = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel)); InitObject(impactor, 1500, Vector(-container_size.x,container_height + container_size.y*2,0), Quaternion(1, 0, 0, 0), 1, 1, 0, true, false, -1, -2); AddCollisionGeometry(impactor, SPHERE, ChVector<>(.5,0,0), Vector(0, 0, 0), Quaternion(1, 0, 0, 0)); FinalizeObject(impactor, (ChSystemGPU *) system_gpu); impactor->SetPos_dt(Vector(2.5,0,0)); //========================================================================================================= //////Rendering specific stuff: // ChOpenGLManager * window_manager = new ChOpenGLManager(); // ChOpenGL openGLView(window_manager, system_gpu, 800, 600, 0, 0, "Test_Solvers"); // openGLView.render_camera->camera_position = glm::vec3(0, -5, -10); // openGLView.render_camera->camera_look_at = glm::vec3(0, -5, 0); // openGLView.render_camera->camera_scale = .1; // openGLView.SetCustomCallback(RunTimeStep); // openGLView.StartSpinning(window_manager); // window_manager->CallGlutMainLoop(); //========================================================================================================= for (int i = 0; i < num_steps; i++) { system_gpu->DoStepDynamics(timestep); double TIME = system_gpu->GetChTime(); double STEP = system_gpu->GetTimerStep(); double BROD = system_gpu->GetTimerCollisionBroad(); double NARR = system_gpu->GetTimerCollisionNarrow(); double LCP = system_gpu->GetTimerLcp(); double UPDT = system_gpu->GetTimerUpdate(); int BODS = system_gpu->GetNbodies(); int CNTC = system_gpu->GetNcontacts(); int REQ_ITS = ((ChLcpSolverGPU*) (system_gpu->GetLcpSolverSpeed()))->GetTotalIterations(); printf("%7.4f|%7.4f|%7.4f|%7.4f|%7.4f|%7.4f|%7d|%7d|%7d\n", TIME, STEP, BROD, NARR, LCP, UPDT, BODS, CNTC, REQ_ITS); // if (i % 1000 == 0) { // cout << "SAVED STATE" << endl; // DumpObjects(system_gpu, "diagonal_impact_settled.txt", "\t"); // } RunTimeStep(system_gpu, i); } DumpObjects(system_gpu, "diagonal_impact_settled.txt", "\t"); }