Application of boundary conditions in a finite-difference solution for the heat equation and Crin-Nicholson

The encoder below solves the one-dimensional heat equation, which is a rod whose ends are stored at zero temperature with the initial condition 10 * np.sin (np.pi * x).

How did the Dirichlet boundary conditions (zero rates from both ends) work in this calculation? I was told that the upper lower rows of the matrix A contain two nonzero elements, and the missing third element contains the Dirichlet condition. But I do not understand by what mechanism this condition affects the calculation. With missing elements in A, how do u_ {0} or u_ {n} vanish?

The finite difference method below uses Crank-Nicholson.

import numpy as np import scipy.linalg # Number of internal points N = 200 # Calculate Spatial Step-Size h = 1/(N+1.0) k = h/2 x = np.linspace(0,1,N+2) x = x[1:-1] # get rid of the '0' and '1' at each end # Initial Conditions u = np.transpose(np.mat(10*np.sin(np.pi*x))) # second derivative matrix I2 = -2*np.eye(N) E = np.diag(np.ones((N-1)), k=1) D2 = (I2 + E + ET)/(h**2) I = np.eye(N) TFinal = 1 NumOfTimeSteps = int(TFinal/k) for i in range(NumOfTimeSteps): # Solve the System: (I - k/2*D2) u_new = (I + k/2*D2)*u_old A = (I - k/2*D2) b = np.dot((I + k/2*D2), u) u = scipy.linalg.solve(A, b) 
+6
python math scipy scientific-computing differential-equations
source share
3 answers

Let's look at a simple example. Suppose that N = 3 , i.e. Three internal points, but first we will include the boundary points in the matrix D2 that describe the approximate derivatives of the second order:

  1 / 1 -2 1 0 0 \ D2 = --- | 0 1 -2 1 0 | h^2 \ 0 0 1 -2 1 / 

The first line means that the approximate second derivative at x_1 is 1/h^2 * (u_0 - 2*u_1 + u_2) . We know that u_0 = 0 , although due to the homogeneity of the Dirichlet boundary conditions, therefore, we can simply omit it from the equation, and e get the same result for the matrix

  1 / 0 -2 1 0 0 \ D2 = --- | 0 1 -2 1 0 | h^2 \ 0 0 1 -2 0 / 

Since u_0 and u_{n+1} are not real unknowns - they are known to be equal to zero, we can completely discard them from the matrix and get

  1 / 2 1 0 \ D2 = --- | 1 -2 1 | h^2 \ 0 1 -2 / 

Missing entries in the matrix really correspond to the fact that the boundary conditions are zero.

+5
source share

I was told that the upper, lower rows of the matrix A contains two non-zero elements and the missing third element (that is, zero) is the Dirichlet condition.

I'm not sure what you were told, but here is what I know about this issue.

The Dirichlet boundary conditions fix the value of the potential (in this case, the temperature). The Neumann boundary condition defines the flow or the first derivative at a point. You will need this if you have boundary conditions for convection on the surface.

Regarding the consideration of the Dirichlet boundary conditions, you formulate a system matrix without taking into account the boundary conditions. If you have a fixed temperature for a given node, you can handle this as follows:

  • Set the line in the vector of the right side for this node to be equal to the boundary temperature. Extract all the columns of this row on the left side of the matrix and set the diagonal element corresponding to this node equal to one.
0
source share

Neither this answer makes any sense to me, we ask about fixed values โ€‹โ€‹that are unchanged during calculations, and will this affect the whole solution and the whole result? So how can we make values โ€‹โ€‹immutable? zeros at the beginning and at the end should not change during the process? as??

0
source share

All Articles