Summation in Function Object for Multiple Processors
2 Attachment(s)
This is my first time writing my own function object for OpenFOAM and am struggling to get it to work with mpirun. There are three quantities I want to calculate and write to a file in the postprocessing directory:
- Total volume of my mesh sum(mesh_.V())- Total volume of my liquid (this is multiphase) sum(mesh_.V()*alpha.internalField())- Sum of the position of the cell times the volume times the volume fraction (this should output a vector, not a scalar) sum(mesh_.V()*mesh_.C().internalField()*alpha.inte rnalField())My code seems to work perfectly when I just run interFoam, but gets hung on the summation part with I try to use it with mpirun. To test where it's getting hung, I separated out each of the calculation steps. It made it through until it hit the summation. Please see the code below which has both these test lines and, below that, the lines with correctly write the info to a file when run on a single processor. I have tried both sum and gSum because it sounds like gSum is what should be used for multiple processors. Other forum posts have mentioned having good luck with gSum, but I can't figure out what I'm doing differently/incorrectly. Links to these posts are below. I'm also concerned that even if I can get the summation to work, that it might only sum over the master processor, not all. Does anyone have any recommendations for how to get gSum to work in function objects with mpirun? https://www.cfd-online.com/Forums/op...um-vs-sum.html https://www.cfd-online.com/Forums/op...alarfield.html Code:
/*---------------------------------------------------------------------------*\ |
Just a guess: what happens if you use explicit OpenFOAM types, e.g. scalar for z?
|
Quote:
Code:
CM.C:121:30: error: cannot convert ‘Foam::dimensioned<double>’ to ‘Foam::scalar {aka double}’ in initialization Code:
CM.C:121:26: error: ‘const class Foam::DimensionedField<double, Foam::volMesh>’ has no member named ‘value’ |
So I guess adding .value() after sum is what it needs to be a double. I no longer get the error during wmake when specifying that it should be a double/scalar. However, interFoam still gets hung on calculating z.
|
Alright, I have it figured out. I actually needed to do some calculations before moving to the master processor. Right now I have it set up to calculate each of my needed quantities on individual processors, gather lists, and then write the result on the master processor. I'm not actually convinced that it's even necessary to gather the list, so I'll post an update if I have a simplified code. But either way, this code works for what I wanted even if it isn't the prettiest.
Code:
/*---------------------------------------------------------------------------*\ |
Center of Mass Function Object
1 Attachment(s)
In case anyone could benefit from it, I've attached the complete center of mass function object directory. You should be able to just run wmake in the attached directory, then include it in your controlDict using something like the following:
center { type CM; libs ("libCMFunctionObject.so") } |
I saw this one a bit late. There are a number of things that are either more work that you need, or too inefficient. Here are some, with inline comments.
Quote:
Code:
const auto& volume = mesh_.V(); Quote:
You were right to doubt the need for all of those awkward processor lists. Instead of more comments, here are some simple tips Code:
scalar someVal =...; // processor local value If you start using these functions, you will be writing a lot less code, more quickly and easier to understand and maintain. Quote:
Code:
// obvious filled directly elsewhere |
Quote:
Is this a cut and paste error? Or have you actually transferred your code copyrights to the OpenFOAM Foundation Ltd.? |
Thank you so much for your feedback! It looks like you've got some excellent suggestions, so I'll go through them all as soon as I have the time!
Yes, the header is a copy and paste error. I used the OpenFOAM provided template, and was too worried about getting the code to work that I didn't check the header. It may be a week or two before I'm able to get back to this, but I'll post a new code when I can. |
All times are GMT -4. The time now is 05:15. |