Setting up a programming environment to develop CFD codes

If you want to develop CFD codes or simply run some examples found on this website, you will need a sensible programming and development environment on your PC or laptop. In this article, we look at how to set one up on Windows, Linux, and macOS. Compiling code on different platforms has historically been a challenge, but these days, compilation workflows on different platforms are converging, and cross-compilation has never been easier.

This article shows how to compile the same code on Windows, Linux, and macOS. Even if you have no interest in working on all three platforms, you may want to support users on all of these, so you probably want to test your code on all supported platforms. And it is my (rather strongly held) opinion that we should strive to make our code work on all three platforms. By the end of this article, you will have three systems set up to compile and run any developed CFD code to accomplish exactly that.

In this article

Introduction

This website aims to get people into programming in CFD solvers. In my view, this is the only practical way to understand how CFD solvers work and build up an intuition for why certain schemes and algorithms behave the way they do. You may not have an interest in writing your own solvers (yet!), but if you want to get a feeling for how changing solver parameters will influence your CFD results, then you need an intuition to go by and the easiest way to get that is to get your hands dirty and start programming.

Compare that to learning an instrument. Sure, you can read books and watch online tutorials on how to play an instrument, but we can probably all agree that no one has learned an instrument just by reading up on it or watching a few tutorials. You need to practice with the instrument directly, and you need time; no one has mastered an instrument within a few hours.

If you only ever care about how to set up a simulation and learn the graphical user interface of a CFD solver (or text input files for a non-graphics-based solver), this is akin to learning all the various switches and buttons on a synthesiser. Knowing what all of these buttons do doesn’t mean that you can play the synthesizer well. You still will need practice. The same is true with CFD, if you want to get an intuitive understanding, you’ll need to spend some time on programming algorithms and observing its behaviour.

When I started my PhD in CFD, I had a good understanding of how ANSYS Fluent was working, and I had worked on a few CFD codes myself before, mainly academic in nature (and not necessarily good ones, including my very own solver based on the lattice Boltzmann method, a horrible collection C++ classes). By the time I finished my PhD, I had developed a few variants of the same solver, and implementing schemes, algorithms, and ideas from scientific papers and books really helped me develop an intuition for how these schemes and algorithms performed.

During that time, I also picked up OpenFOAM, and really getting to grips with OpenFOAM (including writing my own solvers and numerical schemes in it) helped me understand some more advanced concepts that I didn’t touch upon in my simplified CFD solvers. This combination of basic scheme and algorithm implementation + OpenFOAM gave me a drastically different view of how CFD works.

If you only ever stick with ANSYS Fluent, Star-CCM+, or any other larger commercial CFD package, you’ll get a skewed perspective and the impression that CFD is easy. It isn’t, and a lot is hidden from you. Commercial CFD solvers will try their best to get you to a solution. Ideally, it is the correct solution, but that is hard to tell. The problem is that if you feel you have gained expertise in one solver, you will have difficulty switching to another. For example, if you try to switch from Fluent to OpenFOAM, you are in for a nasty surprise! They are very different.

So, if programming is so important, I thought I would share with you my development environment setup, as I have learned, time and again, that most people will set up something that works and stick with it without questioning it. If it ain’t broke, don’t change it, right? Well, there is a lot of information online on how to get code to work, but none of that is satisfactory, in my view. Most sources are focused on a specific platform (Windows, Linux, or macOS), but it is my view that we should aim to write code that can compile on all platforms.

In the 21st century, cross-compiling code for different operating systems and platforms should be the norm. Yet, looking through open-source CFD solvers and libraries, this seems to be the exception. Software engineers are no longer concerned with cross-compilation; this problem was solved long ago. No, software engineering deals with cross-device compilation (PC, web, mobile, embedded devices), though I don’t think we need to get this deep into the material. For our intents and purposes, cross-compilation is good enough.

In this article, we will look at a few cross-platform tools that we can use to create a repeatable development environment. We will then look at how to install everything for each specific platform, with platform-specific tips and tricks along the way.

Cross-platform Tools

