saving image of polyhedrals in paraview format

Asked by Mahdeyeh on 2019-12-01

Hi guys

I have some polyhedra particles, I want to save images of simulation in vtk and paraview format.
How I can do this ?

Another my problem is, when I use vtkExporter :
"
 vtkExporter = export.VTKExporter('//home/mahdeyeh/test/vtkExporter')
vtkExporter.exportPolyhedra('pos','b.state.pos')
"

It shows this error:
"NameError: global name 'exportPolyhedra' is not defined "

why? I write "from yade import export,polyhedra_utils" at the beginning of code.

Thanks for your time

Yade 2018.02b

Question information

Language:
English Edit question
Status:
Needs information
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
2019-12-01
Last reply:
2019-12-01
Robert Caulk (rcaulk) said : #1

Hello,

Please review our forum guidelines [1] and provide an MWE.

Cheers,

Robert

[1]https://www.yade-dem.org/wiki/Howtoask

Mahdeyeh (mahdiye.sky) said : #2

Here is my code:

from yade import export,polyhedra_utils
import os
from yade import plot
import math
from yade import utils
import pylab
import matplotlib; matplotlib.rc('axes',grid=True)
from matplotlib import pyplot
import numpy as np
from numpy import *

RawVer=np.genfromtxt('ri.txt',names=True,dtype=None)
# ListVer is list of all the vertices of ring`s polygons
Ver=()
ListVer=[]
for b in RawVer:
    if b[0]=='*LWPOLYLINE':
        ListVer.append(Ver)
        Ver=()
        continue
    Cordn=b[0]
    Cordn=np.fromstring(Cordn, sep=',')
    Cordn=tuple(Cordn.tolist())
    Cordn1=Cordn+(0.1,) # add z vertex to coordinates
    Cordn2=Cordn+(0.2,) # add z vertex to coordinates
    if not Cordn1 in Ver:
        Ver=Ver+(Cordn1,Cordn2)
ListVer.append(Ver)

RawVer1=np.genfromtxt('boundary.txt',names=True,dtype=None)
# ListVer is list of all the vertices of boundary`s polygons
Ver1=()
ListVer1=[]
for b in RawVer1:
    if b[0]=='*LWPOLYLINE':
        ListVer1.append(Ver1)
        Ver1=()
        continue
    Cordn=b[0]
    Cordn=np.fromstring(Cordn, sep=',')
    Cordn=tuple(Cordn.tolist())
    Cordn1=Cordn+(-2,) # add z vertex to coordinates
    Cordn2=Cordn+(2,) # add z vertex to coordinates
    if not Cordn1 in Ver1:
        Ver1=Ver1+(Cordn1,Cordn2)
ListVer1.append(Ver1)

RawVer2=np.genfromtxt('wa.txt',names=True,dtype=None)
# ListVer is list of all the vertices of caved waste rock`s polygons
Ver2=()
ListVer2=[]
for b in RawVer2:
    if b[0]=='*LWPOLYLINE':
        ListVer2.append(Ver2)
        Ver2=()
        continue
    Cordn=b[0]
    Cordn=np.fromstring(Cordn, sep=',')
    Cordn=tuple(Cordn.tolist())
    Cordn1=Cordn+(0.1,) # add z vertex to coordinates
    Cordn2=Cordn+(0.2,) # add z vertex to coordinates
    if not Cordn1 in Ver2:
        Ver2=Ver2+(Cordn1,Cordn2)
ListVer2.append(Ver2)

Dolomite = PolyhedraMat()
Dolomite.density = 2870 #kg/m^3
Dolomite.young = 24.36e9 #Pa
Dolomite.poisson = 0.2
Dolomite.frictionAngle = radians(55.12) #rad

Shale = PolyhedraMat()
Shale.density = 2750 #kg/m^3
Shale.young = 6e9 #Pa
Shale.poisson = 0.23
Shale.frictionAngle = radians(42) #rad

for ii in ListVer:
    O.bodies.append(polyhedra_utils.polyhedra(Dolomite,v=ii,fixed=False, color=(0.1,0.5,0.2), mask=3))

for iii in ListVer1:
    O.bodies.append(polyhedra_utils.polyhedra(Dolomite,v=iii,fixed=True, color=(1,0,1), mask=4))

for iiii in ListVer2:
    O.bodies.append(polyhedra_utils.polyhedra(Shale,v=iiii,fixed=False, color=(0.9,0.81,0.45), mask=5))

O.bodies.erase(12)

