CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Is it possible to exchange some vectors/ variables within C++ files of OpenFoam ?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 22, 2015, 17:35
Default 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
Asghari_M is on a distinguished road
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);
#}; 
}
Is this operation (defining & exchanging variable (A) within routines/C++ dict files) feasible in this open-source code?
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
Asghari_M is offline   Reply With Quote

Old   July 22, 2015, 20:04
Default
  #2
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
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
And assuming that you want to read A[1] to use it for U BC as X component for fixedValue BC, so edit U as follows;
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;
    }
}
It is the most basic case of using codeStream. For more information about it check the user guide and check this thread which shows some of codeStream functionality http://www.cfd-online.com/Forums/ope...tml#post542310
hk318i is offline   Reply With Quote

Old   July 24, 2015, 05:35
Default
  #3
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
Quote:
Originally Posted by hk318i View Post
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
And assuming that you want to read A[1] to use it for U BC as X component for fixedValue BC, so edit U as follows;
A/U file (I think your purpose was 0/U. Is my view correct?)(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;
    }
}
Hello Hassan.
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;
    }
}
Really, what's difference between writing of vector A in U file and writing of it in an individual Avalue code?

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);
                         #};
Are syntaxes of red expressions correct?
What's dict.lookup meaning in this phrase?
Thanks for your kind attention.
Asghari_M is offline   Reply With Quote

Old   July 24, 2015, 20:07
Default
  #4
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
  • It does matter to define A inside the 0/U file. I put it in separate file just as a more general example.
  • The code in red isn't correct, codeStream has the same syntax as OF library and c++. scalarField is of type List<double> which has access operator [ ] not ( ). Therefore any element could be accessed as A[i] where i must be of type label or int, see my previous post as example for accessing A[1] which is equal to 2.1
  • dict is a reference to the dictionary where the codeStream is defined. dict is declared automatically and the Ostream os as well, see the user guide link in my previous post.
hk318i is offline   Reply With Quote

Old   July 25, 2015, 17:42
Default
  #5
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
Quote:
Originally Posted by hk318i View Post
  • The code in red isn't correct, codeStream has the same syntax as OF library and c++. scalarField is of type List<double> which has access operator [ ] not ( ). Therefore any element could be accessed as A[i] where i must be of type label or int, see my previous post as example for accessing A[1] which is equal to 2.1
Thanks for your kind attentions & helpful responses.
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);
2-Is it possible to access time variables such as db().time().value() within the code with fixedvalue type instead of codedFixedValue without using the following code?
Code:
#include Time.h
Thanks very much .
Asghari_M is offline   Reply With Quote

Old   July 25, 2015, 18:15
Default
  #6
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
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.
__________________
@HIKassem | HassanKassem.me
hk318i is offline   Reply With Quote

Old   July 26, 2015, 14:06
Default
  #7
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
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.
Asghari_M is offline   Reply With Quote

Old   July 26, 2015, 14:14
Default
  #8
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
I am not sure if I understand your question right but A is defined in dictionary 0/U as dictionary entry

Name Value;
__________________
@HIKassem | HassanKassem.me
hk318i is offline   Reply With Quote

Old   July 29, 2015, 03:51
Default
  #9
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
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
Asghari_M is offline   Reply With Quote

Old   July 29, 2015, 04:43
Default
  #10
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
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.
__________________
@HIKassem | HassanKassem.me
hk318i is offline   Reply With Quote

Old   August 2, 2015, 02:39
Default
  #11
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
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.
Asghari_M is offline   Reply With Quote

Reply

Tags
exchanging variables, reading data


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 04:54.