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

Loop through data values

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 2 Post By Tobi
  • 1 Post By cute

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 12, 2016, 09:09
Default Loop through data values
  #1
Member
 
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10
cute is on a distinguished road
Dear members,

I am running modified version of cavity test case with dimension of 1 mm^3 and grid size of 100 x 100 x 100. I want to access all values at z = 95. I can write C++ code but don't know how to do it in openFoam. Could you please help? I searched the forum but did not find related information.

Code:
    for (i=0; i<200; i++)
   {
       for (j=0; j<200; j++)
           cout<< T(i,j,95)<<endl;
   }
Thanks.
cute is offline   Reply With Quote

Old   August 12, 2016, 09:57
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi,

I think you want to have access to the cell values of all cells within (x, y, 95). There are different options. The best one would to make a cell zone of all these cells first (you will get a cell list that contains the ID's of the cells, this will save time).

Otherwise you can search for these cells for each loop. What you have to do is, get the cells (mesh.C()), search for the components and done. But you should more or less define somehow a range. Lets say:

Code:
//- Check the doxygen for the correct Types
const cellField& pF = mesh.C();

//- Search the cells with 94.5 < z < 95.5
List<label> cellIDs;

forAll(pF, ID)
{
       //- z coordinate
       const scalar zCoor = pF[ID].z();

       if ( zCoor < 95.5 && zCoor > 94.5)
       {
             cellIDs.append(ID);
       }
}


//- Print all values from Temperature field
const scalarField& T_ = T.internalField();

forAll(cellIDs, ID)
{
     Info<<  T_[ID].value() << endl;
}
Something like that should do the stuff. It is easier to have a pre-defined cellZone. Then it is much shorter.

Hope it will help you.
Rojj and Hughtong like this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   August 12, 2016, 10:16
Default
  #3
Member
 
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10
cute is on a distinguished road
Thanks for the reply. I will implement as soon as I will be back. But one more thing, If I also need to include boundary value at z=95 what I need to change?
cute is offline   Reply With Quote

Old   August 12, 2016, 10:33
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Then you have to do the same stuff with the boundary conditions. Check for the boundary and search for the face-center and get the ID.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   August 12, 2016, 10:37
Default
  #5
Member
 
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10
cute is on a distinguished road
Thanks, I will try this afternoon.
cute is offline   Reply With Quote

Old   August 12, 2016, 11:42
Default
  #6
Member
 
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10
cute is on a distinguished road
I am getting the following error:

Code:
error: ‘cellField’ does not name a type
     const cellField& pF = mesh().C();
whats wrong here, could not understand?


(2) For creating a list at z=95, why do we need
Code:
zCoor < 95.5 && zCoor > 94.5
can we use ZCoor == 95?
cute is offline   Reply With Quote

Old   August 12, 2016, 11:55
Default
  #7
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
As I told before, you have to check the types and functions yourself. Therefore you can use doxygen (I will not present the solution).

You can take 95 but if the cell centers are not exactly at that position this will not work. You should more like check if the cell goes through this fixed z-line. So it is up to you what you finally do.

For example: http://cpp.openfoam.org/v4/a00886.html

You will see that the first line has to be:
Code:
const volVectorField foobar = mesh.C()
As you can see further, the boundaries are also included (should be because it is a volVectorField).
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   August 12, 2016, 12:04
Default
  #8
Member
 
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10
cute is on a distinguished road
Thanks, it is volVectorField.

Now I am getting different error:
Code:
error: request for member ‘value’ in ‘(& X_)->Foam::Field<double>::<anonymous>.Foam::List<double>::<anonymous>.Foam::UList<T>::operator[]<double>(ID)’, which is of non-class type ‘const double’
            if (X_[ID].value() > 0.0)
what is the reason for this?
cute is offline   Reply With Quote

Old   August 12, 2016, 12:11
Default
  #9
Member
 
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10
cute is on a distinguished road
Got it, after deleting
" .value() "
cute is offline   Reply With Quote

Old   August 13, 2016, 10:58
Default
  #10
Member
 
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10
cute is on a distinguished road
Thaks Tobi for your help. It is running now.
Tobi likes this.
cute is offline   Reply With Quote

Old   August 13, 2016, 14:16
Default
  #11
Member
 
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10
cute is on a distinguished road
This simulation gets stuck for parallel processing .

If I remove the above code, simulation runs and creates data files. Do i need to add something in above code for parallel processing? I added the above code before while-loop (solution-loop).
cute is offline   Reply With Quote

Old   August 15, 2016, 10:30
Default
  #12
Member
 
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10
cute is on a distinguished road
After doing some work on code, I realized that forAll LOOP does not work in parallel.

What should I add or modify in above code for parallel processing?
Need help plz.
cute is offline   Reply With Quote

Old   August 17, 2016, 12:08
Default
  #13
Member
 
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10
cute is on a distinguished road
I am not able to find the answer yet. Some of them in the forum also reported this issue but no solution.

forAll loop is not running in parallel and my simulation gets stuck.

Any hint would be appreciated.
cute is offline   Reply With Quote

Reply


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
Run OpenFoam in 2 nodes of a cluster WhiteW OpenFOAM Running, Solving & CFD 16 December 20, 2016 00:51
[Gmsh] Problem with Gmsh nishant_hull OpenFOAM Meshing & Mesh Conversion 23 August 5, 2015 02:09
Improved solver data output / tracking / visualization chriss85 OpenFOAM Running, Solving & CFD 1 May 13, 2015 07:55
Increasing the accuracy of pressure head values in output data Saeed1390 FLUENT 0 June 13, 2011 02:17
NACA0012 geometry/design software needed Franny Main CFD Forum 13 July 7, 2007 15:57


All times are GMT -4. The time now is 14:25.