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

Commit

Permalink
Started to work on making a variety of collision models other than Fr…
Browse files Browse the repository at this point in the history
…aggle
  • Loading branch information
daminton committed Dec 21, 2022
1 parent 8516873 commit c65211d
Show file tree
Hide file tree
Showing 12 changed files with 333 additions and 158 deletions.
2 changes: 1 addition & 1 deletion examples/Fragmentation/Fragmentation_Movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def data_stream(self, frame=0):
# Set fragmentation parameters
minimum_fragment_gmass = 0.2 * body_Gmass[style][1] # Make the minimum fragment mass a fraction of the smallest body
gmtiny = 0.99 * body_Gmass[style][1] # Make GMTINY just smaller than the smallest original body. This will prevent runaway collisional cascades
sim.set_parameter(fragmentation=True, encounter_save="both", gmtiny=gmtiny, minimum_fragment_gmass=minimum_fragment_gmass, verbose=False)
sim.set_parameter(collision_model="merge", encounter_save="both", gmtiny=gmtiny, minimum_fragment_gmass=minimum_fragment_gmass, verbose=False)
sim.run(dt=1e-3, tstop=1.0e-3, istep_out=1, dump_cadence=0)

print("Generating animation")
Expand Down
46 changes: 28 additions & 18 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,18 @@ def __init__(self,read_param: bool = False, read_old_output: bool = False, simdi
general_relativity : bool, default True
Include the post-Newtonian correction in acceleration calculations.
Parameter input file equivalent: `GR`
fragmentation : bool, default True
If set to True, this turns on the Fraggle fragment generation code and `rotation` must also be True.
collision_model: {"MERGE","BOUNCE","SIMPLE","FRAGGLE"}, default "MERGE"
This is used to set the collision/fragmentation model. [TODO: DESCRIBE THESE]
This argument only applies to Swiftest-SyMBA simulations. It will be ignored otherwise.
Parameter input file equivalent: `FRAGMENTATION`
Parameter input file equivalent: `COLLISION_MODEL`
minimum_fragment_gmass : float, optional
If fragmentation is turned on, this sets the mimimum G*mass of a collisional fragment that can be generated.
If fragmentation is turned on, this sets the mimimum G*mass of a collisional fragment that can be generated if a
fragmentation model is enabled. Ignored otherwise.
*Note.* Only set one of minimum_fragment_gmass or minimum_fragment_mass
Parameter input file equivalent: None
minimum_fragment_mass : float, optional
If fragmentation is turned on, this sets the mimimum mass of a collisional fragment that can be generated.
If fragmentation is turned on, this sets the mimimum mass of a collisional fragment that can be generated. if a
fragmentation model is enabled. Ignored otherwise
*Note.* Only set one of minimum_fragment_gmass or minimum_fragment_mass
Parameter input file equivalent: `MIN_GMFRAG`
rotation : bool, default False
Expand Down Expand Up @@ -777,7 +779,7 @@ def set_parameter(self, verbose: bool = True, **kwargs):
"mtiny": None,
"close_encounter_check": True,
"general_relativity": True,
"fragmentation": False,
"collision_model": "MERGE",
"minimum_fragment_mass": None,
"minimum_fragment_gmass": 0.0,
"rotation": False,
Expand Down Expand Up @@ -1013,7 +1015,7 @@ def get_integrator(self,arg_list: str | List[str] | None = None, verbose: bool |
def set_feature(self,
close_encounter_check: bool | None = None,
general_relativity: bool | None = None,
fragmentation: bool | None = None,
collision_model: Literal["MERGE","BOUNCE","SIMPLE","FRAGGLE"] | None = None,
minimum_fragment_gmass: float | None = None,
minimum_fragment_mass: float | None = None,
rotation: bool | None = None,
Expand Down Expand Up @@ -1046,15 +1048,20 @@ def set_feature(self,
*WARNING*: Enabling this feature could lead to very large files.
general_relativity : bool, optional
Include the post-Newtonian correction in acceleration calculations.
fragmentation : bool, optional
If set to True, this turns on the Fraggle fragment generation code and `rotation` must also be True.
collision_model: {"MERGE","BOUNCE","SIMPLE","FRAGGLE"}, default "MERGE"
This is used to set the collision/fragmentation model. [TODO: DESCRIBE THESE]
This argument only applies to Swiftest-SyMBA simulations. It will be ignored otherwise.
Parameter input file equivalent: `COLLISION_MODEL`
minimum_fragment_gmass : float, optional
If fragmentation is turned on, this sets the mimimum G*mass of a collisional fragment that can be generated.
If fragmentation is turned on, this sets the mimimum G*mass of a collisional fragment that can be generated if a
fragmentation model is enabled. Ignored otherwise.
*Note.* Only set one of minimum_fragment_gmass or minimum_fragment_mass
Parameter input file equivalent: None
minimum_fragment_mass : float, optional
If fragmentation is turned on, this sets the mimimum mass of a collisional fragment that can be generated.
If fragmentation is turned on, this sets the mimimum mass of a collisional fragment that can be generated. if a
fragmentation model is enabled. Ignored otherwise
*Note.* Only set one of minimum_fragment_gmass or minimum_fragment_mass
Parameter input file equivalent: `MIN_GMFRAG`
rotation : bool, optional
If set to True, this turns on rotation tracking and radius, rotation vector, and moments of inertia values
must be included in the initial conditions.
Expand Down Expand Up @@ -1122,13 +1129,16 @@ def set_feature(self,
self.param["GR"] = general_relativity
update_list.append("general_relativity")

if fragmentation is not None:
fragmentation_models = ["FRAGGLE", "SIMPLE"]
if collision_model is not None:
collision_model = collision_model.upper()
fragmentation = collision_model in fragmentation_models
if self.codename != "Swiftest" and self.integrator != "symba" and fragmentation:
warnings.warn("Fragmentation is only available on Swiftest SyMBA.",stacklevel=2)
self.param['FRAGMENTATION'] = False
self.param['COLLISION_MODEL'] = "MERGE"
else:
self.param['FRAGMENTATION'] = fragmentation
update_list.append("fragmentation")
self.param['COLLISION_MODEL'] = collision_model
update_list.append("collision_model")
if fragmentation:
if "MIN_GMFRAG" not in self.param and minimum_fragment_mass is None and minimum_fragment_gmass is None:
warnings.warn("Minimum fragment mass is not set. Set it using minimum_fragment_gmass or minimum_fragment_mass",stacklevel=2)
Expand All @@ -1151,7 +1161,7 @@ def set_feature(self,
self.param['ROTATION'] = rotation
update_list.append("rotation")

if self.param['FRAGMENTATION'] and not self.param['ROTATION']:
if self.param['COLLISION_MODEL'] == "FRAGGLE" and not self.param['ROTATION']:
self.param['ROTATION'] = True
update_list.append("rotation")

Expand Down Expand Up @@ -1230,7 +1240,7 @@ def get_feature(self, arg_list: str | List[str] | None = None, verbose: bool | N
----------
arg_list: str | List[str], optional
A single string or list of strings containing the names of the features to extract. Default is all of:
["close_encounter_check", "general_relativity", "fragmentation", "rotation", "compute_conservation_values"]
["close_encounter_check", "general_relativity", "collision_model", "rotation", "compute_conservation_values"]
verbose: bool, optional
If passed, it will override the Simulation object's verbose flag
**kwargs
Expand All @@ -1245,7 +1255,7 @@ def get_feature(self, arg_list: str | List[str] | None = None, verbose: bool | N
"""

valid_var = {"close_encounter_check": "CHK_CLOSE",
"fragmentation": "FRAGMENTATION",
"collision_model": "COLLISION_MODEL",
"encounter_save": "ENCOUNTER_SAVE",
"minimum_fragment_gmass": "MIN_GMFRAG",
"rotation": "ROTATION",
Expand Down
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ SET(FAST_MATH_FILES
${SRC}/helio/helio_module.f90
${SRC}/symba/symba_module.f90
${SRC}/collision/collision_check.f90
${SRC}/collision/collision_regime.f90
${SRC}/collision/collision_setup.f90
${SRC}/collision/collision_io.f90
${SRC}/collision/collision_model.f90
${SRC}/collision/collision_regime.f90
${SRC}/collision/collision_resolve.f90
${SRC}/collision/collision_setup.f90
${SRC}/collision/collision_util.f90
${SRC}/encounter/encounter_check.f90
${SRC}/encounter/encounter_io.f90
Expand Down
8 changes: 4 additions & 4 deletions src/base/base_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module base
character(STRMAX) :: inplfile = PL_INFILE !! Name of input file for massive bodies
character(STRMAX) :: intpfile = TP_INFILE !! Name of input file for test particles
character(STRMAX) :: in_netcdf = NC_INFILE !! Name of system input file for NetCDF input
character(STRMAX) :: in_type = "ASCII" !! Data representation type of input data files
character(STRMAX) :: in_form = "XV" !! Format of input data files ("EL" or "XV")
character(STRMAX) :: in_type = "NETCDF_DOUBLE" !! Data representation type of input data files
character(STRMAX) :: in_form = "XV" !! Format of input data files ("EL" or ["XV"])
integer(I4B) :: istep_out = -1 !! Number of time steps between saved outputs
character(STRMAX) :: outfile = BIN_OUTFILE !! Name of output binary file
character(STRMAX) :: out_type = "NETCDF_DOUBLE" !! Binary format of output file
Expand All @@ -46,7 +46,7 @@ module base
real(DP) :: rmax = -1.0_DP !! Maximum heliocentric radius for test particle
real(DP) :: rmaxu = -1.0_DP !! Maximum unbound heliocentric radius for test particle
real(DP) :: qmin = -1.0_DP !! Minimum pericenter distance for test particle
character(STRMAX) :: qmin_coord = 'HELIO' !! Coordinate frame to use for qmin
character(STRMAX) :: qmin_coord = "HELIO" !! Coordinate frame to use for qmin (["HELIO"] or "BARY")
real(DP) :: qmin_alo = -1.0_DP !! Minimum semimajor axis for qmin
real(DP) :: qmin_ahi = -1.0_DP !! Maximum semimajor axis for qmin
real(QP) :: MU2KG = -1.0_QP !! Converts mass units to grams
Expand All @@ -58,7 +58,7 @@ module base
real(DP) :: min_GMfrag = -1.0_DP !! Smallest G*mass that can be produced in a fragmentation event
integer(I4B), dimension(:), allocatable :: seed !! Random seeds for fragmentation modeling
logical :: lmtiny_pl = .false. !! Include semi-interacting massive bodies
logical :: lfragmentation = .false. !! Do fragmentation modeling instead of simple merger.
character(STRMAX) :: collision_model = "MERGE" !! The Coll
character(STRMAX) :: encounter_save = "NONE" !! Indicate if and how encounter data should be saved
logical :: lenc_save_trajectory = .false. !! Indicates that when encounters are saved, the full trajectory through recursion steps are saved
logical :: lenc_save_closest = .false. !! Indicates that when encounters are saved, the closest approach distance between pairs of bodies is saved
Expand Down
39 changes: 39 additions & 0 deletions src/collision/collision_generate.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

!! Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
!! 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.

submodule(collision) s_collision_model
use swiftest
contains

module subroutine collision_generate_merge_system(self, system, param, t)
implicit none
class(collision_merge), intent(inout) :: self !! Fraggle fragment system object
class(base_nbody_system), intent(inout) :: 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
end subroutine collision_generate_merge_system

module subroutine collision_generate_bounce_system(self, system, param, t)
implicit none
class(collision_bounce), intent(inout) :: self !! Fraggle fragment system object
class(base_nbody_system), intent(inout) :: 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
end subroutine collision_generate_bounce_system

module subroutine collision_generate_simple_system(self, system, param, t)
implicit none
class(collision_simple), intent(inout) :: self !! Fraggle fragment system object
class(base_nbody_system), intent(inout) :: 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
end subroutine collision_generate_simple_system

end submodule s_collision_model
Loading

0 comments on commit c65211d

Please sign in to comment.