SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
Problem Solving by Computer: Finite Element Method Assignment
by Peter Herbert, University of Manchester
1 Generating Simplicial Meshes
Finding analytic solutions to Partial Differential Equations (PDEs) can sometimes be very difficult. One method for
finding approximate solutions to a PDE problem that has boundary conditions is to use Finite Element Methods (FEM)
that are introduced in [1]. This involves taking the region over which the PDE is being considered, and dividing it into
pieces that are more basic.
In MATH31072 Algebraic Topology, a Geometric Simplicial Surface is defined as a finite set of triangles in some Euclidean
space, satisfying a set of conditions that specify the manner in which triangles are connected together to form a mesh.
A further theorem from the course, proved by Tibor Rad´o, is that every closed surface can be triangulated. Using a
simplicial mesh also helps to make a grid that can fit otherwise awkwardly shaped domains.
Before considering a particular PDE problem, setting up the tools for the numerical implementation of the Finite El-
ement Methods is necessary. There are several packages available for different piece of software. One such program is
available from [2], for use in MATLAB, to generate different kinds of meshes for a variety of geometric objects. The
function distmesh2d takes various inputs that control different aspects of the output mesh. These inputs and outputs
are detailed further in both the code and on page 4 of [3]. The code beside each of these examples comes from the script
examples.m.
The first input is the distance function fd. This is a function that returns the distance from each node to the nearest
boundary. Generating such a function for a standard shape region can be done using one of the presets such as dcircle,
drectangle, dpolygon, or ddiff. This only really needs to change if the domain of the problem changes shape.
(a) A circle (b) An irregular polygon (c) The set difference
Figure 1: Simplicial meshes for differently shaped domains.
1 %%-1.1Circle-%%
2 figure();
3 fd=@(p) dcircle(p,0,0,1);
4 distmesh2d(fd,@huniform,0.2,[-1,-1;1,1],[]);
5 %%-1.2Irregular Polygon-%%
6 figure();
7 pv=[0 1.6;2 2.5;2 -1.4;0.6 -1.5;-0.1 -2.5;...
8 -0.8 -1.4;-2.5 0.2;-2 1.2;-0.7 2.5;0 1.6];
9 distmesh2d(@dpoly,@huniform,0.4,[-2.5,-2.5;2.5,2.5],pv,pv);
10 %%-1.3Set Difference-%%
11 figure();
12 pv=[0 1.6;2 2.5;2 -1.4;0.6 -1.5;-0.1 -2.5;...
13 -0.8 -1.4;-2.5 0.2;-2 1.2;-0.7 2.5;0 1.6];
14 fd=@(p) ddiff(dpoly(p,pv),dcircle(p,0,0,1));
15 distmesh2d(fd,@huniform,0.3,[-2.5,-2.5;2.5,2.5],pv);
1
The second input takes a function h(x, y) which is responsible for the relative distribution of edge lengths in the mesh.
That is to say h(x, y) controls whether the mesh is uniform or not, and how refined specific areas of the mesh are when it
is not uniform. Because it is the relative distribution, scaling h(x, y) will not make the mesh more refined overall. For a
uniform mesh, h(x, y) = constant.
(a) A uniform mesh with evenly
distributed edge lengths.
(b) A non-uniform mesh concentrated
in the middle.
(c) A non-uniform mesh concentrated
at the corners.
Figure 2: Simplicial meshes of a unit square demonstrating how the distribution of edge lengths can be manipulated.
1 %%-2.1Uniform Mesh-%%
2 figure();
3 fd=@(p) drectangle(p,0,1,0,1);
4 distmesh2d(fd,@huniform,0.1,[0,0;1,1],[0,0;1,0;0,1;1,1]);
5 %%-2.2Non-Uniform Centered Mesh-%%
6 figure();
7 fd=@(p) drectangle(p,0,1,0,1);
8 fh=@(p) 0.01+0.3*abs(dcircle(p,0.5,0.5,0));
9 distmesh2d(fd,fh,0.01,[0,0;1,1],[0,0;1,0;0,1;1,1]);
10 %%-2.3Non-Uniform Boundary Mesh-%%
11 figure();
12 fd=@(p) drectangle(p,0,1,0,1);
13 fh=@(p) 0.01+0.3*abs(dcircle(p,0.5,0.5,(sqrt(2))ˆ-1));
14 distmesh2d(fd,fh,0.01,[0,0;1,1],[0,0;1,0;0,1;1,1]);
The next input h0 is the distance between points in the initial distribution. This is the factor to change in order to alter
the fineness of triangulation. When working with dpoly, it is very important to repeat the first vertex at the end of the
list of vertices, as this makes the triangulation algorithm more stable.
(a) Very low mesh refinement. (b) A well refined mesh. (c) A heavily refined mesh.
Figure 3: Simplicial meshes that have increasing mesh refinement.
2
1 %%-3.1Large Mesh-%%
2 figure();
3 fd=@(p) drectangle(p,0,1,0,1);
4 distmesh2d(fd,@huniform,0.3,[0,0;1,1],[0,0;1,0;0,1;1,1]);
5 %%-3.2Intermediate Mesh-%%
6 figure();
7 fd=@(p) drectangle(p,0,1,0,1);
8 distmesh2d(fd,@huniform,0.1,[0,0;1,1],[0,0;1,0;0,1;1,1]);
9 %%-3.3Small Mesh-%%
10 figure();
11 fd=@(p) drectangle(p,0,1,0,1);
12 distmesh2d(fd,@huniform,0.05,[0,0;1,1],[0,0;1,0;0,1;1,1]);
The input bbox describes the boundary box that confines the area where points are positioned whilst the mesh is being
constructed. Finally, pfix picks out points that stay fixed whilst the mesh is being constructed, for instance vertices
defining a polygonal domain for the problem. These inputs hold very important information, but in general do not need
to be adjusted for a particular problem. The function distmesh2d not only produces the graphical representation of the
mesh, but also returns the data for the positions of each point as variable p, and a list of which points are in each simplex,
as variable t.
2 Cotangent Laplacian
2.1 Approximation of Laplacian Operator
The cotangent Laplacian is a finite approximation to the Laplacian operator, 2
, over the domain of the problem. The
cotangent Laplacian takes the form of a |V |×|V | laplacian matrix K for a weighted graph G(V, E), and is given by
Kij =



