CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Heat source in a particular region inside the fluid domain (

robingilbert September 2, 2010 02:31

Heat source in a particular region inside the fluid domain
Hi i want to add a heat source inside a small region in a fluid domain. i added a heat source term in TEqn.H and it works fine for the whole region. But i want to impose a condition that the heat source gets activated inside a small control volume. i have been reading up a lot but cant figure out how to go about doing it. if atleast someone can tell me where to start, I will figure it out. how do i give an if-else condition to check if it is solving the domain i need to add the source term.

i tried the following in the createFields.H


volScalarField x = mesh.C().component(vector::X);
volScalarField y = mesh.C().component(vector::Y);
volScalarField z = mesh.C().component(vector::Z);

    if(x[celli] >= 1 && y[celli] >= 1 && z[celli] >= 2.2 && x[celli] <= 1.5 && y[celli] <= 1.5 && z[celli] <= 2.5)
      dimensionedScalar Q
      dimensionedScalar Q

unfortunately the Q value is not set by this method.


akidess September 2, 2010 03:32

You are just storing a single value for Q, so it will be either 1000 or 5000 depending if your conditions in the last cell are met or not. Additionally, you are declaring Q right within the curly brackets, so it will not be valid outside of the forAll loop.

What I think you want is to have a volScalarField Q, and then assign values to Q[celli].

robingilbert September 2, 2010 03:36

Thank you so much for your reply.

I will try it and let you know what happens.
Thanks once again.

su_junwei September 2, 2010 04:16

It seems you didn't set Q value, just declare a local Q. You can achieve it in a more compact form like the following code

point mint(1.0,1.0,2.2);
point max(1.5, 1.5, 2.5);
boundBox box(min, max);

forAll(Q, cellI)

robingilbert September 2, 2010 04:53

Hi junwei,

i tried your suggestion but i am getting the following error:


In file included from simpleFoam.C:44:
createFields.H: In function ‘int main(int, char**)’:
createFields.H:117: error: ‘Q’ was not declared in this scope
In file included from simpleFoam.C:62:
UEqn.H:16: error: no match for call to ‘(Foam::point) (Foam::scalar&, Foam::scalar&)’
In file included from simpleFoam.C:63:
pEqn.H:22: error: no match for call to ‘(Foam::point) (Foam::scalar&, Foam::scalar&)’
In file included from simpleFoam.C:64:
TEqn.H:14: error: ‘Q’ was not declared in this scope
TEqn.H:21: error: no match for call to ‘(Foam::point) (Foam::scalar&, Foam::scalar&)’

when compiling. do you know why that happens?

akidess September 2, 2010 05:02

Robin, in junwei's code Q is not created, you'll have add that before calling the code. See other forum threads or the wiki how to make a new volScalarField with a certain size.

Also, if Q doesn't change over time and is just determined by the spatial coordinates, you could use setFields (this is used eg. in interFoam / damBreak to preset a volScalarField gamma) instead of including the setup in your solver code.

su_junwei September 2, 2010 12:15

Yes, You have to declare a volScalarField for store source term for your temperature equation in your solver

robingilbert September 2, 2010 14:39

akidess and junwei,

thank you so much guys, for the suggestions. i defined Q as volScalarField and ran a test case with setFieldsDict and looks like its working the way i wanted. I will try it on the real case and see if it works.

thank you once again.

All times are GMT -4. The time now is 01:35.