-
Notifications
You must be signed in to change notification settings - Fork 1
/
ecriture_fichiers_SWMS2D_EL.py
executable file
·194 lines (154 loc) · 6.59 KB
/
ecriture_fichiers_SWMS2D_EL.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
import numpy as np
def number_cells_with_BC_of_p(p):
n_charge_imp=len(np.array(np.where(p[:,2]==1)).T)
n_free_drainage=len(np.array(np.where(p[:,2]==-3)).T)
return n_charge_imp + n_free_drainage
def ecriture_Selector_in(mesh, paramMVG, temps, p):
"""Fonction qui permet d'écrire le fichier Selector.in nécessaire pour lancer SWMS_2D.
Contient surtout les param hydro et les options de SWMS_2D.
"""
s = """*** BLOCK A: BASIC INFORMATION *****************************************
'Heading'
Example 1 - Column Test
LUnit TUnit MUnit BUnit (units are obligatory for all input data)
'cm' 'min' '-' '-'
Kat (0:horizontal plane, 1:axisymmetric vertical flow, 2:vertical plane
1
MaxIt TolTh TolH (maximum number of iterations and tolerances)
25 .001 0.5
lWat lChem ChecF ShortF FluxF AtmInF SeepF FreeD DrainF
t f f t t f f f f
*** BLOCK B: MATERIAL INFORMATION **************************************
NMat NLay hTab1 hTabN NPar
1 1 .001 200. 9
thr ths tha thm Alfa n Ks Kk thk
{tr} {ts} {tha} {thm} {Alfa} {n} {Ks} {Kk} {thk}
*** BLOCK C: TIME INFORMATION ******************************************
dt dtMin dtMax DMul DMul2 MPL
.1 .01 10. 1.1 .7 {MPL}
TPrint(1),TPrint(2),...,TPrint(MPL) (print-time array)
{times}
*** END OF INPUT FILE SELECTOR.IN************************************
""".format(tr=paramMVG.tr,
ts=paramMVG.ts,
tha=paramMVG.tr,
thm=paramMVG.ts,
Alfa=paramMVG.alpha,
n=paramMVG.n,
Ks=paramMVG.Ks,
Kk=paramMVG.Ks,
thk=paramMVG.ts,
MPL=len(temps),
times=" ".join([str(i) for i in temps])
)
fselector=open("Selector.in","w")
fselector.write(s)
fselector.close()
def ecriture_Grid_in_EL(mesh, p):
"""Fonction qui permet d'écrire le fichier Grid.in nécessaire pour lancer SWMS_2D.
Fichier qui contient les Width...
"""
Ncells = mesh.cellCount() #nombre de cellules du maillage
Nnodes = mesh.nodeCount() #nombre de noeuds du maillage
Nbc = number_cells_with_BC_of_p(p) #nombre de noeuds avec Boundary conditions
t = np.zeros((Ncells, 3), dtype = 'float')
for i in range(0,Ncells) :
c=mesh.cell(i)
for j in range(0,3) :
l=c.node(j)
f=l.id()
t[i,j]=f
a = (np.array(np.where(p[:,2]==1))).T #Noeuds ayant une charge imposée constante
b = (np.array(np.where(p[:,2]==-3))).T #Noeuds ayant un drainage
def width(p,a,b) :
import math
e = np.zeros((len(a), 3), dtype = 'float')
f = np.zeros((len(b), 3), dtype = 'float')
e[:,0] = a[:,0]
f[:,0] = b[:,0]
e[:,1] = p[a[:,0],0]
f[:,1] = p[b[:,0],0]
#On trie les noeuds par x croissant
e=np.array(sorted(e, key=lambda colonne: colonne[1]))
f=np.array(sorted(f, key=lambda colonne: colonne[1]))
for i in range(0,len(a[:,0])) :
if i==0 : #Premier noeud
e[i,2] = ((math.pi)/3) * ( (e[i+1,1] + 2* e[i,1]) * (e[i+1,1]-e[i,1]))
elif i==(len(a[:,0])-1) : #Dernier noeud
e[i,2] = ((math.pi)/3) * ( (e[i-1,1] + 2* e[i,1]) * (e[i,1]-e[i-1,1]))
else : #Autres noeuds
e[i,2] = ((math.pi)/3) * ( (e[i-1,1] + 2* e[i,1]) * (e[i,1]-e[i-1,1]) + (e[i+1,1] + 2* e[i,1]) * (e[i+1,1]-e[i,1]))
for i in range (0,len(b[:,0])) :
if i==0 : #Premier noeud
f[i,2] = ((math.pi)/3) * ( (f[i+1,1] + 2* f[i,1]) * (f[i+1,1]-f[i,1]))
elif i==(len(b[:,0])-1) : #Dernier noeud
f[i,2] = ((math.pi)/3) * ( (f[i-1,1] + 2* f[i,1]) * (f[i,1]-f[i-1,1]))
else : #Autre noeuds
f[i,2] = ((math.pi)/3) * ( (f[i-1,1] + 2* f[i,1]) * (f[i,1]-f[i-1,1]) + (f[i+1,1] + 2* f[i,1]) * (f[i+1,1]-f[i,1]))
return e, f
[e, f] = width(p,a,b)
dim = [Nnodes, Ncells, 2, Nbc, 0]
s1 = """*** BLOCK H: NODAL INFORMATION **************************************************
NumNP NumEl IJ NumBP NObs
{dim_list}
n Code x z h Conc Q M B Axz Bxz Dxz
""".format(dim_list=" ".join([str(i) for i in dim]))
s2 = """*** BLOCK I: ELEMENT INFORMATION ************************************************
e i j k l Angle Aniz1 Aniz2 LayNum
"""
s3="""*** BLOCK J: BOUNDARY GEOMETRY INFORMATION *************************************
Node number array:
"""
fgrid=open("Grid.in","w")
fgrid.write(s1)
for i in range(0,len(p)) :
fgrid.write("""{:d} {:d} {:.5f} {:.5f} {:.5f} .00E+00 .00E+00 1 0 1 1 1 \n""".format(i + 1, int(p[i,2]), p[i,0], p[i,1], p[i,3]))
#Attention, il faut enlever une ligne mais je ne vois pas comment faire...
fgrid.write(s2)
for i in range(0,len(t)) :
fgrid.write("""{:d} {:d} {:d} {:d} {:d} 0 1 1 1 \n""".format(i + 1, int(t[i,0]+1), int(t[i,1]+1), int(t[i,2]+1), int(t[i,2]+1)))
fgrid.write(s3)
k = 1
for i in range(0,len(e[:,0])) :
fgrid.write("""{:d} \t""".format(int(e[i,0]+1)))
k = k + 1
if (k==7) :
fgrid.write("""\n""")
k = 1
if(k!=1):
fgrid.write("""\n""")
k = 1
#fgrid.write("""\n""")
if f.any() or f.size > 0:
for i in range(0,len(f[:,0])) :
fgrid.write("""{:d} \t""".format(int(f[i,0]+1)))
k = k + 1
if k==7 :
fgrid.write("""\n""")
k = 1
if(k!=1):
fgrid.write("""\n""")
k = 1
fgrid.write("""Width array:\n""")
for i in range(0,len(e[:,0])) :
fgrid.write("""{:.4f} \t""".format(e[i,2]))
k = k + 1
if k==7 :
fgrid.write("""\n""")
k = 1
if(k!=1):
fgrid.write("""\n""")
k = 1
if f.any() or f.size > 0:
for i in range(0,len(f[:,0])) :
fgrid.write("""{:.4f} \t""".format(f[i,2]))
k = k + 1
if k==7 :
fgrid.write("""\n""")
k=1
if(k!=1):
fgrid.write("""\n""")
fgrid.write("""Length:\n""")
fgrid.write("""0\n""")
fgrid.write("""*** END OF INPUT FILE GRID.IN *************************************************\n""")
fgrid.close()