Skip to content

Instantly share code, notes, and snippets.

@robinknowles
Created February 4, 2022 09:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinknowles/e8171f17eb7d147eb092f1e9731a4f0b to your computer and use it in GitHub Desktop.
Save robinknowles/e8171f17eb7d147eb092f1e9731a4f0b to your computer and use it in GitHub Desktop.
A cheat sheet of foamDictionary commands for making quick command-line edits to OpenFOAM dictionaries

foamDictionary Cheat Sheet

Accompanies OnCFD Newsletter #082: Quick edits with foamDictionary

Retrieve entries

# Print the top-level keywords present in this dictionary
foamDictionary system/snappyHexMeshDict -keywords

# Print the addLayersControls sub-dictionary
foamDictionary system/snappyHexMeshDict -entry addLayersControls

# List the keywords in the addLayersControls sub-dictionary
foamDictionary system/snappyHexMeshDict -keywords -entry addLayersControls

# Print the ENTRY for nLayerIter in addLayersControls
foamDictionary system/snappyHexMeshDict -entry addLayersControls/nLayerIter

# Print the VALUE of nLayerIter in addLayersControls
foamDictionary system/snappyHexMeshDict -entry addLayersControls/nLayerIter -value

Change an existing entry

# Set the value for nLayerIter in addLayersControls to 100
foamDictionary system/snappyHexMeshDict -entry addLayersControls/nLayerIter -set 100

# Set a value as the result of another command
# eg set the number of subdomains = to the number of procs on the machine
foamDictionary system/decomposeParDict -entry numberOfSubdomains -set $(nproc)

Add a new entry

# Add a new top-level entry with a vector
foamDictionary my-include-file -entry top-level-var -add "(1 2 3)"

# Add an empty sub-dictionary called newdict
foamDictionary my-include-file -entry newdict -add "{}"

# Add an entry called myvar into the newdict sub-dictionary
foamDictionary my-include-file -entry newdict/myvar -add 2000

# Add a complete sub-dictionary:
# eg. add a new geometry file into snappyHexMeshDict
foamDictionary system/snappyHexMeshDict -entry geometry/newgeom.obj \
  -add "{type triSurfaceMesh; name my-new-geometry;}"

Remove entries

# Remove the complete "newgeom.obj" sub-dictionary
foamDictionary system/snappyHexMeshDict -entry geometry/newgeom.obj -remove
	
@DWJCW
Copy link

DWJCW commented Jan 30, 2024

Thank you for your nice document. It helps me a lot.

I found an interesting issue about the foamDictionary command. When you try to set a value on an existing dictionary with some macro, the command seems to expand all the macros at first and then set the value. Do you know how to avoid this?

@robinknowles
Copy link
Author

Does foamDictionary -disableFunctionEntries do what you need?

@DWJCW
Copy link

DWJCW commented Jan 30, 2024

Think you for your fast reply.
When I enable this flag, it will raise an error when dealing with the line containing "#eval{}". It says that the number of brackets does not match, while the blockMesh could make mesh without any error.

@robinknowles
Copy link
Author

Ah, OK - yeah I can see this behaviour in some of the blockMesh tutorials.

Maybe you could raise it on the issue tracker?

Maybe you could extract some of the calculations into a separate dictionary & #include them back into your main dictionary?

@DWJCW
Copy link

DWJCW commented Jan 30, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment