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 FILE *dirlist;
46
47 char dirname[LEN], filename[2 * LEN];
48
49 int ntask = -1, rank = 0, size = 1;
50
51 /* Initialize MPI... */
52#ifdef MPI
53 MPI_Init(&argc, &argv);
54 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
55 MPI_Comm_size(MPI_COMM_WORLD, &size);
56#endif
57
58 /* Check arguments... */
59 if (argc < 4)
60 ERRMSG("Give parameters: <dirlist> <ctl> <atm_in>");
61
62 /* Open directory list... */
63 if (!(dirlist = fopen(argv[1], "r")))
64 ERRMSG("Cannot open directory list!");
65
66 /* Loop over directories... */
67 while (fscanf(dirlist, "%4999s", dirname) != EOF) {
68
69 /* MPI parallelization... */
70 if ((++ntask) % size != rank)
71 continue;
72
73 /* Write info... */
74 LOG(1, "Parallelization: ntask= %d | rank= %d | size= %d",
75 ntask, rank, size);
76
77 /* ------------------------------------------------------------
78 Initialize model run...
79 ------------------------------------------------------------ */
80
81 /* Start timers... */
83
84 /* Allocate memory... */
85 mptrac_alloc(&ctl, &cache, &clim, &met0, &met1, &atm);
86
87 /* Read control parameters... */
88 sprintf(filename, "%s/%s", dirname, argv[2]);
89 mptrac_read_ctl(filename, argc, argv, ctl);
90
91 /* Read climatological data... */
92 mptrac_read_clim(ctl, clim);
93
94 /* Read atmospheric data... */
95 sprintf(filename, "%s/%s", dirname, argv[3]);
96 if (!mptrac_read_atm(filename, ctl, atm))
97 ERRMSG("Cannot open file!");
98
99 /* Initialize MPTRAC... */
100 mptrac_init(ctl, cache, clim, atm, ntask);
101
102 /* ------------------------------------------------------------
103 Loop over timesteps...
104 ------------------------------------------------------------ */
105
106 /* Loop over timesteps... */
107 for (double t = ctl->t_start;
108 ctl->direction * (t - ctl->t_stop) < ctl->dt_mod;
109 t += ctl->direction * ctl->dt_mod) {
110
111 /* Adjust length of final time step... */
112 if (ctl->direction * (t - ctl->t_stop) > 0)
113 t = ctl->t_stop;
114
115 /* Get meteo data... */
116 mptrac_get_met(ctl, clim, t, &met0, &met1);
117
118 /* Check time step... */
119 if (ctl->dt_mod > fabs(met0->lon[1] - met0->lon[0]) * 111132. / 150.)
120 WARN("Violation of CFL criterion! Check DT_MOD!");
121
122 /* Run a single time step... */
123 mptrac_run_timestep(ctl, cache, clim, &met0, &met1, atm, t);
124
125 /* Write output... */
126 mptrac_write_output(dirname, ctl, met0, met1, atm, t);
127 }
128
129 /* ------------------------------------------------------------
130 Finalize model run...
131 ------------------------------------------------------------ */
132
133 /* Flush output buffer... */
134 fflush(NULL);
135
136 /* Report problem size... */
137 LOG(1, "SIZE_NP = %d", atm->np);
138 LOG(1, "SIZE_MPI_TASKS = %d", size);
139 LOG(1, "SIZE_OMP_THREADS = %d", omp_get_max_threads());
140
141 /* Report memory usage... */
142 LOG(1, "MEMORY_ATM = %g MByte", sizeof(atm_t) / 1024. / 1024.);
143 LOG(1, "MEMORY_CACHE = %g MByte", sizeof(cache_t) / 1024. / 1024.);
144 LOG(1, "MEMORY_CLIM = %g MByte", sizeof(clim_t) / 1024. / 1024.);
145 LOG(1, "MEMORY_METEO = %g MByte", sizeof(met_t) / 1024. / 1024.);
146
147 /* Free memory... */
148 mptrac_free(ctl, cache, clim, met0, met1, atm);
149
150 /* Report timers... */
153 }
154
155 /* Finalize MPI... */
156#ifdef MPI
157 MPI_Finalize();
158#endif
159
160 return EXIT_SUCCESS;
161}
void mptrac_alloc(ctl_t **ctl, cache_t **cache, clim_t **clim, met_t **met0, met_t **met1, atm_t **atm)
Allocates and initializes memory resources for MPTRAC.
Definition: mptrac.c:4187
void mptrac_get_met(ctl_t *ctl, clim_t *clim, const double t, met_t **met0, met_t **met1)
Retrieves meteorological data for the specified time.
Definition: mptrac.c:4260
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:4381
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
Definition: mptrac.c:4471
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:4400
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:5767
void mptrac_free(ctl_t *ctl, cache_t *cache, clim_t *clim, met_t *met0, met_t *met1, atm_t *atm)
Frees memory resources allocated for MPTRAC.
Definition: mptrac.c:4234
void mptrac_run_timestep(ctl_t *ctl, cache_t *cache, clim_t *clim, met_t **met0, met_t **met1, atm_t *atm, double t)
Executes a single timestep of the MPTRAC model simulation.
Definition: mptrac.c:5418
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:4531
#define LEN
Maximum length of ASCII data lines.
Definition: mptrac.h:241
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:1904
#define WARN(...)
Print a warning message with contextual information.
Definition: mptrac.h:1871
#define START_TIMERS
Starts a timer for tracking.
Definition: mptrac.h:2003
#define PRINT_TIMERS
Print the current state of all timers.
Definition: mptrac.h:1963
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: mptrac.h:1834
#define STOP_TIMERS
Stop the current timer.
Definition: mptrac.h:2018
Air parcel data.
Definition: mptrac.h:3146
int np
Number of air parcels.
Definition: mptrac.h:3149
Cache data structure.
Definition: mptrac.h:3174
Climatological data.
Definition: mptrac.h:3314
Control parameters.
Definition: mptrac.h:2158
int direction
Direction flag (1=forward calculation, -1=backward calculation).
Definition: mptrac.h:2453
double t_stop
Stop time of simulation [s].
Definition: mptrac.h:2459
double dt_mod
Time step of simulation [s].
Definition: mptrac.h:2462
double t_start
Start time of simulation [s].
Definition: mptrac.h:2456
Meteo data structure.
Definition: mptrac.h:3373
double lon[EX]
Longitude [deg].
Definition: mptrac.h:3391
Here is the call graph for this function: