You are on page 1of 13

9.12.

2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

#!/usr/bin/envpython
#
*
coding:Utf8
*
#
#
#ToyGLStructure.py
#
#Aclasstogeneratepinjointedstructures
#asapreprocessingtoToyGL
#
#JulienAverseng,dec.2012
#julien.averseng@univmontp2.fr
#(www.lmgc.univmontp2.fr/~javersen)
#
#
importos,sys
importnumpyasnp
################################################################################
#utilityfunctions
################################################################################
defdistance(pt1,pt2):
"""
Returnsthedistance(2norm)betweentwopoints
"""
returnnp.linalg.norm(np.array(pt1,dtype='d')np.array(pt2,dtype='d'))
defdistance_inf(pt1,pt2):
"""
Returnsthedistance(infinitynorm)betweentwopoints
"""
returnmax(abs(np.array(pt1,dtype='d')np.array(pt2,dtype='d')))
################################################################################
classNode:
"""
Aclassedefininganode:
positionx,y,z
velocityvx,vy,vz
family
"""
def__init__(self,x=0.,y=0.,z=0.,vx=0.,vy=0.,vz=0.,family=0):
"""
Initializationwith(0,0,0)
"""
self.x=x
self.y=y
self.z=z
self.vx=vx
self.vy=vy
self.vz=vz
self.family=family
self.bx=0
self.by=0
self.bz=0
self.fx=0
self.fy=0
self.fz=0

defpos(self):
"""
Currentpositionofthenode
"""
return[self.x,self.y,self.z]

defvel(self):
"""
Currentvelocityofthenode
"""
return[self.vx,self.vy,self.vz]

http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

1/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

defforce(self):
"""
Assignedforce(loading)
"""
return[self.fx,self.fy,self.fz]
################################################################################
classElement:
"""
Aclassdefiningapinjointedelement:
startingnodeindex
endingnodeindex
family
normalforce
unconstrainedlength
"""

def__init__(self,no_start=1,no_end=1,family=0,l0=1,N_force=0.):
self.no_start=no_start
self.no_end=no_end
self.family=family
self.l0=l0
self.N_force=N_force
################################################################################
classNodeFamilyData:
"""
AclasscontainingaNode'scharacteristics:
mass
visual(andcontact)radius
contactstiffness(N/m)
contactviscosity(N.s/m)
visualcolor(R,G,B)
"""

def__init__(self,mass=1.,radius=0.1,contact_stiffness=1000.,contact_viscosity=1.,color=
[1.,0.,0.]):
self.mass=mass
self.radius=radius
self.contact_stiffness=contact_stiffness
self.contact_viscosity=contact_viscosity
self.color=color
defcopy_data(self,nfd):
"""
CopyfromanotherinstanceofNodeFamilyData
"""
self.mass=nfd.mass
self.radius=nfd.radius
self.contact_stiffness=nfd.contact_stiffness
self.contact_viscosity=nfd.contact_viscosity
self.color=nfd.color
################################################################################
classElementFamilyData:
"""
AclasscontaininganElement'scharacteristics:
massdensity
Young'smodulusintension
Young'smodulusincompression
crosssectionarea
radius
contactrigidity
color(RGB)
"""
def__init__(self,mass_density=1000.,E_trac=1.e11,E_comp=1.e11,A=1.e4,
radius=0.1,contact_stiffness=1000.,axial_viscosity=0.1,color=[1.,0.,0.]):
"""
Initialization
"""
self.mass_density=mass_density
self.E_trac=E_trac
http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

2/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

self.E_comp=E_comp
self.A=A

self.radius=radius
self.color=color
self.contact_stiffness=contact_stiffness
self.axial_viscosity=axial_viscosity
defcopy_data(self,efd):
"""
CopyfromanotherinstanceofElementFamilyData
"""
self.mass_density=efd.mass_density
self.E_trac=efd.E_trac
self.E_comp=efd.E_comp
self.A=efd.A
self.radius=efd.radius
self.color=efd.color
self.contact_stiffness=efd.contact_stiffness
self.axial_viscosity=efd.axial_viscosity
################################################################################
classToyGLStructure:
"""
Aclassthatdescribesapinjointedstructure:
listofNodes
listofElements
listofblockedNodes[no,bx,by,bz](bi=0meansthenodeisfreealongtheithdof)
listofNodes'sfamiliesdata
listofElements'familiesdata
timestepfortimesimulationandothersparameters
"""

