Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
gotm.h
Go to the documentation of this file.
1/** @file gotm.h
2 */
3/**
4# General Ocean Turbulence Model interface for multilayer
5
6This module interfaces the [multilayer solver](hydro.h) with
7[GOTM](http://gotm.net).
8
9Vertical diffusion of momentum, temperature and salinity is handled
10by GOTM.
11
12The temperature and salinity fields are undefined by default. If the
13calling solver defines them, the corresponding GOTM vertical diffusion
14routines will be called. */
15
16scalar T = {-1}, S = {-1};
17
18/**
19The surface fluxes of momentum, heat and short-wave radiation are
20provided as surface fields by the calling solver. They are zero by
21default. */
22
23// surface wind stress (eg. in Pa or N/m^2)
24const vector airsea_tau[] = {0.};
25// surface heat flux (eg. in W/m^2)
27// surface short-wave radiation flux (eg. in W/m^2)
29
30/**
31## Implementation
32
33It uses the relevant headers from the [C
34interface](/src/gotm/common.h) to GOTM. */
35
36#include "gotm/common.h"
37#include <gotm/gotm/gotm.h>
38// #include <gotm/gotm/diagnostics.h>
39// #include <gotm/util/time.h>
40
42// #include <gotm/meanflow/updategrid.h>
43// #include <gotm/meanflow/wequation.h>
47// #include <gotm/meanflow/extpressure.h>
48// #include <gotm/meanflow/intpressure.h>
50#include <gotm/meanflow/shear.h>
55
58#include <gotm/util/eqstate.h>
59
61#include <gotm/turbulence/kpp.h>
62
63// #include <gotm/observations/observations.h>
64#include <gotm/airsea/airsea.h>
65
66/**
67The corresponding GOTM libraries need to be linked. Note that the
68`GOTM` environment variable need to point to the proper installation
69directory. */
70
71#pragma autolink \
72 -L$GOTM/build/ -lgotm -lairsea -lmeanflow -lobservations -lturbulence \
73 -linput -lutil -loutput_manager `nf-config --flibs` \
74 -lgfortran
75
76/**
77The timestepping routine is based on its [Fortran
78counterpart](https://github.com/gotm-model/code/blob/v5.2/src/gotm/gotm.F90#L372). */
79
80static void gotm_step (long n)
81{
82 // prepare time and output
83 // time_update_time (&n);
84
85 // all observations/data
86
87#if 0
89 &nl, &meanflow_z);
91 &nl, &meanflow_z);
92#endif
93
94 // external forcing
95#if 0
97 // fixme: check indices
98 airsea_set_sst (&meanflow_t.a[nl-1]); // check this
100 &meanflow_v.a[nl-1]);
101 }
102#endif
103 // airsea_do_airsea (&time_julianday, &time_secondsofday);
104
105 // reset some quantities
108
109 // sum fluxes as a diagnostic
110 // airsea_integrated_fluxes (&dt);
111
112 // meanflow integration starts
113#if 0
117#endif
118
119#if 0
120 double omega = 2.*pi/86164.;
121 double latitude = 50.; // 50.;
122 meanflow_cori = 2.*omega*sin(2.*pi*latitude/360.);
124#endif
125
126 // update velocity
127 integer ext_press_mode = 99; // no external pressure gradient
134#if 0
137#endif
140
141 // update temperature and salinity
142 if (S.i >= 0)
145
146 if (T.i >= 0)
149
150 // update shear and stratification
153 &dt, &gotm_cnpar,
155
156 // compute turbulent mixing
157 switch (turbulence_turb_method) {
158
159 case 0:
160 // do convective adjustment
165 break;
166
167 case 99: {
168 // update KPP model
171 realtype tRad[nl+1], bRad[nl+1]; // fixme: check this
176 &tFlux, &sFlux, &btFlux, &bsFlux,
177 tRad, bRad);
178
182 meanflow_ss.a,
184 &tFlux, &btFlux, &sFlux, &bsFlux,
186 break;
187 }
188
189 default:
190 // update one-point models
196 xP.a
197#else
198 NULL
199#endif
200 );
201 }
202}
203
204/**
205The initialisation tries to call the relevant initialisation functions
206from GOTM, as they appear in the original
207[gotm.F90](https://github.com/gotm-model/code/blob/v5.2/src/gotm/gotm.F90#L129)
208source code. */
209
210/** @brief Event: defaults (i = 0) */
211void event_defaults (void)
212{
213 // cnpar [float, minimum = 0, maximum = 1]
214 // Constant for the theta scheme used for time integration of
215 // diffusion-reaction components. \theta=0.5 for Cranck-Nicholson
216 // (second-order accurate), \theta=0 for Forward Euler (first-
217 // order accurate), \theta=1 for Backward Euler (first-order
218 // accurate). Note that only \theta=1 guarantees positive
219 // solutions for positive definite systems.
220 gotm_cnpar = 1.;
221
222 // buoy_method [integer]
223 // method to compute mean buoyancy
224 // 1: from equation of state (i.e. from potential temperature
225 // and salinity)
226 // 2: from prognostic equation
228
230
232 realtype latitude = 0.;
234 if (turbulence_turb_method == 99) {
235 integer namlst = -1;
237 &G, &meanflow_rho_0);
238 }
239 else
241}
242
243/**
244Vertical diffusion is part of the "viscous terms" of the multilayer
245event loop. We just copy the relevant fields into the corresponding
246GOTM fields, call GOTM and retrieve the updated fields. */
247
248/** @brief Event: viscous_term (i++) */
250{
251 struct { realtype * x, * y; } gotm_u = { meanflow_u.a, meanflow_v.a };
252 struct { realtype * x, * y; } gotm_t = { &airsea_tx, &airsea_ty };
253 for (int _i = 0; _i < _N; _i++) /* foreach */ {
254 for (int _d = 0; _d < dimension; _d++)
255 *gotm_t.x = airsea_tau.x[];
256
257 double z = zb[];
258 foreach_layer() {
259 meanflow_h.a[point.l + 1] = h[];
260 for (int _d = 0; _d < dimension; _d++)
261 gotm_u.x[point.l + 1] = u.x[];
262 if (T.i >= 0)
263 meanflow_t.a[point.l + 1] = T[];
264 if (S.i >= 0)
265 meanflow_s.a[point.l + 1] = S[];
266 meanflow_z.a[point.l + 1] = z + h[]/2.;
267 z += h[];
268 }
269
272 gotm_step (i);
273
274 foreach_layer() {
275 for (int _d = 0; _d < dimension; _d++)
276 u.x[] = gotm_u.x[point.l + 1];
277 if (T.i >= 0)
278 T[] = meanflow_t.a[point.l + 1];
279 if (S.i >= 0)
280 S[] = meanflow_s.a[point.l + 1];
281 }
282 }
283}
284
285/**
286The GOTM cleanup function deallocates Fortran fields etc. */
287
288/** @brief Event: cleanup (t = end) */
289void event_cleanup (void)
290{
292}
293
294/**
295## Utility functions
296
297This function uses GOTM to initialize a vertical temperature profile
298corresponding to a squared buoyancy frequency `NN` for a given constant
299salinity and top temperature. */
300
301void constant_NNT (double T_top, double S_const, double NN,
302 scalar T)
303{
304 for (int _i = 0; _i < _N; _i++) /* foreach */ {
305 double z = zb[];
307 z += h[];
308 T[0,0,nl-1] = T_top;
309 for (int l = nl - 2; l >= 0; l--) {
310 double pFace = G*(z - h[0,0,l]/2.);
311 double alpha = eqstate_eos_alpha (&S_const, &T[0,0,l+1], &pFace, &G,
313 T[0,0,l] = T[0,0,l+1] - 1./(G*alpha)*NN*h[0,0,l];
314 z -= h[0,0,l];
315 }
316 }
317}
#define u
Definition advection.h:30
static void airsea_set_sst(realtype *temp)
Definition airsea.h:134
#define airsea_ty
Definition airsea.h:38
#define airsea_evap
Definition airsea.h:42
#define airsea_precip
Definition airsea.h:40
static void airsea_set_ssuv(realtype *uvel, realtype *vvel)
Definition airsea.h:143
#define airsea_heat
Definition airsea.h:28
#define airsea_tx
Definition airsea.h:36
#define airsea_calc_fluxes
Definition airsea.h:6
#define airsea_i_0
Definition airsea.h:24
const vector alpha
Definition all-mach.h:47
scalar zb[]
Definition atmosphere.h:6
double G
Definition atmosphere.h:12
scalar h[]
Definition atmosphere.h:6
#define dimension
Definition bitree.h:3
define l
int y
Definition common.h:76
int x
Definition common.h:76
int z
Definition common.h:76
#define pi
Definition common.h:4
Point point
Definition conserving.h:86
static void meanflow_convectiveadjustment(integer *nlev, realtype *num, realtype *nuh, realtype *const_num, realtype *const_nuh, integer *buoy_method, realtype *g, realtype *rho_0)
static void util_convert_fluxes(integer *nlev, realtype *g, realtype *cp, realtype *rho_0, realtype *heat, realtype *p_e, realtype *rad, realtype *t, realtype *s, realtype *tflux, realtype *sflux, realtype *btflux, realtype *bsflux, realtype *trad, realtype *brad)
else return n
Definition curvature.h:101
int integer
Definition cvmix.h:105
double dt
scalar int i
Definition embed.h:74
static realtype eqstate_eos_alpha(realtype *s, realtype *t, realtype *p, realtype *g, realtype *rho_0)
Definition eqstate.h:51
static void meanflow_extpressure(integer *method, integer *nlev)
Definition extpressure.h:10
static void meanflow_friction(realtype *kappa, realtype *avmolu, realtype *tx, realtype *ty)
Definition friction.h:12
double realtype
Definition common.h:47
#define gotm_buoy_method
Definition common.h:64
#define gotm_cnpar
Definition common.h:62
static void gotm_clean_up(void)
Definition gotm.h:28
static void input_do_input(integer *jul, integer *secs, integer *nlev, realtype_1d *z)
Definition input.h:58
static void meanflow_coriolis(integer *nlev, realtype *dt)
Definition coriolis.h:10
scalar zeta[]
Definition hele-shaw.h:39
static void meanflow_intpressure(integer *nlev)
Definition intpressure.h:9
static void kpp_do_kpp(integer *nlev, realtype *h0, realtype *h, realtype *rho, realtype *u, realtype *v, realtype *nn, realtype *nnt, realtype *nns, realtype *ss, realtype *u_taus, realtype *u_taub, realtype *tflux, realtype *btflux, realtype *sflux, realtype *bsflux, realtype *trad, realtype *brad, realtype *f)
Definition kpp.h:62
static void kpp_init_kpp(integer *namlst, char *fn, integer *nlev, realtype *h0, realtype *h, realtype *kpp_g, realtype *kpp_rho_0)
Definition kpp.h:30
static void gotm_step(long n)
The corresponding GOTM libraries need to be linked.
Definition gotm.h:80
const scalar airsea_swr_flux[]
Definition gotm.h:28
const vector airsea_tau[]
The surface fluxes of momentum, heat and short-wave radiation are provided as surface fields by the c...
Definition gotm.h:24
void constant_NNT(double T_top, double S_const, double NN, scalar T)
Definition gotm.h:301
const scalar airsea_heat_flux[]
Definition gotm.h:26
void event_viscous_term(void)
Vertical diffusion is part of the "viscous terms" of the multilayer event loop.
Definition gotm.h:249
scalar T
Definition gotm.h:16
void event_cleanup(void)
The GOTM cleanup function deallocates Fortran fields etc.
Definition gotm.h:289
void event_defaults(void)
The initialisation tries to call the relevant initialisation functions from GOTM, as they appear in t...
Definition gotm.h:211
scalar S
Definition gotm.h:16
int nl
Definition layers.h:9
#define foreach_layer()
#define meanflow_u_taus
Definition meanflow.h:134
#define meanflow_nns
Definition meanflow.h:40
#define meanflow_z0b
Definition meanflow.h:122
#define meanflow_ss
Definition meanflow.h:42
#define meanflow_t
Definition meanflow.h:30
#define meanflow_depth
Definition meanflow.h:140
#define meanflow_s
Definition meanflow.h:32
#define meanflow_h
Definition meanflow.h:16
#define meanflow_rad
Definition meanflow.h:50
#define meanflow_v
Definition meanflow.h:22
#define meanflow_cori
Definition meanflow.h:128
#define meanflow_u_taub
Definition meanflow.h:130
#define meanflow_u
Definition meanflow.h:20
#define meanflow_nnt
Definition meanflow.h:38
#define meanflow_z
Definition meanflow.h:12
static void meanflow_post_init_meanflow(integer *nlev, realtype *latitude)
Definition meanflow.h:165
#define meanflow_rho
Definition meanflow.h:34
#define meanflow_rho_0
Definition meanflow.h:108
#define meanflow_cp
Definition meanflow.h:110
#define meanflow_avmolu
Definition meanflow.h:112
#define meanflow_z0s
Definition meanflow.h:124
#define meanflow_nn
Definition meanflow.h:36
#define meanflow_gravity
Definition meanflow.h:106
static void observations_get_all_obs(integer *julday, integer *secs, integer *nlev, realtype_1d *z)
#define observations_ext_press_mode
static void meanflow_salinity(integer *nlev, realtype *dt, realtype *cnpar, realtype *nus, realtype *gams)
Definition salinity.h:13
static void meanflow_shear(integer *nlev, realtype *cnpar)
Definition shear.h:10
def _i
Definition stencils.h:405
static void meanflow_stratification(integer *nlev, integer *buoy_method, realtype *dt, realtype *cnpar, realtype *nub, realtype *gamb)
scalar omega[]
We allocate the vorticity field , the streamfunction field and a structure to store the statistics o...
Definition stream.h:39
int i
Definition common.h:44
scalar x
Definition common.h:47
static void meanflow_temperature(integer *nlev, realtype *dt, realtype *cnpar, realtype *i_0, realtype *heat, realtype *nuh, realtype *gamh, realtype *rad)
Definition temperature.h:16
#define time_julianday
Definition time.h:20
#define time_secondsofday
Definition time.h:22
static void mtridiagonal_init_tridiagonal(integer *n)
Definition tridiagonal.h:9
static void turbulence_do_turbulence(integer *nlev, realtype *dt, realtype *depth, realtype *u_taus, realtype *u_taub, realtype *z0s, realtype *z0b, realtype *h, realtype *nn, realtype *ss, realtype *xp)
Definition turbulence.h:346
static void turbulence_post_init_turbulence(integer *nlev)
Definition turbulence.h:299
#define turbulence_num
Definition turbulence.h:24
#define turbulence_gamu
Definition turbulence.h:30
#define turbulence_nus
Definition turbulence.h:28
#define turbulence_const_nuh
Definition turbulence.h:134
#define turbulence_gamh
Definition turbulence.h:36
#define turbulence_const_num
Definition turbulence.h:132
#define turbulence_gamv
Definition turbulence.h:32
#define turbulence_gams
Definition turbulence.h:38
#define turbulence_kappa
Definition turbulence.h:122
#define turbulence_nuh
Definition turbulence.h:26
#define turbulence_turb_method
Definition turbulence.h:90
static void meanflow_uequation(integer *nlev, realtype *dt, realtype *cnpar, realtype *tx, realtype *num, realtype *gamu, integer *method)
Definition uequation.h:15
static void meanflow_updategrid(integer *nlev, realtype *dt, realtype *zeta)
Definition updategrid.h:11
static void meanflow_vequation(integer *nlev, realtype *dt, realtype *cnpar, realtype *ty, realtype *num, realtype *gamv, integer *method)
Definition vequation.h:15
static void meanflow_wequation(integer *nlev, realtype *dt)
Definition wequation.h:10