Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/north_sea/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def construct_solver(mesh2d, spinup=False, store_station_time_series=True, **mod
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
Expand Down
3 changes: 2 additions & 1 deletion examples/tohoku_inversion/inverse_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_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(
observation_data_dir,
Expand Down
15 changes: 11 additions & 4 deletions examples/tohoku_inversion/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -117,12 +118,19 @@ def construct_solver(bathymetry_2d, elev_init, store_station_time_series=True, *
"""
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)
Comment on lines +123 to +124

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
default_start_date = sim_tz.localize(datetime.datetime(2011, 3, 11, 14, 46))
default_end_date = sim_tz.localize(datetime.datetime(2011, 3, 11, 16, 46))

If you do:
print(datetime.datetime(2011, 3, 11, 14, 46, tzinfo=sim_tz), sim_tz.localize(datetime.datetime(2011, 3, 11, 14, 46)))
you get
2011-03-11 14:46:00+09:19 2011-03-11 14:46:00+09:00
i.e. the former uses a time zone of UTC+9:19 instead of the correct UTC+9. If I understand correctly, datetime in the standard library only has limited support for timezones, and it doesn't handle the fact that timezones change historically (i.e. Japan used to be on UTC+9:19 but is now UTC+9

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
model_options["simulation_end_date"] = datetime.datetime(2011, 3, 11, 14, 51, tzinfo=sim_tz)
model_options["simulation_end_date"] = sim_tz.localize(datetime.datetime(2011, 3, 11, 14, 51))

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
bathymetry_2d.interpolate(bathymetry_2d - elev_init)
Expand All @@ -134,7 +142,6 @@ def construct_solver(bathymetry_2d, elev_init, store_station_time_series=True, *
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"):
Expand Down
2 changes: 1 addition & 1 deletion thetis/solver2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down