Ice Sheet System Model  4.18
Code documentation
Functions
InputUpdateFromDakotax.h File Reference

header file for updating datasets from inputs More...

#include "../../classes/classes.h"

Go to the source code of this file.

Functions

void InputUpdateFromDakotax (FemModel *femmodel, double *variables, char **variables_descriptors, int numvariables)
 

Detailed Description

header file for updating datasets from inputs

Definition in file InputUpdateFromDakotax.h.

Function Documentation

◆ InputUpdateFromDakotax()

void InputUpdateFromDakotax ( FemModel femmodel,
double *  variables,
char **  variables_descriptors,
int  numvariables 
)

Definition at line 12 of file InputUpdateFromDakotax.cpp.

12  {
13 
14  int i,j,k,l;
15 
16  int numberofvertices;
17  int numberofelements;
18  int nrows;
19  int ncols;
20  IssmDouble **variable_partitions = NULL;
21  IssmDouble * variable_partition = NULL;
22  int * variable_partitions_npart = NULL;
23  int * variable_partitions_nt = NULL;
24  int variable_partitions_num;
25  int npart;
26  int nt;
27  int variablecount=0;
28 
29  double *distributed_values = NULL;
30  double *parameter = NULL;
31  char *descriptor = NULL;
32  char root[50]; //root name of variable, ex: DragCoefficent, RhoIce, etc ...
33 
34  if (VerboseQmu())_printf0_("dakota variables updates\n");
35 
36  /*retrieve parameters: */
37  femmodel->parameters->FindParam(&variable_partitions,&variable_partitions_num,NULL,NULL,QmuVariablePartitionsEnum);
38  femmodel->parameters->FindParam(&variable_partitions_npart,NULL,NULL,QmuVariablePartitionsNpartEnum);
39  femmodel->parameters->FindParam(&variable_partitions_nt,NULL,NULL,QmuVariablePartitionsNtEnum);
40 
41  numberofvertices=femmodel->vertices->NumberOfVertices();
42  numberofelements=femmodel->elements->NumberOfElements();
43 
44  /*Go through all dakota descriptors, ex: "rho_ice","thermal_conductivity","thickness1","thickness2", etc ..., and
45  * for each descriptor, take the variable value and plug it into the inputs: */
46  for(i=0;i<numdakotavariables;i++){ //these are the dakota variables, for all partitions.
47 
48  descriptor=variables_descriptors[i];
49 
50  if (VerboseQmu())_printf0_(" updating variable " << descriptor << "\n");
51 
52  /*From descriptor, figure out if the variable is scaled, indexed, nodal, or just a simple variable: */
53  if (strncmp(descriptor,"scaled_",7)==0){
54 
55  /*recover partition vector: */
56  variable_partition=variable_partitions[variablecount];
57  npart=variable_partitions_npart[variablecount];
58  nt=variable_partitions_nt[variablecount];
59 
60  /*Variable is scaled. Determine root name of variable (ex: scaled_DragCoefficient_1 -> DragCoefficient). Allocate distributed_values and fill the
61  * distributed_values with the next npart variables: */
62 
63  //strcpy(root,strstr(descriptor,"_")+1); *strstr(root,"_")='\0';
64  memcpy(root,strstr(descriptor,"_")+1,(strlen(strstr(descriptor,"_")+1)+1)*sizeof(char));
65  *strstr(root,"_")='\0';
66 
67  distributed_values=xNew<double>(npart*nt);
68  for(j=0;j<npart*nt;j++){
69  distributed_values[j]=variables[i+j];
70  }
71 
72 
73  /*Now, pick up the parameter corresponding to root: */
75 
76  /*We've got the parameter, we need to update it using the partition vector, and the distributed_values.
77  In addition, the parameter can be either a static or transient (nrows+1) vector. Finally, the partition vectors can include
78  -1 (meaning, don't update). */
79 
80  //_printf_("nrows: " << nrows << " numberofvertices: " << numberofvertices << " numberofelements: " << numberofelements << "\n");
81 
82  if(ncols!=nt){
83  /*we are trying to update a col sized transient input by scaling with a matrix of col size nt. This can only work if nt==1, otherwise, error out: */
84  if (nt!=1) _error_("InputUpdateFromDakotax error message: transient input being updated should be the same col size as the number of time step in the qmu variable specificationi");
85  }
86 
87  if(nt==1){
88  /*scale all the columns by the same vector:*/
89  if (nrows==numberofvertices || nrows==(numberofvertices+1)){
90  for(k=0;k<numberofvertices;k++){
91  if (variable_partition[k]==-1)continue;
92  else{
93  for(l=0;l<ncols;l++){
94  *(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]];
95  }
96  }
97  }
98  }
99  else if (nrows==numberofelements || nrows==(numberofelements+1)){
100  for(k=0;k<numberofelements;k++){
101  if (variable_partition[k]==-1)continue;
102  else{
103  for(l=0;l<ncols;l++){
104  *(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]];
105  }
106  }
107  }
108 
109  }
110  else _error_("partitioning vector should be either elements or vertex sized!");
111 
112  }
113  else{
114  /*scale all the columns by the scalar matrix:*/
115  if (nrows==numberofvertices || nrows==(numberofvertices+1)){
116  for(k=0;k<numberofvertices;k++){
117  if (variable_partition[k]==-1)continue;
118  else{
119  for(l=0;l<ncols;l++){
120  *(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]*nt+l];
121  }
122  }
123  }
124  }
125  else if (nrows==numberofelements || nrows==(numberofelements+1)){
126  for(k=0;k<numberofelements;k++){
127  if (variable_partition[k]==-1)continue;
128  else{
129  for(l=0;l<ncols;l++){
130  *(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]*nt+l];
131  }
132  }
133  }
134 
135  }
136  else _error_("partitioning vector should be either elements or vertex sized!");
137  }
138 
139  #ifdef _DEBUG_
140  PetscSynchronizedPrintf(IssmComm::GetComm(),"Parameter matrix:");
141  PetscSynchronizedFlush(IssmComm::GetComm());
142  for(l=0;l<ncols;l++){
143  PetscSynchronizedPrintf(IssmComm::GetComm()," time %i\n",l);
144  PetscSynchronizedFlush(IssmComm::GetComm());
145 
146  for(k=0;k<numberofvertices;k++){
147  PetscSynchronizedPrintf(IssmComm::GetComm()," node %i value %g\n",k+1,*(parameter+k*ncols+l));
148  PetscSynchronizedFlush(IssmComm::GetComm());
149  }
150  }
151  PetscSynchronizedPrintf(IssmComm::GetComm()," descriptor: %s root %s enum: %i\n",descriptor,root,StringToEnumx(root));
152  PetscSynchronizedFlush(IssmComm::GetComm());
153  #endif
154 
155  /*Update inputs using the parameter matrix: */
156  if(nrows==numberofvertices || (nrows==numberofvertices+1))
157  InputUpdateFromMatrixDakotax(femmodel, parameter, nrows,ncols,StringToEnumx(root), VertexEnum);
158  else
159  InputUpdateFromMatrixDakotax(femmodel, parameter, nrows,ncols,StringToEnumx(root), ElementEnum);
160 
161  /*increment i to skip the distributed values just collected: */
162  i+=npart*nt-1; //careful, the for loop will add 1.
163 
164  /*Free allocations: */
165  xDelete<double>(parameter);
166  xDelete<double>(distributed_values);
167  }
168  else if (strncmp(descriptor,"indexed_",8)==0){
169  _error_("indexed variables not supported yet!");
170  }
171  else if (strncmp(descriptor,"nodal_",8)==0){
172  _error_("nodal variables not supported yet!");
173  }
174  else{
175  /*Ok, standard variable, just update inputs using the variable: */
176  InputUpdateFromConstantx(femmodel,variables[i],StringToEnumx(descriptor));
177  }
178  variablecount++;
179  }
180 
181  /*Free ressources:*/
182  for(i=0;i<variable_partitions_num;i++){
183  IssmDouble* matrix=variable_partitions[i];
184  xDelete<IssmDouble>(matrix);
185  }
186  xDelete<IssmDouble*>(variable_partitions);
187  xDelete<int>(variable_partitions_npart);
188  xDelete<int>(variable_partitions_nt);
189 
190 }
FemModel::vertices
Vertices * vertices
Definition: FemModel.h:49
IssmDouble
double IssmDouble
Definition: types.h:37
QmuVariablePartitionsNtEnum
@ QmuVariablePartitionsNtEnum
Definition: EnumDefinitions.h:296
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
FemModel::parameters
Parameters * parameters
Definition: FemModel.h:46
IssmComm::GetComm
static ISSM_MPI_Comm GetComm(void)
Definition: IssmComm.cpp:30
Vertices::NumberOfVertices
int NumberOfVertices(void)
Definition: Vertices.cpp:255
QmuVariableDescriptorsEnum
@ QmuVariableDescriptorsEnum
Definition: EnumDefinitions.h:293
InputUpdateFromMatrixDakotax
void InputUpdateFromMatrixDakotax(FemModel *femmodel, double *matrix, int nrows, int ncols, int name, int type)
Definition: InputUpdateFromMatrixDakotax.cpp:10
VerboseQmu
bool VerboseQmu(void)
Definition: Verbosity.cpp:28
ElementEnum
@ ElementEnum
Definition: EnumDefinitions.h:1049
Parameters::FindParamInDataset
void FindParamInDataset(IssmDouble **pIssmDoublearray, int *pM, int *pN, int dataset_type, int enum_type)
Definition: Parameters.cpp:410
QmuVariablePartitionsNpartEnum
@ QmuVariablePartitionsNpartEnum
Definition: EnumDefinitions.h:295
InputUpdateFromConstantx
void InputUpdateFromConstantx(FemModel *femmodel, bool constant, int name)
Definition: InputUpdateFromConstantx.cpp:10
FemModel::elements
Elements * elements
Definition: FemModel.h:44
StringToEnumx
int StringToEnumx(const char *string_in, bool notfounderror=true)
Definition: StringToEnumx.cpp:14
VertexEnum
@ VertexEnum
Definition: EnumDefinitions.h:1322
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
Parameters::FindParam
void FindParam(bool *pinteger, int enum_type)
Definition: Parameters.cpp:262
Elements::NumberOfElements
int NumberOfElements(void)
Definition: Elements.cpp:67
QmuVariablePartitionsEnum
@ QmuVariablePartitionsEnum
Definition: EnumDefinitions.h:294
femmodel
FemModel * femmodel
Definition: esmfbinders.cpp:16