CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   A general openfoam development question about boundary condition (http://www.cfd-online.com/Forums/openfoam/88258-general-openfoam-development-question-about-boundary-condition.html)

kaifu May 12, 2011 06:30

A general openfoam development question about boundary condition
 
Hi Foamers,

A general question: could I use a boundary condition that would be updated from time to time in openfoam? for example, on a wall patch, I would like to specify my wall temperature. But I cannot apply the zero gradient or fixed value into wall condition because it is in function of other parameters. Of course I can get the specified value for each wall patch during calculation. My question is could i put the value directly into the wall patch? like
Code:

Tw[iFace]=...value...
Thanks.

//Kai

Bernhard May 12, 2011 07:27

I would advise you to have a look at groovyBC or swak4Foam

http://openfoamwiki.net/index.php/Contrib_groovyBC
http://openfoamwiki.net/index.php/Contrib/swak4Foam

kaifu May 14, 2011 10:50

Hi Bernhard

Thanks for your advice! After using the library groovyBC in swak4Foam, I still have some questions. First of all, I would like specify my problem. It is about near wall cell's liquid temperature and wall patch temperature. I would like to set the wall patch temperature to a value which could be obtained by other sub models. And then I will calculate the liquid temperature in a energy eq. I hope in the liquid energy eq. I could use this "wall temperature" for boundary conditions instead of the value of zero gradient interpolation of liquid temperature in near wall cells.

I have thought if I could set the specified value into each wall patch, but it doesn't work obviously. And the lib groovyBC could not set a value for a specified face label "iFace" as well. I figured out I could create a volScalarField Tw with zero gradient boundary conditions. Each time I put a value into the cell center of field Tw for near wall cells and hope its value on the wall patch should be the same. And then the liquid enthalpy (or the temperature is similar) boundary conditions could be constructed as follows,

Code:

boundaryField
{
    ...
    walls
    {
        type                  groovyBC;
        variables            "cpl=1419.8;T_sat=359.881;H_sat=292530.0;"
        valueExpression  "cpl*(Tw-T_sat)+H_sat";
        value                uniform 269740;
    }
      ...
}

The above shows the initial boundary conditions for liquid enthalpy.

However, if i check the boundary conditions after several iteration of my solver, I get the output of enthalpy boundary conditions as,

Code:

boundaryField
{
    ...
    walls
    {
        type                    groovyBC;
        refValue                uniform 0;
        refGradient            uniform 0;
        valueFraction        uniform 1;
        value                    uniform 0;
        valueExpression      "0";
        gradientExpression  "0";
        fractionExpression  "1";
        variables              "cpl=1419.8;T_sat=359.881;H_sat=292530.0;";
        timelines      (
);
        lookuptables    (
);
    }
 ...
}

It seems I get a uniform value for the enthalpy BC. That is not what I wanted, since Tw is not a uniform volScalarField. That is really a big confusion. I wonder if I get something wrong when I used the groovyBC...

// Kai

benk May 14, 2011 15:12

Here's a way to do it without groovyBC:


Just say your patch name is "WallBoundary", and your field name is "Temperature" then set the boundary for the Temperature field to a fixedValue.

Then, to change that fixedValue during runtime, use this code:
Code:

fixedValueFvPatchScalarField& WallTemperature = refCast<fixedValueFvPatchScalarField>(Temperature.boundaryField()[WallBoundary]);       
scalarField& TemperatureValue  = WallTemperature;

forAll (TemperatureValue,i) {
TemperatureValue[i] = <INSERT WHATEVER VALUE YOU WANT>;
}

There's a bit more info here: http://www.cfd-online.com/Forums/ope...tml#post271623

which also explains how to do it for a fixedGradient boundary type.

kaifu May 14, 2011 19:55

Hi Ben,

Thanks for you advice. I will look into the codes.


BTW there is a bug in swak4Foam apparently. After I compiled the main lib swak4FoamParsers and lib groovyBC, it seems the environment of openfoam changed. If I type 'icoFoam -help' in cmd, it doesn't work unless i "source /opt/openfoam171/etc/bashrc" again. And all the solver do not work any more. It always comes out
Quote:

icoFoam: error while loading shared libraries: libfiniteVolume.so: cannot open shared object file: No such file or directory
when i test some case. Anybody knows how to figure it out? Thx.

// Kai


kaifu May 15, 2011 05:34

Hi Ben and Foamers, again,

When I used the code above, it seems a new field is created, which means I lose the mesh info. i.e. the 'i' in
Code:

forAll (TemperatureValue,i)
does not refer to iCell or iFace in mesh any more. Any suggestion? Thx.

// Kai

benk May 15, 2011 10:26

Quote:

Originally Posted by kaifu (Post 307669)
When I used the code above, it seems a new field is created, which means I lose the mesh info. i.e. the 'i' in
Code:

forAll (TemperatureValue,i)
does not refer to iCell or iFace in mesh any more. Any suggestion? Thx.

In this case, it will only loop over the boundary values of the WallBoundary patch. So index i=0..n refers to the ith boundary node of the Temperature field, not the internal nodes of the Temperature field. To get the internal nodes, you can do a forAll(Temperature, i) loop, which will go through all internal mesh points but not the boundary points.

gschaider May 16, 2011 09:31

Quote:

Originally Posted by kaifu (Post 307646)
Hi Ben,

Thanks for you advice. I will look into the codes.


BTW there is a bug in swak4Foam apparently. After I compiled the main lib swak4FoamParsers and lib groovyBC, it seems the environment of openfoam changed. If I type 'icoFoam -help' in cmd, it doesn't work unless i "source /opt/openfoam171/etc/bashrc" again. And all the solver do not work any more. It always comes out

when i test some case. Anybody knows how to figure it out? Thx.

// Kai

As long as you compiled it with a straight ./Allwmake there should be no such problem. If you used the Makefile I can't guarantee for anything

kriztof August 1, 2011 09:35

Quote:

Originally Posted by benk (Post 307643)
Here's a way to do it without groovyBC:


Just say your patch name is "WallBoundary", and your field name is "Temperature" then set the boundary for the Temperature field to a fixedValue.

Then, to change that fixedValue during runtime, use this code:
Code:

fixedValueFvPatchScalarField& WallTemperature = refCast<fixedValueFvPatchScalarField>(Temperature.boundaryField()[WallBoundary]);       
scalarField& TemperatureValue  = WallTemperature;

forAll (TemperatureValue,i) {
TemperatureValue[i] = <INSERT WHATEVER VALUE YOU WANT>;
}

There's a bit more info here: http://www.cfd-online.com/Forums/ope...tml#post271623

which also explains how to do it for a fixedGradient boundary type.

I find your clue very valuable. However, I still have a following problem...
I use buoyantPimpleFoam and I want to be able to change patch temperatures (BC type = fixedValue).
In order to be able to read the temperatures during the calculations, I have added the following line to the createFields.H:

Code:

    autoPtr<basicRhoThermo> pThermo
    (
        basicRhoThermo::New(mesh)
    );
    basicRhoThermo& thermo = pThermo();

    const volScalarField& T = thermo.T(); // MY NEW LINE

Now I used your code, to change field T at each time step, but I get a compilation error:
Code:

from buoyantPimpleFoam_FDM.C:36:
/opt/openfoam200/src/OpenFOAM/lnInclude/typeInfo.H: In function ‘To&
Foam::refCast(From&) [with To = Foam::fixedValueFvPatchField<double>,
From = const Foam::fvPatchField<double>]’:
buoyantPimpleFoam_FDM.C:277:  instantiated from here
/opt/openfoam200/src/OpenFOAM/lnInclude/typeInfo.H:110: error: cannot dynamic_cast
 ‘(const Foam::fvPatchField<double>&)((const Foam::fvPatchField<double>*)r)’ (of type ‘const struct Foam::fvPatchField<double>&’) to type ‘class
Foam::fixedValueFvPatchField<double>&’ (conversion casts away constness)

It is probably because I defined field T as const, but otherwise I am not able to define it at all, because I get:
Code:

error: invalid initialization of reference of type ‘Foam::volScalarField&’
from expression of type ‘const Foam::GeometricField<double, Foam::fvPatchField,
 Foam::volMesh>’

How to overcome this?

Thanks in advance for any help...

desert_1250 August 27, 2011 03:00

Hi, i hope that you are well,
can everey one tell me how to define the (( 1-exp(-y^2)+0.5Cos2t)) profile with groovyBC? i can do ((1-exp(-y^2)) with nonuniform BCs and 0.5Cos2t with oscillating BCs, but i dont know how to exert the summation of these two profile at inlet BCs

____
Rasoul

gschaider August 27, 2011 11:09

Quote:

Originally Posted by desert_1250 (Post 321871)
Hi, i hope that you are well,
can everey one tell me how to define the (( 1-exp(-y^2)+0.5Cos2t)) profile with groovyBC? i can do ((1-exp(-y^2)) with nonuniform BCs and 0.5Cos2t with oscillating BCs, but i dont know how to exert the summation of these two profile at inlet BCs

____
Rasoul

I don't quite get your problem: groovyBC supports the summation of expressions (with the + operator. This is a notation that is not uncommon in the scientific literature. In fact: you used it too in your question)

mcdonalds August 15, 2012 12:51

Which file do I put this code in?
 
Quote:

Originally Posted by benk (Post 307643)
Here's a way to do it without groovyBC:


Just say your patch name is "WallBoundary", and your field name is "Temperature" then set the boundary for the Temperature field to a fixedValue.

Then, to change that fixedValue during runtime, use this code:
Code:

fixedValueFvPatchScalarField& WallTemperature = refCast<fixedValueFvPatchScalarField>(Temperature.boundaryField()[WallBoundary]);   
scalarField& TemperatureValue  = WallTemperature;

forAll (TemperatureValue,i) {
TemperatureValue[i] = <INSERT WHATEVER VALUE YOU WANT>;
}

There's a bit more info here: http://www.cfd-online.com/Forums/ope...tml#post271623

which also explains how to do it for a fixedGradient boundary type.

which file do I put this code in?


All times are GMT -4. The time now is 04:34.