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

In summary, the conversation discusses a conceptual model of heat conduction in a bar with a heat source and the use of diffusion/heat conduction equation for modeling. The speaker asks about validating their code for a new solution and mentions a book for reference. They also share their code and ask for a correction or a standard solution for comparison. The respondent suggests checking the book for a semi-analytical solution and provides a potential solution from another source. They also mention the importance of a small timestep in the code and suggest testing it against a self-similar solution or a linear constant heat flux solution.
  • #1
Atr cheema
69
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: 465
Physics news on Phys.org
  • #2
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.
 
  • #3
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: 537
  • #4
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
 
  • #5
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/ .
 
  • #6
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.
 

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

1. What is the purpose of validating a code for 1D diffusion?

The purpose of validating a code for 1D diffusion is to ensure that the code accurately represents the physical phenomenon of 1D diffusion. This involves checking for errors, bugs, and inconsistencies in the code that could affect the accuracy of the results.

2. How is the accuracy of a code for 1D diffusion determined?

The accuracy of a code for 1D diffusion is typically determined by comparing the results of the code with analytical solutions or experimental data. This involves running the code with different input parameters and comparing the output to known solutions or data.

3. What are some common methods for validating a code for 1D diffusion?

Some common methods for validating a code for 1D diffusion include grid convergence analysis, comparison with analytical solutions, and comparison with experimental data. Other methods may also include sensitivity analysis and code verification studies.

4. How can I ensure that my code for 1D diffusion is reliable?

To ensure the reliability of a code for 1D diffusion, it is important to thoroughly test and validate the code using multiple methods. It is also helpful to document the code and its assumptions, and to make sure that the code is well-documented and easily understandable for others to use.

5. Are there any tools or software available for validating a code for 1D diffusion?

Yes, there are several tools and software available for validating a code for 1D diffusion. These may include grid generation software, numerical analysis software, and visualization tools. It is important to choose the appropriate tools and software based on the specific needs and requirements of the code being validated.

Similar threads

Replies
7
Views
2K
Replies
7
Views
2K
  • Other Physics Topics
Replies
1
Views
2K
Replies
8
Views
2K
  • Differential Equations
Replies
1
Views
2K
  • Thermodynamics
Replies
2
Views
1K
  • Differential Equations
Replies
8
Views
2K
Replies
4
Views
1K
  • Differential Equations
Replies
7
Views
3K
Replies
6
Views
2K
Back
Top