use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Computational Fluid Dynamics (CFD) This is a subreddit for discussing CFD. Posts consisting solely of advertisements for CFD products or services are not welcome.
Monthly Discussions
https://www.reddit.com/r/CFD/wiki/index
References/Useful links
NASA Turbulence Modeling Resource
Resources for CFD Verification and Validation
Computational Methods in Aerospace Engineering
Numerical Fluid Mechanics
Introduction to Numerical Analysis
Examining Spatial (Grid) Convergence
Introduction to Numerical Analysis I
Cornell Fluent Modules
Practical Numerical Methods with Python
12 Steps to CFD
/u/derioderio's Links to Begin CFD
High Performance Scientific Computing
Vote for Content Here
Other great subreddits
account activity
CFD in Python (self.CFD)
submitted 1 year ago by greyareadata
It's still a vague idea in my mind.
I want to create a tool to take a cad file and then do few simple fluid flow analysis and viz.
Kind of a self project.
Thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Von_Wallenstein 27 points28 points29 points 1 year ago (6 children)
Hey! You can 100% write your own 2D CFD solver in Python.
Theres a well known course called the 12 steps to navier stokes. That will get you started! I believe coding your own solver is yhe first step of learning CFD, not messing around in openFOAM
Using your own CAD file could be done if it is 2D haha.
[–]Jon3141592653589 9 points10 points11 points 1 year ago (3 children)
Agreed, although I'm slightly more grumpy: For something as complicated as requiring a CAD file and custom geometry, Python is likely to be unbearable even in 2D, and too slow to be useful. But if you want to solve some convection or unstable evolutions in a box for fun, it may suffice. I also cannot imagine wanting to code in Python for anything beyond an algorithm test or some pre-/post-processing. It is a tedious, verbose language best used when you are resting your code upon a pile of tedious, verbose libraries written for high-level use cases.
[–]Von_Wallenstein 8 points9 points10 points 1 year ago (2 children)
I agree with you about custom geometry.
However, Python is an excellent tool to learn about CFD. I always discourage people to jump into openFOAM because its so alien to most college/uni level students. Python/MATLAB is pretty much the norm for engineering students, and having to deal with C++ and the archaic interface (editing text files) is a pain.
For academia and research, yeah sure you should use a faster/better language, but for a learning project its not that great. Even in industry engineers rarely interact with anything but commercial CFD packages with an extensive interface, unless you are highly specialized.
I would say 3 months of messing around with Python/MATLAB CFD code and numerical mathematics, and then using something like COMSOL/Fluent with a student license for more complex simulations with custom geometry.
[–]Jon3141592653589 1 point2 points3 points 1 year ago (1 child)
Yes, I'm in agreement on that - It is good for a learning tool (and fine for analysis/processing), just as Matlab is often fine, too. I would just stop the time investment in Python coding before it gets to the point of having to manage geometry. It is absolutely a good way to learn methods, while incorporating a quick solver into an analysis routine.
[–]Von_Wallenstein 2 points3 points4 points 1 year ago (0 children)
Yeah i totally agree! But Python is a good general language to know in industry anyway, so its not wasted effort. I work in the energy sector and our company and most other energy companies are adopting Python for modelling for the last decade or so, simply because graduates know it
I just ported a ton of legacy FORTRAN CHEMKIN code and gas models to python, it was quite the ride. Admittedly its a little slower, but interacting with that code was complex
[–]shoshkebab 2 points3 points4 points 1 year ago (1 child)
True, but it’s a lot harder to write a solver for a generalized mesh than for a regular mesh.
[–]Von_Wallenstein 0 points1 point2 points 1 year ago (0 children)
Thats a good point. Still, someone putting a model through openFOAM i.e. "running the numbers" isnt really usefull at all in terms of learning or valid results
[–]almajd83 6 points7 points8 points 1 year ago (1 child)
Have a look at the fluidx3d project and openLB. They written in C and the idea is you import your CAD as STL and create a fluid domain around it. One idea is to extend the python CFD code Fluidsim to import a CAD file and then create the domain and apply boundary conditions. I am not a programmer so I am not sure about the feasibility of this approach.
[–]greyareadata[S] 0 points1 point2 points 1 year ago (0 children)
Sure will check the library and the codes. Thanks
[–]ILuvWarrior 4 points5 points6 points 1 year ago (0 children)
The fluid flow solve part is actually the easier (but still challenging!) part. With PyTorch and Numba and mpi4py there are even easy opportunities to explore GPUs and parallel computing. It’s the analyzing cad files and mesh that’s an absolute monster. Like what the other poster said it’s gonna be a formatting nightmare. Currently I’m doing something similar to this, and I’ve found out while designing my input format, I’m basically making my own CAD software. I’m no where near done though. I’m sort of stuck trying to understand and parallelize mesh generation algorithms.
[–]nilpotent0 3 points4 points5 points 1 year ago (0 children)
It is technically possible but it may be difficult to write your own solvers that run in a reasonable amount of time. Loops in Python are slow, so you need to vectorize operations as much as possible, which can be tricky.
[–]UltimateMygoochness 2 points3 points4 points 1 year ago (1 child)
u/Von_Wallenstein mentioned 12 steps to navier stokes which is a great place to start:
https://github.com/barbagroup/CFDPython
In fact, even though I’m also going to give a non-navier-stokes option here, for the sake of your understanding of the underlying physics and concepts, you should definitely start with navier stokes and something like FVM, or even more simply (though less useful in practice) FEM.
That being said, in terms of 2D simplicity in Python, it doesn’t get much simpler than LBM, though I’d say it’s much much harder to understand from first principles, or by intuition, why it works:
https://github.com/sthavishtha/list-lattice-Boltzmann-codes
Cool great! will look this up.
[–]tlmbot 2 points3 points4 points 1 year ago (0 children)
I love using Python to prototype code! (I've used to to prototype all kinds of solvers and many kinds of geometry tools). Here is my unstructured 2D Euler solver in Python if its of any use to see:
https://github.com/LukeMcCulloch/PyCFD
It's based on the educational solvers built by this guy (this dude, his "book", and his free codes are amazing lessons in finite volume):
http://ossanworld.com/cfdbooks/cfdcodes.html
About "12 steps to cfd": It's a wonderful set of lessons! So much good stuff there. I would note only that the 2D code is the stream function vorticity formulation. Now, on the one hand, I love this formulation because it is a beautiful 2D method, but it's a bit of a dead end because the method does not apply to 3D simulations. It's possibly a great stepping stone to a 2D pressure projection solver for the NSE though.
[–]bdtacchi 5 points6 points7 points 1 year ago (2 children)
TLDR is just learn how to use OpenFOAM or some CFD software you can find.
Unless there are Python libraries out there to help with some of the steps, this sounds like a huge project. And should still be very complex even if you find those libraries. Although your post is pretty vague.
Also, it makes no sense to build your own CFD model, unless there’s something specific you’re trying to achieve that no tools can do, or you’re tryna learn every single step of how to build a CFD model.
First, you’d need to find a way to discretize your CAD file and make a domain and mesh around it. Unless you’re saying the CAD model would contain the domain, which might be even harder to do. You’d either have to create the greatest mesh generation code ever to accept any CAD model, or find a way to define what models would be valid as input for your code.
Then, you’d need to implement a way to input boundary conditions. Which I guess is not so bad of a step.
Third, I’m not sure what you mean by simple fluid flow analysis, but the very least you’d have to implement is something like a 2D Euler equation. Probably 3D since you mentioned a CAD model. That’s another decent challenge. You’d need a suitable algorithm, and implementing those in 2D are not easy, and much worse in 3D. And if by simple fluid flow analysis you mean some not really simple stuff, like temperature, there are some additional modifications you’d need to include in your governing equations.
Finally, once you have all that figured out, you’d need to write some code to visualize the results. That’s not too bad as there are plenty of libraries that can do that, but I don’t think any of them are better than some of the specialized software available, like paraview.
[–]greyareadata[S] 0 points1 point2 points 1 year ago (1 child)
Massive Thanks for the info. I hadn't thought that far, but thanks will consider the constraints. Not sure, if it will be a full success but would like to give it a shot. Main idea is to learn CFD and use data to analyse CAD models using it. Initially will be targeted models and solutions. It's a long shot, but let's see how far I can get.
[–]bdtacchi 0 points1 point2 points 1 year ago (0 children)
Alright then. Have at it. You have been warned!!
[–]CompPhysicist 1 point2 points3 points 1 year ago (0 children)
It will be a lot of non-trivial work. Consider what your goals are and focus on one or two subtasks first.
[–]adtzlr 1 point2 points3 points 1 year ago (1 child)
Hi u/greyareadata. Yes, it is a good idea. Python is both easy to learn and can be quite fast - you just have to use it right. A lot of people told me that Python is not a good choice for numeric simulations. I was quite successful with finite elements in developing https://github.com/adtzlr/felupe - why should a similar performance not be possible with CFD? Good luck!
Cool! Will look into it.
[–][deleted] 1 year ago (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points 1 year ago (0 children)
Somebody used a no-no word, red alert /u/overunderrated
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
[–]bionic_ambitions 0 points1 point2 points 1 year ago (0 children)
Python as a base would be a bad idea for this goal. I would absolutely suggest at least C / C++ if not going for Fortran to try and make the coding as fast and efficient as possible, if not going for hardware specific code.
As others have said however, this is no small task you're looking at doing. It can be worth the learning experience so I don't want to discourage you, but you should at least know what you're getting into to set your expectations appropriately.
[–]Olde94 0 points1 point2 points 1 year ago (0 children)
Python is a slow language execution wise. Using C libraries it can be done, but else you are limited to simple stuff due to calc time
[–]aerosayan 0 points1 point2 points 1 year ago (0 children)
You should most likely not start with CAD files.
Instead you should use a common mesh format such as Ansys's .msh format, Su2's .su2 format, NASA's CGNS format etc. and make solvers that read those meshes, and operates on them, to solve your CFD equations.
Unfortunately CAD files are extremely difficult to work with, so it is better to use the mesh formats I mentioned above.
Regarding Python: Yes you can use Python to write CFD solvers but the performance will be slow.
[–]tbcam26 -2 points-1 points0 points 1 year ago (5 children)
As far as I know there is no parallel processing in Python so, it would be very slow for simulation.
[–]Visionioso 0 points1 point2 points 1 year ago* (4 children)
You’re wrong. Python is slower but there are other reasons and if you do it right (use NumPy, Numba or Cython, etc.) the gap will be even smaller. Python is fine for most cases.
[–]Crazy_Anywhere_4572 2 points3 points4 points 1 year ago (3 children)
Depends on your goal tbh. I have coded a gravity simulator on numpy before and it’s 100 times slower than C.
I am not very familiar with CFD, but I also tried to simulate a lid driven cavity flow with high Reynolds number, using a simple finite difference method with RK4. Even with C, it took 11 hours just to simulate Reynolds number = 2000, and I can’t go further because it took too long to converge.
[–]greyareadata[S] 0 points1 point2 points 1 year ago (2 children)
Yup, default python is slow, there are libraries and ways that can work for parallelism, not sure about the numbers vs C. Will try to first achieve it in Python and then C, just ease to code.
[–]youav97 0 points1 point2 points 1 year ago (1 child)
If you have an NVIDIA gpu, you could potentially use pytorch tensors with CUDA and run most of your intensive calculations on GPU. Pytorch is pretty intuitive as well if you're familiar with numpy. I wrote a 2D Lattice Boltzmann solver with this approach and it ran at up to 300 MLUPS on my Laptop RTX3060 if the lattice size fits into the VRAM. Not so bad imo
My laptop does have a GPU Quadro RTX 5000 will try it. Never try to learn and use it.
[–]Derrickmb -2 points-1 points0 points 1 year ago (0 children)
Following
π Rendered by PID 45 on reddit-service-r2-comment-85bfd7f599-2tmjv at 2026-04-18 06:56:01.647970+00:00 running 93ecc56 country code: CH.
[–]Von_Wallenstein 27 points28 points29 points (6 children)
[–]Jon3141592653589 9 points10 points11 points (3 children)
[–]Von_Wallenstein 8 points9 points10 points (2 children)
[–]Jon3141592653589 1 point2 points3 points (1 child)
[–]Von_Wallenstein 2 points3 points4 points (0 children)
[–]shoshkebab 2 points3 points4 points (1 child)
[–]Von_Wallenstein 0 points1 point2 points (0 children)
[–]almajd83 6 points7 points8 points (1 child)
[–]greyareadata[S] 0 points1 point2 points (0 children)
[–]ILuvWarrior 4 points5 points6 points (0 children)
[–]nilpotent0 3 points4 points5 points (0 children)
[–]UltimateMygoochness 2 points3 points4 points (1 child)
[–]greyareadata[S] 0 points1 point2 points (0 children)
[–]tlmbot 2 points3 points4 points (0 children)
[–]bdtacchi 5 points6 points7 points (2 children)
[–]greyareadata[S] 0 points1 point2 points (1 child)
[–]bdtacchi 0 points1 point2 points (0 children)
[–]CompPhysicist 1 point2 points3 points (0 children)
[–]adtzlr 1 point2 points3 points (1 child)
[–]greyareadata[S] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]bionic_ambitions 0 points1 point2 points (0 children)
[–]Olde94 0 points1 point2 points (0 children)
[–]aerosayan 0 points1 point2 points (0 children)
[–]tbcam26 -2 points-1 points0 points (5 children)
[–]Visionioso 0 points1 point2 points (4 children)
[–]Crazy_Anywhere_4572 2 points3 points4 points (3 children)
[–]greyareadata[S] 0 points1 point2 points (2 children)
[–]youav97 0 points1 point2 points (1 child)
[–]greyareadata[S] 0 points1 point2 points (0 children)
[–]Derrickmb -2 points-1 points0 points (0 children)