xref: /phasta/phSolver/common/d2wall.c (revision 08d2ac07b0519855627ebfd43221a09a84cee7bb)
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     /* First we try to read dwal from the restart files. */
51 
52     stream* grstream;
53     if( nfiles == -1 )
54       streamio_setup(grstream, &handle);
55     else if( nfiles == 0 )
56       posixio_setup(&handle, 'r');
57     else if( nfiles > 0 )
58       syncio_setup_read(nfiles, &handle);
59     phio_constructName(handle,"restart",filename);
60     phio_appendInt(filename, timdat.lstep);
61     phio_openfile(filename, handle);
62 
63     int i;
64     for ( i = 0; i < nppp; i++) { /*This loop is useful only if several parts per processor*/
65       nitems = 2;
66       phio_readheader(handle, "dwal", (void*)iarray, &nitems, "double", phasta_iotype);
67 
68       if (iarray[0] == (*numnp)) {
69         if (irank==0) {
70           printf("d2wall field found in %s\n",filename);
71         }
72         *foundd2wall = 1;
73         isize = (*numnp);
74         phio_readdatablock(handle, "dwal", (void*)(array1), &isize, "double", phasta_iotype );
75       }
76       else { /*d2wall fields was not found in the restart file*/
77         *foundd2wall = 0;
78         if (irank==0) {
79           printf("d2wall field not found in %s - trying d2wall files now\n",filename);
80         }
81       }
82     }
83     phio_closefile(handle);
84 
85     if (irank==0) {
86       printf("\n");
87     }
88 }
89