Changeset 17907
- Timestamp:
- 05/01/14 13:40:47 (11 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 3 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/Makefile.am
r17895 r17907 209 209 ./shared/Numerics/extrema.cpp\ 210 210 ./shared/Numerics/XZvectorsToCoordinateSystem.cpp\ 211 ./shared/Numerics/OptArgs.h\212 211 ./shared/Numerics/OptPars.h\ 213 212 ./shared/Exceptions/exceptions.h\ … … 420 419 ./classes/Inputs/ControlInput.cpp\ 421 420 ./shared/Numerics/BrentSearch.cpp\ 422 ./shared/Numerics/OptimalSearch.cpp \423 421 ./cores/control_core.cpp\ 424 422 ./cores/controltao_core.cpp\ 425 423 ./cores/controlm1qn3_core.cpp\ 426 ./cores/objectivefunction.cpp\427 424 ./cores/gradient_core.cpp\ 428 425 ./cores/adjointstressbalance_core.cpp\ -
issm/trunk-jpl/src/c/analyses/Analysis.h
r17686 r17907 17 17 class ElementMatrix; 18 18 class Gauss; 19 class FemModel; 19 20 20 21 class Analysis{ -
issm/trunk-jpl/src/c/classes/FemModel.cpp
r17555 r17907 1174 1174 } 1175 1175 /*}}}*/ 1176 void FemModel::CostFunctionx(IssmDouble* pJ ){/*{{{*/1176 void FemModel::CostFunctionx(IssmDouble* pJ,IssmDouble** pJlist,int* pn){/*{{{*/ 1177 1177 1178 1178 /*Intermediary*/ … … 1188 1188 this->RequestedOutputsx(&cost_functions,responses,num_responses); 1189 1189 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); 1193 1193 for(int i=0;i<num_responses;i++){ 1194 1194 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 } 1199 1198 _assert_(cost_functions->Size()==num_responses); 1200 1199 … … 1202 1201 delete cost_functions; 1203 1202 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; 1205 1207 } 1206 1208 /*}}}*/ -
issm/trunk-jpl/src/c/classes/FemModel.h
r17394 r17907 86 86 void Responsex(IssmDouble* presponse,const char* response_descriptor); 87 87 void OutputControlsx(Results **presults); 88 void CostFunctionx( IssmDouble* pJ);88 void CostFunctionx(IssmDouble* pJ,IssmDouble** pJlist,int* pn); 89 89 void ThicknessAbsGradientx( IssmDouble* pJ); 90 90 #ifdef _HAVE_GIA_ -
issm/trunk-jpl/src/c/cores/control_core.cpp
r16518 r17907 12 12 /*Local prototypes*/ 13 13 bool controlconvergence(IssmDouble J, IssmDouble tol_cm); 14 IssmDouble objectivefunction(IssmDouble search_scalar,void* optargs); 14 15 15 16 void control_core(FemModel* femmodel){ … … 31 32 /*intermediary: */ 32 33 IssmDouble search_scalar = 1.; 33 OptArgs optargs;34 34 OptPars optpars; 35 35 … … 65 65 66 66 /*Initialize some of the BrentSearch arguments: */ 67 optargs.femmodel=femmodel;68 67 optpars.xmin=0; optpars.xmax=1; 69 68 … … 84 83 if(VerboseControl()) _printf0_(" optimizing along gradient direction\n"); 85 84 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); 87 86 88 87 if(VerboseControl()) _printf0_(" updating parameter using optimized search scalar\n"); //true means update save controls … … 128 127 return converged; 129 128 } 129 130 IssmDouble 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 160 160 161 161 /*Compute objective function*/ 162 femmodel->CostFunctionx(pf); 162 IssmDouble* Jlist = NULL; 163 femmodel->CostFunctionx(pf,&Jlist,NULL); 163 164 _printf0_("f(x) = "<<setw(12)<<setprecision(7)<<*pf<<" | "); 164 165 165 166 /*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]); 170 168 _printf0_("\n"); 169 xDelete<IssmDouble>(Jlist); 171 170 172 171 if(indic==0){ -
issm/trunk-jpl/src/c/cores/controltao_core.cpp
r16518 r17907 135 135 136 136 /*Compute objective function*/ 137 femmodel->CostFunctionx(fcn );137 femmodel->CostFunctionx(fcn,NULL,NULL); 138 138 139 139 /*Compute gradient*/ -
issm/trunk-jpl/src/c/cores/cores.h
r17895 r17907 7 7 8 8 /*forward declarations: */ 9 struct OptArgs;10 9 class FemModel; 11 10 class Parameters; … … 45 44 void gia_core(FemModel* femmodel); 46 45 void damage_core(FemModel* femmodel); 47 IssmDouble objectivefunction(IssmDouble search_scalar, OptArgs* optargs);46 IssmDouble objectivefunction(IssmDouble search_scalar,FemModel* femmodel); 48 47 49 48 //optimization -
issm/trunk-jpl/src/c/shared/Numerics/BrentSearch.cpp
r15278 r17907 17 17 #include "./Verbosity.h" 18 18 #include "./OptPars.h" 19 #include "./OptArgs.h"20 19 #include "./types.h" 21 20 #include "./isnan.h" 22 21 23 void BrentSearch(IssmDouble* psearch_scalar,IssmDouble* pJ,OptPars* optpars,IssmDouble (*f)(IssmDouble, OptArgs*), OptArgs* optargs){22 void BrentSearch(IssmDouble* psearch_scalar,IssmDouble* pJ,OptPars* optpars,IssmDouble (*f)(IssmDouble,void*),void* optargs){ 24 23 25 24 /* This routine is optimizing a given function using Brent's method -
issm/trunk-jpl/src/c/shared/Numerics/numerics.h
r17629 r17907 18 18 #include "./types.h" 19 19 #include "./constants.h" 20 #include "./OptArgs.h"21 20 #include "./OptPars.h" 22 21 … … 31 30 int min(int a,int b); 32 31 int 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); 32 void BrentSearch(IssmDouble *psearch_scalar,IssmDouble*pJ,OptPars*optpars,IssmDouble (*f)(IssmDouble,void*),void* optargs); 36 33 void cross(IssmDouble *result,IssmDouble*vector1,IssmDouble*vector2); 37 34 void XZvectorsToCoordinateSystem(IssmDouble *T,IssmDouble*xzvectors);
Note:
See TracChangeset
for help on using the changeset viewer.