1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Crank-Nicolson Example

  1. Mar 26, 2015 #1
    1. The problem statement, all variables and given/known data
    So I'm back to my wonderful computational physics course after a brief hiatus and once again, I am teaching myself the material. This unit we are working on some thermodynamics. We've just used the "Leap Frog" method to determine heat transfer of a 100k bar with both ends put in touch with a 0k sink. No problems there. The next part of the assignment is to use the Crank-Nicolson method to solve the same problem (1m bar, 100K, each end placed against a 0K sink). Our instructor and course material seem to believe that we should all be intimately familiar with Crank and Nicolson, but until now I would have thought them a body shop or law office.

    Apparently the method requires some use of a guassian elimination and matrices. So I'm gone ahead and coded a program that solves a gaussian elminiation. So now my only problem is determining what the base equations are that will populate this matrix. I've been doing quite a bit of digging but I'm just not getting it. None of my textbooks I have hear speak of Crank-Nicolson. Could any link me or work through not even this problem but any problem with setting up Crank-Nicolson? What are the basic equations I'm supposed to be using?

    2. Relevant equations
    From the class slides I have:
    T(i, j+1) - T(i,j) = η/2 [T(i-1,j+1) - 2T(i,j+1) + T(i+1,j+1) + T(i-1,j) - 2T(i,j) + T(i+1,j)
    -T(i-1,j+1) + (2/η + 2)*T(i,j+1) - T(i+1,j+1) = T(i-1,j)+(2/η - 2)*T(i,j) + t(i+1,j)

    3. The attempt at a solution
    Obviously T is the temperature and T(i,j) refers to the temperature at position i (assuming that the left side of the bar is at 0 and the right side is at 1m) and j is the time elapsed since the start (this was how we defined the problem in the first portion so I can't imagine that has changed). Personally I've been using T(x,t) because that seems to make a whole heck of a lot more sense to me than i and j.

    I'm kind of lost. If I could just see how any Crank-Nicolson problem was solved I think I could do it. But I'm trying to create code based off a half-assed stab at instruction and no fore-knowledge of the method in question. Please help!
     
  2. jcsd
  3. Mar 26, 2015 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    Google is your friend here. Just search using "Crank-Nicolson method" and you'll get plenty of hits and even a few examples using the method to solve a heat equation problem.
     
  4. Mar 27, 2015 #3
    With all due respect, saying "Google it" isn't exactly helpful. I have been Googling and while I still am not positive, I believe that my issue was that I was expecting a PDE to actually have some kind of equation at the base. I am getting the impression that (at least in this case) that isn't true. We've previously done the Jacobi relaxation and forward looking (and backwards looking) and I always thought, wouldn't this be more accurate if we included this side points as well? Clearly the answer is "YES!" So I grasped CN before I knew who either of them was.

    So, this is my understanding:

    I have a 1m bar at 100K and each end is placed against a 0K sink. For simplicity, I'll use .2m divisions. My initial state looks like:

    0 100 100 100 100 0 for future reference this will be 0 A B C D 0.

    Given the initial condition I can calculate the next time interval as so, given:

    0 A B C D 0
    0 E F G H 0

    The temp at E will be the average of (0 + A + B + E + 0 + F). The problem is that I dont have a value for F because F is the average of (A + B + C + E + F + G) and I don't have G because G is the average of (B + C + D + F + G + H) and H is the average of (C + D + 0 + G + H + 0). So the problem with CN is that all the equations for the next time interval must be solved simultaneously. Thus we have a system of equations that can be solved using a gaussian elimination.

    E = 100 + 100 + E + F = 1E + 1F + 0G + 0H + 200
    F = 100 + 100 + 100 + E + F + G = E + F + G = 1E + 2F + 1G + 0H + 500
    G = 100 + 100 + 100 + F + G + H = 1E + 2F + 2G + 1H + 800
    H = 100 + 100 + G + H = 1E + 2F + 2G + 2H + 1000

    So my matrix is:
    1 1 0 0 -200
    1 2 1 0 -500
    1 2 2 1 -800
    1 2 2 2 -1000

    But if I solve that I get:
    E = 0
    F = -200
    G = -100
    H = -200

    Which is nonsense. So clearly my matrix is screwed up.
     
    Last edited: Mar 27, 2015
  5. Mar 27, 2015 #4

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    It's not clear what you mean by "a PDE to actually have some kind of equation at the base."

    CN is a method to convert a PDE into a set of algebraic equations using finite differences instead of partial differentials or some other form of discretization like a finite element method.

    IDK what kind of hits you got with your google search, but mine turned up a couple of articles on CN being used to solve a heat equation problem:

    http://people.sc.fsu.edu/~jpeterson/5-CrankNicolson.pdf

    http://web.cecs.pdx.edu/~gerry/class/ME448/notes/pdf/CN_slides.pdf

    https://www.google.com/search?q=crank-nicholson&ie=utf-8&oe=utf-8

    I'm sure if you add more descriptive search terms besides "Crank-Nicholson", you may obtain hits more pertinent to your problem.
     
  6. Mar 27, 2015 #5
    These are the same things I've been looking at. Lets just go ahead and assume for future reference that I know how to Google. Googling solutions is a lot easier than typing all of this up. While I may not have specifically and explicitly said so in my initial post, the "I've been doing quite a bit of digging but I'm just not getting it." referred to Google searches and actual searches through the few textbooks I have access to. So lets further assume that I've already done the Googling. I don't need help in how to use a search engine.

    This particular link does not solve a problem. It outlines the theory behind CN. I get the theory behind CN. I understand what the purpose of it is, how it works and why it is better than the other methods. The difficulty I am having is turning that theory into a set of equations that I can use to populate a matrix.This link discusses the theoretical aspects of using CN to solve a problem. This is also why I requested in my initial post a worked through solution. So that I could see how one translates the theoretical into actual results.

     
    Last edited by a moderator: May 7, 2017
  7. Mar 27, 2015 #6

    DrClaude

    User Avatar

    Staff: Mentor

    It's hard for me to understand what more you want than what is in, e.g., http://web.cecs.pdx.edu/~gerry/class/ME448/notes/pdf/CN_slides.pdf

    On page 6, equation (3) gives you explicitly what you need. The RHS depends only on the known solution at step k, the matrix on the LHS is the thing you keep saying you are looking for, and the vector u is the unknown at step k+1 you are looking for. This is a problem of type ##A x = b##, which I gather you know how to solve.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Crank-Nicolson Example
  1. Operator nabla example (Replies: 9)

Loading...