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 the gradient along the boundaries from a known volScalarFiled? (https://www.cfd-online.com/Forums/openfoam-programming-development/90681-how-calculate-gradient-along-boundaries-known-volscalarfiled.html)

shddx1 July 18, 2011 11:48

How to calculate the gradient along the boundaries from a known volScalarFiled?
 
Hi,

I first obtained a volScalarField in a calculation domain, and then I want to calculate the gradient along the domain boundaries.

Does anyone know how to obtain the gradient along domain boundaries from a known volScalarField?

Thank you very much!

bojiezhang October 27, 2011 09:54

hi shddx1:
I have the same problem with you ! I define a volScalrField first and the value is fixed for all the cells, but I want to caculate the gradient. Do you solve the problem, can you tell me? Thank you!

cliffoi October 28, 2011 18:04

You can obtain the surface normal gradient at each boundary using snGrad function.

p.boundaryField()[patchI].snGrad();

This will give you the surface normal gradient without any non-orthogonality or skewness corrections. If you need these corrections, use fvc::snGrad().

surfaceScalarField snGradP = fvc::snGrad(p);
Then access the value at the boundary with snGradP.boundaryField()[patchI].

If you are looking for a full gradient vector at the boundary, this is a little tricker. Here you will have to interpolate the field gradient (fvc::grad(p)) to the faces and then replace the surface normal component of this with the value coming from fvc::snGrad(p).

Hope this helps
Ivor

alimea October 2, 2016 04:04

Quote:

Originally Posted by cliffoi (Post 329934)
You can obtain the surface normal gradient at each boundary using snGrad function.

p.boundaryField()[patchI].snGrad();

This will give you the surface normal gradient without any non-orthogonality or skewness corrections. If you need these corrections, use fvc::snGrad().

surfaceScalarField snGradP = fvc::snGrad(p);
Then access the value at the boundary with snGradP.boundaryField()[patchI].

If you are looking for a full gradient vector at the boundary, this is a little tricker. Here you will have to interpolate the field gradient (fvc::grad(p)) to the faces and then replace the surface normal component of this with the value coming from fvc::snGrad(p).

Hope this helps
Ivor

Hi
could you please explain about it more?
Where should we get this command:
p.boundaryField()[patchI].snGrad();
??
Thanks

fanny February 27, 2017 05:08

gradients along boundaries.
 
p { margin-bottom: 0.1in; line-height: 120%; } Hi all,


I have a question concerning the calculation of gradients along boundaries.


Let's consider the flow of an incompressible viscous fluid through a channel. At inlet, the velocity is fixed. At outlet, the pressure is fixed to the constant value 0. I using the solver simpleFoam.


In my opinion, that should lead to the following results for the gradient of pressure :
n&grad(p) =0 at the inlet
grad(p) – n* (n&grad(p)) )=0 at the outlet.


For instance, iwith a 2D horizontal channel such that the inlet and outlet are vertical segments (i.e. n_inlet = (-1 0 0) and n_outlet=(1 0 0)), we should have
1) the x-coordinate of the gradient cancels along inlet: grad(p)[x] = 0
2) the y-coordinate of the gradient cancels along outlet: grad(p)[y] =0


But I do not obtain these results. Can anyone tell me what is wrong ? I do the following things:


0. In the file p, I enter the following boundary conditions for the pressure p (volScalarField) :


inlet
{
type zeroGradient;
}


outlet
{
type fixedValue;
value uniform 0;
}




Now I am looking at grad(p) (volVectorField). To to that I using a own postprocessing utility.


1. Firstly, I have simply tried :




