Changeset 4048
- Timestamp:
- 06/16/10 18:20:52 (15 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 7 added
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Makefile.am
r4047 r4048 393 393 ./modules/ScaleInputx/ScaleInputx.h\ 394 394 ./modules/ScaleInputx/ScaleInputx.cpp\ 395 ./modules/AXPYInputx/AXPYInputx.h\ 396 ./modules/AXPYInputx/AXPYInputx.cpp\ 395 397 ./modules/ControlConstrainx/ControlConstrainx.h\ 396 398 ./modules/ControlConstrainx/ControlConstrainx.cpp\ … … 891 893 ./modules/ScaleInputx/ScaleInputx.h\ 892 894 ./modules/ScaleInputx/ScaleInputx.cpp\ 895 ./modules/AXPYInputx/AXPYInputx.h\ 896 ./modules/AXPYInputx/AXPYInputx.cpp\ 893 897 ./modules/ControlConstrainx/ControlConstrainx.h\ 894 898 ./modules/ControlConstrainx/ControlConstrainx.cpp\ -
issm/trunk/src/c/modules/ControlConstrainx/ControlConstrainx.cpp
r3913 r4048 1 /*!\file ControlCon strainx2 * \brief constrain optimization parameters during inverse method1 /*!\file ControlContrainInputx 2 * \brief: Y=Y+aX operation on inputs. 3 3 */ 4 4 5 #include "./ControlConstrainx.h" 6 5 #include "./ControlContrainInputx.h" 7 6 #include "../../shared/shared.h" 8 7 #include "../../include/include.h" … … 10 9 #include "../../EnumDefinitions/EnumDefinitions.h" 11 10 12 void ControlCon strainx( double* p_g, int numdofnodes, double cm_min, double cm_max,int control_type){11 void ControlContrainInputx(DataSet* elements,DataSet* nodes,DataSet* vertices,DataSet* loads,DataSet* materials,Parameters* parameters,int control_type,double cm_min, double cm_max){ 13 12 14 int i; 15 16 if(isnan(cm_min) & isnan(cm_max)){ 17 /*do nothing*/ 13 /*intermediary:*/ 14 int i; 15 16 /*some early returns: */ 17 if(isnan(cm_min) & isnan(cm_max))return; 18 19 /*First, get elements and nodes configured: */ 20 elements->Configure(elements,loads, nodes,vertices, materials,parameters); 21 22 /*Go through elemnets, and ask to carry out the ControlContrain operation on inputs: */ 23 for(i=0;i<elements->Size();i++){ 24 Element* element=(Element*)elements->GetObjectByOffset(i); 25 element->ControlContrainInput(control_type,cm_min,cm_max); 18 26 } 19 else{20 for(i=0;i<numdofnodes;i++){21 if(isnan(p_g[i])){22 ISSMERROR("NaN found in parameter p_g[%i]",i);23 }24 if(!isnan(cm_min)){25 if (p_g[i]<cm_min)p_g[i]=cm_min;26 }27 if(!isnan(cm_max)){28 if (p_g[i]>cm_max)p_g[i]=cm_max;29 }30 }31 }32 33 27 } -
issm/trunk/src/c/modules/ControlConstrainx/ControlConstrainx.h
r3913 r4048 1 /*!\file: ControlCon strainx.h2 * \brief constrain optimization parameters during inverse method1 /*!\file: ControlContrainInputx.h 2 * \brief header file for field extrusion 3 3 */ 4 4 5 #ifndef _CONTROLCON STRAINX_H6 #define _CONTROLCON STRAINX_H5 #ifndef _CONTROLCONTRAININPUTX_H 6 #define _CONTROLCONTRAININPUTX_H 7 7 8 8 #include "../../DataSet/DataSet.h" 9 9 10 10 /* local prototypes: */ 11 void ControlCon strainx( double* p_g, int numberofnodes, double cm_min, double cm_max,int control_type);11 void ControlContrainInputx(DataSet* elements,DataSet* nodes,DataSet* vertices,DataSet* loads,DataSet* materials,Parameters* parameters,int control_type,double cm_min, double cm_max); 12 12 13 #endif /* _C ONTROLCONSTRAINX_H */13 #endif /* _ControlContrainINPUTX_H */ 14 14 -
issm/trunk/src/c/modules/Gradjx/Gradjx.cpp
r4047 r4048 24 24 parameters->FindParam(&dim,DimEnum); 25 25 26 27 26 /*Compute gradients: */ 28 27 for (i=0;i<elements->Size();i++){ -
issm/trunk/src/c/modules/Orthx/Orthx.cpp
r3519 r4048 6 6 7 7 void Orthx( Vec* pnewgradj, Vec gradj, Vec oldgradj){ 8 9 GetSolutionFromInputsx( &ug, femmodel->elements,femmodel->nodes, femmodel->vertices,femmodel->loads, femmodel->materials, femmodel->parameters, analysis_type,sub_analysis_type); 8 10 9 11 /*output: */ -
issm/trunk/src/c/modules/modules.h
r4047 r4048 80 80 #include "./DuplicateInputx/DuplicateInputx.h" 81 81 #include "./ScaleInputx/ScaleInputx.h" 82 #include "./AXPYInputx/AXPYInputx.h" 83 #include "./ControlContrainx/ControlContrainx.h" 82 84 83 85 #endif -
issm/trunk/src/c/objects/Elements/Beam.cpp
r4047 r4048 1002 1002 } 1003 1003 /*}}}*/ 1004 /*FUNCTION Beam::AXPY(int YEnum, double scalar, int XEnum);{{{1*/ 1005 void Beam::AXPY(int YEnum, double scalar, int XEnum){ 1006 1007 Input* xinput=NULL; 1008 Input* yinput=NULL; 1009 1010 /*Find x and y inputs: */ 1011 xinput=(Input*)this->inputs->GetInput(XEnum); 1012 yinput=(Input*)this->inputs->GetInput(YEnum); 1013 1014 /*some checks: */ 1015 if(!xinput || !yinput)ISSMERROR("%s%s%s%s%s"," input ",EnumAsString(XEnum)," or input ",EnumAsString(YEnum)," could not be found!"); 1016 if(xinput->Enum()!=yinput->Enum())ISSMERROR("%s%s%s%s%s"," input ",EnumAsString(XEnum)," and input ",EnumAsString(YEnum)," are not of the same type!"); 1017 1018 /*Scale: */ 1019 yinput->AXPY(xinput,scalar); 1020 } 1021 /*}}}*/ 1022 /*FUNCTION Beam::ControlConstrain(int control_type, double cm_min, double cm_max){{{1*/ 1023 void Beam::ControlConstrain(int control_type, double cm_min, double cm_max){ 1024 1025 Input* input=NULL; 1026 1027 /*Find input: */ 1028 input=(Input*)this->inputs->GetInput(control_type); 1029 1030 /*Do nothing if we don't find it: */ 1031 if(!input)return; 1032 1033 /*Constrain input using cm_min and cm_max: */ 1034 input->Constrain(cm_min,cm_max); 1035 1036 } 1037 /*}}}*/ 1038 /*FUNCTION Beam::GetVectorFromInputs(Vec vector,int NameEnum){{{1*/ 1039 void Beam::GetVectorFromInputs(Vec vector,int NameEnum){ 1040 1041 const int numvertices=2; 1042 int doflist1[numvertices]; 1043 1044 /*Find NameEnum input in the inputs dataset, and get it to fill in the vector: */ 1045 for(i=0;i<this->inputs->Size();i++){ 1046 Input* input=(Input*)this->inputs->GetObjectByOffset(i); 1047 if(input->EnumType==NameEnum){ 1048 /*We found the enum. Use its values to fill into the vector, using the vertices ids: */ 1049 this->GetDofList1(&doflist1[0]); 1050 input->GetVectorFromInputs(vector,&doflist1[0]); 1051 break; 1052 } 1053 } 1054 } 1055 /*}}}*/ -
issm/trunk/src/c/objects/Elements/Beam.h
r4047 r4048 96 96 void DuplicateInput(int original_enum,int new_enum); 97 97 void ScaleInput(int enum_type,double scale_factor); 98 void AXPY(int YEnum, double scalar, int XEnum); 99 void ControlConstrain(int control_type,double cm_min, double cm_max); 98 100 99 101 /*}}}*/ … … 114 116 void GetJacobianDeterminant(double* pJdet,double* z_list, double gauss_coord); 115 117 double MassFlux(double* segment); 118 void GetVectorFromInputs(Vec vector,int NameEnum); 119 116 120 /*}}}*/ 117 121 -
issm/trunk/src/c/objects/Elements/Element.h
r4047 r4048 66 66 virtual void DuplicateInput(int original_enum,int new_enum)=0; 67 67 virtual void ScaleInput(int enum_type,double scale_factor)=0; 68 69 68 virtual void GetVectorFromInputs(Vec vector,int NameEnum)=0; 69 virtual void AXPY(int YEnum, double scalar, int XEnum)=0; 70 virtual void ControlConstrain(int control_type,double cm_min, double cm_max)=0; 70 71 /*Implementation: */ 71 72 -
issm/trunk/src/c/objects/Elements/Penta.cpp
r4047 r4048 5352 5352 } 5353 5353 /*}}}*/ 5354 /*FUNCTION Penta::AXPY(int YEnum, double scalar, int XEnum);{{{1*/ 5355 void Penta::AXPY(int YEnum, double scalar, int XEnum){ 5356 5357 Input* xinput=NULL; 5358 Input* yinput=NULL; 5359 5360 /*Find x and y inputs: */ 5361 xinput=(Input*)this->inputs->GetInput(XEnum); 5362 yinput=(Input*)this->inputs->GetInput(YEnum); 5363 5364 /*some checks: */ 5365 if(!xinput || !yinput)ISSMERROR("%s%s%s%s%s"," input ",EnumAsString(XEnum)," or input ",EnumAsString(YEnum)," could not be found!"); 5366 if(xinput->Enum()!=yinput->Enum())ISSMERROR("%s%s%s%s%s"," input ",EnumAsString(XEnum)," and input ",EnumAsString(YEnum)," are not of the same type!"); 5367 5368 /*Scale: */ 5369 yinput->AXPY(xinput,scalar); 5370 } 5371 /*}}}*/ 5372 /*FUNCTION Penta::ControlConstrain(int control_type, double cm_min, double cm_max){{{1*/ 5373 void Penta::ControlConstrain(int control_type, double cm_min, double cm_max){ 5374 5375 Input* input=NULL; 5376 5377 /*Find input: */ 5378 input=(Input*)this->inputs->GetInput(control_type); 5379 5380 /*Do nothing if we don't find it: */ 5381 if(!input)return; 5382 5383 /*Constrain input using cm_min and cm_max: */ 5384 input->Constrain(cm_min,cm_max); 5385 5386 } 5387 /*}}}*/ 5388 /*FUNCTION Penta::GetVectorFromInputs(Vec vector,int NameEnum){{{1*/ 5389 void Penta::GetVectorFromInputs(Vec vector,int NameEnum){ 5390 5391 const int numvertices=6; 5392 int doflist1[numvertices]; 5393 5394 /*Find NameEnum input in the inputs dataset, and get it to fill in the vector: */ 5395 for(i=0;i<this->inputs->Size();i++){ 5396 Input* input=(Input*)this->inputs->GetObjectByOffset(i); 5397 if(input->EnumType==NameEnum){ 5398 /*We found the enum. Use its values to fill into the vector, using the vertices ids: */ 5399 this->GetDofList1(&doflist1[0]); 5400 input->GetVectorFromInputs(vector,&doflist1[0]); 5401 break; 5402 } 5403 } 5404 } 5405 /*}}}*/ -
issm/trunk/src/c/objects/Elements/Penta.h
r4047 r4048 163 163 void DuplicateInput(int original_enum,int new_enum); 164 164 void ScaleInput(int enum_type,double scale_factor); 165 void AXPY(int YEnum, double scalar, int XEnum); 166 void ControlConstrain(int control_type,double cm_min, double cm_max); 167 void GetVectorFromInputs(Vec vector,int NameEnum); 165 168 166 169 -
issm/trunk/src/c/objects/Elements/Sing.cpp
r4047 r4048 708 708 } 709 709 /*}}}*/ 710 /*FUNCTION Sing::AXPY(int YEnum, double scalar, int XEnum);{{{1*/ 711 void Sing::AXPY(int YEnum, double scalar, int XEnum){ 712 713 Input* xinput=NULL; 714 Input* yinput=NULL; 715 716 /*Find x and y inputs: */ 717 xinput=(Input*)this->inputs->GetInput(XEnum); 718 yinput=(Input*)this->inputs->GetInput(YEnum); 719 720 /*some checks: */ 721 if(!xinput || !yinput)ISSMERROR("%s%s%s%s%s"," input ",EnumAsString(XEnum)," or input ",EnumAsString(YEnum)," could not be found!"); 722 if(xinput->Enum()!=yinput->Enum())ISSMERROR("%s%s%s%s%s"," input ",EnumAsString(XEnum)," and input ",EnumAsString(YEnum)," are not of the same type!"); 723 724 /*Scale: */ 725 yinput->AXPY(xinput,scalar); 726 } 727 /*}}}*/ 728 /*FUNCTION Sing::ControlConstrain(int control_type, double cm_min, double cm_max){{{1*/ 729 void Sing::ControlConstrain(int control_type, double cm_min, double cm_max){ 730 731 Input* input=NULL; 732 733 /*Find input: */ 734 input=(Input*)this->inputs->GetInput(control_type); 735 736 /*Do nothing if we don't find it: */ 737 if(!input)return; 738 739 /*Constrain input using cm_min and cm_max: */ 740 input->Constrain(cm_min,cm_max); 741 742 } 743 /*}}}*/ 744 /*FUNCTION Sing::GetVectorFromInputs(Vec vector,int NameEnum){{{1*/ 745 void Sing::GetVectorFromInputs(Vec vector,int NameEnum){ 746 747 const int numvertices=1; 748 int doflist1[numvertices]; 749 750 /*Find NameEnum input in the inputs dataset, and get it to fill in the vector: */ 751 for(i=0;i<this->inputs->Size();i++){ 752 Input* input=(Input*)this->inputs->GetObjectByOffset(i); 753 if(input->EnumType==NameEnum){ 754 /*We found the enum. Use its values to fill into the vector, using the vertices ids: */ 755 this->GetDofList1(&doflist1[0]); 756 input->GetVectorFromInputs(vector,&doflist1[0]); 757 break; 758 } 759 } 760 } 761 /*}}}*/ -
issm/trunk/src/c/objects/Elements/Sing.h
r4047 r4048 95 95 void DuplicateInput(int original_enum,int new_enum); 96 96 void ScaleInput(int enum_type,double scale_factor); 97 void AXPY(int YEnum, double scalar, int XEnum); 98 void ControlConstrain(int control_type,double cm_min, double cm_max); 97 99 98 100 … … 111 113 double CostFunction(void); 112 114 double MassFlux(double* segment); 115 void GetVectorFromInputs(Vec vector,int NameEnum); 113 116 /*}}}*/ 114 117 -
issm/trunk/src/c/objects/Elements/Tria.cpp
r4047 r4048 5450 5450 } 5451 5451 /*}}}*/ 5452 /*FUNCTION Tria::AXPY(int YEnum, double scalar, int XEnum);{{{1*/ 5453 void Tria::AXPY(int YEnum, double scalar, int XEnum){ 5454 5455 Input* xinput=NULL; 5456 Input* yinput=NULL; 5457 5458 /*Find x and y inputs: */ 5459 xinput=(Input*)this->inputs->GetInput(XEnum); 5460 yinput=(Input*)this->inputs->GetInput(YEnum); 5461 5462 /*some checks: */ 5463 if(!xinput || !yinput)ISSMERROR("%s%s%s%s%s"," input ",EnumAsString(XEnum)," or input ",EnumAsString(YEnum)," could not be found!"); 5464 if(xinput->Enum()!=yinput->Enum())ISSMERROR("%s%s%s%s%s"," input ",EnumAsString(XEnum)," and input ",EnumAsString(YEnum)," are not of the same type!"); 5465 5466 /*Scale: */ 5467 yinput->AXPY(xinput,scalar); 5468 } 5469 /*}}}*/ 5470 /*FUNCTION Tria::ControlConstrain(int control_type, double cm_min, double cm_max){{{1*/ 5471 void Tria::ControlConstrain(int control_type, double cm_min, double cm_max){ 5472 5473 Input* input=NULL; 5474 5475 /*Find input: */ 5476 input=(Input*)this->inputs->GetInput(control_type); 5477 5478 /*Do nothing if we don't find it: */ 5479 if(!input)return; 5480 5481 /*Constrain input using cm_min and cm_max: */ 5482 input->Constrain(cm_min,cm_max); 5483 5484 } 5485 /*}}}*/ 5486 /*FUNCTION Tria::GetVectorFromInputs(Vec vector,int NameEnum){{{1*/ 5487 void Tria::GetVectorFromInputs(Vec vector,int NameEnum){ 5488 5489 const int numvertices=3; 5490 int doflist1[numvertices]; 5491 5492 /*Find NameEnum input in the inputs dataset, and get it to fill in the vector: */ 5493 for(i=0;i<this->inputs->Size();i++){ 5494 Input* input=(Input*)this->inputs->GetObjectByOffset(i); 5495 if(input->EnumType==NameEnum){ 5496 /*We found the enum. Use its values to fill into the vector, using the vertices ids: */ 5497 this->GetDofList1(&doflist1[0]); 5498 input->GetVectorFromInputs(vector,&doflist1[0]); 5499 break; 5500 } 5501 } 5502 } 5503 /*}}}*/ -
issm/trunk/src/c/objects/Elements/Tria.h
r4047 r4048 141 141 void DuplicateInput(int original_enum,int new_enum); 142 142 void ScaleInput(int enum_type,double scale_factor); 143 void AXPY(int YEnum, double scalar, int XEnum); 144 void ControlConstrain(int control_type,double cm_min, double cm_max); 145 void GetVectorFromInputs(Vec vector,int NameEnum); 143 146 144 147 -
issm/trunk/src/c/objects/Inputs/BeamVertexInput.cpp
r4047 r4048 259 259 } 260 260 /*}}}*/ 261 /*FUNCTION BeamVertexInput::AXPY(Input* xinput,double scalar);{{{1*/ 262 void BeamVertexInput::AXPY(Input* xinput,double scalar){ 263 264 int i; 265 const int numgrids=2; 266 BeamVertexInput* xbeamvertexinput=NULL; 267 268 /*xinput is of the same type, so cast it: */ 269 xbeamvertexinput=(BeamVertexInput)xinput; 270 271 /*Carry out the AXPY operation:*/ 272 for(i=0;i<numgrids;i++)this->values[i]=this->values[i]+scalar*xbeamvertexinput->values[i]; 273 274 } 275 /*}}}*/ 276 /*FUNCTION BeamVertexInput::Constrain(double cm_min, double cm_max){{{1*/ 277 void BeamVertexInput::Constrain(double cm_min, double cm_max){ 278 279 int i; 280 const int numgrids=2; 281 282 if(!isnan(cm_min)) for(i=0;i<numgrids;i++)if (this->values[i]<cm_min)this->values[i]=cm_min; 283 if(!isnan(cm_max)) for(i=0;i<numgrids;i++)if (this->values[i]>cm_max)this->values[i]=cm_max; 284 285 } 286 /*}}}*/ 287 /*FUNCTION BeamVertexInput::GetVectorFromInputs(Vec vector,int* doflist){{{1*/ 288 void BeamVertexInput::GetVectorFromInputs(Vec vector,int* doflist){ 289 290 const int numvertices=2; 291 VecSetValues(vector,numvertices,doflist,(const double*)this->values,ADD_VALUES); 292 293 294 } 295 /*}}}*/ -
issm/trunk/src/c/objects/Inputs/BeamVertexInput.h
r4047 r4048 75 75 void SquareMin(double* psquaremin, bool process_units,Parameters* parameters); 76 76 void Scale(double scale_factor); 77 void AXPY(Input* xinput,double scalar); 78 void Constrain(double cm_min, double cm_max); 79 void GetVectorFromInputs(Vec vector,int* doflist); 77 80 /*}}}*/ 78 81 -
issm/trunk/src/c/objects/Inputs/BoolInput.cpp
r4047 r4048 228 228 } 229 229 /*}}}*/ 230 /*FUNCTION BoolInput::AXPY(Input* xinput,double scalar);{{{1*/ 231 void BoolInput::AXPY(Input* xinput,double scalar){ 232 233 BoolInput* xboolinput=NULL; 234 235 /*xinput is of the same type, so cast it: */ 236 xboolinput=(BoolInput)xinput; 237 238 /*Carry out the AXPY operation:*/ 239 this->value=this->value+scalar*xboolinput->value; 240 241 } 242 /*}}}*/ 243 /*FUNCTION BoolInput::Constrain(double cm_min, double cm_max){{{1*/ 244 void BoolInput::Constrain(double cm_min, double cm_max){ 245 246 if(!isnan(cm_min)) if (this->value<cm_min)this->value=cm_min; 247 if(!isnan(cm_max)) if (this->value>cm_max)this->value=cm_max; 248 249 } 250 /*}}}*/ 251 /*FUNCTION BoolInput::GetVectorFromInputs(Vec vector,int* doflist){{{1*/ 252 void BoolInput::GetVectorFromInputs(Vec vector,int* doflist){ 253 254 ISSMERROR(" not supporte yet!"); 255 256 } 257 /*}}}*/ -
issm/trunk/src/c/objects/Inputs/BoolInput.h
r4047 r4048 75 75 void SquareMin(double* psquaremin, bool process_units,Parameters* parameters); 76 76 void Scale(double scale_factor); 77 void AXPY(Input* xinput,double scalar); 78 void Constrain(double cm_min, double cm_max); 79 void GetVectorFromInputs(Vec vector,int* doflist); 77 80 /*}}}*/ 78 81 -
issm/trunk/src/c/objects/Inputs/DoubleInput.cpp
r4047 r4048 239 239 } 240 240 /*}}}*/ 241 /*FUNCTION DoubleInput::AXPY(Input* xinput,double scalar);{{{1*/ 242 void DoubleInput::AXPY(Input* xinput,double scalar){ 243 244 DoubleInput* xdoubleinput=NULL; 245 246 /*xinput is of the same type, so cast it: */ 247 xdoubleinput=(DoubleInput)xinput; 248 249 /*Carry out the AXPY operation:*/ 250 this->value=this->value+scalar*xdoubleinput->value; 251 252 } 253 /*}}}*/ 254 /*FUNCTION DoubleInput::Constrain(double cm_min, double cm_max){{{1*/ 255 void DoubleInput::Constrain(double cm_min, double cm_max){ 256 257 if(!isnan(cm_min)) if (this->value<cm_min)this->value=cm_min; 258 if(!isnan(cm_max)) if (this->value>cm_max)this->value=cm_max; 259 260 } 261 /*}}}*/ 262 /*FUNCTION DoubleInput::GetVectorFromInputs(Vec vector,int* doflist){{{1*/ 263 void DoubleInput::GetVectorFromInputs(Vec vector,int* doflist){ 264 265 ISSMERROR(" not supporte yet!"); 266 267 } 268 /*}}}*/ -
issm/trunk/src/c/objects/Inputs/DoubleInput.h
r4047 r4048 76 76 void SquareMin(double* psquaremin, bool process_units,Parameters* parameters); 77 77 void Scale(double scale_factor); 78 void AXPY(Input* xinput,double scalar); 79 void Constrain(double cm_min, double cm_max); 80 void GetVectorFromInputs(Vec vector,int* doflist); 78 81 /*}}}*/ 79 82 -
issm/trunk/src/c/objects/Inputs/Input.h
r4047 r4048 50 50 virtual Input* SpawnTriaInput(int* indices)=0; 51 51 virtual Result* SpawnResult(int step, double time)=0; 52 virtual void SquareMin(double* psquaremin, bool process_units,Parameters* parameters)=0; 53 virtual void Scale(double scale_factor)=0; 52 virtual void SquareMin(double* psquaremin, bool process_units,Parameters* parameters)=0; 53 virtual void Scale(double scale_factor)=0; 54 virtual void AXPY(Input* xinput,double scalar)=0; 55 virtual void Constrain(double cm_min, double cm_max)=0; 56 virtual void GetVectorFromInputs(Vec vector,int* doflist)=0; 54 57 /*}}}*/ 55 58 -
issm/trunk/src/c/objects/Inputs/IntInput.cpp
r4047 r4048 226 226 } 227 227 /*}}}*/ 228 /*FUNCTION IntInput::AXPY(Input* xinput,int scalar);{{{1*/ 229 void IntInput::AXPY(Input* xinput,int scalar){ 230 231 IntInput* xintinput=NULL; 232 233 /*xinput is of the same type, so cast it: */ 234 xintinput=(IntInput)xinput; 235 236 /*Carry out the AXPY operation:*/ 237 this->value=this->value+scalar*xintinput->value; 238 239 } 240 /*}}}*/ 241 /*FUNCTION IntInput::Constrain(double cm_min, double cm_max){{{1*/ 242 void IntInput::Constrain(double cm_min, double cm_max){ 243 244 if(!isnan(cm_min)) if (this->value<cm_min)this->value=cm_min; 245 if(!isnan(cm_max)) if (this->value>cm_max)this->value=cm_max; 246 247 } 248 /*}}}*/ 249 /*FUNCTION IntInput::GetVectorFromInputs(Vec vector,int* doflist){{{1*/ 250 void IntInput::GetVectorFromInputs(Vec vector,int* doflist){ 251 252 ISSMERROR(" not supporte yet!"); 253 254 } 255 /*}}}*/ -
issm/trunk/src/c/objects/Inputs/IntInput.h
r4047 r4048 75 75 void SquareMin(double* psquaremin, bool process_units,Parameters* parameters); 76 76 void Scale(double scale_factor); 77 void AXPY(Input* xinput,double scalar); 78 void Constrain(double cm_min, double cm_max); 79 void GetVectorFromInputs(Vec vector,int* doflist); 77 80 /*}}}*/ 78 81 -
issm/trunk/src/c/objects/Inputs/PentaVertexInput.cpp
r4047 r4048 908 908 } 909 909 /*}}}*/ 910 /*FUNCTION PentaVertexInput::AXPY(Input* xinput,double scalar);{{{1*/ 911 void PentaVertexInput::AXPY(Input* xinput,double scalar){ 912 913 int i; 914 const int numgrids=6; 915 PentaVertexInput* xpentavertexinput=NULL; 916 917 /*xinput is of the same type, so cast it: */ 918 xpentavertexinput=(PentaVertexInput)xinput; 919 920 /*Carry out the AXPY operation:*/ 921 for(i=0;i<numgrids;i++)this->values[i]=this->values[i]+scalar*xpentavertexinput->values[i]; 922 923 } 924 /*}}}*/ 925 /*FUNCTION PentaVertexInput::Constrain(double cm_min, double cm_max){{{1*/ 926 void PentaVertexInput::Constrain(double cm_min, double cm_max){ 927 928 int i; 929 const int numgrids=6; 930 931 if(!isnan(cm_min)) for(i=0;i<numgrids;i++)if (this->values[i]<cm_min)this->values[i]=cm_min; 932 if(!isnan(cm_max)) for(i=0;i<numgrids;i++)if (this->values[i]>cm_max)this->values[i]=cm_max; 933 934 } 935 /*}}}*/ 936 /*FUNCTION PentaVertexInput::GetVectorFromInputs(Vec vector,int* doflist){{{1*/ 937 void PentaVertexInput::GetVectorFromInputs(Vec vector,int* doflist){ 938 939 const int numvertices=6; 940 VecSetValues(vector,numvertices,doflist,(const double*)this->values,ADD_VALUES); 941 942 943 } 944 /*}}}*/ -
issm/trunk/src/c/objects/Inputs/PentaVertexInput.h
r4047 r4048 84 84 void SquareMin(double* psquaremin, bool process_units,Parameters* parameters); 85 85 void Scale(double scale_factor); 86 void AXPY(Input* xinput,double scalar); 87 void Constrain(double cm_min, double cm_max); 88 void GetVectorFromInputs(Vec vector,int* doflist); 86 89 /*}}}*/ 87 90 -
issm/trunk/src/c/objects/Inputs/SingVertexInput.cpp
r4047 r4048 229 229 } 230 230 /*}}}*/ 231 /*FUNCTION SingVertexInput::AXPY(Input* xinput,double scalar);{{{1*/ 232 void SingVertexInput::AXPY(Input* xinput,double scalar){ 233 234 SingVertexInput* xsingvertexinput=NULL; 235 236 /*xinput is of the same type, so cast it: */ 237 xsingvertexinput=(SingVertexInput)xinput; 238 239 /*Carry out the AXPY operation:*/ 240 this->value=this->value+scalar*xngvertexinput->value; 241 242 } 243 /*}}}*/ 244 /*FUNCTION SingVertexInput::Constrain(double cm_min, double cm_max){{{1*/ 245 void SingVertexInput::Constrain(double cm_min, double cm_max){ 246 247 if(!isnan(cm_min)) if (this->value<cm_min)this->value=cm_min; 248 if(!isnan(cm_max)) if (this->value>cm_max)this->value=cm_max; 249 250 } 251 /*}}}*/ 252 /*FUNCTION SingVertexInput::GetVectorFromInputs(Vec vector,int* doflist){{{1*/ 253 void SingVertexInput::GetVectorFromInputs(Vec vector,int* doflist){ 254 255 const int numvertices=1; 256 VecSetValues(vector,numvertices,doflist,(const double*)&this->value,ADD_VALUES); 257 258 259 } 260 /*}}}*/ -
issm/trunk/src/c/objects/Inputs/SingVertexInput.h
r4047 r4048 74 74 void SquareMin(double* psquaremin, bool process_units,Parameters* parameters); 75 75 void Scale(double scale_factor); 76 void AXPY(Input* xinput,double scalar); 77 void Constrain(double cm_min, double cm_max); 78 void GetVectorFromInputs(Vec vector,int* doflist); 76 79 /*}}}*/ 77 80 -
issm/trunk/src/c/objects/Inputs/TriaVertexInput.cpp
r4047 r4048 482 482 } 483 483 /*}}}*/ 484 /*FUNCTION TriaVertexInput::AXPY(Input* xinput,double scalar);{{{1*/ 485 void TriaVertexInput::AXPY(Input* xinput,double scalar){ 486 487 int i; 488 const int numgrids=3; 489 TriaVertexInput* xtriavertexinput=NULL; 490 491 /*xinput is of the same type, so cast it: */ 492 xtriavertexinput=(TriaVertexInput)xinput; 493 494 /*Carry out the AXPY operation:*/ 495 for(i=0;i<numgrids;i++)this->values[i]=this->values[i]+scalar*xtriavertexinput->values[i]; 496 497 } 498 /*}}}*/ 499 /*FUNCTION TriaVertexInput::Constrain(double cm_min, double cm_max){{{1*/ 500 void TriaVertexInput::Constrain(double cm_min, double cm_max){ 501 502 int i; 503 const int numgrids=3; 504 505 if(!isnan(cm_min)) for(i=0;i<numgrids;i++)if (this->values[i]<cm_min)this->values[i]=cm_min; 506 if(!isnan(cm_max)) for(i=0;i<numgrids;i++)if (this->values[i]>cm_max)this->values[i]=cm_max; 507 508 } 509 /*}}}*/ 510 /*FUNCTION TriaVertexInput::GetVectorFromInputs(Vec vector,int* doflist){{{1*/ 511 void TriaVertexInput::GetVectorFromInputs(Vec vector,int* doflist){ 512 513 const int numvertices=3; 514 VecSetValues(vector,numvertices,doflist,(const double*)this->values,ADD_VALUES); 515 516 517 } 518 /*}}}*/ -
issm/trunk/src/c/objects/Inputs/TriaVertexInput.h
r4047 r4048 81 81 void SquareMin(double* psquaremin, bool process_units,Parameters* parameters); 82 82 void Scale(double scale_factor); 83 void AXPY(Input* xinput,double scalar); 84 void Constrain(double cm_min, double cm_max); 85 void GetVectorFromInputs(Vec vector,int* doflist); 83 86 /*}}}*/ 84 87 -
issm/trunk/src/c/objects/OptArgs.h
r3681 r4048 25 25 class Model; 26 26 struct OptArgs{ 27 Model* model; 28 double* param_g; 29 double* grad_g; 27 FemModel* femmodel; 30 28 int n; 31 29 }; -
issm/trunk/src/c/solutions/ControlRestart.cpp
r3938 r4048 1 2 1 /*!\file: ControlRestart.cpp 3 * \brief: core of the control solution2 * \brief: save as much as possible, to be able to restart the control_core solution 4 3 */ 5 4 … … 8 7 #include "../EnumDefinitions/EnumDefinitions.h" 9 8 10 void ControlRestart( Model* model,double* param_g){9 void ControlRestart(FemModel* femmodel){ 11 10 12 extern int my_rank;13 14 /*output: */15 Results* results=NULL;16 11 char* outputfilename=NULL; 17 18 /*Intermediary: */ 19 int i; 20 int numberofnodes; 21 double* param_g_copy; 22 23 /*Recover parameters used throughout the solution:*/ 24 model->FindParam(&numberofnodes,NumberOfNodesEnum); 12 13 /*retrieve output file name: */ 25 14 model->FindParam(&outputfilename,OutputFileNameEnum); 26 15 27 /* Plug COPYS of the results into output dataset:28 * only the pointer is given to temporary_results and at the29 * end of ProcessResultsx the pointer is deleted. That would30 * destroy param_g*/16 /*we essentially want J and the parameter: */ 17 InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,control_type); //the parameter itself! 18 femmodel->otherresults->AddObject(new DoubleResult(femmodel->otherresults->Size()+1,0,1,"J",J,nsteps)); 19 femmodel->otherresults->AddObject(new StringResult(results->Size()+1,ControlTypeEnum,0,1,EnumAsString(control_type))); 31 20 32 param_g_copy=(double*)xcalloc(numberofnodes,sizeof(double)); 33 for(i=0;i<numberofnodes;i++) param_g_copy[i]=param_g[i]; 34 35 results=new Results(); 36 results->AddObject(new Result(results->Size()+1,0,1,"param_g",param_g_copy,numberofnodes)); 37 results->AddObject(new StringResult(results->Size()+1,AnalysisTypeEnum,0,1,EnumAsString(DiagnosticAnalysisEnum))); 38 39 //Write results on disk 40 OutputResults(results,outputfilename); 21 /*write to disk: */ 22 OutputResults(femmodel->elements, femmodel->loads, femmodel->nodes, femmodel->vertices, femmodel->materials, femmodel->parameters, outputfilename); 41 23 42 24 /*Free ressources:*/ 43 delete results;44 25 xfree((void**)&outputfilename); 45 xfree((void**)¶m_g_copy);46 26 } -
issm/trunk/src/c/solutions/control_core.cpp
r4047 r4048 14 14 void control_core(FemModel* femmodel){ 15 15 16 Vec u_g=NULL;17 Vec t_g=NULL;18 Vec m_g=NULL;19 double search_scalar;16 int i,n; 17 18 /*parameters: */ 19 int verbose=0; 20 20 int control_type; 21 int control_steady; 22 int nsteps; 23 double eps_cm; 24 double tolx; 25 double cm_min; 26 double cm_max; 27 int cm_gradient; 28 21 29 double* fit=NULL; 22 30 double* optscal=NULL; 23 31 double* maxiter=NULL; 24 32 double* cm_jump=NULL; 25 double eps_cm; 26 double tolx; 27 double* param_g=NULL; 28 Vec grad_g=NULL; 29 Vec new_grad_g=NULL; 30 Vec grad_g_old=NULL; 31 double* grad_g_double=NULL; 32 double cm_min; 33 double cm_max; 34 int cm_gradient; 35 int nsteps,n,i; 36 double* J=NULL; 33 34 35 /*intermediary: */ 36 double search_scalar; 37 37 OptArgs optargs; 38 38 OptPars optpars; 39 Param* param=NULL;40 39 41 /*flags: */ 42 int analysis_type; 43 int sub_analysis_type; 44 int control_steady; 45 int verbose=0; 46 int converged=0; 47 int numberofnodes; 40 /*output: */ 41 double* J=NULL; 48 42 49 43 /*Process models*/ … … 62 56 femmodel->parameters->FindParam(&cm_max,CmMaxEnum); 63 57 femmodel->parameters->FindParam(&cm_gradient,CmGradientEnum); 64 femmodel->parameters->FindParam(¶m_g,NULL,NULL,ControlParameterEnum);65 femmodel->parameters->FindParam(&analysis_type,AnalysisTypeEnum);66 femmodel->parameters->FindParam(&sub_analysis_type,SubAnalysisTypeEnum);67 femmodel->parameters->FindParam(&numberofnodes,NumberOfNodesEnum);68 58 femmodel->parameters->FindParam(&control_steady,ControlSteadyEnum); 69 59 70 60 /*Initialize misfit: */ 71 61 J=(double*)xmalloc(nsteps*sizeof(double)); 72 62 63 /*Initialize some of the BrentSearch arguments: */ 64 optargs.femmodel=femmodel; 65 optpars.xmin=0; optpars.xmax=1; optpars.tolerance=tolx ; 66 73 67 /*Start looping: */ 74 68 for(n=0;n<nsteps;n++){ 75 69 76 70 _printf_("\n%s%i%s%i\n"," control method step ",n+1,"/",nsteps); 77 inputs->Add(control_type,param_g,1,numberofnodes);78 71 femmodel->UpdateInputsFromConstant(fit[n],FitEnum); 79 72 80 /*In case we are running a steady state control method, compute new temperature field using new parameter 81 * distribution: */ 73 /*In case we are running a steady state control method, compute new temperature field using new parameter * distribution: */ 82 74 if (control_steady) steadystate_core(model); 83 75 … … 87 79 /*Return gradient if asked: */ 88 80 if (cm_gradient){ 89 /*Transfer gradient from input to results: */90 81 InputToResultx(femodel->elements,femodel->nodes,femodel->vertices,femodel->loads,femodel->materials,femodel->parameters,GradientEnum); 91 return;82 goto cleanup_and_return; 92 83 } 93 84 94 /*Normalize if last gradient not satisfying (search_scalar==0)*/95 if (n>0 && search_scalar==0){96 _printf_("%s"," orthogonalization...");97 Orthx(&new_grad_g,grad_g,grad_g_old);98 _printf_("%s\n"," done.");99 }100 else{101 _printf_("%s"," normalizing directions...");102 Orthx(&new_grad_g,grad_g,NULL);103 _printf_("%s\n"," done.");104 }105 VecFree(&grad_g); VecFree(&grad_g_old);106 grad_g_old=new_grad_g;107 VecToMPISerial(&grad_g_double,new_grad_g);108 109 85 _printf_("%s\n"," optimizing along gradient direction"); 110 optargs.model=model; 111 optargs.param_g=param_g; optargs.grad_g=grad_g_double; optargs.n=n; 112 optpars.xmin=0; optpars.xmax=1; optpars.tolerance=tolx; optpars.maxiter=(int)maxiter[n];optpars.cm_jump=cm_jump[n]; 86 optargs.n=n; optpars.maxiter=(int)maxiter[n]; optpars.cm_jump=cm_jump[n]; 113 87 BrentSearch(&search_scalar,J+n,&optpars,&objectivefunctionC,&optargs); 114 88 115 89 _printf_("%s"," updating parameter using optimized search scalar..."); 116 for(i=0;i<numberofnodes;i++)param_g[i]=param_g[i]+search_scalar*optscal[n]*grad_g_double[i]; 117 _printf_("%s\n"," done."); 90 AXPYInputx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,control_type,search_scalar*optscal[n],ControlParameterEnum); 118 91 119 92 _printf_("%s"," constraining the new distribution..."); 120 ControlConstrainx(param_g,numberofnodes,cm_min,cm_max,control_type); 121 _printf_("%s\n"," done."); 93 ControlConstrainx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,control_type,cm_min,cm_max); 94 95 _printf_("%s"," save new parameter..."); 96 DuplicateInputx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,control_type,ControlParameterEnum); 122 97 123 98 _printf_("%s%i%s%g\n"," value of misfit J after optimization #",n+1,": ",J[n]); 99 100 if(controlconvergence)goto cleanup_and_return; 124 101 125 /*some freeing:*/ 126 xfree((void**)&grad_g_double); 127 128 /*Has convergence been reached?*/ 129 if (!isnan(eps_cm)){ 130 i=n-2; 131 //go through the previous misfits(starting from n-2) 132 while(i>=0){ 133 if (fit[i]==fit[n]){ 134 //convergence test only if we have the same misfits 135 if ((J[i]-J[n])/J[n] <= eps_cm){ 136 //convergence if convergence criteria fullfilled 137 converged=1; 138 _printf_("%s%g%s%g\n"," Convergence criterion: dJ/J = ",(J[i]-J[n])/J[n],"<",eps_cm); 139 } 140 else{ 141 _printf_("%s%g%s%g\n"," Convergence criterion: dJ/J = ",(J[i]-J[n])/J[n],">",eps_cm); 142 } 143 break; 144 } 145 i=i-1; 146 } 147 } 148 //stop if convergence has been reached 149 if(converged) break; 150 151 //some temporary saving 102 /*Temporary saving every 5 control steps: */ 152 103 if (((n+1)%5)==0){ 153 104 _printf_("%s"," saving temporary results..."); 154 ControlRestart(model,param_g); 155 _printf_("%s\n"," done."); 105 ControlRestart(femmodel); 156 106 } 157 107 } 158 108 159 /*Write results to disk: */160 109 _printf_("%s"," preparing final velocity solution"); 161 /*Launch diagnostic with the last parameter distribution*/ 162 if (control_steady){ 163 model->UpdateInputsFromVector(param_g,control_type,VertexEnum); 164 steadystate_results=steadystate_core(model); 110 if (control_steady) steadystate_core(femmodel); 111 else diagnostic_core(femmodel); 165 112 166 //extract u_g ,t_g and m_g from steadystate results, and erase diagnostic_results; 167 steadystate_results->FindResult(&u_g,"u_g"); 168 steadystate_results->FindResult(&m_g,"m_g"); 169 steadystate_results->FindResult(&t_g,"t_g"); 170 delete steadystate_results; 171 } 172 else{ 173 model->UpdateInputsFromVector(param_g,control_type,VertexEnum); 174 diagnostic_results=diagnostic_core(model); 113 /*some results not computed by steadystate_core or diagnostic_core: */ 114 InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,control_type); //the parameter itself! 115 femmodel->otherresults->AddObject(new DoubleResult(femmodel->otherresults->Size()+1,0,1,"J",J,nsteps)); 116 femmodel->otherresults->AddObject(new StringResult(results->Size()+1,ControlTypeEnum,0,1,EnumAsString(control_type))); 175 117 176 //extract u_g from diagnostic_results, and erase diagnostic_results; 177 diagnostic_results->FindResult(&u_g,"u_g"); 178 delete diagnostic_results; 179 } 180 181 /*Plug results into output dataset: */ 182 results->AddObject(new Result(results->Size()+1,0,1,"u_g",u_g)); 183 results->AddObject(new Result(results->Size()+1,0,1,"param_g",param_g,numberofnodes)); 184 results->AddObject(new Result(results->Size()+1,0,1,"J",J,nsteps)); 185 if (control_steady){ 186 results->AddObject(new Result(results->Size()+1,0,1,"t_g",t_g)); 187 results->AddObject(new Result(results->Size()+1,0,1,"m_g",m_g)); 188 } 118 cleanup_and_return: 189 119 190 /*Add analysis_type and control_type to results: */191 results->AddObject(new StringResult(results->Size()+1,AnalysisTypeEnum,0,1,EnumAsString(analysis_type)));192 results->AddObject(new StringResult(results->Size()+1,ControlTypeEnum,0,1,EnumAsString(control_type)));193 194 120 /*Free ressources: */ 195 121 xfree((void**)&control_type); … … 198 124 xfree((void**)&maxiter); 199 125 xfree((void**)&cm_jump); 200 VecFree(&new_grad_g); //do not VecFree grad_g and grad_g_old, they point to new_grad_g201 xfree((void**)&grad_g_double);202 xfree((void**)¶m_g);203 VecFree(&u_g);204 VecFree(&t_g);205 VecFree(&m_g);206 126 xfree((void**)&J); 207 208 //return:209 return results;210 127 } -
issm/trunk/src/c/solutions/gradient_core.cpp
r4047 r4048 13 13 14 14 15 void gradient_core(FemModel* femmodel){ 16 15 void gradient_core(FemModel* femmodel,int step, double search_scalar){ //step defaults to 0, search_scalar defaults to 0 17 16 18 17 /*parameters: */ … … 20 19 int control_type; 21 20 int verbose; 21 Vec new_gradient=NULL; 22 Vec gradient=NULL; 23 Vec old_gradient=NULL; 22 24 23 25 /*retrieve parameters:*/ … … 30 32 31 33 if(verbose)_printf_("%s\n"," compute gradient:"); 32 Gradjx( femmodel->elements,femmodel->nodes, femmodel->vertices,femmodel->loads, femmodel->materials,femmodel->parameters, control_type); 34 Gradjx(&gradient, femmodel->elements,femmodel->nodes, femmodel->vertices,femmodel->loads, femmodel->materials,femmodel->parameters, control_type,AdjointEnum); 35 36 if(verbose)_printf_("%s\n"," retrieve old gradient:"); 37 GetVectorFromInputsx(&old_gradient, femmodel->elements,femmodel->nodes, femmodel->vertices,femmodel->loads, femmodel->materials,femmodel->parameters, OldGradientEnum,VertexEnum); 33 38 34 39 if(control_steady)diagnostic_core(model); 40 41 if (step>0 && search_scalar==0){ 42 _printf_("%s"," orthogonalization..."); 43 Orthx(&new_gradient,gradient,old_gradient); 44 } 45 else{ 46 _printf_("%s"," normalizing directions..."); 47 Orthx(&new_gradient,gradient,NULL); 48 } 49 _printf_("%s\n"," done."); 35 50 51 52 /*point gradient and old_gradient to new_gradient: */ 53 VecFree(&gradient); gradient=new_gradient; 54 VecFree(&old_gradient); old_gradient=new_gradient; 55 56 /*plug back into inputs: */ 57 UpdateInputsFromVectorx( femmodel-> elements,femmodel-> nodes, femmodel-> vertices,femmodel-> loads, femmodel-> materials, femmoel->parameters,gradient,GradientEnum,VertexEnum); 58 UpdateInputsFromVectorx( femmodel-> elements,femmodel-> nodes, femmodel-> vertices,femmodel-> loads, femmodel-> materials, femmoel->parameters,old_gradient,OldGradientEnum,VertexEnum); 59 60 /*Free ressources and return:*/ 61 VecFree(&new_gradient); 36 62 } -
issm/trunk/src/c/solutions/objectivefunctionC.cpp
r3938 r4048 21 21 22 22 /*parameters: */ 23 Model* model=NULL;24 23 FemModel* femmodel=NULL; 25 Results* diagnostic_results=NULL;26 double* param_g=NULL;27 double* grad_g=NULL;28 int numberofdofspernode;29 24 int n; 30 31 /*intermediary:*/32 int gsize;33 25 double* optscal=NULL; 34 26 double* fit=NULL; 35 27 double cm_min; 36 28 double cm_max; 37 int control_type; 38 double* param_g_copy=NULL; 29 int control_type; 39 30 int analysis_type; 40 31 int sub_analysis_type; 41 32 int control_steady; 42 Vec u_g=NULL;43 Vec u_g_full=NULL;44 double* u_g_double=NULL;45 double* vx=NULL;46 double* vy=NULL;47 double* vz=NULL;48 int numberofnodes;49 33 50 /*steadystate: */ 51 int dt=0; 52 int isstokes=0; 53 Results* results_steadystate=NULL; 54 int dofs01[2]={0,1}; 55 double* dofset=NULL; 56 57 /*Recover active model: */ 58 model=optargs->model; 59 femmodel=model->GetActiveFormulation(); 34 /*Recover finite element model: */ 35 femmodel=optargs->femmodel; 60 36 61 37 /*Recover parameters: */ 62 param_g=optargs->param_g;63 grad_g=optargs->grad_g;64 38 n=optargs->n; 65 39 66 gsize=femmodel->nodesets->GetGSize();67 40 femmodel->parameters->FindParam(&optscal,NULL,NULL,OptScalEnum); 68 41 femmodel->parameters->FindParam(&fit,NULL,NULL,FitEnum); … … 73 46 femmodel->parameters->FindParam(&analysis_type,AnalysisTypeEnum); 74 47 femmodel->parameters->FindParam(&sub_analysis_type,SubAnalysisTypeEnum); 75 femmodel->parameters->FindParam(&isstokes,IsStokesEnum);76 femmodel->parameters->FindParam(&numberofnodes,NumberOfNodesEnum);77 femmodel->parameters->FindParam(&numberofdofspernode,NumberOfDofsPerNodeEnum);78 48 79 /*First copy param_g so we don't modify it: */ 80 param_g_copy=(double*)xmalloc(numberofnodes*sizeof(double)); 81 memcpy(param_g_copy,param_g,numberofnodes*sizeof(double)); 82 83 /*First, update param_g using search_scalar: */ 84 for(i=0;i<numberofnodes;i++)param_g_copy[i]=param_g_copy[i]+search_scalar*optscal[n]*grad_g[i]; 49 /*Use ControlParameterEnum input to reinitialize our input parameter: */ 50 DuplicateInputx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,ControlParameterEnum,control_type); 51 52 /*Use search scalar to shoot parameter in the gradient direction: */ 53 AXPYInputx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,control_type,search_scalar*optscal[n],ControlParameterEnum); 85 54 86 55 /*Constrain:*/ 87 ControlConstrainx( param_g_copy,numberofnodes,cm_min,cm_max,control_type);56 ControlConstrainx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,control_type,cm_min,cm_max); 88 57 89 /*Add new parameter to inputs: */ 90 UpdateInputsFromVectorx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,param_g_copy,control_type,VertexEnum); 91 92 /*Run diagnostic with updated parameters.*/ 93 if(!control_steady){ 94 diagnostic_core_nonlinear(&u_g,NULL,NULL,NULL,femmodel,DiagnosticAnalysisEnum,sub_analysis_type); 95 UpdateInputsFromSolutionx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,u_g,DiagnosticAnalysisEnum,sub_analysis_type); 96 VecFree(&u_g); 97 } 98 else{ 99 //We need a 3D velocity!! (vz is required for the next thermal run) 100 diagnostic_results= diagnostic_core(model); 101 102 //extract u_g and add it to input (3d velocity needed by thermal_core) 103 diagnostic_results->FindResult(&u_g,"u_g"); 104 105 SplitSolutionVectorx(u_g,numberofnodes,3,&vx,&vy,&vz); 106 UpdateInputsFromVectorx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,vx,VxEnum,VertexEnum); 107 UpdateInputsFromVectorx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,vy,VyEnum,VertexEnum); 108 UpdateInputsFromVectorx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,vz,VzEnum,VertexEnum); 109 110 delete diagnostic_results; 111 } 58 /*Run diagnostic with updated inputs: */ 59 if(!control_steady) solver_diagnostic_nonlinear(NULL,NULL,NULL,true,femmodel,DiagnosticAnalysisEnum,sub_analysis_type); //true means we conserve loads at each diagnostic run 60 else diagnostic_core(femmodel); //We need a 3D velocity!! (vz is required for the next thermal run) 112 61 113 62 /*Compute misfit for this velocity field.*/ … … 118 67 xfree((void**)&fit); 119 68 xfree((void**)&optscal); 120 xfree((void**)¶m_g_copy);121 xfree((void**)&dofset);122 xfree((void**)&vx);123 xfree((void**)&vy);124 xfree((void**)&vz);125 126 69 return J; 127 70 } -
issm/trunk/src/c/solutions/solutions.h
r4047 r4048 25 25 Results* transient_core_3d(FemModel* model); 26 26 void adjoint_core(FemModel* model); 27 void gradient_core(FemModel* model );27 void gradient_core(FemModel* model,int step=0, double search_scalar=0); 28 28 void diagnostic_core(FemModel* model); 29 29 void thermal_core(FemModel* model); … … 33 33 //int GradJOrth(WorkspaceParams* workspaceparams); 34 34 void convergence(int* pconverged, Mat K_ff,Vec p_f,Vec u_f,Vec u_f_old,Parameters* parameters); 35 int controlconvergence(double* J, double* fit, double eps_cm, int n); 35 36 36 37 int GoldenSearch(double* psearch_scalar,double* pJ,double xa, double xb, double tolerance, int maxiter, double fit,double optscal,double (*f)(double*,double,double,FemModel*),FemModel* femmodel); … … 47 48 48 49 void ControlInitialization(FemModel* model); 49 void ControlRestart(FemModel* model,double* param_g);50 void ControlRestart(FemModel* femmodel); 50 51 51 52 void CreateFemModel(FemModel* femmodel,ConstDataHandle MODEL,int analysis_type,int sub_analysis_type);
Note:
See TracChangeset
for help on using the changeset viewer.