update_v_acoustic_PML.c 13.8 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*-----------------------------------------------------------------------------------------
 * Copyright (C) 2013  For the list of authors, see file AUTHORS.
 *
 * This file is part of DENISE.
 * 
 * DENISE 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.
 * 
 * DENISE 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.
 * 
 * You should have received a copy of the GNU General Public License
 * along with DENISE. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
-----------------------------------------------------------------------------------------*/

/* $Id: update_v_ssg.c,v 1.1.1.1 2007/11/21 22:44:52 koehn Exp $*/
/*------------------------------------------------------------------------
 *   updating particle velocities at gridpoints [nx1...nx2][ny1...ny2]
 *   by a staggered grid finite difference scheme of FDORDER accuracy in space
 *   and second order accuracy in time
 *   T. Bohlen 
 *
 *  ----------------------------------------------------------------------*/

#include "fd.h"



void update_v_acoustic_PML(int nx1, int nx2, int ny1, int ny2, int nt,
	float **  vx, float **  vxp1, float **  vxm1, float ** vy, float **  vyp1, float **  vym1, float ** sp,
	float  **rip, float **rjp, float **  srcpos_loc, float ** signals, float ** signals1, int nsrc, float ** absorb_coeff,
	float *hc, int infoout,int sw, float * K_x_half, float * a_x_half, float * b_x_half,
        float * K_y_half, float * a_y_half, float * b_y_half,
        float ** psi_sxx_x, float ** psi_syy_y){

	int i, j,l,fdoh,m, h, h1;
	float amp, dtdh, azi_rad;
	float vxtmp, vytmp;
        float sp_x, sp_y;
	
	extern float DT, DH;
	double time1, time2;
46
	extern int MYID, QUELLTYP, QUELLTYPB, FDORDER;
Tilman Steinweg's avatar
Tilman Steinweg committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
        extern int FDORDER, INVMAT1;
        extern int FREE_SURF, BOUNDARY, FW;
        extern int NPROCX, NPROCY, POS[3];
	extern FILE *FP;
	extern int VELOCITY;

	
	fdoh = FDORDER/2;
	dtdh = DT*DT/DH;
        
     /* drad = PI/180.0; 
        angle = 135.0; */
         
	if (infoout && (MYID==0)){
		time1=MPI_Wtime();
		fprintf(FP,"\n **Message from update_v (printed by PE %d):\n",MYID);
		fprintf(FP," Updating particle velocities ...");
	}

	
			
	/* ------------------------------------------------------------
	 * Important!
	 * rip and rjp are reciprocal values of averaged densities
	 * ------------------------------------------------------------ */

	switch (FDORDER){
74
	
Tilman Steinweg's avatar
Tilman Steinweg committed
75
76
	case 2:
		for (j=ny1;j<=ny2;j++){
77
78
79
80
		for (i=nx1;i<=nx2;i++){
			sp_x = hc[1]*(sp[j][i+1]-sp[j][i]);
			sp_y = hc[1]*(sp[j+1][i]-sp[j][i]);
			
Tilman Steinweg's avatar
Tilman Steinweg committed
81

82
83
84
85
86
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
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
			/* left boundary */                                         
			if((!BOUNDARY) && (POS[1]==0) && (i<=FW)){
				
				psi_sxx_x[j][i] = b_x_half[i] * psi_sxx_x[j][i] + a_x_half[i] * sp_x;                                                
				sp_x = sp_x / K_x_half[i] + psi_sxx_x[j][i];
				
			}

			/* right boundary */                                         
			if((!BOUNDARY) && (POS[1]==NPROCX-1) && (i>=nx2-FW+1)){

				h1 = (i-nx2+2*FW);
				h=i; 
				
				/*psi_sxx_x[j][i] = b_x_half[i] * psi_sxx_x[j][i] + a_x_half[i] * sxx_x;                                                
				sxx_x = sxx_x / K_x_half[i] + psi_sxx_x[j][i];*/
				
				psi_sxx_x[j][h1] = b_x_half[h1] * psi_sxx_x[j][h1] + a_x_half[h1] * sp_x;                                                
				sp_x = sp_x / K_x_half[h1] + psi_sxx_x[j][h1];
			}
	
			/* top boundary */                                         
			if((POS[2]==0) && (!(FREE_SURF)) && (j<=FW)){
				
				psi_syy_y[j][i] = b_y_half[j] * psi_syy_y[j][i] + a_y_half[j] * sp_y;                                                
				sp_y = sp_y / K_y_half[j] + psi_syy_y[j][i];
			}
	
			/* bottom boundary */                                         
			if((POS[2]==NPROCY-1) && (j>=ny2-FW+1)){
			
				h1 = (j-ny2+2*FW);
				h = j;
							
				/*psi_syy_y[j][i] = b_y_half[j] * psi_syy_y[j][i] + a_y_half[j] * syy_y;                                                
				syy_y = syy_y / K_y_half[j] + psi_syy_y[j][i];*/
				
				psi_syy_y[h1][i] = b_y_half[h1] * psi_syy_y[h1][i] + a_y_half[h1] * sp_y;                                                
				sp_y = sp_y / K_y_half[h1] + psi_syy_y[h1][i];
			}                       
			
			if(sw==0){
				if (VELOCITY==0){
				vxp1[j][i] = rip[j][i]*(sp_x)/DH;
				vyp1[j][i] = rjp[j][i]*(sp_y)/DH;}
				else{
				vxp1[j][i] = rip[j][i]*(sp_x)/DH;
				vyp1[j][i] = rjp[j][i]*(sp_y)/DH;}
			}
			
			if(sw==1){
				if (VELOCITY==0){
				vxp1[j][i] += vx[j][i]*DT;
				vyp1[j][i] += vy[j][i]*DT;}
				else{
				vxp1[j][i] = vx[j][i];
				vyp1[j][i] = vy[j][i];}
			}
			
			vx[j][i] += DT*rip[j][i]*(sp_x)/DH;
			vy[j][i] += DT*rjp[j][i]*(sp_y)/DH;
      
		}
		}
	break;
	
Tilman Steinweg's avatar
Tilman Steinweg committed
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
180
181
182
183
184
185
186
187
	case 4:
		for (j=ny1;j<=ny2;j++){
		for (i=nx1;i<=nx2;i++){
			sp_x =  hc[1]*(sp[j][i+1]-sp[j][i])
					+ hc[2]*(sp[j][i+2]-sp[j][i-1]);

			sp_y = hc[1]*(sp[j+1][i]-sp[j][i])
					+ hc[2]*(sp[j+2][i]-sp[j-1][i]);
			
			/* left boundary */                                         
			if((!BOUNDARY) && (POS[1]==0) && (i<=FW)){
				
				psi_sxx_x[j][i] = b_x_half[i] * psi_sxx_x[j][i] + a_x_half[i] * sp_x;                                                
				sp_x = sp_x / K_x_half[i] + psi_sxx_x[j][i];

			}

			/* right boundary */                                         
			if((!BOUNDARY) && (POS[1]==NPROCX-1) && (i>=nx2-FW+1)){

				h1 = (i-nx2+2*FW);
				h=i; 
					
				/*psi_sxx_x[j][i] = b_x_half[i] * psi_sxx_x[j][i] + a_x_half[i] * sxx_x;                                                
				sxx_x = sxx_x / K_x_half[i] + psi_sxx_x[j][i];*/
				
				psi_sxx_x[j][h1] = b_x_half[h1] * psi_sxx_x[j][h1] + a_x_half[h1] * sp_x;                                                
				sp_x = sp_x / K_x_half[h1] + psi_sxx_x[j][h1];

			}

	
			/* top boundary */                                         
			if((POS[2]==0) && (!(FREE_SURF)) && (j<=FW)){

				psi_syy_y[j][i] = b_y_half[j] * psi_syy_y[j][i] + a_y_half[j] * sp_y;                                                
				sp_y = sp_y / K_y_half[j] + psi_syy_y[j][i]; 
				
			}
Tilman Steinweg's avatar
Tilman Steinweg committed
188
		
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228

			/* bottom boundary */                                         
			if((POS[2]==NPROCY-1) && (j>=ny2-FW+1)){
				
				h1 = (j-ny2+2*FW);
				h = j;
							
				/*psi_syy_y[j][i] = b_y_half[j] * psi_syy_y[j][i] + a_y_half[j] * syy_y;                                                
				syy_y = syy_y / K_y_half[j] + psi_syy_y[j][i];*/
				
				psi_syy_y[h1][i] = b_y_half[h1] * psi_syy_y[h1][i] + a_y_half[h1] * sp_y;                                                
				sp_y = sp_y / K_y_half[h1] + psi_syy_y[h1][i];
				
			}                   
			
			if(sw==0){
				if (VELOCITY==0){
					vxp1[j][i] = rip[j][i]*(sp_x)/DH;
					vyp1[j][i] = rjp[j][i]*(sp_y)/DH;}
				else{
					vxp1[j][i] = rip[j][i]*(sp_x)/DH;
					vyp1[j][i] = rjp[j][i]*(sp_y)/DH;}
			}
			
			if(sw==1){
				if (VELOCITY==0){
					vxp1[j][i] += vx[j][i]*DT;
					vyp1[j][i] += vy[j][i]*DT;}
				else{
					vxp1[j][i] = vx[j][i];
					vyp1[j][i] = vy[j][i];}
			}
			
			vx[j][i] += DT*rip[j][i]*(sp_x)/DH;
			vy[j][i] += DT*rjp[j][i]*(sp_y)/DH;

		}
		}
	
	break;
Tilman Steinweg's avatar
Tilman Steinweg committed
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
	case 6:
		for (j=ny1;j<=ny2;j++){
		for (i=nx1;i<=nx2;i++){
			sp_x =  hc[1]*(sp[j][i+1]-sp[j][i])
					+ hc[2]*(sp[j][i+2]-sp[j][i-1])
					+ hc[3]*(sp[j][i+3]-sp[j][i-2]);
			
			sp_y = hc[1]*(sp[j+1][i]-sp[j][i])
					+ hc[2]*(sp[j+2][i]-sp[j-1][i])
					+ hc[3]*(sp[j+3][i]-sp[j-2][i]);
			

			/* left boundary */                                         
			if((!BOUNDARY) && (POS[1]==0) && (i<=FW)){
					
				psi_sxx_x[j][i] = b_x_half[i] * psi_sxx_x[j][i] + a_x_half[i] * sp_x;                                                
				sp_x = sp_x / K_x_half[i] + psi_sxx_x[j][i];
			}

			/* right boundary */                                         
			if((!BOUNDARY) && (POS[1]==NPROCX-1) && (i>=nx2-FW+1)){

				h1 = (i-nx2+2*FW);
				h=i; 
					
				/*psi_sxx_x[j][i] = b_x_half[i] * psi_sxx_x[j][i] + a_x_half[i] * sxx_x;                                                
				sxx_x = sxx_x / K_x_half[i] + psi_sxx_x[j][i];*/
				
				psi_sxx_x[j][h1] = b_x_half[h1] * psi_sxx_x[j][h1] + a_x_half[h1] * sp_x;                                                
				sp_x = sp_x / K_x_half[h1] + psi_sxx_x[j][h1];
			}

		
			/* top boundary */                                         
			if((POS[2]==0) && (!(FREE_SURF)) && (j<=FW)){
						
				psi_syy_y[j][i] = b_y_half[j] * psi_syy_y[j][i] + a_y_half[j] * sp_y;                                                
				sp_y = sp_y / K_y_half[j] + psi_syy_y[j][i];
			}
			

			/* bottom boundary */                                         
			if((POS[2]==NPROCY-1) && (j>=ny2-FW+1)){
				
				h1 = (j-ny2+2*FW);
				h = j;
							
				/*psi_syy_y[j][i] = b_y_half[j] * psi_syy_y[j][i] + a_y_half[j] * syy_y;                                                
				syy_y = syy_y / K_y_half[j] + psi_syy_y[j][i];*/
				
				psi_syy_y[h1][i] = b_y_half[h1] * psi_syy_y[h1][i] + a_y_half[h1] * sp_y;                                                
				sp_y = sp_y / K_y_half[h1] + psi_syy_y[h1][i];
			}                       
			
			if(sw==0){
				if (VELOCITY==0){
					vxp1[j][i] = rip[j][i]*(sp_x)/DH;
					vyp1[j][i] = rjp[j][i]*(sp_y)/DH;}
				else{
					vxp1[j][i] = rip[j][i]*(sp_x)/DH;
					vyp1[j][i] = rjp[j][i]*(sp_y)/DH;}
			}
			
			if(sw==1){
				if (VELOCITY==0){
					vxp1[j][i] += vx[j][i]*DT;
					vyp1[j][i] += vy[j][i]*DT;}
				else{
					vxp1[j][i] = vx[j][i];
					vyp1[j][i] = vy[j][i];}
			}
			
			vx[j][i] += DT*rip[j][i]*(sp_x)/DH;
			vy[j][i] += DT*rjp[j][i]*(sp_y)/DH; 		         

		}
		}

	
	break;
		
	case 8:

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

			sp_x =  hc[1]*(sp[j][i+1]-sp[j][i])
					+ hc[2]*(sp[j][i+2]-sp[j][i-1])
					+ hc[3]*(sp[j][i+3]-sp[j][i-2])
					+ hc[4]*(sp[j][i+4]-sp[j][i-3]);

			sp_y = hc[1]*(sp[j+1][i]-sp[j][i])
					+ hc[2]*(sp[j+2][i]-sp[j-1][i])
					+ hc[3]*(sp[j+3][i]-sp[j-2][i])
					+ hc[4]*(sp[j+4][i]-sp[j-3][i]);
			

			/* left boundary */                                         
			if((!BOUNDARY) && (POS[1]==0) && (i<=FW)){
					
				psi_sxx_x[j][i] = b_x_half[i] * psi_sxx_x[j][i] + a_x_half[i] * sp_x;                                                
				sp_x = sp_x / K_x_half[i] + psi_sxx_x[j][i];
			}

			/* right boundary */                                         
			if((!BOUNDARY) && (POS[1]==NPROCX-1) && (i>=nx2-FW+1)){

				h1 = (i-nx2+2*FW);
				h=i; 
					
				/*psi_sxx_x[j][i] = b_x_half[i] * psi_sxx_x[j][i] + a_x_half[i] * sxx_x;                                                
				sxx_x = sxx_x / K_x_half[i] + psi_sxx_x[j][i];*/
				
				psi_sxx_x[j][h1] = b_x_half[h1] * psi_sxx_x[j][h1] + a_x_half[h1] * sp_x;                                                
				sp_x = sp_x / K_x_half[h1] + psi_sxx_x[j][h1];
			}
Tilman Steinweg's avatar
Tilman Steinweg committed
346

347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
		
			/* top boundary */                                         
			if((POS[2]==0) && (!(FREE_SURF)) && (j<=FW)){
						
				psi_syy_y[j][i] = b_y_half[j] * psi_syy_y[j][i] + a_y_half[j] * sp_y;                                                
				sp_y = sp_y / K_y_half[j] + psi_syy_y[j][i];
			}
			

			/* bottom boundary */                                         
			if((POS[2]==NPROCY-1) && (j>=ny2-FW+1)){
				
				h1 = (j-ny2+2*FW);
				h = j;
							
				/*psi_syy_y[j][i] = b_y_half[j] * psi_syy_y[j][i] + a_y_half[j] * syy_y;                                                
				syy_y = syy_y / K_y_half[j] + psi_syy_y[j][i];*/
				
				psi_syy_y[h1][i] = b_y_half[h1] * psi_syy_y[h1][i] + a_y_half[h1] * sp_y;                                                
				sp_y = sp_y / K_y_half[h1] + psi_syy_y[h1][i];
				
			}                       
			
			if(sw==0){
				if (VELOCITY==0){
					vxp1[j][i] = rip[j][i]*(sp_x)/DH;
					vyp1[j][i] = rjp[j][i]*(sp_y)/DH;}
				else{
					vxp1[j][i] = rip[j][i]*(sp_x)/DH;
					vyp1[j][i] = rjp[j][i]*(sp_y)/DH;}
			}
			
			if(sw==1){
				if (VELOCITY==0){
					vxp1[j][i] += vx[j][i]*DT;
					vyp1[j][i] += vy[j][i]*DT;}
				else{
					vxp1[j][i] = vx[j][i];
					vyp1[j][i] = vy[j][i];}
			}
			
			vx[j][i] += DT*rip[j][i]*(sp_x)/DH;
			vy[j][i] += DT*rjp[j][i]*(sp_y)/DH;
		}
		}
	
	break;
