Changes between Version 15 and Version 16 of u/ehansen/buildcode


Ignore:
Timestamp:
11/01/11 10:57:01 (13 years ago)
Author:
ehansen
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • u/ehansen/buildcode

    v15 v16  
    11= Building a 1D Hydro Code =
    2 [[BR]]
     2
    33== Introduction ==
    44I've created this page to document the important aspects of building a hydro code.  It contains general information that I have learned from reading ''Riemann Solvers and Numerical Methods for Fluid Dynamics: A Practical Introduction'' by E.F. Toro.  In the near future, it will contain useful information from my own personal experience as I build my first hydro code.
     5
    56[[BR]]
    67== The Euler Equations ==
     
    1718
    1819In this form, it might be easier to see that the change in a conserved quantity is equal to its flux coming into the volume minus its flux going out of the volume.
     20
     21[[BR]]
    1922== Solving the Riemann Problem ==
    2023The Riemann problem is essentially the Euler equations with discrete initial conditions.  Initial data has a left state and a right state, separated by a discontinuity.
     24
    2125[[BR]]
    2226== Discretisation ==
    2327Discretisation is the process of taking a domain and dividing it into cells.  The "mesh size" [[latex($\Delta x$)]] is defined as the domain length divided by the number of cells.  Each cell contains data corresponding to a specific problem initialization thus creating many Riemann problems.  In other words, each neighboring pair of cells is now a "local" Riemann problem.  Given two neighboring cells, the left cell is the left data state, the right cell is the right data state, and the intercell boundary is the discontinuity position.  Now each local Riemann problem can be solved and that solution can be used to calculate the fluxes required to update the cells to the next time step.
     28
    2429[[BR]]
    2530== Godunov's First Order Upwind Scheme ==
     
    5560
    5661In summary, the necessary quantities to update a cell are: its initial quantities, the mesh size, the time step size, and the fluxes through its boundaries.  Initial quantities are known, the mesh size is chosen by the user, and the fluxes are calculated from solving the Riemann problem.  However, in order to calculate the fluxes for the first and last cell we need more information.
     62
    5763[[BR]]
    5864== Boundary Conditions ==
     65When you discretize a domain, you have to create "ghost" cells outside your domain so that you can calculate the necessary fluxes.  These ghost cells are assigned values depending on the boundary conditions, and this assignment is imposed every time step.  The three most common boundary conditions are transparent, reflective, and periodic.
     66=== Transparent ===
     67Transparent boundary conditions are the simplest of the three.  A ghost cell is simply given the values of its neighboring cell.
     68=== Reflective ===
     69Think of reflective boundary conditions as a rigid wall.  A ghost cell is given the same values as its neighboring cell, except its velocity is negated.
     70=== Periodic ===
     71For periodic boundary conditions, I like to think of the old Atari game Asteroids.  If material leaves through the right boundary it comes back through the left boundary.  To achieve this, the first ghost cell is given the same values as the last domain cell, and the last ghost cell is given the same values as the first domain cell.
     72
     73Now that we have boundary conditions, we can get all the fluxes for our domain cells.  However, we still need to choose an appropriate time step size to make our updating scheme complete.
     74
    5975[[BR]]
    6076== The CFL Condition ==
     77CFL stands for Courant-Friedrichs-Lewy.  The CFL coefficient (often just referred to as the CFL) is used to calculate the time step size.  The time step size along with the CFL condition is:
     78
     79[[latex($\Delta t = \frac{CFL \ \Delta x}{S_{max}}$)]]
     80
     81Where [[latex($0<CFL \le 1$)]].  [[latex($S_{max}$)]] is the maximum wave speed within the domain at the current computational time.  This condition ensures that the time step is not large enough to allow a wave to pass through an entire cell within that time.  A CFL of 1 gives the maximum time step size, which is the most efficient, but can often lead to inaccuracies if [[latex($S_{max}$)]] is not reasonably known.  Therefore, it is common to use a CFL of 0.9.  A popular estimate for the maximum wave speed is:
     82
     83[[latex($S_{max} = max[|v_i| + a_i]$)]]
     84
     85Where v is the particle velocity and a is the sound speed.
     86
    6187[[BR]]
    6288== Program Outline ==
     
    76102   * Repeat time stepping procedure until final time is reached
    77103* Output data to a file
     104
    78105[[BR]]
    79106== Test Results ==
    80 Five different tests were run in accordance with the tests in Ch. 6 of Toro's aforementioned book.  All tests were run with a domain length of 1.0 and 100 computing cells.  For the first five time steps a CFL of 0.18 was used to give the various waves time to develop.  For the time steps following, a more natural CFL of 0.9 was used to obtain more accurate results.  Here is a table of all the input data for each test:
     107Five different tests were run in accordance with the tests in Ch. 6 of Toro's aforementioned book.  All tests were run with a domain length of 1.0 and 100 computing cells.  For the first five time steps a CFL of 0.18 was used to give the various waves time to develop.  For the time steps following, a more natural CFL of 0.9 was used for better efficiency.  Here is a table of all the input data for each test:
    81108
    82109||= Test Number =||= Discontinuity Position =||= Output Time =||= [[latex($ \rho_L$)]] =||= [[latex($v_L$)]] =||= [[latex($p_L$)]] =||= [[latex($\rho_R$)]] =||= [[latex($v_R$)]] =||= [[latex($p_R$)]] =||