Skip to content

Commit

Permalink
Add test programs relocated from main Chrono repository
Browse files Browse the repository at this point in the history
  • Loading branch information
rserban committed Nov 23, 2023
1 parent 6f8cb65 commit 07d4931
Show file tree
Hide file tree
Showing 11 changed files with 1,892 additions and 4 deletions.
31 changes: 31 additions & 0 deletions data/gpu/compression.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"sphere_radius": 0.5,
"sphere_density": 2.5,
"box_X": 10,
"box_Y": 10 ,
"box_Z": 20 ,
"step_size": 5e-5,
"time_end": 5,
"grav_X": 0,
"grav_Y": 0,
"grav_Z": -980,
"normalStiffS2S": 1e7,
"normalStiffS2W": 1e7,
"normalDampS2S": 1e4,
"normalDampS2W": 1e4,
"tangentStiffS2S" : 2e6,
"tangentStiffS2W" : 1e6,
"tangentDampS2S": 50,
"tangentDampS2W": 50,
"cohesion_ratio": 0,
"adhesion_ratio_s2w": 0,
"static_friction_coeffS2S": 0.2,
"static_friction_coeffS2W": 0.25,
"verbose": false,

"psi_T": 32,
"psi_L": 16,

"output_dir": "compression",
"write_mode": "csv"
}
39 changes: 39 additions & 0 deletions data/gpu/soilBin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"sphere_radius": 0.5,
"sphere_density": 2.5,

"box_X": 100,
"box_Y": 100,
"box_Z": 50,

"step_size": 1e-5,
"time_end": 1,

"grav_X": 0,
"grav_Y": 0,
"grav_Z": -980,

"normalStiffS2S": 1e7,
"normalStiffS2W": 1e7,
"normalDampS2S": 5e3,
"normalDampS2W": 5e3,

"tangentStiffS2S" : 1e5,
"tangentStiffS2W" : 1e5,
"tangentDampS2S": 0,
"tangentDampS2W": 0,

"static_friction_coeffS2S" : 0.5,
"static_friction_coeffS2W" : 0.5,

"cohesion_ratio": 0,
"adhesion_ratio_s2w": 0,

"verbose": 0,
"psi_T": 32,
"psi_L": 16,

"output_dir": "soilBin",
"write_mode": "csv",
"run_mode": "one_step"
}
29 changes: 29 additions & 0 deletions data/gpu/soilBin_benchmark.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"sphere_radius": 0.5,
"sphere_density": 2.5,
"box_X": 600,
"box_Y": 600,
"box_Z": 100,
"step_size": 2e-5,
"time_end": 1,
"grav_X": 0,
"grav_Y": 0,
"grav_Z": -980,
"normalStiffS2S": 1e8,
"normalStiffS2W": 1e8,
"normalDampS2S": 1000,
"normalDampS2W": 1000,
"tangentStiffS2S" : 1e8,
"tangentStiffS2W" : 1e8,
"tangentDampS2S": 1000,
"tangentDampS2W": 1000,
"static_friction_coeffS2S": 0.7,
"static_friction_coeffS2W": 0.7,
"cohesion_ratio": 0,
"verbose": false,

"psi_T": 32,
"psi_L": 16,
"output_dir": "soilBin",
"write_mode": "binary"
}
16 changes: 12 additions & 4 deletions projects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ endif()
# Invoke CMake in subdirectories
#-----------------------------------------------------------------------------


