CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

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

Register Blogs Community New Posts Updated Threads Search

Like Tree11Likes
  • 8 Post By cliffoi
  • 2 Post By fanny
  • 1 Post By fanny

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 18, 2011, 12:48
Default How to calculate the gradient along the boundaries from a known volScalarFiled?
  #1
New Member
 
Join Date: Jul 2011
Posts: 2
Rep Power: 0
shddx1 is on a distinguished road
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!
shddx1 is offline   Reply With Quote

Old   October 27, 2011, 10:54
Default
  #2
Member
 
bojiezhang
Join Date: Jan 2010
Posts: 64
Rep Power: 16
bojiezhang is on a distinguished road
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!
bojiezhang is offline   Reply With Quote

Old   October 28, 2011, 19:04
Default
  #3
Member
 
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17
cliffoi is on a distinguished road
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
cliffoi is offline   Reply With Quote

Old   October 2, 2016, 05:04
Default
  #4
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 308
Rep Power: 12
alimea is on a distinguished road
Quote:
Originally Posted by cliffoi View Post
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
alimea is offline   Reply With Quote

Old   February 27, 2017, 06:08
Default gradients along boundaries.
  #5
New Member
 
Join Date: Feb 2016
Posts: 13
Rep Power: 10
fanny is on a distinguished road
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
freuen and linyanx like this.
fanny is offline   Reply With Quote

Old   March 15, 2017, 15:38
Default
  #6
Member
 
Linyan X
Join Date: Dec 2015
Posts: 43
Rep Power: 11
linyanx is on a distinguished road
Quote:
Originally Posted by fanny View Post
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
linyanx is offline   Reply With Quote

Old   March 16, 2017, 04:41
Default
  #7
New Member
 
Join Date: Feb 2016
Posts: 13
Rep Power: 10
fanny is on a distinguished road
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 likes this.
fanny is offline   Reply With Quote

Old   March 16, 2017, 11:47
Default
  #8
Member
 
Linyan X
Join Date: Dec 2015
Posts: 43
Rep Power: 11
linyanx is on a distinguished road
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.
linyanx is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF-How to calculate gradient of a scalar Tony Tonton Fluent UDF and Scheme Programming 19 November 20, 2023 09:13
how to calculate the temperature gradient of wall houbaolin FLUENT 0 July 28, 2008 03:51
Calculate normal gradient Sunil FLUENT 0 April 30, 2008 17:44
calculate the temperature gradient on a profile arther FLUENT 0 April 20, 2006 00:12
how to calculate the gradient of volume fraction hxhua FLUENT 0 July 1, 2005 09:43


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