In this section, we’ll look at tools that work across different platforms, and these reflect some of my favourite tools that I personally use on all platforms. You don’t need any of these, and if you have strong beliefs to go with alternative tools, then by all means, go for them. I list them here as I believe these can greatly simplify your workflow switching from one platform to another; the operating system may look different, but the development will feel exactly the same (pretty much) regardless of the platform.

Cross-platform compilers

When it comes to cross-platform compilers, there aren’t many compilers available. I only know one compiler that works across Windows, Linux, and macOS: the clang compiler by LLVM (for completeness, I am talking about open-source compilers; I know that other commercial compilers like Intel work across platforms). The advantage of having one compiler across all platforms is that you only have to learn compiler flags once. Each compiler also gives you different ways of reporting errors, and these are not always sensible, in my view, so if you know one compiler, it doesn’t matter where you compile.

If you work natively on Windows, you’ll likely work with Microsoft’s cl compiler. On Linux, you would use the GNU compiler suite, and on macOS, well, you would actually use clang. Clang and GNU’s C++ compiler are pretty similar in terms of compiler flags, but Clang probably provides nicer and more human-friendly error messages. cl loses out on both aspects, for me, but you can’t avoid the Microsoft toolchain on Windows entirely by using Clang (I have tried and failed!), especially once you get into compiling static and dynamic libraries.

Cross-platform code editor

Name a code editor, and I have probably stress-tested it for a few months to years before switching to a different editor. Since 2012, I have had a compulsion to change my code editor whenever I come across something new and shiny, though I had a sting in 2015-2018 where I stuck with the same code editor for years (sublime text, in case you are interested).

In 2018, I came across Microsoft’s Visual Studio Code (not to be confused with Visual Studio, great naming by great people), and I have basically never looked back since then. I tried a few alternatives since then (atom, which was then ultimately discontinued) and VIM (programming in hardcode mode, but perhaps I am not nerdy enough to find it enjoyable), though I have never found a compelling reason to switch (though, after locating the link for sublime text above, I looked through the latest list of features, and I have to say, I am intrigued…).

Visual Studio Code (or vscode, in short) is a great open-source tool if you can live with Microsoft’s constant need to monitor you and your project and likely steal some of that data/code to train its deep neural networks (just so that you can get a bing chatbot, great) If you are OK with that, then this software is actually quite decent. There is a monitoring free alternative, based on the same core of vscode, called vscodium, unfortunately, though, all Microsoft extensions are blocked from the extension market place and that means no C++ support, which is annoying.

All that aside, I have found vscode to be the perfect lightweight code editor suited for pretty much anyone’s programming needs. The editor itself is very barebones and doesn’t have many features, but it comes with the same key commands as sublime text, which makes changing over very simple (and offers really powerful text editing capabilities). There is a decent git integration and integrated terminal, and that is all you need, really, to get started.

But should you need anything else (and you will, eventually), then you have a marketplace with so many extensions to choose from that you can customise your instance of vscode to fit your needs. The extensions will really shape the editor into the final product so different people using vscode for different purposes will have an entirely different code editor, where only the interface looks the same (although even that can be customised).

Here is a list of my favourite extensions that you may want to give a try if you are using vscode:

  • All the C/C++ extensions from Microsoft: Adds syntactic sugar to your IDE (syntax highlighting, intelisense, all the good stuff you need to edit C/C++ files). Similar extensions do exist for other languages such as Python, Fortran, etc.
  • CMake, CMake Integration and CMake Tools: One you adopt CMake for your projects to automatically build them from the ground up, these tools will supercharge your build environment and add additional functionalities to your editor to speed up the buidl process.
  • Codeium: One of the best extensions out there, and, completely free (yes, completely free!). Think ChatGPT but integrated into your IDE, it comes with a chat box like ChatGPT to ask questions, but it also analyses your code as you type and it will provide auto-completion as you type, and it is pretty much spot on. It’s like intellisense on steroids and has not let me down so far, a pretty neat tool to enhance your writing speed.
  • Test Explorer: If you are using software testing in your project, the test explorer extension will discover tests automatically in your project, add them to the list, and allow you to run them conveniently from within your IDE. If you have gone through my software testing series, install the Test Explorer extension, and you will no longer have to compile your tests manually. Run them from within the interface and get visual clues for which tests are passing and failing (and why). I love this extension, probably just as much as Codeium.
  • VS Sequential Number: Such a small yet effective extension. Suppose you have multiple lines selected in your document. In that case, it allows you to insert numbers at those selected lines and increment (or decrement) each number by 1 (or a specified value). Pretty useful for unrolling lists or quickly adding print statements to your code.
  • Todo+: A glorified to-do list with nice syntax highlighting and annotation capabilities. It’s best to see this in action, search for it on the extension marketplace within VS Code and look at the demo to get an overview, but suffice to say that it can be a pretty useful thing to keep your to-dos within the same project and just crossing off items as you go along.

Cross-platform terminal/shell

For some time, I didn’t even think of the possibility of having a cross-platform terminal but I have just recently learned that this is indeed possible. Well, I sort of knew for some time, but I have never really invested time exploring this direction. I’d probably still use native terminals/shells on each platform, but it seems that these are converging and so if you know one, you can operate pretty much any terminal it feels.

Knowing how to get around a terminal/shell (or console if you are an old-school Windows fanboy) is a must and the first thing you’ll need to master. Thankfully, Windows has been ditching the console for some time now and replaced it with its new terminal called PowerShell. Interestingly enough, it actually works cross-platform, meaning if you know how to use it, you can use it on any platform as your default terminal. It pretty much follows the same UNIX commands, so you can switch from any Linux or macOS terminal to PowerShell.

One nice feature I like about PowerShell is its auto prediction of commands. Once you start to type something, it’ll guess what you want to write and if it is correct, a simple tap on the right-arrow key will auto complete the command for you. It works pretty well and most of the time is spot on.

Having said all that, it doesn’t mean that I would recommend installing PowerShell as your only shell and then forgetting about all the native terminals entirely on either Linux or macOS platforms. The reason is simple: I haven’t tested it enough to give my approval, though I can’t see why it should not work out of the box as your default development terminal.

Since both Linux and macOS use very similar shells/terminals, it is easy to learn one and then switch to the other. Depending on which flavour of UNIX you are using, chances are you are using Bash as your shell. MacOS uses Zsh as the default shell, though you can switch from Zsh to Bash quite easily should you feel this is necessary (though both shells are pretty similar). Having the same shell means you can develop on both Linux and macOS in the same way, but should you distribute your software, keep in mind that not everyone will have the same shell as you.

And, if you are on Windows, fear not; you can get that native bash shell feeling as well through the Windows Subsystem for Linux (or WSL). Honestly, this is one of the best things Microsoft has ever integrated into Windows (and a bold move), and it has opened so many possibilities on Windows that were just not possible before (running all of these academic CFD codes that only compile on Linux, I am looking at you, OpenFOAM (which started as an academic code)).

I have made it a habit now to have both PowerShell and WSL installed on Windows, and these give me the right tools to develop code. Both PowerShell and WSL will need some specific settings (which we will look at below), after which you can develop away, and it doesn’t matter if you are running Windows or Linux. I test less on macOS (primarily because I don’t own a Mac), but virtual machines/paid remote desktop apps can provide some relief here to sanity-check that my developed code compiles fine on macOS as well.

Setting up a Development environment for specific operating systems

In this section, I want to go through specific steps I take to set up an empty and freshly installed installation of either a Linux flavour, Windows, or macOS, and show how we can set up a programming environment to write CFD solvers that compile across different platforms. We’ll start off with Linux, as there are elements that we’ll reuse for both Windows (WSL) and macOS, so read this first and then additionally Windows or macOS if that is what you require.

Linux

The first thing we need to ask ourselves is which flavour of Linux we want. There are quite a few to choose from, and similar to my compulsion to test different code editors, I had the same experience with different Linux distributions. I have tested probably somewhere between 5-10 different operating systems, but I always get back to Ubuntu. This is where I feel most at home. It is the most used platform, so if you have a question, chances are someone had exactly the same issue before you, and you will easily find a solution to your problem.

For the remainder of this section, I am assuming you are using Ubuntu. If you use a different distribution, commands will be slightly different.

