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

lookup alpha1 from boundary patch

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

Like Tree2Likes
  • 1 Post By kmooney
  • 1 Post By michielm

Reply
 
LinkBack Thread Tools Display Modes
Old   October 18, 2012, 04:56
Default lookup alpha1 from boundary patch
  #1
Member
 
Michiel
Join Date: Oct 2010
Location: Delft, Netherlands
Posts: 96
Rep Power: 5
michielm is on a distinguished road
Hi,
I am trying to read the value of alpha1 in the boundary cells to apply it in a boundary condition, but until now I am unsuccesful. I have tried two different routes, both resulting in compilation errors.

The first thing I tried was to acces the mesh and extract alpha1 from it like this
Code:
const fvMesh& mesh = patch().boundaryMesh().mesh();
     
const volScalarField& alpha1 = mesh.lookupObject<volScalarField>("alpha1");
but this resulted in this massive error message
Code:
CAHCoxVoinovAngleFvPatchScalarField.C: In member function ‘virtual Foam::tmp<Foam::Field<double> > Foam::CAHCoxVoinovAngleFvPatchScalarField::theta(const Foam::fvPatchVectorField&, const Foam::fvsPatchVectorField&) const’:
CAHCoxVoinovAngleFvPatchScalarField.C:145: warning: unused variable ‘alpha1’
/opt/apps/openfoam-2.1.0//OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/objectRegistryTemplates.C: In member function ‘const Type& Foam::objectRegistry::lookupObject(const Foam::word&) const [with Type = Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>]’:
CAHCoxVoinovAngleFvPatchScalarField.C:146:   instantiated from here
/opt/apps/openfoam-2.1.0//OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/objectRegistryTemplates.C:104: error: cannot dynamic_cast ‘iter.Foam::HashTable<T, Key, Hash>::const_iterator::operator() [with T = Foam::regIOobject*, Key = Foam::word, Hash = Foam::string::hash]()’ (of type ‘class Foam::regIOobject* const’) to type ‘const struct Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>*’ (target is not pointer or reference to complete type)
/opt/apps/openfoam-2.1.0//OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/objectRegistryTemplates.C:111: error: incomplete type ‘Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>’ used in nested name specifier
CAHCoxVoinovAngleFvPatchScalarField.C:146:   instantiated from here
/opt/apps/openfoam-2.1.0//OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/objectRegistryTemplates.C:128: error: incomplete type ‘Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>’ used in nested name specifier
/opt/apps/openfoam-2.1.0//OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/objectRegistryTemplates.C:128: error: incomplete type ‘Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>’ used in nested name specifier
/opt/apps/openfoam-2.1.0//OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/typeInfo.H: In function ‘bool Foam::isA(const Type&) [with TestType = Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>, Type = Foam::regIOobject]’:
/opt/apps/openfoam-2.1.0//OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/objectRegistryTemplates.C:40:   instantiated from ‘Foam::wordList Foam::objectRegistry::names() const [with Type = Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>]’
/opt/apps/openfoam-2.1.0//OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/objectRegistryTemplates.C:128:   instantiated from ‘const Type& Foam::objectRegistry::lookupObject(const Foam::word&) const [with Type = Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>]’
CAHCoxVoinovAngleFvPatchScalarField.C:146:   instantiated from here
/opt/apps/openfoam-2.1.0//OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/typeInfo.H:136: error: cannot dynamic_cast ‘(const Foam::regIOobject*)t’ (of type ‘const class Foam::regIOobject*’) to type ‘const struct Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>*’ (target is not pointer or reference to complete type)
make: *** [Make/linux64GccDPOpt/CAHCoxVoinovAngleFvPatchScalarField.o] Error 1
Then a colleague suggested to use 'lookupPatchField' instead, like this:
Code:
const fvPatchField<scalar>& alpha1 = patch().lookupPatchField<volScalarField, scalar>("alpha1");
but alpha1 doesn't seem to exist in the patchField:
Code:
CAHCoxVoinovAngleFvPatchScalarField.C: In member function ‘virtual Foam::tmp<Foam::Field<double> > Foam::CAHCoxVoinovAngleFvPatchScalarField::theta(const Foam::fvPatchVectorField&, const Foam::fvsPatchVectorField&) const’:
CAHCoxVoinovAngleFvPatchScalarField.C:150: error: no matching function for call to ‘Foam::fvPatch::lookupPatchField(const char [7]) const’
CAHCoxVoinovAngleFvPatchScalarField.C:149: warning: unused variable ‘alpha1’
make: *** [Make/linux64GccDPOpt/CAHCoxVoinovAngleFvPatchScalarField.o] Error 1
Could someone please explain what is wrong in the two strategies above, or explain to me what the correct way of looking up alpha1 is?!
michielm is offline   Reply With Quote

Old   October 25, 2012, 11:43
Default
  #2
Senior Member
 
kmooney's Avatar
 
Kyle Mooney
Join Date: Jul 2009
Location: Amherst, MA USA - San Diego, CA USA
Posts: 242
Rep Power: 8
kmooney is on a distinguished road
Something like this might work for you:

Code:
//get the patch ID number
label patchID = mesh.boundaryMesh().findPatchID("myPatchNameString");

//Lookup the desired alpha values on the patch you want
const fvPatchField<scalar>& alphaPatchField = alpha1.boundaryField()[patchID]

//local face value access
forAll(cPatch,faceI)
{
     scalar patchAlphaValue = alphaPatchField[faceI];
}
mm.abdollahzadeh likes this.
kmooney is offline   Reply With Quote

Old   October 26, 2012, 03:35
Default
  #3
Member
 
Michiel
Join Date: Oct 2010
Location: Delft, Netherlands
Posts: 96
Rep Power: 5
michielm is on a distinguished road
Thanks for the response!

I have tried this, but I get the error that 'alpha1' is not declared in this scope.
So before I will be able to use your piece of code I first have to lookup alpha1 from somewhere and that is where it goes wrong.

Do you perhaps know how I can look up alpha1 from the mesh or the patch or something like it?!
michielm is offline   Reply With Quote

Old   October 26, 2012, 04:13
Default
  #4
Member
 
Michiel
Join Date: Oct 2010
Location: Delft, Netherlands
Posts: 96
Rep Power: 5
michielm is on a distinguished road
I just found out what the issue was: apparently alpha1 should not be read as a volScalarField but as a scalarField. I don't really understand why. But if i use this it works:


Code:
const fvMesh& mesh = patch().boundaryMesh().mesh();       
const scalarField& alpha1 = mesh.lookupObject<scalarField>("alpha1");
And then of course I still need to select the values on the patch, but that will work out with the method you describe.
Bernhard likes this.
michielm is offline   Reply With Quote

Reply

Thread Tools
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
No layers in a small gap bobburnquist OpenFOAM Native Meshers: snappyHexMesh and Others 2 November 25, 2012 08:54
domain imbalance for enrgy equation happy CFX 14 September 6, 2012 01:54
StarToFoam error Kart OpenFOAM Meshing & Mesh Conversion 1 February 4, 2010 04:38
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 06:51
Import gmsh msh to Foam adorean Open Source Meshers: Gmsh, Netgen, CGNS, ... 24 April 27, 2005 08:19


All times are GMT -4. The time now is 06:17.