11_dictionary
Important
Visit https://aerosand.cc for the latest updates.
0. Preface
The previous discussions have helped us understand the essence of input/output and dictionaries in OpenFOAM. Now, let us examine the input/output methods provided by OpenFOAM.
OpenFOAM applications typically need to read dictionaries from the case and output computational results to the case, among other operations.
How does OpenFOAM implement reading from and writing to folders? OpenFOAM’s input and output are more advanced; the method of indexing and searching by keyword is directly encapsulated in the relevant classes, and can be used directly by calling the methods. We do not need to delve into the implementation code at this stage.
This section primarily discusses:
- Understanding input/output for different data formats in OpenFOAM
- Understanding the methods provided by OpenFOAM dictionary classes
- Compiling and running a dictionary project
1. Project Preparation
Run the following commands in the terminal to create the project for this section:
ofsp
foamNewApp ofsp_11_dictionary
code ofsp_11_dictionaryRun the following command in the terminal to prepare a test case for the project:
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity debug_caseRun the following commands in the terminal to test the initial solver:
wmake
ofsp_11_dictionary -case debug_caseThe terminal output is as follows:
Create time
ExecutionTime = 0 s ClockTime = 0 s
EndThe above output indicates that the initial solver is functioning correctly and can be used as a basis for development.
2. Documentation File
As a relatively complete OpenFOAM project, we provide a documentation file:
## About
This is a project for understanding OpenFOAM dictionaries.
## Bio
- Aerosand @ Aerosand
## Caution
OpenFOAM v2406 or newer versions are required.
## Deploy
Prepare the environment and all files.
Execute the following commands in the terminal in the root directory:
Clean and recompile the application:
1. wclean
2. wmake
Clean and recompute the test case:
1. ./caseclean
2. ./caserun
## Event
@ 202509010
- Added cleaning script3. Script Files
The scripts are similar to those discussed in previous projects; only the solver name in the scripts needs to be modified.
The caserun script is primarily responsible for running the test case after the application is successfully compiled. It currently contains the following content:
| |
The caseclean script is primarily responsible for cleaning up the application to its pre-compilation state. If the application is modified, the test case should also be restored to its pre-run state. It currently contains the following content:
| |
Run the following command in the terminal to grant permissions to the scripts:
chmod +x caserun caseclean4. File Structure
The file structure is as follows:
.
├── caseclean
├── caserun
├── debug_case
│ ├── 0
│ │ ├── p
│ │ └── U
│ ├── constant
│ │ └── transportProperties
│ └── system
│ ├── blockMeshDict
│ ├── controlDict
│ ├── decomposeParDict
│ ├── fvSchemes
│ ├── fvSolution
│ └── PDRblockMeshDict
├── Make
│ ├── files
│ └── options
├── ofsp_11_dictionary.C
└── README.md5. Main Source Code
The main source code in ofsp_11_dictionary.C is as follows:
| |
6. Providing Dictionaries
Provide the dictionary file debug_case/constant/customProperties. Since this dictionary has no read or write operations, it only needs a correct file header, with its content left blank.
| |
The dictionary file debug_case/constant/myProperties has the following content:
| |
7. Compilation and Execution
Run the following commands in the terminal to compile and run:
wclean
wmake
./caseclean
./caserunThe terminal output is as follows:
Create time
Create mesh for time = 0
Reading myProperties
application: icoFoam
writeFormat: ascii
deltaT: 0.01
alpha: alpha [0 0 0 0 0 0 0] 0.2
beta: beta [0 0 0 0 0 0 0] 0.5
purgeWrite: 1
point: 3(0 1 2)
source:
2
(
U1 (0 0 0)
U2 (1 0 0)
)
myVec: (0 0 1)
ExecutionTime = 0 s ClockTime = 0 s
EndAdditionally, a new folder debug_case/processing/ has been created under the test case folder, and the content of myOutPut.dat under this path is as follows:
| |
8. Summary
This project discussed the file stream input/output methods designed in OpenFOAM. In future practice, dictionaries and dictionary-related methods will be continuously used.
This section has completed the following discussions:
- Understanding input/output for different data formats in OpenFOAM
- Understanding the methods provided by OpenFOAM dictionary classes
- Compiling and running a dictionary project
Support us
Tip
Hopefully, the sharing here can be helpful to you.
If you find this content helpful, your comments or donations would be greatly appreciated. Your support helps ensure the ongoing updates, corrections, refinements, and improvements to this and future series, ultimately benefiting new readers as well.
The information and message provided during donation will be displayed as an acknowledgment of your support.
Copyright @ 2026 Aerosand
- Course (text, images, etc.):CC BY-NC-SA 4.0
- Code derived from OpenFOAM:GPL v3
- Other code:MIT License
