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

Commit

Permalink
I decided that changing param.in to config.in was silly. It's best to…
Browse files Browse the repository at this point in the history
… keep changes like this to a minimum. So I refactored everything back to maintain consistency with earlier version of the codebase
  • Loading branch information
daminton committed Jun 24, 2021
1 parent 6658513 commit a993807
Show file tree
Hide file tree
Showing 69 changed files with 894 additions and 894 deletions.
4 changes: 2 additions & 2 deletions Makefile.Defines
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ GPAR = -fopenmp -ftree-parallelize-loops=4
GMEM = -fsanitize=undefined -fsanitize=address -fsanitize=leak
GWARNINGS = -Wall -Warray-bounds -Wimplicit-interface -Wextra -Warray-temporaries

#FFLAGS = $(IDEBUG) $(HEAPARR)
FFLAGS = -init=snan,arrays -no-wrap-margin -fp-model strict -fp-model no-except -traceback -g $(OPTIMIZE) -O3 $(SIMDVEC) $(PAR) $(HEAPARR)
FFLAGS = $(IDEBUG) $(HEAPARR)
#FFLAGS = -init=snan,arrays -no-wrap-margin -fp-model strict -fp-model no-except -traceback -g $(OPTIMIZE) -O3 $(SIMDVEC) $(PAR) $(HEAPARR)
FORTRAN = ifort
#AR = xiar

Expand Down
Empty file.
2 changes: 1 addition & 1 deletion examples/rmvs_gr_test/init_cond.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
swifter_bin = "bin.swifter.dat"
swifter_enc = "enc.swifter.dat"

