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/)
-   -   Dynamic Mesh Refinement - Sizes of two fields differ (https://www.cfd-online.com/Forums/openfoam-programming-development/120329-dynamic-mesh-refinement-sizes-two-fields-differ.html)

nlinder July 4, 2013 10:54

Dynamic Mesh Refinement - Sizes of two fields differ
 
Hi Foamers,

I am using (a modified) interDyMFoam solver. After all the meshMovement stuff, or just before "twoPhaseProperties.correct();" is called, I make some calculations. One of them is
Code:

scalarField Ca = mag(mup)*mag(uwall)/sigma;
where
Code:

scalarField mup = mu.boundaryField()[wallPatchID];
and uwall derives from (normalized form of the following Uwall)
Code:

vectorField Uwall = U.boundaryField()[wallPatchID];
.

This works fine without dynamic mesh refinement. When I do the same calculation with dynamic mesh refinement, the size of the fields differ if the mesh is refined. Or more precisely: The size of uwall relates to the refined mesh, mu remains unchanged.

Mu is created in createFields.H as
Code:

    volScalarField mu
    (
        IOobject
        (
            "mu",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT
        ),
        twoPhaseProperties.mu()
    );

Does anyone know how I can tell mu, that the mesh has been refined and it needs to be updated?

Thanks for any hints!

Greetings
Nicklas

gaza February 8, 2019 05:56

Hi

I have similar problem
after mesh refinement one of the field is unchanged
Code:

--> FOAM FATAL ERROR:
index 10240 out of range 0 ... 10239

    From function void Foam::UList<T>::checkIndex(Foam::label) const [with T = double; Foam::label = int]
    in file /home/przemek/OpenFOAM/OpenFOAM-v1612+/src/OpenFOAM/lnInclude/UListI.H at line 106.

FOAM aborting

I found that the reason is the line
Code:

volVectorField gradAlpha(fvc::grad(smoothAlpha_));
smoothAlpha_ is created in the constructor as follows
Code:

Foam::smoothInterfaceProperties::smoothInterfaceProperties
(
    const volScalarField& alpha1,
    const volVectorField& U,
    const IOdictionary& dict
)
:
    transportPropertiesDict_(dict),
    cAlpha_
    (
        readScalar
        (
            alpha1.mesh().solverDict(alpha1.name()).lookup("cAlpha")
        )
    ),
    smoothItr_
        (
            readScalar
            (
                alpha1.mesh().solutionDict().subDict("PIMPLE").lookup("smoothItr")
            )
        ),
    kSmoothItr_
    (
            readScalar
            (
                    alpha1.mesh().solutionDict().subDict("PIMPLE").lookup("kSmoothItr")
            )
    ),
    sigma_("sigma", dimensionSet(1, 0, -2, 0, 0), dict),
    deltaN_
    (
        "deltaN",
        1e-8/pow(average(alpha1.mesh().V()), 1.0/3.0)
    ),

    smoothAlpha_(alpha1),
    alpha1_(alpha1),
    U_(U),

    nHatf_
    (
        IOobject
        (
            "nHatf",
            alpha1_.time().timeName(),
            alpha1_.mesh()
        ),
        alpha1_.mesh(),
        dimensionedScalar("nHatf", dimArea, 0.0)
    ),

    K_
    (
        IOobject
        (
            "smoothInterfaceProperties:K",
            alpha1_.time().timeName(),
            alpha1_.mesh()
        ),
        alpha1_.mesh(),
        dimensionedScalar("K", dimless/dimLength, 0.0)
    )
{
    calculateK();
}

and
Code:

class smoothInterfaceProperties
{
    // Private data

        //- Keep a reference to the transportProperties dictionary
        const dictionary& transportPropertiesDict_;

        //- Compression coefficient
        scalar cAlpha_;

        // iteration numbers over smooth function
        scalar smoothItr_;

        // iteration numbers over smooth function for curvature, 0 represent no smooth
        scalar kSmoothItr_;

        //- Surface tension
        dimensionedScalar sigma_;


        //- Stabilisation for normalisation of the interface normal
        const dimensionedScalar deltaN_;
        volScalarField smoothAlpha_;

        const volScalarField& alpha1_;
        const volVectorField& U_;
        surfaceScalarField nHatf_;
        volScalarField K_;


    // Private Member Functions

        //- Disallow default bitwise copy construct and assignment
        smoothInterfaceProperties(const smoothInterfaceProperties&);
        void operator=(const smoothInterfaceProperties&);

        //- Correction for the boundary condition on the unit normal nHat on
        //  walls to produce the correct contact dynamic angle
        //  calculated from the component of U parallel to the wall
        void correctContactAngle
        (
            surfaceVectorField::Boundary& nHat,
            surfaceVectorField::Boundary& gradAlphaf
        ) const;

        //- Re-calculate the interface curvature
        void calculateK();


public:

    //- Conversion factor for degrees into radians
    static const scalar convertToRad;


    // Constructors

        //- Construct from volume fraction field gamma and IOdictionary
        smoothInterfaceProperties
        (
            const volScalarField& alpha1,
            const volVectorField& U,
            const IOdictionary&
        );


    // Member Functions

        scalar cAlpha() const
        {
            return cAlpha_;
        }

        const dimensionedScalar& deltaN() const
        {
            return deltaN_;
        }

        const surfaceScalarField& nHatf() const
        {
            return nHatf_;
        }

        const volScalarField& K() const
        {
            return K_;
        }

        const volScalarField& smoothAlpha() const
        {
            return smoothAlpha_;
        }

        const dimensionedScalar& sigma() const
        {
            return sigma_;
        }

        tmp<volScalarField> sigmaK() const
        {
            return sigma_*K_;
        }

        tmp<surfaceScalarField> surfaceTensionForce() const;

        //- Indicator of the proximity of the interface
        //  Field values are 1 near and 0 away for the interface.
        tmp<volScalarField> nearInterface() const;

        void correct()
        {
            calculateK();
        }

        //- Read transportProperties dictionary
        bool read();
};

When I change the problematic line into
Code:

volVectorField gradAlpha(fvc::grad(alpha1_));
everything goes well. But I need the version
Code:

volVectorField gradAlpha(fvc::grad(smoothAlpha_));
Can anybody explain why the line with alpha1_ works and smoothAlpha_ does not?

gaza February 8, 2019 06:54

I checked the size of smoothAlpha_ and it is updated
so what is wrong?

gaza February 8, 2019 07:57

I do not understand the difference between smoothAlpha_ and alpha1_
why with alpha1_ works and with smoothAlpha_ does not?

gaza February 9, 2019 07:08

OK I found solution

I had to change constructor
I do not know why the previous version did not work
Code:

...

    alpha1_(alpha1),

    smoothAlpha_
    (
        IOobject
        (
            "smoothAlpha",
            alpha1_.time().timeName(),
            alpha1_.mesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        alpha1_.mesh(),
        dimensionedScalar("smoothAlpha", dimless, 0.0)
    ),
...



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