1 |
% EL_AREAS - compute triangular finite element areas |
---|
2 |
% |
---|
3 |
% EL_AREAS(FEM_GRID_STRUCT) computes the areas for the |
---|
4 |
% elements of the FEM domain described in the |
---|
5 |
% structure FEM_GRID_STRUCT. The function must |
---|
6 |
% return a new structure, which is identical to the |
---|
7 |
% input structure with the element areas attached. |
---|
8 |
% The element areas are contained in the field .ar, |
---|
9 |
% so that the new structure now includes: |
---|
10 |
% |
---|
11 |
% .ar - element areas [ne x 1 double] |
---|
12 |
% |
---|
13 |
% |
---|
14 |
% EL_AREAS optionally returns an index of element |
---|
15 |
% numbers whose areas are negative (if any). |
---|
16 |
% Negative element areas indicate clockwise elemental |
---|
17 |
% node numbering, instead of the conventional counter- |
---|
18 |
% clockwise numbering. |
---|
19 |
% |
---|
20 |
% INPUT : fem_grid_struct - (from LOADGRID, see FEM_GRID_STRUCT) |
---|
21 |
% |
---|
22 |
% OUTPUT : new_struct (REQ) - new structure with areas |
---|
23 |
% ineg (OPT) - index of negative area elements |
---|
24 |
% |
---|
25 |
% CALL : >>new_struct=el_areas(fem_grid_struct); |
---|
26 |
% or |
---|
27 |
% >>[new_struct,ineg]=el_areas(fem_grid_struct); |
---|
28 |
% |
---|
29 |
% Written by : Brian O. Blanton |
---|
30 |
% Summer 1997 |
---|
31 |
% |
---|
32 |
|
---|
33 |
function [ret_struct,ineg]=el_areas(fem_grid_struct) |
---|
34 |
|
---|
35 |
% VERIFY INCOMING STRUCTURE |
---|
36 |
% |
---|
37 |
if ~is_valid_struct(fem_grid_struct) |
---|
38 |
error(' Argument to EL_AREAS must be a valid fem_grid_struct.') |
---|
39 |
end |
---|
40 |
|
---|
41 |
% NEED ONE or TWO OUT ARGS |
---|
42 |
% |
---|
43 |
if nargout~=1 & nargout~=2 |
---|
44 |
error(' EL_AREAS must have 1 or 2 output arguments.') |
---|
45 |
end |
---|
46 |
|
---|
47 |
% BREAK DOWN INCOMING STRUCTURE |
---|
48 |
% |
---|
49 |
e=fem_grid_struct.e; |
---|
50 |
x=fem_grid_struct.x; |
---|
51 |
y=fem_grid_struct.y; |
---|
52 |
|
---|
53 |
% COMPUTE GLOBAL DY |
---|
54 |
% |
---|
55 |
dy=[y(e(:,2))-y(e(:,3)) y(e(:,3))-y(e(:,1)) y(e(:,1))-y(e(:,2))]; |
---|
56 |
|
---|
57 |
% COMPUTE ELEMENTAL AREAS |
---|
58 |
% |
---|
59 |
AR=(x(e(:,1)).*dy(:,1)+x(e(:,2)).*dy(:,2)+x(e(:,3)).*dy(:,3))/2.; |
---|
60 |
|
---|
61 |
%Create return structure and attach element areas to ret_struct |
---|
62 |
% |
---|
63 |
ret_struct=fem_grid_struct; |
---|
64 |
ret_struct.ar=AR; |
---|
65 |
|
---|
66 |
if nargout==2 |
---|
67 |
% ANY NEGATIVE OR ZERO AREAS ? |
---|
68 |
% |
---|
69 |
ineg=find(AR<=0); |
---|
70 |
end |
---|
71 |
|
---|
72 |
% |
---|
73 |
% Brian O. Blanton |
---|
74 |
% Curriculum in Marine Sciences |
---|
75 |
% Ocean Processes Numerical Modeling Laboratory |
---|
76 |
% 15-1A Venable Hall |
---|
77 |
% CB# 3300 |
---|
78 |
% Uni. of North Carolina |
---|
79 |
% Chapel Hill, NC |
---|
80 |
% 27599-3300 |
---|
81 |
% |
---|
82 |
% 919-962-4466 |
---|
83 |
% blanton@marine.unc.edu |
---|
84 |
% |
---|
85 |
% October 1995 |
---|
86 |
% |
---|