toy_example_ac_start.c 7.65 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
/*-----------------------------------------------------------------------------------------
 * Copyright (C) 2005  <name of author>
 *
 * 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: hh_el.c,v 2.3 2007/08/21 13:16:19 tbohlen Exp $*/
/*
 *   Model defined by flnode file. 
 */

#include "fd.h"
25
#include "../src/fd.h"
Tilman Steinweg's avatar
Tilman Steinweg committed
26 27 28 29

void model_acoustic(float **rho, float **pi){

	/* extern variables */
30
	extern int NX, NY, NXG, NYG, POS[3], MYID, FDORDER;
Tilman Steinweg's avatar
Tilman Steinweg committed
31
	extern float DH, DT;
32 33 34
	extern char MFILE[STRING_SIZE];
	extern char INV_MODELFILE[STRING_SIZE];
	extern char TAPER_FILE_NAME[STRING_SIZE], TAPER_FILE_NAME_RHO[STRING_SIZE];
Tilman Steinweg's avatar
Tilman Steinweg committed
35

36 37 38
	/* local variables */
	float piv, vp, rhov, taperv, **taper;
	int i, j, ii, jj, l, nd;
Tilman Steinweg's avatar
Tilman Steinweg committed
39 40 41 42 43 44
	char modfile[STRING_SIZE];
	
	FILE *flfile;
	int nodes;
	char cline[256];
	
45
	float *fldepth, *flrho, *flvp, *fltaper;
Tilman Steinweg's avatar
Tilman Steinweg committed
46
	
47
	nd = FDORDER/2 + 1;
Tilman Steinweg's avatar
Tilman Steinweg committed
48 49
	
	/*read FL nodes from File*/
50 51
	nodes=5;
	
Tilman Steinweg's avatar
Tilman Steinweg committed
52 53
	fldepth=vector(1,nodes);
	flrho=vector(1,nodes);
54 55 56 57 58
	flvp=vector(1,nodes);
	fltaper=vector(1,nodes);
	
	taper=matrix(-nd+1,NY+nd,-nd+1,NX+nd);
	
Tilman Steinweg's avatar
Tilman Steinweg committed
59 60 61 62 63 64 65
	flfile=fopen("model_true/flnodes.toy_example_ac.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]!='#'){
66
			sscanf(cline,"%f%f%f%f",&fldepth[l], &flrho[l], &flvp[l], &fltaper[l]);
Tilman Steinweg's avatar
Tilman Steinweg committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
		}
		else l=l-1;
	
	}
	
	if(MYID==0){
	printf(" ------------------------------------------------------------------ \n\n");
	printf(" Information of FL nodes: \n\n");
	printf(" \t depth \t vp \n\n");
	
	for (l=1;l<=nodes;l++){
	printf(" \t %f \t %f\n\n",fldepth[l],flvp[l]);
	}
	printf(" ------------------------------------------------------------------ \n\n");
	}
	
	/* loop over global grid */
		for (i=1;i<=NXG;i++){
			for (l=1;l<nodes;l++){
				if (fldepth[l]==fldepth[l+1]){
					if ((i==1) && (MYID==0)){
					printf("depth: %f m: double node\n",fldepth[l]);}}
				else{
					for (j=(int)(fldepth[l]/DH)+1;j<=(int)(fldepth[l+1]/DH);j++){
91
						
Tilman Steinweg's avatar
Tilman Steinweg committed
92
						vp=0.0;
93
						
Tilman Steinweg's avatar
Tilman Steinweg committed
94 95
						vp=(DH*(j-1)-fldepth[l])*(flvp[l+1]-flvp[l])/(fldepth[l+1]-fldepth[l])+flvp[l];
						vp=vp*1000.0;
96
						
Tilman Steinweg's avatar
Tilman Steinweg committed
97 98 99
						piv=vp;
						
						/* only the PE which belongs to the current global gridpoint 
100
						is saving model parameters in his local arrays */
Tilman Steinweg's avatar
Tilman Steinweg committed
101
						if ((POS[1]==((i-1)/NX)) && 
102
						(POS[2]==((j-1)/NY))){
Tilman Steinweg's avatar
Tilman Steinweg committed
103 104
						ii=i-POS[1]*NX;
						jj=j-POS[2]*NY;
105
						
Tilman Steinweg's avatar
Tilman Steinweg committed
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
						pi[jj][ii]=piv;
						}
					}
				}
			}
			
			for (j=(int)(fldepth[nodes]/DH)+1;j<=NYG;j++){
			  
				vp=0.0;
				vp=flvp[nodes]*1000.0;
				
				piv=vp;

				/* 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))){
						ii=i-POS[1]*NX;
						jj=j-POS[2]*NY;

						pi[jj][ii]=piv;
						}
			}
		}
		
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
	/* loop over global grid - taper */
		for (i=1;i<=NXG;i++){
			for (l=1;l<nodes;l++){
				if (fldepth[l]==fldepth[l+1]){
					if ((i==1) && (MYID==0)){
					printf("depth: %f m: double node\n",fldepth[l]);}}
				else{
					for (j=(int)(fldepth[l]/DH)+1;j<=(int)(fldepth[l+1]/DH);j++){
						
						taperv=0.0;
						
						taperv=(DH*(j-1)-fldepth[l])*(fltaper[l+1]-fltaper[l])/(fldepth[l+1]-fldepth[l])+fltaper[l];
						
						/* 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))){
						ii=i-POS[1]*NX;
						jj=j-POS[2]*NY;
						
						taper[jj][ii]=taperv;
						}
					}
				}
			}
			
			for (j=(int)(fldepth[nodes]/DH)+1;j<=NYG;j++){
			  
				taperv=0.0;
				taperv=fltaper[nodes];
				
				/* 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))){
						ii=i-POS[1]*NX;
						jj=j-POS[2]*NY;

						taper[jj][ii]=taperv;
						}
			}
		}
		
Tilman Steinweg's avatar
Tilman Steinweg committed
174 175 176
	free_vector(fldepth,1,nodes);
	free_vector(flrho,1,nodes);
	free_vector(flvp,1,nodes);
177
	free_vector(fltaper,1,nodes);
Tilman Steinweg's avatar
Tilman Steinweg committed
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
	
	
	/**************************************************/
	/* creation of density models */
	/**************************************************/
	
	/*read FL nodes from File*/
	nodes=6;
	fldepth=vector(1,nodes);
	flrho=vector(1,nodes);
	flvp=vector(1,nodes);	
	flfile=fopen("model_true/flnodes.toy_example_ac","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",&fldepth[l], &flrho[l], &flvp[l]);
		}
		else l=l-1;
	}
	
	
	if(MYID==0){
	printf(" ------------------------------------------------------------------ \n\n");
	printf(" Information of FL nodes: \n\n");
	printf(" \t depth \t vp \t rho \n\n");
	
	for (l=1;l<=nodes;l++){
	printf(" \t %f \t %f \t %f \n\n",fldepth[l],flvp[l],flrho[l]);
	}
	printf(" ------------------------------------------------------------------ \n\n");
	}
	
	/* loop over global grid */
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
	for (i=1;i<=NXG;i++){
		for (l=1;l<nodes;l++){
			if (fldepth[l]==fldepth[l+1]){
				if ((i==1) && (MYID==0)){
					printf("depth: %f m: double node\n",fldepth[l]);
				}
			}else{
				for (j=(int)(fldepth[l]/DH)+1;j<=(int)(fldepth[l+1]/DH);j++){
		
					rhov=0.0;
				
					rhov=(DH*(j-1)-fldepth[l])*(flrho[l+1]-flrho[l])/(fldepth[l+1]-fldepth[l])+flrho[l];
					rhov=rhov*1000.0;
					
					
					/* 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))){
Tilman Steinweg's avatar
Tilman Steinweg committed
231 232 233 234 235 236 237
						ii=i-POS[1]*NX;
						jj=j-POS[2]*NY;

						rho[jj][ii]=rhov;
					}
				}
			}
238 239 240
		}
		
		for (j=(int)(fldepth[nodes]/DH)+1;j<=NYG;j++){
Tilman Steinweg's avatar
Tilman Steinweg committed
241
			
242 243 244 245 246 247 248 249 250
			rhov=0.0;
			rhov=flrho[nodes]*1000.0;
			
			
			/* 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))){
				ii=i-POS[1]*NX;
				jj=j-POS[2]*NY;
Tilman Steinweg's avatar
Tilman Steinweg committed
251

252
				rho[jj][ii]=rhov;
Tilman Steinweg's avatar
Tilman Steinweg committed
253 254
			}
		}
255
	}
Tilman Steinweg's avatar
Tilman Steinweg committed
256 257 258 259
	
	free_vector(fldepth,1,nodes);
	free_vector(flrho,1,nodes);
	free_vector(flvp,1,nodes);	
260
	
Tilman Steinweg's avatar
Tilman Steinweg committed
261 262 263 264 265 266 267 268
	
        sprintf(modfile,"%s_rho_it0.bin",INV_MODELFILE);
	writemod(modfile,rho,3);
	MPI_Barrier(MPI_COMM_WORLD);
	if (MYID==0) mergemod(modfile,3);
	MPI_Barrier(MPI_COMM_WORLD); 
	sprintf(modfile,"%s_rho_it0.bin.%i%i",INV_MODELFILE,POS[1],POS[2]);
	remove(modfile);
269
	
Tilman Steinweg's avatar
Tilman Steinweg committed
270 271 272 273 274 275 276
	sprintf(modfile,"%s_vp_it0.bin",INV_MODELFILE);
	writemod(modfile,pi,3);
	MPI_Barrier(MPI_COMM_WORLD);
	if (MYID==0) mergemod(modfile,3);
	MPI_Barrier(MPI_COMM_WORLD); 
	sprintf(modfile,"%s_vp_it0.bin.%i%i",INV_MODELFILE,POS[1],POS[2]);
	remove(modfile);
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
	
	sprintf(modfile,"%s",TAPER_FILE_NAME);
	writemod(modfile,taper,3);
	MPI_Barrier(MPI_COMM_WORLD);
	if (MYID==0) mergemod(modfile,3);
	MPI_Barrier(MPI_COMM_WORLD); 
	sprintf(modfile,"%s.%i%i",TAPER_FILE_NAME,POS[1],POS[2]);
	remove(modfile);
	
	sprintf(modfile,"%s",TAPER_FILE_NAME_RHO);
	writemod(modfile,taper,3);
	MPI_Barrier(MPI_COMM_WORLD);
	if (MYID==0) mergemod(modfile,3);
	MPI_Barrier(MPI_COMM_WORLD); 
	sprintf(modfile,"%s.%i%i",TAPER_FILE_NAME_RHO,POS[1],POS[2]);
	remove(modfile);
	
	free_matrix(taper,-nd+1,NY+nd,-nd+1,NX+nd);
	
Tilman Steinweg's avatar
Tilman Steinweg committed
296
}