Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date aware examples #325

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions examples/north_sea/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

That's 5 minutes past midnight, no? but the timestep is in hours?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot! Fixed in 1b07342.


# Create solver
solver_obj = solver2d.FlowSolver2d(mesh2d, bathymetry_2d)
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 @@ -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
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(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)
Expand All @@ -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"):
Expand Down