fvTotalSource.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) 2021-2024 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 "fvTotalSource.H"
27 #include "fvCellSet.H"
28 #include "fvMatrices.H"
29 
30 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
35 }
36 
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
40 void Foam::fvTotalSource::readCoeffs()
41 {
42  phaseName_ = coeffs().lookupOrDefault<word>("phase", word::null);
43 }
44 
45 
46 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
47 
49 {
51  << "eqnField=" << eqn.psi().name() << endl;
52 
53  const labelUList cells = this->cells();
54  const scalar V = this->V();
55  const dimensionedScalar S = this->S();
56 
57  // Check the dimensions
58  eqn.dimensions() = S.dimensions();
59 
60  // Apply the source
61  scalarField& eqnSource = eqn.source();
62  forAll(cells, i)
63  {
64  const scalar f = mesh().V()[cells[i]]/V;
65  eqnSource[cells[i]] -= f*S.value();
66  }
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
73 (
74  const word& name,
75  const word& modelType,
76  const fvMesh& mesh,
77  const dictionary& dict
78 )
79 :
80  fvSource(name, modelType, mesh, dict),
81  phaseName_()
82 {
83  readCoeffs();
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
88 
90 {}
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
95 bool Foam::fvTotalSource::addsSupToField(const word& fieldName) const
96 {
97  const word group = IOobject::group(fieldName);
98 
99  return group == word::null || group == phaseName_;
100 }
101 
102 
104 (
105  const word& fieldName
106 ) const
107 {
108  return
110  (
111  new scalarField
112  (
113  nCells(),
114  (IOobject::group(fieldName) == phaseName_ ? S().value()/V() : 0)
115  )
116  );
117 }
118 
119 
121 {
122  if (fvModel::read(dict))
123  {
124  readCoeffs();
125  return true;
126  }
127  else
128  {
129  return false;
130  }
131 }
132 
133 
134 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
word group() const
Return group (extension part of name)
Definition: IOobject.C:324
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T, if not found return the given default.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
Field< Type > & source()
Definition: fvMatrix.H:307
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:99
const dictionary & coeffs() const
Return dictionary.
Definition: fvModelI.H:59
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:199
Base class for finite volume sources.
Definition: fvSource.H:52
Base class for sources which are specified as a total value (e.g., volume or mass flow rate),...
Definition: fvTotalSource.H:55
fvTotalSource(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from explicit source name and mesh.
Definition: fvTotalSource.C:73
virtual bool read(const dictionary &dict)
Read source dictionary.
virtual tmp< scalarField > source(const word &fieldName) const
Return the source value.
virtual ~fvTotalSource()
Destructor.
Definition: fvTotalSource.C:89
virtual bool addsSupToField(const word &fieldName) const
Return true if the fvModel adds a source term to the given.
Definition: fvTotalSource.C:95
void addSource(fvMatrix< scalar > &eqn) const
Add a source term to a field-less proxy equation.
Definition: fvTotalSource.C:48
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
A special matrix type and solver, designed for finite volume solutions of scalar equations.
const cellShapeList & cells
#define DebugInFunction
Report an information message using Foam::Info.
const char *const group
Group name for atomic constants.
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const VolField< Type > &)
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
dictionary dict