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

Field value inside a boundary condition class

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree34Likes
  • 1 Post By pcaron
  • 5 Post By su_junwei
  • 2 Post By pcaron
  • 15 Post By CedricVH
  • 1 Post By pcaron
  • 7 Post By mchurchf
  • 2 Post By Jung hoo
  • 1 Post By ufocfd

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 13, 2010, 15:12
Post Field value inside a boundary condition class
  #1
Member
 
Pablo Caron
Join Date: Nov 2009
Location: Buenos Aires, Argentina
Posts: 75
Rep Power: 16
pcaron is on a distinguished road
Hello Forum,

I'm using OF-1.5-dev in openSUSE 11.2. I want to implement a boundary condition class which depends on a field value at a point.

I used the parabolicVelocity class as start point. I modified it to fix the boundary value according to different parameters and it works fine.

The next step is to read a field value at a point and use it to modify the boundary value.

I read several post, but I can't understand how to know a field value at a point. These are the posts I read

http://www.cfd-online.com/Forums/ope...ary-point.html
http://openfoamwiki.net/index.php/Sn...value_at_point

Can somebody help me? Thanks in advance

Pablo
atulkjoy likes this.
pcaron is offline   Reply With Quote

Old   April 13, 2010, 22:58
Default
  #2
Senior Member
 
su_junwei's Avatar
 
su junwei
Join Date: Mar 2009
Location: Xi'an China
Posts: 151
Rep Power: 20
su_junwei is on a distinguished road
Send a message via MSN to su_junwei
Hi Pablo
try the following code segment

point p(x,y,z) ;
label cellNo=mesh_.findCell(p);
//using the cell center value or make an interpolation
type value=Variable[cellNO];
If you want to do an interpolation, please see the following thread
http://www.cfd-online.com/Forums/ope...tml#post254038

regards,Junwei
su_junwei is offline   Reply With Quote

Old   April 14, 2010, 09:52
Post
  #3
Member
 
Pablo Caron
Join Date: Nov 2009
Location: Buenos Aires, Argentina
Posts: 75
Rep Power: 16
pcaron is on a distinguished road
Hi Junwei

thanks for your reply!

I read your idea before. The problem is that I want to do this evaluation inside a BC class, so I don't have any reference to mesh_ and Variable.

So, I think the improved question could be: How should I reference a Variable (like p or U) and mesh_ inside a BC class?

BTW: These are my first steps in OF programming.

Regards

Pablo
atulkjoy and JamesCC like this.
pcaron is offline   Reply With Quote

Old   April 14, 2010, 10:04
Default
  #4
Member
 
Cedric Van Holsbeke
Join Date: Dec 2009
Location: Belgium
Posts: 81
Rep Power: 16
CedricVH is on a distinguished road
You have the access member function const objectRegistry& db() const. Accessing for example U is done by the code:

Code:
const volVectorField& U = db().lookupObject<volVectorField>("U");
For accessing the mesh: when creating a boundary condition, you have access to the patch. You can thus access the mesh with:

Code:
const fvMesh& mesh = patch().boundaryMesh().mesh();
CedricVH is offline   Reply With Quote

Old   April 14, 2010, 10:48
Default Boundary Condition Using Information from Opposite Face
  #5
Member
 
Matthew J. Churchfield
Join Date: Nov 2009
Location: Boulder, Colorado, USA
Posts: 49
Rep Power: 18
mchurchf is on a distinguished road
Hello,

I have a related question. I am using OpenFOAM-1.6, and I want to set up a boundary condition on velocity that requires knowledge of the velocity at the face opposite the boundary face. Is there a straightforward way to do this from within a derived fvPatchFields class? Or will I have to access the entire velocity volume field from within that derived fvPatchFields class and use something like "oppositeCellFace"? If I need to do the latter, can someone give some guidance, please?

Thank you,

Matt
mchurchf is offline   Reply With Quote

Old   April 14, 2010, 16:23
Default
  #6
Member
 
Pablo Caron
Join Date: Nov 2009
Location: Buenos Aires, Argentina
Posts: 75
Rep Power: 16
pcaron is on a distinguished road
Hi Cedric and Junwei

I want to thank you. I could implement my new boundary condition and is working now!

BTW, Cedric, As I told you these are my first steps. I found very difficult to understand and/or find functions and classes in OF Oxygen help. Is there another place to find a more user friendly help?

Thanks for your help!

Pablo

Quote:
Originally Posted by CedricVH View Post
You have the access member function const objectRegistry& db() const. Accessing for example U is done by the code:

Code:
const volVectorField& U = db().lookupObject<volVectorField>("U");
For accessing the mesh: when creating a boundary condition, you have access to the patch. You can thus access the mesh with:

Code:
const fvMesh& mesh = patch().boundaryMesh().mesh();
Zhiheng Wang likes this.
pcaron is offline   Reply With Quote

Old   April 14, 2010, 22:48
Default
  #7
Senior Member
 
su_junwei's Avatar
 
su junwei
Join Date: Mar 2009
Location: Xi'an China
Posts: 151
Rep Power: 20
su_junwei is on a distinguished road
Send a message via MSN to su_junwei
Quote:
Originally Posted by mchurchf View Post
Hello,

I have a related question. I am using OpenFOAM-1.6, and I want to set up a boundary condition on velocity that requires knowledge of the velocity at the face opposite the boundary face. Is there a straightforward way to do this from within a derived fvPatchFields class?
Thank you,
Matt
Hi Matt

Is your "opposite boundary face" a boundary patch in your case? If it is, You can search the patch by its index or patch name.

label patchId=patch().boundaryMesh().lookupPatchID(patch Name);
and using the following code

const vectorField =U.boundaryField()[patchId];
.... // do your work

U can be obtained using credricVH's method mentioned above.(lookup using ObjectRegistry)

regards, Junwei
su_junwei is offline   Reply With Quote

Old   April 16, 2010, 09:38
Default Accessing internal field and mesh from within boundary condition
  #8
Member
 
Matthew J. Churchfield
Join Date: Nov 2009
Location: Boulder, Colorado, USA
Posts: 49
Rep Power: 18
mchurchf is on a distinguished road
Thank you all for your help,

I was able to implement my boundary condition as well. I used the following code to access the internal velocity field and the mesh two layers of cells inward from the boundary:

Code:
//  Set up access to the internal velocity field and mesh
    const volVectorField& U =
        db().objectRegistry::lookupObject<volVectorField>(UName_);
    const fvMesh& mesh = patch().boundaryMesh().mesh();

    forAll(patch(), facei)
    {
    // get global cell indices for cells adjacent to patch    
        label celli = patch().faceCells()[facei];

    // get global face indices for faces opposite patch face
    label oppFacei = mesh.cells()[celli].opposingFaceLabel(facei+patch().patch().start(),mesh.faces());

    // get coordinates of center of cell adjacent to patch (patch cells)
    vector cellCentreO = mesh.cellCentres()[mesh.owner()[oppFacei]];

    // get coordinates of center of cell on the side opposite the patch of
    // the patch cell
    vector cellCentreN = mesh.cellCentres()[mesh.neighbour()[oppFacei]];

    // get coordinates of center of face opposite the patch boundary face
    vector faceCentre  = mesh.faceCentres()[oppFacei];

    // get coordinates of center of patch boundary face;
    vector patchFaceCentre = mesh.faceCentres()[facei+patch().patch().start()];
    }
mchurchf is offline   Reply With Quote

Old   July 27, 2010, 06:04
Default
  #9
Member
 
George Pichurov
Join Date: Jul 2010
Posts: 52
Rep Power: 16
jorkolino is on a distinguished road
How can I access patch() function? I try to include it in my solver files with a compile error "patch is not defined in this scope". My wish is to inject a particle in each boundary cell of a patch. I have the code for particle generation, I just can not find the cell index for which to generate it.
I can not find the function lookupPatchID in the doxygen documentation, either. Though it may still work, I can not test it without first fixing the patch() error message.

Last edited by jorkolino; July 27, 2010 at 07:58.
jorkolino is offline   Reply With Quote

Old   October 1, 2015, 12:00
Default
  #10
Member
 
Xinguang Wang
Join Date: Feb 2015
Posts: 45
Rep Power: 11
JasonWang3 is on a distinguished road
Quote:
Originally Posted by mchurchf View Post
Thank you all for your help,

I was able to implement my boundary condition as well. I used the following code to access the internal velocity field and the mesh two layers of cells inward from the boundary:

Code:
//  Set up access to the internal velocity field and mesh
    const volVectorField& U =
        db().objectRegistry::lookupObject<volVectorField>(UName_);
    const fvMesh& mesh = patch().boundaryMesh().mesh();

    forAll(patch(), facei)
    {
    // get global cell indices for cells adjacent to patch    
        label celli = patch().faceCells()[facei];

    // get global face indices for faces opposite patch face
    label oppFacei = mesh.cells()[celli].opposingFaceLabel(facei+patch().patch().start(),mesh.faces());

    // get coordinates of center of cell adjacent to patch (patch cells)
    vector cellCentreO = mesh.cellCentres()[mesh.owner()[oppFacei]];

    // get coordinates of center of cell on the side opposite the patch of
    // the patch cell
    vector cellCentreN = mesh.cellCentres()[mesh.neighbour()[oppFacei]];

    // get coordinates of center of face opposite the patch boundary face
    vector faceCentre  = mesh.faceCentres()[oppFacei];

    // get coordinates of center of patch boundary face;
    vector patchFaceCentre = mesh.faceCentres()[facei+patch().patch().start()];
    }
