Changeset 17907


Ignore:
Timestamp:
05/01/14 13:40:47 (11 years ago)
Author:
Mathieu Morlighem
Message:

CHG: simplifying inversions

Location:
issm/trunk-jpl/src/c
Files:
3 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/Makefile.am

    r17895 r17907  
    209209                                        ./shared/Numerics/extrema.cpp\
    210210                                        ./shared/Numerics/XZvectorsToCoordinateSystem.cpp\
    211                                         ./shared/Numerics/OptArgs.h\
    212211                                        ./shared/Numerics/OptPars.h\
    213212                                        ./shared/Exceptions/exceptions.h\
     
    420419                                        ./classes/Inputs/ControlInput.cpp\
    421420                                        ./shared/Numerics/BrentSearch.cpp\
    422                                         ./shared/Numerics/OptimalSearch.cpp \
    423421                                        ./cores/control_core.cpp\
    424422                                        ./cores/controltao_core.cpp\
    425423                                        ./cores/controlm1qn3_core.cpp\
    426                                         ./cores/objectivefunction.cpp\
    427424                                        ./cores/gradient_core.cpp\
    428425                                        ./cores/adjointstressbalance_core.cpp\
  • issm/trunk-jpl/src/c/analyses/Analysis.h

    r17686 r17907  
    1717class ElementMatrix;
    1818class Gauss;
     19class FemModel;
    1920
    2021class Analysis{
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r17555 r17907  
    11741174}
    11751175/*}}}*/
    1176 void FemModel::CostFunctionx(IssmDouble* pJ){/*{{{*/
     1176void FemModel::CostFunctionx(IssmDouble* pJ,IssmDouble** pJlist,int* pn){/*{{{*/
    11771177
    11781178        /*Intermediary*/
     
    11881188        this->RequestedOutputsx(&cost_functions,responses,num_responses);
    11891189
    1190         /*Add all contributions one by one*/
    1191         IssmDouble J=0;
    1192         //_printf0_("list of misfits: ");
     1190        /*Get and add all contributions one by one*/
     1191        IssmDouble  J=0;
     1192        IssmDouble* Jlist = xNew<IssmDouble>(num_responses);
    11931193        for(int i=0;i<num_responses;i++){
    11941194                ExternalResult* result=(ExternalResult*)cost_functions->GetObjectByOffset(i);
    1195                 J += reCast<IssmDouble>(result->GetValue());
    1196                 //_printf0_(J<<" ");
    1197         }
    1198         //_printf0_(" \n");
     1195                Jlist[i] = reCast<IssmDouble>(result->GetValue());
     1196                J       += Jlist[i];
     1197        }
    11991198        _assert_(cost_functions->Size()==num_responses);
    12001199
     
    12021201        delete cost_functions;
    12031202        xDelete<int>(responses);
    1204         *pJ=J;
     1203        if(pJ)     *pJ     = J;
     1204        if(pJlist) *pJlist = Jlist;
     1205        else        xDelete<IssmDouble>(Jlist);
     1206        if(pn)     *pn     = num_responses;
    12051207}
    12061208/*}}}*/
  • issm/trunk-jpl/src/c/classes/FemModel.h

    r17394 r17907  
    8686                void Responsex(IssmDouble* presponse,const char* response_descriptor);
    8787                void OutputControlsx(Results **presults);
    88                 void CostFunctionx( IssmDouble* pJ);
     88                void CostFunctionx(IssmDouble* pJ,IssmDouble** pJlist,int* pn);
    8989                void ThicknessAbsGradientx( IssmDouble* pJ);
    9090                #ifdef _HAVE_GIA_
  • issm/trunk-jpl/src/c/cores/control_core.cpp

    r16518 r17907  
    1212/*Local prototypes*/
    1313bool controlconvergence(IssmDouble J, IssmDouble tol_cm);
     14IssmDouble objectivefunction(IssmDouble search_scalar,void* optargs);
    1415
    1516void control_core(FemModel* femmodel){
     
    3132        /*intermediary: */
    3233        IssmDouble search_scalar = 1.;
    33         OptArgs    optargs;
    3434        OptPars    optpars;
    3535
     
    6565
    6666        /*Initialize some of the BrentSearch arguments: */
    67         optargs.femmodel=femmodel;
    6867        optpars.xmin=0; optpars.xmax=1;
    6968
     
    8483                if(VerboseControl()) _printf0_("   optimizing along gradient direction\n");
    8584                optpars.maxiter=reCast<int,IssmDouble>(maxiter[n]); optpars.cm_jump=cm_jump[n];
    86                 BrentSearch(&search_scalar,J+n,&optpars,&objectivefunction,&optargs);
     85                BrentSearch(&search_scalar,J+n,&optpars,&objectivefunction,(void*)femmodel);
    8786
    8887                if(VerboseControl()) _printf0_("   updating parameter using optimized search scalar\n"); //true means update save controls
     
    128127        return converged;
    129128}
     129
     130IssmDouble objectivefunction(IssmDouble search_scalar,void* optargs){
     131
     132        /*output: */
     133        IssmDouble J;
     134
     135        /*parameters: */
     136        int        solution_type,analysis_type;
     137        bool       isFS       = false;
     138        bool       conserve_loads = true;
     139        FemModel  *femmodel       = (FemModel*)optargs;
     140
     141        /*Recover parameters: */
     142        femmodel->parameters->FindParam(&isFS,FlowequationIsFSEnum);
     143        femmodel->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
     144        femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
     145
     146        /*set analysis type to compute velocity: */
     147        if (solution_type==SteadystateSolutionEnum || solution_type==StressbalanceSolutionEnum){
     148                femmodel->SetCurrentConfiguration(StressbalanceAnalysisEnum);
     149        }
     150        else if (solution_type==BalancethicknessSolutionEnum){
     151                femmodel->SetCurrentConfiguration(BalancethicknessAnalysisEnum);
     152        }
     153        else if (solution_type==BalancethicknessSoftSolutionEnum){
     154                femmodel->SetCurrentConfiguration(BalancethicknessAnalysisEnum);
     155        }
     156        else{
     157                _error_("Solution " << EnumToStringx(solution_type) << " not implemented yet");
     158        }
     159
     160        /*update parameter according to scalar: */ //false means: do not save control
     161        InputControlUpdatex(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,search_scalar,false);
     162
     163        /*Run stressbalance with updated inputs: */
     164        if (solution_type==SteadystateSolutionEnum){
     165                stressbalance_core(femmodel);   //We need a 3D velocity!! (vz is required for the next thermal run)
     166        }
     167        else if (solution_type==StressbalanceSolutionEnum){
     168                solutionsequence_nonlinear(femmodel,conserve_loads);
     169        }
     170        else if (solution_type==BalancethicknessSolutionEnum){
     171                solutionsequence_linear(femmodel);
     172        }
     173        else if (solution_type==BalancethicknessSoftSolutionEnum){
     174                /*Don't do anything*/
     175        }
     176        else{
     177                _error_("Solution " << EnumToStringx(solution_type) << " not implemented yet");
     178        }
     179
     180        /*Compute misfit for this velocity field.*/
     181        femmodel->CostFunctionx(&J,NULL,NULL);
     182
     183        /*Free ressources:*/
     184        return J;
     185}
  • issm/trunk-jpl/src/c/cores/controlm1qn3_core.cpp

    r17905 r17907  
    160160
    161161        /*Compute objective function*/
    162         femmodel->CostFunctionx(pf);
     162        IssmDouble* Jlist = NULL;
     163        femmodel->CostFunctionx(pf,&Jlist,NULL);
    163164        _printf0_("f(x) = "<<setw(12)<<setprecision(7)<<*pf<<"  |  ");
    164165
    165166        /*Retrieve objective functions independently*/
    166         for(int i=0;i<num_responses;i++){
    167                 femmodel->Responsex(&f,EnumToStringx(responses[i]));
    168                 _printf0_(" "<<setw(12)<<setprecision(7)<<f);
    169         }
     167        for(int i=0;i<num_responses;i++) _printf0_(" "<<setw(12)<<setprecision(7)<<Jlist[i]);
    170168        _printf0_("\n");
     169        xDelete<IssmDouble>(Jlist);
    171170
    172171        if(indic==0){
  • issm/trunk-jpl/src/c/cores/controltao_core.cpp

    r16518 r17907  
    135135
    136136        /*Compute objective function*/
    137         femmodel->CostFunctionx(fcn);
     137        femmodel->CostFunctionx(fcn,NULL,NULL);
    138138
    139139        /*Compute gradient*/
  • issm/trunk-jpl/src/c/cores/cores.h

    r17895 r17907  
    77
    88/*forward declarations: */
    9 struct OptArgs;
    109class FemModel;
    1110class Parameters;
     
    4544void gia_core(FemModel* femmodel);
    4645void damage_core(FemModel* femmodel);
    47 IssmDouble objectivefunction(IssmDouble search_scalar,OptArgs* optargs);
     46IssmDouble objectivefunction(IssmDouble search_scalar,FemModel* femmodel);
    4847
    4948//optimization
  • issm/trunk-jpl/src/c/shared/Numerics/BrentSearch.cpp

    r15278 r17907  
    1717#include "./Verbosity.h"
    1818#include "./OptPars.h"
    19 #include "./OptArgs.h"
    2019#include "./types.h"
    2120#include "./isnan.h"
    2221
    23 void BrentSearch(IssmDouble* psearch_scalar,IssmDouble* pJ,OptPars* optpars,IssmDouble (*f)(IssmDouble,OptArgs*), OptArgs* optargs){
     22void BrentSearch(IssmDouble* psearch_scalar,IssmDouble* pJ,OptPars* optpars,IssmDouble (*f)(IssmDouble,void*),void* optargs){
    2423
    2524        /* This routine is optimizing a given function using Brent's method
  • issm/trunk-jpl/src/c/shared/Numerics/numerics.h

    r17629 r17907  
    1818#include "./types.h"
    1919#include "./constants.h"
    20 #include "./OptArgs.h"
    2120#include "./OptPars.h"
    2221
     
    3130int         min(int a,int b);
    3231int         max(int a,int b);
    33 IssmDouble  OptFunc(IssmDouble scalar, OptArgs *optargs);
    34 void        BrentSearch(IssmDouble *psearch_scalar,IssmDouble*pJ,OptPars*optpars,IssmDouble (*f)(IssmDouble,OptArgs*), OptArgs*optargs);
    35 void        OptimalSearch(IssmDouble *psearch_scalar,IssmDouble*pJ,OptPars*optpars,IssmDouble (*f)(IssmDouble,OptArgs*), OptArgs*optargs);
     32void        BrentSearch(IssmDouble *psearch_scalar,IssmDouble*pJ,OptPars*optpars,IssmDouble (*f)(IssmDouble,void*),void* optargs);
    3633void        cross(IssmDouble *result,IssmDouble*vector1,IssmDouble*vector2);
    3734void        XZvectorsToCoordinateSystem(IssmDouble *T,IssmDouble*xzvectors);
Note: See TracChangeset for help on using the changeset viewer.