Skip to content

Instantly share code, notes, and snippets.

@robinknowles
Created February 4, 2022 09:46
Show Gist options
  • 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 via email

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