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