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

Commit

Permalink
update the Hill's sphere when taking snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Jan 30, 2023
1 parent 4c8c7c1 commit af9be87
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
19 changes: 16 additions & 3 deletions python/swiftest/swiftest/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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".
Expand All @@ -103,6 +102,7 @@ def bool2tf(boolval):
else:
return "F"


def str2bool(input_str):
"""
Converts a string into an equivalent boolean.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -898,6 +902,7 @@ def string_converter(da):

return da


def char_converter(da):
"""`
Converts a string to a unicode string
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2999,5 +2999,3 @@ def clean(self):
os.remove(f)
return



3 changes: 0 additions & 3 deletions python/swiftest/swiftest/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions python/swiftest/swiftest/visualize.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions src/fraggle/fraggle_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/swiftest/swiftest_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit af9be87

Please sign in to comment.