Changeset 25215
- Timestamp:
- 07/06/20 18:02:00 (5 years ago)
- Location:
- issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp
r25084 r25215 6 6 #include "../../shared/shared.h" 7 7 #include "../../toolkits/toolkits.h" 8 #include "../../classes/Inputs2/TransientInput2.h" 9 #include "../../classes/Inputs2/DatasetInput2.h" 10 #include "../../classes/Inputs2/TriaInput2.h" 8 11 #include "../InputUpdateFromMatrixDakotax/InputUpdateFromMatrixDakotax.h" 9 12 #include "../InputUpdateFromConstantx/InputUpdateFromConstantx.h" 10 13 #include "../InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.h" 11 12 void InputUpdateFromDakotax(FemModel* femmodel,double* variables,char* *variables_descriptors,int numdakotavariables){ 14 15 void InputUpdateFromDakotax(FemModel* femmodel,double* variables,char* *variables_descriptors,int numdakotavariables){ /*{{{*/ 13 16 14 17 int i,j,k,l; … … 166 169 xDelete<double>(distributed_values); 167 170 } 171 else if (strncmp(descriptor,"distributed_",12)==0){ 172 173 /*recover partition vector: */ 174 variable_partition=variable_partitions[variablecount]; 175 npart=variable_partitions_npart[variablecount]; 176 177 /*Variable is distributed. Determine root name of variable (ex: distributed_DragCoefficient_1 -> DragCoefficient). 178 * Allocate distributed_values and fill the distributed_values with the next npart variables: */ 179 180 memcpy(root,strstr(descriptor,"_")+1,(strlen(strstr(descriptor,"_")+1)+1)*sizeof(char)); 181 *strstr(root,"_")='\0'; 182 183 distributed_values=xNew<double>(npart); 184 for(j=0;j<npart;j++){ 185 distributed_values[j]=variables[i+j]; 186 } 187 188 //for (int j=0;j<npart;j++)_printf_(j << ":" << distributed_values[j] << "\n"); 189 190 //Call specialty code: 191 InputUpdateSpecialtyCode(femmodel,distributed_values,variable_partition,npart,root); 192 193 /*increment i to skip the distributed values just collected: */ 194 i+=npart-1; //careful, the for loop will add 1. 195 196 /*Free allocations: */ 197 xDelete<double>(parameter); 198 xDelete<double>(distributed_values); 199 } 168 200 else if (strncmp(descriptor,"indexed_",8)==0){ 169 201 _error_("indexed variables not supported yet!"); … … 188 220 xDelete<int>(variable_partitions_nt); 189 221 190 } 222 } /*}}}*/ 223 void InputUpdateSpecialtyCode(FemModel* femmodel,IssmDouble* distributed_values,IssmDouble* variable_partition,int npart,char* root){ //{{{ 224 225 /*Here, we put all the code that cannot be handled any other place: */ 226 if (strncmp(root,"SurfaceloadModelid",18)==0){ 227 228 if(VerboseQmu())_printf_("Updating SurfaceloadModelid MME, with ids: " << "\n"); 229 for (int i=0;i<npart;i++)_printf_(distributed_values[i] << " "); 230 231 232 if (femmodel->inputs2->GetInputObjectEnum(SurfaceloadIceThicknessChangeEnum)==DatasetInput2Enum) 233 MmeToInput(femmodel,distributed_values,variable_partition,npart,SurfaceloadIceThicknessChangeEnum, P0Enum); 234 235 if (femmodel->inputs2->GetInputObjectEnum(MaskIceLevelsetEnum)==DatasetInput2Enum) 236 MmeToInput(femmodel,distributed_values,variable_partition,npart,MaskIceLevelsetEnum, P1Enum); 237 238 if (femmodel->inputs2->GetInputObjectEnum(MaskOceanLevelsetEnum)==DatasetInput2Enum) 239 MmeToInput(femmodel,distributed_values,variable_partition,npart,MaskOceanLevelsetEnum, P1Enum); 240 241 } 242 else _error_("InputUpdateSpecialtyCode error message: " << root << " not supported yet!"); 243 244 } //}}} 245 void MmeToInput(FemModel* femmodel,IssmDouble* distributed_values,IssmDouble* variable_partition,int npart,int rootenum, int interpolationenum){ /*{{{*/ 246 247 TransientInput2* transientinput = NULL; 248 TransientInput2* transientinput2 = NULL; 249 Tria* element = NULL; 250 IssmDouble value; 251 IssmDouble* values = NULL; 252 IssmDouble* times = NULL; 253 int N; 254 int id; 255 256 /*find thickness dataset: */ 257 DatasetInput2* datasetinput = femmodel->inputs2->GetDatasetInput2(rootenum); 258 259 /*Initialize new transient input: */ 260 transientinput = datasetinput->GetTransientInputByOffset(0); _assert_(transientinput); 261 transientinput->GetAllTimes(×,&N); 262 femmodel->inputs2->SetTransientInput(DummyEnum,times,N); 263 transientinput2 = femmodel->inputs2->GetTransientInput(DummyEnum); 264 265 for (int i=0;i<femmodel->elements->Size();i++){ 266 267 Tria* element=xDynamicCast<Tria*>(femmodel->elements->GetObjectByOffset(i)); 268 269 if((int)variable_partition[element->Sid()]==-1)id=0; //grab background field 270 else id=distributed_values[(int)variable_partition[element->Sid()]]; //grab partition field 271 272 if (element->Sid()==577 && rootenum==MaskOceanLevelsetEnum)_printf_("577 -> " << id); 273 274 /*recover the right field from the mme: */ 275 transientinput = datasetinput->GetTransientInputByOffset(id); _assert_(transientinput); 276 277 /*copy values from the transientinput to the final transientinput2: */ 278 for (int j=0;j<N;j++){ 279 TriaInput2* tria_input=transientinput->GetTriaInput(j); 280 element->InputServe(tria_input); 281 if(interpolationenum==P0Enum){ 282 value=tria_input->element_values[0]; 283 transientinput2->AddTriaTimeInput( j,1,&(element->lid),&value,P0Enum); 284 } 285 else if(interpolationenum==P1Enum){ 286 287 /*Get values and lid list*/ 288 const int numvertices = element->GetNumberOfVertices(); 289 int *vertexlids = xNew<int>(numvertices); 290 int *vertexsids = xNew<int>(numvertices); 291 292 /*Recover vertices ids needed to initialize inputs*/ 293 element->GetVerticesLidList(&vertexlids[0]); 294 element->GetVerticesSidList(&vertexsids[0]); 295 values=tria_input->element_values; 296 if (element->Sid()==577 && rootenum==MaskOceanLevelsetEnum)_printf_(" sids: " << vertexsids[0] << " " << vertexsids[1] << " " << vertexsids[2] << " values: " << values[0] << " " << values[1] << " " << values[2] << "\n"); 297 transientinput2->AddTriaTimeInput( j,numvertices,vertexlids,values,P1Enum); 298 } 299 } 300 } 301 302 /*wipe out existing SurfaceloadIceThicknessChangeEnum dataset:*/ 303 femmodel->inputs2->ChangeEnum(DummyEnum,rootenum); 304 305 //reconfigure: 306 transientinput2->Configure(femmodel->parameters); 307 } //}}} -
issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.h
r15849 r25215 9 9 10 10 void InputUpdateFromDakotax(FemModel* femmodel,double* variables,char* *variables_descriptors,int numvariables); 11 void InputUpdateSpecialtyCode(FemModel* femmodel,IssmDouble* distributed_values,IssmDouble* variable_partition,int npart,char* root); 12 void MmeToInput(FemModel* femmodel,IssmDouble* distributed_values,IssmDouble* variable_partition,int npart,int rootenum, int interpolationenum); 13 11 14 12 15 #endif /* _INPUTUPDATEFROMDAKOTAXX_H */
Note:
See TracChangeset
for help on using the changeset viewer.