CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   volScalarField for cell volumes and face surfaces (

AlmostSurelyRob December 11, 2010 13:41

volScalarField for cell volumes and face surfaces
Dear OpenFOAM Programmers,

I would appreciate your advice on two issues I am facing.

1) Is it possible to obtain cell volumes as volScalarField object?
2) Assume that for a given direction d and every cell I pick an adjacent surface that lies in direction of d. Is it possible to obtain cell surfaces as volScalarField object of a set defined this way?

I am fairly new to development of openFOAM but I do have some programming experience in C++. I am working with a copy of interFoam code OF. 1.7.1.

For question 1) I have found that I can get mesh.V() to obtain Volume but it is not of volScalarField type. How can I make a conversion?

Please, let me tell you that I am highly impressed by an objective nature of this CFD code. I am sure that if I had more time I would find the answer to questions in documentation. It's just I am pressed by time at the moment as I am struggling to supply a proof of concept.

MartinB December 11, 2010 17:33

Hey Rob,

ad 1)

volScalarField cellVolume
cellVolume.internalField() = mesh.V();

ad 2.)
What shall the volScalarField contain? The face number (an integer)? Or the face areas?
With the direction of d, do you want to start at the cell center of each cell?
Why do you need it as a volScalarField, can't you just loop over each cell and do calculations with the appropriate surface found?


AlmostSurelyRob December 13, 2010 06:24

Thanks Martin for your prompt reply! It worked like a a charm.

As for my second question. I'd like to have an interFoam with cyclic boundaries that keeps the mass flow rates of both phases constant. Something akin to channelFoam, but channelFoam is incompressible and therefore you can just worry for the superficial or average velocity (denoted by Ubar in channelFoam).

To keep my mass flow rate constant in simulation with cyclic boundaries I need to be able to calculate it, so I was thinking of doing

\Sigma_f{rho_1 \alpha_f u_f * S_f) = M1

where rho_1 density, S_f surface area, u_f velocity, \alpha phase fraction. Subsript denote faces in a cross-section perpendicular to the flow direction.

I also thought I could calculate volume weighted average of the above expression for the whole domain and hence my question.

Anyway having the above as an additional condition I decompose my velocity into an old value and correction. After some manipulations the surfaces appear in the correction expression for the gradient.

Does it make more sense now? I will value any comments.

So answering your questions, VolScalarField must contain surface areas.

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