Changeset 6238
- Timestamp:
- 10/11/10 12:28:01 (14 years ago)
- Location:
- issm/trunk/src
- Files:
-
- 6 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified issm/trunk/src/c/Makefile.am ¶
r6213 r6238 551 551 ./modules/ControlInputSetGradientx/ControlInputSetGradientx.cpp\ 552 552 ./modules/ControlInputSetGradientx/ControlInputSetGradientx.h\ 553 ./modules/ControlInputScaleGradientx/ControlInputScaleGradientx.cpp\ 554 ./modules/ControlInputScaleGradientx/ControlInputScaleGradientx.h\ 553 555 ./modules/SystemMatricesx/SystemMatricesx.cpp\ 554 556 ./modules/SystemMatricesx/SystemMatricesx.h\ … … 1115 1117 ./modules/ControlInputSetGradientx/ControlInputSetGradientx.cpp\ 1116 1118 ./modules/ControlInputSetGradientx/ControlInputSetGradientx.h\ 1119 ./modules/ControlInputScaleGradientx/ControlInputScaleGradientx.cpp\ 1120 ./modules/ControlInputScaleGradientx/ControlInputScaleGradientx.h\ 1117 1121 ./modules/SystemMatricesx/SystemMatricesx.cpp\ 1118 1122 ./modules/SystemMatricesx/SystemMatricesx.h\ -
TabularUnified issm/trunk/src/c/modules/Orthx/Orthx.cpp ¶
r5323 r6238 25 25 } 26 26 27 /*scale to 1: gradient=gradient/max(abs(gradient))*/28 VecNorm(newgradj,NORM_INFINITY,&norm_new);29 if (norm_new<=0){30 ISSMERROR("||∂J/∂α||∞ = 0 gradient is zero");31 }32 if(isnan(norm_new)){33 ISSMERROR("input vector norm is NaN\n");34 }35 VecScale(newgradj,1.0/norm_new);36 37 27 /*Assign correct pointer*/ 38 28 *pnewgradj=newgradj; -
TabularUnified issm/trunk/src/c/modules/modules.h ¶
r6200 r6238 21 21 #include "./ControlInputGetGradientx/ControlInputGetGradientx.h" 22 22 #include "./ControlInputSetGradientx/ControlInputSetGradientx.h" 23 #include "./ControlInputScaleGradientx/ControlInputScaleGradientx.h" 23 24 #include "./CostFunctionx/CostFunctionx.h" 24 25 #include "./CreateNodalConstraintsx/CreateNodalConstraintsx.h" -
TabularUnified issm/trunk/src/c/objects/Elements/Element.h ¶
r6216 r6238 60 60 virtual void ControlInputGetGradient(Vec gradient,int enum_type)=0; 61 61 virtual void ControlInputSetGradient(double* gradient,int enum_type)=0; 62 virtual void ControlInputScaleGradient(int enum_type, double scale)=0; 62 63 virtual void ProcessResultsUnits(void)=0; 63 64 virtual void MinVel(double* pminvel, bool process_units)=0; -
TabularUnified issm/trunk/src/c/objects/Elements/Penta.cpp ¶
r6232 r6238 816 816 ((ControlInput*)input)->GetGradient(gradient,&doflist1[0]); 817 817 818 }/*}}}*/ 819 /*FUNCTION Penta::ControlInputScaleGradient{{{1*/ 820 void Penta::ControlInputScaleGradient(int enum_type,double scale){ 821 822 Input* input=NULL; 823 824 if(enum_type==RheologyBbarEnum){ 825 input=(Input*)matice->inputs->GetInput(enum_type); 826 } 827 else{ 828 input=inputs->GetInput(enum_type); 829 } 830 if (!input) ISSMERROR("Input %s not found",EnumToString(enum_type)); 831 if (input->Enum()!=ControlInputEnum) ISSMERROR("Input %s is not a ControlInput",EnumToString(enum_type)); 832 833 ((ControlInput*)input)->ScaleGradient(scale); 818 834 }/*}}}*/ 819 835 /*FUNCTION Penta::ControlInputSetGradient{{{1*/ -
TabularUnified issm/trunk/src/c/objects/Elements/Penta.h ¶
r6231 r6238 95 95 void InputScale(int enum_type,double scale_factor); 96 96 void ControlInputGetGradient(Vec gradient,int enum_type); 97 void ControlInputScaleGradient(int enum_type,double scale); 97 98 void ControlInputSetGradient(double* gradient,int enum_type); 98 99 void InputToResult(int enum_type,int step,double time); -
TabularUnified issm/trunk/src/c/objects/Elements/Tria.cpp ¶
r6233 r6238 793 793 794 794 }/*}}}*/ 795 /*FUNCTION Tria::ControlInputScaleGradient{{{1*/ 796 void Tria::ControlInputScaleGradient(int enum_type,double scale){ 797 798 Input* input=NULL; 799 800 if(enum_type==RheologyBbarEnum){ 801 input=(Input*)matice->inputs->GetInput(enum_type); 802 } 803 else{ 804 input=inputs->GetInput(enum_type); 805 } 806 if (!input) ISSMERROR("Input %s not found",EnumToString(enum_type)); 807 if (input->Enum()!=ControlInputEnum) ISSMERROR("Input %s is not a ControlInput",EnumToString(enum_type)); 808 809 ((ControlInput*)input)->ScaleGradient(scale); 810 }/*}}}*/ 795 811 /*FUNCTION Tria::ControlInputSetGradient{{{1*/ 796 812 void Tria::ControlInputSetGradient(double* gradient,int enum_type){ -
TabularUnified issm/trunk/src/c/objects/Elements/Tria.h ¶
r6231 r6238 96 96 void InputScale(int enum_type,double scale_factor); 97 97 void ControlInputGetGradient(Vec gradient,int enum_type); 98 void ControlInputScaleGradient(int enum_type,double scale); 98 99 void ControlInputSetGradient(double* gradient,int enum_type); 99 100 void InputToResult(int enum_type,int step,double time); -
TabularUnified issm/trunk/src/c/objects/Inputs/ControlInput.cpp ¶
r6200 r6238 266 266 if(gradient) gradient->GetVectorFromInputs(gradient_vec,doflist); 267 267 }/*}}}*/ 268 /*FUNCTION ControlInput::ScaleGradient{{{1*/ 269 void ControlInput::ScaleGradient(double scaling_factor){ 270 if(!gradient) ISSMERROR("Gradient of ControlInput %s not found",EnumToString(enum_type)); 271 gradient->Scale(scaling_factor); 272 }/*}}}*/ 268 273 /*FUNCTION ControlInput::SetGradient{{{1*/ 269 274 void ControlInput::SetGradient(Input* gradient_in){ -
TabularUnified issm/trunk/src/c/objects/Inputs/ControlInput.h ¶
r6200 r6238 78 78 ElementResult* SpawnGradient(int step, double time); 79 79 void GetGradient(Vec gradient_vec,int* doflist); 80 void ScaleGradient(double scale); 80 81 void SetGradient(Input* gradient_in); 81 82 void UpdateValue(double scalar); -
TabularUnified issm/trunk/src/c/solutions/gradient_core.cpp ¶
r6230 r6238 21 21 int *control_type = NULL; 22 22 double *optscal_list = NULL; 23 double optscal,norm_grad; 23 24 24 25 /*Intermediaries*/ … … 34 35 femmodel->parameters->FindParam(&verbose,VerboseEnum); 35 36 37 /*Compute and norm gradient of all controls*/ 36 38 for (int i=0;i<num_controls;i++){ 37 39 … … 44 46 _printf_("%s"," orthogonalization...\n"); 45 47 ControlInputGetGradientx(&old_gradient,femmodel->elements,femmodel->nodes, femmodel->vertices,femmodel->loads, femmodel->materials,femmodel->parameters,control_type[i]); 46 Orthx(&new_gradient,gradient,old_gradient); 47 VecFree(&old_gradient); 48 Orthx(&new_gradient,gradient,old_gradient); VecFree(&old_gradient); VecFree(&gradient); 48 49 } 49 50 else{ 50 51 _printf_("%s"," normalizing directions...\n"); 51 Orthx(&new_gradient,gradient,NULL); 52 Orthx(&new_gradient,gradient,NULL); VecFree(&gradient); 52 53 } 53 VecFree(&gradient);54 54 55 /*Scale gradient for current step and current parameter*/ 56 VecScale(new_gradient,optscal_list[num_controls*step+i]); 55 /*Get scaling factor of current control:*/ 56 VecNorm(new_gradient,NORM_INFINITY,&norm_grad); 57 if(norm_grad<=0) ISSMERROR("||∂J/∂α||∞ = 0 gradient norm of J with respect to %s is zero",EnumToString(control_type[i])); 58 if(isnan(norm_grad))ISSMERROR("||∂J/∂α||∞ = NaN gradient norm of J with respect to %s is NaN" ,EnumToString(control_type[i])); 59 if(i==0 || (optscal_list[num_controls*step+i]/norm_grad)<optscal) optscal=optscal_list[num_controls*step+i]/norm_grad; 57 60 58 61 /*plug back into inputs: */ 59 62 ControlInputSetGradientx(femmodel-> elements,femmodel-> nodes, femmodel-> vertices,femmodel-> loads, femmodel-> materials, femmodel->parameters,control_type[i],new_gradient); 60 61 /*Free ressources and return:*/62 63 VecFree(&new_gradient); 63 64 } 65 printf("norm grad = %g\n",norm_grad); 66 printf("optscal = %g\n",optscal); 67 68 /*Scale Gradients*/ 69 for (int i=0;i<num_controls;i++) ControlInputScaleGradientx(femmodel-> elements,femmodel-> nodes, femmodel-> vertices,femmodel-> loads, femmodel-> materials, femmodel->parameters,control_type[i],optscal); 64 70 65 71 /*Clean up and return*/ -
TabularUnified issm/trunk/src/m/solutions/gradient_core.m ¶
r6226 r6238 25 25 control_type=femmodel.parameters.ControlType; 26 26 control_steady=femmodel.parameters.ControlSteady; 27 optscal =femmodel.parameters.OptScal;27 optscal_list=femmodel.parameters.OptScal; 28 28 29 29 for i=1:num_controls, … … 32 32 grad=Gradj(femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters); 33 33 34 35 if control_steady; 34 if control_steady, 36 35 femmodel=diagnostic_core(femmodel); 37 36 end … … 46 45 end 47 46 48 %Scale Gradient 49 new_gradient=optscal(step,i)*new_gradient; 47 %Get scaling factor of current control: 48 norm_grad=norm(new_gradient,inf); 49 if(norm_grad<=0), error(['||∂J/∂α||∞ = 0 gradient norm of J with respect to ' EnumToString(control_type(i)) ' is zero']); end 50 if(isnan(norm_grad)), error(['||∂J/∂α||∞ = NaN gradient norm of J with respect to ' EnumToString(control_type(i)) ' is NaN' ]); end 51 if(i==1 | (optscal_list(step,i)/norm_grad)<optscal) optscal=optscal_list(step,i)/norm_grad; end 50 52 51 53 %plug back into inputs: 52 54 [femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters]=ControlInputSetGradient(femmodel.elements,femmodel.nodes, femmodel.vertices,femmodel.loads, femmodel.materials, femmodel.parameters,control_type(i),new_gradient); 53 55 end 56 57 %Scale all gradients 58 for i=1:num_controls, 59 [femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters]=ControlInputScaleGradient(femmodel.elements,femmodel.nodes, femmodel.vertices,femmodel.loads, femmodel.materials, femmodel.parameters,control_type(i),optscal); 60 end -
TabularUnified issm/trunk/src/mex/Makefile.am ¶
r6200 r6238 15 15 ControlOptimization\ 16 16 ControlInputGetGradient\ 17 ControlInputScaleGradient\ 17 18 ControlInputSetGradient\ 18 19 ContourToMesh \ … … 133 134 ControlInputGetGradient/ControlInputGetGradient.h 134 135 136 ControlInputScaleGradient_SOURCES = ControlInputScaleGradient/ControlInputScaleGradient.cpp\ 137 ControlInputScaleGradient/ControlInputScaleGradient.h 138 135 139 ControlInputSetGradient_SOURCES = ControlInputSetGradient/ControlInputSetGradient.cpp\ 136 140 ControlInputSetGradient/ControlInputSetGradient.h
Note:
See TracChangeset
for help on using the changeset viewer.