|
[Sponsors] |
August 12, 2016, 10:09 |
Loop through data values
|
#1 |
Member
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10 |
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; } |
|
August 12, 2016, 10:57 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
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; } Hope it will help you.
__________________
Keep foaming, Tobias Holzmann |
|
August 12, 2016, 11:16 |
|
#3 |
Member
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10 |
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?
|
|
August 12, 2016, 11:33 |
|
#4 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
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 |
|
August 12, 2016, 11:37 |
|
#5 |
Member
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10 |
Thanks, I will try this afternoon.
|
|
August 12, 2016, 12:42 |
|
#6 |
Member
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10 |
I am getting the following error:
Code:
error: ‘cellField’ does not name a type const cellField& pF = mesh().C(); (2) For creating a list at z=95, why do we need Code:
zCoor < 95.5 && zCoor > 94.5 |
|
August 12, 2016, 12:55 |
|
#7 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
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()
__________________
Keep foaming, Tobias Holzmann |
|
August 12, 2016, 13:04 |
|
#8 |
Member
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10 |
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) |
|
August 12, 2016, 13:11 |
|
#9 |
Member
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10 |
Got it, after deleting
" .value() " |
|
August 13, 2016, 11:58 |
|
#10 |
Member
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10 |
Thaks Tobi for your help. It is running now.
|
|
August 13, 2016, 15:16 |
|
#11 |
Member
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10 |
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). |
|
August 15, 2016, 11:30 |
|
#12 |
Member
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10 |
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. |
|
August 17, 2016, 13:08 |
|
#13 |
Member
anonymous
Join Date: Mar 2016
Location: Canada
Posts: 93
Rep Power: 10 |
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. |
|
|
|
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 01:51 |
[Gmsh] Problem with Gmsh | nishant_hull | OpenFOAM Meshing & Mesh Conversion | 23 | August 5, 2015 03:09 |
Improved solver data output / tracking / visualization | chriss85 | OpenFOAM Running, Solving & CFD | 1 | May 13, 2015 08:55 |
Increasing the accuracy of pressure head values in output data | Saeed1390 | FLUENT | 0 | June 13, 2011 03:17 |
NACA0012 geometry/design software needed | Franny | Main CFD Forum | 13 | July 7, 2007 16:57 |