diff --git a/cgyro/bin/restart_add_dims.py b/cgyro/bin/restart_add_dims.py index 55dffc92a..6ab4ce93e 100755 --- a/cgyro/bin/restart_add_dims.py +++ b/cgyro/bin/restart_add_dims.py @@ -76,15 +76,128 @@ def get_arguments(): metavar='SCALE', help="Scaling factor for exended elements (Default: 1.0)", type=float, - default=1.0, + default=0.0, required=False) args=parser.parse_args() return args.o,args.n,args.s +# use edge val, no scaling +def add_dims_1(org_dir, new_dir, org_grid, new_grid, dim_offset): + org_fname = os.path.join(org_dir,libcgyrorestart.restart_fname) + new_fname = os.path.join(new_dir,libcgyrorestart.restart_fname) + + header_size = libcgyrorestart.header_size + + org_header = libcgyrorestart.CGyroRestartHeader() + org_header.load(org_dir) + if (not org_grid.isSame(org_header.grid)): + raise IOError("Wrong CGyroRestartHeader grid content") + thetabytes = org_header.get_thetabytes() + org_fsize = org_header.get_total_bytes() + if os.stat(org_fname).st_size!=org_fsize: + raise IOError("Wrong restart file size") + + new_header = libcgyrorestart.CGyroRestartHeader() + new_header.load(org_dir) # keep the same format as the old one + # Update the relevant dims + new_header.grid = new_grid + # nt_loc may not be compatible with new n_toroidal, just set to 1 to be safe + new_header.fmt.nt_loc = 1 + # invalidate optional info, to maintain consistency + new_header.reset_info() + new_fsize = new_header.get_total_bytes() + with open(org_fname,"rb") as org_fd: + with open(new_fname,"wb") as new_fd: + new_fd.truncate(new_fsize) + new_header.savev3(new_fd) + + for i_t in range(new_grid.n_toroidal): + j_t = min(i_t, org_grid.n_toroidal-1) # will extend last element past the limit + for i_e in range(new_grid.n_energy): + for i_x in range(new_grid.n_xi): + for i_s in range(new_grid.n_species): + for i_r in range(new_grid.n_radial): + new_off = new_header.theta_offset(i_r, + i_s, i_x, i_e, + i_t) + new_fd.seek(header_size+new_off) + if i_r