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-2023 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 {
40  (
41  fvModel,
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 fvMesh& mesh,
64  const dictionary& dict
65 )
66 :
67  interRegionModel(name, modelType, mesh, dict),
68  UName_(word::null),
69  filter_
70  (
71  volScalarField::Internal::New
72  (
73  "filter",
74  mesh,
76  )
77  ),
78  porosityPtr_(nullptr)
79 {
80  readCoeffs();
81 
83 
84  interpolate(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 {
169  return true;
170 }
171 
172 
174 (
175  const polyTopoChangeMap&
176 )
177 {
179 }
180 
181 
183 (
184  const polyMeshMap&
185 )
186 {
188 }
189 
190 
192 (
193  const polyDistributionMap&
194 )
195 {
197 }
198 
199 
201 {
203  {
204  readCoeffs();
205  return true;
206  }
207  else
208  {
209  return false;
210  }
211 }
212 
213 
214 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
Generic GeometricField class.
void setSize(const label)
Reset size of List.
Definition: List.C:281
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: MeshZones.C:341
void clearAddressing()
Clear addressing.
Definition: MeshZones.C:387
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
A subset of mesh cells.
Definition: cellZone.H:64
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
VolField< Type > & psi()
Definition: fvMatrix.H:289
const dimensionSet & dimensions() const
Definition: fvMatrix.H:302
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:406
Finite volume model abstract base class.
Definition: fvModel.H:59
const dictionary & coeffs() const
Return dictionary.
Definition: fvModelI.H:40
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:34
const word & name() const
Return const access to the source name.
Definition: fvModelI.H:28
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
interRegionExplicitPorositySource(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from components.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual bool read(const dictionary &dict)
Read dictionary.
virtual void addSup(const volScalarField &rho, fvMatrix< vector > &eqn, const word &fieldName) const
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Base class for inter-region exchange.
virtual bool read(const dictionary &dict)
Read dictionary.
const word & nbrRegionName() const
Return const access to the neighbour region name.
const fvMesh & nbrMesh() const
Return const access to the neighbour mesh.
tmp< Field< Type > > interpolate(const Field< Type > &field) const
Interpolate field.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
const meshCellZones & cellZones() const
Return cell zones.
Definition: polyMesh.H:451
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
static autoPtr< porosityModel > New(const word &name, const fvMesh &mesh, const dictionary &dict, const word &cellZoneName=word::null)
Selector.
label nCells() const
A class for handling words, derived from string.
Definition: word.H:62
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
A special matrix type and solver, designed for finite volume solutions of scalar equations.
addToRunTimeSelectionTable(fvConstraint, bound, dictionary)
defineTypeNameAndDebug(bound, 0)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const dimensionSet dimless
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
error FatalError
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
labelList fv(nPoints)
dictionary dict