# FEM Method in 2D

• I
• bob012345

#### bob012345

Gold Member
TL;DR Summary
I wish to set up the node equations for a 2D heated plate with boundary conditions.
I wish to set up the node equations for a 2D heated plate with boundary conditions. I understand how to do this in 1D but have not found a suitable example problem worked out in 2D and examples I have seen are very involved and complex. @pasmith showed me you to set up the 1D problem as follows;

##N_i## are test functions with $T$ approximated by ##T_1N_1(x) + T_2N_2(x)##. If so, then ##\frac{d^2T}{dx^2} + kT(x) = -f(x)##where ##f(x)## is a known source term gives ;
$$\begin{multline} \int_{x_1}^{x_2} N_i(x)\frac{d^2T}{dx^2} + kN_i(x)T(x) + N_i(x)f(x)\,dx \\= \left[ N_i(x)\frac{dT}{dx}\right]_{x_1}^{x_2} +\int_{x_1}^{x_2} -\frac{dN_i}{dx}\frac{dT}{dx} + kN_i(x)T(x) + N_i(x)f(x)\,dx \end{multline}$$which results in ;
$$\begin{multline} \begin{pmatrix} \int_{x_1}^{x_2} \left(\frac{dN_1}{dx}\right)^2\,dx & \int_{x_1}^{x_2} \frac{dN_1}{dx}\frac{dN_2}{dx} \,dx \\ \int_{x_1}^{x_2} \frac{dN_1}{dx}\frac{dN_2}{dx} \,dx & \int_{x_1}^{x_2} \left(\frac{dN_2}{dx}\right)^2\,dx \end{pmatrix} \begin{pmatrix} T_1 \\ T_2 \end{pmatrix} \\ - k\begin{pmatrix} \int_{x_1}^{x_2} N_1^2(x)\,dx & \int_{x_1}^{x_2} N_1(x)N_2(x)\,dx \\ \int_{x_1}^{x_2} N_1(x)N_2(x)\,dx & \int_{x_1}^{x_2} N_2^2(x)\,dx \end{pmatrix} \begin{pmatrix} T_1 \\ T_2 \end{pmatrix} \\ = \begin{pmatrix} N_1(x_2) \frac{dT}{dx}(x_2) - N_1(x_1) \frac{dT}{dx}(x_1) \\ N_2(x_2) \frac{dT}{dx}(x_2) - N_2(x_1) \frac{dT}{dx}(x_1) \end{pmatrix} + \begin{pmatrix} \int_{x_1}^{x_2} N_1(x)f(x)\,dx \\ \int_{x_1}^{x_2} N_2(x)f(x)\,dx \end{pmatrix}.\end{multline}$$

I wish to amend this for a 2D problem. My book starts with an element equation ##u(x, y) = a_0 + a_{1,1}x + a_{1,2} y## and test functions like this ##N_1 = 1/ 2Ae [(x_2 y_3 − x_3 y_2) + (y_2 − y_3)x + (x_3 − x_2)y]## but I can't seem to put things together.

Last edited:

Have you looked at FreeFEM++ ? The docs may give useful 2D examples and the software itself is quite nice for 2D problems.

bob012345
Have you looked at FreeFEM++ ? The docs may give useful 2D examples and the software itself is quite nice for 2D problems.
Thanks. Looks like that will be useful but I still need help figuring the element equations for my simple 2D case so I can work out a limited example by hand for teaching purposes. Basically this thing in two dimensions;
$$\begin{multline} \int_{x_1}^{x_2} N_i(x)\frac{d^2T}{dx^2} + N_i(x)f(x)\,dx \\= \left[ N_i(x)\frac{dT}{dx}\right]_{x_1}^{x_2} +\int_{x_1}^{x_2} -\frac{dN_i}{dx}\frac{dT}{dx} + N_i(x)f(x)\,dx \end{multline}$$

There is no unique answer to your question. But first I would write the integral on the left as integral over the 2D domain. This will contain a ##\nabla^2 T## term. Integration by parts, see Green’s theorem, will leave you with a line integral over the boundary plus a ##\nabla N\cdot \nabla T## term. Both sides of the equation are zero. This means the boundary line integral which involves your boundary condition will become the drive vector of the ensuing matrix equation while the area integral becomes the system matrix times the vector of unknowns.

So, one must chose a 2D finite element basis for the ##N_i## and the ##T_i##. Now I notice while typing that your setting the problem up as a weak form of the heat equation. Typically people start by writing a Lagrangian form and then apply the galarkin (sp) approach.

[second thoughts] okay, the ##f(x)## term is the source or drive term in your heat flow problem. I think the line integral may vanish but I can’t tell just by staring at it.

