readmod_el_vti.c 8.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 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
/*-----------------------------------------------------------------------------------------
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
 *
 * This file is part of IFOS.
 *
 * IFOS 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.
 *
 * IFOS 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 IFOS. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
 -----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *   Read elastic model properties (vp,vs,density,delta,epsilon,gamma) from files
 *
 *  ----------------------------------------------------------------------*/


/* This file contains function readmod, which has the purpose
 to read data from model-files for viscoelastic simulation */

#include "fd.h"

void readmod_el_vti(float  **  rho, float **  pi, float **  u, float **delta, float **epsilon, float **vshor){
    
    extern int NX, NY, NXG, NYG,  POS[3], MYID, PARAMETERIZATION,WAVETYPE;
    extern char  MFILE[STRING_SIZE];
    extern FILE *FP;
    
    
    /* local variables */
    float rhov, vp = 0.0, vs, deltav, epsilonv, vshorv;
    int i, j, ii, jj;
    FILE *fp_vs, *fp_vp = NULL, *fp_rho, *fp_epsilon, *fp_delta, *fp_vshor;
    char filename[STRING_SIZE];


    
    
    
    
	   fprintf(FP,"\n...reading model information from model-files...\n");
       /* ----------------------------------- */
	   /* read density and seismic velocities */
	   /* ----------------------------------- */
	   if(PARAMETERIZATION==1){
           
           if(WAVETYPE==1||WAVETYPE==3){
               fprintf(FP,"\t Vp:\n\t %s.vp\n\n",MFILE);
               sprintf(filename,"%s.vp",MFILE);
               fp_vp=fopen(filename,"r");
               if (fp_vp==NULL) declare_error(" Could not open model file for Vp ! ");
	       
	       fprintf(FP,"\t Epsilon:\n\t %s.epsilon\n\n",MFILE);
	       sprintf(filename,"%s.epsilon",MFILE);
	       fp_epsilon=fopen(filename,"r");
	       if (fp_epsilon==NULL) declare_error(" Could not open model file for epsilon ! ");
	    
	       fprintf(FP,"\t Delta:\n\t %s.delta\n\n",MFILE);
	       sprintf(filename,"%s.delta",MFILE);
	       fp_delta=fopen(filename,"r");
	       if (fp_delta==NULL) declare_error(" Could not open model file for delta ! ");
           }
           
	   
	   if(WAVETYPE==2||WAVETYPE==3){
		fprintf(FP,"\t Vshor:\n\t %s.vshor\n\n",MFILE);
		sprintf(filename,"%s.vshor",MFILE);
		fp_vshor=fopen(filename,"r");
		if (fp_vshor==NULL) declare_error(" Could not open model file for vshor ! ");
	   }
	   
	   fprintf(FP,"\t Vs:\n\t %s.vs\n\n",MFILE);
           sprintf(filename,"%s.vs",MFILE);
           fp_vs=fopen(filename,"r");
           if (fp_vs==NULL) declare_error(" Could not open model file for Vs ! ");
           
           fprintf(FP,"\t Density:\n\t %s.rho\n\n",MFILE);
           sprintf(filename,"%s.rho",MFILE);
           fp_rho=fopen(filename,"r");
           if (fp_rho==NULL) declare_error(" Could not open model file for densities ! ");
           
           
       } else {
	   
	   /* read density and Lame parameters */
	   /* ----------------------------------- */
           fprintf(FP,"\t Lame parameter lambda:\n\t %s.lam\n\n",MFILE);
           sprintf(filename,"%s.lam",MFILE);
           fp_vp=fopen(filename,"r");
           if (fp_vp==NULL) declare_error(" Could not open model file for Lame parameter lambda ! ");
           
           
           fprintf(FP,"\t Lame parameter mu:\n\t %s.mu\n\n",MFILE);
           sprintf(filename,"%s.mu",MFILE);
           fp_vs=fopen(filename,"r");
           if (fp_vs==NULL) declare_error(" Could not open model file for Lame parameter mu ! ");
           
           fprintf(FP,"\t Density:\n\t %s.rho\n\n",MFILE);
           sprintf(filename,"%s.rho",MFILE);
           fp_rho=fopen(filename,"r");
           if (fp_rho==NULL) declare_error(" Could not open model file for densities ! ");
       }
	   
    
    /* loop over global grid */
    for (i=1;i<=NXG;i++){
        for (j=1;j<=NYG;j++){
            
            if(WAVETYPE==1||WAVETYPE==3){
                
                if(feof(fp_vp)){
                    declare_error("Model file VP is to small. Check dimensions NX*NY of file.");
		}
		if(feof(fp_epsilon) || feof(fp_delta)){
                    declare_error("Model file EPSILON or DELTA is to small. Check dimensions NX*NY of file.");    
                }
                
                fread(&vp, sizeof(float), 1, fp_vp);
		fread(&epsilonv, sizeof(float), 1, fp_epsilon);
		fread(&deltav, sizeof(float), 1, fp_delta);
                
            }
            
            if(WAVETYPE==2||WAVETYPE==3){
		
		if(feof(fp_vshor)){
		    declare_error("Model file VSHOR is to small. Check dimensions NX*NY of file.");
		}
		
		fread(&vshorv, sizeof(float), 1, fp_vshor);
	    }
            
            
            
            if(feof(fp_vs) || feof(fp_rho)){
                declare_error("Model file VS or RHO is to small. Check dimensions NX*NY of file.");
            }
            
            fread(&vs, sizeof(float), 1, fp_vs);
            fread(&rhov, sizeof(float), 1, fp_rho);
	    
	    
            
            
            /* 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;
                
// 		c33v=vp*vp*rhov;
// 		c55v=vs*vs*rhov;
// 		c11v=c33v*(1+2*epsilon);
// 		c13v=sqrt(2*delta*c33v*(c33v-c55v)+(c33v-c55v)*(c33v-c55v))-c55v;
// 		c66v=c55v*(2*gamma+1);
	    
		u[jj][ii]=vs;
		pi[jj][ii]=vp;
		delta[jj][ii]=deltav;
		epsilon[jj][ii]=epsilonv;
		vshor[jj][ii]=vshorv;		//horizontal SH-velocity
		rho[jj][ii]=rhov;
					
					
	    
//                 u[jj][ii]=vs;
//                 rho[jj][ii]=rhov;
//                 if(WAVETYPE==1||WAVETYPE==3){
// //                    pi[jj][ii]=vp;
//                 }
                
                
                
            }
        }
    }
    if(WAVETYPE==1||WAVETYPE==3){
        
        fread(&vp, sizeof(float), 1, fp_vp);
        if(!feof(fp_vp)){
            declare_error("Model file VP is to big. Check dimensions NX*NY of file.");
        }
        
        fread(&epsilonv, sizeof(float), 1, fp_epsilon);
	fread(&delta, sizeof(float), 1, fp_delta);
        if(!feof(fp_epsilon) || !feof(fp_delta)){
            declare_error("Model file EPSILON or DELTA is to big. Check dimensions NX*NY of file.");
        }
        
        fclose(fp_vp);
	fclose(fp_epsilon);
	fclose(fp_delta);
    }
    
    if(WAVETYPE==2||WAVETYPE==3){
	
	fread(&vshorv, sizeof(float), 1, fp_vshor);
	if(!feof(fp_vshor)){
            declare_error("Model file VSHOR is to big. Check dimensions NX*NY of file.");
        }
	fclose(fp_vshor);
    }
    
    fread(&vs, sizeof(float), 1, fp_vs);
    fread(&rhov, sizeof(float), 1, fp_rho);
    if(!feof(fp_vs) || !feof(fp_rho)){
        declare_error("Model file VS or RHO is to big. Check dimensions NX*NY of file.");
    }
    fclose(fp_vs);
    fclose(fp_rho);
    
    
    
    
    
    /* each PE writes his model to disk */
    if(WAVETYPE==1||WAVETYPE==3){
        if(PARAMETERIZATION==1) sprintf(filename,"%s.out.vp",MFILE);
        if(PARAMETERIZATION==3) sprintf(filename,"%s.out.pi",MFILE);
        write_matrix_disk(pi, filename);
	
	sprintf(filename,"%s.out.epsilon",MFILE);
	write_matrix_disk(epsilon, filename);
	
	sprintf(filename,"%s.out.delta",MFILE);
	write_matrix_disk(delta, filename);
    }
    
    if(WAVETYPE==2||WAVETYPE==3){
	sprintf(filename,"%s.out.vshor",MFILE);
	write_matrix_disk(vshor, filename);
    }
	
    
    if(PARAMETERIZATION==1) sprintf(filename,"%s.out.vs",MFILE);
    if(PARAMETERIZATION==3) sprintf(filename,"%s.out.mu",MFILE);
    write_matrix_disk(u, filename);
    
    sprintf(filename,"%s.out.rho",MFILE);
    write_matrix_disk(rho, filename);
    
    
    
    
    
}