From 107fc88c9f997340009aa88f91aa6924bf045c0a Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 14 Jan 2023 21:00:11 -0500 Subject: [PATCH] Fixed some bugs involved in trying to read in simulation data without radius --- python/swiftest/swiftest/simulation_class.py | 10 +++++++--- src/swiftest/swiftest_io.f90 | 14 ++++++++------ src/swiftest/swiftest_util.f90 | 6 +++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index e2a5d78dc..53f9669e2 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -28,6 +28,7 @@ import subprocess import shlex import warnings +import sys from tqdm.auto import tqdm from typing import ( Literal, @@ -453,9 +454,11 @@ def _type_scrub(output_data): if p.returncode != 0: for line in res[1]: print(line, end='') - warnings.warn("Failure in swiftest_driver", stacklevel=2) + warnings.warn("Failure in swiftest_driver", stacklevel=2) + sys.exit() except: warnings.warn(f"Error executing main swiftest_driver program", stacklevel=2) + sys.exit() pbar.close() return @@ -918,8 +921,9 @@ def set_integrator(self, warnings.warn(f"Cannot find the Swiftest driver in {str(self.binary_path)}",stacklevel=2) self.driver_executable = None else: - shutil.copy(self.binary_source, self.driver_executable) - self.driver_executable.resolve() + if self.binary_path.exists(): + shutil.copy(self.binary_source, self.driver_executable) + self.driver_executable.resolve() else: self.binary_path = "NOT IMPLEMENTED FOR THIS CODE" self.driver_executable = None diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index da0693b95..2bc8143fe 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -800,12 +800,14 @@ module subroutine swiftest_io_netcdf_initialize_output(self, param) end do ! Set special fill mode for discard time so that we can make use of it for non-discarded bodies. - select case (vartype) - case(NF90_FLOAT) - call netcdf_io_check( nf90_def_var_fill(nc%id, nc%discard_time_varid, NO_FILL, huge(1.0_SP)), "netcdf_io_initialize_output nf90_def_var_fill discard_time NF90_FLOAT" ) - case(NF90_DOUBLE) - call netcdf_io_check( nf90_def_var_fill(nc%id, nc%discard_time_varid, NO_FILL, huge(1.0_DP)), "netcdf_io_initialize_output nf90_def_var_fill discard_time NF90_DOUBLE" ) - end select + if (param%lclose) then + select case (vartype) + case(NF90_FLOAT) + call netcdf_io_check( nf90_def_var_fill(nc%id, nc%discard_time_varid, NO_FILL, huge(1.0_SP)), "netcdf_io_initialize_output nf90_def_var_fill discard_time NF90_FLOAT" ) + case(NF90_DOUBLE) + call netcdf_io_check( nf90_def_var_fill(nc%id, nc%discard_time_varid, NO_FILL, huge(1.0_DP)), "netcdf_io_initialize_output nf90_def_var_fill discard_time NF90_DOUBLE" ) + end select + end if ! Take the file out of define mode call netcdf_io_check( nf90_enddef(nc%id), "netcdf_io_initialize_output nf90_enddef" ) diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index 0c25abbd5..ecd3708ed 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -1446,7 +1446,11 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) nbody_system%L_orbit(j) = Lcborbit(j) + sum(Lplorbit(j,1:npl), pl%lmask(1:npl)) end do - nbody_system%be = sum(-3*pl%Gmass(1:npl)*pl%mass(1:npl)/(5*pl%radius(1:npl)), pl%lmask(1:npl)) + if ((param%lclose)) then + nbody_system%be = sum(-3*pl%Gmass(1:npl)*pl%mass(1:npl)/(5*pl%radius(1:npl)), pl%lmask(1:npl)) + else + nbody_system%be = 0.0_DP + end if nbody_system%te = nbody_system%ke_orbit + nbody_system%ke_spin + nbody_system%pe + nbody_system%be nbody_system%L_total(:) = nbody_system%L_orbit(:) + nbody_system%L_spin(:) end associate