update_p_PML.c 8.57 KB
Newer Older
tilman.metz's avatar
tilman.metz committed
1
/*-----------------------------------------------------------------------------------------
2
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
tilman.metz's avatar
tilman.metz committed
3
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
4
 * This file is part of IFOS.
tilman.metz's avatar
tilman.metz committed
5
 * 
Florian Wittkamp's avatar
Florian Wittkamp committed
6
 * IFOS is free software: you can redistribute it and/or modify
tilman.metz's avatar
tilman.metz committed
7 8 9
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
 * 
Florian Wittkamp's avatar
Florian Wittkamp committed
10
 * IFOS is distributed in the hope that it will be useful,
tilman.metz's avatar
tilman.metz committed
11 12 13 14 15
 * 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.
 * 
 * You should have received a copy of the GNU General Public License
Florian Wittkamp's avatar
Florian Wittkamp committed
16
 * along with IFOS. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
tilman.metz's avatar
tilman.metz committed
17 18 19 20 21 22 23 24 25 26
-----------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------
 *   updating stress components at gridpoints [nx1...nx2][ny1...ny2]
 *   by a staggered grid finite difference scheme of arbitrary (FDORDER) order accuracy in space
 *   and second order accuracy in time
 *
 *  ----------------------------------------------------------------------*/

#include "fd.h"

