I do like CFD.
Useful books on Computational Fluid Dynamics
Free CFD Codes
Facebook share

More sample programs are coming up: Delaunay triangulation code, a panel code for an airfoil, 2D unstructured Navier-Stokes code, etc.
[Note: As the name, Katate Masatsuka, implies, I write only when I find time.]

"I do like CFD, VOL.1, Second Edition" is now available in both printed and PDF versions. Download PDF (FREE) at cfd-boook page.

CFD seminar at National Institute of Aerospace is now broadcast online!
Check out the website for seminar videos and files - NIA CFD Seminar

Favorite Codes and Subroutines      


2D Implicit Unstructured Euler code (OSSAN-Euler2D-Implicit; 5 files):

  data_package_v0.f90
  euler_solver_v0.f90
  jacobian_v0.f90
  linear_solve_v0.f90
  main_v0.f90
  readme_v0.txt
  twod_bump_irregular_grid_v0.f90(grid generation code)
 
Want to learn how to write an implicit unstructured CFD code? Grab this code, look inside to see how it is written, get good understanding, and then write your own. This code computes a steady flow over a bump with the Roe flux by two solution methods: explicit 2-stage Runge-Kutta scheme and implicit (defect correction) method with the Jacobian exact for 1st-order scheme, on irregular triangular grids. A grid generation code is included.

NOTE: It is an edge-based second-order finite-volume code. It contains enough information to convert it to a cell-centered finite-volume code.

NOTE: These files are different from the explicit version of the OSSAN-Euler2D (which is designed to solve a shock diffraction problem).

NOTE: The implicit method becomes Newton's method with infinte CFL and GS relaxations for 1st-order spatial discretization (if LSQ gradients are set zero).




[ I plan to upload a 2D Navier-Stokes code (OSSAN2D) in future. This is the inviscid steady version. ]

Machine zero:   machinezero_v2.f90
What is machine zero? Maybe, it is a non-zero number which cannot be recognized by a machine. So, it depends on machines. Download, compile, and run it to find out the `zero' in your machine.

Generalized. Now it finds `machine zero' for a given value. (11-29-12)

Automatic Differentiation Ver.1:   ad_driver_v1.f90   module_ddt3.f90
Automatic differentiation is nice. It is sometimes used to compute flux Jacobians for implicit formulaitons in CFD. To those who are curious about it, here is a set of files with which you can experience and learn how it works. Simply compile the file "ad_driver.f90" and run it (the other file will be automatically included in the program) to get a feeling of automatic differentiation.

Numerical Fluxes (3D Euler) Ver.3: threed_euler_fluxes_v3.f90
Here are 3D Euler numerical fluxes. Download and take a look. Learn how the standard Roe and a very robust rotated-hybrid fluxes are implemented for the 3D Euler equations, and also how the Roe flux can be implemented without tangent vectors. Included are Roe with/without tangent vectors, and Rotated-RHLL fluxes. I'll be extremely happy if you kindly report bugs. Thank you, arigatou!

Bugs fixed for the RHLL flux, more comments added, Roe without tangent vectors added. (04-30-12).

2D Explicit Unstructured Euler code (OSSAN-Euler2D; 3 files):

  data_package_v0.f90
  euler_solver_v0.f90
  main_v0.f90
  readme_v0.txt
  twod_rectangular_grid_v0.f90

Want to learn how to write an unstructured CFD code? Grab this code, look inside to see how it is written, get good understanding, and then write your own. This code has Roe and Rotated-RHLL fluxes, Van Albada limiter, and a 2-stage Runge-Kutta time-stepping for solving a shock diffraction problem. It works for quadrilateral grids, triangular grids, and mixed grids also. It is set up to solve a shock diffraction problem. You can easily modify it for solving other problems. A grid generation code is included.

NOTE: It is an edge-based finite-volume code. It contains enough information to convert it to a cell-centered finite-volume code.




[ I plan to upload a 2D Navier-Stokes code (OSSAN2D) in future. This is the inviscid version. ]

3D Grid Generation for Hemishpere Cylinder:
How to make a nice and isotropic 3D grid for a hemisphere cylinder? I came up with an idea and implemented it into the code. It works great. It still requires a little improvement, but it does generate a very nice triangulation on the body. Grab the code, try it, improve it and let me know. Thanks, arigatou!

12-18-11: Serious bug found. Will correct them and upload it again.

Flow around a Karman-Trefftz airfoil (generate grids and exact solutions):
  vkt_airfoil_v3.f90 ,   vkt_airfoil_v1_display.m
Karman-Trefftz airfoil is an intriguing airfoil for which a complete set of exact solutions can be computed. This solution has been used by many people to verify the accuracy of their inviscid code (incompressible limit). If you have not, use this code now to generate a (quadrilateral or triangular) grid, run your code on it, compute the error, and verify the accuracy of your code. Me? I have used it for my third-order multigrid Cauchy-Riemann solver (IJNMF 2004).

