|
[Sponsors] |
September 16, 2015, 10:40 |
Integration of part of the simulation domain
|
#1 |
New Member
Edwin
Join Date: Nov 2014
Posts: 5
Rep Power: 11 |
Hi Foamers!
I am trying to do a simple water volume calculation in a two-phase flow. To find the volume of the water in inter(DyM)Foam, I can simply use Code:
dimensionedScalar waterVolume = sum(mesh.V()*alpha1); Code:
dimensionedScalar waterVolumeLeft = sum(mesh.V()*alpha1*neg(mesh.C().internalField().component(vector::X))); dimensionedScalar waterVolumeRight = sum(mesh.V()*alpha1*pos(mesh.C().internalField().component(vector::X))); waterVolume: 1.31441405254865e-11, left+right:7.109575809296095e-12. I've also tried to write the x-positions to a volScalarField, and looping over the elements, but I keep getting a (consistent) volume of 7.1095...e-12, with something like this: Code:
volScalarField xPositions ( IOobject ( "xPositions", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedScalar("xPositions",dimensionSet(0,1,0,0,0,0,0), 0.0) ); forAll(xPositions,iter) { xPositions[iter]=mesh.C().internalField()[iter].component(vector::X); } dimensionedScalar waterVolumeLeftCheck = 0.0; dimensionedScalar waterVolumeRightCheck = 0.0; forAll(xPositions,iter) { if (xPositions[iter]<0) waterVolumeLeftCheck+=mesh.V()[iter]*alpha1[iter]; else waterVolumeRightCheck+=mesh.V()[iter]*alpha1[iter]; } Best, Edwin |
|
September 16, 2015, 12:02 |
|
#2 |
New Member
Edwin
Join Date: Nov 2014
Posts: 5
Rep Power: 11 |
Hmm after another search, I just found this topic:
http://www.cfd-online.com/Forums/ope...integrate.html It looks like the fvc::domainIntegrate(alpha1*neg(xPositions)) function is the solution. I still don't see how my other attempts failed to give the right answer.. |
|
September 16, 2015, 12:18 |
|
#3 |
Senior Member
Join Date: Oct 2013
Posts: 397
Rep Power: 19 |
Just a rough sketch:
scalar volume = 0; forAll(mesh, cellI) { if(mesh.C().x() <= 0) volume += mesh.V()[cellI]*alpha1[cellI]; } |
|
September 16, 2015, 13:04 |
|
#4 |
New Member
Edwin
Join Date: Nov 2014
Posts: 5
Rep Power: 11 |
||
September 16, 2015, 15:56 |
|
#5 |
Senior Member
Wouter van der Meer
Join Date: May 2009
Location: Elahuizen, Netherlands
Posts: 203
Rep Power: 18 |
hello Edwon,
Did you try this with a little larger volume, because it could be a numerical accuracy problem. hope this helps, Wouter |
|
September 17, 2015, 05:40 |
|
#6 |
Senior Member
Join Date: Oct 2013
Posts: 397
Rep Power: 19 |
Did you run this on multiple cores or on a single core? The code I showed is only suitable for a single core. If you need multiple cores, you need to run reduce(volume, sumOp<scalar>()); at the end to add the results of all the separate meshes together.
|
|
September 17, 2015, 06:20 |
|
#7 |
New Member
Edwin
Join Date: Nov 2014
Posts: 5
Rep Power: 11 |
I just checked, that also solves the problem! (I assumed that the contributions of all cores would add up automagically)
I still find it strange that sum(mesh.V()*alpha1) works on multiple cores, and sum(mesh.V()*alpha1*neg( mesh.C().internalField().component(vector::X) )) does not. But, we (you) found out what was causing the discrepancy and that is what counts! @Wouter, I've just checked, that was not the case. Haven't thought to look at that before, though. Last edited by Edwon; September 17, 2015 at 08:00. |
|
Tags |
integration, interfoam, sum() |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
PEM fuel cell simulation | pchoopanya | Mesh Generation & Pre-Processing | 1 | March 1, 2016 00:56 |
VAWT simulation rotation domain | steve20024 | Main CFD Forum | 0 | March 2, 2015 04:37 |
Waterwheel shaped turbine inside a pipe simulation problem | mshahed91 | CFX | 3 | January 10, 2015 12:19 |
Floating point exception: Zero divide | liladhar | CFX | 11 | December 16, 2013 05:07 |
How to define size of domain for free surface simulation? | Sunya | Main CFD Forum | 2 | June 9, 2009 00:33 |