The first thing you want to do is open up a new terminal and install some default tools. I would always install the latest updates first, and this is sometimes also required to avoid some errors with the apt package manager, which may otherwise not find packages. Then, I would install default development tools which will install the GNU compiler suite. Finally, I’ll add some additional packages I know I may need later for my own development or to run other solvers. These steps are shown below:

sudo apt update # update ubuntu distribution and ensure correct working of apt package manager
sudo apt install -y build-essential # install default compilers and development tools
sudo apt install -y cmake # for all your (and other project's) software build needs
sudo apt install -y gfortran # in case I (or a library I download) need Fortran support
sudo apt install -y clang # give me that sweet cross-compiler juice
sudo apt install -y mpich # in case I need MPI support
sudo apt install -y ninja-build # not really required, but a much nicer build tool than make for cmake to use

sudo snap install --classic code # install vscode, in case you want to use it
sudo snap install --classic powershell # gives you the latest PowerShell release

That’s it. You only need to run these commands once after installing Ubuntu, and your system should now be set up in a sensible way. With that, you should be able to compile pretty much any software project.

If you want to use git, you can configure that at this point as well (and, if it is not available for some reason, use the apt package manager to install it in a way similar to the commands shown above, i.e. sudo apt install -y git):

git config --global user.name "your-user-name"
git config --global user.email "your-email-address"

We can test this by creating a little test project. Some time ago, we looked at how to compile the CGNS library on our system, be it UNIX or Windows based. We will use that script in all environments to ensure that the development environment has been installed correctly. First, download the installCGNS.zip file, which you can find at the top of the article on how to integrate external CFD libraries into our code.

Next, open a terminal and create a temporary folder somewhere, I just create a folder called test in my user’s home directory. If you are new to the terminal, I can recommend the following series on YouTube: Part 1, Part 2, and Part 3. If you feel particularly fancy, there is a Part 4 on how to edit text files within the terminal, I would ignore that though for now if you are just getting started.

To create a new test folder in the home directory, use the following commands:

cd ~
mkdir test
cd test
code .

The last command will open vscode and you should see an interface similar to the following:

There are a few things to note here, highlighted by the red boxes and corresponding numbers:

  1. Install the extensions that I have mentioned above using the extension marketplace.
  2. You can sign in with a GitHub account and sync your profile across multiple devices. I don’t know how many times I have vscode installed across my devices but suffice to say that I do want the same development environment all the time, syncing my profile is extremely useful.
  3. If you have the integrated terminal opened, you can add different types of shells by clicking the + symbol (to change the type of the shell, click the ˅ symbol next to it). I currently have a native (Linux) bash shell and PowerShell opened.

In this case, we are going to run the installCGNS.sh script, which you should be able to run as is, without modifications (but see comments below on notes on how to execute scripts that you have downloaded from this website). To execute the script, run the following command:

./installCGNS.sh

If your development environment was set up correctly, then you should see the following test printed towards the end of the console output

Test CGNS installation

CGNS library version detected in C++ test code: 4.4
If you see a version printed above, the installation was successful.

Windows

Since Windows 10, we have a package manager called winget, which no one knows about. It’s odd, but from today, it is your best friend. Windows is converging towards a UNIX feel when it comes to developing code, so if you have worked on either Linux or macOS before and have used the terminal intensively, you will feel right at home.

On Windows 10, you may need to install it first. To do so, go to the Microsoft App Store, search for App Installer and install it. Of course, only the geniuses at Microsoft would come up with the idea of having different names for the software itself and the title under which it can be found in the App Store. Brilliant! On Windows 11, it should be installed by default, though, you know, we are talking about Microsoft, better check that it is actually installed …

Open up a PowerShell and then type

winget --version

This should display the version of winget (or app installer, whatever), and if it does, chances are you have it installed and working correctly. Now, you can use it to find and install software automatically. But before we do that, let’s update our PowerShell to the latest version. Windows comes with an outdated PowerShell, and the latest version (starting from version 7.x) has some nice additional features. Head over to the PowerShell Github release page and locate the latest version which has a Windows installer. It will have a file name of PowerShell-<version>-win-x64.msi.

