Ice Sheet System Model  4.18
Code documentation
Functions | Variables
esmfbinders.cpp File Reference
#include "./issm.h"

Go to the source code of this file.

Functions

void InitializeISSM (int argc, char **argv, int **pelementsonlocalrank, int *pnumberofelements, ISSM_MPI_Comm comm_init)
 
void RunISSM (IssmDouble dt, IssmDouble *gcmforcings, IssmDouble *issmoutputs)
 
void FinalizeISSM ()
 

Variables

const int GCMForcingNumTerms = 1
 
const int GCMForcingTerms [GCMForcingNumTerms] = { SMBgcmEnum}
 
const int ISSMOutputNumTerms = 1
 
const int ISSMOutputTerms [ISSMOutputNumTerms] = { SurfaceEnum }
 
FemModelfemmodel
 

Function Documentation

◆ InitializeISSM()

void InitializeISSM ( int  argc,
char **  argv,
int **  pelementsonlocalrank,
int *  pnumberofelements,
ISSM_MPI_Comm  comm_init 
)

Definition at line 18 of file esmfbinders.cpp.

18  { /*{{{*/
19 
20  int numberofelements;
21  int* elementsonlocalrank=NULL;
22 
23  /*Initialize femmodel from arguments provided command line: */
24  femmodel = new FemModel(argc,argv,comm_init);
25 
26  /*Figure out the partition for elements, and return: */
27  numberofelements=femmodel->elements->NumberOfElements();
28 
29  elementsonlocalrank=xNewZeroInit<int>(numberofelements);
30  for (int i=0;i<femmodel->elements->Size();i++){
31  Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
32  elementsonlocalrank[element->Sid()]=1;
33  }
34 
35  /*Some specific code here for the binding: */
36  femmodel->parameters->SetParam(SMBgcmEnum,SmbEnum); //bypass SMB model, will be provided by GCM!
37 
38  /*Restart file: */
39  femmodel->Restart();
40 
41  /*Assign output pointers: */
42  *pnumberofelements=numberofelements;
43  *pelementsonlocalrank=elementsonlocalrank;
44 
45  } /*}}}*/

◆ RunISSM()

void RunISSM ( IssmDouble  dt,
IssmDouble gcmforcings,
IssmDouble issmoutputs 
)

Definition at line 46 of file esmfbinders.cpp.

46  { /*{{{*/
47 
48  int numberofelements;
49  IssmDouble yts;
50  IssmDouble rho_ice;
51  IssmDouble area;
52  IssmDouble start_time,final_time;
53 
54  /*Figure out number of elements: */
55  numberofelements=femmodel->elements->Size();
56 
57  /*Fetch some necessary constants: */
59 
60  /*Setup gcm forcings as element-wise input: {{{ */
61  for (int f=0;f<GCMForcingNumTerms;f++){
62 
63  int forcing_type=GCMForcingTerms[f];
64 
65  for (int i=0;i<femmodel->elements->Size();i++){
66  Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
67 
68  switch(forcing_type){
69  case SMBgcmEnum:
70  /*{{{*/
71  {
72 
73  /*Recover rho_ice: */
74  rho_ice=element->FindParam(MaterialsRhoIceEnum);
75 
76  /*Recover area of element: */
77  area=element->SurfaceArea();
78 
79  /*Recover smb forcing from the gcm forcings: */
80  IssmDouble smbforcing=*(gcmforcings+f*numberofelements+i);
81 
82  /*Convert to SI. The smbforcing from GEOS-5 in kg/s, and we transform it into m/s: */
83  smbforcing=smbforcing/(rho_ice*area);
84 
85  /*Add into the element as new forcing :*/
86  element->inputs->AddInput(new DoubleInput(SmbMassBalanceEnum,smbforcing));
87 
88  }
89  /*}}}*/
90  break;
91  default:
92  { _error_("Unknown forcing type " << forcing_type << "\n"); }
93  break;
94  }
95  }
96  }
97 
98  /*}}}*/
99 
100  /*Retrieve ISSM outputs and pass them back to the Gcm : {{{*/
101  for (int f=0;f<ISSMOutputNumTerms;f++){
102 
103  int output_type=ISSMOutputTerms[f];
104 
105  for (int i=0;i<femmodel->elements->Size();i++){
106  Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
107 
108  switch(output_type){
109  case SurfaceEnum:
110  /*{{{*/
111  {
112 
113  IssmDouble surface;
114 
115  /*Recover surface from the ISSM element: */
116  Input2* surface_input = element->GetInput2(SurfaceEnum); _assert_(surface_input);
117  surface_input->GetInputAverage(&surface);
118 
119  *(issmoutputs+f*numberofelements+i) = surface;
120 
121  }
122  /*}}}*/
123  break;
124  default:
125  { _error_("Unknown output type " << output_type << "\n"); }
126  break;
127  }
128  }
129  }
130 
131  /*}}}*/
132 
133  /*Before running, setup the time interval: */
134  femmodel->parameters->FindParam(&start_time,TimeEnum);
135  final_time=start_time+dt;
136  femmodel->parameters->SetParam(final_time,TimesteppingFinalTimeEnum); //we are bypassing ISSM's initial final time!
137 
138  /*Now, run: */
139  femmodel->Solve();
140 
141  /*For the next time around, save the final time as start time */
142  femmodel->parameters->SetParam(final_time,TimeEnum);
143  } /*}}}*/

