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

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

◆ main()

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

Definition at line 27 of file met_check_dt.c.

29 {
30
31 ctl_t ctl;
32
33 clim_t *clim;
34
35 met_t *met;
36
37 dd_t *dd;
38
39 /* Check arguments... */
40 if (argc < 4)
41 ERRMSG("Give parameters: <ctl> <dt_file> <met>");
42
43 /* Allocate... */
44 ALLOC(clim, clim_t, 1);
45 ALLOC(met, met_t, 1);
46 ALLOC(dd, dd_t, 1);
47
48 /* Read control parameters... */
49 mptrac_read_ctl(argv[1], argc, argv, &ctl);
50 const double kx = scan_ctl(argv[1], argc, argv, "KX", -1, "50.0", NULL);
51 const double kz = scan_ctl(argv[1], argc, argv, "KZ", -1, "0.1", NULL);
52 const double dx = 1e3 * scan_ctl(argv[1], argc, argv, "DX", -1, "", NULL);
53 const double c_max = scan_ctl(argv[1], argc, argv, "CMAX", -1, "0.5", NULL);
54 const double n_max = scan_ctl(argv[1], argc, argv, "NMAX", -1, "0.3", NULL);
55
56 /* Read climatological data... */
57 mptrac_read_clim(&ctl, clim);
58
59 /* Read meteo data... */
60 if (!mptrac_read_met(argv[3], &ctl, clim, met, dd))
61 ERRMSG("Cannot open file!");
62
63 /* Create output file... */
64 FILE *out;
65 LOG(1, "Write time step data file: %s", argv[2]);
66 if (!(out = fopen(argv[2], "w")))
67 ERRMSG("Cannot create file!");
68
69 /* Write header... */
70 fprintf(out,
71 "# $1 = height [km]\n"
72 "# $2 = time step for horizontal advection [s]\n"
73 "# $3 = time step for vertical advection [s]\n"
74 "# $4 = time step for horizontal diffusion [s]\n"
75 "# $5 = time step for vertical diffusion [s]\n\n");
76
77 /* Loop over pressure levels... */
78 for (int ip = 1; ip < met->np - 1; ip++) {
79
80 /* Init... */
81 double dt_x_min = 1e100;
82 double dt_p_min = 1e100;
83 double dt_dx_min = 1e100;
84 double dt_dp_min = 1e100;
85
86 /* Loop over columns... */
87#pragma omp parallel for default(shared) collapse(2) reduction(min:dt_x_min,dt_p_min,dt_dx_min,dt_dp_min)
88 for (int ix = 0; ix < met->nx; ix++)
89 for (int iy = 1; iy < met->ny - 1; iy++) {
90
91 /* Check advection... */
92 const double vh =
93 sqrt(SQR(met->u[ix][iy][ip]) + SQR(met->v[ix][iy][ip]));
94 const double dt_x = fabs(c_max * dx / vh);
95 if (vh != 0)
96 dt_x_min = MIN(dt_x, dt_x_min);
97
98 const double dp = 0.5 * fabs(met->p[ip + 1] - met->p[ip - 1]);
99 const double dt_p = fabs(c_max * dp / met->w[ix][iy][ip]);
100 if (met->w[ix][iy][ip])
101 dt_p_min = MIN(dt_p, dt_p_min);
102
103 /* Check diffusion... */
104 const double dt_dx = 0.5 * SQR(n_max * dx) / kx;
105 dt_dx_min = MIN(dt_dx, dt_dx_min);
106
107 const double dt_dp =
108 0.5 * SQR(n_max * dp) / (SQR(met->p[ip] / (100. * H0)) * kz);
109 dt_dp_min = MIN(dt_dp, dt_dp_min);
110 }
111
112 /* Write output... */
113 fprintf(out, "%g %g %g %g %g\n", Z(met->p[ip]), dt_x_min, dt_p_min,
114 dt_dx_min, dt_dp_min);
115 }
116
117 /* Close output file... */
118 fclose(out);
119
120 /* Free... */
121 free(clim);
122 free(met);
123 free(dd);
124
125 return EXIT_SUCCESS;
126}
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:10899
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
Definition: mptrac.c:5406
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:6357
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:5466
#define H0
Scale height [km].
Definition: mptrac.h:219
#define MIN(a, b)
Macro to determine the minimum of two values.
Definition: mptrac.h:1138
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2043
#define Z(p)
Convert pressure to altitude.
Definition: mptrac.h:1880
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
Definition: mptrac.h:416
#define SQR(x)
Compute the square of a value.
Definition: mptrac.h:1696
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: mptrac.h:1973
Climatological data.
Definition: mptrac.h:3487
Control parameters.
Definition: mptrac.h:2264
Domain decomposition data structure.
Definition: mptrac.h:3720
Meteo data structure.
Definition: mptrac.h:3546
float w[EX][EY][EP]
Vertical velocity [hPa/s].
Definition: mptrac.h:3669
int nx
Number of longitudes.
Definition: mptrac.h:3552
int ny
Number of latitudes.
Definition: mptrac.h:3555
int np
Number of pressure levels.
Definition: mptrac.h:3558
float u[EX][EY][EP]
Zonal wind [m/s].
Definition: mptrac.h:3663
float v[EX][EY][EP]
Meridional wind [m/s].
Definition: mptrac.h:3666
double p[EP]
Pressure levels [hPa].
Definition: mptrac.h:3570
Here is the call graph for this function: