diff --git a/examples/Basic_Simulation/initial_conditions.py b/examples/Basic_Simulation/initial_conditions.py index 4d7fe7ae5..a577c6658 100644 --- a/examples/Basic_Simulation/initial_conditions.py +++ b/examples/Basic_Simulation/initial_conditions.py @@ -23,7 +23,7 @@ from numpy.random import default_rng # Initialize the simulation object as a variable -sim = swiftest.Simulation(tstart=0.0, tstop=1.0e3, dt=0.01, tstep_out=1.0e0, dump_cadence=0, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8) +sim = swiftest.Simulation(fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8) # Add the modern planets and the Sun using the JPL Horizons Database sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto"]) @@ -67,4 +67,4 @@ sim.get_parameter() # Run the simulation -sim.run() +sim.run(tstart=0.0, tstop=1.0e2, dt=0.01, tstep_out=1.0e0, dump_cadence=0, ) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index b0dabe922..fb7ae2fbd 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -406,4 +406,10 @@ def vec2xr(param: Dict, ds = xr.merge([ds_info,ds]) ds["space"] = xr.DataArray(space_coords,dims=["space"],coords={"space":space_coords}) + # Re-order dimension coordinates so that they are in the same order as the Fortran side + idx = ds.indexes + dim_order = ["time", "space", "id"] + idx = {index_name: idx[index_name] for index_name in dim_order} + ds = ds.reindex(idx) + return ds \ No newline at end of file diff --git a/python/swiftest/swiftest/io.py b/python/swiftest/swiftest/io.py index 01983bad6..caa36926a 100644 --- a/python/swiftest/swiftest/io.py +++ b/python/swiftest/swiftest/io.py @@ -193,7 +193,19 @@ def read_swiftest_param(param_file_name, param, verbose=True): print(f"{param_file_name} not found.") return param - +def reorder_dims(ds): + + # Re-order dimension coordinates so that they are in the same order as the Fortran side + idx = ds.indexes + if "id" in idx: + dim_order = ["time", "space", "id"] + elif "name" in idx: + dim_order = ["time", "space", "name"] + else: + dim_order = idx + idx = {index_name: idx[index_name] for index_name in dim_order} + ds = ds.reindex(idx) + return ds def read_swifter_param(param_file_name, verbose=True): """ Reads in a Swifter param.in file and saves it as a dictionary @@ -1134,6 +1146,7 @@ def swiftest_xr2infile(ds, param, in_type="NETCDF_DOUBLE", infile_name=None,fram frame = unclean_string_values(frame) if verbose: print(f"Writing initial conditions to file {infile_name}") + frame = reorder_dims(frame) frame.to_netcdf(path=infile_name) return frame diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index aad511e92..9e1279a79 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -2549,6 +2549,7 @@ def get_nvals(ds): self.data = get_nvals(self.data) self.data = self.data.sortby("id") + self.data = io.reorder_dims(self.data) return dsnew