CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   lookup alpha1 from boundary patch (https://www.cfd-online.com/Forums/openfoam-programming-development/108266-lookup-alpha1-boundary-patch.html)

michielm October 18, 2012 04:56

lookup alpha1 from boundary patch
 
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?!

kmooney October 25, 2012 11:43

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];
}


michielm October 26, 2012 03:35

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 October 26, 2012 04:13

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.


All times are GMT -4. The time now is 20:36.