CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   varying cp with temperature . (https://www.cfd-online.com/Forums/openfoam-programming-development/84704-varying-cp-temperature.html)

balkrishna February 7, 2011 04:50

varying cp with temperature .
 
In the buoyantBousinessqSimpleFoam solver i want to vary my Cp with temperature . How should i write the program for this ?

balkrishna February 8, 2011 05:08

As a start , lets say i want to vary Cp in the following manner :
Cp = C*tanh(mT) ;

I write the program in the following manner :
Code:

Info<<" Reading field Cp "<<endl ;
    volScalarField Cp
    (
        IOobject
        (
            "Cp",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

Info<<" Reading field C "<<endl ;
    volScalarField C
    (
        IOobject
        (
            "C",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

and in readTransportProperties.H
Code:

dimensionedScalar m (laminarTransport.lookup("m"));
m will have dimensions of [ 0 0 0 -1 0 0 0]
In TEqn.H i have the added a source term . and hence need Cp . I add it in the following manner .
Code:

Cp = C*tanh(mT);
followed by the temperature equation .

This compiles fine but when i run the program i get the following error :
Code:

--> FOAM FATAL ERROR:
Argument of trancendental function not dimensionless

    From function trans(const dimensionSet& ds)
    in file dimensionSet/dimensionSet.C at line 370.

Does any1 have a clue to solve this ???

chandramurthy February 8, 2011 11:25

i think, this is something to do with dimensional consistency for LHS and RHS. From the error message it may said that the term "C*tanh(mT)" should have the units of cp.

An alternative way is use JANAF tables.

nimasam February 8, 2011 16:24

1) you can use thermodynamic table which is implemented in open foam
2) but whats the dimension of c and cp, does they have the same dimensions?
if yes,
try it
forAll (C,celli)
{cp[celli]=c[celli]*tanh(m*T[celli])
}
or
define m as dimless and use T.value() to get just the value of it

balkrishna February 8, 2011 21:09

@chandramurthy : C has the dimensions of Cp and m*T is dimensionless. .... m has dimensions of [ 0 0 0 -1 0 0 0 ] while T has that of [0 0 0 1 0 0 0].... The error says that m*T is not dimensionless .... which is not very clear to me ...

balkrishna February 8, 2011 21:19

@nimasam : C and Cp have the same dimensions . regarding the loop you have suggested when i declare C and Cp as volScalarFields and simply do Cp = C*tanh(m*T) shouldnt it be executed on all cells ?

nimasam February 8, 2011 21:50

u are right, every thing seems correct! but those two suggested methods were to insure that variable are dimensionless

balkrishna February 8, 2011 23:02

@nimasam I get the following error for the first one :
error: ‘struct Foam::volScalarField’ has no member named ‘value’

for the second one :
error: cannot convert ‘Foam::dimensioned<double>’ to ‘double’ in assignment

alberto February 9, 2011 01:01

Hi,

value() is a method for scalars, not for volScalarFields. You have to loop over cells to use it.

Did you check mT is actually dimensionless (you did not say how you define it in the code).

Best,

balkrishna February 9, 2011 04:13

@alberto i define m in transportProperties in the following manner :
Code:

m                m [0 0 0 -1 0 0 0] 0.2;
to read m i define it in readTransportProperties.H
as
Code:

dimensionedScalar m (laminarTransport.lookup("m"));
and T is temperature i.e. [0 0 0 1 0 0 0] . I loop over cells in the above mentioned manner and i got the following error :
Code:

error: cannot convert ‘Foam::dimensioned<double>’ to ‘double’ in assignment
basically that means i cant declare m in readTransportProperties.H . Then what is the workaround ?

alberto February 9, 2011 04:21

Use

m.value()

However it should really work with fields without looping.

Best,

karthik1414 February 9, 2011 04:32

about janafthermo
 
Quote:

Originally Posted by chandramurthy (Post 294243)
i think, this is something to do with dimensional consistency for LHS and RHS. From the error message it may said that the term "C*tanh(mT)" should have the units of cp.

An alternative way is use JANAF tables.

hello,
i am very new to openfoam, is it possible to use janafthermo.H while using the interfoam solver?? basically i want to vary Cp and density with temperature and pressure in a 2 phase incompressible vof problem.
Please help me out in this matter.
regards,
karthik

balkrishna February 9, 2011 04:43

that gives the following error :
Code:

error: call of overloaded ‘tanh(double)’ is ambiguous

balkrishna February 9, 2011 05:05

problem solved . Thanks everyone . I was including the variation in a header file . Once this was removed and added it in TEqn.H ... it worked ... thanks a lot for your help .

nimasam February 9, 2011 05:12

ambiguous
 
Quote:

Originally Posted by balkrishna (Post 294363)
that gives the following error :
Code:

error: call of overloaded ‘tanh(double)’ is ambiguous

i know ur problem get solve but for who to seek answer for this problem:

use Foam::tanh(....) instead of tanh() , it will cure the pain;)

balkrishna February 10, 2011 07:10

In case of varying Cp with temperature , i wish to vary it conditionally .
What i mean is :
for T < Tvalue
Cp = f(T) ;
for T >= Tvalue
Cp = g(T) ;

in such a case i am not able to use the standard operators like >= or > or <
My code is as follows:
Code:

forAll(T,celli)
      {
        if ( T[celli] >= Tleft && T[celli] <= Tmid)
          {
            Cp[celli] = 1000*41.2/50.0 * (T[celli] - Tleft) +  cpConstant;
          }
        else if ( T[celli] > Tmid && T[celli] <= Tright )
          {
            Cp[celli] = -1000*41.2/50 * ( T[celli] - Tright ) + cpConstant;
          }
      }

I get the following error :
Code:

TEqn.H: In function ‘int main(int, char**)’:
TEqn.H:23: error: no match for ‘operator>=’ in ‘T.Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::<anonymous>.Foam::DimensionedField<double, Foam::volMesh>::<anonymous>.Foam::Field<double>::<anonymous>.Foam::List<double>::<anonymous>.Foam::UList<T>::operator[] [with T = double](celli) >= Tleft’
TEqn.H:23: error: no match for ‘operator<=’ in ‘T.Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::<anonymous>.Foam::DimensionedField<double, Foam::volMesh>::<anonymous>.Foam::Field<double>::<anonymous>.Foam::List<double>::<anonymous>.Foam::UList<T>::operator[] [with T = double](celli) <= Tmid’
TEqn.H:25: error: cannot convert ‘Foam::dimensioned<double>’ to ‘double’ in assignment
TEqn.H:27: error: no match for ‘operator>’ in ‘T.Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::<anonymous>.Foam::DimensionedField<double, Foam::volMesh>::<anonymous>.Foam::Field<double>::<anonymous>.Foam::List<double>::<anonymous>.Foam::UList<T>::operator[] [with T = double](celli) > Tmid’
TEqn.H:27: error: no match for ‘operator<=’ in ‘T.Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::<anonymous>.Foam::DimensionedField<double, Foam::volMesh>::<anonymous>.Foam::Field<double>::<anonymous>.Foam::List<double>::<anonymous>.Foam::UList<T>::operator[] [with T = double](celli) <= Tright’
TEqn.H:29: error: cannot convert ‘Foam::dimensioned<double>’ to ‘double’ in assignment
/home/ifmg/OpenFOAM/OpenFOAM-1.7.0/src/finiteVolume/lnInclude/readSIMPLEControls.H:9: warning: unused variable ‘transonic’
make: *** [Make/linux64GccDPOpt/buoyantBoussinesqSimpleFoam.o] Error 1

In the above case , Tmid , Tleft , Tright are dimensionedScalars defined in the following manner :
Code:

In readTransportProperties.H
dimensionedScalar  Tleft (laminarTransport.lookup("Tleft"));
dimensionedScalar  Tright (laminarTransport.lookup("Tright"));
dimensionedScalar  Tmid (laminarTransport.lookup("Tmid"));

How should i use the conditional operators in this case ?

nimasam February 10, 2011 07:29

dear friend you can not assign a dimension Scalar to a scalar so use value()

Tleft.value() and so on

balkrishna February 10, 2011 07:44

thanks ,

that was a lesson learnt ....

balkrishna February 22, 2011 05:07

I am solving a heat transfer problem with water as fluid . So far I am using the buoyantBousinessqSimpleFoam solver . This solver however has the temperature formulation instead of the enthalpy formulation for the energy equation . That is correct considering that Cp and rho are assumed to be constant . I wish to formulate the energy equation using enthalpy . Can any of the already available solvers do this ? I went through the tutorials of solvers which are present in OF170 , what i found was that all of them used the working substance as air , assuming it as a perfectGas . This was declared in constant/thermophysicalProperties as :
Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  1.7.0                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.com                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    object      thermophysicalProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

thermoType      hPsiThermo<pureMixture<constTransport<specieThermo<hConstThermo<perfectGas>>>>>;

mixture        air 1 28.96 1004.4 0 1.831e-05 0.705;

// ************************************************************************* //

How do i use solvers like buoyantPimpleFoam for water ?

balkrishna February 22, 2011 07:24

When i rewrite the enthalpy equation as :
Code:

fvScalarMatrix hEqn
          (
          fvm::ddt(rho, h)
          + fvm::div(phi, h)
          ==
            fvm::laplacian(k,T)
          + DpDt + heatSource
          );
//In the above , k is thermal conductivity , T is temperature , h is enthalpy .

I get the following error :
Code:

incompatible fields for operation
    [h] == [T]

    From function checkMethod(const fvMatrix<Type>&, const fvMatrix<Type>&)
    in file /home/ifmg/OpenFOAM/OpenFOAM-1.7.0/src/finiteVolume/lnInclude/fvMatrix.C at line 1181.

How to overcome it ?

akidess February 22, 2011 07:44

It means that you are trying to solve for two variables within one equation.

balkrishna February 22, 2011 07:49

Thanks. That is clear . However a formulation like below ,
Code:

fvScalarMatrix hEqn
    (
        fvm::ddt(rho, h)
      + fvm::div(phi, h)
      - fvm::laplacian(turbulence->alphaEff(), h)
    ==
        DpDt
    );

assumes constant k . How does one program without the constant k assumption ?

RaghavendraRohith July 18, 2013 05:12

Hi BalKrishna

Have you found the solution for this problem. How can some body solve 2 variables here.

Regards
Rohith

wadekar June 16, 2015 10:10

Dear sir,
I am getting the error after using Foam::tanh(...)

The error is: call of overloaded ‘tanh(const int&)’ is ambiguous
c[ignCell] =1-Foam::tanh(ignSite.cells()[icelli]);

The code is:

forAll(ign.sites(), i)
{
const ignitionSite& ignSite = ign.sites()[i];

if (ignSite.igniting())
{
forAll(ignSite.cells(), icelli)
{
label ignCell = ignSite.cells()[icelli];

c[ignCell] =1-Foam::tanh(ignSite.cells()[icelli]);
}
}
}

wadekar June 16, 2015 10:18

Dear sir,
I am getting the error after using Foam::tanh(...)

The error is: call of overloaded ‘tanh(const int&)’ is ambiguous
c[ignCell] =1-Foam::tanh(ignSite.cells()[icelli]);

The code is:

forAll(ign.sites(), i)
{
const ignitionSite& ignSite = ign.sites()[i];

if (ignSite.igniting())
{
forAll(ignSite.cells(), icelli)
{
label ignCell = ignSite.cells()[icelli];

c[ignCell] =1-Foam::tanh(ignSite.cells()[icelli]);
}
}
}

RaghavendraRohith June 16, 2015 10:41

Hi Sandip,

I hope tanh in openfoam takes only a value i.e if you define a dimensionedScalar then please define its value. See that there exists no Fields. I See Ignsites is a constant, i am not sure. If you can define it so.

Best Regards,
Rohith

wadekar June 16, 2015 11:09

Thanks Raghavendra

I have tried with the interger value 5,
but still i am getting the same error:

call of overloaded ‘tanh(int)’ is ambiguous
c[ignCell] =Foam::tanh(5);

wadekar June 18, 2015 03:32

Hello friends,
I am compile the below mention code and i am getting the error

error: ‘distance’ was not declared in this scope
c = Foam::tanh[distance];

Code:


pointField meshPoints(mesh.points());
      label i(0);
     
      forAll( meshPoints, kk)
      { 
        vector curPoint = meshPoints[kk];
        vector distance = curPoint - vector(0, 0, 0);
   
        i++;
    scalar dis = mag(distance);   
        Info<< "distance = " << dis << endl;
 
      }
      Info << i << "  Points are changed" << endl;
     
    volScalarField  c = Foam::tanh[distance];


elham usefi June 30, 2016 17:32

Quote:

Originally Posted by balkrishna (Post 296408)
When i rewrite the enthalpy equation as :
Code:

fvScalarMatrix hEqn
          (
          fvm::ddt(rho, h)
          + fvm::div(phi, h)
          ==
            fvm::laplacian(k,T)
          + DpDt + heatSource
          );
//In the above , k is thermal conductivity , T is temperature , h is enthalpy .

I get the following error :
Code:

incompatible fields for operation
    [h] == [T]

    From function checkMethod(const fvMatrix<Type>&, const fvMatrix<Type>&)
    in file /home/ifmg/OpenFOAM/OpenFOAM-1.7.0/src/finiteVolume/lnInclude/fvMatrix.C at line 1181.

How to overcome it ?


Hi i knw this post is old but i need help on this problem :D
in my case Cp varies in different locations, so I need to write energy equation with enthalpy. I wrote it like this:
Code:

  fvScalarMatrix EEqn
    (
        fvm::div(phi, E)
      - fvm::laplacian(k_n/cp, E)
    ==
        fvOptions(rho,E)
    );

    EEqn.relax();

    fvOptions.constrain(EEqn);

    EEqn.solve();

    fvOptions.correct(E);
    T=E/cp;
    rhok = (1.0 - beta*(T - TRef));

but I got unrealistic solution that diverges!
can u help me?:confused:

RaghavendraRohith July 1, 2016 01:09

Hi,

The only error i see is that you have defined enthalpy as E=cp*T But it is
deltaE = cp*deltaT.

Hope it helps

Regards,
Rohith

elham usefi July 3, 2016 18:12

Quote:

Originally Posted by RaghavendraRohith (Post 607515)
Hi,

The only error i see is that you have defined enthalpy as E=cp*T But it is
deltaE = cp*deltaT.

Hope it helps

Regards,
Rohith

HI!
thank u for ur response:) but I didnt get it!:confused: if we replace E with cp*T in
Code:

    (
        fvm::div(phi, E)
      - fvm::laplacian(k_n/cp, E)
    ==
        fvOptions(rho,E)
    );

the result would be like:
Code:

    (
        fvm::div(phiCp, T)
      - fvm::laplacian(k_n, T)
    ==
        fvOptions(rhoCp,T)
    );

so isnt EEqn correct?

actually first I tried TEqn like this:
Code:

    (
        fvm::div(phiCp, T)
      - fvm::laplacian(k_n, T)
    ==
        fvOptions(rhoCp,T)
    );

but I didnt get correct results!
but when I assume that cp is constant! like this:
Code:

    (
        cp*fvm::div(phi, T)
      - fvm::laplacian(k_n, T)
    ==
        fvOptions(rhoCp,T)
    );

I get good results! although the variation of cp is not very significant!
so I tried EEqn :D


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