calc_opt_step.c 3.18 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1
/*-----------------------------------------------------------------------------------------
2
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
Tilman Steinweg's avatar
Tilman Steinweg committed
3
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
4
 * This file is part of IFOS.
Tilman Steinweg's avatar
Tilman Steinweg committed
5
 * 
Florian Wittkamp's avatar
Florian Wittkamp committed
6
 * IFOS is free software: you can redistribute it and/or modify
Tilman Steinweg's avatar
Tilman Steinweg committed
7 8 9
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
 * 
Florian Wittkamp's avatar
Florian Wittkamp committed
10
 * IFOS is distributed in the hope that it will be useful,
Tilman Steinweg's avatar
Tilman Steinweg committed
11 12 13 14 15
 * 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
Florian Wittkamp's avatar
Florian Wittkamp committed
16
 * along with IFOS. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
Tilman Steinweg's avatar
Tilman Steinweg committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
-----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *   calculate step length for material parameter update
 *   
 *   waveconv = conjugated gradient direction
 *   gradp    = preconditionated gradient
 *   
 *
 *  ---------------------------------------------------------------------*/

#include "fd.h"
float calc_opt_step(float *  L2t, float ** waveconv, float ** gradg, float * epst, int sws, float C_vp){

extern int NX, NY, IDX, IDY, MYID;
extern float EPSILON, EPSILON_u, EPSILON_rho;
33 34
int i, n;
float opteps, critmult;
Tilman Steinweg's avatar
Tilman Steinweg committed
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
float *x, *b, **A;

critmult = 5.0;
n = 3; /* number of test calculations */

A =  matrix(1,n,1,n);
x = vector(1,n);
b = vector(1,n);

/* calculate optimal step size after Tarantola (1986)*/
/*H1=0.0;
H2=0.0;
for (i=1;i<=NX;i=i+IDX){
     for (j=1;j<=NY;j=j+IDY){
         H1 += waveconv[j][i]*(1.0/C_vp)*waveconv[j][i];
	 H2 += waveconv[j][i]*gradg[j][i];
     }
  }
    
H1=exchange_L2(H1,1,1); 
H2=exchange_L2(H2,1,1);*/

/* calculate optimal step length for Vp update */
/*if(sws==1){
opteps = (H2/((L2t[sws]*L2t[sws]/(EPSILON*EPSILON))+H1));
if(fabs(opteps) > (10.0 * fabs(EPSILON)) ){opteps=EPSILON;}
61
opteps = EPSILON;*/
Tilman Steinweg's avatar
Tilman Steinweg committed
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
/*}*/ 

/* calculate optimal step length for Vs update */
/*if(sws==2){
opteps = EPSILON_u * ((L2t[sws]*L2t[4])/(L2t[sws]*L2t[sws]));
if(fabs(opteps) > (10.0 * fabs(EPSILON_u)) ){opteps=EPSILON_u;}
} */

/* calculate optimal step size by line search */

/* fit parabola function to L2 norm */

/* define coefficient matrix A */
for (i=1;i<=n;i++){
   A[i][3]=(epst[i]*epst[i]);
   A[i][2]=(epst[i]);
   A[i][1]=(1.0);
}

/* define RHS vector b */
for (i=1;i<=n;i++){
   b[i]=(L2t[i]);
}

/* solve matrix equation using LU decomposition */
/*LU_decomp(A,x,b,n);*/
solvelin(A,b,x,n,1);

/* calculate optimal step length -> extremum of the parabola */
opteps = -x[2]/(2.0*x[3]);

/* if L2[1] < L2[2] < L2[3]*/
if (((2.0*x[3])< 0.0)&&(L2t[2] > L2t[3])){
opteps = epst[3];
}

/* if L2[1] > L2[2] > L2[3] */
/*if (((2.0*x[3])< 0.0)&&(L2t[2] > L2t[1])){
opteps = epst[3];
}*/

/* if opteps < 50.0 set opteps=50.0 */
if (opteps > epst[3]){
opteps = epst[3];
}

if (opteps < 0.0){
opteps = epst[1];
}

/*if (epst[3]==0){
opteps = epst[1]/2.0;
}*/

/*opteps = epst[1];*/

/*if (isnan(opteps))
{opteps = epst[1];}*/


free_matrix(A,1,n,1,n);
free_vector(x,1,n);
free_vector(b,1,n);
return opteps;		
}