xref: /phasta/phSolver/common/d2wall.c (revision 93b99f60430dd206491e8c956b118d7feecf22ca)
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 nfields;
29     int numparts;
30     int irank;
31     int nprocs;
32 
33     /*  Retrieve and compute the parameters required for SyncIO */
34     numparts = workfc.numpe;
35     irank = *pid; /* workfc.myrank; */
36     nprocs = workfc.numpe;
37 
38     /* Calculate number of parts each proc deal with and where it start and end ... */
39     int nppp = numparts/nprocs;/* nppp : Number of parts per proc ... */
40     assert(nppp==1);
41     int startpart = irank * nppp +1;/* Part id from which I (myrank) start ... */
42     int endpart = startpart + nppp - 1;/* Part id to which I (myrank) end ... */
43 
44     phio_fp handle;
45     char filename[255],path[255];
46     memset((void*)filename,0,255);
47     *foundd2wall = 0;
48     /* First we try to read dwal from the restart files. */
49 
50     if( outpar.input_mode == -1 )
51       streamio_setup_read(&handle, streamio_get_gr());
52     else if( outpar.input_mode == 0 )
53       posixio_setup(&handle, 'r');
54     else if( outpar.input_mode > 0 )
55       syncio_setup_read(outpar.nsynciofiles, &handle);
56     phio_constructName(handle,"restart",filename);
57     phio_appendInt(filename, timdat.lstep);
58     phio_openfile(filename, handle);
59 
60     int i;
61     for ( i = 0; i < nppp; i++) { /*This loop is useful only if several parts per processor*/
62       nitems = 2;
63       phio_readheader(handle, "dwal", (void*)iarray, &nitems, "double", phasta_iotype);
64 
65       if (iarray[0] == (*numnp)) {
66         if (irank==0) {
67           printf("d2wall field found in %s\n",filename);
68         }
69         *foundd2wall = 1;
70         isize = (*numnp);
71         phio_readdatablock(handle, "dwal", (void*)(array1), &isize, "double", phasta_iotype );
72       }
73       else { /*d2wall fields was not found in the restart file*/
74         *foundd2wall = 0;
75         if (irank==0) {
76           printf("d2wall field not found in %s - trying d2wall files now\n",filename);
77         }
78       }
79     }
80     phio_closefile(handle);
81 
82     if (irank==0) {
83       printf("\n");
84     }
85 }
86