How to solve the issue 'a float is required' when using the mathfunction log

Asked by Lifan Chen

Hello,I'm going to use yade to simulate biaxial drained compression experiment. But when it runs to script 46,strainy = -100.*math.log(O.cell.trsf[1]), the runner will report an error, a float is required.I'm very confused on the function log I use.
Could you please help me solve the error?
Thank you.

Here are my scripts and I use python 2.7.15.
from yade import pack,plot
import math

O.materials.append(FrictMat(young=6.e8,poisson=.8,frictionAngle=.0))

sp = pack.SpherePack()
size = .24
sp.makeCloud(minCorner=(0,0,.05),maxCorner=(size,size,.05),rMean=.005,rRelFuzz=.4,num=400,periodic=True,seed=1)
sp.toSimulation()
O.cell.hSize = Matrix3(size,0,0, 0,size,0, 0,0,.1)
print len(O.bodies)
for p in O.bodies:
   p.state.blockedDOFs = 'zXY'
   p.state.mass = 2650 * 0.1 * pi * p.shape.radius**2 # 0.1 = thickness of cylindrical particle
   inertia = 0.5 * p.state.mass * p.shape.radius**2
   p.state.inertia = (.5*inertia,.5*inertia,inertia)

O.dt = utils.PWaveTimeStep()
print O.dt

O.engines = [
   ForceResetter(),
   InsertionSortCollider([Bo1_Sphere_Aabb()]),
   InteractionLoop(
      [Ig2_Sphere_Sphere_ScGeom()],
      [Ip2_FrictMat_FrictMat_FrictPhys()],
      [Law2_ScGeom_FrictPhys_CundallStrack()]
   ),
   PeriTriaxController(
      dynCell=True,
      goal=(-1.e5,-1.e5,0),
      stressMask=3,
      relStressTol=.001,
      maxUnbalanced=.001,
      maxStrainRate=(.5,.5,.0),
      doneHook='shear()',
      label='biax'
   ),
   NewtonIntegrator(damping=0.1),
   PyRunner(command='saveAddData()',iterPeriod=200)
]

def saveAddData():
   stress = utils.getStress()
   plot.addData(
      strainy = -100.*math.log(O.cell.trsf[1]),
      stressy = -0.001*stress[1],
      p = -0.0005*(stress[0]+stress[1]),
      q = 0.0005*(stress[0]-stress[1])
   )
   plot.saveDataTxt('drained.txt',vars=('strainy','stressy','p','q'))

def shear():
   print getStress()
   print O.cell.hSize
   setContactFriction(0.5)
   O.cell.trsf=Matrix3.Identity
   biax.goal=(-1.e5,-1.e-1,0)
   biax.stressMask=1
   biax.relStressTol=0.01
   biax.maxUnbalanced=0.01
   biax.maxStrainRate=(0.01,0.01,0)
   O.engines=O.engines+[PyRunner(command='saveAddData()',iterPeriod=200)]
   O.pause()

O.run();O.wait()

The error it reports is as follows.
/usr/bin/yadedaily in <module>()

/usr/bin/yadedaily in saveAddData()
     44 stress = utils.getStress()
     45 plot.addData(
---> 46 strainy = -100.*math.log(O.cell.trsf[1]),
     47 stressy = -0.001*stress[1],
     48 p = -0.0005*(stress[0]+stress[1]),

TypeError: a float is required

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Robert Caulk
Solved:
Last query:
Last reply:
Revision history for this message
Best Robert Caulk (rcaulk) said :
#1

Hello,

O.cell.trsf returns the transformation matrix [1]. O.cell.trsf[1], as you have written, returns a vector from the matrix. The function math.log() cannot take a vector as an argument. If you are looking for eyy, I guess you would use O.cell.trsf[1,1] to index the float from the matrix.

Cheers,

Robert

[1]https://yade-dev.gitlab.io/trunk/yade.wrapper.html#yade.wrapper.Cell.trsf

Revision history for this message
Lifan Chen (lichan) said :
#2

Thanks Robert Caulk, that solved my question.