Coder Social home page Coder Social logo

simulkade / jfvm.jl Goto Github PK

View Code? Open in Web Editor NEW
42.0 7.0 13.0 1.62 MB

A simple finite volume tool for Julia

License: Other

Julia 100.00%
pde boundary-conditions julia finite-volume finite-volume-methods advection-diffusion reactive-transport dirichlet neumann robin

jfvm.jl's Introduction

JFVM

DOI

IMPORTANT NOTES

  • The code now works with Julia 1.0. All you need to do is to check out the master branch:
] 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:
] 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

sudo apt-get install python-matplotlib

Then install JFVM by the following commands:

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

Windows

  • open Julia and type
] add https://github.com/simulkade/JFVM.jl
  • For visualization, download and install Anaconda
    Run anaconda command prompt (as administrator) and install matplotlib by
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:

using JFVM, JFVMvis
Nx = 10
Lx = 1.0
m = createMesh1D(Nx, Lx)
BC = createBC(m)
BC.left.a[:].=BC.right.a[:].=0.0
BC.left.b[:].=BC.right.b[:].=1.0
BC.left.c[:].=1.0
BC.right.c[:].=0.0
c_init = 0.0 # initial value of the variable
c_old = createCellVariable(m, 0.0, BC)
D_val = 1.0 # value of the diffusion coefficient
D_cell = createCellVariable(m, D_val) # assigned to cells
# Harmonic average
D_face = harmonicMean(D_cell)
N_steps = 20 # number of time steps
dt= sqrt(Lx^2/D_val)/N_steps # time step
M_diff = diffusionTerm(D_face) # matrix of coefficient for diffusion term
(M_bc, RHS_bc)=boundaryConditionTerm(BC) # matrix of coefficient and RHS for the BC
for i =1:5
    (M_t, RHS_t)=transientTerm(c_old, dt, 1.0)
    M=M_t-M_diff+M_bc # add all the [sparse] matrices of coefficient
    RHS=RHS_bc+RHS_t # add all the RHS's together
    c_old = solveLinearPDE(m, M, RHS) # solve the PDE
end
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

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

jfvm.jl's People

Contributors

simulkade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jfvm.jl's Issues

"full" not defined in reshapeCell and reshapeInternalCell

Attempts to use reshapeCell or reshapeInternalCell result in an error of:

ERROR: LoadError: UndefVarError: full not defined
Stacktrace:
 [1] reshapeCell(m::MeshStructure, phi::CellValue)
   @ JFVM D:\Programs\Julia-1.6.1\.julia\packages\JFVM\v1vqd\src\JFVMtools.jl:330

my temporary (and quite poor) workaround to this is:

Ti = internalCells(T)
        Ti = [Ti[1,1:end]';Ti;Ti[end,1:end]']
        Ti = [Ti[1:end,1] Ti Ti[1:end,end]]
        T = createCellVariable(m,Ti)

So that I may use the cellvariable T (which is a solution from solving a PDE) in functions that are dependant on T, but return errors when operating on the ghost values of T.

I will look into a better fix & branch it later this week.

Thanks.

Could please help to solve this problem?

equation
PT1

Could you please help to solve it in Julia ?
I can do it in ansys fluent , but I want learn Julia.

oscillating flow through pipe (2D)
it is a transient compressible, viscous 2D flow problem. also, conventional heat transfer considers from the pipe wall.
it is a convention diffusion problem. at both ends, there are porous heat exchangers.

Thank you

A question about transient term calculation

What is the significance of using dt step-by-step calculation in transient term calculation? Will using a one-step calculation result in significant errors (compared to step-by-step calculation) ?

Thanks a lot for your help !

Info about upcoming removal of packages in the General registry

As described in https://discourse.julialang.org/t/ann-plans-for-removing-packages-that-do-not-yet-support-1-0-from-the-general-registry/ we are planning on removing packages that do not support 1.0 from the General registry. This package has been detected to not support 1.0 and is thus slated to be removed. The removal of packages from the registry will happen approximately a month after this issue is open.

To transition to the new Pkg system using Project.toml, see https://github.com/JuliaRegistries/Registrator.jl#transitioning-from-require-to-projecttoml.
To then tag a new version of the package, see https://github.com/JuliaRegistries/Registrator.jl#via-the-github-app.

If you believe this package has erroneously been detected as not supporting 1.0 or have any other questions, don't hesitate to discuss it here or in the thread linked at the top of this post.

"solvePDE" function broken

It seems the "solvePDE" set of functions cause my terminal to crash when attempting to solve a PDE. The error I receive is:

The terminal process "D:\Programs\Julia-1.8.0\bin\julia.exe '--color=yes', '--startup-file=no', '--history-file=no', '--project=d:\Github\CRUD.jl', 'c:\Users\sa8416.vscode\extensions\julialang.language-julia-1.7.6\scripts\debugger\run_debugger.jl', '\.\pipe\vsc-jl-dbg-9aa81c39-1399-435d-9fb6-f07804f28e12', '\.\pipe\vsc-jl-cr-e272cddf-e589-4ef3-9716-a35a7693db3e'" terminated with exit code: 1.

Edit: It seems the issue lies in the matrix of coefficients 'M' being a sparse matrix, temporary fix is to convert it to a dense matrix:

x=(collect(M))\RHS

Cylindrical1D version of Nonlinear PDE example

I am trying to convert the Nonlinear PDE example (https://nbviewer.jupyter.org/github/simulkade/JFVM.jl/blob/master/examples/solving-nonlinear-pdes-with-fvm.ipynb) to a Cylindrical1D mesh. The left (r=0) boundary is the standard (a=1,b=0,c=0) while the right boundary is a Robin BC. It appears that the Robin BC is working, but the left boundary holds the value (acts like a Dirichlet boundary) instead of allowing phi to drop. Perhaps I'm missing something in the conversion? The script is attached here:
FV_polygon1Dradial.jl.zip

The output of the script looks like:
Figure_1

But should look something more like:
compare

Julia wrapper for SU2 (The Open-Source CFD Code) (Stanford University Unstructured)

Python wrapper is available for SU2 (The Open-Source CFD Code).
Please provide Julia wrapper for SU2.
SU2 is a suite of open-source software tools written in C++ for the numerical solution of partial differential equations and performing PDE-constrained optimization.

There is no package for CFD in Julia. SU2 is good access for Julia.

could you forward it to the correct group to get more attention?

A question on 1D transient-diffusion problem

In fliud flow, is this method still appropriate for curve path? That is to say , if the one-dimensional mesh is polyline, is the transient-diffusion still applicable? My purpose is studying the water pressure of the polyline/curve crack path,like the black simplified crack paths in the picture. I want to know whether I can treat the polyline as a straight line to solve the transient-diffusion problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.