CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   How do I install a custom solver? (

NJG January 25, 2013 15:29

How do I install a custom solver?
First off let me say I am quite new to Ubuntu, C++, and OpenFOAM, nor am I all that adept at programming. My background is more in experimental fluid mechanics. But we all have to start somewhere, right?

Ok, so my goal here is to "install" (or "add" or any other verb that would be appropriate) a custom solver to OpenFOAM 2.1.1. I am working on a CFD project that is a follow up of some previous work that was done with this custom solver. I have successfully installed OpenFOAM on my system and run several tutorials, so she is running correctly I think. Now I have this custom solver and related folders and files that need to be added to my install in a way that I can run it. So, basically I need to know where these files need to go and how I should build/compile/whatever them.

Here is a rough inventory of what I have:

-lots of .H files for various variables, readTransportProperties, and
-a files and an options file

-an Allwmake file
-a .C, .H, and .dep fvPathc files related to
-apparently the same .C and .H file in the line above
-a files and an options file
-an Allwmake file
-an Allwmake file
-a bunch of folders including a couple kOmegas, a Make,
another lnInclude, and a derviedFvPatchFields, all
ultimately including solver specific (I think) C., H., and .dep

That's it. I can offer more detail as needed.

First off, I know I need to add these to my file tree somehow. But, I am unclear on whether I should add these into my $WM_PROJECT_USER_DIR (which I understand to be the "OpenFOAM/user-2.1.1/..." location from which the tutorials are run) or if they need to be added to $WM_PROJECT_DIR (which I understand to be the "FileSystem/opt/openfoam211/..." location that seems to contain all the OpenFOAM nuts and bolts), or both. And if I add them to the opt/openfoam211 side of things I am not sure if they are added in addition or in replacement off existing files.

Next, I will ultimately need to run/build/compile some of these so she is ready to go. I have a sense that this comes from the Allwmake files, but I am not sure how. And as for building the solver, I am not sure how to do that (wmake within the solver directory?), so some advice there would be nice as well.

Thanks so much for your help. I apologize for the basic nature of this request and am grateful for your responses. Also, if this question is in the wrong place in these forums, my apologies.


NJG January 25, 2013 15:31

Reading my post I see the indentation I used to make clear the folder structure of what I have was lost, so it is not so clear what is in what folder. My apologies, I can clear this up is needs be.

NJG January 25, 2013 15:50

Let me also add that I am presently reading the User Guide section 3.2, which should shed a lot of light on this I hope, and so if you respond you can assume I have at least familiarized myself with that.


NJG January 26, 2013 07:49

Ok, I have I think mostly figured this out. I can as wished put all my new stuff in $WM_PROJECT_USER_DIR as wished (and as I did). Most of problems have come from the fact the solver was written in a previous version of OpenFOAM, and then I need to go through and edit accordingly.

Any insight anyone has would still be appreciated.


JimKnopf January 30, 2013 07:12

Hi There,

I'm not sure you got a solution allready.

First: You can put your code where ever you want, if you have the openFoam Variables in your shell

You have to compile the code with wmake. Make sure that in the Make/files file


If your solver is for a older foam version, you may need to adjust the includes in options.


chegdan January 30, 2013 20:03

a method to the madness
To add to this discussion, I would approach this in a slightly different manner in the version of a long post

1. Compile OpenFOAM yourself If you are using ubuntu, I would remove the existing OpenFOAM install that you did with sudo apt-get install and compile 2.1.x from scratch. It is actually very straightforward and will be good practice to get to know Ubuntu and OpenFOAM. Some good instructions are located here. Though the package install of Ubuntu is handy, i think compiling from scratch is a much better idea.

2. Practice compiling a simple solver There are other things that may be difficult for a novice programmer when compiling a custom solver (like debugging). But a good intermediate step is to compile an existing solver with a different name or add more to an existing solver. A basic example is located here. At this point you might want to get a cup of coffee and start reading the users guide and programmers guide. This will save you lots of time by reading them and also avoid posting something that is already answered in the manuals.

3. Program and Compile your custom solver By now, you will have some experience as to what you need to do to compile a custom solver. If there are mistakes in your coding, you will need to debug it and recompile after you correct errors. Take each error message and correct them one by one, thinking about what could be causing the error. Use the source code documentation here to help with the coding and figuring out how classes are assembled in OpenFOAM and what you can access in your solver. You will receive errors and if you don't know what the error message is, then search the forum or use google. If you are stuck, then provide lots of detail and/or code. As a tip, better formatting will get some attention from users, as it shows you took time to communicate your question. Some examples and help are located here. Be patient on your posts and don't bump them as people might be less likely to answer a question that is replied to by the author 23 times in a 2 day period (you're doing well so far :) ). Use the edit functionality to correct your posts if you have made a mistake (i will probably need to do that for this post). Refer to to get some help to how to post.

4. Set up a test case Even if a solver compiles, it may still give errors at runtime e.g. floating point errors due to divide by zero. Setting up a test case with an adequate mesh, correct boundary conditions, and some knowledge of expected outcome e.g. the temperature on the left side will be higher than here because of ... is helpful. Change your discretization schemes in a logical and methodical way e.g. use steadyState for a times discretization scheme if its a steady state solver or use upwind for your divergence schemes as a first approximation.

5. Validate your solver Come up with a simple example that may have an analytic solution or experimental results. Play with the disretization schemes (in a logical and methodical manner) and use reasonable values for physiochemical values (i.e. viscosity, diffusivity, etc.), initial conditions, and boundary values. Always try to tune your case to get closer to the analytic solutions. If it is still very far off from your validation data, go back and reassess your model and possibly change your solver.

6. Celebrate and then plan a strategy and execute said strategy If you have validated your solver and everything works great then you take a break, relax for a bit, and continue your work at a later time. Writing the solvers and then running them are two different things so take a break and gather your wits to come up with an efficient strategy for running cases (e.g. what dimensionless numbers are present in my system and how can i design a set of runs to test a meaningful range of values?). Once you have a strategy, you can automate the running of cases with bash scripts like the allrun scripts located in many tutorials; if you like python you can use pyFoam to run and analyze your results; and/or use swak4Foam to create realistic initial conditions, boundary conditions, or probe your domain.

You may already know some of this, but its good to have them written down here in case others stumble upon the same question. Good luck and post back if you need help.

p.s. sorry for the long post.

All times are GMT -4. The time now is 01:26.