apply_workflow.c 4.94 KB
Newer Older
1
/*-----------------------------------------------------------------------------------------
2
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
3
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
4
 * This file is part of IFOS.
5
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
6
 * IFOS is free software: you can redistribute it and/or modify
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,
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>.
17 18 19 20 21 22 23 24 25
 -----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *  Apply workflow
 *
 *  ----------------------------------------------------------------------*/

#include "fd.h"

26
void apply_workflow(float ** workflow,int workflow_lines,char workflow_header[STRING_SIZE],int *iter,float *F_LOW_PASS,int wavetype_start, int * change_wavetype_iter, int * LBFGS_iter_start){
27 28 29 30 31 32 33 34 35 36 37 38 39
    
    /* 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
40
    extern int GRAD_METHOD;
41
    extern int WORKFLOW_STAGE;
42 43 44 45 46 47 48 49
    
    /******************/
    /* Apply Workflow */
    /******************/
    
    /* Print current workflow */
    if(MYID==0){
        printf("\n ---------- Applying Workflow -----------\n");
50
        printf(" %s ",workflow_header);
51
        for(x=1;x<=WORKFLOW_MAX_VAR;x++){
52
            printf("%.2f\t",workflow[WORKFLOW_STAGE][x]);
53 54 55 56
        }
    }
    
    /* Inversion of material parameter */
57 58
    if(workflow[WORKFLOW_STAGE][2]!=-1) {
        if(workflow[WORKFLOW_STAGE][2]==1) {
59 60 61 62 63 64 65 66
            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;
        }
    }
    
67 68
    if(workflow[WORKFLOW_STAGE][3]!=-1){
        if(workflow[WORKFLOW_STAGE][3]==1) {
69 70 71 72 73 74 75 76
            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;
        }
    }
    
77 78
    if(workflow[WORKFLOW_STAGE][4]!=-1){
        if(workflow[WORKFLOW_STAGE][4]==1) {
79 80 81 82 83 84 85 86
            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;
        }
    }
    
87
    /* Abort criterium */
88
    PRO=workflow[WORKFLOW_STAGE][5];
89 90
    
    /* Frequency filtering  */
91
    if(TIME_FILT==1) {
92
        TIME_FILT=workflow[WORKFLOW_STAGE][6];
93 94 95 96 97 98
        if(*F_LOW_PASS>workflow[WORKFLOW_STAGE][7]&&(workflow[WORKFLOW_STAGE][6]>0)) {
            if(MYID==0)printf("\n Due to the abort criteriom F_LOW_PASS is already higher than specified in workflow\n");
            if(MYID==0)printf(" therefore instead of %.2f HZ F_LOW_PASS=%.2f HZ is used\n",workflow[WORKFLOW_STAGE][7],*F_LOW_PASS);
        } else {
            if(*F_LOW_PASS!=workflow[WORKFLOW_STAGE][7]) *LBFGS_iter_start=*iter;
            *F_LOW_PASS=workflow[WORKFLOW_STAGE][7];
99 100
        }
    } else {
101
        if(MYID==0&&(workflow[WORKFLOW_STAGE][6]>0))printf("\n TIME_FILT cannot be activated due to it is not activated in the JSON File \n");
102
    }
103
    
104
    /* Change of wavetype  */
105
    if(wavetype_start!=3&&(WAVETYPE!=workflow[WORKFLOW_STAGE][8])){
106 107 108 109
        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 */
110
        if(WAVETYPE!=workflow[WORKFLOW_STAGE][8]) {
111 112 113
            *change_wavetype_iter=*iter;
            *LBFGS_iter_start=*iter;
        }
114
        WAVETYPE=workflow[WORKFLOW_STAGE][8];
115 116 117
    }
    
    /* Joint inversion PSV and SH  */
118 119
    JOINT_INVERSION_PSV_SH_ALPHA_VS=workflow[WORKFLOW_STAGE][9];
    JOINT_INVERSION_PSV_SH_ALPHA_RHO=workflow[WORKFLOW_STAGE][10];
120 121
    
    /* Approx. Hessian  */
122
    if(EPRECOND==0 && workflow[WORKFLOW_STAGE][11]!=0){
123 124
        if(MYID==0) printf(" WARNING: EPRECOND have to be set >0 in JSON (if so, ignore this message)");
    }
125 126
    EPRECOND=workflow[WORKFLOW_STAGE][11];
    EPSILON_WE=workflow[WORKFLOW_STAGE][12];
127
    
Florian Wittkamp's avatar
Florian Wittkamp committed
128
    if(*LBFGS_iter_start==*iter && GRAD_METHOD==2){
129 130
        if(MYID==0)printf("\n L-BFGS will be used from iteration %d on.",*LBFGS_iter_start+1);
    }
131
}