-
Notifications
You must be signed in to change notification settings - Fork 21
Add a prescribed ocean to the src #412
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
Open
simone-silvestri
wants to merge
8
commits into
main
Choose a base branch
from
ss/add-a-prescribed-ocean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
16655a2
Revert "Revert "add a prescribed ocean""
simone-silvestri 1a00396
better like this
simone-silvestri 7e5babd
add a docstring
simone-silvestri 83b1a8a
better comment
simone-silvestri 6a92445
let's go
simone-silvestri 60a0c65
it's a model
simone-silvestri c1441c2
update
simone-silvestri fb76671
import correct stuff
simone-silvestri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| using Oceananigans.Models: AbstractModel | ||
| using Oceananigans.OutputReaders: extract_field_time_series, update_field_time_series! | ||
|
|
||
| import Oceananigans.TimeSteppers: time_step!, update_state!, reset!, tick! | ||
| import Oceananigans.Models: timestepper, update_model_field_time_series! | ||
|
|
||
| import ClimaOcean: reference_density, heat_capacity | ||
| import Oceananigans.Architectures: on_architecture | ||
|
|
||
| ##### | ||
| ##### A prescribed ocean... | ||
| ##### | ||
|
|
||
| struct PrescribedOceanModel{G, C, U, T, F, Arch} <: AbstractModel{Nothing, Arch} | ||
| architecture :: Arch | ||
| grid :: G | ||
| clock :: Clock{C} | ||
| velocities :: U | ||
| tracers :: T | ||
| timeseries :: F | ||
| end | ||
|
|
||
| """ | ||
| PrescribedOceanModel(timeseries=NamedTuple(); grid, clock=Clock{Float64}(time = 0)) | ||
|
|
||
| Create a prescribed ocean model to be used in combination with ClimaOcean's `OceanSeaIceModel` | ||
| on a `grid` with a `clock`. | ||
|
|
||
| Arguments | ||
| ========= | ||
| - `timeseries`: A `NamedTuple` containing time series data for various fields. The named tuple can be empty | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the name is confusing because when we say "timeseries" it means just one series. But this is many timeseries? |
||
| (meaning that the ocean does not evolve in time) or include any combination of the | ||
| following fields: `u`, `v`, `T`, `S`. All elements provided must be of type `FieldTimeSeries` | ||
| and reside on the provided `grid`. | ||
| """ | ||
| function PrescribedOceanModel(timeseries=NamedTuple(); | ||
| grid, | ||
| clock=Clock{Float64}(time = 0)) | ||
|
|
||
| # Make sure all elements of the timeseries are on the same grid | ||
| # If we decide to pass a timeseries | ||
| if !isempty(timeseries) | ||
| for (k, v) in timeseries | ||
| isa(v, FieldTimeSeries) || | ||
| throw(ArgumentError("All variables in the `timeseries` argument must be `FieldTimeSeries`")) | ||
| v.grid == grid || | ||
| throw(ArgumentError("All variables in the timeseries reside on the provided grid")) | ||
| end | ||
| end | ||
|
|
||
| τx = Field{Face, Center, Nothing}(grid) | ||
| τy = Field{Center, Face, Nothing}(grid) | ||
| Jᵀ = Field{Center, Center, Nothing}(grid) | ||
| Jˢ = Field{Center, Center, Nothing}(grid) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this? I think this is wrong |
||
|
|
||
| u = XFaceField(grid, boundary_conditions=FieldBoundaryConditions(grid, (Face, Center, Center), top = FluxBoundaryCondition(τx))) | ||
| v = YFaceField(grid, boundary_conditions=FieldBoundaryConditions(grid, (Center, Face, Center), top = FluxBoundaryCondition(τy))) | ||
| T = CenterField(grid, boundary_conditions=FieldBoundaryConditions(grid, (Center, Center, Center), top = FluxBoundaryCondition(Jᵀ))) | ||
| S = CenterField(grid, boundary_conditions=FieldBoundaryConditions(grid, (Center, Center, Center), top = FluxBoundaryCondition(Jˢ))) | ||
|
|
||
| return PrescribedOceanModel(architecture(grid), grid, clock, (; u, v, w=ZeroField()), (; T, S), timeseries) | ||
| end | ||
|
|
||
| ##### | ||
| ##### Need to extend a couple of methods | ||
| ##### | ||
|
|
||
| function time_step!(model::PrescribedOceanModel, Δt; callbacks=[], euler=true) | ||
| tick!(model.clock, Δt) | ||
| time = Time(model.clock.time) | ||
|
|
||
| possible_fts = merge(model.velocities, model.tracers) | ||
| time_series_tuple = extract_field_time_series(possible_fts) | ||
|
|
||
| for fts in time_series_tuple | ||
| update_field_time_series!(fts, time) | ||
| end | ||
|
|
||
| update_u_velocity = haskey(model.timeseries, :u) | ||
| update_v_velocity = haskey(model.timeseries, :v) | ||
| update_temperature = haskey(model.timeseries, :T) | ||
| update_salinity = haskey(model.timeseries, :S) | ||
|
|
||
| update_u_velocity && parent(model.velocities.u) .= parent(model.timeseries.u[time]) | ||
| update_v_velocity && parent(model.velocities.v) .= parent(model.timeseries.v[time]) | ||
| update_temperature && parent(model.tracers.T) .= parent(model.timeseries.T[time]) | ||
| update_salinity && parent(model.tracers.S) .= parent(model.timeseries.S[time]) | ||
|
|
||
| return nothing | ||
| end | ||
|
|
||
| update_state!(::PrescribedOceanModel) = nothing | ||
| timestepper(::PrescribedOceanModel) = nothing | ||
|
|
||
| reference_density(ocean::Simulation{<:PrescribedOceanModel}) = 1025.6 | ||
| heat_capacity(ocean::Simulation{<:PrescribedOceanModel}) = 3995.6 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call it
PrescribedAtmosphere. Is thisPrescribedOceanorPrescribedOceanModel?I'm not sure really sure what a "prescribed model" is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this is because we add a simulation on top, while the atmosphere is a "simulation" rather than a model. I can switch it to a simulation rather than a model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is because the infrastructure we have now expects an ocean with a pattern of
ocean.model.stuff..., while there is no assumption on the atmosphere. I did not want to make a huge refactor here, I can call itPrescribedOceanthough and just have one field calledmodelinside of it