nearWallDist.C 3.98 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
6
     \\/     M anipulation  |
OpenFOAM bot's avatar
OpenFOAM bot committed
7
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2016 OpenFOAM Foundation
9 10 11 12
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

13 14 15 16
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
17 18 19 20 21 22 23

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
24
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
25 26 27 28 29 30 31 32 33 34 35

\*---------------------------------------------------------------------------*/

#include "nearWallDist.H"
#include "fvMesh.H"
#include "cellDistFuncs.H"
#include "wallFvPatch.H"
#include "surfaceFields.H"

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

36
void Foam::nearWallDist::calculate()
37 38 39 40
{
    cellDistFuncs wallUtils(mesh_);

    // Get patch ids of walls
41
    labelHashSet wallPatchIDs(wallUtils.getPatchIDs<wallPolyPatch>());
42 43 44 45 46 47 48 49 50 51

    // Size neighbours array for maximum possible

    labelList neighbours(wallUtils.maxPatchSize(wallPatchIDs));


    // Correct all cells with face on wall

    const volVectorField& cellCentres = mesh_.C();

52
    forAll(mesh_.boundary(), patchi)
53
    {
54
        fvPatchScalarField& ypatch = operator[](patchi);
55

56
        const fvPatch& patch = mesh_.boundary()[patchi];
57

58
        if (isA<wallFvPatch>(patch))
59 60 61
        {
            const polyPatch& pPatch = patch.patch();

62
            const labelUList& faceCells = patch.faceCells();
63 64

            // Check cells with face on wall
65
            forAll(patch, patchFacei)
66 67 68 69
            {
                label nNeighbours = wallUtils.getPointNeighbours
                (
                    pPatch,
70
                    patchFacei,
71 72 73
                    neighbours
                );

74
                label minFacei = -1;
75

76
                ypatch[patchFacei] = wallUtils.smallestDist
77
                (
78
                    cellCentres[faceCells[patchFacei]],
79 80 81
                    pPatch,
                    nNeighbours,
                    neighbours,
82
                    minFacei
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
                );
            }
        }
        else
        {
            ypatch = 0.0;
        }
    }
}


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

Foam::nearWallDist::nearWallDist(const Foam::fvMesh& mesh)
:
98
    volScalarField::Boundary
99 100 101 102 103 104 105
    (
        mesh.boundary(),
        mesh.V(),           // Dummy internal field,
        calculatedFvPatchScalarField::typeName
    ),
    mesh_(mesh)
{
106
    calculate();
107 108 109 110 111 112 113 114 115 116 117 118 119
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::nearWallDist::~nearWallDist()
{}


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

void Foam::nearWallDist::correct()
{
120
    if (mesh_.topoChanging())
121
    {
122 123 124 125
        const DimensionedField<scalar, volMesh>& V = mesh_.V();
        const fvBoundaryMesh& bnd = mesh_.boundary();

        this->setSize(bnd.size());
126
        forAll(*this, patchi)
127
        {
128 129
            this->set
            (
130
                patchi,
131 132 133
                fvPatchField<scalar>::New
                (
                    calculatedFvPatchScalarField::typeName,
134
                    bnd[patchi],
135 136 137
                    V
                )
            );
138 139 140
        }
    }

141
    calculate();
142 143 144 145
}


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