read_checkpoint.c 5.73 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1 2 3 4
/*------------------------------------------------------------------------
 * Copyright (C) 2011 For the list of authors, see file AUTHORS.
 *
 * This file is part of SOFI3D.
5
 *
Tilman Steinweg's avatar
Tilman Steinweg committed
6 7 8
 * SOFI3D is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
9
 *
Tilman Steinweg's avatar
Tilman Steinweg committed
10 11 12 13
 * SOFI3D is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14
 *
Tilman Steinweg's avatar
Tilman Steinweg committed
15
 * You should have received a copy of the GNU General Public License
16
 * along with SOFI3D. See file COPYING and/or
Tilman Steinweg's avatar
Tilman Steinweg committed
17 18 19 20 21 22 23
  * <http://www.gnu.org/licenses/gpl-2.0.html>.
--------------------------------------------------------------------------*/
/* ----------------------------------------------------------------------
 * reads checkpoint file for the continuation of a simulation
 ----------------------------------------------------------------------*/
#include "fd.h"

24 25 26 27 28 29 30
void read_checkpoint(int nx1, int nx2, int ny1, int ny2, int nz1, int nz2, float *** vx, float *** vy, float *** vz,
                     float *** sxx, float *** syy, float *** szz, float *** sxy, float *** syz, float *** sxz,
		     float *** rxx, float *** ryy,float *** rzz, float *** rxy, float *** ryz, float *** rxz,
		     float *** psi_sxx_x, float *** psi_sxy_x, float *** psi_sxz_x, float *** psi_sxy_y,
		     float *** psi_syy_y, float *** psi_syz_y, float *** psi_sxz_z, float *** psi_syz_z, float *** psi_szz_z,
                     float *** psi_vxx, float *** psi_vyx, float *** psi_vzx, float *** psi_vxy, float *** psi_vyy, float *** psi_vzy,
                     float *** psi_vxz, float *** psi_vyz, float *** psi_vzz) {
Tilman Steinweg's avatar
Tilman Steinweg committed
31 32 33 34 35 36

	int i,j,k;
	char myid[5];
	FILE *fp;
	char checkptfile[STRING_SIZE];
	extern int MYID;
37 38
	extern int ABS_TYPE, NX,NY,NZ,FW,POS[4],NPROCX,NPROCY,NPROCZ,FREE_SURF;
	extern int L;
Tilman Steinweg's avatar
Tilman Steinweg committed
39
	extern char  CHECKPTFILE[STRING_SIZE];
40
	
Tilman Steinweg's avatar
Tilman Steinweg committed
41 42 43 44 45 46 47 48 49


	sprintf(checkptfile,"%s",CHECKPTFILE);
	sprintf(myid,".%d",MYID);
	strcat(checkptfile,myid);



	fp=fopen(checkptfile,"rb");
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
	if (fp==NULL) {
		err("CHECKPTFILE can't be opened !");
	}


	for (j=ny1; j<=ny2; j++) {
		for (i=nx1; i<=nx2; i++) {
			for (k=nz1; k<=nz2; k++) {

				fread(&vx[j][i][k],sizeof(float),1,fp);
				fread(&vy[j][i][k],sizeof(float),1,fp);
				fread(&vz[j][i][k],sizeof(float),1,fp);
				fread(&sxx[j][i][k],sizeof(float),1,fp);
				fread(&syy[j][i][k],sizeof(float),1,fp);
				fread(&szz[j][i][k],sizeof(float),1,fp);
				fread(&sxy[j][i][k],sizeof(float),1,fp);
				fread(&syz[j][i][k],sizeof(float),1,fp);
				fread(&sxz[j][i][k],sizeof(float),1,fp);
			}
		}
	}

	
	if (L) {
		for (j=1; j<=NY; j++) {
			for (i=1; i<=NX; i++) {
				for (k=1; k<=NZ; k++) {
					fread(&rxx[j][i][k],sizeof(float),1,fp);
					fread(&ryy[j][i][k],sizeof(float),1,fp);
					fread(&rzz[j][i][k],sizeof(float),1,fp);
					fread(&rxy[j][i][k],sizeof(float),1,fp);
					fread(&ryz[j][i][k],sizeof(float),1,fp);
					fread(&rxz[j][i][k],sizeof(float),1,fp);
				}
			}
		}
	}
Tilman Steinweg's avatar
Tilman Steinweg committed
87
	
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
	
	
	if (ABS_TYPE == 1) {

		if (POS[1]==0) {
			for (j=1; j<=NY; j++) {
				for (i=1; i<=FW; i++) {
					for (k=1; k<=NZ; k++) {
						fread(&psi_sxx_x[j][i][k],sizeof(float),1,fp);
						fread(&psi_sxy_x[j][i][k],sizeof(float),1,fp);
						fread(&psi_sxz_x[j][i][k],sizeof(float),1,fp);
						fread(&psi_vxx[j][i][k],sizeof(float),1,fp);
						fread(&psi_vyx[j][i][k],sizeof(float),1,fp);
						fread(&psi_vzx[j][i][k],sizeof(float),1,fp);
					}
				}
			}
		}

		if (POS[1]==NPROCX-1) {
			for (j=1; j<=NY; j++) {
				for (i=FW+1; i<=2*FW; i++) {
					for (k=1; k<=NZ; k++) {
						fread(&psi_sxx_x[j][i][k],sizeof(float),1,fp);
						fread(&psi_sxy_x[j][i][k],sizeof(float),1,fp);
						fread(&psi_sxz_x[j][i][k],sizeof(float),1,fp);
						fread(&psi_vxx[j][i][k],sizeof(float),1,fp);
						fread(&psi_vyx[j][i][k],sizeof(float),1,fp);
						fread(&psi_vzx[j][i][k],sizeof(float),1,fp);
					}
				}
			}
		}
Tilman Steinweg's avatar
Tilman Steinweg committed
121

122 123 124 125 126 127 128 129 130 131 132 133
		if (POS[2]==0 && FREE_SURF==0) {
			for (j=1; j<=FW; j++) {
				for (i=1; i<=NX; i++) {
					for (k=1; k<=NZ; k++) {
						fread(&psi_sxy_y[j][i][k],sizeof(float),1,fp);
						fread(&psi_syy_y[j][i][k],sizeof(float),1,fp);
						fread(&psi_syz_y[j][i][k],sizeof(float),1,fp);
						fread(&psi_vxy[j][i][k],sizeof(float),1,fp);
						fread(&psi_vyy[j][i][k],sizeof(float),1,fp);
						fread(&psi_vzy[j][i][k],sizeof(float),1,fp);
					}
				}
Tilman Steinweg's avatar
Tilman Steinweg committed
134 135
			}
		}
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
		if (POS[2]==NPROCY-1) {
			for (j=FW+1; j<=2*FW; j++) {
				for (i=1; i<=NX; i++) {
					for (k=1; k<=NZ; k++) {
						fread(&psi_sxy_y[j][i][k],sizeof(float),1,fp);
						fread(&psi_syy_y[j][i][k],sizeof(float),1,fp);
						fread(&psi_syz_y[j][i][k],sizeof(float),1,fp);
						fread(&psi_vxy[j][i][k],sizeof(float),1,fp);
						fread(&psi_vyy[j][i][k],sizeof(float),1,fp);
						fread(&psi_vzy[j][i][k],sizeof(float),1,fp);
					}
				}
			}
		}

		if (POS[3]==0) {
			for (j=1; j<=NY; j++) {
				for (i=1; i<=NX; i++) {
					for (k=1; k<=FW; k++) {
						fread(&psi_sxz_z[j][i][k],sizeof(float),1,fp);
						fread(&psi_syz_z[j][i][k],sizeof(float),1,fp);
						fread(&psi_szz_z[j][i][k],sizeof(float),1,fp);
						fread(&psi_vxz[j][i][k],sizeof(float),1,fp);
						fread(&psi_vyz[j][i][k],sizeof(float),1,fp);
						fread(&psi_vzz[j][i][k],sizeof(float),1,fp);
					}
				}
			}
		}
		if (POS[3]==NPROCZ-1) {
			for (j=1; j<=NY; j++) {
				for (i=1; i<=NX; i++) {
					for (k=FW+1; k<=2*FW; k++) {
						fread(&psi_sxz_z[j][i][k],sizeof(float),1,fp);
						fread(&psi_syz_z[j][i][k],sizeof(float),1,fp);
						fread(&psi_szz_z[j][i][k],sizeof(float),1,fp);
						fread(&psi_vxz[j][i][k],sizeof(float),1,fp);
						fread(&psi_vyz[j][i][k],sizeof(float),1,fp);
						fread(&psi_vzz[j][i][k],sizeof(float),1,fp);
					}
				}
			}
		}

Tilman Steinweg's avatar
Tilman Steinweg committed
180 181 182 183 184
	}

	fclose(fp);

}