| 1 | #include "./SealevelriseAnalysis.h"
|
|---|
| 2 | #include <math.h>
|
|---|
| 3 | #include "../toolkits/toolkits.h"
|
|---|
| 4 | #include "../classes/classes.h"
|
|---|
| 5 | #include "../classes/Inputs/TransientInput.h"
|
|---|
| 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 | }/*}}}*/
|
|---|
| 16 | void SealevelriseAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel,bool isamr){/*{{{*/
|
|---|
| 17 | ::CreateNodes(nodes,iomodel,SealevelriseAnalysisEnum,P1Enum);
|
|---|
| 18 | }/*}}}*/
|
|---|
| 19 | int SealevelriseAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
|
|---|
| 20 | return 1;
|
|---|
| 21 | }/*}}}*/
|
|---|
| 22 | void SealevelriseAnalysis::UpdateElements(Elements* elements,Inputs* inputs,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
|
|---|
| 23 |
|
|---|
| 24 | int geodetic=0;
|
|---|
| 25 | int dslmodel=0;
|
|---|
| 26 |
|
|---|
| 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);
|
|---|
| 32 | element->Update(inputs,i,iomodel,analysis_counter,analysis_type,P1Enum);
|
|---|
| 33 | counter++;
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /*Create inputs: */
|
|---|
| 38 | iomodel->FetchDataToInput(inputs,elements,"md.mask.ocean_levelset",MaskOceanLevelsetEnum);
|
|---|
| 39 | iomodel->FetchDataToInput(inputs,elements,"md.mask.ice_levelset",MaskIceLevelsetEnum);
|
|---|
| 40 | iomodel->FetchData(&geodetic,"md.solidearth.settings.computesealevelchange");
|
|---|
| 41 | iomodel->FetchDataToInput(inputs,elements,"md.solidearth.surfaceload.icethicknesschange",SurfaceloadIceThicknessChangeEnum);
|
|---|
| 42 | iomodel->FetchDataToInput(inputs,elements,"md.solidearth.initialsealevel",SealevelEnum,0);
|
|---|
| 43 | iomodel->FetchDataToInput(inputs,elements,"md.geometry.bed",BedEnum);
|
|---|
| 44 | iomodel->FetchDataToInput(inputs,elements,"md.solidearth.surfaceload.waterheightchange",SurfaceloadWaterHeightChangeEnum);
|
|---|
| 45 |
|
|---|
| 46 | /*dynamic sea level: */
|
|---|
| 47 | iomodel->FetchData(&dslmodel,"md.dsl.model");
|
|---|
| 48 | if (dslmodel==1){ /*standard dsl model:{{{*/
|
|---|
| 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 | inputs->SetTransientInput(DslGlobalAverageThermostericSeaLevelChangeEnum,times,N);
|
|---|
| 64 | TransientInput* transientinput = inputs->GetTransientInput(DslGlobalAverageThermostericSeaLevelChangeEnum);
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | for(Object* & object : elements->objects){
|
|---|
| 68 | Element* element=xDynamicCast<Element*>(object);
|
|---|
| 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: */
|
|---|
| 84 | iomodel->FetchDataToInput(inputs,elements,"md.dsl.sea_surface_height_change_above_geoid", DslSeaSurfaceHeightChangeAboveGeoidEnum);
|
|---|
| 85 | iomodel->FetchDataToInput(inputs,elements,"md.dsl.sea_water_pressure_change_at_sea_floor", DslSeaWaterPressureChangeAtSeaFloorEnum);
|
|---|
| 86 |
|
|---|
| 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.global_average_thermosteric_sea_level_change {{{*/
|
|---|
| 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 | TransientInput* transientinput=inputs->SetDatasetTransientInput(DslGlobalAverageThermostericSeaLevelChangeEnum,i, times,N);
|
|---|
| 114 |
|
|---|
| 115 | for(Object* & object : elements->objects){
|
|---|
| 116 | Element* element=xDynamicCast<Element*>(object);
|
|---|
| 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 | iomodel->FetchDataToInput(inputs,elements,"md.dsl.sea_surface_height_change_above_geoid",DslSeaSurfaceHeightChangeAboveGeoidEnum);
|
|---|
| 138 | iomodel->FetchDataToInput(inputs,elements,"md.dsl.sea_water_pressure_change_at_sea_floor",DslSeaWaterPressureChangeAtSeaFloorEnum);
|
|---|
| 139 |
|
|---|
| 140 | } /*}}}*/
|
|---|
| 141 | else _error_("Dsl model " << dslmodel << " not implemented yet!");
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 | /*Initialize cumdeltalthickness and sealevel rise rate input*/
|
|---|
| 146 | InputUpdateFromConstantx(inputs,elements,0.,SealevelriseCumDeltathicknessEnum);
|
|---|
| 147 | InputUpdateFromConstantx(inputs,elements,0.,SealevelNEsaRateEnum);
|
|---|
| 148 | InputUpdateFromConstantx(inputs,elements,0.,SealevelUEsaRateEnum);
|
|---|
| 149 | InputUpdateFromConstantx(inputs,elements,0.,SealevelRSLRateEnum);
|
|---|
| 150 | InputUpdateFromConstantx(inputs,elements,0.,SealevelEustaticMaskEnum);
|
|---|
| 151 | InputUpdateFromConstantx(inputs,elements,0.,SealevelEustaticOceanMaskEnum);
|
|---|
| 152 |
|
|---|
| 153 | }/*}}}*/
|
|---|
| 154 | void SealevelriseAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
|
|---|
| 155 |
|
|---|
| 156 | int nl;
|
|---|
| 157 | IssmDouble* love_h=NULL;
|
|---|
| 158 | IssmDouble* love_k=NULL;
|
|---|
| 159 | IssmDouble* love_l=NULL;
|
|---|
| 160 | IssmDouble* love_th=NULL;
|
|---|
| 161 | IssmDouble* love_tk=NULL;
|
|---|
| 162 | IssmDouble* love_tl=NULL;
|
|---|
| 163 | int dslmodel=0;
|
|---|
| 164 |
|
|---|
| 165 | IssmDouble* G_rigid = NULL;
|
|---|
| 166 | IssmDouble* G_rigid_local = NULL;
|
|---|
| 167 | IssmDouble* G_elastic = NULL;
|
|---|
| 168 | IssmDouble* G_elastic_local = NULL;
|
|---|
| 169 | IssmDouble* U_elastic = NULL;
|
|---|
| 170 | IssmDouble* U_elastic_local = NULL;
|
|---|
| 171 | IssmDouble* H_elastic = NULL;
|
|---|
| 172 | IssmDouble* H_elastic_local = NULL;
|
|---|
| 173 | int M,m,lower_row,upper_row;
|
|---|
| 174 | IssmDouble degacc=.01;
|
|---|
| 175 | IssmDouble planetradius=0;
|
|---|
| 176 | IssmDouble planetarea=0;
|
|---|
| 177 | bool rigid=false;
|
|---|
| 178 | bool elastic=false;
|
|---|
| 179 | bool rotation=false;
|
|---|
| 180 |
|
|---|
| 181 | int numoutputs;
|
|---|
| 182 | char** requestedoutputs = NULL;
|
|---|
| 183 |
|
|---|
| 184 | /*transition vectors: */
|
|---|
| 185 | IssmDouble **transitions = NULL;
|
|---|
| 186 | int *transitions_M = NULL;
|
|---|
| 187 | int *transitions_N = NULL;
|
|---|
| 188 | int ntransitions;
|
|---|
| 189 | IssmDouble* partitionice=NULL;
|
|---|
| 190 | IssmDouble* partitionhydro=NULL;
|
|---|
| 191 | IssmDouble* bslrice_partition=NULL;
|
|---|
| 192 | IssmDouble* bslrhydro_partition=NULL;
|
|---|
| 193 | int npartice,nparthydro,nel;
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 | /*some constant parameters: */
|
|---|
| 197 | parameters->AddObject(iomodel->CopyConstantObject("md.dsl.model",DslModelEnum));
|
|---|
| 198 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.runfrequency",SolidearthSettingsRunFrequencyEnum));
|
|---|
| 199 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.reltol",SolidearthSettingsReltolEnum));
|
|---|
| 200 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.abstol",SolidearthSettingsAbstolEnum));
|
|---|
| 201 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.maxiter",SolidearthSettingsMaxiterEnum));
|
|---|
| 202 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.rigid",SolidearthSettingsRigidEnum));
|
|---|
| 203 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.horiz",SolidearthSettingsHorizEnum));
|
|---|
| 204 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.elastic",SolidearthSettingsElasticEnum));
|
|---|
| 205 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.rotation",SolidearthSettingsRotationEnum));
|
|---|
| 206 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.rotational.equatorialmoi",RotationalEquatorialMoiEnum));
|
|---|
| 207 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.rotational.polarmoi",RotationalPolarMoiEnum));
|
|---|
| 208 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.rotational.angularvelocity",RotationalAngularVelocityEnum));
|
|---|
| 209 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.ocean_area_scaling",SolidearthSettingsOceanAreaScalingEnum));
|
|---|
| 210 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.computesealevelchange",SolidearthSettingsComputesealevelchangeEnum));
|
|---|
| 211 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.isgrd",SolidearthSettingsGRDEnum));
|
|---|
| 212 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.planetradius",SolidearthPlanetRadiusEnum));
|
|---|
| 213 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.settings.glfraction",SolidearthSettingsGlfractionEnum));
|
|---|
| 214 | parameters->AddObject(new DoubleParam(CumBslrEnum,0.0));
|
|---|
| 215 | parameters->AddObject(new DoubleParam(CumBslrIceEnum,0.0));
|
|---|
| 216 | parameters->AddObject(new DoubleParam(CumBslrHydroEnum,0.0));
|
|---|
| 217 | parameters->AddObject(new DoubleParam(CumGmtslrEnum,0.0));
|
|---|
| 218 |
|
|---|
| 219 | /*compute planet area and plug into parameters:*/
|
|---|
| 220 | iomodel->FetchData(&planetradius,"md.solidearth.planetradius");
|
|---|
| 221 | planetarea=4*PI*planetradius*planetradius;
|
|---|
| 222 | parameters->AddObject(new DoubleParam(SolidearthPlanetAreaEnum,planetarea));
|
|---|
| 223 |
|
|---|
| 224 | /*Deal with partition of the barystatic contribution:*/
|
|---|
| 225 | iomodel->FetchData(&npartice,"md.solidearth.npartice");
|
|---|
| 226 | parameters->AddObject(new IntParam(SolidearthNpartIceEnum,npartice));
|
|---|
| 227 | if(npartice){
|
|---|
| 228 | iomodel->FetchData(&partitionice,&nel,NULL,"md.solidearth.partitionice");
|
|---|
| 229 | parameters->AddObject(new DoubleMatParam(SolidearthPartitionIceEnum,partitionice,nel,1));
|
|---|
| 230 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.npartice",SolidearthNpartIceEnum));
|
|---|
| 231 | bslrice_partition=xNewZeroInit<IssmDouble>(npartice);
|
|---|
| 232 | parameters->AddObject(new DoubleMatParam(CumBslrIcePartitionEnum,bslrice_partition,npartice,1));
|
|---|
| 233 | xDelete<IssmDouble>(partitionice);
|
|---|
| 234 | }
|
|---|
| 235 | iomodel->FetchData(&nparthydro,"md.solidearth.nparthydro");
|
|---|
| 236 | parameters->AddObject(new IntParam(SolidearthNpartHydroEnum,nparthydro));
|
|---|
| 237 | if(nparthydro){
|
|---|
| 238 | iomodel->FetchData(&partitionhydro,&nel,NULL,"md.solidearth.partitionhydro");
|
|---|
| 239 | parameters->AddObject(new DoubleMatParam(SolidearthPartitionHydroEnum,partitionhydro,nel,1));
|
|---|
| 240 | parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.nparthydro",SolidearthNpartHydroEnum));
|
|---|
| 241 | bslrhydro_partition=xNewZeroInit<IssmDouble>(nparthydro);
|
|---|
| 242 | parameters->AddObject(new DoubleMatParam(CumBslrHydroPartitionEnum,bslrhydro_partition,nparthydro,1));
|
|---|
| 243 | xDelete<IssmDouble>(partitionhydro);
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | /*Deal with dsl multi-model ensembles: {{{*/
|
|---|
| 247 | iomodel->FetchData(&dslmodel,"md.dsl.model");
|
|---|
| 248 | parameters->AddObject(iomodel->CopyConstantObject("md.dsl.compute_fingerprints",DslComputeFingerprintsEnum));
|
|---|
| 249 | if(dslmodel==2){
|
|---|
| 250 | IssmDouble modelid;
|
|---|
| 251 | int nummodels;
|
|---|
| 252 |
|
|---|
| 253 | /*create double param, not int param, because Dakota will be updating it as
|
|---|
| 254 | * a double potentially: */
|
|---|
| 255 | iomodel->FetchData(&modelid,"md.dsl.modelid");
|
|---|
| 256 | parameters->AddObject(new DoubleParam(DslModelidEnum,modelid));
|
|---|
| 257 | parameters->AddObject(iomodel->CopyConstantObject("md.dsl.nummodels",DslNummodelsEnum));
|
|---|
| 258 | iomodel->FetchData(&nummodels,"md.dsl.nummodels");
|
|---|
| 259 |
|
|---|
| 260 | /*quick checks: */
|
|---|
| 261 | if(nummodels<=0)_error_("dslmme object in md.dsl field should contain at least 1 ensemble model!");
|
|---|
| 262 | 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!");
|
|---|
| 263 | } /*}}}*/
|
|---|
| 264 | /*Deal with elasticity {{{*/
|
|---|
| 265 | iomodel->FetchData(&rigid,"md.solidearth.settings.rigid");
|
|---|
| 266 | iomodel->FetchData(&elastic,"md.solidearth.settings.elastic");
|
|---|
| 267 | iomodel->FetchData(&rotation,"md.solidearth.settings.rotation");
|
|---|
| 268 |
|
|---|
| 269 | if(elastic | rigid){
|
|---|
| 270 | /*compute green functions for a range of angles*/
|
|---|
| 271 | iomodel->FetchData(°acc,"md.solidearth.settings.degacc");
|
|---|
| 272 | M=reCast<int,IssmDouble>(180./degacc+1.);
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | /*love numbers: */
|
|---|
| 276 | if(elastic){
|
|---|
| 277 | iomodel->FetchData(&love_h,&nl,NULL,"md.solidearth.lovenumbers.h");
|
|---|
| 278 | iomodel->FetchData(&love_k,&nl,NULL,"md.solidearth.lovenumbers.k");
|
|---|
| 279 | iomodel->FetchData(&love_l,&nl,NULL,"md.solidearth.lovenumbers.l");
|
|---|
| 280 | iomodel->FetchData(&love_th,&nl,NULL,"md.solidearth.lovenumbers.th");
|
|---|
| 281 | iomodel->FetchData(&love_tk,&nl,NULL,"md.solidearth.lovenumbers.tk");
|
|---|
| 282 | iomodel->FetchData(&love_tl,&nl,NULL,"md.solidearth.lovenumbers.tl");
|
|---|
| 283 |
|
|---|
| 284 | parameters->AddObject(new DoubleMatParam(LoadLoveHEnum,love_h,nl,1));
|
|---|
| 285 | parameters->AddObject(new DoubleMatParam(LoadLoveKEnum,love_k,nl,1));
|
|---|
| 286 | parameters->AddObject(new DoubleMatParam(LoadLoveLEnum,love_l,nl,1));
|
|---|
| 287 | parameters->AddObject(new DoubleMatParam(TidalLoveHEnum,love_th,nl,1));
|
|---|
| 288 | parameters->AddObject(new DoubleMatParam(TidalLoveKEnum,love_tk,nl,1));
|
|---|
| 289 | parameters->AddObject(new DoubleMatParam(TidalLoveLEnum,love_tl,nl,1));
|
|---|
| 290 |
|
|---|
| 291 | // AD performance is sensitive to calls to ensurecontiguous.
|
|---|
| 292 | // // Providing "t" will cause ensurecontiguous to be called.
|
|---|
| 293 | #ifdef _HAVE_AD_
|
|---|
| 294 | G_elastic=xNew<IssmDouble>(M,"t");
|
|---|
| 295 | U_elastic=xNew<IssmDouble>(M,"t");
|
|---|
| 296 | H_elastic=xNew<IssmDouble>(M,"t");
|
|---|
| 297 | #else
|
|---|
| 298 | G_elastic=xNew<IssmDouble>(M);
|
|---|
| 299 | U_elastic=xNew<IssmDouble>(M);
|
|---|
| 300 | H_elastic=xNew<IssmDouble>(M);
|
|---|
| 301 | #endif
|
|---|
| 302 | }
|
|---|
| 303 | if(rigid){
|
|---|
| 304 | #ifdef _HAVE_AD_
|
|---|
| 305 | G_rigid=xNew<IssmDouble>(M,"t");
|
|---|
| 306 | #else
|
|---|
| 307 | G_rigid=xNew<IssmDouble>(M);
|
|---|
| 308 | #endif
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | if(rotation)parameters->AddObject(iomodel->CopyConstantObject("md.solidearth.lovenumbers.tk2secular",TidalLoveK2SecularEnum));
|
|---|
| 312 |
|
|---|
| 313 | if(rigid | elastic){
|
|---|
| 314 |
|
|---|
| 315 | /*compute combined legendre + love number (elastic green function:*/
|
|---|
| 316 | m=DetermineLocalSize(M,IssmComm::GetComm());
|
|---|
| 317 | GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,IssmComm::GetComm());
|
|---|
| 318 | }
|
|---|
| 319 | if(elastic){
|
|---|
| 320 | #ifdef _HAVE_AD_
|
|---|
| 321 | G_elastic_local=xNew<IssmDouble>(m,"t");
|
|---|
| 322 | U_elastic_local=xNew<IssmDouble>(m,"t");
|
|---|
| 323 | H_elastic_local=xNew<IssmDouble>(m,"t");
|
|---|
| 324 | #else
|
|---|
| 325 | G_elastic_local=xNew<IssmDouble>(m);
|
|---|
| 326 | U_elastic_local=xNew<IssmDouble>(m);
|
|---|
| 327 | H_elastic_local=xNew<IssmDouble>(m);
|
|---|
| 328 | #endif
|
|---|
| 329 | }
|
|---|
| 330 | if(rigid){
|
|---|
| 331 | #ifdef _HAVE_AD_
|
|---|
| 332 | G_rigid_local=xNew<IssmDouble>(m,"t");
|
|---|
| 333 | #else
|
|---|
| 334 | G_rigid_local=xNew<IssmDouble>(m);
|
|---|
| 335 | #endif
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | if(rigid){
|
|---|
| 339 | for(int i=lower_row;i<upper_row;i++){
|
|---|
| 340 | IssmDouble alpha,x;
|
|---|
| 341 | alpha= reCast<IssmDouble>(i)*degacc * PI / 180.0;
|
|---|
| 342 | G_rigid_local[i-lower_row]= .5/sin(alpha/2.0);
|
|---|
| 343 | }
|
|---|
| 344 | }
|
|---|
| 345 | if(elastic){
|
|---|
| 346 | for(int i=lower_row;i<upper_row;i++){
|
|---|
| 347 | IssmDouble alpha,x;
|
|---|
| 348 | alpha= reCast<IssmDouble>(i)*degacc * PI / 180.0;
|
|---|
| 349 |
|
|---|
| 350 | G_elastic_local[i-lower_row]= (love_k[nl-1]-love_h[nl-1])*G_rigid_local[i-lower_row];
|
|---|
| 351 | U_elastic_local[i-lower_row]= (love_h[nl-1])*G_rigid_local[i-lower_row];
|
|---|
| 352 | H_elastic_local[i-lower_row]= 0;
|
|---|
| 353 | IssmDouble Pn = 0.;
|
|---|
| 354 | IssmDouble Pn1 = 0.;
|
|---|
| 355 | IssmDouble Pn2 = 0.;
|
|---|
| 356 | IssmDouble Pn_p = 0.;
|
|---|
| 357 | IssmDouble Pn_p1 = 0.;
|
|---|
| 358 | IssmDouble Pn_p2 = 0.;
|
|---|
| 359 |
|
|---|
| 360 | for (int n=0;n<nl;n++) {
|
|---|
| 361 | IssmDouble deltalove_G;
|
|---|
| 362 | IssmDouble deltalove_U;
|
|---|
| 363 |
|
|---|
| 364 | deltalove_G = (love_k[n]-love_k[nl-1]-love_h[n]+love_h[nl-1]);
|
|---|
| 365 | deltalove_U = (love_h[n]-love_h[nl-1]);
|
|---|
| 366 |
|
|---|
| 367 | /*compute legendre polynomials: P_n(cos\theta) & d P_n(cos\theta)/ d\theta: */
|
|---|
| 368 | if(n==0){
|
|---|
| 369 | Pn=1;
|
|---|
| 370 | Pn_p=0;
|
|---|
| 371 | }
|
|---|
| 372 | else if(n==1){
|
|---|
| 373 | Pn = cos(alpha);
|
|---|
| 374 | Pn_p = 1;
|
|---|
| 375 | }
|
|---|
| 376 | else{
|
|---|
| 377 | Pn = ( (2*n-1)*cos(alpha)*Pn1 - (n-1)*Pn2 ) /n;
|
|---|
| 378 | Pn_p = ( (2*n-1)*(Pn1+cos(alpha)*Pn_p1) - (n-1)*Pn_p2 ) /n;
|
|---|
| 379 | }
|
|---|
| 380 | Pn2=Pn1; Pn1=Pn;
|
|---|
| 381 | Pn_p2=Pn_p1; Pn_p1=Pn_p;
|
|---|
| 382 |
|
|---|
| 383 | G_elastic_local[i-lower_row] += deltalove_G*Pn; // gravitational potential
|
|---|
| 384 | U_elastic_local[i-lower_row] += deltalove_U*Pn; // vertical (up) displacement
|
|---|
| 385 | H_elastic_local[i-lower_row] += sin(alpha)*love_l[n]*Pn_p; // horizontal displacements
|
|---|
| 386 | }
|
|---|
| 387 | }
|
|---|
| 388 | }
|
|---|
| 389 | if(rigid){
|
|---|
| 390 |
|
|---|
| 391 | /*merge G_elastic_local into G_elastic; U_elastic_local into U_elastic; H_elastic_local to H_elastic:{{{*/
|
|---|
| 392 | int* recvcounts=xNew<int>(IssmComm::GetSize());
|
|---|
| 393 | int* displs=xNew<int>(IssmComm::GetSize());
|
|---|
| 394 |
|
|---|
| 395 | //recvcounts:
|
|---|
| 396 | ISSM_MPI_Allgather(&m,1,ISSM_MPI_INT,recvcounts,1,ISSM_MPI_INT,IssmComm::GetComm());
|
|---|
| 397 |
|
|---|
| 398 | /*displs: */
|
|---|
| 399 | ISSM_MPI_Allgather(&lower_row,1,ISSM_MPI_INT,displs,1,ISSM_MPI_INT,IssmComm::GetComm());
|
|---|
| 400 |
|
|---|
| 401 | /*All gather:*/
|
|---|
| 402 | ISSM_MPI_Allgatherv(G_rigid_local, m, ISSM_MPI_DOUBLE, G_rigid, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
|---|
| 403 | if(elastic){
|
|---|
| 404 | ISSM_MPI_Allgatherv(G_elastic_local, m, ISSM_MPI_DOUBLE, G_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
|---|
| 405 | ISSM_MPI_Allgatherv(U_elastic_local, m, ISSM_MPI_DOUBLE, U_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
|---|
| 406 | ISSM_MPI_Allgatherv(H_elastic_local, m, ISSM_MPI_DOUBLE, H_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
|---|
| 407 | }
|
|---|
| 408 |
|
|---|
| 409 | /*free resources: */
|
|---|
| 410 | xDelete<int>(recvcounts);
|
|---|
| 411 | xDelete<int>(displs);
|
|---|
| 412 |
|
|---|
| 413 | /*Avoid singularity at 0: */
|
|---|
| 414 | G_rigid[0]=G_rigid[1];
|
|---|
| 415 | if(elastic){
|
|---|
| 416 | G_elastic[0]=G_elastic[1];
|
|---|
| 417 | U_elastic[0]=U_elastic[1];
|
|---|
| 418 | H_elastic[0]=H_elastic[1];
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 | /*Save our precomputed tables into parameters*/
|
|---|
| 423 | parameters->AddObject(new DoubleVecParam(SealevelriseGRigidEnum,G_rigid,M));
|
|---|
| 424 | if(elastic){
|
|---|
| 425 | parameters->AddObject(new DoubleVecParam(SealevelriseGElasticEnum,G_elastic,M));
|
|---|
| 426 | parameters->AddObject(new DoubleVecParam(SealevelriseUElasticEnum,U_elastic,M));
|
|---|
| 427 | parameters->AddObject(new DoubleVecParam(SealevelriseHElasticEnum,H_elastic,M));
|
|---|
| 428 | }
|
|---|
| 429 |
|
|---|
| 430 | /*free resources: */
|
|---|
| 431 | xDelete<IssmDouble>(G_rigid);
|
|---|
| 432 | xDelete<IssmDouble>(G_rigid_local);
|
|---|
| 433 | if(elastic){
|
|---|
| 434 | xDelete<IssmDouble>(love_h);
|
|---|
| 435 | xDelete<IssmDouble>(love_k);
|
|---|
| 436 | xDelete<IssmDouble>(love_l);
|
|---|
| 437 | xDelete<IssmDouble>(love_th);
|
|---|
| 438 | xDelete<IssmDouble>(love_tk);
|
|---|
| 439 | xDelete<IssmDouble>(love_tl);
|
|---|
| 440 | xDelete<IssmDouble>(G_elastic);
|
|---|
| 441 | xDelete<IssmDouble>(G_elastic_local);
|
|---|
| 442 | xDelete<IssmDouble>(U_elastic);
|
|---|
| 443 | xDelete<IssmDouble>(U_elastic_local);
|
|---|
| 444 | xDelete<IssmDouble>(H_elastic);
|
|---|
| 445 | xDelete<IssmDouble>(H_elastic_local);
|
|---|
| 446 | }
|
|---|
| 447 | } /*}}}*/
|
|---|
| 448 |
|
|---|
| 449 | /*Indicate we have not yet run the Geometry Core module: */
|
|---|
| 450 | parameters->AddObject(new BoolParam(SealevelriseGeometryDoneEnum,false));
|
|---|
| 451 | /*}}}*/
|
|---|
| 452 |
|
|---|
| 453 | /*Transitions:{{{ */
|
|---|
| 454 | iomodel->FetchData(&transitions,&transitions_M,&transitions_N,&ntransitions,"md.solidearth.transitions");
|
|---|
| 455 | if(transitions){
|
|---|
| 456 | parameters->AddObject(new DoubleMatArrayParam(SealevelriseTransitionsEnum,transitions,ntransitions,transitions_M,transitions_N));
|
|---|
| 457 |
|
|---|
| 458 | for(int i=0;i<ntransitions;i++){
|
|---|
| 459 | IssmDouble* transition=transitions[i];
|
|---|
| 460 | xDelete<IssmDouble>(transition);
|
|---|
| 461 | }
|
|---|
| 462 | xDelete<IssmDouble*>(transitions);
|
|---|
| 463 | xDelete<int>(transitions_M);
|
|---|
| 464 | xDelete<int>(transitions_N);
|
|---|
| 465 | } /*}}}*/
|
|---|
| 466 | /*Requested outputs {{{*/
|
|---|
| 467 | iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.solidearth.requested_outputs");
|
|---|
| 468 | if(numoutputs)parameters->AddObject(new StringArrayParam(SealevelriseRequestedOutputsEnum,requestedoutputs,numoutputs));
|
|---|
| 469 | iomodel->DeleteData(&requestedoutputs,numoutputs,"md.solidearth.requested_outputs");
|
|---|
| 470 | /*}}}*/
|
|---|
| 471 |
|
|---|
| 472 | }/*}}}*/
|
|---|
| 473 |
|
|---|
| 474 | /*Finite Element Analysis*/
|
|---|
| 475 | void SealevelriseAnalysis::Core(FemModel* femmodel){/*{{{*/
|
|---|
| 476 | _error_("not implemented");
|
|---|
| 477 | }/*}}}*/
|
|---|
| 478 | ElementVector* SealevelriseAnalysis::CreateDVector(Element* element){/*{{{*/
|
|---|
| 479 | /*Default, return NULL*/
|
|---|
| 480 | return NULL;
|
|---|
| 481 | }/*}}}*/
|
|---|
| 482 | ElementMatrix* SealevelriseAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
|---|
| 483 | _error_("Not implemented");
|
|---|
| 484 | }/*}}}*/
|
|---|
| 485 | ElementMatrix* SealevelriseAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
|---|
| 486 | _error_("not implemented yet");
|
|---|
| 487 | }/*}}}*/
|
|---|
| 488 | ElementVector* SealevelriseAnalysis::CreatePVector(Element* element){/*{{{*/
|
|---|
| 489 | _error_("not implemented yet");
|
|---|
| 490 | }/*}}}*/
|
|---|
| 491 | void SealevelriseAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
|---|
| 492 | _error_("not implemented yet");
|
|---|
| 493 | }/*}}}*/
|
|---|
| 494 | void SealevelriseAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_interp,int control_index){/*{{{*/
|
|---|
| 495 | _error_("Not implemented yet");
|
|---|
| 496 | }/*}}}*/
|
|---|
| 497 | void SealevelriseAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
|---|
| 498 | _error_("not implemeneted yet!");
|
|---|
| 499 |
|
|---|
| 500 | }/*}}}*/
|
|---|
| 501 | void SealevelriseAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
|---|
| 502 | /*Default, do nothing*/
|
|---|
| 503 | return;
|
|---|
| 504 | }/*}}}*/
|
|---|