xref: /phasta/phSolver/common/d2wall.c (revision e81a6dc1f924882a3384f8e849eaba3a3575cfa5)
1 #include <stdlib.h>
2 #include <FCMangle.h>
3 #include <new_interface.h>
4 #include <stdio.h>
5 #include <string.h> //memset
6 #include <assert.h>
7 #include "common_c.h"
8 #include "phastaIO.h"
9 #include "phIO.h"
10 #include "syncio.h"
11 #include "posixio.h"
12 #include "streamio.h"
13 #include "setsyncioparam.h"
14 
15 void
16 read_d2wall(  int* pid,
17               int* numnp,
18               double* array1,
19               int* foundd2wall ) {
20     int isize, nitems;
21     int iarray[10];
22     int j;
23     for ( j = 0; j < 10; j++) {
24        //Initialize iarray to 0 so that we can assess the result of readheader
25        iarray[j] = 0;
26     }
27 
28     int nfiles;
29     int nfields;
30     int numparts;
31     int irank;
32     int nprocs;
33 
34     //  Retrieve and compute the parameters required for SyncIO
35     nfiles = outpar.nsynciofiles;
36     numparts = workfc.numpe;
37     irank = *pid; // workfc.myrank;
38     nprocs = workfc.numpe;
39 
40     // Calculate number of parts each proc deal with and where it start and end ...
41     int nppp = numparts/nprocs;// nppp : Number of parts per proc ...
42     assert(nppp==1);
43     int startpart = irank * nppp +1;// Part id from which I (myrank) start ...
44     int endpart = startpart + nppp - 1;// Part id to which I (myrank) end ...
45 
46     phio_fp handle;
47     char filename[255],path[255];
48     memset((void*)filename,0,255);
49     *foundd2wall = 0;
50     ////////////////////////////////////////////////////
51     // First we try to read dwal from the restart files.
52     ////////////////////////////////////////////////////
53 
54     phio_format fmt = 0;
55     stream* grstream;
56     if( nfiles == -1 ) {
57       fmt = PHIO_STREAM;
58       streamio_setup(grstream, &handle);
59     } else if( nfiles == 0 ) {
60       fmt = PHIO_POSIX;
61       posixio_setup(&handle, 'r');
62     } else if( nfiles == 1 ) {
63       fmt = PHIO_SYNC;
64       syncio_setup_read(nfiles, &handle);
65     }
66     phio_constructName(fmt,"restart",filename);
67     phio_appendInt(filename, timdat.lstep);
68     phio_openfile(filename, handle);
69 
70     int i;
71     for ( i = 0; i < nppp; i++) { //This loop is useful only if several parts per processor
72       nitems = 2;
73       phio_readheader(handle, "dwal", (void*)iarray, &nitems, "double", phasta_iotype);
74 
75       if (iarray[0] == (*numnp)) {
76         if (irank==0) {
77           printf("d2wall field found in %s\n",filename);
78         }
79         *foundd2wall = 1;
80         isize = (*numnp);
81         phio_readdatablock(handle, "dwal", (void*)(array1), &isize, "double", phasta_iotype );
82       }
83       else { //d2wall fields was not found in the restart file
84         *foundd2wall = 0;
85         if (irank==0) {
86           printf("d2wall field not found in %s - trying d2wall files now\n",filename);
87         }
88       }
89     }
90     phio_closefile(handle);
91 
92     if (irank==0) {
93       printf("\n");
94     }
95 }
96