CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Creating a new case from command line (https://www.cfd-online.com/Forums/openfoam-pre-processing/62022-creating-new-case-command-line.html)

gregh April 17, 2007 05:15

Hi, is there a command (I d
 
Hi,

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, ...) ?

Thanks

Greg

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/*

Bye
Mavimo

farbfilm October 8, 2008 05:13

Hi, is there another way to
 
Hi,

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???

Thanks

braennstroem October 8, 2008 14:24

Hi, I have a template direc
 
Hi,

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

(defun opf_standard_0()
(interactive)
(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")
...
...
(revert-buffer)
(remember)
)

A simple menu can look like:

(easy-menu-define cfd-pre-menu dired-mode-map
"'org-mode' menu"
'("CFD-Pre"
["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.chdir(os.path.dirname(sys.argv[1]))
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.

Fabian

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
 
Hi,

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.

Håkan.

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 http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif 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
 
Hi,

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.

Thanks!
Håkan.

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.

Gavin

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:

http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif PipeWandrb.py

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


Fabian

wikstrom October 9, 2008 07:49

Hi, for non huge cases I fi
 
Hi,

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

http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif 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...

/Niklas

wikstrom October 9, 2008 07:59

Now with -compressible availab
 
Now with -compressible available...
http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif createFieldTemplates.tgz
/Niklas

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...

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

boundaryField
{
examplePatch
{
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.

Håkan.

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.

/niklas

gschaider October 9, 2008 15:13

Hi! Sorry for advertising (
 
Hi!

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

-----
pyFoamCreateBoundaryPatches.py [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

pyFoamCreateBoundaryPatches.py --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

Bernhard

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.

Håkan.

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

Bernhard

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

pyFoamCreateBoundaryPatches.py --verbose --clear-unused 0/U
pyFoamCreateBoundaryPatches.py --verbose --overwrite --filter="wall.+" --default="{'type':'fixedValue','value':'uniform (0 0 0)'}" 0/U
pyFoamCreateBoundaryPatches.py --verbose --overwrite --filter="velocity-inlet-5" --default="{'type':'fixedValue','value':'uniform (1 0 0)'}" 0/U
pyFoamCreateBoundaryPatches.py --verbose --overwrite --filter="velocity-inlet-6" --default="{'type':'fixedValue','value':'uniform (0 3 0)'}" 0/U
pyFoamCreateBoundaryPatches.py --verbose --clear-unused 0/p
pyFoamCreateBoundaryPatches.py --verbose --overwrite --clear-unused --filter="pressure.+" --default="{'type':'fixedValue','value':'uniform 0'}" 0/p
pyFoamCreateBoundaryPatches.py --verbose --clear-unused 0/k
pyFoamCreateBoundaryPatches.py --verbose --overwrite --filter="velocity-inlet.+" --default="{'type':'turbulentIntensityKineticEnergyI nlet','intensity':'0.1', 'value':'uniform 0.375'}" 0/k
pyFoamCreateBoundaryPatches.py --verbose --clear-unused 0/epsilon
pyFoamCreateBoundaryPatches.py --verbose --overwrite --filter="velocity-inlet.+" --default="{'type':'turbulentMixingLengthDissipation RateInlet','mixingLength': '0.05', 'value':'uniform 14.855'}" 0/epsilon

pyFoamWriteDictionary.py system/controlDict endTime 300

rm 0/nuTilda
rm 0/R
simpleFoam

Håkan.

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 ....

Bernhard

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.

/N

olesen October 21, 2008 04:19

Off-hand I know there's an oka
 
Off-hand I know there's an okay example of mis-using an IOMap<dictionary> to write the headers and supply a stream for a Map<dictionary> in src/conversion/meshTables/cellTable.?
Specifically, Foam::cellTable::readDict() and Foam::cellTable::writeDict() might be of some use to you as reference.

BTW: in your original program, you were using include "createMesh.H", but you should be able to just read in the polyMesh/boundary directly (and save lots of time and memory).
Take a look at src/OpenFOAM/meshes/preservePatchTypes/preservePatchTypes.C

wikstrom October 21, 2008 06:45

Many thanks! I'll have a lo
 
Many thanks!

I'll have a look at it.

/Niklas

wikstrom November 16, 2008 11:16

Hi again, I never had time
 
Hi again,

I never had time to dive into the dictionary creation and writing inside OF. So, in the mean time I reverted to a simplistic solution and use the following python script to create the changeDictionaryDict:

http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif createChangeDictionaryDict.py

May be useful.

( run with --help :-) )

/N

wikstrom November 16, 2008 11:54

To explain the previous post:
 
To explain the previous post:

Using createFieldTemplates (above in this thread) and the python script above,
the procedure I use to initiate fields for a case, after having built the mesh becomes e.g.:

1) createFieldTemplates -scalarFields "(p)" -vectorFields "(U)" -time 3
2) createChangeDictionaryDict.py --fields="U p" --instant=3 -o system/changeDictionaryDict
3) Edit system/changeDictionaryDict
4) changeDictionary -time 3

/N

wikstrom October 29, 2009 06:40

createFieldTemplates revisited
 
1 Attachment(s)
Uploading a createFieldTemplates that writes a changeDictionaryDict on the fly. Whether you want it or not... Use the -dict option. See description in source header.

/N

Siemen November 14, 2013 07:38

Hi Hakan,

For my centrifugal pump simulations I inject the final solution from a steady-state simulation as initial solution for a transient simulation (using pyFoamCopyLastToFirst.py).
The steady-state simulation computes the flow in a non-rotating impeller inside a volute.
The transient simulation is about an impeller, which is rotating in a volute.
In order to give the rotating impeller the correct boundary conditions, I have to change the type of boundary condition from "fixedValue" to "movingWallVelocity" in the [case/0/U]-file for the transient simulation.

Therefore, I am trying to apply the function <pyFoamCreateBoundaryPatches.py>.
However, it seems that both the type and value of the boundary condition are changed using this function, and I only want to change the type.
Do you know whether it is possible to only change the type and remain the value of the boundary condition unchanged?

Thanks in advance!
Siemen


All times are GMT -4. The time now is 13:46.