r/CFD • • Feb 03 '21

[February] Programming languages for CFD

As per the discussion topic vote, February's monthly topic is "Programming languages for CFD"

User /u/SignificantCell2 asked for Rust experiences, but that sounded overly specific so i op'ed'd it into this.

Talk about your experiences and preferences with various programming languages in the context of CFD programming.

43 Upvotes

72 comments sorted by

View all comments

68

u/Overunderrated Feb 03 '21 edited Feb 03 '21

C++: it sucks, if you like it you're insane, but it's the only viable programming language for modern full featured CFD code. If you write in C++ you're definitely bad at C++, sorry not sorry.

Fortran: cool, keep on keeping on, tell me about your experiences when you grow past 1000 lines

F77: you didn't know F90 is backward compatible?

F90: you didn't know F2003 is backward compatible?

F2003: you knew F2003 exists but you didn't pick a different language? are you insane?

F2008: woowwwww really?

F2018: you exceeded neckbeard, circled around, and won it again.

python: cool, tell me about your experiences when you grow past 5 functions

C: i assume you're not actually writing numerical code, but someone else told you to because a book 40 years ago said to.

java: how are you even here?

matlab: that's really cute that you "do cfd"

rust: lol do you even know what a PDE is

julia: really surprised you're here, i assumed you're only on message boards talking about julia

pythonviabarba: welcome friends, hope you enjoyed copy-pasting, let's do real cfd now

19

u/anointed9 Feb 03 '21

Lmao. To repurpose an old joke:

How do you guess if someone uses julia?

You won't have to, they'll tell you first.

14

u/Overunderrated Feb 03 '21

How do you guess if someone uses julia?

You won't have to, they'll tell you first.

Don't worry, they'lll tell you they're unemployed first.

13

u/TurboHertz Feb 03 '21

Visual Basic?

40

u/Overunderrated Feb 03 '21

User has been banned for this post.

10

u/TurboHertz Feb 03 '21

Empty threat count: 3

10

u/Overunderrated Feb 03 '21

User has been banned for this post.

3

u/anointed9 Feb 03 '21

Strung up on a gibbet.

→ More replies (1)

3

u/Jon3141592653589 Feb 04 '21

Almost a decade ago now, I was teaching a CFD-relevant course and this guy showed up who loved Visual Basic. I made him complete all our projects in Fortran 77-90 and Matlab and, out of spite or obsession, he did a large fraction of it in VB, too, to show how "nice" the GUIs were. I didn't bother to ask for benchmarks, but probably should have.

6

u/Overunderrated Feb 04 '21

out of spite or obsession

I like this guy. If there's anything deserving an A, it's doing more work out of spite.

7

u/Jon3141592653589 Feb 05 '21

I had the same conundrum when a guy coded an iterative numerical (and series analytical) solution to a 2D Poisson equation in Excel by generating worksheet after worksheet, and automatically coloring the cells as "pixels" to visualize the solution, effectively making an Excel flip-book. There was a bit of spite involved in that one, too, no doubt. He's just lucky it converged within 255 iterations.

5

u/Overunderrated Feb 05 '21

I thought I was the only one. I saw a guy do 2D Euler in excel.

→ More replies (1)
→ More replies (1)

11

u/hivemind_unity Feb 03 '21

Dammn... This was brutal.. F90 guy here... I just googled backward compatibility

3

u/tlmbot Feb 20 '21 edited Feb 20 '21

I maintained 500,000 lines of F77 (plus the GUI in C++) for 6 years until somewhat recently. Fortran backward compatibility... yeah

7

u/reeram Feb 03 '21

I like C++. Am I clinically insane?

2

u/tlmbot Feb 20 '21

Perhaps, but lets add some nuance. First, this is a good thing, as, like the C++ template system, you to, are Turing completely insane. Congrats! Clinical insanity, however, is non-rigorous. Therefore... eh, maybe.

15

u/Ferentzfever Feb 03 '21

Matlab: Still better than my professor's hand-me-down F77 code (from his professor) that had to be recompiled every time you changed the mesh-size. Oh, and it was parallelized - on GPUs. And I made a GUI interface for it. And I didn't have to write my own linspace routines. And no GOTO. And we could post-process the data in-situ rather than write out a bunch of ASCII text files to be later read into Matlab for post-processing. And we didn't have to write our own FFT implementation. And I didn't have to teach undergrads what Cygwin was and what a "terminal" was... I will forever love Matlab, solely because it saved me from F77.

→ More replies (3)

4

u/TurbulentViscosity Feb 03 '21

rust: lol do you even know what a PDE is

Is this alluding to a lack of library support? Considering the number of segfaults and pointer problems I've had in the past with other codes, I was considering writing at least a mesher in rust.

6

u/psharpep Feb 03 '21

My guess is that it's alluding to the fact that most of the Rust users I know are "CS-types" rather than CFD/applied-math types (which is not necessarily a bad thing, just funny)?

I think a mesher in Rust would be a great idea, I've had problems like that too.

4

u/Remco_ Feb 03 '21

I'm mainly using Rust, coming from applied math background and I think that's an accurate assessment, but things in Rust are developing rapidly. Here's my take on doing Math in Rust:

Rust right now has great support for number-theoretic applications (this is where I've been working). I'd say for cryptography it has already overtaken C++ as the primary language for new development.

For linear algebra it's much more early days. There are two main libraries nalgebra and ndarray, they have some Blas/Lapack support and seem like a solid foundation. Sparse matrix support is still very early days.

Development is mostly driven by the needs of a quickly growing Rust game development community. See for example the Rapier and nphysics real-time physics engines. There's even promising implementation of Smoothed Particle Hydrodynamics: Salva. Besides games, a secondary driver for mathy developments is the machine learning community.

Both these communities have a strong interest in GPU support, so that is developing rapidly. WebAssembly/Browser support is also high on the agenda. Neither games nor machine learning is as concerned about numerical accuracy as CFD would be, but the Rust community is generally quite pedantic, so I'm sure contributions to improve things here are very welcome.

I'm myself interested in accurate CFD for sail boat design in Rust and was wondering if a SPH approach is appropriate so I could adapt Salva to my needs.

→ More replies (1)

3

u/ald_loop Feb 03 '21

C++ is nice, as long as you minimize pointer usage

I love it (most of the time)

My group code is header only due to the sheer number of templates, and while there are drawbacks to this sort of style I think it's great.

2

u/Wrench_Scar Feb 03 '21

How about some HolyC ??

→ More replies (11)