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

Wrong result for mass flux in parallel

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By mitti

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 15, 2018, 16:03
Lightbulb Wrong result for mass flux in parallel
  #1
New Member
 
Join Date: Nov 2016
Posts: 15
Rep Power: 9
mitti is on a distinguished road
Hi folks,

my current case (Channel Flow, OF 2.1.x) works fine except one point: I calculate the mass flux during run time via phi. Works fine in single core but in parallel the result is wrong. The code looks like:

Code:
scalar inletFlux = 0;
label inletPatch = mesh.boundaryMesh().findPatchID("inlet");
inletFlux  = -1.0*gSum(phi.boundaryField()[inletPatch]);
Even if I use "reduce(inletFlux, sumOp<scalar>());" and "sum" instead "gSum" the result is wrong. If I take a look into the output of every processor in parallel, the results do not sum up to the correct value.

Any guess, idea etc. what could be the problem? Do you need more information?

Last edited by mitti; August 29, 2018 at 15:43.
mitti is offline   Reply With Quote

Old   August 19, 2018, 09:02
Default
  #2
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
can you provide a bit more information:


What mass flow is calculated in each processor and with is calculated by summing it over the processors.




findPatchId gives back -1 if it does not find any patch with the name specified.



I'm not sure what happens in a decomposed case when the patch looked for is not on a processor and you do the gsum.






did you try to sum the mass flux phi with the function sum only in case findPatchId gives back a number different than -1 and after that the results over all processors
mAlletto is offline   Reply With Quote

Old   August 20, 2018, 17:05
Default
  #3
New Member
 
Join Date: Nov 2016
Posts: 15
Rep Power: 9
mitti is on a distinguished road
Hi Michael,

thank you for your reply.

Quote:
Originally Posted by mAlletto View Post
What mass flow is calculated in each processor and with is calculated by summing it over the processors.
Single core: \dot{m}=0.066554155

The fun part is, that the mass flux is different for the number of processors:
4 processors: \dot{m}=0.033277077. With values in three processors, one is zero.
8 processors: \dot{m}=0. (This is something I really don’t understand)
16 processors: \dot{m}=0.0002943775 but only one processor has a value, all others are zero.
32 processors: \dot{m}=0.0056845246 with different values in six processors.

This weird results could be because I use scotch? I will try different decompose methods.

Quote:
Originally Posted by mAlletto View Post
findPatchId gives back -1 if it does not find any patch with the name specified.

I'm not sure what happens in a decomposed case when the patch looked for is not on a processor and you do the gsum. did you try to sum the mass flux phi with the function sum only in case findPatchId gives back a number different than -1 and after that the results over all processors
I don’t know too, so I modified the code:
Code:
scalar inletFlux = 0;
label inletPatch = mesh.boundaryMesh().findPatchID("inlet");

if (inletPatch == -1) {
    Info << "Failure to find patch for mass flow calc" << endl;
}
else {
    inletFlux = gSum(phi.boundaryField()[inletPatch]);
    inletFlux *= -1.0;
}
I also tried this but there is no difference in the result:
Code:
scalar inletFlux = 0;
label inletPatch = mesh.boundaryMesh().findPatchID("inlet");

if (inletPatch == -1) {
    Info << "Failure to find patch for mass flow calc" << endl;
}
else {
    inletFlux = sum(phi.boundaryField()[inletPatch]);
}

reduce(inletFlux, sumOp<scalar>());
inletFlux *= -1.0;
mitti is offline   Reply With Quote

Old   August 22, 2018, 03:42
Default
  #4
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
That's strange. What are the initial and boundary conditions? Do you have a constant pressure gradient which drives the flow? Did you try a newer version of OF?
mAlletto is offline   Reply With Quote

Old   August 22, 2018, 03:54
Default
  #5
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
By the way, there is a function object already available in OF which determines the mass flow at a specific patch. See how to calculate mass flow rate /simpleFoam.

Maybe you can compere your output with the output of the function object and this can give you a hint what's going wrong.
mAlletto is offline   Reply With Quote

Old   August 23, 2018, 12:31
Default
  #6
New Member
 
Join Date: Nov 2016
Posts: 15
Rep Power: 9
mitti is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
By the way, there is a function object already available in OF which determines the mass flow at a specific patch. See how to calculate mass flow rate /simpleFoam.

Maybe you can compere your output with the output of the function object and this can give you a hint what's going wrong.
I took me some time to modify it for 2.1.x but now it runs. Next time I should read the whole wiki thread first^^
Anyway, calcMassFlow is only single core and it gives me the same result as I get for single core.
mitti is offline   Reply With Quote

Old   August 23, 2018, 12:36
Default
  #7
New Member
 
Join Date: Nov 2016
Posts: 15
Rep Power: 9
mitti is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
That's strange. What are the initial and boundary conditions? Do you have a constant pressure gradient which drives the flow?
You can find my initial/boundary conditions attached.