1
2 cot(θ+
) + 1
2 cot(θ−
) if (i, j) ∈ E
−
(i,j)∈E
Kij if i = j
0 Otherwise
,
where the angles θ+
and θ−
are angles in distinct triangles, that oppose the edge between vertices vi and vj, as shown in
Figure (4a) and Figure (4b). For edges on the boundary, there is only one corresponding angle opposite it, hence there is
only one cotangent term contributing to that value. The derivation of this approximation is discussed in more detail in
‘3. Discrete Laplacians’ in [5].
(a) Interior edge in red. (b) Boundary edge in red.
Figure 4: Diagram showing the angles used to calculate the (i, j)th
entry of the cotangent Laplacian
The function cotan takes each triangle from t, and stores the vertex indices in ascending order, in variable ti. This is
so that creating the strictly upper triangular part of the cotangent Laplacian K is simplified. The variable pos stores the
vector corresponding to the edge opposite the vertex in the corresponding entry of ti. The direction of each edge vector
3
preserves the orientation of the triangle. Then for each vertex in the triangle, the 1
2 cot(θ) term for the angle at that vertex
is calculated by evaluating the dot product, and the norm of the cross product. This is then added to the Kij, (i < j)
entry of the cotangent Laplacian. The final lines of the function take the strictly upper triangular matrix and add it to
it’s transpose, making K symmetric, and filling in the diagonal such that the column summations equal zero.
1 function K=cotan(p,t)
2 %COTAN calculates cotangent laplacian matrix K given positions of vertices p
3 % and list of vertices in each triangle t.
4 K=zeros(length(p));
5 for i=1:length(t)
6 ti=sort(t(i,:));%Choose a triangle, and put indices in increasing order.
7 pos=zeros(3,3);%Going to store vector of the edge opposite corresponding vertex in ti.
8 pos(1,:)=[p(ti(3),1)-p(ti(2),1),p(ti(3),2)-p(ti(2),2),0];%edge v2 to v3 - opposite v1.
9 pos(2,:)=[p(ti(1),1)-p(ti(3),1),p(ti(1),2)-p(ti(3),2),0];%edge v3 to v1 - opposite v2.
10 pos(3,:)=[p(ti(2),1)-p(ti(1),1),p(ti(2),2)-p(ti(1),2),0];%edge v1 to v2 - opposite v3.
11 for v=ti
12 X=[pos(ti~=v,:)];%Putting the edge opposite the vertex last, means it can be found easily.
13 Y=ti(ti~=v);
14 coangl=-dot(X(1,:),X(2,:))/norm(cross(X(1,:),X(2,:)));%Calculating the cotangent of the angle between vectors.
15 K(Y(1),Y(2))=K(Y(1),Y(2))+(0.5*(coangl));%Add cotangent term to upper triangular entry as Y(1)<=Y(2).
16 end
17 end
18 K=K+K';%Turns upper triangular matrix into symmetric matrix.
19 indx=logical(eye(length(p)));
20 K(indx)=-sum(K,2);%Fill in the diagonal entries of the Laplacian. Column and row sum is now zero.
21 end
2.2 Application to Partial Differencial Equations
The Laplacian operator, 2
= ∂2
∂x2 + ∂2
∂y2 is used in many different equations. One such equation is Poisson’s equa-
tion,
2
u = q.
Here, q is a known forcing term, and the PDE is being solved for u. Laplace’s equation is the homogeneous Poisson’s
equation, i.e. 2
u = 0.
Finding solutions to these PDEs can be done if boundary conditions are imposed. Consider a PDE that is to be solved
over a domain Ω ⊆ R2
. A Dirichlet boundary condition has the form
u(x, y) = f(x, y), for (x, y) ∈ ∂Ω,
for some suitably differentiable function f, so this fixes the value at the boundary. A Neumann boundary condition has
the form
∂
∂n
u(x, y) = u(x, y) · n = g(x, y), for (x, y) ∈ ∂Ω
for outward unit normal n on the boundary, and some function g. Since u is a vector that points of the direction for
which u increases the quickest, u · n quantifies how quickly u is increasing perpendicular to the boundary. Hence the
Neumann Boundary Condition fixes how quickly u increases across the boundary. As this boundary condition is expressed
in terms of a derivative, the solution u will only be unique up to the addition of a constant, whilst the solution to a
Dirichlet problem will be unique.
It should be noted that Laplace’s Equation is satisfied by either the real or imaginary part of an analytic function of
z = x + yi ∈ C. For example, if U(z) = z2
= (x + iy)2
= (x2
− y2
) + (2xy)i, then x2
− y2
and 2xy satisfy Laplace’s
Equation. This is because a complex analytic function f(z) = u(x, y) + iv(x, y), z = x + iy ∈ C satisfies the Cauchy-
Riemann equations ux = vy and uy = −vx, which leads to uxx = −uyy and similarly for v. By De Moivre’s theorem,
zm
= rm
(cos(θ) + isin(θ))m
= rm
(cos(mθ) + isin(mθ)),
so these solutions will have a periodic behaviour that is related to the value of m.
One way to test the cotangent Laplacian is to apply it in the context of partial differential equations. By solving a Dirichlet
problem and a Neumann problem for which the exact solutions are known, the approximate solutions can be compared
4
to their exact solutions. Doing this at a number of mesh sizes will demonstrate the manner in which the approximate
solutions will converge to their exact solution.
1 %%--cotantest.m--%%
2 for j=[0.1,0.075,0.05];
3 figure('Visible','Off');
4 fd=@(p) dcircle(p,0,0,1);
5 [p,t]=distmesh2d(fd,@huniform,j,[-1,-1;1,1],[]);
6 K=cotan(p,t);% Create Cotangent Laplacian.
7 bvert=boundedges(p,t);bvert=sort(bvert(:,1)); %Finding boundary vertices of mesh.
8 invtx=setdiff(1:size(p,1),bvert)';%Finding interior vertices of mesh.
9 %--Dirichlet Problem--%
10 f=@(x,y) real((x + 1i*y).ˆ6 + (x+1i*y).ˆ3); %Harmonic function to be applied at boundary vertices.
11 ui=K(invtx,invtx)(-K(invtx,bvert)*f(p(bvert,1),p(bvert,2)));%Calculate values at interior vertices.
12 Ufem(invtx)=ui;Ufem(bvert)=f(p(bvert,1),p(bvert,2));
13 Uexact=f(p(:,1),p(:,2));%Analytic solution evaluated at all vertices.
14 error=norm(Uexact'-Ufem,inf)/norm(Uexact',inf);%Error in the approximate solution for this problem.
15 figure();trisurf(t,p(:,1),p(:,2),Ufem); colormap jet;
16 suptitle({['Approximate solution with relative error ',num2str(error)],['h {0}= ',num2str(j)]});
17 %--Neumann Problem--%
18 [th,r]=cart2pol(p(:,1),p(:,2));
19 q=((jˆ2)*sqrt(3)/2)*(3*pi*0.5)*(-(3*pi*0.5)*sin(3*pi*0.5*r(invtx))...
20 + (r(invtx).ˆ-1).*cos(3*pi*0.5*r(invtx)));%The inhomogeneous part of the possion's equation.
21 ui2= K(invtx,invtx)(q);
22 Ufem2(invtx)=ui2;Ufem2(bvert)=0;%Using boundary condition, arbitrarily choose zero at boundary vertices.
23 Uexact2=sin(3*pi*0.5*r)+1;%Analytic solution which is zero on boundary vertices.
24 error2=norm(Uexact2'-Ufem2,inf)/norm(Uexact2',inf);
25 figure();trisurf(t,p(:,1),p(:,2),Ufem2);colormap jet;
26 suptitle({['Approximate solution with relative error ',num2str(error2)],['h {0}= ',num2str(j)]});
27 end
Firstly, consider a Dirichlet problem for Laplace’s equation, where the domain Ω is the unit circle, given by 2
u(x, y) =
0 for (x, y) ∈ Ω and u(x, y) = Re(z6
+ z3
) for (x, y) ∈ ∂Ω, where z = x + iy. This corresponds to the problem solved in
lines 10-16 of cotantest.m.
Note that u(x, y) = Re(z6
+z3
) is a solution to Laplace’s equation in Ω, as it is derived from a complex analytical function
as discussed previously. Since this function is used to define the boundary conditions, u(x, y) = Re(z6
+ z3
) is the exactly
solution to evaluate at all points in the domain, and compare it to the finite element method solution.
Approximate solution with relative error 0.0044703
h0
= 0.1
−1
−0.5
0
0.5
1
−1
−0.5
0
0.5
1
−2
−1
0
1
2
(a)
Approximate solution with relative error 0.0021821
h0
= 0.075
−1
−0.5
0
0.5
1
−1
−0.5
0
0.5
1
−2
−1
0
1
2
(b)
Approximate solution with relative error 0.00093813
h0
= 0.05
−1
−0.5
0
0.5
1
−1
−0.5
0
0.5
1
−2
−1
0
1
2
(c)
Figure 5: Solutions to the Dirichlet problem for Laplace’s equation over increasingly refined meshes.
The results of using the finite element method are shown in Figure 5. The relative error, measure by
uexact − uF EM ∞
uexact ∞
,
shows that as the simplicial mesh becomes more refined, the error in the finite element method solution decreases. When
the mesh size is h0 = 0.1 in Figure 5a, the relative error is approximately 4.5×10−3
. The mesh size decreases linearly until
h0 = 0.05 in Figure 5c, where the relative error has dropped to approximately 9.4×10−4
. Using the script Errorplots.m,
the relative error for mesh sizes specified in variable h is calculated and plotted in a Figure 6. The relative error appears to
increase expotentially as the mesh size increases in increments 0.01, meaning that there is significant advantage to using
a more refined mesh.
5
0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16
0
0.005
0.01
0.015
Errors for Dirichlet problem
RelativeError
Mesh size h0
Figure 6: Relative error for the Dirichlet problem compared to the known exact solution.
The next problem involves the Poisson’s equation 2
u = q, for some function q. It will be necessary to apply a scaling
factor to q. This is because in the problem, q is a function evaluated over the whole of Ω, and the discrete approximation
of this needs to account for the values of this function inside triangles of the mesh. The integral for q from slide 5 of [1]
can be interpreted more simply. It means that the value of q at a vertex needs to be equal to the sum of values of q at
points in the surrounding triangles, weighted by now near the points are to the vertex.
The basic approximation of an integral of a function f is the value of f × (area of region integrating over) . It can be
approximated by barycentric subdivision that, since there are three vertices for each triangle, the integral for such a vertex
V is a third of the integral over the entire triangle. A further approximation is to say that a vertex V is at the centre of
a hexagon, where each surrounding triangle is approximately equilateral, and the area of this hexagon is approximately
3
√
3
2 h2
0. This means that the approximate value of q at a vertex is 1
3 × 3
√
3
2 h2
0 × q. Let A =
√
3
2 h2
0 denote this scaling factor
of q below.
Therefore, consider the Neumann problem for Poisson’s equation given in polar coordinates by
2
u = A −
3π
2
2
sin
3π
2
r +
3π
2r
cos
3π
2
r for (r, θ) ∈ ∂Ω,
u · n
r=1
=
∂u
∂r r=1
= 0,
Here the domain Ω is the unit circle. This boundary condition means that the solution u is only unique up to the
addition of a constant. Having constructed this example with a particular solution, it is known that u = sin 3π
2 r + 1
satisfies these equations, and so this will be the exact solution. This corresponds to the problem solved in lines 18-26 of
cotantest.m
Approximate solution with relative error 0.10744
h0
= 0.1
−1
−0.5
0
0.5
1
−1
−0.5
0
0.5
1
0
0.5
1
1.5
2
(a)
Approximate solution with relative error 0.040693
h0
= 0.075
−1
−0.5
0
0.5
1
−1
−0.5
0
0.5
1
0
0.5
1
1.5
2
(b)
Approximate solution with relative error 0.039153
h0
= 0.05
−1
−0.5
0
0.5
1
−1
−0.5
0
0.5
1
0
0.5
1
1.5
2
(c)
Figure 7: Solutions to the Neumann problem for Poisson’s equation over increasingly refined meshes.
The results of using the finite element method in the script cotantest.m are shown in Figure 7. The relative error in these
diagrams demonstrates that as the mesh becomes more refined, the finite element method constructs a solution which
converges to the exact solution. When the mesh size is h0 = 0.1, as in Figure 7a, the relative error is 0.107. Reducing
the mesh size by 0.025 to h0 = 0.075 in Figure 7b causes the relative error of solution to fall dramatically to 0.041, which
6
is over half the previous error. Finally, in Figure 7c, where the mesh size is h0 = 0.05, the relative error only decreases
by a small amount to 0.039. A more detailed investigation is run by the script Errorplots.m, and the graph in Figure
8 shows the results. The error appears to increase almost linearly as the mesh size is increased linearly in increments of
0.01. In applications, it might be possible to compromise on relative error if the mesh size requires a lot of computational
power.
0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
Errors for Neumann problem
RelativeError
Mesh size h0
Figure 8: Relative error for the Neumann problem compared to the known exact solution.
1 %%--Errorplots.m--%%
2 h=[0.02:0.01:0.15];
3 for j=1:length(h)
4 figure('Visible','Off');
5 fd=@(p) dcircle(p,0,0,1);
6 [p,t]=distmesh2d(fd,@huniform,h(j),[-1,-1;1,1],[]);
7 K=cotan(p,t);% Create Cotangent Laplacian.
8 bvert=boundedges(p,t);bvert=sort(bvert(:,1)); %Finding boundary vertices of mesh.
9 invtx=setdiff(1:size(p,1),bvert)';%Finding interior vertices of mesh.
10 %--Dirichlet Problem--%
11 f=@(x,y) real((x + 1i*y).ˆ6 + (x+1i*y).ˆ3); %Harmonic function to be applied at boundary vertices.
12 ui=K(invtx,invtx)(-K(invtx,bvert)*f(p(bvert,1),p(bvert,2)));%Calculate values at interior vertices.
13 Ufem(invtx)=ui;Ufem(bvert)=f(p(bvert,1),p(bvert,2));
14 Uexact=f(p(:,1),p(:,2));%Analytic solution evaluated at all vertices.
15 error(j)=norm(Uexact'-Ufem,inf)/norm(Uexact',inf);%Error in the approximate solution for this problem.
16 %--Neumann Problem--%
17 [th,r]=cart2pol(p(:,1),p(:,2));
18 q=((h(j)ˆ2)*sqrt(3)/2)*(3*pi*0.5)*(-(3*pi*0.5)*sin(3*pi*0.5*r(invtx))...
19 + (r(invtx).ˆ-1).*cos(3*pi*0.5*r(invtx)));%The inhomogeneous part of the possion's equation.
20 ui2= K(invtx,invtx)(q);
21 Ufem2(invtx)=ui2;Ufem2(bvert)=0;%Using boundary condition, arbitrarily choose zero at boundary vertices.
22 Uexact2=sin(3*pi*0.5*r)+1;%Analytic solution which is zero on boundary vertices.
23 error2(j)=norm(Uexact2'-Ufem2,inf)/norm(Uexact2',inf);
24 clear Ufem Ufem2;
25 end
26 figure();plot(h,error,'-k.');title('Errors for Dirichlet problem');
27 ylabel('Relative Error');xlabel('Mesh size h {0}');
28 figure();plot(h,error2,'-k.');title('Errors for Neumann problem');
29 ylabel('Relative Error');xlabel('Mesh size h {0}');
2.3 The Maximum-Minimum Principle
An additional feature of a Laplace’s equation, which is demonstrated in Figure 5c, is know as the Maximum-Minimum
Principle. This theorem is given in [6], and stated as:
Let u be a solution for 2
u = 0 over Ω and continuous over Ω∂Ω = ¯Ω. Let m+
and m−
be the maximum and minimum
values of u attained on the boundary ∂Ω, respectively. Then, either m−
< u(x) < m+
for x ∈ ¯Ω or m−
= u(x) = m+
for
x ∈ ¯Ω.
Informally, this means that the only part of the domain Ω where the maximum and minimum values of u are attained are
on the boundary, and u evaluated strictly within this boundary is always strictly between the minimum and maximum
values attained. Otherwise, the surface is flat. After running the script cotantest.m, it is possible to check that this
example satisfies the condition by executing the commands below.
any(Ufem(invtx)==max(Ufem)) Checks if any points of the interior attain the maximum value of the domain.
any(Ufem(bvert)==max(Ufem)) Checks if any points of the boundary attain the maximum value of the domain.
7
any(Ufem(invtx)==max(Ufem)) Checks if any points of the interior attain the minimum value of the domain.
any(Ufem(bvert)==max(Ufem)) Checks if any points of the boundary attain the minimum value of the domain.
By interpretting the logical reponse of these commands, it can be seen that this example satisfies the Maximum-Minimum
Principle.
3 Applications in Pollution Simulation
It is possible to use the methods demonstrated above to solve a more realistic problem. Consider an island which has
a contaminant leaking into the environment at one or more points in the interior.It is know that the concentration of
pollution at the coastline is zero. Using the hypothesis that the concentration field satisfies Poisson’s equation with a
delta-function source at each point of contamination, it is possible to simulate the concentration field across the island.
This problem details a Dirichlet problem for Poisson’s equation, given by 2
u(x, y) = q for (x, y) ∈ Ω, where q is the
delta-function representing sources, and u(x, y) = 0 for (x, y) ∈ ∂Ω .
1 %--islandsol--%
2 figure('Visible','Off');
3 pv=[0.2,-5.7;-3.7,-2.4;-5.3,-3.6;-6.9,-3;-8,-3.4;-7.6,-4.3;-6.3,-5;...
4 -5.8,-6.2;-7,-6.5;-8,-5.7;-8.4,-6;-8.8,-7;-9.3,-6;-8.8,-5.1;...
5 -9.3,-2.5;-7,-1;-6.6,0.9;-5,0;-4.8,2.4;-4,3.2;-3.2,6.6;-2.1,7.2;...
6 -1.2,6.6;0.3,4.3;3.2,2.4;4.1,2.2;6.5,4.1;6.7,3.3;5.5,1.9;5.6,0;...
7 6.5,-1.3;3.3,-2.5;0.2,-5.7;];
8 [p,t]=distmesh2d(@dpoly,@huniform,0.4,[-10,-10;7.5,7.5],pv,pv);
9 K=cotan(p,t);
10 bvert=boundedges(p,t);%Finding boundary edges to apply Dirichlet condition to.
11 bvert=sort(bvert(:,1));
12 invtx=setdiff(1:size(p,1),bvert)';%Find interior vertices of mesh.
13 b=zeros(length(p),1);
14 location=randsample(invtx,3);b(location)=1;%Randomly Select point sources
15 uu= K(invtx,invtx)b(invtx);
16 usol(invtx)=uu;usol(bvert)=0;
17 figure();trisurf(t,p(:,1),p(:,2),usol);colormap jet;
18 figure();%Begin plotting contour plot.
19 F= scatteredInterpolant(p(:,1),p(:,2),usol');
20 xi = -10:0.05:7.5;
21 [qx,qy]=meshgrid(xi,xi);
22 qz=F(qx,qy);[C,h]=contour(qx,qy,qz);h.LevelList=0:0.1:min(usol);
23 xlim([-10.5,7.5]);ylim([-8,7.5]);
The script islandsol.m solves this Dirichlet problem for Poisson’s equation by using finite element method techniques,
before plotting the contour lines that represent the concentration levels of pollution. An example, using three point sources
at randomly choosen locations, is shown in Figure 9.
−10 −8 −6 −4 −2 0 2 4 6
−8
−6
−4
−2
0
2
4
6
(a) Plot showing the pollution concentration levels as
contours.
−10
−5
0
5
10
−10
−5
0
5
10
−0.8
−0.6
−0.4
−0.2
0
(b) Surface showing the regions heavily influenced by
pollution.
Figure 9
8
Trying to locate sources of pollution with very little initial data can be challenging. Different approaches will have their
benefits and costs. In order to understand the problem in a familiar context, consider the problem as being analogous to
the board game, Battleships. First, assume that a source of pollution of major interest affects a region of atleast a certain
area. The area that a source affects will be comparable to the length of a battle ship. Testing pollution concentrations at
different locations will be like firing a missile at enemy boats, and finding out whether the result is a ‘hit’ or ‘miss’.
Several possible approaches, given in the context of the board game, are suggested in [7]. One of the most intuitive
strategies discussed here is the notion of a parity targeting algorithm. More simply, using the assumption above, locating
all the sources on the island can be done minimally by spacing testing locations out relative to the size of this region. It
is only necessary to check a proportion of all the vertices in the interior. Once a source has been detected, it’s precise
location can be determined by testing locations nearby the first test site, to find the direction in which the concentration
is increasing. Following the gradient to local maximum should lead back to a point source.
An improved method is to use probability density functions to assign the probability of a source being at a vertex, then
deciding which vertex to test based on the highest probability. Updating the probability after each test means that some
regions can be quickly excluded from the search. this is also explained in more detail in [7].
In the case that this model is not sufficiently accurate enough, there are a number of possible ares of improvement that can
be considered. One such adjustment would be to consider the sources of pollution to be acting over a finite region, rather
than being point sources. This would then effect the direction and magnitude of the pollution flowing out of a source,
and hence where the equilibrium state would form. Also challenging the assumptions relating to the topography; that
is the homogeneity of the soil, the shape of the terrain, and presence of features such as rivers that transport pollution
differently. Taking into account these features will provide a more realistic and detailed picture of the concentration of
pollution. A different model to also consider is the time-varying diffusion model, which will not reach an equilibrium
state, and so would be a better model for a pollution source that is acting over relatively long periods of time. This model
would also allow people to project forward and make assessments about the damage caused by pollution sources.
References
[1] Lionheart, W.R.B. (2015) A very quick introduction to FEM for Poisson’s equation [Slides] Available from:
“https://oldwww.ma.man.ac.uk//~bl/teaching/PSBC/private/femslides.pdf”. Problem Solving by Computer, Uni-
versity of Manchester, 20 March 2015
[2] Persson, P.-O. (2012) DistMesh(Version 1.1) [Computer Code] Available from:
“http://persson.berkeley.edu/distmesh/index.html”. [Accessed: 22 March 2015]
[3] Persson, P.-O., Strang, G. (2004) A Simple Mesh Generator in MATLAB [Online] Available from:
“http://persson.berkeley.edu/distmesh/persson04mesh.pdf”. [Accessed: 22 March 2015]
[4] Nealen, A., Igarashi, T., Sorkine, O., Alexa, M. (2006) Laplacian Mesh Optimization [Online] Available from:
“http://www.cs.jhu.edu/~misha/Fall07/Papers/Nealen06.pdf”. [Accessed: 8 April 2015]
[5] Herholz, P. (2012) General discrete Laplace operators on polygonal meshes [Online] Available from:
“https://www.ki.informatik.hu-berlin.de/viscom/thesis/final/Diplomarbeit_Herholz_201301.pdf”. [Accessed:
17 April 2015]
[6] Kersal´e, E. (2012) Chapter 4 Elliptic Equations [Online] Available from:
“http://www1.maths.leeds.ac.uk/~kersale/Teach/M3414/Notes/chap4.pdf”. [Accessed: 25 April 2015]
[7] DataGenetics (2012) Algorithm for playing Battleshipts [Online] Available from:
“http://www.datagenetics.com/blog/december32011/”. [Accessed: 25 April 2015]
9

