32static double pbl_weight_dt(
36 const double pbl_trans);
39static double tropo_weight_dt(
68 ERRMSG(
"Missing or invalid command-line arguments.\n\n"
69 "Usage: met_check_dt <ctl> <dt_file> <met> [KEY VALUE ...]\n\n"
70 "Use -h for full help.");
73 mptrac_alloc(NULL, NULL, &clim, &met, NULL, NULL, NULL, &dd);
78 const double dx = 1e3 *
scan_ctl(argv[1], argc, argv,
"DX", -1,
"", NULL);
79 const double c_max =
scan_ctl(argv[1], argc, argv,
"CMAX", -1,
"0.5", NULL);
80 const double n_max =
scan_ctl(argv[1], argc, argv,
"NMAX", -1,
"0.3", NULL);
87 ERRMSG(
"Cannot open file!");
91 LOG(1,
"Write time step data file: %s", argv[2]);
92 if (!(out = fopen(argv[2],
"w")))
93 ERRMSG(
"Cannot create file!");
97 "# $1 = height [km]\n"
98 "# $2 = time step for horizontal advection [s]\n"
99 "# $3 = time step for vertical advection [s]\n"
100 "# $4 = time step for horizontal diffusion [s]\n"
101 "# $5 = time step for vertical diffusion [s]\n"
102 "# $6 = time step for PBL transition diffusion [s]\n"
103 "# $7 = time step for PBL depth diffusion [s]\n\n");
106 for (
int ip = 1; ip < met->
np - 1; ip++) {
109 double dt_x_min = 1e100;
110 double dt_p_min = 1e100;
111 double dt_dx_min = 1e100;
112 double dt_dp_min = 1e100;
113 double dt_pbl_min = 1e100;
114 double dt_pbl_depth_min = 1e100;
117#pragma omp parallel for default(shared) collapse(2) reduction(min:dt_x_min,dt_p_min,dt_dx_min,dt_dp_min,dt_pbl_min,dt_pbl_depth_min)
118 for (
int ix = 0; ix < met->
nx; ix++)
119 for (
int iy = 1; iy < met->
ny - 1; iy++) {
123 sqrt(
SQR(met->
u[ix][iy][ip]) +
SQR(met->
v[ix][iy][ip]));
124 const double dt_x = fabs(c_max * dx / vh);
126 dt_x_min =
MIN(dt_x, dt_x_min);
128 const double dp = 0.5 * fabs(met->
p[ip + 1] - met->
p[ip - 1]);
129 const double dt_p = fabs(c_max * dp / met->
w[ix][iy][ip]);
130 if (met->
w[ix][iy][ip] != 0)
131 dt_p_min =
MIN(dt_p, dt_p_min);
138 pbl_weight_dt(met->
p[ip], met->
pbl[ix][iy], met->
ps[ix][iy],
140 const double wtrop = tropo_weight_dt(met->
p[ip], pt) * (1.0 - wpbl);
141 const double wstrat = 1.0 - wpbl - wtrop;
147 const double dt_dx = 0.5 *
SQR(n_max * dx) / dx_loc;
148 dt_dx_min =
MIN(dt_dx, dt_dx_min);
154 const double dt_dp = 0.5 *
SQR(n_max * dp)
155 / (
SQR(met->
p[ip] / (100. *
H0)) * dz_loc);
156 dt_dp_min =
MIN(dt_dp, dt_dp_min);
160 if (pbl_trans > 0 && met->
ps[ix][iy] > met->
pbl[ix][iy]
161 && met->
p[ip] <= met->
pbl[ix][iy]
162 && met->
p[ip] >= met->
pbl[ix][iy]
163 - pbl_trans * (met->
ps[ix][iy] - met->
pbl[ix][iy])) {
164 const double p0 = met->
pbl[ix][iy];
165 const double p1 = p0 - pbl_trans * (met->
ps[ix][iy] - p0);
166 const double dz_trans = 1e3 * fabs(
Z(p1) -
Z(p0));
168 if (dz_trans > 0 && dz_max > 0) {
169 const double dt_trans = 0.5 *
SQR(n_max * dz_trans) / dz_max;
170 dt_pbl_min =
MIN(dt_trans, dt_pbl_min);
175 if (met->
ps[ix][iy] > met->
pbl[ix][iy]
176 && met->
p[ip] >= met->
pbl[ix][iy]) {
177 const double dz_pbl =
178 1e3 * fabs(
Z(met->
pbl[ix][iy]) -
Z(met->
ps[ix][iy]));
180 const double dt_pbl_depth =
182 dt_pbl_depth_min =
MIN(dt_pbl_depth, dt_pbl_depth_min);
188 const double out_dt_dx = dt_dx_min < 1e99 ? dt_dx_min : NAN;
189 const double out_dt_dp = dt_dp_min < 1e99 ? dt_dp_min : NAN;
190 const double out_dt_pbl = dt_pbl_min < 1e99 ? dt_pbl_min : NAN;
191 const double out_dt_pbl_depth =
192 dt_pbl_depth_min < 1e99 ? dt_pbl_depth_min : NAN;
193 fprintf(out,
"%g %g %g %g %g %g %g\n",
Z(met->
p[ip]), dt_x_min, dt_p_min,
194 out_dt_dx, out_dt_dp, out_dt_pbl, out_dt_pbl_depth);
201 mptrac_free(NULL, NULL, clim, met, NULL, NULL, NULL, dd);
212 printf(
"\nMPTRAC met_check_dt tool.\n\n");
213 printf(
"Check model time-step constraints for meteorological data.\n");
216 printf(
" met_check_dt <ctl> <dt_file> <met> [KEY VALUE ...]\n");
218 printf(
"Arguments:\n");
219 printf(
" <ctl> Control file.\n");
220 printf(
" <dt_file> Output table for time-step diagnostics.\n");
221 printf(
" <met> Meteorological input file.\n");
222 printf(
" [KEY VALUE] Optional control parameters.\n");
223 printf(
"\nFurther information:\n");
224 printf(
" Manual: https://slcs-jsc.github.io/mptrac/\n");
229static double pbl_weight_dt(
233 const double pbl_trans) {
235 const double p0 = pbl;
236 const double p1 = pbl - pbl_trans * (ps - pbl);
243 return LIN(p0, 1.0, p1, 0.0, p);
248static double tropo_weight_dt(
252 const double p1 = pt * 0.866877899;
253 const double p0 = pt / 0.866877899;
260 return LIN(p0, 1.0, p1, 0.0, p);
int main(int argc, char *argv[])
void usage(void)
Print command-line help.
double clim_tropo(const clim_t *clim, const double t, const double lat)
Calculates the tropopause pressure based on climatological data.
void mptrac_free(ctl_t *ctl, cache_t *cache, clim_t *clim, met_t *met0, met_t *met1, atm_t *atm, depo_t *depo, dd_t *dd)
Frees memory resources allocated for MPTRAC.
double scan_ctl(const char *filename, int argc, char *argv[], const char *varname, const int arridx, const char *defvalue, char *value)
Scans a control file or command-line arguments for a specified variable.
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
void mptrac_alloc(ctl_t **ctl, cache_t **cache, clim_t **clim, met_t **met0, met_t **met1, atm_t **atm, depo_t **depo, dd_t **dd)
Allocates and initializes memory resources for MPTRAC.
int mptrac_read_met(const char *filename, const ctl_t *ctl, const clim_t *clim, met_t *met, dd_t *dd)
Reads meteorological data from a file, supporting multiple formats and MPI broadcasting.
void mptrac_read_ctl(const char *filename, int argc, char *argv[], ctl_t *ctl)
Reads control parameters from a configuration file and populates the given structure.
MPTRAC library declarations.
#define H0
Scale height [km].
#define MIN(a, b)
Macro to determine the minimum of two values.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define USAGE
Print usage information on -h or --help.
#define Z(p)
Convert pressure to altitude.
#define SQR(x)
Compute the square of a value.
#define LOG(level,...)
Print a log message with a specified logging level.
#define LIN(x0, y0, x1, y1, x)
Linear interpolation.
#define MAX(a, b)
Macro to determine the maximum of two values.
double met_utm_ref_lat
Reference latitude [deg] for UTM grid.
double turb_dz_trop
Vertical turbulent diffusion coefficient (troposphere) [m^2/s].
double turb_dx_strat
Horizontal turbulent diffusion coefficient (stratosphere) [m^2/s].
double turb_dx_trop
Horizontal turbulent diffusion coefficient (troposphere) [m^2/s].
double turb_pbl_trans
Depth of turbulent PBL transition layer (fraction of PBL pressure thickness).
double turb_dx_pbl
Horizontal turbulent diffusion coefficient (PBL) [m^2/s].
int met_coord_type
Type of coordinates for meteo data (-1=detect, 0=lat/lon [deg], 1=UTM [m]).
double turb_dz_strat
Vertical turbulent diffusion coefficient (stratosphere) [m^2/s].
double turb_dz_pbl
Vertical turbulent diffusion coefficient (PBL) [m^2/s].
Domain decomposition data structure.
float w[EX][EY][EP]
Vertical velocity [hPa/s].
int nx
Number of longitudes.
int ny
Number of latitudes.
float ps[EX][EY]
Surface pressure [hPa].
int np
Number of pressure levels.
float u[EX][EY][EP]
Zonal wind [m/s].
float pbl[EX][EY]
Boundary layer pressure [hPa].
float v[EX][EY][EP]
Meridional wind [m/s].
double lat[EY]
Latitudes [deg].
double p[EP]
Pressure levels [hPa].