From 7c035a2602e69a7c4c44f06309dcf6c7c3b11d16 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 27 Aug 2021 07:03:37 -0400 Subject: [PATCH] Performed some maintenance on the intial conditions generators and conversion routines to fix issues with the indexing of the central body and when rotation is disabled --- python/swiftest/swiftest/init_cond.py | 4 +++- python/swiftest/swiftest/io.py | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index d058744ba..2b8248ec4 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -119,7 +119,9 @@ def solar_system_horizons(plname, idval, param, ephemerides_start_date, ds): Ipsun = np.array([0.0, 0.0, planetIpz['Sun']]) cbid = np.array([1]) - cvec = np.vstack([GMcb, Rcb, J2RP2, J4RP4, Ipsun[0], Ipsun[1], Ipsun[2], rotcb.x, rotcb.y, rotcb.z ]) + cvec = np.vstack([GMcb, Rcb, J2RP2, J4RP4]) + if param['ROTATION'] == 'YES': + cvec = np.vstack([cvec, Ipsun[0], Ipsun[1], Ipsun[2], rotcb.x, rotcb.y, rotcb.z]) # Horizons date time internal variables tstart = datetime.date.fromisoformat(ephemerides_start_date) diff --git a/python/swiftest/swiftest/io.py b/python/swiftest/swiftest/io.py index 81cfd4c77..0b29bc5d5 100644 --- a/python/swiftest/swiftest/io.py +++ b/python/swiftest/swiftest/io.py @@ -766,8 +766,8 @@ def swiftest_xr2infile(ds, param, framenum=-1): A set of three input files for a Swiftest run """ frame = ds.isel(time=framenum) - cb = frame.where(frame.id == 0, drop=True) - pl = frame.where(frame.id > 0, drop=True) + cb = frame.where(frame.id == 1, drop=True) + pl = frame.where(frame.id > 1, drop=True) pl = pl.where(np.invert(np.isnan(pl['Gmass'])), drop=True).drop_vars(['J_2', 'J_4']) tp = frame.where(np.isnan(frame['Gmass']), drop=True).drop_vars(['Gmass', 'radius', 'J_2', 'J_4']) @@ -775,12 +775,13 @@ def swiftest_xr2infile(ds, param, framenum=-1): RSun = np.double(cb['radius']) J2 = np.double(cb['J_2']) J4 = np.double(cb['J_4']) - Ip1cb = np.double(cb['Ip1']) - Ip2cb = np.double(cb['Ip2']) - Ip3cb = np.double(cb['Ip3']) - rotxcb = np.double(cb['rotx']) - rotycb = np.double(cb['roty']) - rotzcb = np.double(cb['rotz']) + if param['ROTATION'] == 'YES': + Ip1cb = np.double(cb['Ip1']) + Ip2cb = np.double(cb['Ip2']) + Ip3cb = np.double(cb['Ip3']) + rotxcb = np.double(cb['rotx']) + rotycb = np.double(cb['roty']) + rotzcb = np.double(cb['rotz']) cbid = int(0) if param['IN_TYPE'] == 'ASCII': @@ -942,8 +943,8 @@ def swifter_xr2infile(ds, param, framenum=-1): A set of input files for a Swifter run """ frame = ds.isel(time=framenum) - cb = frame.where(frame.id == 0, drop=True) - pl = frame.where(frame.id > 0, drop=True) + cb = frame.where(frame.id == 1, drop=True) + pl = frame.where(frame.id > 1, drop=True) pl = pl.where(np.invert(np.isnan(pl['Gmass'])), drop=True).drop_vars(['J_2', 'J_4']) tp = frame.where(np.isnan(frame['Gmass']), drop=True).drop_vars(['Gmass', 'radius', 'J_2', 'J_4']) @@ -956,7 +957,7 @@ def swifter_xr2infile(ds, param, framenum=-1): # Swiftest Central body file plfile = open(param['PL_IN'], 'w') print(pl.id.count().values + 1, file=plfile) - print(cb.id.values[0], cb['Gmass'].values[0], file=plfile) + print(cb.id.values[0], GMSun, file=plfile) print('0.0 0.0 0.0', file=plfile) print('0.0 0.0 0.0', file=plfile) for i in pl.id: