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

Accessing a field value in a boundary condition

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 22, 2015, 10:32
Default Accessing a field value in a boundary condition
  #1
Senior Member
 
Join Date: Jul 2013
Posts: 124
Rep Power: 13
wildfire230 is on a distinguished road
Hi, I am trying to solve a convection-diffusion problem in which my viscosity and diffusivity are both functions of the local concentration, C, and I need a fixedFlux boundary condition. Normally we could use the fixedGradient boundary condition and just set the gradient as flux/diffusivity, but in this case the diffusivity is not a constant.

So, I am trying to edit the fixedGradient b.c. to allow me to divide by the local diffusivity. What is the proper way to access a field variable inside a boundary condition?

This compiles with no errors, but it gives hanging pointer errors when I try to run the solver.



template<class Type>
void myfixedFluxFvPatchField<Type>::evaluate(const Pstream::commsTypes)
{

// THIS IS THE LINE OF INTEREST
const fvPatchField<scalar>& Cp = this->patch().template lookupPatchField<surfaceScalarField, scalar>("C");


if (!this->updated())
{
this->updateCoeffs();
}

Field<Type>::operator=
(
this->patchInternalField() + gradient_/this->patch().deltaCoeffs()
);

fvPatchField<Type>::evaluate();
}



Does anyone know the proper way to access my concentration, C (a volScalarField) in my boundary condition?

Thanks,
Jesse
wildfire230 is offline   Reply With Quote

Old   July 22, 2015, 12:22
Default
  #2
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 13
ssss is on a distinguished road
You can use groovyBC form that. Declare C as a volScalarObject with an IOobject in the solver code and then use groovyBC to set the boundary condition
ssss is offline   Reply With Quote

Old   July 22, 2015, 13:25
Default
  #3
Senior Member
 
Join Date: Jul 2013
Posts: 124
Rep Power: 13
wildfire230 is on a distinguished road
Hi, thanks for your suggestion. I am not familiar with the groovyBC, but it seems it should be implemented something like as follows:

inlet
{
type groovyBC;
refValue uniform 1;
gradientExpression "J/D";
variables "J=10; D=C*1e-4;";
}


So the gradient I want to set is essentially J/D, where D is my diffusivity and is a function of the concentration C (here I've said that D=C*1e-4 for example). Is this the appropriate way to handle this?

I'm unclear, because C is a volScalarField, so I'm not sure what that makes gradientExpression, nor if this is truly what I want.

As is, it seems to through a floating point error:

#0 Foam::error:rintStack(Foam::Ostream&) at ??:?
#1 Foam::sigFpe::sigHandler(int) at ??:?
#2 in "/lib64/libc.so.6"
#3
at ??:?
#4 __libc_start_main in "/lib64/libc.so.6"
#5
at ??:?
Floating point exception

Do you have any suggestions? Thanks again.
wildfire230 is offline   Reply With Quote

Old   July 22, 2015, 13:49
Default
  #4
Senior Member
 
Join Date: Jul 2013
Posts: 124
Rep Power: 13
wildfire230 is on a distinguished road
Sorry, that was an unrelated problem with the solver.
wildfire230 is offline   Reply With Quote

Old   July 22, 2015, 18:11
Default
  #5
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 13
ssss is on a distinguished road
It should be enough with the approach you are using in the code you have shown. If you declare a volScalarField with an IOobject in the constructor, inside your solver, groovyBC will be able to access to its values. It will iterate through each face of the patch and it will set the gradient according to the value of C in each face.
ssss is offline   Reply With Quote

Old   July 22, 2015, 18:44
Default
  #6
Senior Member
 
Join Date: Jul 2013
Posts: 124
Rep Power: 13
wildfire230 is on a distinguished road
Thanks, I think you're right. groovyBC looks like a very useful tool.
wildfire230 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
Field value inside a boundary condition class pcaron OpenFOAM Programming & Development 14 October 17, 2022 10:40
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 07:28
Error finding variable "THERMX" sunilpatil CFX 8 April 26, 2013 08:00
vorticity boundary condition bearcharge Main CFD Forum 0 May 14, 2010 12:32
Boundary condition vector field gradient from two sides of patch face quba OpenFOAM 0 December 12, 2007 06:26


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