CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   implement heat flux (http://www.cfd-online.com/Forums/openfoam-programming-development/84040-implement-heat-flux.html)

 Tobi January 18, 2011 18:19

implement heat flux

hey together,

i am using OF 1.7.x and working with OF for a half year now.
Using the chtMultiRegionSimpleFoam to solve the heat transfer from fluid to solid and
solid to solid.

The solutions are very good and now i want to implement the heat flux in the cht..Foam so that i can visual it like U / rho / etc in paraview.

First of all i want to implement the heat flux in my solid regions.
Code:

```Q = lambda / delta * A * dT  =  K * A * dT and q = Q/A  q = K * dT    (is this correct?)  q = - K * grad(T)```
I changed this files in the ~/applications/solver/heatTransfer/chtMultiRegionSimpleFoam/solid/:

createSolidFields.H
Code:

```         Info<< " Adding to fluxs\n" << endl;         fluxs.set         (             i,             new volScalarField             (                 IOobject                 (                     "flux",                     runTime.timeName(),                     solidRegions[i],                     IOobject::MUST_READ,                     IOobject::AUTO_WRITE                 ),                 solidRegions[i]             )         );```

setRegionSolidFields.H
Code:

```    volScalarField& flux = fluxs[i]; ```

solveSolid.H
Code:

``` for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)     {         fvScalarMatrix tEqn         (             -fvm::laplacian(K, T)         );         tEqn.relax();         eqnResidual = tEqn.solve().initialResidual();         maxResidual = max(eqnResidual, maxResidual);     // solving heatflux     fvScalarMatrix fluxEqn         (                     -K*fvc::grad(T)         );         fluxEqn.relax();         eqnResidual =          fluxEqn.solve().initialResidual();         maxResidual = max(eqnResidual, maxResidual);     } ```

Don 't know how to implement q = K * grad(T)
and if this code is correct ... ??? tried some other codes but always got an error...
Code:

```    fvScalarMatrix fluxEqn         (                     -K*fvc::grad(T)         );         fluxEqn.relax();         eqnResidual =          fluxEqn.solve().initialResidual();         maxResidual = max(eqnResidual, maxResidual); ```

Its the first time i want to add a equation and i am not sure how i have to implement this? I think i got all wrong or?

Can someone help me - thanks ?

Tobi

 eelcovv January 19, 2011 08:19

use groovyBC for setting wall heat fluxes

Hi Tobi

I can not immediately see what goes wrong in your code, but I would use groovyBC for setting heat fluxes. No need to rewrite you code, and it is very flexible (parallel run no problem, non-uniform and time dependent heat fluxes possible, only editing in bounary conditions of variables required, etc.). Have a look at my post

http://www.cfd-online.com/Forums/ope...r-restart.html

Regards

Eelco

 Tobi January 19, 2011 08:31

Hi Eelco,

thanks for you answer. I ll have a look at your post.

But you said that this is a BC. ? ?

Simple expamle. I have two walls parallel and know the temperature t_hot and t_cold. Further i know K and A and now i want to calculate the heat flux in both walls. Is this possible with groovyBC ?

And i know that the compilations error occurs with the following line:

Hmmm...
But i will have a look at groovyBC.
Thx.

Tobi

 Canesin January 19, 2011 08:46

You have to change the dictionary setting...

"MUST_READ" .. you SHOULDN'T read the that dict.. you need only to write in it.

Them, in the equation what you really have is: -K*grad(T) = 0 ... what you want is: flux = -K*grat(T).

That should do.

 eelcovv January 19, 2011 09:24

surfaceScalarField

Hi Toby

Sorry, I assumed you want to impose a heat flux at a wall. No, I don't think you can use groovyBC for internal faces.

Perhaps something is going wrong because you are mixing up a surfaceScalarField (i.e. scalar values defined at the cell faces) and volumeScalarField (i.e. scalar values defined at the cell centres).

Have a look at the wallHeatFlux utility for instance. Here you can see the difference between the both. More details can be found in the programmers Guide.

Good luck!

Regards,
Eelco

 Tobi January 19, 2011 09:54

Hi,

@eelcovv :) don 't matter :) but i 'll have a look at your advice.

@Canesin:

thats true - i just have to write in it so i changed the syntax to: NO_READ
I suppose that the flux - file is added automatically.
Further i changed the solveSolid.H:

Code:

```    for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)     {         fvScalarMatrix tEqn         (             -fvm::laplacian(K, T)         );         tEqn.relax();         eqnResidual = tEqn.solve().initialResidual();         maxResidual = max(eqnResidual, maxResidual);             fvScalarMatrix fluxEqn         (           flux = -K*fvc::grad(T)         );         fluxEqn.relax();         eqnResidual = fluxEqn.solve().initialResidual();         maxResidual = max(eqnResidual, maxResidual);     }```
or is this the correct form:

Code:

