Changes between Version 15 and Version 16 of u/ehansen/buildcode
- Timestamp:
- 11/01/11 10:57:01 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
u/ehansen/buildcode
v15 v16 1 1 = Building a 1D Hydro Code = 2 [[BR]] 2 3 3 == Introduction == 4 4 I'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 5 6 [[BR]] 6 7 == The Euler Equations == … … 17 18 18 19 In 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]] 19 22 == Solving the Riemann Problem == 20 23 The 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 21 25 [[BR]] 22 26 == Discretisation == 23 27 Discretisation 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 24 29 [[BR]] 25 30 == Godunov's First Order Upwind Scheme == … … 55 60 56 61 In 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 57 63 [[BR]] 58 64 == Boundary Conditions == 65 When 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 === 67 Transparent boundary conditions are the simplest of the three. A ghost cell is simply given the values of its neighboring cell. 68 === Reflective === 69 Think 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 === 71 For 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 73 Now 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 59 75 [[BR]] 60 76 == The CFL Condition == 77 CFL 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 81 Where [[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 85 Where v is the particle velocity and a is the sound speed. 86 61 87 [[BR]] 62 88 == Program Outline == … … 76 102 * Repeat time stepping procedure until final time is reached 77 103 * Output data to a file 104 78 105 [[BR]] 79 106 == 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:107 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 for better efficiency. Here is a table of all the input data for each test: 81 108 82 109 ||= Test Number =||= Discontinuity Position =||= Output Time =||= [[latex($ \rho_L$)]] =||= [[latex($v_L$)]] =||= [[latex($p_L$)]] =||= [[latex($\rho_R$)]] =||= [[latex($v_R$)]] =||= [[latex($p_R$)]] =||