From 34d3b4bacd0ee4bee5ebbc0450429599a98b43a8 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Fri, 30 Sep 2022 09:36:03 +0100 Subject: [PATCH 1/7] North Sea: actually use shorter test time --- examples/north_sea/model_config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/north_sea/model_config.py b/examples/north_sea/model_config.py index be5332a09..72aafd780 100644 --- a/examples/north_sea/model_config.py +++ b/examples/north_sea/model_config.py @@ -97,15 +97,15 @@ def construct_solver(spinup=False, store_station_time_series=True, **model_optio coriolis_2d.interpolate(2 * omega * sin(lat * pi / 180.0)) # Setup temporal discretisation - default_start_date = datetime.datetime(2022, 1, 1, tzinfo=sim_tz) - default_end_date = datetime.datetime(2022, 1, 2, tzinfo=sim_tz) + default_start_date = datetime.datetime(2022, 1, 1, 0, 0, tzinfo=sim_tz) + default_end_date = datetime.datetime(2022, 1, 2, 0, 0, tzinfo=sim_tz) start_date = model_options.pop("start_date", default_start_date) end_date = model_options.pop("end_date", default_end_date) dt = 3600.0 t_export = 3600.0 t_end = (end_date - start_date).total_seconds() if os.getenv("THETIS_REGRESSION_TEST") is not None: - t_end = 5 * t_export + end_date = datetime.datetime(2022, 1, 1, 0, 5, tzinfo=sim_tz) # Create solver solver_obj = solver2d.FlowSolver2d(mesh2d, bathymetry_2d) From fff2666b9dc21617b7a8a8d3fd1fb1736aaf0981 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Fri, 30 Sep 2022 09:36:19 +0100 Subject: [PATCH 2/7] Tohoku: make date-aware --- examples/tohoku_inversion/inverse_problem.py | 3 ++- examples/tohoku_inversion/model_config.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/tohoku_inversion/inverse_problem.py b/examples/tohoku_inversion/inverse_problem.py index b7a297934..5438de733 100644 --- a/examples/tohoku_inversion/inverse_problem.py +++ b/examples/tohoku_inversion/inverse_problem.py @@ -78,7 +78,8 @@ sta_manager.set_model_field(solver_obj.fields.elev_2d) # Define the scaling for the cost function so that J ~ O(1) -J_scalar = Constant(solver_obj.dt / options.simulation_end_time) +t_end = (options.simulation_end_date - options.simulation_initial_date).total_seconds() +J_scalar = Constant(solver_obj.dt / t_end) # Create inversion manager and add controls no_exports = os.getenv("THETIS_REGRESSION_TEST") is not None diff --git a/examples/tohoku_inversion/model_config.py b/examples/tohoku_inversion/model_config.py index 3ed0ada65..632e3edde 100644 --- a/examples/tohoku_inversion/model_config.py +++ b/examples/tohoku_inversion/model_config.py @@ -9,7 +9,8 @@ import scipy.interpolate as si -# Setup UTM zone +# Setup zones +sim_tz = timezone.pytz.timezone("Japan") coord_system = coordsys.UTMCoordinateSystem(utm_zone=54) # Earthquake epicentre in longitude-latitude coordinates @@ -117,12 +118,19 @@ def construct_solver(elev_init, store_station_time_series=True, **model_options) """ mesh2d = elev_init.function_space().mesh() - t_end = 2 * 3600.0 + # Setup temporal discretisation u_mag = Constant(5.0) + default_start_date = datetime.datetime(2011, 3, 11, 14, 46, tzinfo=sim_tz) + default_end_date = datetime.datetime(2011, 3, 11, 16, 46, tzinfo=sim_tz) t_export = 60.0 dt = 60.0 if os.getenv("THETIS_REGRESSION_TEST") is not None: - t_end = 5 * t_export + model_options["simulation_initial_date"] = default_start_date + model_options["simulation_end_date"] = datetime.datetime(2011, 3, 11, 14, 51, tzinfo=sim_tz) + if "simulation_initial_date" not in model_options: + model_options["simulation_initial_date"] = default_start_date + if "simulation_end_date" not in model_options: + model_options["simulation_end_date"] = default_end_date # Bathymetry P1_2d = get_functionspace(mesh2d, "CG", 1) @@ -141,7 +149,6 @@ def construct_solver(elev_init, store_station_time_series=True, **model_options) options.element_family = "dg-dg" options.simulation_export_time = t_export options.fields_to_export = ["elev_2d"] - options.simulation_end_time = t_end options.horizontal_velocity_scale = u_mag options.swe_timestepper_type = "CrankNicolson" if not hasattr(options.swe_timestepper_options, "use_automatic_timestep"): From 1b073425f37bb9ba501a3a3fa8a3471257ddf1ac Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Thu, 29 Feb 2024 14:04:00 +0000 Subject: [PATCH 3/7] minutes->hours --- examples/north_sea/model_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/north_sea/model_config.py b/examples/north_sea/model_config.py index 72aafd780..aa59d1e06 100644 --- a/examples/north_sea/model_config.py +++ b/examples/north_sea/model_config.py @@ -105,7 +105,7 @@ def construct_solver(spinup=False, store_station_time_series=True, **model_optio t_export = 3600.0 t_end = (end_date - start_date).total_seconds() if os.getenv("THETIS_REGRESSION_TEST") is not None: - end_date = datetime.datetime(2022, 1, 1, 0, 5, tzinfo=sim_tz) + end_date = datetime.datetime(2022, 1, 1, 5, 0, tzinfo=sim_tz) # Create solver solver_obj = solver2d.FlowSolver2d(mesh2d, bathymetry_2d) From 48d749497826c1ba705596dcf540f5fe0ed4b7fd Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Thu, 4 Jun 2026 16:19:04 +0100 Subject: [PATCH 4/7] Use simulation dates rather than times --- examples/tohoku_inversion/inverse_problem.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/tohoku_inversion/inverse_problem.py b/examples/tohoku_inversion/inverse_problem.py index 4115f22fa..26c36c5dc 100644 --- a/examples/tohoku_inversion/inverse_problem.py +++ b/examples/tohoku_inversion/inverse_problem.py @@ -75,7 +75,8 @@ ) # Define the scaling for the cost function so that dJ/dm ~ O(1) # TODO: Update scaling to depend on number of DOFs in the problem -cost_function_scaling = domain_constant(10000000 * solver_obj.dt / options.simulation_end_time, mesh2d) +time_span = (options.simulation_end_date - options.simulation_start_date).total_seconds() +cost_function_scaling = domain_constant(10000000 * solver_obj.dt / time_span, mesh2d) sta_manager.cost_function_scaling = cost_function_scaling sta_manager.load_scalar_observation_data( observation_data_dir, From 127e7aa5e7dad67ea920972a2dfcb5a241fe6162 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Thu, 4 Jun 2026 16:47:41 +0100 Subject: [PATCH 5/7] Fix start->initial --- examples/tohoku_inversion/inverse_problem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tohoku_inversion/inverse_problem.py b/examples/tohoku_inversion/inverse_problem.py index 26c36c5dc..617090e81 100644 --- a/examples/tohoku_inversion/inverse_problem.py +++ b/examples/tohoku_inversion/inverse_problem.py @@ -75,7 +75,7 @@ ) # Define the scaling for the cost function so that dJ/dm ~ O(1) # TODO: Update scaling to depend on number of DOFs in the problem -time_span = (options.simulation_end_date - options.simulation_start_date).total_seconds() +time_span = (options.simulation_end_date - options.simulation_initial_date).total_seconds() cost_function_scaling = domain_constant(10000000 * solver_obj.dt / time_span, mesh2d) sta_manager.cost_function_scaling = cost_function_scaling sta_manager.load_scalar_observation_data( From 846a7635ea5582d50a67c87b9ecfd7f2fffc4f4f Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Fri, 5 Jun 2026 09:46:56 +0100 Subject: [PATCH 6/7] Remove THETIS_REGRESSION_TEST end_date change --- examples/north_sea/model_config.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/north_sea/model_config.py b/examples/north_sea/model_config.py index 3e055da3b..07408c39b 100644 --- a/examples/north_sea/model_config.py +++ b/examples/north_sea/model_config.py @@ -104,8 +104,6 @@ def construct_solver(mesh2d, spinup=False, store_station_time_series=True, **mod dt = 3600.0 t_export = 3600.0 t_end = (end_date - start_date).total_seconds() - if os.getenv("THETIS_REGRESSION_TEST") is not None: - end_date = datetime.datetime(2022, 1, 1, 5, 0, tzinfo=sim_tz) # Create solver solver_obj = solver2d.FlowSolver2d(mesh2d, bathymetry_2d) From e19e062a3d64de9aa7d1c5c2f97338923052d703 Mon Sep 17 00:00:00 2001 From: Stephan Kramer Date: Sat, 6 Jun 2026 19:12:39 +0100 Subject: [PATCH 7/7] Fix timedelta calculation Affects when options.simulation_initial_date is set *and* self.simulation_time is nonzero (i.e. when running from checkpoint with load_state()). --- thetis/solver2d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thetis/solver2d.py b/thetis/solver2d.py index ef5a31b82..79a34dfe6 100644 --- a/thetis/solver2d.py +++ b/thetis/solver2d.py @@ -1090,7 +1090,7 @@ def create_iterator(self, update_forcings=None, export_func=None, adj_timesteppe init_date = self.options.simulation_initial_date end_date = self.options.simulation_end_date if (init_date is not None and end_date is not None): - now = init_date + datetime.timedelta(initial_simulation_time) + now = init_date + datetime.timedelta(seconds=initial_simulation_time) assert end_date > now, f'Simulation end date must be greater than initial time {now}' print_output( f'Running simulation\n'