MPTRAC
Functions
trac.c File Reference

Lagrangian particle dispersion model. 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

Lagrangian particle dispersion model.

Definition in file trac.c.

Function Documentation

◆ usage()

void usage ( void  )

Print command-line help.

Definition at line 187 of file trac.c.

188 {
189
190 printf("\nMPTRAC trac tool.\n\n");
191 printf("Run forward or backward trajectory calculations.\n");
192 printf("\n");
193 printf("Usage:\n");
194 printf(" trac <dirlist> <ctl> <atm_in> [KEY VALUE ...]\n");
195 printf("\n");
196 printf("Arguments:\n");
197 printf(" <dirlist> Text file containing work directories to process.\n");
198 printf(" <ctl> Control file name relative to each work directory.\n");
199 printf
200 (" <atm_in> Atmospheric input file name relative to each work directory.\n");
201 printf(" [KEY VALUE] Optional control parameters.\n");
202 printf("\nFurther information:\n");
203 printf(" Manual: https://slcs-jsc.github.io/mptrac/\n");
204}

◆ main()

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

Definition at line 43 of file trac.c.

45 {
46
47 ctl_t *ctl;
48
49 atm_t *atm;
50
51 cache_t *cache;
52
53 clim_t *clim;
54
55 met_t *met0, *met1;
56
57 dd_t *dd;
58
59 FILE *dirlist;
60
61 char dirname[LEN], filename[2 * LEN];
62
63 int ntask = -1, rank = 0, size = 1;
64
65 /* Print usage information... */
66 USAGE;
67
68 /* Initialize MPI... */
69#ifdef MPI
70 MPI_Init(&argc, &argv);
71 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
72 MPI_Comm_size(MPI_COMM_WORLD, &size);
73#endif
74
75 /* Check arguments... */
76 if (argc < 4)
77 ERRMSG("Missing or invalid command-line arguments.\n\n"
78 "Usage: trac <dirlist> <ctl> <atm_in> [KEY VALUE ...]\n\n"
79 "Use -h for full help.");
80
81 /* Open directory list... */
82 if (!(dirlist = fopen(argv[1], "r")))
83 ERRMSG("Cannot open directory list!");
84
85 /* Loop over directories... */
86 while (fscanf(dirlist, "%4999s", dirname) != EOF) {
87
88 /* MPI parallelization... */
89 if ((++ntask) % size != rank)
90 continue;
91
92 /* Write info... */
93 LOG(1, "Parallelization: ntask= %d | rank= %d | size= %d",
94 ntask, rank, size);
95
96 /* ------------------------------------------------------------
97 Initialize model run...
98 ------------------------------------------------------------ */
99
100 /* Allocate memory... */
101 mptrac_alloc(&ctl, &cache, &clim, &met0, &met1, &atm, &dd);
102
103 /* Read control parameters... */
104 sprintf(filename, "%s/%s", dirname, argv[2]);
105 mptrac_read_ctl(filename, argc, argv, ctl);
106
107 /* Read climatological data... */
108 mptrac_read_clim(ctl, clim);
109
110 /* Read atmospheric data... */
111 sprintf(filename, "%s/%s", dirname, argv[3]);
112 if (!mptrac_read_atm(filename, ctl, atm))
113 ERRMSG("Cannot open file!");
114
115 /* Initialize MPTRAC... */
116 mptrac_init(ctl, cache, clim, atm, ntask);
117
118 /* ------------------------------------------------------------
119 Loop over timesteps...
120 ------------------------------------------------------------ */
121
122 /* Loop over timesteps... */
123 for (double t = ctl->t_start;
124 ctl->direction * (t - ctl->t_stop) < ctl->dt_mod;
125 t += ctl->direction * ctl->dt_mod) {
126
127 /* Adjust length of final time step... */
128 if (ctl->direction * (t - ctl->t_stop) > 0)
129 t = ctl->t_stop;
130
131 /* Get meteo data... */
132 mptrac_get_met(ctl, clim, t, &met0, &met1, dd);
133
134 /* Check time step... */
135 if (ctl->dt_mod > fabs(met0->lon[1] - met0->lon[0]) * 111132. / 150.)
136 WARN("Violation of CFL criterion! Check DT_MOD!");
137
138#ifdef DD
139 /* Set-up domain decomposition... */
140 if ((t == ctl->t_start) && (ctl->dd == 1))
141 dd_init(ctl, dd, atm);
142#endif
143
144 /* Run a single time step... */
145 mptrac_run_timestep(ctl, cache, clim, &met0, &met1, atm, t, dd);
146
147 /* Write output... */
148 mptrac_write_output(dirname, ctl, met0, met1, atm, t);
149 }
150
151 /* ------------------------------------------------------------
152 Finalize model run...
153 ------------------------------------------------------------ */
154
155 /* Flush output buffer... */
156 fflush(NULL);
157
158 /* Report problem size... */
159 LOG(1, "SIZE_NP = %d", atm->np);
160 LOG(1, "SIZE_MPI_TASKS = %d", size);
161 LOG(1, "SIZE_OMP_THREADS = %d", omp_get_max_threads());
162
163 /* Report memory usage... */
164 LOG(1, "MEMORY_ATM = %g MByte", sizeof(atm_t) / 1024. / 1024.);
165 LOG(1, "MEMORY_CACHE = %g MByte", sizeof(cache_t) / 1024. / 1024.);
166 LOG(1, "MEMORY_CLIM = %g MByte", sizeof(clim_t) / 1024. / 1024.);
167 LOG(1, "MEMORY_METEO = %g MByte", sizeof(met_t) / 1024. / 1024.);
168
169 /* Free memory... */
170 mptrac_free(ctl, cache, clim, met0, met1, atm, dd);
171
172 /* Report timers... */
174 }
175
176 /* Finalize MPI... */
177#ifdef MPI
178 MPI_Finalize();
179#endif
180
181 return EXIT_SUCCESS;
182}
void mptrac_alloc(ctl_t **ctl, cache_t **cache, clim_t **clim, met_t **met0, met_t **met1, atm_t **atm, dd_t **dd)
Allocates and initializes memory resources for MPTRAC.
Definition: mptrac.c:4887
void mptrac_run_timestep(ctl_t *ctl, cache_t *cache, clim_t *clim, met_t **met0, met_t **met1, atm_t *atm, double t, dd_t *dd)
Executes a single timestep of the MPTRAC model simulation.
Definition: mptrac.c:6260
void mptrac_init(ctl_t *ctl, cache_t *cache, clim_t *clim, atm_t *atm, const int ntask)
Initializes the MPTRAC model and its associated components.
Definition: mptrac.c:5098
void mptrac_get_met(ctl_t *ctl, clim_t *clim, const double t, met_t **met0, met_t **met1, dd_t *dd)
Retrieves meteorological data for the specified time.
Definition: mptrac.c:4976
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
Definition: mptrac.c:5188
int mptrac_read_atm(const char *filename, const ctl_t *ctl, atm_t *atm)
Reads air parcel data from a specified file into the given atmospheric structure.
Definition: mptrac.c:5117
void mptrac_write_output(const char *dirname, const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, const double t)
Writes various types of output data to files in a specified directory.
Definition: mptrac.c:6630
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:5248
void mptrac_free(ctl_t *ctl, cache_t *cache, clim_t *clim, met_t *met0, met_t *met1, atm_t *atm, dd_t *dd)
Frees memory resources allocated for MPTRAC.
Definition: mptrac.c:4940
void dd_init(const ctl_t *ctl, dd_t *dd, atm_t *atm)
Initialize the domain decomposition infrastructure.
#define LEN
Maximum length of ASCII data lines.
Definition: mptrac.h:345
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2102
#define USAGE
Print usage information on -h or --help.
Definition: mptrac.h:1909
#define WARN(...)
Print a warning message with contextual information.
Definition: mptrac.h:2069
#define PRINT_TIMERS
Print the current state of all timers.
Definition: mptrac.h:2161
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: mptrac.h:2032
Air parcel data.
Definition: mptrac.h:3241
int np
Number of air parcels.
Definition: mptrac.h:3244
Cache data structure.
Definition: mptrac.h:3296
Climatological data.
Definition: mptrac.h:3436
Control parameters.
Definition: mptrac.h:2190
int direction
Direction flag (1=forward calculation, -1=backward calculation).
Definition: mptrac.h:2518
int dd
Domain decomposition (0=no, 1=yes, with 2x2 if not specified).
Definition: mptrac.h:3220
double t_stop
Stop time of simulation [s].
Definition: mptrac.h:2524
double dt_mod
Time step of simulation [s].
Definition: mptrac.h:2527
double t_start
Start time of simulation [s].
Definition: mptrac.h:2521
Domain decomposition data structure.
Definition: mptrac.h:3669
Meteo data structure.
Definition: mptrac.h:3495
double lon[EX]
Longitudes [deg].
Definition: mptrac.h:3513
Here is the call graph for this function: