syntax error in rot_compress.py

Asked by Temitope

Hi there,

Thanks for your tutorials . They have been helpful.

Please I am getting a syntax error in the rot_compress.py tutorial as shown below:

adminuser@temitope-oladele:~$ export PATH=/usr/local/bin/:$PATH
adminuser@temitope-oladele:~$ export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
adminuser@temitope-oladele:~$ export LIBRARY_PATH=/usr/local/lib/:$LIBRARY_PATH
adminuser@temitope-oladele:~$ export PYTHONPATH=/usr/local/lib/python2.7/dist-packages/:$PYTHONPATH
adminuser@temitope-oladele:~$ mpirun -np 2 esysparticle rot_compress.py
CSubLatticeControler::initMPI()
  File "rot_compress.py", line 38
    geoRandomBlock.generate()
                 ^
SyntaxError: invalid syntax

All codes seems correct but i guess that it's the version of my python that might be causing it. Kindly help me with this. below is the tutorial code that i am running :

#import the approprate esysparticle modules
from esys.lsm import*
from esys.lsm.util import*
from esys.lsm.geometary import*
from WallLoader import WallLoaderRunnable

#instantiate a simulation object
sim = LsmMPi (numWorkerProcesses = 1, mpiDimList = [1,1,1])

#initialise the neighbouring search algorithm
sim.initNeighbourSearch (
 particleType = "RotSphere",
 gridSpacing = 5.0000,
 verletDist = 0.08000
)

#set the number of timesteps and timestep increament:
sim.setNumTimeSteps (250000)
sim.setTimeStepSize (1.0000e-06)

#specify the spatial domain for the simulation
domain = BoundingBox(Vec3(-20,-20,20), Vec3(20,20,20))
sim.setSpatialDomain (domain)

#create a prism of speherical particles
geoRandomBlock = RandomBoxPacker (
 minRadius = 0.400,
 MaxRadius = 2.0000,
 cubicPackRadius = 2.2000,
 maxInsertFails = 5000,
 bBox = BoundingBox(
  Vec3(-5.0000, 0.0000, -5.0000),
  Vec3(5.0000, 20.0000, 5.00000
 ),
 circDimList = [False, False, False],
 tolerance = 1.0000e-05
)
geoRandomBlock.generate()
geoRandomBlock_particles = geoRandomBlock.getSimpleSphereCollection()

#add the particles to the simulation object:
sim.createParticles(geoRandomBlock_particles)

#bond particles together with bondTag =1:
sim.createConnections(
 ConnectionFinder(
  maxDist = 0.005,
  bondTag = 1,
  pList = geoRandomBlock_particles
 )
)

#Create bottom wall of the come.
sim.createWall (
 name = "Bottom_wall",
 posn = Vec3(0.0000, 0.0000, 0.0000),
 normal = Vec3(0.0000, 1.0000, 0.0000)
)

#create a wall at the top of the model:
sim.createWall (
 name = "top_wall",
 posn = Vec3(0.0000, 20.0000, 0.0000),
 normal = Vec3(0.0000, -1.0000, 0.0000)
)
#specify elastic repulsion from the bottom wall:
sim.createInteractionGroup (
 NRotElasticWallPrms (
  name = "bottom_wall_repel",
  wallName = "bottom_wall",
  normalK = 100000.0
 )
)

#Specify elastic repulsion from topwall:
sim.createInteractionGroup (
 NRotElasticWallPrms (
  name = "top_wall_repel",
  wallName = "top_wall",
  normalK = 100000.0
 )
)
#create rotational elastic-brittle bonds between particles:
pp_bonds = sim.createInteractionGroup (
 BrittleBeamPrms(
  name="pp_bonds",
  youngsModulus=100000.0,
  cohesion=100.0,
  tanAngle=1.0
  tag=1
 )
)
#initialise frictional interactions for unbonded particles:
sim.createInteractionGroup (
 FrictionPrms(
  name="friction",
  youngsModulus=100000.0,
  poissonsRatio=0.25,
  dynamicMu=0.4,
  staticMu=0.6
 )
)
#create an exlusion between particle pair i.e there undergo bonded or frictional interaction but not both
sim.createExclusion (
 interactionName1 ="pp_bonds",
 interactionName2 = "friction"
)
#add translational viscous damping:
sim.createInteractionGroup (
 LinDampingPrms(
  name="damping1",
  viscosity=0.002,
  maxiteration=50
 )
)
#add rotational viscous damping:
sim.createInteractionGroup (
 RotDampingPrms(
  name="damping2",
  viscosity=0.002,
  maxIteration=50
 )
)

#add a wall loader to move the top wall:
wall_loader1 = WallLoaderRunnable (
 LsmMpi =sim,
 wallName = 'top_wall',
 vPlate = Vec3(0.0, -0.125, 0.0),
 startTime = 0,
 rampTime = 50000
)
sim.addPreTimeStepRunnable (wall_loader1)

#add a wall loader to move the bottom wall:
wall_loader2 = WallLoaderRunnable (
 LsmMpi = sim,
 wallName = "bottom_wall",
 vPlate = Vec3(0.0, 0.125, 0.0),
 startTime = 0,
 rampTime = 50000
)
sim.addPreTimeStepRunnable (wall_loader2)

#execute the simulation:
sim.run()

Question information

Language:
English Edit question
Status:
Solved
For:
ESyS-Particle Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Qi Shao (uqqshao) said :
#1

Hi Temitope,

I think you have missed a ‘)’ in ‘geoRandomBlock = RandomBoxPacker (...)’ of your script, try to replace the code fragment with the followings:

