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/)
-   -   How to calculate T+gradT where T is volScalarField and gradT is scalarField ??? (https://www.cfd-online.com/Forums/openfoam-programming-development/172204-how-calculate-t-gradt-where-t-volscalarfield-gradt-scalarfield.html)

Zhiheng Wang May 25, 2016 19:29

How to calculate T+gradT where T is volScalarField and gradT is scalarField ???
 
Hi, I have stuck in code where I am preprocesing Temperature values.

label patchID = mesh.boundaryMesh().findPatchID("inlet");
scalarField InletTGrad=T.boundaryField()[patchID].snGrad();
const scalarField HEIGHT = 1.0/mesh.deltaCoeffs().boundaryField()[patchID];
const fvBoundaryMesh& myBoundary = mesh.boundary();
forAll( myBoundary, fvPatchID ) /
{
const fvPatch& myPatch = myBoundary[patchID];
const vectorField& position = myPatch.Cf();
forAll( myPatch, i)
{
Ts.boundaryField()[fvPatchID][i] = Ts.boundaryField()[patchID][i]+HEIGHT*InletTGrad;
}
Problem is Ts is volScalarField and Height*InleGrad is scalarField
How can I update my boundary values using this code
plese Send your valuable suggetions.


Can we convert scalarField to volScalarField ?? or Can access scalarField element one by one

anishtain4 May 26, 2016 12:59

I'm not sure how this applies to you problem but you are using gradient and Height from inlet to update all of your boundaries, is this physically meaningful?

Your problem here is not about volScalarField and scalarField. your Ts.boundaryField()[patchID][i] is temperature on patchID on face i, which is a scalar, not field. While Height and InletTGrad are fields. if Height and InletTGrad are consistent (which I think they are) the scalar would be added to them, so right hand side runs well, but it's the = operator that gets you, OF can't figure out how to fill you scalar Ts.boundaryField()[fvPatchID][i] with a field you've just calculated.

Probably you want to average the Height*InletTGrad?

Zhiheng Wang May 26, 2016 16:41

Hello and Thank You very much for your quick reply
I have resolved the issue by the way I can explain it is a kind of Cold flow solver part which I need to apply to correct BC before producing spark
You may say its a kind of iterative BC.

yes Its like getting T[i]=T[i]+DT[i]

mesh.dettaCoeffs() gives 1/distance;
so HEIGTHT=1/mesh.deltaCoeffs().boundaryField()[patchID] will be face center to adjacent cell center distance ( difference of y co-ordinate for 2D case in X-Z plane);
inletTGrad gives normal gradient to plane.
Height[i]*InletGradT[i] gives DT[i] (for ith face-center)
I

anishtain4 May 27, 2016 10:12

I'm not sure if your reply is complete or not as I see a single "I" at the end.
But I just noticed another syntax error in definition of HEIGHT:
HEIGHT=scalar/scalarField, which is not defined in openFoam operator. you can't divide a scalar by a scalarField, it must be either two scalars or a cmptDivide(field1,field2).

Zhiheng Wang May 28, 2016 13:51

Hi Mahdi,
I am sorry for not typing is properly :( my mistake
The code segment is written as
I am having 16 faces at inlet which i have created for liquid patch for evaporative interface
const scalarField HEIGHT = 1.0/mesh.deltaCoeffs().boundaryField()[patchID];
Info<<endl<<" Normal distance between boundary face centre and cell centre is "<<HEIGHT<<endl;
OUTPUT is
Normal distance between boundary face centre and cell centre is
16
(
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
0.00333333
)
Regards


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