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/)
-   -   mixedBoundary not writting the correct refGrad values when executed in parallel (https://www.cfd-online.com/Forums/openfoam-programming-development/240258-mixedboundary-not-writting-correct-refgrad-values-when-executed-parallel.html)

MamboJambo December 21, 2021 19:25

mixedBoundary not writting the correct refGrad values when executed in parallel
 
Hello to all,


I am new to OF programming, I am using OF2106, and I am trying to build a new mixed boundary condition.


As an example, I have:



Code:


#ifndef trash_H
#define trash_H

#include "mixedFvPatchField.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "PatchFunction1.H"


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
    Class trash Declaration
\*---------------------------------------------------------------------------*/

class trash
:
    public mixedFvPatchField<scalar>
{
    // Private Data


public:

    //- Runtime type information
    TypeName("trash");


    // Constructors

        //- Construct from patch and internal field
        trash
        (
            const fvPatch&,
            const DimensionedField<scalar, volMesh>&
        );

        //- Construct from patch, internal field and dictionary
        trash
        (
            const fvPatch&,
            const DimensionedField<scalar, volMesh>&,
            const dictionary&
        );

        //- Construct by mapping given
        //- trash
        //- onto a new patch
        trash
        (
            const trash&,
            const fvPatch&,
            const DimensionedField<scalar, volMesh>&,
            const fvPatchFieldMapper&
        );

        //- Construct as copy
        trash
        (
            const trash&
        );

        //- Construct and return a clone
        virtual tmp<fvPatchField<scalar>> clone() const
        {
            return tmp<fvPatchField<scalar>>
            (
                new
                trash(*this)
            );
        }

        //- Construct as copy setting internal field reference
        trash
        (
            const trash&,
            const DimensionedField<scalar, volMesh>&
        );

        //- Construct and return a clone setting internal field reference
        virtual tmp<fvPatchField<scalar>> clone
        (
            const DimensionedField<scalar, volMesh>& iF
        ) const
        {
            return tmp<fvPatchField<scalar>>
            (
                new
                trash
                (
                    *this,
                    iF
                )
            );
        }



        // Evaluation

            //- Update the coefficients associated with the patch field
            virtual void updateCoeffs();


        //- Write
        virtual void write(Ostream&) const;
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

and the implementation


Code:


#include "trash.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "gravityMeshObject.H"


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::trash::trash
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF
)
:
    mixedFvPatchField<scalar>(p, iF)
{
    refValue() = 0.0;
    refGrad() = 0.0;
    valueFraction() = 0.0;
}


Foam::trash::trash
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const dictionary& dict
)
:
    mixedFvPatchField<scalar>(p, iF)
{
    refValue() = 0.0;
    refGrad() = 0.0;
    valueFraction() = 0.0;

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


Foam::trash::trash
(
    const trash& ptf,
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const fvPatchFieldMapper& mapper
)
:
    mixedFvPatchField<scalar>(ptf, p, iF, mapper)
{}


Foam::trash::trash
(
    const trash& tppsf
)
:
    mixedFvPatchField<scalar>(tppsf)
{}


Foam::trash::trash
(
    const trash& tppsf,
    const DimensionedField<scalar, volMesh>& iF
)
:
    mixedFvPatchField<scalar>(tppsf, iF)
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //


void Foam::trash::updateCoeffs()
{
    if (updated())
    {
        return;
    }
         
                                       
    this->refGrad() = 2;
    this->valueFraction() = scalar(0);
    this->refValue() = scalar(0);         


    Info << "New boundary" << endl;

    mixedFvPatchField<scalar>::updateCoeffs();
}


void Foam::trash::write
(
    Ostream& os
) const
{
    mixedFvPatchField<scalar>::write(os);

}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
    makePatchTypeField
    (
        fvPatchScalarField,
        trash
    );

}

When I run the code in serial the refGrad value of 2 appears in the variable file (T in scalarTransporFoam). However, when I run the code in parallel the refGrad value gets a value of 0. Why is this happening?


Can anyone reproduce this?



Thanks!

MamboJambo December 27, 2021 17:19

Can anyone give me a hand with this? Why is not writing the values correctly? If i use OF9 just to run reconstructPar, it will reconstruct correctly ...


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