def checkUnbalanced():
    print "iter %d , unbalanced forces %f"%(O.iter, utils.unbalancedForce()) # %[(keyname)][flags][width][.precision]typecode : String Formatting

O.engines=[
   ForceResetter(),
   InsertionSortCollider([Bo1_Polyhedra_Aabb(),]), # We can set collider's verletDist to a fraction of the polyhedra minimum size, since it determines how much is each body enlarged to avoid collision detection at every step.
   InteractionLoop(
      [Ig2_Polyhedra_Polyhedra_PolyhedraGeom(),],
      [Ip2_PolyhedraMat_PolyhedraMat_PolyhedraPhys()], # collision "physics"
      [Law2_PolyhedraGeom_PolyhedraPhys_Volumetric()] # contact law -- apply forces
   ),
   NewtonIntegrator(gravity=(0,-9.81,0),damping=0.2),
]

O.engines=O.engines+[PyRunner(iterPeriod=20,command='calm()',label="calmRunner")] # because we need to calm only on the first few steps in our model.
O.engines=O.engines+[PyRunner(command='checkUnbalanced()',iterPeriod=1000,label="checker")] # call our function defined above 1000 cycles

polyhedra_utils.SizeRatio() # save sizes of polyhedra into file

export.textPolyhedra('poly.txt') # Save polyhedra into a text file, id, number of vertices and number of surfaces, particleVelocity and ... .

clrOre=[0.1,0.5,0.2]
clrWaste=[0.9,0.81,0.45]

def positions():
    for b in O.bodies:
        if b.shape.color==clrOre:
            print "%.9f , %.9f , %.9f "%(b.state.pos[0],b.state.pos[1],b.state.pos[2])
            time1=O.time

            Positions=open("Positions time x y z.txt","a")
            Positions.write(repr(time1)+' '+repr(b.state.pos[0])+' '+repr(b.state.pos[1])+' '+repr(b.state.pos[2])+' '"\n")
            Positions.close()

O.engines=O.engines+[PyRunner(command='positions()',realPeriod=0.5,label="flow")] # call our function defined above every 60 seconds

O.dt=10e-6

iii=0
while iii<50:
    O.run(1000,True)
    iii+=1

O.save('test1.bz2')
O.saveTmp('test1')

Mahdeyeh (mahdiye.sky) said : #3

content of ri.txt:

*LWPOLYLINE
4.34559213436763,4.19563889421937
4.31042320818271,4.19563889421937
4.31042320818271,4.05445713776717
4.33341560779634,4.09083399031995
4.34559213436763,4.19563889421937
*LWPOLYLINE
4.03286380514289,4.43515523404666
4.17241407759840,4.43515523404666
4.22754503815440,4.36456304177393
4.03458661095554,4.31635372702571
3.96113997193621,4.31635372702571
4.03286380514289,4.43515523404666
*LWPOLYLINE
3.41971278690444,4.44366348237027
3.46320431378560,4.54994505088534
3.51343273075365,4.54994505088534
3.49728561797354,4.44366348237027
3.41971278690444,4.44366348237027
*LWPOLYLINE
4.25338987548479,9.19037679709093
4.25530578302851,9.26087198721953
4.29473955139678,9.29716228619832
4.45949178466789,9.29348909994814
4.45949178466789,9.27716014638961
4.42052364456134,9.19927290554726
4.25338987548479,9.19037679709093
*LWPOLYLINE
3.69430516443352,4.73783273957938
3.69430516443352,4.93182238931670
3.75625576954475,5.05564563793556
3.89787386380568,5.05564563793556
3.88841683538887,4.96484181584951
3.78929567430250,4.73783273957938
3.69430516443352,4.73783273957938

content of wa.txt:

