interRegionExplicitPorositySource.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2022 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 
27 #include "fvMesh.H"
28 #include "fvMatrices.H"
29 #include "porosityModel.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace fv
37 {
38  defineTypeNameAndDebug(interRegionExplicitPorositySource, 0);
40  (
41  fvModel,
42  interRegionExplicitPorositySource,
43  dictionary
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * //
50 
51 void Foam::fv::interRegionExplicitPorositySource::readCoeffs()
52 {
53  UName_ = coeffs().lookupOrDefault<word>("U", "U");
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
60 (
61  const word& name,
62  const word& modelType,
63  const dictionary& dict,
64  const fvMesh& mesh
65 )
66 :
67  interRegionModel(name, modelType, dict, mesh),
68  UName_(word::null),
69  filter_
70  (
72  (
73  "filter",
74  mesh,
76  )
77  ),
78  porosityPtr_(nullptr)
79 {
80  readCoeffs();
81 
82  const fvMesh& nbrMesh = mesh.time().lookupObject<fvMesh>(nbrRegionName());
83 
84  meshInterp().mapTgtToSrc(scalarField(nbrMesh.nCells(), 1), filter_);
85 
86  const word zoneName(name + ":porous");
87 
88  const meshCellZones& cellZones = mesh.cellZones();
89  label zoneID = cellZones.findZoneID(zoneName);
90 
91  if (zoneID == -1)
92  {
93  meshCellZones& cz = const_cast<meshCellZones&>(cellZones);
94 
95  zoneID = cz.size();
96 
97  cz.setSize(zoneID + 1);
98 
99  // Scan the porous region filter for all cells containing porosity
100  labelList porousCells(mesh.nCells());
101 
102  label i = 0;
103  forAll(filter_, celli)
104  {
105  if (filter_[celli] > small)
106  {
107  porousCells[i++] = celli;
108  }
109  }
110  porousCells.setSize(i);
111 
112  cz.set
113  (
114  zoneID,
115  new cellZone
116  (
117  zoneName,
118  porousCells,
119  zoneID,
120  cellZones
121  )
122  );
123 
124  cz.clearAddressing();
125  }
126  else
127  {
129  << "Unable to create porous cellZone " << zoneName
130  << ": zone already exists"
131  << abort(FatalError);
132  }
133 
134  porosityPtr_ = porosityModel::New
135  (
136  name,
137  mesh,
138  coeffs(),
139  zoneName
140  );
141 }
142 
143 
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
145 
148 {
149  return wordList(1, UName_);
150 }
151 
152 
154 (
155  const volScalarField& rho,
156  fvMatrix<vector>& eqn,
157  const word& fieldName
158 ) const
159 {
160  fvMatrix<vector> porosityEqn(eqn.psi(), eqn.dimensions());
161  porosityPtr_->addResistance(porosityEqn);
162  eqn -= filter_*porosityEqn;
163 }
164 
165 
167 {
168  return true;
169 }
170 
171 
173 (
174  const polyTopoChangeMap&
175 )
176 {}
177 
178 
180 (
181  const polyMeshMap& map
182 )
183 {}
184 
185 
187 (
188  const polyDistributionMap&
189 )
190 {}
191 
192 
194 {
195  if (interRegionModel::read(dict))
196  {
197  readCoeffs();
198  return true;
199  }
200  else
201  {
202  return false;
203  }
204 }
205 
206 
207 // ************************************************************************* //
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: MeshZones.C:341
defineTypeNameAndDebug(fixedTemperatureConstraint, 0)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &)
Return a temporary field constructed from name, mesh.
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
virtual bool read(const dictionary &dict)
Read dictionary.
const meshCellZones & cellZones() const
Return cell zones.
Definition: polyMesh.H:501
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
const GeometricField< Type, fvPatchField, volMesh > & psi() const
Definition: fvMatrix.H:290
label nCells() const
const dimensionSet dimless
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:372
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Macros for easy insertion into run-time selection tables.
Base class for inter-region exchange.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static const word null
An empty word.
Definition: word.H:77
interRegionExplicitPorositySource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:72
virtual bool read(const dictionary &dict)
Read dictionary.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
A subset of mesh cells.
Definition: cellZone.H:61
addToRunTimeSelectionTable(fvConstraint, fixedTemperatureConstraint, dictionary)
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
List< word > wordList
A List of words.
Definition: fileName.H:54
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
A special matrix type and solver, designed for finite volume solutions of scalar equations.
static autoPtr< porosityModel > New(const word &name, const fvMesh &mesh, const dictionary &dict, const word &cellZoneName=word::null)
Selector.
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:50
void clearAddressing()
Clear addressing.
Definition: MeshZones.C:387
Namespace for OpenFOAM.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual void addSup(const volScalarField &rho, fvMatrix< vector > &eqn, const word &fieldName) const
const dimensionSet & dimensions() const
Definition: fvMatrix.H:295