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/)
-   -   access inletValue (https://www.cfd-online.com/Forums/openfoam-programming-development/147485-access-inletvalue.html)

demichie January 22, 2015 09:33

access inletValue
 
I continue here an old thread without a solution.


Quote:

Originally Posted by stevek (Post 283348)
Hi,

I am manipulating boundary values where I access the "value" of inletOutlet bc with:

fvPatchScalarField& kInlet = k.boundaryField()[inletPatchID]

How can I similarly access "inletValue" of this bc for modification.

Thanks,
Steve

I have the same problem and I would like to access the "inletValue" of an inletOutlet boundary condition but I don't know how to do it.

If I write this piece of code:

const volVectorField::GeometricBoundaryField& U2bf = U2.boundaryField();

forAll(U2bf, patchi)
{
if ( U2bf.types()[patchi] == "inletOutlet" )
{
Info << U2bf[patchi].inletValue() << endl;
}
}

compilation fails giving the following error:

error: ‘const class Foam::fvPatchField<Foam::Vector<double> >’ has no member named ‘inletValue’

I have not found the member for inletValue! Can someone help me please?

Thank you
Mattia

alexeym January 22, 2015 10:29

Hi,

If you take a look at the inletOutletFvPatchField documentation http://foam.sourceforge.net/docs/cpp/a01095.html, you can find, that it is a child of mixedFvPatchField and has refValue method.

Alternatively you can look at the sources:

Code:

template<class Type>
Foam::inletOutletFvPatchField<Type>::inletOutletFvPatchField
(
    const fvPatch& p,
    const DimensionedField<Type, volMesh>& iF,
    const dictionary& dict
)
:
    mixedFvPatchField<Type>(p, iF),
    phiName_(dict.lookupOrDefault<word>("phi", "phi"))
{
    this->refValue() = Field<Type>("inletValue", dict, p.size());

    if (dict.found("value"))
    {
        fvPatchField<Type>::operator=
        (
            Field<Type>("value", dict, p.size())
        );
    }
    else
    {
        fvPatchField<Type>::operator=(this->refValue());
    }

    this->refGrad() = pTraits<Type>::zero;
    this->valueFraction() = 0.0;
}

There you'll be able to find that inletValue is stored as refValue. You have to cast patch into mixedFvPatchField before accessing refValue method.

demichie January 22, 2015 11:19

Dear alexeym,
following your suggestion I have solved the problem!
Here there is the working code:

Code:

const volVectorField::GeometricBoundaryField& U2bf = U2.boundaryField();

forAll(U2bf, patchi)
    {
      Info << U2bf[patchi] << endl;
      if ( U2bf.types()[patchi] == "inletOutlet" )
        {
          mixedFvPatchField<vector>& U2inletOutlet = refCast<mixedFvPatchField<vector> >(U2.boundaryField()[patchi]);

          Info << U2inletOutlet.refValue() << endl;
          }
    }



Thank you
Mattia


All times are GMT -4. The time now is 15:50.