Question about the ChParticleCloud, Crash when collisions are enabled

60 views
Skip to first unread message

Zaftrox

unread,
Aug 24, 2025, 5:04:23 PMAug 24
to ProjectChrono
Hi, i wanted to create a particlecloud to handle a bunch of cylindrical objects in pychrono. However, when i setup the particlecloud then enable the collisions, it crashs immediately.

Here's the snippet :

# Particles cloud :
particles = chrono.ChParticleCloud()
particles.SetMass(simMat["ParticleMass"])
particles.SetInertiaXX(chrono.ChVector3d( simMat["ParticleInertia"],  simMat["ParticleInertia"],  simMat["ParticleInertia"]))

# Collision shape/model :
colModel = chrono.ChCollisionModel()
colModel.Clear()
cylShape = chrono.ChCollisionShapeCylinder(material, .01, .002)
colModel.AddShape(cylShape)
particles.AddCollisionModel(colModel)
particles.AddCollisionShape(cylShape)

visShape = chrono.ChVisualShapeCylinder(.01, .002)
frame = chrono.ChFramed(chrono.ChVector3d(0,0,0), chrono.QuatFromAngleAxis(chrono.CH_PI/2, chrono.ChVector3d(1,0,0)))
particles.AddVisualShape(visShape, frame)

# addition loop :
for i in range(20):
    possys = chrono.ChCoordsysd(
        chrono.ChVector3d(random.uniform(-.3, .3), random.uniform(-.3, .3), 0),
        chrono.QuatFromAngleAxis(-chrono.CH_PI/2, chrono.ChVector3d(1,0,0))
    )
    particles.AddParticle(possys)
#particles.EnableCollision(True)
system.Add(particles)

Dan Negrut

unread,
Aug 24, 2025, 8:47:32 PMAug 24
to Zaftrox, ProjectChrono

Hi, would you mind dropping the entire PyChrono script, top to bottom, that demonstrates the problem?

 

NOTE: this is a public forum, remove any sensitive information/data.

 

Thank you,

Dan

---------------------------------------------

Bernard A. and Frances M. Weideman Professor

NVIDIA CUDA Fellow

Department of Mechanical Engineering

Department of Computer Science

University of Wisconsin - Madison

4150ME, 1513 University Avenue

Madison, WI 53706-1572

608 772 0914

http://sbel.wisc.edu/

http://projectchrono.org/

---------------------------------------------

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/projectchrono/a2929f89-b15a-42f5-a807-c7e7d02ec0edn%40googlegroups.com.

Zaftrox

unread,
Aug 24, 2025, 9:07:49 PMAug 24
to ProjectChrono
here's the code :

import pychrono.core as chrono
import pychrono.irrlicht as chronoirr
import random
import numpy as np

# Sim-DATA :
simData = {
    "Density" : 5200,
    "ExpectedDiameter" : .05e-3
}
simData["ParticleVolume"] = (3/4)*np.pi*np.power((simData["ExpectedDiameter"]/2), 3)
simData["ParticleMass"] = simData["ParticleVolume"]*simData["Density"]
simData["ParticleInertia"] = (2/5)*simData["ParticleMass"]*np.power((simData["ExpectedDiameter"]/2), 2)

# Create Chrono physical system
system = chrono.ChSystemNSC()
system.SetCollisionSystemType(chrono.ChCollisionSystem.Type_MULTICORE)
system.SetGravitationalAcceleration(chrono.ChVector3d(0, -9.81, 0))
ground = chrono.ChBody()
ground.SetFixed(True)
system.Add(ground)
material = chrono.ChContactMaterialNSC()
material.SetFriction(.5)

def constrain_to_2D(body):
    # Dummy body as reference :
    dummy = chrono.ChBodyAuxRef()
    dummy.SetFixed(True)
    system.AddBody(dummy)

    # Planar constraint and its frame :
    plane_constraint = chrono.ChLinkLockPlanar()
    frame_abs = chrono.ChFramed(body.GetPos(), chrono.QUNIT)
    # Init :
    plane_constraint.Initialize(body, dummy, True, frame_abs, frame_abs)
    # constraint generic mate :
    lock = chrono.ChLinkMateGeneric()
    lock.Initialize(body, dummy, False, frame_abs, frame_abs)
    # Constrain Tz and X/Y rotation in case of offset :
    lock.SetConstrainedCoords(False, False, True,  # Tx, Ty, Tz
                              True, True, False)   # Rx, Ry, Rz

    system.Add(lock)
    system.AddLink(plane_constraint)

