export fabric tensor in txt

Asked by jamespaul on 2019-02-01

Hi,

I want to export fabric tensor in TXT.

>If i use fabTot=utils.fabricTensor(splitTensor=False) in plot.addData, resulting in an error.

ValueError: plot.addData given unhandled sequence type (is a tuple, must be number or Vector2/Vector3/Matrix3)

>If i use fabTot=utils.fabricTensor(splitTensor=False)[0] in plot.addData, resulting in an error.

KeyError: 'f'

So,how can i save it in txt.

Thanks,

James

################################
# encoding: utf-8
from yade import pack, qt

sigmaIso=-25000
O.periodic=True

sp=pack.SpherePack()
sp.makeCloud((0,0,0),(3,3,3),rMean=.1,rRelFuzz=.3,periodic=True)
sp.toSimulation()

O.engines=[
   ForceResetter(),
   InsertionSortCollider([Bo1_Sphere_Aabb()]),
   InteractionLoop(
      [Ig2_Sphere_Sphere_ScGeom()],
      [Ip2_FrictMat_FrictMat_FrictPhys()],
      [Law2_ScGeom_FrictPhys_CundallStrack()]
   ),
   PeriTriaxController(label='triax',
      goal=(sigmaIso,sigmaIso,sigmaIso),stressMask=7,
      dynCell=True,maxStrainRate=(1,1,1),
      maxUnbalanced=.1,relStressTol=1e-3,
      doneHook='triaxFinished()'
   ),
   NewtonIntegrator(damping=.1),
   PyRunner(command='addPlotData()',iterPeriod=1000),
]
O.dt=.5*PWaveTimeStep()

def addPlotData():
    plot.addData(
                 fabTot=utils.fabricTensor(splitTensor=False)[0],
 )
 print(fabricTensor(0.5))
 plot.saveDataTxt('f.dat',vars=('fabTot'))

def triaxFinished():
   O.pause()

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jérôme Duriez
Solved:
2019-02-12
Last query:
2019-02-12
Last reply:
2019-02-08

Hi,
plot.addData() can only add real numbers, if you want to record a matrix (stress tensor) you need to record its components one by one.
Bruno

jamespaul (jamespauljames) said : #2

Hi Bruno,

I access the first number of tuples.

fabTot=utils.fabricTensor(splitTensor=False)[0]

If I don't write plot.saveDataTxt('f.dat',vars=('fabTot')) ,it doesn't report an error

Which code went wrong?

James

Shame on me! Sorry.
I read the question again and I don't understand what happens.
Plus, according to the error message addData should accept Vector3 and Matrix3, I didn't know.
Hopefully someone else will have a better idea.
Bruno

jamespaul (jamespauljames) said : #4

Thank you anyway, Bruno,

Since the question has been answered, I am afraid that no one will see the question again. May I ask it again?

James

re-opened

Best Jérôme Duriez (jduriez) said : #6

Hi,

I think #1 actually was the source of your problem.

utils.fabricTensor(splitTensor=False) returns (for some reason) a tuple with a matrix as a first element, and no second element.

E.g.
In [5]: fabricTensor(splitTensor=False)
Out[5]: (Matrix3(nan,nan,nan, nan,nan,nan, nan,nan,nan),) # "nan" at a state without any interactions

Then:

In [2]: fabricTensor(splitTensor=False)[0]
Out[2]: Matrix3(nan,nan,nan, nan,nan,nan, nan,nan,nan) # is a matrix...

and you do not deal yet with numbers. (fabricTensor(splitTensor=False)[0][0][0] would)

Going into more details, plot.addData() can deal with matrices: it stores all the components in plot.data, but plot.saveDataTxt() can deal with numbers only.

Jérôme

PS : please avoid "NameError: name 'plot' is not defined" in your script next time... ;-)

jamespaul (jamespauljames) said : #7

Thanks Jérôme Duriez, that solved my question.

Jan Stránský (honzik) said : #11

Please, if you have another question, open a new thread for a new question.
Especially do not duplicate questions (Jerome can see your talk with Bruno. If you are afraid that only Bruno pays attention, as said, open a new question).
cheers
Jan

jamespaul (jamespauljames) said : #12

Sorry Jan.

I was in too much of a hurry. I'll see to it later.

James

jamespaul (jamespauljames) said : #13

Thanks Jérôme Duriez, that solved my question.