#initializationmethods
def__init__(self):
"""
Initialization
"""
self.RAZ()

defRAZ(self):
"""
Initializationwith0noeudsand0elements("RemiseAZero")
"""
#nodesandelements
self.nodes=[]
self.elements=[]

#30familiesbydefault,butextendable
self.nodes_family_data=[NodeFamilyData()foriinrange(20)]
self.elements_family_data=[ElementFamilyData()foriinrange(20)]

#timestepfortimesimulationwithToyGL
self.timestep=1.0e5

#Dimensionaltolerance,distinctionbetweennodes
self.tol=1e6

#Variousflagstobesaved
self.flag_contact_ground=False
self.flag_contact_node_node=False
self.flag_contact_node_element=False
self.flag_contact_element_element=False

#Loading
self.loading_steps=1

#identificationmethods
defid_node(self,pt3d):
"""
Testsfortheexistenceofageometricalnodeatpt3d(atupleof3real)
http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

3/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

Returnsitsidinself.Nodesifitexists,1else
"""
point_tuple=tuple(pt3d)
index_retour=1
p=0
while(index_retour<0)and(p<len(self.nodes)):
posno=self.nodes[p].pos()
diff=distance_inf(tuple(posno),point_tuple)
ifdiff<self.tol:
index_retour=p
p+=1
returnindex_retour

defid_element(self,pt1,pt2):
"""
Teststheexistenceofthegeometricalelementbetweenpt1andpt2
Returnsitsindexifitexists,1else
"""
index_retour=1

#Setthetypetotuple
pt1=tuple(pt1)
pt2=tuple(pt2)

#gettheindexesofnodes
i_pt1=self.id_node(pt1)
ifi_pt1>=0:
i_pt2=self.id_node(pt2)
ifi_pt2>=0:
#thetwonodesexist,theelementmaybeintheelements'list
ind=0
while(index_retour<0)and(ind<len(self.elements)):
couple_no=[self.elements[ind].no_start,self.elements[ind].no_end]
if(i_pt1incouple_no):
if(i_pt2incouple_no):
index_retour=ind
ind+=1
returnindex_retour
deflength_element(self,id_elem):
"""
Givethelengthofanelement
"""
pt1=self.nodes[self.elements[id_elem].no_start].pos()
pt2=self.nodes[self.elements[id_elem].no_end].pos()
returndistance(pt1,pt2)
defaxial_force_element(self,ind_elem):
"""
Returntheaxialforceofanalement
"""
elem=self.elements[ind_elem]
pt1=self.nodes[elem.no_start].pos()
pt2=self.nodes[elem.no_end].pos()
longueur=distance(pt1,pt2)
car_elem=self.elements_family_data[elem.family]

#computationofnormalforce:Hooke'sLaw
tension=car_elem.A*(longueurelem.l0)/elem.l0
iftension>=0:
tension*=car_elem.E_trac
else:
tension*=car_elem.E_comp

returntension

defmass_element(self,ind):
"""
Returnthemassofanelement=A*l0*mdens
"""
fam=self.elements[ind].family
http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

4/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

llib=self.elements[ind].l0
mdens=self.elements_family_data[fam].mass_density
A=self.elements_family_data[fam].A
returnmdens*A*llib
defmass_node(self,ind):
"""
Renvoielamassed'unnoeud
"""
fam=self.liste_noeuds[ind].famille
returnself.liste_carac_noeuds[fam].mass
defmass_total(self):
"""
Returnthemassofthestructure
"""
liste_masses_elements=[self.mass_element(i)foriinrange(len(self.elements))]
liste_masses_noeuds=[self.mass_node(i)foriinrange(len(self.noeuds))]
return(sum(liste_masses_elements)+sum(liste_masses_noeuds))
#constructionandmodificationmethods
defcreate_node(self,pt3d,family=0):
"""
Addsanodeatthegeometricalpositiongiveninpt3d
Returnsitsidinself.nodes,checkingitsexistencebefore
"""
return_id=1
pt_tuple=np.array(pt3d,dtype='d')#pours'assurerquec'estuntuple
index_no=self.id_node(pt_tuple)#onrecuperesonindex,1s'iln'existepas
ifindex_no>=0:
#thenodeisalreadythere,wejustassigntohimthefamily
self.nodes[index_no].family=family
return_id=index_no
else:
#wecreatethenode
self.nodes.append(Node(x=pt_tuple[0],y=pt_tuple[1],z=pt_tuple[2],family=
family))
return_id=len(self.nodes)1#indexofthefinalnode
returnreturn_id

