From 7eae81ce5cf7087bdc8209466861522bf2729099 Mon Sep 17 00:00:00 2001 From: anand43 Date: Sat, 10 Feb 2024 17:23:33 -0500 Subject: [PATCH] fixed netcdf start+count error for rotphase; added rotphase to sim.add_body --- src/swiftest/swiftest_io.f90 | 4 ++-- swiftest/init_cond.py | 9 +++++++-- swiftest/simulation_class.py | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 70f57aebd..efc0a3791 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -1529,9 +1529,9 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier ! rotphase may not be input by the user status = nf90_inq_varid(nc%id, nc%rotphase_varname, nc%rotphase_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%rotphase_varid, rtemp, start=[tslot]), & + call netcdf_io_check( nf90_get_var(nc%id, nc%rotphase_varid, cb%rotphase, start=[tslot]), & "netcdf_io_read_frame_system nf90_getvar rotphase_varid" ) - cb%rotphase = rtemp(1) * DEG2RAD + cb%rotphase = cb%rotphase * DEG2RAD else cb%rotphase = 0.0_DP end if diff --git a/swiftest/init_cond.py b/swiftest/init_cond.py index a4c89a90e..8f132073d 100644 --- a/swiftest/init_cond.py +++ b/swiftest/init_cond.py @@ -459,6 +459,9 @@ def vec2xr(param: Dict, **kwargs: Any): Time at start of simulation c_lm : (2, lmax + 1, lmax + 1) array of floats, optional Spherical Harmonics coefficients; lmax = max spherical harmonics order + rotphase : float + rotational phase angle of the central body in degrees + Returns ------- ds : xarray dataset @@ -470,9 +473,9 @@ def vec2xr(param: Dict, **kwargs: Any): sph_dims = ['sign', 'l', 'm'] # Spherical Harmonics dimensions vector_vars = ["rh","vh","Ip","rot"] - scalar_vars = ["name","a","e","inc","capom","omega","capm","Gmass","radius","rhill","j2rp2","j4rp4"] + scalar_vars = ["name","a","e","inc","capom","omega","capm","Gmass","radius","rhill","j2rp2","j4rp4", "rotphase"] sph_vars = ["c_lm"] - time_vars = ["rh","vh","Ip","rot","a","e","inc","capom","omega","capm","Gmass","radius","rhill","j2rp2","j4rp4"] + time_vars = ["rh","vh","Ip","rot","a","e","inc","capom","omega","capm","Gmass","radius","rhill","j2rp2","j4rp4", "rotphase"] # Check for valid keyword arguments kwargs = {k:kwargs[k] for k,v in kwargs.items() if v is not None} @@ -482,6 +485,8 @@ def vec2xr(param: Dict, **kwargs: Any): kwargs['rot'] = np.zeros((len(kwargs['Gmass']),3)) if "Ip" not in kwargs and "Gmass" in kwargs: kwargs['Ip'] = np.full((len(kwargs['Gmass']),3), 0.4) + if "rotphase" not in kwargs: + kwargs['rotphase'] = 0.0 if "time" not in kwargs: kwargs["time"] = np.array([0.0]) diff --git a/swiftest/simulation_class.py b/swiftest/simulation_class.py index 0511f0a50..3075f1609 100644 --- a/swiftest/simulation_class.py +++ b/swiftest/simulation_class.py @@ -2601,7 +2601,7 @@ def input_to_clm_array(val, n): Gmass = self.GU * mass dsnew = init_cond.vec2xr(self.param, name=name, a=a, e=e, inc=inc, capom=capom, omega=omega, capm=capm, id=id, - Gmass=Gmass, radius=radius, rhill=rhill, Ip=Ip, rh=rh, vh=vh,rot=rot, j2rp2=J2, j4rp4=J4, c_lm=c_lm, time=time) + Gmass=Gmass, radius=radius, rhill=rhill, Ip=Ip, rh=rh, vh=vh,rot=rot, j2rp2=J2, j4rp4=J4, c_lm=c_lm, rotphase=rotphase, time=time) dsnew = self._combine_and_fix_dsnew(dsnew) self.save(verbose=False)