*LWPOLYLINE
3.88376464353553,1.33800969242003
3.83751523200053,1.44820764004128
3.58728936915612,1.50080199767633
3.46538550372381,1.33429481921918
3.41389145499828,1.03535559574160
3.73344705537207,1.11568049675982
3.84774706442400,1.21264488864129
3.88376464353553,1.33800969242003
*LWPOLYLINE
3.23345566297171,0.52192032713330
3.27958743353576,0.74458543448110
3.44401021214259,0.78324840940373
3.23345566297171,0.52192032713330
*LWPOLYLINE
3.27937272637005,0.74453494745106
3.15506808053324,0.71530549733790
2.98498203374232,0.38894887153548
3.15154241501946,0.32440546898789
3.23317773197976,0.52156467644088
3.27937272637005,0.74453494745106
*LWPOLYLINE
3.34888179054002,0.32417690959650
3.15161168322698,0.32417690959650
2.92220949434164,0.25736425612108
2.93389111001614,0.05224953101619
3.00549399142725,0.00010000000000
3.34888179054002,0.00010000000000
3.34888179054002,0.32417690959650
*LWPOLYLINE
3.57679473408223,1.01790146152510
3.57679473408223,0.83456485024469
3.44421172347698,0.78360397581583
3.15527423779965,0.71566215621148
3.19601496840083,0.87852086403109
3.41369711466930,1.03487992070231
3.57679473408223,1.01790146152510
*LWPOLYLINE
3.86738813143966,0.58337060642318
3.83746323753791,0.84595222640707
3.73344146483806,1.11520040778873
3.57719473408223,1.01797061697598
3.57719473408223,0.83445564194878
3.66221469097450,0.53877534257427
3.86738813143966,0.58337060642318
*LWPOLYLINE
3.66196325599892,0.53856416977056
3.56332020100036,0.42298764735279
3.34895989235118,0.32437690959650
3.15174705630338,0.32437690959650
3.23336062877583,0.52148360146984
3.44433175430850,0.78332871413536
3.57692877684050,0.83429497432244
3.66196325599892,0.53856416977056
*LWPOLYLINE
3.66200050292966,0.42280599391862
3.56340387919622,0.42280599391862
3.34908179054002,0.32421283824984
3.34908179054002,0.00010000000000
3.70621554064660,0.00010000000000
3.70621554064660,0.28004870859782
3.66200050292966,0.42280599391862
*LWPOLYLINE
3.99847226107518,0.35938967395906
3.99847226107518,0.49250250795166
3.98265338055999,0.58366165149205
3.86761829926308,0.58311362967768
3.66217421731288,0.53845954082487
3.66217421731288,0.42292112543294
3.70638892102347,0.28016491851989
3.86623728143229,0.28249100841280
3.99847226107518,0.35938967395906
*LWPOLYLINE
4.02515441091265,0.28460352599531
4.02515441091265,0.00010000000000
3.70641554064660,0.00010000000000
3.70641554064660,0.27996528471022
4.02515441091265,0.28460352599531
*LWPOLYLINE
4.30413367924914,0.18964871156068
4.14673174306678,0.47513307236743
3.99869071915651,0.35929786155562
4.02534269858442,0.28475508939912
4.15266467969082,0.13013810552518
4.30413367924914,0.18964871156068
*LWPOLYLINE
4.54630602367677,0.33860146403383
4.30434112014817,0.18951980072554
4.25121355577861,0.12998034442008
4.25121355577861,0.00010000000000
4.57188101771511,0.00010000000000
4.54630602367677,0.33860146403383
*LWPOLYLINE
4.23893702920732,0.02521356962770
4.23600764623852,0.00000000000000
4.02525441091265,0.00000000000000
4.02525441091265,0.28470499176791
4.23893702920732,0.02521356962770
*LWPOLYLINE
4.54722317565999,0.34173497470129
4.18612100505811,0.54485821136444
4.14687710961946,0.47528364443020
4.30431312790843,0.18973746793899
4.54722317565999,0.34173497470129
*LWPOLYLINE
4.61136751993339,0.51437853423804
4.57329885211446,0.61220404001163
4.46750289343816,0.75785372203540
4.28885151333754,0.78952977027159
4.23675325130835,0.78952977027159
4.15620489702067,0.69246006924729
4.15657936559847,0.57364946371320
4.54849417296813,0.34276745307863
4.61136751993339,0.51437853423804
*LWPOLYLINE
4.23688450979664,0.78962942909311
4.28894388072864,0.78955511764699
4.31514645593306,0.93474249500317
4.23688450979664,0.78962942909311
*LWPOLYLINE
4.23661738714208,0.79009572683008
4.31459517260939,0.93414422850604
4.25305696370129,1.04531513536767
4.15611113300849,1.14692500498727
4.09239770296196,1.07617760288610
4.09239770296196,0.91097681013456
4.23661738714208,0.79009572683008
*LWPOLYLINE
4.70801109755023,0.93329176655703
4.62352778151693,0.93755303096189
4.49729628015638,0.87148389435201
4.61361224106665,0.74952553604328
4.70801109755023,0.93329176655703
*LWPOLYLINE
4.46932125790003,0.83226460378960
4.46766090651647,0.75798073803234
4.53859438992813,0.67396429956045
4.61349738618748,0.74935617827594
4.53613295461995,0.83047349864733
4.46932125790003,0.83226460378960
*LWPOLYLINE
4.61365287966731,0.74914856336957
4.75402012596840,0.72359540791696
4.82418289068574,0.57945329248956
4.64623944061147,0.53689379985654
4.57354899537441,0.61237283109078
4.53879978467813,0.67384885206932
4.61365287966731,0.74914856336957
*LWPOLYLINE
4.57206789256519,0.00028126439047
4.54649517907742,0.33875254387356
4.64623311199867,0.53656636628661
4.82437179006051,0.51881376496360
4.82437179006051,0.35125564019668
4.57206789256519,0.00028126439047
*LWPOLYLINE
4.82467179006051,0.35184428483564
4.82467179006051,1.09700321080087
5.00868371997173,1.27131720855991
5.15795675661717,1.27131720855991
5.27962273740085,0.98471649311446
4.82467179006051,0.35184428483564
*LWPOLYLINE
4.75429216951600,0.72455157476592
4.82417179006051,0.83510987645294
4.82417179006051,1.09678048199827
4.76064554806168,1.09495190984522
4.70848123217985,0.93336887812435
4.75429216951600,0.72455157476592
*LWPOLYLINE
4.75969409082984,1.09516662019536
4.55129197730726,1.25032922302600
4.31640544760074,1.22154926459495
4.21360781752571,1.17079984977864
4.25376184384467,1.04569361758754
4.31536355613207,0.93440798967065
4.38429353758557,0.83299247671404
4.62320166113135,0.93806683472729
4.75969409082984,1.09516662019536

