-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathmodels.jl
More file actions
97 lines (83 loc) · 4.29 KB
/
Copy pathmodels.jl
File metadata and controls
97 lines (83 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using .TurbulenceClosures
mutable struct Model{A<:Architecture, G, TC, T}
arch :: A # Computer `Architecture` on which `Model` is run.
grid :: G # Grid of physical points on which `Model` is solved.
clock :: Clock{T} # Tracks iteration number and simulation time of `Model`.
eos :: EquationOfState # Defines relationship between temperature, salinity, and
# buoyancy in the Boussinesq vertical momentum equation.
constants :: PlanetaryConstants # Set of physical constants, inc. gravitational acceleration.
velocities :: VelocityFields # Container for velocity fields `u`, `v`, and `w`.
tracers :: TracerFields # Container for tracer fields.
pressures :: PressureFields # Container for hydrostatic and nonhydrostatic pressure.
forcing # Container for forcing functions defined by the user
closure :: TC # Diffusive 'turbulence closure' for all model fields
boundary_conditions :: ModelBoundaryConditions # Container for 3d bcs on all fields.
G :: SourceTerms # Container for right-hand-side of PDE that governs `Model`
Gp :: SourceTerms # RHS at previous time-step (for Adams-Bashforth time integration)
poisson_solver # ::PoissonSolver or ::PoissonSolverGPU
stepper_tmp :: StepperTemporaryFields # Temporary fields used for the Poisson solver.
output_writers :: Array{OutputWriter, 1} # Objects that write data to disk.
diagnostics :: Array{Diagnostic, 1} # Objects that calc diagnostics on-line during simulation.
end
"""
Model(; kwargs...)
Construct an `Oceananigans.jl` model.
"""
function Model(;
# Model resolution and domain size
N,
L,
# Model architecture and floating point precision
arch = CPU(),
float_type = Float64,
grid = RegularCartesianGrid(float_type, N, L),
# Isotropic transport coefficients (exposed to `Model` constructor for convenience)
ν = 1.05e-6, νh=ν, νv=ν,
κ = 1.43e-7, κh=κ, κv=κ,
closure = ConstantAnisotropicDiffusivity(float_type, νh=νh, νv=νv, κh=κh, κv=κv),
# Time stepping
start_time = 0,
iteration = 0,
clock = Clock{float_type}(start_time, iteration),
# Fluid and physical parameters
constants = Earth(float_type),
eos = LinearEquationOfState(float_type),
# Forcing and boundary conditions for (u, v, w, T, S)
forcing = Forcing(nothing, nothing, nothing, nothing, nothing),
boundary_conditions = ModelBoundaryConditions(),
# Output and diagonstics
output_writers = OutputWriter[],
diagnostics = Diagnostic[]
)
arch == GPU() && !HAVE_CUDA && throw(ArgumentError("Cannot create a GPU model. No CUDA-enabled GPU was detected!"))
# Initialize fields, including source terms and temporary variables.
velocities = VelocityFields(arch, grid)
tracers = TracerFields(arch, grid)
pressures = PressureFields(arch, grid)
G = SourceTerms(arch, grid)
Gp = SourceTerms(arch, grid)
stepper_tmp = StepperTemporaryFields(arch, grid)
# Initialize Poisson solver.
poisson_solver = PoissonSolver(arch, grid)
# Set the default initial condition
initialize_with_defaults!(eos, tracers, velocities, G, Gp)
Model(arch, grid, clock, eos, constants,
velocities, tracers, pressures, forcing, closure, boundary_conditions,
G, Gp, poisson_solver, stepper_tmp, output_writers, diagnostics)
end
arch(model::Model{A}) where A <: Architecture = A
float_type(m::Model) = eltype(model.grid)
add_bcs!(model::Model; kwargs...) = add_bcs(model.boundary_conditions; kwargs...)
function initialize_with_defaults!(eos, tracers, sets...)
# Default tracer initial condition is deteremined by eos.
tracers.S.data.parent .= eos.S₀
tracers.T.data.parent .= eos.T₀
# Set all further fields to 0
for set in sets
for fldname in propertynames(set)
fld = getproperty(set, fldname)
fld.data.parent .= 0 # promotes to eltype of fld.data
end
end
return nothing
end