CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM

access to volume of the cells

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   February 25, 2010, 05:14
Default access to volume of the cells
  #1
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 359
Rep Power: 11
romant is on a distinguished road
Hej,

I know that I can access the volume of the cells with mesh.V(). But for some reason, the following two lines of code give an error message upon compiling

Code:
const fvMesh& mesh = alpha1_.mesh();
const volScalarField& volumeCell = mesh.V();
The error message is
Code:
invalid initialization of reference of type ‘const Foam::volScalarField&’ from expression of type ‘const Foam::DimensionedField<double, Foam::volMesh>’
Does anybody have an idea why this assignment does not work?
__________________
~roman
romant is offline   Reply With Quote

Old   February 26, 2010, 02:09
Default
  #2
New Member
 
Vojtech Betak
Join Date: Mar 2009
Location: Czech republic
Posts: 28
Rep Power: 9
betakv is on a distinguished road
Hi,

try this const scalarField& Volumes = mesh.V();

Vojta
betakv is offline   Reply With Quote

Old   February 26, 2010, 03:54
Default half done
  #3
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 359
Rep Power: 11
romant is on a distinguished road
this worked for the part that it did not complain while compiling, the problem now is that it is not a volumeField anymore. therefore I can not use it in further calculations for volumefields like in this one

Code:
const volScalarField& p = alpha1_.db().lookupObject<volScalarField>("p");
    volScalarField limitedAlpha1 = min(max(alpha1_, scalar(0)), scalar(1));
    const fvMesh& mesh = alpha1_.mesh(); // get the underlying mesh
    const scalarField& volumeCell = mesh.V(); 

      limitedAlpha1 * rho1() * volumeCell * (Tsat_-Tinf_) * 
        combFrequency_/(ifg_ * (1-limitedAlpha1)),
      rho2()*0.0*combFrequency_*(pSat()/p)
I want to calculate the mass "rho1()*volumeCell*limitedAlpha1" of the water within the cell. How would I do this.
__________________
~roman
romant is offline   Reply With Quote

Old   March 3, 2010, 04:51
Default anyone
  #4
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 359
Rep Power: 11
romant is on a distinguished road
Does anyone have an idea? The goal is to have a volScalarField with dimensions m^3, containing the cell volumes in order to calculate further with it.

The programmer's guide gives

volScalarField foo = mesh.V(), but this assignment does not work.
__________________
~roman
romant is offline   Reply With Quote

Old   March 3, 2010, 05:42
Default
  #5
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 14
l_r_mcglashan will become famous soon enough
A quick fix might be to set the internalField of a volScalarField:

Code:
volumeCell.internalField() = mesh.V();
Edit: Corrected.
__________________
Laurence R. McGlashan :: Website

Last edited by l_r_mcglashan; March 3, 2010 at 06:10.
l_r_mcglashan is offline   Reply With Quote

Old   March 3, 2010, 05:51
Default
  #6
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Deltares, Delft, The Netherlands
Posts: 1,608
Rep Power: 25
ngj will become famous soon enoughngj will become famous soon enough
Hi

According to Doxygen, this is the following is the way to access the volume:

const Foam:imensionedField<double, Foam::volMesh> & foo = mesh.V();

See
http://foam.sourceforge.net/doc/Doxy...4cd0efe7fb3baa

Best regards,

Niels
ngj is offline   Reply With Quote

Old   March 3, 2010, 06:14
Default
  #7
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 359
Rep Power: 11
romant is on a distinguished road
Code:
const Foam::DimensionedField<double, Foam::volMesh> & volumeCell = mesh.V();
Does compile but then I run into the problem that I can't use it to calculate the mass or something else by simply multiplying it, because the operator "*" is not defined for this data type.

This is the reason I want a volScalarField, which contains the volume of each cell of the mesh. It doesn't even have to be dimensioned, because that can be fixed with work arounds. But it must be possible to somehow get the volume of each cell into a volScalarField.

Code:
const volScalarField& volumeCell.internalField() = mesh.V();
does not compile, neither does any other combination
__________________
~roman
romant is offline   Reply With Quote

Old   March 3, 2010, 06:39
Default
  #8
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Deltares, Delft, The Netherlands
Posts: 1,608
Rep Power: 25
ngj will become famous soon enoughngj will become famous soon enough
Hi

A work around, as you have spent a lot of time on this is to do for instance as follows:

// gamma being a volScalarField
scalarField V = mesh.V();
forAll(V,i)
{
gamma[i] *= V[i];
}

Good luck,

Niels
ngj is offline   Reply With Quote

Old   March 3, 2010, 09:14
Default
  #9
Senior Member
 
Jens Klostermann
Join Date: Mar 2009
Posts: 117
Rep Power: 8
jens_klostermann is on a distinguished road
I would go with Laurence idea:

volScalarField cellVolu
(
IOobject
(
"cellVolu",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("zero", dimVolume, 0.0)
);
cellVolu.internalField() = mesh.V();


At least for me it does the job!

Jens
jens_klostermann is offline   Reply With Quote

Old   March 3, 2010, 09:23
Default
  #10
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 359
Rep Power: 11
romant is on a distinguished road
Hej Jens, thanks for the reply, one more question about the following code snippet

Code:
volScalarField cellVolu
    (
    IOobject
       (
        "cellVolu",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
       ),
        mesh,
    dimensionedScalar("zero", dimVolume, 0.0)
    );   
    cellVolu.internalField() = mesh.V(); 
Do I integrate this code into the createFields.H and then read it out while in my solver like
Code:
const volScalarField& volumes = alpha1_.db().lookupObject<volScalarField>("cellVolu");
?
__________________
~roman
romant is offline   Reply With Quote

Old   March 3, 2010, 10:37
Default
  #11
Senior Member
 
Jens Klostermann
Join Date: Mar 2009
Posts: 117
Rep Power: 8
jens_klostermann is on a distinguished road
I don't know, what you want to do. But cellVolu gives you a field of the cell volumes (this is already of type volScalarField).
If alpha1 is your volume fraction denity*cellVolu gives you the mass per cell. (but this is not the answer?)

Hope it helps.

Jens
jens_klostermann is offline   Reply With Quote

Old   March 3, 2010, 10:50
Default
  #12
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 359
Rep Power: 11
romant is on a distinguished road
Thank you for this snippet. I will try the method tomorrow and see what I get.
__________________
~roman
romant is offline   Reply With Quote

Old   March 4, 2010, 07:36
Default thanks
  #13
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 359
Rep Power: 11
romant is on a distinguished road
Thanks, this worked wonderfully.
__________________
~roman
romant is offline   Reply With Quote

Reply

Tags
compiling issues, development, volume mesh

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
negative element volume (CFX-10.0) CFDworker CFX 8 September 27, 2011 18:16
BlockMesh FOAM warning gaottino OpenFOAM Native Meshers: blockMesh 7 July 19, 2010 14:11
FloWorks (Flow Express) Volume Goal Setting rbigelow Main CFD Forum 0 November 13, 2009 15:28
Calculating volume of Phase Pavan FLUENT 2 March 5, 2008 11:04
split volume Kabo FLUENT 1 January 28, 2008 08:08


All times are GMT -4. The time now is 14:00.