MPTRAC
Functions
trac.c File Reference

Lagrangian particle dispersion model. More...

#include "mptrac.h"

Go to the source code of this file.

Functions

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

Detailed Description

Lagrangian particle dispersion model.

Definition in file trac.c.

Function Documentation

◆ main()

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

Definition at line 31 of file trac.c.

33 {
34
35 ctl_t *ctl;
36
37 atm_t *atm;
38
39 cache_t *cache;
40
41 clim_t *clim;
42
43 met_t *met0, *met1;
44
45 dd_t *dd;
46
47 FILE *dirlist;
48
49 char dirname[LEN], filename[2 * LEN];
50
51 int ntask = -1, rank = 0, size = 1;
52
53 /* Initialize MPI... */
54#ifdef MPI
55 MPI_Init(&argc, &argv);
56 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
57 MPI_Comm_size(MPI_COMM_WORLD, &size);
58#endif
59
60 /* Check arguments... */
61 if (argc < 4)
62 ERRMSG("Give parameters: <dirlist> <ctl> <atm_in>");
63
64 /* Open directory list... */
65 if (!(dirlist = fopen(argv[1], "r")))
66 ERRMSG("Cannot open directory list!");
67
68 /* Loop over directories... */
69 while (fscanf(dirlist, "%4999s", dirname) != EOF) {
70
71 /* MPI parallelization... */
72 if ((++ntask) % size != rank)
73 continue;
74
75 /* Write info... */
76 LOG(1, "Parallelization: ntask= %d | rank= %d | size= %d",
77 ntask, rank, size);
78
79 /* ------------------------------------------------------------
80 Initialize model run...
81 ------------------------------------------------------------ */
82
83 /* Start timers... */
85
86 /* Allocate memory... */
87 mptrac_alloc(&ctl, &cache, &clim, &met0, &met1, &atm, &dd);
88
89 /* Read control parameters... */
90 sprintf(filename, "%s/%s", dirname, argv[2]);
91 mptrac_read_ctl(filename, argc, argv, ctl);
92
93 /* Read climatological data... */
94 mptrac_read_clim(ctl, clim);
95
96 /* Read atmospheric data... */
97 sprintf(filename, "%s/%s", dirname, argv[3]);
98 if (!mptrac_read_atm(filename, ctl, atm))
99 ERRMSG("Cannot open file!");
100
101 /* Initialize MPTRAC... */
102 mptrac_init(ctl, cache, clim, atm, ntask);
103
104 /* ------------------------------------------------------------
105 Loop over timesteps...
106 ------------------------------------------------------------ */
107
108 /* Loop over timesteps... */
109 for (double t = ctl->t_start;
110 ctl->direction * (t - ctl->t_stop) < ctl->dt_mod;
111 t += ctl->direction * ctl->dt_mod) {
112
113 /* Adjust length of final time step... */
114 if (ctl->direction * (t - ctl->t_stop) > 0)
115 t = ctl->t_stop;
116
117 /* Get meteo data... */
118 mptrac_get_met(ctl, clim, t, &met0, &met1, dd);
119
120 /* Check time step... */
121 if (ctl->dt_mod > fabs(met0->lon[1] - met0->lon[0]) * 111132. / 150.)
122 WARN("Violation of CFL criterion! Check DT_MOD!");
123
124#ifdef DD
125 /* Set-up domain decomposition... */
126 if ((t == ctl->t_start || !dd->init) && (ctl->dd == 1))
127 dd->init = dd_init(ctl, dd, atm);
128#endif
129
130
131 /* Run a single time step... */
132 mptrac_run_timestep(ctl, cache, clim, &met0, &met1, atm, t, dd);
133
134 /* Write output... */
135 mptrac_write_output(dirname, ctl, met0, met1, atm, t);
136 }
137
138 /* ------------------------------------------------------------
139 Finalize model run...
140 ------------------------------------------------------------ */
141
142 /* Flush output buffer... */
143 fflush(NULL);
144
145 /* Report problem size... */
146 LOG(1, "SIZE_NP = %d", atm->np);
147 LOG(1, "SIZE_MPI_TASKS = %d", size);
148 LOG(1, "SIZE_OMP_THREADS = %d", omp_get_max_threads());
149
150 /* Report memory usage... */
151 LOG(1, "MEMORY_ATM = %g MByte", sizeof(atm_t) / 1024. / 1024.);
152 LOG(1, "MEMORY_CACHE = %g MByte", sizeof(cache_t) / 1024. / 1024.);
153 LOG(1, "MEMORY_CLIM = %g MByte", sizeof(clim_t) / 1024. / 1024.);
154 LOG(1, "MEMORY_METEO = %g MByte", sizeof(met_t) / 1024. / 1024.);
155
156 /* Free memory... */
157 mptrac_free(ctl, cache, clim, met0, met1, atm, dd);
158
159
160 /* Report timers... */
163 }
164
165 /* Finalize MPI... */
166#ifdef MPI
167 MPI_Finalize();
168#endif
169
170 return EXIT_SUCCESS;
171}
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:5108
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:6466
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:5316
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:5194
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_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:5335
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:6830
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
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:5161
int dd_init(ctl_t *ctl, dd_t *dd, atm_t *atm)
Initializes domain decomposition for parallel processing.
#define LEN
Maximum length of ASCII data lines.
Definition: mptrac.h:298
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2043
#define WARN(...)
Print a warning message with contextual information.
Definition: mptrac.h:2010
#define START_TIMERS
Starts a timer for tracking.
Definition: mptrac.h:2142
#define PRINT_TIMERS
Print the current state of all timers.
Definition: mptrac.h:2102
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: mptrac.h:1973
#define STOP_TIMERS
Stop the current timer.
Definition: mptrac.h:2157
Air parcel data.
Definition: mptrac.h:3292
int np
Number of air parcels.
Definition: mptrac.h:3295
Cache data structure.
Definition: mptrac.h:3347
Climatological data.
Definition: mptrac.h:3487
Control parameters.
Definition: mptrac.h:2264
int direction
Direction flag (1=forward calculation, -1=backward calculation).
Definition: mptrac.h:2574
int dd
Domain decomposition (0=no, 1=yes, with 2x2 if not specified).
Definition: mptrac.h:3268
double t_stop
Stop time of simulation [s].
Definition: mptrac.h:2580
double dt_mod
Time step of simulation [s].
Definition: mptrac.h:2583
double t_start
Start time of simulation [s].
Definition: mptrac.h:2577
Domain decomposition data structure.
Definition: mptrac.h:3720
int init
Shows if domain decomposition was initialized.
Definition: mptrac.h:3779
Meteo data structure.
Definition: mptrac.h:3546
double lon[EX]
Longitudes [deg].
Definition: mptrac.h:3564
Here is the call graph for this function: