Пример #1
0
void Foam::AveragingMethods::Basic<Type>::updateGrad()
{
    GeometricField<Type, fvPatchField, volMesh> tempData
    (
        IOobject
        (
            "BasicAverage::Data",
            this->mesh_,
            IOobject::NO_READ,
            IOobject::NO_WRITE,
            false
        ),
        this->mesh_,
        dimensioned<Type>("zero", dimless, Zero),
        zeroGradientFvPatchField<Type>::typeName
    );
    tempData.primitiveFieldRef() = data_;
    tempData.correctBoundaryConditions();
    dataGrad_ = fvc::grad(tempData)->primitiveField();
}
Пример #2
0
void pointPatchInterpolation::interpolate
(
    const GeometricField<Type, fvPatchField, volMesh>& vf,
    GeometricField<Type, pointPatchField, pointMesh>& pf,
    bool overrideFixedValue
) const
{
    if (debug)
    {
        Info<< "pointPatchInterpolation::interpolate("
            << "const GeometricField<Type, fvPatchField, volMesh>&, "
            << "GeometricField<Type, pointPatchField, pointMesh>&) : "
            << "interpolating field from cells to points"
            << endl;
    }

    // Interpolate patch values: over-ride the internal values for the points
    // on the patch with the interpolated point values from the faces of the
    // patch

    const fvBoundaryMesh& bm = fvMesh_.boundary();

    forAll(bm, patchi)
    {
        if (!isA<emptyFvPatch>(bm[patchi]) && !bm[patchi].coupled())
        {
            pointPatchField<Type>& ppf = pf.boundaryField()[patchi];

            // Only map the values corresponding to the points associated with
            // faces, not "lone" points due to decomposition
            ppf.setInInternalField
            (
                pf.internalField(),
                patchInterpolators_[patchi].faceToPointInterpolate
                (
                    vf.boundaryField()[patchi]
                )()
            );

            if
            (
                overrideFixedValue
             && isA
                <
                    ValuePointPatchField
                    <
                        pointPatchField,
                        pointMesh,
                        pointPatch,
                        DummyMatrix,
                        Type
                    >
                >(ppf)
            )
            {
                refCast
                <
                    ValuePointPatchField
                    <
                        pointPatchField,
                        pointMesh,
                        pointPatch,
                        DummyMatrix,
                        Type
                    >
                >(ppf) = ppf;
            }
        }
    }


    // Correct patch-patch boundary points by interpolation "around" corners
    const labelListList& PointFaces = fvMesh_.pointFaces();

    forAll(patchPatchPoints_, pointi)
    {
        const label curPoint = patchPatchPoints_[pointi];
        const labelList& curFaces = PointFaces[curPoint];

        label fI = 0;

        // Reset the boundary value before accumulation
        pf[curPoint] = pTraits<Type>::zero;

        // Go through all the faces
        forAll(curFaces, facei)
        {
            if (!fvMesh_.isInternalFace(curFaces[facei]))
            {
                label patchi =
                    fvMesh_.boundaryMesh().whichPatch(curFaces[facei]);

                if (!isA<emptyFvPatch>(bm[patchi]) && !bm[patchi].coupled())
                {
                    label faceInPatchi =
                        bm[patchi].patch().whichFace(curFaces[facei]);

                    pf[curPoint] +=
                        patchPatchPointWeights_[pointi][fI]
                       *vf.boundaryField()[patchi][faceInPatchi];

                    fI++;
                }
            }
        }
    }


    // Update coupled and constrained boundaries
    pf.correctBoundaryConditions();

    if (debug)
    {
        Info<< "pointPatchInterpolation::interpolate("
            << "const GeometricField<Type, fvPatchField, volMesh>&, "
            << "GeometricField<Type, pointPatchField, pointMesh>&) : "
            << "finished interpolating field from cells to points"
            << endl;
    }
}
Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
Foam::linearUpwindV<Type>::correction
(
    const GeometricField<Type, fvPatchField, volMesh>& vf
) const
{
   const fvMesh& mesh = this->mesh();

   tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsfCorr
   (
       new GeometricField<Type, fvsPatchField, surfaceMesh>
       (
           IOobject
           (
               vf.name(),
               mesh.time().timeName(),
               mesh
           ),
           mesh,
           dimensioned<Type>
           (
               vf.name(),
               vf.dimensions(),
               pTraits<Type>::zero
           )
       )
   );

   GeometricField<Type, fvsPatchField, surfaceMesh>& sfCorr = tsfCorr();

   const surfaceScalarField& faceFlux = this->faceFlux_;
   const surfaceScalarField& w = mesh.weights();

   const labelList& own = mesh.owner();
   const labelList& nei = mesh.neighbour();

   const vectorField& C = mesh.C();
   const vectorField& Cf = mesh.Cf();

   GeometricField
       <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
       gradVf = gradScheme_().grad(vf);

    // Note: in order for the patchNeighbourField to be correct on coupled
    // boundaries, correctBoundaryConditions needs to be called.
    // The call shall be moved into the library fvc operators
    gradVf.correctBoundaryConditions(); 

   forAll(faceFlux, facei)
   {
       vector maxCorr;

       if (faceFlux[facei] > 0.0)
       {
           maxCorr =
               (1.0 - w[facei])
               *(vf[nei[facei]] - vf[own[facei]]);

           sfCorr[facei] =
               (Cf[facei] - C[own[facei]]) & gradVf[own[facei]];
       }
       else
       {
           maxCorr =
               w[facei]*(vf[own[facei]] - vf[nei[facei]]);

           sfCorr[facei] =
               (Cf[facei] - C[nei[facei]]) & gradVf[nei[facei]];
       }

       scalar sfCorrs = magSqr(sfCorr[facei]);
       scalar maxCorrs = sfCorr[facei] & maxCorr;

       if (sfCorrs > 0)
       {
           if (maxCorrs < 0)
           {
               sfCorr[facei] = vector::zero;
           }
           else if (sfCorrs > maxCorrs)
           {
               sfCorr[facei] *= maxCorrs/(sfCorrs + VSMALL);
           }
       }
       else if (sfCorrs < 0)
       {
           if (maxCorrs > 0)
           {
               sfCorr[facei] = vector::zero;
           }
           else if (sfCorrs < maxCorrs)
           {
               sfCorr[facei] *= maxCorrs/(sfCorrs - VSMALL);
           }
       }
   }