source: issm/oecreview/Archive/19101-20495/ISSM-20135-20136.diff@ 20498

Last change on this file since 20498 was 20498, checked in by Mathieu Morlighem, 9 years ago

CHG: done with Archive/19101-20495

File size: 15.4 KB
  • ../trunk-jpl/src/c/analyses/SealevelriseAnalysis.cpp

     
    5151        int     numoutputs;
    5252        char**  requestedoutputs = NULL;
    5353
     54        /*transition vectors: */
     55        IssmDouble **transitions    = NULL;
     56        int         *transitions_M    = NULL;
     57        int         *transitions_N    = NULL;
     58        int          ntransitions;
     59
    5460        /*some constant parameters: */
    5561        parameters->AddObject(iomodel->CopyConstantObject(SealevelriseReltolEnum));
    5662        parameters->AddObject(iomodel->CopyConstantObject(SealevelriseAbstolEnum));
     
    125131                xDelete<IssmDouble>(G_elastic_local);
    126132        }
    127133       
     134        /*Transitions: */
     135        iomodel->FetchData(&transitions,&transitions_M,&transitions_N,&ntransitions,SealevelriseTransitionsEnum);
     136        if(transitions){
     137                parameters->AddObject(new DoubleMatArrayParam(SealevelriseTransitionsEnum,transitions,ntransitions,transitions_M,transitions_N));
     138
     139                for(int i=0;i<ntransitions;i++){
     140                        IssmDouble* transition=transitions[i];
     141                        xDelete<IssmDouble>(transition);
     142                }
     143                xDelete<IssmDouble*>(transitions);
     144                xDelete<IssmDouble*>(transitions_M);
     145                xDelete<IssmDouble*>(transitions_N);
     146        }
     147
    128148        /*Requested outputs*/
    129149        iomodel->FetchData(&requestedoutputs,&numoutputs,SealevelriseRequestedOutputsEnum);
    130150        parameters->AddObject(new IntParam(SealevelriseNumRequestedOutputsEnum,numoutputs));
  • ../trunk-jpl/src/c/cores/transient_core.cpp

     
    2020
    2121        /*parameters: */
    2222        IssmDouble starttime,finaltime,dt,yts;
    23         bool       isstressbalance,ismasstransport,issmb,isFS,isthermal,isgroundingline,isgia,islevelset,isdamageevolution,ishydrology,iscalving;
     23        bool       isstressbalance,ismasstransport,issmb,isFS,isthermal,isgroundingline,isgia,isslr,iscoupler,islevelset,isdamageevolution,ishydrology,iscalving;
    2424        bool       save_results,dakota_analysis;
    2525        bool       time_adapt;
    2626        int        output_frequency;
     
    5050        femmodel->parameters->FindParam(&issmb,TransientIssmbEnum);
    5151        femmodel->parameters->FindParam(&isthermal,TransientIsthermalEnum);
    5252        femmodel->parameters->FindParam(&isgia,TransientIsgiaEnum);
     53        femmodel->parameters->FindParam(&isslr,TransientIsslrEnum);
     54        femmodel->parameters->FindParam(&iscoupler,TransientIscouplerEnum);
    5355        femmodel->parameters->FindParam(&isgroundingline,TransientIsgroundinglineEnum);
    5456        femmodel->parameters->FindParam(&islevelset,TransientIslevelsetEnum);
    5557        femmodel->parameters->FindParam(&isdamageevolution,TransientIsdamageevolutionEnum);
     
    140142                        #endif
    141143                }
    142144
     145                /*Sea level rise: */
     146                if(isslr | iscoupler) sealevelrise_core(femmodel);
     147
    143148                /*unload results*/
    144149                if(VerboseSolution()) _printf0_("   computing requested outputs\n");
    145150                femmodel->RequestedOutputsx(&femmodel->results,requested_outputs,numoutputs,save_results);
  • ../trunk-jpl/src/c/cores/cores.h

     
    4949void smb_core(FemModel* femmodel);
    5050void damage_core(FemModel* femmodel);
    5151void sealevelrise_core(FemModel* femmodel);
    52 Vector<IssmDouble> * sealevelrise_core_eustatic(FemModel* femmodel);
    53 Vector<IssmDouble> * sealevelrise_core_noneustatic(FemModel* femmodel,Vector<IssmDouble>* Sg_eustatic);
     52Vector<IssmDouble>* sealevelrise_core_eustatic(FemModel* femmodel);
     53Vector<IssmDouble>* sealevelrise_core_noneustatic(FemModel* femmodel,Vector<IssmDouble>* Sg_eustatic);
    5454IssmDouble objectivefunction(IssmDouble search_scalar,FemModel* femmodel);
    5555
    5656//optimization
     
    6161void WriteLockFile(char* filename);
    6262void ResetBoundaryConditions(FemModel* femmodel, int analysis_type);
    6363void PrintBanner(void);
     64void TransferForcing(FemModel* femmodel,int forcingenum);
     65void TransferSealevel(FemModel* femmodel,int forcingenum);
    6466
    6567//solution configuration
    6668void CorePointerFromSolutionEnum(void (**psolutioncore)(FemModel*),Parameters* parameters,int solutiontype);
  • ../trunk-jpl/src/c/cores/sealevelrise_core.cpp

     
    99#include "../modules/modules.h"
    1010#include "../solutionsequences/solutionsequences.h"
    1111
    12 void sealevelrise_core(FemModel* femmodel){
     12void sealevelrise_core(FemModel* femmodel){ /*{{{*/
    1313
    1414        Vector<IssmDouble> *Sg    = NULL;
    1515        Vector<IssmDouble> *Sg_eustatic    = NULL;
    16         bool save_results;
     16        bool save_results,isslr,iscoupler;
    1717        int configuration_type;
     18        int solution_type;
    1819        int        numoutputs        = 0;
    1920        char     **requested_outputs = NULL;
    20 
    21         if(VerboseSolution()) _printf0_("   computing sea level rise\n");
    22 
     21       
    2322        /*Recover some parameters: */
    2423        femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
     24        femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
    2525        femmodel->parameters->FindParam(&save_results,SaveResultsEnum);
    26         femmodel->parameters->FindParam(&numoutputs,SealevelriseNumRequestedOutputsEnum);
    27         if(numoutputs) femmodel->parameters->FindParam(&requested_outputs,&numoutputs,SealevelriseRequestedOutputsEnum);
     26        femmodel->parameters->FindParam(&isslr,TransientIsslrEnum);
     27        femmodel->parameters->FindParam(&iscoupler,TransientIscouplerEnum);
    2828
     29        /*several cases here, depending on value of iscoupler and isslr:
     30        ( !iscoupler & !isslr)       we are not interested in being here :)
     31        ( !iscoupler & isslr)        we are running in uncoupled mode
     32        ( iscoupler & isslr)         we are running in coupled mode, and better be earth
     33        ( iscoupler & !isslr)        we are running in coupled mode, and better be an ice cap
     34        */
     35
     36        /*early return: */
     37        if( !iscoupler & !isslr) return;  //we are not interested in being here :)
     38
     39        /*In what follows we assume we are all running slr, either in coupled, or uncoupled mode:*/
     40        if(VerboseSolution()) _printf0_("   computing sea level rise\n");
     41
    2942        /*set configuration: */
    30         femmodel->SetCurrentConfiguration(SealevelriseAnalysisEnum);
     43        if(isslr)femmodel->SetCurrentConfiguration(SealevelriseAnalysisEnum);
    3144
    32         /*call two sub cores:*/
    33         Sg_eustatic=sealevelrise_core_eustatic(femmodel); //generalized eustatic (Farrel and Clark, Eq 4, 1st, 3rd and 4rd terms on the RHS.
     45        /*transfer deltathickness forcing from ice caps to earth model: */
     46        if(iscoupler) TransferForcing(femmodel,SealevelriseDeltathicknessEnum);
    3447
    35         Sg=sealevelrise_core_noneustatic(femmodel,Sg_eustatic); //sea-level rise dependent terms (2nd and 5th terms on the RHS)
     48        /*call sea-level rise sub cores:*/
     49        if(isslr){
     50                Sg_eustatic=sealevelrise_core_eustatic(femmodel); //generalized eustatic (Farrel and Clark, Eq 4, 1st, 3rd and 4rd terms on the RHS.
    3651
    37         /*get results out:*/
    38         InputUpdateFromVectorx(femmodel,Sg,SealevelriseSEnum,VertexSIdEnum);
     52                Sg=sealevelrise_core_noneustatic(femmodel,Sg_eustatic); //sea-level rise dependent terms (2nd and 5th terms on the RHS)
    3953
    40         if(save_results){
    41                 if(VerboseSolution()) _printf0_("   saving results\n");
    42                 femmodel->RequestedOutputsx(&femmodel->results,requested_outputs,numoutputs);
     54                /*get results into elements:*/
     55                InputUpdateFromVectorx(femmodel,Sg,SealevelriseSEnum,VertexSIdEnum);
     56
     57                if(save_results){
     58                        if(VerboseSolution()) _printf0_("   saving results\n");
     59                        femmodel->parameters->FindParam(&requested_outputs,&numoutputs,SealevelriseRequestedOutputsEnum);
     60                        femmodel->RequestedOutputsx(&femmodel->results,requested_outputs,numoutputs);
     61                }
     62
     63                if(solution_type==SealevelriseSolutionEnum)femmodel->RequestedDependentsx();
     64
     65                /*Free ressources:*/   
     66                delete Sg;
     67                delete Sg_eustatic;
     68                if(numoutputs){for(int i=0;i<numoutputs;i++){xDelete<char>(requested_outputs[i]);} xDelete<char*>(requested_outputs);}
    4369        }
     70
     71        /*transfer sea-level back to ice caps: */
     72        if(iscoupler)TransferSealevel(femmodel,SealevelriseSEnum);
     73}
     74/*}}}*/
     75void TransferForcing(FemModel* femmodel,int forcingenum){ /*{{{*/
     76
     77        /*forcing being transferred from models to earth: */
     78        IssmDouble** forcings=NULL;
     79        IssmDouble*  forcing=NULL;
     80        Vector<IssmDouble>* forcingglobal=NULL;
     81        int*         nvs=NULL;
    4482       
    45         /*Free ressources:*/   
    46         if(numoutputs){for(int i=0;i<numoutputs;i++){xDelete<char>(requested_outputs[i]);} xDelete<char*>(requested_outputs);}
    47         delete Sg;
    48         delete Sg_eustatic;
     83        /*transition vectors:*/
     84        IssmDouble** transitions=NULL;
     85        int          ntransitions;
     86        int*         transitions_m=NULL;
     87        int*         transitions_n=NULL;
     88        int          nv;
     89       
     90        /*communicators:*/
     91        ISSM_MPI_Comm tocomm;
     92        ISSM_MPI_Comm* fromcomms=NULL;
     93        ISSM_MPI_Status status;
     94        int         my_rank;
     95        int         modelid,earthid;
     96        int         nummodels;
    4997
     98        /*Recover some parameters: */
     99        femmodel->parameters->FindParam(&modelid,ModelIdEnum);
     100        femmodel->parameters->FindParam(&earthid,EarthIdEnum);
     101        femmodel->parameters->FindParam(&nummodels,NumModelsEnum);
     102        my_rank=IssmComm::GetRank();
     103       
     104        /*retrieve the inter communicators that will be used to send data from each ice cap to the earth: */
     105        if(modelid==earthid)femmodel->parameters->FindParam(&fromcomms,&nv,IcecapToEarthCommEnum);
     106        else femmodel->parameters->FindParam(&tocomm, IcecapToEarthCommEnum);
    50107
    51 }
     108        /*For each icecap, retrieve the forcing vector that will be sent to the earth model: */
     109        if(modelid!=earthid){
     110                nv=femmodel->vertices->NumberOfVertices();
     111                GetVectorFromInputsx(&forcing,femmodel,forcingenum,VertexSIdEnum);
     112        }
     113
     114        /*Send the forcing to the earth model:{{{*/
     115        if(my_rank==0){
     116                if(modelid==earthid){
     117                        forcings=xNew<IssmDouble*>(nummodels-1);
     118                        nvs=xNew<int>(nummodels-1);
     119                        for(int i=0;i<earthid;i++){
     120                                MPI_Recv(nvs+i, 1, ISSM_MPI_INT, 0,i, fromcomms[i], &status);
     121                                forcings[i]=xNew<IssmDouble>(nvs[i]);
     122                                MPI_Recv(forcings[i], nvs[i], ISSM_MPI_DOUBLE, 0,i, fromcomms[i], &status);
     123                        }
     124                       
     125                }
     126                else{
     127                        ISSM_MPI_Send(&nv, 1, ISSM_MPI_INT, 0, modelid, tocomm);
     128                        ISSM_MPI_Send(forcing, nv, ISSM_MPI_DOUBLE, 0, modelid, tocomm);
     129                }
     130        }
     131        /*}}}*/
     132
     133        /*On the earth model, consolidate all the forcings into one, and update the elements dataset accordingly: {{{*/
     134        if(modelid==earthid){
     135               
     136                /*Out of all the delta thicknesses, build one delta thickness vector made of all the ice cap contributions.
     137                 *First, build the global delta thickness vector in the earth model: */
     138                nv=femmodel->vertices->NumberOfVertices();
     139                forcingglobal= new Vector<IssmDouble>(nv);
     140
     141                /*Retrieve transition vectors, used to plug from each ice cap into the global forcing:*/
     142                femmodel->parameters->FindParam(&transitions,&ntransitions,&transitions_m,&transitions_n,SealevelriseTransitionsEnum);
     143
     144                if(ntransitions!=earthid)_error_("TransferForcing error message: number of transition vectors is not equal to the number of icecaps!");
     145
     146                /*Go through all the delta thicknesses coming from each ice cap: */
     147                if(my_rank==0){
     148                        for(int i=0;i<earthid;i++){
     149
     150                                IssmDouble* forcingfromcap= forcings[i]; //careful, this only exists on rank 0 of the earth model!
     151                                IssmDouble* transition=transitions[i];
     152                                int         M=transitions_m[i];
     153
     154                                /*build index to plug values: */
     155                                int*        index=xNew<int>(M); for(int i=0;i<M;i++)index[i]=reCast<int>(transition[i])-1; //matlab indexing!
     156
     157
     158                                /*We are going to plug this vector into the earth model, at the right vertices corresponding to this particular
     159                                 * ice cap: */
     160                                forcingglobal->SetValues(M,index,forcingfromcap,INS_VAL);
     161                                xDelete<int>(index);
     162                        }
     163                }
     164
     165                /*Assemble vector:*/
     166                forcingglobal->Assemble();
     167               
     168                /*Plug into elements:*/
     169                InputUpdateFromVectorx(femmodel,forcingglobal,forcingenum,VertexSIdEnum);
     170        }
     171        /*}}}*/
     172
     173        /*Free ressources:{{{*/
     174        if(forcings){
     175                for(int i=0;i<nummodels-1;i++){
     176                        IssmDouble* temp=forcings[i]; xDelete<IssmDouble>(temp);
     177                }
     178                xDelete<IssmDouble*>(forcings);
     179        }
     180        if(forcing)xDelete<IssmDouble>(forcing);
     181        if(forcingglobal)delete forcingglobal;
     182        if(transitions){
     183                for(int i=0;i<earthid;i++){
     184                        IssmDouble* temp=transitions[i];
     185                        xDelete<IssmDouble>(temp);
     186                }
     187                xDelete<IssmDouble*>(transitions);
     188                xDelete<int>(transitions_m);
     189                xDelete<int>(transitions_n);
     190        }
     191        if(nvs)xDelete<int>(nvs);
     192        /*}}}*/
     193
     194} /*}}}*/
     195void TransferSealevel(FemModel* femmodel,int forcingenum){ /*{{{*/
     196
     197        /*forcing being transferred from earth to ice caps: */
     198        IssmDouble*  forcing=NULL;
     199        IssmDouble*  forcingglobal=NULL;
     200       
     201        /*transition vectors:*/
     202        IssmDouble** transitions=NULL;
     203        int          ntransitions;
     204        int*         transitions_m=NULL;
     205        int*         transitions_n=NULL;
     206        int          nv;
     207       
     208        /*communicators:*/
     209        ISSM_MPI_Comm fromcomm;
     210        ISSM_MPI_Comm* tocomms=NULL;
     211        ISSM_MPI_Status status;
     212        int         my_rank;
     213        int         modelid,earthid;
     214        int         nummodels;
     215        int         numcoms;
     216
     217        /*Recover some parameters: */
     218        femmodel->parameters->FindParam(&modelid,ModelIdEnum);
     219        femmodel->parameters->FindParam(&earthid,EarthIdEnum);
     220        femmodel->parameters->FindParam(&nummodels,NumModelsEnum);
     221        my_rank=IssmComm::GetRank();
     222       
     223        /*retrieve the inter communicators that will be used to send data from earth to ice caps:*/
     224        if(modelid==earthid)femmodel->parameters->FindParam(&tocomms,&numcoms,IcecapToEarthCommEnum);
     225        else femmodel->parameters->FindParam(&fromcomm, IcecapToEarthCommEnum);
     226
     227
     228        /*Retrieve sea-level on earth model: */
     229        if(modelid==earthid){
     230                nv=femmodel->vertices->NumberOfVertices();
     231                GetVectorFromInputsx(&forcingglobal,femmodel,forcingenum,VertexSIdEnum);
     232        }
     233
     234        /*Send the forcing to the ice caps:{{{*/
     235        if(my_rank==0){
     236               
     237                if(modelid==earthid){
     238                       
     239                        /*Retrieve transition vectors, used to figure out global forcing contribution to each ice cap's own elements: */
     240                        femmodel->parameters->FindParam(&transitions,&ntransitions,&transitions_m,&transitions_n,SealevelriseTransitionsEnum);
     241                       
     242                        if(ntransitions!=earthid)_error_("TransferSeaLevel error message: number of transition vectors is not equal to the number of icecaps!");
     243
     244                        for(int i=0;i<earthid;i++){
     245                                nv=transitions_m[i];
     246                                forcing=xNew<IssmDouble>(nv);
     247                                IssmDouble* transition=transitions[i];
     248                                for(int j=0;j<nv;j++){
     249                                        forcing[j]=forcingglobal[reCast<int>(transition[j])-1];
     250                                }
     251                                ISSM_MPI_Send(&nv, 1, ISSM_MPI_INT, 0, i, tocomms[i]);
     252                                ISSM_MPI_Send(forcing, nv, ISSM_MPI_DOUBLE, 0, i, tocomms[i]);
     253                        }
     254                }
     255                else{
     256                        ISSM_MPI_Recv(&nv, 1, ISSM_MPI_INT, 0, modelid, fromcomm, &status);
     257                        forcing=xNew<IssmDouble>(nv);
     258                        ISSM_MPI_Recv(forcing, nv, ISSM_MPI_DOUBLE, 0, modelid, fromcomm, &status);
     259                }
     260        }
     261        /*}}}*/
     262
     263        /*On each ice cap, spread the forcing across cpus, and update the elements dataset accordingly: {{{*/
     264        if(modelid!=earthid){
     265
     266                ISSM_MPI_Bcast(&nv,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     267                if(my_rank!=0)forcing=xNew<IssmDouble>(nv);
     268                ISSM_MPI_Bcast(forcing,nv,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     269
     270                /*Plug into elements:*/
     271                InputUpdateFromVectorx(femmodel,forcing,forcingenum,VertexSIdEnum);
     272        }
     273        /*}}}*/
     274
     275        /*Free ressources:{{{*/
     276        if(forcingglobal)xDelete<IssmDouble>(forcingglobal);
     277        if(forcing)xDelete<IssmDouble>(forcing);
     278        if(transitions){
     279                for(int i=0;i<ntransitions;i++){
     280                        IssmDouble* temp=transitions[i];
     281                        xDelete<IssmDouble>(temp);
     282                }
     283                xDelete<IssmDouble*>(transitions);
     284                xDelete<int>(transitions_m);
     285                xDelete<int>(transitions_n);
     286        }
     287        /*}}}*/
     288
     289} /*}}}*/
Note: See TracBrowser for help on using the repository browser.