Contenu connexe

Tendances

Pelat lantai kendaraan
Pelat lantai kendaraanPelat lantai kendaraan
Pelat lantai kendaraanAgam Agam
 
laporan Rancangan perkerasan jalan Raya I
laporan Rancangan perkerasan jalan Raya Ilaporan Rancangan perkerasan jalan Raya I
laporan Rancangan perkerasan jalan Raya Imas_weri
 
Perancangan struktur kuda kuda baja tipe gable
Perancangan struktur kuda kuda baja tipe gablePerancangan struktur kuda kuda baja tipe gable
Perancangan struktur kuda kuda baja tipe gableAfret Nobel
 
การผลิตสื่อวิดีโอระบบดิจิทัลเบื้องต้น (Basic Digital Video Production)
การผลิตสื่อวิดีโอระบบดิจิทัลเบื้องต้น (Basic Digital Video Production)การผลิตสื่อวิดีโอระบบดิจิทัลเบื้องต้น (Basic Digital Video Production)
การผลิตสื่อวิดีโอระบบดิจิทัลเบื้องต้น (Basic Digital Video Production)Rachabodin Suwannakanthi
 
Rekayasa lalu lintas dan persimpangan jalan
Rekayasa lalu lintas dan persimpangan jalanRekayasa lalu lintas dan persimpangan jalan
Rekayasa lalu lintas dan persimpangan jalanAli Asnan
 
