eprecond1.c 1.91 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
/* This function is copied from DENISE Black Edition from D. Koehn  */

#include "fd.h"
void eprecond1(float ** We, float ** Ws, float ** Wr){
    
    extern int NX, NY, IDX, IDY, DTINV, EPRECOND, VERBOSE;
    extern int POS[3], NXG;
    extern float DH;
    int i, j, k, l, ii, jj;
    float maxWetmp, maxWe, x, y, xmin, xmax;
    extern float EPSILON_WE;
    xmin = DH;
    xmax = NXG*DH;
    
    
    maxWetmp=0.0;
    
    if(EPRECOND==1){
        /* calculate energy weighting */
        for (i=1;i<=NX;i=i+IDX){
            for (j=1;j<=NY;j=j+IDY){
                
                We[j][i]=sqrt(Ws[j][i]*Wr[j][i]); /* energy weighted source and receiver contribution */
                
                /* estimate maximum We on this CPU*/
                if(We[j][i]>maxWetmp){
                    maxWetmp = We[j][i];
                }
                
            }
        }
    }
    
    if(EPRECOND==3){
        /* Forward wavefield + approximation of the receiver Greens function (Plessix and Mulder, 2004) */
        for (i=1;i<=NX;i=i+IDX){
            for (j=1;j<=NY;j=j+IDY){
                
                /* calculate global coordinates */
                ii=i+POS[1]*NX;
                jj=j+POS[2]*NY;
                
                x = ii*DH;
                y = jj*DH;
                
                We[j][i]= sqrt(Ws[j][i]) * (asinh((xmax-x)/y)-asinh((xmin-x)/y));
                
                /* estimate maximum We on this CPU*/
                if(We[j][i]>maxWetmp){
                    maxWetmp = We[j][i];
                }
                
            }
        }
    }
    
    /* estimate maximum of We */
    MPI_Allreduce(&maxWetmp,&maxWe,1,MPI_FLOAT,MPI_MAX,MPI_COMM_WORLD);
    /* regularize energy weighting to avoid divison by zero */
    for (i=1;i<=NX;i=i+IDX){
        for (j=1;j<=NY;j=j+IDY){
            
            We[j][i] = We[j][i] + (EPSILON_WE*maxWe);
            
        }
    }
    
    
}