source: palm/trunk/SCRIPTS/palm_gf_files/palm_gf_exec.py @ 2712

Last change on this file since 2712 was 2308, checked in by gronemeier, 7 years ago

new version of palm_gf (bugfixes, changes and new options)

File size: 10.6 KB
Line 
1def grid_executer():
2    import palm_gf_conf as config_wr
3    import sqlite3
4    conn = sqlite3.connect(".palm_gf_data.db")
5    c = conn.cursor()
6    c.execute("DROP TABLE IF EXISTS grid_current")
7    c.execute("DROP TABLE IF EXISTS grid_limits")
8    c.execute("CREATE TABLE IF NOT EXISTS grid_current(nx INT, ny INT, nz INT, npex INT, npey INT, npxnpy FLOAT, np INT, ngpts INT)")
9    c.execute("CREATE TABLE IF NOT EXISTS grid_limits(nx INT, ny INT, nz INT, npex INT, npey INT, npxnpy FLOAT, np INT, ngpts INT)")
10    conn.commit()
11    main_bool = True
12    parameters = config_wr.read_config()
13    print(parameters)
14    min_procs = int(parameters[0])
15    max_procs = int(parameters[1])
16    tpn = int(parameters[2])
17    dnpexnpey = float(parameters[3])
18    dnxny = float(parameters[4])
19    nx_min = int(parameters[5])
20    nx_max = int(parameters[6])
21    ny_min = int(parameters[7])
22    ny_max = int(parameters[8])
23    nz_min = int(parameters[9])
24    nz_max = int(parameters[10])
25    poisfft = parameters[11]
26    switch = parameters[12]
27    tempterton = parameters[13]
28    mlt_grid = parameters[14]
29    spectr = parameters[15]
30
31    if poisfft == str(True):
32        poisfft = True
33    else:
34        poisfft = False
35
36    if switch == str(True):
37        switch = True
38    else:
39        switch = False
40
41    if tempterton == str(True):
42        tempterton = True
43    else:
44        tempterton = False
45
46    if mlt_grid == str(True):
47        mlt_grid = True
48    else:
49        mlt_grid = False
50
51    if spectr == str(True):
52        spectr = True
53    else:
54        spectr = False
55
56    print(spectr, type(spectr))
57    print(poisfft, switch, tempterton, mlt_grid, spectr)
58
59    np_used = min_procs
60    counter = 0
61
62    nx = nx_min
63    ny = ny_min
64    nz = nz_min
65
66    from math import floor
67
68    def factors(n):
69        result = []
70        for i in range(2, n + 1):  # test all integers between 2 and n
71            s = 0
72            while n / i == floor(n / float(i)):  # is n/i an integer?
73                n = n / float(i)
74                s += 1
75            if s > 0:
76                for k in range(s):
77                    result.append(i)  # i is a pf s times
78                    if n == 1:
79                        return result
80
81    while np_used <= max_procs:
82        a = 1
83
84        while a <= np_used:
85            prcs_var = np_used % a
86            if prcs_var != 0:
87                a += 1
88            elif prcs_var == 0:
89                npex = a
90                npey = int(np_used / npex)
91
92                if tpn != 0:
93                    if np_used % tpn != 0:
94                        a += 1
95                        continue
96
97                if dnpexnpey != 0 and npex / npey != dnpexnpey:
98                    a += 1
99                    continue
100
101                while nx <= nx_max:
102                    if (nx + 1) % npex != 0:
103                        nx += 1
104                        continue
105
106                    if mlt_grid is True and (nx + 1) % 2 != 0:
107                        nx += 1
108                        continue
109
110                    if switch is True and (nx + 1) % npey != 0:
111                        nx += 1
112                        continue
113                    if npex > nx:
114                        nx += 1
115                        continue
116
117                    while ny <= ny_max:
118
119                        if dnxny != 0 and float(nx) / float(ny) != float(dnxny):
120                            ny += 1
121                            continue
122                        if (ny + 1) % npey != 0:
123                            ny += 1
124                            continue
125
126                        if mlt_grid is True and ny % 2 != 0:
127                            ny += 1
128                            continue
129
130                        if (ny + 1) % npex != 0 and switch is True:
131                            ny += 1
132                            continue
133                        if npey > ny:
134                            ny += 1
135                            continue
136
137                        while nz <= nz_max:
138
139                            if mlt_grid is True and nz % 2 != 0:
140                                nz += 1
141                                continue
142
143                            if poisfft is True and nz % npex != 0:
144                                nz += 1
145                                continue
146
147                            if spectr is True and nz % npey != 0:
148                                nz += 1
149                                continue
150
151                            if tempterton is True and nx > 1 and ny > 1:  # and nz < 1:
152
153                                nx_list = factors(nx + 1)
154                                i = 0
155                                nx_var = nx_list[i]
156
157                                while i < len(nx_list):
158                                    if nx_var != 2 or nx_var != 3 or nx_var != 5:
159
160                                        i += 1
161                                        continue
162
163                                    i += 1
164                                ny_list = factors(ny + 1)
165                                i = 0
166                                ny_var = ny_list[i]
167                                while i < len(ny_list):
168                                    if ny_var != 2 or ny_var != 3 or ny_var != 5:
169
170                                        i += 1
171                                        continue
172                                    i += 1
173
174                            counter += 1
175
176                            npxnpy = format(float(npex)/float(npey), '.2f')
177                            c.execute("""INSERT OR REPLACE INTO grid_current(nx, ny, nz, npex, npey, npxnpy, np, ngpts) VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
178                            (nx, ny, nz, npex, npey, npxnpy, (npex * npey), (nx*ny*nz)))
179
180                            nz += 11
181                        nz = nz_min
182                        ny += 1
183                    ny = ny_min
184                    nx += 1
185                nx = nx_min
186                a += 1
187                #  a += 1
188        np_used += 1
189
190        conn.commit()
191
192
193
194    conn.commit()
195    c.close()
196    conn.close()
197
198    #********************************
199
200    conn = sqlite3.connect(".palm_gf_data.db")
201    c = conn.cursor()
202    try:
203        c.execute("SELECT nx FROM grid_current ORDER BY nx DESC LIMIT 1")
204        mx_nx = c.fetchone()[0]
205        #print(mx_nx)
206        c.execute("SELECT nx FROM grid_current ORDER BY nx  LIMIT 1")
207        mn_nx = c.fetchone()[0]
208        #print(mn_nx)
209        c.execute("SELECT ny FROM grid_current ORDER BY ny DESC LIMIT 1")
210        mx_ny = c.fetchone()[0]
211        #print(mx_ny)
212        c.execute("SELECT ny FROM grid_current ORDER BY ny  LIMIT 1")
213        mn_ny = c.fetchone()[0]
214        #print(mn_ny)
215        c.execute("SELECT nz FROM grid_current ORDER BY nz DESC LIMIT 1")
216        mx_nz = c.fetchone()[0]
217        #print(mx_nz)
218        c.execute("SELECT nz FROM grid_current ORDER BY nz  LIMIT 1")
219        mn_nz = c.fetchone()[0]
220        #print(mn_nz)
221        c.execute("SELECT npex FROM grid_current ORDER BY npex DESC LIMIT 1")
222        mx_npex = c.fetchone()[0]
223        #print(mx_npex)
224        c.execute("SELECT npex FROM grid_current ORDER BY npex  LIMIT 1")
225        mn_npex = c.fetchone()[0]
226        #print(mn_npex)
227        c.execute("SELECT npey FROM grid_current ORDER BY npey DESC LIMIT 1")
228        mx_npey = c.fetchone()[0]
229        #print(mx_npey)
230        c.execute("SELECT npey FROM grid_current ORDER BY npey  LIMIT 1")
231        mn_npey = c.fetchone()[0]
232        #print(mn_npey)
233        c.execute("SELECT npxnpy FROM grid_current ORDER BY npxnpy DESC LIMIT 1")
234        mx_npxnpy = c.fetchone()[0]
235        #print(mx_npxnpy)
236        c.execute("SELECT npxnpy FROM grid_current ORDER BY npxnpy  LIMIT 1")
237        mn_npxnpy = c.fetchone()[0]
238        #print(mn_npxnpy)
239        c.execute("SELECT np FROM grid_current ORDER BY np DESC LIMIT 1")
240        mx_np = c.fetchone()[0]
241        #print(mx_np)
242        c.execute("SELECT np FROM grid_current ORDER BY np LIMIT 1")
243        mn_np = c.fetchone()[0]
244        #print(mn_np)
245        c.execute("SELECT ngpts FROM grid_current ORDER BY ngpts DESC LIMIT 1")
246        mx_ngpts = c.fetchone()[0]
247        #print(mx_ngpts)
248        c.execute("SELECT ngpts FROM grid_current ORDER BY ngpts LIMIT 1")
249        mn_ngpts = c.fetchone()[0]
250        #print(mn_ngpts)
251
252        conn.commit()
253        c.execute(
254            """INSERT OR REPLACE INTO grid_limits(nx, ny, nz, npex, npey, npxnpy, np, ngpts) VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
255            (mn_nx, mn_ny, mn_nz, mn_npex, mn_npey, mn_npxnpy, mn_np, mn_ngpts))
256        #conn.commit()
257        #print("test", mn_nx)
258        c.execute(
259            """INSERT OR REPLACE INTO grid_limits(nx, ny, nz, npex, npey, npxnpy, np, ngpts) VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
260            (mx_nx, mx_ny, mx_nz, mx_npex, mx_npey, mx_npxnpy, mx_np, mx_ngpts))
261        conn.commit()
262
263        c.close()
264        conn.close()
265    except TypeError:
266
267        checkfile = open(".palm_gf_tmp", "w")
268        if counter != 0:
269            checkfile.write("Gridfinder found " + str(counter) + " results.\n1")
270        else:
271            checkfile.write("Check input, no Results found.\n0")
272        checkfile.close()
273
274
275
276    checkfile = open(".palm_gf_tmp", "w")
277    if counter != 0:
278        checkfile.write("Gridfinder found " + str(counter) + " results.\n1")
279    else:
280        checkfile.write("Check input, no Results found.\n0")
281    checkfile.close()
282    return main_bool
283
284
285
286def grid_maxmin():
287
288    import palm_gf_conf
289    import sqlite3
290
291    conn = sqlite3.connect("grid_current.db")
292    c = conn.cursor()
293    c.execute("DROP TABLE IF EXISTS grid_maxmin")
294    c.execute("CREATE TABLE IF NOT EXISTS grid_maxmin(np_min INT,np_max INT, npex_min INT,npex_max INT, npey_min INT,npey_max INT, nx_min INT,nx_max INT,"
295              " ny_min INT,ny_max INT, nz_min INT, nz_max INT)")
296    parm = config_wr.read_config()
297    min_procs = int(parm[0])
298    max_procs = int(parameters[1])
299    tpn = int(parameters[2])
300    dnpexnpey = float(parameters[3])
301    dnxny = float(parameters[4])
302    nx_min = int(parameters[5])
303    nx_max = int(parameters[6])
304    ny_min = int(parameters[7])
305    ny_max = int(parameters[8])
306    nz_min = int(parameters[9])
307    nz_max = int(parameters[10])
308
309
310
311
312
313    c.execute(
314        """INSERT OR REPLACE INTO grid_maxmin(np_min, np_max, npex_min, npex_max, npey_min, npey_max, nx_min, nx_max,
315         ny_min, ny_max, nz_min, nz_max) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
316        (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12))
317
318    conn.commit()
319    c.close()
320    conn.close()
Note: See TracBrowser for help on using the repository browser.