Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Started the process of converting Python code to the SPACE DIMENSION.…
Browse files Browse the repository at this point in the history
… Still a ways to go.
  • Loading branch information
daminton committed Dec 3, 2022
1 parent 0131789 commit 2afdbec
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 71 deletions.
7 changes: 5 additions & 2 deletions python/swiftest/swiftest/init_cond.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def solar_system_horizons(plname: str,
v4 = pldata[plname].vectors()['vx'][0] * VCONV
v5 = pldata[plname].vectors()['vy'][0] * VCONV
v6 = pldata[plname].vectors()['vz'][0] * VCONV

rh = pldata[plname].vectors()[['x','y','z']][0] * DCONV
vh = pldata[plname].vectors()[['vx','vy','vz']][0] * VCONV
elif param['IN_FORM'] == 'EL':
v1 = pldata[plname].elements()['a'][0] * DCONV
v2 = pldata[plname].elements()['e'][0]
Expand Down Expand Up @@ -276,13 +279,13 @@ def vec2xr(param: Dict,
namevals :
v1 : array of floats
xh
rh
v2 : array of floats
yh
v3 : array of floats
zh
v4 : array of floats
vhxh
vhrh
v5 : array of floats
vhyh
v6 : array of floats
Expand Down
54 changes: 27 additions & 27 deletions python/swiftest/swiftest/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,9 @@ def swifter_stream(f, param):

tlab = []
if param['OUT_FORM'] == 'XV' or param['OUT_FORM'] == 'XVEL':
tlab.append('xhx')
tlab.append('xhy')
tlab.append('xhz')
tlab.append('rhx')
tlab.append('rhy')
tlab.append('rhz')
tlab.append('vhx')
tlab.append('vhy')
tlab.append('vhz')
Expand Down Expand Up @@ -577,9 +577,9 @@ def make_swiftest_labels(param):
"""
tlab = []
if param['OUT_FORM'] == 'XV' or param['OUT_FORM'] == 'XVEL':
tlab.append('xhx')
tlab.append('xhy')
tlab.append('xhz')
tlab.append('rhx')
tlab.append('rhy')
tlab.append('rhz')
tlab.append('vhx')
tlab.append('vhy')
tlab.append('vhz')
Expand Down Expand Up @@ -619,16 +619,16 @@ def make_swiftest_labels(param):

infolab_float = [
"origin_time",
"origin_xhx",
"origin_xhy",
"origin_xhz",
"origin_rhx",
"origin_rhy",
"origin_rhz",
"origin_vhx",
"origin_vhy",
"origin_vhz",
"discard_time",
"discard_xhx",
"discard_xhy",
"discard_xhz",
"discard_rhx",
"discard_rhy",
"discard_rhz",
"discard_vhx",
"discard_vhy",
"discard_vhz",
Expand Down Expand Up @@ -1013,7 +1013,7 @@ def swiftest_particle_stream(f):
ID of massive bodie
origin_type : string
The origin type for the body (Initial conditions, disruption, supercatastrophic, hit and run, etc)
origin_xh : float array
origin_rh : float array
The origin heliocentric position vector
origin_vh : float array
The origin heliocentric velocity vector
Expand Down Expand Up @@ -1043,7 +1043,7 @@ def swiftest_particle_2xr(param):
-------
infoxr : xarray dataset
"""
veclab = ['time_origin', 'xhx_origin', 'py_origin', 'pz_origin', 'vhx_origin', 'vhy_origin', 'vhz_origin']
veclab = ['time_origin', 'rhx_origin', 'py_origin', 'pz_origin', 'vhx_origin', 'vhy_origin', 'vhz_origin']
id_list = []
origin_type_list = []
origin_vec_list = []
Expand Down Expand Up @@ -1100,7 +1100,7 @@ def select_active_from_frame(ds, param, framenum=-1):
# Select only the active particles at this time step
# Remove the inactive particles
if param['OUT_FORM'] == 'XV' or param['OUT_FORM'] == 'XVEL':
iactive = iframe[count_dim].where((~np.isnan(iframe['Gmass'])) | (~np.isnan(iframe['xhx'])), drop=True)[count_dim]
iactive = iframe[count_dim].where((~np.isnan(iframe['Gmass'])) | (~np.isnan(iframe['rhx'])), drop=True)[count_dim]
else:
iactive = iframe[count_dim].where((~np.isnan(iframe['Gmass'])) | (~np.isnan(iframe['a'])), drop = True)[count_dim]
if count_dim == "id":
Expand Down Expand Up @@ -1197,7 +1197,7 @@ def swiftest_xr2infile(ds, param, in_type="NETCDF_DOUBLE", infile_name=None,fram
if param['CHK_CLOSE']:
print(pli['radius'].values[0], file=plfile)
if param['IN_FORM'] == 'XV':
print(pli['xhx'].values[0], pli['xhy'].values[0], pli['xhz'].values[0], file=plfile)
print(pli['rhx'].values[0], pli['rhy'].values[0], pli['rhz'].values[0], file=plfile)
print(pli['vhx'].values[0], pli['vhy'].values[0], pli['vhz'].values[0], file=plfile)
elif param['IN_FORM'] == 'EL':
print(pli['a'].values[0], pli['e'].values[0], pli['inc'].values[0], file=plfile)
Expand All @@ -1216,7 +1216,7 @@ def swiftest_xr2infile(ds, param, in_type="NETCDF_DOUBLE", infile_name=None,fram
tpi = tp.sel(id=i)
print(tpi['name'].values[0], file=tpfile)
if param['IN_FORM'] == 'XV':
print(tpi['xhx'].values[0], tpi['xhy'].values[0], tpi['xhz'].values[0], file=tpfile)
print(tpi['rhx'].values[0], tpi['rhy'].values[0], tpi['rhz'].values[0], file=tpfile)
print(tpi['vhx'].values[0], tpi['vhy'].values[0], tpi['vhz'].values[0], file=tpfile)
elif param['IN_FORM'] == 'EL':
print(tpi['a'].values[0], tpi['e'].values[0], tpi['inc'].values[0], file=tpfile)
Expand Down Expand Up @@ -1280,7 +1280,7 @@ def swifter_xr2infile(ds, param, framenum=-1):
print(i.values, pli['Gmass'].values, file=plfile)
if param['CHK_CLOSE']:
print(pli['radius'].values, file=plfile)
print(pli['xhx'].values, pli['xhy'].values, pli['xhz'].values, file=plfile)
print(pli['rhx'].values, pli['rhy'].values, pli['rhz'].values, file=plfile)
print(pli['vhx'].values, pli['vhy'].values, pli['vhz'].values, file=plfile)
plfile.close()

Expand All @@ -1290,7 +1290,7 @@ def swifter_xr2infile(ds, param, framenum=-1):
for i in tp.id:
tpi = tp.sel(id=i)
print(i.values, file=tpfile)
print(tpi['xhx'].values, tpi['xhy'].values, tpi['xhz'].values, file=tpfile)
print(tpi['rhx'].values, tpi['rhy'].values, tpi['rhz'].values, file=tpfile)
print(tpi['vhx'].values, tpi['vhy'].values, tpi['vhz'].values, file=tpfile)
tpfile.close()
else:
Expand Down Expand Up @@ -1461,10 +1461,10 @@ def swift2swifter(swift_param, plname="", tpname="", conversion_questions={}):
print(plrad, file=plnew)
line = plold.readline()
i_list = [i for i in re.split(' +|\t',line) if i.strip()]
xh = real2float(i_list[0])
rh = real2float(i_list[0])
yh = real2float(i_list[1])
zh = real2float(i_list[2])
print(xh, yh, zh, file=plnew)
print(rh, yh, zh, file=plnew)
line = plold.readline()
i_list = [i for i in re.split(' +|\t',line) if i.strip()]
vhx = real2float(i_list[0])
Expand Down Expand Up @@ -1500,10 +1500,10 @@ def swift2swifter(swift_param, plname="", tpname="", conversion_questions={}):
print(npl + n + 1, file=tpnew)
line = tpold.readline()
i_list = [i for i in re.split(' +|\t',line) if i.strip()]
xh = real2float(i_list[0])
rh = real2float(i_list[0])
yh = real2float(i_list[1])
zh = real2float(i_list[2])
print(xh, yh, zh, file=tpnew)
print(rh, yh, zh, file=tpnew)
line = tpold.readline()
i_list = [i for i in re.split(' +|\t',line) if i.strip()]
vhx = real2float(i_list[0])
Expand Down Expand Up @@ -1589,10 +1589,10 @@ def swifter2swiftest(swifter_param, plname="", tpname="", cbname="", conversion_
print(plrad, file=plnew)
line = plold.readline()
i_list = [i for i in re.split(' +|\t',line) if i.strip()]
xh = real2float(i_list[0])
rh = real2float(i_list[0])
yh = real2float(i_list[1])
zh = real2float(i_list[2])
print(xh, yh, zh, file=plnew)
print(rh, yh, zh, file=plnew)
line = plold.readline()
i_list = [i for i in re.split(' +|\t',line) if i.strip()]
vhx = real2float(i_list[0])
Expand Down Expand Up @@ -1633,10 +1633,10 @@ def swifter2swiftest(swifter_param, plname="", tpname="", cbname="", conversion_
print(name, file=tpnew)
line = tpold.readline()
i_list = [i for i in re.split(' +|\t',line) if i.strip()]
xh = real2float(i_list[0])
rh = real2float(i_list[0])
yh = real2float(i_list[1])
zh = real2float(i_list[2])
print(xh, yh, zh, file=tpnew)
print(rh, yh, zh, file=tpnew)
line = tpold.readline()
i_list = [i for i in re.split(' +|\t',line) if i.strip()]
vhx = real2float(i_list[0])
Expand Down
74 changes: 32 additions & 42 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2273,13 +2273,13 @@ def _get_instance_var(self, arg_list: str | List[str], valid_arg: Dict, verbose:
def add_body(self,
name: str | List[str] | npt.NDArray[np.str_] | None=None,
idvals: int | list[int] | npt.NDArray[np.int_] | None=None,
v1: float | List[float] | npt.NDArray[np.float_] | None = None,
v2: float | List[float] | npt.NDArray[np.float_] | None = None,
v3: float | List[float] | npt.NDArray[np.float_] | None = None,
v4: float | List[float] | npt.NDArray[np.float_] | None = None,
v5: float | List[float] | npt.NDArray[np.float_] | None = None,
v6: float | List[float] | npt.NDArray[np.float_] | None = None,
xh: List[float] | List[npt.NDArray[np.float_]] | npt.NDArray[np.float_] | None = None,
a: float | List[float] | npt.NDArray[np.float_] | None = None,
e: float | List[float] | npt.NDArray[np.float_] | None = None,
inc: float | List[float] | npt.NDArray[np.float_] | None = None,
capom: float | List[float] | npt.NDArray[np.float_] | None = None,
omega: float | List[float] | npt.NDArray[np.float_] | None = None,
capm: float | List[float] | npt.NDArray[np.float_] | None = None,
rh: List[float] | List[npt.NDArray[np.float_]] | npt.NDArray[np.float_] | None = None,
vh: List[float] | List[npt.NDArray[np.float_]] | npt.NDArray[np.float_] | None = None,
mass: float | List[float] | npt.NDArray[np.float_] | None=None,
Gmass: float | List[float] | npt.NDArray[np.float_] | None=None,
Expand Down Expand Up @@ -2308,19 +2308,19 @@ def add_body(self,
idvals : int or array-like of int, optional
Unique id values. If not passed, an id will be assigned in ascending order starting from the pre-existing
Dataset ids.
v1 : float or array-like of float, optional
xhx for param['IN_FORM'] == "XV"; a for param['IN_FORM'] == "EL"
v2 : float or array-like of float, optional
xhy for param['IN_FORM'] == "XV"; e for param['IN_FORM'] == "EL"
v3 : float or array-like of float, optional
xhz for param['IN_FORM'] == "XV"; inc for param['IN_FORM'] == "EL"
v4 : float or array-like of float, optional
vhx for param['IN_FORM'] == "XV"; capom for param['IN_FORM'] == "EL"
v5 : float or array-like of float, optional
vhy for param['IN_FORM'] == "XV"; omega for param['IN_FORM'] == "EL"
v6 : float or array-like of float, optional
vhz for param['IN_FORM'] == "XV"; capm for param['IN_FORM'] == "EL"
xh : (n,3) array-like of float, optional
a : float or array-like of float, optional
semimajor axis for param['IN_FORM'] == "EL"
e : float or array-like of float, optional
eccentricity for param['IN_FORM'] == "EL"
inc : float or array-like of float, optional
inclination for param['IN_FORM'] == "EL"
capom : float or array-like of float, optional
longitude of periapsis for param['IN_FORM'] == "EL"
omega : float or array-like of float, optional
argument of periapsis for param['IN_FORM'] == "EL"
capm : float or array-like of float, optional
mean anomaly for param['IN_FORM'] == "EL"
rh : (n,3) array-like of float, optional
Position vector array. This can be used instead of passing v1, v2, and v3 sepearately for "XV" input format
vh : (n,3) array-like of float, optional
Velocity vector array. This can be used instead of passing v4, v5, and v6 sepearately for "XV" input format
Expand All @@ -2332,10 +2332,6 @@ def add_body(self,
Radius values if these are massive bodies
rhill : float or array-like of float, optional
Hill's radius values if these are massive bodies
Ip<1,2,3> : float or array-like of float, optional
Principal axes moments of inertia if these are massive bodies with rotation enabled
rot<x,y,z>: float or array-like of float, optional
Rotation rate vector components if these are massive bodies with rotation enabled
rot: (3) or (n,3) array-like of float, optional
Rotation rate vectors if these are massive bodies with rotation enabled. This can be used instead of passing
rotx, roty, and rotz separately
Expand Down Expand Up @@ -2404,27 +2400,21 @@ def input_to_array_3d(val,n=None):

nbodies = None
name,nbodies = input_to_array(name,"s",nbodies)
v1,nbodies = input_to_array(v1,"f",nbodies)
v2,nbodies = input_to_array(v2,"f",nbodies)
v3,nbodies = input_to_array(v3,"f",nbodies)
v4,nbodies = input_to_array(v4,"f",nbodies)
v5,nbodies = input_to_array(v5,"f",nbodies)
v6,nbodies = input_to_array(v6,"f",nbodies)
a,nbodies = input_to_array(a,"f",nbodies)
e,nbodies = input_to_array(e,"f",nbodies)
inc,nbodies = input_to_array(inc,"f",nbodies)
capom,nbodies = input_to_array(capm,"f",nbodies)
omega,nbodies = input_to_array(omega,"f",nbodies)
capm,nbodies = input_to_array(capm,"f",nbodies)
idvals,nbodies = input_to_array(idvals,"i",nbodies)
mass,nbodies = input_to_array(mass,"f",nbodies)
Gmass,nbodies = input_to_array(Gmass,"f",nbodies)
rhill,nbodies = input_to_array(rhill,"f",nbodies)
radius,nbodies = input_to_array(radius,"f",nbodies)
Ip1,nbodies = input_to_array(Ip1,"f",nbodies)
Ip2,nbodies = input_to_array(Ip2,"f",nbodies)
Ip3,nbodies = input_to_array(Ip3,"f",nbodies)
rotx,nbodies = input_to_array(rotx,"f",nbodies)
roty,nbodies = input_to_array(roty,"f",nbodies)
rotz,nbodies = input_to_array(rotz,"f",nbodies)
J2,nbodies = input_to_array(J2,"f",nbodies)
J4,nbodies = input_to_array(J4,"f",nbodies)

xh,nbodies = input_to_array_3d(xh,nbodies)
rh,nbodies = input_to_array_3d(rh,nbodies)
vh,nbodies = input_to_array_3d(vh,nbodies)
rot,nbodies = input_to_array_3d(rot,nbodies)
Ip,nbodies = input_to_array_3d(Ip,nbodies)
Expand All @@ -2447,13 +2437,13 @@ def input_to_array_3d(val,n=None):

t = self.param['TSTART']

if xh is not None:
if rh is not None:
if v1 is not None or v2 is not None or v3 is not None:
raise ValueError("Cannot use xh and v1,v2,v3 inputs simultaneously!")
raise ValueError("Cannot use rh and v1,v2,v3 inputs simultaneously!")
else:
v1 = xh.T[0]
v2 = xh.T[1]
v3 = xh.T[2]
v1 = rh.T[0]
v2 = rh.T[1]
v3 = rh.T[2]

if vh is not None:
if v4 is not None or v5 is not None or v6 is not None:
Expand Down

0 comments on commit 2afdbec

Please sign in to comment.