项目作者: simulkade

项目描述 :
A simple finite volume tool for Julia
高级语言: Julia
项目地址: git://github.com/simulkade/JFVM.jl.git
创建时间: 2014-12-31T23:26:06Z
项目社区:https://github.com/simulkade/JFVM.jl

开源协议:Other

下载


JFVM

DOI

IMPORTANT NOTES

  • The code now works with Julia 1.0. All you need to do is to check out the master branch:
    1. ] add https://github.com/simulkade/JFVM.jl
  • 3D visualization requires calling Mayavi via PyCall. It made too many problems recently, so I have decided to disable it until I find a better solution for 3D visualization. Suggestions/PRs are very welcome.
  • I have decided to move the visualization to a new package JFVMvis.jl, that you can install by:
    1. ] add https://github.com/simulkade/JFVMvis.jl

Equations

You can solve the following PDE (or a subset of it):
advection diffusion

with the following boundary conditions:
boundary condition

Believe it or not, the above equations describe the majority of the transport phenomena in chemical and petroleum engineering and similar fields.

A simple finite volume tool written in Julia

This code is a Matlabesque implementation of my Matlab finite volume tool. The code is not in its most beautiful form, but it works if you believe my words. Please remember that the code is written by a chemical/petroleum engineer. Petroleum engineers are known for being simple-minded folks and chemical engineers have only one rule: “any answer is better than no answer”. You can expect to easily discretize a linear transient advection-diffusion PDE into the matrix of coefficients and RHS vectors. Domain shape is limited to rectangles, circles (or a section of a circle), cylinders, and soon spheres. The mesh can be uniform or nonuniform:

  • Cartesian (1D, 2D, 3D)
  • Cylindrical (1D, 2D, 3D)
  • Radial (2D r and \theta)

You can have the following boundary conditions or a combination of them on each boundary:

  • Dirichlet (constant value)
  • Neumann (constant flux)
  • Robin (a linear combination of the above)
  • Periodic (so funny when visualize)

It is relatively easy to use the code to solve a system of coupled linear PDE’s and not too difficult to solve nonlinear PDE’s.

Installation

You need to have matplotlib (only for visualization)

Linux

In Ubuntu-based systems, try

  1. sudo apt-get install python-matplotlib

Then install JFVM by the following commands:

  1. ] add https://github.com/simulkade/JFVM.jl

Windows

  • open Julia and type
    1. ] add https://github.com/simulkade/JFVM.jl
  • For visualization, download and install Anaconda
    Run anaconda command prompt (as administrator) and install matplotlib by
    1. conda install matplotlib

Please let me know if it does not work on your windows machines.

Tutorial

I have written a short tutorial, which will be extended gradually.

In action

Copy and paste the following code to solve a transient diffusion equation:

  1. using JFVM, JFVMvis
  2. Nx = 10
  3. Lx = 1.0
  4. m = createMesh1D(Nx, Lx)
  5. BC = createBC(m)
  6. BC.left.a[:].=BC.right.a[:].=0.0
  7. BC.left.b[:].=BC.right.b[:].=1.0
  8. BC.left.c[:].=1.0
  9. BC.right.c[:].=0.0
  10. c_init = 0.0 # initial value of the variable
  11. c_old = createCellVariable(m, 0.0, BC)
  12. D_val = 1.0 # value of the diffusion coefficient
  13. D_cell = createCellVariable(m, D_val) # assigned to cells
  14. # Harmonic average
  15. D_face = harmonicMean(D_cell)
  16. N_steps = 20 # number of time steps
  17. dt= sqrt(Lx^2/D_val)/N_steps # time step
  18. M_diff = diffusionTerm(D_face) # matrix of coefficient for diffusion term
  19. (M_bc, RHS_bc)=boundaryConditionTerm(BC) # matrix of coefficient and RHS for the BC
  20. for i =1:5
  21. (M_t, RHS_t)=transientTerm(c_old, dt, 1.0)
  22. M=M_t-M_diff+M_bc # add all the [sparse] matrices of coefficient
  23. RHS=RHS_bc+RHS_t # add all the RHS's together
  24. c_old = solveLinearPDE(m, M, RHS) # solve the PDE
  25. end
  26. visualizeCells(c_old)

Now change the 4th line to m=createMesh2D(Nx, Nx, Lx, Lx) and see this:
diffusion 2D

More examples

TO DO

IJulia notebooks

How to cite

If you have used the code in your research, please cite it as

Ali A Eftekhari. (2017, August 23). JFVM.jl: A Finite Volume Tool for Solving Advection-Diffusion Equations. Zenodo. http://doi.org/10.5281/zenodo.847056

  1. @misc{ali_a_eftekhari_2017_847056,
  2. author = {Ali A Eftekhari},
  3. title = {{JFVM.jl: A Finite Volume Tool for Solving
  4. Advection-Diffusion Equations}},
  5. month = aug,
  6. year = 2017,
  7. doi = {10.5281/zenodo.847056},
  8. url = {https://doi.org/10.5281/zenodo.847056}
  9. }