```    for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)     {         fvScalarMatrix tEqn         (             -fvm::laplacian(K, T)         );         tEqn.relax();         eqnResidual = tEqn.solve().initialResidual();         maxResidual = max(eqnResidual, maxResidual);     }     flux = -K*fvc::grad(T)```
I tried to compile both code's and got this error-message for the first code:

Code:

```tobi@shorty:~/OpenFOAM/OpenFOAM-1.7.x/applications/solvers/heatTransfer/chtMultiRegionSimpleFoam\$ wmake Making dependency list for source file chtMultiRegionSimpleFoam.C SOURCE=chtMultiRegionSimpleFoam.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-40 -Ifluid    -Isolid    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/finiteVolume/lnInclude    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/meshTools/lnInclude    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/thermophysicalModels/basic/lnInclude    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/turbulenceModels    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/turbulenceModels/compressible/turbulenceModel/lnInclude    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/turbulenceModels/compressible/RAS/lnInclude -IlnInclude -I. -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/OpenFOAM/lnInclude -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/OSspecific/POSIX/lnInclude  -fPIC -c \$SOURCE -o Make/linux64GccDPOpt/chtMultiRegionSimpleFoam.o In file included from chtMultiRegionSimpleFoam.C:79: solid/solveSolid.H: In function ‘int main(int, char**)’: solid/solveSolid.H:15: error: no match for ‘operator=’ in ‘fluxEqn = Foam::operator*(const Foam::tmp<Foam::GeometricField<double, PatchField, GeoMesh> >&, const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh](((const Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >&)((const Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >*)(& Foam::fvc::grad(const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&) [with Type = double]()))))’ /home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/finiteVolume/lnInclude/fvMatrix.C:867: note: candidates are: void Foam::fvMatrix<Type>::operator=(const Foam::fvMatrix<Type>&) [with Type = double] /home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/finiteVolume/lnInclude/fvMatrix.C:902: note:                void Foam::fvMatrix<Type>::operator=(const Foam::tmp<Foam::fvMatrix<Type> >&) [with Type = double] solid/setRegionSolidFields.H:1: warning: unused variable ‘mesh’ solid/setRegionSolidFields.H:3: warning: unused variable ‘flux’ solid/setRegionSolidFields.H:4: warning: unused variable ‘rho’ solid/setRegionSolidFields.H:5: warning: unused variable ‘cp’ make: *** [Make/linux64GccDPOpt/chtMultiRegionSimpleFoam.o] Fehler 1```
and for the second time that one:

Code:

```aking dependency list for source file chtMultiRegionSimpleFoam.C SOURCE=chtMultiRegionSimpleFoam.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-40 -Ifluid    -Isolid    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/finiteVolume/lnInclude    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/meshTools/lnInclude    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/thermophysicalModels/basic/lnInclude    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/turbulenceModels    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/turbulenceModels/compressible/turbulenceModel/lnInclude    -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/turbulenceModels/compressible/RAS/lnInclude -IlnInclude -I. -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/OpenFOAM/lnInclude -I/home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/OSspecific/POSIX/lnInclude  -fPIC -c \$SOURCE -o Make/linux64GccDPOpt/chtMultiRegionSimpleFoam.o In file included from chtMultiRegionSimpleFoam.C:79: solid/solveSolid.H: In function ‘int main(int, char**)’: solid/solveSolid.H:14: error: no match for ‘operator=’ in ‘flux = Foam::operator*(const Foam::tmp<Foam::GeometricField<double, PatchField, GeoMesh> >&, const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh](((const Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >&)((const Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >*)(& Foam::fvc::grad(const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&) [with Type = double]()))))’ /home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/OpenFOAM/lnInclude/GeometricField.C:1086: note: candidates are: void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=(const Foam::GeometricField<Type, PatchField, GeoMesh>&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh] /home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/OpenFOAM/lnInclude/GeometricField.C:1111: note:                void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=(const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh] /home/tobi/OpenFOAM/OpenFOAM-1.7.x/src/OpenFOAM/lnInclude/GeometricField.C:1147: note:                void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=(const Foam::dimensioned<Type>&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh] solid/setRegionSolidFields.H:1: warning: unused variable ‘mesh’ solid/setRegionSolidFields.H:4: warning: unused variable ‘rho’ solid/setRegionSolidFields.H:5: warning: unused variable ‘cp’ make: *** [Make/linux64GccDPOpt/chtMultiRegionSimpleFoam.o] Fehler 1```
The error is in line 15: flux = -K*grad(T)
Something i did wrong. Can not interpret that error message completly

Tobi

 mvoss January 19, 2011 10:55

it´s just
flux.write;

no solve, no residual. did you forgot about some ";"?
Is it possible to make flux a volScalarField and then do smth. ON a patch; sounds mored like surfaceScalarField??!!

 Tobi January 19, 2011 11:54

Hi,

okay first of all i could compile my code but why can i compile that one:

Code:

` -K*fvc::snGrad(T) = flux;`
and here i got a error:

Code:

` flux = -K*fvc::snGrad(T);`