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