geoRandomBlock = RandomBoxPacker (
    minRadius = 0.400,
    maxRadius = 2.0000,
    cubicPackRadius = 2.2000,
    maxInsertFails = 5000,
    bBox = BoundingBox(
        Vec3(-5.0000, 0.0000,-5.0000),
        Vec3(5.0000, 20.0000, 5.0000)
    ),
    circDimList = [False, False, False],
    tolerance = 1.0000e-05
)

I have also noticed a few other mistakes in your script, for example:

line 4: ‘geometary’ -> ‘geometry’
line 8: ‘LsmMPi’ -> ‘LsmMpi’
line 56: ‘Bottom_wall’ -> ‘bottom_wall’
line 88: missing ‘poissonsRatio=0.25,’
line 91: missing comma ‘,’
both line 118 and 128: ‘maxiteration’ -> ‘maxiterations’

Please examine your script carefully. For comparison, the scripts for the examples are provided in Appendix A of the Tutorial.

Cheers,
Qi

Revision history for this message
Temitope (temitope) said :
#2

Thanks Qi Shao, that solved my question.

Revision history for this message
Temitope (temitope) said :
#3

HI Qi,
That solved my problem thanks.

How ever, with further progress into rot_compress tutorial, I got the following error. I have checked my code but could not figure out what might possible be wrong. Here is the error message:
adminuser@temitope-oladele:~$ export PATH=/usr/local/bin/:$PATH
adminuser@temitope-oladele:~$ export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
adminuser@temitope-oladele:~$ export LIBRARY_PATH=/usr/local/lib/:$LIBRARY_PATH
adminuser@temitope-oladele:~$ export PYTHONPATH=/usr/local/lib/python2.7/dist-packages/:$PYTHONPATH
adminuser@temitope-oladele:~$ mpirun -np 2 esysparticle rot_compress.py
CSubLatticeControler::initMPI()
slave started at local/global rank 0 / 1
Traceback (most recent call last):
  File "rot_compress.py", line 153, in <module>
    timeStepIncr = 10
Boost.Python.ArgumentError: Python argument types in
    WallVectorFieldSaverPrms.__init__(WallVectorFieldSaverPrms)
did not match C++ signature:
    __init__(_object*, boost::python::list wallName, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fieldName, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fileName, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fileFormat, int beginTimeStep, int endTimeStep, int timeStepIncr)
    __init__(_object*, boost::python::tuple wallName, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fieldName, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fileName, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fileFormat, int beginTimeStep, int endTimeStep, int timeStepIncr)
    __init__(_object*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > wallName, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fieldName, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fileName, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > fileFormat, int beginTimeStep, int endTimeStep, int timeStepIncr)

below is the rot_compress code:

#import the approprate esysparticle modules
from esys.lsm import*
from esys.lsm.util import*
from esys.lsm.geometry import*
from WallLoader import WallLoaderRunnable

#instantiate a simulation object
sim = LsmMpi (numWorkerProcesses = 1, mpiDimList = [1,1,1])

#initialise the neighbouring search algorithm
sim.initNeighbourSearch (
 particleType = "RotSphere",
 gridSpacing = 5.0000,
 verletDist = 0.08000
)

#set the number of timesteps and timestep increament:
sim.setNumTimeSteps (250000)
sim.setTimeStepSize (1.0000e-06)

#specify the spatial domain for the simulation
domain = BoundingBox(Vec3(-20,-20,20), Vec3(20,20,20))
sim.setSpatialDomain (domain)

