MPTRAC
Functions
met_check_dt.c File Reference

Check model time step based on given meteorological data. More...

#include "mptrac.h"

Go to the source code of this file.

Functions

void usage (void)
 Print command-line help. More...
 
int main (int argc, char *argv[])
 

Detailed Description

Check model time step based on given meteorological data.

Definition in file met_check_dt.c.

Function Documentation

◆ usage()

void usage ( void  )

Print command-line help.

Definition at line 209 of file met_check_dt.c.

210 {
211
212 printf("\nMPTRAC met_check_dt tool.\n\n");
213 printf("Check model time-step constraints for meteorological data.\n");
214 printf("\n");
215 printf("Usage:\n");
216 printf(" met_check_dt <ctl> <dt_file> <met> [KEY VALUE ...]\n");
217 printf("\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");
225}

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 51 of file met_check_dt.c.

53 {
54
55 ctl_t ctl;
56
57 clim_t *clim;
58
59 met_t *met;
60
61 dd_t *dd;
62
63 /* Print usage information... */
64 USAGE;
65
66 /* Check arguments... */
67 if (argc < 4)
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.");
71
72 /* Allocate... */
73 mptrac_alloc(NULL, NULL, &clim, &met, NULL, NULL, NULL, &dd);
74
75 /* Read control parameters... */
76 mptrac_read_ctl(argv[1], argc, argv, &ctl);
77 const double pbl_trans = ctl.turb_pbl_trans;
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);
81
82 /* Read climatological data... */
83 mptrac_read_clim(&ctl, clim);
84
85 /* Read meteo data... */
86 if (!mptrac_read_met(argv[3], &ctl, clim, met, dd))
87 ERRMSG("Cannot open file!");
88
89 /* Create output file... */
90 FILE *out;
91 LOG(1, "Write time step data file: %s", argv[2]);
92 if (!(out = fopen(argv[2], "w")))
93 ERRMSG("Cannot create file!");
94
95 /* Write header... */
96 fprintf(out,
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");
104
105 /* Loop over pressure levels... */
106 for (int ip = 1; ip < met->np - 1; ip++) {
107
108 /* Init... */
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;
115
116 /* Loop over columns... */
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++) {
120
121 /* Check advection... */
122 const double vh =
123 sqrt(SQR(met->u[ix][iy][ip]) + SQR(met->v[ix][iy][ip]));
124 const double dt_x = fabs(c_max * dx / vh);
125 if (vh != 0)
126 dt_x_min = MIN(dt_x, dt_x_min);
127
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);
132
133 /* Get layer weights... */
134 const double pt = clim_tropo(clim, met->time,
135 ctl.met_coord_type ==
136 0 ? met->lat[iy] : ctl.met_utm_ref_lat);
137 const double wpbl =
138 pbl_weight_dt(met->p[ip], met->pbl[ix][iy], met->ps[ix][iy],
139 pbl_trans);
140 const double wtrop = tropo_weight_dt(met->p[ip], pt) * (1.0 - wpbl);
141 const double wstrat = 1.0 - wpbl - wtrop;
142
143 /* Check layer-aware diffusion... */
144 const double dx_loc = wpbl * ctl.turb_dx_pbl
145 + wtrop * ctl.turb_dx_trop + wstrat * ctl.turb_dx_strat;
146 if (dx_loc > 0) {
147 const double dt_dx = 0.5 * SQR(n_max * dx) / dx_loc;
148 dt_dx_min = MIN(dt_dx, dt_dx_min);
149 }
150
151 const double dz_loc = wpbl * ctl.turb_dz_pbl
152 + wtrop * ctl.turb_dz_trop + wstrat * ctl.turb_dz_strat;
153 if (dz_loc > 0) {
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);
157 }
158
159 /* Check PBL transition diffusion... */
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));
167 const double dz_max = MAX(ctl.turb_dz_pbl, ctl.turb_dz_trop);
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);
171 }
172 }
173
174 /* Check PBL depth diffusion on the full PBL scale. */
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]));
179 if (dz_pbl > 0 && ctl.turb_dz_pbl > 0) {
180 const double dt_pbl_depth =
181 0.5 * SQR(n_max * dz_pbl) / ctl.turb_dz_pbl;
182 dt_pbl_depth_min = MIN(dt_pbl_depth, dt_pbl_depth_min);
183 }
184 }
185 }
186
187 /* Write output... */
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);
195 }
196
197 /* Close output file... */
198 fclose(out);
199
200 /* Free... */
201 mptrac_free(NULL, NULL, clim, met, NULL, NULL, NULL, dd);
202
203 return EXIT_SUCCESS;
204}
double clim_tropo(const clim_t *clim, const double t, const double lat)
Calculates the tropopause pressure based on climatological data.
Definition: mptrac.c:213
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.
Definition: mptrac.c:6397
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.
Definition: mptrac.c:12462
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
Definition: mptrac.c:6683
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.
Definition: mptrac.c:6314
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.
Definition: mptrac.c:7767
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.
Definition: mptrac.c:6743
#define H0
Scale height [km].
Definition: mptrac.h:269
#define MIN(a, b)
Macro to determine the minimum of two values.
Definition: mptrac.h:1478
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2405
#define USAGE
Print usage information on -h or --help.
Definition: mptrac.h:2212
#define Z(p)
Convert pressure to altitude.
Definition: mptrac.h:2242
#define SQR(x)
Compute the square of a value.
Definition: mptrac.h:2036
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: mptrac.h:2335
#define MAX(a, b)
Macro to determine the maximum of two values.
Definition: mptrac.h:1377
Climatological data.
Definition: mptrac.h:3787
Control parameters.
Definition: mptrac.h:2493
double met_utm_ref_lat
Reference latitude [deg] for UTM grid.
Definition: mptrac.h:2852
double turb_dz_trop
Vertical turbulent diffusion coefficient (troposphere) [m^2/s].
Definition: mptrac.h:3053
double turb_dx_strat
Horizontal turbulent diffusion coefficient (stratosphere) [m^2/s].
Definition: mptrac.h:3047
double turb_dx_trop
Horizontal turbulent diffusion coefficient (troposphere) [m^2/s].
Definition: mptrac.h:3044
double turb_pbl_trans
Depth of turbulent PBL transition layer (fraction of PBL pressure thickness).
Definition: mptrac.h:3065
double turb_dx_pbl
Horizontal turbulent diffusion coefficient (PBL) [m^2/s].
Definition: mptrac.h:3041
int met_coord_type
Type of coordinates for meteo data (-1=detect, 0=lat/lon [deg], 1=UTM [m]).
Definition: mptrac.h:2849
double turb_dz_strat
Vertical turbulent diffusion coefficient (stratosphere) [m^2/s].
Definition: mptrac.h:3056
double turb_dz_pbl
Vertical turbulent diffusion coefficient (PBL) [m^2/s].
Definition: mptrac.h:3050
Domain decomposition data structure.
Definition: mptrac.h:4023
Meteo data structure.
Definition: mptrac.h:3846
float w[EX][EY][EP]
Vertical velocity [hPa/s].
Definition: mptrac.h:3972
int nx
Number of longitudes.
Definition: mptrac.h:3855
int ny
Number of latitudes.
Definition: mptrac.h:3858
float ps[EX][EY]
Surface pressure [hPa].
Definition: mptrac.h:3888
int np
Number of pressure levels.
Definition: mptrac.h:3861
float u[EX][EY][EP]
Zonal wind [m/s].
Definition: mptrac.h:3966
float pbl[EX][EY]
Boundary layer pressure [hPa].
Definition: mptrac.h:3918
float v[EX][EY][EP]
Meridional wind [m/s].
Definition: mptrac.h:3969
double time
Time [s].
Definition: mptrac.h:3849
double lat[EY]
Latitudes [deg].
Definition: mptrac.h:3870
double p[EP]
Pressure levels [hPa].
Definition: mptrac.h:3873
Here is the call graph for this function: