rheinstetten_elastic_start.c 3.3 KB
Newer Older
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
/*
 *   Model defined by flnode file. 
 */

#include "fd.h"

void model(st_model *mod){

	/*--------------------------------------------------------------------------*/
	/* extern variables */

	extern int NX, NY,NZ, NXG, NYG, NZG, POS[4], MYID;
	extern float DZ;
	extern FILE *FP;
	
		/* local variables */
	float muv, piv, vp, vs, rhov;
	int i, j,k, ii, jj,kk, l;
	
	FILE *flfile;
	int nodes;
	char cline[256];
	
	float *fldepth, *flrho, *flvp, *flvs;
	
	nodes=7;
	
	fldepth=vector(1,nodes);
	flrho=vector(1,nodes);
	flvp=vector(1,nodes);
	flvs=vector(1,nodes);
		
	
	
	/*read FL nodes from File*/
	
	flfile=fopen("flnodes/flnodes.rheinstetten_start","r");
	if (flfile==NULL) err(" FL-file could not be opened !");
	
	
	
	for (l=1;l<=nodes;l++){
		fgets(cline,255,flfile);
		if (cline[0]!='#'){
			sscanf(cline,"%f%f%f%f",&fldepth[l], &flrho[l], &flvp[l], &flvs[l]);
		}
		else l=l-1;
	
	}
	
	
	if(MYID==0){
	fprintf(FP," ------------------------------------------------------------------ \n\n");
	fprintf(FP," Information of FL nodes: \n\n");
	fprintf(FP," \t depth \t rho \t vp \t vs \n\n");
	
	for (l=1;l<=nodes;l++){
	fprintf(FP," \t %f \t %f \t %f \t %f\n\n",fldepth[l],flrho[l],flvp[l],flvs[l]);
	}
	fprintf(FP," ------------------------------------------------------------------ \n\n");
	}
	/*-----------------------------------------------------------------------*/
	
	
		
	/*-----------------------------------------------------------------------*/

	/* loop over global grid */
		for (i=1;i<=NXG;i++){
			for (k=1; k<=NZG; k++) {
			for (l=1;l<nodes;l++){
				if (fldepth[l]==fldepth[l+1]){
					if ((i==1) && (k==1) && (MYID==0)){
					fprintf(FP,"depth: %f m: double node\n",fldepth[l]);}}
				else{
					for (j=(int)(fldepth[l]/DZ)+1;j<=(int)(fldepth[l+1]/DZ);j++){
			
						vp=0.0; vs=0.0; rhov=0.0;
				  
						vp=(DZ*(j-1)-fldepth[l])*(flvp[l+1]-flvp[l])/(fldepth[l+1]-fldepth[l])+flvp[l];
						vp=vp*1000.0;
						vs=(DZ*(j-1)-fldepth[l])*(flvs[l+1]-flvs[l])/(fldepth[l+1]-fldepth[l])+flvs[l];
						vs=vs*1000.0;
						rhov=(DZ*(j-1)-fldepth[l])*(flrho[l+1]-flrho[l])/(fldepth[l+1]-fldepth[l])+flrho[l];
						rhov=rhov*1000.0;
						
						
						muv=vs*vs*rhov;
						piv=vp*vp*rhov;

						
						/* only the PE which belongs to the current global gridpoint 
				  		is saving model parameters in his local arrays */
						if ((POS[1]==((i-1)/NX)) &&
						(POS[2]==((j-1)/NY)) &&
						(POS[3]==((k-1)/NZ))) {
						ii=i-POS[1]*NX;
						jj=j-POS[2]*NY;
						kk=k-POS[3]*NZ;

						mod->u[jj][ii][kk]=muv;
						mod->rho[jj][ii][kk]=rhov;
						mod->pi[jj][ii][kk]=piv;
						}
					}
				}
			}
			
			for (j=(int)(fldepth[nodes]/DZ)+1;j<=NYG;j++){
			  
				vp=0.0; vs=0.0; rhov=0.0;
				vp=flvp[nodes]*1000.0; vs=flvs[nodes]*1000.0; rhov=flrho[nodes]*1000.0;
				
				muv=vs*vs*rhov;
				piv=vp*vp*rhov;

				/* only the PE which belongs to the current global gridpoint 
				  		is saving model parameters in his local arrays */
					if ((POS[1]==((i-1)/NX)) &&
					        (POS[2]==((j-1)/NY)) &&
					        (POS[3]==((k-1)/NZ))) {
						ii=i-POS[1]*NX;
						jj=j-POS[2]*NY;
						kk=k-POS[3]*NZ;

						mod->u[jj][ii][kk]=muv;
						mod->rho[jj][ii][kk]=rhov;
						mod->pi[jj][ii][kk]=piv;
						}
			}
		}
		}
		
		
	
	
	free_vector(fldepth,1,nodes);
	free_vector(flrho,1,nodes);
	free_vector(flvp,1,nodes);
	free_vector(flvs,1,nodes);

}