Changeset 4869 for palm/trunk/SCRIPTS/palm_gf_files/palm_gf_exec.py
- Timestamp:
- Feb 8, 2021 4:14:27 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/SCRIPTS/palm_gf_files/palm_gf_exec.py
r2308 r4869 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(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: 1 #!/usr/bin/env python 2 from PyQt5.QtCore import pyqtSignal, QThread 3 from math import floor 4 from palm_gf_files.palm_gf_conf import cfg_read 5 from datetime import datetime 6 import sqlite3 7 8 9 class MyThread(QThread): 10 change_value = pyqtSignal(int) 11 completed = pyqtSignal(int, int) 12 busy = pyqtSignal() 13 14 def run(self): 15 # has to be defined in QThread class 16 # starts calculation 17 self.mainroutine() 18 19 def mainroutine(self): 20 # determines all possible solutions for given parameters 21 start = datetime.now() 22 conn = sqlite3.connect("palm_gf_data.db") 23 c = conn.cursor() 24 c.execute("DROP TABLE IF EXISTS grid_current") 25 c.execute("DROP TABLE IF EXISTS grid_limits") 26 c.execute("CREATE TABLE IF NOT EXISTS grid_current(nx INT, ny INT, nz INT, npex INT, npey INT, pxpy FLOAT," 27 "np INT, ngpts FLOAT, nxnpex FLOAT, nynpey FLOAT)") 28 c.execute("CREATE TABLE IF NOT EXISTS grid_limits(nx INT, ny INT, nz INT, npex INT, npey INT, pxpy FLOAT," 29 "np INT, ngpts FLOAT, nxnpex FLOAT, nynpey FLOAT)") 30 conn.commit() 31 var = cfg_read() 32 33 for j in range(12, 17): 34 if var[j] == "True": 35 var[j] = True 36 else: 37 var[j] = False 38 39 nx_min = int(var[0]) 40 nx_max = int(var[1]) 41 ny_min = int(var[2]) 42 ny_max = int(var[3]) 43 nz_min = int(var[4]) 44 nz_max = int(var[5]) 45 procs_min = int(var[6]) 46 procs_max = int(var[7]) 47 tpn = int(var[8]) 48 dnxny = float(var[9]) 49 dpxpy = float(var[10]) 50 dpxpy_dev = int(var[11]) 51 poisfft = var[12] 52 switch = var[13] 53 temperton = var[14] 54 mlt_grid = var[15] 55 spectr = var[16] 56 57 np_used = procs_min 58 counter = 0 59 cnt = 0 60 nx = nx_min 61 ny = ny_min 62 nz = nz_min 63 64 def factors(n): 65 # prime factorization 66 result = [] 67 for i in range(2, n + 1): 68 s = 0 69 while n / i == floor(n / float(i)): 70 n = n / float(i) 71 s += 1 72 if s > 0: 73 for k in range(s): 74 result.append(i) 75 if n == 1: 76 return result 77 78 def temperton_check(nx_, ny_): 79 # uses previously defined prime factorization and determines if ny+1/nx+1 is multiple of 2,3,5 80 nx_list = factors(nx_ + 1) 81 ny_list = factors(ny_ + 1) 82 return_value = 1 83 i = 0 84 if nx_list is not None: 85 while i < len(nx_list): 86 if not (nx_list[i] == 2 or nx_list[i] == 3 or nx_list[i] == 5): 87 return_value = 0 88 i += 1 89 j = 0 90 if ny_list is not None: 91 while j < len(ny_list): 92 if not (ny_list[j] == 2 or ny_list[j] == 3 or ny_list[j] == 5): 93 return_value = 0 94 j += 1 95 96 if nx_list is None: 97 return_value = 0 98 if ny_list is None: 99 return_value = 0 100 101 return return_value 102 # * * * 103 104 while np_used <= procs_max: 105 a = 1 106 while a <= np_used: 107 if cnt != ((np_used - procs_min) / (procs_max - procs_min)) * 100: 108 cnt = ((np_used - procs_min) / (procs_max - procs_min)) * 100 109 self.change_value.emit(cnt) 110 procs_var = np_used % a 111 if procs_var != 0: 98 112 a += 1 99 continue 100 101 while nx <= nx_max: 102 if (nx + 1) % npex != 0: 113 elif procs_var == 0: 114 npex = a 115 npey = int(np_used / npex) 116 117 if tpn != 0: 118 if np_used % tpn != 0: 119 a += 1 120 continue 121 122 if dpxpy != 0.: 123 if (dpxpy - dpxpy_dev*dpxpy) > (float(npex)/float(npey)) or \ 124 (float(npex)/float(npey)) > (dpxpy + dpxpy_dev*dpxpy): 125 a += 1 126 continue 127 128 # if dpxpy != 0. and float(npex) / float(npey) != dpxpy: 129 # a += 1 130 # continue 131 132 while nx <= nx_max: 133 if (nx + 1) % npex != 0: 134 nx += 1 135 continue 136 137 if mlt_grid is True and nx % 2 != 0: 138 nx += 1 139 continue 140 141 if switch is True and (nx + 1) % npey != 0: 142 nx += 1 143 continue 144 145 if npex > nx: 146 nx += 1 147 continue 148 149 while ny <= ny_max: 150 151 if dnxny != 0. and float(nx) / float(ny) != float(dnxny): 152 ny += 1 153 continue 154 155 if (ny + 1) % npey != 0: 156 ny += 1 157 continue 158 159 if mlt_grid is True and ny % 2 != 0: 160 ny += 1 161 continue 162 163 if switch is True and (ny + 1) % npex != 0: 164 ny += 1 165 continue 166 167 if npey > ny: 168 ny += 1 169 continue 170 171 while nz <= nz_max: 172 173 if mlt_grid is True and nz % 2 != 0: 174 nz += 1 175 continue 176 177 if poisfft is True and nz % npex != 0: 178 nz += 1 179 continue 180 181 if spectr is True and nz % npey != 0: 182 nz += 1 183 continue 184 185 if temperton is True and nx > 1 and ny > 1 and temperton_check(nx, ny) == 0: 186 nz += 1 187 continue 188 189 npxnpy = format(float(npex) / float(npey), '.2f') 190 nxnpex = float(nx + 1) / float(npex) 191 nynpey = float(ny + 1) / float(npey) 192 193 c.execute("""INSERT OR REPLACE INTO grid_current(nx, ny, nz, npex, npey, pxpy, 194 np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", 195 (nx, ny, nz, npex, npey, npxnpy, (npex * npey), (nx * ny * nz), 196 nxnpex, nynpey)) 197 198 counter += 1 199 nz += 1 200 nz = nz_min 201 ny += 1 202 ny = ny_min 103 203 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 204 nx = nx_min 205 a += 1 206 np_used += 1 207 conn.commit() 189 208 190 209 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 286 def 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() 210 self.busy.emit() 211 # read out limits of data in .db 212 try: 213 c.execute("SELECT nx FROM grid_current ORDER BY nx DESC LIMIT 1") 214 mx_nx = c.fetchone()[0] 215 c.execute("SELECT nx FROM grid_current ORDER BY nx LIMIT 1") 216 mn_nx = c.fetchone()[0] 217 c.execute("SELECT ny FROM grid_current ORDER BY ny DESC LIMIT 1") 218 mx_ny = c.fetchone()[0] 219 c.execute("SELECT ny FROM grid_current ORDER BY ny LIMIT 1") 220 mn_ny = c.fetchone()[0] 221 c.execute("SELECT nz FROM grid_current ORDER BY nz DESC LIMIT 1") 222 mx_nz = c.fetchone()[0] 223 c.execute("SELECT nz FROM grid_current ORDER BY nz LIMIT 1") 224 mn_nz = c.fetchone()[0] 225 c.execute("SELECT npex FROM grid_current ORDER BY npex DESC LIMIT 1") 226 mx_npex = c.fetchone()[0] 227 c.execute("SELECT npex FROM grid_current ORDER BY npex LIMIT 1") 228 mn_npex = c.fetchone()[0] 229 c.execute("SELECT npey FROM grid_current ORDER BY npey DESC LIMIT 1") 230 mx_npey = c.fetchone()[0] 231 c.execute("SELECT npey FROM grid_current ORDER BY npey LIMIT 1") 232 mn_npey = c.fetchone()[0] 233 c.execute("SELECT pxpy FROM grid_current ORDER BY pxpy DESC LIMIT 1") 234 mx_npxnpy = c.fetchone()[0] 235 c.execute("SELECT pxpy FROM grid_current ORDER BY pxpy LIMIT 1") 236 mn_npxnpy = c.fetchone()[0] 237 c.execute("SELECT np FROM grid_current ORDER BY np DESC LIMIT 1") 238 mx_np = c.fetchone()[0] 239 c.execute("SELECT np FROM grid_current ORDER BY np LIMIT 1") 240 mn_np = c.fetchone()[0] 241 c.execute("SELECT ngpts FROM grid_current ORDER BY ngpts DESC LIMIT 1") 242 mx_ngpts = c.fetchone()[0] 243 c.execute("SELECT ngpts FROM grid_current ORDER BY ngpts LIMIT 1") 244 mn_ngpts = c.fetchone()[0] 245 c.execute("SELECT nxnpex FROM grid_current ORDER BY nxnpex DESC LIMIT 1") 246 mx_nxpex = c.fetchone()[0] 247 c.execute("SELECT nxnpex FROM grid_current ORDER BY nxnpex LIMIT 1") 248 mn_nxpex = c.fetchone()[0] 249 c.execute("SELECT nynpey FROM grid_current ORDER BY nynpey DESC LIMIT 1") 250 mx_nypey = c.fetchone()[0] 251 c.execute("SELECT nynpey FROM grid_current ORDER BY nynpey LIMIT 1") 252 mn_nypey = c.fetchone()[0] 253 254 conn.commit() 255 c.execute( 256 """INSERT OR REPLACE INTO grid_limits(nx, ny, nz, npex, npey, 257 pxpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", 258 (mn_nx, mn_ny, mn_nz, mn_npex, mn_npey, mn_npxnpy, mn_np, mn_ngpts, mn_nxpex, mn_nypey)) 259 260 c.execute( 261 """INSERT OR REPLACE INTO grid_limits(nx, ny, nz, npex, npey, 262 pxpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", 263 (mx_nx, mx_ny, mx_nz, mx_npex, mx_npey, mx_npxnpy, mx_np, mx_ngpts, mx_nxpex, mx_nypey)) 264 conn.commit() 265 266 c.close() 267 conn.close() 268 except TypeError: 269 pass 270 271 finish = datetime.now() 272 timedelta = finish - start 273 timer = (int(timedelta.seconds)) 274 self.completed.emit(counter, timer)
Note: See TracChangeset
for help on using the changeset viewer.