defcreate_element_pt1_f1_pt2_f2_fam_l0(self,pt1,fam1,pt2,fam2,family,l0):
"""
Createstheelementdefinedbythetwogeometricalpointspt1andpt2
Returntheindexofthenewelement,ortheindexoftheexistingone
Createsthenodesifneeded.
Thisshouldbeoneoftherarefunctionstobeusedwhencreatingastructure
"""
retour=1

#setthetypetoarray
pt1=np.array(pt1,dtype='d')
pt2=np.array(pt2,dtype='d')
index_retour=1

#proximitytestbetweenelements
if(distance(pt1,pt2)<self.tol):
retour=1
else:
#Existencetest
index_el=self.id_element(pt1,pt2)
ifindex_el>=0:
#thereisalreadyanelementthere,returntheindex
index_retour=index_el
else:
#wecanaddtheelement
ip1=self.create_node(pt1,family=fam1)
ip2=self.create_node(pt2,family=fam2)
self.elements.append(Element(ip1,ip2,family,l0=l0))
index_retour=len(self.elements)1
retour=index_retour
returnretour

http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

5/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

defcreate_element_pt1_f1_pt2_f2_fam(self,pt1,fam1,pt2,fam2,family):
"""
Createstheelementdefinedbythetwogeometricalpointspt1andpt2
Returntheindexofthenewelement,ortheindexoftheexistingone
Createsthenodesifneeded.
Thisshouldbeoneoftherarefunctionstobeusedwhencreatingastructure
L0issettothedistancebetweenthenodesoN_force=0
"""
l00=distance(pt1,pt2)
returnself.create_element_pt1_f1_pt2_f2_fam_l0(pt1,fam1,pt2,fam2,family,l0=l00)

defadd_structure_at(self,st0,pos=[0.,0.,0.]):
"""
Addstheelementsofst0tothecurrentstructure
Doesatranslationbyposbefore(default=[0,0,0])
Doesn'tmergeyetthefamiliesdata
"""
ifst0==self:
st1=ToyGLStructure()
st1.add_structure(st0)
else:
st1=st0
forel1inst1.elements:
#getthegeometricalpositionofstartandend,andfamilies
pt_deb=np.array(st1.nodes[el1.no_start].pos())
fam_deb=st1.nodes[el1.no_start].family
pt_fin=np.array(st1.nodes[el1.no_end].pos())
fam_fin=st1.nodes[el1.no_end].family
fam=el1.family

#translation
pt_deb+=np.array(pos)
pt_fin+=np.array(pos)

#weaddtheelement
self.create_element_pt1_f1_pt2_f2_fam(pt_deb,fam_deb,pt_fin,fam_fin,fam)
self.set_families_from_structure(st1)
deftranslate_xyz(self,dx,dy,dz):
"""
Translationofthestructurebyvector[dx,dy,dz]
"""
fornoinself.nodes:
no.x+=dx
no.y+=dy
no.z+=dz
#deletion
defdelete_node(self,id_no):
"""
Deletesthenodewithid=id_noandthedependingelements
"""
ifid_no>=0:
ifid_no<len(self.nodes):
#it'sOK
self.nodes.pop(id_no)

#deletionofdependingelements
kk=0
whilekk<len(self.elements):
if(self.elements[kk].no_start==id_no)or(self.elements[kk].no_end==id_no):
self.delete_element(kk)
else:
#referenceshiftinself.elements
ifself.elements[kk].no_start>id_no:
self.elements[kk].no_start=1
ifself.elements[kk].no_end>id_no:
self.elements[kk].no_end=1
kk+=1

