Changeset 15718


Ignore:
Timestamp:
08/06/13 08:54:01 (12 years ago)
Author:
Mathieu Morlighem
Message:

CHG: extended arbitrary number of nodes to other solutions

Location:
issm/trunk-jpl/src/c/classes/Elements
Files:
2 edited

Legend:

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

    r15717 r15718  
    51875187}
    51885188/*}}}*/
    5189 /*FUNCTION Tria::CreatePVectorAdjointFS{{{*/
    5190 ElementVector* Tria::CreatePVectorAdjointFS(void){
    5191 
    5192         /*Intermediaries */
    5193         int        i,resp;
    5194         int       *responses=NULL;
    5195         int        num_responses;
    5196         IssmDouble     Jdet;
    5197         IssmDouble     obs_velocity_mag,velocity_mag;
    5198         IssmDouble     dux,duy;
    5199         IssmDouble     epsvel=2.220446049250313e-16;
    5200         IssmDouble     meanvel=3.170979198376458e-05; /*1000 m/yr*/
    5201         IssmDouble     scalex=0,scaley=0,scale=0,S=0;
    5202         IssmDouble     vx,vy,vxobs,vyobs,weight;
    5203         IssmDouble     xyz_list[NUMVERTICES][3];
    5204         IssmDouble     basis[3];
    5205         GaussTria* gauss=NULL;
    5206 
    5207         /*Initialize Element vector*/
    5208         ElementVector* pe=new ElementVector(nodes,NUMVERTICES,this->parameters,FSApproximationEnum);
    5209 
    5210         /*Retrieve all inputs and parameters*/
    5211         GetVerticesCoordinates(&xyz_list[0][0],vertices,NUMVERTICES);
    5212         this->parameters->FindParam(&num_responses,InversionNumCostFunctionsEnum);
    5213         this->parameters->FindParam(&responses,NULL,NULL,StepResponsesEnum);
    5214         Input* weights_input = inputs->GetInput(InversionCostFunctionsCoefficientsEnum);   _assert_(weights_input);
    5215         Input* vx_input      = inputs->GetInput(VxEnum);        _assert_(vx_input);
    5216         Input* vy_input      = inputs->GetInput(VyEnum);        _assert_(vy_input);
    5217         Input* vxobs_input   = inputs->GetInput(InversionVxObsEnum);     _assert_(vxobs_input);
    5218         Input* vyobs_input   = inputs->GetInput(InversionVyObsEnum);     _assert_(vyobs_input);
    5219 
    5220         /*Get Surface if required by one response*/
    5221         for(resp=0;resp<num_responses;resp++){
    5222                 if(responses[resp]==SurfaceAverageVelMisfitEnum){
    5223                         inputs->GetInputValue(&S,SurfaceAreaEnum); break;
    5224                 }
    5225         }
    5226 
    5227         /* Start  looping on the number of gaussian points: */
    5228         gauss=new GaussTria(4);
    5229         for(int ig=gauss->begin();ig<gauss->end();ig++){
    5230 
    5231                 gauss->GaussPoint(ig);
    5232 
    5233                 /* Get Jacobian determinant: */
    5234                 GetJacobianDeterminant(&Jdet, &xyz_list[0][0],gauss);
    5235 
    5236                 /*Get all parameters at gaussian point*/
    5237                 vx_input->GetInputValue(&vx,gauss);
    5238                 vy_input->GetInputValue(&vy,gauss);
    5239                 vxobs_input->GetInputValue(&vxobs,gauss);
    5240                 vyobs_input->GetInputValue(&vyobs,gauss);
    5241                 GetNodalFunctions(basis, gauss);
    5242 
    5243                 /*Loop over all requested responses*/
    5244                 for(resp=0;resp<num_responses;resp++){
    5245 
    5246                         weights_input->GetInputValue(&weight,gauss,resp);
    5247 
    5248                         switch(responses[resp]){
    5249 
    5250                                 case SurfaceAbsVelMisfitEnum:
    5251                                         /*
    5252                                          *      1  [           2              2 ]
    5253                                          * J = --- | (u - u   )  +  (v - v   )  |
    5254                                          *      2  [       obs            obs   ]
    5255                                          *
    5256                                          *        dJ
    5257                                          * DU = - -- = (u   - u )
    5258                                          *        du     obs
    5259                                          */
    5260                                         for (i=0;i<NUMVERTICES;i++){
    5261                                                 dux=vxobs-vx;
    5262                                                 duy=vyobs-vy;
    5263                                                 pe->values[i*NDOF4+0]+=dux*weight*Jdet*gauss->weight*basis[i];
    5264                                                 pe->values[i*NDOF4+1]+=duy*weight*Jdet*gauss->weight*basis[i];
    5265                                         }
    5266                                         break;
    5267                                 case SurfaceRelVelMisfitEnum:
    5268                                         /*
    5269                                          *      1  [     \bar{v}^2             2   \bar{v}^2              2 ]
    5270                                          * J = --- | -------------  (u - u   ) + -------------  (v - v   )  |
    5271                                          *      2  [  (u   + eps)^2       obs    (v   + eps)^2       obs    ]
    5272                                          *              obs                        obs                     
    5273                                          *
    5274                                          *        dJ     \bar{v}^2
    5275                                          * DU = - -- = ------------- (u   - u )
    5276                                          *        du   (u   + eps)^2    obs
    5277                                          *               obs
    5278                                          */
    5279                                         for (i=0;i<NUMVERTICES;i++){
    5280                                                 scalex=pow(meanvel/(vxobs+epsvel),2); if(vxobs==0)scalex=0;
    5281                                                 scaley=pow(meanvel/(vyobs+epsvel),2); if(vyobs==0)scaley=0;
    5282                                                 dux=scalex*(vxobs-vx);
    5283                                                 duy=scaley*(vyobs-vy);
    5284                                                 pe->values[i*NDOF4+0]+=dux*weight*Jdet*gauss->weight*basis[i];
    5285                                                 pe->values[i*NDOF4+1]+=duy*weight*Jdet*gauss->weight*basis[i];
    5286                                         }
    5287                                         break;
    5288                                 case SurfaceLogVelMisfitEnum:
    5289                                         /*
    5290                                          *                 [        vel + eps     ] 2
    5291                                          * J = 4 \bar{v}^2 | log ( -----------  ) | 
    5292                                          *                 [       vel   + eps    ]
    5293                                          *                            obs
    5294                                          *
    5295                                          *        dJ                 2 * log(...)
    5296                                          * DU = - -- = - 4 \bar{v}^2 -------------  u
    5297                                          *        du                 vel^2 + eps
    5298                                          *           
    5299                                          */
    5300                                         for (i=0;i<NUMVERTICES;i++){
    5301                                                 velocity_mag    =sqrt(pow(vx,   2)+pow(vy,   2))+epsvel;
    5302                                                 obs_velocity_mag=sqrt(pow(vxobs,2)+pow(vyobs,2))+epsvel;
    5303                                                 scale=-8*pow(meanvel,2)/pow(velocity_mag,2)*log(velocity_mag/obs_velocity_mag);
    5304                                                 dux=scale*vx;
    5305                                                 duy=scale*vy;
    5306                                                 pe->values[i*NDOF4+0]+=dux*weight*Jdet*gauss->weight*basis[i];
    5307                                                 pe->values[i*NDOF4+1]+=duy*weight*Jdet*gauss->weight*basis[i];
    5308                                         }
    5309                                         break;
    5310                                 case SurfaceAverageVelMisfitEnum:
    5311                                         /*
    5312                                          *      1                    2              2
    5313                                          * J = ---  sqrt(  (u - u   )  +  (v - v   )  )
    5314                                          *      S                obs            obs
    5315                                          *
    5316                                          *        dJ      1       1
    5317                                          * DU = - -- = - --- ----------- * 2 (u - u   )
    5318                                          *        du      S  2 sqrt(...)           obs
    5319                                          */
    5320                                         for (i=0;i<NUMVERTICES;i++){
    5321                                                 scale=1./(S*2*sqrt(pow(vx-vxobs,2)+pow(vy-vyobs,2))+epsvel);
    5322                                                 dux=scale*(vxobs-vx);
    5323                                                 duy=scale*(vyobs-vy);
    5324                                                 pe->values[i*NDOF4+0]+=dux*weight*Jdet*gauss->weight*basis[i];
    5325                                                 pe->values[i*NDOF4+1]+=duy*weight*Jdet*gauss->weight*basis[i];
    5326                                         }
    5327                                         break;
    5328                                 case SurfaceLogVxVyMisfitEnum:
    5329                                         /*
    5330                                          *      1            [        |u| + eps     2          |v| + eps     2  ]
    5331                                          * J = --- \bar{v}^2 | log ( -----------  )   +  log ( -----------  )   | 
    5332                                          *      2            [       |u    |+ eps              |v    |+ eps     ]
    5333                                          *                              obs                       obs
    5334                                          *        dJ                              1      u                             1
    5335                                          * DU = - -- = - \bar{v}^2 log(u...) --------- ----  ~ - \bar{v}^2 log(u...) ------
    5336                                          *        du                         |u| + eps  |u|                           u + eps
    5337                                          */
    5338                                         for (i=0;i<NUMVERTICES;i++){
    5339                                                 dux = - meanvel*meanvel * log((fabs(vx)+epsvel)/(fabs(vxobs)+epsvel)) / (vx+epsvel);
    5340                                                 duy = - meanvel*meanvel * log((fabs(vy)+epsvel)/(fabs(vyobs)+epsvel)) / (vy+epsvel);
    5341                                                 pe->values[i*NDOF4+0]+=dux*weight*Jdet*gauss->weight*basis[i];
    5342                                                 pe->values[i*NDOF4+1]+=duy*weight*Jdet*gauss->weight*basis[i];
    5343                                         }
    5344                                         break;
    5345                                 case DragCoefficientAbsGradientEnum:
    5346                                         /*Nothing in P vector*/
    5347                                         break;
    5348                                 case ThicknessAbsGradientEnum:
    5349                                         /*Nothing in P vector*/
    5350                                         break;
    5351                                 case ThicknessAcrossGradientEnum:
    5352                                         /*Nothing in P vector*/
    5353                                         break;
    5354                                 case ThicknessAlongGradientEnum:
    5355                                         /*Nothing in P vector*/
    5356                                         break;
    5357                                 case RheologyBbarAbsGradientEnum:
    5358                                         /*Nothing in P vector*/
    5359                                         break;
    5360                                 default:
    5361                                         _error_("response " << EnumToStringx(responses[resp]) << " not supported yet");
    5362                         }
    5363                 }
    5364         }
    5365 
    5366         /*Clean up and return*/
    5367         delete gauss;
    5368         xDelete<int>(responses);
    5369         return pe;
    5370 }
    5371 /*}}}*/
    53725189/*FUNCTION Tria::DragCoefficientAbsGradient{{{*/
    53735190IssmDouble Tria::DragCoefficientAbsGradient(int weight_index){
     
    60505867ElementVector* Tria::CreatePVectorHydrologyDCInefficient(void){
    60515868
    6052         /*Constants*/
    6053         const int    numdof=NDOF1*NUMVERTICES;
    6054 
    60555869        /*Intermediaries */
    60565870        IssmDouble Jdet;
     
    60595873        IssmDouble water_load,transfer;
    60605874        IssmDouble sediment_storing;
    6061         IssmDouble basis[numdof];
    6062         GaussTria* gauss=NULL;
    6063 
    6064         /*Initialize Element vector*/
    6065         ElementVector* pe=new ElementVector(nodes,NUMVERTICES,this->parameters);
     5875
     5876        /*Fetch number of nodes and dof for this finite element*/
     5877        int numnodes = this->NumberofNodes();
     5878
     5879        /*Initialize Element vector and other vectors*/
     5880        ElementVector* pe    = new ElementVector(nodes,numnodes,this->parameters);
     5881        IssmDouble*    basis = xNew<IssmDouble>(numnodes);
    60665882
    60675883        /*Retrieve all inputs and parameters*/
     
    60785894
    60795895        /* Start  looping on the number of gaussian points: */
    6080         gauss=new GaussTria(2);
     5896        GaussTria* gauss=new GaussTria(2);
    60815897        for(int ig=gauss->begin();ig<gauss->end();ig++){
    60825898
     
    60905906                scalar = Jdet*gauss->weight*(water_load+transfer);
    60915907                if(reCast<bool,IssmDouble>(dt)) scalar = scalar*dt;
    6092                 for(int i=0;i<numdof;i++) pe->values[i]+=scalar*basis[i];
     5908                for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
    60935909
    60945910                /*Transient term*/
     
    60965912                        old_wh_input->GetInputValue(&water_head,gauss);
    60975913                        scalar = Jdet*gauss->weight*water_head*sediment_storing;
    6098                         for(int i=0;i<numdof;i++) pe->values[i]+=scalar*basis[i];
    6099                 }
    6100         }
     5914                        for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
     5915                }
     5916        }
     5917
    61015918        /*Clean up and return*/
     5919        xDelete<IssmDouble>(basis);
    61025920        delete gauss;
    61035921        return pe;
     
    61065924/*FUNCTION Tria::CreatePVectorHydrologyDCEfficient {{{*/
    61075925ElementVector* Tria::CreatePVectorHydrologyDCEfficient(void){
    6108 
    6109         /*Constants*/
    6110         const int    numdof=NDOF1*NUMVERTICES;
    61115926
    61125927        /*Intermediaries */
     
    61175932        IssmDouble transfer,residual;
    61185933        IssmDouble epl_storing;
    6119         IssmDouble basis[numdof];
    6120         GaussTria* gauss=NULL;
     5934        GaussTria* gauss = NULL;
    61215935
    61225936        /*Check that all nodes are active, else return empty matrix*/
     
    61245938                return NULL;
    61255939        }
    6126         /*Initialize Element vector*/
    6127         ElementVector* pe=new ElementVector(nodes,NUMVERTICES,this->parameters);
     5940
     5941        /*Fetch number of nodes and dof for this finite element*/
     5942        int numnodes = this->NumberofNodes();
     5943
     5944        /*Initialize Element vector and other vectors*/
     5945        ElementVector* pe    = new ElementVector(nodes,numnodes,this->parameters);
     5946        IssmDouble*    basis = xNew<IssmDouble>(numnodes);
    61285947
    61295948        /*Retrieve all inputs and parameters*/
     
    61455964                gauss->GaussPoint(ig);
    61465965                GetJacobianDeterminant(&Jdet, &xyz_list[0][0],gauss);
    6147                 GetNodalFunctions(basis, gauss);
     5966                GetNodalFunctions(basis,gauss);
    61485967
    61495968                /*Loading term*/
     
    61515970                scalar = Jdet*gauss->weight*(-transfer);
    61525971                if(reCast<bool,IssmDouble>(dt)) scalar = scalar*dt;
    6153                 for(int i=0;i<numdof;i++) pe->values[i]+=scalar*basis[i];
     5972                for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
    61545973
    61555974                /*Transient term*/
     
    61575976                        old_wh_input->GetInputValue(&water_head,gauss);
    61585977                        scalar = Jdet*gauss->weight*water_head*epl_storing;
    6159                         for(int i=0;i<numdof;i++) pe->values[i]+=scalar*basis[i];
     5978                        for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
    61605979                }
    61615980        }
     
    61715990                pe->values[iv]+=residual/connectivity;
    61725991        }
     5992
    61735993        /*Clean up and return*/
     5994        xDelete<IssmDouble>(basis);
    61745995        delete gauss;
    61755996        return pe;
  • issm/trunk-jpl/src/c/classes/Elements/Tria.h

    r15695 r15718  
    241241                ElementMatrix* CreateKMatrixAdjointSSA(void);
    242242                ElementVector* CreatePVectorAdjointHoriz(void);
    243                 ElementVector* CreatePVectorAdjointFS(void);
    244243                ElementVector* CreatePVectorAdjointBalancethickness(void);
    245244                void      InputUpdateFromSolutionAdjointBalancethickness( IssmDouble* solution);
Note: See TracChangeset for help on using the changeset viewer.