◆ FinalizeISSM()

void FinalizeISSM ( )

Definition at line 144 of file esmfbinders.cpp.

144  { /*{{{*/
145 
146  /*Output results: */
148 
149  /*Check point: */
150  femmodel->CheckPoint();
151 
152  /*Wrap up: */
153  delete femmodel; femmodel=NULL;
154  } /*}}}*/

Variable Documentation

◆ GCMForcingNumTerms

const int GCMForcingNumTerms = 1

Definition at line 8 of file esmfbinders.cpp.

◆ GCMForcingTerms

const int GCMForcingTerms[GCMForcingNumTerms] = { SMBgcmEnum}

Definition at line 9 of file esmfbinders.cpp.

◆ ISSMOutputNumTerms

const int ISSMOutputNumTerms = 1

Definition at line 11 of file esmfbinders.cpp.

◆ ISSMOutputTerms

const int ISSMOutputTerms[ISSMOutputNumTerms] = { SurfaceEnum }

Definition at line 12 of file esmfbinders.cpp.

◆ femmodel

FemModel* femmodel

Definition at line 16 of file esmfbinders.cpp.

DataSet::Size
int Size()
Definition: DataSet.cpp:399
TimesteppingFinalTimeEnum
@ TimesteppingFinalTimeEnum
Definition: EnumDefinitions.h:430
SmbMassBalanceEnum
@ SmbMassBalanceEnum
Definition: EnumDefinitions.h:748
FemModel::Solve
void Solve(void)
Definition: FemModel.cpp:883
SmbEnum
@ SmbEnum
Definition: EnumDefinitions.h:358
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
IssmDouble
double IssmDouble
Definition: types.h:37
OutputResultsx
void OutputResultsx(FemModel *femmodel)
Definition: OutputResultsx.cpp:17
Element::SurfaceArea
virtual IssmDouble SurfaceArea(void)=0
Element::FindParam
void FindParam(bool *pvalue, int paramenum)
Definition: Element.cpp:933
GCMForcingTerms
const int GCMForcingTerms[GCMForcingNumTerms]
Definition: esmfbinders.cpp:9
FemModel::parameters
Parameters * parameters
Definition: FemModel.h:46
TimeEnum
@ TimeEnum
Definition: EnumDefinitions.h:427
SMBgcmEnum
@ SMBgcmEnum
Definition: EnumDefinitions.h:1245
ISSMOutputNumTerms
const int ISSMOutputNumTerms
Definition: esmfbinders.cpp:11
MaterialsRhoIceEnum
@ MaterialsRhoIceEnum
Definition: EnumDefinitions.h:264
ConstantsYtsEnum
@ ConstantsYtsEnum
Definition: EnumDefinitions.h:104
Element::Sid
int Sid()
Definition: Element.cpp:3578
Element::GetInput2
virtual Input2 * GetInput2(int inputenum)=0
Element
Definition: Element.h:41
Parameters::SetParam
void SetParam(bool boolean, int enum_type)
Definition: Parameters.cpp:441
SurfaceEnum
@ SurfaceEnum
Definition: EnumDefinitions.h:823
GCMForcingNumTerms
const int GCMForcingNumTerms
Definition: esmfbinders.cpp:8
FemModel::elements
Elements * elements
Definition: FemModel.h:44
Input2
Definition: Input2.h:18
FemModel
Definition: FemModel.h:31
FemModel::CheckPoint
void CheckPoint(void)
Definition: FemModel.cpp:238
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
DataSet::GetObjectByOffset
Object * GetObjectByOffset(int offset)
Definition: DataSet.cpp:334
FemModel::Restart
void Restart(void)
Definition: FemModel.cpp:549
ISSMOutputTerms
const int ISSMOutputTerms[ISSMOutputNumTerms]
Definition: esmfbinders.cpp:12
Parameters::FindParam
void FindParam(bool *pinteger, int enum_type)
Definition: Parameters.cpp:262
Elements::NumberOfElements
int NumberOfElements(void)
Definition: Elements.cpp:67
Input2::GetInputAverage
virtual void GetInputAverage(IssmDouble *pvalue)
Definition: Input2.h:33
femmodel
FemModel * femmodel
Definition: esmfbinders.cpp:16