Download the file, execute the installer, and once you are finished, open the new PowerShell. Make sure winget is still found by PowerShell by checking that you can display the current version, and if you can, let’s start to find some software. The commands you will need are

winget search <name>
winget install <name>

For example, let’s say we want to find the latest version of Visual Studio (which we will need to install all related C++ development tools), then we would type

winget search visualstudio

No spaces are allowed in the name. This will return a list that looks as the following (I am only showing the first two columns as these are the important ones):

Name                                     Id                                      
---------------------------------------------------------------------------------
Visual Studio Professional 2022 Preview  Microsoft.VisualStudio.2022.Professiona…
Visual Studio Enterprise 2022 Preview    Microsoft.VisualStudio.2022.Enterprise.…
Visual Studio Community 2022 Preview     Microsoft.VisualStudio.2022.Community.P…
IsWiX                                    IsWiX.IsWiX                             
Microsoft Visual Studio Code Insiders C… Microsoft.VisualStudioCode.Insiders.CLI 
Microsoft Visual Studio Code Insiders    Microsoft.VisualStudioCode.Insiders     
Microsoft Visual Studio Code CLI         Microsoft.VisualStudioCode.CLI          
Microsoft Visual Studio Code             Microsoft.VisualStudioCode              
Visual Studio Locator                    Microsoft.VisualStudio.Locator          
Visual Studio Configuration Finder       Microsoft.VisualStudio.ConfigFinder
Visual Studio Professional 2022          Microsoft.VisualStudio.2022.Professional
Visual Studio Enterprise 2022            Microsoft.VisualStudio.2022.Enterprise  
Visual Studio Community 2022             Microsoft.VisualStudio.2022.Community   
Visual Studio BuildTools 2022            Microsoft.VisualStudio.2022.BuildTools  
Visual Studio Professional 2019          Microsoft.VisualStudio.2019.Professional
Visual Studio Enterprise 2019            Microsoft.VisualStudio.2019.Enterprise
Visual Studio BuildTools 2019            Microsoft.VisualStudio.2019.BuildTools

If we want to install the latest free version (Community edition) of Visual Studio, then we need to locate the corresponding ID. In this case, it is Microsoft.VisualStudio.2022.Community. Copy this ID and then execute the install step on it with

winget install Microsoft.VisualStudio.2022.Community

This will install the Visual Studio installer. Locate this by searching for it in the taskbar and launching it. You should see an interface similar to the following:

After selecting modify, you should see the following Window:

Make sure that Desktop development with C++ is activated, and check that the Clang tools for Windows are selected as well for the installation. Download and install these packages (which may take some time). In the meantime, return back to your PowerShell and install a few additional packages:

winget install Python.Python.3.12
winget install git.git

Afterwards, close PowerShell and open it again (to apply all settings). If you have a GitHub account, now would be a good time to tell Git who you are:

git config --global user.name "your-user-name"
git config --global user.email "your-email-address"

The final step you want to do is to install WSL. This is rather straight forward, but can create error messages. If that is the case on your system, have a look at this troubleshooting guide. Otherwise, the command that you want to execute first is

wsl --list --online

This will give you a list of all available Linux distributions/flavours. I typically pick the latest version of Ubuntu, e.g., Ubuntu-24.04. Note down the name and then install it with

wsl --install -d Ubuntu-24.04

This may take some time, and you will be prompted to finish the setup within the console by providing your username and password. After that is done, you should be able to locate Ubuntu from the search bar. Open it and continue using the Linux instructions provided above.

At this point, we are not done yet. We need to tell PowerShell to load the development tools we just installed every time we open a new PowerShell instance. This will make the compiler and related development tools available. To do that, we must create a new profile, which will be automatically loaded every time we launch PowerShell. To do that, type

New-Item -Path $profile -Type File -Force

We need to open this file that we have just created, which we can do with the following command:

notepad $profile

This should provide us with an empty text file. Add the following two lines to this profile and save the file. You can close it afterwards.