Presentasi Tugas Akhir
Presentasi  Tugas AkhirPresentasi  Tugas Akhir
Presentasi Tugas AkhirKurniawan Riza
 
menghitung Momen Ultimate baja komposit
menghitung Momen Ultimate baja kompositmenghitung Momen Ultimate baja komposit
menghitung Momen Ultimate baja kompositShaleh Afif Hasibuan
 
Konstruksi gudang-baja
Konstruksi gudang-bajaKonstruksi gudang-baja
Konstruksi gudang-bajaekobudi27
 
02 ekotek perhitungan bunga (tgs klp 1)
02 ekotek perhitungan bunga (tgs klp 1)02 ekotek perhitungan bunga (tgs klp 1)
02 ekotek perhitungan bunga (tgs klp 1)Al Ibra
 
80747511 tabel-profil
80747511 tabel-profil80747511 tabel-profil
80747511 tabel-profilJunaida Wally
 
Bab ii distribusi momen
Bab ii distribusi momenBab ii distribusi momen
Bab ii distribusi momendika andika
 
Materi perkerasan Jalan
Materi perkerasan Jalan Materi perkerasan Jalan
Materi perkerasan Jalan hycal farist
 
Baja - Balok Komposit
Baja - Balok Komposit Baja - Balok Komposit
Baja - Balok Komposit Yasmin Rosyad
 
Standard Geometrik Jalan Tol
Standard Geometrik Jalan TolStandard Geometrik Jalan Tol
Standard Geometrik Jalan Tolfaisal_fafa
 
kereb jalan median jalan
kereb jalan median jalankereb jalan median jalan
kereb jalan median jalanGibran Yuki
 
Laporan tugas struktur baja
Laporan tugas struktur bajaLaporan tugas struktur baja
Laporan tugas struktur bajatanchul
 

Tendances (20)

Pelat lantai kendaraan
Pelat lantai kendaraanPelat lantai kendaraan
Pelat lantai kendaraan
 
laporan Rancangan perkerasan jalan Raya I
laporan Rancangan perkerasan jalan Raya Ilaporan Rancangan perkerasan jalan Raya I
laporan Rancangan perkerasan jalan Raya I
 
Perancangan struktur kuda kuda baja tipe gable
Perancangan struktur kuda kuda baja tipe gablePerancangan struktur kuda kuda baja tipe gable
Perancangan struktur kuda kuda baja tipe gable
 
KLASIFIKASI JALAN
KLASIFIKASI JALANKLASIFIKASI JALAN
KLASIFIKASI JALAN
 
การผลิตสื่อวิดีโอระบบดิจิทัลเบื้องต้น (Basic Digital Video Production)
การผลิตสื่อวิดีโอระบบดิจิทัลเบื้องต้น (Basic Digital Video Production)การผลิตสื่อวิดีโอระบบดิจิทัลเบื้องต้น (Basic Digital Video Production)
การผลิตสื่อวิดีโอระบบดิจิทัลเบื้องต้น (Basic Digital Video Production)
 
Mappa Piste ciclabili a Torino
Mappa Piste ciclabili a Torino Mappa Piste ciclabili a Torino
Mappa Piste ciclabili a Torino
 
Tugas 5 Struktur Beton 1
Tugas 5 Struktur Beton 1Tugas 5 Struktur Beton 1
Tugas 5 Struktur Beton 1
 
Rekayasa lalu lintas dan persimpangan jalan
Rekayasa lalu lintas dan persimpangan jalanRekayasa lalu lintas dan persimpangan jalan
Rekayasa lalu lintas dan persimpangan jalan
 
Presentasi Tugas Akhir
Presentasi  Tugas AkhirPresentasi  Tugas Akhir
Presentasi Tugas Akhir
 
