Is it possible to exchange some vectors/ variables within C++ files of OpenFoam ?
Hi all,
Since OpenFoam is an open-source code , it sounds like to be possible exchanging variables within its essential C++ files. However, in some cases, it seems to be impossible. How can we explain this paradox? For example , suppose there is a data/txt file as input as follows: --- 2 2.1 2.5 3.27 Now , I'm going to define a vector variable (A) corresponding with this txt/data file in an initial file as follows: A(1)=2 (first line of data file) A(2)=2.1 (second line of data file) A(3)=2.5 (third line of data file) A(4)=3.27 (forth line of data file) Then , this vector is used in the inlet BC at blockMesh dict as follows: Code:
inlet How can I define a vector based on txt/data file? No wonder if the most of open-source codes have this capability. Note that computational cost is a critical matter in this case. Thanks a lot for any suggestion & attention. M.Asghari |
Here is an example which could be a start point for your case,
Assume A = (2 2.1 2.5 3.27) So create a file in 0 directory and name it Avalue and add A as follows; 0/Avalue file Code:
A (2 2.1 2.5 3.27); A/U file (note this from cavity tutorial) Code:
#include "Avalue" |
Quote:
Can I set A vector in its own 0/U code as follows? Code:
A (2 2.1 2.5 3.27); Also, assume I use I and A(I) phrases since I need them for inlet velocity BC linear interpolation. Can I use following code (inserted in U file) for their definition (assume the relations are correct . I only worry about syntax in OF & C++): Code:
code What's dict.lookup meaning in this phrase? Thanks for your kind attention. |
|
Quote:
Only two question remain. 1-Is it feasible to use A[I] and db().time().value(), synchronously at code as follows? Code:
os << "uniform " <<vector(A[I]*db().time().value()+A[I+1],0,0); Code:
#include Time.h |
I didn't try before but if time is available using codedFixedValue, you can use it instead of fixed value. I believe the same syntax for reading A will work.
|
As last question, Is it important to know what's the type of Avalue file?
There two types for typical output or info/dict files as far as I know as follows: 1- Plain text document (text/plain) like thing which used in probes. 2- C source code (text/x-csrc) such as 0/U file. Is Avalue file type first or second? Thanks for your all helpful answers. |
I am not sure if I understand your question right but A is defined in dictionary 0/U as dictionary entry
Name Value; |
Frankly you're the only one ever to all my questions without hesitation replied.
Thank you for your kindness. As for the type of file, by right clicking on the file and then clicking on properies , file type is specified. Due to ur discription, Avalue file type should be c source code or same second option. Also, I'd glad if you participate in my next discussions in this forum and post-processing one that I will post them. M.Asghari |
You are welcome.
Don't worry about the file time because Linux isn't like windows needs file extension to recognise the file type. All OF case files are just text file and the type which you can see down in gedit is just for highlighting. |
I concluded that it isn't a critical matter what is to be the type of Avalue file.
It can be either Plain text document (text/plain) or C source code type. Isn't it? Best Regards. |
All times are GMT -4. The time now is 23:11. |