CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums

CFD Blog (1): OpenFOAM small bits: How to compile new solver

Register Blogs Community New Posts Updated Threads Search

Rate this Entry

CFD Blog (1): OpenFOAM small bits: How to compile new solver

Posted December 27, 2021 at 11:42 by Ash Kot

Hello Engineers and Scientists,

Preamble:
(If this is your first time then you may like read it, or you can skip it if it’s not your first time)

Being involved in CFD engineering and development/programming, I decided to dedicate some of the learning to community by writing through blog towards new budding CFD developers and engineers. So that new people don’t have to start from scratch. In this blog series, I shall try to create link to connect my files over GitHub, and explanation in this blog. I have work on many CFD, numerical modeling software packages. However, I’m indented to discuss very few software packages which are linked to the various stories which I experienced throughout academia or industry. These software packages are OpenFOAM, ANSYS FLUENT, ANSYS CFX, Star CCM+, COMSOL and MATLAB. The topics discuss in this blog is at random, and independent of difficulty level. Many of you may consider this first blog entry as ‘‘easy-peasy child’s play’’, or may stumble upon it as ‘‘I’m not able to understand at all, what is this gobbledygook’’
In my CFD academia and industrial career, what I have learned is that, the humans can solve PDEs in various different ways, such as reducing to ODEs and then applying boundary conditions to the ODEs so on and so forth, that is essentially ‘think and solve’ mechanism through human brain. This computers can’t do they can only do ‘solve’ mechanism which humans told them to do. Thus, computers solvers solve numerical modeling equations in particular fashion, which humans can also do that but can’t go beyond probably 100 × 100 matrices, I guess.
Although, over the period of time, as the Machine Learning/Artificial Intelligence is growing and everyone want to supersede the previously developed algorithms, soon one day a computer should be able to think and solve PDEs just like humans and should be able to solve Navier-Stokes equations with no approximations involved, by method of direct numerical simulation. After that I don’t know what humans shall do, indulge in artistic activities or leave planet, I guess.

CFD Blog (1): OpenFOAM small bits: How to compile new solver using 'wmake' utility.

The procedure describe here is generalized procedure regardless of what solver a person trying to build using 'wmake' utility. Thus, this blog entry does not give you representation of creating new solver out of previously existing solver library, however this blog post shall let you know ‘what need to do’ and ‘what not to do’ while building solver using 'wmake' utility.

1. A) If you planning to create solver based upon previously existing solvers then first send command 'echo $FOAM_SOLVERS' then check the path in ubuntu system where the solvers are installed. After that, give command 'cd $FOAM_SOLVERS' and enter the directory and copy whichever original solver you planning to use as base for your solver, copy that solver to '$FOAM_RUN' directory by giving command in terminal as, ‘cp -r /name_of_solver/ \$FOAM_RUN/solvers/new_named_Solver’ (replace name of solver with the solver you want to use).
B) If the new solver is planned to make from scratch, then just enter in $FOAM_RUN directory by command ‘cd $FOAM_RUN’ and start typing your code.

2. Now, that solver is created with modified conditions, or novel solver is created from scratch. We shall check the solver build parameters are correctly defined or not. For that, first enter Make directory of that newly modified solver. Inside the directory you shall see two files, one file titled ‘files’ (This file essentially keeps track of executable path and its functionality) and another file you shall see titled ‘options’ (This file essentially keep checks of what libraries and other executable utilities need to use while performing complete error free build process). Open file which is named ‘files’ in your favorite text editor (I usually use sublime text 3), and change wherever in that file mentioned, ‘solver_name.C’ (here solver name can be anything such as ‘icoFoam.C’ or ‘interFoam.C’) to ‘new_solver_name.C’ (Example: ‘new_icoFoam.C’, or ‘new_interFoam.C’) and then change $(FOAM_APPBIN) to $(FOAM_USER_APPBIN) in that same file. Also make sure the file mentioning ‘new_interFoam.C’ that should also be the same file name in that directory, in other words the solver file name which contains the solver code should also be ‘new_interFoam.C’.

3. Now make sure that the solver is clean, that means it does not contain previously build files. Thus, run command over top directory of solver called ‘wclean’ no need to use sudo, in fact sudo does not recognizes this command.

4. Now, in older OpenFOAM solver compilation sometimes it is mentioned that copy wmake folder from openfoam directory and paste it in solver directory. You can do that as well, but disadvantage is that you won’t be able to call newly created solver from anywhere in the system. For example, if command ‘which new_icoFoam’ is given in any terminal window, then Ubuntu OS will not be able to provide path in response, or if you type ‘new_’ in terminal and press tab, then terminal will not able to provide any available commands in response. However, the advantage of copying wmake to solver directory and then building solver is that, you create this solver as portable. Now in this case, if your co-worker want to run the case that you have created then you need to provide only that built executable file and case study along with it in zip folder and co-worker should be able to run the case file by giving solver command.
If you have created solver as portable then make sure the executable built is in top directory of case file as well after that you’ll have to give command as ‘./your_solver_name’ (that is, ‘./new_interFoam’ or ‘./new_icoFoam’).

5. If the solver directory does not contain wmake folder copied from the main ‘opt/openfoam-x/’ directory, then it’ll directly use the default wmake folder and its utilities for compilation. In this case, now you have solver that can be called from any terminal window in Ubuntu OS. As well as now case directory does not need to have solver executable built file, and if you are in case directory then all you have to do is type ‘new_solver_name’ (that is, ‘new_interFoam’ or ‘new_icoFoam’), and that’s it, it’ll start calculations.

Thus, this blog entry ends by giving small titbits to beginners as well as experienced users as well. Good bye and see you next time.
Posted in Uncategorized
Views 703 Comments 0 Edit Tags Email Blog Entry
« Prev     Main     Next »
Total Comments 0

Comments

 

All times are GMT -4. The time now is 12:30.