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

/*------------------------------------------------------------------------
 *  Apply workflow
 *
 *  Written by Wittkamp Oct 2015
 *  ----------------------------------------------------------------------*/

#include "fd.h"

void apply_workflow(float ** workflow,int workflow_lines,int workflow_line_current ,int *iter,float *FC,int wavetype_start, int * change_wavetype_iter, int * LBFGS_iter_start){
    
    /* local variables */
    int x;
    
    /* extern variables */
    extern int INV_RHO_ITER,INV_VS_ITER,INV_VP_ITER;
    extern int TIME_FILT,MYID;
    extern float PRO;
    extern int WAVETYPE;
    extern float JOINT_INVERSION_PSV_SH_ALPHA_VS;
    extern float JOINT_INVERSION_PSV_SH_ALPHA_RHO;
    extern int EPRECOND;
    extern float EPSILON_WE;
Florian Wittkamp's avatar
Florian Wittkamp committed
41
    extern int GRAD_METHOD;
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
    
    /******************/
    /* Apply Workflow */
    /******************/
    
    /* Print current workflow */
    if(MYID==0){
        printf("\n ---------- Applying Workflow -----------\n");
        printf(" ITER\tINV_VS\tINV_VP\tINV_RHO\tPRO\tTI_FILT\tFC\tWT\n ");
        for(x=1;x<=WORKFLOW_MAX_VAR;x++){
            printf("%.2f\t",workflow[workflow_line_current][x]);
        }
    }
    
    /* Inversion of material parameter */
    if(workflow[workflow_line_current][2]!=-1) {
        if(workflow[workflow_line_current][2]==1) {
            if(INV_VS_ITER>*iter) INV_VS_ITER=*iter;
        } else {
            /* detect change and reset LBFGS */
            if(INV_VS_ITER<*iter) *LBFGS_iter_start=*iter;
            INV_VS_ITER=*iter+10;
        }
    }
    
    if(workflow[workflow_line_current][3]!=-1){
        if(workflow[workflow_line_current][3]==1) {
            if(INV_VP_ITER>*iter) INV_VP_ITER=*iter;
        } else {
            /* detect change and reset LBFGS */
            if(INV_VP_ITER<*iter) *LBFGS_iter_start=*iter;
            INV_VP_ITER=*iter+10;
        }
    }
    
    if(workflow[workflow_line_current][4]!=-1){
        if(workflow[workflow_line_current][4]==1) {
            if(INV_RHO_ITER>*iter) INV_RHO_ITER=*iter;
        } else {
            /* detect change and reset LBFGS */
            if(INV_RHO_ITER<*iter) *LBFGS_iter_start=*iter;
            INV_RHO_ITER=*iter+10;
        }
    }
    
    PRO=workflow[workflow_line_current][5];
    
    /* Frequency filtering  */
    if(TIME_FILT==1) {
        TIME_FILT=workflow[workflow_line_current][6];
        if(*FC>workflow[workflow_line_current][7]&&(workflow[workflow_line_current][6]>0)) {
            if(MYID==0)printf("\n Due to the abort criteriom FC is already higher than specified in workflow\n");
            if(MYID==0)printf(" therefore instead of %.2f HZ FC=%.2f HZ is used\n",workflow[workflow_line_current][7],*FC);
        } else {
            if(*FC!=workflow[workflow_line_current][7]) *LBFGS_iter_start=*iter;
            *FC=workflow[workflow_line_current][7];
        }
    } else {
        if(MYID==0)printf("\n TIME_FILT cannot be activated due to it is not activated in the JSON File \n");
    }
    /* Change of wavetype  */
    if(wavetype_start!=3&&(WAVETYPE!=workflow[workflow_line_current][8])){
        if(MYID==0)printf("\n Sorry, change of WAVETYPE with workflow only possible if WAVETYPE==3 in *.json");
        if(MYID==0)printf("\n WAVETYPE will remain unchanged %i",WAVETYPE);
    } else {
        /* detect change and reset some things */
        if(WAVETYPE!=workflow[workflow_line_current][8]) {
            *change_wavetype_iter=*iter;
            *LBFGS_iter_start=*iter;
        }
        WAVETYPE=workflow[workflow_line_current][8];
    }
    
    /* Joint inversion PSV and SH  */
    JOINT_INVERSION_PSV_SH_ALPHA_VS=workflow[workflow_line_current][9];
    JOINT_INVERSION_PSV_SH_ALPHA_RHO=workflow[workflow_line_current][10];
    
    /* Approx. Hessian  */
    EPRECOND=workflow[workflow_line_current][11];
    EPSILON_WE=workflow[workflow_line_current][12];
    
Florian Wittkamp's avatar
Florian Wittkamp committed
123
    if(*LBFGS_iter_start==*iter && GRAD_METHOD==2){
124 125 126
        if(MYID==0)printf("\n L-BFGS will be used from iteration %d on.",*LBFGS_iter_start+1);
    }
}