Import-Module "$env:ProgramFiles\Microsoft Visual Studio\2022\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell -VsInstallPath "$env:ProgramFiles\Microsoft Visual Studio\2022\Community" -DevCmdArguments '-arch=x64 -no_logo'

Note: If you used winget to install Visual Studio, it will have placed it in the default installation path and you should be fine to copy and paste the text as is. If you have installed Visual Studio manually in a non-standard directory, amend the first and second lines accordingly. These two lines load and apply the development settings, which essentially just load paths to the compiler and other tools so that we can use them from the command line.

Additional note: When you install Visual Studio, you’ll also get two new shortcuts created, one named Development PowerShell for VS 2022 – x64 and another called x64 Native Tools Command Prompt for VS 2022. Ignore the Command Prompt (forever), and while I am pleased to see that Microsoft has finally opted to make the Development PowerShell by default 64-bit, it still uses the outdated PowerShell version 5, which comes by default with Windows. Following the steps above gives us the same development environment with the latest PowerShell.

At this point, we should have a sensible development environment set up and similar to the Linux instructions given above, we can create a dummy project to test our new setup. Create a new folder somewhere (either in your user’s home directory or Desktop for simplicity) and copy the installCGNS.ps1 file into the folder (that you can download from this article at the top).

cd C:\Users\<your-user-name>\Desktop
mkdir test
cd test
code .

I would always recommend opening a PowerShell console first, navigating to the folder in which you want to work, and then launching vscode from there. This will set the correct working directory, which will avoid compiler issues later. You can then proceed to execute the installation script by running

./installCGNS.ps1

And, again, similar to the Linux output, you should be seeing the following success message towards the bottom of the screen, indicating that all tools were installed correctly:

Test CGNS installation

CGNS library version detected in C++ test code: 4.4
If you see a version printed above, the installation was successful.

macOS

If you are on a Mac, there are two essential tools you need: Xcode and a package manager. We need Xcode as this will allow us to install some default command line tools that we need to develop software (which is essentially the same as the build-essential package on Linux that we looked at above). The package manager will ensure that we can install missing software easily.

To install Xcode, the simplest solution is to download and install the latest version directly from the App Store. If this doesn’t work for you or you need a different version of Xcode, then these instructions may help. Within Xcode, we also need to install the command line tools. How to install these will also depend on your Xcode version (which in turn depends on your macOS), and there is a good writeup on stackoverflow to show you how.

I find this volatility highly frustrating, but there you go. Who would have thought that setting up a development environment on Windows would be more enjoyable? I know, the die hard apple users are getting ready to slay me for this comment, so how about I offer this 3 minute distraction so we can all move on?

The second thing you’ll need is a package manager, and homebrew is pretty uncontested on macOS, though it works just as well on other UNIX distributions. Most of them, though, come with their own package manager, so homebrew seems to be used predominantly by Mac users.

Installing it is pretty straightforward; if you check out homebrew’s website, you’ll see that you need to copy and paste the following line into your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

However, depending on your Mac’s CPU, you may have to modify this command as detailed in this article.

With both Xcode and homebrew installed, you can proceed to install additional packages that you may need. As I can’t verify that the command line tools are consistently installing all pacakges you’ll need on your end, I am being conservative here and list all packages that you would need in my view, it may be that these are, though, already installed through Xcode’s command line tools. This is for completeness only.

brew install git
brew install python
brew install cmake
brew install mpich
brew install gcc
brew install ninja
brew install wget
brew install git
brew install --cask powershell
brew install --cask visual-studio-code

Afterwards, you should have a sensible development environment available (I have noticed that I am suggesting installing PowerShell on macOS, which probably will upset most Apple users, and I have also run out of distraction videos, ups …). But you know what? Why not embrace this and double down on it? I propose that all Apple users install a virtual machine and install Windows on it if they are serious about software development. There, I said it; I am waiting for your angry emails …

I digress; where was I? Right, the configuration of our development environment. Like on Linux and Windows, we can configure our git account at this point if we want to use it:

git config --global user.name "your-user-name"
git config --global user.email "your-email-address"

With that done, we should be able to run our CGNS installer script, as we have done for the other environments. Download the script, and run it in your shell. The best approach to running it would be to use the following command:

