-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_pout_v2_2.py
394 lines (328 loc) · 12.1 KB
/
parser_pout_v2_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#This code provides the parser for simple beams
import sp
def parser():
commentaire=sp.R(r'#.*')
blancs=sp.R(r'\s+')
nom=sp.R(r'[a-zA-Z_]')
nomPout=sp.R(r'\w+')
nomFich=sp.R(r'\[\w+\]')
component=sp.R(r'Ux')|sp.R(r'Uy')|sp.R(r'Uz')|sp.R(r'Theta_x')|sp.R(r'Theta_y')|sp.R(r'Theta_z')
coord=sp.R(r'X')|sp.R(r'Y')|sp.R(r'Z')
nombre=sp.R(r'[0-9]+') / int #convertit le nombre en entier
nbVirgule=(sp.R(r'-?'+'[0-9]*'+'.'+'[0-9]+')|sp.R(r'-?'+'[0-9]+')|sp.R(r'-?'+'[0-9]+'+'.')) /float
express=sp.R(r'[\w|\+|\-|\*|\^|(|)|\.|/]+')
separator=sp.R(r';|,|_|-')
baliseDebutPoutre=sp.K(r'<')
baliseDebutBoundaries=sp.K(r'<BOUNDARIES>')|sp.K(r'<LIMITES>')
baliseDebutDimensions=sp.K(r'<DIMENSIONS>')
baliseDebutLeft=sp.K(r'<Left>')|sp.K(r'<Gauche>')
baliseDebutRight=sp.K(r'<Right>')|sp.K(r'<Droite>')
baliseDebutLoading=sp.K(r'<LOADING>')|sp.K(r'<CHARGEMENT>')
baliseDebutLin=sp.K(r'<Lineic>')|sp.K(r'<Lineique>')
baliseDebutSolveur=sp.K(r'<SOLVER>')|sp.K(r'<SOLVEUR>')
baliseDebutLink=sp.K(r'<LINK>')|sp.K(r'<LIAISON>')
baliseDebutOutput=sp.K(r'<OUTPUT>')|sp.K(r'<SORTIE>')
baliseDebutOutDyn=sp.K(r'<TIME_OUTPUT>')|sp.K(r'<SORTIE_TEMPS>')
baliseDebutOutPlot=sp.K(r'<PLOT_OUTPUT>')|sp.K(r'<SORTIE_AFFI>')
baliseDebutParam=sp.K(r'<PARAMETERS>')|sp.K(r'<PARAMETRES>')
baliseDebutID=sp.K(r'<Init_defo>')|sp.K(r'<Defo_init>')
baliseDebutRep=sp.K(r'<SYSTEM>')|sp.K(r'<REPERE>')
baliseDebutRepM=sp.K(r'<MOB_SYSTEM>')|sp.K(r'<REPERE_MOB>')
baliseFinPoutre=sp.K(r'</BEAM>')|sp.K(r'</POUTRE>')
baliseFinBoundaries=sp.K(r'</BOUNDARIES>')|sp.K(r'</LIMITES>')
baliseFinDimensions=sp.K(r'</DIMENSIONS>')
baliseFinLeft=sp.K(r'</Left>')|sp.K(r'</Gauche>')
baliseFinRight=sp.K(r'</Right>')|sp.K(r'</Droite>')
baliseFinLoading=sp.K(r'</LOADING>')|sp.K(r'</CHARGEMENT>')
baliseFinLin=sp.K(r'</Lineic>')|sp.K(r'</Lineique>')
baliseFinSolveur=sp.K(r'</SOLVER>')|sp.K(r'</SOLVEUR>')
baliseFinLink=sp.K(r'</LINK>')|sp.K(r'</LIAISON>')
baliseFinOutput=sp.K(r'</OUTPUT>')|sp.K(r'</SORTIE>')
baliseFinOutDyn=sp.K(r'</TIME_OUTPUT>')|sp.K(r'</SORTIE_TEMPS>')
baliseFinOutPlot=sp.K(r'</PLOT_OUTPUT>')|sp.K(r'</SORTIE_AFFI>')
baliseFinParam=sp.K(r'</PARAMETERS>')|sp.K(r'</PARAMETRES>')
baliseFinID=sp.K(r'</Init_defo>')|sp.K(r'</Defo_init>')
baliseFinRep=sp.K(r'</SYSTEM>')|sp.K(r'</REPERE>')
baliseFinRepM=sp.K(r'</MOB_SYSTEM>')|sp.K(r'</REPERE_MOB>')
gNomPoutre=sp.K(r'Beam Name')|sp.K(r'Nom Poutre')
gGauche=sp.K(r'Left')|sp.K(r'Gauche')
gDroite=sp.K(r'Right')|sp.K(r'Droite')
gPout1=sp.K(r'Beam1')|sp.K(r'Poutre1')
gPout2=sp.K(r'Beam2')|sp.K(r'Poutre2')
gPout=sp.K(r'Beam')|sp.K(r'Poutre')
gNomSort=sp.K(r'Output_name')|sp.K(r'Nom_sortie')
gCompo=sp.K(r'Component')|sp.K(r'Composante')
gAx=sp.K(r'Axis')|sp.K(r'Axe')
gRepere=sp.K(r'System')|sp.K(r'Repere')
gNom=sp.K(r'Name')|sp.K(r'Nom')
egal=sp.K(r'=')
depoin=sp.K(r':')
#########################################################################################################
with sp.Separator(blancs|commentaire): #on fait abstraction des blancs et des commentaires
assembly=sp.Rule()
beam=sp.Rule()
link=sp.Rule()
repe=sp.Rule()
repemob=sp.Rule()
blocBoundaries=sp.Rule()
blocDimensions=sp.Rule()
blocLoading=sp.Rule()
blocSolveur=sp.Rule()
blocOutput=sp.Rule()
blocOutDyn=sp.Rule()
blocOutPlot=sp.Rule()
blocParam=sp.Rule()
blocLeft=sp.Rule()
blocRight=sp.Rule()
blocLineic=sp.Rule()
blocInDef=sp.Rule()
blocCoL=sp.Rule()
blocCoR=sp.Rule()
blocL=sp.Rule()
blocE=sp.Rule()
blocNu=sp.Rule()
blocS=sp.Rule()
blocIy=sp.Rule()
blocIz=sp.Rule()
blocRho=sp.Rule()
blocNb=sp.Rule()
blocU=sp.Rule()
blocF=sp.Rule()
blocCo=sp.Rule()
blocUx=sp.Rule()
blocUy=sp.Rule()
blocUz=sp.Rule()
blocTx=sp.Rule()
blocTy=sp.Rule()
blocTz=sp.Rule()
blocFx=sp.Rule()
blocFy=sp.Rule()
blocFz=sp.Rule()
blocMx=sp.Rule()
blocMy=sp.Rule()
blocMz=sp.Rule()
blocSolve=sp.Rule()
blocName1=sp.Rule()
blocName2=sp.Rule()
blocName=sp.Rule()
blocx=sp.Rule()
blocBNam=sp.Rule()
blocSeparator=sp.Rule()
blocTech=sp.Rule()
blocDur=sp.Rule()
blocComp=sp.Rule()
blocNiter=sp.Rule()
blocNom=sp.Rule()
blocAxis=sp.Rule()
blocRepere=sp.Rule()
affect=sp.Rule()
blocRef=sp.Rule()
L=sp.Rule()
E=sp.Rule()
Type=sp.Rule()
N=sp.Rule()
##########################################################################################################
assembly|=repe[0:] & beam[0:] & repemob[0:] & link[0:] & blocSolveur & blocParam[0:1]
link|=baliseDebutLink & blocName1 & blocx & blocName2 & blocx & blocSolve & blocAxis[0:1] & blocRepere[0:1] & baliseFinLink
beam|=baliseDebutPoutre & gNomPoutre & egal & '"' & nomPout &'" >' & blocDimensions & blocBoundaries & blocLoading & baliseFinPoutre
repe|=baliseDebutRep & blocNom & blocSolve & blocMz & blocMy & blocMx & baliseFinRep
repemob|=baliseDebutRepM & blocNom & blocRef & blocSolve & blocMz & blocMy & blocMx & baliseFinRepM
blocBoundaries|=baliseDebutBoundaries & blocLeft & blocRight & baliseFinBoundaries
blocDimensions|=baliseDebutDimensions & blocCoL & blocCoR & blocE & blocNu & blocS & blocIy & blocIz & blocRho & blocNb & blocInDef[0:1] & baliseFinDimensions
blocLoading|=baliseDebutLoading & blocLeft[0:1] & blocRight[0:1] & blocLineic[0:1] & baliseFinLoading
blocSolveur|=baliseDebutSolveur & blocSolve & blocDur[0:1] & blocTech[0:1] & blocNiter[0:1] & blocName & blocOutput[0:] & blocOutDyn[0:] & blocOutPlot[0:] & baliseFinSolveur
blocOutput|=baliseDebutOutput & blocBNam & blocU & blocF & baliseFinOutput
blocOutDyn|=baliseDebutOutDyn & blocBNam & blocx & blocComp & baliseFinOutDyn
blocOutPlot|=baliseDebutOutPlot & blocBNam & blocCo & blocU & blocF & blocSeparator[0:1] & baliseFinOutPlot
blocParam|=baliseDebutParam & affect[0:] & baliseFinParam
blocLeft|=baliseDebutLeft & blocUx[0:1] & blocUy[0:1] & blocUz[0:1] & blocTx[0:1] & blocTy[0:1] & blocTz[0:1] & baliseFinLeft
blocRight|=baliseDebutRight & blocUx[0:1] & blocUy[0:1] & blocUz[0:1] & blocTx[0:1] & blocTy[0:1] & blocTz[0:1] & baliseFinRight
blocLineic|=baliseDebutLin & blocFx[0:1] & blocFy[0:1] & blocFz[0:1] & blocMx[0:1] & blocMy[0:1] & blocMz[0:1] & baliseFinLin
blocInDef|=baliseDebutID & blocUx[0:1] & blocUy[0:1] & blocUz[0:1] & baliseFinID
blocCoL|=gGauche & depoin & L & ',' & L & ',' & L & ';'
blocCoR|=gDroite & depoin & L & ',' & L & ',' & L & ';'
blocL|='L' & egal & L &';'
blocE|='E' & egal & E &';'
blocNu|='Nu' & egal & E &';'
blocS|='S' & egal & E &';'
blocIy|='Iy' & egal & E &';'
blocIz|='Iz' & egal & E &';'
blocRho|='Rho' & egal & E &';'
blocNb|='n' & egal & N &';'
blocU|='U' & egal & component[0:6] & ';'
blocF|='F' & egal & component[0:6] & ';'
blocCo|='Coord' & egal & coord[0:3] & ';'
blocUx|='Ux' & egal & L & ';'
blocUy|='Uy' & egal & L & ';'
blocUz|='Uz' & egal & L & ';'
blocTx|='Theta_x' & egal & L & ';'
blocTy|='Theta_y' & egal & L & ';'
blocTz|='Theta_z' & egal & L & ';'
blocFx|='fx' & egal & E & ';'
blocFy|='fy' & egal & E & ';'
blocFz|='fz' & egal & E & ';'
blocMx|='mx' & egal & E & ';'
blocMy|='my' & egal & E & ';'
blocMz|='mz' & egal & E & ';'
blocSolve|='Type' & egal & Type & N[0:1] & ';'
blocName1|=gPout1 & egal & Type & ';'
blocName2|=gPout2 & egal & Type & ';'
blocName|=gNomSort & egal & Type & ';'
blocx|='X' & egal & L & ';'
blocBNam|=gPout & egal & nomPout & ';'
blocSeparator|='Sep' & egal & separator & ';'
blocTech|='dt' & egal & L & ';'
blocDur|='T' & egal & L & ';'
blocComp|=gCompo & egal & component & ';'
blocNiter|='n_iter' & egal & N & ';'
blocNom|=gNom & egal & nomPout & ';'
blocAxis|=gAx & egal & nom & ';'
blocRepere|=gRepere & egal & nomPout & ';'
affect|=nomPout & egal & express & ';'
blocRef|='ref' & egal & nomPout & ',' & express & ';'
L|=express
E|=express|nomFich#|express#|nomPout|nbVirgule
Type|=nomPout
N|=express
return assembly
if __name__ == "__main__" :
traduire=parser()
texte1="""
<SYSTEM>
Name = Repere0 ;
Type = ZYX ;
mz = Pi1/16;
my = Pi1/8 ;
mx = -Pi1/16 ;
</SYSTEM>
<Beam Name="Poutre1" >
<DIMENSIONS>
Left : 0.0 , 0.0 , 0.0 ;#Coords of the beginning of the beam (m)
Right: 0.3 , 0.0 , 0.0 ;#Coords of the end of the beam (m)
E= 210000000000.0 ;#Young modulus (Pa)
Nu = 0.3 ;#Fish coefficient
S = 0.001 ;#Section(m^2)
Iy = 0.00000000001 ;#Quadratic moment (m^4)
Iz =[dataiz] ;#Quadratic moment (m^4)
Rho = 7800 ; #Volumic mass (kg.m-3)
n = 10 ; #Number of elements between 2 sides of a beam
<Init_defo>
Ux = 0.01*sin(X/0.3*pi) ;
</Init_defo>
</DIMENSIONS>
<LIMITES> #boundaries conditions for displacement
<Left>
Ux = 0.0 ;
Uy = 0.0 ;
Uz = 0.0 ;
Theta_x = 0.0 ;
Theta_y=0.0 ;
Theta_z = 0.0 ;
</Left>
<Right>
Ux = 0.0 ;
</Right>
</BOUNDARIES>
<LOADING> #efforts on the beam
<Left> #ponctual effort on the left
Uy = 0.0 ;
Theta_x = 0.0 ;
</Left>
<Lineic> #Lineic effort
fy=-1.0;#Nm-1
mx = [datamx];
</Lineic>
</LOADING>
</BEAM>
<Beam Name="Poutre2" >
<DIMENSIONS>
Left : 0.3 , 0.0 , 0.0 ;#Coords of the beginning of the beam (m)
Right : 0.4 , 0.0 , 0.0 ;#Coords of the end of the beam (m)
E = 210000000000.0 ;#Young modulus (Pa)
Nu = 0.3 ;#Fish coefficient
S = 0.001 ;#Section(m^2)
Iy = 0.00000000001 ;#Quadratic moment (m^4)
Iz = 0.0000000002 ;#Quadratic moment (m^4)
Rho = 7800 ; #Volumic mass (kg.m-3)
n = 10 ; #Number of elements between 2 sides of a beam
</DIMENSIONS>
<BOUNDARIES> #boundaries conditions for displacement
<Left>
Ux = 0.0 ;
Theta_y = 0.0 ;
</Left>
<Right>
Ux = 0 ;
Uy = 0.0 ;
Uz = 0.0 ;
Theta_x = 0.0 ;
Theta_y = 0.0 ;
Theta_z = 0.0 ;
</Right>
</BOUNDARIES>
<LOADING> #efforts on the beam
<Left> #ponctual effort on the left
Uy = 0.0 ;
Theta_x = 0.0 ;
</Left>
<Right> #ponctual effort on the right
Theta_z = 0.0 ;
</Right>
<Lineic> #Lineic effort
#nope
</Lineic>
</LOADING>
</BEAM>
<MOB_SYSTEM>
Name = Repere0 ;
ref = Poutre2 , 0 ;
Type = ZYX ;
mz = Pi1/16;
my = Pi1/8 ;
mx = -Pi1/16 ;
</MOB_SYSTEM>
<LINK>
Beam1 = Poutre1 ; #1st beam
X = 3.0 ; #curvilign absciss on beam 1
Beam2 = Poutre2 ; #2nd beam
X = 0.0 ;
Type = pivot ;
Axis = x ;
System = global ;
</LINK>
<SOLVER>
Type = static;
Output_name = toto;
<OUTPUT>
Beam = Poutre1 ;
U = Ux Uy Uz Theta_x Theta_y Theta_z ;
F = Ux Uy Uz Theta_x Theta_y Theta_z ;
</OUTPUT>
<OUTPUT>
Beam = Poutre2 ;
U = Ux Uy Uz Theta_x Theta_y Theta_z ;
F = Ux Uy Uz Theta_x Theta_y Theta_z ;
</OUTPUT>
<TIME_OUTPUT>
Beam = Poutre1 ;
X = 3.0 ;
Component = Ux ;
</TIME_OUTPUT>
<PLOT_OUTPUT>
Beam = Poutre1 ;
Coord = X Y Z ;
U = Ux Uy Uz Theta_x Theta_y Theta_z ;
F = Ux Uy Uz Theta_x Theta_y Theta_z ;
Sep = ; ;
</PLOT_OUTPUT>
</SOLVER>
<PARAMETERS>
Pi1 = 3.1415926535 ;
L1 = cos(5.03) ; #def of a param
</PARAMETERS>"""
try :
donnees=traduire(texte1)
except SyntaxError as erreur :
print("-Erreur à[ligne:colonne]")
print(' ',erreur)
print(donnees)