diff --git a/python/swiftest/swiftest/io.py b/python/swiftest/swiftest/io.py index 0f9941066..98e6c154a 100644 --- a/python/swiftest/swiftest/io.py +++ b/python/swiftest/swiftest/io.py @@ -34,8 +34,6 @@ "DUMP_CADENCE", "ENCOUNTER_SAVE") - - # This list defines features that are booleans, so must be converted to/from string when writing/reading from file bool_param = ["RESTART", "CHK_CLOSE", @@ -83,7 +81,8 @@ def bool2yesno(boolval): return "YES" else: return "NO" - + + def bool2tf(boolval): """ Converts a boolean into a string of either "T" or "F". @@ -103,6 +102,7 @@ def bool2tf(boolval): else: return "F" + def str2bool(input_str): """ Converts a string into an equivalent boolean. @@ -801,6 +801,7 @@ def swifter2xr(param, verbose=True): if verbose: print(f"Successfully converted {ds.sizes['time']} output frames.") return ds + def process_netcdf_input(ds, param): """ Performs several tasks to convert raw NetCDF files output by the Fortran program into a form that @@ -823,6 +824,7 @@ def process_netcdf_input(ds, param): return ds + def swiftest2xr(param, verbose=True): """ Converts a Swiftest binary data file into an xarray DataSet. @@ -849,6 +851,7 @@ def swiftest2xr(param, verbose=True): return ds + def xstrip_nonstr(a): """ Cleans up the string values in the DataSet to remove extra white space @@ -864,6 +867,7 @@ def xstrip_nonstr(a): func = lambda x: np.char.strip(x) return xr.apply_ufunc(func, a.str.decode(encoding='utf-8'),dask='parallelized') + def xstrip_str(a): """ Cleans up the string values in the DataSet to remove extra white space @@ -898,6 +902,7 @@ def string_converter(da): return da + def char_converter(da): """` Converts a string to a unicode string @@ -916,6 +921,7 @@ def char_converter(da): da = xstrip_nonstr(da) return da + def clean_string_values(ds): """ Cleans up the string values in the DataSet that have artifacts as a result of coming from NetCDF Fortran @@ -963,6 +969,7 @@ def unclean_string_values(ds): ds[c] = n.str.ljust(1).str.encode('utf-8') return ds + def fix_types(ds,itype=np.int64,ftype=np.float64): ds = clean_string_values(ds) @@ -1054,6 +1061,7 @@ def swiftest_particle_2xr(param): return infoxr + def select_active_from_frame(ds, param, framenum=-1): """ Selects a particular frame from a DataSet and returns only the active particles in that frame @@ -1096,6 +1104,7 @@ def select_active_from_frame(ds, param, framenum=-1): return frame + def swiftest_xr2infile(ds, param, in_type="NETCDF_DOUBLE", infile_name=None,framenum=-1,verbose=True): """ Writes a set of Swiftest input files from a single frame of a Swiftest xarray dataset @@ -1281,6 +1290,7 @@ def swifter_xr2infile(ds, param, framenum=-1): return + def swift2swifter(swift_param, plname="", tpname="", conversion_questions={}): """ Converts from a Swift run to a Swifter run @@ -1501,6 +1511,7 @@ def swift2swifter(swift_param, plname="", tpname="", conversion_questions={}): return swifter_param + def swifter2swiftest(swifter_param, plname="", tpname="", cbname="", conversion_questions={}): """ Converts from a Swifter run to a Swiftest run @@ -1753,6 +1764,7 @@ def swifter2swiftest(swifter_param, plname="", tpname="", cbname="", conversion_ swiftest_param['! VERSION'] = "Swiftest parameter file converted from Swifter" return swiftest_param + def swift2swiftest(swift_param, plname="", tpname="", cbname="", conversion_questions={}): """ Converts from a Swift run to a Swiftest run @@ -1798,6 +1810,7 @@ def swift2swiftest(swift_param, plname="", tpname="", cbname="", conversion_ques swiftest_param['! VERSION'] = "Swiftest parameter file converted from Swift" return swiftest_param + def swiftest2swifter_param(swiftest_param, J2=0.0, J4=0.0): """ Converts from a Swiftest run to a Swifter run diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 82fd6e70a..6e80909c4 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -2999,5 +2999,3 @@ def clean(self): os.remove(f) return - - diff --git a/python/swiftest/swiftest/tool.py b/python/swiftest/swiftest/tool.py index 1b53b2c7a..7fe2c8884 100644 --- a/python/swiftest/swiftest/tool.py +++ b/python/swiftest/swiftest/tool.py @@ -9,10 +9,7 @@ If not, see: https://www.gnu.org/licenses. """ -import swiftest import numpy as np -import os -import glob import xarray as xr """ Functions that recreate the Swift/Swifter tool programs diff --git a/python/swiftest/swiftest/visualize.py b/python/swiftest/swiftest/visualize.py new file mode 100644 index 000000000..bf095fc2f --- /dev/null +++ b/python/swiftest/swiftest/visualize.py @@ -0,0 +1,42 @@ +""" + Copyright 2023 - David Minton, + This file is part of Swiftest. + Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with Swiftest. + If not, see: https://www.gnu.org/licenses. +""" +import matplotlib.pyplot as plt +import numpy as np +import xarray as xr + +def _square_plot(): + figsize = (4,4) + fig = plt.figure(figsize=figsize, dpi=300) + plt.tight_layout(pad=0) + + ax = plt.Axes(fig, [0.1, 0.1, 0.8, 0.8]) + ax.set_xticks([]) + ax.set_yticks([]) + ax.set_aspect('equal') + fig.add_axes(ax) + return fig, ax + +def select_one_collision(collisions, collision_id): + ds = collisions.sel(collision_id=collision_id) + bgood = ds.sel(stage='before')['name'].where(ds.sel(stage='before')['particle_type'] != 'nan',drop=True) + agood = ds.sel(stage='after')['name'].where(ds.sel(stage='after')['particle_type'] != 'nan',drop=True) + goodname=np.unique(np.concatenate((bgood,agood))) + ds = ds.sel(name=goodname) + + return ds + +def collisions(collisions, collision_id): + fig, ax = _square_plot() + + ds = select_one_collision(collisions, collision_id) + + + return \ No newline at end of file diff --git a/src/fraggle/fraggle_module.f90 b/src/fraggle/fraggle_module.f90 index 27c2e2b74..333bfdfe6 100644 --- a/src/fraggle/fraggle_module.f90 +++ b/src/fraggle/fraggle_module.f90 @@ -16,18 +16,18 @@ module fraggle public type, extends(collision_basic) :: collision_fraggle - real(DP) :: fail_scale !! Scale factor to apply to distance values in the position model when overlaps occur. + real(DP) :: fail_scale !! Scale factor to apply to distance values in the position model when overlaps occur. contains - procedure :: disrupt => fraggle_generate_disrupt !! Generates a system of fragments in barycentric coordinates that conserves energy and momentum. - procedure :: generate => fraggle_generate !! A simple disruption models that does not constrain energy loss in collisions - procedure :: hitandrun => fraggle_generate_hitandrun !! Generates either a pure hit and run, or one in which the runner is disrupted - procedure :: set_mass_dist => fraggle_util_set_mass_dist !! Sets the distribution of mass among the fragments depending on the regime type + procedure :: disrupt => fraggle_generate_disrupt !! Generates a system of fragments in barycentric coordinates that conserves energy and momentum. + procedure :: generate => fraggle_generate !! A simple disruption models that does not constrain energy loss in collisions + procedure :: hitandrun => fraggle_generate_hitandrun !! Generates either a pure hit and run, or one in which the runner is disrupted + procedure :: set_mass_dist => fraggle_util_set_mass_dist !! Sets the distribution of mass among the fragments depending on the regime type end type collision_fraggle interface module subroutine fraggle_generate(self, nbody_system, param, t) implicit none - class(collision_fraggle), intent(inout) :: self !! Fraggle fragment system object + class(collision_fraggle), intent(inout) :: self !! Fraggle fragment system object class(base_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object class(base_parameters), intent(inout) :: param !! Current run configuration parameters real(DP), intent(in) :: t !! The time of the collision diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index 1c7a40cb1..ba2ffe774 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -3054,6 +3054,8 @@ module subroutine swiftest_util_snapshot_system(self, param, nbody_system, t, ar end select end select + call nbody_system%pl%set_rhill(nbody_system%cb) + ! Take a minimal snapshot wihout all of the extra storage objects allocate(snapshot, mold=nbody_system) allocate(snapshot%cb, source=nbody_system%cb )