defdelete_element(self,id_el):
"""
http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

6/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

Deletestheelementwithid=id_el
"""
ifid_el>=0:
ifid_el<len(self.elements):
#it'sOK
self.elements.pop(id_el)
#propertiesassignment
defset_l0_structure(self):
"""
Settheunconstrainedlengthsinthestructure,fromtheinitialtensions
"""
forid,elinenumerate(self.elements):
self.set_l0_element(id)

defset_l0_element(self,ind_elem):
"""
Settheunconstrainedlengthofanelementtomakeitcorrespondtoits
normalforceN_force
"""
elem0=self.elements[ind_elem]
T0=elem0.N_force
family=elem0.family
car_elem=self.elements_family_data[family]
ifT0>=0:
#it'sintension
E_elem=car_elem.E_trac
else:
E_elem=car_elem.E_comp

pt1=self.noeuds[elem0.no_start].pos()
pt2=self.noeuds[elem0.no_end].pos()
longueur=distance(pt1,pt2)

self.elements[ind_elem].l0=E_elem*car_elem.A*longueur/(T0+E_elem*car_elem.aire_A)

defset_families_from_structure(self,s0):
"""
Setthecharacteristicsfromthoseofthestructures0
"""
#################
#nodesfamilies
#addmissingfamiliesifnecessary
nfam,nfam_s0=len(self.nodes_family_data),len(s0.nodes_family_data)
ifnfam<nfam_s0:
foriinrange(nfam_s0nfam):
self.nodes_family_data.append(NodeFamilyData())

#copyingdata
foriinrange(nfam_s0):
self.nodes_family_data[i].copy_data(s0.nodes_family_data[i])

#################
#elementsfamilies
#addmissingfamiliesifnecessary
nfam,nfam_s0=len(self.elements_family_data),len(s0.elements_family_data)
ifnfam<nfam_s0:
foriinrange(nfam_s0nfam):
self.elements_family_data.append(ElementFamilyData())

#copyingdata
foriinrange(nfam_s0):
self.elements_family_data[i].copy_data(s0.elements_family_data[i])

defset_node_family_mass_radius_color(self,family,mass,radius,color):
"""
Quicksettingofmassandradiusforanode'sfamily
"""
self.nodes_family_data[family].mass=mass
self.nodes_family_data[family].radius=radius
self.nodes_family_data[family].color=color

http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

7/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

defset_node_family_contact_stifness_viscosity(self,family,contact_stiffness,contact_viscosity):
"""
Quicksettingofcontactpropertiesforanode'sfamily
"""
self.nodes_family_data[family].contact_stiffness=contact_stiffness
self.nodes_family_data[family].contact_viscosity=contact_viscosity

defset_element_family_Etrac_Ecomp_A_Mdens(self,id_fam,E_trac,E_comp,A,Mdens):
"""
QuicksettingofYoung'smoduli,crosssectionalareaandmassdensity
"""
self.elements_family_data[id_fam].E_trac=E_trac
self.elements_family_data[id_fam].E_comp=E_comp
self.elements_family_data[id_fam].A=A
self.elements_family_data[id_fam].mass_density=Mdens
defset_element_family_cont_stiffness_axial_viscosity(self,id_fam,cont_stiffness,axial_viscosity):
"""
Quicksettingofcontactstiffnessandaxialviscosity
"""
self.elements_family_data[id_fam].contact_stiffness=cont_stiffness
self.elements_family_data[id_fam].axial_viscosity=axial_viscosity
defset_element_family_radius_color(self,id_fam,radius,color):
"""
Quicksettingofradiusandcolor
"""
self.elements_family_data[id_fam].radius=radius
self.elements_family_data[id_fam].color=color
defblock_node_XYZ(self,id_no,bx,by,bz):
"""
Blockthenodealongxyandz
0meansfree,anythingelsemeansblocked
"""
self.nodes[id_no].bx=bx
self.nodes[id_no].by=by
self.nodes[id_no].bz=bz
defload_node_XYZ(self,id_no,fx,fy,fz):
"""
Assignaforce(loading)tothenode
"""
self.nodes[id_no].fx=fx
self.nodes[id_no].fy=fy
self.nodes[id_no].fz=fz
#inputfromandoutputtofile
defsave_for_toygl(self,fich):
"""
SavethedefinitionofthesysteminatextfileintheformatreadableusingToyGL

Theformatis:
noeuds=
familyxyzvxvyvz
...
elements=
familyno_startno_endn_force
...
caracteristiquesfamillesnoeuds=
idmass(kg)r(m)K_contact(N/m)C_contact(N/ms1)couleur[RVB]
...
caracteristiqueselements=
idm_vol(kg/m3)E_trac(Pa)E_comp(Pa)A(m2)r(m)K_contact(N/m)C_axiale(N/ms1)
couleur[RVB]
...
noeudsbloques=
idbxbybz(0=free,blockedelse)
...
pasdetemps=
timestep
"""
http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