Hi

I follow your code, and write a code to test if it could work or not:
Quote:
#include "fvCFD.H"
#include "wallFvPatch.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
timeSelector::addOptions();
#include "setRootCase.H"
#include "createTime.H"

Info<< "Create mesh, no clear-out\n" << endl;
fvMesh mesh
(
IOobject
(
fvMesh::defaultRegion,
runTime.timeName(),
runTime,
IOobject::MUST_READ
)
);

const fvPatchList& patches = mesh.boundary();

forAll(mesh.boundary(), patchi)
{
const fvPatch& patch = patches[patchi];
if (isA<wallFvPatch>(patch)) // is wall or not//
{
const fvMesh& mesh = patch.boundaryMesh().mesh();

forAll(patch, facei)
{
// get global cell indices for cells adjacent to patch
label celli = patch.faceCells()[facei];

// get global face indices for faces opposite patch face
label oppFacei = mesh.cells()[celli].opposingFaceLabel(facei+patch.patch.start(),mesh. faces());

Info<< facei << endl;
Info<< celli << endl;
Info<< oppFacei << endl;
Info<< ' ' << endl;
}

}

}

}
But I can not compile this code, some errors have happens in the opposiongFaceLabel. Do you have any suggestions about the code?
JasonWang3 is offline   Reply With Quote

Old   October 1, 2015, 12:44
Default
  #11
Member
 
Xinguang Wang
Join Date: Feb 2015
Posts: 45
Rep Power: 11
JasonWang3 is on a distinguished road
I figure it out, just delete one patch from opposingFaceLabel(facei+patch.patch.start(),mesh. faces());

Sorry to trouble you.
JasonWang3 is offline   Reply With Quote

Old   September 11, 2016, 07:14
Default
  #12
Member
 
Lee Jung Hoo
Join Date: Dec 2015
Posts: 37
Rep Power: 10
Jung hoo is on a distinguished road
Hi, I'm trying to create my own boundary condition.

I'm modifying the Member Function from parabolicVelocityFvPatchVectorField.C(i.e, I chose parabolicVelocityFvPatchVectorField.C as the base)

When I tried to read field values like U or p on the boundary member function, compiling was successfully done, but I get the error message as belows when I run "setFields" on an example case based on interFoam.

Quote:
--> FOAM Warning :
From function dlLibraryTableOpen(const fileName& functionLibName)
in file db/dlLibraryTable/dlLibraryTable.C at line 85
could not load /home/lee/foam/lee-3.1/lib/linux64GccDPOpt/libmyfunctionfinal2.so: undefined symbol: _ZTVN4Foam15twoPhaseMixtureE
And then, when I run application(interFoam), an error message is shown :

Quote:
Reading field T

--> FOAM FATAL ERROR:
request for volVectorField U from objectRegistry region0 failed
available objects of type volVectorField are
1
(
T
)

From function objectRegistry::lookupObject<Type>(const word&) const
in file /home/lee/foam/foam-extend-3.1/src/foam/lnInclude/objectRegistryTemplates.C at line 139.
FOAM aborting
Aborted (core dumped)
I used these commans for reading the field values(U, phi, alpha1)

Quote:
const volVectorField& U = db().lookupObject<volVectorField>("U");
const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>("phi");
const volScalarField& alpha1 = db().lookupObject<volScalarField>("alpha1");
I'm beginner in programming, so I guess I'm missing a simple thing...

this is a part of Member Function:

