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

LinkBack  Thread Tools  Display Modes 
July 18, 2011, 11:48 
How to calculate the gradient along the boundaries from a known volScalarFiled?

#1 
New Member
Join Date: Jul 2011
Posts: 2
Rep Power: 0 
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! 

October 27, 2011, 09:54 

#2 
Member
bojiezhang
Join Date: Jan 2010
Posts: 64
Rep Power: 9 
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! 

October 28, 2011, 18:04 

#3 
Member
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 91
Rep Power: 10 
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 nonorthogonality 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 

October 2, 2016, 04:04 

#4  
Member
A. Min
Join Date: Mar 2015
Posts: 67
Rep Power: 4 
Quote:
could you please explain about it more? Where should we get this command: p.boundaryField()[patchI].snGrad(); ?? Thanks 

February 27, 2017, 06:08 
gradients along boundaries.

#5 
New Member
Join Date: Feb 2016
Posts: 4
Rep Power: 3 
p { marginbottom: 0.1in; lineheight: 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 xcoordinate of the gradient cancels along inlet: grad(p)[x] = 0 2) the ycoordinate 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 

March 15, 2017, 15:38 

#6  
New Member
Linyan X
Join Date: Dec 2015
Posts: 23
Rep Power: 3 
Quote:
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 

March 16, 2017, 04:41 

#7 
New Member
Join Date: Feb 2016
Posts: 4
Rep Power: 3 
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 

March 16, 2017, 11:47 

#8 
New Member
Linyan X
Join Date: Dec 2015
Posts: 23
Rep Power: 3 
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. 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
UDFHow to calculate gradient of a scalar  Tony Tonton  Fluent UDF and Scheme Programming  17  September 21, 2015 09:13 
how to calculate the temperature gradient of wall  houbaolin  FLUENT  0  July 28, 2008 02:51 
Calculate normal gradient  Sunil  FLUENT  0  April 30, 2008 16:44 
calculate the temperature gradient on a profile  arther  FLUENT  0  April 19, 2006 23:12 
how to calculate the gradient of volume fraction  hxhua  FLUENT  0  July 1, 2005 08:43 