CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Pre-Processing (
-   -   Creating a new case from command line (

gregh April 17, 2007 05:15

Hi, is there a command (I d

is there a command (I don't want to use the FoamX interface) to create automatically the directory tree and files needed for a new clean case (no mesh, I will convert it from a 3rd party soft, no solution, ...) ?



mavimo May 19, 2007 14:46

You can duplicate the original
You can duplicate the original case with:
cp -r /original/case /new/case
and after delete the mesh with
rm /new/case/constant/polyMesh/*


farbfilm October 8, 2008 05:13

Hi, is there another way to

is there another way to create a new case from command line without copying an old case or tutorial cases???

I'm using OpenFoam1.5 and want to create a new case with a command that creates automatically the directory tree! Is that possible???


braennstroem October 8, 2008 14:24

Hi, I have a template direc

I have a template directory and use emacs/dired to create a new case with:

(defun opf_standard_0()
(dired-create-directory "0")
(dired "0")
(copy-file "/home/gcae504/SCR1/Software/Vorlagen/0/k" "k")
(copy-file "/home/gcae504/SCR1/Software/Vorlagen/0/omega" "omega")
(copy-file "/home/gcae504/SCR1/Software/Vorlagen/0/epsilon" "epsilon")
(copy-file "/home/gcae504/SCR1/Software/Vorlagen/0/R" "R")
(copy-file "/home/gcae504/SCR1/Software/Vorlagen/0/p" "p")
(copy-file "/home/gcae504/SCR1/Software/Vorlagen/0/U" "U")
(copy-file "/home/gcae504/SCR1/Software/Vorlagen/0/nuTilda" "nuTilda")

A simple menu can look like:

(easy-menu-define cfd-pre-menu dired-mode-map
"'org-mode' menu"
["FLUENT Journals isotherm/stationaer" fluent_standard_journals_stationaer t]
["OpenFOAM New Case" opf_standard_simpleFoam t]
["OpenFOAM Decompose " dummy t]
["OpenFOAM Standard Randbedingungen Erstellen " opf_boundaries t]

Or use some other scripts like python:
import os
import sys
os.system("cp -a /home/gcae504/SCR1/Software/Vorlagen/OpenFOAM_Standard . ")

Obviously you need some more templates, if you are using a lot of different solvers.


olesen October 9, 2008 02:35

If you want the same as Fabian
If you want the same as Fabian, but without emacs, see if "foamCopySettings -help" does what you want.

hani October 9, 2008 03:15

Hi, foamCopySettings does a

foamCopySettings does a part of the job. Another part of the job is (when the mesh has been created) to modify the boundary conditions in the 0 directory according to a given 'boundary' file in constant/polyMesh. This was previously done by FoamX, and this was in my opinion the only thing that was useful with FoamX. Is there any script or application that does this in 1.5? I haven't found any yet.


olesen October 9, 2008 03:43

I never tried FoamX to discove
I never tried FoamX to discover anything useful in it, but adjusting the boundary conditions to match the polyMesh/boundary was always *really* annoying.

With the new dictionary expansion mechanism, however, it becomes much easier. In this case I would prefer to stick to my favourite editor. Here's a small example example-0.tar.gz

Switching one of the inlets on and all the others off is just a matter of setting a link to the appropriate boundaryField-* file. These files are easily generated with a script.

hani October 9, 2008 04:33

Hi, This actually looks qui

This actually looks quite useful. Thanks!

Actually, FoamX used the physicalType in the boundary file to generate the time directories automatically. It used configuration files supplied in each solver/FoamX directory so that the boundary conditions were set according to that specific solver (Those FoamX directories are removed in 1.5.x). The solver was chosen in the controlDict. I found this quite useful, although I seldom used it. There is a need for a similar application that does the same thing, but without FoamX. I want to be clear that I do not want FoamX back!

I will try out your new approach.


grtabor October 9, 2008 06:04

Seconded! I hated FoamX, but a
Seconded! I hated FoamX, but a convenient automated case generation mechanism would be useful, even if the actual editing has to be done by hand.


braennstroem October 9, 2008 07:23

PyFoam is another approach. Di
PyFoam is another approach. Different python scripts could do the job in the old fashion:

Though, one has to be consistent with the naming...


wikstrom October 9, 2008 07:49

Hi, for non huge cases I fi

for non huge cases I find this utility helpful creating new fields: createFieldTemplates.tgz

It simply creates a mesh, reads which fields to write from command line, creates them with a default BC and writes them to disk.

What about the "new dictionary expansion"? I fail to understand...


wikstrom October 9, 2008 07:59

Now with -compressible availab
Now with -compressible available... createFieldTemplates.tgz

hani October 9, 2008 09:09

Splendid Niklas! A small tu
Splendid Niklas!

A small tutorial:
The syntax seems to be:
createFieldTemplates -scalarFields "(p k epsilon)" -vectorFields "(U)"

What is missing is some option to use physicalType from the boundary file, or to list all the possible boundary conditions for each patch and variable. I guess that there is some list of possible boundary conditions that can be reached, and printed out...

If a variable can use boundary conditions zeroGradient, and fixedValue only, then it would be nice if this code would automatically output something like:

type zeroGradient;
// {
// type fixedValue;
// value 0;
// }

Then it would be easy to un-comment the appropriate lines that are wanted instead of the default one.


wikstrom October 9, 2008 09:57

Oh, sorry for not including an
Oh, sorry for not including an example command line; thanks Håkan.

It would be nice to have such functionality, although perhaps not through "physicalType" since this key seems on it's way out? (and was a tad confusing anyway, imho.)

However, to create templates for all or some possible BC's increases the complexity of the '5 minute code' I uploaded quite much and I have not the time for that at the moment. When I have something, I'll share it.


gschaider October 9, 2008 15:13

Hi! Sorry for advertising (

Sorry for advertising (I won't quote the full help here):

----- [options] <fieldfile>

Takes a field-file. Looks up the polyMesh/boundary-file of the case and adds
the corresponding patches to the boundary field setting it to zeroGradient for
all patches and walls

The online-help doesn't say that of course patches like symmetryPlane are set to that type in the field file. Together with the --filter and the --default option a lot can be done if there is a consistent naming for the boundaries. Like --filter="heated.+" --default="{'type':'fixedValue','value':'uniform 800'}" myCase/0/T

to set all patches that start with "heated" to a fixed temperature of 800


hani October 10, 2008 03:12

Bernhard, I think that you sho
Bernhard, I think that you should really advertise pyFoam more. I suggest that you propose a talk on pyFoam at the fourth workshop. Then there is also a need for a talk on the other developments you have made. It is an impressive amount of work!

I must admit - I did't have the time to use pyFoam yet, but I just opened your Wiki and started to have a look at it.


gschaider October 10, 2008 05:09

Hi Hakan! Thanks for your k
Hi Hakan!

Thanks for your kind words.

BTW: Fabian. I liked your script as an example for the usage of PyFoam. May I just add one remark. The Functionality of the pyFoam-Utilities is implemented as classes in the PyFoam.Applications-hierarchy that simply get a list with the command line arguments. This means that instead of the os.system("pyFoamCreateBoundary ....") you could use CreateBoundaryPatches(args=["--overwrite",case0k]). Also the os.system("cp ...")s might be replaced with a CloneCase-call


hani October 10, 2008 08:27

Hi Bernhard, I have been pl
Hi Bernhard,

I have been playing for a while :-)

I guess that you might have a hint on how to reduce the number of commands for the example I show below. In the example I want to run the icoFoam/elbow case with simpleFoam. Is there a way to reduce the number of PyFoam commands?

cp -r $FOAM_TUTORIALS/simpleFoam/pitzDaily $FOAM_RUN/simpleElbow
cp -r $FOAM_TUTORIALS/icoFoam/elbow/elbow.msh $FOAM_RUN/simpleElbow
cd $FOAM_RUN/simpleElbow
fluentMeshToFoam elbow.msh --verbose --clear-unused 0/U --verbose --overwrite --filter="wall.+" --default="{'type':'fixedValue','value':'uniform (0 0 0)'}" 0/U --verbose --overwrite --filter="velocity-inlet-5" --default="{'type':'fixedValue','value':'uniform (1 0 0)'}" 0/U --verbose --overwrite --filter="velocity-inlet-6" --default="{'type':'fixedValue','value':'uniform (0 3 0)'}" 0/U --verbose --clear-unused 0/p --verbose --overwrite --clear-unused --filter="pressure.+" --default="{'type':'fixedValue','value':'uniform 0'}" 0/p --verbose --clear-unused 0/k --verbose --overwrite --filter="velocity-inlet.+" --default="{'type':'turbulentIntensityKineticEnergyI nlet','intensity':'0.1', 'value':'uniform 0.375'}" 0/k --verbose --clear-unused 0/epsilon --verbose --overwrite --filter="velocity-inlet.+" --default="{'type':'turbulentMixingLengthDissipation RateInlet','mixingLength': '0.05', 'value':'uniform 14.855'}" 0/epsilon system/controlDict endTime 300

rm 0/nuTilda
rm 0/R


gschaider October 17, 2008 07:04

Hi Hakan! I'm afraid it doe
Hi Hakan!

I'm afraid it doesn't work much simpler than that. The only thing I spotted is that for subsequent calls for a field the --clear-unused option can be omitted (but it doesn't hurt either)

Just as a preview: inspired by this thread I'm working on a util that generates a case using a description file. But I'll need two or three more train-rides to complete it ....


wikstrom October 21, 2008 02:49

With all possible respect to
With all possible respect to Python and pyFoam - I love python- I still want to expand the functionality of the createFieldTemplates app above.

I am trying to write a changeDictionaryDict from field and boundaryMesh information. However, I'm lost among dictionaries and entries. Anyone with an example code creating and writing a dictinoary? I allmost got there using IOdictionary, but IOdictionary::writeData does not produce andy line breaks.

The idea is that if all fields are created with default patches along with a corresponding changeDictionaryDict, it's only a matter of editing the dict and run changeDictionary. I'd like that.


All times are GMT -4. The time now is 17:56.