yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #21400
Re: [Question #686446]: saving image of polyhedrals in paraview format
Question #686446 on Yade changed:
https://answers.launchpad.net/yade/+question/686446
Status: Needs information => Open
Mahdeyeh gave more information on the question:
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')
--
You received this question notification because your team yade-users is
an answer contact for Yade.