Changeset 4869 for palm/trunk/SCRIPTS/palm_gf_files/palm_gf_conf.py
- Timestamp:
- Feb 8, 2021 4:14:27 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/SCRIPTS/palm_gf_files/palm_gf_conf.py
r2308 r4869 1 def write_config(np_min, np_max, nx_min, nx_max, ny_min, ny_max, nz_min, nz_max, tpn, dnpexnpey, dnpexnpey_tolerance, dnxny, poisfft, switch, 2 temperton, mlt_grid, spectr, rslt_thrs, ld_thrs): 3 #from configparser import ConfigParser # windows 4 from ConfigParser import ConfigParser # Linux 1 #!/usr/bin/env python 2 # windows 3 from configparser import ConfigParser 4 # linux 5 #from configparser import configparser 6 import os 5 7 6 # if __name__ == "__main__": 7 cfg = ConfigParser() 8 9 import os.path 10 if os.path.exists('.palm_gf_conf') is False: 11 cfg.add_section("processor_topology") 12 cfg.add_section("numerical_grid") 13 cfg.add_section("method") 14 15 #cfg.add_section("processor_topology") 16 cfg.set("processor_topology", "np_min", np_min) 17 cfg.set("processor_topology", "np_max", np_max) 18 cfg.set("processor_topology", "tasks_per_node", tpn) 19 cfg.set("processor_topology", "dnpexnpey", dnpexnpey) 20 cfg.set("processor_topology", "dnpexnpey_tolerance", dnpexnpey_tolerance) 21 cfg.set("processor_topology", "dnxny", dnxny) 22 23 #cfgadd_section("numerical_grid"). 24 cfg.set("numerical_grid", "nx_min", nx_min) 25 cfg.set("numerical_grid", "nx_max", nx_max) 26 cfg.set("numerical_grid", "ny_min", ny_min) 27 cfg.set("numerical_grid", "ny_max", ny_max) 28 cfg.set("numerical_grid", "nz_min", nz_min) 29 cfg.set("numerical_grid", "nz_max", nz_max) 30 31 #cfg.add_section("method") 32 cfg.set("method", "poisfft", poisfft) 33 cfg.set("method", "switch", switch) 34 cfg.set("method", "temperton", temperton) 35 cfg.set("method", "mlt_grid", mlt_grid) 36 cfg.set("method", "spectr", spectr) 37 38 #cfg.add_section("settings") 39 #cfg.set("settings", "path", path) 40 #cfg.set("settings", "result_threshold", rslt_thrs) 41 #cfg.set("settings", "load_threshold", ld_thrs) 8 cfg = ConfigParser() 42 9 43 10 44 with open(".palm_gf_config", "a") as configfile: 45 cfg.write(configfile) 11 def cfg_write(nx_min, nx_max, ny_min, ny_max, nz_min, nz_max, np_min, np_max, tpn, 12 poisfft, switch, temperton, mlt_grid, spectr, dnxny, dpxpy, dpxpy_dev): 13 # receives parameters from palm_gf and creates/updates .ini file 14 if os.path.exists('./palm_gf_config.ini') is False: 15 cfg.add_section("Numerical Grid") 16 cfg.add_section("Processor Topology") 17 cfg.add_section("Method") 18 else: 19 cfg.read("palm_gf_config.ini") 20 21 cfg.set("Numerical Grid", "nx min", str(nx_min)) 22 cfg.set("Numerical Grid", "nx max", str(nx_max)) 23 cfg.set("Numerical Grid", "ny min", str(ny_min)) 24 cfg.set("Numerical Grid", "ny max", str(ny_max)) 25 cfg.set("Numerical Grid", "nz min", str(nz_min)) 26 cfg.set("Numerical Grid", "nz max", str(nz_max)) 27 28 cfg.set("Processor Topology", "np min", str(np_min)) 29 cfg.set("Processor Topology", "np max", str(np_max)) 30 cfg.set("Processor Topology", "tasks per node", str(tpn)) 31 cfg.set("Processor Topology", "ratio nx/ny", str(dnxny)) 32 cfg.set("Processor Topology", "ratio npex/npey", str(dpxpy)) 33 cfg.set("Processor Topology", "ratio npex/npey tolerance", str(dpxpy_dev)) 34 35 cfg.set("Method", "poisfft", str(poisfft)) 36 cfg.set("Method", "switch", str(switch)) 37 cfg.set("Method", "temperton", str(temperton)) 38 cfg.set("Method", "multigrid", str(mlt_grid)) 39 cfg.set("Method", "spectra", str(spectr)) 40 41 with open("./palm_gf_config.ini", 'w') as cfgfile: 42 cfg.write(cfgfile) 43 44 return True 46 45 47 46 48 def read_config(): 49 #from configparser import ConfigParser # windows 50 from ConfigParser import ConfigParser # Linux 47 def cfg_read(): 48 # reads the .ini File and returns all parameters in a list 49 cfg.read("palm_gf_config.ini") 50 return_list = [cfg.get("Numerical Grid", "nx min"), cfg.get("Numerical Grid", "nx max"), 51 cfg.get("Numerical Grid", "ny min"), cfg.get("Numerical Grid", "ny max"), 52 cfg.get("Numerical Grid", "nz min"), cfg.get("Numerical Grid", "nz max"), 53 cfg.get("Processor Topology", "np min"), cfg.get("Processor Topology", "np max"), 54 cfg.get("Processor Topology", "tasks per node"), cfg.get("Processor Topology", "ratio nx/ny"), 55 cfg.get("Processor Topology", "ratio npex/npey"), 56 cfg.get("Processor Topology", "ratio npex/npey tolerance"), cfg.get("Method", "poisfft"), 57 cfg.get("Method", "switch"), cfg.get("Method", "temperton"), cfg.get("Method", "multigrid"), 58 cfg.get("Method", "spectra")] 51 59 52 53 cfg = ConfigParser() 54 55 cfg.read(".palm_gf_config") 56 np_min = cfg.get("processor_topology", "np_min") 57 np_max = cfg.get("processor_topology", "np_max") 58 tpn = cfg.get("processor_topology", "tasks_per_node") 59 dnpexnpey = cfg.get("processor_topology", "dnpexnpey") 60 dnpexnpey_tolerance = cfg.get("processor_topology", "dnpexnpey_tolerance") 61 dnxny = cfg.get("processor_topology", "dnxny") 62 63 nx_min = cfg.get("numerical_grid", "nx_min") 64 nx_max = cfg.get("numerical_grid", "nx_max") 65 ny_min = cfg.get("numerical_grid", "ny_min") 66 ny_max = cfg.get("numerical_grid", "ny_max") 67 nz_min = cfg.get("numerical_grid", "nz_min") 68 nz_max = cfg.get("numerical_grid", "nz_max") 69 70 poisfft = cfg.get("method", "poisfft") 71 switch = cfg.get("method", "switch") 72 temperton = cfg.get("method", "temperton") 73 mlt_grid = cfg.get("method", "mlt_grid") 74 spectr = cfg.get("method", "spectr") 75 76 import ConfigParser as conf 77 try: 78 result_threshold = cfg.get("settings", "result_threshold") 79 load_threshold = cfg.get("settings", "load_threshold") 80 path = cfg.get("settings", 'path') 81 82 except conf.NoSectionError: 83 84 path = '/localdata/' 85 result_threshold = 250000 86 load_threshold = 100000 87 88 return np_min, np_max, tpn, dnpexnpey, dnpexnpey_tolerance, dnxny, nx_min, nx_max, ny_min, ny_max, nz_min, nz_max, poisfft, switch, temperton, mlt_grid, spectr, result_threshold, load_threshold, path 89 90 91 def write_config_settings(path, rslt_thrs, ld_thrs): 92 93 from ConfigParser import ConfigParser 94 95 cfg = ConfigParser() 96 97 cfg.add_section('settings') 98 99 cfg.set('settings', 'path', path) 100 cfg.set('settings', "result_threshold", rslt_thrs) 101 cfg.set('settings', "load_threshold", ld_thrs) 102 103 with open(".palm_gf_config", "a") as configfile: 104 cfg.write(configfile) 105 106 107 def read_config_settings(): 108 109 from ConfigParser import ConfigParser 110 import ConfigParser as con 111 112 cfg = ConfigParser() 113 cfg.read(".palm_gf_config") 114 115 try: 116 path = cfg.get("settings", "path") 117 result_thrs = cfg.get("settings", "result_threshold") 118 load_thrs = cfg.get("settings", "load_threshold") 119 120 except con.NoSectionError: 121 122 path = '/localdata/' 123 result_thrs = 250000 124 load_thrs = 100000 125 126 except con.NoOptionError: 127 128 path = '/localdata/' 129 result_thrs = 250000 130 load_thrs = 100000 131 132 #print path, result_thrs, load_thrs 133 134 return path, result_thrs, load_thrs 135 136 137 # *********************************************** 138 139 140 def closing_cleanup(): 141 from ConfigParser import ConfigParser # Linux 142 import ConfigParser as conf 143 import os, shutil, time 144 145 cfg = ConfigParser() 146 147 try: 148 149 cfg.read(".palm_gf_config") 150 np_min = cfg.get("processor_topology", "np_min") 151 np_max = cfg.get("processor_topology", "np_max") 152 tpn = cfg.get("processor_topology", "tasks_per_node") 153 dnpexnpey = cfg.get("processor_topology", "dnpexnpey") 154 dnpexnpey_tolerance = cfg.get("processor_topology", "dnpexnpey_tolerance") 155 dnxny = cfg.get("processor_topology", "dnxny") 156 157 nx_min = cfg.get("numerical_grid", "nx_min") 158 nx_max = cfg.get("numerical_grid", "nx_max") 159 ny_min = cfg.get("numerical_grid", "ny_min") 160 ny_max = cfg.get("numerical_grid", "ny_max") 161 nz_min = cfg.get("numerical_grid", "nz_min") 162 nz_max = cfg.get("numerical_grid", "nz_max") 163 164 poisfft = cfg.get("method", "poisfft") 165 switch = cfg.get("method", "switch") 166 temperton = cfg.get("method", "temperton") 167 mlt_grid = cfg.get("method", "mlt_grid") 168 spectr = cfg.get("method", "spectr") 169 170 var1_bool = True 171 172 except conf.NoSectionError: 173 np_min = 0 174 np_max = 0 175 tpn = 0 176 dnpexnpey = 0 177 dnpexnpey_tolerance = 0 178 dnxny = 0 179 180 nx_min = 0 181 nx_max = 0 182 ny_min = 0 183 ny_max = 0 184 nz_min = 0 185 nz_max = 0 186 187 poisfft = False 188 switch = False 189 temperton = False 190 mlt_grid = False 191 spectr = False 192 var1_bool = False 193 194 with open(".palm_gf_config", "w") as configfile: 195 cfg.write(configfile) 196 197 try: 198 cfg.read(".palm_gf_config") 199 rslt_thrs = cfg.get("settings", "result_threshold") 200 ld_thrs = cfg.get("settings", "load_threshold") 201 path = cfg.get("settings", 'path') 202 203 var2_bool = True 204 205 except conf.NoSectionError: 206 207 path = '/localdata/' 208 rslt_thrs = 250000 209 ld_thrs = 100000 210 211 var2_bool = False 212 213 214 215 with open(".palm_gf_config", "w") as configfile: 216 cfg.write(configfile) 217 218 219 220 #os.remove('.palm_gf_config') 221 222 223 224 try: 225 cfg.set("processor_topology", "np_min", np_min) 226 cfg.set("processor_topology", "np_max", np_max) 227 cfg.set("processor_topology", "tasks_per_node", tpn) 228 cfg.set("processor_topology", "dnpexnpey", dnpexnpey) 229 cfg.set("processor_topology", "dnpexnpey_tolerance", dnpexnpey_tolerance) 230 cfg.set("processor_topology", "dnxny", dnxny) 231 232 233 cfg.set("numerical_grid", "nx_min", nx_min) 234 cfg.set("numerical_grid", "nx_max", nx_max) 235 cfg.set("numerical_grid", "ny_min", ny_min) 236 cfg.set("numerical_grid", "ny_max", ny_max) 237 cfg.set("numerical_grid", "nz_min", nz_min) 238 cfg.set("numerical_grid", "nz_max", nz_max) 239 240 241 cfg.set("method", "poisfft", poisfft) 242 cfg.set("method", "switch", switch) 243 cfg.set("method", "temperton", temperton) 244 cfg.set("method", "mlt_grid", mlt_grid) 245 cfg.set("method", "spectr", spectr) 246 247 except conf.NoSectionError: 248 cfg.add_section("processor_topology") 249 cfg.set("processor_topology", "np_min", np_min) 250 cfg.set("processor_topology", "np_max", np_max) 251 cfg.set("processor_topology", "tasks_per_node", tpn) 252 cfg.set("processor_topology", "dnpexnpey", dnpexnpey) 253 cfg.set("processor_topology", "dnpexnpey_tolerance", dnpexnpey_tolerance) 254 cfg.set("processor_topology", "dnxny", dnxny) 255 256 cfg.add_section("numerical_grid") 257 cfg.set("numerical_grid", "nx_min", nx_min) 258 cfg.set("numerical_grid", "nx_max", nx_max) 259 cfg.set("numerical_grid", "ny_min", ny_min) 260 cfg.set("numerical_grid", "ny_max", ny_max) 261 cfg.set("numerical_grid", "nz_min", nz_min) 262 cfg.set("numerical_grid", "nz_max", nz_max) 263 264 cfg.add_section("method") 265 cfg.set("method", "poisfft", poisfft) 266 cfg.set("method", "switch", switch) 267 cfg.set("method", "temperton", temperton) 268 cfg.set("method", "mlt_grid", mlt_grid) 269 cfg.set("method", "spectr", spectr) 270 271 272 try: 273 cfg.set("settings", "path", path) 274 cfg.set("settings", "result_threshold", rslt_thrs) 275 cfg.set("settings", "load_threshold", ld_thrs) 276 277 except conf.NoSectionError: 278 cfg.add_section("settings") 279 cfg.set("settings", "path", path) 280 cfg.set("settings", "result_threshold", rslt_thrs) 281 cfg.set("settings", "load_threshold", ld_thrs) 282 283 284 285 286 287 288 with open(".palm_gf_config", "w") as configfile: 289 cfg.write(configfile) 290 60 return return_list
Note: See TracChangeset
for help on using the changeset viewer.