source: issm/trunk-jpl/src/m/contrib/tsantos/integrate_field.m

Last change on this file was 26228, checked in by tsantos, 4 years ago

ADD: function to integrate a field over a 2d mesh

File size: 613 bytes
Line 
1function total=integrate_field(index,x,y,field)
2%INTEGRATE_FIELD: integrate a field over a 2D mesh
3%
4% Usage:
5% total=integrate_field(index,x,y,field);
6%
7% Examples:
8% volume=integrate_field(md.mesh.elements,md.mesh.x,md.mesh.y,md.geometry.thickness);
9
10% areas of each element
11x1=x(index(:,1)); x2=x(index(:,2)); x3=x(index(:,3));
12y1=y(index(:,1)); y2=y(index(:,2)); y3=y(index(:,3));
13areas=(0.5*((x2-x1).*(y3-y1)-(y2-y1).*(x3-x1)));
14
15% element-wise integration
16v1=index(:,1); v2=index(:,2); v3=index(:,3);
17elem_int=areas.*mean(field([v1 v2 v3]),2);
18
19% compute integration
20total=sum(elem_int);
21
22end
Note: See TracBrowser for help on using the repository browser.