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

access boundary fields in a boundary condition

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

Like Tree4Likes
  • 2 Post By floquation
  • 2 Post By just

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 4, 2014, 11:11
Default access boundary fields in a boundary condition
  #1
New Member
 
Join Date: Dec 2014
Location: Germany
Posts: 3
Rep Power: 11
just is on a distinguished road
Hello everyone,
I am just starting out with OpenFoam for my master thesis. This far I studied fluid mechanics and didn´t have the chance to learn a lot about programming.

I´m trying to implement my own boundary condition, which does not differ a lot from flowRateInletVelocity. I need to access to some values (velocity-component Ux, pressure, temperature) from the 0-folder for other boundary-surfaces to adjust to the needs of my experimental data. Actually, I want to give a blowing ratio instead of a flowrate on this one inlet (as I have 2 inlets I need to get values for this other one).

I looked for an answer on the forum, but nothing I tried worked. For instance the function lookupPatchID(my_boundary) called an error :
error: ‘const class Foam::fvBoundaryMesh’ has no member named ‘lookupPatchID’
and the name my_boundary was said "not declared in this scope".

I guess it must not be that complicated to call my boundary values, since it is quite an useful and common request ; but I´d be pleased if someone could give me a hint for the right syntax.

Thanks a lot,
Regards
just is offline   Reply With Quote

Old   December 5, 2014, 03:12
Default
  #2
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20
floquation will become famous soon enough
I'm not an expert, but I do have some quick guesses based on http://www.cfd-online.com/Forums/ope...nditions.html:

Quote:
my_boundary was said "not declared in this scope".
You need to replace "my_boundary" with the actual name of your boundary. The code does not simply know that. I.e., the name of the patch as you specified it in your blockMeshDict.

Quote:
‘const class Foam::fvBoundaryMesh’ has no member named ‘lookupPatchID’
Not sure, as I never tried it. But what I'd conclude based on your error and the URL I gave above is that you should probably use "findPatchID" instead of "lookupPatchID".

If that does not help, please post more details of your code for people to be truly able to help rather than guess.



Instead of coding, you might want to have a look at the groovyBC library first. Judging by what you say, I think it is able to do what you want.
floquation is offline   Reply With Quote

Old   December 5, 2014, 04:56
Default
  #3
New Member
 
Join Date: Dec 2014
Location: Germany
Posts: 3
Rep Power: 11
just is on a distinguished road
Hi,
Thank you for your answer. Of course I did replace "my_boundary" with the name of my boundary. I tried with findPatchID and it caused less errors but the code still does not recognise my U (velocity field) as a boundary field.

As I said, I´m just using the code of the boundary condition flowRateInletVelocity.C and here is the only thing I changed in the code of the member function "updateCoeffs()" :

My boundary is called MF_INLET.
Quote:
const fvMesh& mesh = patch().boundaryMesh().mesh();
label myinlet = mesh.boundaryMesh().findPatchID("MF_INLET");
fvPatchVectorField& U_p = U.boundaryField()[myinlet];
The error is
Quote:
blowingRatioInletVelocityFvPatchVectorField.C:223: error: ‘U’ was not declared in this scope
My U-file in the 0-folder is as follows :
Quote:
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.2.2 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
location "0";
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 1 -1 0 0 0 0];

internalField uniform (0 0 0);

boundaryField
{
MF_INLET
{
type fixedValue;
value uniform (60 0 0);
}
... other boundaries
And what I want to access is this Ux-component 60m/s to use it (as well as other values I need to get in a similar way) in a formula in this same updateCoeffs function.

I´ll be looking at this groovyBC library now ; but I would really like to manage coding my boundary condition, I´m sure it is not as hard a I first thought !
just is offline   Reply With Quote

Old   December 5, 2014, 06:37
Default
  #4
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20
floquation will become famous soon enough
You need to access "U" via the ObjectRegistry.
This thread (specifically the first post) will help with that: http://www.cfd-online.com/Forums/ope...ct-scalar.html

Code:
const volVectorField& U = this->db().objectRegistry::lookupObject<volVectorField>  ("U");
Which you should include between your second and third line.



The first post of the above thread does as well tell you how to access a dictionary.
This thread tells you how to read a vector from a dictionary:
http://www.cfd-online.com/Forums/ope...d-vectors.html

This should help as well with accessing the x-component of U:
http://www.cfd-online.com/Forums/ope...ell-label.html



I am, however, unsure if you can access the 0/U file as a dictionary - I can't find anyone doing so. In the createFields.H file of every solver it is read using an IOObject.
Otherwise... I hope someone else know how to acess the 0/U file.
(But do you need the IC anyway? Or do you just need the velocity at the current time?)



(Note that I'm trying to formulate an answer by simply searching, as I have little experience with this - but I learn as I go, and attempting to answering questions is an effective way to learn.)
beatlejuice and al.csc like this.
floquation is offline   Reply With Quote

Old   December 11, 2014, 04:22
Default
  #5
New Member
 
Join Date: Dec 2014
Location: Germany
Posts: 3
Rep Power: 11
just is on a distinguished road
Thank you for your help, Kevin.
I finally did it ! I combined several of your links and I finally found a way to write it that worked.

Here is my code, in case someone would need it in the future :

Quote:
const fvMesh& mesh = patch().boundaryMesh().mesh();
label myinlet = mesh.boundaryMesh().findPatchID("MF_INLET");
const volVectorField& U = this->db().objectRegistry::lookupObject<volVectorFiel d> ("U");
const fvPatchVectorField& U_p = U.boundaryField()[myinlet];
scalar Ux = 0.0;

if (U_p.size())
{
Ux = U_p[0].x();
}
reduce(Ux, maxOp<scalar>());

dimensionedScalar uInfX(
"uInfx",
dimensionSet(0, 1, -1, 0, 0),
Ux
);
//Info << "U at inlet = " << uInfX.value() << " m/s" << endl;
I adapted the other fields I needed and my boundary condition runs now.

Good luck for your further work with OpenFoam !
edsaac and vsb like this.
just is offline   Reply With Quote

Reply

Tags
boundary condition, boundary field, openfoam

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
Low Mixing time Problem Mavier CFX 5 April 29, 2013 00:00
Velocity profile boundary condition Tuca FLOW-3D 1 April 23, 2013 12:02
Opening Boundary Condition andreachan Main CFD Forum 11 March 19, 2013 16:46
asking for Boundary condition in FLUENT Destry FLUENT 0 July 27, 2010 00:55
External Radiation Boundary Condition for Grid Interface CFD XUE FLUENT 0 July 9, 2010 02:53


All times are GMT -4. The time now is 02:27.