def importMeshBody(meshFile, material, contrained2D=False, fixed=True, scale=0.001, initialPos=chrono.ChVector3d(0, 0, 0), colorVec=chrono.ChColor(0.3, 0.3, 0.3)):
    # Prior :
    body = chrono.ChBody()
    system.Add(body)
    body.SetPos(initialPos)
    if contrained2D :
        constrain_to_2D(body)
    # mesh :
    mesh = chrono.ChTriangleMeshConnected()
    mesh.LoadWavefrontMesh(meshFile)
    transformationMatrix = chrono.ChMatrix33d(scale)
    mesh.Transform(chrono.ChVector3d(0,0,0), transformationMatrix)

    # Visualization part :
    visShape = chrono.ChVisualShapeTriangleMesh()
    visShape.SetMesh(mesh)
    visShape.SetColor(colorVec)
    body.AddVisualShape(visShape)

    # Collision part :
    body_ct_shape = chrono.ChCollisionShapeTriangleMesh(material, mesh, False, False, 0.01)
    body.AddCollisionShape(body_ct_shape)
    body.EnableCollision(True)
    body.SetFixed(fixed)
    return body

plate = importMeshBody("test PLATE.obj", material, contrained2D=True, scale=.001, fixed=True)


# Particles cloud :
particles = chrono.ChParticleCloud()
particles.SetMass(simData["ParticleMass"])
particles.SetInertiaXX(chrono.ChVector3d(simData["ParticleInertia"], simData["ParticleInertia"], simData["ParticleInertia"]))


# Collision shape/model :
colModel = chrono.ChCollisionModel()
colModel.Clear()
cylShape = chrono.ChCollisionShapeCylinder(material, .01, .002)   # radius

colModel.AddShape(cylShape)
particles.AddCollisionModel(colModel)
particles.AddCollisionShape(cylShape)

visShape = chrono.ChVisualShapeCylinder(.01, .002)
frame = chrono.ChFramed(chrono.ChVector3d(0,0,0), chrono.QuatFromAngleAxis(chrono.CH_PI/2, chrono.ChVector3d(1,0,0)))
particles.AddVisualShape(visShape, frame)

# Add particles (positions only)

for i in range(20):
    possys = chrono.ChCoordsysd(
        chrono.ChVector3d(random.uniform(-.3, .3), random.uniform(-.3, .3), 0),
        chrono.QuatFromAngleAxis(-chrono.CH_PI/2, chrono.ChVector3d(1,0,0))
    )
    particles.AddParticle(possys)
particles.EnableCollision(True)
system.Add(particles)

vis = chronoirr.ChVisualSystemIrrlicht()
vis.AttachSystem(system)
vis.SetWindowSize(1024, 768)
vis.SetWindowTitle("Mixer simulator")
vis.Initialize()
vis.AddSkyBox()
vis.AddCamera(chrono.ChVector3d(0, 0, 2))
vis.AddTypicalLights()
   
time_step = 0.005
while vis.Run():
    vis.BeginScene()
    vis.Render()
    vis.EndScene()
    system.DoStepDynamics(time_step)

Bocheng Zou

unread,
Aug 24, 2025, 11:22:01 PMAug 24
to projec...@googlegroups.com

Hi Zaftrox,

Thank you for raising the issue. To help us investigate, could you please report if there's any output in the terminal before the program crashes?

Best,

Bocheng Zou

Zaftrox

unread,
Aug 25, 2025, 2:50:44 AMAug 25
to ProjectChrono
No, there's nothing.
When the simulation starts and the rendering window pop-up it freezes instantaneously and crash. It comes from the collision so if the particles cloud is set fixed or by disabling the collision, the simulation works fine.

Bocheng Zou

unread,
Aug 25, 2025, 3:14:41 AMAug 25
to projec...@googlegroups.com

Hi Zaftrox,

Thank you for the follow up. To help us better identify the problem, could you please upload the "test PLATE.obj" file? In addition, could you please provide information on how do you install the PyChrono. Specifically, if you install PyChrono via conda, could you please also attach your "conda list" output?

Best,

Bocheng Zou

Zaftrox

unread,
Aug 25, 2025, 3:31:21 AMAug 25
to ProjectChrono
just installed pychrono 9.0.0 using conda.

btw, i tested without triangularmesh (the test PLATE) and the problem persist.
test PLATE.obj

Bocheng Zou

unread,
Aug 25, 2025, 9:12:50 AMAug 25
to projec...@googlegroups.com

Hi Zaftrox,

Thank you for getting back. The issue has been successfully reproduced on my end. I will look into that and let you know once a fix has been implemented. 

Best,

Bocheng Zou

Reply all
Reply to author
Forward
0 new messages