27 28 29 30 31
void update_p_PML(int nx1, int nx2, int ny1, int ny2, 	float **  vx, float ** vy, float ** sp, float ** pi, float ** absorb_coeff, float **rho, float *hc, int infoout,
		  float * K_x, float * a_x, float * b_x, float * K_x_half, float * a_x_half, float * b_x_half,
		  float * K_y, float * a_y, float * b_y, float * K_y_half, float * a_y_half, float * b_y_half, 
		  float ** psi_vxx, float ** psi_vyy, float ** psi_vxy, float ** psi_vyx){
	
tilman.metz's avatar
tilman.metz committed
32 33
	int i,j, m, fdoh, h, h1;
	float g;
34 35
	float  vxx, vyy;
	float  dhi;
tilman.metz's avatar
tilman.metz committed
36
	extern float DT, DH;
37
	extern int MYID, FDORDER, PARAMETERIZATION, FW;
tilman.metz's avatar
tilman.metz committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
        extern int FREE_SURF, BOUNDARY;
	extern int NPROCX, NPROCY, POS[3];
	extern FILE *FP;
	double time1, time2;
	
	
	dhi = DT/DH;
	fdoh = FDORDER/2;
	
	if (infoout && (MYID==0)){
		time1=MPI_Wtime();
		fprintf(FP,"\n **Message from update_p (printed by PE %d):\n",MYID);
		fprintf(FP," Updating stress components ...");
	}
	
	switch (FDORDER){
54
	
tilman.metz's avatar
tilman.metz committed
55 56
	case 2:
		for (j=ny1;j<=ny2;j++){
57
		for (i=nx1;i<=nx2;i++){
tilman.metz's avatar
tilman.metz committed
58
			vxx = (  hc[1]*(vx[j][i]  -vx[j][i-1]))*dhi;
59 60 61 62 63 64 65 66 67 68 69
			vyy = (  hc[1]*(vy[j][i]  -vy[j-1][i]))*dhi; 
			
			/* left boundary */                                         
			if((!BOUNDARY) && (POS[1]==0) && (i<=FW)){
				
				psi_vxx[j][i] = b_x[i] * psi_vxx[j][i] + a_x[i] * vxx;
				vxx = vxx / K_x[i] + psi_vxx[j][i];
			}
			
			/* right boundary */                                         
			if((!BOUNDARY) && (POS[1]==NPROCX-1) && (i>=nx2-FW+1)){
tilman.metz's avatar
tilman.metz committed
70
				
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
				h1 = (i-nx2+2*FW);
				h = i;
				
				psi_vxx[j][h1] = b_x[h1] * psi_vxx[j][h1] + a_x[h1] * vxx;
				vxx = vxx / K_x[h1] + psi_vxx[j][h1];
			}
			
			/* top boundary */                                         
			if((POS[2]==0) && (!(FREE_SURF)) && (j<=FW)){
				
				psi_vyy[j][i] = b_y[j] * psi_vyy[j][i] + a_y[j] * vyy;                                            
				vyy = vyy / K_y[j] + psi_vyy[j][i];
			}
			
			/* bottom boundary */                                         
			if((POS[2]==NPROCY-1) && (j>=ny2-FW+1)){
				
				h1 = (j-ny2+2*FW);                                        
				h = j;
				
				psi_vyy[h1][i] = b_y[h1] * psi_vyy[h1][i] + a_y[h1] * vyy;                                            
				vyy = vyy / K_y[h1] + psi_vyy[h1][i];
			}
			
			/* lambda - mu relationship*/
96
			if (PARAMETERIZATION==1){
97 98
				g = rho[j][i] * (pi[j][i] * pi[j][i]);
			}
tilman.metz's avatar
tilman.metz committed
99 100 101 102
			
			sp[j][i] += g*(vxx+vyy);
			
		}
103 104
		}
	break;
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

	case 4:
		for (j=ny1;j<=ny2;j++){
		for (i=nx1;i<=nx2;i++){
			vxx = (  hc[1]*(vx[j][i]  -vx[j][i-1])
				       + hc[2]*(vx[j][i+1]-vx[j][i-2]))*dhi;
			
                        vyy = (  hc[1]*(vy[j][i]  -vy[j-1][i])
				       + hc[2]*(vy[j+1][i]-vy[j-2][i]))*dhi; 

			/* left boundary */                                         
			if((!BOUNDARY) && (POS[1]==0) && (i<=FW)){
				
				psi_vxx[j][i] = b_x[i] * psi_vxx[j][i] + a_x[i] * vxx;
				vxx = vxx / K_x[i] + psi_vxx[j][i];             
			}

			/* right boundary */                                         
			if((!BOUNDARY) && (POS[1]==NPROCX-1) && (i>=nx2-FW+1)){
			
				h1 = (i-nx2+2*FW);
				h = i;
				
				psi_vxx[j][h1] = b_x[h1] * psi_vxx[j][h1] + a_x[h1] * vxx;
				vxx = vxx / K_x[h1] + psi_vxx[j][h1];
			}

			/* top boundary */                                         
			if((POS[2]==0) && (!(FREE_SURF)) && (j<=FW)){
				
				psi_vyy[j][i] = b_y[j] * psi_vyy[j][i] + a_y[j] * vyy;
				vyy = vyy / K_y[j] + psi_vyy[j][i];
			}
		
			/* bottom boundary */                                         
			if((POS[2]==NPROCY-1) && (j>=ny2-FW+1)){

				h1 = (j-ny2+2*FW);                                        
				h = j;
				
				psi_vyy[h1][i] = b_y[h1] * psi_vyy[h1][i] + a_y[h1] * vyy;                                            
				vyy = vyy / K_y[h1] + psi_vyy[h1][i];
			}
			
149
			if (PARAMETERIZATION==1){
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
				g = rho[j][i] * (pi[j][i] * pi[j][i]);}
			
			sp[j][i] += g*(vxx+vyy);
			
		}
		}
	break;

	case 6:
		for (j=ny1;j<=ny2;j++){
			for (i=nx1;i<=nx2;i++){
			vxx = (  hc[1]*(vx[j][i]  -vx[j][i-1])
				       + hc[2]*(vx[j][i+1]-vx[j][i-2])
				       + hc[3]*(vx[j][i+2]-vx[j][i-3]))*dhi;
			
                        vyy = (  hc[1]*(vy[j][i]  -vy[j-1][i])
				       + hc[2]*(vy[j+1][i]-vy[j-2][i])
				       + hc[3]*(vy[j+2][i]-vy[j-3][i]))*dhi; 

			/* left boundary */                                         
			if((!BOUNDARY) && (POS[1]==0) && (i<=FW)){
				
				psi_vxx[j][i] = b_x[i] * psi_vxx[j][i] + a_x[i] * vxx;
				vxx = vxx / K_x[i] + psi_vxx[j][i];
			}

			/* right boundary */                                         
			if((!BOUNDARY) && (POS[1]==NPROCX-1) && (i>=nx2-FW+1)){
			
				h1 = (i-nx2+2*FW);
				h = i;
				
				psi_vxx[j][h1] = b_x[h1] * psi_vxx[j][h1] + a_x[h1] * vxx;
				vxx = vxx / K_x[h1] + psi_vxx[j][h1]; 
			}

			/* top boundary */                                         
			if((POS[2]==0) && (!(FREE_SURF)) && (j<=FW)){
				
				psi_vyy[j][i] = b_y[j] * psi_vyy[j][i] + a_y[j] * vyy;
				vyy = vyy / K_y[j] + psi_vyy[j][i];

			}
			
			/* bottom boundary */                                         
			if((POS[2]==NPROCY-1) && (j>=ny2-FW+1)){

				h1 = (j-ny2+2*FW);                                        
				h = j;
				
				psi_vyy[h1][i] = b_y[h1] * psi_vyy[h1][i] + a_y[h1] * vyy;                                            
				vyy = vyy / K_y[h1] + psi_vyy[h1][i];
			}
			
204
			if (PARAMETERIZATION==1){
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
				g = rho[j][i] * (pi[j][i] * pi[j][i]);}
			
			sp[j][i] += g*(vxx+vyy);
			
		}
		}
	break;

	case 8:

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

			vxx = (  hc[1]*(vx[j][i]  -vx[j][i-1])
				       + hc[2]*(vx[j][i+1]-vx[j][i-2])
				       + hc[3]*(vx[j][i+2]-vx[j][i-3])
				       + hc[4]*(vx[j][i+3]-vx[j][i-4]))*dhi;
			
			vyy = (  hc[1]*(vy[j][i]  -vy[j-1][i])
				       + hc[2]*(vy[j+1][i]-vy[j-2][i])
				       + hc[3]*(vy[j+2][i]-vy[j-3][i])
				       + hc[4]*(vy[j+3][i]-vy[j-4][i]))*dhi; 

			/* left boundary */                                         
			if((!BOUNDARY) && (POS[1]==0) && (i<=FW)){
				
				psi_vxx[j][i] = b_x[i] * psi_vxx[j][i] + a_x[i] * vxx;
				vxx = vxx / K_x[i] + psi_vxx[j][i];        
			}

			/* right boundary */                                         
			if((!BOUNDARY) && (POS[1]==NPROCX-1) && (i>=nx2-FW+1)){
			
				h1 = (i-nx2+2*FW);
				h = i;
				
				psi_vxx[j][h1] = b_x[h1] * psi_vxx[j][h1] + a_x[h1] * vxx;
				vxx = vxx / K_x[h1] + psi_vxx[j][h1]; 
			}

			/* top boundary */                                         
			if((POS[2]==0) && (!(FREE_SURF)) && (j<=FW)){
				
				psi_vyy[j][i] = b_y[j] * psi_vyy[j][i] + a_y[j] * vyy;
				vyy = vyy / K_y[j] + psi_vyy[j][i];
			}
			
			/* bottom boundary */                                         
			if((POS[2]==NPROCY-1) && (j>=ny2-FW+1)){

				h1 = (j-ny2+2*FW);                                        
				h = j;
				
				psi_vyy[h1][i] = b_y[h1] * psi_vyy[h1][i] + a_y[h1] * vyy;                                            
				vyy = vyy / K_y[h1] + psi_vyy[h1][i];
			}
			
262
			if (PARAMETERIZATION==1){
263 264 265 266 267 268 269
				g = rho[j][i] * (pi[j][i] * pi[j][i]);}
			
			sp[j][i] += g*(vxx+vyy);
			
		}
		}
	break;
270
	
tilman.metz's avatar
tilman.metz committed
271 272 273 274 275 276 277 278
	default:
		for (j=ny1;j<=ny2;j++){
			for (i=nx1;i<=nx2;i++){
				vxx = 0.0;
				vyy = 0.0;
				for (m=1; m<=fdoh; m++) {
					vxx += hc[m]*(vx[j][i+m-1] -vx[j][i-m]  );
					vyy += hc[m]*(vy[j+m-1][i] -vy[j-m][i]  );
279 280 281 282
				}
				
				g=pi[j][i]*DT;
				
tilman.metz's avatar
tilman.metz committed
283 284 285
				sp[j][i]+=(g*(vxx+vyy))*dhi;
			}
		}
286
	break;
tilman.metz's avatar
tilman.metz committed
287 288
		
	} /* end of switch(FDORDER) */
289
	
tilman.metz's avatar
tilman.metz committed
290 291 292 293 294
	if (infoout && (MYID==0)){
		time2=MPI_Wtime();
		fprintf(FP," finished (real time: %4.2f s).\n",time2-time1);
	}
}