Updated (10-13-10). Formula corrected. It works now for cambered airfoils.

1D Hyperbolic Diffusion Scheme:   oned_upwind_diffusion.f90
Believe or not, the diffusion equation is solved by an upwind scheme. The idea is to integrate an equivalent hyperbolic system toward a steady state. This way, we can advance in time with a large O(h) time step (not O(h^2)), and compute the solution gradient with the equal order of accuracy. Compare with a common scheme (Galerkin) for 512 nodes to see how fast the upwind scheme can be.

Reference: JCP2007 | Preprint

3D Mixed Grid Generation:   mixgrid_cube_v3.f90
Mixed (tetrahedral-prismatic) grid in a unit cube is generated and written in the UGRID format. Learn how a typical viscous-type grid can be generated. You may want to modify the code to apply stretching to the prismatic layer for a smooth transition to the isotropic tetrahedral region.

3D Tetrahedral Grid Generation:   tetgrid_cube_v3.f90
Tetrahedral grid in a unit cube is generated and written in the UGRID format. Learn how the hexahedron can be divided into six tetrahedra. Mdify the code to divide the hexahedron into five tetrahedra.

3D Prismatic Grid Generation:   przgrid_cube_v3.f90
Prismatic grid in a unit cube is generated and written in the UGRID format. It's just a cubic domain, but may be useful in learning unstructured grid data.

3D Hex Grid Generation (Unstructured Format):   hexgrid_cube_v3.f90
Hexahedral grid in a unit cube is generated and written as unstructured/finite-element data in a UGRID 3D unstructured grid file. It may be useful for those who want to learn a typical data structure of unstructured grids.

Genetic Algorithm, Ver.1:   ga_v1.f90
This is a simple genetic algorithm program for finding minimizers of a function. I wrote this in 1999 when I was interested in aerodynamic optimization problems. I think that genetic algorithm is a very interesting optimization algorithm.

1D Euler Code Ver.1:   oned_euler_v1.f90 ,   oned_euler_plot_v1.m
Here is a 1D Euler code (1D shock tube code) for solving Sod's shock tube problem, using Roe's Approximate Riemann solver, minmod limiter, and 2-stage Runge-Kutta time-stepping. Learn how a second-order non-oscillatory Euler code is written, or just run it to see how it is capable of computing discontinuous solutions. Incorporate various flux subroutines given below to explore other methods.

Minor bugs fixed (12-29-10).

Numerical Fluxes (1D Euler) Ver.5:   oned_euler_fluxes_v5.f90
All numerical fluxes are functions of the left and right states (and possibly dt and dx). Learn how those famous fluxes can be implemented, or just use them to see how they work for various shock-tube problems. Included are Lax-Friedrichs, Richtmyer, MacCormack, Steger-Warming, Van Leer, AUSM, Zha-Bilgen, Godunov, Osher, Roe, Rusanov, HLL, HLLL, AUFS flux functions.

Bug fixed for Godunov fluxes.

Numerical Fluxes (2D Euler) Ver.2:   twod_euler_fluxes_v2.f90
Want 2D fluxes also? Here you are. Download and take a look. Learn how the standard Roe and a very robust rotated-hybrid fluxes are implemented. Included are Roe and Rotated-RHLL fluxes (Riemann Solvers).

Bugs fixed for the Rotated-RHLL flux. It works very well now.

Ringleb's Flow (generate grids and exact solutions):   ringleb_v1.f90
Ringleb's flow is a famous exact solution of the compressible Euler equations with a smooth transition from subsonic to supersonic without any shock waves. This solution has been used actually by many people to verify the accuracy of their Euler code. If you have not, use this code now to generate a (quadrilateral or triangular) grid, run your Euler code on it, compute the error, and verify the accuracy of your Euler code.

Minor bugs fixed (12-29-10).

Blasius solutions for a flow over a flat-plate (compute the exact solution) :
  blasius_v1.f90 ,   blasius_plot_v1.m
Exact solution for a flow over a flat-plate. This solution has been used by many people to verify the accuracy of their Navier-Stokes code. If you have not, use this code now to compute the exact solution at any point on your grid, compute the error, and verify the accuracy of your code.

Minor bugs fixed (12-29-10).

Viscous shock structure NS-solution (compute the exact solution) :
  ns_shock_structure_v1.f90 ,   ns_shock_structure_plot_v1.m
Exact solution for a shock wave internal structure to the 1D Navier-Stokes equations. This solution has been used by some people to verify the accuracy of their 1D Navier-Stokes code. If you have not, use this code now to generate a data file for the exact solution, use it as an initial solution for your code, converge to a steady state, and verify the accuracy of your code.

Minor bugs fixed (12-29-10).