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

Integration of part of the simulation domain

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By chriss85

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 16, 2015, 10:40
Default Integration of part of the simulation domain
  #1
New Member
 
Edwin
Join Date: Nov 2014
Posts: 5
Rep Power: 12
Edwon is on a distinguished road
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);
However, for my simulations I need to know the volume of water in a certain part of the simulation domain, for example, let's say x<0 and x>=0. One of my attempts was this:
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)));
However, this does not result in the correct volume: as a test I add both pos(..) and neg(..), which should result in the same waterVolume, but instead it gives this in a test run:
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];
}
Can anyone point me in the right direction with this? Any help is appreciated!

Best,
Edwin
Edwon is offline   Reply With Quote

Old   September 16, 2015, 12:02
Default
  #2
New Member
 
Edwin
Join Date: Nov 2014
Posts: 5
Rep Power: 12
Edwon is on a distinguished road
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..
Edwon is offline   Reply With Quote

Old   September 16, 2015, 12:18
Default
  #3
Senior Member
 
Join Date: Oct 2013
Posts: 397
Rep Power: 19
chriss85 will become famous soon enough
Just a rough sketch:
scalar volume = 0;
forAll(mesh, cellI)
{
if(mesh.C().x() <= 0)
volume += mesh.V()[cellI]*alpha1[cellI];
}
chriss85 is offline   Reply With Quote

Old   September 16, 2015, 13:04
Default
  #4
New Member
 
Edwin
Join Date: Nov 2014
Posts: 5
Rep Power: 12
Edwon is on a distinguished road
Quote:
Originally Posted by chriss85 View Post
Just a rough sketch:
scalar volume = 0;
forAll(mesh, cellI)
{
if(mesh.C().x() <= 0)
volume += mesh.V()[cellI]*alpha1[cellI];
}
That was my first try as well, but it gives an incorrect value. I link to a solution to the problem in my previous post.
Edwon is offline   Reply With Quote

Old   September 16, 2015, 15:56
Default
  #5
Senior Member
 
Wouter van der Meer
Join Date: May 2009
Location: Elahuizen, Netherlands
Posts: 203
Rep Power: 18
wouter is on a distinguished road
hello Edwon,
Did you try this with a little larger volume, because it could be a numerical accuracy problem.

hope this helps,
Wouter
wouter is offline   Reply With Quote

Old   September 17, 2015, 05:40
Default
  #6
Senior Member
 
Join Date: Oct 2013
Posts: 397
Rep Power: 19
chriss85 will become famous soon enough
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.
Edwon likes this.
chriss85 is offline   Reply With Quote

Old   September 17, 2015, 06:20
Default
  #7
New Member
 
Edwin
Join Date: Nov 2014
Posts: 5
Rep Power: 12
Edwon is on a distinguished road
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.
Edwon is offline   Reply With Quote

Reply

Tags
integration, interfoam, sum()


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
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


All times are GMT -4. The time now is 17:39.