Last edited:
bob012345
Thanks, By not unique I assume you mean what hat functions and what kind of grid I choose, triangle ect. I really should have said I was starting with this;

$$\begin{multline} \begin{pmatrix} \int_{x_1}^{x_2} \left(\frac{dN_1}{dx}\right)^2\,dx & \int_{x_1}^{x_2} \frac{dN_1}{dx}\frac{dN_2}{dx} \,dx \\ \int_{x_1}^{x_2} \frac{dN_1}{dx}\frac{dN_2}{dx} \,dx & \int_{x_1}^{x_2} \left(\frac{dN_2}{dx}\right)^2\,dx \end{pmatrix} \begin{pmatrix} T_1 \\ T_2 \end{pmatrix} \\ = \begin{pmatrix} N_1(x_2) \frac{dT}{dx}(x_2) - N_1(x_1) \frac{dT}{dx}(x_1) \\ N_2(x_2) \frac{dT}{dx}(x_2) - N_2(x_1) \frac{dT}{dx}(x_1) \end{pmatrix} + \begin{pmatrix} \int_{x_1}^{x_2} N_1(x)f(x)\,dx \\ \int_{x_1}^{x_2} N_2(x)f(x)\,dx \end{pmatrix}.\end{multline}$$

This is the one dimensional problem. The surface terms ##\frac{dT}{dx}## are the heat flow at the boundary points. These are determined by the physical properties of the problem what ever that may be.

Generalization to 2 dimensions means replacing ##\frac{dT^2}{d^2x}## with ##\nabla^2T## and defining the 2D region etc. What is your problem statement?

l might add that you are subdivided the problem into just two finite elements. In general people will use more. Also you must choose the form of your 2D elements.

This is the one dimensional problem. The surface terms ##\frac{dT}{dx}## are the heat flow at the boundary points. These are determined by the physical properties of the problem what ever that may be.

Generalization to 2 dimensions means replacing ##\frac{dT^2}{d^2x}## with ##\nabla^2T## and defining the 2D region etc. What is your problem statement?

l might add that you are subdivided the problem into just two finite elements. In general people will use more. Also you must choose the form of your 2D elements.
The problem I am trying to develop as an example is a simple 2D plate with one edge 100C, opposite edge 0C, then the other edges 75C and 50C. No other heat source. I am looking at the equilibrium situation. I did it with the student using finite difference but now the student wants to see it done with the FEM. We previously did a 1D rod using FEM. The equations I showed above were the element equations for the 1D rod element with two nodes. We used 5 elements and thus assembled a stiffness matrix. I was just showing that as a reference meaning I am looking for a 2D analog. I assume if it a triangular element it will have three nodes? Thanks.

Okay, let's try an approach based on minimizing a Lagrangian.

##L = \int_{x_1=0}^{x^2=1}\int_{y_1=0}^{y_2=1} \left[(\frac{\partial T}{\partial x})^2+(\frac{\partial T}{\partial y})^2\right]dxdy##

Variation of this functional yields the heat equation,

##\nabla^2 T = 0##

which is the equation you wish to solve subject to fixed temperatures on the boundary. We introduce a square grid of points or nodes on the unit square. We represent ##T##, our solution, as a sum of basis functions where each basis element is zero on all nodes but one where it is one,

## T(x,y) = \sum_k c_kN_k(x,y) + \sum_m d_m N_m(x,y)##

Clearly all we need to do is find the temperature at the interior nodes points. The temperature at all the other points are interpolated by our basis. The basis element at node, ##k=(i,j)##, is one and ramps down linearly to zero at ##(i+1,j), (i-1,j), (i,j+1), (i,j-1)##. I've split the above basis expansion into a sum over nodes interior to the region, ##c_k## which are our unknowns, and those on the boundary, ##d_m##, which are known.

If you plug ##T(x,y)## into ##L## and integrate you get a quadratic form in the ##c_k## and ##d_m##. The coefficients of this form are integrals over overlapping basis elements. Variation with respect to the ##c_k## will yield the matrix equation,

##A_{k'k}c_k = B_{k'm}d_m##

which one solves for the ##c_k##.

bob012345
I assume if it a triangular element it will have three nodes? Thanks.
Well, here you have many possibilities. The elements I use in the previous post have 4 corner nodes and one central node (a pyramid). The reason for this choice is simplicity of the mesh or grid. Your problem domain is rectangular which make this choice very simple.

bob012345
Schaum's outline on Finite Element Methods has some worked out 2D problems. I think it is a good starting point when writing a simple 2D FEM:
https://www.amazon.com/dp/0070087148/?tag=pfamazon01-20