Changeset 3250


Ignore:
Timestamp:
03/10/10 16:27:21 (15 years ago)
Author:
Mathieu Morlighem
Message:

Added rift on border capability

File:
1 edited

Legend:

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

    r3023 r3250  
    6262bamg_geometry.SubDomains=zeros(0,3);
    6363if exist(options,'domain'),
     64
     65        %Check that file exists
    6466        domainfile=getfieldvalueerr(options,'domain');
    6567        if ~exist(domainfile,'file')
    6668                error(['bamg error message: file ' domainfile ' not found ']);
    67         else
    68                 domain=expread(domainfile);
    69 
    70                 %build geometry
    71                 count=0;
    72 
    73                 for i=1:length(domain),
    74 
    75                         %if current profile is closed
    76                         if (domain(i).x(1)==domain(i).x(end) & domain(i).y(1)==domain(i).y(end)),
    77                                 nods=domain(i).nods-1; %the domain are closed 1=end;
    78                                 bamg_geometry.Vertices=[bamg_geometry.Vertices; [domain(i).x(1:nods) domain(i).y(1:nods) ones(nods,1)]];
    79                                 bamg_geometry.Edges=[bamg_geometry.Edges; [transp(count+1:count+nods) transp([count+2:count+nods count+1])  1*ones(nods,1)]];
    80                                 if i>1,
    81                                         %if closed : hole
    82                                         clockwise=-1;
    83                                         bamg_geometry.SubDomains=[2 count+1 clockwise 1];
    84 
     69        end
     70
     71        %Build geometry
     72        domain=expread(domainfile);
     73        count=0;
     74        for i=1:length(domain),
     75
     76                %Check that the domain is closed
     77                if (domain(i).x(1)~=domain(i).x(end) | domain(i).y(1)~=domain(i).y(end)),
     78                        error('bamg error message: all contours provided in ''domain'' should be closed');
     79                end
     80                %Checks that all holes are INSIDE the principla domain outline
     81                if i>1,
     82                        flags=ContourToNodes(domain(i).x,domain(i).y,domain(1),0);
     83                        if any(~flags),
     84                                error('bamg error message: All holes should be stricly inside the principal domain');
     85                        end
     86                end
     87
     88                %Add all points to bamg_geometry
     89                nods=domain(i).nods-1; %the domain are closed 1=end;
     90                bamg_geometry.Vertices=[bamg_geometry.Vertices; [domain(i).x(1:nods) domain(i).y(1:nods) ones(nods,1)]];
     91                bamg_geometry.Edges=[bamg_geometry.Edges; [transp(count+1:count+nods) transp([count+2:count+nods count+1])  1*ones(nods,1)]];
     92
     93                %update counter
     94                count=count+nods;
     95        end
     96
     97        %take care of rifts
     98        if exist(options,'rifts'),
     99
     100                %Check that file exists
     101                riftfile=getfieldvalueerr(options,'rifts');
     102                if ~exist(riftfile,'file')
     103                        error(['bamg error message: file ' riftfile ' not found ']);
     104                end
     105                rift=expread(riftfile);
     106
     107                for i=1:length(rift),
     108
     109                        %detect wether all points of the rift are inside the domain
     110                        flags=ContourToNodes(rift(i).x,rift(i).y,domain(1),0);
     111                        if ~flags,
     112                                error('one Rift has all his points outside of the domain outline'),
     113
     114                        elseif any(~flags),
     115                                %We LOTS of work to do
     116                                disp('Rift tip outside of or on the domain has been detected and is being processed...');
     117
     118                                %check that only one point is outsie (for now)
     119                                if sum(~flags)~=1,
     120                                        error('bamg error message: only one point outside of the domain is supported yet');
    85121                                end
    86122
    87                         elseif i>1
    88                                 %rift
    89                                 nods=domain(i).nods-1;
    90                                 bamg_geometry.Vertices=[bamg_geometry.Vertices; [domain(i).x(:) domain(i).y(:) ones(nods+1,1)]];
     123                                %Move tip outside to the first position
     124                                if flags(1)==0,
     125                                        %OK, first point is outside (do nothing),
     126                                elseif (flags(end)==0),
     127                                        rift(i).x=flipud(rift(i).x);
     128                                        rift(i).y=flipud(rift(i).y);
     129                                else
     130                                        error('bamg error message: only a rift tip can be outside of the domain');
     131                                end
     132
     133                                %Get cordinate of intersection point
     134                                x1=rift(i).x(1); y1=rift(i).y(1);
     135                                x2=rift(i).x(2); y2=rift(i).y(2);
     136                                for j=1:length(domain(1).x)-1;
     137                                        if SegIntersect([x1 y1; x2 y2],[domain(1).x(j) domain(1).y(j); domain(1).x(j+1) domain(1).y(j+1)]),
     138
     139                                                %Get position of the two nodes of the edge in domain
     140                                                i1=j;
     141                                                i2=mod(j+1,domain(1).nods-1);
     142
     143                                                %rift is crossing edge [i1 i2] of the domain
     144                                                %Get coordinate of intersection point (http://mathworld.wolfram.com/Line-LineIntersection.html)
     145                                                x3=domain(1).x(i1); y3=domain(1).y(i1);
     146                                                x4=domain(1).x(i2); y4=domain(1).y(i2);
     147                                                x=det([det([x1 y1; x2 y2])  x1-x2;det([x3 y3; x4 y4])  x3-x4])/det([x1-x2 y1-y2;x3-x4 y3-y4]);
     148                                                y=det([det([x1 y1; x2 y2])  y1-y2;det([x3 y3; x4 y4])  y3-y4])/det([x1-x2 y1-y2;x3-x4 y3-y4]);
     149
     150                                                %Add intersection point to Vertices
     151                                                bamg_geometry.Vertices=[bamg_geometry.Vertices; x y 1];
     152                                                count=count+1;
     153
     154                                                %Decompose the crossing edge in 2 subedges
     155                                                pos=find(bamg_geometry.Edges(:,1)==i1 & bamg_geometry.Edges(:,2)==i2);
     156                                                if isempty(pos) error('bamg error message: a problem occured...'); end
     157                                                bamg_geometry.Edges=[bamg_geometry.Edges(1:pos-1,:);...
     158                                                        bamg_geometry.Edges(pos,1) count                           bamg_geometry.Edges(pos,3);...
     159                                                        count                      bamg_geometry.Edges(pos,2)   bamg_geometry.Edges(pos,3);...
     160                                                        bamg_geometry.Edges(pos+1:end,:)];
     161
     162                                                %OK, no we can add our own rift
     163                                                nods=rift(i).nods-1;
     164                                                bamg_geometry.Vertices=[bamg_geometry.Vertices; [rift(i).x(2:end) rift(i).y(2:end) ones(nods,1)]];
     165                                                bamg_geometry.Edges=[bamg_geometry.Edges;...
     166                                                        count  count+1  2 ;...
     167                                                        [transp(count+1:count+nods-1) transp([count+2:count+nods])  2*ones(nods-1,1)]];
     168                                                count=count+nods;
     169
     170                                                disp(' done'); break;
     171                                        end
     172                                end
     173                        else
     174                                nods=rift(i).nods-1;
     175                                bamg_geometry.Vertices=[bamg_geometry.Vertices; [rift(i).x(:) rift(i).y(:) ones(nods+1,1)]];
    91176                                bamg_geometry.Edges=[bamg_geometry.Edges; [transp(count+1:count+nods) transp([count+2:count+nods+1])  2*ones(nods,1)]];
    92 
    93                         else
    94                                 error('bamg error message: the first domain should be closed');
     177                                count=count+nods+1;
    95178                        end
    96                         count=count+nods;
    97                 end
    98                 if exist(options,'hVertices'),
    99                         bamg_geometry.hVertices=getfieldvalueerr(options,'hVertices');
    100                         if length(bamg_geometry.hVertices)~=nods,
    101                                 error(['hVertices option should be of size [' num2str(nods) ',1]']);
    102                         end
    103                 end
    104                 bamg_geometry.NumVertices=size(bamg_geometry.Vertices,1);
    105                 bamg_geometry.NumEdges=size(bamg_geometry.Edges,1);
    106                 bamg_geometry.NumSubDomains=size(bamg_geometry.SubDomains,1);
    107         end
     179                end
     180        end
     181
     182        if exist(options,'hVertices'),
     183                bamg_geometry.hVertices=getfieldvalueerr(options,'hVertices');
     184                if length(bamg_geometry.hVertices)~=nods,
     185                        error(['hVertices option should be of size [' num2str(nods) ',1]']);
     186                end
     187        end
     188
     189        %update other fields of bamg_geometry
     190        bamg_geometry.NumVertices=size(bamg_geometry.Vertices,1);
     191        bamg_geometry.NumEdges=size(bamg_geometry.Edges,1);
     192        bamg_geometry.NumSubDomains=size(bamg_geometry.SubDomains,1);
    108193end
    109194%}}}
Note: See TracChangeset for help on using the changeset viewer.