CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   starting off with OpenFOAM (

semaviso February 7, 2011 07:31

starting off with OpenFOAM

I am a new user of OpenFOAM and would like to solve an unsteady energy equation for a compressible gas through a porous media.

I have basic knowledge of C++ prograqming, please help.

thanx in advance

kathrin_kissling February 8, 2011 03:24

Hi semaviso,

have a look into the rhoReactingFoam application to see how its done there.
This is the general way to go. Look whether theres something you need.



semaviso February 16, 2011 09:21

thanx Kathrin

I checked it out and now I want to understand the meaning of:

00008 volScalarField rUA = 1.0/UEqn.A();
00009 U = rUA*UEqn.H();

from rhoReactingFoam/pEqn.H

How can I write Darcy's formula (U_gas = (-permK/mu)*grad(p) )
U_gas being the gas flux or velocity in m/s
in OpenFOAM to use with the mass transport equation.

thanx again for your help.:)

kathrin_kissling February 16, 2011 10:48

1. Question
This is part of the pressure velocity coupling see:
for details.

What is done:
UEqn.A() gives you the central coefficient of the the fvMatrix (fv=finiteVolume) UEqn.
UEqn.H() gives you the H operator which is basically

in that way the velocity is evaluated by U = rUA*UEqn.H();


2. Question
I'm not really sure what your trying to do. Can you specify a little?
Do you want to use your U_gas in the continuity equation?


Cyp February 16, 2011 17:37

Hi semaviso!

There are several way to solve your problem:

- either your add a source term in an existing momentum equation (for example rhoReactingFoam as suggested by Kathrin, or may be rhoPisoFoam will be easier to begin) :


    fvVectorMatrix UEqn
        fvm::ddt(rho, U)
      + fvm::div(phi, U)
      + turbulence->divDevRhoReff(U)
      - fvm::Sp(mu/K,U)

or you code your own porous media solver. For a incompressible flow, you have to solve the following diffusion equation on P variable :



It is not very difficult to adapt this porous solver to compressible flow (Darcy's law replaced within continuity equation).


kathrin_kissling February 17, 2011 03:40

Maybe you want to have a look into rhoPorousFoam. I never worked with it. But it sounds promising.



semaviso February 22, 2011 09:21

thanx guys it worked.

another question is, how do I add a source term to an energy balance equation if the source term is as follows: [deltaH - T(Cp_ss - Cp_s)]

deltaH : Heart of reaction
Cp_ss : saturated solid (porous media) heat capacity
Cp_s : solid (porous media) heat capacity

kathrin_kissling February 23, 2011 03:10

Which variable are you solving for in your energy equation T or h?

Best Kathrin

semaviso February 24, 2011 04:09

Hi Kathrin

I want "T" but I had used the energy equation with "h".
since h = Cp*T.

thanx in advance

kathrin_kissling February 25, 2011 05:07

could you post the equation you have?
Do you reconstruct the Temperature from the energy?



semaviso February 25, 2011 05:38

the equation is from

equation 1 of this publication.

I have decided to use h becouse i found a lot of hEqn.H file that I think have something almost similar to this equation.

Cyp February 25, 2011 05:47

Hi semaviso!

You should try something like that:



where the flux phi is defined as:

surfaceScalarField phi = rho*Cpg*linearInterpolate(U)&mesh.Sf();
(if rho or Cpg are volScalarField, you must use:


surfaceScalarField phi = fvc::interpolate(rho)*fvc::interpolate(Cpg)*linearInterpolate(U)&mesh.Sf();
Best Regards,

semaviso August 2, 2011 07:50

thank you a lot,

I have been tryin to modify the porousExplicitSourceReactingParcelFoam to solve for a compressible gas inside a porous reactor.


All times are GMT -4. The time now is 20:45.