Changeset 46
- Timestamp:
- 04/24/09 15:31:51 (16 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 3 added
- 3 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Makefile.am
r9 r46 71 71 ./shared/Numerics/numerics.h\ 72 72 ./shared/Numerics/GaussPoints.h\ 73 ./shared/Numerics/GaussPoints.cpp\ 73 74 ./shared/Numerics/BrentSearch.cpp\ 74 75 ./shared/Numerics/OptFunc.cpp\ 75 76 ./shared/Numerics/extrema.cpp\ 76 ./shared/Numerics/GaussPoints.cpp\77 77 ./shared/Exceptions/exceptions.h\ 78 78 ./shared/Exceptions/Exceptions.cpp\ … … 419 419 ./parallel/CreateFemModel.cpp\ 420 420 ./parallel/OutputDiagnostic.cpp\ 421 ./parallel/WriteLockFile.cpp 421 ./parallel/WriteLockFile.cpp\ 422 ./parallel/control.cpp\ 423 ./parallel/OutputControl.cpp\ 424 ./parallel/objectivefunctionC.cpp\ 425 ./parallel/GradJCompute.cpp 422 426 423 427 libpISSM_a_CXXFLAGS = -fPIC -D_PARALLEL_ -D_C_ … … 426 430 bin_PROGRAMS = 427 431 else 428 bin_PROGRAMS = diagnostic.exe 429 # control.exethermalsteady.exe432 bin_PROGRAMS = diagnostic.exe control.exe 433 #thermalsteady.exe 430 434 endif 431 435 -
issm/trunk/src/c/ModelProcessorx/CreateElementsNodesAndMaterialsDiagnosticHoriz.cpp
r1 r46 64 64 double tria_q; 65 65 int tria_shelf; 66 double tria_fit;67 66 double tria_meanvel;/*!scaling ratio for velocities*/ 68 67 double tria_epsvel; /*!minimum velocity to avoid infinite velocity ratios*/ 69 int tria_acceleration;70 68 71 69 /*matice constructor input: */ … … 90 88 int penta_onbed; 91 89 int penta_onsurface; 92 double penta_fit;93 90 double penta_meanvel;/*!scaling ratio for velocities*/ 94 91 double penta_epsvel; /*!minimum velocity to avoid infinite velocity ratios*/ 95 int penta_acceleration;96 92 int penta_collapse; 97 93 double penta_melting[6]; … … 151 147 int grid_id; 152 148 149 /*Get analysis_type: */ 150 analysis_type=AnalysisTypeAsEnum(model->analysis_type); 153 151 154 152 /*First create the elements, nodes and material properties: */ … … 156 154 nodes = new DataSet(NodesEnum()); 157 155 materials = new DataSet(MaterialsEnum()); 158 159 156 160 157 /*Width of elements: */ … … 226 223 ModelFetchData((void**)&model->q,NULL,NULL,model_handle,"q","Matrix","Mat"); 227 224 ModelFetchData((void**)&model->elementoniceshelf,NULL,NULL,model_handle,"elementoniceshelf","Matrix","Mat"); 228 ModelFetchData((void**)&model->fit,NULL,NULL,model_handle,"fit","Matrix","Mat");229 225 ModelFetchData((void**)&model->B,NULL,NULL,model_handle,"B","Matrix","Mat"); 230 226 ModelFetchData((void**)&model->n,NULL,NULL,model_handle,"n","Matrix","Mat"); 231 232 227 233 228 for (i=0;i<model->numberofelements;i++){ … … 275 270 tria_shelf=(int)*(model->elementoniceshelf+i); 276 271 277 /*type of fitting? : */278 tria_fit=model->fit[0];279 272 tria_meanvel=model->meanvel; 280 273 tria_epsvel=model->epsvel; 281 274 282 /*diverse:*/283 tria_acceleration=0;284 285 275 /*Create tria element using its constructor:*/ 286 tria=new Tria(tria_id, tria_mid, tria_mparid, tria_g, tria_h, tria_s, tria_b, tria_k, tria_friction_type, tria_p, tria_q, tria_shelf, tria_ fit, tria_meanvel, tria_epsvel, tria_acceleration);276 tria=new Tria(tria_id, tria_mid, tria_mparid, tria_g, tria_h, tria_s, tria_b, tria_k, tria_friction_type, tria_p, tria_q, tria_shelf, tria_meanvel, tria_epsvel); 287 277 288 278 /*Add tria element to elements dataset: */ … … 333 323 xfree((void**)&model->q); 334 324 xfree((void**)&model->elementoniceshelf); 335 xfree((void**)&model->fit);336 325 xfree((void**)&model->B); 337 326 xfree((void**)&model->n);*/ … … 348 337 ModelFetchData((void**)&model->q,NULL,NULL,model_handle,"q","Matrix","Mat"); 349 338 ModelFetchData((void**)&model->elementoniceshelf,NULL,NULL,model_handle,"elementoniceshelf","Matrix","Mat"); 350 ModelFetchData((void**)&model->fit,NULL,NULL,model_handle,"fit","Matrix","Mat");351 339 ModelFetchData((void**)&model->elementonbed,NULL,NULL,model_handle,"elementonbed","Matrix","Mat"); 352 340 ModelFetchData((void**)&model->elementonsurface,NULL,NULL,model_handle,"elementonsurface","Matrix","Mat"); … … 384 372 /*diverse: */ 385 373 penta_shelf=(int)*(model->elementoniceshelf+i); 386 penta_fit=(int)model->fit[0];387 374 penta_onbed=(int)*(model->elementonbed+i); 388 375 penta_onsurface=(int)*(model->elementonsurface+i); 389 376 penta_meanvel=model->meanvel; 390 377 penta_epsvel=model->epsvel; 391 penta_acceleration=0;392 378 393 379 if (*(model->elements_type+2*i+0)==MacAyealEnum()){ //elements of type 3 are MacAyeal type Penta. We collapse the formulation on their base. … … 401 387 /*Create Penta using its constructor:*/ 402 388 penta= new Penta( penta_id,penta_mid,penta_mparid,penta_g,penta_h,penta_s,penta_b,penta_k,penta_friction_type, 403 penta_p,penta_q,penta_shelf,penta_onbed,penta_onsurface,penta_ fit,penta_meanvel,penta_epsvel,404 penta_ acceleration,penta_collapse,penta_melting,penta_accumulation,penta_geothermalflux,penta_artdiff,389 penta_p,penta_q,penta_shelf,penta_onbed,penta_onsurface,penta_meanvel,penta_epsvel, 390 penta_collapse,penta_melting,penta_accumulation,penta_geothermalflux,penta_artdiff, 405 391 penta_thermal_steadystate); 406 392 … … 446 432 447 433 /*Free data: */ 448 /*xfree((void**)&model->elements);434 xfree((void**)&model->elements); 449 435 xfree((void**)&model->thickness); 450 436 xfree((void**)&model->surface); … … 454 440 xfree((void**)&model->q); 455 441 xfree((void**)&model->elementoniceshelf); 456 xfree((void**)&model->fit);457 442 xfree((void**)&model->elementonbed); 458 443 xfree((void**)&model->elementonsurface); 459 444 xfree((void**)&model->elements_type); 460 445 xfree((void**)&model->n); 461 xfree((void**)&model->B); */446 xfree((void**)&model->B); 462 447 463 448 } //if (strcmp(meshtype,"2d")==0) … … 555 540 ModelFetchData((void**)&model->gridonsurface,NULL,NULL,model_handle,"gridonsurface","Matrix","Mat"); 556 541 557 /*Get analysis_type: */ 558 analysis_type=AnalysisTypeAsEnum(model->analysis_type); 559 542 560 543 /*Get number of dofs per node: */ 561 544 DistributeNumDofs(&node_numdofs,analysis_type); -
issm/trunk/src/c/objects/OptArgs.h
r8 r46 21 21 }; 22 22 #else 23 24 #include "./FemModel.h" 25 #include "./ParameterInputs.h" 26 23 27 struct OptArgs{ 24 28 FemModel* femmodel; 29 double* p_g; 30 double* u_g_obs; 31 double* grad_g; 32 ParameterInputs* inputs; 33 int n; 25 34 }; 26 35 #endif -
issm/trunk/src/c/objects/OptPars.h
r8 r46 16 16 17 17 #endif 18 19 20 -
issm/trunk/src/c/objects/Penta.cpp
r1 r46 19 19 } 20 20 Penta::Penta( int penta_id, int penta_mid, int penta_mparid, int penta_node_ids[6], double penta_h[6], double penta_s[6], double penta_b[6], double penta_k[6], int penta_friction_type, 21 double penta_p, double penta_q, int penta_shelf, int penta_onbed, int penta_onsurface, double penta_ fit, double penta_meanvel,double penta_epsvel,22 int penta_ acceleration, int penta_collapse, double penta_melting[6], double penta_accumulation[6], double penta_geothermalflux[6],21 double penta_p, double penta_q, int penta_shelf, int penta_onbed, int penta_onsurface, double penta_meanvel,double penta_epsvel, 22 int penta_collapse, double penta_melting[6], double penta_accumulation[6], double penta_geothermalflux[6], 23 23 int penta_artdiff, int penta_thermal_steadystate){ 24 24 … … 46 46 onbed = penta_onbed; 47 47 onsurface = penta_onsurface; 48 fit = penta_fit;49 48 meanvel = penta_meanvel; 50 49 epsvel = penta_epsvel; 51 acceleration = penta_acceleration;52 50 collapse = penta_collapse; 53 51 artdiff = penta_artdiff; … … 79 77 printf(" onbed: %i\n",onbed); 80 78 printf(" onsurface: %i\n",onsurface); 81 printf(" fit: %g\n",fit);82 79 printf(" meanvel: %g\n",meanvel); 83 80 printf(" epsvel: %g\n",epsvel); 84 printf(" acceleration: %i\n",acceleration);85 81 printf(" collapse: %i\n",collapse); 86 82 … … 122 118 memcpy(marshalled_dataset,&onbed,sizeof(onbed));marshalled_dataset+=sizeof(onbed); 123 119 memcpy(marshalled_dataset,&onsurface,sizeof(onsurface));marshalled_dataset+=sizeof(onsurface); 124 memcpy(marshalled_dataset,&fit,sizeof(fit));marshalled_dataset+=sizeof(fit);125 120 memcpy(marshalled_dataset,&meanvel,sizeof(meanvel));marshalled_dataset+=sizeof(meanvel); 126 121 memcpy(marshalled_dataset,&epsvel,sizeof(epsvel));marshalled_dataset+=sizeof(epsvel); 127 memcpy(marshalled_dataset,&acceleration,sizeof(acceleration));marshalled_dataset+=sizeof(acceleration);128 122 memcpy(marshalled_dataset,&collapse,sizeof(collapse));marshalled_dataset+=sizeof(collapse); 129 123 memcpy(marshalled_dataset,&melting,sizeof(melting));marshalled_dataset+=sizeof(melting); … … 139 133 int Penta::MarshallSize(){ 140 134 141 return sizeof(id)+sizeof(mid)+sizeof(mparid)+sizeof(node_ids)+sizeof(h)+sizeof(s)+sizeof(b)+sizeof(k)+sizeof(friction_type)+sizeof(p)+sizeof(q)+sizeof(shelf)+sizeof(onbed)+sizeof(onsurface)+sizeof( fit)+sizeof(meanvel)+sizeof(epsvel)+sizeof(acceleration)+sizeof(collapse)+sizeof(melting)+sizeof(accumulation)+sizeof(geothermalflux)+sizeof(artdiff)+sizeof(thermal_steadystate) +sizeof(int); //sizeof(int) for enum type135 return sizeof(id)+sizeof(mid)+sizeof(mparid)+sizeof(node_ids)+sizeof(h)+sizeof(s)+sizeof(b)+sizeof(k)+sizeof(friction_type)+sizeof(p)+sizeof(q)+sizeof(shelf)+sizeof(onbed)+sizeof(onsurface)+sizeof(meanvel)+sizeof(epsvel)+sizeof(collapse)+sizeof(melting)+sizeof(accumulation)+sizeof(geothermalflux)+sizeof(artdiff)+sizeof(thermal_steadystate) +sizeof(int); //sizeof(int) for enum type 142 136 } 143 137 … … 170 164 memcpy(&onbed,marshalled_dataset,sizeof(onbed));marshalled_dataset+=sizeof(onbed); 171 165 memcpy(&onsurface,marshalled_dataset,sizeof(onsurface));marshalled_dataset+=sizeof(onsurface); 172 memcpy(&fit,marshalled_dataset,sizeof(fit));marshalled_dataset+=sizeof(fit);173 166 memcpy(&meanvel,marshalled_dataset,sizeof(meanvel));marshalled_dataset+=sizeof(meanvel); 174 167 memcpy(&epsvel,marshalled_dataset,sizeof(epsvel));marshalled_dataset+=sizeof(epsvel); 175 memcpy(&acceleration,marshalled_dataset,sizeof(acceleration));marshalled_dataset+=sizeof(acceleration);176 168 memcpy(&collapse,marshalled_dataset,sizeof(collapse));marshalled_dataset+=sizeof(collapse); 177 169 memcpy(&melting,marshalled_dataset,sizeof(melting));marshalled_dataset+=sizeof(melting); -
issm/trunk/src/c/objects/Penta.h
r1 r46 42 42 int onbed; 43 43 int onsurface; 44 double fit;45 44 double meanvel;/*!scaling ratio for velocities*/ 46 45 double epsvel; /*!minimum velocity to avoid infinite velocity ratios*/ 47 int acceleration;48 46 int collapse; 49 47 double melting[6]; … … 58 56 Penta(); 59 57 Penta( int id, int mid, int mparid, int g[6], double h[6], double s[6], double b[6], double k[6], int friction_type, 60 double p, double q, int shelf, int onbed, int onsurface, double fit, doublemeanvel,double epsvel,61 int acceleration, intcollapse, double melting[6], double accumulation[6], double geothermalflux[6],58 double p, double q, int shelf, int onbed, int onsurface, double meanvel,double epsvel, 59 int collapse, double melting[6], double accumulation[6], double geothermalflux[6], 62 60 int artdiff, int thermal_steadystate); 63 61 ~Penta(); -
issm/trunk/src/c/objects/Tria.cpp
r1 r46 33 33 34 34 Tria::Tria(int tria_id,int tria_mid,int tria_mparid,int tria_node_ids[3],double tria_h[3],double tria_s[3],double tria_b[3],double tria_k[3], 35 int tria_friction_type,double tria_p,double tria_q,int tria_shelf,double tria_ fit,double tria_meanvel,double tria_epsvel,int tria_acceleration){35 int tria_friction_type,double tria_p,double tria_q,int tria_shelf,double tria_meanvel,double tria_epsvel){ 36 36 37 37 int i; … … 57 57 q=tria_q; 58 58 shelf=tria_shelf; 59 fit=tria_fit;60 59 meanvel=tria_meanvel; 61 60 epsvel=tria_epsvel; 62 acceleration=tria_acceleration;63 61 onbed=1; 64 62 … … 87 85 printf(" q: %g\n",q); 88 86 printf(" shelf: %i\n",shelf); 89 printf(" fit: %g\n",fit);90 87 printf(" meanvel: %g\n",meanvel); 91 88 printf(" epsvel: %g\n",epsvel); 92 printf(" acceleration: %i\n",acceleration);93 89 printf(" onbed: %i\n",onbed); 94 90 printf(" nodes: \n"); … … 136 132 memcpy(marshalled_dataset,&q,sizeof(q));marshalled_dataset+=sizeof(q); 137 133 memcpy(marshalled_dataset,&shelf,sizeof(shelf));marshalled_dataset+=sizeof(shelf); 138 memcpy(marshalled_dataset,&fit,sizeof(fit));marshalled_dataset+=sizeof(fit);139 134 memcpy(marshalled_dataset,&meanvel,sizeof(meanvel));marshalled_dataset+=sizeof(meanvel); 140 135 memcpy(marshalled_dataset,&epsvel,sizeof(epsvel));marshalled_dataset+=sizeof(epsvel); 141 memcpy(marshalled_dataset,&acceleration,sizeof(acceleration));marshalled_dataset+=sizeof(acceleration);142 136 143 137 *pmarshalled_dataset=marshalled_dataset; … … 165 159 +sizeof(q) 166 160 +sizeof(shelf) 167 +sizeof(fit)168 161 +sizeof(meanvel) 169 162 +sizeof(epsvel) 170 +sizeof(acceleration)171 163 +sizeof(int); //sizeof(int) for enum type 172 164 } … … 206 198 memcpy(&q,marshalled_dataset,sizeof(q));marshalled_dataset+=sizeof(q); 207 199 memcpy(&shelf,marshalled_dataset,sizeof(shelf));marshalled_dataset+=sizeof(shelf); 208 memcpy(&fit,marshalled_dataset,sizeof(fit));marshalled_dataset+=sizeof(fit);209 200 memcpy(&meanvel,marshalled_dataset,sizeof(meanvel));marshalled_dataset+=sizeof(meanvel); 210 201 memcpy(&epsvel,marshalled_dataset,sizeof(epsvel));marshalled_dataset+=sizeof(epsvel); 211 memcpy(&acceleration,marshalled_dataset,sizeof(acceleration));marshalled_dataset+=sizeof(acceleration);212 202 213 203 /*nodes and materials are not pointing to correct objects anymore:*/ … … 338 328 double MOUNTAINKEXPONENT=10; 339 329 340 341 /*First check that acceleration is not on: */342 if (acceleration){343 /*do nothing: */344 return;345 }346 330 347 331 /*recover extra inputs from users, at current convergence iteration: */ … … 650 634 double thickness; 651 635 652 /*First check that acceleration is not on: */653 if (acceleration){654 return;655 }656 657 636 /* Get node coordinates and dof list: */ 658 637 GetElementNodeData( &xyz_list[0][0], nodes, numgrids); … … 1313 1292 fit=*fit_param; 1314 1293 } 1294 else throw ErrorException(__FUNCT__," missing fit input parameter"); 1315 1295 1316 1296 /*Initialize velocities: */ … … 1844 1824 fit=*fit_param; 1845 1825 } 1826 else ErrorException(__FUNCT__," missing fit input parameter"); 1846 1827 1847 1828 /*Initialize velocities: */ -
issm/trunk/src/c/objects/Tria.h
r1 r46 40 40 double q; 41 41 int shelf; 42 double fit;43 42 double meanvel;/*!scaling ratio for velocities*/ 44 43 double epsvel; /*!minimum velocity to avoid infinite velocity ratios*/ 45 int acceleration;46 44 int onbed; 47 45 … … 50 48 Tria(); 51 49 Tria(int id,int mid,int mparid,int node_ids[3],double h[3],double s[3],double b[3],double k[3], 52 int friction_type,double p,double q,int shelf,double fit,double meanvel,double epsvel,int acceleration);50 int friction_type,double p,double q,int shelf,double meanvel,double epsvel); 53 51 ~Tria(); 54 52 -
issm/trunk/src/c/parallel/CreateFemModel.cpp
r1 r46 68 68 ConfigureObjectsx(elements, loads, nodes, materials); 69 69 70 _printf_(" process parameters:\n"); 71 ProcessParamsx( parameters, partition); 72 70 73 _printf_(" free ressources:\n"); 71 74 DeleteModel(&model); … … 86 89 femmodel->ys=ys; 87 90 femmodel->ys0=ys0; 91 88 92 89 93 } -
issm/trunk/src/c/parallel/OutputDiagnostic.cpp
r1 r46 13 13 void OutputDiagnostic(Vec u_g,Vec partition,char* filename,NodeSets* nodesets,char* analysis_type){ 14 14 15 /* error handling: */16 15 int i; 17 18 16 extern int my_rank; 19 17 … … 23 21 /* standard output: */ 24 22 double* serial_partition=NULL; 25 int serial_partition_rows;26 23 int analysis_size; 27 24 28 25 double* serial_u_g=NULL; 29 int serial_u_g_rows; 30 int dummy=1; 26 int one=1; 31 27 int gsize; 32 28 33 29 /*serialize outputs: */ 34 30 VecShift(partition,1.0); //matlab indexing 35 VecGetSize(partition,&serial_partition_rows);36 31 VecToMPISerial(&serial_partition,partition); 37 32 38 VecGetSize(u_g,&serial_u_g_rows);39 33 VecToMPISerial(&serial_u_g,u_g); 40 34 … … 52 46 53 47 /*Write partition: */ 54 WriteDataToDisk(serial_partition,& serial_partition_rows,&dummy,"Mat",fid);48 WriteDataToDisk(serial_partition,&one,&one,"Mat",fid); 55 49 56 50 /*Write solution to disk: */ 57 WriteDataToDisk(serial_u_g,& serial_u_g_rows,&dummy,"Mat",fid);51 WriteDataToDisk(serial_u_g,&gsize,&one,"Mat",fid); 58 52 59 53 /*Close file: */ -
issm/trunk/src/c/parallel/control.cpp
r1 r46 1 /* 2 * cielocontrol.c:3 */ 1 /*!\file: control.cpp 2 * \brief: control solution 3 */ 4 4 5 #include "../include/cielo.h" 6 #include "../modules.h" 5 #include "../issm.h" 7 6 #include "./parallel.h" 8 7 9 8 #undef __FUNCT__ 10 #define __FUNCT__ "cielocontrol" 9 #define __FUNCT__ "control" 10 11 #ifdef HAVE_CONFIG_H 12 #include "config.h" 13 #else 14 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 15 #endif 11 16 12 17 int main(int argc,char* *argv){ 13 14 int i,n; 15 18 19 int n; 20 int i; 21 16 22 /*I/O: */ 17 23 FILE* fid=NULL; … … 21 27 char* analysis_type="control"; 22 28 23 /*Finite element model: */ 24 #if defined(_PARALLEL_) && defined(_HAVE_PETSC_) 29 /*Intermediary: */ 25 30 FemModel femmodel; 31 Vec u_g=NULL; 32 ParameterInputs* inputs=NULL; 33 int waitonlock=0; 34 double search_scalar; 35 char* control_type=NULL; 36 int gsize; 37 double* fit=NULL; 38 double* optscal=NULL; 39 double* u_g_obs=NULL; 40 int* maxiter=NULL; 41 double tolx; 42 double* p_g=NULL; 43 Vec grad_g=NULL; 44 Vec new_grad_g=NULL; 45 Vec grad_g_old=NULL; 46 double* grad_g_double=NULL; 47 double mincontrolconstraint; 48 double maxcontrolconstraint; 49 int nsteps; 50 double* J=NULL; 51 OptArgs optargs; 52 OptPars optpars; 53 54 55 MODULEBOOT(); 56 57 #if !defined(_PARALLEL_) || (defined(_PARALLEL_) && !defined(_HAVE_PETSC_)) 58 throw ErrorException(__FUNCT__," parallel executable was compiled without support of parallel libraries!"); 26 59 #endif 27 60 28 /*control : */ 29 #if defined(_PARALLEL_) && defined(_HAVE_PETSC_) 30 Vec* u_g=NULL; 31 #endif 32 double* search_vector=NULL; 33 int status; 34 ParameterInputs* inputs=NULL; 35 int reloop; 61 PetscInitialize(&argc,&argv,(char *)0,""); 62 63 /*Size and rank: */ 64 MPI_Comm_rank(MPI_COMM_WORLD,&my_rank); 65 MPI_Comm_size(MPI_COMM_WORLD,&num_procs); 66 67 _printf_("recover , input file name and output file name:\n"); 68 inputfilename=argv[2]; 69 outputfilename=argv[3]; 70 lockname=argv[4]; 71 72 /*Open handle to data on disk: */ 73 fid=fopen(inputfilename,"rb"); 74 if(fid==NULL) throw ErrorException(__FUNCT__,exprintf("%s%s%s","could not open file ",inputfilename," for binary reading")); 36 75 37 #if !defined(_PARALLEL_) || (defined(_PARALLEL_) && !defined(_HAVE_PETSC_)) 38 _printf_("%s%s\n",__FUNCT__," error message: parallel executable was compiled without support of parallel libraries!"); 39 return 1; 40 #else 76 _printf_("read and create finite element model:\n"); 77 CreateFemModel(&femmodel,fid,analysis_type); 78 79 /*Recover parameters used throughout the solution:*/ 80 femmodel.parameters->FindParam((void*)&nsteps,"nsteps"); 81 femmodel.parameters->FindParam((void*)&control_type,"control_type"); 82 femmodel.parameters->FindParam((void*)&fit,"fit"); 83 femmodel.parameters->FindParam((void*)&optscal,"optscal"); 84 femmodel.parameters->FindParam((void*)&maxiter,"maxiter"); 85 femmodel.parameters->FindParam((void*)&tolx,"tolx"); 86 femmodel.parameters->FindParam((void*)&waitonlock,"waitonlock"); 87 femmodel.parameters->FindParam((void*)&mincontrolconstraint,"mincontrolconstraint"); 88 femmodel.parameters->FindParam((void*)&maxcontrolconstraint,"maxcontrolconstraint"); 89 gsize=femmodel.nodes->NumberOfDofs(); 41 90 42 /*Initialize MPI environment: */43 PetscInitialize(&argc,&argv,(char *)0,"");91 femmodel.parameters->FindParam((void*)&p_g,"p_g"); 92 femmodel.parameters->FindParam((void*)&u_g_obs,"u_g_obs"); 44 93 45 /*Size and rank: */46 MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);47 MPI_Comm_size(MPI_COMM_WORLD,&num_procs);48 94 49 /*Some checks on size of cluster*/ 50 if (num_procs<=1){ 51 _printf_("\nSize of MPI COMM WORLD is 1, needs to be at least 2. Include more nodes\n"); 52 PetscFinalize(); 53 return 0; 95 /*Start looping: */ 96 for(n=0;n<nsteps;n++){ 97 98 _printf_("\n%s%i%s%i\n"," control method step ",n+1,"/",nsteps); 99 100 //initialize inputs, ie parameters on which we invert. 101 DeleteParameterInputs(&inputs); inputs=NewParameterInputs(); 102 ParameterInputsAddFromMat(inputs,p_g,gsize,control_type); 103 ParameterInputsAddFromDouble(inputs,fit[n],"fit"); 104 105 _printf_("%s\n"," computing gradJ..."); 106 grad_g=GradJCompute(inputs,&femmodel,u_g_obs); 107 _printf_("%s\n"," done."); 108 109 110 _printf_("%s\n"," normalizing directions..."); 111 Orthx(&new_grad_g,grad_g,grad_g_old); 112 VecFree(&grad_g); grad_g=new_grad_g; 113 VecFree(&grad_g_old); grad_g_old=grad_g; 114 VecToMPISerial(&grad_g_double,grad_g); 115 _printf_("%s\n"," done."); 116 117 118 _printf_("%s\n"," optimizing along gradient direction..."); 119 optargs.femmodel=&femmodel; optargs.p_g=p_g; optargs.u_g_obs=u_g_obs; optargs.grad_g=grad_g_double; optargs.inputs=inputs;optargs.n=n; 120 optpars.xmin=-1; optpars.xmax=1; optpars.tolerance=tolx; optpars.maxiter=maxiter[n]; 121 BrentSearch(&search_scalar,J+n,&optpars,&objectivefunctionC,&optargs); 122 _printf_("%s\n"," done."); 123 124 125 126 _printf_("%s\n"," updating parameter using optimized search scalar..."); 127 for(i=0;i<gsize;i++)p_g[i]=p_g[i]+search_scalar*optscal[n]*grad_g_double[i]; 128 _printf_("%s\n"," done."); 129 130 _printf_("%s\n"," constraining the new distribution..."); 131 ControlConstrainx( p_g,gsize,mincontrolconstraint,maxcontrolconstraint,control_type); 132 _printf_("%s\n"," done."); 133 134 //some temporary saving 135 if ((n%5)==0){ 136 _printf_("%s\n"," saving temporary results..."); 137 OutputControl(u_g,p_g,J,nsteps,femmodel.partition,outputfilename,femmodel.nodesets); 138 _printf_("%s\n"," done."); 54 139 } 55 140 56 /*Recover dbdir, input file name and output file name: */57 dbdir=argv[1];58 inputfilename=argv[2];59 outputfilename=argv[3];60 lockname=argv[4];141 _printf_("%s\n"," value of misfit J after optimization #",n,": ",J[n]); 142 143 /*some freeing:*/ 144 xfree((void**)&grad_g_double); 145 } 61 146 62 /*Open handle to data on disk: */ 63 fid=fopen(inputfilename,"rb"); 64 if(fid==NULL){ 65 _printf_("%s%s\n",__FUNCT__," error message: could not open file ",inputfilename," for binary reading"); 66 return 0; 67 } 147 /*Write results to disk: */ 148 _printf_("%s\n"," preparing final velocity solution..."); 149 DeleteParameterInputs(&inputs); inputs=NewParameterInputs(); 150 ParameterInputsAddFromMat(inputs,p_g,gsize,control_type); 151 ParameterInputsAddFromDouble(inputs,fit[n],"fit"); 152 153 diagnostic_core_nonlinear(&u_g,NULL,NULL,inputs,&femmodel); 154 155 _printf_("%s\n"," saving final results..."); 156 OutputControl(u_g,p_g,J,nsteps,femmodel.partition,outputfilename,femmodel.nodesets); 157 _printf_("%s\n"," done."); 68 158 69 /*Read and create finite element model: */ 70 if(!CreateFemModel(&femmodel,fid,analysis_type)){ 71 _printf_("%s\n",__FUNCT__," error message: could not read finite element model!\n"); 72 return 0; 73 } 159 /*Write lock file if requested: */ 160 if (waitonlock){ 161 WriteLockFile(lockname); 162 } 163 164 _printf_("closing MPI and Petsc\n"); 165 MPI_Barrier(MPI_COMM_WORLD); 74 166 75 /*Initialize inputs: */ 76 inputs=NewParameterInputs(); 77 78 /*For now, only one parameter is allowed: */ 79 if (femmodel.workspaceparams->num_control_parameters>1){ 80 _printf_("%s%s\n",__FUNCT__," error message: multiple control parameters not implemented yet!"); 81 PetscFinalize(); 82 return 1; 83 } 84 85 /*Initialize search vector: */ 86 search_vector=xmalloc(femmodel.workspaceparams->num_control_parameters*sizeof(double)); 87 88 /*Start looping: */ 89 for(n=0;n<femmodel.workspaceparams->nsteps;n++){ 90 91 _printf_("\n%s%i%s%i\n"," control method step ",(n+1),"/",femmodel.workspaceparams->nsteps); 92 93 //initialize inputs, ie parameters on which we invert. 94 DeleteParameterInputs(&inputs); inputs=NewParameterInputs(); 95 96 for(i=0;i<femmodel.workspaceparams->num_control_parameters;i++){ 97 char* control_type=femmodel.workspaceparams->control_types[i]; 98 ParameterInputsAddFromMat(inputs,WorkspaceParamsGetParameter(femmodel.workspaceparams,control_type),femmodel.workspaceparams->gsize,control_type); 99 } 100 ParameterInputsAddFromDouble(inputs,femmodel.workspaceparams->fit[n],"fit"); 101 102 //update velocity: 103 _printf_("%s\n"," updating velocity..."); 104 VecFree(&u_g); cielodiagnostic_core_nonlinear(&u_g,NULL,NULL,inputs,&femmodel); 105 _printf_("%s\n"," done."); 106 107 //call gradJ module 108 _printf_("%s\n"," computing gradJ..."); 109 GradJCompute(inputs,&femmodel); 110 _printf_("%s\n"," done."); 111 112 //normalize directions 113 _printf_("%s\n"," normalizing directions..."); 114 GradJOrth(femmodel.workspaceparams); 115 _printf_("%s\n"," done."); 167 /*Close MPI libraries: */ 168 PetscFinalize(); 116 169 117 170 118 //search along the direction for the parameter vector that minimizes the misfit J 119 _printf_("%s\n"," optimizing..."); 120 status=GradJSearch(search_vector,&femmodel,n); 121 _printf_("%s\n"," done."); 122 123 _printf_("%s%g\n"," misfit: ",femmodel.workspaceparams->J[n]); 124 125 //Check the GradJSearch actually resulting in improving the misfit. Otherwise, reloop. 126 reloop=GradJCheck(femmodel.workspaceparams,n,status); 127 if (reloop){ 128 printf("reloop\n",reloop); 129 n=n-1; 130 continue; 131 } 132 133 //update parameters with new optimized values 134 _printf_("%s\n"," updating parameters..."); 135 ParameterUpdate(search_vector,n,femmodel.workspaceparams,femmodel.batchparams); 136 _printf_("%s\n"," done."); 137 138 //temporary saving 139 if ((n%1)==0){ 140 _printf_("%s\n"," saving temporary results..."); 141 OutputControl(femmodel.workspaceparams,femmodel.batchparams,u_g,femmodel.tpartition,outputfilename,"control"); 142 _printf_("%s\n"," done."); 143 } 144 145 } 146 147 /*Write results to disk: */ 148 _printf_("%s\n"," saving final results..."); 149 OutputControl(femmodel.workspaceparams,femmodel.batchparams,u_g,femmodel.tpartition,outputfilename,"control"); 150 _printf_("%s\n"," done."); 151 152 /*Write lock file if requested: */ 153 if (femmodel.batchparams->waitonlock){ 154 WriteLockFile(lockname); 155 } 156 157 cleanup_and_return: 158 _printf_("exiting.\n"); 159 160 /*Synchronize everyone before exiting: */ 161 MPI_Barrier(MPI_COMM_WORLD); 162 163 /*Close MPI libraries: */ 164 PetscFinalize(); 165 166 return 0; //unix success return; 167 #endif 171 /*end module: */ 172 MODULEEND(); 173 174 return 0; //unix success return; 168 175 } -
issm/trunk/src/c/parallel/diagnostic.cpp
r1 r46 59 59 60 60 _printf_("call computational core:\n"); 61 diagnostic_core_nonlinear(&u_g,NULL,NULL,inputs, femmodel);61 diagnostic_core_nonlinear(&u_g,NULL,NULL,inputs,&femmodel); 62 62 63 63 _printf_("write results to disk:\n"); -
issm/trunk/src/c/parallel/diagnostic_core_nonlinear.cpp
r1 r46 11 11 #include "../issm.h" 12 12 13 void diagnostic_core_nonlinear(Vec* pug,Mat* pKff0,Mat* pKfs0, ParameterInputs* inputs,FemModel fem){13 void diagnostic_core_nonlinear(Vec* pug,Mat* pKff0,Mat* pKfs0, ParameterInputs* inputs,FemModel* fem){ 14 14 15 15 … … 45 45 /*Recover parameters: */ 46 46 kflag=1; pflag=1; 47 fem .parameters->FindParam((void*)&connectivity,"connectivity");48 fem .parameters->FindParam((void*)&numberofdofspernode,"numberofdofspernode");49 fem .parameters->FindParam((void*)&solver_string,"solverstring");50 fem .parameters->FindParam((void*)&eps_rel,"eps_rel");51 fem .parameters->FindParam((void*)&debug,"debug");47 fem->parameters->FindParam((void*)&connectivity,"connectivity"); 48 fem->parameters->FindParam((void*)&numberofdofspernode,"numberofdofspernode"); 49 fem->parameters->FindParam((void*)&solver_string,"solverstring"); 50 fem->parameters->FindParam((void*)&eps_rel,"eps_rel"); 51 fem->parameters->FindParam((void*)&debug,"debug"); 52 52 53 fem .parameters->FindParam((void*)&analysis_type_string,"analysis_type");53 fem->parameters->FindParam((void*)&analysis_type_string,"analysis_type"); 54 54 analysis_type=AnalysisTypeAsEnum(analysis_type_string); 55 55 56 56 /*Copy loads for backup: */ 57 loads=fem .loads->Copy();57 loads=fem->loads->Copy(); 58 58 59 59 count=1; … … 71 71 72 72 /*Update parameters: */ 73 UpdateFromInputsx(fem .elements,fem.nodes,loads, fem.materials,inputs);73 UpdateFromInputsx(fem->elements,fem->nodes,loads, fem->materials,inputs); 74 74 75 75 if (debug) _printf_(" Generating matrices\n"); 76 76 //*Generate system matrices 77 SystemMatricesx(&Kgg, &pg,fem .elements,fem.nodes,loads,fem.materials,kflag,pflag,connectivity,numberofdofspernode,inputs,analysis_type);77 SystemMatricesx(&Kgg, &pg,fem->elements,fem->nodes,loads,fem->materials,kflag,pflag,connectivity,numberofdofspernode,inputs,analysis_type); 78 78 79 79 if (debug) _printf_(" Generating penalty matrices\n"); 80 80 //*Generate penalty system matrices 81 PenaltySystemMatricesx(Kgg, pg,fem .elements,fem.nodes,loads,fem.materials,kflag,pflag,inputs,analysis_type);81 PenaltySystemMatricesx(Kgg, pg,fem->elements,fem->nodes,loads,fem->materials,kflag,pflag,inputs,analysis_type); 82 82 83 83 if (debug) _printf_(" reducing matrix from g to f set\n"); 84 84 /*!Reduce matrix from g to f size:*/ 85 Reducematrixfromgtofx(&Kff,&Kfs,Kgg,fem .Gmn,fem.nodesets);85 Reducematrixfromgtofx(&Kff,&Kfs,Kgg,fem->Gmn,fem->nodesets); 86 86 87 87 /*Free ressources: */ … … 90 90 if (debug) _printf_(" reducing load from g to f set\n"); 91 91 /*!Reduce load from g to f size: */ 92 Reduceloadfromgtofx(&pf, pg, fem .Gmn, Kfs, fem.ys, fem.nodesets);92 Reduceloadfromgtofx(&pf, pg, fem->Gmn, Kfs, fem->ys, fem->nodesets); 93 93 94 94 //no need for pg and Kfs anymore … … 106 106 if (debug) _printf_(" merging solution from f to g set\n"); 107 107 //Merge back to g set 108 Mergesolutionfromftogx(&ug, uf,fem .Gmn,fem.ys,fem.nodesets);108 Mergesolutionfromftogx(&ug, uf,fem->Gmn,fem->ys,fem->nodesets); 109 109 110 110 //Deal with penalty loads … … 112 112 ParameterInputsAddFromVec(inputs,ug,"velocity"); 113 113 114 PenaltyConstraintsx(&constraints_converged, &num_unstable_constraints, fem .elements,fem.nodes,loads,fem.materials,inputs,analysis_type);114 PenaltyConstraintsx(&constraints_converged, &num_unstable_constraints, fem->elements,fem->nodes,loads,fem->materials,inputs,analysis_type); 115 115 116 116 //Figure out if convergence is reached. … … 143 143 kflag=1; pflag=0; //stiffness generation only 144 144 145 SystemMatricesx(&Kgg, &pg,fem .elements,fem.nodes,fem.loads,fem.materials,kflag,pflag,connectivity,numberofdofspernode,inputs,analysis_type);145 SystemMatricesx(&Kgg, &pg,fem->elements,fem->nodes,fem->loads,fem->materials,kflag,pflag,connectivity,numberofdofspernode,inputs,analysis_type); 146 146 147 Reducematrixfromgtofx(&Kff,&Kfs,Kgg,fem .Gmn,fem.nodesets);147 Reducematrixfromgtofx(&Kff,&Kfs,Kgg,fem->Gmn,fem->nodesets); 148 148 149 149 MatFree(&Kgg);VecFree(&pg); -
issm/trunk/src/c/parallel/parallel.h
r1 r46 8 8 #include "../objects/objects.h" 9 9 10 int GradJCompute(ParameterInputs* inputs,FemModel* femmodel);10 Vec GradJCompute(ParameterInputs* inputs,FemModel* femmodel,double* u_g_obs); 11 11 12 void diagnostic_core_nonlinear(Vec* pug,Mat* pK_ff0,Mat* pK_fs0, ParameterInputs* inputs,FemModel fem);12 void diagnostic_core_nonlinear(Vec* pug,Mat* pK_ff0,Mat* pK_fs0, ParameterInputs* inputs,FemModel* fem); 13 13 int cielothermal_core(Vec** pt_g,ParameterInputs* inputs,FemModel* femmodel); 14 14 … … 19 19 int BrentSearch(double* psearch_scalar,double* pJ,double xa, double xb, double tolerance, int maxiter, double fit,double optscal,double (*f)(double*,double,double,FemModel*,ParameterInputs*),FemModel* femmodel); 20 20 21 double objectivefunctionC(double * search_vector,double fit,double optscal,FemModel* femmodel,ParameterInputs* inputs);21 double objectivefunctionC(double search_scalar,OptArgs* optargs); 22 22 23 23 int GradJSearch(double* search_vector,FemModel* femmodel,int step); … … 27 27 void OutputDiagnostic(Vec u_g,Vec tpartition,char* filename,NodeSets* nodesets,char* analysis_type); 28 28 int OutputThermal(Vec* t_g,Vec* tpartition,char* filename,char* analysis_type); 29 //int OutputControl(WorkspaceParams* workspaceparams,BatchParams* batchparams,Vec* u_g,Vec* tpartition, char* filename,char* analysis_type);29 void OutputControl(Vec u_g,double* p_g, double* J, int nsteps, Vec partition,char* filename,NodeSets* nodesets); 30 30 void WriteLockFile(char* filename); 31 31
Note:
See TracChangeset
for help on using the changeset viewer.