update_v_interior.c 10.2 KB
Newer Older
tilman.metz's avatar
tilman.metz 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 46 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 74 75 76 77 78 79 80 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 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 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 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
/*------------------------------------------------------------------------
 * Copyright (C) 2015 For the list of authors, see file AUTHORS.
 *
 * This file is part of SOFI2D.
 *
 * SOFI2D 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.
 *
 * SOFI2D 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 SOFI2D. See file COPYING and/or
  * <http://www.gnu.org/licenses/gpl-2.0.html>.
--------------------------------------------------------------------------*/

/* $Id: update_v_interior.c 819 2015-04-17 11:07:06Z tmetz $*/
/*------------------------------------------------------------------------
 *   updating particle velocities at interior gridpoints (excluding boundarys) [gx2+1...gx3][gy2+1...gy3]
 *   by a staggered grid finite difference scheme of FDORDER accuracy in space
 *   and second order accuracy in time
 *
 *   gx and gy are arrays with the locations of the boundary specified in subgrid_bounds.c
 *   for each subgrid
 *  ----------------------------------------------------------------------*/

#include "fd.h"



void update_v_interior ( int nx1, int nx2, int ny1, int ny2, int *gx, int *gy, int nt,
                         float **  vx, float ** vy, float ** sxx, float ** syy,
                         float ** sxy, float **rho, float  **rip, float **rjp,
                         float **  srcpos_loc, float ** signals, int nsrc,float *hc )
{

	int i, j,l;
	float amp, dtdh;
	float sxx_x, sxy_x, sxy_y, syy_y;
	float azi_rad;
	extern float DT, DH;
	extern int OUTNTIMESTEPINFO;
	double time1=0.0, time2=0.0;
	extern int MYID, SOURCE_TYPE, CHECKPTREAD, FDORDER;
	extern FILE *FP;

	dtdh = DT/DH;



	if ( ( MYID==0 ) && ( ( nt+ ( OUTNTIMESTEPINFO-1 ) ) %OUTNTIMESTEPINFO ) ==0 ) {
		time1=MPI_Wtime();
		fprintf ( FP,"\n **Message from update_v_interior (printed by PE %d):\n",MYID );
		fprintf ( FP," Updating particle velocities ..." );
	}


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



	if ( !CHECKPTREAD )
		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;

			//amp=signals[l][nt]; // unscaled force amplitude
			amp= ( DT*signals[l][nt] ) / ( DH*DH ); // scaled force amplitude with F= 1N

			//fprintf(FP," amp at timestep nt %i = %5.5e with DH=%5.2f  DT=%5.8f\n",nt,amp,DH,DT);

			SOURCE_TYPE= ( int ) srcpos_loc[8][l];

			switch ( SOURCE_TYPE ) {
			case 2 : /* single force in x */


				vx[j][i]  +=  rip[j][i]*amp;

				/* previous implementation of body forces as seismic sources.
				 * Implementation according to Coutant et al., BSSA, Vol. 85, No 5, 1507-1512.
				 * The stress tensor components sxx and syy are incremented prior to
				 * particle velocity update. Thereby the body force (both directions)
				 * are located at full grid point (i,j) (same position as pressure source).
				 * as a consequence, source signals are added [and weighted] at multiple grid points.
				 * This implementation works but not quite physical when considering e.g. a force of 1 N
				 * and aiming to gain the particle velocity strictly according to that force.
				 * Therefore it has been commented */

				/*for (m=1; m<=fdoh; m++) {

					vx[j][i+m-1]  +=  hc[m]*rip[j][i]*amp;
					vx[j][i-m]    +=  hc[m]*rip[j][i-1]*amp;

				}*/


				break;
			case 3 : /* single force in y */

				vy[j][i]  +=  rjp[j][i]*amp;

				/*for (m=1; m<=fdoh; m++) {

					vy[j+m-1][i]  +=  hc[m]*rjp[j][i]*amp;
					vy[j-m][i]    +=  hc[m]*rjp[j][i-1]*amp;

				}*/

				break;
			case 4 : /* custom force */

				vx[j][i]  +=  sin ( azi_rad ) * ( rip[j][i]*amp );
				vy[j][i]  +=  cos ( azi_rad ) * ( rjp[j][i]*amp );

				/*for (m=1; m<=fdoh; m++) {

					vx[j][i+m-1]  +=  sin(azi_rad)*(hc[m]*rip[j][i]*amp);
					vx[j][i-m]    +=  sin(azi_rad)*(hc[m]*rip[j][i-1]*amp);

					vy[j+m-1][i]  +=  cos(azi_rad)*(hc[m]*rjp[j][i]*amp);
					vy[j-m][i]    +=  cos(azi_rad)*(hc[m]*rjp[j][i-1]*amp);

				}*/

				break;

			}
		}



	switch ( FDORDER ) {
	case 2:
		for ( j=gy[2]+1; j<=gy[3]; j++ ) {
			for ( i=gx[2]+1; i<=gx[3]; i++ ) {

				sxx_x =  hc[1]* ( sxx[j][i+1]-sxx[j][i] );
				sxy_x =  hc[1]* ( sxy[j][i]-sxy[j][i-1] );
				sxy_y =  hc[1]* ( sxy[j][i]-sxy[j-1][i] );
				syy_y =  hc[1]* ( syy[j+1][i]-syy[j][i] );

				vx[j][i] += ( sxx_x+sxy_y ) *dtdh*rip[j][i];
				vy[j][i] += ( sxy_x+syy_y ) *dtdh*rjp[j][i];

			}
		}
		break;

	case 4:
		for ( j=gy[2]+1; j<=gy[3]; j++ ) {
			for ( i=gx[2]+1; i<=gx[3]; i++ ) {

				sxx_x =  hc[1]* ( sxx[j][i+1]-sxx[j][i] )
				         + hc[2]* ( sxx[j][i+2]-sxx[j][i-1] );

				sxy_x = hc[1]* ( sxy[j][i]-sxy[j][i-1] )
				        + hc[2]* ( sxy[j][i+1]-sxy[j][i-2] );

				sxy_y =  hc[1]* ( sxy[j][i]-sxy[j-1][i] )
				         + hc[2]* ( sxy[j+1][i]-sxy[j-2][i] );

				syy_y = hc[1]* ( syy[j+1][i]-syy[j][i] )
				        + hc[2]* ( syy[j+2][i]-syy[j-1][i] );

				vx[j][i] += ( sxx_x+sxy_y ) *dtdh*rip[j][i];
				vy[j][i] += ( sxy_x+syy_y ) *dtdh*rjp[j][i];
			}
		}
		break;

	case 6:
		for ( j=gy[2]+1; j<=gy[3]; j++ ) {
			for ( i=gx[2]+1; i<=gx[3]; i++ ) {
				sxx_x =  hc[1]* ( sxx[j][i+1]-sxx[j][i] )
				         + hc[2]* ( sxx[j][i+2]-sxx[j][i-1] )
				         + hc[3]* ( sxx[j][i+3]-sxx[j][i-2] );

				sxy_x = hc[1]* ( sxy[j][i]-sxy[j][i-1] )
				        + hc[2]* ( sxy[j][i+1]-sxy[j][i-2] )
				        + hc[3]* ( sxy[j][i+2]-sxy[j][i-3] );
				sxy_y =  hc[1]* ( sxy[j][i]-sxy[j-1][i] )
				         + hc[2]* ( sxy[j+1][i]-sxy[j-2][i] )
				         + hc[3]* ( sxy[j+2][i]-sxy[j-3][i] );

				syy_y = hc[1]* ( syy[j+1][i]-syy[j][i] )
				        + hc[2]* ( syy[j+2][i]-syy[j-1][i] )
				        + hc[3]* ( syy[j+3][i]-syy[j-2][i] );

				vx[j][i] += ( sxx_x+sxy_y ) *dtdh*rip[j][i];
				vy[j][i] += ( sxy_x+syy_y ) *dtdh*rjp[j][i];

			}
		}
		break;

	case 8:
		for ( j=gy[2]+1; j<=gy[3]; j++ ) {
			for ( i=gx[2]+1; i<=gx[3]; i++ ) {

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

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

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

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

				vx[j][i] += ( sxx_x+sxy_y ) *dtdh*rip[j][i];
				vy[j][i] += ( sxy_x+syy_y ) *dtdh*rjp[j][i];

			}
		}
		break;

	case 10:
		for ( j=gy[2]+1; j<=gy[3]; j++ ) {
			for ( i=gx[2]+1; i<=gx[3]; i++ ) {
				sxx_x= hc[1]* ( sxx[j][i+1]-sxx[j][i] )
				       + hc[2]* ( sxx[j][i+2]-sxx[j][i-1] )
				       + hc[3]* ( sxx[j][i+3]-sxx[j][i-2] )
				       + hc[4]* ( sxx[j][i+4]-sxx[j][i-3] )
				       + hc[5]* ( sxx[j][i+5]-sxx[j][i-4] );

				sxy_x= hc[1]* ( sxy[j][i]  -sxy[j][i-1] )
				       + hc[2]* ( sxy[j][i+1]-sxy[j][i-2] )
				       + hc[3]* ( sxy[j][i+2]-sxy[j][i-3] )
				       + hc[4]* ( sxy[j][i+3]-sxy[j][i-4] )
				       + hc[5]* ( sxy[j][i+4]-sxy[j][i-5] );


				sxy_y= hc[1]* ( sxy[j][i]  -sxy[j-1][i] )
				       + hc[2]* ( sxy[j+1][i]-sxy[j-2][i] )
				       + hc[3]* ( sxy[j+2][i]-sxy[j-3][i] )
				       + hc[4]* ( sxy[j+3][i]-sxy[j-4][i] )
				       + hc[5]* ( sxy[j+4][i]-sxy[j-5][i] );


				syy_y= hc[1]* ( syy[j+1][i]-syy[j][i] )
				       + hc[2]* ( syy[j+2][i]-syy[j-1][i] )
				       + hc[3]* ( syy[j+3][i]-syy[j-2][i] )
				       + hc[4]* ( syy[j+4][i]-syy[j-3][i] )
				       + hc[5]* ( syy[j+5][i]-syy[j-4][i] );

				vx[j][i] += ( sxx_x+sxy_y ) *dtdh*rip[j][i];
				vy[j][i] += ( sxy_x+syy_y ) *dtdh*rjp[j][i];
			}
		}
		break;

	case 12:
		for ( j=gy[2]+1; j<=gy[3]; j++ ) {
			for ( i=gx[2]+1; i<=gx[3]; i++ ) {
				sxx_x = hc[1]* ( sxx[j][i+1]-sxx[j][i] )
				        + hc[2]* ( sxx[j][i+2]-sxx[j][i-1] )
				        + hc[3]* ( sxx[j][i+3]-sxx[j][i-2] )
				        + hc[4]* ( sxx[j][i+4]-sxx[j][i-3] )
				        + hc[5]* ( sxx[j][i+5]-sxx[j][i-4] )
				        + hc[6]* ( sxx[j][i+6]-sxx[j][i-5] );

				sxy_x = hc[1]* ( sxy[j][i]  -sxy[j][i-1] )
				        + hc[2]* ( sxy[j][i+1]-sxy[j][i-2] )
				        + hc[3]* ( sxy[j][i+2]-sxy[j][i-3] )
				        + hc[4]* ( sxy[j][i+3]-sxy[j][i-4] )
				        + hc[5]* ( sxy[j][i+4]-sxy[j][i-5] )
				        + hc[6]* ( sxy[j][i+5]-sxy[j][i-6] );

				sxy_y = hc[1]* ( sxy[j][i]  -sxy[j-1][i] )
				        + hc[2]* ( sxy[j+1][i]-sxy[j-2][i] )
				        + hc[3]* ( sxy[j+2][i]-sxy[j-3][i] )
				        + hc[4]* ( sxy[j+3][i]-sxy[j-4][i] )
				        + hc[5]* ( sxy[j+4][i]-sxy[j-5][i] )
				        + hc[6]* ( sxy[j+5][i]-sxy[j-6][i] );


				syy_y = hc[1]* ( syy[j+1][i]-syy[j][i] )
				        + hc[2]* ( syy[j+2][i]-syy[j-1][i] )
				        + hc[3]* ( syy[j+3][i]-syy[j-2][i] )
				        + hc[4]* ( syy[j+4][i]-syy[j-3][i] )
				        + hc[5]* ( syy[j+5][i]-syy[j-4][i] )
				        + hc[6]* ( syy[j+6][i]-syy[j-5][i] );

				vx[j][i] += ( sxx_x+sxy_y ) *dtdh*rip[j][i];
				vy[j][i] += ( sxy_x+syy_y ) *dtdh*rjp[j][i];
			}
		}
		break;

	default: // 2nd order
		for ( j=gy[2]+1; j<=gy[3]; j++ ) {
			for ( i=gx[2]+1; i<=gx[3]; i++ ) {

				sxx_x =  hc[1]* ( sxx[j][i+1]-sxx[j][i] );
				sxy_x =  hc[1]* ( sxy[j][i]-sxy[j][i-1] );
				sxy_y =  hc[1]* ( sxy[j][i]-sxy[j-1][i] );
				syy_y =  hc[1]* ( syy[j+1][i]-syy[j][i] );

				vx[j][i] += ( sxx_x+sxy_y ) *dtdh*rip[j][i];
				vy[j][i] += ( sxy_x+syy_y ) *dtdh*rjp[j][i];

			}
		}
		break;

	} /* end of switch(FDORDER) */





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