eprecond1.c 1.9 KB
Newer Older
1 2 3
/* This function is copied from DENISE Black Edition from D. Koehn  */

#include "fd.h"
4
void eprecond1(float ** We, float ** Ws, float ** Wr, float epsilon){
5 6 7 8 9 10 11 12 13 14 15 16 17 18
    
    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;
    xmin = DH;
    xmax = NXG*DH;
    
    
    maxWetmp=0.0;
    
    if(EPRECOND==1){
        /* calculate energy weighting */
19 20
        for (j=1;j<=NY;j=j+IDY){
            for (i=1;i<=NX;i=i+IDX){
21 22 23 24 25 26 27 28 29 30 31 32 33 34
                
                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) */
35 36
        for (j=1;j<=NY;j=j+IDY){
            for (i=1;i<=NX;i=i+IDX){
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
                
                /* 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);
58
    
59
    /* regularize energy weighting to avoid divison by zero */
60 61
    for (j=1;j<=NY;j=j+IDY){
        for (i=1;i<=NX;i=i+IDX){
62
            
63
            We[j][i] = We[j][i] + (epsilon*maxWe);
64 65 66 67 68 69
            
        }
    }
    
    
}