Tilman Steinweg's avatar
Tilman Steinweg committed
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
		
	default:
		for (j=ny1;j<=ny2;j++){
			for (i=nx1;i<=nx2;i++){
				vxtmp = 0;
				vytmp = 0;
				for (m=1; m<=fdoh; m++) {
					vxtmp +=   hc[m]*( sp[j][i+m]   - sp[j][i-m+1] );
							
					vytmp +=   hc[m]*( sp[j+m][i]   - sp[j-m+1][i] );
				}
					
				vx[j][i] += vxtmp*dtdh*rip[j][i];
				vy[j][i] += vytmp*dtdh*rjp[j][i];
			}
		}
		break;

	} /* end of switch(FDORDER) */


 		/* Forward Modelling (sw==0) */
	        if(sw==0){
	        for (l=1;l<=nsrc;l++) {
		    i=(int)srcpos_loc[1][l];
		    j=(int)srcpos_loc[2][l];
		    azi_rad=srcpos_loc[7][l]*PI/180;
		    QUELLTYP=(int)srcpos_loc[8][l];
		
		    if(QUELLTYP==2){vx[j][i] += (DT*rip[j][i]*signals1[l][nt])/(DH*DH);}  /* single force in x */
		    if(QUELLTYP==3){vy[j][i] += (DT*rjp[j][i]*signals1[l][nt])/(DH*DH);}  /* single force in y */
		    if(QUELLTYP==4){vx[j][i] += (DT*rip[j][i]*sin(azi_rad) * signals[l][nt])/(DH*DH);    /* rotated force in x */
		                    vy[j][i] += (DT*rjp[j][i]*cos(azi_rad) * signals[l][nt])/(DH*DH);}  /* rotated force in y */          
		              
		}}
		
		/* Backpropagation (sw==1) */
		if(sw==1){
		for (l=1;l<=nsrc;l++) {
433
434
			i=(int)srcpos_loc[1][l];
			j=(int)srcpos_loc[2][l];
Tilman Steinweg's avatar
Tilman Steinweg committed
435
		    
436
437
438
439
440
441
442
443
444
445
			if(QUELLTYPB==1){
				vx[j][i] += signals[l][nt];   /* single force in x */
				vy[j][i] += signals1[l][nt];  /* + single force in y */
			}
			
			if(QUELLTYPB==2)
				vy[j][i] += signals1[l][nt];  /* single force in y */
			if(QUELLTYPB==3)
				vx[j][i] += signals[l][nt];   /* single force in x */
			
Tilman Steinweg's avatar
Tilman Steinweg committed
446
447
448
449
450
451
452
453
		}}                         
	

	if (infoout && (MYID==0)){
		time2=MPI_Wtime();
		fprintf(FP," finished (real time: %4.2f s).\n",time2-time1);
	}
}