Changeset 419


Ignore:
Timestamp:
05/14/09 08:50:30 (16 years ago)
Author:
Mathieu Morlighem
Message:

better way to compute Misfit integral

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/objects/Tria.cpp

    r418 r419  
    15771577
    15781578        /* parameters: */
    1579         double  velocity_x,velocity_y,velocity_mag;
    1580         double  obs_velocity_x,obs_velocity_y,obs_velocity_mag;
     1579        double  obs_velocity_mag,velocity_mag;
    15811580        double  absolutex,absolutey,relativex,relativey,logarithmicx,logarithmicy;
    15821581
     
    20952094#define __FUNCT__ "Tria::Misfit"
    20962095double Tria::Misfit(double* velocity,double* obs_velocity,void* vinputs,int analysis_type){
     2096
    20972097        int i;
    20982098       
     
    21132113        double obs_vx_list[numgrids];
    21142114        double obs_vy_list[numgrids];
     2115        double absolute_list[numgrids];
     2116        double relative_list[numgrids];
     2117        double logarithmic_list[numgrids];
    21152118
    21162119        /* gaussian points: */
     
    21242127
    21252128        /* parameters: */
    2126         double  velocity_x,velocity_y,velocity_mag;
    2127         double  obs_velocity_x,obs_velocity_y,obs_velocity_mag;
     2129        double  velocity_mag,obs_velocity_mag;
     2130        double  absolute,relative,logarithmic;
    21282131
    21292132        /* Jacobian: */
     
    21552158        }
    21562159       
     2160        /*Compute Misfit at the 3 nodes (integration of the linearized function)*/
     2161        if(fit==0){
     2162                /*We are using an absolute misfit: */
     2163                for (i=0;i<numgrids;i++){
     2164                        absolute_list[i]=0.5*(pow((vx_list[i]-obs_vx_list[i]),2)+pow((vy_list[i]-obs_vy_list[i]),2));
     2165                }
     2166        }
     2167        else if(fit==1){
     2168                /*We are using a relative misfit: */
     2169                for (i=0;i<numgrids;i++){
     2170                        scalex=pow(meanvel/(obs_vx_list[i]+epsvel),2);
     2171                        scaley=pow(meanvel/(obs_vy_list[i]+epsvel),2);
     2172                        if(obs_vx_list[i]==0)scalex=0;
     2173                        if(obs_vy_list[i]==0)scaley=0;
     2174                        relative_list[i]=0.5*(scalex*pow((vx_list[i]-obs_vx_list[i]),2)+scaley*pow((vy_list[i]-obs_vy_list[i]),2))*Jdet*gauss_weight;
     2175                }
     2176        }
     2177        else if(fit==2){
     2178                /*We are using a logarithmic misfit: */
     2179                for (i=0;i<numgrids;i++){
     2180                        velocity_mag=sqrt(pow(vx_list[i],2)+pow(vy_list[i],2))+epsvel; //epsvel to avoid velocity being nil.
     2181                        obs_velocity_mag=sqrt(pow(obs_vx_list[i],2)+pow(obs_vy_list[i],2))+epsvel; //epsvel to avoid observed velocity being nil.
     2182                        logarithmic_list[i]=4*pow(meanvel,2)*pow(log(velocity_mag/obs_velocity_mag),2);
     2183                }
     2184        }
     2185        else{
     2186                /*Not supported yet! : */
     2187                throw ErrorException(__FUNCT__,exprintf("%s%g","unsupported type of fit: ",fit));
     2188        }
     2189
    21572190        /* Get gaussian points and weights (make this a statically initialized list of points? fstd): */
    21582191        GaussTria( &num_gauss, &first_gauss_area_coord, &second_gauss_area_coord, &third_gauss_area_coord, &gauss_weights, 2);
     
    21722205                gauss_l1l2l3[2]=*(third_gauss_area_coord+ig);
    21732206
    2174                 /*Compute velocities at gaussian point: */
    2175                 GetParameterValue(&velocity_x, &vx_list[0],gauss_l1l2l3);
    2176                 GetParameterValue(&velocity_y, &vy_list[0],gauss_l1l2l3);
    2177                 #ifdef _DEBUG_
    2178                         printf("Velocity: %g %g\n", velocity_x,velocity_y);
    2179                 #endif
    2180        
    2181                 /*Compute obs_velocities at gaussian point: */
    2182                 GetParameterValue(&obs_velocity_x, &obs_vx_list[0],gauss_l1l2l3);
    2183                 GetParameterValue(&obs_velocity_y, &obs_vy_list[0],gauss_l1l2l3);
    2184                 #ifdef _DEBUG_
    2185                         printf("Observed velocity: %g %g\n", obs_velocity_x,obs_velocity_y);
    2186                 #endif
    2187 
    21882207                /* Get Jacobian determinant: */
    21892208                GetJacobianDeterminant2d(&Jdet, &xyz_list[0][0],gauss_l1l2l3);
     
    21942213                /*Differents misfits are allowed: */
    21952214                if(fit==0){
    2196                         /*Absolute misfit: */
    2197                         Jelem+=.5*(pow((velocity_x-obs_velocity_x),2)+pow((velocity_y-obs_velocity_y),2))*Jdet*gauss_weight;
     2215                        /*Compute absolute misfit at gaussian point: */
     2216                        GetParameterValue(&absolute, &absolute_list[0],gauss_l1l2l3);
     2217
     2218                        /*compute Misfit*/
     2219                        Jelem+=absolute*Jdet*gauss_weight;
    21982220                }
    21992221                else if(fit==1){
    2200                         /*Relative misfit: */
    2201                         scalex=pow(meanvel/(obs_velocity_x+epsvel),2);
    2202                         scaley=pow(meanvel/(obs_velocity_y+epsvel),2);
    2203                         if(obs_velocity_x==0)scalex=0;
    2204                         if(obs_velocity_y==0)scaley=0;
    2205                         Jelem+=.5*(scalex*pow((velocity_x-obs_velocity_x),2)+scaley*pow((velocity_y-obs_velocity_y),2))*Jdet*gauss_weight;
     2222                        /*Compute relative misfit at gaussian point: */
     2223                        GetParameterValue(&relative, &relative_list[0],gauss_l1l2l3);
     2224
     2225                        /*compute Misfit*/
     2226                        Jelem+=relative*Jdet*gauss_weight;
    22062227                }       
    22072228                else if(fit==2){
    2208                         /*Logarithmic misfit: */
    2209                         velocity_mag=sqrt(pow(velocity_x,2)+pow(velocity_y,2))+epsvel; //epsvel to avoid velocity being nil.
    2210                         obs_velocity_mag=sqrt(pow(obs_velocity_x,2)+pow(obs_velocity_y,2))+epsvel; //epsvel to avoid observed velocity being nil.
    2211                         Jelem+=4*pow(meanvel,2)*pow(log(velocity_mag/obs_velocity_mag),2)*Jdet*gauss_weight;
     2229                        /*Compute logarithmic misfit at gaussian point: */
     2230                        GetParameterValue(&logarithmic, &logarithmic_list[0],gauss_l1l2l3);
     2231
     2232                        /*compute Misfit*/
     2233                        Jelem+=logarithmic*Jdet*gauss_weight;
    22122234                }
    22132235                else throw ErrorException(__FUNCT__,exprintf("%s%i%s","fit type",fit," not supported yet!"));
Note: See TracChangeset for help on using the changeset viewer.