menghitung Momen Ultimate baja komposit
menghitung Momen Ultimate baja kompositmenghitung Momen Ultimate baja komposit
menghitung Momen Ultimate baja komposit
 
Penyaluran tulangan beton
Penyaluran tulangan betonPenyaluran tulangan beton
Penyaluran tulangan beton
 
Konstruksi gudang-baja
Konstruksi gudang-bajaKonstruksi gudang-baja
Konstruksi gudang-baja
 
02 ekotek perhitungan bunga (tgs klp 1)
02 ekotek perhitungan bunga (tgs klp 1)02 ekotek perhitungan bunga (tgs klp 1)
02 ekotek perhitungan bunga (tgs klp 1)
 
80747511 tabel-profil
80747511 tabel-profil80747511 tabel-profil
80747511 tabel-profil
 
Bab ii distribusi momen
Bab ii distribusi momenBab ii distribusi momen
Bab ii distribusi momen
 
Materi perkerasan Jalan
Materi perkerasan Jalan Materi perkerasan Jalan
Materi perkerasan Jalan
 
Baja - Balok Komposit
Baja - Balok Komposit Baja - Balok Komposit
Baja - Balok Komposit
 
Standard Geometrik Jalan Tol
Standard Geometrik Jalan TolStandard Geometrik Jalan Tol
Standard Geometrik Jalan Tol
 
kereb jalan median jalan
kereb jalan median jalankereb jalan median jalan
kereb jalan median jalan
 
Laporan tugas struktur baja
Laporan tugas struktur bajaLaporan tugas struktur baja
Laporan tugas struktur baja
 

Similaire à Problem Solving by Computer Finite Element Method

Tree distance algorithm
Tree distance algorithmTree distance algorithm
Tree distance algorithmTrector Rancor
 
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...IOSR Journals
 
Low rank tensor approximation of probability density and characteristic funct...
Low rank tensor approximation of probability density and characteristic funct...Low rank tensor approximation of probability density and characteristic funct...
Low rank tensor approximation of probability density and characteristic funct...Alexander Litvinenko
 
Approximate Thin Plate Spline Mappings
Approximate Thin Plate Spline MappingsApproximate Thin Plate Spline Mappings
Approximate Thin Plate Spline MappingsArchzilon Eshun-Davies
 
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...Alexander Litvinenko
 
Differential Equations Assignment Help
Differential Equations Assignment HelpDifferential Equations Assignment Help
Differential Equations Assignment HelpMaths Assignment Help
 
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片Chyi-Tsong Chen
 
International journal of engineering and mathematical modelling vol2 no1_2015_1
International journal of engineering and mathematical modelling vol2 no1_2015_1International journal of engineering and mathematical modelling vol2 no1_2015_1
International journal of engineering and mathematical modelling vol2 no1_2015_1IJEMM
 
Cgo2007 P3 3 Birkbeck
Cgo2007 P3 3 BirkbeckCgo2007 P3 3 Birkbeck
Cgo2007 P3 3 BirkbeckaiQUANT
 
A Dimension Abstraction Approach to Vectorization in Matlab
A Dimension Abstraction Approach to Vectorization in MatlabA Dimension Abstraction Approach to Vectorization in Matlab
A Dimension Abstraction Approach to Vectorization in MatlabaiQUANT
 
Parallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-JoinsParallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-JoinsJonny Daenen
 

Similaire à Problem Solving by Computer Finite Element Method (20)

Tree distance algorithm
Tree distance algorithmTree distance algorithm
Tree distance algorithm
 
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
 
Low rank tensor approximation of probability density and characteristic funct...
Low rank tensor approximation of probability density and characteristic funct...Low rank tensor approximation of probability density and characteristic funct...
Low rank tensor approximation of probability density and characteristic funct...
 
Data Analysis Assignment Help
Data Analysis Assignment HelpData Analysis Assignment Help
Data Analysis Assignment Help
 
Approximate Thin Plate Spline Mappings
Approximate Thin Plate Spline MappingsApproximate Thin Plate Spline Mappings
Approximate Thin Plate Spline Mappings
 
ilovepdf_merged
ilovepdf_mergedilovepdf_merged
ilovepdf_merged
 
Diffusion Homework Help
Diffusion Homework HelpDiffusion Homework Help
Diffusion Homework Help
 
3 D Graphics
3 D Graphics3 D Graphics
3 D Graphics
 
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
 
Differential Equations Assignment Help
Differential Equations Assignment HelpDifferential Equations Assignment Help
Differential Equations Assignment Help
 
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
 
International journal of engineering and mathematical modelling vol2 no1_2015_1
International journal of engineering and mathematical modelling vol2 no1_2015_1International journal of engineering and mathematical modelling vol2 no1_2015_1
International journal of engineering and mathematical modelling vol2 no1_2015_1
 
kactl.pdf
kactl.pdfkactl.pdf
kactl.pdf
 
Cgo2007 P3 3 Birkbeck
Cgo2007 P3 3 BirkbeckCgo2007 P3 3 Birkbeck
Cgo2007 P3 3 Birkbeck
 
A Dimension Abstraction Approach to Vectorization in Matlab
A Dimension Abstraction Approach to Vectorization in MatlabA Dimension Abstraction Approach to Vectorization in Matlab
A Dimension Abstraction Approach to Vectorization in Matlab
 
Parallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-JoinsParallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-Joins
 
Lect5 v2
Lect5 v2Lect5 v2
Lect5 v2
 
CDT 22 slides.pdf
CDT 22 slides.pdfCDT 22 slides.pdf
CDT 22 slides.pdf
 
Numerical Analysis Assignment Help
Numerical Analysis Assignment HelpNumerical Analysis Assignment Help
Numerical Analysis Assignment Help
 
lecture6.ppt
lecture6.pptlecture6.ppt
lecture6.ppt
 

