Changeset 18956


Ignore:
Timestamp:
12/11/14 01:20:21 (10 years ago)
Author:
jbondzio
Message:

ADD: Computation of Tria-area covered by ice. Computation of determination of ice distribution in element.

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

Legend:

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

    r18953 r18956  
    879879}
    880880/*}}}*/
     881IssmDouble Tria::GetAreaIce(void){/*{{{*/
     882
     883        /*return area of element covered by ice*/
     884        /*Intermediaries*/
     885        int numiceverts;
     886        IssmDouble area_fraction;
     887        IssmDouble s[2]; // s:fraction of intersected triangle edges that lie inside ice
     888        int* indices=NULL;
     889
     890        this->GetLevelsetIntersection(&indices, &numiceverts, s, MaskIceLevelsetEnum, 0.);
     891
     892        switch (numiceverts){
     893                case 0: // no vertex has ice: element is ice free
     894                        area_fraction=0.;
     895                        break;
     896                case 1: // one vertex has ice: get area of triangle
     897                        area_fraction=s[0]*s[1];
     898                        break;
     899                case 2: // two vertices have ice: get area of quadrangle
     900                        area_fraction=s[0]+s[1]-s[0]*s[1];
     901                        break;
     902                case NUMVERTICES: // all vertices have ice: return triangle area
     903                        area_fraction=1.;
     904                        break;
     905                default:
     906                        _error_("Wrong number of ice vertices in Tria::GetAreaIce!");
     907                        break;
     908        }
     909        _assert_((area_fraction>=0.) && (area_fraction<=1.));
     910
     911        xDelete<int>(indices);
     912        return area_fraction*this->GetArea();
     913}/*}}}*/
    881914void       Tria::GetAreaCoordinates(IssmDouble* area_coordinates,IssmDouble* xyz_zero,IssmDouble* xyz_list,int numpoints){/*{{{*/
    882915        /*Computeportion of the element that is grounded*/
     
    11841217        xDelete<int>(indicesfront);
    11851218}/*}}}*/
     1219void                    Tria::GetLevelsetIntersection(int** pindices, int* pnumiceverts, IssmDouble* fraction, int levelset_enum, IssmDouble level){/*{{{*/
     1220       
     1221        /* GetLevelsetIntersection computes:
     1222         * 1. indices of element, sorted in [iceverts, noiceverts] in counterclockwise fashion,
     1223         * 2. fraction of intersected triangle edges intersected by levelset, lying below level*/
     1224
     1225        /*Intermediaries*/
     1226        int i, numiceverts, numnoiceverts;
     1227        int ind0, ind1, lastindex;
     1228        int indices_ice[NUMVERTICES],indices_noice[NUMVERTICES];
     1229        IssmDouble lsf[NUMVERTICES];
     1230        int* indices = xNew<int>(NUMVERTICES);
     1231
     1232        /*Retrieve all inputs and parameters*/
     1233        GetInputListOnVertices(&lsf[0],levelset_enum);
     1234
     1235        /* Determine distribution of ice over element.
     1236         * Exploit: ice/no-ice parts are connected, so find starting vertex of segment*/
     1237        lastindex=0;
     1238        for(i=0;i<NUMVERTICES;i++){ // go backwards along vertices, and check for sign change
     1239                ind0=(NUMVERTICES-i)%NUMVERTICES;
     1240                ind1=(ind0-1+NUMVERTICES)%NUMVERTICES;
     1241                if((lsf[ind0]-level)*(lsf[ind1]-level)<=0.){ // levelset has been crossed, find last index belonging to segment
     1242                        if(lsf[ind1]==level) //if levelset intersects 2nd vertex, choose this vertex as last
     1243                                lastindex=ind1;
     1244                        else
     1245                                lastindex=ind0;
     1246                        break;
     1247                }
     1248        }
     1249
     1250        numiceverts=0;
     1251        numnoiceverts=0;
     1252        for(i=0;i<NUMVERTICES;i++){
     1253                ind0=(lastindex+i)%NUMVERTICES;
     1254                if(lsf[i]<=level){
     1255                        indices_ice[numiceverts]=i;
     1256                        numiceverts++;
     1257                }
     1258                else{
     1259                        indices_noice[numnoiceverts]=i;
     1260                        numnoiceverts++;
     1261                }
     1262        }
     1263        //merge indices
     1264        for(i=0;i<numiceverts;i++){indices[i]=indices_ice[i];}
     1265        for(i=0;i<numnoiceverts;i++){indices[numiceverts+i]=indices_noice[i];}
     1266
     1267        switch (numiceverts){
     1268                case 0: // no vertex has ice: element is ice free, no intersection
     1269                        for(i=0;i<2;i++)
     1270                                fraction[i]=0.;
     1271                        break;
     1272                case 1: // one vertex has ice:
     1273                        for(i=0;i<2;i++){
     1274                                fraction[i]=(level-lsf[indices[0]])/(lsf[indices[numiceverts+i]]-lsf[indices[0]]);
     1275                        }
     1276                        break;
     1277                case 2: // two vertices have ice: get area of quadrangle
     1278                        for(i=0;i<2;i++){
     1279                                fraction[i]=(level-lsf[indices[i]])/(lsf[indices[numiceverts]]-lsf[indices[i]]);
     1280                        }
     1281                        break;
     1282                case NUMVERTICES: // all vertices have ice: return triangle area
     1283                        for(i=0;i<2;i++)
     1284                                fraction[i]=1.;
     1285                        break;
     1286                default:
     1287                        _error_("Wrong number of ice vertices in Tria::GetLevelsetIntersection!");
     1288                        break;
     1289        }
     1290
     1291        *pindices=indices;
     1292        *pnumiceverts=numiceverts;
     1293}
     1294/*}}}*/
    11861295void       Tria::GetLevelsetPositivePart(int* point1,IssmDouble* fraction1,IssmDouble* fraction2, bool* mainlynegative,IssmDouble* gl){/*{{{*/
    11871296       
  • TabularUnified issm/trunk-jpl/src/c/classes/Elements/Tria.h

    r18953 r18956  
    143143                void           AddInput(int input_enum, IssmDouble* values, int interpolation_enum);
    144144                IssmDouble     GetArea(void);
     145                IssmDouble      GetAreaIce(void);
    145146                void           GetAreaCoordinates(IssmDouble *area_coordinates,IssmDouble* xyz_zero,IssmDouble* xyz_list,int numpoints);
     147                void            GetLevelsetIntersection(int** pindices, int* pnumiceverts, IssmDouble* fraction, int levelset_enum, IssmDouble level);
    146148                int            GetElementType(void);
    147149                void           GetInputValue(IssmDouble* pvalue,Node* node,int enumtype);
Note: See TracChangeset for help on using the changeset viewer.