1 | #include "./SmbAnalysis.h"
|
---|
2 | #include "../toolkits/toolkits.h"
|
---|
3 | #include "../classes/classes.h"
|
---|
4 | #include "../shared/shared.h"
|
---|
5 | #include "../modules/modules.h"
|
---|
6 |
|
---|
7 | // FIX
|
---|
8 | #include "./shared/io/Print/Print.h"
|
---|
9 |
|
---|
10 | /*Model processing*/
|
---|
11 | void SmbAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
|
---|
12 | /*No constraints*/
|
---|
13 | }/*}}}*/
|
---|
14 | void SmbAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
|
---|
15 | /*No loads*/
|
---|
16 | }/*}}}*/
|
---|
17 | void SmbAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel,bool isamr){/*{{{*/
|
---|
18 | ::CreateNodes(nodes,iomodel,SmbAnalysisEnum,P1Enum);
|
---|
19 | }/*}}}*/
|
---|
20 | int SmbAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
|
---|
21 | return 1;
|
---|
22 | }/*}}}*/
|
---|
23 | void SmbAnalysis::UpdateElements(Elements* elements,Inputs* inputs,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
|
---|
24 |
|
---|
25 | int smb_model;
|
---|
26 | bool isdelta18o,ismungsm,isd18opd,issetpddfac,isprecipscaled,istemperaturescaled,isfirnwarming,isstochastic;
|
---|
27 |
|
---|
28 | /*Update elements: */
|
---|
29 | int counter=0;
|
---|
30 | for(int i=0;i<iomodel->numberofelements;i++){
|
---|
31 | if(iomodel->my_elements[i]){
|
---|
32 | Element* element=(Element*)elements->GetObjectByOffset(counter);
|
---|
33 | element->Update(inputs,i,iomodel,analysis_counter,analysis_type,P1Enum);
|
---|
34 | counter++;
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | /*Figure out smb model: */
|
---|
39 | iomodel->FindConstant(&smb_model,"md.smb.model");
|
---|
40 | iomodel->FindConstant(&isstochastic,"md.stochasticforcing.isstochasticforcing");
|
---|
41 | switch(smb_model){
|
---|
42 | case SMBforcingEnum:
|
---|
43 | iomodel->FetchDataToInput(inputs,elements,"md.smb.mass_balance",SmbMassBalanceEnum,0.);
|
---|
44 | if(isstochastic){
|
---|
45 | iomodel->FetchDataToInput(inputs,elements,"md.stochasticforcing.default_id",StochasticForcingDefaultIdEnum);
|
---|
46 | iomodel->FetchDataToInput(inputs,elements,"md.smb.mass_balance",BaselineSmbMassBalanceEnum,0.);
|
---|
47 | }
|
---|
48 | break;
|
---|
49 | case SMBgembEnum:
|
---|
50 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Ta",SmbTaEnum);
|
---|
51 | iomodel->FetchDataToInput(inputs,elements,"md.smb.V",SmbVEnum);
|
---|
52 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dswrf",SmbDswrfEnum);
|
---|
53 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dswdiffrf",SmbDswdiffrfEnum);
|
---|
54 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dlwrf",SmbDlwrfEnum);
|
---|
55 | iomodel->FetchDataToInput(inputs,elements,"md.smb.P",SmbPEnum);
|
---|
56 | iomodel->FetchDataToInput(inputs,elements,"md.smb.eAir",SmbEAirEnum);
|
---|
57 | iomodel->FetchDataToInput(inputs,elements,"md.smb.pAir",SmbPAirEnum);
|
---|
58 | iomodel->FetchDataToInput(inputs,elements,"md.smb.zTop",SmbZTopEnum);
|
---|
59 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dzTop",SmbDzTopEnum);
|
---|
60 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dzMin",SmbDzMinEnum);
|
---|
61 | iomodel->FetchDataToInput(inputs,elements,"md.smb.zY",SmbZYEnum);
|
---|
62 | iomodel->FetchDataToInput(inputs,elements,"md.smb.zMax",SmbZMaxEnum);
|
---|
63 | iomodel->FetchDataToInput(inputs,elements,"md.smb.zMin",SmbZMinEnum);
|
---|
64 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Tmean",SmbTmeanEnum);
|
---|
65 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Vmean",SmbVmeanEnum);
|
---|
66 | iomodel->FetchDataToInput(inputs,elements,"md.smb.C",SmbCEnum);
|
---|
67 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Tz",SmbTzEnum);
|
---|
68 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Vz",SmbVzEnum);
|
---|
69 | InputUpdateFromConstantx(inputs,elements,false,SmbIsInitializedEnum);
|
---|
70 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Dzini",SmbDziniEnum);
|
---|
71 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Dini",SmbDiniEnum);
|
---|
72 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Reini",SmbReiniEnum);
|
---|
73 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Gdnini",SmbGdniniEnum);
|
---|
74 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Gspini",SmbGspiniEnum);
|
---|
75 | iomodel->FetchDataToInput(inputs,elements,"md.smb.ECini",SmbECiniEnum);
|
---|
76 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Wini",SmbWiniEnum);
|
---|
77 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Aini",SmbAiniEnum);
|
---|
78 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Adiffini",SmbAdiffiniEnum);
|
---|
79 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Tini",SmbTiniEnum);
|
---|
80 | iomodel->FetchDataToInput(inputs,elements,"md.smb.Sizeini",SmbSizeiniEnum);
|
---|
81 | iomodel->FetchDataToInput(inputs,elements,"md.smb.aValue",SmbAValueEnum);
|
---|
82 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dulwrfValue",SmbDulwrfValueEnum);
|
---|
83 | iomodel->FetchDataToInput(inputs,elements,"md.smb.teValue",SmbTeValueEnum);
|
---|
84 | iomodel->FetchDataToInput(inputs,elements,"md.smb.szaValue",SmbSzaValueEnum);
|
---|
85 | iomodel->FetchDataToInput(inputs,elements,"md.smb.cotValue",SmbCotValueEnum);
|
---|
86 | iomodel->FetchDataToInput(inputs,elements,"md.smb.ccsnowValue",SmbCcsnowValueEnum);
|
---|
87 | iomodel->FetchDataToInput(inputs,elements,"md.smb.cciceValue",SmbCciceValueEnum);
|
---|
88 | break;
|
---|
89 | case SMBpddEnum:
|
---|
90 | iomodel->FindConstant(&isdelta18o,"md.smb.isdelta18o");
|
---|
91 | iomodel->FindConstant(&ismungsm,"md.smb.ismungsm");
|
---|
92 | iomodel->FindConstant(&issetpddfac,"md.smb.issetpddfac");
|
---|
93 | iomodel->FetchDataToInput(inputs,elements,"md.thermal.spctemperature",ThermalSpctemperatureEnum);
|
---|
94 | iomodel->FetchDataToInput(inputs,elements,"md.smb.s0p",SmbS0pEnum);
|
---|
95 | iomodel->FetchDataToInput(inputs,elements,"md.smb.s0t",SmbS0tEnum);
|
---|
96 | if(isdelta18o || ismungsm){
|
---|
97 | iomodel->FetchDataToDatasetInput(inputs,elements,"md.smb.temperatures_lgm",SmbTemperaturesLgmEnum);
|
---|
98 | iomodel->FetchDataToDatasetInput(inputs,elements,"md.smb.temperatures_presentday",SmbTemperaturesPresentdayEnum);
|
---|
99 | iomodel->FetchDataToDatasetInput(inputs,elements,"md.smb.precipitations_presentday",SmbPrecipitationsPresentdayEnum);
|
---|
100 | iomodel->FetchDataToDatasetInput(inputs,elements,"md.smb.precipitations_lgm",SmbPrecipitationsLgmEnum);
|
---|
101 | }else{
|
---|
102 | iomodel->FetchDataToDatasetInput(inputs,elements,"md.smb.precipitation",SmbPrecipitationEnum);
|
---|
103 | iomodel->FetchDataToDatasetInput(inputs,elements,"md.smb.monthlytemperatures",SmbMonthlytemperaturesEnum);
|
---|
104 | }
|
---|
105 | if(issetpddfac){
|
---|
106 | iomodel->FetchDataToInput(inputs,elements,"md.smb.pddfac_snow",SmbPddfacSnowEnum,-1.);
|
---|
107 | iomodel->FetchDataToInput(inputs,elements,"md.smb.pddfac_ice",SmbPddfacIceEnum,-1.);
|
---|
108 | }
|
---|
109 | break;
|
---|
110 | case SMBpddSicopolisEnum:
|
---|
111 | iomodel->FetchDataToInput(inputs,elements,"md.smb.s0p",SmbS0pEnum);
|
---|
112 | iomodel->FetchDataToInput(inputs,elements,"md.smb.s0t",SmbS0tEnum);
|
---|
113 | iomodel->FindConstant(&isfirnwarming,"md.smb.isfirnwarming");
|
---|
114 | iomodel->FetchDataToInput(inputs,elements,"md.smb.smb_corr",SmbSmbCorrEnum);
|
---|
115 | iomodel->FetchDataToInput(inputs,elements,"md.smb.precipitation_anomaly",SmbPrecipitationsAnomalyEnum);
|
---|
116 | iomodel->FetchDataToInput(inputs,elements,"md.smb.temperature_anomaly",SmbTemperaturesAnomalyEnum);
|
---|
117 | iomodel->FetchDataToDatasetInput(inputs,elements,"md.smb.monthlytemperatures",SmbMonthlytemperaturesEnum);
|
---|
118 | iomodel->FetchDataToDatasetInput(inputs,elements,"md.smb.precipitation",SmbPrecipitationEnum);
|
---|
119 | break;
|
---|
120 | case SMBd18opddEnum:
|
---|
121 | iomodel->FindConstant(&istemperaturescaled,"md.smb.istemperaturescaled");
|
---|
122 | iomodel->FindConstant(&isprecipscaled,"md.smb.isprecipscaled");
|
---|
123 | iomodel->FindConstant(&ismungsm,"md.smb.ismungsm");
|
---|
124 | iomodel->FindConstant(&isd18opd,"md.smb.isd18opd");
|
---|
125 | iomodel->FindConstant(&issetpddfac,"md.smb.issetpddfac");
|
---|
126 | iomodel->FetchDataToInput(inputs,elements,"md.thermal.spctemperature",ThermalSpctemperatureEnum);
|
---|
127 | iomodel->FetchDataToInput(inputs,elements,"md.smb.s0p",SmbS0pEnum);
|
---|
128 | iomodel->FetchDataToInput(inputs,elements,"md.smb.s0t",SmbS0tEnum);
|
---|
129 | if(isd18opd){
|
---|
130 | iomodel->FetchDataToDatasetInput(inputs,elements,"md.smb.temperatures_presentday",SmbTemperaturesPresentdayEnum);
|
---|
131 | iomodel->FetchDataToDatasetInput(inputs,elements,"md.smb.precipitations_presentday",SmbPrecipitationsPresentdayEnum);
|
---|
132 | if(!istemperaturescaled){
|
---|
133 | /*Fetch array*/
|
---|
134 | IssmDouble* doublearray = NULL;
|
---|
135 | int M,N;
|
---|
136 | iomodel->FetchData(&doublearray,&M,&N,"md.smb.temperatures_reconstructed");
|
---|
137 | if(M!=iomodel->numberofvertices+1) _error_("md.smb.temperatures_reconstructed should have nbv+1 rows");
|
---|
138 | if(N%12!=0) _error_("md.smb.temperatures_reconstructed should have a multiple of 12 columns (since it is monthly)");
|
---|
139 |
|
---|
140 | /*Build indices*/
|
---|
141 | int* ids = xNew<int>(N); for(int i=0;i<N;i++) ids[i] = i;
|
---|
142 |
|
---|
143 | for(Object* & object : elements->objects){
|
---|
144 | Element* element=xDynamicCast<Element*>(object);
|
---|
145 | element->DatasetInputCreate(doublearray,M-1,N,ids,N,inputs,iomodel,SmbTemperaturesReconstructedEnum);
|
---|
146 | }
|
---|
147 | xDelete<int>(ids);
|
---|
148 | iomodel->DeleteData(doublearray,"md.smb.temperatures_reconstructed");
|
---|
149 | }
|
---|
150 | if(!isprecipscaled){
|
---|
151 | /*Fetch array*/
|
---|
152 | IssmDouble* doublearray = NULL;
|
---|
153 | int M,N;
|
---|
154 | iomodel->FetchData(&doublearray,&M,&N,"md.smb.precipitations_reconstructed");
|
---|
155 | if(M!=iomodel->numberofvertices+1) _error_("md.smb.precipitations_reconstructed should have nbv+1 rows");
|
---|
156 | if(N%12!=0) _error_("md.smb.precipitations_reconstructed should have a multiple of 12 columns (since it is monthly)");
|
---|
157 |
|
---|
158 | /*Build indices*/
|
---|
159 | int* ids = xNew<int>(N); for(int i=0;i<N;i++) ids[i] = i;
|
---|
160 |
|
---|
161 | for(Object* & object : elements->objects){
|
---|
162 | Element* element=xDynamicCast<Element*>(object);
|
---|
163 | element->DatasetInputCreate(doublearray,M-1,N,ids,N,inputs,iomodel,SmbPrecipitationsReconstructedEnum);
|
---|
164 | }
|
---|
165 | xDelete<int>(ids);
|
---|
166 | iomodel->DeleteData(doublearray,"md.smb.precipitations_reconstructed");
|
---|
167 | }
|
---|
168 | }
|
---|
169 | if(issetpddfac){
|
---|
170 | iomodel->FetchDataToInput(inputs,elements,"md.smb.pddfac_snow",SmbPddfacSnowEnum,-1.);
|
---|
171 | iomodel->FetchDataToInput(inputs,elements,"md.smb.pddfac_ice",SmbPddfacIceEnum,-1.);
|
---|
172 | }
|
---|
173 | break;
|
---|
174 | case SMBgradientsEnum:
|
---|
175 | iomodel->FetchDataToInput(inputs,elements,"md.smb.href",SmbHrefEnum);
|
---|
176 | iomodel->FetchDataToInput(inputs,elements,"md.smb.smbref",SmbSmbrefEnum);
|
---|
177 | iomodel->FetchDataToInput(inputs,elements,"md.smb.b_pos",SmbBPosEnum);
|
---|
178 | iomodel->FetchDataToInput(inputs,elements,"md.smb.b_neg",SmbBNegEnum);
|
---|
179 | break;
|
---|
180 | case SMBgradientselaEnum:
|
---|
181 | iomodel->FetchDataToInput(inputs,elements,"md.smb.ela",SmbElaEnum);
|
---|
182 | iomodel->FetchDataToInput(inputs,elements,"md.smb.b_pos",SmbBPosEnum);
|
---|
183 | iomodel->FetchDataToInput(inputs,elements,"md.smb.b_neg",SmbBNegEnum);
|
---|
184 | iomodel->FetchDataToInput(inputs,elements,"md.smb.b_max",SmbBMaxEnum);
|
---|
185 | iomodel->FetchDataToInput(inputs,elements,"md.smb.b_min",SmbBMinEnum);
|
---|
186 | break;
|
---|
187 | case SMBarmaEnum:
|
---|
188 | iomodel->FetchDataToInput(inputs,elements,"md.smb.basin_id",SmbBasinsIdEnum);
|
---|
189 | break;
|
---|
190 | case SMBhenningEnum:
|
---|
191 | iomodel->FetchDataToInput(inputs,elements,"md.smb.smbref",SmbSmbrefEnum,0.);
|
---|
192 | break;
|
---|
193 | case SMBcomponentsEnum:
|
---|
194 | iomodel->FetchDataToInput(inputs,elements,"md.smb.accumulation",SmbAccumulationEnum,0.);
|
---|
195 | iomodel->FetchDataToInput(inputs,elements,"md.smb.evaporation",SmbEvaporationEnum,0.);
|
---|
196 | iomodel->FetchDataToInput(inputs,elements,"md.smb.runoff",SmbRunoffEnum,0.);
|
---|
197 | break;
|
---|
198 | case SMBmeltcomponentsEnum:
|
---|
199 | iomodel->FetchDataToInput(inputs,elements,"md.smb.accumulation",SmbAccumulationEnum,0.);
|
---|
200 | iomodel->FetchDataToInput(inputs,elements,"md.smb.evaporation",SmbEvaporationEnum,0.);
|
---|
201 | iomodel->FetchDataToInput(inputs,elements,"md.smb.melt",SmbMeltEnum,0.);
|
---|
202 | iomodel->FetchDataToInput(inputs,elements,"md.smb.refreeze",SmbRefreezeEnum,0.);
|
---|
203 | break;
|
---|
204 | case SMBgradientscomponentsEnum:
|
---|
205 | /* Nothing to add to input */
|
---|
206 | break;
|
---|
207 | case SMBsemicEnum:
|
---|
208 | iomodel->FetchDataToInput(inputs,elements,"md.thermal.spctemperature",ThermalSpctemperatureEnum);
|
---|
209 | iomodel->FetchDataToInput(inputs,elements,"md.smb.s0gcm",SmbS0gcmEnum);
|
---|
210 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dailysnowfall",SmbDailysnowfallEnum);
|
---|
211 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dailyrainfall",SmbDailyrainfallEnum);
|
---|
212 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dailydsradiation",SmbDailydsradiationEnum);
|
---|
213 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dailydlradiation",SmbDailydlradiationEnum);
|
---|
214 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dailywindspeed",SmbDailywindspeedEnum);
|
---|
215 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dailypressure",SmbDailypressureEnum);
|
---|
216 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dailyairdensity",SmbDailyairdensityEnum);
|
---|
217 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dailyairhumidity",SmbDailyairhumidityEnum);
|
---|
218 | iomodel->FetchDataToInput(inputs,elements,"md.smb.dailytemperature",SmbDailytemperatureEnum);
|
---|
219 | break;
|
---|
220 | default:
|
---|
221 | _error_("Surface mass balance model "<<EnumToStringx(smb_model)<<" not supported yet");
|
---|
222 | }
|
---|
223 |
|
---|
224 | }/*}}}*/
|
---|
225 | void SmbAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
|
---|
226 |
|
---|
227 | int numoutputs;
|
---|
228 | char** requestedoutputs = NULL;
|
---|
229 | bool isdelta18o,ismungsm,isd18opd,issetpddfac,interp,cycle,isfirnwarming;
|
---|
230 | int smb_model, smbslices, averaging;
|
---|
231 | IssmDouble *temp = NULL;
|
---|
232 | int N,M;
|
---|
233 |
|
---|
234 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.model",SmbEnum));
|
---|
235 |
|
---|
236 | iomodel->FindConstant(&smb_model,"md.smb.model");
|
---|
237 | iomodel->FindConstant(&interp,"md.timestepping.interp_forcing");
|
---|
238 | iomodel->FindConstant(&cycle,"md.timestepping.cycle_forcing");
|
---|
239 |
|
---|
240 | iomodel->FindConstant(&smbslices,"md.smb.steps_per_step");
|
---|
241 | parameters->AddObject(new IntParam(SmbStepsPerStepEnum,smbslices));
|
---|
242 |
|
---|
243 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.averaging",SmbAveragingEnum));
|
---|
244 |
|
---|
245 | switch(smb_model){
|
---|
246 | case SMBforcingEnum:
|
---|
247 | break;
|
---|
248 | case SMBgembEnum:
|
---|
249 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.aIdx",SmbAIdxEnum));
|
---|
250 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.eIdx",SmbEIdxEnum));
|
---|
251 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.tcIdx",SmbTcIdxEnum));
|
---|
252 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.swIdx",SmbSwIdxEnum));
|
---|
253 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.denIdx",SmbDenIdxEnum));
|
---|
254 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.dsnowIdx",SmbDsnowIdxEnum));
|
---|
255 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.cldFrac",SmbCldFracEnum));
|
---|
256 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.t0wet",SmbT0wetEnum));
|
---|
257 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.t0dry",SmbT0dryEnum));
|
---|
258 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.K",SmbKEnum));
|
---|
259 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.aSnow",SmbASnowEnum));
|
---|
260 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.aIce",SmbAIceEnum));
|
---|
261 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.dt",SmbDtEnum));
|
---|
262 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isgraingrowth",SmbIsgraingrowthEnum));
|
---|
263 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isalbedo",SmbIsalbedoEnum));
|
---|
264 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isshortwave",SmbIsshortwaveEnum));
|
---|
265 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isthermal",SmbIsthermalEnum));
|
---|
266 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isaccumulation",SmbIsaccumulationEnum));
|
---|
267 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.ismelt",SmbIsmeltEnum));
|
---|
268 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isdensification",SmbIsdensificationEnum));
|
---|
269 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isturbulentflux",SmbIsturbulentfluxEnum));
|
---|
270 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isconstrainsurfaceT",SmbIsconstrainsurfaceTEnum));
|
---|
271 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isdeltaLWup",SmbIsdeltaLWupEnum));
|
---|
272 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.InitDensityScaling",SmbInitDensityScalingEnum));
|
---|
273 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.ThermoDeltaTScaling",SmbThermoDeltaTScalingEnum));
|
---|
274 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.adThresh",SmbAdThreshEnum));
|
---|
275 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.teThresh",SmbTeThreshEnum));
|
---|
276 | break;
|
---|
277 | case SMBpddEnum:
|
---|
278 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isdelta18o",SmbIsdelta18oEnum));
|
---|
279 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.ismungsm",SmbIsmungsmEnum));
|
---|
280 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.issetpddfac",SmbIssetpddfacEnum));
|
---|
281 | iomodel->FindConstant(&isdelta18o,"md.smb.isdelta18o");
|
---|
282 | iomodel->FindConstant(&ismungsm,"md.smb.ismungsm");
|
---|
283 |
|
---|
284 | if(ismungsm){
|
---|
285 | iomodel->FetchData(&temp,&N,&M,"md.smb.Pfac"); _assert_(N==2);
|
---|
286 | parameters->AddObject(new TransientParam(SmbPfacEnum,&temp[0],&temp[M],interp,cycle,M));
|
---|
287 | iomodel->DeleteData(temp,"md.smb.Pfac");
|
---|
288 |
|
---|
289 | iomodel->FetchData(&temp,&N,&M,"md.smb.Tdiff"); _assert_(N==2);
|
---|
290 | parameters->AddObject(new TransientParam(SmbTdiffEnum,&temp[0],&temp[M],interp,cycle,M));
|
---|
291 | iomodel->DeleteData(temp,"md.smb.Tdiff");
|
---|
292 |
|
---|
293 | iomodel->FetchData(&temp,&N,&M,"md.smb.sealev"); _assert_(N==2);
|
---|
294 | parameters->AddObject(new TransientParam(SmbSealevEnum,&temp[0],&temp[M],interp,cycle,M));
|
---|
295 | iomodel->DeleteData(temp,"md.smb.sealev");
|
---|
296 | }
|
---|
297 | if(isdelta18o){
|
---|
298 | iomodel->FetchData(&temp,&N,&M,"md.smb.delta18o"); _assert_(N==2);
|
---|
299 | parameters->AddObject(new TransientParam(SmbDelta18oEnum,&temp[0],&temp[M],interp,cycle,M));
|
---|
300 | iomodel->DeleteData(temp,"md.smb.delta18o");
|
---|
301 |
|
---|
302 | iomodel->FetchData(&temp,&N,&M,"md.smb.delta18o_surface"); _assert_(N==2);
|
---|
303 | parameters->AddObject(new TransientParam(SmbDelta18oSurfaceEnum,&temp[0],&temp[M],interp,cycle,M));
|
---|
304 | iomodel->DeleteData(temp,"md.smb.delta18o_surface");
|
---|
305 | }
|
---|
306 |
|
---|
307 | break;
|
---|
308 | case SMBpddSicopolisEnum:
|
---|
309 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isfirnwarming",SmbIsfirnwarmingEnum));
|
---|
310 | break;
|
---|
311 | case SMBd18opddEnum:
|
---|
312 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.ismungsm",SmbIsmungsmEnum));
|
---|
313 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isd18opd",SmbIsd18opdEnum));
|
---|
314 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.issetpddfac",SmbIssetpddfacEnum));
|
---|
315 | iomodel->FindConstant(&ismungsm,"md.smb.ismungsm");
|
---|
316 | iomodel->FindConstant(&isd18opd,"md.smb.isd18opd");
|
---|
317 | iomodel->FindConstant(&issetpddfac,"md.smb.issetpddfac");
|
---|
318 | if(isd18opd){
|
---|
319 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.f",SmbFEnum));
|
---|
320 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.istemperaturescaled",SmbIstemperaturescaledEnum));
|
---|
321 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.isprecipscaled",SmbIsprecipscaledEnum));
|
---|
322 | iomodel->FetchData(&temp,&N,&M,"md.smb.delta18o"); _assert_(N==2);
|
---|
323 | parameters->AddObject(new TransientParam(SmbDelta18oEnum,&temp[0],&temp[M],interp,cycle,M));
|
---|
324 | iomodel->DeleteData(temp,"md.smb.delta18o");
|
---|
325 |
|
---|
326 | IssmDouble yts;
|
---|
327 | bool istemperaturescaled,isprecipscaled;
|
---|
328 | iomodel->FindConstant(&yts,"md.constants.yts");
|
---|
329 | iomodel->FindConstant(&istemperaturescaled,"md.smb.istemperaturescaled");
|
---|
330 | iomodel->FindConstant(&isprecipscaled,"md.smb.isprecipscaled");
|
---|
331 | if(!istemperaturescaled){
|
---|
332 | /*Fetch array*/
|
---|
333 | IssmDouble* doublearray = NULL;
|
---|
334 | int M,N;
|
---|
335 | iomodel->FetchData(&doublearray,&M,&N,"md.smb.temperatures_reconstructed");
|
---|
336 | if(M!=iomodel->numberofvertices+1) _error_("md.smb.temperatures_reconstructed should have nbv+1 rows");
|
---|
337 | if(N%12!=0) _error_("md.smb.temperatures_reconstructed should have a multiple of 12 columns (since it is monthly)");
|
---|
338 | int numyears = N/12; _assert_(numyears*12==N);
|
---|
339 |
|
---|
340 | /*Check times*/
|
---|
341 | #ifdef _ISSM_DEBUG_
|
---|
342 | for(int i=0;i<numyears;i++){
|
---|
343 | for(int j=1;j<12;j++){
|
---|
344 | //_assert_(floor(doublearray[(M-1)*N+i*12+j]/yts)==floor(doublearray[(M-1)*N+i*12]/yts));
|
---|
345 | _assert_(doublearray[(M-1)*N+i*12+j]>doublearray[(M-1)*N+i*12+j-1]);
|
---|
346 | }
|
---|
347 | }
|
---|
348 | #endif
|
---|
349 |
|
---|
350 | /*Build time*/
|
---|
351 | IssmDouble* times = xNew<IssmDouble>(numyears); for(int i=0;i<numyears;i++) times[i] = doublearray[(M-1)*N+i*12];
|
---|
352 | parameters->AddObject(new DoubleVecParam(SmbTemperaturesReconstructedYearsEnum,times,numyears));
|
---|
353 | xDelete<IssmDouble>(times);
|
---|
354 | iomodel->DeleteData(doublearray,"md.smb.temperatures_reconstructed");
|
---|
355 | }
|
---|
356 | if(!isprecipscaled){
|
---|
357 | /*Fetch array*/
|
---|
358 | IssmDouble* doublearray = NULL;
|
---|
359 | int M,N;
|
---|
360 | iomodel->FetchData(&doublearray,&M,&N,"md.smb.precipitations_reconstructed");
|
---|
361 | if(M!=iomodel->numberofvertices+1) _error_("md.smb.precipitations_reconstructed should have nbv+1 rows");
|
---|
362 | if(N%12!=0) _error_("md.smb.precipitations_reconstructed should have a multiple of 12 columns (since it is monthly)");
|
---|
363 | int numyears = N/12; _assert_(numyears*12==N);
|
---|
364 |
|
---|
365 | /*Check times*/
|
---|
366 | #ifdef _ISSM_DEBUG_
|
---|
367 | for(int i=0;i<numyears;i++){
|
---|
368 | for(int j=1;j<12;j++){
|
---|
369 | //_assert_(floor(doublearray[(M-1)*N+i*12+j]/yts)==floor(doublearray[(M-1)*N+i*12]/yts));
|
---|
370 | _assert_(doublearray[(M-1)*N+i*12+j]>doublearray[(M-1)*N+i*12+j-1]);
|
---|
371 | }
|
---|
372 | }
|
---|
373 | #endif
|
---|
374 |
|
---|
375 | /*Build time*/
|
---|
376 | IssmDouble* times = xNew<IssmDouble>(numyears); for(int i=0;i<numyears;i++) times[i] = doublearray[(M-1)*N+i*12];
|
---|
377 | parameters->AddObject(new DoubleVecParam(SmbPrecipitationsReconstructedYearsEnum,times,numyears));
|
---|
378 | xDelete<IssmDouble>(times);
|
---|
379 | iomodel->DeleteData(doublearray,"md.smb.precipitations_reconstructed");
|
---|
380 | }
|
---|
381 | }
|
---|
382 |
|
---|
383 | break;
|
---|
384 | case SMBgradientsEnum:
|
---|
385 | /*Nothing to add to parameters*/
|
---|
386 | break;
|
---|
387 | case SMBgradientselaEnum:
|
---|
388 | /*Nothing to add to parameters*/
|
---|
389 | break;
|
---|
390 | case SMBarmaEnum:
|
---|
391 | /*Nothing to add to parameters*/
|
---|
392 | break;
|
---|
393 | case SMBhenningEnum:
|
---|
394 | /*Nothing to add to parameters*/
|
---|
395 | break;
|
---|
396 | case SMBcomponentsEnum:
|
---|
397 | break;
|
---|
398 | case SMBmeltcomponentsEnum:
|
---|
399 | break;
|
---|
400 | case SMBgradientscomponentsEnum:
|
---|
401 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.accualti",SmbAccualtiEnum));
|
---|
402 | parameters->AddObject(iomodel->CopyConstantObject("md.smb.runoffalti",SmbRunoffaltiEnum));
|
---|
403 |
|
---|
404 | iomodel->FetchData(&temp,&N,&M,"md.smb.accugrad"); _assert_(N==2);
|
---|
405 | parameters->AddObject(new TransientParam(SmbAccugradEnum,&temp[0],&temp[M],interp,cycle,M));
|
---|
406 | iomodel->DeleteData(temp,"md.smb.accugrad");
|
---|
407 | iomodel->FetchData(&temp,&N,&M,"md.smb.runoffgrad"); _assert_(N==2);
|
---|
408 | parameters->AddObject(new TransientParam(SmbRunoffgradEnum,&temp[0],&temp[M],interp,cycle,M));
|
---|
409 | iomodel->DeleteData(temp,"md.smb.runoffgrad");
|
---|
410 |
|
---|
411 | iomodel->FetchData(&temp,&N,&M,"md.smb.accuref"); _assert_(N==2);
|
---|
412 | parameters->AddObject(new TransientParam(SmbAccurefEnum,&temp[0],&temp[M],interp,cycle,M));
|
---|
413 | iomodel->DeleteData(temp,"md.smb.accuref");
|
---|
414 | iomodel->FetchData(&temp,&N,&M,"md.smb.runoffref"); _assert_(N==2);
|
---|
415 | parameters->AddObject(new TransientParam(SmbRunoffrefEnum,&temp[0],&temp[M],interp,cycle,M));
|
---|
416 | iomodel->DeleteData(temp,"md.smb.runoffref");
|
---|
417 | break;
|
---|
418 | case SMBsemicEnum:
|
---|
419 | /*Nothing to add to parameters*/
|
---|
420 | break;
|
---|
421 | default:
|
---|
422 | _error_("Surface mass balance model "<<EnumToStringx(smb_model)<<" not supported yet");
|
---|
423 | }
|
---|
424 |
|
---|
425 | iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.smb.requested_outputs");
|
---|
426 | parameters->AddObject(new IntParam(SmbNumRequestedOutputsEnum,numoutputs));
|
---|
427 | if(numoutputs)parameters->AddObject(new StringArrayParam(SmbRequestedOutputsEnum,requestedoutputs,numoutputs));
|
---|
428 | iomodel->DeleteData(&requestedoutputs,numoutputs,"md.smb.requested_outputs");
|
---|
429 |
|
---|
430 | }/*}}}*/
|
---|
431 |
|
---|
432 | /*Finite Element Analysis*/
|
---|
433 | void SmbAnalysis::Core(FemModel* femmodel){/*{{{*/
|
---|
434 |
|
---|
435 | int smb_model;
|
---|
436 |
|
---|
437 | /*Figure out smb model: */
|
---|
438 | femmodel->parameters->FindParam(&smb_model,SmbEnum);
|
---|
439 |
|
---|
440 | /*branch to correct module*/
|
---|
441 | switch(smb_model){
|
---|
442 | case SMBforcingEnum:
|
---|
443 | SmbForcingx(femmodel);
|
---|
444 | break;
|
---|
445 | case SMBgembEnum:
|
---|
446 | Gembx(femmodel);
|
---|
447 | break;
|
---|
448 | case SMBpddEnum:
|
---|
449 | bool isdelta18o,ismungsm;
|
---|
450 | femmodel->parameters->FindParam(&isdelta18o,SmbIsdelta18oEnum);
|
---|
451 | femmodel->parameters->FindParam(&ismungsm,SmbIsmungsmEnum);
|
---|
452 | if(isdelta18o){
|
---|
453 | if(VerboseSolution()) _printf0_(" call Delta18oParameterization module\n");
|
---|
454 | Delta18oParameterizationx(femmodel);
|
---|
455 | }
|
---|
456 | if(ismungsm){
|
---|
457 | if(VerboseSolution()) _printf0_(" call MungsmtpParameterization module\n");
|
---|
458 | MungsmtpParameterizationx(femmodel);
|
---|
459 | }
|
---|
460 | if(VerboseSolution()) _printf0_(" call positive degree day module\n");
|
---|
461 | PositiveDegreeDayx(femmodel);
|
---|
462 | break;
|
---|
463 | case SMBpddSicopolisEnum:
|
---|
464 | if(VerboseSolution()) _printf0_(" call SICOPOLIS positive degree day module\n");
|
---|
465 | PositiveDegreeDaySicopolisx(femmodel);
|
---|
466 | break;
|
---|
467 | case SMBd18opddEnum:
|
---|
468 | bool isd18opd;
|
---|
469 | femmodel->parameters->FindParam(&isd18opd,SmbIsd18opdEnum);
|
---|
470 | if(isd18opd){
|
---|
471 | if(VerboseSolution()) _printf0_(" call Delta18opdParameterization module\n");
|
---|
472 | Delta18opdParameterizationx(femmodel);
|
---|
473 | if(VerboseSolution()) _printf0_(" call positive degree day module\n");
|
---|
474 | PositiveDegreeDayx(femmodel);
|
---|
475 | }
|
---|
476 | break;
|
---|
477 | case SMBgradientsEnum:
|
---|
478 | if(VerboseSolution())_printf0_(" call smb gradients module\n");
|
---|
479 | SmbGradientsx(femmodel);
|
---|
480 | break;
|
---|
481 | case SMBgradientselaEnum:
|
---|
482 | if(VerboseSolution())_printf0_(" call smb gradients ela module\n");
|
---|
483 | SmbGradientsElax(femmodel);
|
---|
484 | break;
|
---|
485 | case SMBarmaEnum:
|
---|
486 | if(VerboseSolution())_printf0_(" call smb arma module\n");
|
---|
487 | Smbarmax(femmodel);
|
---|
488 | break;
|
---|
489 | case SMBhenningEnum:
|
---|
490 | if(VerboseSolution())_printf0_(" call smb Henning module\n");
|
---|
491 | SmbHenningx(femmodel);
|
---|
492 | break;
|
---|
493 | case SMBcomponentsEnum:
|
---|
494 | if(VerboseSolution())_printf0_(" call smb Components module\n");
|
---|
495 | SmbComponentsx(femmodel);
|
---|
496 | break;
|
---|
497 | case SMBmeltcomponentsEnum:
|
---|
498 | if(VerboseSolution())_printf0_(" call smb Melt Components module\n");
|
---|
499 | SmbMeltComponentsx(femmodel);
|
---|
500 | break;
|
---|
501 | case SMBgcmEnum:
|
---|
502 | /*Nothing to be done*/
|
---|
503 | break;
|
---|
504 | case SMBgradientscomponentsEnum:
|
---|
505 | if(VerboseSolution())_printf0_(" call smb gradients components module\n");
|
---|
506 | SmbGradientsComponentsx(femmodel);
|
---|
507 | break;
|
---|
508 | case SMBsemicEnum:
|
---|
509 | #ifdef _HAVE_SEMIC_
|
---|
510 | if(VerboseSolution())_printf0_(" call smb SEMIC module\n");
|
---|
511 | SmbSemicx(femmodel);
|
---|
512 | #else
|
---|
513 | _error_("SEMIC not installed");
|
---|
514 | #endif //_HAVE_SEMIC_
|
---|
515 | break;
|
---|
516 | default:
|
---|
517 | _error_("Surface mass balance model "<<EnumToStringx(smb_model)<<" not supported yet");
|
---|
518 | }
|
---|
519 |
|
---|
520 | }/*}}}*/
|
---|
521 | void SmbAnalysis::PreCore(FemModel* femmodel){/*{{{*/
|
---|
522 | _error_("not implemented");
|
---|
523 | }/*}}}*/
|
---|
524 | ElementVector* SmbAnalysis::CreateDVector(Element* element){/*{{{*/
|
---|
525 | _error_("not implemented");
|
---|
526 | }/*}}}*/
|
---|
527 | ElementMatrix* SmbAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
528 | _error_("Not implemented");
|
---|
529 | }/*}}}*/
|
---|
530 | ElementMatrix* SmbAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
531 | _error_("not implemented yet");
|
---|
532 | }/*}}}*/
|
---|
533 | ElementVector* SmbAnalysis::CreatePVector(Element* element){/*{{{*/
|
---|
534 | _error_("not implemented yet");
|
---|
535 | }/*}}}*/
|
---|
536 | void SmbAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
537 | _error_("not implemented yet");
|
---|
538 | }/*}}}*/
|
---|
539 | void SmbAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_interp,int control_index){/*{{{*/
|
---|
540 | _error_("Not implemented yet");
|
---|
541 | }/*}}}*/
|
---|
542 | void SmbAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
543 | _error_("not implemented yet");
|
---|
544 | }/*}}}*/
|
---|
545 | void SmbAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
546 | /*Default, do nothing*/
|
---|
547 | return;
|
---|
548 | }/*}}}*/
|
---|