|
[Sponsors] |
Is it possible to exchange some vectors/ variables within C++ files of OpenFoam ? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 22, 2015, 17:35 |
Is it possible to exchange some vectors/ variables within C++ files of OpenFoam ?
|
#1 |
Senior Member
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16 |
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 { Read A type codedFixedValue; value $internalField; redirectType ramp; code #{ I= int(db().time().value()/A(1)) (*this)==vector(A(I)*db().time().value()+A(I+1),0,0); #}; } 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 |
|
July 22, 2015, 20:04 |
|
#2 |
Senior Member
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18 |
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); #inputMode merge A/U file (note this from cavity tutorial) Code:
#include "Avalue" dimensions [0 1 -1 0 0 0 0]; internalField uniform (0 0 0); boundaryField { movingWall { type fixedValue; value #codeStream { codeInclude #{ #include "scalarField.H" #include "vector.H" #}; codeOptions #{ // optional you may need it later which adds flags to EXE_INC in Make/options #}; codeLibs #{ // optional you may need it later which adds flags to LIB_LIBS in Make/options #}; code #{ scalarField A(dict.lookup("A", true)); os << "uniform " << vector(A[1],0,0); #}; }; } fixedWalls { type fixedValue; value uniform (0 0 0); } frontAndBack { type empty; } } |
|
July 24, 2015, 05:35 |
|
#3 | |
Senior Member
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16 |
Quote:
Can I set A vector in its own 0/U code as follows? Code:
A (2 2.1 2.5 3.27); dimensions [0 1 -1 0 0 0 0]; internalField uniform (0 0 0); boundaryField { movingWall { type fixedValue; value #codeStream { codeInclude #{ #include "scalarField.H" #include "vector.H" #}; codeOptions #{ // optional you may need it later which adds flags to EXE_INC in Make/options #}; codeLibs #{ // optional you may need it later which adds flags to LIB_LIBS in Make/options #}; code #{ scalarField A(dict.lookup("A", true)); os << "uniform " << vector(A[1],0,0); #}; }; } fixedWalls { type fixedValue; value uniform (0 0 0); } frontAndBack { type empty; } } 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 #{ scalarField A(dict.lookup("A", true)); I= real( int(db().time().value()/A(1))); os << "uniform " <<vector(A(I)*db().time().value()+A(I+1),0,0); #}; What's dict.lookup meaning in this phrase? Thanks for your kind attention. |
||
July 24, 2015, 20:07 |
|
#4 |
Senior Member
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18 |
|
|
July 25, 2015, 17:42 |
|
#5 | |
Senior Member
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16 |
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 |
||
July 25, 2015, 18:15 |
|
#6 |
Senior Member
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18 |
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.
|
|
July 26, 2015, 14:06 |
|
#7 |
Senior Member
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16 |
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. |
|
July 26, 2015, 14:14 |
|
#8 |
Senior Member
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18 |
I am not sure if I understand your question right but A is defined in dictionary 0/U as dictionary entry
Name Value; |
|
July 29, 2015, 03:51 |
|
#9 |
Senior Member
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16 |
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 |
|
July 29, 2015, 04:43 |
|
#10 |
Senior Member
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18 |
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. |
|
August 2, 2015, 02:39 |
|
#11 |
Senior Member
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16 |
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. |
|
Tags |
exchanging variables, reading data |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Map of the OpenFOAM Forum - Understanding where to post your questions! | wyldckat | OpenFOAM | 10 | September 2, 2021 06:29 |
about the additional output files when using CrankNicholson or backward in Openfoam | openfoammaofnepo | OpenFOAM Running, Solving & CFD | 0 | August 30, 2014 11:08 |
OpenFOAM Foundation releases OpenFOAM 2.2.2 | opencfd | OpenFOAM Announcements from ESI-OpenCFD | 0 | October 14, 2013 08:18 |
Problems in compiling paraview in Suse 10.3 platform | chiven | OpenFOAM Installation | 3 | December 1, 2009 08:21 |
Adventure of fisrst openfoam installation on Ubuntu 710 | jussi | OpenFOAM Installation | 0 | April 24, 2008 15:25 |