Changeset 1223


Ignore:
Timestamp:
07/02/09 15:50:07 (16 years ago)
Author:
Eric.Larour
Message:

Better detection of icefronts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/m/classes/public/geography2.m

    r1126 r1223  
    11function md=geography2(md,landname,iceshelfname,icesheetname)
     2
    23%Get assigned fields
    34x=md.x;
     
    89[gridonland,elementonland]=ContourToMesh(elements,x,y,expread(landname,1),'element and node',2);
    910
    10 %use segments to make sure gridonland is correct at the boundary:
    11 pos=find(md.segmentmarkers==2);
    12 gridonland(md.segments(pos,1))=1;
    13 gridonland(md.segments(pos,2))=1;
    14 %now, any elements with 3 grids on land should be on land:
     11%any element with 3 grids on land should be on land:
    1512elementsonwater=find(~elementonland);
    1613wrongelements=elementsonwater(find(( gridonland(md.elements(elementsonwater,1)) + gridonland(md.elements(elementsonwater,2)) + gridonland(md.elements(elementsonwater,3)) ...
     
    1815elementonland(wrongelements)=1;
    1916
    20 %finally, any element with its barycentre in the water should be in the water!
    21 xelem=x(md.elements)*[1;1;1]/3; yelem=y(md.elements)*[1;1;1]/3;
     17%any element with its barycentre on land should be on land:
     18weights={[1;1;1],[2;1;1],[1;2;1],[1;1;2]};
     19for i=1:length(weights),
     20        xelem=x(md.elements)*weights{i}/sum(weights{i});
     21        yelem=y(md.elements)*weights{i}/sum(weights{i});
     22end
    2223baryonland=ContourToNodes(xelem,yelem,expread(landname,1),1);
    2324pos=find(~baryonland); elementonland(pos)=0;
     25pos=find(baryonland); elementonland(pos)=1;
    2426
    2527%figure out which elements on land are actually in the middle of the ocean!
     
    2931connectedtolandsum=sum(connectedtoland,2);
    3032waterelements=pos1(find(connectedtolandsum==3));
     33elementonland(waterelements)=0;
    3134
    32 %now use waterelements to correct elementonland:
    33 elementonland(waterelements)=0;
     35%figure out which elements on water  are actually in the middle of the land!
     36pos1=find(~elementonland);
     37connectedtowater=md.elementconnectivity(pos1,:);
     38pos=find(connectedtowater); connectedtowater(pos)=elementonland(connectedtowater(pos));
     39connectedtowatersum=sum(connectedtowater,2);
     40landelements=pos1(find(connectedtowatersum==3));
     41elementonland(landelements)=1;
    3442
    3543%recover arrays of ice shelf grids and elements, and ice sheet grids and elements.
     
    7482elementonicesheet=double(~elementoniceshelf & ~elementonwater);
    7583
     84
     85
     86%Deal with segments on neumann:
     87elementconnectivity=md.elementconnectivity;
     88pos=find(elementconnectivity);
     89elementconnectivity(pos)=elementonwater(elementconnectivity(pos));
     90
     91pos=find(elementonwater);
     92elementconnectivity(pos,:)=0;
     93
     94num_segments=sum(sum(elementconnectivity));
     95segments=zeros(num_segments,3);
     96
     97icefrontelementsonland=find(sum(elementconnectivity,2));
     98
     99count=1;
     100for i=1:numel(icefrontelementsonland),
     101        el1=icefrontelementsonland(i);
     102        els2=md.elementconnectivity(el1,find(elementconnectivity(el1,:)));
     103        for j=1:numel(els2),
     104                el2=els2(j);
     105                %we have a segment between land el1 and water el2:
     106                segments(count,:)=[intersect(md.elements(el1,:),md.elements(el2,:)) el1];
     107               
     108                ord1=find(segments(count,1)==md.elements(el1,:));
     109                ord2=find(segments(count,2)==md.elements(el1,:));
     110
     111                %swap segment grids if necessary
     112                if ( (ord1==1 & ord2==2) | (ord1==2 & ord2==3) | (ord1==3 & ord2==1) ),
     113                        temp=segments(count,1);
     114                        segments(count,1)=segments(count,2);
     115                        segments(count,2)=temp;
     116                end
     117                segments(count,1:2)=fliplr(segments(count,1:2));
     118               
     119                count=count+1;
     120        end
     121end
     122
    76123%Return:
    77124md.gridoniceshelf=gridoniceshelf;
     
    84131md.elementonicesheet=elementonicesheet;
    85132
    86 %Deal with segments on neumann:
    87 pos=find(md.segmentmarkers==2); %internal segments.
    88 segments=md.segments(pos,:);
    89 
    90 %swap segments so they are all oriented the same way
    91 maxcon=size(md.nodeconnectivity,2);
    92 for i=1:length(segments),
    93 
    94         pair=intersect(md.nodeconnectivity(segments(i,1),1:md.nodeconnectivity(segments(i,1),maxcon)),md.nodeconnectivity(segments(i,2),1:md.nodeconnectivity(segments(i,2),maxcon)));
    95 
    96     if md.elementonwater(pair(1)),
    97                 segments(i,3)=pair(2);
    98         else
    99                 segments(i,3)=pair(1);
    100         end
    101        
    102         ord1=find(segments(i,1)==md.elements(segments(i,3),:));
    103         ord2=find(segments(i,2)==md.elements(segments(i,3),:));
    104        
    105         %swap segment grids if necessary
    106         if ( (ord1==1 & ord2==2) | (ord1==2 & ord2==3) | (ord1==3 & ord2==1) ),
    107                 temp=segments(i,1);
    108                 segments(i,1)=segments(i,2);
    109                 segments(i,2)=temp;
    110         end
    111         segments(i,1:2)=fliplr(segments(i,1:2));
    112        
    113 end
    114133md.segmentonneumann_diag=segments;
    115134md.counter=2;
Note: See TracChangeset for help on using the changeset viewer.