1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "singleLayerRegion.H"
29 #include "directMappedWallPolyPatch.H"
30 #include "zeroGradientFvPatchFields.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace regionModels
38 defineTypeNameAndDebug(singleLayerRegion, 0);
42 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
44 void Foam::regionModels::singleLayerRegion::constructMeshObjects()
46 // construct patch normal vectors
56 IOobject::READ_IF_PRESENT,
60 dimensionedVector("zero", dimless, vector::zero),
61 zeroGradientFvPatchField<vector>::typeName
65 // construct patch areas
75 IOobject::READ_IF_PRESENT,
79 dimensionedScalar("zero", dimArea, 0.0),
80 zeroGradientFvPatchField<scalar>::typeName
86 void Foam::regionModels::singleLayerRegion::initialise()
90 Pout<< "singleLayerRegion::initialise()" << endl;
93 label nBoundaryFaces = 0;
94 const polyBoundaryMesh& rbm = regionMesh().boundaryMesh();
95 volVectorField& nHat = nHatPtr_();
96 volScalarField& magSf = magSfPtr_();
97 forAll(intCoupledPatchIDs_, i)
99 const label patchI = intCoupledPatchIDs_[i];
100 const polyPatch& pp = rbm[patchI];
101 const labelList& fCells = pp.faceCells();
103 nBoundaryFaces += fCells.size();
105 UIndirectList<vector>(nHat, fCells) = pp.faceNormals();
106 UIndirectList<scalar>(magSf, fCells) = mag(pp.faceAreas());
108 nHat.correctBoundaryConditions();
109 magSf.correctBoundaryConditions();
111 if (nBoundaryFaces != regionMesh().nCells())
113 FatalErrorIn("singleLayerRegion::initialise()")
114 << "Number of primary region coupled boundary faces not equal to "
115 << "the number of cells in the local region" << nl << nl
116 << "Number of cells = " << regionMesh().nCells() << nl
117 << "Boundary faces = " << nBoundaryFaces << nl
118 << abort(FatalError);
121 scalarField passiveMagSf(magSf.size(), 0.0);
122 passivePatchIDs_.setSize(intCoupledPatchIDs_.size(), -1);
123 forAll(intCoupledPatchIDs_, i)
125 const label patchI = intCoupledPatchIDs_[i];
126 const polyPatch& ppIntCoupled = rbm[patchI];
127 if (ppIntCoupled.size() > 0)
129 label cellId = rbm[patchI].faceCells()[0];
130 const cell& cFaces = regionMesh().cells()[cellId];
132 label faceI = ppIntCoupled.start();
133 label faceO = cFaces.opposingFaceLabel(faceI, regionMesh().faces());
135 label passivePatchI = rbm.whichPatch(faceO);
136 passivePatchIDs_[i] = passivePatchI;
137 const polyPatch& ppPassive = rbm[passivePatchI];
138 UIndirectList<scalar>(passiveMagSf, ppPassive.faceCells()) =
139 mag(ppPassive.faceAreas());
143 Pstream::listCombineGather(passivePatchIDs_, maxEqOp<label>());
144 Pstream::listCombineScatter(passivePatchIDs_);
146 magSf.field() = 0.5*(magSf + passiveMagSf);
147 magSf.correctBoundaryConditions();
151 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
153 bool Foam::regionModels::singleLayerRegion::read()
155 return regionModel::read();
159 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
161 Foam::regionModels::singleLayerRegion::singleLayerRegion(const fvMesh& mesh)
170 Foam::regionModels::singleLayerRegion::singleLayerRegion
173 const word& regionType,
174 const word& modelName,
178 regionModel(mesh, regionType, modelName, false),
185 constructMeshObjects();
196 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
198 Foam::regionModels::singleLayerRegion::~singleLayerRegion()
202 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
204 const Foam::volVectorField& Foam::regionModels::singleLayerRegion::nHat() const
206 if (!nHatPtr_.valid())
208 FatalErrorIn("const fvMesh& singleLayerRegion::nHat() const")
209 << "Region patch normal vectors not available"
210 << abort(FatalError);
217 const Foam::volScalarField& Foam::regionModels::singleLayerRegion::magSf() const
219 if (!magSfPtr_.valid())
221 FatalErrorIn("const fvMesh& singleLayerRegion::magSf() const")
222 << "Region patch areas not available"
223 << abort(FatalError);
230 const Foam::labelList&
231 Foam::regionModels::singleLayerRegion::passivePatchIDs() const
233 return passivePatchIDs_;
237 // ************************************************************************* //