[19984] | 1 | #include "./SealevelriseAnalysis.h"
|
---|
[24959] | 2 | #include <math.h>
|
---|
[19984] | 3 | #include "../toolkits/toolkits.h"
|
---|
| 4 | #include "../classes/classes.h"
|
---|
[24481] | 5 | #include "../classes/Inputs2/TransientInput2.h"
|
---|
[19984] | 6 | #include "../shared/shared.h"
|
---|
| 7 | #include "../modules/modules.h"
|
---|
| 8 |
|
---|
| 9 | /*Model processing*/
|
---|
| 10 | void SealevelriseAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
|
---|
| 11 | /*No constraints*/
|
---|
| 12 | }/*}}}*/
|
---|
| 13 | void SealevelriseAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
|
---|
| 14 | /*No loads*/
|
---|
| 15 | }/*}}}*/
|
---|
[23585] | 16 | void SealevelriseAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel,bool isamr){/*{{{*/
|
---|
[19984] | 17 | ::CreateNodes(nodes,iomodel,SealevelriseAnalysisEnum,P1Enum);
|
---|
| 18 | }/*}}}*/
|
---|
| 19 | int SealevelriseAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
|
---|
| 20 | return 1;
|
---|
| 21 | }/*}}}*/
|
---|
[24335] | 22 | void SealevelriseAnalysis::UpdateElements(Elements* elements,Inputs2* inputs2,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
|
---|
[19984] | 23 |
|
---|
[22955] | 24 | int geodetic=0;
|
---|
[24469] | 25 | int dslmodel=0;
|
---|
[22955] | 26 |
|
---|
[19984] | 27 | /*Update elements: */
|
---|
| 28 | int counter=0;
|
---|
| 29 | for(int i=0;i<iomodel->numberofelements;i++){
|
---|
| 30 | if(iomodel->my_elements[i]){
|
---|
| 31 | Element* element=(Element*)elements->GetObjectByOffset(counter);
|
---|
[24335] | 32 | element->Update(inputs2,i,iomodel,analysis_counter,analysis_type,P1Enum);
|
---|
[19984] | 33 | counter++;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | /*Create inputs: */
|
---|
[24861] | 38 | iomodel->FetchDataToInput(inputs2,elements,"md.mask.ocean_levelset",MaskOceanLevelsetEnum);
|
---|
[24335] | 39 | iomodel->FetchDataToInput(inputs2,elements,"md.mask.ice_levelset",MaskIceLevelsetEnum);
|
---|
[25118] | 40 | iomodel->FetchData(&geodetic,"md.solidearth.settings.computesealevelchange");
|
---|
| 41 | iomodel->FetchDataToInput(inputs2,elements,"md.solidearth.surfaceload.icethicknesschange",SurfaceloadIceThicknessChangeEnum);
|
---|
| 42 | iomodel->FetchDataToInput(inputs2,elements,"md.solidearth.sealevel",SealevelEnum,0);
|
---|
[24335] | 43 | iomodel->FetchDataToInput(inputs2,elements,"md.geometry.bed",BedEnum);
|
---|
[25118] | 44 | iomodel->FetchDataToInput(inputs2,elements,"md.solidearth.surfaceload.waterheightchange",SurfaceloadWaterHeightChangeEnum);
|
---|
[24469] | 45 |
|
---|
| 46 | /*dynamic sea level: */
|
---|
| 47 | iomodel->FetchData(&dslmodel,"md.dsl.model");
|
---|
[24505] | 48 | if (dslmodel==1){ /*standard dsl model:{{{*/
|
---|
[24481] | 49 |
|
---|
| 50 | /*deal with global mean steric rate: */
|
---|
| 51 | IssmDouble* str=NULL;
|
---|
| 52 | IssmDouble* times = NULL;
|
---|
| 53 | int M,N;
|
---|
| 54 |
|
---|
| 55 | /*fetch str vector:*/
|
---|
| 56 | iomodel->FetchData(&str,&M,&N,"md.dsl.global_average_thermosteric_sea_level_change"); _assert_(M==2);
|
---|
| 57 |
|
---|
| 58 | //recover time vector:
|
---|
| 59 | times=xNew<IssmDouble>(N);
|
---|
| 60 | for(int t=0;t<N;t++) times[t] = str[N+t];
|
---|
| 61 |
|
---|
| 62 | /*create transient input: */
|
---|
| 63 | inputs2->SetTransientInput(DslGlobalAverageThermostericSeaLevelChangeEnum,times,N);
|
---|
| 64 | TransientInput2* transientinput = inputs2->GetTransientInput(DslGlobalAverageThermostericSeaLevelChangeEnum);
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | for(int i=0;i<elements->Size();i++){
|
---|
| 68 | Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
|
---|
| 69 |
|
---|
| 70 | for(int t=0;t<N;t++){
|
---|
| 71 | switch(element->ObjectEnum()){
|
---|
| 72 | case TriaEnum: transientinput->AddTriaTimeInput( t,1,&element->lid,&str[t],P0Enum); break;
|
---|
| 73 | case PentaEnum: transientinput->AddPentaTimeInput(t,1,&element->lid,&str[t],P0Enum); break;
|
---|
| 74 | default: _error_("Not implemented yet");
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | /*cleanup:*/
|
---|
| 80 | xDelete<IssmDouble>(times);
|
---|
| 81 | iomodel->DeleteData(str,"md.dsl.global_average_thermosteric_sea_level_change");
|
---|
| 82 |
|
---|
| 83 | /*deal with dynamic sea level fields: */
|
---|
[24469] | 84 | iomodel->FetchDataToInput(inputs2,elements,"md.dsl.sea_surface_height_change_above_geoid", DslSeaSurfaceHeightChangeAboveGeoidEnum);
|
---|
| 85 | iomodel->FetchDataToInput(inputs2,elements,"md.dsl.sea_water_pressure_change_at_sea_floor", DslSeaWaterPressureChangeAtSeaFloor);
|
---|
[24481] | 86 |
|
---|
[24505] | 87 | } /*}}}*/
|
---|
| 88 | else if (dslmodel==2){ /*multi-model ensemble dsl model:{{{*/
|
---|
| 89 |
|
---|
| 90 | /*variables:*/
|
---|
| 91 | int nummodels;
|
---|
| 92 | IssmDouble** pstr=NULL;
|
---|
| 93 | IssmDouble* str=NULL;
|
---|
| 94 | IssmDouble* times = NULL;
|
---|
| 95 | int* pM = NULL;
|
---|
| 96 | int* pN = NULL;
|
---|
| 97 | int M,N;
|
---|
| 98 |
|
---|
| 99 | /*deal with dsl.sea_surface_height_change_above_geoid {{{*/
|
---|
| 100 | iomodel->FetchData(&pstr,&pM,&pN,&nummodels,"md.dsl.global_average_thermosteric_sea_level_change");
|
---|
| 101 |
|
---|
| 102 | /*go through the mat array and create a dataset of transient inputs:*/
|
---|
| 103 | for (int i=0;i<nummodels;i++){
|
---|
| 104 |
|
---|
| 105 | M=pM[i];
|
---|
| 106 | N=pN[i];
|
---|
| 107 | str=pstr[i];
|
---|
| 108 |
|
---|
| 109 | //recover time vector:
|
---|
| 110 | times=xNew<IssmDouble>(N);
|
---|
| 111 | for(int t=0;t<N;t++) times[t] = str[(M-1)*N+t];
|
---|
| 112 |
|
---|
| 113 | TransientInput2* transientinput=inputs2->SetDatasetTransientInput(DslGlobalAverageThermostericSeaLevelChangeEnum,i, times,N);
|
---|
| 114 |
|
---|
| 115 | for(int j=0;j<elements->Size();j++){
|
---|
| 116 | Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(j));
|
---|
| 117 |
|
---|
| 118 | for(int t=0;t<N;t++){
|
---|
| 119 | switch(element->ObjectEnum()){
|
---|
| 120 | case TriaEnum: transientinput->AddTriaTimeInput( t,1,&element->lid,&str[t],P0Enum); break;
|
---|
| 121 | case PentaEnum: transientinput->AddPentaTimeInput(t,1,&element->lid,&str[t],P0Enum); break;
|
---|
| 122 | default: _error_("Not implemented yet");
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | xDelete<IssmDouble>(times);
|
---|
| 127 | }
|
---|
| 128 | /*Delete data:*/
|
---|
| 129 | for(int i=0;i<nummodels;i++){
|
---|
| 130 | IssmDouble* str=pstr[i];
|
---|
| 131 | xDelete<IssmDouble>(str);
|
---|
| 132 | }
|
---|
| 133 | xDelete<IssmDouble*>(pstr);
|
---|
| 134 | xDelete<int>(pM);
|
---|
| 135 | xDelete<int>(pN);
|
---|
| 136 | /*}}}*/
|
---|
| 137 | /*now do the same with the dsl.sea_surface_height_change_above_geoid field:{{{ */
|
---|
| 138 | iomodel->FetchData(&pstr,&pM,&pN,&nummodels,"md.dsl.sea_surface_height_change_above_geoid");
|
---|
| 139 |
|
---|
| 140 | for (int i=0;i<nummodels;i++){
|
---|
| 141 | M=pM[i];
|
---|
| 142 | N=pN[i];
|
---|
| 143 | str=pstr[i];
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | //recover time vector:
|
---|
| 147 | times=xNew<IssmDouble>(N);
|
---|
| 148 | for(int t=0;t<N;t++) times[t] = str[(M-1)*N+t];
|
---|
| 149 |
|
---|
| 150 | TransientInput2* transientinput=inputs2->SetDatasetTransientInput(DslSeaSurfaceHeightChangeAboveGeoidEnum,i, times,N);
|
---|
| 151 |
|
---|
| 152 | for(int j=0;j<elements->Size();j++){
|
---|
| 153 |
|
---|
| 154 | /*Get the right transient input*/
|
---|
| 155 | Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(j));
|
---|
| 156 |
|
---|
| 157 | /*Get values and lid list*/
|
---|
| 158 | const int numvertices = element->GetNumberOfVertices();
|
---|
| 159 | int *vertexlids = xNew<int>(numvertices);
|
---|
| 160 | int *vertexsids = xNew<int>(numvertices);
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | /*Recover vertices ids needed to initialize inputs*/
|
---|
| 164 | _assert_(iomodel->elements);
|
---|
| 165 | for(int k=0;k<numvertices;k++){
|
---|
[25219] | 166 | vertexsids[k] =reCast<int>(iomodel->elements[numvertices*element->Sid()+k]-1); //ids for vertices are in the elements array from Matlab
|
---|
| 167 | vertexlids[k]=iomodel->my_vertices_lids[vertexsids[k]];
|
---|
[24505] | 168 | }
|
---|
| 169 |
|
---|
| 170 | IssmDouble* values=xNew<IssmDouble>(numvertices);
|
---|
| 171 |
|
---|
| 172 | for(int t=0;t<N;t++){
|
---|
| 173 | for (int k=0;k<numvertices;k++)values[k]=str[N*vertexsids[k]+t];
|
---|
| 174 |
|
---|
| 175 | switch(element->ObjectEnum()){
|
---|
| 176 | case TriaEnum: transientinput->AddTriaTimeInput( t,numvertices,vertexlids,values,P1Enum); break;
|
---|
| 177 | case PentaEnum: transientinput->AddPentaTimeInput(t,numvertices,vertexlids,values,P1Enum); break;
|
---|
| 178 | default: _error_("Not implemented yet");
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
| 181 | xDelete<IssmDouble>(values);
|
---|
| 182 | xDelete<int>(vertexlids);
|
---|
| 183 | xDelete<int>(vertexsids);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | xDelete<IssmDouble>(times);
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | /*Delete data:*/
|
---|
| 190 | for(int i=0;i<nummodels;i++){
|
---|
| 191 | IssmDouble* str=pstr[i];
|
---|
| 192 | xDelete<IssmDouble>(str);
|
---|
| 193 | }
|
---|
| 194 | xDelete<IssmDouble*>(pstr);
|
---|
| 195 | xDelete<int>(pM);
|
---|
| 196 | xDelete<int>(pN);
|
---|
| 197 | /*}}}*/
|
---|
| 198 | /*now do the same with the dsl.sea_water_pressure_change_at_sea_floor field:{{{ */
|
---|
| 199 | iomodel->FetchData(&pstr,&pM,&pN,&nummodels,"md.dsl.sea_water_pressure_change_at_sea_floor");
|
---|
| 200 |
|
---|
| 201 | for (int i=0;i<nummodels;i++){
|
---|
| 202 | M=pM[i];
|
---|
| 203 | N=pN[i];
|
---|
| 204 | str=pstr[i];
|
---|
| 205 |
|
---|
| 206 | //recover time vector:
|
---|
| 207 | times=xNew<IssmDouble>(N);
|
---|
| 208 | for(int t=0;t<N;t++) times[t] = str[(M-1)*N+t];
|
---|
| 209 |
|
---|
| 210 | TransientInput2* transientinput=inputs2->SetDatasetTransientInput(DslSeaWaterPressureChangeAtSeaFloor,i, times,N);
|
---|
| 211 |
|
---|
| 212 | for(int j=0;j<elements->Size();j++){
|
---|
| 213 |
|
---|
| 214 | /*Get the right transient input*/
|
---|
| 215 | Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(j));
|
---|
| 216 |
|
---|
| 217 | /*Get values and lid list*/
|
---|
| 218 | const int numvertices = element->GetNumberOfVertices();
|
---|
| 219 | int *vertexlids = xNew<int>(numvertices);
|
---|
| 220 | int *vertexsids = xNew<int>(numvertices);
|
---|
| 221 |
|
---|
| 222 |
|
---|
| 223 | /*Recover vertices ids needed to initialize inputs*/
|
---|
| 224 | _assert_(iomodel->elements);
|
---|
| 225 | for(int k=0;k<numvertices;k++){
|
---|
[25219] | 226 | vertexsids[k] =reCast<int>(iomodel->elements[numvertices*element->Sid()+k]-1); //ids for vertices are in the elements array from Matlab
|
---|
| 227 | vertexlids[k]=iomodel->my_vertices_lids[vertexsids[k]];
|
---|
[24505] | 228 | }
|
---|
| 229 |
|
---|
| 230 | IssmDouble* values=xNew<IssmDouble>(numvertices);
|
---|
| 231 |
|
---|
| 232 | for(int t=0;t<N;t++){
|
---|
| 233 | for (int k=0;k<numvertices;k++)values[k]=str[N*vertexsids[k]+t];
|
---|
| 234 |
|
---|
| 235 | switch(element->ObjectEnum()){
|
---|
| 236 | case TriaEnum: transientinput->AddTriaTimeInput( t,numvertices,vertexlids,values,P1Enum); break;
|
---|
| 237 | case PentaEnum: transientinput->AddPentaTimeInput(t,numvertices,vertexlids,values,P1Enum); break;
|
---|
| 238 | default: _error_("Not implemented yet");
|
---|
| 239 | }
|
---|
| 240 | }
|
---|
| 241 | xDelete<IssmDouble>(values);
|
---|
| 242 | xDelete<int>(vertexlids);
|
---|
| 243 | xDelete<int>(vertexsids);
|
---|
| 244 | }
|
---|
| 245 | xDelete<IssmDouble>(times);
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | /*Delete data:*/
|
---|
| 249 | for(int i=0;i<nummodels;i++){
|
---|
| 250 | IssmDouble* str=pstr[i];
|
---|
| 251 | xDelete<IssmDouble>(str);
|
---|
| 252 | }
|
---|
| 253 | xDelete<IssmDouble*>(pstr);
|
---|
| 254 | xDelete<int>(pM);
|
---|
| 255 | xDelete<int>(pN);
|
---|
| 256 | /*}}}*/
|
---|
| 257 |
|
---|
| 258 | } /*}}}*/
|
---|
[24469] | 259 | else _error_("Dsl model " << dslmodel << " not implemented yet!");
|
---|
[25060] | 260 |
|
---|
[25066] | 261 |
|
---|
[25060] | 262 |
|
---|
[22968] | 263 | /*Initialize cumdeltalthickness and sealevel rise rate input*/
|
---|
[24335] | 264 | InputUpdateFromConstantx(inputs2,elements,0.,SealevelriseCumDeltathicknessEnum);
|
---|
| 265 | InputUpdateFromConstantx(inputs2,elements,0.,SealevelNEsaRateEnum);
|
---|
| 266 | InputUpdateFromConstantx(inputs2,elements,0.,SealevelUEsaRateEnum);
|
---|
| 267 | InputUpdateFromConstantx(inputs2,elements,0.,SealevelRSLRateEnum);
|
---|
| 268 | InputUpdateFromConstantx(inputs2,elements,0.,SealevelEustaticMaskEnum);
|
---|
| 269 | InputUpdateFromConstantx(inputs2,elements,0.,SealevelEustaticOceanMaskEnum);
|
---|
[22968] | 270 |
|
---|
[19984] | 271 | }/*}}}*/
|
---|
| 272 | void SealevelriseAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
|
---|
| 273 |
|
---|
[19986] | 274 | int nl;
|
---|
[19984] | 275 | IssmDouble* love_h=NULL;
|
---|
| 276 | IssmDouble* love_k=NULL;
|
---|
[20999] | 277 | IssmDouble* love_l=NULL;
|
---|
[25139] | 278 | IssmDouble* love_th=NULL;
|
---|
| 279 | IssmDouble* love_tk=NULL;
|
---|
| 280 | IssmDouble* love_tl=NULL;
|
---|
[24469] | 281 | int dslmodel=0;
|
---|
[23066] | 282 |
|
---|
[24921] | 283 | IssmDouble* G_rigid = NULL;
|
---|
| 284 | IssmDouble* G_rigid_local = NULL;
|
---|
[20028] | 285 | IssmDouble* G_elastic = NULL;
|
---|
[20033] | 286 | IssmDouble* G_elastic_local = NULL;
|
---|
[20999] | 287 | IssmDouble* U_elastic = NULL;
|
---|
| 288 | IssmDouble* U_elastic_local = NULL;
|
---|
| 289 | IssmDouble* H_elastic = NULL;
|
---|
| 290 | IssmDouble* H_elastic_local = NULL;
|
---|
[20033] | 291 | int M,m,lower_row,upper_row;
|
---|
| 292 | IssmDouble degacc=.01;
|
---|
[24959] | 293 | IssmDouble planetradius=0;
|
---|
| 294 | IssmDouble planetarea=0;
|
---|
[19984] | 295 |
|
---|
[20036] | 296 | int numoutputs;
|
---|
| 297 | char** requestedoutputs = NULL;
|
---|
| 298 |
|
---|
[20136] | 299 | /*transition vectors: */
|
---|
| 300 | IssmDouble **transitions = NULL;
|
---|
| 301 | int *transitions_M = NULL;
|
---|
| 302 | int *transitions_N = NULL;
|
---|
| 303 | int ntransitions;
|
---|
| 304 |
|
---|
[19986] | 305 | /*some constant parameters: */
|
---|
[24531] | 306 | parameters->AddObject(iomodel->CopyConstantObject("md.dsl.model",DslModelEnum));
|
---|
[25118] | 307 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.runfrequency",SolidearthSettingsRunFrequencyEnum));
|
---|
| 308 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.reltol",SolidearthSettingsReltolEnum));
|
---|
| 309 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.abstol",SolidearthSettingsAbstolEnum));
|
---|
| 310 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.maxiter",SolidearthSettingsMaxiterEnum));
|
---|
| 311 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.rigid",SolidearthSettingsRigidEnum));
|
---|
| 312 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.horiz",SolidearthSettingsHorizEnum));
|
---|
| 313 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.elastic",SolidearthSettingsElasticEnum));
|
---|
| 314 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.rotation",SolidearthSettingsRotationEnum));
|
---|
| 315 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.rotational.equatorialmoi",RotationalEquatorialMoiEnum));
|
---|
| 316 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.rotational.polarmoi",RotationalPolarMoiEnum));
|
---|
| 317 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.rotational.angularvelocity",RotationalAngularVelocityEnum));
|
---|
| 318 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.ocean_area_scaling",SolidearthSettingsOceanAreaScalingEnum));
|
---|
| 319 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.computesealevelchange",SolidearthSettingsComputesealevelchangeEnum));
|
---|
| 320 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.planetradius",SolidearthPlanetRadiusEnum));
|
---|
[19986] | 321 |
|
---|
[24959] | 322 | /*compute planet area and plug into parameters:*/
|
---|
[25118] | 323 | iomodel->FetchData(&planetradius,"md.solidearth.planetradius");
|
---|
[24959] | 324 | planetarea=4*PI*planetradius*planetradius;
|
---|
[25118] | 325 | parameters->AddObject(new DoubleParam(SolidearthPlanetAreaEnum,planetarea));
|
---|
[24959] | 326 |
|
---|
[24505] | 327 | /*Deal with dsl multi-model ensembles: {{{*/
|
---|
| 328 | iomodel->FetchData(&dslmodel,"md.dsl.model");
|
---|
| 329 | parameters->AddObject(iomodel->CopyConstantObject("md.dsl.compute_fingerprints",DslComputeFingerprintsEnum));
|
---|
| 330 | if(dslmodel==2){
|
---|
| 331 | int modelid;
|
---|
| 332 | int nummodels;
|
---|
| 333 |
|
---|
| 334 | parameters->AddObject(iomodel->CopyConstantObject("md.dsl.modelid",DslModelidEnum));
|
---|
| 335 | parameters->AddObject(iomodel->CopyConstantObject("md.dsl.nummodels",DslNummodelsEnum));
|
---|
| 336 | iomodel->FetchData(&modelid,"md.dsl.modelid");
|
---|
| 337 | iomodel->FetchData(&nummodels,"md.dsl.nummodels");
|
---|
| 338 |
|
---|
| 339 | /*quick checks: */
|
---|
| 340 | if(nummodels<=0)_error_("dslmme object in md.dsl field should contain at least 1 ensemble model!");
|
---|
| 341 | if(modelid<=0 || modelid>nummodels)_error_("modelid field in dslmme object of md.dsl field should be between 1 and the number of ensemble runs!");
|
---|
| 342 | } /*}}}*/
|
---|
[24481] | 343 | /*Deal with elasticity {{{*/
|
---|
[24921] | 344 | /*love numbers: */
|
---|
[25146] | 345 | iomodel->FetchData(&love_h,&nl,NULL,"md.solidearth.lovenumbers.h");
|
---|
| 346 | iomodel->FetchData(&love_k,&nl,NULL,"md.solidearth.lovenumbers.k");
|
---|
| 347 | iomodel->FetchData(&love_l,&nl,NULL,"md.solidearth.lovenumbers.l");
|
---|
| 348 | iomodel->FetchData(&love_th,&nl,NULL,"md.solidearth.lovenumbers.th");
|
---|
| 349 | iomodel->FetchData(&love_tk,&nl,NULL,"md.solidearth.lovenumbers.tk");
|
---|
| 350 | iomodel->FetchData(&love_tl,&nl,NULL,"md.solidearth.lovenumbers.tl");
|
---|
| 351 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.lovenumbers.tk2secular",TidalLoveK2SecularEnum));
|
---|
[19984] | 352 |
|
---|
[25139] | 353 | parameters->AddObject(new DoubleMatParam(LoadLoveHEnum,love_h,nl,1));
|
---|
| 354 | parameters->AddObject(new DoubleMatParam(LoadLoveKEnum,love_k,nl,1));
|
---|
| 355 | parameters->AddObject(new DoubleMatParam(LoadLoveLEnum,love_l,nl,1));
|
---|
| 356 | parameters->AddObject(new DoubleMatParam(TidalLoveHEnum,love_th,nl,1));
|
---|
| 357 | parameters->AddObject(new DoubleMatParam(TidalLoveKEnum,love_tk,nl,1));
|
---|
| 358 | parameters->AddObject(new DoubleMatParam(TidalLoveLEnum,love_tl,nl,1));
|
---|
| 359 |
|
---|
[24921] | 360 | /*compute elastic green function for a range of angles*/
|
---|
[25118] | 361 | iomodel->FetchData(°acc,"md.solidearth.settings.degacc");
|
---|
[24921] | 362 | M=reCast<int,IssmDouble>(180./degacc+1.);
|
---|
[20022] | 363 |
|
---|
[24921] | 364 | // AD performance is sensitive to calls to ensurecontiguous.
|
---|
| 365 | // // Providing "t" will cause ensurecontiguous to be called.
|
---|
| 366 | #ifdef _HAVE_AD_
|
---|
| 367 | G_rigid=xNew<IssmDouble>(M,"t");
|
---|
| 368 | G_elastic=xNew<IssmDouble>(M,"t");
|
---|
| 369 | U_elastic=xNew<IssmDouble>(M,"t");
|
---|
| 370 | H_elastic=xNew<IssmDouble>(M,"t");
|
---|
| 371 | #else
|
---|
| 372 | G_rigid=xNew<IssmDouble>(M);
|
---|
| 373 | G_elastic=xNew<IssmDouble>(M);
|
---|
| 374 | U_elastic=xNew<IssmDouble>(M);
|
---|
| 375 | H_elastic=xNew<IssmDouble>(M);
|
---|
| 376 | #endif
|
---|
[21742] | 377 |
|
---|
[24921] | 378 | /*compute combined legendre + love number (elastic green function:*/
|
---|
| 379 | m=DetermineLocalSize(M,IssmComm::GetComm());
|
---|
| 380 | GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,IssmComm::GetComm());
|
---|
| 381 | // AD performance is sensitive to calls to ensurecontiguous.
|
---|
| 382 | // // Providing "t" will cause ensurecontiguous to be called.
|
---|
| 383 | #ifdef _HAVE_AD_
|
---|
| 384 | G_elastic_local=xNew<IssmDouble>(m,"t");
|
---|
| 385 | G_rigid_local=xNew<IssmDouble>(m,"t");
|
---|
| 386 | U_elastic_local=xNew<IssmDouble>(m,"t");
|
---|
| 387 | H_elastic_local=xNew<IssmDouble>(m,"t");
|
---|
| 388 | #else
|
---|
| 389 | G_elastic_local=xNew<IssmDouble>(m);
|
---|
| 390 | G_rigid_local=xNew<IssmDouble>(m);
|
---|
| 391 | U_elastic_local=xNew<IssmDouble>(m);
|
---|
| 392 | H_elastic_local=xNew<IssmDouble>(m);
|
---|
| 393 | #endif
|
---|
[21742] | 394 |
|
---|
[24921] | 395 | for(int i=lower_row;i<upper_row;i++){
|
---|
| 396 | IssmDouble alpha,x;
|
---|
| 397 | alpha= reCast<IssmDouble>(i)*degacc * PI / 180.0;
|
---|
[20033] | 398 |
|
---|
[24921] | 399 | G_rigid_local[i-lower_row]= .5/sin(alpha/2.0);
|
---|
| 400 | G_elastic_local[i-lower_row]= (love_k[nl-1]-love_h[nl-1])*G_rigid_local[i-lower_row];
|
---|
| 401 | U_elastic_local[i-lower_row]= (love_h[nl-1])*G_rigid_local[i-lower_row];
|
---|
| 402 | H_elastic_local[i-lower_row]= 0;
|
---|
| 403 | IssmDouble Pn = 0.;
|
---|
| 404 | IssmDouble Pn1 = 0.;
|
---|
| 405 | IssmDouble Pn2 = 0.;
|
---|
| 406 | IssmDouble Pn_p = 0.;
|
---|
| 407 | IssmDouble Pn_p1 = 0.;
|
---|
| 408 | IssmDouble Pn_p2 = 0.;
|
---|
[20029] | 409 |
|
---|
[24921] | 410 | for (int n=0;n<nl;n++) {
|
---|
| 411 | IssmDouble deltalove_G;
|
---|
| 412 | IssmDouble deltalove_U;
|
---|
[21908] | 413 |
|
---|
[24921] | 414 | deltalove_G = (love_k[n]-love_k[nl-1]-love_h[n]+love_h[nl-1]);
|
---|
| 415 | deltalove_U = (love_h[n]-love_h[nl-1]);
|
---|
[20033] | 416 |
|
---|
[24921] | 417 | /*compute legendre polynomials: P_n(cos\theta) & d P_n(cos\theta)/ d\theta: */
|
---|
| 418 | if(n==0){
|
---|
| 419 | Pn=1;
|
---|
| 420 | Pn_p=0;
|
---|
| 421 | }
|
---|
| 422 | else if(n==1){
|
---|
| 423 | Pn = cos(alpha);
|
---|
| 424 | Pn_p = 1;
|
---|
| 425 | }
|
---|
| 426 | else{
|
---|
| 427 | Pn = ( (2*n-1)*cos(alpha)*Pn1 - (n-1)*Pn2 ) /n;
|
---|
| 428 | Pn_p = ( (2*n-1)*(Pn1+cos(alpha)*Pn_p1) - (n-1)*Pn_p2 ) /n;
|
---|
| 429 | }
|
---|
| 430 | Pn2=Pn1; Pn1=Pn;
|
---|
| 431 | Pn_p2=Pn_p1; Pn_p1=Pn_p;
|
---|
[23066] | 432 |
|
---|
[24921] | 433 | G_elastic_local[i-lower_row] += deltalove_G*Pn; // gravitational potential
|
---|
| 434 | U_elastic_local[i-lower_row] += deltalove_U*Pn; // vertical (up) displacement
|
---|
| 435 | H_elastic_local[i-lower_row] += sin(alpha)*love_l[n]*Pn_p; // horizontal displacements
|
---|
[20033] | 436 | }
|
---|
[24921] | 437 | }
|
---|
[20033] | 438 |
|
---|
[24921] | 439 | /*merge G_elastic_local into G_elastic; U_elastic_local into U_elastic; H_elastic_local to H_elastic:{{{*/
|
---|
| 440 | int* recvcounts=xNew<int>(IssmComm::GetSize());
|
---|
| 441 | int* displs=xNew<int>(IssmComm::GetSize());
|
---|
[20033] | 442 |
|
---|
[24921] | 443 | //recvcounts:
|
---|
| 444 | ISSM_MPI_Allgather(&m,1,ISSM_MPI_INT,recvcounts,1,ISSM_MPI_INT,IssmComm::GetComm());
|
---|
[20033] | 445 |
|
---|
[24921] | 446 | /*displs: */
|
---|
| 447 | ISSM_MPI_Allgather(&lower_row,1,ISSM_MPI_INT,displs,1,ISSM_MPI_INT,IssmComm::GetComm());
|
---|
[20033] | 448 |
|
---|
[24921] | 449 | /*All gather:*/
|
---|
| 450 | ISSM_MPI_Allgatherv(G_rigid_local, m, ISSM_MPI_DOUBLE, G_rigid, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
---|
| 451 | ISSM_MPI_Allgatherv(G_elastic_local, m, ISSM_MPI_DOUBLE, G_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
---|
| 452 | ISSM_MPI_Allgatherv(U_elastic_local, m, ISSM_MPI_DOUBLE, U_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
---|
| 453 | ISSM_MPI_Allgatherv(H_elastic_local, m, ISSM_MPI_DOUBLE, H_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
---|
| 454 | /*free ressources: */
|
---|
| 455 | xDelete<int>(recvcounts);
|
---|
| 456 | xDelete<int>(displs);
|
---|
[20033] | 457 |
|
---|
[24921] | 458 | /*}}}*/
|
---|
[20033] | 459 |
|
---|
[24921] | 460 | /*Avoid singularity at 0: */
|
---|
| 461 | G_rigid[0]=G_rigid[1];
|
---|
| 462 | parameters->AddObject(new DoubleVecParam(SealevelriseGRigidEnum,G_rigid,M));
|
---|
| 463 | G_elastic[0]=G_elastic[1];
|
---|
| 464 | parameters->AddObject(new DoubleVecParam(SealevelriseGElasticEnum,G_elastic,M));
|
---|
| 465 | U_elastic[0]=U_elastic[1];
|
---|
| 466 | parameters->AddObject(new DoubleVecParam(SealevelriseUElasticEnum,U_elastic,M));
|
---|
| 467 | H_elastic[0]=H_elastic[1];
|
---|
| 468 | parameters->AddObject(new DoubleVecParam(SealevelriseHElasticEnum,H_elastic,M));
|
---|
[20028] | 469 |
|
---|
[24921] | 470 | /*free ressources: */
|
---|
| 471 | xDelete<IssmDouble>(love_h);
|
---|
| 472 | xDelete<IssmDouble>(love_k);
|
---|
| 473 | xDelete<IssmDouble>(love_l);
|
---|
[25139] | 474 | xDelete<IssmDouble>(love_th);
|
---|
| 475 | xDelete<IssmDouble>(love_tk);
|
---|
| 476 | xDelete<IssmDouble>(love_tl);
|
---|
[24921] | 477 | xDelete<IssmDouble>(G_rigid);
|
---|
| 478 | xDelete<IssmDouble>(G_rigid_local);
|
---|
| 479 | xDelete<IssmDouble>(G_elastic);
|
---|
| 480 | xDelete<IssmDouble>(G_elastic_local);
|
---|
| 481 | xDelete<IssmDouble>(U_elastic);
|
---|
| 482 | xDelete<IssmDouble>(U_elastic_local);
|
---|
| 483 | xDelete<IssmDouble>(H_elastic);
|
---|
| 484 | xDelete<IssmDouble>(H_elastic_local);
|
---|
[24977] | 485 |
|
---|
| 486 | /*Indicate we have not yet ran the Geometry Core module: */
|
---|
| 487 | parameters->AddObject(new BoolParam(SealevelriseGeometryDoneEnum,false));
|
---|
| 488 |
|
---|
[24921] | 489 | /*}}}*/
|
---|
[24481] | 490 | /*Transitions:{{{ */
|
---|
[25118] | 491 | iomodel->FetchData(&transitions,&transitions_M,&transitions_N,&ntransitions,"md.solidearth.transitions");
|
---|
[20136] | 492 | if(transitions){
|
---|
| 493 | parameters->AddObject(new DoubleMatArrayParam(SealevelriseTransitionsEnum,transitions,ntransitions,transitions_M,transitions_N));
|
---|
| 494 |
|
---|
| 495 | for(int i=0;i<ntransitions;i++){
|
---|
| 496 | IssmDouble* transition=transitions[i];
|
---|
| 497 | xDelete<IssmDouble>(transition);
|
---|
| 498 | }
|
---|
| 499 | xDelete<IssmDouble*>(transitions);
|
---|
[20138] | 500 | xDelete<int>(transitions_M);
|
---|
| 501 | xDelete<int>(transitions_N);
|
---|
[24481] | 502 | } /*}}}*/
|
---|
| 503 | /*Requested outputs {{{*/
|
---|
[25118] | 504 | iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.solidearth.requested_outputs");
|
---|
[20036] | 505 | if(numoutputs)parameters->AddObject(new StringArrayParam(SealevelriseRequestedOutputsEnum,requestedoutputs,numoutputs));
|
---|
[25118] | 506 | iomodel->DeleteData(&requestedoutputs,numoutputs,"md.solidearth.requested_outputs");
|
---|
[24481] | 507 | /*}}}*/
|
---|
[20029] | 508 |
|
---|
[19984] | 509 | }/*}}}*/
|
---|
| 510 |
|
---|
| 511 | /*Finite Element Analysis*/
|
---|
| 512 | void SealevelriseAnalysis::Core(FemModel* femmodel){/*{{{*/
|
---|
| 513 | _error_("not implemented");
|
---|
| 514 | }/*}}}*/
|
---|
| 515 | ElementVector* SealevelriseAnalysis::CreateDVector(Element* element){/*{{{*/
|
---|
| 516 | /*Default, return NULL*/
|
---|
| 517 | return NULL;
|
---|
| 518 | }/*}}}*/
|
---|
| 519 | ElementMatrix* SealevelriseAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
| 520 | _error_("Not implemented");
|
---|
| 521 | }/*}}}*/
|
---|
| 522 | ElementMatrix* SealevelriseAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
| 523 | _error_("not implemented yet");
|
---|
| 524 | }/*}}}*/
|
---|
| 525 | ElementVector* SealevelriseAnalysis::CreatePVector(Element* element){/*{{{*/
|
---|
| 526 | _error_("not implemented yet");
|
---|
| 527 | }/*}}}*/
|
---|
| 528 | void SealevelriseAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
| 529 | _error_("not implemented yet");
|
---|
| 530 | }/*}}}*/
|
---|
| 531 | void SealevelriseAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
|
---|
| 532 | _error_("Not implemented yet");
|
---|
| 533 | }/*}}}*/
|
---|
| 534 | void SealevelriseAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
[22955] | 535 | _error_("not implemeneted yet!");
|
---|
[20153] | 536 |
|
---|
[19984] | 537 | }/*}}}*/
|
---|
| 538 | void SealevelriseAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
| 539 | /*Default, do nothing*/
|
---|
| 540 | return;
|
---|
| 541 | }/*}}}*/
|
---|