sh installCGNS.sh

The default shell on macOS is zsh, while it is bash on most other Linux platforms. You can figure out which one you are using by typing:

echo $0

This may not work for more exotic shells like fish. In any case, running bash scripts (like the installCGNS.sh script) works in zsh as well, most of the time. There are small differences in the syntax, but I am using fairly non-controversial bash scripting in this file, so it should run in both. If it doesn’t, it may be that some dependencies or software are missing, in which case the output should give you a good indication of what to install with homebrew. If everything worked out fine, you should see the following output again on the console after the script ran successfully:

Test CGNS installation

CGNS library version detected in C++ test code: 4.4
If you see a version printed above, the installation was successful.

Notes on how to run scripts downloaded from cfd.university

In the past section, we looked at how to setup a sensible development environment and we used scripts that I have provided on this website to test our development environment. If you are able to install all packages within the installation script, your development environment should be set up correctly and working for CFD solver development and testing.

However, whenever you run scripts on your machine that you have downloaded from this website, you may need to go through additional steps to make these scripts executable. Below are additional steps may need to take to achieve this, organised by operating systems.

Windows

By default, Windows will block you from executing PowerShell scripts you downloaded from the internet, preventing malicious code from running on your PC. This seems like a decent option, and I looked into making my scripts trusted. It turns out that if you are willing to fork over a non-insignificant amount of money to Microsoft (on a yearly basis), anyone can become a trusted entity, and your scripts will run without the additional steps below. So even if a scammer can become trusted, what is the point again?

Anyhow, you will first need to allow for scripts to be executed if you downloaded them from the internet. This is done by setting the execution policy on your PC. You can print the current execution policy by opening a PowerShell and typing:

Get-ExecutionPolicy

Your execution policy needs to be set to RemoteSigned before you can execute any scripts. To change this, right-click on your PowerShell and select Run as Administrator. Then, type the following into the terminal:

Set-ExecutionPolicy RemoteSigned

You only have to do this once; your execution policy will not reset to its default. If you don’t have administrator rights on your PC that you are working on, you can change it only for the current user using the following command:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

But this is not all; Windows has a second security feature to block scripts from executing, even if the execution policy is set correctly to RemoteSigned. To unblock your scripts, right-click on the file and select properties. At the bottom of the Windows properties, you may see a checkbox that allows you to unblock the script. Select the checkbox and select OK to close the properties panel. You should now be able to run PowerShell scripts. This is shown in the figure below as well:

UNIX (macOS & Linux)

Running bash scripts is considerably simpler on UNIX. It may run fine without any intervention, but if you find that it does not run, then you will have to set the file permission, similar to the execution policy on Windows. Open a terminal (no need for sudo rights) and navigate to the folder where you have the bash script located. Then, execute the following command:

chmod +x <bash-file-name>

Change <bash-file-name> to the script that you want to execute, e.g. in the examples above, installCGNS.sh. The +x option sets the execution policy such that the script you provide will be executable and you can run it now with the usual command, i.e.

sh <bash-file-name>

Summary

In this article, we have developed a sensible default development environment that should let you write and compile code on your machine. You should also have all the tools in place now to compile pretty much any other software you want from source. We have looked at development environments on Windows, Linux, and macOS; thankfully, these converge towards a similar development workflow.

We have package managers on each platform with winget on Windows, apt on Linux (other flavours may have other package managers), and homebrew on macOS. Windows and macOS require you to install their integrated development environment (IDEs) to install default development tools such as compilers and build tools, while we can get a similar set of tools on Linux with the build-essential package.

Using any of these package managers, we are able to install any other missing software and this can help us to quickly get to a development environment that is suitable for us and CFD development in general.

Sure, along the way I have alienated most if not all Apple users and probably non of them have made it to this summary section. And for the few that have made it here, remember, the best thing about a Mac is that you can install a virtual machine and run WIndows in it (and now all Apple users have left). But so have I, bye!


Tom-Robin Teschner is a senior lecturer in computational fluid dynamics and course director for the MSc in computational fluid dynamics and the MSc in aerospace computational engineering at Cranfield University.