Changeset 27490


Ignore:
Timestamp:
01/01/23 08:43:06 (2 years ago)
Author:
Mathieu Morlighem
Message:

CHG: deal with issolid and rheologymodel: they should be bool* and int* respectively, otherwise AD gives us a lot of warnings... and some compilers too!

Location:
issm/trunk-jpl/src/c
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/IoModel.cpp

    r27102 r27490  
    11241124}
    11251125/*}}}*/
     1126void  IoModel::FetchData(bool** pmatrix,int* pM,int* pN,const char* data_name){/*{{{*/
     1127
     1128        /*output: */
     1129        int M,N;
     1130        IssmPDouble* matrix=NULL;
     1131        bool*        bool_matrix=NULL;
     1132        int code=0;
     1133
     1134        /*recover my_rank:*/
     1135        int my_rank=IssmComm::GetRank();
     1136
     1137        /*Set file pointer to beginning of the data: */
     1138        fid=this->SetFilePointerToData(&code,NULL,data_name);
     1139
     1140        if(code!=5 && code!=6 && code!=7)_error_("expecting a IssmDouble, integer or boolean matrix for \""<<data_name<<"\""<<" (Code is "<<code<<")");
     1141
     1142        /*Now fetch: */
     1143
     1144        /*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */
     1145        /*numberofelements: */
     1146        if(my_rank==0){
     1147                if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
     1148        }
     1149
     1150        ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     1151
     1152        if(my_rank==0){
     1153                if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
     1154        }
     1155        ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     1156
     1157        /*Now allocate matrix: */
     1158        if(M*N){
     1159                matrix=xNew<IssmPDouble>(M*N);
     1160
     1161                /*Read matrix on node 0, then broadcast: */
     1162                if(my_rank==0){
     1163                        if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
     1164                }
     1165
     1166                ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
     1167        }
     1168
     1169        /*Now cast to bool: */
     1170        if(M*N){
     1171                bool_matrix=xNew<bool>(M*N);
     1172                for(int i=0;i<M;i++){
     1173                        for(int j=0;j<N;j++){
     1174                                bool_matrix[i*N+j]=(bool)matrix[i*N+j];
     1175                        }
     1176                }
     1177        }
     1178        else{
     1179                bool_matrix=NULL;
     1180        }
     1181        /*Free resources:*/
     1182        xDelete<IssmPDouble>(matrix);
     1183
     1184        /*Assign output pointers: */
     1185        *pmatrix=bool_matrix;
     1186        if (pM)*pM=M;
     1187        if (pN)*pN=N;
     1188
     1189}
     1190/*}}}*/
    11261191void  IoModel::FetchData(int** pmatrix,int* pM,int* pN,const char* data_name){/*{{{*/
    11271192        int i,j;
  • issm/trunk-jpl/src/c/classes/IoModel.h

    r26073 r27490  
    136136                void        FetchData(char*** pstrings,int* pnumstrings,const char* data_name);
    137137                void        FetchData(int** pmatrix,int* pM,int* pN,const char* data_name);
     138                void        FetchData(bool**  pboolmatrix,int* pM,int* pN,const char* data_name);
    138139                void        FetchData(IssmDouble**  pscalarmatrix,int* pM,int* pN,const char* data_name);
    139140#if _HAVE_AD_  && !defined(_WRAPPERS_)
  • issm/trunk-jpl/src/c/classes/Materials/Matlitho.cpp

    r27102 r27490  
    1414/*Matlitho constructors and destructor*/
    1515Matlitho::Matlitho(){/*{{{*/
    16         this->numlayers=0;
    17         this->radius=NULL;
    18         this->viscosity=NULL;
    19         this->lame_lambda=NULL;
    20         this->lame_mu=NULL;
    21         this->burgers_viscosity=NULL;
    22         this->burgers_mu=NULL;
    23         this->ebm_alpha=NULL;
    24         this->ebm_delta=NULL;   
    25         this->ebm_taul=NULL;
    26         this->ebm_tauh=NULL;
    27         this->density=NULL;
    28         this->rheologymodel=NULL;
    29         this->issolid=NULL;
    30         return;
    31 }
    32 /*}}}*/
    33 Matlitho::Matlitho(int matlitho_mid, IoModel* iomodel){/*{{{*/
    34 
    35         IssmDouble* rheologymodeld=NULL;
    36         IssmDouble* issolidd=NULL;
     16        this->numlayers         = 0;
     17        this->radius            = NULL;
     18        this->viscosity         = NULL;
     19        this->lame_lambda       = NULL;
     20        this->lame_mu           = NULL;
     21        this->burgers_viscosity = NULL;
     22        this->burgers_mu        = NULL;
     23        this->ebm_alpha         = NULL;
     24        this->ebm_delta         = NULL;
     25        this->ebm_taul          = NULL;
     26        this->ebm_tauh          = NULL;
     27        this->density           = NULL;
     28        this->rheologymodel     = NULL;
     29        this->issolid           = NULL;
     30        return;
     31}
     32/*}}}*/
     33Matlitho::Matlitho(int matlitho_mid, IoModel* iomodel, bool* issolid_in, int* rheo_in){/*{{{*/
    3734
    3835        this->mid=matlitho_mid;
     
    7269        xMemCpy<IssmDouble>(this->density, iomodel->Data("md.materials.density"),this->numlayers);
    7370
    74         this->rheologymodel=xNew<IssmDouble>(this->numlayers);
    75         xMemCpy<IssmDouble>(this->rheologymodel, iomodel->Data("md.materials.rheologymodel"),this->numlayers);
    76 
    77         this->issolid=xNew<IssmDouble>(this->numlayers);
    78         xMemCpy<IssmDouble>(this->issolid, iomodel->Data("md.materials.issolid"),this->numlayers);
    79 
    80         /*rheologymodeld= xNew<IssmDouble>(this->numlayers);
    81         this->rheologymodel=xNew<bool>(this->numlayers);
    82         xMemCpy<IssmDouble>(rheologymodeld, iomodel->Data("md.materials.rheologymodel"),this->numlayers);
    83         for (int i=0;i<this->numlayers;i++)this->rheologymodel[i]=reCast<bool,IssmDouble>(rheologymodeld[i]);
    84 
    85         issolidd= xNew<IssmDouble>(this->numlayers);
     71        this->rheologymodel=xNew<int>(this->numlayers);
     72        xMemCpy<int>(this->rheologymodel, rheo_in, this->numlayers);
     73
    8674        this->issolid=xNew<bool>(this->numlayers);
    87         xMemCpy<IssmDouble>(issolidd, iomodel->Data("md.materials.issolid"),this->numlayers);
    88         for (int i=0;i<this->numlayers;i++)this->issolid[i]=reCast<bool,IssmDouble>(issolidd[i]);*/
    89 
    90         /*Free resources: */
    91         xDelete<IssmDouble>(rheologymodeld);
    92         xDelete<IssmDouble>(issolidd);
     75        xMemCpy<bool>(this->issolid, issolid_in, this->numlayers);
    9376}
    9477/*}}}*/
     
    10689        xDelete<IssmDouble>(ebm_tauh);
    10790        xDelete<IssmDouble>(density);
    108         xDelete<IssmDouble>(rheologymodel);
    109         xDelete<IssmDouble>(issolid);
     91        xDelete<int>(rheologymodel);
     92        xDelete<bool>(issolid);
    11093
    11194        return;
     
    141124                matlitho->ebm_tauh=xNew<IssmDouble>(this->numlayers); xMemCpy<IssmDouble>(matlitho->ebm_tauh, this->ebm_tauh,this->numlayers);
    142125                matlitho->density=xNew<IssmDouble>(this->numlayers); xMemCpy<IssmDouble>(matlitho->density, this->density,this->numlayers);
    143                 matlitho->rheologymodel=xNew<IssmDouble>(this->numlayers); xMemCpy<IssmDouble>(matlitho->rheologymodel, this->rheologymodel,this->numlayers);
    144                 matlitho->issolid=xNew<IssmDouble>(this->numlayers); xMemCpy<IssmDouble>(matlitho->issolid, this->issolid,this->numlayers);
    145                 /*matlitho->rheologymodel=xNew<bool>(this->numlayers); for(int i=0;i<this->numlayers;i++)matlitho->rheologymodel[i]=this->rheologymodel[i];
    146                 matlitho->issolid=xNew<bool>(this->numlayers); for(int i=0;i<this->numlayers;i++)matlitho->issolid[i]=this->issolid[i];*/
     126                matlitho->rheologymodel=xNew<int>(this->numlayers); xMemCpy<int>(matlitho->rheologymodel, this->rheologymodel,this->numlayers);
     127                matlitho->issolid=xNew<bool>(this->numlayers); xMemCpy<bool>(matlitho->issolid, this->issolid,this->numlayers);
    147128        }
    148129
  • issm/trunk-jpl/src/c/classes/Materials/Matlitho.h

    r27031 r27490  
    2828                IssmDouble*  ebm_tauh;
    2929                IssmDouble*  density;
    30                 IssmDouble*  rheologymodel;
    31                 IssmDouble*  issolid;
     30                int*         rheologymodel;
     31                bool*        issolid;
    3232
    3333                Matlitho();
    34                 Matlitho(int matlitho_id, IoModel* iomodel);
     34                Matlitho(int matlitho_id, IoModel* iomodel, bool* issolid_in, int* rheo_in);
    3535                ~Matlitho();
    3636                void SetMid(int matlitho_mid);
  • issm/trunk-jpl/src/c/cores/love_core.cpp

    r27477 r27490  
    589589        int rheo=matlitho->rheologymodel[layer_index];
    590590
    591         if (vi!=0 && omega!=0.0){ //take into account viscosity in the rigidity if the material isn't a perfect fluid
     591        if(vi!=0 && omega!=0.0){ //take into account viscosity in the rigidity if the material isn't a perfect fluid
    592592                doubletype ka=la0 + 2.0/3.0*mu0; //Bulk modulus
    593                 if (rheo==2){//EBM
     593                if(rheo==2){//EBM
    594594                        mu=muEBM<doubletype>(layer_index, omega, matlitho, femmodel);
    595595                        la=ka-2.0/3.0*mu;
    596596                }
    597                 else if (rheo==1){//Burgers
     597                else if(rheo==1){//Burgers
    598598                        doubletype vi2=matlitho->burgers_viscosity[layer_index];
    599599                        doubletype mu2=matlitho->burgers_mu[layer_index];
     
    674674        doubletype frh,frhg0,fgr0,fgr,fn,rm0,rlm,flm;
    675675        doubletype xmin,xmax,x,dr;
    676         doubletype g,ro, issolid;
     676        doubletype g,ro;
     677        bool       issolid;
    677678
    678679        if (pomega) { //frequency and degree dependent terms /*{{{*/
     
    690691                        ro=matlitho->density[layer_index];
    691692                        issolid=matlitho->issolid[layer_index];
    692                         if(issolid!=0){
     693                        if(issolid){
    693694                                //GetEarthRheology<doubletype>(&la, &mu,layer_index,omega,matlitho);   
    694695                                mu=vars->mu[layer_index*vars->nfreq+vars->ifreq];
     
    769770                                g=GetGravity<doubletype>(x*ra,layer_index,femmodel,matlitho,vars);
    770771
    771                                 if(issolid==1){
     772                                if(issolid){
    772773                                        yi_prefactor[nindex+ 1*6+3]= fn/x;                  // in dy[1*6+3]
    773774                                        yi_prefactor[nindex+ 5*6+2]= -(fgr/g0*fn)/x;        // in dy[5*6+2]
     
    802803                                g=GetGravity<doubletype>(x*ra,layer_index,femmodel,matlitho,vars);
    803804                                nindex=nsteps*36+n*36;
    804                                 if(issolid==1){
     805                                if(issolid){
    805806                                        yi_prefactor[nindex+ 1*6+5]= -frhg0;       // in dy[1*6+5]
    806807                                        yi_prefactor[nindex+ 2*6+0]= -1.0/x;       // in dy[2*6+0]
     
    825826        //computes yi derivatives at r=radius[layer_index]+ n/nstep*(radius[layer_index+1]-radius[layer_index])
    826827
    827         int issolid=matlitho->issolid[layer_index];
     828        bool issolid=matlitho->issolid[layer_index];
    828829        int iy,id,ny, nindex, nstep, nsteps;
    829830        //femmodel->parameters->FindParam(&nstep,LoveIntStepsPerLayerEnum);
     
    842843                           fn=(deg*(deg+1.0));
    843844
    844                            if(issolid==1){
     845                           if(issolid){
    845846                           ny = 6;
    846847
     
    899900        nindex=nsteps*36+n*36;
    900901
    901         if(issolid==1){
     902        if(issolid){
    902903                ny = 6;
    903904        } else {
     
    12351236
    12361237                // Boundary Condition matrix - solid regions
    1237                 if (matlitho->issolid[i]){
     1238                if(matlitho->issolid[i]){
    12381239                        one = -1.0;
    1239                         if (i>0) if (!matlitho->issolid[i-1]) one = 1.0;
     1240                        if(i>0) if(!matlitho->issolid[i-1]) one = 1.0;
    12401241                        for (int j=0;j<6;j++){
    12411242                                yi[(j+6*ici)+ nyi*(j+6*ici+3)] = one;
  • issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateElementsVerticesAndMaterials.cpp

    r27102 r27490  
    197197                                                break;
    198198                                        case MatlithoEnum: { /*{{{*/
    199                                                         iomodel->FetchData(13,"md.materials.radius","md.materials.viscosity","md.materials.lame_lambda","md.materials.lame_mu","md.materials.burgers_viscosity","md.materials.burgers_mu","md.materials.ebm_alpha","md.materials.ebm_delta","md.materials.ebm_taul","md.materials.ebm_tauh","md.materials.rheologymodel","md.materials.issolid","md.materials.density");
    200                                                         materials->AddObject(new Matlitho(iomodel->numberofelements+1,iomodel));
    201                                                         iomodel->DeleteData(13,"md.materials.radius","md.materials.viscosity","md.materials.lame_lambda","md.materials.lame_mu","md.materials.burgers_viscosity","md.materials.burgers_mu","md.materials.ebm_alpha","md.materials.ebm_delta","md.materials.ebm_taul","md.materials.ebm_tauh","md.materials.rheologymodel","md.materials.issolid","md.materials.density");
     199                                                        bool* issolid = NULL;
     200                                                        int*  rheologymodel = NULL;
     201                                                        iomodel->FetchData(&issolid, NULL, NULL, "md.materials.issolid");
     202                                                        iomodel->FetchData(&rheologymodel, NULL, NULL, "md.materials.rheologymodel");
     203                                                        iomodel->FetchData(11,"md.materials.radius","md.materials.viscosity","md.materials.lame_lambda","md.materials.lame_mu","md.materials.burgers_viscosity","md.materials.burgers_mu","md.materials.ebm_alpha","md.materials.ebm_delta","md.materials.ebm_taul","md.materials.ebm_tauh","md.materials.density");
     204                                                        materials->AddObject(new Matlitho(iomodel->numberofelements+1, iomodel, issolid, rheologymodel));
     205                                                        iomodel->DeleteData(11,"md.materials.radius","md.materials.viscosity","md.materials.lame_lambda","md.materials.lame_mu","md.materials.burgers_viscosity","md.materials.burgers_mu","md.materials.ebm_alpha","md.materials.ebm_delta","md.materials.ebm_taul","md.materials.ebm_tauh","md.materials.density");
     206                                                        xDelete<bool>(issolid);
     207                                                        xDelete<int>(rheologymodel);
    202208                                                }
    203209                                                /*}}}*/
Note: See TracChangeset for help on using the changeset viewer.