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/)
-   -   manipulating boundaryField of a volScalarField in OpenFOAM (https://www.cfd-online.com/Forums/openfoam-programming-development/128006-manipulating-boundaryfield-volscalarfield-openfoam.html)

thanasis December 30, 2013 10:28

manipulating boundaryField of a volScalarField in OpenFOAM
 
Dear all,

I need to manipulate a volScalarField using some complex expressions that include other volScalarFields and scalars. I have already a library (C++ class library) that operates on scalars and in order to take advantage of this I (note that I need to perform element by element multiplications), I employed a for loop for the internal field:

Code:

for (label i=0; i<D.internalField()[i]; ++i)
    {
        D.internalField()[i]*= libraryObject.libraryFunction
                                    (
                                        T.internalField()[i],
                                        P.internalField()[i],
                                        someScalar
                                    );
    }

I can not however perform the same type of calculations for the boundary field:

Code:

scalar scalarT;
scalar scalarP;
for (label i=0; i<D.boundaryField()[i]; ++i)
    {
        scalarT=T.boundaryField()[i];
        scalarP=P.boundaryField()[i];
        D.boundaryField()[i]*= libraryObject.libraryFunction
                                    (
                                        scalarT,
                                        scalarP,
                                        someScalar
                                    );
    }

The above code does not compile since T.boundaryField()[i] and P.boundaryField()[i] are of fvPatchField type and it seems that I can not assign them to scalars in order to call the library function.

Is there a way to "cast" boundaryField()[i] to a scalar? Is there any other way to manipulate the boundary field using the libraryFunction? I know that boundary condition models employ the == operator to reset them, but I can not figure out how this could work in the boundaryField of a volScalarField variable.

I would be grateful for any recommendations/suggestions.

kmooney January 15, 2014 15:47

Howdy!

When referencing the index of an D.internalField[i] <-like that, the i is refering to a cell index. A boundaryField() is different in that it returns not a patch but a list of patches. For example, to access face j on patch i you would have to write D.boundaryField()[i][j]

You're most likey meaning to do something like this:
Code:

forAll(D.boundaryField(), patchI)
{
        scalarField& tPatch=T.boundaryField()[patchI];
        scalarField& pPatch=P.boundaryField()[patchI];
        scalarField& DPatch=D.boundaryField()[patchI];

        forAll(DPatch,faceI)
        {
      DPatch[faceI]*= libraryObject.libraryFunction
                                    (
                                        tPatch[faceI],
                                        pPatch[faceI],
                                        someScalar
                                    );
        }
}

Note that there is a pretty good chance I messed something up here but I think it will help explain things!
Good luck!

Kyle

thanasis January 19, 2014 02:23

Thank you Kyle! that was the problem.

alimea September 21, 2018 04:00

Hi foamers

I defined a volSymmTensorField and now want to change the values of that in a special boundary:

Code:

volSymmTensorField TauT_RT = tauT;

// changing the values of internal field

forAll (TauT_RT , i) 
{
        TauT_RT[i].xy() =40.5;
}


// changing the values of boundary field

forAll (TauT_RT.boundaryField()[patchI] , i)
{
  TauT_RT.boundaryField()[patchI][i].component(symmTensor::XY) = 40 * i;
}

But it gives me this error:

Quote:

error: assignment of read-only location ‘(&(&(& TauT_RT.Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryField<Foam::SymmTensor<double>, Foam::fvPatchField, Foam::volMesh>())->Foam::GeometricField<Foam::SymmTensor<double>, Foam::fvPatchField, Foam::volMesh>::Boundary::<anonymous>.Foam::FieldF ield<Foam::fvPatchField, Foam::SymmTensor<double> >::<anonymous>.Foam::PtrList<Foam::fvPatchField<Fo am::SymmTensor<double> > >::<anonymous>.Foam::UPtrList<T>::operator[]<Foam::fvPatchField<Foam::SymmTensor<double> > >(patchI))->Foam::fvPatchField<Foam::SymmTensor<double> >::<anonymous>.Foam::Field<Foam::SymmTensor<double > >::<anonymous>.Foam::List<Foam::SymmTensor<doubl e> >::<anonymous>.Foam::UList<T>::operator[]<Foam::SymmTensor<double> >(i))->Foam::SymmTensor<double>::<anonymous>.Foam::Vecto rSpace<Form, Cmpt, Ncmpts>::component<Foam::SymmTensor<double>, double, 6u>(1)’
TauT_RT.boundaryField()[patchI][i].component(symmTensor::XY) = 40 * i;

I'm really appreciated if you answers me.

ztdep February 5, 2020 22:26

Quote:

Originally Posted by alimea (Post 707014)
Hi foamers

I defined a volSymmTensorField and now want to change the values of that in a special boundary:

Code:

volSymmTensorField TauT_RT = tauT;

// changing the values of internal field

forAll (TauT_RT , i) 
{
        TauT_RT[i].xy() =40.5;
}


// changing the values of boundary field

forAll (TauT_RT.boundaryField()[patchI] , i)
{
  TauT_RT.boundaryField()[patchI][i].component(symmTensor::XY) = 40 * i;
}

But it gives me this error:



I'm really appreciated if you answers me.

just modify it to TauT_RT.boundaryFieldRef()


All times are GMT -4. The time now is 08:00.