singleLayerRegion.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "singleLayerRegion.H"
27 #include "fvMesh.H"
28 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace regionModels
36 {
38 }
39 }
40 
41 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
42 
44 {
45  // construct patch normal vectors
46  nHatPtr_.reset
47  (
48  new volVectorField
49  (
50  IOobject
51  (
52  "nHat",
53  time_.timeName(),
54  regionMesh(),
56  NO_WRITE
57  ),
58  regionMesh(),
61  )
62  );
63 
64  // construct patch areas
65  magSfPtr_.reset
66  (
67  new volScalarField
68  (
69  IOobject
70  (
71  "magSf",
72  time_.timeName(),
73  regionMesh(),
75  NO_WRITE
76  ),
77  regionMesh(),
78  dimensionedScalar("zero", dimArea, 0.0),
80  )
81  );
82 }
83 
84 
86 {
87  if (debug)
88  {
89  Pout<< "singleLayerRegion::initialise()" << endl;
90  }
91 
92  label nBoundaryFaces = 0;
93  const polyBoundaryMesh& rbm = regionMesh().boundaryMesh();
94  volVectorField& nHat = nHatPtr_();
95  volScalarField& magSf = magSfPtr_();
96  forAll(intCoupledPatchIDs_, i)
97  {
98  const label patchI = intCoupledPatchIDs_[i];
99  const polyPatch& pp = rbm[patchI];
100  const labelList& fCells = pp.faceCells();
101 
102  nBoundaryFaces += fCells.size();
103 
104  UIndirectList<vector>(nHat, fCells) = pp.faceNormals();
105  UIndirectList<scalar>(magSf, fCells) = mag(pp.faceAreas());
106  }
109 
110  if (nBoundaryFaces != regionMesh().nCells())
111  {
113  << "Number of primary region coupled boundary faces not equal to "
114  << "the number of cells in the local region" << nl << nl
115  << "Number of cells = " << regionMesh().nCells() << nl
116  << "Boundary faces = " << nBoundaryFaces << nl
117  << abort(FatalError);
118  }
119 
120  scalarField passiveMagSf(magSf.size(), 0.0);
121  passivePatchIDs_.setSize(intCoupledPatchIDs_.size(), -1);
122  forAll(intCoupledPatchIDs_, i)
123  {
124  const label patchI = intCoupledPatchIDs_[i];
125  const polyPatch& ppIntCoupled = rbm[patchI];
126  if (ppIntCoupled.size() > 0)
127  {
128  label cellId = rbm[patchI].faceCells()[0];
129  const cell& cFaces = regionMesh().cells()[cellId];
130 
131  label faceI = ppIntCoupled.start();
132  label faceO = cFaces.opposingFaceLabel(faceI, regionMesh().faces());
133 
134  label passivePatchI = rbm.whichPatch(faceO);
135  passivePatchIDs_[i] = passivePatchI;
136  const polyPatch& ppPassive = rbm[passivePatchI];
137  UIndirectList<scalar>(passiveMagSf, ppPassive.faceCells()) =
138  mag(ppPassive.faceAreas());
139  }
140  }
141 
142  Pstream::listCombineGather(passivePatchIDs_, maxEqOp<label>());
143  Pstream::listCombineScatter(passivePatchIDs_);
144 
145  magSf.field() = 0.5*(magSf + passiveMagSf);
147 }
148 
149 
150 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
151 
153 {
154  return regionModel::read();
155 }
156 
157 
158 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
159 
161 (
162  const fvMesh& mesh,
163  const word& regionType
164 )
165 :
166  regionModel(mesh, regionType),
167  nHatPtr_(NULL),
168  magSfPtr_(NULL),
169  passivePatchIDs_()
170 {}
171 
172 
174 (
175  const fvMesh& mesh,
176  const word& regionType,
177  const word& modelName,
178  bool readFields
179 )
180 :
181  regionModel(mesh, regionType, modelName, false),
182  nHatPtr_(NULL),
183  magSfPtr_(NULL),
184  passivePatchIDs_()
185 {
186  if (active_)
187  {
188  constructMeshObjects();
189  initialise();
190 
191  if (readFields)
192  {
193  read();
194  }
195  }
196 }
197 
198 
199 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
200 
202 {}
203 
204 
205 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
206 
208 {
209  if (!nHatPtr_.valid())
210  {
212  << "Region patch normal vectors not available"
213  << abort(FatalError);
214  }
215 
216  return nHatPtr_();
217 }
218 
219 
221 {
222  if (!magSfPtr_.valid())
223  {
225  << "Region patch areas not available"
226  << abort(FatalError);
227  }
228 
229  return magSfPtr_();
230 }
231 
232 
233 const Foam::labelList&
235 {
236  return passivePatchIDs_;
237 }
238 
239 
240 // ************************************************************************* //
Foam::regionModels::singleLayerRegion::passivePatchIDs
virtual const labelList & passivePatchIDs() const
Return the list of patch IDs opposite to internally.
Definition: singleLayerRegion.C:234
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
singleLayerRegion
Base class for single layer region models.
Foam::regionModels::singleLayerRegion::~singleLayerRegion
virtual ~singleLayerRegion()
Destructor.
Definition: singleLayerRegion.C:201
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::maxEqOp
Definition: ops.H:77
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::readFields
This function object reads fields from the time directories and adds them to the mesh database for fu...
Definition: readFields.H:104
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::zeroGradientFvPatchField
This boundary condition applies a zero-gradient condition from the patch internal field onto the patc...
Definition: zeroGradientFvPatchField.H:63
Foam::regionModels::regionModel
Definition: regionModel.H:57
Foam::dimensionedVector
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Definition: dimensionedVector.H:48
Foam::dimArea
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:57
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::regionModels::singleLayerRegion::magSfPtr_
autoPtr< volScalarField > magSfPtr_
Face area magnitudes / [m2].
Definition: singleLayerRegion.H:82
Foam::regionModels::singleLayerRegion::singleLayerRegion
singleLayerRegion(const singleLayerRegion &)
Disallow default bitwise copy construct.
singleLayerRegion.H
Foam::regionModels::singleLayerRegion::magSf
virtual const volScalarField & magSf() const
Return the face area magnitudes / [m2].
Definition: singleLayerRegion.C:220
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:41
Foam::polyBoundaryMesh::whichPatch
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Definition: polyBoundaryMesh.C:703
Foam::regionModels::regionModel::read
virtual bool read()
Read control parameters from dictionary.
Definition: regionModel.C:171
Foam::regionModels::singleLayerRegion::initialise
void initialise()
Initialise the region.
Definition: singleLayerRegion.C:85
Foam::regionModels::defineTypeNameAndDebug
defineTypeNameAndDebug(regionModel, 0)
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::polyPatch::faceCells
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:340
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
cellId
label cellId
Definition: interrogateWallPatches.H:67
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:885
Foam::Pstream::listCombineGather
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
Definition: combineGatherScatter.C:282
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::regionModels::regionModel::time_
const Time & time_
Reference to the time database.
Definition: regionModel.H:90
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::PrimitivePatch::faceNormals
const Field< PointType > & faceNormals() const
Return face normals for patch.
Definition: PrimitivePatchTemplate.C:520
Foam::cell::opposingFaceLabel
label opposingFaceLabel(const label masterFaceLabel, const faceUList &meshFaces) const
Return index of opposite face.
Definition: oppositeCellFace.C:40
Foam::Time::timeName
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::polyPatch::faceAreas
const vectorField::subField faceAreas() const
Return face normals.
Definition: polyPatch.C:314
Foam::regionModels::singleLayerRegion::nHatPtr_
autoPtr< volVectorField > nHatPtr_
Patch normal vectors.
Definition: singleLayerRegion.H:79
Foam::regionModels::singleLayerRegion::nHat
virtual const volVectorField & nHat() const
Return the patch normal vectors.
Definition: singleLayerRegion.C:207
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
Foam::regionModels::singleLayerRegion::constructMeshObjects
void constructMeshObjects()
Construct region mesh and fields.
Definition: singleLayerRegion.C:43
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Pstream::listCombineScatter
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
Definition: combineGatherScatter.C:417
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::IOobject::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: IOobject.H:110
zeroGradientFvPatchFields.H
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::regionModels::singleLayerRegion::read
virtual bool read()
Read control parameters from dictionary.
Definition: singleLayerRegion.C:152
Foam::regionModels::regionModel::regionMesh
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:61