eprecond1.c 2.1 KB
Newer Older
Florian Wittkamp's avatar
Florian Wittkamp committed
1
/*                          Acknowledgement                         */
2
/* This function is copied from DENISE Black Edition from D. Koehn  */
Florian Wittkamp's avatar
Florian Wittkamp committed
3
4
/* Licence: GNU GENERAL PUBLIC LICENSE Version 2, June 1991         */
/* https://github.com/daniel-koehn/DENISE-Black-Edition             */
5
6

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