8/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

#nodes
f=open(fich,'w')
f.write('//definitiondesnoeuds:\n')
f.write('noeuds='+str(len(self.nodes))+'\n')
f.write('//famille\tx(m)\ty(m)\tz(m)\tvx(m/s)\tvy(m/s)\tvz(m/s)\n')
foriinself.nodes:
f.write(str(i.family)+'\t'+str(i.x)+'\t'+str(i.y)+'\t'+str(i.z)+'\t')
f.write(str(i.vx)+'\t'+str(i.vy)+'\t'+str(i.vz)+'\n')

#elements
f.write('//definitiondeselements:\n')
f.write('elements='+str(len(self.elements))+'\n')
f.write('//famille\tno_debut\tno_fin\ttension(N)\t(forinformation:l0(m)\tl(m)\force
density(N/m)\n')
forind,iinenumerate(self.elements):
f.write(str(i.family)+'\t'+str(i.no_start)+'\t'+str(i.no_end)+'\t'
+str(self.axial_force_element(ind))+"\t"+str(self.elements[ind].l0)+"\t"
+str(self.length_element(ind))+"\t"
+str(self.axial_force_element(ind)/self.length_element(ind))+'\n')

#nodesfamilies
f.write('//caracteristiquesdesfamillesdenoeuds:\n')
f.write('caracteristiquesnoeuds='+str(len(self.nodes_family_data))+'\n')
f.write('//n.\tm(kg)\tr(m)\tK_contact(N/m)\tC_contact(N/(m.s
1))\tcouleur.r[0.:1.]\tcouleur.v[0.:1.]\tcouleur.b[0.:1.]\n')
forind,iinenumerate(self.nodes_family_data):
f.write(str(ind)+'\t'+str(i.mass)+'\t'+str(i.radius)+'\t'+
str(i.contact_stiffness)+'\t'+str(i.contact_viscosity))
f.write('\t'+str(i.color[0])+'\t'+str(i.color[1])+'\t'+str(i.color[2])+'\n')

