Ignore:
Timestamp:
05/09/14 14:51:29 (11 years ago)
Author:
Mathieu Morlighem
Message:

CHG: moving misfits to modules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.cpp

    r16314 r17975  
    1010void SurfaceLogVelMisfitx( IssmDouble* pJ, Elements* elements,Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials,Parameters* parameters){
    1111
    12         /*Intermediary*/
    13         int i;
    14         Element* element=NULL;
    15 
    1612        /*output: */
    17         IssmDouble J=0;
     13        IssmDouble J=0.;
    1814        IssmDouble J_sum;
    1915
    2016        /*Compute Misfit: */
    21         for (i=0;i<elements->Size();i++){
    22                 element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
    23                 J+=element->SurfaceLogVelMisfit();
     17        for(int i=0;i<elements->Size();i++){
     18                Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
     19                J+=SurfaceLogVelMisfit(element);
    2420        }
    2521
     
    3228        *pJ=J;
    3329}
     30
     31IssmDouble SurfaceLogVelMisfit(Element* element){
     32
     33        int        domaintype,numcomponents;
     34        bool       surfaceintegral;
     35        IssmDouble Jelem=0.;
     36        IssmDouble epsvel=2.220446049250313e-16;
     37        IssmDouble meanvel=3.170979198376458e-05; /*1000 m/yr*/
     38        IssmDouble velocity_mag,obs_velocity_mag;
     39        IssmDouble misfit,Jdet;
     40        IssmDouble vx,vy,vxobs,vyobs,weight;
     41        IssmDouble* xyz_list = NULL;
     42
     43        /*Get basal element*/
     44        if(!element->IsOnSurface()) return 0.;
     45
     46        /*If on water, return 0: */
     47        if(!element->IsIceInElement()) return 0.;
     48
     49        /*Get problem dimension*/
     50        element->FindParam(&domaintype,DomainTypeEnum);
     51        switch(domaintype){
     52                case Domain2DverticalEnum:
     53                        surfaceintegral = true;
     54                        numcomponents   = 1;
     55                        break;
     56                case Domain3DEnum:
     57                        surfaceintegral = true;
     58                        numcomponents   = 2;
     59                        break;
     60                case Domain2DhorizontalEnum:
     61                        surfaceintegral = false;
     62                        numcomponents   = 2;
     63                        break;
     64                default: _error_("not supported yet");
     65        }
     66
     67        /*Spawn surface element*/
     68        Element* topelement = element->SpawnTopElement();
     69
     70        /* Get node coordinates*/
     71        topelement->GetVerticesCoordinates(&xyz_list);
     72
     73        /*Retrieve all inputs we will be needing: */
     74        Input* weights_input=topelement->GetInput(InversionCostFunctionsCoefficientsEnum); _assert_(weights_input);
     75        Input* vx_input     =topelement->GetInput(VxEnum);                                 _assert_(vx_input);
     76        Input* vxobs_input  =topelement->GetInput(InversionVxObsEnum);                     _assert_(vxobs_input);
     77        Input* vy_input     = NULL;
     78        Input* vyobs_input  = NULL;
     79        if(numcomponents==2){
     80                vy_input    =topelement->GetInput(VyEnum);              _assert_(vy_input);
     81                vyobs_input =topelement->GetInput(InversionVyObsEnum);  _assert_(vyobs_input);
     82        }
     83
     84        /* Start  looping on the number of gaussian points: */
     85        Gauss* gauss=topelement->NewGauss(4);
     86        for(int ig=gauss->begin();ig<gauss->end();ig++){
     87
     88                gauss->GaussPoint(ig);
     89
     90                /* Get Jacobian determinant: */
     91                topelement->JacobianDeterminant(&Jdet,xyz_list,gauss);
     92
     93                /*Get all parameters at gaussian point*/
     94                weights_input->GetInputValue(&weight,gauss,SurfaceLogVelMisfitEnum);
     95                vx_input->GetInputValue(&vx,gauss);
     96                vxobs_input->GetInputValue(&vxobs,gauss);
     97                if(numcomponents==2){
     98                        vy_input->GetInputValue(&vy,gauss);
     99                        vyobs_input->GetInputValue(&vyobs,gauss);
     100                }
     101
     102                /*Compute SurfaceLogVelMisfit:
     103                 *                 [        vel + eps     ] 2
     104                 * J = 4 \bar{v}^2 | log ( -----------  ) | 
     105                 *                 [       vel   + eps    ]
     106                 *                            obs
     107                 */
     108                if(numcomponents==1){
     109                        velocity_mag    =fabs(vx)+epsvel;
     110                        obs_velocity_mag=fabs(vxobs)+epsvel;
     111                }
     112                else{
     113                        velocity_mag    =sqrt(vx*vx+vy*vy)+epsvel;
     114                        obs_velocity_mag=sqrt(vxobs*vxobs+vyobs*vyobs)+epsvel;
     115                }
     116
     117                misfit=4*pow(meanvel,2)*pow(log(velocity_mag/obs_velocity_mag),2);
     118
     119                /*Add to cost function*/
     120                Jelem+=misfit*weight*Jdet*gauss->weight;
     121        }
     122
     123        /*clean up and Return: */
     124        if(domaintype!=Domain2DhorizontalEnum){topelement->DeleteMaterials(); delete topelement;};
     125        xDelete<IssmDouble>(xyz_list);
     126        delete gauss;
     127        return Jelem;
     128}
Note: See TracChangeset for help on using the changeset viewer.