Changeset 5251
- Timestamp:
- 08/13/10 15:25:10 (15 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/EnumDefinitions/EnumDefinitions.h
r5225 r5251 226 226 TemperatureOldEnum, 227 227 ThicknessEnum, 228 ThicknessObsEnum, 228 229 TypeEnum, 229 230 VelEnum, … … 346 347 347 348 /*Functions on enums: */ 348 int EnumIsElement(int en);349 int EnumIsLoad(int en);350 int EnumIsMaterial(int en);351 char *EnumToString(int enum_type);352 int StringToEnum(char*string);353 char * EnumToModelField(inten);349 int EnumIsElement(int en); 350 int EnumIsLoad(int en); 351 int EnumIsMaterial(int en); 352 char *EnumToString(int enum_type); 353 int StringToEnum(char *string); 354 char *EnumToModelField(int en); 354 355 355 356 #endif -
issm/trunk/src/c/EnumDefinitions/EnumToString.cpp
r5227 r5251 200 200 case TemperatureOldEnum : return "TemperatureOld"; 201 201 case ThicknessEnum : return "Thickness"; 202 case ThicknessObsEnum : return "ThicknessObs"; 202 203 case TypeEnum : return "Type"; 203 204 case VelEnum : return "Vel"; -
issm/trunk/src/c/EnumDefinitions/StringToEnum.cpp
r5227 r5251 198 198 else if (strcmp(name,"TemperatureOld")==0) return TemperatureOldEnum; 199 199 else if (strcmp(name,"Thickness")==0) return ThicknessEnum; 200 else if (strcmp(name,"ThicknessObs")==0) return ThicknessObsEnum; 200 201 else if (strcmp(name,"Type")==0) return TypeEnum; 201 202 else if (strcmp(name,"Vel")==0) return VelEnum; -
issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness/UpdateElementsBalancedthickness.cpp
r4441 r5251 32 32 IoModelFetchData(&iomodel->accumulation_rate,NULL,NULL,iomodel_handle,"accumulation_rate"); 33 33 IoModelFetchData(&iomodel->dhdt,NULL,NULL,iomodel_handle,"dhdt"); 34 35 34 if (iomodel->dim==3){ 36 35 IoModelFetchData(&iomodel->elementonbed,NULL,NULL,iomodel_handle,"elementonbed"); 37 36 IoModelFetchData(&iomodel->elementonsurface,NULL,NULL,iomodel_handle,"elementonsurface"); 37 } 38 if(iomodel->control_analysis){ 39 IoModelFetchData(&iomodel->thickness_obs,NULL,NULL,iomodel_handle,"thickness_obs"); 40 IoModelFetchData(&iomodel->weights,NULL,NULL,iomodel_handle,"weights"); 41 if(strcmp(iomodel->control_type,"dhdt")==0){ 42 IoModelFetchData(&iomodel->control_parameter,NULL,NULL,iomodel_handle,iomodel->control_type); //copy the control parameter in iomodel 43 } 38 44 } 39 45 … … 61 67 xfree((void**)&iomodel->melting_rate); 62 68 xfree((void**)&iomodel->accumulation_rate); 69 xfree((void**)&iomodel->thickness_obs); 70 xfree((void**)&iomodel->weights); 71 xfree((void**)&iomodel->control_parameter); 63 72 } -
issm/trunk/src/c/objects/Elements/Tria.cpp
r5166 r5251 389 389 InputUpdateFromSolutionOneDof(solution,ThicknessEnum); 390 390 } 391 else if (analysis_type==AdjointBalancedthicknessAnalysisEnum){ 392 InputUpdateFromSolutionAdjointBalancedthickness( solution); 393 } 391 394 else if (analysis_type==BalancedvelocitiesAnalysisEnum){ 392 395 InputUpdateFromSolutionOneDof(solution,VelEnum); … … 657 660 658 661 /*Just branch to the correct element stiffness matrix generator, according to the type of analysis we are carrying out: */ 659 if (analysis_type==DiagnosticHorizAnalysisEnum){ 660 CreateKMatrixDiagnosticMacAyeal( Kgg); 661 } 662 else if (analysis_type==AdjointHorizAnalysisEnum){ 663 /*Same as diagnostic*/ 662 if (analysis_type==DiagnosticHorizAnalysisEnum || analysis_type==AdjointHorizAnalysisEnum){ 664 663 CreateKMatrixDiagnosticMacAyeal( Kgg); 665 664 } … … 678 677 ISSMERROR("Element type %s not supported yet",EnumToString(GetElementType())); 679 678 } 680 else if (analysis_type==BalancedthicknessAnalysisEnum ){679 else if (analysis_type==BalancedthicknessAnalysisEnum || analysis_type==AdjointBalancedthicknessAnalysisEnum){ 681 680 if (GetElementType()==P1Enum) 682 681 CreateKMatrixBalancedthickness_CG( Kgg); … … 736 735 else 737 736 ISSMERROR("Element type %s not supported yet",EnumToString(GetElementType())); 737 } 738 else if (analysis_type==AdjointBalancedthicknessAnalysisEnum){ 739 CreatePVectorAdjointBalancedthickness(pg); 738 740 } 739 741 else if (analysis_type==BalancedvelocitiesAnalysisEnum){ … … 869 871 else if (control_type==RheologyB2dEnum){ 870 872 GradjB(gradient); 873 } 874 else if (control_type==DhDtEnum){ 875 GradjDhDt(gradient); 871 876 } 872 877 else ISSMERROR("%s%i","control type not supported yet: ",control_type); … … 1205 1210 } 1206 1211 /*}}}*/ 1212 /*FUNCTION Tria::GradjDhDt{{{1*/ 1213 void Tria::GradjDhDt(Vec gradient){ 1214 1215 int i; 1216 1217 /* node data: */ 1218 const int numgrids=3; 1219 const int NDOF1=1; 1220 const int numdof=NDOF1*numgrids; 1221 double xyz_list[numgrids][3]; 1222 int doflist1[numgrids]; 1223 1224 /* grid data: */ 1225 double DhDt[numgrids]; 1226 1227 /* gaussian points: */ 1228 int num_gauss,ig; 1229 double* first_gauss_area_coord = NULL; 1230 double* second_gauss_area_coord = NULL; 1231 double* third_gauss_area_coord = NULL; 1232 double* gauss_weights = NULL; 1233 double gauss_weight; 1234 double gauss_l1l2l3[3]; 1235 1236 /*element vector at the gaussian points: */ 1237 double grade_g[numgrids]={0.0}; 1238 double grade_g_gaussian[numgrids]; 1239 1240 /* Jacobian: */ 1241 double Jdet; 1242 1243 /*nodal functions: */ 1244 double l1l2l3[3]; 1245 double lambda; 1246 1247 /*Inputs*/ 1248 Input* adjoint_input=NULL; 1249 1250 GetVerticesCoordinates(&xyz_list[0][0], nodes, numgrids); 1251 GetDofList1(&doflist1[0]); 1252 1253 /* Get gaussian points and weights (make this a statically initialized list of points? fstd): */ 1254 GaussTria( &num_gauss, &first_gauss_area_coord, &second_gauss_area_coord, &third_gauss_area_coord, &gauss_weights, 4); 1255 1256 /*Retrieve all inputs we will be needing: */ 1257 adjoint_input=inputs->GetInput(AdjointEnum); 1258 1259 /* Start looping on the number of gaussian points: */ 1260 for (ig=0; ig<num_gauss; ig++){ 1261 /*Pick up the gaussian point: */ 1262 gauss_weight=*(gauss_weights+ig); 1263 gauss_l1l2l3[0]=*(first_gauss_area_coord+ig); 1264 gauss_l1l2l3[1]=*(second_gauss_area_coord+ig); 1265 gauss_l1l2l3[2]=*(third_gauss_area_coord+ig); 1266 1267 /*Get thickness: */ 1268 adjoint_input->GetParameterValue(&lambda, gauss_l1l2l3); 1269 1270 /* Get Jacobian determinant: */ 1271 GetJacobianDeterminant2d(&Jdet, &xyz_list[0][0],gauss_l1l2l3); 1272 1273 /* Get nodal functions value at gaussian point:*/ 1274 GetNodalFunctions(l1l2l3, gauss_l1l2l3); 1275 1276 /*DhDtuild gradje_g_gaussian vector (actually -dJ/dDhDt): */ 1277 for (i=0;i<numgrids;i++){ 1278 //standard gradient dJ/dki 1279 grade_g_gaussian[i]=lambda*Jdet*gauss_weight*l1l2l3[i]; 1280 } 1281 1282 /*Add grade_g_gaussian to grade_g: */ 1283 for( i=0; i<numgrids;i++) grade_g[i]+=grade_g_gaussian[i]; 1284 } 1285 1286 /*Add grade_g to global vector gradient: */ 1287 VecSetValues(gradient,numgrids,doflist1,(const double*)grade_g,ADD_VALUES); 1288 1289 xfree((void**)&first_gauss_area_coord); 1290 xfree((void**)&second_gauss_area_coord); 1291 xfree((void**)&third_gauss_area_coord); 1292 xfree((void**)&gauss_weights); 1293 } 1294 /*}}}*/ 1207 1295 /*FUNCTION Tria::InputControlUpdate{{{1*/ 1208 1296 void Tria::InputControlUpdate(double scalar,bool save_parameter){ … … 1253 1341 /*Finally: save input if requested*/ 1254 1342 if (save_parameter) inputs->DuplicateInput(DragCoefficientEnum,ControlParameterEnum); 1343 1344 } 1345 else if(control_type==DhDtEnum){ 1346 1347 /*First, get revert to previous parameter value (kept in ControlParameter input)*/ 1348 this->inputs->DuplicateInput(ControlParameterEnum,DhDtEnum); 1349 1350 /*Now, update using the gradient new = old + scalar * gradient*/ 1351 this->inputs->AXPY(DhDtEnum,scalar,GradientEnum); 1352 1353 /*Constrain input*/ 1354 input=(Input*)this->inputs->GetInput(DhDtEnum); ISSMASSERT(input); 1355 input->Constrain(cm_min,cm_max); 1356 1357 /*Finally: save input if requested*/ 1358 if (save_parameter) inputs->DuplicateInput(DhDtEnum,ControlParameterEnum); 1255 1359 1256 1360 } … … 2155 2259 for(i=0;i<3;i++)nodeinputs[i]=iomodel->control_parameter[tria_vertex_ids[i]-1]; 2156 2260 this->inputs->AddInput(new TriaVertexInput(ControlParameterEnum,nodeinputs)); 2261 } 2262 if (iomodel->thickness_obs) { 2263 for(i=0;i<3;i++)nodeinputs[i]=iomodel->thickness_obs[tria_vertex_ids[i]-1]/iomodel->yts; 2264 this->inputs->AddInput(new TriaVertexInput(ThicknessObsEnum,nodeinputs)); 2157 2265 } 2158 2266 if (iomodel->melting_rate) { … … 4222 4330 } 4223 4331 /*}}}*/ 4332 /*FUNCTION Tria::CreatePVectorAdjointBalancedthickness{{{1*/ 4333 void Tria::CreatePVectorAdjointBalancedthickness(Vec p_g){ 4334 4335 int i; 4336 4337 /* node data: */ 4338 const int numgrids=3; 4339 const int numdof=1*numgrids; 4340 double xyz_list[numgrids][3]; 4341 int* doflist=NULL; 4342 4343 /* gaussian points: */ 4344 int num_gauss,ig; 4345 double* first_gauss_area_coord = NULL; 4346 double* second_gauss_area_coord = NULL; 4347 double* third_gauss_area_coord = NULL; 4348 double* gauss_weights = NULL; 4349 double gauss_weight; 4350 double gauss_l1l2l3[3]; 4351 4352 /* parameters: */ 4353 double thickness,thicknessobs,weight; 4354 4355 /*element vector : */ 4356 double pe_g[numdof]={0.0}; 4357 double pe_g_gaussian[numdof]; 4358 4359 /* Jacobian: */ 4360 double Jdet; 4361 4362 /*nodal functions: */ 4363 double l1l2l3[3]; 4364 4365 /*inputs: */ 4366 Input* thickness_input=NULL; 4367 Input* thicknessobs_input=NULL; 4368 Input* weights_input=NULL; 4369 4370 /* Get node coordinates and dof list: */ 4371 GetVerticesCoordinates(&xyz_list[0][0], nodes, numgrids); 4372 GetDofList(&doflist); 4373 4374 /*Retrieve all inputs we will be needing: */ 4375 thickness_input =inputs->GetInput(ThicknessEnum); ISSMASSERT(thickness_input); 4376 thicknessobs_input=inputs->GetInput(ThicknessObsEnum);ISSMASSERT(thicknessobs_input); 4377 weights_input =inputs->GetInput(ThicknessObsEnum);ISSMASSERT(weights_input); 4378 4379 /* Get gaussian points and weights (make this a statically initialized list of points? fstd): */ 4380 GaussTria( &num_gauss, &first_gauss_area_coord, &second_gauss_area_coord, &third_gauss_area_coord, &gauss_weights, 2); 4381 4382 /* Start looping on the number of gaussian points: */ 4383 for (ig=0; ig<num_gauss; ig++){ 4384 /*Pick up the gaussian point: */ 4385 gauss_weight=*(gauss_weights+ig); 4386 gauss_l1l2l3[0]=*(first_gauss_area_coord+ig); 4387 gauss_l1l2l3[1]=*(second_gauss_area_coord+ig); 4388 gauss_l1l2l3[2]=*(third_gauss_area_coord+ig); 4389 4390 /* Get Jacobian determinant: */ 4391 GetJacobianDeterminant2d(&Jdet, &xyz_list[0][0],gauss_l1l2l3); 4392 4393 /* Get nodal functions value at gaussian point:*/ 4394 GetNodalFunctions(l1l2l3, gauss_l1l2l3); 4395 4396 /*Get parameters at gauss point*/ 4397 thickness_input->GetParameterValue(&thickness, &gauss_l1l2l3[0]); 4398 thicknessobs_input->GetParameterValue(&thicknessobs, &gauss_l1l2l3[0]); 4399 weights_input->GetParameterValue(&weight, &gauss_l1l2l3[0]); 4400 4401 for (i=0;i<numgrids;i++){ 4402 pe_g_gaussian[i]=(thicknessobs-thickness)*weight*Jdet*gauss_weight*l1l2l3[i]; 4403 } 4404 4405 /*Add pe_g_gaussian vector to pe_g: */ 4406 for( i=0; i<numdof; i++){ 4407 pe_g[i]+=pe_g_gaussian[i]; 4408 } 4409 } 4410 4411 /*Add pe_g to global vector p_g: */ 4412 VecSetValues(p_g,numdof,doflist,(const double*)pe_g,ADD_VALUES); 4413 4414 /*Free ressources:*/ 4415 xfree((void**)&first_gauss_area_coord); 4416 xfree((void**)&second_gauss_area_coord); 4417 xfree((void**)&third_gauss_area_coord); 4418 xfree((void**)&gauss_weights); 4419 xfree((void**)&doflist); 4420 } 4421 /*}}}*/ 4224 4422 /*FUNCTION Tria::CreatePVectorAdjointHoriz{{{1*/ 4225 4423 void Tria::CreatePVectorAdjointHoriz(Vec p_g){ … … 5833 6031 } 5834 6032 /*}}}*/ 6033 /*FUNCTION Tria::InputUpdateFromSolutionAdjointBalancedthickness {{{1*/ 6034 void Tria::InputUpdateFromSolutionAdjointBalancedthickness(double* solution){ 6035 6036 int i; 6037 6038 const int numvertices=3; 6039 const int numdofpervertex=1; 6040 const int numdof=numdofpervertex*numvertices; 6041 int* doflist=NULL; 6042 double values[numdof]; 6043 double lambda[numvertices]; 6044 6045 /*Get dof list: */ 6046 GetDofList(&doflist); 6047 6048 /*Use the dof list to index into the solution vector: */ 6049 for(i=0;i<numdof;i++){ 6050 values[i]=solution[doflist[i]]; 6051 } 6052 6053 /*Ok, we have vx and vy in values, fill in vx and vy arrays: */ 6054 for(i=0;i<numvertices;i++){ 6055 lambda[i]=values[i*numdofpervertex+0]; 6056 } 6057 6058 /*Add vx and vy as inputs to the tria element: */ 6059 this->inputs->AddInput(new TriaVertexInput(AdjointEnum,lambda)); 6060 6061 /*Free ressources:*/ 6062 xfree((void**)&doflist); 6063 6064 } 6065 /*}}}*/ 5835 6066 /*FUNCTION Tria::InputUpdateFromSolutionAdjointHoriz {{{1*/ 5836 6067 void Tria::InputUpdateFromSolutionAdjointHoriz(double* solution){ -
issm/trunk/src/c/objects/Elements/Tria.h
r5166 r5251 82 82 void GradjB(Vec gradient); 83 83 void GradjDrag(Vec gradient); 84 void GradjDhDt(Vec gradient); 84 85 void InputControlUpdate(double scalar,bool save_parameter); 85 86 bool InputConvergence(double* eps, int* enums,int num_enums,int* criterionenums,double* criterionvalues,int num_criterionenums); … … 130 131 void CreatePVectorAdjointHoriz(Vec pg); 131 132 void CreatePVectorAdjointStokes(Vec pg); 133 void CreatePVectorAdjointBalancedthickness(Vec pg); 132 134 void CreatePVectorDiagnosticHutter(Vec pg); 133 135 void CreatePVectorPrognostic_CG(Vec pg); … … 149 151 void GetStrainRate2d(double* epsilon,double* xyz_list, double* gauss, Input* vx_input, Input* vy_input); 150 152 void GradjDragStokes(Vec gradient); 153 void InputUpdateFromSolutionAdjointBalancedthickness( double* solution); 151 154 void InputUpdateFromSolutionAdjointHoriz( double* solution); 152 155 void InputUpdateFromSolutionDiagnosticHoriz( double* solution); -
issm/trunk/src/c/objects/IoModel.cpp
r5196 r5251 56 56 xfree((void**)&this->gridonstokes); 57 57 xfree((void**)&this->borderstokes); 58 xfree((void**)&this->thickness_obs); 58 59 xfree((void**)&this->thickness); 59 60 xfree((void**)&this->surface); … … 267 268 this->gridonstokes=NULL; 268 269 this->borderstokes=NULL; 270 this->thickness_obs=NULL; 269 271 this->thickness=NULL; 270 272 this->surface=NULL; -
issm/trunk/src/c/objects/IoModel.h
r5196 r5251 59 59 60 60 /*observations: */ 61 double* thickness_obs; 61 62 double* vx_obs; 62 63 double* vy_obs; -
issm/trunk/src/c/solutions/adjoint_core.cpp
r4839 r5251 26 26 27 27 /*set analysis type to compute velocity: */ 28 _printf_("%s\n"," computing velocities"); 29 if(isstokes)femmodel->SetCurrentConfiguration(DiagnosticStokesAnalysisEnum); 30 else femmodel->SetCurrentConfiguration(DiagnosticHorizAnalysisEnum); 31 solver_diagnostic_nonlinear(femmodel,conserve_loads); 28 if (solution_type==SteadystateSolutionEnum || solution_type==DiagnosticSolutionEnum){ 29 _printf_("%s\n"," computing velocities"); 30 if(isstokes)femmodel->SetCurrentConfiguration(DiagnosticStokesAnalysisEnum); 31 else femmodel->SetCurrentConfiguration(DiagnosticHorizAnalysisEnum); 32 solver_diagnostic_nonlinear(femmodel,conserve_loads); 33 } 34 else if (solution_type==BalancedthicknessSolutionEnum){ 35 femmodel->SetCurrentConfiguration(BalancedthicknessAnalysisEnum); 36 solver_linear(femmodel); 37 } 38 else{ 39 ISSMERROR("Solution %s not implemented yet",EnumToString(solution_type)); 40 } 32 41 33 42 /*Update inputs using adjoint solution, and same type of setup as diagnostic solution: */ 34 43 _printf_("%s\n"," computing adjoint"); 35 if(isstokes)femmodel->SetCurrentConfiguration(DiagnosticStokesAnalysisEnum,AdjointStokesAnalysisEnum); 36 else femmodel->SetCurrentConfiguration(DiagnosticHorizAnalysisEnum,AdjointHorizAnalysisEnum); 44 if (solution_type==SteadystateSolutionEnum || solution_type==DiagnosticSolutionEnum){ 45 if(isstokes)femmodel->SetCurrentConfiguration(DiagnosticStokesAnalysisEnum,AdjointStokesAnalysisEnum); 46 else femmodel->SetCurrentConfiguration(DiagnosticHorizAnalysisEnum,AdjointHorizAnalysisEnum); 47 } 48 else if (solution_type==BalancedthicknessSolutionEnum){ 49 femmodel->SetCurrentConfiguration(BalancedthicknessAnalysisEnum,AdjointBalancedthicknessAnalysisEnum); 50 } 37 51 solver_adjoint_linear(femmodel); 38 52 -
issm/trunk/src/c/solutions/objectivefunctionC.cpp
r4974 r5251 28 28 29 29 /*parameters: */ 30 FemModel * femmodel=NULL;31 int n;32 double * optscal=NULL;33 double * fit=NULL;34 int control_type;35 int analysis_type;36 bool control_steady;37 bool isstokes=false;38 bool conserve_loads=true;39 bool process_units=false;30 FemModel *femmodel = NULL; 31 int n; 32 double *optscal = NULL; 33 double *fit = NULL; 34 int control_type; 35 int solution_type; 36 int analysis_type; 37 bool isstokes = false; 38 bool conserve_loads = true; 39 bool process_units = false; 40 40 41 41 /*Recover finite element model: */ … … 49 49 femmodel->parameters->FindParam(&isstokes,IsStokesEnum); 50 50 femmodel->parameters->FindParam(&control_type,ControlTypeEnum); 51 femmodel->parameters->FindParam(&control_steady,ControlSteadyEnum);52 51 femmodel->parameters->FindParam(&analysis_type,AnalysisTypeEnum); 52 femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum); 53 53 54 54 /*set analysis type to compute velocity: */ 55 if(isstokes)femmodel->SetCurrentConfiguration(DiagnosticStokesAnalysisEnum); 56 else femmodel->SetCurrentConfiguration(DiagnosticHorizAnalysisEnum); 55 if (solution_type==SteadystateSolutionEnum || solution_type==DiagnosticSolutionEnum){ 56 if(isstokes)femmodel->SetCurrentConfiguration(DiagnosticStokesAnalysisEnum); 57 else femmodel->SetCurrentConfiguration(DiagnosticHorizAnalysisEnum); 58 } 59 else if (solution_type==BalancedthicknessSolutionEnum){ 60 femmodel->SetCurrentConfiguration(BalancedthicknessAnalysisEnum); 61 } 62 else{ 63 ISSMERROR("Solution %s not implemented yet",EnumToString(solution_type)); 64 } 57 65 58 66 /*update parameter according to scalar: */ //false means: do not copy updated parameter onto ControlParameter input … … 60 68 61 69 /*Run diagnostic with updated inputs: */ 62 if(!control_steady) solver_diagnostic_nonlinear(femmodel,conserve_loads); //true means we conserve loads at each diagnostic run 63 else diagnostic_core(femmodel); //We need a 3D velocity!! (vz is required for the next thermal run) 70 if (solution_type==SteadystateSolutionEnum){ 71 diagnostic_core(femmodel); //We need a 3D velocity!! (vz is required for the next thermal run) 72 } 73 else if (solution_type==DiagnosticSolutionEnum){ 74 solver_diagnostic_nonlinear(femmodel,conserve_loads); 75 } 76 else if (solution_type==BalancedthicknessSolutionEnum){ 77 solver_linear(femmodel); 78 } 79 else{ 80 ISSMERROR("Solution %s not implemented yet",EnumToString(solution_type)); 81 } 64 82 65 83 /*Compute misfit for this velocity field.*/
Note:
See TracChangeset
for help on using the changeset viewer.