Changeset 22212


Ignore:
Timestamp:
11/02/17 14:18:56 (7 years ago)
Author:
Mathieu Morlighem
Message:

NEW: added holes and subdomains options, provided as extra .exp files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/mesh/bamg.m

    r22210 r22212  
    55%
    66%   - domain :            followed by an ARGUS file that prescribes the domain outline
     7%   - holes :             followed by an ARGUS file that prescribes the holes
     8%   - subdomains :        followed by an ARGUS file that prescribes the list of
     9%                         subdomains (that need to be inside domain)
     10%
    711%   - hmin :              minimum edge length (default is 10^-100)
    812%   - hmax :              maximum edge length (default is 10^100)
     
    5963
    6064subdomain_ref = 1;
     65hole_ref = 1;
    6166% Bamg Geometry parameters {{{
    6267if exist(options,'domain'),
     
    8287        end
    8388
     89        holes = [];
     90        if exist(options,'holes'),
     91                holesfile=getfieldvalue(options,'holes');
     92                if ischar(holesfile),
     93                        if ~exist(holesfile,'file') error(['bamg error message: file ' holesfile ' not found']); end
     94
     95                        %read holes according to its extension:
     96                        [path,name,ext]=fileparts(holesfile);
     97                        if strcmp(ext,'.exp'),
     98                                holes=expread(holesfile);
     99                        elseif strcmp(ext,'.shp'),
     100                                holes=shpread(holesfile);
     101                        else
     102                                error(['bamg error message: file ' holesfile ' format not supported (.shp or .exp)']);
     103                        end
     104                elseif isstruct(holesfile),
     105                        holes = holesfile;
     106                else
     107                        error('''holes'' type not supported yet');
     108                end
     109        end
     110        subdomains = [];
     111        if exist(options,'subdomains'),
     112                subdomainsfile=getfieldvalue(options,'subdomains');
     113                if ischar(subdomainsfile),
     114                        if ~exist(subdomainsfile,'file') error(['bamg error message: file ' subdomainsfile ' not found']); end
     115
     116                        %read subdomains according to its extension:
     117                        [path,name,ext]=fileparts(subdomainsfile);
     118                        if strcmp(ext,'.exp'),
     119                                subdomains=expread(subdomainsfile);
     120                        elseif strcmp(ext,'.shp'),
     121                                subdomains=shpread(subdomainsfile);
     122                        else
     123                                error(['bamg error message: file ' subdomainsfile ' format not supported (.shp or .exp)']);
     124                        end
     125                elseif isstruct(subdomainsfile),
     126                        subdomains = subdomainsfile;
     127                else
     128                        error('''subdomains'' type not supported yet');
     129                end
     130        end
     131
    84132        %Build geometry
    85133        count=0;
     
    99147                end
    100148
     149                %Check orientation
     150                nods=domain(i).nods-1; %the domain are closed 1=end;
     151                test = sum([(domain(i).x(2:nods+1) - domain(i).x(1:nods)).*(domain(i).y(2:nods+1) + domain(i).y(1:nods))]);
     152                if (i==1 && test>0) || (i>1 && test<0),
     153                        disp('At least one contour was not correctly oriented and has been re-oriented');
     154                        domain(i).x = flipud(domain(i).x); domain(i).y = flipud(domain(i).y);
     155                end
     156
    101157                %Add all points to bamg_geometry
    102                 nods=domain(i).nods-1; %the domain are closed 1=end;
    103158                bamg_geometry.Vertices=[bamg_geometry.Vertices; [domain(i).x(1:nods) domain(i).y(1:nods) ones(nods,1)]];
     159                bamg_geometry.Edges   =[bamg_geometry.Edges;    [transpose(count+1:count+nods) transpose([count+2:count+nods count+1])  1*ones(nods,1)]];
     160                if i>1,
     161                        bamg_geometry.SubDomains=[bamg_geometry.SubDomains; 2 count+1 1 -subdomain_ref]; subdomain_ref = subdomain_ref+1;
     162                else
     163                        bamg_geometry.SubDomains=[bamg_geometry.SubDomains; 2 count+1 1 0];
     164                end
     165
     166                %update counter
     167                count=count+nods;
     168        end
     169        for i=1:length(holes),
     170
     171                %Check that the subdomains is closed
     172                if (holes(i).x(1)~=holes(i).x(end) | holes(i).y(1)~=holes(i).y(end)),
     173                        error('bamg error message: all contours provided in ''holes'' should be closed');
     174                end
     175
     176                %Checks that all holes are INSIDE the principle domain outline
     177                flags=ContourToNodes(holes(i).x,holes(i).y,domain(1),0);
     178                if any(~flags), error('bamg error message: All holes should be strictly inside the principal domain'); end
     179
     180                %Check that hole is correctly oriented
     181                nods=holes(i).nods-1; %the holes are closed 1=end;
     182                if(sum([(holes(i).x(2:nods+1) - holes(i).x(1:nods)).*(holes(i).y(2:nods+1) + holes(i).y(1:nods))]))<0
     183                        disp('At least one hole was not correctly oriented and has been re-oriented');
     184                        holes(i).x = flipud(holes(i).x); holes(i).y = flipud(holes(i).y);
     185                end
     186
     187                %Add all points to bamg_geometry
     188                bamg_geometry.Vertices=[bamg_geometry.Vertices; [holes(i).x(1:nods) holes(i).y(1:nods) ones(nods,1)]];
    104189                bamg_geometry.Edges   =[bamg_geometry.Edges;    [transpose(count+1:count+nods) transpose([count+2:count+nods count+1])  1.*ones(nods,1)]];
    105                 if i>1, bamg_geometry.SubDomains=[bamg_geometry.SubDomains; 2 count+1 1 subdomain_ref]; subdomain_ref = subdomain_ref+1; end
     190                bamg_geometry.SubDomains=[bamg_geometry.SubDomains; 2 count+1 1 -hole_ref]; hole_ref = hole_ref+1;
     191
     192                %update counter
     193                count=count+nods;
     194        end
     195        for i=1:length(subdomains),
     196
     197                %Check that the subdomains is closed
     198                if (subdomains(i).x(1)~=subdomains(i).x(end) | subdomains(i).y(1)~=subdomains(i).y(end)),
     199                        error('bamg error message: all contours provided in ''subdomains'' should be closed');
     200                end
     201
     202                %Checks that all holes are INSIDE the principle domain outline
     203                flags=ContourToNodes(subdomains(i).x,subdomains(i).y,domain(1),0);
     204                if any(~flags),
     205                        error('bamg error message: All holes should be strictly inside the principal domain');
     206                end
     207
     208                %Check that hole is correctly oriented
     209                nods=subdomains(i).nods-1; %the subdomains are closed 1=end;
     210                if(sum([(subdomains(i).x(2:nods+1) - subdomains(i).x(1:nods)).*(subdomains(i).y(2:nods+1) + subdomains(i).y(1:nods))]))>0
     211                        disp('At least one subdomain was not correctly oriented and has been re-oriented');
     212                        subdomains(i).x = flipud(subdomains(i).x); subdomains(i).y = flipud(subdomains(i).y);
     213                end
     214
     215                %Add all points to bamg_geometry
     216                bamg_geometry.Vertices=[bamg_geometry.Vertices; [subdomains(i).x(1:nods) subdomains(i).y(1:nods) ones(nods,1)]];
     217                bamg_geometry.Edges   =[bamg_geometry.Edges;    [transpose(count+1:count+nods) transpose([count+2:count+nods count+1])  1.*ones(nods,1)]];
     218                bamg_geometry.SubDomains=[bamg_geometry.SubDomains; 2 count+1 1 subdomain_ref]; subdomain_ref = subdomain_ref+1;
    106219
    107220                %update counter
Note: See TracChangeset for help on using the changeset viewer.