аватар question@mail.ru · 01.01.1970 03:00

The numerical solution of the thermal conductivity problem

It is necessary to solve the problem of thermal conductivity on the segment

The solution used an explicit scheme

N = 10> # maximum number of steps in xK = 10 # maximum number of steps in tl = l = 1 # value of x on the right borderh = l /N # grid# grid pitch along xT= 1 # maximum time value t on the right bordert = T/K # grid step by time# setting the grid x_i = np.arange(0, N, h) # values in nodes of xt_j = np.arange(0, K, t) # value in nodes by tr_j=ass=""># value in nodes by tr_j= len(t_j) # number of nodes by tr_i = len(x_i) # number of nodes by xw_h_t = np.zeros([r_i, r_j]) # final grid size x_i*t_j# set the value of the function included in the initial equationx =nx = 0defdef f(x): retu np.sin(x)# boundary conditions# boundary coditionsux_0 = 1 # boundary condition at the left end at x=0ut_0 = np.cos(x_i) # boundary condition at t=0# find the values at zero layer at t=0 ut_0 = np.cos(x_i)w_h_t[0] = np.cos(x_i)# find the values of w_h_t on the first and subsequent layersconst = t / (h**2) forfor j ins="">in range(1, len(x_i)-1):    1):    for i in range(len(w_h_t[j])-1):                w_h_t[j+1, i] = w_h_t[j, i] + const * (w_h_t[j,i] - 2*w_h_t[j,i] + w_h_t[j, i-1]) + t*f(x_i[j])        w_h_t[j+1, 0] = 1        w_h_t[j+1, len(w_h_t[i])-1] = w_h_t[j+1, len(w_h_t[i])-2] + h * t_j[j+1]plot_ = np.arange(0,len(w_h_t)-1,1)foran>,1)for y inpan> plot_:    plt.plot(x_i, w_h_t[y])

As a result, I got this graph of the dependence of X on the calculated value of the function at the nodes of the grid

I don't understand how wrong my decision is. I had problems finding a private solution, wolfram gave u(x) = 1.54x+1+sinx, which doesn't seem right to me, but I couldn't solve it myself. There were no similar examples in Filippov's textbook, and I didn't find anything detailed enough on the Web to figure out the solution. Can you tell me where I can find how to solve such an equation analytically and how wrong is my solution? What is the error? And how is it generally checked for the correctness of solving such problems, except for comparison with an analytical solution?


In general, I figured it out. I decided to add an edited solution to my question, perhaps it will be useful to someone. The numerical solution has not been found correctly, but it is found by the Fourier method (separation of variables). Final schedule:

Working code:

N = 10> # maximum number of steps in xK = 500 # maximum number of steps in tl = l = 1 # value of x on the right borderh = l /N # grid# grid pitch along xT= 1 # maximum time value t on the right bordert = T/K # grid time step# set the grid x_i = np.range(0, 1, h) # values in nodes of xt_j = np.arange(0, 1, t) # value in nodes by tr_j =ss=""># value in nodes by tr_j = len(t_j) # number of nodes by tr_i = len(x_i) # number of nodes by xw_h_t = np.zeros([r_j, r_i]) # final grid size x_i*t_j# set the value of the function included in the initial equationx =nx = 0defdef f(x): retu np.sin(x)# boundary conditions# boundary coditionsux_0 = 1 # boundary condition at the left end at x=0ut_0 = np.cos(x_i) # boundary condition at t=0# find the values at zero layer at t=0 ut_0 = np.cos(x_i)w_h_t[0] = np.cos(x_i)# find the values of w_h_t on the first and subsequent layersconst = t / (h**2) forfor j ins="">in range(len(w_h_t) - 1):    1):    for i in range(len(w_h_t[j]) - 1):                w_h_t[j + 1, i] = w_h_t[j, i] + const* (w_h_t[j, i+1] - 2/span> * w_h_t[j, i] + w_h_t[j, i - 1]) + t*f(x_i[i])        w_h_t[j + 1, 0] = 1        w_h_t[j + 1, len(w_h_t[i])-1] = w_h_t[j + 1, len(w_h_t[i])-1] + h
                        
                    
аватар answer@mail.ru · 01.01.1970 03:00

Unfortunately, not a specialist is precisely in thermal conductivity, but I can note a few accurately problematic points:

  • at the moment, a step on the net of time is not connected with a step in the grid in space. In obvious schemes - this leads to instability. We need to observe. In your case, if I remember correctly thermodynamics, & delta; t & lt; CFL * & chi; * (& Delta; x) & sup2; . That is, & delta; t & lt; (& Delta; x) & super2; (& chi; - Radiative Diffusion in your equation = 1). In your program, this is clearly not observed either by specific values ​​or in algorithm. Solution: Bind k and n to each other.

  • according to your graphics, it is very difficult to understand what is happening. If you draw every step of time on a separate schedule, then it can be seen that the numerical solution is diverging. In particular, this is also visible in your drawing ( e121 ). It is explained at least clause 1, and, possibly, some other problems in the program. In addition, decisions on the intermediate steps look very suspicious.

  • See the values ​​of the x_i and t_j ( print (x_i) ) - now these are arrays from 0 to 9.9 with a step 0.1 . Judging by the condition, the step, the number of steps and the right border is confused.

  • now by checking solutions. Formally, such a code can be checked through, but for your task, of course, this is too much.

    when teaching numerical methods, the tasks are most often used for which the analytical solution is known and the result is already compared with it. It is also worth checking:

    • are the initial and final conditions of
    • the analysis of the convergence (reduced the step by time - it became better? Did you have reduced the sampling step in space - it became better?)
    • does the energy come out of nowhere (for closed systems)? The solution with the solution of the commercial \ open-source of the simulator?
    • If you solve the equation with another numerical method (for example, by the method of final elements), will we get about the same?

    Latest

    Similar