#elementsfamilies
f.write('//caracteristiquesdesfamillesd\'elements:\n')
f.write('caracteristiqueselements='+str(len(self.elements_family_data))+'\n')
f.write('//
n.\tm_vol(kg/m3)\tE_trac(Pa)\tE_comp(Pa)\tA(m2)\tr(m)\tK_contact(N/m)\tC_axiale(N/(m.s
1))\tcouleur.r[0.:1.]\tcouleur.v[0.:1.]\tcouleur.b[0.:1.]\n')
forind,iinenumerate(self.elements_family_data):
f.write(str(ind)+'\t'+str(i.mass_density)+'\t')
f.write(str(i.E_trac)+'\t'+str(i.E_comp)+'\t'+str(i.A))
f.write('\t'+str(i.radius)+'\t'+str(i.contact_stiffness)+'\t'+
str(i.axial_viscosity)+'\t')
f.write(str(i.color[0])+'\t'+str(i.color[1])+'\t'+str(i.color[2])+'\n')

#blockednodes
f.write('//noeudsbloques:\n')
blocked_nodes=[(i,node.bx,node.by,node.bz)fori,nodeinenumerate(self.nodes)if((node.bx
!=0)and(node.bx!=0)and(node.bx!=0))]
f.write('noeudsbloques='+str(len(blocked_nodes))+'\n')
f.write('//n.\tbl_x\tbl_y\tbl_z(0:libre,sinonbloque\n')
forind,blninenumerate(blocked_nodes):
f.write(str(bln[0])+'\t'+str(bln[1])+'\t'+str(bln[2])+'\t'+str(bln[3])+'\n')

#pasdetemps
f.write('//pasdetemps(s)\n')
f.write('pasdetemps=\n')
f.write(str(self.timestep)+'\n')

#flagsdivers
f.write('//contactsol(1=vrai,0=faux)\n')
f.write('contactsol=\n')
ifself.flag_contact_ground:
f.write('1\n')
else:
f.write('0\n')
f.write('//contactnoeudnoeud(1=vrai,0=faux)\n')
f.write('contactnoeudnoeud=\n')
ifself.flag_contact_node_node:
f.write('1\n')
else:
f.write('0\n')
http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

9/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

f.write('//contactnoeudelement(1=vrai,0=faux)\n')
f.write('contactnoeudelement=\n')
ifself.flag_contact_node_element:
f.write('1\n')
else:
f.write('0\n')
f.write('//contactelementelement(1=vrai,0=faux)\n')
f.write('contactelementelement=\n')
ifself.flag_contact_element_element:
f.write('1\n')
else:
f.write('0\n')
#chargement
f.write('//chargement\n')
f.write('//iFxFyFz\n')
f.write('chargement=\n')
noeuds_charges=[(i,no.fx,no.fy,no.fz)fori,noinenumerate(self.nodes)if
np.linalg.norm([no.fx,no.fy,no.fz])>self.tol]
forncinnoeuds_charges:
f.write(str(nc[0])+'\t'+str(nc[1])+'\t'+str(nc[2])+'\t'+str(nc[3])+'\n')
f.write('//etapesdechargement\n')
f.write('etapescharges=\n')
f.write(str(self.loading_steps))

#THEEND
f.close()

defload_from_toygl(self,nom_fich):
"""
FileimportfromatextfilegeneratedbyToyGL
"""
f=open(nom_fich,'r')
fl=f.readlines()
f.close()

###################################
#eliminationdescommentaires
fl2=[]
forlinfl:
ifnotl.startswith('//'):
fl2.append(l)

##################################
#identificationdessections
liste_ind_sections=[]
forind,linenumerate(fl2):
if'='inl:
liste_ind_sections.append(ind)

###############################
#dcoupageensections
liste_sections=[]
foriinrange(len(liste_ind_sections)):
ifi==len(liste_ind_sections)1:
section_courante=fl2[liste_ind_sections[i]:]
else:
section_courante=fl2[liste_ind_sections[i]:liste_ind_sections[i+1]]
liste_sections.append(section_courante)

############################
#lecturedessections
forsinliste_sections:
ind_titre_section=s[0].index("=")
titre_section=s[0][:ind_titre_section]
#print"Titresection:",titre_section

iftitre_section=="noeuds":
#lecturedesnoeuds
self.nodes=[]
http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

10/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

foriinrange(1,len(s)):
ls=s[i].split()
iflen(ls)==7:
no=Node()
no.family=eval(ls[0])
no.x=eval(ls[1])
no.y=eval(ls[2])
no.z=eval(ls[3])
no.vx=eval(ls[4])
no.vy=eval(ls[5])
no.vz=eval(ls[6])
self.nodes.append(no)
eliflen(ls)==4:
no=Node()
no.family=eval(ls[0])
no.x=eval(ls[1])
no.y=eval(ls[2])
no.z=eval(ls[3])
no.vx=0.
no.vy=0.
no.vz=0.
self.nodes.append(no)
else:
print"Fileerror:Nodes"
eliftitre_section=="elements":
#lecturedeselements
self.elements=[]
foriinrange(1,len(s)):
ls=s[i].split()
iflen(ls)>=4:
el=Element()
el.family=eval(ls[0])
el.no_start=eval(ls[1])
el.no_end=eval(ls[2])
el.N_force=eval(ls[3])
self.elements.append(el)
else:
print"Fileerror:elements"
eliftitre_section=="caracteristiquesnoeuds":
#lecturedescaracteristiquesnoeuds
foriinrange(1,len(s)):
ls=s[i].split()
iflen(ls)!=8:
print"Fileerror:nodesdata"
else:
car_no=NodeFamilyData()
car_no.mass=eval(ls[1])
car_no.radius=eval(ls[2])
car_no.contact_stiffness=eval(ls[3])
car_no.contact_viscosity=eval(ls[4])
car_no.color=[eval(ls[5]),eval(ls[6]),eval(ls[7])]
ifeval(ls[0])>(len(self.nodes_family_data)1):
fam_to_add=eval(ls[0])len(self.nodes_family_data)+1
forjinrange(fam_to_add):
self.nodes_family_data.append(NodeFamilyData())
self.nodes_family_data[eval(ls[0])]=car_no
eliftitre_section=="caracteristiqueselements":
#lecturedescaracteristiqueselements
foriinrange(1,len(s)):
ls=s[i].split()
iflen(ls)!=11:
print"Fileerror:elementsdata"
else:
car_el=ElementFamilyData()
car_el.mass_density=eval(ls[1])
car_el.E_trac=eval(ls[2])
car_el.E_comp=eval(ls[3])
car_el.A=eval(ls[4])
car_el.radius=eval(ls[5])
car_el.contact_stiffness=eval(ls[6])
car_el.axial_viscosity=eval(ls[7])
car_el.color=[eval(ls[8]),eval(ls[9]),eval(ls[10])]
http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

11/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

ifeval(ls[0])>(len(self.elements_family_data)1):
fam_to_add=eval(ls[0])len(self.elements_family_data)+1
forjinrange(fam_to_add):
self.elements_family_data.append(ElementFamilyData())
self.elements_family_data[eval(ls[0])]=car_el
eliftitre_section=="noeudsbloques":
#lecturedesnoeudsbloques
foriinrange(1,len(s)):
ls=s[i].split()
iflen(ls)!=4:
print"Fileerror:blockednodes"
else:
no_bl=[eval(ls[0]),eval(ls[1]),eval(ls[2]),eval(ls[3])]
self.block_node_XYZ(no_bl[0],no_bl[1],no_bl[2],no_bl[3])
eliftitre_section=="pasdetemps":
#lecturedupasdetemps
try:
self.pas_de_temps=eval(s[1])
except:
print"Fileerror:timestep"
eliftitre_section=="contactsol":
try:
ifeval(s[1])>0:
self.flag_contact_sol=True
else:
self.flag_contact_sol=False
except:
print"Fileerror:flagcontact_ground"
eliftitre_section=="contactnoeudnoeud":
try:
ifeval(s[1])>0:
self.flag_contact_noeud_noeud=True
else:
self.flag_contact_noeud_noeud=False
except:
print"Fileerror:flagcontactnodenode"
eliftitre_section=="contactnoeudelement":
try:
ifeval(s[1])>0:
self.flag_contact_noeud_element=True
else:
self.flag_contact_noeud_element=False
except:
print"Fileerror:flagcontactnodeelement"
eliftitre_section=="contactelementelement":
try:
ifeval(s[1])>0:
self.flag_contact_element_element=True
else:
self.flag_contact_element_element=False
except:
print"Fileerror:flagcontactelementelement"
eliftitre_section=="chargement":
#self.liste_noeuds_charges=[]
foriinrange(1,len(s)):
ls=s[i].split()
iflen(ls)!=4:
print"Fileerror:loading(",i,")"
else:
lnc=[eval(ls[0]),eval(ls[1]),eval(ls[2]),eval(ls[3])]
self.load_node_XYZ(lnc[0],lnc[1],lnc[2],lnc[3])
eliftitre_section=="etapescharge":
try:
self.loading_steps=eval(s[1])
except:
print"Fileerror:loadingsteps"

#########################
#l0setting
#########################
forelinself.elements:
car_el=self.elements_family_data[el.family]
http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

12/13

9.12.2014

transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

module_E=1.
ifel.N_force>0:
#onestentraction
module_E=car_el.E_trac
else:
#onestencompression
module_E=car_el.E_comp
no_deb=self.nodes[el.no_start]
no_fin=self.nodes[el.no_end]
v_el=np.array([no_fin.xno_deb.x,
no_fin.yno_deb.y,
no_fin.zno_deb.z])
l_el=np.linalg.norm(v_el)
el.l0=module_E*car_el.A*l_el/(el.N_force+module_E*car_el.A)

http://transfert.lmgc.univmontp2.fr/~averseng/JA/ToyGL_files/ToyGLStructure.py

13/13