swiftest_input = "config.swiftest.in"
swiftest_input = "param.swiftest.in"
swiftest_pl = "pl.swiftest.in"
swiftest_tp = "tp.swiftest.in"
swiftest_cb = "cb.swiftest.in"
Expand Down
4 changes: 2 additions & 2 deletions examples/rmvs_gr_test/particle_distance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file config.swiftest.in\n"
"Reading Swiftest file param.swiftest.in\n"
]
}
],
"source": [
"inparfile = \"config.swiftest.in\"\n",
"inparfile = \"param.swiftest.in\"\n",
"paramfile = swio.read_swiftest_config(inparfile)\n",
"swiftestdat = swio.swiftest2xr(paramfile)"
]
Expand Down
6 changes: 3 additions & 3 deletions examples/rmvs_gr_test/swiftest_relativity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file config.gr.in\n"
"Reading Swiftest file param.gr.in\n"
]
}
],
"source": [
"config_file_name = 'config.gr.in'\n",
"config = swio.read_swiftest_config(config_file_name)\n",
"param_file_name = 'param.gr.in'\n",
"config = swio.read_swiftest_config(param_file_name)\n",
"swiftestdat = swio.swiftest2xr(config)"
]
},
Expand Down
6 changes: 3 additions & 3 deletions examples/rmvs_gr_test/swifttest_rmvs_vs_swifter_rmvs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file config.swiftest.in\n"
"Reading Swiftest file param.swiftest.in\n"
]
}
],
"source": [
"config_file_name = 'config.swiftest.in'\n",
"config = swio.read_swiftest_config(config_file_name)\n",
"param_file_name = 'param.swiftest.in'\n",
"config = swio.read_swiftest_config(param_file_name)\n",
"swiftestdat = swio.swiftest2xr(config)"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file config.swiftest.in\n"
"Reading Swiftest file param.swiftest.in\n"
]
}
],
"source": [
"config_file_name = 'config.swiftest.in'\n",
"config = swio.read_swiftest_config(config_file_name)\n",
"param_file_name = 'param.swiftest.in'\n",
"config = swio.read_swiftest_config(param_file_name)\n",
"swiftestdat = swio.swiftest2xr(config)"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
swifter_bin = "bin.swifter.dat"
swifter_enc = "enc.swifter.dat"

swiftest_input = "config.swiftest.in"
swiftest_input = "param.swiftest.in"
swiftest_pl = "pl.swiftest.in"
swiftest_tp = "tp.swiftest.in"
swiftest_cb = "cb.swiftest.in"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file config.swiftest.in\n"
"Reading Swiftest file param.swiftest.in\n"
]
}
],
"source": [
"config_file_name = 'config.swiftest.in'\n",
"config = swio.read_swiftest_config(config_file_name)\n",
"param_file_name = 'param.swiftest.in'\n",
"config = swio.read_swiftest_config(param_file_name)\n",
"swiftestdat = swio.swiftest2xr(config)"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
import xarray as xr

# Swiftest configuration file
# Swiftest paramuration file
# Both codes use the same tp input file
tpin = "tp.in"

Expand All @@ -17,7 +17,7 @@
swifter_bin = "bin.swifter.dat"
swifter_enc = "enc.swifter.dat"

swiftest_input = "config.swiftest.in"
swiftest_input = "param.swiftest.in"
swiftest_pl = "pl.swiftest.in"
swiftest_cb = "cb.swiftest.in"
swiftest_bin = "bin.swiftest.dat"
Expand Down Expand Up @@ -83,14 +83,14 @@
print(f'DU2M {DU2M}')
print(f'TU2S {TU2S}')
sys.stdout = sys.__stdout__
config = swio.read_swiftest_config(swiftest_input)
ds = swio.solar_system_pl(config, tstart)
param = swio.read_swiftest_param(swiftest_input)
ds = swio.solar_system_pl(param, tstart)

ntp = 18
dims = ['time', 'id', 'vec']
tp = []
t = np.array([0.0])
clab, plab, tlab = swio.make_swiftest_labels(config)
clab, plab, tlab = swio.make_swiftest_labels(param)

# For each planet, we will initialize a pair of test particles. One on its way in, and one on its way out. We will also initialize two additional particles that don't encounter anything
tpnames = np.arange(101, 101 + ntp)
Expand Down Expand Up @@ -142,7 +142,7 @@
tpds = tpda.to_dataset(dim = 'vec')

ds = xr.combine_by_coords([ds, tpds])
swio.swiftest_xr2_infile(ds, config)
swio.swiftest_xr2_infile(ds, param)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file config.swiftest.in\n"
"Reading Swiftest file param.swiftest.in\n"
]
}
],
"source": [
"config_file_name = 'config.swiftest.in'\n",
"config = swio.read_swiftest_config(config_file_name)\n",
"param_file_name = 'param.swiftest.in'\n",
"config = swio.read_swiftest_config(param_file_name)\n",
"swiftestdat = swio.swiftest2xr(config)"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file config.swiftest.in\n"
"Reading Swiftest file param.swiftest.in\n"
]
}
],
"source": [
"config_file_name = 'config.swiftest.in'\n",
"config = swio.read_swiftest_config(config_file_name)\n",
"param_file_name = 'param.swiftest.in'\n",
"config = swio.read_swiftest_config(param_file_name)\n",
"swiftestdat = swio.swiftest2xr(config)"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/whm_gr_test/init_cond.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
swifter_bin = "bin.swifter.dat"
swifter_enc = "enc.swifter.dat"

swiftest_input = "config.swiftest.in"
swiftest_input = "param.swiftest.in"
swiftest_pl = "pl.swiftest.in"
swiftest_tp = "tp.swiftest.in"
swiftest_cb = "cb.swiftest.in"
Expand Down
6 changes: 3 additions & 3 deletions examples/whm_gr_test/swiftest_relativity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file config.swiftest.in\n"
"Reading Swiftest file param.swiftest.in\n"
]
}
],
"source": [
"config_file_name = 'config.swiftest.in'\n",
"config = swio.read_swiftest_config(config_file_name)\n",
"param_file_name = 'param.swiftest.in'\n",
"config = swio.read_swiftest_config(param_file_name)\n",
"swiftestdat = swio.swiftest2xr(config)"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/whm_swifter_comparison/init_cond.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
swifter_bin = "bin.swifter.dat"
swifter_enc = "enc.swifter.dat"

swiftest_input = "config.swiftest.in"
swiftest_input = "param.swiftest.in"
swiftest_pl = "pl.swiftest.in"
swiftest_tp = "tp.swiftest.in"
swiftest_cb = "cb.swiftest.in"
Expand Down
6 changes: 3 additions & 3 deletions examples/whm_swifter_comparison/whm_swiftest_vs_swifter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file config.swiftest.in\n"
"Reading Swiftest file param.swiftest.in\n"
]
}
],
"source": [
"config_file_name = 'config.swiftest.in'\n",
"config = swio.read_swiftest_config(config_file_name)\n",
"param_file_name = 'param.swiftest.in'\n",
"config = swio.read_swiftest_config(param_file_name)\n",
"swiftestdat = swio.swiftest2xr(config)"
]
},
Expand Down
Empty file added param.restart.in
Empty file.
80 changes: 40 additions & 40 deletions python/swifter2swiftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,61 @@
"""
G = 6.6743E-11 # Universal gravitational constant in SI units

def read_config(config):
def read_param(param):
# Read and parse old Swifter parameter file
swifterfile = config['swifterfile']
swiftestfile = config['swiftestfile']
swifterfile = param['swifterfile']
swiftestfile = param['swiftestfile']

# Read config.in file
print('Reading Swifter file ' + config['swifterfile'])
# Read param.in file
print('Reading Swifter file ' + param['swifterfile'])
fold = open(swifterfile, 'r')
swifterlines = fold.readlines()
fold.close()
for line in swifterlines:
fields = line.split()
if len(fields) > 0:
if ('PL_IN' == fields[0].upper()): config['PL_OLD'] = fields[1]
if ('TP_IN' == fields[0].upper()): config['TP_OLD'] = fields[1]
if ('CHK_CLOSE' == fields[0].upper()): config['CHK_CLOSE'] = fields[1].upper()
if ('RHILL_PRESENT'== fields[0].upper()): config['RHILL_PRESENT'] = fields[1].upper()
if ('J2' == fields[0].upper()): config['J2'] = float(fields[1])
if ('J4' == fields[0].upper()): config['J4'] = float(fields[1])

print('Reading Swiftest file ' + config['swiftestfile'])
if ('PL_IN' == fields[0].upper()): param['PL_OLD'] = fields[1]
if ('TP_IN' == fields[0].upper()): param['TP_OLD'] = fields[1]
if ('CHK_CLOSE' == fields[0].upper()): param['CHK_CLOSE'] = fields[1].upper()
if ('RHILL_PRESENT'== fields[0].upper()): param['RHILL_PRESENT'] = fields[1].upper()
if ('J2' == fields[0].upper()): param['J2'] = float(fields[1])
if ('J4' == fields[0].upper()): param['J4'] = float(fields[1])

print('Reading Swiftest file ' + param['swiftestfile'])
fnew = open(swiftestfile, 'r')
swiftestlines = fnew.readlines()
for line in swiftestlines:
fields = line.split()
if len(fields) > 0:
if ('MU2KG' == fields[0].upper()): config['MU2KG'] = float(fields[1])
if ('DU2M' == fields[0].upper()): config['DU2M'] = float(fields[1])
if ('TU2S' == fields[0].upper()): config['TU2S'] = float(fields[1])
if ('CB_IN' == fields[0].upper()): config['CB_NEW'] = fields[1]
if ('PL_IN' == fields[0].upper()): config['PL_NEW'] = fields[1]
if ('TP_IN' == fields[0].upper()): config['TP_NEW'] = fields[1]
if ('CHK_CLOSE' == fields[0].upper()): config['CHK_CLOSE_NEW'] = fields[1].upper()
if ('MU2KG' == fields[0].upper()): param['MU2KG'] = float(fields[1])
if ('DU2M' == fields[0].upper()): param['DU2M'] = float(fields[1])
if ('TU2S' == fields[0].upper()): param['TU2S'] = float(fields[1])
if ('CB_IN' == fields[0].upper()): param['CB_NEW'] = fields[1]
if ('PL_IN' == fields[0].upper()): param['PL_NEW'] = fields[1]
if ('TP_IN' == fields[0].upper()): param['TP_NEW'] = fields[1]
if ('CHK_CLOSE' == fields[0].upper()): param['CHK_CLOSE_NEW'] = fields[1].upper()

if __name__ == '__main__':

config = {'swifterfile' : "param.in",
'swiftestfile': "config.in"}
param = {'swifterfile' : "param.in",
'swiftestfile': "param.in"}

read_config(config)
MU2KG = config['MU2KG']
DU2M = config['DU2M']
TU2S = config['TU2S']
read_param(param)
MU2KG = param['MU2KG']
DU2M = param['DU2M']
TU2S = param['TU2S']

for key, val in config.items():
for key, val in param.items():
print(key, val)

GU = G / (DU2M ** 3 / (MU2KG * TU2S ** 2))

cbrad = 6.95700e8 / DU2M

plnew = open(config['PL_NEW'], 'w')
print(f'Writing out new PL file: {config["PL_NEW"]}')
plnew = open(param['PL_NEW'], 'w')
print(f'Writing out new PL file: {param["PL_NEW"]}')

with open(config['PL_OLD'], 'r') as plold:
with open(param['PL_OLD'], 'r') as plold:
line = plold.readline()
line = line.split("!")[0] # Ignore comments
i_list = [i for i in line.split(" ") if i.strip()]
Expand All @@ -81,7 +81,7 @@ def read_config(config):
GMpl = float(i_list[1])
#print(f'{name} {GMpl} -> {GMpl / GU}')
print(name, GMpl,file=plnew)
if config['CHK_CLOSE'] == 'YES':
if param['CHK_CLOSE'] == 'YES':
line = plold.readline()
i_list = [i for i in line.split(" ") if i.strip()]
plrad = float(i_list[0])
Expand All @@ -104,10 +104,10 @@ def read_config(config):

plold.close()
plnew.close()
tpnew = open(config['TP_NEW'], 'w')
tpnew = open(param['TP_NEW'], 'w')

print(f'Writing out new TP file: {config["TP_NEW"]}')
with open(config['TP_OLD'], 'r') as tpold:
print(f'Writing out new TP file: {param["TP_NEW"]}')
with open(param['TP_OLD'], 'r') as tpold:
line = tpold.readline()
line = line.split("!")[0] # Ignore comments
i_list = [i for i in line.split(" ") if i.strip()]
Expand Down Expand Up @@ -138,18 +138,18 @@ def read_config(config):
tpold.close()
tpnew.close()

print(f'Writing out new CB file: {config["CB_NEW"]}')
print(f'Writing out new CB file: {param["CB_NEW"]}')
# Write out new central body file
cbnew = open(config['CB_NEW'], 'w')
cbnew = open(param['CB_NEW'], 'w')

print(f'GMsun = {GMsun} -> {GMsun / GU}')
print(GMsun, file=cbnew)
print(cbrad)
print(cbrad, file=cbnew)
print(config['J2'])
print(config['J2'], file=cbnew)
print(config['J4'])
print(config['J4'], file=cbnew)
print(param['J2'])
print(param['J2'], file=cbnew)
print(param['J4'])
print(param['J4'], file=cbnew)

cbnew.close()

Loading

0 comments on commit a993807

Please sign in to comment.