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

accessing internal cell gradient field at boundary when applying boundary condition

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By vishalsacharya

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 10, 2019, 17:19
Question accessing internal cell gradient field at boundary when applying boundary condition
  #1
Member
 
Vishal Achasrya
Join Date: Nov 2011
Posts: 38
Rep Power: 15
vishalsacharya is on a distinguished road
Hi,
I am looking at implementing a generic BC that also involves a second gradient at the boundary. Typically, if you look at zeroGradient or fixedGradient BC, the this->internalField value is available and then used to apply the values at the patch. For a second gradient, I need to take the gradient in the cell and then change its value first to a new gradient and then take the new gradient along with this->internalField to change the value at the patch. How do you generate gradient values in boundary cells only at the time of BC application so that there is low memory usage? A simple starting point is a zero second gradient BC upon which the generic BC can be built, but I am unsure how to get the gradient at the boundary internal field cells first. Also, the boundary patch face Sf() vector and the cell center C() at the boundary are also needed so that the correct component of the gradient along the cell-center-to-patch-center is used when applying/making changes.

Thanks in advance!
vishalsacharya is offline   Reply With Quote

Old   February 10, 2019, 18:07
Default
  #2
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
Quote:
Originally Posted by vishalsacharya View Post
Hi,
I am looking at implementing a generic BC that also involves a second gradient at the boundary. Typically, if you look at zeroGradient or fixedGradient BC, the this->internalField value is available and then used to apply the values at the patch. For a second gradient, I need to take the gradient in the cell and then change its value first to a new gradient and then take the new gradient along with this->internalField to change the value at the patch. How do you generate gradient values in boundary cells only at the time of BC application so that there is low memory usage? A simple starting point is a zero second gradient BC upon which the generic BC can be built, but I am unsure how to get the gradient at the boundary internal field cells first. Also, the boundary patch face Sf() vector and the cell center C() at the boundary are also needed so that the correct component of the gradient along the cell-center-to-patch-center is used when applying/making changes.

Thanks in advance!
Does this sound similar to your question? Gradient at the boundary
massive_turbulence is offline   Reply With Quote

Old   February 10, 2019, 18:11
Default
  #3
Member
 
Vishal Achasrya
Join Date: Nov 2011
Posts: 38
Rep Power: 15
vishalsacharya is on a distinguished road
Quote:
Originally Posted by massive_turbulence View Post
Does this sound similar to your question? Gradient at the boundary
Andrew, It is not similar to this thread. That thread concerns the discrepancy in applying gradient BCs at the boundary at a different method compared to that which is used in the internal cells for grad from fvSchemes. What I am asking for is on how to make a gradient field just for boundary cells that can then be used to make a second gradient calculation.
vishalsacharya is offline   Reply With Quote

Old   February 10, 2019, 20:45
Default
  #4
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
Quote:
Originally Posted by vishalsacharya View Post
Andrew, It is not similar to this thread. That thread concerns the discrepancy in applying gradient BCs at the boundary at a different method compared to that which is used in the internal cells for grad from fvSchemes. What I am asking for is on how to make a gradient field just for boundary cells that can then be used to make a second gradient calculation.
This might be on the right track, line 162 from fixedGradientFvPatchField.H

Code:
  //- Return gradient at boundary
             virtual Field<Type>& gradient()
             {
                 return gradient_;
             }
https://www.openfoam.com/documentati...8H_source.html

I would assume you make the gradient initially a fixedGradient.
There are other patch fields as well. You just have to find the right type and inherit from its class.
massive_turbulence is offline   Reply With Quote

Old   February 14, 2019, 19:22
Default
  #5
Member
 
Vishal Achasrya
Join Date: Nov 2011
Posts: 38
Rep Power: 15
vishalsacharya is on a distinguished road
Quote:
Originally Posted by massive_turbulence View Post
This might be on the right track, line 162 from fixedGradientFvPatchField.H

Code:
  //- Return gradient at boundary
             virtual Field<Type>& gradient()
             {
                 return gradient_;
             }
https://www.openfoam.com/documentati...8H_source.html

I would assume you make the gradient initially a fixedGradient.
There are other patch fields as well. You just have to find the right type and inherit from its class.
This function in that BC just returns the user supplied value for the "gradient" keyword in the BC file. I am trying to get the gradient from the cell center of the boundary cells and this would vary cell to cell and needs to be available at the time the BC is applied. It does not seem like OF has been designed with this possibility in mind.
vishalsacharya is offline   Reply With Quote

Old   February 14, 2019, 20:39
Default
  #6
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
Quote:
Originally Posted by vishalsacharya View Post
This function in that BC just returns the user supplied value for the "gradient" keyword in the BC file. I am trying to get the gradient from the cell center of the boundary cells and this would vary cell to cell and needs to be available at the time the BC is applied. It does not seem like OF has been designed with this possibility in mind.
Are you asking for the gradient of the pressure at the boundaries basically?
massive_turbulence is offline   Reply With Quote

Old   February 20, 2019, 15:08
Default
  #7
Member
 
Vishal Achasrya
Join Date: Nov 2011
Posts: 38
Rep Power: 15
vishalsacharya is on a distinguished road
Let us say we are looking at a quantity 'f' and solving for this and I want to apply BC to this.
I want to do d/dx(df/dx) = 0 at the boundary. To apply this, I need to first know the df/dx (gradient) at cell center in cell next to boundary and then use this value along with value of f at cell center to update f at the patch.
d/dx(df/dx) = 0 is the same as applying
f_patch = f_cell + df/dx_cell * (x_patch-x_cell)
massive_turbulence likes this.
vishalsacharya is offline   Reply With Quote

Old   February 25, 2019, 16:36
Thumbs up
  #8
Member
 
Vishal Achasrya
Join Date: Nov 2011
Posts: 38
Rep Power: 15
vishalsacharya is on a distinguished road
I figured it out.
The best way is to compute gradient and store it in a variable and then pass it as a word to this BC. You can then use lookup object to fund the value of the gradient and then apply it.
The other faster way is to do it in the main code, after solve() has completed. For this, the BC must be set to calculated first and then you can access the boundaryField and internalFieldRef() values and update as needed. For some reason this way of applying BC is much faster computationally... ?
vishalsacharya is offline   Reply With Quote

Reply

Tags
boundary condition, second gradient


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
Foam::error::PrintStack almir OpenFOAM Running, Solving & CFD 92 May 21, 2024 08:56
My radial inflow turbine Abo Anas CFX 27 May 11, 2018 02:44
Internal field boundary condition confusion cleoo OpenFOAM Pre-Processing 3 September 6, 2016 07:58
Low Mixing time Problem Mavier CFX 5 April 29, 2013 01:00
CFX fails to calculate a diffuser pipe flow shenying0710 CFX 7 March 26, 2013 05:13


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