Thanks for the response!
I updated the code to this as reccomended and ran a lot of different scenarios and began to think that maybe I don't need the basin and could have a particle domain that just surrounds the shell as the image attached shows. I've been really trying to show some decent progress since we've last talked. Now I just need to densely pack the particles and decrease the size eventually to start conveying some stuff! Then maybe trying to write the code for preventing it spawning in mesh. Let me know what you think
#include <DEM/API.h>
#include <DEM/HostSideHelpers.hpp>
#include <DEM/utils/Samplers.hpp>
#include <chrono>
#include <iostream>
#include <filesystem>
#include <cmath> // For sqrt function
using namespace deme;
using namespace std::chrono;
namespace fs = std::filesystem;
int main() {
// Initialize the DEM solver
DEMSolver DEMSim;
DEMSim.SetVerbosity(INFO);
DEMSim.SetOutputFormat(OUTPUT_FORMAT::CSV);
DEMSim.SetOutputContent(OUTPUT_CONTENT::ABSV);
DEMSim.SetMeshOutputFormat(MESH_FORMAT::VTK);
// Material properties with reduced stiffness and increased damping
auto mat_type_mixer = DEMSim.LoadMaterial({
{"E", 1e5f}, // Reduced stiffness to prevent high contact forces
{"nu", 0.3f},
{"CoR", 0.2f},
{"mu", 0.3f},
{"Crr", 0.2f} // Increased rolling resistance
});
// Adjusted simulation domain dimensions
float domain_x = 3.0f; // Increased domain to accommodate spawning area
float domain_y = 3.0f;
float domain_z = 3.0f;
DEMSim.InstructBoxDomainDimension(domain_x, domain_y, domain_z);
DEMSim.InstructBoxDomainBoundingBC("none", mat_type_mixer); // We'll add custom walls instead
// Load mesh objects (Auger and Drum) without scaling
// Commented out the basin as per user request
/*
auto basin = DEMSim.AddWavefrontMeshObject(
"/home/butterco/DEM-Engine/data/mesh/augertest_shapes/body_1_1_collision.obj",
mat_type_mixer
);
basin->SetFamily(0);
DEMSim.SetFamilyFixed(0); // Basin is fixed
*/
auto auger = DEMSim.AddWavefrontMeshObject(
"/home/butterco/DEM-Engine/data/mesh/augertest_shapes/body_2_1_collision.obj",
mat_type_mixer
);
auto drum = DEMSim.AddWavefrontMeshObject(
"/home/butterco/DEM-Engine/data/mesh/augertest_shapes/body_3_1_collision.obj",
mat_type_mixer
);
drum->Move(make_float3(0, 0, -0.6f), make_float4(0, 0.7071f, 0.7071f, 0));
auger->Move(make_float3(0, 0, 0.85f), make_float4(1, 0, 0, 0));
// Set family numbers for simulation properties
// basin->SetFamily(0); // Basin is commented out
auger->SetFamily(1);
drum->SetFamily(2);
// Fix the auger
DEMSim.SetFamilyFixed(1); // Auger is completely fixed
// DEMSim.SetFamilyFixed(2); // Removed to allow drum rotation
// Assign prescribed angular velocity to the drum
DEMSim.SetFamilyPrescribedAngVel(2, "0", "0", "0.5"); // Drum rotates around Z-axis at 0.5 rad/s
// Define particle template with decreased radius
float particle_radius = 0.01f; // Particle radius decreased to 10 mm
float mass = 2.6e3f * (4.0f / 3.0f) * M_PI * pow(particle_radius, 3); // Mass in kg (~0.1088 kg)
float3 MOI = (2.0f / 5.0f) * mass * particle_radius * particle_radius * make_float3(1.0f, 1.0f, 1.0f); // MOI for a sphere (~4.352e-5 kg·m²)
auto particle_template = DEMSim.LoadSphereType(particle_radius, mass, mat_type_mixer);
// Sampler setup to spawn particles around the drum and auger
float drum_radius = 0.02f; // Drum radius in meters
// Reverted inner and outer radii
float inner_radius = 0.036f; // Original inner radius (3.6 cm)
float outer_radius = 0.15f; // Reduced outer radius to 0.15 meters to match particle domain
// Adjusted fill height and fill bottom based on spawning volume calculation
float fill_height = 0.2f; // Fill height in meters (20 cm)
float fill_bottom = -0.7f; // Bottom of the fill region in meters
float3 fill_center = make_float3(0.0f, 0.0f, fill_bottom + fill_height / 2.0f); // (0, 0, -0.6)
// Debugging: Print inner and outer radii and fill height
std::cout << "Inner Radius: " << inner_radius << " meters" << std::endl;
std::cout << "Outer Radius: " << outer_radius << " meters" << std::endl;
std::cout << "Fill Height: " << fill_height << " meters" << std::endl;
// Adjust sampler spacing to prevent overlaps and slightly increase particle count
HCPSampler sampler(2.8f * particle_radius); // Sampler spacing set to 0.028m (2.8x particle_radius)
// Sample particles in the cylinder with outer radius
auto input_xyz_all = sampler.SampleCylinderZ(fill_center, outer_radius, fill_height);
// Filter out particles within the inner radius to create a donut shape
std::vector<float3> input_xyz;
for (const auto& pos : input_xyz_all) {
float dx = pos.x - fill_center.x;
float dy = pos.y - fill_center.y;
float dist = sqrt(dx * dx + dy * dy);
if (dist >= inner_radius && dist <= outer_radius) {
input_xyz.push_back(pos);
}
}
std::cout << "Total number of particles generated: " << input_xyz.size() << std::endl;
if (!input_xyz.empty()) {
// Add clumps and get the clump batch
auto clump_batch = DEMSim.AddClumps(particle_template, input_xyz);
clump_batch->SetFamily(3); // Assign particles to family 3, which is not fixed
} else {
std::cerr << "Error: No particles were generated. Adjust sampling parameters." << std::endl;
return -1;
}
// Adjust the initial time step size
DEMSim.SetInitTimeStep(0.5e-6f); // Decrease time step for higher stability
// Set gravity and other simulation parameters
DEMSim.SetGravitationalAcceleration(make_float3(0.0f, 0.0f, -9.81f));
DEMSim.SetCDUpdateFreq(40);
DEMSim.SetExpandSafetyAdder(2.0f);
// Increase the maximum allowed average contacts per sphere
DEMSim.SetErrorOutAvgContacts(300); // Increased from 250 to 300
// Increase the allowed system max velocity
DEMSim.SetErrorOutVelocity(3000.0f); // Increased from 2000 to 3000
DEMSim.SetAdaptiveBinSizeUpperProactivity(0.5f);
DEMSim.SetAdaptiveBinSizeLowerProactivity(0.15f);
// Set initial bin size to prevent bins from becoming overpopulated
DEMSim.SetInitBinSize(25.0f * particle_radius); // 25 * 0.01 = 0.25m
// Increase maximum spheres per bin if necessary
DEMSim.SetMaxSphereInBin(50000);
// Add walls to prevent particles from falling over the edge
auto walls = DEMSim.AddExternalObject();
walls->AddPlane(make_float3(0, 0, -0.7f), make_float3(0, 0, 1), mat_type_mixer); // Bottom plane at Z=-0.7m
walls->AddCylinder(
make_float3(0, 0, 0),
make_float3(0, 0, 1),
outer_radius, // 0.15m
mat_type_mixer
); // Outer cylinder
walls->SetFamily(4); // Assign walls to a new family
DEMSim.SetFamilyFixed(4); // Fix the walls
// Initialize the simulation
DEMSim.Initialize();
// Create output directory
std::string output_dir = "/home/butterco/DEM-Engine/data/output/";
fs::create_directories(output_dir);
auto max_velocity_finder = DEMSim.CreateInspector("clump_max_absv");
// Extend the simulation duration
float sim_end = 20.0f; // Simulation end time in seconds
unsigned int fps = 20; // Frames per second
float frame_time = 1.0f / fps;
unsigned int curr_frame = 0;
// Simulation loop
for (float t = 0.0f; t < sim_end; t += frame_time) {
std::cout << "Simulating frame " << curr_frame << std::endl;
char filename[200], mesh_filename[200];
sprintf(filename, "%sDEM_output_%04d.csv", output_dir.c_str(), curr_frame);
sprintf(mesh_filename, "%sDEM_mesh_output_%04d.vtk", output_dir.c_str(), curr_frame++);
DEMSim.WriteSphereFile(std::string(filename));
DEMSim.WriteMeshFile(std::string(mesh_filename));
DEMSim.DoDynamics(frame_time);
float max_velocity = max_velocity_finder->GetValue();
std::cout << "Max velocity of any particle: " << max_velocity << std::endl;
}
DEMSim.ShowTimingStats();
std::cout << "Simulation complete." << std::endl;
return 0;
}
--
You received this message because you are subscribed to a topic in the Google Groups "ProjectChrono" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/projectchrono/ewhC4AYLF-Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to projectchron...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/projectchrono/c7552937-946a-4488-a32c-27cc429f24c9n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/projectchrono/33ae610f-5c39-4263-8f59-24b464cae99en%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/projectchrono/3405bac5-e865-41a2-8516-60a76a30a782n%40googlegroups.com.