cmake_dependent_option(ENABLE_PRJ_DEM_VALIDATION
"Enable projects for DEM validation" ON
"ENABLE_PROJECTS" OFF)
Expand All @@ -21,10 +22,13 @@ cmake_dependent_option(ENABLE_PRJ_VEHICLE_TESTS
"Enable projects for Chrono::Vehicle tests" ON
"ENABLE_PROJECTS" OFF)
cmake_dependent_option(ENABLE_PRJ_CORE_TESTS
"Enable projects for Chrono::Engine core tests" ON
"Enable projects for Chrono core tests" ON
"ENABLE_PROJECTS" OFF)
cmake_dependent_option(ENABLE_PRJ_PHYSICS_TESTS
"Enable projects for Chrono::Engine physics tests" ON
"Enable projects for basic physics tests" ON
"ENABLE_PROJECTS" OFF)
cmake_dependent_option(ENABLE_PRJ_MBS_TESTS
"Enable projects for MBS simulation" ON
"ENABLE_PROJECTS" OFF)
cmake_dependent_option(ENABLE_PRJ_FEA_TESTS
"Enable projects for Chrono::FEA tests" ON
Expand All @@ -33,10 +37,10 @@ cmake_dependent_option(ENABLE_PRJ_COSIMULATION
"Enable projects for Chrono::Vehicle cosimulation" ON
"ENABLE_PROJECTS" OFF)
cmake_dependent_option(ENABLE_PRJ_GPU_TESTS
"Enable projects for Chrono::Gpu tests" ON
"Enable projects for Chrono::GPU granular tests" ON
"ENABLE_PROJECTS" OFF)
cmake_dependent_option(ENABLE_PRJ_SYN_HIGHWAY
"Enable projects for SynChrono Highway" OFF
"Enable SynChrono Highway test" OFF
"ENABLE_PROJECTS" OFF)

if (ENABLE_PRJ_CORE_TESTS)
Expand All @@ -47,6 +51,10 @@ if (ENABLE_PRJ_PHYSICS_TESTS)
add_subdirectory(physics_tests)
endif()

if (ENABLE_PRJ_MBS_TESTS)
add_subdirectory(mbs)
endif()

if (ENABLE_PRJ_FEA_TESTS)
add_subdirectory(fea_tests)
endif()
Expand Down
3 changes: 3 additions & 0 deletions projects/gpu_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ set(DEMOS
test_GPU_roll
test_GPU_incline
test_GPU_repose
test_GPU_soilBin
test_GPU_ballDrop
test_GPU_compression
)

#--------------------------------------------------------------
Expand Down
164 changes: 164 additions & 0 deletions projects/gpu_tests/test_GPU_ballDrop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2021 projectchrono.org
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
// http://projectchrono.org/license-chrono.txt.
//
// =============================================================================
// Authors: Luning Fang
// =============================================================================
// Impact test: Granular material settling in a cylindrical container
// to generate the bed for balldrop test. Once particles are settled,
// a projectile modeled as boundary condition is dropped
// with impact velocity 1m/s
// =============================================================================

#include <iostream>
#include <string>

#include "chrono/core/ChGlobal.h"
#include "chrono/utils/ChUtilsSamplers.h"

#include "chrono_thirdparty/filesystem/path.h"

#include "chrono_gpu/physics/ChSystemGpu.h"

using namespace chrono;
using namespace chrono::gpu;

void setMaterialProperty(ChSystemGpu& gran_sys) {
double cor_p = 0.5; // use cor_p = 0.9 for sand or glass beads
double cor_w = 0.5;
double youngs_modulus = 1e8;
double mu_s2s = 0.16;
double mu_s2w = 0.45;
double mu_roll = 0.09;
double poisson_ratio = 0.24;

gran_sys.UseMaterialBasedModel(true);
gran_sys.SetYoungModulus_SPH(youngs_modulus);
gran_sys.SetYoungModulus_WALL(youngs_modulus);
gran_sys.SetRestitution_SPH(cor_p);
gran_sys.SetRestitution_WALL(cor_w);
gran_sys.SetPoissonRatio_SPH(poisson_ratio);
gran_sys.SetPoissonRatio_WALL(poisson_ratio);
gran_sys.SetRollingMode(CHGPU_ROLLING_MODE::SCHWARTZ);
gran_sys.SetRollingCoeff_SPH2SPH(mu_roll);
gran_sys.SetRollingCoeff_SPH2WALL(mu_roll);
gran_sys.SetFrictionMode(CHGPU_FRICTION_MODE::MULTI_STEP);
gran_sys.SetStaticFrictionCoeff_SPH2SPH(mu_s2s);
gran_sys.SetStaticFrictionCoeff_SPH2WALL(mu_s2w);
}

int main(int argc, char* argv[]) {
// unit gcm
double sphere_radius = 0.5f;
double sphere_density = 2.48;
double box_X = 31.5;
double box_Y = 31.5;
double box_Z = 30.0;

double grav_X = 0.0f;
double grav_Y = 0.0f;
double grav_Z = -980.0f;

float step_size = 1e-5f;
float time_settle = 1.5f;
float time_impact = 0.5f;
float time_end = time_settle + time_impact;

ChSystemGpu gran_sys(sphere_radius, sphere_density, ChVector<float>(box_X, box_Y, box_Z));
gran_sys.SetBDFixed(true);

// create cylinder containter
ChVector<float> cyl_center(0.0f, 0.0f, 0.0f);
float cyl_rad = std::min(box_X, box_Y) / 2.0f;
gran_sys.CreateBCCylinderZ(cyl_center, cyl_rad, false, true);

// generate a cloud of particles
std::vector<chrono::ChVector<float>> body_points;
utils::PDSampler<float> sampler(2.001 * sphere_radius);
ChVector<float> sampler_center(0.0f, 0.0f, 0.0f);
body_points = sampler.SampleCylinderZ(sampler_center, cyl_rad - 4 * sphere_radius, box_Z / 2 - 4 * sphere_radius);
auto numSpheres = body_points.size();
std::cout << "Numbers of particles created: " << numSpheres << std::endl;
gran_sys.SetParticles(body_points);

// set up material properties
setMaterialProperty(gran_sys);

// set up projectile radius, mass and impact velocity
float projectile_radius = 5.0f;
float projectile_mass = 1000;
ChVector<float> projectile_pos(0, 0, box_Z / 2.0f - projectile_radius);
ChVector<float> projectile_impact_velo(0.0, 0.0, -100.0f);
size_t projectile_id = gran_sys.CreateBCSphere(projectile_pos, projectile_radius, true, true, projectile_mass);

gran_sys.SetGravitationalAcceleration(ChVector<float>(grav_X, grav_Y, grav_Z));
gran_sys.SetPsiFactors(32.0f, 16.0f);
gran_sys.SetFixedStepSize(step_size);
gran_sys.SetTimeIntegrator(CHGPU_TIME_INTEGRATOR::FORWARD_EULER);

std::string out_dir = GetChronoOutputPath() + "GPU/";
filesystem::create_directory(filesystem::path(out_dir));
out_dir = out_dir + "/ballDrop/";
filesystem::create_directory(filesystem::path(out_dir));

gran_sys.SetParticleOutputFlags(ABSV);
gran_sys.SetParticleOutputMode(CHGPU_OUTPUT_MODE::CSV);

gran_sys.Initialize();
// Fix projectile until granular particles are settled
gran_sys.DisableBCbyID(projectile_id);

double t = 0.0f;
int curr_step_settle = 0;

double frame_step_settle = 0.01;
double frame_step_impact = 5e-4;
char filename[200];

// settling phase
while (t < time_settle) {
gran_sys.AdvanceSimulation(frame_step_settle);

// write particle output
sprintf(filename, "%s/settling%06d.csv", out_dir.c_str(), curr_step_settle);
gran_sys.WriteParticleFile(std::string(filename));

curr_step_settle++;
t += frame_step_settle;
}

double max_particle_z = gran_sys.GetMaxParticleZ();

// set projectile position and velocity
projectile_pos.z() = max_particle_z + sphere_radius + projectile_radius;
gran_sys.EnableBCbyID(projectile_id);
gran_sys.SetBCSpherePosition(projectile_id, projectile_pos);
gran_sys.SetBCSphereVelocity(projectile_id, projectile_impact_velo);

ChVector<float> bc_pos(0.0f, 0.0f, 0.0f);
ChVector<float> bc_velo(0.0f, 0.0f, 0.0f);
ChVector<float> bc_force(0.0f, 0.0f, 0.0f);

// impact phase
while (t < time_end) {
gran_sys.AdvanceSimulation(frame_step_impact);

t += frame_step_impact;

bc_pos = gran_sys.GetBCSpherePosition(projectile_id);
bc_velo = gran_sys.GetBCSphereVelocity(projectile_id);
gran_sys.GetBCReactionForces(projectile_id, bc_force);

// output projectile position, velocity and acceleration in z direction
printf("%e, %e, %e, %e\n", t, bc_pos.z(), bc_velo.z(), bc_force.z() / projectile_mass + grav_Z);
}

return 0;
}
Loading

0 comments on commit 07d4931

Please sign in to comment.