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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "singleLayerRegion.H"
30 #include "fvMesh.H"
31 #include "Time.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace regionModels
39 {
40  defineTypeNameAndDebug(singleLayerRegion, 0);
41 }
42 }
43 
44 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
45 
46 void Foam::regionModels::singleLayerRegion::constructMeshObjects()
47 {
48  // construct patch normal vectors
49  nHatPtr_.reset
50  (
51  new volVectorField
52  (
53  IOobject
54  (
55  "nHat",
56  time_.timeName(),
57  regionMesh(),
59  NO_WRITE
60  ),
61  regionMesh(),
63  zeroGradientFvPatchField<vector>::typeName
64  )
65  );
66 
67  // construct patch areas
68  magSfPtr_.reset
69  (
70  new volScalarField
71  (
72  IOobject
73  (
74  "magSf",
75  time_.timeName(),
76  regionMesh(),
78  NO_WRITE
79  ),
80  regionMesh(),
82  zeroGradientFvPatchField<scalar>::typeName
83  )
84  );
85 }
86 
87 
88 void Foam::regionModels::singleLayerRegion::initialise()
89 {
90  if (debug)
91  {
92  Pout<< "singleLayerRegion::initialise()" << endl;
93  }
94 
95  label nBoundaryFaces = 0;
96  const polyBoundaryMesh& rbm = regionMesh().boundaryMesh();
97  volVectorField& nHat = nHatPtr_();
98  volScalarField& magSf = magSfPtr_();
99  forAll(intCoupledPatchIDs_, i)
100  {
101  const label patchi = intCoupledPatchIDs_[i];
102  const polyPatch& pp = rbm[patchi];
103  const labelList& fCells = pp.faceCells();
104 
105  nBoundaryFaces += fCells.size();
106 
107  UIndirectList<vector>(nHat, fCells) = pp.faceNormals();
108  UIndirectList<scalar>(magSf, fCells) = mag(pp.faceAreas());
109  }
110  nHat.correctBoundaryConditions();
111  magSf.correctBoundaryConditions();
112 
113  if (nBoundaryFaces != regionMesh().nCells())
114  {
116  << "Number of primary region coupled boundary faces not equal to "
117  << "the number of cells in the local region" << nl << nl
118  << "Number of cells = " << regionMesh().nCells() << nl
119  << "Boundary faces = " << nBoundaryFaces << nl
120  << abort(FatalError);
121  }
122 
123  scalarField passiveMagSf(magSf.size(), Zero);
124  passivePatchIDs_.setSize(intCoupledPatchIDs_.size(), -1);
125  forAll(intCoupledPatchIDs_, i)
126  {
127  const label patchi = intCoupledPatchIDs_[i];
128  const polyPatch& ppIntCoupled = rbm[patchi];
129  if (ppIntCoupled.size() > 0)
130  {
131  label cellId = rbm[patchi].faceCells()[0];
132  const cell& cFaces = regionMesh().cells()[cellId];
133 
134  label facei = ppIntCoupled.start();
135  label faceO = cFaces.opposingFaceLabel(facei, regionMesh().faces());
136 
137  label passivePatchi = rbm.whichPatch(faceO);
138  passivePatchIDs_[i] = passivePatchi;
139  const polyPatch& ppPassive = rbm[passivePatchi];
140  UIndirectList<scalar>(passiveMagSf, ppPassive.faceCells()) =
141  mag(ppPassive.faceAreas());
142  }
143  }
144 
145  Pstream::listCombineGather(passivePatchIDs_, maxEqOp<label>());
146  Pstream::listCombineScatter(passivePatchIDs_);
147 
148  magSf.field() = 0.5*(magSf + passiveMagSf);
149  magSf.correctBoundaryConditions();
150 }
151 
152 
153 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
154 
156 {
157  return regionModel::read();
158 }
159 
160 
161 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
162 
163 Foam::regionModels::singleLayerRegion::singleLayerRegion
164 (
165  const fvMesh& mesh,
166  const word& regionType
167 )
168 :
169  regionModel(mesh, regionType),
170  nHatPtr_(nullptr),
171  magSfPtr_(nullptr),
172  passivePatchIDs_()
173 {}
174 
175 
176 Foam::regionModels::singleLayerRegion::singleLayerRegion
177 (
178  const fvMesh& mesh,
179  const word& regionType,
180  const word& modelName,
181  bool readFields
182 )
183 :
184  regionModel(mesh, regionType, modelName, false),
185  nHatPtr_(nullptr),
186  magSfPtr_(nullptr),
187  passivePatchIDs_()
188 {
189  if (active_)
190  {
191  constructMeshObjects();
192  initialise();
193 
194  if (readFields)
195  {
196  read();
197  }
198  }
199 }
200 
201 
202 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
203 
205 {}
206 
207 
208 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
209 
211 {
212  if (!nHatPtr_)
213  {
215  << "Region patch normal vectors not available"
216  << abort(FatalError);
217  }
218 
219  return *nHatPtr_;
220 }
221 
222 
224 {
225  if (!magSfPtr_)
226  {
228  << "Region patch areas not available"
229  << abort(FatalError);
230  }
231 
232  return *magSfPtr_;
233 }
234 
235 
236 const Foam::labelList&
238 {
239  return passivePatchIDs_;
240 }
241 
242 
243 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::regionModels::singleLayerRegion::passivePatchIDs
virtual const labelList & passivePatchIDs() const
Return the list of patch IDs opposite to internally.
Definition: singleLayerRegion.C:237
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::regionModels::defineTypeNameAndDebug
defineTypeNameAndDebug(KirchhoffShell, 0)
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::regionModels::singleLayerRegion::~singleLayerRegion
virtual ~singleLayerRegion()
Destructor.
Definition: singleLayerRegion.C:204
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::IOobject::IOobject
IOobject(const IOobject &)=default
Copy construct.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::regionModels::regionModel
Base class for region models.
Definition: regionModel.H:60
Foam::dimensionedVector
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Definition: dimensionedVector.H:50
Foam::dimArea
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:59
Foam::regionModels::singleLayerRegion::magSfPtr_
autoPtr< volScalarField > magSfPtr_
Face area magnitudes / [m2].
Definition: singleLayerRegion.H:81
singleLayerRegion.H
Foam::regionModels::singleLayerRegion::magSf
virtual const volScalarField & magSf() const
Return the face area magnitudes / [m2].
Definition: singleLayerRegion.C:223
Foam::regionModels::regionModel::regionMesh
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:64
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:187
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::regionModels::regionModel::read
virtual bool read()
Read control parameters from dictionary.
Definition: regionModel.C:149
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
cellId
label cellId
Definition: interrogateWallPatches.H:67
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Definition: ReadFieldsTemplates.C:312
Foam::volVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:62
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:290
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::regionModels::regionModel::time_
const Time & time_
Reference to the time database.
Definition: regionModel.H:90
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
Foam::regionModels::singleLayerRegion::nHatPtr_
autoPtr< volVectorField > nHatPtr_
Patch normal vectors.
Definition: singleLayerRegion.H:78
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::regionModels::singleLayerRegion::nHat
virtual const volVectorField & nHat() const
Return the patch normal vectors.
Definition: singleLayerRegion.C:210
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:432
Foam::GeometricField< vector, fvPatchField, volMesh >
zeroGradientFvPatchFields.H
Foam::regionModels::singleLayerRegion::read
virtual bool read()
Read control parameters from dictionary.
Definition: singleLayerRegion.C:155
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189