Quote:
void cbVelocityFvPatchVectorField::updateCoeffs()
{
if (updated())
{
return;
}
const fvMesh& mesh = dimensionedInternalField().mesh();
//const fvMesh& mesh = patch().boundaryMesh().mesh();
const word& patchName = this->patch().name();
const label patchID = mesh.boundaryMesh().findPatchID(patchName);
const volVectorField& U = db().lookupObject<volVectorField>("U");
const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>("phi");
const volScalarField& alpha1 = db().lookupObject<volScalarField>(alphaName());
//volVectorField U("U", U);
//surfaceScalarField phi("phi", phi);
//volScalarField alpha1("alpha1", alpha1);
twoPhaseMixture twoPhaseProperties(U, phi, "alpha1");
autoPtr<incompressible::turbulenceModel> turbulence
(
incompressible::turbulenceModel::New(U, phi, twoPhaseProperties)
);
volSymmTensorField Reff(turbulence->devReff());

scalar rho = 1000;
scalar nu = 1e-06;
scalar mu = nu*rho;
scalar g = 9.81;
scalar s = 1.4;
scalar d = 0.005;
scalar shieldsc = 0.05;
scalar kappa = 0.8;
scalar c0 = 3;
//scalar Alpha1 = 0.8*mathematicalConstantPi;
scalar Alpha1 = 2;
scalarField wallShearStress = rho*mag((-mesh.Sf().boundaryField()[patchID]/mesh.magSf().boundaryField()[patchID]) & Reff.boundaryField()[patchID]);
scalarField shields = (wallShearStress)/(rho*(s-1)*g*d);
scalarField PEF = (pow((1+pow4((((1/6)*mathematicalConstantPi*mu)/(shields-shieldsc)))), -(1/4)));
scalarField linearC = sqrt(((sqr(kappa)*sqr(Alpha1))*(shields-shieldsc-((1/6)*mathematicalConstantPi*mu*PEF)))/(0.013*s*shields));
scalarField cb = c0/pow3((1+(1/linearC)));
vectorField n = patch().nf();
vectorFieldOperator=(-n*cb);
Any comments will help me a lot!
Thank you in advance!!
atulkjoy and AnthonyP like this.

Last edited by Jung hoo; September 11, 2016 at 11:07.
Jung hoo is offline   Reply With Quote

Old   May 22, 2017, 18:23
Default Access specific boundaries
  #13
Member
 
Sugajen
Join Date: Jan 2012
Location: Tempe, USA
Posts: 52
Rep Power: 14
Sugajen is on a distinguished road
I am trying to access only the z-direction boundaries of the Velocity field to set new boundary condition for the next timestep. Is there a way to do so ? I have separated the boundary fields in the input blockMeshDict file. But can we access it in the solver?
Sugajen is offline   Reply With Quote

Old   May 24, 2018, 17:06
Default how to get field value in mesh two layers of cells inward from the boundary?
  #14
New Member
 
Hao Zeng
Join Date: Mar 2017
Posts: 8
Rep Power: 9
Noémie is on a distinguished road
Quote:
Originally Posted by mchurchf View Post
Thank you all for your help,

I was able to implement my boundary condition as well. I used the following code to access the internal velocity field and the mesh two layers of cells inward from the boundary:

Code:
//  Set up access to the internal velocity field and mesh
    const volVectorField& U =
        db().objectRegistry::lookupObject<volVectorField>(UName_);
    const fvMesh& mesh = patch().boundaryMesh().mesh();

    forAll(patch(), facei)
    {
    // get global cell indices for cells adjacent to patch    
        label celli = patch().faceCells()[facei];

    // get global face indices for faces opposite patch face
    label oppFacei = mesh.cells()[celli].opposingFaceLabel(facei+patch().patch().start(),mesh.faces());

    // get coordinates of center of cell adjacent to patch (patch cells)
    vector cellCentreO = mesh.cellCentres()[mesh.owner()[oppFacei]];

    // get coordinates of center of cell on the side opposite the patch of
    // the patch cell
    vector cellCentreN = mesh.cellCentres()[mesh.neighbour()[oppFacei]];

    // get coordinates of center of face opposite the patch boundary face
    vector faceCentre  = mesh.faceCentres()[oppFacei];

    // get coordinates of center of patch boundary face;
    vector patchFaceCentre = mesh.faceCentres()[facei+patch().patch().start()];
    }

I followed your code and it works! However, I want to get the field values from cells that 2 layers inward from the boundary. How can I access it?

Thanks in advance.

Hao
Noémie is offline   Reply With Quote

Old   October 17, 2022, 09:40
Default
  #15
Senior Member
 
Giles Richardson
Join Date: Jun 2012
Location: Cambs UK
Posts: 102
Rep Power: 14
ufocfd is on a distinguished road
that's been very useful - thanks

Quote:
Originally Posted by CedricVH View Post
You have the access member function const objectRegistry& db() const. Accessing for example U is done by the code:

Code:
const volVectorField& U = db().lookupObject<volVectorField>("U");
For accessing the mesh: when creating a boundary condition, you have access to the patch. You can thus access the mesh with:

Code:
const fvMesh& mesh = patch().boundaryMesh().mesh();
saeed jamshidi likes this.
ufocfd is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Boundary Conditions Thomas P. Abraham Main CFD Forum 20 July 7, 2013 05:05
inlet velocity boundary condition murali CFX 5 August 3, 2012 08:56
Airfoil boundary condition Frank Main CFD Forum 1 April 21, 2008 18:36
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Meshing & Mesh Conversion 2 July 15, 2005 04:15
meshing F1 front wing Steve FLUENT 0 April 17, 2003 12:37


All times are GMT -4. The time now is 14:13.