content of boundary.txt:

*LWPOLYLINE
4.08255289437355,10.09276250439400
4.08255289437355,10.09267857306840
1.10586584671010,10.07329237103019
1.10586584671010,10.09157421969086
4.08255289437355,10.09276250439400
*LWPOLYLINE
2.99998810347806,4.00000313063418
2.99999580536406,4.00000313063418
4.08257892143658,10.09266327552933
4.08255971098529,10.09266327552933
2.99998810347806,4.00000313063418
*LWPOLYLINE
2.99999775296742,4.00000184118644
2.99999775296742,3.99999621450540
0.00001072960445,3.99999621450540
0.00001072960445,4.00000143090761
2.99999775296742,4.00000184118644
*LWPOLYLINE
-2.49931484958066,-0.00101851609184
-2.49931484958066,-0.00102163169796
4.57127606574311,-0.00102332221523
4.57127429519460,-0.00101804720175
-2.49931484958066,-0.00101851609184
*LWPOLYLINE
6.74054678821628,3.01646737237143
6.74054678821628,3.01622648008920
4.57127199826347,-0.00101605441888
4.57126509312429,-0.00101605441888
6.74054678821628,3.01646737237143
*LWPOLYLINE
6.74394420521669,4.00000471313822
6.74397262252020,4.00000471313822
9.00000729919090,17.00000025330731
9.00000375809388,17.00000025330731
6.74394420521669,4.00000471313822
*LWPOLYLINE
9.00199854656797,17.00025743952006
9.00307114485281,17.00025743952006
9.15994103424950,20.99918197533170
9.15058935115142,20.99918197533170
9.00199854656797,17.00025743952006
*LWPOLYLINE
2.99999978909820,4.00000201702022
2.99999978909820,3.99999592144909
4.40711072453751,3.99999592144909
4.40711072453751,4.00000365813553
2.99999978909820,4.00000201702022
*LWPOLYLINE
0.93992738492143,10.08756919501224
0.93233447618162,10.08756919501224
2.09931423935388,17.01043053746017
2.11236344742409,17.01043053746017
0.93992738492143,10.08756919501224
*LWPOLYLINE
2.21380206652951,17.01191891181903
2.20071718190691,17.01191891181903
2.23533459218311,21.09244556170691
2.25092002246048,21.09244556170691
2.21380206652951,17.01191891181903
*LWPOLYLINE
6.74394385714427,4.00000128625949
6.74397284694039,4.00000128625949
6.74080534794294,3.01622977759656
6.74059883761924,3.01622977759656
6.74394385714427,4.00000128625949

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

Hello,

there is no exportPolyhedra (what the error is about) in the code you have posted. Please make the problem consistent.

Also please try to make it MWE, where M stands for minimal..

thanks
Jan

Can you help with this problem?

Provide an answer of your own, or ask Mahdeyeh for more information if necessary.

To post a message you must log in.