How to validate a code written for solution of 1D diffusion?

Click For Summary

Discussion Overview

The discussion revolves around the validation of a code developed for solving the one-dimensional diffusion equation related to heat conduction in a bar. Participants explore various approaches to validate their numerical or semi-analytical solutions, particularly when subjected to sinusoidal heat sources.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a conceptual model of heat conduction and seeks validation methods for their code, specifically looking for standard solutions to compare against.
  • Another participant suggests consulting "Conduction of Heat in Solids" by Carslaw and Jaeger for semi-analytical solutions.
  • A participant shares their MATLAB code attempting to implement a solution from Carslaw and Jaeger but reports erratic results, indicating difficulties in achieving correct outputs.
  • One participant proposes a different solution approach for the dynamic steady state, referencing "Transport Phenomena" by Bird, Stewart, and Lightfoot, which includes a sinusoidal temperature variation model.
  • Another participant emphasizes the importance of maintaining a small timestep-to-space step ratio to avoid instability in the numerical solution and suggests testing against self-similar solutions.
  • A later reply provides a specific solution form from Bird et al. for the temperature variation in the context of the problem discussed.

Areas of Agreement / Disagreement

Participants express differing views on the appropriate solutions and methods for validation, indicating that multiple competing approaches exist without a clear consensus on the best path forward.

Contextual Notes

Participants mention various sources and methods for validation, but there are unresolved issues regarding the implementation of the numerical code and the specific conditions under which the solutions apply.

Atr cheema
Messages
67
Reaction score
0
Consider the conceptual model presented in the attached image, of heat conduction in a bar.

There is a heat source at left side and heat is observed at point Ho after a distance L from the source. If we consider only heat transfer through conduction then this problem can be modeled by diffusion/heat conduction equation.
$$ \frac{\partial T}{\partial t} =D \frac{\partial T}{\partial x^2} $$
If I have developed a new semi-analytical or numerical solution (and eventually code) of this problem, then how can I validate my code?. For simplicity, suppose the source to be sinusoidal. Is there a standard solution for such an ideal case with sine input source, so that I can compare my code and then apply it to real field conditions?
 

Attachments

  • heatconduction.png
    heatconduction.png
    11.6 KB · Views: 563
Science news on Phys.org
Atr cheema said:
Consider the conceptual model presented in the attached image, of heat conduction in a bar.

There is a heat source at left side and heat is observed at point Ho after a distance L from the source. If we consider only heat transfer through conduction then this problem can be modeled by diffusion/heat conduction equation.
$$ \frac{\partial T}{\partial t} =D \frac{\partial T}{\partial x^2} $$
If I have developed a new semi-analytical or numerical solution (and eventually code) of this problem, then how can I validate my code?. For simplicity, suppose the source to be sinusoidal. Is there a standard solution for such an ideal case with sine input source, so that I can compare my code and then apply it to real field conditions?
Sure. See Conduction of Heat in Solids by Carslaw and Jaeger.
 
Chestermiller said:
Sure. See Conduction of Heat in Solids by Carslaw and Jaeger.
I have gone through some chapters of that book. He provides semi-analytical solutions in the form of equations for which we need to write code for example for example in case of semi infinite rod the solution he provides is
$$ \Delta h_m = \sum\limits_{m=1}^p \Delta H_m \{ erfc \frac{u}{2 \sqrt[]{p-m}} \} $$ p is total number of time steps and u is field variable.
I am unable to write a proper code for this equation. I have written following MATLAB code for this but it is giving me erratic results.
Code:
clear all; close all; clc;
deltat = 0.5;
deltaHvecc=sin(linspace(0.3,2.6,50));

deltaHvec=deltaHvecc-deltaHvecc(1);
x=45;
v = 40;
pvec = 1:50;  % total number of discrete values are 50
%suma=linspace(0,0,length(pvec));
u = x/sqrt(v*deltat);  % field variable
for i=1:length(pvec)
    p=pvec(i);
    deltaH=deltaHvec(i);
    suma = 0;
    for m=1:i
        erfcArg =  (u/(2*sqrt(p-m)));
      erfcfunc=erfc(erfcArg);  % calculating error function
      tek = deltaH*erfcfunc;
      suma = suma + tek;          % summation in the equation
    end
summa(i)=suma;
end
plot(summa); hold on; plot(deltaHvecc,'k')

The result of this code is given in the image I have attached with this answer, which is wrong as calculated can not be more than source.
So I can't compare the solution that I have derived with that of Carslaw and Jaeger.
My problem will be solved if either I am able to correct my code or get sample standard solution for the problem posed in original question.
 

Attachments

  • pinder.png
    pinder.png
    2.1 KB · Views: 610
This is not the solution I had in mind. The solution I had in mind was for the dynamic steady state at long times, in which the temperature approaches $$T=T_0+A(x)\sin{\omega t}+B(x)\cos{\omega t}$$ This solution is given in Transport Phenomena by Bird, Stewart, and Lightfoot, Chapter 4, Example 4.1-3
 
The factor ##\frac{\Delta t}{(\Delta x )^2}##, where ##\Delta t## is the timestep and ##\Delta x## the position step in the discretization, needs to be small enough or otherwise the solution will become unstable (small wavelength Fourier components of the solution will "explode" in amplitude). The code can be tested against the self similar solution

##C(x,0) = Ae^{-B(x-x_0 )^2}##
##C(x,t) = A(t)e^{-B(t) (x-x_0 )^2}##,

called "self-similar" because it's Gaussian for all ##t \in \mathbb{R}## (the functions A(t) and B(t) can be found from several sources), or simply the linear constant heat flux solution where the temperature/concentration are forced to stay constant at the endpoints of the domain.

I haven't done this for a sine/cosine time dependent source term (in the wave equation case that kind of term would excite oscillation modes that are in resonance with the frequency of the source term), but I have some related codes here in my blog:

https://physicscomputingblog.wordpress.com/2017/02/11/numerical-solution-of-pdes-part-1-explicit-method/
https://physicscomputingblog.wordpress.com/2017/02/11/numerical-solution-of-pdes-part-2-implicit-method/
https://physicscomputingblog.wordpress.com/2017/02/20/numerical-solution-of-pdes-part-3-2d-diffusion-problem/ .
 
The solution in Bird et al is: $$T=T_0+Ae^{-\sqrt{\omega/2D}x}\cos{(\omega t-\sqrt{\omega/2D}x)}$$where A is the amplitude of the temperature variation at x = 0.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 8 ·
Replies
8
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
13
Views
4K
Replies
4
Views
8K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 32 ·
2
Replies
32
Views
5K
Replies
4
Views
2K