Commit f7f20d4a authored by mozul's avatar mozul

hydro-quebec : lmgc90 use instead of scontact

parent 7cd3f9a8
import numpy as np
from pylmgc90 import chipy
class LmgcParticles(object):
"""
A class definition holding data of lmgc90
in a compatible form to use coupling with
gmsh
Attributs are :
- number of disks
- volume of diskx
- reference on diskx2rbdy2 map
The methods are :
- iterate() : do one time iteration
- position() : give back position of all diskx
- velocity() : give back position of all diskx
- externalForces() : update external forces on particles
- getMeanRadius() : return the mean radius of particles
- getVolume() : give back the volume of all diskx
- writeHeader() : write header file for plot
"""
def __init__(self,space_dim, dt, theta) :
"""
Initialize LMGC90
"""
### Set dimension in chipy for dummies ###
chipy.SetDimension(2)
chipy.Initialize()
### definition des parametres du calcul ###
chipy.utilities_logMes('INIT TIME STEPPING')
chipy.TimeEvolution_SetTimeStep(dt)
chipy.Integrator_InitTheta(theta)
### lecture du modele ###
chipy.utilities_logMes('READ BEHAVIOURS')
chipy.ReadBehaviours()
chipy.utilities_logMes('READ BODIES')
chipy.ReadBodies()
chipy.utilities_logMes('LOAD BEHAVIOURS')
chipy.LoadBehaviours()
chipy.utilities_logMes('READ INI DOF')
chipy.ReadIniDof()
chipy.utilities_logMes('READ DRIVEN DOF')
chipy.ReadDrivenDof()
chipy.utilities_logMes('LOAD TACTORS')
chipy.LoadTactors()
chipy.utilities_logMes('READ INI Vloc Rloc')
chipy.ReadIniVlocRloc()
##### ecriture paranoiaque du modele ###
##utilities_logMes('WRITE BODIES')
##WriteBodies()
##utilities_logMes('WRITE BEHAVIOURS')
##WriteBehaviours()
##utilities_logMes('WRITE DRIVEN DOF')
##WriteDrivenDof()
chipy.OpenPostproFiles()
chipy.OpenDisplayFiles()
chipy.WriteDisplayFiles()
chipy.ComputeMass()
self._nbDisk = chipy.DISKx_GetNbDISKx()
self._d2bMap = chipy.DISKx_GetPtrDISKx2RBDY2()
self._position = np.empty([self._nbDisk,3], 'd')
self._velocity = np.empty([self._nbDisk,3], 'd')
self._externalF= np.empty([self._nbDisk,3], 'd')
self._volume = np.empty([self._nbDisk,1], 'd')
for i in xrange(self._nbDisk):
self._volume[i] = np.pi * chipy.DISKx_GetContactorRadius(i+1)**2
def iterate(self,freq_detect,freq_write,freq_display,ref_radius,**solver_args):
"""
Do one step of a LMGC90 computation.
Last argument is a dictionnary holding nlgs_solver list of arguments.
"""
#
chipy.IncrementStep()
chipy.ComputeFext()
for i in xrange(self._nbDisk):
chipy.RBDY2_PutBodyVector('Fext_', int(self._d2bMap[i,0]), self._externalF[i,:])
chipy.ComputeBulk()
chipy.ComputeFreeVelocity()
chipy.SelectProxTactors(freq_detect)
chipy.RecupRloc()
chipy.ExSolver(**solver_args)
chipy.StockRloc()
chipy.ComputeDof()
if freq_write > 0:
chipy.WriteOutDof(freq_write)
chipy.WriteOutVlocRloc(freq_write)
else:
chipy.WriteLastDof()
chipy.WriteLastVlocRloc()
chipy.WritePostproFiles()
if freq_display > 0:
chipy.WriteDisplayFiles(freq_display,ref_radius)
chipy.UpdateStep()
def volume(self):
""" Return the volume of particles """
return self._volume
def position(self):
""" Get current position of contactors and return it """
for i in xrange(self._nbDisk):
self._position[i,:] = chipy.DISKx_GetContactorCoor(i+1)
self._position[i,2] = 0.
return self._position[:,:2]
def velocity(self):
""" Get current velocity of body of contactor and return it
Beware : it should not work very well with clusters !
"""
for i in xrange(self._nbDisk):
self._velocity[i,:] = chipy.RBDY2_GetBodyVector('V____',int(self._d2bMap[i,0]))
self._velocity[i,2] = 0.
return self._velocity[:,:2]
def externalForces(self):
""" Get an external forces array
"""
return self._externalF[:,:2]
def __del__(self):
"""
"""
chipy.ClosePostproFiles()
chipy.CloseDisplayFiles()
chipy.Finalize()
#!/usr/bin/env python
import numpy as np
import os, time, shutil
import runf
outputdir ="output_lrun"
if not os.path.isdir(outputdir) :
os.makedirs(outputdir)
class meshVelocity :
def __init__(self) :
self.Y = 0
self.V = 0
def cb(self, cm, v, x) :
l = 0.1
L = 2
h = 0.5
H = 1.5
fx = np.minimum(1 - (np.abs(x[:, 0]) - l) / (L - l), 1.)
HX = self.Y * fx
HH = np.where(x[:, 1] > HX, H - HX , H + HX)
fy = np.minimum(1 - (np.abs(x[:, 1] - HX) - h) / (HH - h), 1.)
v[:, 0] = 0
v[:, 1] = fx * fy * self.V
def update(self, dt) :
self.Y += self.V * dt
def writep(p, odir, i) :
outputname = "%s/part-%05i" % (odir, i)
tmpoutputname = "%s/part-%05i_tmp" % (odir, i)
p.write(tmpoutputname)
shutil.move(tmpoutputname, outputname)
fric = 0.
rho_particle = 1.
tEnd = 3.
tCycle = 3.
t = 0.
g = 1.
gravity = [0., -g, 0.]
theta = 0.5
freq_write = 10
freq_display = 1
ref_radius = 0.1e-1
freq_detect = 1
solver_params = { 'type' :'Stored_Delassus_Loops ',
'norm' : 'Quad ',
'conv' : 1e-5,
'relax' : 1.0,
'gsit1' : 200,
'gsit2' : 200
}
from pylmgc90 import pre_lmgc
datbox_path = 'DATBOX'
if not os.path.isdir(datbox_path):
os.mkdir(datbox_path)
f = open('deposited')
pillar_tag = 2
l = f.readline()
space_dim = int(l.split()[1])
x = []
v = []
r = []
pb = []
for l in f.readlines():
if l[0] == 'P':
l = l.split()
x.append( map(float,l[1:space_dim+1]) )
v.append( map(float,l[space_dim+1:2*space_dim+1]) )
r.append( float(l[2*space_dim+1]) )
elif l[0] == 'S':
l = l.split()
if int(l[-1]) == pillar_tag:
pb.append( map(float,l[space_dim+1:2*space_dim+1]) )
pb.append( map(float,l[1:space_dim+1]) )
x = np.array(x)
r = np.array(r)
pb = np.array(pb)
x_extremum = []
x_extremum.append(x[:,0].min()+r.min())
x_extremum.append(x[:,0].max()-r.min())
x_extremum.append(x[:,1].min()+r.min())
x_extremum = np.array(x_extremum)
avs = pre_lmgc.avatars()
mat = pre_lmgc.materials()
mod = pre_lmgc.models()
svs = pre_lmgc.see_tables()
tac = pre_lmgc.tact_behavs()
mater = pre_lmgc.material(name='STONE',type='RIGID',density=rho_particle)
model = pre_lmgc.model(name='rigid', type='MECAx', element='Rxx2D',dimension=space_dim)
mat.addMaterial(mater)
mod.addModel(model)
for i in xrange(r.size) :
P = pre_lmgc.rigidDisk( r=r[i], center=x[i], model=model, material=mater, color='INxxx')
P.imposeInitValue(component=[1,2],value=v[i])
avs.addAvatar(P)
r_min = np.min(r)
x_min = np.min(x[:,0])
x_max = np.max(x[:,0])
y_min = np.min(x[:,1])
y_max = np.max(x[:,1])
left = pre_lmgc.rigidJonc(axe1=y_max-y_min, axe2=r_min, center=[x_min-2*r_min,y_max],model=model,material=mater,color='OUTxx')
right= pre_lmgc.rigidJonc(axe1=y_max-y_min, axe2=r_min, center=[x_max+2*r_min,y_max],model=model,material=mater,color='OUTxx')
down = pre_lmgc.rigidJonc(axe1=(x_max-x_min)/2., axe2=r_min, center=[(x_max+x_min)/2., y_min-2*r_min],model=model,material=mater,color='OUTxx')
left.rotate(psi=-np.pi/2., center=left.nodes[1].coor)
right.rotate(psi=np.pi/2., center=right.nodes[1].coor)
left.imposeDrivenDof(component=[1,2,3],dofty='vlocy')
right.imposeDrivenDof(component=[1,2,3],dofty='vlocy')
down.imposeDrivenDof(component=[1,2,3],dofty='vlocy')
avs.addAvatar(left)
avs.addAvatar(right)
avs.addAvatar(down)
to_keep = [0]
for i in xrange(1,pb.shape[0]):
keeping = True
for j in to_keep:
if (pb[i,:] == pb[j,:]).all() :
keeping = False
break
if keeping:
to_keep.append(i)
pb = pb[to_keep[:],:]
to_keep = [0]
for i in xrange(1,pb.shape[0]-1):
v1 = pb[i+1,:]-pb[i,:]
v2 = pb[i-1,:]-pb[i,:]
if abs(np.dot(v1,v2)) != np.linalg.norm(v1)*np.linalg.norm(v2) :
to_keep.append(i)
pb = pb[to_keep[::-1],:]
pillar = pre_lmgc.rigidPolygon(model,mater,np.zeros([space_dim]),color='PILAR',generation_type="full",vertices=pb)
avs.addAvatar(pillar)
def imposedVelocity(t):
tCycle = 3.
return (-1 if ((t % tCycle) < (tCycle / 2)) else 1) * 1/ (tCycle/2)
times = [0.,tCycle/2.-1.e-7,tCycle/2.]
for i in xrange(int(2*tEnd/tCycle)):
times.extend(map(lambda x: x+tCycle/2.,times[-2:]))
pre_lmgc.writeEvolution(f=imposedVelocity, instants=times, path='DATBOX/', name='v_pillar.dat')
pillar.imposeDrivenDof(component=[1,3],dofty='vlocy')
pillar.imposeDrivenDof(type='evolution',component=space_dim,dofty='vlocy',evolutionFile='v_pillar.dat')
clb_fric = pre_lmgc.tact_behav(name='iqsc0',type='IQS_CLB',fric=fric)
tac += clb_fric
IN = pre_lmgc.see_table(CorpsCandidat ="RBDY2", candidat ="DISKx", colorCandidat ='INxxx',
CorpsAntagoniste="RBDY2", antagoniste="DISKx", colorAntagoniste='INxxx',
behav=clb_fric, alert=r.min())
OUT = pre_lmgc.see_table(CorpsCandidat ="RBDY2", candidat ="DISKx", colorCandidat ='INxxx',
CorpsAntagoniste="RBDY2", antagoniste="JONCx", colorAntagoniste='OUTxx',
behav=clb_fric, alert=r.min())
PIL = pre_lmgc.see_table(CorpsCandidat ="RBDY2", candidat ="DISKx", colorCandidat ='INxxx',
CorpsAntagoniste="RBDY2", antagoniste="POLYG", colorAntagoniste='PILAR',
behav=clb_fric, alert=r.min())
svs += IN
svs += OUT
svs += PIL
post = pre_lmgc.postpro_commands()
solv = pre_lmgc.postpro_command(type='SOLVER INFORMATIONS', step=1)
post.addCommand(solv)
# file writting
pre_lmgc.writeBodies(avs,chemin=datbox_path)
pre_lmgc.writeDrvDof(avs,chemin=datbox_path)
pre_lmgc.writeDofIni(avs,chemin=datbox_path)
pre_lmgc.writeModels(mod,chemin=datbox_path)
pre_lmgc.writeBulkBehav(mat,chemin=datbox_path,gravy=gravity)
pre_lmgc.writeTactBehav(tac,svs,chemin=datbox_path)
pre_lmgc.writeVlocRlocIni(chemin=datbox_path)
pre_lmgc.writePostpro(commands=post, parts=avs, path=datbox_path)
from lmgc_particles import *
chipy.nlgs_SetWithQuickScramble()
chipy.checkDirectories()
mean_r = np.mean(r)
dt = 0.1 * mean_r * abs(tCycle)
p = LmgcParticles(space_dim,dt,theta)
outf = freq_display
mv = meshVelocity()
hydro = runf.hydro("mesh.msh", mv.cb, dt, mean_r, rhop=rho_particle, g=gravity[:space_dim])
mv.V = 0.5/dt
hydro.moveMesh()
mv.update(dt)
t = 0.
ii = 1
outputname = "%s/part-%05i" % (outputdir, 0)
#p.velocity()[:, :] = 0;
#p.write(outputname)
#writep(p, outputdir, 0)
hydro.writeSolution(outputdir, 0, t, filetype="vtk")
tic = time.clock()
while t < tEnd :
mv.V = (-1 if ((t % tCycle) < (tCycle / 2)) else 1) * 1/ (tCycle/2)
hydro.moveMesh()
hydro.solve(p.volume(), p.position(), p.velocity(), p.externalForces())
p.iterate(freq_detect,freq_write,freq_display,ref_radius,**solver_params)
t += dt
if ii %outf == 0 :
ioutput = int(ii/outf)
#writep(p, outputdir, ioutput)
hydro.writeSolution(outputdir, ioutput, t, filetype="vtk")
ii += 1
mv.update(dt)
print("%.2g/%.2g" % (t, tEnd))
print("cpu time : %g" % (time.clock() - tic))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment