Skip to content

Commit 9964670

Browse files
authored
Rename Model to IncompressibleModel (#626)
Rename Model to IncompressibleModel
2 parents 8352e56 + 99f7404 commit 9964670

28 files changed

+109
-99
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ At this time, updating should be done with care, as Oceananigans is under rapid
8282
**Note**: Oceananigans requires at least Julia v1.1 to run correctly.
8383

8484
## Running your first model
85-
Let's initialize a 3D model with 100×100×50 grid points on a 2×2×1 km domain and simulate it for 10 time steps using steps of 60 seconds each (for a total of 10 minutes of simulation time).
85+
Let's initialize a 3D model with 100×100×50 grid points on a 2×2×1 km domain and simulate it for 1 time step of 60 seconds.
8686
```julia
8787
using Oceananigans
88-
model = Model(grid = RegularCartesianGrid(size=(100, 100, 50), length = (2000, 2000, 1000)))
89-
time_step!(model; Δt=60, Nt=10)
88+
grid = RegularCartesianGrid(size=(100, 100, 50), length = (2000, 2000, 1000))
89+
model = IncompressibleModel(grid=grid)
90+
time_step!(model, 60)
9091
```
9192
You just simulated what might have been a 3D patch of ocean, it's that easy! It was a still lifeless ocean so nothing interesting happened but now you can add interesting dynamics and visualize the output.
9293

@@ -97,9 +98,11 @@ using Oceananigans
9798

9899
# We'll set up a 2D model with an xz-slice so there's only 1 grid point in y
99100
# and use an artificially high viscosity ν and diffusivity κ.
100-
model = Model(architecture = CPU(),
101-
grid = RegularCartesianGrid(size=(128, 128, 128), length=(2000, 2000, 2000)),
102-
closure = ConstantIsotropicDiffusivity=4e-2, κ=4e-2))
101+
model = IncompressibleModel(
102+
architecture = CPU(),
103+
grid = RegularCartesianGrid(size=(128, 128, 128), length=(2000, 2000, 2000)),
104+
closure = ConstantIsotropicDiffusivity=4e-2, κ=4e-2)
105+
)
103106

104107
# Set a temperature perturbation with a Gaussian profile located at the center
105108
# of the vertical slice. This will create a buoyant thermal bubble that will
@@ -109,7 +112,8 @@ x₀, z₀ = Lx/2, Lz/2
109112
T₀(x, y, z) = 20 + 0.01 * exp(-100 * ((x - x₀)^2 + (z - z₀)^2) / (Lx^2 + Lz^2))
110113
set!(model; T=T₀)
111114

112-
time_step!(model; Δt=10, Nt=5000)
115+
simulation = Simulation(model, Δt=10, stop_iteration=5000)
116+
run!(simulation)
113117
```
114118
By changing `arch=CPU()` to `arch=GPU()`, the example will run on an Nvidia GPU!
115119

src/Diagnostics/cfl.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ for advection across a cell.
3434
Example
3535
=======
3636
```julia
37-
julia> model = Model(grid=RegularCartesianGrid(size=(16, 16, 16), length=(8, 8, 8)));
37+
julia> model = IncompressibleModel(grid=RegularCartesianGrid(size=(16, 16, 16), length=(8, 8, 8)));
3838
3939
julia> cfl = AdvectiveCFL(1.0);
4040
@@ -59,7 +59,7 @@ returned.
5959
Example
6060
=======
6161
```julia
62-
julia> model = Model(grid=RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1)));
62+
julia> model = IncompressibleModel(grid=RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1)));
6363
6464
julia> dcfl = DiffusiveCFL(0.1);
6565

src/Diagnostics/field_maximum.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ element-wise to `field`.
77
Examples
88
=======
99
```julia
10-
julia> model = Model(grid=RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1)));
10+
julia> model = IncompressibleModel(grid=RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1)));
1111
1212
julia> max_abs_u = FieldMaximum(abs, model.velocities.u);
1313

src/Diagnostics/time_series.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ A `TimeSeries` `Diagnostic` that records a time series of `diagnostic(model)`.
1919
Example
2020
=======
2121
```julia
22-
julia> model = Model(grid=RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1)));
22+
julia> model = IncompressibleModel(grid=RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1)));
2323
2424
julia> max_u = TimeSeries(FieldMaximum(abs, model.velocities.u), model; frequency=1)
2525
@@ -55,7 +55,7 @@ A `TimeSeries` `Diagnostic` that records a `NamedTuple` of time series of
5555
Example
5656
=======
5757
```julia
58-
julia> model = Model(grid=RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1))); Δt = 1.0;
58+
julia> model = IncompressibleModel(grid=RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1))); Δt = 1.0;
5959
6060
julia> cfl = TimeSeries((adv=AdvectiveCFL(Δt), diff=DiffusiveCFL(Δt)), model; frequency=1);
6161

src/Fields/set!.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ a function with arguments `(x, y, z)`, or any data type for which a
1414
Example
1515
=======
1616
```julia
17-
model = Model(grid=RegularCartesianGrid(size=(32, 32, 32), length=(1, 1, 1))
17+
model = IncompressibleModel(grid=RegularCartesianGrid(size=(32, 32, 32), length=(1, 1, 1))
1818
1919
# Set u to a parabolic function of z, v to random numbers damped
2020
# at top and bottom, and T to some silly array of half zeros,

src/Forcing/model_forcing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Example
1111
1212
julia> u_forcing = SimpleForcing((x, y, z, t) -> exp(z) * cos(t))
1313
14-
julia> model = Model(forcing=ModelForcing(u=u_forcing))
14+
julia> model = IncompressibleModel(forcing=ModelForcing(u=u_forcing))
1515
"""
1616
function ModelForcing(; u=zeroforcing, v=zeroforcing, w=zeroforcing, tracer_forcings...)
1717
u = at_location((Face, Cell, Cell), u)

src/Models/Models.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Models
22

3-
export Model, ChannelModel, NonDimensionalModel, Clock
3+
export IncompressibleModel, NonDimensionalModel, Clock
44

55
using Oceananigans.Architectures
66
using Oceananigans.Fields
@@ -20,7 +20,7 @@ Abstract supertype for models.
2020
abstract type AbstractModel end
2121

2222
include("clock.jl")
23-
include("model.jl")
23+
include("incompressible_model.jl")
2424
include("non_dimensional_model.jl")
2525
include("show_models.jl")
2626

src/Models/model.jl renamed to src/Models/incompressible_model.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ using Oceananigans.Architectures: AbstractArchitecture
66
using Oceananigans.Buoyancy: validate_buoyancy
77
using Oceananigans.TurbulenceClosures: ν₀, κ₀, with_tracers
88

9-
mutable struct Model{TS, E, A<:AbstractArchitecture, G, T, B, R, SW, U, C, Φ, F,
10-
BCS, S, K, Θ} <: AbstractModel
9+
mutable struct IncompressibleModel{TS, E, A<:AbstractArchitecture, G, T, B, R, SW, U, C, Φ, F,
10+
BCS, S, K, Θ} <: AbstractModel
1111

1212
architecture :: A # Computer `Architecture` on which `Model` is run
1313
grid :: G # Grid of physical points on which `Model` is solved
@@ -28,7 +28,7 @@ mutable struct Model{TS, E, A<:AbstractArchitecture, G, T, B, R, SW, U, C, Φ, F
2828
end
2929

3030
"""
31-
Model(;
31+
IncompressibleModel(;
3232
grid,
3333
architecture = CPU(),
3434
float_type = Float64,
@@ -48,7 +48,7 @@ end
4848
pressure_solver = PressureSolver(architecture, grid, PressureBoundaryConditions(boundary_conditions.u))
4949
)
5050
51-
Construct an `Oceananigans.jl` model on `grid`.
51+
Construct an incompressible `Oceananigans.jl` model on `grid`.
5252
5353
Keyword arguments
5454
=================
@@ -63,7 +63,7 @@ Keyword arguments
6363
or `ModelBoundaryConditions`. See `BoundaryConditions`, `HorizontallyPeriodicSolutionBCs`, and `ChannelSolutionBCs`.
6464
- `parameters`: User-defined parameters for use in user-defined forcing functions and boundary condition functions.
6565
"""
66-
function Model(;
66+
function IncompressibleModel(;
6767
grid,
6868
architecture = CPU(),
6969
float_type = Float64,
@@ -97,7 +97,7 @@ function Model(;
9797
closure = with_tracers(tracernames(tracers), closure)
9898
boundary_conditions = ModelBoundaryConditions(tracernames(tracers), diffusivities, boundary_conditions)
9999

100-
return Model(architecture, grid, clock, buoyancy, coriolis, surface_waves, velocities, tracers,
101-
pressures, forcing, closure, boundary_conditions, timestepper,
102-
pressure_solver, diffusivities, parameters)
100+
return IncompressibleModel(architecture, grid, clock, buoyancy, coriolis, surface_waves,
101+
velocities, tracers, pressures, forcing, closure, boundary_conditions,
102+
timestepper, pressure_solver, diffusivities, parameters)
103103
end

src/Models/non_dimensional_model.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ forcing.
1818
1919
Note that `N`, `L`, and `Re` are required.
2020
21-
Additional `kwargs` are passed to the regular `Model` constructor.
21+
Additional `kwargs` are passed to the regular `IncompressibleModel` constructor.
2222
"""
2323
function NonDimensionalModel(; grid, float_type=Float64, Re, Pr=0.7, Ro=Inf,
2424
buoyancy = BuoyancyTracer(),
2525
coriolis = FPlane(float_type, f=1/Ro),
2626
closure = ConstantIsotropicDiffusivity(float_type, ν=1/Re, κ=1/(Pr*Re)),
2727
kwargs...)
2828

29-
return Model(; float_type=float_type, grid=grid, closure=closure,
30-
coriolis=coriolis, tracers=(:b,), buoyancy=buoyancy, kwargs...)
29+
return IncompressibleModel(; float_type=float_type, grid=grid, closure=closure,
30+
coriolis=coriolis, tracers=(:b,), buoyancy=buoyancy, kwargs...)
3131
end

src/Models/show_models.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ using Oceananigans.Grids: short_show
22
using Oceananigans.Utils: prettytime, ordered_dict_show
33

44
"""Show the innards of a `Model` in the REPL."""
5-
Base.show(io::IO, model::Model) =
6-
print(io, "Oceananigans.Model on a $(typeof(model.architecture)) architecture ",
5+
Base.show(io::IO, model::IncompressibleModel) =
6+
print(io, "Oceananigans.IncompressibleModel on a $(typeof(model.architecture)) architecture ",
77
"(time = $(prettytime(model.clock.time)), iteration = $(model.clock.iteration)) \n",
88
"├── grid: $(short_show(model.grid))\n",
99
"├── tracers: $(tracernames(model.tracers))\n",

src/Oceananigans.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export
4646
TimeStepWizard, update_Δt!,
4747

4848
# Models
49-
Model, ChannelModel, NonDimensionalModel,
49+
IncompressibleModel, NonDimensionalModel,
5050

5151
# Simulations
5252
Simulation, run!,

src/OutputWriters/checkpointer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function restore_from_checkpoint(filepath; kwargs=Dict())
125125
end
126126
end
127127

128-
model = Model(; kwargs...)
128+
model = IncompressibleModel(; kwargs...)
129129

130130
# Now restore fields.
131131
for p in cps

src/TimeSteppers/adams_bashforth.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ end
3131
#####
3232

3333
"""
34-
time_step!(model::Model{<:AdamsBashforthTimeStepper}, Δt; euler=false)
34+
time_step!(model::IncompressibleModel{<:AdamsBashforthTimeStepper}, Δt; euler=false)
3535
3636
Step forward `model` one time step `Δt` with a 2nd-order Adams-Bashforth method and
3737
pressure-correction substep. Setting `euler=true` will take a forward Euler time step.
3838
"""
39-
function time_step!(model::Model{<:AdamsBashforthTimeStepper}, Δt; euler=false)
39+
function time_step!(model::IncompressibleModel{<:AdamsBashforthTimeStepper}, Δt; euler=false)
4040
χ = ifelse(euler, convert(eltype(model.grid), -0.5), model.timestepper.χ)
4141

4242
# Convert NamedTuples of Fields to NamedTuples of OffsetArrays

test/regression_tests/ocean_large_eddy_simulation_regression_test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function run_ocean_large_eddy_simulation_regression_test(arch, closure)
5858
S_bcs = TracerBoundaryConditions(grid, top = BoundaryCondition(Flux, 5e-8))
5959

6060
# Model instantiation
61-
model = Model(
61+
model = IncompressibleModel(
6262
architecture = arch,
6363
grid = grid,
6464
coriolis = FPlane(f=1e-4),

test/regression_tests/rayleigh_benard_regression_test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function run_rayleigh_benard_regression_test(arch)
3131
bbcs = TracerBoundaryConditions(grid, top = BoundaryCondition(Value, 0.0),
3232
bottom = BoundaryCondition(Value, Δb))
3333

34-
model = Model(
34+
model = IncompressibleModel(
3535
architecture = arch,
3636
grid = grid,
3737
closure = ConstantIsotropicDiffusivity=ν, κ=κ),

test/regression_tests/thermal_bubble_regression_test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function run_thermal_bubble_regression_test(arch)
55

66
grid = RegularCartesianGrid(size=(Nx, Ny, Nz), length=(Lx, Ly, Lz))
77
closure = ConstantIsotropicDiffusivity=4e-2, κ=4e-2)
8-
model = Model(architecture=arch, grid=grid, closure=closure, coriolis=FPlane(f=1e-4))
8+
model = IncompressibleModel(architecture=arch, grid=grid, closure=closure, coriolis=FPlane(f=1e-4))
99
simulation = Simulation(model, Δt=6, stop_iteration=10)
1010

1111
model.tracers.T.data.parent .= 9.85

test/test_abstract_operations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ end
354354
for FT in float_types
355355
@info " Testing computation of abstract operations [$FT, $(typeof(arch))]..."
356356

357-
model = Model(
357+
model = IncompressibleModel(
358358
architecture = arch,
359359
float_type = FT,
360360
grid = RegularCartesianGrid(FT, size=(16, 16, 16), length=(1, 1, 1))

test/test_boundary_conditions.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ function test_z_boundary_condition_simple(arch, FT, fldname, bctype, bc, Nx, Ny)
1313
fieldbcs = TracerBoundaryConditions(grid, top=bc)
1414
modelbcs = SolutionBoundaryConditions(grid; Dict(fldname=>fieldbcs)...)
1515

16-
model = Model(grid=grid, architecture=arch, float_type=FT, boundary_conditions=modelbcs)
16+
model = IncompressibleModel(grid=grid, architecture=arch, float_type=FT, boundary_conditions=modelbcs)
1717

1818
time_step!(model, 1e-16, euler=true)
1919

20-
return typeof(model) <: Model
20+
return model isa IncompressibleModel
2121
end
2222

2323
function test_z_boundary_condition_top_bottom_alias(arch, FT, fldname)
@@ -29,7 +29,7 @@ function test_z_boundary_condition_top_bottom_alias(arch, FT, fldname)
2929
fieldbcs = TracerBoundaryConditions(grid, top=top_bc, bottom=bottom_bc)
3030
modelbcs = SolutionBoundaryConditions(grid; Dict(fldname=>fieldbcs)...)
3131

32-
model = Model(grid=grid, architecture=arch, float_type=FT, boundary_conditions=modelbcs)
32+
model = IncompressibleModel(grid=grid, architecture=arch, float_type=FT, boundary_conditions=modelbcs)
3333

3434
bcs = getfield(model.boundary_conditions.solution, fldname)
3535

@@ -53,7 +53,7 @@ function test_z_boundary_condition_array(arch, FT, fldname)
5353
fieldbcs = TracerBoundaryConditions(grid, top=value_bc)
5454
modelbcs = SolutionBoundaryConditions(grid; Dict(fldname=>fieldbcs)...)
5555

56-
model = Model(grid=grid, architecture=arch, float_type=FT, boundary_conditions=modelbcs)
56+
model = IncompressibleModel(grid=grid, architecture=arch, float_type=FT, boundary_conditions=modelbcs)
5757

5858
bcs = getfield(model.boundary_conditions.solution, fldname)
5959

@@ -72,8 +72,8 @@ function test_flux_budget(arch, FT, fldname)
7272
modelbcs = SolutionBoundaryConditions(grid; Dict(fldname=>fieldbcs)...)
7373

7474
closure = ConstantIsotropicDiffusivity(FT, ν=κ, κ=κ)
75-
model = Model(grid=grid, closure=closure, architecture=arch,
76-
float_type=FT, buoyancy=nothing, boundary_conditions=modelbcs)
75+
model = IncompressibleModel(grid=grid, closure=closure, architecture=arch,
76+
float_type=FT, buoyancy=nothing, boundary_conditions=modelbcs)
7777

7878
if fldname (:u, :v, :w)
7979
field = getfield(model.velocities, fldname)
@@ -121,8 +121,9 @@ function fluxes_with_diffusivity_boundary_conditions_are_correct(arch, FT)
121121
model_bcs = ModelBoundaryConditions(tracer_names, diffusivities, solution_bcs;
122122
diffusivities=diffusivities_bcs)
123123

124-
model = Model(grid=grid, architecture=arch, float_type=FT, tracers=tracer_names, buoyancy=BuoyancyTracer(),
125-
closure=closure, diffusivities=diffusivities, boundary_conditions=model_bcs)
124+
model = IncompressibleModel(grid=grid, architecture=arch, float_type=FT, tracers=tracer_names,
125+
buoyancy=BuoyancyTracer(), closure=closure, diffusivities=diffusivities,
126+
boundary_conditions=model_bcs)
126127

127128
b₀(x, y, z) = z * bz
128129
set!(model, b=b₀)

test/test_diagnostics.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function horizontal_average_is_correct(arch, FT)
22
grid = RegularCartesianGrid(size=(16, 16, 16), length=(100, 100, 100))
3-
model = Model(grid=grid, architecture=arch, float_type=FT)
3+
model = IncompressibleModel(grid=grid, architecture=arch, float_type=FT)
44

55
T₀(x, y, z) = 20 + 0.01*z
66
set!(model; T=T₀)
@@ -14,7 +14,7 @@ end
1414

1515
function nan_checker_aborts_simulation(arch, FT)
1616
grid=RegularCartesianGrid(size=(16, 16, 2), length=(1, 1, 1))
17-
model = Model(grid=grid, architecture=arch, float_type=FT)
17+
model = IncompressibleModel(grid=grid, architecture=arch, float_type=FT)
1818

1919
# It checks for NaNs in w by default.
2020
nc = NaNChecker(model; frequency=1, fields=Dict(:w => model.velocities.w.data.parent))
@@ -26,14 +26,16 @@ function nan_checker_aborts_simulation(arch, FT)
2626
end
2727

2828
TestModel(::GPU, FT, ν=1.0, Δx=0.5) =
29-
Model(grid = RegularCartesianGrid(FT, size=(16, 16, 16), length=(16Δx, 16Δx, 16Δx)),
29+
IncompressibleModel(
30+
grid = RegularCartesianGrid(FT, size=(16, 16, 16), length=(16Δx, 16Δx, 16Δx)),
3031
closure = ConstantIsotropicDiffusivity(FT, ν=ν, κ=ν),
3132
architecture = GPU(),
3233
float_type = FT
3334
)
3435

3536
TestModel(::CPU, FT, ν=1.0, Δx=0.5) =
36-
Model(grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3Δx, 3Δx, 3Δx)),
37+
IncompressibleModel(
38+
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3Δx, 3Δx, 3Δx)),
3739
closure = ConstantIsotropicDiffusivity(FT, ν=ν, κ=ν),
3840
architecture = CPU(),
3941
float_type = FT

0 commit comments

Comments
 (0)