source: CIVL/examples/omp/HydroC/parametres.c@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 11.2 KB
RevLine 
[70c4392]1/*
2 A simple 2D hydro code
3 (C) Romain Teyssier : CEA/IRFU -- original F90 code
4 (C) Pierre-Francois Lavallee : IDRIS -- original F90 code
5 (C) Guillaume Colin de Verdiere : CEA/DAM -- for the C version
6 (C) Adèle Villiermet : CINES -- for FTI integration
7*/
8/*
9
10This software is governed by the CeCILL license under French law and
11abiding by the rules of distribution of free software. You can use,
12modify and/ or redistribute the software under the terms of the CeCILL
13license as circulated by CEA, CNRS and INRIA at the following URL
14"http://www.cecill.info".
15
16As a counterpart to the access to the source code and rights to copy,
17modify and redistribute granted by the license, users are provided only
18with a limited warranty and the software's author, the holder of the
19economic rights, and the successive licensors have only limited
20liability.
21
22In this respect, the user's attention is drawn to the risks associated
23with loading, using, modifying and/or developing or reproducing the
24software by the user in light of its specific status of free software,
25that may mean that it is complicated to manipulate, and that also
26therefore means that it is reserved for developers and experienced
27professionals having in-depth computer knowledge. Users are therefore
28encouraged to load and test the software's suitability as regards their
29requirements in conditions enabling the security of their systems and/or
30data to be ensured and, more generally, to use and operate it in the
31same conditions as regards security.
32
33The fact that you are presently reading this means that you have had
34knowledge of the CeCILL license and that you accept its terms.
35
36*/
37
38#ifdef MPI
39#include <mpi.h>
40#if FTI>0
41#include <fti.h>
42#endif
43#endif
44
45#include <stdio.h>
46#include <stdlib.h>
47#include <unistd.h>
48#include <string.h>
49#include <values.h>
50
51#include "parametres.h"
52#include "SplitSurface.h"
53static void
54usage(void) {
55 fprintf(stderr, "options of hydro");
56 fprintf(stderr, "--help");
57 fprintf(stderr, "-i input");
58 fprintf(stderr, "-v :: to increase verbosity");
59 fprintf(stderr, "-c :: configuration file for fti");
60 fprintf(stderr, "------------------------------------");
61 exit(1);
62}
63
64static void
65default_values(hydroparam_t * H) {
66
67 // Default values should be given
68 H->prt = 0; // no printing of internal arrays
69 H->nx = 20;
70 H->ny = 20;
71 H->globnx = H->nx;
72 H->globny = H->ny;
73 H->nproc = 1;
74 H->mype = 0;
75 H->box[XMIN_BOX] = -1;
76 H->box[XMAX_BOX] = -1;
77 H->box[YMIN_BOX] = -1;
78 H->box[YMAX_BOX] = -1;
79 // -1 means its is a boundary of the global domain
80 H->box[UP_BOX] = -1;
81 H->box[DOWN_BOX] = -1;
82 H->box[LEFT_BOX] = -1;
83 H->box[RIGHT_BOX] = -1;
84
85 H->nxystep = -1; // default=one row/column processed per call
86 H->nvar = IP + 1;
87 H->dx = 1.0;
88 H->t = 0.0;
89 H->nstep = 0;
90 H->tend = 0.0;
91 H->gamma = 1.4;
92 H->courant_factor = one / two;
93 H->smallc = 1e-10;
94 H->smallr = 1e-10;
95 H->niter_riemann = 10;
96 H->iorder = 2;
97 H->slope_type = 1.;
98
99 // strcpy(H->scheme, "muscl");
100 H->scheme = HSCHEME_MUSCL;
101 H->boundary_right = 1;
102 H->boundary_left = 1;
103 H->boundary_up = 1;
104 H->boundary_down = 1;
105 H->noutput = 0;
106 H->nstepmax = INT_MAX;
107 H->dtoutput = 0.0;
108 H->testCase = 0;
109}
110
111
112static void
113keyval(char *buffer, char **pkey, char **pval) {
114 char *ptr;
115 *pkey = buffer;
116 *pval = buffer;
117
118 // kill the newline
119 *pval = strchr(buffer, '\n');
120 if (*pval)
121 **pval = 0;
122
123 // suppress leading whites or tabs
124 while ((**pkey == ' ') || (**pkey == '\t'))
125 (*pkey)++;
126 *pval = strchr(buffer, '=');
127 if (*pval) {
128 **pval = 0;
129 (*pval)++;
130 }
131 // strip key from white or tab
132 while ((ptr = strchr(*pkey, ' ')) != NULL) {
133 *ptr = 0;
134 }
135 while ((ptr = strchr(*pkey, '\t')) != NULL) {
136 *ptr = 0;
137 }
138}
139
140static void
141process_input(char *datafile, hydroparam_t * H)
142{
143 FILE *fd = NULL;
144 char buffer[1024];
145 char *pval, *pkey;
146 char *realFmt;
147
148 if (sizeof(real_t) == sizeof(double)) {
149 realFmt = "%lf";
150 } else {
151 realFmt = "%f";
152 }
153
154 fd = fopen(datafile, "r");
155 if (fd == NULL) {
156 fprintf(stderr, "can't read input file\n");
157 exit(1);
158 }
159 while (fgets(buffer, 1024, fd) == buffer) {
160 keyval(buffer, &pkey, &pval);
161
162 // int parameters
163 if (strcmp(pkey, "nstepmax") == 0) {
164 sscanf(pval, "%d", &H->nstepmax);
165 continue;
166 }
167 if (strcmp(pkey, "prt") == 0) {
168 sscanf(pval, "%d", &H->prt);
169 continue;
170 }
171 if (strcmp(pkey, "nx") == 0) {
172 sscanf(pval, "%d", &H->nx);
173 continue;
174 }
175 if (strcmp(pkey, "ny") == 0) {
176 sscanf(pval, "%d", &H->ny);
177 continue;
178 }
179 if (strcmp(pkey, "nxystep") == 0) {
180 sscanf(pval, "%d", &H->nxystep);
181 continue;
182 }
183 if (strcmp(pkey, "boundary_left") == 0) {
184 sscanf(pval, "%d", &H->boundary_left);
185 continue;
186 }
187 if (strcmp(pkey, "boundary_right") == 0) {
188 sscanf(pval, "%d", &H->boundary_right);
189 continue;
190 }
191 if (strcmp(pkey, "boundary_up") == 0) {
192 sscanf(pval, "%d", &H->boundary_up);
193 continue;
194 }
195 if (strcmp(pkey, "boundary_down") == 0) {
196 sscanf(pval, "%d", &H->boundary_down);
197 continue;
198 }
199 if (strcmp(pkey, "niter_riemann") == 0) {
200 sscanf(pval, "%d", &H->niter_riemann);
201 continue;
202 }
203 if (strcmp(pkey, "noutput") == 0) {
204 sscanf(pval, "%d", &H->noutput);
205 continue;
206 }
207 if (strcmp(pkey, "iorder") == 0) {
208 sscanf(pval, "%d", &H->iorder);
209 continue;
210 }
211 // float parameters
212 if (strcmp(pkey, "slope_type") == 0) {
213 sscanf(pval, realFmt, &H->slope_type);
214 continue;
215 }
216 if (strcmp(pkey, "tend") == 0) {
217 sscanf(pval, realFmt, &H->tend);
218 continue;
219 }
220 if (strcmp(pkey, "dx") == 0) {
221 sscanf(pval, realFmt, &H->dx);
222 continue;
223 }
224 if (strcmp(pkey, "courant_factor") == 0) {
225 sscanf(pval, realFmt, &H->courant_factor);
226 continue;
227 }
228 if (strcmp(pkey, "smallr") == 0) {
229 sscanf(pval, realFmt, &H->smallr);
230 continue;
231 }
232 if (strcmp(pkey, "smallc") == 0) {
233 sscanf(pval, realFmt, &H->smallc);
234 continue;
235 }
236 if (strcmp(pkey, "dtoutput") == 0) {
237 sscanf(pval, realFmt, &H->dtoutput);
238 continue;
239 }
240 if (strcmp(pkey, "testcase") == 0) {
241 sscanf(pval, "%d", &H->testCase);
242 continue;
243 }
244 // string parameter
245 if (strcmp(pkey, "scheme") == 0) {
246 if (strcmp(pval, "muscl") == 0) {
247 H->scheme = HSCHEME_MUSCL;
248 } else if (strcmp(pval, "plmde") == 0) {
249 H->scheme = HSCHEME_PLMDE;
250 } else if (strcmp(pval, "collela") == 0) {
251 H->scheme = HSCHEME_COLLELA;
252 } else {
253 fprintf(stderr, "Scheme name <%s> is unknown, should be one of [muscl,plmde,collela]\n", pval);
254 exit(1);
255 }
256 continue;
257 }
258 }
259 // exit(0);
260}
261
262void
263process_args(int argc, char **argv, hydroparam_t * H) {
264 int n = 1;
265 char donnees[512];
266 char config[512];
267
268#if FTI==0
269 default_values(H);
270
271#ifdef MPI
272 MPI_Comm_size(MPI_COMM_WORLD, &H->nproc);
273 MPI_Comm_rank(MPI_COMM_WORLD, &H->mype);
274#else
275 H->nproc = 1;
276 H->mype = 0;
277#endif
278 while (n < argc) {
279 if (strcmp(argv[n], "--help") == 0) {
280 usage();
281 n++;
282 continue;
283 }
284 if (strcmp(argv[n], "-v") == 0) {
285 n++;
286 H->prt++;
287 continue;
288 }
289 if (strcmp(argv[n], "-i") == 0) {
290 n++;
291 strncpy(donnees, argv[n], 512);
292 donnees[511] = 0; // security
293 n++;
294 continue;
295 }
296 if (strcmp(argv[n], "-c") == 0) {
297 n++;
298 fprintf(stderr, "FTI is not available\n");
299 n++;
300 continue;
301 }
302 fprintf(stderr, "Key %s is unkown\n", argv[n]);
303 n++;
304 }
305 if (donnees != NULL) {
306 process_input(donnees, H);
307 } else {
308 fprintf(stderr, "Option -i is missing\n");
309 exit(1);
310 }
311#endif
312#if FTI>0
313 H->prt=0;
314 default_values(H);
315
316 while (n < argc) {
317 if (strcmp(argv[n], "--help") == 0) {
318 usage();
319 n++;
320 continue;
321 }
322 if (strcmp(argv[n], "-v") == 0) {
323 n++;
324 H->prt++;
325 continue;
326 }
327 if (strcmp(argv[n], "-i") == 0) {
328 n++;
329 strncpy(donnees, argv[n], 512);
330 donnees[511] = 0; // security
331 n++;
332 continue;
333 }
334 if (strcmp(argv[n], "-c") == 0) {
335 n++;
336 strncpy(config, argv[n], 512);
337 config[511] = 0; // security
338 n++;
339 continue;
340 }
341 fprintf(stderr, "Key %s is unkown\n", argv[n]);
342 n++;
343 }
344 if (config != NULL) {
345#ifdef MPI
346 //FTI initialization
347 FTI_Init(config, MPI_COMM_WORLD);
348#else
349 fprintf(stderr, "FTI need MPI\n", argv[n]);
350#endif
351 } else {
352 fprintf(stderr, "Option -c is missing\n");
353 exit(1);
354 }
355 default_values(H);
356
357#ifdef MPI
358 MPI_Comm_size(FTI_COMM_WORLD, &H->nproc);
359 MPI_Comm_rank(FTI_COMM_WORLD, &H->mype);
360#else
361 H->nproc = 1;
362 H->mype = 0;
363#endif
364 if (donnees != NULL) {
365 process_input(donnees, H);
366 } else {
367 fprintf(stderr, "Option -i is missing\n");
368 exit(1);
369 }
370#endif
371
372 H->globnx = H->nx;
373 H->globny = H->ny;
374 H->box[XMIN_BOX] = 0;
375 H->box[XMAX_BOX] = H->nx;
376 H->box[YMIN_BOX] = 0;
377 H->box[YMAX_BOX] = H->ny;
378
379#ifdef MPI
380 if (H->nproc > 1) {
381#if FTI==0
382 MPI_Barrier(MPI_COMM_WORLD);
383#endif
384#if FTI>0
385 MPI_Barrier(FTI_COMM_WORLD);
386#endif
387 // first pass : determin our actual sub problem size
388 CalcSubSurface(0, H->globnx, 0, H->globny, 0, H->nproc - 1, 0, H->box, H->mype, 0);
389 // second pass : determin our neighbours
390 CalcSubSurface(0, H->globnx, 0, H->globny, 0, H->nproc - 1, 0, H->box, H->mype, 1);
391
392 H->nx = H->box[XMAX_BOX] - H->box[XMIN_BOX];
393 H->ny = H->box[YMAX_BOX] - H->box[YMIN_BOX];
394 printf("[%4d/%4d] x=%4d X=%4d y=%4d Y=%4d / u=%4d d=%4d l=%4d r=%4d \n", H->mype, H->nproc, H->box[XMIN_BOX], H->box[XMAX_BOX], H->box[YMIN_BOX], H->box[YMAX_BOX], H->box[UP_BOX], H->box[DOWN_BOX], H->box[LEFT_BOX], H->box[RIGHT_BOX]);
395
396 if (H->nx <= 0) {
397 printf("Decomposition not suited for this geometry along X: increase nx or change number of procs\n");
398 }
399
400 if (H->ny <= 0) {
401 printf("Decomposition not suited for this geometry along Y: increase ny or change number of procs\n");
402 }
403
404 if (H->nx == 0 || H->ny == 0) {
405#if FTI==0
406 MPI_Abort(MPI_COMM_WORLD, 123);
407#endif
408#if FTI>0
409 MPI_Abort(FTI_COMM_WORLD, 123);
410#endif
411 }
412
413 // adapt the boundary conditions
414 if (H->box[LEFT_BOX] != -1) {
415 H->boundary_left = 0;
416 }
417 if (H->box[RIGHT_BOX] != -1) {
418 H->boundary_right = 0;
419 }
420 if (H->box[DOWN_BOX] != -1) {
421 H->boundary_down = 0;
422 }
423 if (H->box[UP_BOX] != -1) {
424 H->boundary_up = 0;
425 }
426 }
427 fflush(stdout);
428#endif
429
430 if (H->nxystep == -1) {
431 // default = full slab
432 H->nxystep = (H->nx < H->ny) ? H->nx: H->ny;
433 } else {
434 if (H->nxystep > H->nx) H->nxystep = H->nx;
435 if (H->nxystep > H->ny) H->nxystep = H->ny;
436 }
437
438 // small summary of the run conditions
439 if (H->mype == 0) {
440 printf("+-------------------+\n");
441 printf("|GlobNx=%-7d |\n", H->globnx);
442 printf("|GlobNy=%-7d |\n", H->globny);
443 printf("|nx=%-7d |\n", H->nx);
444 printf("|ny=%-7d |\n", H->ny);
445 printf("|nxystep=%-7d |\n", H->nxystep);
446 printf("|tend=%-10.3f |\n", H->tend);
447 printf("|nstepmax=%-7d |\n", H->nstepmax);
448 printf("|noutput=%-7d |\n", H->noutput);
449 printf("|dtoutput=%-10.3f|\n", H->dtoutput);
450 printf("+-------------------+\n");
451 }
452}
Note: See TracBrowser for help on using the repository browser.