NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/FEM/basis2d.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function [phi,jj]=basis2d(fem_grid_struct,xylist,j)
2 %BASIS2D compute basis functions for input points in FEM grid
3 %   BASIS2D computes the FEM basis functions for a given
4 %   horizontal position, specified either in the argument
5 %   list or with the mouse.
6 %
7 %   In determining which element has been selected,
8 %   BASIS2D needs elemental areas and shape functions.
9 %   Element areas are returned by LOADGRID.
10 %   The routine BELINT computes shape function information
11 %   and attaches it to the input fem_grid_struct.
12 %   These two functions MUST be run before BASIS2D will
13 %   run.
14 %
15 %   BELINT is run as:
16 %      new_struct=belint(fem_grid_struct);
17 %   If ever needed, EL_AREAS is run as:
18 %      [new_struct,ineg]=el_areas(fem_grid_struct);
19 %
20 %   INPUT : fem_grid_struct - (from LOADGRID, see FEM_GRID_STRUCT)     
21 %           xylist  (op)    - points to find elements for [n x 2 double]
22 %           j       (op)    - element list corresponding to the xylist
23 %                             set of points.  Optional, but isf passed in,
24 %                             points will not be relocated. length(j) must
25 %                             equal length(xylist).
26 %           
27 %   OUTPUT : basis function(s) and element number(s)
28 %            If elements were NOT passed in, then providing two output
29 %            arguments will collect the elements determined to contain the
30 %            specified points.
31 %
32 %   CALL : >> [phi,j]=basis2d(fem_grid_struct)   for interactive
33 %    or
34 %          >> [phi,j]=basis2d(fem_grid_struct,xylist)       
35 %    or
36 %          >> phi=basis2d(fem_grid_struct,xylist,j)       
37 %
38 % Written by : Brian O. Blanton
39 % Summer 1998
40 %
41
42 % Input arguemnt number check
43 nargchk(1,3,nargin);
44
45 if nargin==3 & nargout==2
46    error('cannot input AND output element list to BASIS2D')
47 end
48
49 if nargin==1
50    % VERIFY INCOMING STRUCTURE
51    %
52    if ~is_valid_struct(fem_grid_struct)
53       error('    Grid argument to BASIS2D must be a valid fem_grid_struct.')
54    end
55
56    % Make sure additional needed fields of the fem_grid_struct
57    % have been filled.
58    if ~is_valid_struct2(fem_grid_struct)
59       error('    fem_grid_struct to BASIS2D invalid.')
60    end
61    xylist=[];
62    j=[];
63 elseif nargin==2 | nargin==3
64    % second argument must be Nx2
65    [m,n]=size(xylist);
66    if n~=2 & m~=2
67       error('xylist to BASIS1D must be Nx2')
68    end
69    
70    % allow for possible 2 x N shape
71    if n>2
72       xylist=xylist';
73    end
74
75    [n,m]=size(xylist);  % resize after possible transpose
76    
77    xp=xylist(:,1);
78    yp=xylist(:,2);
79    if nargin==3
80       [mj,nj]=size(j);
81       if mj~=1 & nj~=1
82          error(' element list to BASIS2D is not a 1-D vector.')
83       end
84       nj=max(mj,nj);
85       if n~=nj
86          error('length of xylist and element list are NOT equal!')
87       end
88       j=j(:);
89    else
90       j=[];
91    end
92    
93 end
94
95 % If no points were input, use mouse to select a
96 % set of points
97 if isempty(xylist)
98    disp('Click on element ...');
99    waitforbuttonpress;
100    Pt=gcp;
101    xp=Pt(2);yp=Pt(4);
102    line(xp,yp,'Marker','+')
103    xylist=[xp(:) yp(:)];
104 end
105 if isempty(j)
106  % Get the element number containing points
107    j=findelem(fem_grid_struct,xylist);
108 end
109
110 inan=find(~isnan(j));
111
112 if isempty(inan)
113    phi=[];
114    j=[];
115    return;
116 end
117
118 phi=NaN*ones(length(j),3);
119
120 % Extract local information
121 n3=fem_grid_struct.e(j(inan),:);
122 x=reshape(fem_grid_struct.x(n3),size(n3));
123 x1=x(:,1);x2=x(:,2);x3=x(:,3);
124 y=reshape(fem_grid_struct.y(n3),size(n3));
125 y1=y(:,1);y2=y(:,2);y3=y(:,3);
126 area=fem_grid_struct.ar(j(inan));
127
128 xptemp=xp(inan);
129 yptemp=yp(inan);
130
131 % Basis function #1
132 a=(x2.*y3-x3.*y2)./(2.0*area);
133 b=(y2-y3)./(2.0*area);
134 c=-(x2-x3)./(2.0*area);
135 phi(inan,1)=a+b.*xptemp+c.*yptemp;
136
137 % Basis function #2
138 a=(x3.*y1-x1.*y3)./(2.0*area);
139 b=(y3-y1)./(2.0*area);
140 c=-(x3-x1)./(2.0*area);
141 phi(inan,2)=a+b.*xptemp+c.*yptemp;
142
143 % Basis function #3
144 a=(x1.*y2-x2.*y1)./(2.0*area);
145 b=(y1-y2)./(2.0*area);
146 c=-(x1-x2)./(2.0*area);
147 phi(inan,3)=a+b.*xptemp+c.*yptemp;
148
149 if nargout==0
150    clear j phi
151 end
152
153 %
154 %        Brian O. Blanton
155 %        Department of Marine Sciences
156 %        15-1A Venable Hall
157 %        CB# 3300
158 %        Uni. of North Carolina
159 %        Chapel Hill, NC
160 %                 27599-3300
161 %
162 %        919-962-4466
163 %        blanton@marine.unc.edu
164 %
165 %        Summer 1998
166
167
168
169
170
Note: See TracBrowser for help on using the browser.