Changeset 3169
- Timestamp:
- 03/03/10 16:21:37 (15 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 3 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/DataSet/DataSet.cpp
r3045 r3169 1486 1486 } 1487 1487 1488 void DataSet::Misfit(double* pJ,void* inputs,int analysis_type,int sub_analysis_type ,int real){1488 void DataSet::Misfit(double* pJ,void* inputs,int analysis_type,int sub_analysis_type){ 1489 1489 1490 1490 double J=0;; … … 1498 1498 1499 1499 element=(Element*)(*object); 1500 J+=element->Misfit(inputs,analysis_type,sub_analysis_type ,real);1500 J+=element->Misfit(inputs,analysis_type,sub_analysis_type); 1501 1501 1502 1502 } … … 1508 1508 } 1509 1509 1510 void DataSet::CostFunction(double* pJ,void* inputs,int analysis_type,int sub_analysis_type){ 1511 1512 double J=0;; 1513 1514 vector<Object*>::iterator object; 1515 Element* element=NULL; 1516 1517 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1518 1519 if(EnumIsElement((*object)->Enum())){ 1520 1521 element=(Element*)(*object); 1522 J+=element->CostFunction(inputs,analysis_type,sub_analysis_type); 1523 1524 } 1525 } 1526 1527 /*Assign output pointers:*/ 1528 *pJ=J; 1529 1530 } 1531 1510 1532 void DataSet::FieldExtrude(Vec field,double* field_serial,char* field_name, int collapse){ 1511 1533 -
issm/trunk/src/c/DataSet/DataSet.h
r3045 r3169 81 81 void Du(Vec du_g,void* inputs,int analysis_type,int sub_analysis_type); 82 82 void Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type); 83 void Misfit(double* pJ, void* inputs,int analysis_type,int sub_analysis_type,int real); 83 void Misfit(double* pJ, void* inputs,int analysis_type,int sub_analysis_type); 84 void CostFunction(double* pJ, void* inputs,int analysis_type,int sub_analysis_type); 84 85 void FieldDepthAverageAtBase(Vec field,double* field_serial,char* fieldname); 85 86 int DeleteObject(Object* object); -
issm/trunk/src/c/Makefile.am
r3159 r3169 235 235 ./Misfitx/Misfitx.h\ 236 236 ./Misfitx/Misfitx.cpp\ 237 ./CostFunctionx/CostFunctionx.h\ 238 ./CostFunctionx/CostFunctionx.cpp\ 237 239 ./Orthx/Orthx.h\ 238 240 ./Orthx/Orthx.cpp\ … … 561 563 ./Misfitx/Misfitx.h\ 562 564 ./Misfitx/Misfitx.cpp\ 565 ./CostFunctionx/CostFunctionx.h\ 566 ./CostFunctionx/CostFunctionx.cpp\ 563 567 ./Orthx/Orthx.h\ 564 568 ./Orthx/Orthx.cpp\ -
issm/trunk/src/c/Misfitx/Misfitx.cpp
r3045 r3169 14 14 15 15 void Misfitx( double* pJ, DataSet* elements,DataSet* nodes, DataSet* loads, DataSet* materials,DataSet* parameters, 16 ParameterInputs* inputs,int analysis_type,int sub_analysis_type ,int real){16 ParameterInputs* inputs,int analysis_type,int sub_analysis_type){ 17 17 18 18 /*output: */ … … 25 25 26 26 /*Compute gradients: */ 27 elements->Misfit(&J,inputs,analysis_type,sub_analysis_type ,real);27 elements->Misfit(&J,inputs,analysis_type,sub_analysis_type); 28 28 29 29 /*Sum all J from all cpus of the cluster:*/ -
issm/trunk/src/c/Misfitx/Misfitx.h
r3045 r3169 10 10 /* local prototypes: */ 11 11 void Misfitx( double* pJ, DataSet* elements,DataSet* nodes, DataSet* loads, DataSet* materials, DataSet* parameters, 12 ParameterInputs* inputs,int analysis_type,int sub_analysis_type ,int real);12 ParameterInputs* inputs,int analysis_type,int sub_analysis_type); 13 13 14 14 #endif /* _MISFITX_H */ -
issm/trunk/src/c/Qmux/DakotaResponses.cpp
r3057 r3169 264 264 265 265 /*Compute misfit: */ 266 Misfitx( &J, femmodel->elements,femmodel->nodes, femmodel->loads, femmodel->materials, femmodel->parameters,inputs,analysis_type,sub_analysis_type ,1);266 Misfitx( &J, femmodel->elements,femmodel->nodes, femmodel->loads, femmodel->materials, femmodel->parameters,inputs,analysis_type,sub_analysis_type); 267 267 268 268 -
issm/trunk/src/c/issm.h
r3127 r3169 53 53 #include "./Orthx/Orthx.h" 54 54 #include "./Misfitx/Misfitx.h" 55 #include "./CostFunctionx/CostFunctionx.h" 55 56 #include "./ControlConstrainx/ControlConstrainx.h" 56 57 #include "./FieldDepthAveragex/FieldDepthAveragex.h" -
issm/trunk/src/c/objects/Beam.cpp
r3159 r3169 233 233 } 234 234 /*}}}*/ 235 /*FUNCTION Beam CostFunction{{{1*/ 236 #undef __FUNCT__ 237 #define __FUNCT__ "Beam::CostFunction" 238 double Beam::CostFunction(void*,int,int){ 239 throw ErrorException(__FUNCT__," not supported yet!"); 240 } 241 /*}}}*/ 235 242 /*FUNCTION Beam CreateKMatrix{{{1*/ 236 243 #undef __FUNCT__ … … 666 673 #undef __FUNCT__ 667 674 #define __FUNCT__ "Beam::Misfit" 668 double Beam::Misfit(void*,int,int ,int){675 double Beam::Misfit(void*,int,int){ 669 676 throw ErrorException(__FUNCT__," not supported yet!"); 670 677 } -
issm/trunk/src/c/objects/Beam.h
r3041 r3169 87 87 void GradjDrag(_p_Vec*, void*, int,int ); 88 88 void GradjB(_p_Vec*, void*, int,int ); 89 double Misfit(void*,int,int,int); 89 double Misfit(void*,int,int); 90 double CostFunction(void*,int,int); 90 91 void GetNodalFunctions(double* l1l2, double gauss_coord); 91 92 void GetParameterValue(double* pvalue, double* value_list,double gauss_coord); -
issm/trunk/src/c/objects/Element.h
r3041 r3169 38 38 virtual void GradjDrag(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type)=0; 39 39 virtual void GradjB(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type)=0; 40 virtual double Misfit(void* inputs,int analysis_type,int sub_analysis_type,int real)=0; 40 virtual double Misfit(void* inputs,int analysis_type,int sub_analysis_type)=0; 41 virtual double CostFunction(void* inputs,int analysis_type,int sub_analysis_type)=0; 41 42 virtual void ComputePressure(Vec p_g)=0; 42 43 virtual double MassFlux(double* segment,double* ug)=0; -
issm/trunk/src/c/objects/Penta.cpp
r3161 r3169 282 282 Object* Penta::copy() { 283 283 return new Penta(*this); 284 } 285 /*}}}*/ 286 /*FUNCTION CostFunction {{{1*/ 287 #undef __FUNCT__ 288 #define __FUNCT__ "Penta::CostFunction" 289 double Penta::CostFunction(void* inputs,int analysis_type,int sub_analysis_type){ 290 291 double J; 292 Tria* tria=NULL; 293 294 /*If on water, return 0: */ 295 if(onwater)return 0; 296 297 /*Bail out if this element if: 298 * -> Non collapsed and not on the surface 299 * -> collapsed (2d model) and not on bed) */ 300 if ((!collapse && !onsurface) || (collapse && !onbed)){ 301 return 0; 302 } 303 else if (collapse){ 304 305 /*This element should be collapsed into a tria element at its base. Create this tria element, 306 * and compute CostFunction*/ 307 tria=(Tria*)SpawnTria(0,1,2); //grids 0, 1 and 2 make the new tria (lower face). 308 J=tria->CostFunction(inputs,analysis_type,sub_analysis_type); 309 delete tria; 310 return J; 311 } 312 else{ 313 314 tria=(Tria*)SpawnTria(3,4,5); //grids 3, 4 and 5 make the new tria (upper face). 315 J=tria->CostFunction(inputs,analysis_type,sub_analysis_type); 316 delete tria; 317 return J; 318 } 284 319 } 285 320 /*}}}*/ … … 3915 3950 #undef __FUNCT__ 3916 3951 #define __FUNCT__ "Penta::Misfit" 3917 double Penta::Misfit(void* inputs,int analysis_type,int sub_analysis_type ,int real){3952 double Penta::Misfit(void* inputs,int analysis_type,int sub_analysis_type){ 3918 3953 3919 3954 double J; … … 3934 3969 * and compute Misfit*/ 3935 3970 tria=(Tria*)SpawnTria(0,1,2); //grids 0, 1 and 2 make the new tria (lower face). 3936 J=tria->Misfit(inputs,analysis_type,sub_analysis_type ,real);3971 J=tria->Misfit(inputs,analysis_type,sub_analysis_type); 3937 3972 delete tria; 3938 3973 return J; … … 3941 3976 3942 3977 tria=(Tria*)SpawnTria(3,4,5); //grids 3, 4 and 5 make the new tria (upper face). 3943 J=tria->Misfit(inputs,analysis_type,sub_analysis_type ,real);3978 J=tria->Misfit(inputs,analysis_type,sub_analysis_type); 3944 3979 delete tria; 3945 3980 return J; -
issm/trunk/src/c/objects/Penta.h
r3041 r3169 88 88 void GradjDrag(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type); 89 89 void GradjB(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type); 90 double Misfit(void* inputs,int analysis_type,int sub_analysis_type,int real); 90 double Misfit(void* inputs,int analysis_type,int sub_analysis_type); 91 double CostFunction(void* inputs,int analysis_type,int sub_analysis_type); 91 92 92 93 void GetThicknessList(double* thickness_list); -
issm/trunk/src/c/objects/Sing.cpp
r3041 r3169 216 216 } 217 217 /*}}}*/ 218 /*FUNCTION Sing::CostFunction {{{1*/ 219 #undef __FUNCT__ 220 #define __FUNCT__ "Sing::CostFunction" 221 double Sing::CostFunction(void*, int,int){ 222 throw ErrorException(__FUNCT__," not supported yet!"); 223 } 224 /*}}}*/ 218 225 /*FUNCTION Sing::CreateKMatrix {{{1*/ 219 226 #undef __FUNCT__ … … 515 522 #undef __FUNCT__ 516 523 #define __FUNCT__ "Sing::Misfit" 517 double Sing::Misfit(void*, int,int ,int){524 double Sing::Misfit(void*, int,int){ 518 525 throw ErrorException(__FUNCT__," not supported yet!"); 519 526 } -
issm/trunk/src/c/objects/Sing.h
r3041 r3169 82 82 void GradjDrag(_p_Vec*, void*, int,int); 83 83 void GradjB(_p_Vec*, void*, int,int); 84 double Misfit(void*,int,int,int); 84 double Misfit(void*,int,int); 85 double CostFunction(void*,int,int); 85 86 double MassFlux(double* segment,double* ug); 86 87 -
issm/trunk/src/c/objects/Tria.cpp
r3160 r3169 268 268 } 269 269 /*}}}*/ 270 /*FUNCTION CostFunction {{{1*/ 271 #undef __FUNCT__ 272 #define __FUNCT__ "Tria::CostFunction" 273 double Tria::CostFunction(void* vinputs,int analysis_type,int sub_analysis_type){ 274 275 int i; 276 277 /* output: */ 278 double Jelem; 279 280 /* node data: */ 281 const int numgrids=3; 282 const int numdof=2*numgrids; 283 const int NDOF2=2; 284 int dofs1[1]={0}; 285 int dofs2[2]={0,1}; 286 double xyz_list[numgrids][3]; 287 288 /* grid data: */ 289 double B[numgrids]; 290 291 /* gaussian points: */ 292 int num_gauss,ig; 293 double* first_gauss_area_coord = NULL; 294 double* second_gauss_area_coord = NULL; 295 double* third_gauss_area_coord = NULL; 296 double* gauss_weights = NULL; 297 double gauss_weight; 298 double gauss_l1l2l3[3]; 299 double k_gauss; 300 double B_gauss; 301 302 /* parameters: */ 303 double dk[NDOF2]; 304 double dB[NDOF2]; 305 306 /* Jacobian: */ 307 double Jdet; 308 309 ParameterInputs* inputs=NULL; 310 311 /*If on water, return 0: */ 312 if(onwater)return 0; 313 314 /*recover pointers: */ 315 inputs=(ParameterInputs*)vinputs; 316 317 /* Get node coordinates and dof list: */ 318 GetVerticesCoordinates(&xyz_list[0][0], nodes, numgrids); 319 320 /*First, get Misfit*/ 321 Jelem=Misfit(inputs,analysis_type,sub_analysis_type); 322 323 /* Get gaussian points and weights (make this a statically initialized list of points? fstd): */ 324 GaussTria( &num_gauss, &first_gauss_area_coord, &second_gauss_area_coord, &third_gauss_area_coord, &gauss_weights, 2); 325 326 #ifdef _ISSM_DEBUG_ 327 for (i=0;i<num_gauss;i++){ 328 printf("Gauss coord %i: %lf %lf %lf Weight: %lf\n",i,*(first_gauss_area_coord+i),*(second_gauss_area_coord+i),*(third_gauss_area_coord+i),*(gauss_weights+i)); 329 } 330 #endif 331 332 /* Start looping on the number of gaussian points: */ 333 for (ig=0; ig<num_gauss; ig++){ 334 /*Pick up the gaussian point: */ 335 gauss_weight=*(gauss_weights+ig); 336 gauss_l1l2l3[0]=*(first_gauss_area_coord+ig); 337 gauss_l1l2l3[1]=*(second_gauss_area_coord+ig); 338 gauss_l1l2l3[2]=*(third_gauss_area_coord+ig); 339 340 /* Get Jacobian determinant: */ 341 GetJacobianDeterminant2d(&Jdet, &xyz_list[0][0],gauss_l1l2l3); 342 343 /*Add Tikhonov regularization term to misfit*/ 344 if (strcmp(numpar->control_type,"drag")==0){ 345 if (!shelf){ 346 347 GetParameterDerivativeValue(&dk[0], &k[0],&xyz_list[0][0], gauss_l1l2l3); 348 Jelem+=numpar->cm_noisedmp*1/2*(pow(dk[0],2)+pow(dk[1],2))*Jdet*gauss_weight; 349 350 } 351 } 352 else if (strcmp(numpar->control_type,"B")==0){ 353 354 if(!inputs->Recover("B",&B[0],1,dofs1,numgrids,(void**)nodes)){ 355 throw ErrorException(__FUNCT__,"parameter B not found in input"); 356 } 357 GetParameterDerivativeValue(&dB[0], &B[0],&xyz_list[0][0], gauss_l1l2l3); 358 Jelem+=numpar->cm_noisedmp*1/2*(pow(dB[0],2)+pow(dB[1],2))*Jdet*gauss_weight; 359 360 } 361 else{ 362 throw ErrorException(__FUNCT__,exprintf("%s%s","unsupported control type: ",numpar->control_type)); 363 } 364 365 } 366 367 xfree((void**)&first_gauss_area_coord); 368 xfree((void**)&second_gauss_area_coord); 369 xfree((void**)&third_gauss_area_coord); 370 xfree((void**)&gauss_weights); 371 372 /*Return: */ 373 return Jelem; 374 } 375 /*}}}*/ 270 376 /*FUNCTION CreateKMatrix {{{1*/ 271 377 #undef __FUNCT__ … … 4318 4424 #undef __FUNCT__ 4319 4425 #define __FUNCT__ "Tria::Misfit" 4320 double Tria::Misfit(void* vinputs,int analysis_type,int sub_analysis_type ,int real){4426 double Tria::Misfit(void* vinputs,int analysis_type,int sub_analysis_type){ 4321 4427 4322 4428 int i; … … 4343 4449 double relative_list[numgrids]; 4344 4450 double logarithmic_list[numgrids]; 4345 double B[numgrids];4346 4451 4347 4452 /* gaussian points: */ … … 4353 4458 double gauss_weight; 4354 4459 double gauss_l1l2l3[3]; 4355 double k_gauss;4356 double B_gauss;4357 4460 4358 4461 /* parameters: */ 4359 4462 double velocity_mag,obs_velocity_mag; 4360 4463 double absolute,relative,logarithmic; 4361 double dk[NDOF2];4362 double dB[NDOF2];4363 4464 4364 4465 /* Jacobian: */ … … 4431 4532 GaussTria( &num_gauss, &first_gauss_area_coord, &second_gauss_area_coord, &third_gauss_area_coord, &gauss_weights, 2); 4432 4533 4433 #ifdef _ISSM_DEBUG_4434 for (i=0;i<num_gauss;i++){4435 printf("Gauss coord %i: %lf %lf %lf Weight: %lf\n",i,*(first_gauss_area_coord+i),*(second_gauss_area_coord+i),*(third_gauss_area_coord+i),*(gauss_weights+i));4436 }4437 #endif4438 4439 4534 /* Start looping on the number of gaussian points: */ 4440 4535 for (ig=0; ig<num_gauss; ig++){ … … 4447 4542 /* Get Jacobian determinant: */ 4448 4543 GetJacobianDeterminant2d(&Jdet, &xyz_list[0][0],gauss_l1l2l3); 4449 #ifdef _ISSM_DEBUG_4450 printf("Element id %i Jacobian determinant: %lf\n",GetId(),Jdet);4451 #endif4452 4453 /*Add dampening terms to misfit*/4454 if(!real){4455 if (strcmp(numpar->control_type,"drag")==0){4456 if (!shelf){4457 4458 //noise dampening4459 GetParameterDerivativeValue(&dk[0], &k[0],&xyz_list[0][0], gauss_l1l2l3);4460 Jelem+=numpar->cm_noisedmp*1/2*(pow(dk[0],2)+pow(dk[1],2))*Jdet*gauss_weight;4461 4462 }4463 }4464 else if (strcmp(numpar->control_type,"B")==0){4465 if(!inputs->Recover("B",&B[0],1,dofs1,numgrids,(void**)nodes)){4466 throw ErrorException(__FUNCT__,"parameter B not found in input");4467 }4468 //noise dampening4469 GetParameterDerivativeValue(&dB[0], &B[0],&xyz_list[0][0], gauss_l1l2l3);4470 Jelem+=numpar->cm_noisedmp*1/2*(pow(dB[0],2)+pow(dB[1],2))*Jdet*gauss_weight;4471 4472 //min dampening4473 GetParameterValue(&B_gauss, &B[0],gauss_l1l2l3);4474 if(B_gauss<numpar->cm_mindmp_value){4475 Jelem+=numpar->cm_mindmp_slope*B_gauss*Jdet*gauss_weight;4476 }4477 4478 //max dampening4479 if(B_gauss>numpar->cm_maxdmp_value){4480 Jelem+=numpar->cm_maxdmp_slope*B_gauss*Jdet*gauss_weight;4481 }4482 }4483 else{4484 throw ErrorException(__FUNCT__,exprintf("%s%s","unsupported control type: ",numpar->control_type));4485 }4486 }4487 4544 4488 4545 /*Differents misfits are allowed: */ … … 4509 4566 } 4510 4567 else throw ErrorException(__FUNCT__,exprintf("%s%i%s","fit type",fit," not supported yet!")); 4511 4512 4513 } 4514 cleanup_and_return: 4568 4569 } 4570 4515 4571 xfree((void**)&first_gauss_area_coord); 4516 4572 xfree((void**)&second_gauss_area_coord); -
issm/trunk/src/c/objects/Tria.h
r3041 r3169 99 99 void SurfaceNormal(double* surface_normal, double xyz_list[3][3]); 100 100 void GradjB(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type); 101 double Misfit(void* inputs,int analysis_type,int sub_analysis_type,int real); 101 double Misfit(void* inputs,int analysis_type,int sub_analysis_type); 102 double CostFunction(void* inputs,int analysis_type,int sub_analysis_type); 102 103 103 104 void CreatePVectorDiagnosticHoriz(Vec pg,void* inputs,int analysis_type,int sub_analysis_type); -
issm/trunk/src/c/parallel/objectivefunctionC.cpp
r3045 r3169 97 97 /*Compute misfit for this velocity field.*/ 98 98 inputs->Add("fit",fit[n]); 99 Misfitx( &J, femmodel->elements,femmodel->nodes, femmodel->loads, femmodel->materials, femmodel->parameters,inputs,analysis_type,sub_analysis_type,0);99 CostFunctionx( &J, femmodel->elements,femmodel->nodes, femmodel->loads, femmodel->materials, femmodel->parameters,inputs,analysis_type,sub_analysis_type); 100 100 101 101 /*Free ressources:*/
Note:
See TracChangeset
for help on using the changeset viewer.