TP_compression.py 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
import os, shutil

from pylmgc90.chipy import *

##### TP final : create a new directory to run the compression  #####
#
# TODO :
#  create a new directory
#  copy the current DATBOX in it
#  copy the OUTBOX/*.LAST files as .INI file in the DATBOX of the computation directory
#  change the computation directory     
#
# needed function
#

comp_path = 'COMPRESSION'
if not os.path.isdir(comp_path):
  os.mkdir(comp_path)

comp_datbox = os.path.join(comp_path,'DATBOX')
if os.path.isdir(comp_datbox):
  shutil.rmtree(comp_datbox)

shutil.copytree('DATBOX', comp_datbox)
shutil.copy('OUTBOX/DOF.LAST', os.path.join(comp_datbox,'DOF.INI'))
shutil.copy('OUTBOX/Vloc_Rloc.LAST', os.path.join(comp_datbox,'Vloc_Rloc.INI'))

overall_SetWorkingDirectory(comp_path+'/')

def applyPressure(dt, nb_layers,pressure):

  has_p = np.zeros(RBDY3_GetNbRBDY3(),dtype=np.double)
 
  nbs = SPHER_GetNbSPHER()
  s2b = SPHER_GetPtrSPHER2RBDY3()
  x = np.empty([nbs,4],dtype=np.double)
  for i in xrange(nbs):
    x[i,:3] = RBDY3_GetBodyVector('Coorb',int(s2b[i,0]))[:3]
    x[i,3]  = SPHER_GetContactorRadius(i+1)

  r  = np.empty([x.shape[0]])
  for i in xrange(x.shape[0]):
    r[i]  = np.linalg.norm(x[i,:2])

  h0 = np.min(x[:,2]-x[:,3])
  h  = np.max(x[:,2]+x[:,3]) - h0
  dh = h/nb_layers

  layer = []
  for i in xrange(nb_layers):
    layer.append([])
  for i in xrange(s2b.shape[0]):
    layer[int((x[i,2]-h0)/dh)].append(i)

  f_ext = np.zeros([6])

  for k in layer:
    k = np.array(k)
    r_out = np.max( r[k] + x[k,3] )
    dr    = 2.*np.max( x[k,3] )
    sic   = np.nonzero( r[k] > r_out - dr )
    F  = pressure * 2.*np.pi*r_out * dh / np.sum( r[k[sic[0]]] )
    for i in sic[0]:
      has_p[k[i]] = 1.
      f_ext[:2] = - x[k[i],3] * F * x[k[i],:2] / r[k[i]]
      RBDY3_PutBodyVector('Fext_',int(s2b[k[i],0]),dt*f_ext)

  return has_p

checkDirectories()

dt = 1.e-2
nb_steps = 1000

theta = 0.5

freq_detect = 1
tol = 0.166e-4
relax = 1.0
norm = 'Quad '
gs_it1 = 33
gs_it2 = 100
83
storage='Stored_Delassus_Loop          '
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
nlgs_SetWithQuickScramble()

freq_write   = 10
freq_display = 10
ref_radius   = 1.

confinent_p = 5.e6
nb_layers   = 10

SetDimension(3)

TimeEvolution_SetTimeStep(dt)
Integrator_InitTheta(theta)

ReadBehaviours()
ReadBodies()
LoadBehaviours()
ReadIniDof()
ReadDrivenDof()

LoadTactors()

ReadIniVlocRloc()

WriteBodies()
WriteBehaviours()
WriteDrivenDof()

OpenDisplayFiles()
OpenPostproFiles()

ComputeMass()

nbs = SPHER_GetNbSPHER()
s2b = SPHER_GetPtrSPHER2RBDY3()
x = np.empty([nbs,4],dtype=np.double)
for i in xrange(nbs):
  x[i,:3] = RBDY3_GetBodyVector('Coorb',int(s2b[i,0]))[:3]
  x[i,3]  = SPHER_GetContactorRadius(i+1)

h0 = np.min(x[:,2]-x[:,3])
h  = np.max(x[:,2]+x[:,3]) - h0
dh = h / nb_layers

slayerId = np.empty([nbs])
for i in xrange(nbs):
  slayerId[i] = int((x[i,2]-h0)/dh) + 1

layerID = {'SPHER':slayerId}
layerID['PLANx'] = np.zeros(PLANx_GetNbPLANx())
layerID['DNLYC'] = np.zeros(DNLYC_GetNbDNLYC())

has_p = applyPressure(dt,nb_layers,confinent_p)

WriteDisplayFiles(freq_display,ref_radius,has_p=('rigid', has_p),layerID=('tactor',layerID))

for k in xrange(nb_steps):
  #
  IncrementStep()
  
  ComputeFext()
  has_p = applyPressure(dt, nb_layers, confinent_p)
  
  ComputeBulk()
  ComputeFreeVelocity()
  
  SelectProxTactors(freq_detect)
  
  RecupRloc()
  ExSolver(storage,norm,tol,relax,gs_it1,gs_it2)
  StockRloc()
  
  ComputeDof()
  UpdateStep()
  
  WriteLastDof()
  WriteLastVlocRloc()

  WriteDisplayFiles(freq_display,ref_radius,has_p=('rigid', has_p),layerID=('tactor',layerID))

CloseDisplayFiles()
ClosePostproFiles()