Problem Solving by Computer Finite Element Method

  • 1. Problem Solving by Computer: Finite Element Method Assignment by Peter Herbert, University of Manchester 1 Generating Simplicial Meshes Finding analytic solutions to Partial Differential Equations (PDEs) can sometimes be very difficult. One method for finding approximate solutions to a PDE problem that has boundary conditions is to use Finite Element Methods (FEM) that are introduced in [1]. This involves taking the region over which the PDE is being considered, and dividing it into pieces that are more basic. In MATH31072 Algebraic Topology, a Geometric Simplicial Surface is defined as a finite set of triangles in some Euclidean space, satisfying a set of conditions that specify the manner in which triangles are connected together to form a mesh. A further theorem from the course, proved by Tibor Rad´o, is that every closed surface can be triangulated. Using a simplicial mesh also helps to make a grid that can fit otherwise awkwardly shaped domains. Before considering a particular PDE problem, setting up the tools for the numerical implementation of the Finite El- ement Methods is necessary. There are several packages available for different piece of software. One such program is available from [2], for use in MATLAB, to generate different kinds of meshes for a variety of geometric objects. The function distmesh2d takes various inputs that control different aspects of the output mesh. These inputs and outputs are detailed further in both the code and on page 4 of [3]. The code beside each of these examples comes from the script examples.m. The first input is the distance function fd. This is a function that returns the distance from each node to the nearest boundary. Generating such a function for a standard shape region can be done using one of the presets such as dcircle, drectangle, dpolygon, or ddiff. This only really needs to change if the domain of the problem changes shape. (a) A circle (b) An irregular polygon (c) The set difference Figure 1: Simplicial meshes for differently shaped domains. 1 %%-1.1Circle-%% 2 figure(); 3 fd=@(p) dcircle(p,0,0,1); 4 distmesh2d(fd,@huniform,0.2,[-1,-1;1,1],[]); 5 %%-1.2Irregular Polygon-%% 6 figure(); 7 pv=[0 1.6;2 2.5;2 -1.4;0.6 -1.5;-0.1 -2.5;... 8 -0.8 -1.4;-2.5 0.2;-2 1.2;-0.7 2.5;0 1.6]; 9 distmesh2d(@dpoly,@huniform,0.4,[-2.5,-2.5;2.5,2.5],pv,pv); 10 %%-1.3Set Difference-%% 11 figure(); 12 pv=[0 1.6;2 2.5;2 -1.4;0.6 -1.5;-0.1 -2.5;... 13 -0.8 -1.4;-2.5 0.2;-2 1.2;-0.7 2.5;0 1.6]; 14 fd=@(p) ddiff(dpoly(p,pv),dcircle(p,0,0,1)); 15 distmesh2d(fd,@huniform,0.3,[-2.5,-2.5;2.5,2.5],pv); 1
  • 2. The second input takes a function h(x, y) which is responsible for the relative distribution of edge lengths in the mesh. That is to say h(x, y) controls whether the mesh is uniform or not, and how refined specific areas of the mesh are when it is not uniform. Because it is the relative distribution, scaling h(x, y) will not make the mesh more refined overall. For a uniform mesh, h(x, y) = constant. (a) A uniform mesh with evenly distributed edge lengths. (b) A non-uniform mesh concentrated in the middle. (c) A non-uniform mesh concentrated at the corners. Figure 2: Simplicial meshes of a unit square demonstrating how the distribution of edge lengths can be manipulated. 1 %%-2.1Uniform Mesh-%% 2 figure(); 3 fd=@(p) drectangle(p,0,1,0,1); 4 distmesh2d(fd,@huniform,0.1,[0,0;1,1],[0,0;1,0;0,1;1,1]); 5 %%-2.2Non-Uniform Centered Mesh-%% 6 figure(); 7 fd=@(p) drectangle(p,0,1,0,1); 8 fh=@(p) 0.01+0.3*abs(dcircle(p,0.5,0.5,0)); 9 distmesh2d(fd,fh,0.01,[0,0;1,1],[0,0;1,0;0,1;1,1]); 10 %%-2.3Non-Uniform Boundary Mesh-%% 11 figure(); 12 fd=@(p) drectangle(p,0,1,0,1); 13 fh=@(p) 0.01+0.3*abs(dcircle(p,0.5,0.5,(sqrt(2))ˆ-1)); 14 distmesh2d(fd,fh,0.01,[0,0;1,1],[0,0;1,0;0,1;1,1]); The next input h0 is the distance between points in the initial distribution. This is the factor to change in order to alter the fineness of triangulation. When working with dpoly, it is very important to repeat the first vertex at the end of the list of vertices, as this makes the triangulation algorithm more stable. (a) Very low mesh refinement. (b) A well refined mesh. (c) A heavily refined mesh. Figure 3: Simplicial meshes that have increasing mesh refinement. 2
  • 3. 1 %%-3.1Large Mesh-%% 2 figure(); 3 fd=@(p) drectangle(p,0,1,0,1); 4 distmesh2d(fd,@huniform,0.3,[0,0;1,1],[0,0;1,0;0,1;1,1]); 5 %%-3.2Intermediate Mesh-%% 6 figure(); 7 fd=@(p) drectangle(p,0,1,0,1); 8 distmesh2d(fd,@huniform,0.1,[0,0;1,1],[0,0;1,0;0,1;1,1]); 9 %%-3.3Small Mesh-%% 10 figure(); 11 fd=@(p) drectangle(p,0,1,0,1); 12 distmesh2d(fd,@huniform,0.05,[0,0;1,1],[0,0;1,0;0,1;1,1]); The input bbox describes the boundary box that confines the area where points are positioned whilst the mesh is being constructed. Finally, pfix picks out points that stay fixed whilst the mesh is being constructed, for instance vertices defining a polygonal domain for the problem. These inputs hold very important information, but in general do not need to be adjusted for a particular problem. The function distmesh2d not only produces the graphical representation of the mesh, but also returns the data for the positions of each point as variable p, and a list of which points are in each simplex, as variable t. 2 Cotangent Laplacian 2.1 Approximation of Laplacian Operator The cotangent Laplacian is a finite approximation to the Laplacian operator, 2 , over the domain of the problem. The cotangent Laplacian takes the form of a |V |×|V | laplacian matrix K for a weighted graph G(V, E), and is given by Kij =    1 2 cot(θ+ ) + 1 2 cot(θ− ) if (i, j) ∈ E − (i,j)∈E Kij if i = j 0 Otherwise , where the angles θ+ and θ− are angles in distinct triangles, that oppose the edge between vertices vi and vj, as shown in Figure (4a) and Figure (4b). For edges on the boundary, there is only one corresponding angle opposite it, hence there is only one cotangent term contributing to that value. The derivation of this approximation is discussed in more detail in ‘3. Discrete Laplacians’ in [5]. (a) Interior edge in red. (b) Boundary edge in red. Figure 4: Diagram showing the angles used to calculate the (i, j)th entry of the cotangent Laplacian The function cotan takes each triangle from t, and stores the vertex indices in ascending order, in variable ti. This is so that creating the strictly upper triangular part of the cotangent Laplacian K is simplified. The variable pos stores the vector corresponding to the edge opposite the vertex in the corresponding entry of ti. The direction of each edge vector 3
  • 4. preserves the orientation of the triangle. Then for each vertex in the triangle, the 1 2 cot(θ) term for the angle at that vertex is calculated by evaluating the dot product, and the norm of the cross product. This is then added to the Kij, (i < j) entry of the cotangent Laplacian. The final lines of the function take the strictly upper triangular matrix and add it to it’s transpose, making K symmetric, and filling in the diagonal such that the column summations equal zero. 1 function K=cotan(p,t) 2 %COTAN calculates cotangent laplacian matrix K given positions of vertices p 3 % and list of vertices in each triangle t. 4 K=zeros(length(p)); 5 for i=1:length(t) 6 ti=sort(t(i,:));%Choose a triangle, and put indices in increasing order. 7 pos=zeros(3,3);%Going to store vector of the edge opposite corresponding vertex in ti. 8 pos(1,:)=[p(ti(3),1)-p(ti(2),1),p(ti(3),2)-p(ti(2),2),0];%edge v2 to v3 - opposite v1. 9 pos(2,:)=[p(ti(1),1)-p(ti(3),1),p(ti(1),2)-p(ti(3),2),0];%edge v3 to v1 - opposite v2. 10 pos(3,:)=[p(ti(2),1)-p(ti(1),1),p(ti(2),2)-p(ti(1),2),0];%edge v1 to v2 - opposite v3. 11 for v=ti 12 X=[pos(ti~=v,:)];%Putting the edge opposite the vertex last, means it can be found easily. 13 Y=ti(ti~=v); 14 coangl=-dot(X(1,:),X(2,:))/norm(cross(X(1,:),X(2,:)));%Calculating the cotangent of the angle between vectors. 15 K(Y(1),Y(2))=K(Y(1),Y(2))+(0.5*(coangl));%Add cotangent term to upper triangular entry as Y(1)<=Y(2). 16 end 17 end 18 K=K+K';%Turns upper triangular matrix into symmetric matrix. 19 indx=logical(eye(length(p))); 20 K(indx)=-sum(K,2);%Fill in the diagonal entries of the Laplacian. Column and row sum is now zero. 21 end 2.2 Application to Partial Differencial Equations The Laplacian operator, 2 = ∂2 ∂x2 + ∂2 ∂y2 is used in many different equations. One such equation is Poisson’s equa- tion, 2 u = q. Here, q is a known forcing term, and the PDE is being solved for u. Laplace’s equation is the homogeneous Poisson’s equation, i.e. 2 u = 0. Finding solutions to these PDEs can be done if boundary conditions are imposed. Consider a PDE that is to be solved over a domain Ω ⊆ R2 . A Dirichlet boundary condition has the form u(x, y) = f(x, y), for (x, y) ∈ ∂Ω, for some suitably differentiable function f, so this fixes the value at the boundary. A Neumann boundary condition has the form ∂ ∂n u(x, y) = u(x, y) · n = g(x, y), for (x, y) ∈ ∂Ω for outward unit normal n on the boundary, and some function g. Since u is a vector that points of the direction for which u increases the quickest, u · n quantifies how quickly u is increasing perpendicular to the boundary. Hence the Neumann Boundary Condition fixes how quickly u increases across the boundary. As this boundary condition is expressed in terms of a derivative, the solution u will only be unique up to the addition of a constant, whilst the solution to a Dirichlet problem will be unique. It should be noted that Laplace’s Equation is satisfied by either the real or imaginary part of an analytic function of z = x + yi ∈ C. For example, if U(z) = z2 = (x + iy)2 = (x2 − y2 ) + (2xy)i, then x2 − y2 and 2xy satisfy Laplace’s Equation. This is because a complex analytic function f(z) = u(x, y) + iv(x, y), z = x + iy ∈ C satisfies the Cauchy- Riemann equations ux = vy and uy = −vx, which leads to uxx = −uyy and similarly for v. By De Moivre’s theorem, zm = rm (cos(θ) + isin(θ))m = rm (cos(mθ) + isin(mθ)), so these solutions will have a periodic behaviour that is related to the value of m. One way to test the cotangent Laplacian is to apply it in the context of partial differential equations. By solving a Dirichlet problem and a Neumann problem for which the exact solutions are known, the approximate solutions can be compared 4
  • 5. to their exact solutions. Doing this at a number of mesh sizes will demonstrate the manner in which the approximate solutions will converge to their exact solution. 1 %%--cotantest.m--%% 2 for j=[0.1,0.075,0.05]; 3 figure('Visible','Off'); 4 fd=@(p) dcircle(p,0,0,1); 5 [p,t]=distmesh2d(fd,@huniform,j,[-1,-1;1,1],[]); 6 K=cotan(p,t);% Create Cotangent Laplacian. 7 bvert=boundedges(p,t);bvert=sort(bvert(:,1)); %Finding boundary vertices of mesh. 8 invtx=setdiff(1:size(p,1),bvert)';%Finding interior vertices of mesh. 9 %--Dirichlet Problem--% 10 f=@(x,y) real((x + 1i*y).ˆ6 + (x+1i*y).ˆ3); %Harmonic function to be applied at boundary vertices. 11 ui=K(invtx,invtx)(-K(invtx,bvert)*f(p(bvert,1),p(bvert,2)));%Calculate values at interior vertices. 12 Ufem(invtx)=ui;Ufem(bvert)=f(p(bvert,1),p(bvert,2)); 13 Uexact=f(p(:,1),p(:,2));%Analytic solution evaluated at all vertices. 14 error=norm(Uexact'-Ufem,inf)/norm(Uexact',inf);%Error in the approximate solution for this problem. 15 figure();trisurf(t,p(:,1),p(:,2),Ufem); colormap jet; 16 suptitle({['Approximate solution with relative error ',num2str(error)],['h {0}= ',num2str(j)]}); 17 %--Neumann Problem--% 18 [th,r]=cart2pol(p(:,1),p(:,2)); 19 q=((jˆ2)*sqrt(3)/2)*(3*pi*0.5)*(-(3*pi*0.5)*sin(3*pi*0.5*r(invtx))... 20 + (r(invtx).ˆ-1).*cos(3*pi*0.5*r(invtx)));%The inhomogeneous part of the possion's equation. 21 ui2= K(invtx,invtx)(q); 22 Ufem2(invtx)=ui2;Ufem2(bvert)=0;%Using boundary condition, arbitrarily choose zero at boundary vertices. 23 Uexact2=sin(3*pi*0.5*r)+1;%Analytic solution which is zero on boundary vertices. 24 error2=norm(Uexact2'-Ufem2,inf)/norm(Uexact2',inf); 25 figure();trisurf(t,p(:,1),p(:,2),Ufem2);colormap jet; 26 suptitle({['Approximate solution with relative error ',num2str(error2)],['h {0}= ',num2str(j)]}); 27 end Firstly, consider a Dirichlet problem for Laplace’s equation, where the domain Ω is the unit circle, given by 2 u(x, y) = 0 for (x, y) ∈ Ω and u(x, y) = Re(z6 + z3 ) for (x, y) ∈ ∂Ω, where z = x + iy. This corresponds to the problem solved in lines 10-16 of cotantest.m. Note that u(x, y) = Re(z6 +z3 ) is a solution to Laplace’s equation in Ω, as it is derived from a complex analytical function as discussed previously. Since this function is used to define the boundary conditions, u(x, y) = Re(z6 + z3 ) is the exactly solution to evaluate at all points in the domain, and compare it to the finite element method solution. Approximate solution with relative error 0.0044703 h0 = 0.1 −1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1 −2 −1 0 1 2 (a) Approximate solution with relative error 0.0021821 h0 = 0.075 −1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1 −2 −1 0 1 2 (b) Approximate solution with relative error 0.00093813 h0 = 0.05 −1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1 −2 −1 0 1 2 (c) Figure 5: Solutions to the Dirichlet problem for Laplace’s equation over increasingly refined meshes. The results of using the finite element method are shown in Figure 5. The relative error, measure by uexact − uF EM ∞ uexact ∞ , shows that as the simplicial mesh becomes more refined, the error in the finite element method solution decreases. When the mesh size is h0 = 0.1 in Figure 5a, the relative error is approximately 4.5×10−3 . The mesh size decreases linearly until h0 = 0.05 in Figure 5c, where the relative error has dropped to approximately 9.4×10−4 . Using the script Errorplots.m, the relative error for mesh sizes specified in variable h is calculated and plotted in a Figure 6. The relative error appears to increase expotentially as the mesh size increases in increments 0.01, meaning that there is significant advantage to using a more refined mesh. 5
  • 6. 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0 0.005 0.01 0.015 Errors for Dirichlet problem RelativeError Mesh size h0 Figure 6: Relative error for the Dirichlet problem compared to the known exact solution. The next problem involves the Poisson’s equation 2 u = q, for some function q. It will be necessary to apply a scaling factor to q. This is because in the problem, q is a function evaluated over the whole of Ω, and the discrete approximation of this needs to account for the values of this function inside triangles of the mesh. The integral for q from slide 5 of [1] can be interpreted more simply. It means that the value of q at a vertex needs to be equal to the sum of values of q at points in the surrounding triangles, weighted by now near the points are to the vertex. The basic approximation of an integral of a function f is the value of f × (area of region integrating over) . It can be approximated by barycentric subdivision that, since there are three vertices for each triangle, the integral for such a vertex V is a third of the integral over the entire triangle. A further approximation is to say that a vertex V is at the centre of a hexagon, where each surrounding triangle is approximately equilateral, and the area of this hexagon is approximately 3 √ 3 2 h2 0. This means that the approximate value of q at a vertex is 1 3 × 3 √ 3 2 h2 0 × q. Let A = √ 3 2 h2 0 denote this scaling factor of q below. Therefore, consider the Neumann problem for Poisson’s equation given in polar coordinates by 2 u = A − 3π 2 2 sin 3π 2 r + 3π 2r cos 3π 2 r for (r, θ) ∈ ∂Ω, u · n r=1 = ∂u ∂r r=1 = 0, Here the domain Ω is the unit circle. This boundary condition means that the solution u is only unique up to the addition of a constant. Having constructed this example with a particular solution, it is known that u = sin 3π 2 r + 1 satisfies these equations, and so this will be the exact solution. This corresponds to the problem solved in lines 18-26 of cotantest.m Approximate solution with relative error 0.10744 h0 = 0.1 −1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1 0 0.5 1 1.5 2 (a) Approximate solution with relative error 0.040693 h0 = 0.075 −1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1 0 0.5 1 1.5 2 (b) Approximate solution with relative error 0.039153 h0 = 0.05 −1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1 0 0.5 1 1.5 2 (c) Figure 7: Solutions to the Neumann problem for Poisson’s equation over increasingly refined meshes. The results of using the finite element method in the script cotantest.m are shown in Figure 7. The relative error in these diagrams demonstrates that as the mesh becomes more refined, the finite element method constructs a solution which converges to the exact solution. When the mesh size is h0 = 0.1, as in Figure 7a, the relative error is 0.107. Reducing the mesh size by 0.025 to h0 = 0.075 in Figure 7b causes the relative error of solution to fall dramatically to 0.041, which 6
  • 7. is over half the previous error. Finally, in Figure 7c, where the mesh size is h0 = 0.05, the relative error only decreases by a small amount to 0.039. A more detailed investigation is run by the script Errorplots.m, and the graph in Figure 8 shows the results. The error appears to increase almost linearly as the mesh size is increased linearly in increments of 0.01. In applications, it might be possible to compromise on relative error if the mesh size requires a lot of computational power. 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 Errors for Neumann problem RelativeError Mesh size h0 Figure 8: Relative error for the Neumann problem compared to the known exact solution. 1 %%--Errorplots.m--%% 2 h=[0.02:0.01:0.15]; 3 for j=1:length(h) 4 figure('Visible','Off'); 5 fd=@(p) dcircle(p,0,0,1); 6 [p,t]=distmesh2d(fd,@huniform,h(j),[-1,-1;1,1],[]); 7 K=cotan(p,t);% Create Cotangent Laplacian. 8 bvert=boundedges(p,t);bvert=sort(bvert(:,1)); %Finding boundary vertices of mesh. 9 invtx=setdiff(1:size(p,1),bvert)';%Finding interior vertices of mesh. 10 %--Dirichlet Problem--% 11 f=@(x,y) real((x + 1i*y).ˆ6 + (x+1i*y).ˆ3); %Harmonic function to be applied at boundary vertices. 12 ui=K(invtx,invtx)(-K(invtx,bvert)*f(p(bvert,1),p(bvert,2)));%Calculate values at interior vertices. 13 Ufem(invtx)=ui;Ufem(bvert)=f(p(bvert,1),p(bvert,2)); 14 Uexact=f(p(:,1),p(:,2));%Analytic solution evaluated at all vertices. 15 error(j)=norm(Uexact'-Ufem,inf)/norm(Uexact',inf);%Error in the approximate solution for this problem. 16 %--Neumann Problem--% 17 [th,r]=cart2pol(p(:,1),p(:,2)); 18 q=((h(j)ˆ2)*sqrt(3)/2)*(3*pi*0.5)*(-(3*pi*0.5)*sin(3*pi*0.5*r(invtx))... 19 + (r(invtx).ˆ-1).*cos(3*pi*0.5*r(invtx)));%The inhomogeneous part of the possion's equation. 20 ui2= K(invtx,invtx)(q); 21 Ufem2(invtx)=ui2;Ufem2(bvert)=0;%Using boundary condition, arbitrarily choose zero at boundary vertices. 22 Uexact2=sin(3*pi*0.5*r)+1;%Analytic solution which is zero on boundary vertices. 23 error2(j)=norm(Uexact2'-Ufem2,inf)/norm(Uexact2',inf); 24 clear Ufem Ufem2; 25 end 26 figure();plot(h,error,'-k.');title('Errors for Dirichlet problem'); 27 ylabel('Relative Error');xlabel('Mesh size h {0}'); 28 figure();plot(h,error2,'-k.');title('Errors for Neumann problem'); 29 ylabel('Relative Error');xlabel('Mesh size h {0}'); 2.3 The Maximum-Minimum Principle An additional feature of a Laplace’s equation, which is demonstrated in Figure 5c, is know as the Maximum-Minimum Principle. This theorem is given in [6], and stated as: Let u be a solution for 2 u = 0 over Ω and continuous over Ω∂Ω = ¯Ω. Let m+ and m− be the maximum and minimum values of u attained on the boundary ∂Ω, respectively. Then, either m− < u(x) < m+ for x ∈ ¯Ω or m− = u(x) = m+ for x ∈ ¯Ω. Informally, this means that the only part of the domain Ω where the maximum and minimum values of u are attained are on the boundary, and u evaluated strictly within this boundary is always strictly between the minimum and maximum values attained. Otherwise, the surface is flat. After running the script cotantest.m, it is possible to check that this example satisfies the condition by executing the commands below. any(Ufem(invtx)==max(Ufem)) Checks if any points of the interior attain the maximum value of the domain. any(Ufem(bvert)==max(Ufem)) Checks if any points of the boundary attain the maximum value of the domain. 7
  • 8. any(Ufem(invtx)==max(Ufem)) Checks if any points of the interior attain the minimum value of the domain. any(Ufem(bvert)==max(Ufem)) Checks if any points of the boundary attain the minimum value of the domain. By interpretting the logical reponse of these commands, it can be seen that this example satisfies the Maximum-Minimum Principle. 3 Applications in Pollution Simulation It is possible to use the methods demonstrated above to solve a more realistic problem. Consider an island which has a contaminant leaking into the environment at one or more points in the interior.It is know that the concentration of pollution at the coastline is zero. Using the hypothesis that the concentration field satisfies Poisson’s equation with a delta-function source at each point of contamination, it is possible to simulate the concentration field across the island. This problem details a Dirichlet problem for Poisson’s equation, given by 2 u(x, y) = q for (x, y) ∈ Ω, where q is the delta-function representing sources, and u(x, y) = 0 for (x, y) ∈ ∂Ω . 1 %--islandsol--% 2 figure('Visible','Off'); 3 pv=[0.2,-5.7;-3.7,-2.4;-5.3,-3.6;-6.9,-3;-8,-3.4;-7.6,-4.3;-6.3,-5;... 4 -5.8,-6.2;-7,-6.5;-8,-5.7;-8.4,-6;-8.8,-7;-9.3,-6;-8.8,-5.1;... 5 -9.3,-2.5;-7,-1;-6.6,0.9;-5,0;-4.8,2.4;-4,3.2;-3.2,6.6;-2.1,7.2;... 6 -1.2,6.6;0.3,4.3;3.2,2.4;4.1,2.2;6.5,4.1;6.7,3.3;5.5,1.9;5.6,0;... 7 6.5,-1.3;3.3,-2.5;0.2,-5.7;]; 8 [p,t]=distmesh2d(@dpoly,@huniform,0.4,[-10,-10;7.5,7.5],pv,pv); 9 K=cotan(p,t); 10 bvert=boundedges(p,t);%Finding boundary edges to apply Dirichlet condition to. 11 bvert=sort(bvert(:,1)); 12 invtx=setdiff(1:size(p,1),bvert)';%Find interior vertices of mesh. 13 b=zeros(length(p),1); 14 location=randsample(invtx,3);b(location)=1;%Randomly Select point sources 15 uu= K(invtx,invtx)b(invtx); 16 usol(invtx)=uu;usol(bvert)=0; 17 figure();trisurf(t,p(:,1),p(:,2),usol);colormap jet; 18 figure();%Begin plotting contour plot. 19 F= scatteredInterpolant(p(:,1),p(:,2),usol'); 20 xi = -10:0.05:7.5; 21 [qx,qy]=meshgrid(xi,xi); 22 qz=F(qx,qy);[C,h]=contour(qx,qy,qz);h.LevelList=0:0.1:min(usol); 23 xlim([-10.5,7.5]);ylim([-8,7.5]); The script islandsol.m solves this Dirichlet problem for Poisson’s equation by using finite element method techniques, before plotting the contour lines that represent the concentration levels of pollution. An example, using three point sources at randomly choosen locations, is shown in Figure 9. −10 −8 −6 −4 −2 0 2 4 6 −8 −6 −4 −2 0 2 4 6 (a) Plot showing the pollution concentration levels as contours. −10 −5 0 5 10 −10 −5 0 5 10 −0.8 −0.6 −0.4 −0.2 0 (b) Surface showing the regions heavily influenced by pollution. Figure 9 8
  • 9. Trying to locate sources of pollution with very little initial data can be challenging. Different approaches will have their benefits and costs. In order to understand the problem in a familiar context, consider the problem as being analogous to the board game, Battleships. First, assume that a source of pollution of major interest affects a region of atleast a certain area. The area that a source affects will be comparable to the length of a battle ship. Testing pollution concentrations at different locations will be like firing a missile at enemy boats, and finding out whether the result is a ‘hit’ or ‘miss’. Several possible approaches, given in the context of the board game, are suggested in [7]. One of the most intuitive strategies discussed here is the notion of a parity targeting algorithm. More simply, using the assumption above, locating all the sources on the island can be done minimally by spacing testing locations out relative to the size of this region. It is only necessary to check a proportion of all the vertices in the interior. Once a source has been detected, it’s precise location can be determined by testing locations nearby the first test site, to find the direction in which the concentration is increasing. Following the gradient to local maximum should lead back to a point source. An improved method is to use probability density functions to assign the probability of a source being at a vertex, then deciding which vertex to test based on the highest probability. Updating the probability after each test means that some regions can be quickly excluded from the search. this is also explained in more detail in [7]. In the case that this model is not sufficiently accurate enough, there are a number of possible ares of improvement that can be considered. One such adjustment would be to consider the sources of pollution to be acting over a finite region, rather than being point sources. This would then effect the direction and magnitude of the pollution flowing out of a source, and hence where the equilibrium state would form. Also challenging the assumptions relating to the topography; that is the homogeneity of the soil, the shape of the terrain, and presence of features such as rivers that transport pollution differently. Taking into account these features will provide a more realistic and detailed picture of the concentration of pollution. A different model to also consider is the time-varying diffusion model, which will not reach an equilibrium state, and so would be a better model for a pollution source that is acting over relatively long periods of time. This model would also allow people to project forward and make assessments about the damage caused by pollution sources. References [1] Lionheart, W.R.B. (2015) A very quick introduction to FEM for Poisson’s equation [Slides] Available from: “https://oldwww.ma.man.ac.uk//~bl/teaching/PSBC/private/femslides.pdf”. Problem Solving by Computer, Uni- versity of Manchester, 20 March 2015 [2] Persson, P.-O. (2012) DistMesh(Version 1.1) [Computer Code] Available from: “http://persson.berkeley.edu/distmesh/index.html”. [Accessed: 22 March 2015] [3] Persson, P.-O., Strang, G. (2004) A Simple Mesh Generator in MATLAB [Online] Available from: “http://persson.berkeley.edu/distmesh/persson04mesh.pdf”. [Accessed: 22 March 2015] [4] Nealen, A., Igarashi, T., Sorkine, O., Alexa, M. (2006) Laplacian Mesh Optimization [Online] Available from: “http://www.cs.jhu.edu/~misha/Fall07/Papers/Nealen06.pdf”. [Accessed: 8 April 2015] [5] Herholz, P. (2012) General discrete Laplace operators on polygonal meshes [Online] Available from: “https://www.ki.informatik.hu-berlin.de/viscom/thesis/final/Diplomarbeit_Herholz_201301.pdf”. [Accessed: 17 April 2015] [6] Kersal´e, E. (2012) Chapter 4 Elliptic Equations [Online] Available from: “http://www1.maths.leeds.ac.uk/~kersale/Teach/M3414/Notes/chap4.pdf”. [Accessed: 25 April 2015] [7] DataGenetics (2012) Algorithm for playing Battleshipts [Online] Available from: “http://www.datagenetics.com/blog/december32011/”. [Accessed: 25 April 2015] 9