Changeset 9362 for issm/trunk/src/c/objects/IoModel.cpp
- Timestamp:
- 08/19/11 20:01:40 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/objects/IoModel.cpp
r9356 r9362 12 12 #include <string.h> 13 13 #include <stdio.h> 14 #include <stdlib.h> 15 #include <stdarg.h> 16 14 17 #include "./objects.h" 15 18 #include "./Container/Parameters.h" … … 21 24 IoModel::IoModel(){ 22 25 this->fid=NULL; 23 this->parameters=NULL; 24 } 25 /*}}}*/ 26 /*FUNCTION IoModel::IoModel(FILE* iomodel_handle){{{1*/ 27 IoModel::IoModel(FILE* iomodel_handle){ 28 29 int i,j; 30 31 /*First, keep track of the file handle: */ 32 this->fid=iomodel_handle; 33 34 /*Initialize and read parameters:*/ 35 this->parameters=new Parameters(); 36 this->FetchParameters(this->parameters); /*this routine goes through the input file, and fetches bools, ints, doubles and strings only, nothing memory intensive*/ 37 38 /*Initialize the structure: */ 39 this->IoModelInit(); 40 41 } 42 /*}}}*/ 43 /*FUNCTION IoModel::~IoModel(){{{1*/ 44 IoModel::~IoModel(){ 45 46 int i; 47 48 /*!Two cases here: 49 * - serial mode: matlab's memory manager will take care of delete iomodel when returning from Imp. Do nothing here, so as not to confuse 50 * the memory manager. 51 * - in parallel, anything the io layer does (FetchData) did needs to be erased explicitely in the iomodel. 52 */ 53 54 #ifdef _PARALLEL_ 55 xfree((void**)&this->x); 56 xfree((void**)&this->y); 57 xfree((void**)&this->z); 58 xfree((void**)&this->elements); 59 xfree((void**)&this->elementconnectivity); 60 xfree((void**)&this->elements_type); 61 xfree((void**)&this->vertices_type); 62 xfree((void**)&this->nodeonhutter); 63 xfree((void**)&this->nodeonmacayeal); 64 xfree((void**)&this->elements2d); 65 xfree((void**)&this->upperelements); 66 xfree((void**)&this->lowerelements); 67 xfree((void**)&this->nodeonpattyn); 68 xfree((void**)&this->elementonbed); 69 xfree((void**)&this->elementonsurface); 70 xfree((void**)&this->nodeonbed); 71 xfree((void**)&this->nodeonsurface); 72 xfree((void**)&this->nodeonstokes); 73 xfree((void**)&this->borderstokes); 74 xfree((void**)&this->thickness_obs); 75 xfree((void**)&this->thickness_coeff); 76 xfree((void**)&this->thickness); 77 xfree((void**)&this->surface); 78 xfree((void**)&this->bed); 79 xfree((void**)&this->bathymetry); 80 xfree((void**)&this->vx_obs); 81 xfree((void**)&this->vy_obs); 82 xfree((void**)&this->vz_obs); 83 xfree((void**)&this->vx); 84 xfree((void**)&this->vy); 85 xfree((void**)&this->vz); 86 xfree((void**)&this->pressure); 87 xfree((void**)&this->temperature); 88 xfree((void**)&this->waterfraction); 89 xfree((void**)&this->drag_coefficient); 90 xfree((void**)&this->drag_p); 91 xfree((void**)&this->drag_q); 92 xfree((void**)&this->elementoniceshelf); 93 xfree((void**)&this->elementonwater); 94 xfree((void**)&this->nodeonicesheet); 95 xfree((void**)&this->nodeoniceshelf); 96 xfree((void**)&this->nodeonwater); 97 xfree((void**)&this->pressureload); 98 xfree((void**)&this->spcvx); 99 xfree((void**)&this->spcvy); 100 xfree((void**)&this->spcvz); 101 xfree((void**)&this->spcthickness); 102 xfree((void**)&this->spcwatercolumn); 103 xfree((void**)&this->spctemperature); 104 xfree((void**)&this->diagnostic_ref); 105 xfree((void**)&this->edges); 106 xfree((void**)&this->geothermalflux); 107 xfree((void**)&this->basal_melting_rate); 108 xfree((void**)&this->watercolumn); 109 xfree((void**)&this->basal_melting_rate_correction); 110 xfree((void**)&this->surface_accumulation_rate); 111 xfree((void**)&this->surface_ablation_rate); 112 xfree((void**)&this->surface_mass_balance); 113 xfree((void**)&this->dhdt); 114 xfree((void**)&this->rheology_B); 115 xfree((void**)&this->rheology_n); 116 xfree((void**)&this->control_type); 117 xfree((void**)&this->cm_responses); 118 xfree((void**)&this->weights); 119 xfree((void**)&this->cm_jump); 120 xfree((void**)&this->cm_min); 121 xfree((void**)&this->cm_max); 122 xfree((void**)&this->optscal); 123 xfree((void**)&this->maxiter); 124 125 126 /*!Delete structure fields: */ 127 xfree((void**)&this->riftinfo); 128 xfree((void**)&this->penalties); 129 130 /*exterior data: */ 131 xfree((void**)&this->my_elements); 132 xfree((void**)&this->my_vertices); 133 xfree((void**)&this->my_nodes); 134 xfree((void**)&this->singlenodetoelementconnectivity); 135 xfree((void**)&this->numbernodetoelementconnectivity); 136 #endif 137 } 138 /*}}}*/ 139 /*FUNCTION IoModel::IoModelInit{{{1*/ 140 void IoModel::IoModelInit(void){ 141 142 /*exterior data: */ 26 this->constants=NULL; 27 28 this->my_elements=NULL; 29 this->my_nodes=NULL; 30 this->my_vertices=NULL; 31 this->singlenodetoelementconnectivity=NULL; 32 this->numbernodetoelementconnectivity=NULL; 33 143 34 this->nodecounter=0; 144 35 this->loadcounter=0; 145 36 this->constraintcounter=0; 146 147 /*!initialize all pointers to 0: */ 148 this->x=NULL; 149 this->y=NULL; 150 this->z=NULL; 151 this->elements=NULL; 152 this->elementconnectivity=NULL; 153 this->elements_type=NULL; 154 this->vertices_type=NULL; 155 this->elements2d=NULL; 156 this->upperelements=NULL; 157 this->lowerelements=NULL; 158 this->nodeonhutter=NULL; 159 this->nodeonmacayeal=NULL; 160 this->nodeonpattyn=NULL; 161 162 this->vx_obs=NULL; 163 this->vy_obs=NULL; 164 this->vz_obs=NULL; 165 this->vx=NULL; 166 this->vy=NULL; 167 this->vz=NULL; 168 this->pressure=NULL; 169 this->temperature=NULL; 170 this->waterfraction=NULL; 171 this->basal_melting_rate=NULL; 172 this->watercolumn=NULL; 173 this->basal_melting_rate_correction=NULL; 174 this->geothermalflux=NULL; 175 this->elementonbed=NULL; 176 this->elementonsurface=NULL; 177 this->nodeonbed=NULL; 178 this->nodeonsurface=NULL; 179 this->nodeonstokes=NULL; 180 this->borderstokes=NULL; 181 this->thickness_obs=NULL; 182 this->thickness_coeff=NULL; 183 this->thickness=NULL; 184 this->surface=NULL; 185 this->bed=NULL; 186 this->bathymetry=NULL; 187 this->elementoniceshelf=NULL; 188 this->elementonwater=NULL; 189 this->nodeonicesheet=NULL; 190 this->nodeoniceshelf=NULL; 191 this->nodeonwater=NULL; 192 193 this->drag_coefficient=NULL; 194 this->drag_p=NULL; 195 this->drag_q=NULL; 196 197 198 this->pressureload=NULL; 199 this-> spcvx=NULL; 200 this-> spcvy=NULL; 201 this-> spcvz=NULL; 202 this-> spctemperature=NULL; 203 this-> spcthickness=NULL; 204 this-> spcwatercolumn=NULL; 205 this-> diagnostic_ref=NULL; 206 this->edges=NULL; 207 208 /*!materials: */ 209 this->rheology_n=NULL; 210 this->rheology_B=NULL; 211 212 /*!solution parameters: */ 213 this->control_type=NULL; 214 this->cm_responses=NULL; 215 this->weights=NULL; 216 this->cm_jump=NULL; 217 this->maxiter=NULL; 218 this->cm_min=NULL; 219 this->cm_max=NULL; 220 this->optscal=NULL; 221 222 this->riftinfo=NULL; 223 224 /*!penalties: */ 225 this->penalties=NULL; 226 227 /*!surface: */ 228 this->surface_mass_balance=NULL; 229 this->surface_accumulation_rate=NULL; 230 this->surface_ablation_rate=NULL; 231 this->dhdt=NULL; 232 233 /*exterior data: */ 37 38 } 39 /*}}}*/ 40 /*FUNCTION IoModel::IoModel(FILE* iomodel_handle){{{1*/ 41 IoModel::IoModel(FILE* iomodel_handle){ 42 43 /*First, keep track of the file handle: */ 44 this->fid=iomodel_handle; 45 46 /*Initialize and read constants:*/ 47 this->constants=new Parameters(); 48 this->FetchParameters(this->constants); /*this routine goes through the input file, and fetches bools, ints, doubles and strings only, nothing memory intensive*/ 49 50 /*Initialize data: */ 51 this->data=new Parameters(); 52 53 /*Initialize permanent data: */ 234 54 this->my_elements=NULL; 55 this->my_nodes=NULL; 235 56 this->my_vertices=NULL; 236 this->my_nodes=NULL;237 57 this->singlenodetoelementconnectivity=NULL; 238 58 this->numbernodetoelementconnectivity=NULL; 59 60 this->nodecounter=0; 61 this->loadcounter=0; 62 this->constraintcounter=0; 63 64 65 } 66 /*}}}*/ 67 /*FUNCTION IoModel::~IoModel(){{{1*/ 68 IoModel::~IoModel(){ 69 70 delete this->constants; 71 delete this->data; 72 73 xfree((void**)&this->my_elements); 74 xfree((void**)&this->my_nodes); 75 xfree((void**)&this->my_vertices); 76 xfree((void**)&this->singlenodetoelementconnectivity); 77 xfree((void**)&this->numbernodetoelementconnectivity); 239 78 } 240 79 /*}}}*/ … … 638 477 *pndims=ndims; 639 478 *pnumrecords=numrecords; 479 } 480 /*}}}*/ 481 /*FUNCTION IoModel::FetchData(int num,...){{{1*/ 482 void IoModel::FetchData(int num,...){ 483 484 485 va_list ap; 486 int dataenum; 487 double* matrix=NULL; 488 int M,N; 489 int i; 490 491 /*Go through the entire list of enums and fetch the corresponding data. Add it to the iomodel->data dataset. Everything 492 *we fetch is a double* : */ 493 494 va_start(ap,num); 495 496 for(i = 0; i <num; i++){ 497 498 dataenum=va_arg(ap, int); 499 this->FetchData(&matrix,&M,&N,dataenum); 500 501 /*Add to this->data: */ 502 this->data->AddObject(new DoubleMatParam(dataenum,matrix,M,N)); 503 504 /*Free ressources:*/ 505 xfree((void**)&matrix); 506 } 507 va_end(ap); 508 509 } 510 /*}}}*/ 511 /*FUNCTION IoModel::DeleteData(int num,...){{{1*/ 512 void IoModel::DeleteData(int num,...){ 513 514 515 va_list ap; 516 int dataenum; 517 int i; 518 DoubleMatParam* parameter=NULL; 519 520 /*Go through the entire list of enums and delete the corresponding data from the iomodel-data dataset: */ 521 522 va_start(ap,num); 523 524 for(i = 0; i <num; i++){ 525 526 dataenum=va_arg(ap, int); 527 528 parameter=(DoubleMatParam*)this->data->FindParamObject(dataenum); 529 if(parameter){ 530 this->data->DeleteObject((Object*)parameter); 531 } 532 else{ 533 /*do nothing, we did not find the data, but this is no reason to error out: */ 534 } 535 } 536 va_end(ap); 537 538 } 539 /*}}}*/ 540 /*FUNCTION IoModel::get(int dataenum){{{1*/ 541 double* IoModel::f(int dataenum){ 542 543 DoubleMatParam* parameter=NULL; 544 545 parameter=(DoubleMatParam*)this->data->FindParamObject(dataenum); 546 547 if (parameter==NULL)return NULL; //might be legitimate 548 else{ 549 return parameter->GetPointer(); 550 } 640 551 } 641 552 /*}}}*/ … … 935 846 936 847 /*Fetch parameters: */ 937 this-> parameters->FindParam(&numberofelements,NumberOfElementsEnum);848 this->constants->FindParam(&numberofelements,NumberOfElementsEnum); 938 849 939 850 /*First of, find the record for the enum, and get code of data type: */
Note:
See TracChangeset
for help on using the changeset viewer.