I do have a pressure gradient which drives the flow. It is added into the momentum equation.


Quote:
Originally Posted by mAlletto View Post
Did you try a newer version of OF?

Not yet, will do it today and keep you updated.
Attached Files
File Type: zip 0.zip (2.5 KB, 3 views)
mitti is offline   Reply With Quote

Old   August 28, 2018, 18:11
Default
  #8
New Member
 
Join Date: Nov 2016
Posts: 15
Rep Power: 9
mitti is on a distinguished road
Quote:
Originally Posted by mitti View Post
Not yet, will do it today and keep you updated.
Finally, I found enough time to give it a shoot with of1606 and 1712. It is the same result for both versions, the only major difference is that it works for 2 and 4 processors but as soon as I use 8 or more, it fails again. This time with different results for each processor than in of2.1.x.

However, while reading a bunch of stuff here, I came across this thread and the statement "The main problem could be that faces that are on a processor boundary could be counted twice (or not at all)".

Also, in the wiki for calcMassFlow it's stated that the calculation of the mass flux in parallel is an issues. Nevertheless, all threads are relatively old.
mitti is offline   Reply With Quote

Old   August 29, 2018, 06:44
Default
  #9
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Quote:
Originally Posted by mitti View Post
You can find my initial/boundary conditions attached.

I do have a pressure gradient which drives the flow. It is added into the momentum equation.





Not yet, will do it today and keep you updated.


I just had a look on the initialization and it seems you used fixed value boundary conditions for nut, epsilon and k. I would rather advise you to use fixed value for k and epsilon and calculated for nut, or use wall function for all three quantities. Otherwise you get some inconsistency for the boundary conditions.

A and you do you specify the pressure gradient which drives the flow? Is it specified in the fvOption? If so can you post it too so I can have a look?
mAlletto is offline   Reply With Quote

Old   August 29, 2018, 12:30
Default
  #10
New Member
 
Join Date: Nov 2016
Posts: 15
Rep Power: 9
mitti is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
I just had a look on the initialization and it seems you used fixed value boundary conditions for nut, epsilon and k. I would rather advise you to use fixed value for k and epsilon and calculated for nut, or use wall function for all three quantities. Otherwise you get some inconsistency for the boundary conditions.
As far as I know it makes, regarding nut, no difference for Channel Flow. But I will run a simulation and check it. Thanks.

Since I use a low-Re model, wall functions are not necessary.

Quote:
Originally Posted by mAlletto View Post
A and you do you specify the pressure gradient which drives the flow? Is it specified in the fvOption? If so can you post it too so I can have a look?
I modified the UEqn.h

Code:
fvVectorMatrix UEqn
(
   fvm::ddt(U)
 + fvm::div(phi, U)
 + turbulence->divDevReff(U)
 ==
   vector(1,0,0) * gradP
);

UEqn.relax();

if (momentumPredictor)
{
   solve(UEqn == -fvc::grad(p));
}
with a pre-calculation of gradP at the beginning of the simulation. ReTau is the desired ReTau, height is the channel half height.

Code:
dimensionedScalar uTau = ReTau*nu/height;
dimensionedScalar gradP = pow(uTau,2)/height;
mitti is offline   Reply With Quote

Old   August 29, 2018, 15:39
Lightbulb
  #11
New Member
 
Join Date: Nov 2016
Posts: 15
Rep Power: 9
mitti is on a distinguished road
Quote:
Originally Posted by mitti View Post
As far as I know it makes, regarding nut, no difference for Channel Flow. But I will run a simulation and check it. Thanks.
Done and the results are the same for U, k and nut. And, so far LaunderSharma is capable, the results are close to DNS data.

Nevertheless, I found the solution for my problem with further and deeper digging in the forum finally in this thread.
The problem is, as I already figured out, the way how openFoam parallelizes: the simple fact that a patch can also be the processor boundary, can cause problems when summing up values on this patch. See both links for further information.
However, with "forcing" the decomposePar-method that all boundaries are on one processor (with preservePatches in the decomposeParDict) this problem is avoided. The impact of a maybe bad decomposition, which could effect the runtime, for my case is another aspect.
mAlletto likes this.
mitti 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
udf error srihari FLUENT 1 October 31, 2016 14:18
Udf for moving heat flux in 2D cylindrical geometry devia21 Fluent UDF and Scheme Programming 0 April 20, 2015 00:27
An error has occurred in cfx5solve: volo87 CFX 5 June 14, 2013 17:44
Wrong result with bilinear interpolation zonexo Main CFD Forum 1 June 12, 2007 15:55
laminar pipe flow? Fluent gives wrong result SAM FLUENT 2 November 5, 2004 01:39


All times are GMT -4. The time now is 11:33.