How to read dictionary variables from another dictionary
Hello,
In OpenFOAM, we can create variables in dictionary files. For example, in 0/U (The U file in 0 folder)I can define a variable xvelocity like this: Code:
... |
I don't know for sure, but it is possible that variables defined in a dictionary such as xvelocity in your example, are local to the dictionary they are defined in.
One problem with having such variables available to other files would be this: can you guarantee that the dictionary containing the variable is read before the one that needs to use it? |
Quote:
Currently I am looking for some tricks but I am not sure if that will work. I want to use #codeStream or codedFixedValue to access inputs from other dictionaries. I will post any relevant progressing steps here. |
It is possible. You need to include the file. In your 0/U file, add the following
Code:
#include "path-to-file/file" |
Quote:
|
Hi.
You could just define all the variables you need in a separate file and include that into the files where you need them. Say that you make a file: 0/variables/myvars where you define the variables: Code:
xVelocity 15; That way you do not risk the chance of overwriting dictionaries. Best regards Mathias |
Quote:
|
I just figured it out, using #codeStream and using this function
Code:
#include <iostream> Now, we can combine this with the famous utilty foamDictionary to read dictionary entries and modifying them; Here is an example of usage: Code:
// This will change the value of the entry myVar in 0/p file |
Quote:
The scope can be protected. This worked for me: Code:
More tricks: https://cfd.direct/openfoam/user-gui...c-file-format/ |
All times are GMT -4. The time now is 11:41. |