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