#create a prism of speherical particles
geoRandomBlock = RandomBoxPacker (
 minRadius = 0.400,
 maxRadius = 2.0000,
 cubicPackRadius = 2.2000,
 maxInsertFails = 5000,
 bBox = BoundingBox(
  Vec3(-5.0000, 0.0000, -5.0000),
  Vec3(5.0000, 20.0000, 5.00000)
 ),
 circDimList = [False, False, False],
 tolerance = 1.0000e-05
)
geoRandomBlock.generate()
geoRandomBlock_particles = geoRandomBlock.getSimpleSphereCollection()

#add the particles to the simulation object:
sim.createParticles(geoRandomBlock_particles)

#bond particles together with bondTag =1:
sim.createConnections(
 ConnectionFinder(
  maxDist = 0.005,
  bondTag = 1,
  pList = geoRandomBlock_particles
 )
)

#Create bottom wall of the come.
sim.createWall (
 name = "bottom_wall",
 posn = Vec3(0.0000, 0.0000, 0.0000),
 normal = Vec3(0.0000, 1.0000, 0.0000)
)

#create a wall at the top of the model:
sim.createWall (
 name = "top_wall",
 posn = Vec3(0.0000, 20.0000, 0.0000),
 normal = Vec3(0.0000, -1.0000, 0.0000)
)
#specify elastic repulsion from the bottom wall:
sim.createInteractionGroup (
 NRotElasticWallPrms (
  name = "bottom_wall_repel",
  wallName = "bottom_wall",
  normalK = 100000.0
 )
)

#Specify elastic repulsion from topwall:
sim.createInteractionGroup (
 NRotElasticWallPrms (
  name = "top_wall_repel",
  wallName = "top_wall",
  normalK = 100000.0
 )
)
#create rotational elastic-brittle bonds between particles:
pp_bonds = sim.createInteractionGroup (
 BrittleBeamPrms(
  name="pp_bonds",
  youngsModulus=100000.0,
  poissonsRatio=0.25,
  cohesion=100.0,
  tanAngle=1.0,
  tag=1
 )
)
#initialise frictional interactions for unbonded particles:
sim.createInteractionGroup (
 FrictionPrms(
  name="friction",
  youngsModulus=100000.0,
  poissonsRatio=0.25,
  dynamicMu=0.4,
  staticMu=0.6
 )
)
#create an exlusion between particle pair i.e there undergo bonded or frictional interaction but not both
sim.createExclusion (
 interactionName1 ="pp_bonds",
 interactionName2 = "friction"
)
#add translational viscous damping:
sim.createInteractionGroup (
 LinDampingPrms(
  name="damping1",
  viscosity=0.002,
  maxIterations=50
 )
)
#add rotational viscous damping:
sim.createInteractionGroup (
 RotDampingPrms(
  name="damping2",
  viscosity=0.002,
  maxIterations=50
 )
)

#add a wall loader to move the top wall:
wall_loader1 = WallLoaderRunnable (
 LsmMpi =sim,
 wallName = 'top_wall',
 vPlate = Vec3(0.0, -0.125, 0.0),
 startTime = 0,
 rampTime = 50000
)
sim.addPreTimeStepRunnable (wall_loader1)

#add a wall loader to move the bottom wall:
wall_loader2 = WallLoaderRunnable (
 LsmMpi = sim,
 wallName = "bottom_wall",
 vPlate = Vec3(0.0, 0.125, 0.0),
 startTime = 0,
 rampTime = 50000
)
sim.addPreTimeStepRunnable (wall_loader2)

#create a FieldSaver to wall positions:
posn_saver = WallVectorFieldSaverPrms(
 wallName=["bottom_wall", "top_wall"],
 fieldName="Position",
 fileName="out_Position.dat",
 fileFormat="RAW_SERIES",
 beginTimeStep=250000,
 timeStepIncr = 10
)
sim.createFieldSaver(posn_saver)

#create FieldSaver to wall forces:
force_saver = WallVectorFieldSaverPrms(
 wallName=["bottom_wall", "top_wall"],
 fieldName="Force",
 fileName="out_Force.dat",
 fileFormat="RAW_SERIES",
 beginTimeStep=0,
 endTimeStep=250000,
 timeStepIncr=10
)
sim.createFieldSaver(force_saver)

#execute the simulation:
sim.run()

Revision history for this message
Best Manfred Hampl (m-hampl) said :
#4

The first call
posn_saver = WallVectorFieldSaverPrms(
  wallName=["bottom_wall", "top_wall"],
  fieldName="Position",
  fileName="out_Position.dat",
  fileFormat="RAW_SERIES",
  beginTimeStep=250000,
  timeStepIncr = 10
)
Does not have a endTimeStep value.

Revision history for this message
Temitope (temitope) said :
#5

Thank you ManFred.