Advertisement
nicogodet

Untitled

Jun 29th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 64.03 KB | None | 0 0
  1. ########################################## encoding: utf-8 #######################################
  2. from yade.gridpfacet import *
  3. from yade import pack,plot
  4. import math
  5. import random as rand
  6. import numpy as np
  7. from scipy.stats import gaussian_kde
  8.  
  9. # Time step
  10. O.dt=1e-6
  11.  
  12. # Skeleton creation
  13. #title='FILETAIEAIE'
  14. #folder=os.path.dirname(sys.argv[0])+"Results/"+str(title)+'/'
  15. #if os.path.exists(folder)==False:
  16.     #os.mkdir(folder)
  17.     #os.mkdir(folder+'VTK/')
  18.    
  19.    
  20.  
  21.                 # Geometry and date #
  22. ##########################################  BASSIN #######################################
  23. young=6e8                          
  24. color=[0.,1.,1.]
  25. RBASSIN=0.01                            # Rudius Pfacet
  26. Base=3.78;base=3.78;Hight=2.;AB=(Base-base)/2 ;Long=10. # Channel dimensions
  27. frictvirtual=30                         # virtual friction angle (Only in the area where the mesh is placed)
  28. frictreal=20                            # friction angle
  29.  
  30. slope_channel = math.radians(31)    #Slope of the channe, in radian
  31. length_channel = 90 #Length of the channe, in m
  32. width_channel = 4   #Width of the channel, in m
  33. height_channel = 2  #Height of the channel, in m
  34. gravityVector = Vector3(0.,-9.81*sin(slope_channel),-9.81*cos(slope_channel))   #Gravity vector to consider a channel inclined with slope angle 'slope'
  35.  
  36.  
  37. ##########################################  Geometry and date FENCE PARAMETERS #######################################
  38. #CenterCoord = [0.,1.01*Hight,Long/3.] #Coordonnees du centre du filet
  39.  
  40. Nx=12.          #24-> 15.12m        # Loops in X
  41. Nz=18.          #27-> 4.9m      # Loops/2 in z
  42. Rfilet=0.008/2                      # Mesh radius
  43. young_wire=60e9                     # Young
  44. young_Conn=60e9
  45. frict_wire=10#10                 # friction angle
  46. frict_Con=10.   #30
  47.  
  48. Lx=0.63/2                           # Length of one loop
  49. Lz=0.35/2                           # Hight of one loop
  50. Lz1=Lz/2                       
  51. Lx1=Lx*4/5
  52. CenterCoord = [Base/2,Long/2.,((Nz+1) * Lz/2)/2]    # Center
  53.  
  54.     ########### BOUCLE ############
  55. ouv = 0.04 /2                       # Oppening of boucle
  56. Rman = 0.005 /2                     # Boucle section radius
  57. decman = ouv/2+Rman+Rfilet              # Gap
  58.  
  59. ########################################## CABLE #######################################
  60. # Initial vaule of pretension the legth of the vector depending on the number of cables
  61. PreTimput=[0,0,0]
  62. # Value of pretension
  63. ForcePretini=[4000.,4000.,4000.]
  64.  
  65. ForcePret=[10000.,10000.,10000.]
  66. # If braided=> 1
  67. Braid=[0,1,1]
  68. # position of the cables lookingfor: z_cable ###REFERENCE MESH 0 Zmax=(Nz+1) * Lz/2
  69. z_cable=[(Nz+1)*Lz/2,1.5/2,0.]
  70.  
  71. # Cable radius
  72. Rcable=0.012/2                             
  73.  
  74. ########################################## FREINS #######################################
  75.  
  76. Rfrein = 0.012/2                # Cable radius
  77. Ffrein = 176e3                  # Force frein to stard (the maximun force is define inside de function)
  78.  
  79. ########################################## LAVES TORRENTIELLES PARAMETERS #######################################
  80.  
  81. rb=.5                  
  82. young_sph=10e8
  83. spIds=[]
  84. vel_front=Vector3(0.,0.,0.)
  85. ### Engines need to be defined first since the function gridConnection creates the interaction
  86.  
  87. ########################################## MATERIAL #######################################
  88.  
  89.     ################### SCRIPT NICO ##################
  90. # Channel
  91. chanFrictAng =  70.
  92.  
  93. #Fluid
  94. fluidDensity =  1200.   #Density of the fluid, in kg/m3, used for the computation of the dragforce
  95. m_viscosity =   2   #Test avec 0.022
  96.  
  97. # Debris
  98. diameterPart =  0.2 #Diameter of the particles, in m
  99. m_roughness =   0.01    #Fraction on the radius
  100. sphDensity =    2500
  101. sphYoung =  1e7
  102. sphPoisson =    0.2
  103. sphFrictAng =   35.
  104.  
  105. O.materials.append(
  106.         FrictMat(
  107.             density=sphDensity,
  108.             frictionAngle=math.radians(sphFrictAng),
  109.             poisson=sphPoisson,
  110.             young=sphYoung,
  111.             label='Frict'
  112.         ))
  113.  
  114. O.materials.append(
  115.                 FrictMat(
  116.                         density=2500,
  117.                         frictionAngle=math.radians(chanFrictAng),
  118.                         poisson=0.2,
  119.                         young=1e7,
  120.                         label='FrictBase'
  121.                 ))
  122.  
  123. O.materials.append(
  124.                 FrictMat(
  125.                         density=2500,
  126.                         frictionAngle=math.radians(0.),
  127.                         poisson=0.2,
  128.                         young=1e7,
  129.                         label='FrictWall'
  130.                 ))
  131.  
  132. O.materials.append(
  133.                 FrictMat(
  134.                         density=2500,
  135.                         frictionAngle=math.radians(20.),
  136.                         poisson=0.2,
  137.                         young=1e7,
  138.                         label='FrictRigid'
  139.                 ))
  140.  
  141.     ###################### BASIN #####################
  142.  
  143. # Virtual
  144. O.materials.append( CohFrictMat( young=young,poisson=0.3,density=2650,frictionAngle=radians(frictvirtual),normalCohesion=3e100,shearCohesion=3e100,momentRotationLaw=True,label='gridNodeMat1' ) )  # material to create the gridConnections
  145. O.materials.append( FrictMat( young=young,poisson=0.3,density=2650,frictionAngle=radians(frictvirtual),label='pFacetMat1' ) )  # material for general interactions
  146. # Real
  147. O.materials.append( CohFrictMat( young=young,poisson=0.3,density=2650,frictionAngle=radians(frictreal),normalCohesion=3e100,shearCohesion=3e100,momentRotationLaw=True,label='gridNodeMat' ) )  # material to create the gridConnections
  148. O.materials.append( FrictMat( young=young,poisson=0.3,density=2650,frictionAngle=radians(frictreal),label='pFacetMat' ) )  # material for general interactions
  149.  
  150.     ###################### FENCE #####################
  151.  
  152. # Stress–strain curve
  153. E1_1 = 500e6
  154. E2_1 = 1460e6
  155. Ef_1 = 5869.565e6
  156. Defini_1 = 0.0001
  157. Def1_1 = 0.060
  158. Def2_1 = 0.015+Def1_1
  159. Deff_1 = 0.041+Def2_1
  160. SSVal_Simple=[(Defini_1,2*Defini_1*Ef_1),(Def1_1,Def1_1*E1_1),(Def2_1,Def2_1*E2_1),(Deff_1,2*Deff_1*Ef_1)]#[(0.0001,5.09e6),(0.030,50e6),(0.043,155e6),(0.067,1250e6)]
  161.  
  162. O.materials.append( WireMat( young=young_wire,poisson=0.3,frictionAngle=radians(frict_wire),density=7850,diameter=2*Rfilet,isDoubleTwist=False,label='gridNodeNetPackSimple',strainStressValues=SSVal_Simple) ) # Material to create the GridNode
  163.  
  164. SSVal_Double=[(0.0001,5.09e6),(0.020,50e6),(0.035,250e6),(0.088,2000e6)]      
  165. SSVal_Double=SSVal_Simple
  166.  
  167. O.materials.append( WireMat( young=young_wire,poisson=0.3,frictionAngle=radians(frict_wire),density=7850,diameter=2*Rfilet,isDoubleTwist=False,label='gridNodeNetPackDouble',strainStressValues=SSVal_Simple) ) # Material to create the GridNode
  168.  
  169. O.materials.append(FrictMat( young=young_Conn,poisson=0.3,density=7850,frictionAngle=radians(frict_Con), label='CohMat'))#normalCohesion=200e6,isCohesive=True,shearCohesion=200e2,momentRotationLaw=False, label='CohMat') ) # Material to create the iteraction (Gridconection)
  170.  
  171. ######################################### ENGINES #######################################
  172.  
  173. # Definition of simulation's variable
  174. Factor = 1.5    #Factor ratio for the distance detection of distant interactions
  175. theta_method = 0.55 #1 : Euler Backward, 0.5 : trapezoidal rule, 0 : not used, 0.55 : suggested optimum
  176. resolution = 1      #Change normal component resolution method, 0: Iterative exact resolution (theta method, linear contact), 1: Newton-Rafson dimentionless resolution (theta method, linear contact), 2: Newton-Rafson with nonlinear surface deflection (Hertzian-like contact)
  177. NewtonRafsonTol = 1e-6  #Precision of the resolution of Newton-Rafson's method
  178. vel_front = Vector3(0.,0.,0.)
  179.  
  180. O.engines=[
  181.     ForceResetter(),
  182.     InsertionSortCollider([
  183.         Bo1_Sphere_Aabb(aabbEnlargeFactor=Factor, label="aabb"),
  184.         Bo1_GridConnection_Aabb(),
  185.         Bo1_Wall_Aabb(),
  186.         Bo1_Box_Aabb()],
  187.         verletDist=-0.1,
  188.         allowBiggerThanPeriod=False
  189.     ), 
  190.     InteractionLoop([
  191.         Ig2_Sphere_Sphere_ScGeom(),
  192.         Ig2_GridNode_GridNode_GridNodeGeom6D(),        
  193.         Ig2_GridConnection_GridConnection_GridCoGridCoGeom(),  
  194.         Ig2_Sphere_GridConnection_ScGridCoGeom(),      
  195.         Ig2_Sphere_Sphere_ScGeom6D(interactionDetectionFactor=Factor,label="Ig2"),
  196.         Ig2_Box_Sphere_ScGeom6D(),
  197.     ], 
  198.     [
  199.         Ip2_WireMat_WireMat_WirePhys(),
  200.         Ip2_CohFrictMat_CohFrictMat_CohFrictPhys(setCohesionNow=True,setCohesionOnNewContacts=False),
  201.        
  202.         Ip2_FrictMat_FrictMat_FrictPhys(),
  203.         Ip2_FrictMat_FrictMat_LubricationPhys(eta=m_viscosity,eps=m_roughness,label="Phys_Lub"),
  204.     ],
  205.     [
  206.         Law2_ScGeom6D_CohFrictPhys_CohesionMoment(),
  207.         Law2_ScGeom_FrictPhys_CundallStrack(),
  208.         Law2_ScGridCoGeom_FrictPhys_CundallStrack(),
  209.         Law2_ScGeom_WirePhys_WirePM(),
  210.         Law2_GridCoGridCoGeom_FrictPhys_CundallStrack(),
  211.         Law2_ScGeom_ImplicitLubricationPhys(
  212.                         activateNormalLubrication=True,
  213.                         activateTangencialLubrication=True,
  214.                         activateTwistLubrication=True,
  215.                         activateRollLubrication=True,
  216.                         theta=theta_method,
  217.                         resolution=resolution,
  218.                         warnedOnce=True,
  219.                         maxSubSteps=20,
  220.                         NewtonRafsonTol=NewtonRafsonTol,
  221.                         debug=False)
  222.  
  223.     ]
  224.     ),
  225.     #DragEngine(Rho=1200,Cd=0.47,V=vel_front, label='Drag', dead=True),
  226.     NewtonIntegrator(gravity=gravityVector,damping=0.3,label='newton'),
  227.     PyRunner(command='Tension()',iterPeriod=700,label='measureTension',dead=True), # Measure the tension
  228. #   PyRunner(command='StaTension()',iterPeriod=5,label='stabtension',dead=True), # Stabalize after tension
  229.     PyRunner(command='StaCable()',iterPeriod=700,label='cableengine'),  # mesh placed
  230.     PyRunner(command='gravityDeposit()',iterPeriod=500,label='gravDep',dead=False),
  231.     PyRunner(command='Fx, Fy, Fz=Force_wall()',iterPeriod=1000,label='FWall',dead=True),
  232.     PyRunner(command='deadZone()',iterPeriod=1000,label='deadZone_engine',dead=True),
  233.     PyRunner(command='max_pos_x,height_front, vel_front=front()',iterPeriod=1000,label='dista',dead=True),
  234.     PyRunner(command='vel_profil()',iterPeriod=1000,label='velProfil',dead=True),
  235.     PyRunner(command='shearLub_tot,shearCon_tot=bedshear_total()',iterPeriod=1000,label='bedshear_tot_engine',dead=True),
  236. #   PyRunner(command='shearLub1,shearCon1=bedshear_at_x(0.15*length)',iterPeriod=1000,label='bedshear_1_engine',dead=True),
  237. #    PyRunner(command='shearLub2,shearCon2=bedshear_at_x(30)',iterPeriod=1000,label='bedshear_2_engine',dead=True),
  238. #    PyRunner(command='shearLub3,shearCon3=bedshear_at_x(50)',iterPeriod=1000,label='bedshear_3_engine',dead=True),
  239. #    PyRunner(command='shearLub4,shearCon4=bedshear_at_x(75)',iterPeriod=1000,label='bedshear_4_engine',dead=True),
  240.     #VTKRecorder(fileName=folder+'/VTK/vtk-',virtPeriod=0.1),
  241. ]
  242.  
  243. #Drag.ids=spIds
  244. #Drag.Rho=fluidDensity
  245. #Drag.Cd=0.47
  246.  
  247. collider.avoidSelfInteractionMask = 2
  248.  
  249. ######################################### CONSTRUCTION DU BASSIN #######################################
  250.  
  251. boxColor = (104/255., 111/255., 140/255.)
  252. chanBack = O.bodies.append(aabbWalls([(0,length_channel/3.,0),(0,length_channel/3.,height_channel)],thickness=0.0,material='FrictWall',oversizeFactor=1.0,color=boxColor))
  253. chanS1 = O.bodies.append(aabbWalls([(0,length_channel/3.,0),(0,0,height_channel)],thickness=0.0,material='FrictWall',oversizeFactor=1.0,color=boxColor))
  254. chanB = O.bodies.append(aabbWalls([(0,length_channel/3.,0),(width_channel,0,0)],thickness=0.0,material='FrictBase',oversizeFactor=1.0,color=boxColor))
  255. chanS2 = O.bodies.append(aabbWalls([(width_channel,0,0),(width_channel,length_channel/3.,height_channel)],thickness=0.0,material='FrictWall',oversizeFactor=1.0,color=boxColor))
  256. chanBottom = O.bodies.append(aabbWalls([(0,0,0),(width_channel,0,height_channel)],thickness=0.0,material='FrictWall',oversizeFactor=1.0,color=boxColor))
  257.  
  258.  
  259. DepBox = O.bodies.append(aabbWalls([(0.,length_channel/3.,-0.1),(width_channel,length_channel/3.-0.1*length_channel,2*height_channel)],thickness=0.0,material='FrictWall',oversizeFactor=1.0,color=boxColor))
  260.  
  261. ######################################### AJOUT ECOULEMENT #######################################
  262.  
  263. partCloud = pack.SpherePack()
  264. partCloud.makeCloud(minCorner=(0.,length_channel/3.-length_channel/10./2.,0.),maxCorner=(width_channel,length_channel/3.-0.095*length_channel,height_channel*2.), rMean=diameterPart/2.0)
  265. spIds = partCloud.toSimulation(material='Frict',color=[205./255,175./255,149./255])
  266. allSp = spIds
  267.  
  268. ######################################### CONSTRUCTION DU MAILLAGE #######################################
  269.  
  270.     ##################### TAILLE REELLE #####################
  271.  
  272. Lxreel = Nx * Lx           
  273. Lzreel = (Nz+1) * Lz/2
  274. print 'Longueur réelle X = ', Lxreel
  275. print 'Longueur réelle Z = ', Lzreel
  276. Agraphes = []
  277.    
  278. hz = Nz+1                   # Number of heights
  279. xstart = CenterCoord[0] - (Nx*Lx/2)         # Coordinates of the left inf angle
  280. y = CenterCoord[1]
  281. zstart = CenterCoord[2]- ((hz*0.5*Lz)/2)
  282.  
  283. if (Nz%2==0):                   # Numbers of loops z           
  284.     kz = int(Nz/2 + 1)
  285. else:
  286.     kz = int(ceil(Nz/2))
  287.  
  288.    
  289. Nx = int(Nx)
  290.  
  291. NetPack = []                    # All point of the mesh
  292. ItLeft = []                 # Left side
  293. ItRight = []                    # Right side
  294. ItCenter = []
  295.  
  296. for i in range(Nx+1):               # Loops x
  297.     x = xstart + Lx*i
  298.         for j in range(kz):         # loops z
  299.         z = zstart + Lz*j
  300. ################################### ACCROCHE COTE GAUCHE ######################################
  301.     # Note: the radius is 1.01*Rfilet and 0.99*Rfilet because in that way when you create a grid connection betwen two GridNode with diferent characteristics it  takes the inf of the bigest radius
  302.         if i == 0:
  303.                     NetPack += [O.bodies.append( gridNode([x+Lx/4,y,z+Lz/2],1.01*Rfilet, color=[0,0,1],material='gridNodeNetPackDouble',wire=False,highlight=False,fixed=False))]
  304.                     ItLeft.append(NetPack[-1])
  305.                     Agraphes.append(NetPack[-1])
  306.                     if j != 0:
  307.                         NetPack += [ O.bodies.append( gridNode([x,y,z],0.99*Rfilet, color=[1,0,0],material='gridNodeNetPackSimple',wire=False,highlight=False,fixed=False))]
  308.                 ItLeft.append(NetPack[-1])
  309.  
  310.     ##################### ACCROCHE COTE DROIT #####################
  311.         if i == Nx:
  312.                     NetPack += [ O.bodies.append( gridNode([x-Lx/4,y,z],1.01*Rfilet, color=[0,0,1],material='gridNodeNetPackDouble',wire=False,highlight=False,fixed=False))]
  313.                     Agraphes.append(NetPack[-1])
  314.                     ItRight.append(NetPack[-1])
  315.                     if j != kz-1:
  316.                         NetPack += [ O.bodies.append( gridNode([x,y,z+Lz/2],0.99*Rfilet, color=[1,0,0],material='gridNodeNetPackSimple',wire=False,highlight=False,fixed=False))]
  317.                         ItRight.append(NetPack[-1])
  318.  
  319.                     if j == kz-1:
  320.                         if Nz%2 != 0:
  321.                             NetPack +=[ O.bodies.append( gridNode([x,y,z+Lz/2],0.99*Rfilet, color=[1,0,0],material='gridNodeNetPackSimple',wire=False,highlight=False,fixed=False))]
  322.                             ItRight.append(NetPack[-1])
  323.                             NetPack +=[ O.bodies.append( gridNode([x-Lx/4,y,z+Lz],1.01*Rfilet, color=[0,0,1],material='gridNodeNetPackDouble',wire=False,highlight=False,fixed=False))]
  324.                             Agraphes.append(NetPack[-1])
  325.                             ItRight.append(NetPack[-1])
  326.  
  327.     ##################### RESTE MAILLAGE #####################
  328.                 if i!= 0 and i!= Nx:
  329.                     NetPack += [ O.bodies.append( gridNode([x-Lx/4,y,z],1.01*Rfilet, color=[0,0,1],material='gridNodeNetPackDouble',wire=False,highlight=False,fixed=False))]
  330.                     Agraphes.append(NetPack[-1])
  331.                     ItCenter.append(NetPack[-1])
  332.                
  333.                     NetPack +=[ O.bodies.append( gridNode([x,y,z+Lz/4],0.99*Rfilet, color=[0,1,0],material='gridNodeNetPackSimple',wire=False,highlight=False,fixed=False))]
  334.                     ItCenter.append(NetPack[-1])
  335.                     NetPack += [ O.bodies.append( gridNode([x+Lx/4,y,z+Lz/2],1.01*Rfilet, color=[0,0,1],material='gridNodeNetPackDouble',wire=False,highlight=False,fixed=False))]
  336.                     Agraphes.append(NetPack[-1])
  337.                     ItCenter.append(NetPack[-1])
  338.                
  339.                     if j != kz-1:
  340.                         NetPack += [ O.bodies.append( gridNode([x,y,z+3*Lz/4],0.99*Rfilet, color=[0,1,0],material='gridNodeNetPackSimple',wire=False,highlight=False,fixed=False))]
  341.                         ItCenter.append(NetPack[-1])
  342.                     if j == kz-1:
  343.                         if  Nz%2!=0:
  344.                              NetPack += [ O.bodies.append( gridNode([x,y,z+3*Lz/4],0.99*Rfilet, color=[0,1,0],material='gridNodeNetPackSimple',wire=False,highlight=False,fixed=False))]
  345.                              ItCenter.append(NetPack[-1])
  346.                              NetPack += [ O.bodies.append( gridNode([x-Lx/4,y,z+Lz],1.01*Rfilet, color=[0,1,0],material='gridNodeNetPackDouble',wire=False,highlight=False,fixed=False))]
  347.                              Agraphes.append(NetPack[-1])
  348.                              ItCenter.append(NetPack[-1])
  349.            
  350. ##################### Détermination des coordonnees maximales et minimales ####################
  351.  
  352. xmax = CenterCoord[0]
  353. xmin = CenterCoord[0]
  354. zmax = CenterCoord[2]
  355. zmin = CenterCoord[2]
  356. id1 = NetPack[1]
  357. xmax = O.bodies[id1].state.pos[0]
  358. xmin = O.bodies[id1].state.pos[0]
  359. zmax = O.bodies[id1].state.pos[2]
  360. zmin = O.bodies[id1].state.pos[2]
  361. for i in NetPack:
  362.     id1 = i
  363.     if xmax < O.bodies[i].state.pos[0]:
  364.             xmax = O.bodies[i].state.pos[0]
  365.         if zmax < O.bodies[i].state.pos[2]:
  366.             zmax = O.bodies[i].state.pos[2]
  367.         Idzmax=i
  368.         if xmin > O.bodies[i].state.pos[0]:
  369.             xmin = O.bodies[i].state.pos[0]
  370.         if zmin > O.bodies[i].state.pos[2]:
  371.             zmin = O.bodies[i].state.pos[2]
  372.         Idzmin=i
  373.  
  374. print 'xmin =', xmin
  375. print 'xmax =', xmax
  376. print 'zmin =', zmin
  377. print 'zmax =', zmax
  378.  
  379. #### y=mx+n Equation of channel slope
  380. m=(-Hight)/(AB-xmin)
  381. n=zmax-m*xmin
  382.  
  383.     ##################### DEFINITION INERACTIONS #####################
  384.  
  385. Pos1 = lambda x: O.bodies[x].state.pos[2]   # To sort the list
  386. Pos0 = lambda x: O.bodies[x].state.pos[0]
  387. list.sort(ItLeft, key = Pos1)
  388. list.sort(ItRight, key = Pos1)  
  389. list.sort(Agraphes, key = Pos0)
  390. list.sort(Agraphes, key = Pos1)
  391.  
  392.    
  393. for i,j in zip(ItLeft[:-1], ItLeft[1:]):#it gauche
  394.     O.bodies.append( gridConnection(i,j,Rfilet,material='CohMat',color=[1,2,1],mask=3))
  395. for i,j in zip(ItCenter[:-1], ItCenter[1:]):#it centre
  396.     if O.bodies[i].state.pos[2] != zmax:
  397.         O.bodies.append( gridConnection(i,j,Rfilet,material='CohMat',color=[1,2,1],mask=3))
  398. for i,j in zip(ItRight[:-1], ItRight[1:]):#it Droite
  399.         O.bodies.append( gridConnection(i,j,Rfilet,material='CohMat',color=[1,2,1],mask=3))
  400.  
  401. for i,j in zip(ItCenter[:-2], ItCenter[2:]) :#it centre verticale
  402.         if O.bodies[i].state.pos[0] == O.bodies[j].state.pos[0]:
  403.                 O.bodies.append( gridConnection(i,j,Rfilet,material='CohMat',color=[1,2,1],mask=3))
  404. for i, j in zip(Agraphes[:-Nx], Agraphes[Nx:]):
  405.         O.bodies.append( gridConnection(i,j,Rfilet,material='CohMat',color=[1,2,1],mask=3))
  406.  
  407. ############################# NOEUDS Sup et Inf ##################################
  408.  
  409. Netsup = []         # To create the Boucle
  410. Netinf =[]          # To have a list with the inf points
  411. for i in O.bodies:
  412.     if zmax == i.state.pos[2]:
  413.         Netsup += [i.id]
  414.     if zmin == i.state.pos[2]:
  415.         Netinf += [i.id]
  416. side=[]
  417. side+=ItLeft + ItRight
  418.  
  419.  
  420.  
  421. ########################################## Function CABLE #######################################
  422.  
  423. def CABLEc(cablez,Braid,ForcePret) :
  424. ## cablex,cablez are the initial point cable in the final position. If Braid=1 is true if Braid =0 => False
  425.  
  426. ##### Parameters
  427.     Young_cab=60e9
  428.     Young_cabco=Young_cab
  429.     strenruptc=1400e9           #A.Trad & D.Betrand If 360e3 Error=> Ask
  430.     densityc=7850.
  431.     frottement=10.
  432.     shearCohc = 1e100  
  433.     Rcable=0.012/2
  434.     dec_cable=2*Rcable+Rfilet       # Gap between net and cable
  435.  
  436. ########################################## Material #######################################
  437.  
  438.     O.materials.append(CohFrictMat(young=Young_cab,poisson=0.3,density=densityc,frictionAngle=radians(frottement),normalCohesion=pi*strenruptc,isCohesive=True,shearCohesion=shearCohc,momentRotationLaw=False, alphaKr = 1.0,label='cablemat'))
  439.  
  440.     O.materials.append(FrictMat(young=Young_cabco,poisson=0.3,density=densityc,frictionAngle=radians(frottement),label='cablecomat'))
  441.  
  442. ########################################## CÂBLE #######################################
  443.     cable=[]
  444.     cablecon=[]
  445.     deplx=0.    # To create the Pretension
  446.     deply=0.
  447.     deplz=0.
  448.     if  Braid==1:   # If Braid=1 the cable is braided in other case used Boucle (The boucle can only be used on the upper cable)
  449.         posz=cablez/(Lz/2)  # Position related with loops  
  450. ### to have all the time contact with the basin, its take the point after and add the last segment
  451.         if posz!=0 and posz <= (Nz+1)*0.99:
  452.             if 0.<=posz-int(posz)<=0.5:
  453.                 posz=int(posz)+0.5
  454.             if 0.5 < posz-int(posz)<1:
  455.                 posz=int(posz)+1.5
  456.         posx=((posz*(Lz/2)-n)/m+4*Rfrein+2*RBASSIN)/Lx
  457.         if int(posx)< 1:
  458.             if 0<posx-int(posx) < 0.25:
  459.                 posx1=int(posx)+0.25
  460.                 print '1'
  461.             if 0.25 <= posx-int(posx) < 0.5:
  462.                 posx1=int(posx)+0.75
  463.                 print '2'
  464.             if 0.5 <= posx-int(posx) < 1:
  465.                 posx1=int(posx)+1.75
  466.                 print '3'
  467.         else:
  468.             if 0.<=posx-int(posx) < 0.5:
  469.                 posx1=int(posx)+0.75
  470.                 print '4'
  471.             if 0.5 <= posx-int(posx) < 1:
  472.                 posx1=int(posx)+1.25
  473.                 print '5'
  474.  
  475.         zCa=posz*(Lz/2)
  476.         inipoint=Vector3(posx1*Lx+xmin,CenterCoord[1],posz*(Lz/2))
  477.         finpoint=Vector3((Nx-posx1)*Lx+xmin,CenterCoord[1],posz*(Lz/2))
  478.         Long_cable = finpoint-inipoint
  479.         lfinal = abs(Long_cable)
  480.         direction=Long_cable/abs(Long_cable)
  481.         kx=int(lfinal/(Lx/16))
  482.         print posx, posx1, posz
  483.         if round(posz,1) == float(Nz+1):    # Sup Normally with boucle
  484.             if Nz%2==0:
  485. # create all the points that make up the cable
  486.                 cable.append(O.bodies.append(gridNode([(posx*Lx),CenterCoord[1],posz*(Lz/2)-2.1*Rcable],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  487.                 cable.append(O.bodies.append(gridNode([inipoint[0]+dec_cable/5,inipoint[1]-dec_cable,inipoint[2]-2.25*Rcable],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  488.                 for i in range(kx+1):
  489.                     if i!=0 and i != kx:
  490.                         if i%2==0:
  491.                             x = inipoint[0] + (direction*abs(Long_cable))[0]*i/kx
  492.                             y = inipoint[1] + (direction*abs(Long_cable))[1]*i/kx
  493.                             z = inipoint[2] + (direction*abs(Long_cable))[2]*i/kx-2.25*Rcable
  494.                             cable.append(O.bodies.append(gridNode([x,y,z],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  495.                         else:
  496.                             x = inipoint[0] + (direction*abs(Long_cable))[0]*i/kx
  497.                             y = inipoint[1] + (direction*abs(Long_cable))[1]*i/kx
  498.                             z = inipoint[2] + (direction*abs(Long_cable))[2]*i/kx-2.25*Rcable
  499.                             cable.append(O.bodies.append(gridNode([x,y,z],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  500.                     else:
  501.                         x = inipoint[0] + (direction*abs(Long_cable))[0]*i/kx
  502.                         y = inipoint[1] + (direction*abs(Long_cable))[1]*i/kx
  503.                         z = inipoint[2] + (direction*abs(Long_cable))[2]*i/kx-2.25*Rcable
  504.                         cable.append(O.bodies.append(gridNode([x,y,z],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  505.  
  506.                 cable.append(O.bodies.append(gridNode([((Nx-posx)*Lx),CenterCoord[1],posz*(Lz/2)-2.1*Rcable],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  507.  
  508. ### Pretension
  509. #           Long_cable=( O.bodies[cable[-1]].state.pos- O.bodies[cable[0]].state.pos)
  510. #           lfinal = abs(Long_cable)
  511. #           linit = Young_cabco*lfinal/((ForcePret/(pi*Rcable*Rcable))+Young_cabco)
  512. #           deltaL=lfinal-linit
  513. #           if ForcePret!= 0:
  514. #               for k in cable:
  515. #                   i=O.bodies[k]
  516. #                   if Long_cable[0] != 0: 
  517. #                       deplx = ((direction*deltaL)[0]/(direction*linit)[0])*(i.state.pos[0]-O.bodies[cable[0]].state.pos[0])
  518. #                   if Long_cable[1] != 0: 
  519. #                       deply = ((direction*deltaL)[1]/(direction*linit)[1])*(i.state.pos[1]-O.bodies[cable[0]].state.pos[1])
  520. #                   if Long_cable[2] != 0: 
  521. #                       deplz = ((direction*deltaL)[2]/(direction*linit)[2])*(i.state.pos[2]-O.bodies[cable[0]].state.pos[2])
  522. #                   i.state.pos=Vector3(i.state.pos[0]+deplx,i.state.pos[1]+deply,i.state.pos[2]+deplz)
  523.  
  524. ## Braid
  525.                 for i in range((len(cable))/8):
  526.                     for j in range(8):
  527.                         if i%2!=0:
  528.                             if j<7:
  529.                                 x = O.bodies[cable[2+j+i*8]].state.pos[0]
  530.                                 y = O.bodies[cable[2+j+i*8]].state.pos[1] -(dec_cable/(8))*j
  531.                                 z = O.bodies[cable[2+j+i*8]].state.pos[2]
  532.                                 O.bodies[cable[2+j+i*8]].state.pos=(x,y,z)
  533.                             if 7<=j<8:
  534.                                 x = O.bodies[cable[2+j+i*8]].state.pos[0]
  535.                                 y = O.bodies[cable[2+j+i*8]].state.pos[1] -(1.2*dec_cable/(8))*j
  536.                                 z = O.bodies[cable[2+j+i*8]].state.pos[2]
  537.                                 O.bodies[cable[2+j+i*8]].state.pos=(x,y,z)
  538.                         else:
  539.                             if j<2 :
  540.                                 x = O.bodies[cable[2+j+i*8]].state.pos[0]
  541.                                 y = O.bodies[cable[2+j+i*8]].state.pos[1] +(1.2*dec_cable)*j
  542.                                 z = O.bodies[cable[2+j+i*8]].state.pos[2]
  543.                                 O.bodies[cable[2+j+i*8]].state.pos=(x,y,z)
  544.                             if i==0 and j==0:
  545.                                 x = O.bodies[cable[2+j+i*8]].state.pos[0] +dec_cable/5
  546.                                 y = O.bodies[cable[2+j+i*8]].state.pos[1]
  547.                                 z = O.bodies[cable[2+j+i*8]].state.pos[2] -dec_cable/10
  548.                                 O.bodies[cable[2+j+i*8]].state.pos=(x,y,z)
  549.                             if 2<=j<8:
  550.                                 x = O.bodies[cable[2+j+i*8]].state.pos[0]
  551.                                 y = O.bodies[cable[2+j+i*8]].state.pos[1] -(dec_cable/(8))*j+dec_cable
  552.                                 z = O.bodies[cable[2+j+i*8]].state.pos[2]
  553.                                 O.bodies[cable[2+j+i*8]].state.pos=(x,y,z)
  554.                 O.bodies[cable[0]].state.pos=(O.bodies[cable[-0]].state.pos[0]+dec_cable/1.4,O.bodies[cable[0]].state.pos[1]-1.4*dec_cable,O.bodies[cable[0]].state.pos[2])
  555.                 O.bodies[cable[-1]].state.pos=(O.bodies[cable[-1]].state.pos[0],O.bodies[cable[-1]].state.pos[1]-dec_cable,O.bodies[cable[-1]].state.pos[2])
  556.  
  557.             else:
  558.                 cable.append(O.bodies.append(gridNode([(posx*Lx),CenterCoord[1],posz*(Lz/2)-2.1*Rcable],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  559.                 for i in range(kx+1):
  560.                     if i!=0 and i != kx:
  561.                         if i%2==0:
  562.                             x = inipoint[0] + (direction*abs(Long_cable))[0]*i/kx
  563.                             y = inipoint[1] + (direction*abs(Long_cable))[1]*i/kx
  564.                             z = inipoint[2] + (direction*abs(Long_cable))[2]*i/kx-2.25*Rcable
  565.                             cable.append(O.bodies.append(gridNode([x,y,z],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  566.                         else:
  567.                             x = inipoint[0] + (direction*abs(Long_cable))[0]*i/kx
  568.                             y = inipoint[1] + (direction*abs(Long_cable))[1]*i/kx
  569.                             z = inipoint[2] + (direction*abs(Long_cable))[2]*i/kx-2.25*Rcable
  570.                             cable.append(O.bodies.append(gridNode([x,y,z],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  571.                     else:
  572.                         x = inipoint[0] + (direction*abs(Long_cable))[0]*i/kx
  573.  
  574.                         y = inipoint[1] + (direction*abs(Long_cable))[1]*i/kx
  575.                         z = inipoint[2] + (direction*abs(Long_cable))[2]*i/kx-2.25*Rcable
  576.                         cable.append(O.bodies.append(gridNode([x,y,z],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  577.  
  578.                 cable.append(O.bodies.append(gridNode([((Nx-posx)*Lx),CenterCoord[1],posz*(Lz/2)-2.1*Rcable],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  579.                 for i in range((len(cable))/8):
  580.                     for j in range(8):
  581.                         if i%2!=0:
  582.                             if j==0:
  583.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0] +dec_cable/5
  584.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1]
  585.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2] -dec_cable/10
  586.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  587.                             if 0<j<=7:
  588.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  589.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] -(dec_cable/(8))*j+dec_cable
  590.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  591.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  592.                         else:
  593.                             if j<7:
  594.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  595.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] -(dec_cable/(8))*j
  596.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  597.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  598.                             if j==7 :
  599.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  600.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] -(1.2*dec_cable)
  601.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  602.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  603.                 O.bodies[cable[-1]].state.pos=(O.bodies[cable[-1]].state.pos[0],O.bodies[cable[-1]].state.pos[1]+dec_cable,O.bodies[cable[-1]].state.pos[2])
  604.             for i,j in zip(cable[:-1],cable[1:]):
  605.                 cablecon.append( O.bodies.append(gridConnection(i,j,Rcable,wire=False, material = 'cablecomat',color=[1,01,0],mask=3) ) )
  606.             O.bodies[cable[0]].state.blockedDOFs = 'xyzXYZ'
  607.             O.bodies[cable[-1]].state.blockedDOFs = 'xyzXYZ'
  608.             O.bodies[cable[0]].shape.color=[0.5,.75,1]
  609.             O.bodies[cable[-1]].shape.color=[0.5,.75,1]
  610.  
  611.         if posz!=0 and  round(posz,1) != float(Nz+1): # Cent Normally braided
  612. # create all the points that make up the cable
  613.             cable.append(O.bodies.append(gridNode([(posx*Lx),CenterCoord[1],posz*(Lz/2)],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  614.             print O.bodies[-1].state.pos
  615.             for i in range(kx+1):
  616.                 x = inipoint[0] + (direction*abs(Long_cable))[0]*i/kx
  617.                 y = inipoint[1] + (direction*abs(Long_cable))[1]*i/kx
  618.                 z = inipoint[2] + (direction*abs(Long_cable))[2]*i/kx
  619.                 cable.append(O.bodies.append(gridNode([x,y,z],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  620.             cable.append(O.bodies.append(gridNode([((Nx-posx)*Lx),CenterCoord[1],posz*(Lz/2)],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  621. ### To do the first Tension
  622. #           for i,j in zip(cable[:-1],cable[1:]):
  623. #               cablecon.append( O.bodies.append(gridConnection(i,j,Rcable,wire=False, material = 'cablecomat',color=[1,01,0],mask=3) ) )
  624. ###  Pretension
  625. #           Long_cable=( O.bodies[cable[-1]].state.pos- O.bodies[cable[0]].state.pos)
  626. #          
  627. #           lfinal = abs(Long_cable)
  628. #           linit = Young_cabco*lfinal/((ForcePret/(pi*Rcable*Rcable))+Young_cabco)
  629. #           deltaL=lfinal-linit
  630. #           if ForcePret!= 0:
  631. #               for k in cable:
  632. #                   i=O.bodies[k]
  633. #                   if Long_cable[0] != 0: 
  634. #                       deplx = ((direction*deltaL)[0]/(direction*linit)[0])*(i.state.pos[0]-O.bodies[cable[0]].state.pos[0])
  635. #                   if Long_cable[1] != 0: 
  636. #                       deply = ((direction*deltaL)[1]/(direction*linit)[1])*(i.state.pos[1]-O.bodies[cable[0]].state.pos[1])
  637. #                   if Long_cable[2] != 0: 
  638. #                       deplz = ((direction*deltaL)[2]/(direction*linit)[2])*(i.state.pos[2]-O.bodies[cable[0]].state.pos[2])
  639. #                   i.state.pos=Vector3(i.state.pos[0]+deplx,i.state.pos[1]+deply,i.state.pos[2]+deplz)
  640. ## Braid
  641.             for i in range((len(cable)-1)/8):
  642.                 for j in range(8):
  643.                     if i%2!=0:
  644.                         if j<4:
  645.                             x = O.bodies[cable[1+j+i*8]].state.pos[0]
  646.                             y = O.bodies[cable[1+j+i*8]].state.pos[1] -(2*dec_cable/(8))*j
  647.                             z = O.bodies[cable[1+j+i*8]].state.pos[2]
  648.                             O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  649.                         else:
  650.                             x = O.bodies[cable[1+j+i*8]].state.pos[0]
  651.                             y = O.bodies[cable[1+j+i*8]].state.pos[1] +(2*dec_cable/(8))*j-2*dec_cable
  652.                             z = O.bodies[cable[1+j+i*8]].state.pos[2]
  653.                             O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  654.                     else:
  655.                         if j<4:
  656.                             x = O.bodies[cable[1+j+i*8]].state.pos[0]
  657.                             y = O.bodies[cable[1+j+i*8]].state.pos[1] +(2*dec_cable/(8))*j
  658.                             z = O.bodies[cable[1+j+i*8]].state.pos[2]
  659.                             O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  660.                         else:
  661.                             x = O.bodies[cable[1+j+i*8]].state.pos[0]
  662.                             y = O.bodies[cable[1+j+i*8]].state.pos[1] -(2*dec_cable/(8))*j+2*dec_cable
  663.                             z = O.bodies[cable[1+j+i*8]].state.pos[2]
  664.                             O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  665.             O.bodies[cable[0]].state.pos=(O.bodies[cable[-0]].state.pos[0],O.bodies[cable[0]].state.pos[1]-dec_cable,O.bodies[cable[0]].state.pos[2])
  666.             O.bodies[cable[1]].state.pos=(O.bodies[cable[1]].state.pos[0],O.bodies[cable[0]].state.pos[1],O.bodies[cable[1]].state.pos[2])
  667.             O.bodies[cable[-1]].state.pos=(O.bodies[cable[-1]].state.pos[0],O.bodies[cable[-1]].state.pos[1]-dec_cable,O.bodies[cable[-1]].state.pos[2])
  668.             O.bodies[cable[-2]].state.pos=(O.bodies[cable[-2]].state.pos[0],O.bodies[cable[-1]].state.pos[1],O.bodies[cable[-2]].state.pos[2])
  669.                
  670.             for i,j in zip(cable[:-1],cable[1:]):
  671.                 cablecon.append( O.bodies.append(gridConnection(i,j,Rcable,wire=False, material = 'cablecomat',color=[1,01,0], mask=3) ) )
  672.         if posz ==0:    # Inf normaly braided
  673.  
  674. # create all the points that make up the cable
  675.             cable.append(O.bodies.append(gridNode([(posx*Lx),CenterCoord[1],posz*(Lz/2)++2.1*Rcable],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  676.  
  677.             if posx1-int(posx1)== 0.25:
  678.                 for i in range(kx+1):
  679.                     x = inipoint[0] + (direction*lfinal)[0]*i/kx
  680.                     y = inipoint[1] + (direction*lfinal)[1]*i/kx
  681.                     z = inipoint[2] + (direction*lfinal)[2]*i/kx+2.25*Rcable
  682.                     cable.append(O.bodies.append(gridNode([x,y,z],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  683.                 cable.append(O.bodies.append(gridNode([((Nx-posx)*Lx+xmin),CenterCoord[1],posz*(Lz/2)+2.1*Rcable],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  684. ### To do the first Tension
  685. #               for i,j in zip(cable[:-1],cable[1:]):
  686. #                   cablecon.append( O.bodies.append(gridConnection(i,j,Rcable,wire=False, material = 'cablecomat',color=[1,01,0],mask=3) ) )
  687. ### Pretension
  688. #               Long_cable=( O.bodies[cable[-1]].state.pos- O.bodies[cable[0]].state.pos)
  689. #               lfinal = abs(Long_cable)
  690. #               linit = Young_cabco*lfinal/((ForcePret/(pi*Rcable*Rcable))+Young_cabco)
  691. #               deltaL=lfinal-linit
  692. #               if ForcePret!= 0:
  693. #                   for k in cable:
  694. #                       i=O.bodies[k]
  695. #                       if Long_cable[0] != 0: 
  696. #                           deplx = ((direction*deltaL)[0]/(direction*linit)[0])*(i.state.pos[0]-O.bodies[cable[0]].state.pos[0])
  697. #                       if Long_cable[1] != 0: 
  698. #                           deply = ((direction*deltaL)[1]/(direction*linit)[1])*(i.state.pos[1]-O.bodies[cable[0]].state.pos[1])
  699. #                       if Long_cable[2] != 0: 
  700. #                           deplz = ((direction*deltaL)[2]/(direction*linit)[2])*(i.state.pos[2]-O.bodies[cable[0]].state.pos[2])
  701. #                       i.state.pos=Vector3(i.state.pos[0]+deplx,i.state.pos[1]+deply,i.state.pos[2]+deplz)
  702. ### Braid
  703.                 for i in range((len(cable))/8):
  704.                     for j in range(8):
  705.                         if i%2!=0:
  706.                             if j<2:
  707.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  708.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] +(1.2*dec_cable)*j
  709.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  710.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  711.                             if 2<=j<8:
  712.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  713.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] -(dec_cable/(8))*j+dec_cable
  714.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  715.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  716.                         else:
  717.                             if j<7:
  718.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  719.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] -(dec_cable/(8))*j
  720.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  721.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  722.                             if 7<=j<8:
  723.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  724.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] -(1.2*dec_cable/(8))*j
  725.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  726.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  727.  
  728.                 O.bodies[cable[0]].state.pos=(O.bodies[cable[-0]].state.pos[0],O.bodies[cable[0]].state.pos[1]-dec_cable,O.bodies[cable[0]].state.pos[2])
  729.                 O.bodies[cable[-2]].state.pos=(O.bodies[cable[-2]].state.pos[0],O.bodies[cable[-2]].state.pos[1]+dec_cable/3,O.bodies[cable[-2]].state.pos[2]+dec_cable/5)
  730.                 O.bodies[cable[-1]].state.pos=(O.bodies[cable[-1]].state.pos[0],O.bodies[cable[-1]].state.pos[1]+dec_cable,O.bodies[cable[-1]].state.pos[2])
  731.             if posx1-int(posx1)== 0.75:
  732.                 for i in range(kx+1):
  733.                     x = inipoint[0] + (direction*lfinal)[0]*i/kx
  734.                     y = inipoint[1] + (direction*lfinal)[1]*i/kx
  735.                     z = inipoint[2] + (direction*lfinal)[2]*i/kx+2.25*Rcable
  736.                     cable.append(O.bodies.append(gridNode([x,y,z],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  737.                 cable.append(O.bodies.append(gridNode([((Nx-posx)*Lx),CenterCoord[1],posz*(Lz/2)+2.1*Rcable],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))
  738. ### To do the first Tension
  739. #               for i,j in zip(cable[:-1],cable[1:]):
  740. #                   cablecon.append( O.bodies.append(gridConnection(i,j,Rcable,wire=False, material = 'cablecomat',color=[1,01,0],mask=3) ) )
  741. ### Pretension
  742. #               Long_cable=( O.bodies[cable[-1]].state.pos- O.bodies[cable[0]].state.pos)
  743. #               lfinal = abs(Long_cable)
  744. #               linit = Young_cabco*lfinal/((ForcePret/(pi*Rcable*Rcable))+Young_cabco)
  745. #               deltaL=lfinal-linit
  746. #               if ForcePret!= 0:
  747. #                   for k in cable:
  748. #                       i=O.bodies[k]
  749. #                       if Long_cable[0] != 0: 
  750. #                           deplx = ((direction*deltaL)[0]/(direction*linit)[0])*(i.state.pos[0]-O.bodies[cable[0]].state.pos[0])
  751. #                       if Long_cable[1] != 0: 
  752. #                           deply = ((direction*deltaL)[1]/(direction*linit)[1])*(i.state.pos[1]-O.bodies[cable[0]].state.pos[1])
  753. #                       if Long_cable[2] != 0: 
  754. #                           deplz = ((direction*deltaL)[2]/(direction*linit)[2])*(i.state.pos[2]-O.bodies[cable[0]].state.pos[2])
  755. #                       i.state.pos=Vector3(i.state.pos[0]+deplx,i.state.pos[1]+deply,i.state.pos[2]+deplz)
  756. ## Braid
  757.                 for i in range((len(cable))/8):
  758.                     for j in range(8):
  759.                         if i%2!=0:
  760.                             if j<7:
  761.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  762.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] -(dec_cable/(8))*j
  763.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  764.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  765.                             if 7<=j<8:
  766.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  767.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] -(1.2*dec_cable/(8))*j
  768.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  769.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  770.                         else:
  771.                             if j<2:
  772.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  773.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] +(1.2*dec_cable)*j
  774.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  775.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  776.                             if 2<=j<8:
  777.                                 x = O.bodies[cable[1+j+i*8]].state.pos[0]
  778.                                 y = O.bodies[cable[1+j+i*8]].state.pos[1] -(dec_cable/(8))*j+dec_cable
  779.                                 z = O.bodies[cable[1+j+i*8]].state.pos[2]
  780.                                 O.bodies[cable[1+j+i*8]].state.pos=(x,y,z)
  781.  
  782.                 O.bodies[cable[0]].state.pos=(O.bodies[cable[-0]].state.pos[0],O.bodies[cable[0]].state.pos[1]-dec_cable,O.bodies[cable[0]].state.pos[2])
  783.                 O.bodies[cable[1]].state.pos=(O.bodies[cable[1]].state.pos[0]-dec_cable/5,O.bodies[cable[0]].state.pos[1]-dec_cable/2,O.bodies[cable[1]].state.pos[2])
  784.                 O.bodies[cable[2]].state.pos=(O.bodies[cable[2]].state.pos[0]-dec_cable/1.5,O.bodies[cable[2]].state.pos[1],O.bodies[cable[2]].state.pos[2])
  785.                 O.bodies[cable[-1]].state.pos=(O.bodies[cable[-1]].state.pos[0],O.bodies[cable[-1]].state.pos[1]-dec_cable,O.bodies[cable[-1]].state.pos[2])
  786.             for i,j in zip(cable[:-1],cable[1:]):
  787.                 cablecon.append( O.bodies.append(gridConnection(i,j,Rcable,wire=False, material = 'cablecomat',color=[1,01,0],mask=3) ) )
  788.            
  789.             O.bodies[cable[0]].state.blockedDOFs = 'xyzXYZ'
  790.             O.bodies[cable[-1]].state.blockedDOFs = 'xyzXYZ'
  791.  
  792.             O.bodies[cable[0]].shape.color=[0.5,.75,1]
  793.             O.bodies[cable[-1]].shape.color=[0.5,.75,1]
  794.     else:
  795.         if cablez==zmax:
  796.             zCa=cablez+decman
  797.             xCa=(zCa-n)*(Lz/2)/m+xmin+4*Rfrein+2*RBASSIN
  798.             inipoint=Vector3(xCa,CenterCoord[1],zCa)
  799.             finpoint=Vector3(Base-xCa,CenterCoord[1],zCa)
  800.             print inipoint
  801.         else:
  802.             posz=cablez/(Lz/2)  # Position related with loops  
  803.             posx=(cablez-n)/m/Lx
  804.             if posz!=0 and posz <= (Nz+1)*0.99:
  805.                 if 0.<=posz-int(posz)<=0.5:
  806.                     posz=int(posz)+0.5
  807.                 if 0.5 < posz-int(posz)<1:
  808.                     posz=int(posz)-0.5
  809.             zCa=posz*(Lz/2)
  810.             xCa=(posz*(Lz/2)-n)/m+xmin+4*Rfrein+2*RBASSIN
  811.             inipoint=Vector3(xCa,CenterCoord[1]-decman,zCa)
  812.             finpoint=Vector3(Base-xCa,CenterCoord[1]-decman,zCa)
  813.             print inipoint
  814.         Long_cable = finpoint-inipoint
  815.         lfinal = abs(Long_cable)
  816.         linit = Young_cabco*lfinal/((ForcePret/(pi*Rcable*Rcable))+Young_cabco)
  817.         deltaL=lfinal-linit
  818.         direction=Long_cable/abs(Long_cable)
  819.         kx=int(lfinal/(Lx/16))
  820. # create all the points that make up the cable
  821.         for i in range(kx+1):
  822.             x = inipoint[0] + (direction*abs(Long_cable))[0]*i/kx
  823.             y = inipoint[1] + (direction*abs(Long_cable))[1]*i/kx
  824.             z = inipoint[2] + (direction*abs(Long_cable))[2]*i/kx
  825.             cable.append(O.bodies.append(gridNode([x,y,z],Rcable,wire=False,fixed=False,material='cablemat',color=[1,01,0])))      
  826.         for i,j in zip(cable[:-1],cable[1:]):
  827.             cablecon.append( O.bodies.append(gridConnection(i,j,Rcable,wire=False, material = 'cablecomat',color=[1,01,0],mask=3) ) )
  828. ### Pretension
  829.         if ForcePret!= 0:
  830.             for k in cable:
  831.                 i=O.bodies[k]
  832.                 if Long_cable[0] != 0
  833.                     deplx = ((direction*deltaL)[0]/(direction*linit)[0])*(i.state.pos[0]-O.bodies[cable[0]].state.pos[0])
  834.                 if Long_cable[1] != 0
  835.                     deply = ((direction*deltaL)[1]/(direction*linit)[1])*(i.state.pos[1]-O.bodies[cable[0]].state.pos[1])
  836.                 if Long_cable[2] != 0
  837.                     deplz = ((direction*deltaL)[2]/(direction*linit)[2])*(i.state.pos[2]-O.bodies[cable[0]].state.pos[2])
  838.                 i.state.pos=Vector3(i.state.pos[0]+deplx,i.state.pos[1]+deply,i.state.pos[2]+deplz)
  839.     return (cable, cablecon, zCa)
  840.  
  841. #######################################################################################################################################
  842.  
  843. ### Creacion de los cables ###
  844.  
  845.  
  846. ## Position z cables ##
  847. #z_cable=[zmax,6.5,zmax/1.5,zmax/2,zmax/2.2,zmin]
  848.  
  849. CABLELIST=[] ### TODA LA INF DEL CABLE
  850. for i in range(len(z_cable)):
  851.     CABLELIST.append(CABLEc(z_cable[i],Braid[i],ForcePretini[i]))
  852.  
  853. CABLE=[]    ##### Contiene Gridnode y GridConnection
  854. Z_real=[]   ##### Contiene Z real de los cables
  855. Cable_iniend=[] ##### Contiene estremos del cable
  856. for i in range(len(CABLELIST)):
  857.     CABLE+=CABLELIST[i][0]+CABLELIST[i][1]
  858.     Z_real.append(CABLELIST[i][2])
  859.     Cable_iniend.append([CABLELIST[i][0][0],CABLELIST[i][0][-1]])
  860.  
  861. #################################### Function Frein #######################################
  862.  
  863. def Freins(Pos1, Pos2, Fdec,radius):
  864.    
  865.     colorf=[0,1,0]
  866.     Asf = pi*pow(radius,2)
  867. # Stress–strain curve
  868.     Ffrein = Fdec
  869.     E1f = 60e9              #module du cable
  870.     sig1f = Ffrein/Asf
  871.     def1f = sig1f/E1f
  872.  
  873.     E2f = 8e5
  874.     def2f = 104             #Calibrated
  875.     sig2f = sig1f+(def2f-def1f)*E2f
  876.  
  877.     sigruptf = 383e3/(Asf)          #1400e6 (Experimental date)
  878.     defruptf = def2f + (sigruptf-sig2f)/E1f
  879.     strainStressValuesf=[(def1f,sig1f),(def2f,sig2f),(defruptf,sigruptf)]
  880.     densityf = 7850
  881.     youngf = strainStressValuesf[0][1] / strainStressValuesf[0][0]
  882.     poissonf = 0.3
  883.  
  884.     freinmat = O.materials.append(WireMat(young=youngf, poisson=poissonf,frictionAngle=radians(10),density=densityf,isDoubleTwist=False,diameter=2*radius,strainStressValues=strainStressValuesf))
  885.    
  886.     frein = []
  887.     frein.extend([
  888.     O.bodies.append(utils.sphere(Pos1,radius,wire=False,fixed=False,material=freinmat,color=colorf,mask=3)),
  889.     O.bodies.append(utils.sphere(Pos2,radius,wire=False,fixed=False,material=freinmat,color=colorf,mask=3))])
  890.     createInteraction(frein[0],frein[1])
  891.  
  892.     return (frein)
  893.  
  894. #################### Creacion de frenos ################
  895. Frein=[] #### Contiene frenos lista de frenos por cable [[c1fr1],[c1fr2],[c2fr1],etc]
  896. for i in  range(len( Cable_iniend)):
  897.     Frein.append(Freins ( [m+n for m,n in zip(O.bodies[Cable_iniend[i][0]].state.pos,[-2*Rcable,0,0])],[m+n for m,n in zip(O.bodies[Cable_iniend[i][0]].state.pos,[-4*Rcable,0,0])],Ffrein,Rfrein))
  898.     Frein.append(Freins ( [m+n for m,n in zip(O.bodies[Cable_iniend[i][-1]].state.pos,[+2*Rcable,0,0])],[m+n for m,n in zip(O.bodies[Cable_iniend[i][-1]].state.pos,[+4*Rcable,0,0])],Ffrein,Rfrein))
  899.  
  900.  
  901. ################################### MANILLE ##################################
  902.  
  903. def Manille_Vert(Rman, ouv, posX, posY, posZ, base):
  904.  
  905.     youngb =5e8         #A.Trad & D.Betrand:  105GPa * Cylinder area / Steel area
  906.     strenruptb=100e9    #FORCE #A.Trad & D.Betrand
  907.     densityb=7850.
  908.     poissonb = 0.3
  909.     shearCohb = 1e100
  910.     frottement = 10     ### Ask
  911.  
  912.     bouclemat = O.materials.append(CohFrictMat(young=youngb,poisson=poissonb,density=densityb,frictionAngle=radians(frottement),normalCohesion=pi*strenruptb,shearCohesion=shearCohb,momentRotationLaw=True))
  913.     bouclecomat = O.materials.append(FrictMat(young=youngb,poisson=poissonb,density=densityb,frictionAngle=radians(frottement)))
  914.     """
  915.     Maillage d'une manille orientée verticalement et attachée
  916.  
  917.     Rman = rayon de la section d'acier
  918.     ouv = ouverture interieure de la manille, de bord à bord
  919.     posX, Y, Z = position du centre de la manille
  920.     base = sphere à laquelle la manille est attachée
  921.     bouclemat = matériaux pour les noeud
  922.     bouclecomat = matériaux pour les connexion
  923.     numclump = numero du noeud qui est clump (entre 0 et 3)
  924.     """
  925.     colorb=[1,0,0]
  926.     boucle = []
  927.     dec = Rman + ouv/2      # Gap
  928.     wire = True
  929.     boucle.extend([
  930.         O.bodies.append(gridNode([posX,posY,posZ+dec],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)),
  931.         O.bodies.append(gridNode([posX,posY+dec,posZ],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)),
  932.         O.bodies.append(gridNode([posX,posY,posZ-dec],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)),
  933.         O.bodies.append(gridNode([posX,posY-dec,posZ],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)) ])
  934.  
  935.     conboucle=[]
  936.     for i,j in zip(boucle[:-1],boucle[1:]):
  937.         conboucle.append( O.bodies.append( gridConnection(i,j,Rman,wire=wire, material = bouclecomat,color=colorb,mask=3) ) )
  938.     conboucle.append( O.bodies.append( gridConnection(boucle[0],boucle[-1],Rman,wire=wire, material = bouclecomat,color=colorb,mask=3) ) )
  939.  
  940.         ############ CLUMP ############
  941.     clumping = []
  942.     clumping.extend([boucle[0],boucle[1],boucle[2],boucle[3],base])
  943.     clumps = O.bodies.clump(clumping)
  944.  
  945.     return boucle,conboucle,clumps
  946. def Manille_frein(Rman, ouv, posX, posY, posZ,Dir):
  947.  
  948.     youngb =5e8         #A.Trad & D.Betrand:  105GPa * Cylinder area / Steel area
  949.     strenruptb=100e9    #FORCE #A.Trad & D.Betrand
  950.     densityb=7850.
  951.     poissonb = 0.3
  952.     shearCohb = 1e100
  953.     frottement = 10     ### Ask
  954.  
  955.     bouclemat = O.materials.append(CohFrictMat(young=youngb,poisson=poissonb,density=densityb,frictionAngle=radians(frottement),normalCohesion=pi*strenruptb,shearCohesion=shearCohb,momentRotationLaw=True))
  956.     bouclecomat = O.materials.append(FrictMat(young=youngb,poisson=poissonb,density=densityb,frictionAngle=radians(frottement)))
  957.     """
  958.     Maillage d'une manille orientée verticalement et attachée
  959.  
  960.     Rman = rayon de la section d'acier
  961.     ouv = ouverture interieure de la manille, de bord à bord
  962.     posX, Y, Z = position du centre de la manille
  963.     base = sphere à laquelle la manille est attachée
  964.     bouclemat = matériaux pour les noeud
  965.     bouclecomat = matériaux pour les connexion
  966.     numclump = numero du noeud qui est clump (entre 0 et 3)
  967.     Dir direction du body
  968.     """
  969.     colorf=[0,1,0]
  970.     Asf = pi*pow(Rfrein,2)
  971. # Stress–strain curve
  972.     E1f = 60e9              #module du cable
  973.     sig1f = Ffrein/Asf
  974.     def1f = sig1f/E1f
  975.  
  976.     E2f = 8e5
  977.     def2f = 104             #Calibrated
  978.     sig2f = sig1f+(def2f-def1f)*E2f
  979.  
  980.     sigruptf =1400e6/(Asf)          #1400e6 (Experimental date)
  981.     defruptf = def2f + (sigruptf-sig2f)/E1f
  982.     strainStressValuesf=[(def1f,sig1f),(def2f,sig2f),(defruptf,sigruptf)]
  983.     densityf = 7850
  984.     youngf = strainStressValuesf[0][1] / strainStressValuesf[0][0]
  985.     poissonf = 0.3
  986.  
  987.     freinmat = O.materials.append(WireMat(young=youngf, poisson=poissonf,frictionAngle=radians(10),density=densityf,isDoubleTwist=False,diameter=2*Rfrein,strainStressValues=strainStressValuesf))
  988.    
  989.     colorb=[1,0,0]
  990.     boucle = []
  991.     dec = Rman + ouv/2      # Gap
  992.     wire = True
  993.     if Dir=='Left':
  994.         boucle.extend([
  995.             O.bodies.append(gridNode([posX-dec*cos(2*Lz/Lx),posY,posZ+dec*sin(2*Lz/Lx)],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)),
  996.             O.bodies.append(gridNode([posX,posY+dec,posZ],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)),
  997.             O.bodies.append(gridNode([posX+dec*cos(2*Lz/Lx),posY,posZ-dec*sin(2*Lz/Lx)],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)),
  998.             O.bodies.append(gridNode([posX,posY-dec,posZ],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)) ])
  999.     else:
  1000.         boucle.extend([
  1001.             O.bodies.append(gridNode([posX+dec*cos(2*Lz/Lx),posY,posZ+dec*sin(2*Lz/Lx)],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)),
  1002.             O.bodies.append(gridNode([posX,posY+dec,posZ],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)),
  1003.             O.bodies.append(gridNode([posX-dec*cos(2*Lz/Lx),posY,posZ-dec*sin(2*Lz/Lx)],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)),
  1004.             O.bodies.append(gridNode([posX,posY-dec,posZ],Rman,wire=wire,fixed=False,material=bouclemat,color=colorb)) ])
  1005.  
  1006.     frein = []
  1007.     if Dir=='Left':
  1008.         frein.extend([
  1009.         O.bodies.append(utils.sphere([O.bodies[boucle[0]].state.pos[0],O.bodies[boucle[0]].state.pos[1],O.bodies[boucle[0]].state.pos[2]*1.001],Rman,wire=False,fixed=False,material=freinmat,color=colorf,mask=3)),
  1010.         O.bodies.append(utils.sphere([i+j for i,j in zip(O.bodies[boucle[0]].state.pos,[-dec*cos(2*Lz/Lx),0,dec*sin(2*Lz/Lx)])],Rman,wire=False,fixed=False,material=freinmat,color=colorf,mask=3))])
  1011.         O.bodies[-1].shape.color.color=[0.5,0.5,0.5]
  1012.     else:
  1013.         frein.extend([
  1014.         O.bodies.append(utils.sphere([O.bodies[boucle[0]].state.pos[0],O.bodies[boucle[0]].state.pos[1],O.bodies[boucle[0]].state.pos[2]*1.001],Rman,wire=False,fixed=False,material=freinmat,color=colorf,mask=3)),
  1015.         O.bodies.append(utils.sphere([i+j for i,j in zip(O.bodies[boucle[0]].state.pos,[dec*cos(2*Lz/Lx),0,dec*sin(2*Lz/Lx)])],Rman,wire=False,fixed=False,material=freinmat,color=colorf,mask=3))])
  1016.     createInteraction(frein[0],frein[1])
  1017.  
  1018.     conboucle=[]
  1019.     for i,j in zip(boucle[:-1],boucle[1:]):
  1020.         conboucle.append( O.bodies.append( gridConnection(i,j,Rman,wire=wire, material = bouclecomat,color=colorb,mask=3) ) )
  1021.     conboucle.append( O.bodies.append( gridConnection(boucle[0],boucle[-1],Rman,wire=wire, material = bouclecomat,color=colorb,mask=3) ) )
  1022.  
  1023.         ############ CLUMP ############
  1024.     clumping = []
  1025.     clumping.extend([boucle[0],boucle[1],boucle[2],boucle[3],frein[0]])
  1026.     clumps = O.bodies.clump(clumping)
  1027.     TTT=frein[1]
  1028.     return boucle,conboucle,clumps,TTT
  1029. boucle,conboucle,shackles=[],[],[]
  1030.  
  1031. # Creacion de las manillas para todos los elementos
  1032. for i in range(len(Braid)):
  1033.     if Braid[i]==0:
  1034.         if Z_real[i]>=zmax:
  1035.             for j in range(len(Netsup)):
  1036.                 if j==0 or j==len(Netsup)-1:
  1037.                     if j==0:
  1038.                         for k in CABLELIST[0][0]:
  1039.                             if O.bodies[k].state.pos[0]-Lx/32<O.bodies[Netsup[j]].state.pos[0]<O.bodies[k].state.pos[0]+Lx/32:
  1040.                                 PPP=[O.bodies.clump([Netsup[j],k]),[Netsup[j],k]]
  1041.                     else:
  1042.                         for k in CABLELIST[0][0]:
  1043.                             if O.bodies[k].state.pos[0]-Lx/32<O.bodies[Netsup[j]].state.pos[0]<O.bodies[k].state.pos[0]+Lx/32:
  1044.                                 TTT=[O.bodies.clump([Netsup[j],k]),[Netsup[j],k]]
  1045.                 else:
  1046.                     posX = O.bodies[Netsup[j]].state.pos[0]
  1047.                     aa,bb,cc = Manille_Vert(Rman = Rman, ouv = ouv, posX = posX, posY = CenterCoord[1], posZ = Z_real[i], base = Netsup[j])
  1048.                     boucle.append(aa)
  1049.                     conboucle.append(bb)
  1050.                     shackles.append(cc)
  1051.         else:
  1052.             for j in NetPack:
  1053.                 if round(Z_real[i],4) == round(O.bodies[j].state.pos[2],4) and O.bodies[Cable_iniend[i][0]].state.pos[0]<=O.bodies[j].state.pos[0]<=O.bodies[Cable_iniend[i][-1]].state.pos[0]:
  1054.                     posX = O.bodies[j].state.pos[0]
  1055.                     aa,bb,cc = Manille_Vert(Rman = Rman, ouv = ouv, posX = posX, posY = CenterCoord[1]-decman, posZ = Z_real[i], base = j) 
  1056.                     boucle.append(aa)
  1057.                     conboucle.append(bb)
  1058.                     shackles.append(cc)
  1059. N_Braid=0.
  1060. for i in Braid:
  1061.     N_Braid+=i
  1062. if N_Braid<len(Braid):
  1063.     shackles_la=[PPP[0],TTT[0]]
  1064.  
  1065. ################################### Iteraction Frein-Cable #######################################
  1066.  
  1067. C_F=[]
  1068. clumpCF=[]
  1069. for i in  range(len( Cable_iniend)):
  1070.     C_F+=[O.bodies.clump([Cable_iniend[i][0],Frein[i*2][0]])]
  1071.     C_F+=[O.bodies.clump([Cable_iniend[i][-1],Frein[i*2+1][0]])]
  1072.     clumpCF+=[Cable_iniend[i][0],Frein[i*2][0],Cable_iniend[i][-1],Frein[i*2+1][0]]
  1073.  
  1074. ##############################################################################################
  1075. ################################### CONDITIONS LIMITES #######################################
  1076. #####################################################################   #########################
  1077.  
  1078. velz=-0.75
  1079. vely=-0.25
  1080. # Blocked external point breaks
  1081.  
  1082. for i in range(len( Frein)):
  1083.     O.bodies[Frein[i][-1]].state.blockedDOFs = 'xyzXYZ'
  1084.  
  1085. for i in C_F:       # Fixing Iteraction Frein-Cable
  1086.     O.bodies[i].state.blockedDOFs = 'xyzXYZ'
  1087.  
  1088. ## Blocked shackles
  1089.  
  1090. if N_Braid<len(Braid):
  1091.     for i in shackles:
  1092.         O.bodies[i].state.blockedDOFs = 'xyzXYZ'
  1093. ## Blocked cables
  1094. if N_Braid<len(Braid):
  1095.     for i in CABLE:
  1096.         if not i in clumpCF or i in PPP[1] or i in TTT[1]:
  1097.             O.bodies[i].state.blockedDOFs = 'xyzXYZ'
  1098. else:
  1099.     for i in CABLE:
  1100.         if not i in clumpCF:
  1101.             O.bodies[i].state.blockedDOFs = 'xyzXYZ'
  1102.  
  1103. if N_Braid<len(Braid):
  1104.     for i in shackles_la:
  1105.         O.bodies[i].state.blockedDOFs = 'xyzXYZ'
  1106.  
  1107.  
  1108. ########################## Functions ##############################
  1109.  
  1110. #########################
  1111. ## FUNCTION DEFINITION ##
  1112. #########################
  1113.  
  1114. def gravityDeposit():
  1115.     if O.iter>5000 and kineticEnergy()<10 and unbalancedForce()<1 and MeshStabilized:
  1116.         #O.pause()
  1117.         for i in DepBox:
  1118.             O.bodies.erase(i)
  1119.         gravDep.dead=True
  1120.         #Drag.dead=False
  1121.         dista.dead=False
  1122.         velProfil.dead=False
  1123.         bedshear_tot_engine.dead=False
  1124.         bedshear_1_engine.dead=False
  1125.         bedshear_2_engine.dead=False
  1126.         bedshear_3_engine.dead=False
  1127.         bedshear_4_engine.dead=False
  1128.         newton.damping=0.
  1129.         FWall.dead=False
  1130. #       O.save("deposit-mono5cm.yade")
  1131.         print "Gravity deposit finished & gate opened"
  1132.  
  1133. def addPack(minX,minY,minZ,maxX,maxY,maxZ,num):
  1134.     global spIds
  1135.     PackAdd = pack.SpherePack()
  1136.     PackAdd.makeCloud(minCorner=(minX,minY,minZ),maxCorner=(maxX,maxY,maxZ),rMean=diameterPart/2.,num=num)
  1137.     spIdsAdd=PackAdd.toSimulation(material=mat,color=[205./255,175./255,149./255])
  1138.     spIds=spIds+spIdsAdd
  1139.     #Drag.ids=spIds
  1140.  
  1141. xs=np.linspace(0,length_channel,int(length_channel)*10)
  1142. zs=np.linspace(0,height_channel,int(height_channel)*100)
  1143. max_pos_x, height_front, vel_front, max_vel_front=0.,0.,Vector3(0.,0.,0.),0.
  1144. def front():
  1145.     global max_vel_front
  1146.     #fvel=open(folder+"front.txt","a")
  1147.     #fvel3D=open(folder+"front3D.txt","a")
  1148. #   for i in spIds:
  1149. #       O.bodies[i].shape.color=[205./255,175./255,149./255]
  1150.     list_x,list_z=[],[]
  1151.     for i in spIds:
  1152.         list_x.append(O.bodies[i].state.pos[0])
  1153.         list_z.append(O.bodies[i].state.pos[2])
  1154.     density_x = gaussian_kde(list_x)
  1155.     density_x.covariance_factor = lambda : .05
  1156.     density_x._compute_covariance()
  1157.     density_z = gaussian_kde(list_z)
  1158.     density_z.covariance_factor = lambda : .05
  1159.     density_z._compute_covariance()
  1160.    
  1161.     max_density_x=max(density_x(xs))
  1162.     max_pos_x=xs[max([i for i,x in enumerate(density_x(xs)) if x>0.5*max_density_x])]
  1163.    
  1164.     height=max([x for x in zs if 0.95>density_z.integrate_box_1d(0,x)])+diameterPart/2.
  1165.  
  1166.     vel_front,a=Vector3(0.,0.,0.),0
  1167.     for i in spIds:
  1168.         if abs(O.bodies[i].state.pos[0] - max_pos_x) <=0.5:
  1169. #           O.bodies[i].shape.color=[0./255,0./255,255./255]
  1170.             vel_front+=O.bodies[i].state.vel
  1171.             a+=1
  1172.     if a!=0:
  1173.         vel_front=vel_front/float(a)
  1174.         #Drag.V=vel_front
  1175.  
  1176.     max_vel_front=max(max_vel_front,vel_front[0])
  1177.    
  1178.     #fvel.write(str(O.time)+";"+str(max_pos_x)+";"+str(height)+";"+str(vel_front[0])+"\n")
  1179.     #fvel3D.write(str(O.time)+";"+str(vel_front[0])+";"+str(vel_front[1])+";"+str(vel_front[2])+"\n")
  1180.     #fvel.close()
  1181.     #fvel3D.close()
  1182.    
  1183.     return max_pos_x,height, vel_front
  1184.  
  1185. def distance(a,b):
  1186.     return sqrt((a.state.pos[0]-b.state.pos[0])**2+(a.state.pos[1]-b.state.pos[1])**2+(a.state.pos[2]-b.state.pos[2])**2)
  1187.  
  1188. deadZoneIds=[]
  1189. def deadZone():
  1190.     global spIds
  1191.     for i in spIds:
  1192.         if (O.bodies[i].state.vel[0]/float(max_vel_front)) < 0.05:
  1193.             spIds.remove(i)
  1194.             deadZoneIds.append(i)
  1195.     if spIds==[]:
  1196.         dista.dead=True
  1197.         velProfil.dead=True
  1198.     #Drag.ids=spIds
  1199.  
  1200. def vel_profil():
  1201.     #velocity_profil=open(folder+"velocity_profil.txt","a") #ecriture dans un fichier velocity_profil.txt
  1202.     #velocity_profil.write(str(O.time)+";"+str(max_pos_x)+";")
  1203.     l=[]
  1204.     for i in spIds:
  1205.         if max_pos_x-1.2 <= O.bodies[i].state.pos[0] <= max_pos_x-0.8:
  1206.             l.append(i)
  1207.    
  1208.     list_vel_x,list_vel_y,list_vel_z="0","0","0"
  1209.     for h in range(int(height_front/diameterPart)):
  1210.         vel_x,vel_y,vel_z,a=0.,0.,0.,0
  1211.         for i in l:
  1212.             if h*diameterPart <= O.bodies[i].state.pos[2] <= (h+1)*diameterPart:
  1213.                 vel_x+=O.bodies[i].state.vel[0]
  1214.                 vel_y+=O.bodies[i].state.vel[1]
  1215.                 vel_z+=O.bodies[i].state.vel[2]
  1216.                 a+=1
  1217.         if a!=0:
  1218.             list_vel_x+=":"+str(vel_x/a)
  1219.             list_vel_y+=":"+str(vel_y/a)
  1220.             list_vel_z+=":"+str(vel_z/a)   
  1221.     #velocity_profil.write(str(height_front)+";"+str(list_vel_x)+";"+str(list_vel_y)+";"+str(list_vel_z)+"\n")
  1222.     #velocity_profil.close()
  1223.  
  1224. FtotX,FtotY,FtotZ,tF=[],[],[],[]
  1225. def Force_wall():
  1226.     #f=open(folder+"Force_wall.txt","a")
  1227.     ### Calculate each component of the total NORMAL force between impacting particles and the wall:
  1228.     ### Diviser le mur en multiple tranche
  1229.  
  1230.     Fx=0
  1231.     Fy=0
  1232.     Fz=0
  1233.     for i in O.interactions:
  1234.         if i.id1 == rigWall[0]:
  1235.             deadZone_engine.dead=False
  1236.             Fx+= i.phys.normalForce[0]
  1237.             Fy+= i.phys.normalForce[1]
  1238.             Fz+= i.phys.normalForce[2]
  1239.     FtotX.append(Fx)
  1240.     FtotY.append(Fy)
  1241.     FtotZ.append(Fz)
  1242.     tF.append(O.time)
  1243.     #f.write(str(O.time)+";"+str(Fx)+";"+str(Fy)+";"+str(Fz)+"\n")
  1244.     #f.close()
  1245.     return Fx, Fy, Fz
  1246.  
  1247. shearLub_tot,shearCon_tot=Vector3(0.,0.,0.),Vector3(0.,0.,0.)
  1248. def bedshear_total():
  1249.     shearLub,shearCon=Vector3(0.,0.,0.),Vector3(0.,0.,0.)
  1250.     #fbedshear=open(folder+"bedshear.txt","a")
  1251.     for i in O.interactions:
  1252.         if i.id1 in chanB:
  1253.             shearLub+=i.phys.shearLubricationForce
  1254.             shearCon+=i.phys.shearContactForce
  1255.     #fbedshear.write(str(O.time)+";"+str(shearLub[0])+";"+str(shearLub[1])+";"+str(shearLub[2])+";"+str(shearCon[0])+";"+str(shearCon[1])+";"+str(shearCon[2])+"\n")
  1256.     #fbedshear.close()
  1257.     return shearLub,shearCon
  1258.  
  1259. shearLub1,shearCon1=Vector3(0.,0.,0.),Vector3(0.,0.,0.)
  1260. shearLub2,shearCon2=Vector3(0.,0.,0.),Vector3(0.,0.,0.)
  1261. shearLub3,shearCon3=Vector3(0.,0.,0.),Vector3(0.,0.,0.)
  1262. shearLub4,shearCon4=Vector3(0.,0.,0.),Vector3(0.,0.,0.)
  1263. shearLub5,shearCon5=Vector3(0.,0.,0.),Vector3(0.,0.,0.)
  1264. def bedshear_at_x(x):
  1265.     #fbedshear=open(folder+"bedshear_at_"+str(x)+".txt","a")
  1266.     shearLub,shearCon=Vector3(0.,0.,0.),Vector3(0.,0.,0.)
  1267.     for i in O.interactions:
  1268.         if (i.id1 in chanB) and (x-0.5 <= O.bodies[i.id2].state.pos[0] <= x+0.5):
  1269.             shearLub+=i.phys.shearLubricationForce
  1270.             shearCon+=i.phys.shearContactForce
  1271.     #fbedshear.write(str(O.time)+";"+str(shearLub[0])+";"+str(shearLub[1])+";"+str(shearLub[2])+";"+str(shearCon[0])+";"+str(shearCon[1])+";"+str(shearCon[2])+"\n")
  1272.     #fbedshear.close()
  1273.     return shearLub,shearCon
  1274.  
  1275. Epot,Ekin,Etot=0.,0.,0.
  1276. def Energy():
  1277.     Epot,Ekin,Etot=0.,0.,0.
  1278.     for i in spIds:
  1279.         p=Vector3(length_channel-O.bodies[i].state.pos[0],O.bodies[i].state.pos[1],O.bodies[i].state.pos[2])
  1280.         Epot+=O.bodies[i].state.mass*Vector3.dot(gravityVector,p)
  1281.         Ekin+=0.5*O.bodies[i].state.mass*O.bodies[i].state.vel.norm()**2
  1282.     return Epot,Ekin,Epot+Ekin
  1283.  
  1284.  
  1285. a,b,c=0,0,0
  1286. ww,zz=0,0
  1287.  
  1288.  
  1289.  
  1290. Elem_conct=0
  1291. def Element():
  1292.     global Elem_conct
  1293.     for i in side:
  1294.         El=O.bodies[i].intrs()
  1295.         for j in El:
  1296.             for k in Basin:
  1297.                 if j.id1==k or j.id2==k:
  1298.                     Elem_conct+=1
  1299.     return Elem_conct
  1300.  
  1301.  
  1302.  
  1303. MeshStabilized=False
  1304. def StaCable():
  1305.     global a,CABLE,Frein,C_F,shackles,shackles_la,PreTimput,MeshStabilized#,infTen,infTen2
  1306.     # Equilibrum
  1307.     if unbalancedForce()<0.0006 and a==0 :
  1308.         # move cable
  1309.         for i in CABLE:
  1310.             O.bodies[i].state.vel=(0.,vely,velz)
  1311.         ## Move breaks external
  1312.         for i in range(len( Frein)):
  1313.             O.bodies[Frein[i][-1]].state.vel=(0.,vely,velz)
  1314.             O.bodies[Frein[i][-1]].shape.color=[1,0,1]
  1315.             O.bodies[Frein[i][-1]].state.blockedDOFs = 'xyzXYZ'
  1316.         ## Move breaks-Cable
  1317.         for i in C_F:
  1318.             O.bodies[i].state.vel=(0.,vely,velz)
  1319.         ## Move shackles
  1320.         if N_Braid<len(Braid):
  1321.             for i in shackles:
  1322.                 O.bodies[i].state.vel=(0.,vely,velz)
  1323.             for i in shackles_la:
  1324.                 O.bodies[i].state.vel=(0.,vely,velz)
  1325.         print ('Equilibrium', int(O.realtime/60), 'min', int(O.realtime-int(O.realtime/60)*60), 's')
  1326.         a=1    
  1327.     # movement of all the cables
  1328.     if O.bodies[Idzmax].state.pos[2]<=0 and a==1:
  1329.     #Mesh placed, removing of the velocity and fixing the break
  1330.         ## move cable
  1331.         if N_Braid<len(Braid):
  1332.             for i in CABLE:
  1333.                 if not i in clumpCF or i in PPP[1] or i in TTT[1]:
  1334.                     O.bodies[i].state.blockedDOFs = ''
  1335.         else:
  1336.             for i in CABLE:
  1337.                 if not i in clumpCF:
  1338.                     O.bodies[i].state.blockedDOFs = ''
  1339.  
  1340.         ## Move breaks external
  1341.         for i in range(len( Frein)):
  1342.             O.bodies[Frein[i][-1]].state.vel=(0.,0.,0.)
  1343.             O.bodies[Frein[i][-1]].shape.color=[1,0,1]
  1344.             O.bodies[Frein[i][-1]].state.blockedDOFs = 'xyz'
  1345.         ## Move breaks-Cable
  1346.         for i in C_F:
  1347.             O.bodies[i].state.vel=(0.,0.,0.)
  1348.             O.bodies[i].state.blockedDOFs = ''
  1349.         ## Move shackles
  1350.         if  N_Braid<len(Braid):
  1351.             for i in shackles:
  1352.                 O.bodies[i].state.vel=(0.,0.,0.)
  1353.                 O.bodies[j].state.blockedDOFs = ''
  1354.             for i in shackles_la:
  1355.                 O.bodies[i].state.blockedDOFs = ''
  1356.                 O.bodies[i].state.vel=(0.,0.,0.)
  1357.         a=2
  1358.         print ('Mesh placed', int(O.realtime/60), 'min', int(O.realtime-int(O.realtime/60)*60), 's')
  1359.        
  1360.         measureTension.dead=False
  1361. #       cableengine.iterPeriod=250
  1362.     if unbalancedForce()<0.04 and a==2 : # unbalancedForce stabilizes the tensions of the cables
  1363.         for i in range(len(PreTimput)):
  1364.             PreTimput[i]=Preimput(CABLELIST[i][0])
  1365.             PreTimput[i]=PreTension(CABLELIST[i][0],ForcePret[i],PreTimput[i])
  1366.            
  1367. ################################ ESTA CONDICION HAY QUE PENSAR COMO HACERLA INDEPENDIENTEMENTE DE N° CABLES) ######
  1368.         if (0.999*ForcePret[0] <= PreTimput[0] <= 1.001*ForcePret[0]) and (0.999*ForcePret[1] <= PreTimput[1] <= 1.001*ForcePret[1])and (0.999*ForcePret[1] <= PreTimput[1] <= 1.001*ForcePret[1]) and (0.999*ForcePret[2] <= PreTimput[2] <= 1.001*ForcePret[2]) and (0.999*ForcePret[3] <= PreTimput[3] <= 1.001*ForcePret[3]) and (0.999*ForcePret[4] <= PreTimput[4] <= 1.001*ForcePret[4]):
  1369.             print ('Tension', int(O.realtime/60) ,'min', int(O.realtime-int(O.realtime/60)*60), 's')
  1370.             a=3
  1371. #           O.save('VERSOYEN03.yade.gz')
  1372. #           infTen=infT(infTen)
  1373.     if unbalancedForce()<0.04 and a==3:
  1374.         # Removing damping 
  1375.         newton.damping=0
  1376. #       infTen2=infT(infTen2)
  1377.         print ('placed', int(O.realtime/60), 'min', int(O.realtime-int(O.realtime/60)*60) ,'s')
  1378.         a=4
  1379.         MeshStabilized=True
  1380. #       O.bodies[IdSphere].state.vel[1]=-1
  1381. #       makeVideo(snapshot.snapshots,'3D.mpeg',fps=10,bps=10000)
  1382.         #O.pause()
  1383.  
  1384. #       Elem_conctac=Element()
  1385.  
  1386. def PreTension(cable,PreTREAl,PreTimput):
  1387.     for i,j in zip(cable[:-1],cable[1:]):
  1388.             Lseg = abs(O.bodies[j].state.pos-O.bodies[i].state.pos)
  1389.             if PreTimput < 0.5* PreTREAl :
  1390.                 O.interactions[i,j].phys.unp = O.interactions[i,j].phys.unp+Lseg*0.0003 #PreTREAl*3.3e-8#0.000003
  1391.             if 0.5* PreTREAl <= PreTimput < 0.80* PreTREAl :
  1392.                 O.interactions[i,j].phys.unp = O.interactions[i,j].phys.unp+Lseg*0.000006   #PreTREAl*3.3e-8#0.000003
  1393.         if  0.80* PreTREAl < PreTimput < 0.99* PreTREAl :
  1394.                 O.interactions[i,j].phys.unp = O.interactions[i,j].phys.unp+Lseg*0.0000001
  1395.             if 0.99* PreTREAl <= PreTimput <= PreTREAl*0.999  :
  1396.                 O.interactions[i,j].phys.unp = O.interactions[i,j].phys.unp+Lseg*0.00000002#PreTREAl*1.67e-10
  1397.             if 1.001*PreTREAl <= PreTimput <= 1.05*PreTREAl  :
  1398.                 O.interactions[i,j].phys.unp = O.interactions[i,j].phys.unp-Lseg*0.00000002#PreTREAl*2*3.33e-11
  1399.             if 1.05*PreTREAl < PreTimput  <= 1.10*PreTREAl :
  1400.                 O.interactions[i,j].phys.unp = O.interactions[i,j].phys.unp-Lseg*0.0000005#PreTREAl*3.33e-8
  1401.             if 1.10*PreTREAl < PreTimput :
  1402.                 O.interactions[i,j].phys.unp = O.interactions[i,j].phys.unp-Lseg*0.000015#PreTREAl*3.33e-8
  1403. #       if  0.9999*PreTREAl <= PreTimput <= 1.0001*PreTREAl:
  1404. #       print 'tensil'
  1405.     obj1=O.bodies[cable[-1]].intrs() # MEASURE IN THE CENTER OF ITS HIGHT
  1406.     PreTimput=(obj1[0].phys.normalForce+obj1[0].phys.shearForce).norm()
  1407.     return PreTimput
  1408.  
  1409. def Preimput(cable):
  1410.     obj1=O.bodies[cable[-1]].intrs() # MEASURE IN THE CENTER OF ITS HIGHT
  1411.     PreTimput=(obj1[0].phys.normalForce+obj1[0].phys.shearForce).norm()
  1412.     return PreTimput
  1413.  
  1414. def Tension():
  1415.     obj1=O.bodies[Cable_iniend[0][0]].intrs() # MEASURE IN THE CENTER OF ITS HIGHT
  1416.     PreT_UpL=(obj1[0].phys.normalForce).norm()
  1417.     obj11=O.bodies[Cable_iniend[0][1]].intrs() # MEASURE IN THE CENTER OF ITS HIGHT
  1418.     PreT_UpR=(obj11[0].phys.normalForce).norm()
  1419.     obj2=O.bodies[Cable_iniend[1][0]].intrs() # MEASURE IN THE CENTER OF ITS HIGHT
  1420.     PreT_CenL=(obj2[0].phys.normalForce).norm()
  1421.     obj22=O.bodies[Cable_iniend[1][1]].intrs() # MEASURE IN THE CENTER OF ITS HIGHT
  1422.     PreT_CenR=(obj22[0].phys.normalForce).norm()
  1423.     obj3=O.bodies[Cable_iniend[2][0]].intrs() # MEASURE IN THE CENTER OF ITS HIGHT
  1424.     PreT_DownL=(obj3[0].phys.normalForce).norm()
  1425.     obj33=O.bodies[Cable_iniend[2][1]].intrs() # MEASURE IN THE CENTER OF ITS HIGHT
  1426.     PreT_DownR=(obj33[0].phys.normalForce).norm()
  1427.     plot.addData(i=O.iter, ii=O.iter, PreT_Up_left=PreT_UpL,PreT_Cen_left=PreT_CenL,PreT_Down_left=PreT_DownL,PreT_Up_right=PreT_UpR,PreT_Cen_right=PreT_CenR,PreT_Down_right=PreT_DownR, unbalanced=unbalancedForce(), **O.energy)
  1428.  
  1429. Tension()
  1430. #plot.plots={'i':('PreT_Up_left','PreT_Up_right','PreT_Cen_left','PreT_Cen_right','PreT_Down_left','PreT_Down_right'),'ii':('unbalanced',None,O.energy.keys)}  #display the graph with the indicated legends
  1431. #plot.plot(subPlots=True) # show the previously described graph on the screen, and update while the simulation runs
  1432.  
  1433.  
  1434. O.trackEnergy=True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement