1 | function md=BasinConstrain(md,domain);
|
---|
2 | %BASINCONSTRAIN - constrain basin
|
---|
3 | %
|
---|
4 | % Constrain basin using a constraint domain outline,
|
---|
5 | % to dirichlet boundary conditions.
|
---|
6 | % constraindomain is an Argus domain outline file enclosing
|
---|
7 | % the geographical area of interest.
|
---|
8 | %
|
---|
9 | % Usage:
|
---|
10 | % md=BasinConstrain(md,constraindomain)
|
---|
11 | %
|
---|
12 | % Example:
|
---|
13 | % md=BasinConstrain(md,'DomainOutline.exp');
|
---|
14 | % md=BasinConstrain(md,'~Iceshelves.exp');
|
---|
15 |
|
---|
16 | %now, flag grids and elements outside the domain outline.
|
---|
17 | if ischar(domain),
|
---|
18 | if isempty(domain),
|
---|
19 | elementondomain=zeros(md.numberofelements,1);
|
---|
20 | gridondomain=zeros(md.numberofgrids,1);
|
---|
21 | invert=0;
|
---|
22 | elseif strcmpi(domain,'all')
|
---|
23 | elementondomain=ones(md.numberofelements,1);
|
---|
24 | gridondomain=ones(md.numberofgrids,1);
|
---|
25 | invert=0;
|
---|
26 | else
|
---|
27 | %make sure that we actually don't want the elements outside the domain outline!
|
---|
28 | if strcmpi(domain(1),'~'),
|
---|
29 | domain=domain(2:end);
|
---|
30 | invert=1;
|
---|
31 | else
|
---|
32 | invert=0;
|
---|
33 | end
|
---|
34 | %ok, flag elements and nodes
|
---|
35 | [gridondomain elementondomain]=ContourToMesh(md.elements(:,1:3),md.x,md.y,expread(domain,1),'element and node',2);
|
---|
36 | end
|
---|
37 | if invert,
|
---|
38 | gridondomain=~gridondomain;
|
---|
39 | elementondomain=~elementondomain;
|
---|
40 | end
|
---|
41 | else
|
---|
42 | error('BasinConstrain error message: domain type not supported yet');
|
---|
43 | end
|
---|
44 |
|
---|
45 | %list of elements and nodes not on domain
|
---|
46 | gridnotondomain=find(~gridondomain);
|
---|
47 | elementnotondomain=find(~elementondomain);
|
---|
48 |
|
---|
49 | %all elements outside the constraint domain are equivalent to water. all grids outside are spc'd.
|
---|
50 | md.gridondirichlet_diag(gridnotondomain)=1;
|
---|
51 | md.dirichletvalues_diag(gridnotondomain,1)=md.vx_obs(gridnotondomain);
|
---|
52 | md.dirichletvalues_diag(gridnotondomain,2)=md.vy_obs(gridnotondomain);
|
---|
53 | md.elementonwater(elementnotondomain)=1;
|
---|
54 |
|
---|
55 | %now, make sure all elements on water have grids that are spc'd, otherwise, we'll get a singular problem.
|
---|
56 | pos=find(~md.elementonwater);
|
---|
57 | numpos=unique(md.elements(pos,:));
|
---|
58 | grids=setdiff(1:1:md.numberofgrids,numpos);
|
---|
59 | md.gridondirichlet_diag(grids)=1;
|
---|
60 | md.dirichletvalues_diag(grids,1)=md.vx_obs(grids);
|
---|
61 | md.dirichletvalues_diag(grids,2)=md.vy_obs(grids);
|
---|
62 |
|
---|
63 |
|
---|
64 | %make sure any grid with NaN velocity is spc'd:
|
---|
65 | pos=find(isnan(md.vel_obs_raw));
|
---|
66 | md.gridondirichlet_diag(pos)=1;
|
---|
67 | %we spc to the smoothed value, so that control methods don't go berserk trying to figure out what reaction force to apply for the spc to stand.
|
---|
68 | md.dirichletvalues_diag(pos,1)=md.vx_obs(pos);
|
---|
69 | md.dirichletvalues_diag(pos,2)=md.vy_obs(pos);
|
---|
70 |
|
---|
71 | %make sure icefronts that are completely spc'd are taken out:
|
---|
72 | free_segments=find(sum(md.gridondirichlet_diag(md.segmentonneumann_diag(:,1:2)),2)~=2);
|
---|
73 | md.segmentonneumann_diag=md.segmentonneumann_diag(free_segments,:);
|
---|