Looping over a volScalarField in a parallel run
Dear all,
I'd like to do some on-the-run monitoring of my computation where I am interested in a temperature front. Actually, of all the cells in my domain where the temperature exceeds 1000 K, I'd like to determine the one which has the highest x-coordinate. My code looks like this: Code:
label maxindex=0; Regards, Florian |
ooo, a well formulated problem with a simple answer, my favourite :)
you cant use the index cause it only makes sense on the own processor. I would do it like this. Code:
scalar xMax = -1.0e+10; |
Thank you Niklas,
the reduce command should read Code:
reduce(xMax, maxOp<scalar>()); A more tricky problem: I also want to know the y and z coordinate of the location, where the highest x coordinate is (not the maximum y and z coordinate). So a separate reduce on the scalars won't work. Code:
scalar xMax = -1.0e+10; Thanks, Florian |
That was a bit trickier...
I dont know if there's such an operation already implemented, but I would transfer the location vector for each coordinate to the main processor and do the comparison there. Here's a piece of code that generates a random vector on each processor and sends it to the 0-processor, it should be straightforward to apply it to your case. You might wanna put it inside an if(Pstream:: parRun()) if you want it to work for both serial and parallell runs. (edit:: actually its not necessary) Code:
Random rnd(0); |
Thank you, it seems to work fine!
|
coded functions with forAll have similar problems with parallel execution
this is a coded function added in controlDict,
Quote:
Quote:
please help...:confused::confused::confused:. All suggestions are most welcome. Thanks and regards. |
Quote:
Code:
reduce(volIntegral, maxOp<scalar>()); |
Thanks Zeppo.
syntax wise (reduce(volIntegral, maxOp<scalar>());) works, but the answer of serial and parallel is different. parallel output at one time-step. Quote:
Quote:
|
1. You might want to use a built-in feature instead of developing your own code. There's a function object volRegion (http://cpp.openfoam.org/v4/a06355_source.html)
Code:
pIntegral 2. Nevertheless, if you want to "reinvent the wheel" (or practice in OpenFOAM/C++ programming, if you like to think of it this way ;)) look at how this function object is implemented Code:
// "src/functionObjects/field/fieldValues/volRegion/volRegion.H" Code:
// "src/functionObjects/field/fieldValues/volRegion/volRegion.H" Code:
// "src/functionObjects/field/fieldValues/fieldValue/fieldValueTemplates.C" Code:
reduce(volIntegral, maxOp<scalar>()); Code:
reduce(volIntegral, sumOp<scalar>()); |
Thanks Zeppo for a informative reply!
I will try this Code: reduce(volIntegral, sumOp<scalar>()); reduce(volIntegralV, sumOp<scalar>()); and get back to you! :) |
All times are GMT -4. The time now is 08:20. |