Info<< "Calculate gradient " << endl;
volVectorField gradp0
(
IOobject
(
"gradp0",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
fvc::grad(p)
);
gradp0.write();






This return a file, named “gradp0”, containing the lines
type zeroGradient;
at inlet and outlet !!
In my opinion, that is completely wrong: the normal gradient of grad(p) does not have to cancel on inlet nor on outlet !




2. Secondly, I added the following code lines into my postprocessing utility :


Info<< "Explicitly express numerical values on borders" << endl;
volVectorField gradp
(
IOobject
(
gradp,
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
1.0*gradp0
);
forAll(gradp0.boundaryField(), patchI) /
{
gradp.boundaryField()[patchI] = gradp0.boundaryField()[patchI];
}
gradp.write();


This returns a file, named “gradp”, containing numerical values over the boundaries.
Using these numerical values, I can control that the normal gradient n.grad(p) cancels on inlet (i.e. that grad(p)[x]=0 in case of vertical inlet segment). Great !
But the tangential part of the gradient does not cancel on outlet (i.e. I don t have that grad(p)[y]=0 in case of vertical outlet segment). Why ? What is wrong ?


Thank you for your help !!!
Fanny

linyanx March 15, 2017 14:38

Quote:

Originally Posted by fanny (Post 638673)
p { margin-bottom: 0.1in; line-height: 120%; } Hi all,


I have a question concerning the calculation of gradients along boundaries.


Let's consider the flow of an incompressible viscous fluid through a channel. At inlet, the velocity is fixed. At outlet, the pressure is fixed to the constant value 0. I using the solver simpleFoam.


In my opinion, that should lead to the following results for the gradient of pressure :
n&grad(p) =0 at the inlet
grad(p) – n* (n&grad(p)) )=0 at the outlet.


For instance, iwith a 2D horizontal channel such that the inlet and outlet are vertical segments (i.e. n_inlet = (-1 0 0) and n_outlet=(1 0 0)), we should have
1) the x-coordinate of the gradient cancels along inlet: grad(p)[x] = 0
2) the y-coordinate of the gradient cancels along outlet: grad(p)[y] =0


But I do not obtain these results. Can anyone tell me what is wrong ? I do the following things:


0. In the file p, I enter the following boundary conditions for the pressure p (volScalarField) :


inlet
{
type zeroGradient;
}


outlet
{
type fixedValue;
value uniform 0;
}




Now I am looking at grad(p) (volVectorField). To to that I using a own postprocessing utility.


1. Firstly, I have simply tried :




Info<< "Calculate gradient " << endl;
volVectorField gradp0
(
IOobject
(
"gradp0",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
fvc::grad(p)
);
gradp0.write();






This return a file, named “gradp0”, containing the lines
type zeroGradient;
at inlet and outlet !!
In my opinion, that is completely wrong: the normal gradient of grad(p) does not have to cancel on inlet nor on outlet !




2. Secondly, I added the following code lines into my postprocessing utility :


Info<< "Explicitly express numerical values on borders" << endl;
volVectorField gradp
(
IOobject
(
gradp,
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
1.0*gradp0
);
forAll(gradp0.boundaryField(), patchI) /
{
gradp.boundaryField()[patchI] = gradp0.boundaryField()[patchI];
}
gradp.write();


This returns a file, named “gradp”, containing numerical values over the boundaries.
Using these numerical values, I can control that the normal gradient n.grad(p) cancels on inlet (i.e. that grad(p)[x]=0 in case of vertical inlet segment). Great !
But the tangential part of the gradient does not cancel on outlet (i.e. I don t have that grad(p)[y]=0 in case of vertical outlet segment). Why ? What is wrong ?


Thank you for your help !!!
Fanny

Hi Fanny,

I cannot answer your question. But after reading your question, I have a quick question regarding the volVectorField that you've gotten on your 1st try, named field'gardp0'. How can you implement this volVectorField term into the equation that you want to solve? Like, for example, UEqn.H in interFoam. I want to add the force vector term into the UEqn.H, written as 'interpolate(F)'. But the system will always complain about the format of this vector term.

Hence, I guess you may know this after reading your post. Really appreciate your help for any hints.

Regards,
Linyan

fanny March 16, 2017 03:41

Hi linyanx and all :)

I am not sure I am going to exactly answer your question ... I did not met any difficulty to implement gradp0 into equations.

Let us, for example, consider the solver simpleFoam. We can replace

solve(UEqn() == -fvc::grad(p));
with solve(UEqn() == -gradp0);
(line 18 in file applications/solvers/incompressible/simpleFoam/UEqn.H)

Do not forget to define grad0 with createFields.H by entering e.g.

Info<< "Calculate gradient " << endl;
volVectorField gradp0
(
IOobject
(
"gradp0",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
fvc::grad(p)
);
gradp0.write();

This definition must be placed after the p's definition.

We can also implement the definition of gradp given in the 2. of my previous post
(explicitly expressing numerical values on borders)

Nevertheless, the results of the simulations with original simpleFoam (using fvc::grad(p)) and the modified ones (using gradp0 or gradp) ARE NOT the same...

And this is my question : why ? what is wrong within the gradp0's and gradp's definitions ?

Thanks !!
Fanny

linyanx March 16, 2017 10:47

Thanks Fanny! Your hint inspired me! I now realise that the volVectorField term is not supposed to reconstruct. Hence, the 'F' term is written outside of 'reconstruct' structure. Please allow me to quote your answer to my post for future reader's reference.
Regards,
Antelope X.


All times are GMT -4. The time now is 16:57.