heatSource.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 "heatSource.H"
27 #include "basicThermo.H"
28 #include "fvModels.H"
29 #include "fvMatrix.H"
30 #include "Scale.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace fv
38 {
41  (
42  fvModel,
43  heatSource,
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 void Foam::fv::heatSource::readCoeffs()
53 {
54  if (!coeffs().found("q") && !coeffs().found("Q"))
55  {
57  << "Neither heat source per unit volume, q, or total heat source, "
58  << "Q, has been specified. One is required." << exit(FatalIOError);
59  }
60 
61  if (coeffs().found("q") && coeffs().found("Q"))
62  {
64  << "Both heat source per unit volume, q, and total heat source, "
65  << "Q, have been specified. One is required."
66  << exit(FatalIOError);
67  }
68 
69  if (coeffs().found("q"))
70  {
71  q_.reset
72  (
74  (
75  "q",
76  mesh().time().userUnits(),
78  coeffs()
79  ).ptr()
80  );
81  }
82  else
83  {
84  q_.reset
85  (
86  new Function1s::Scale<scalar>
87  (
88  "q",
89  Function1s::Constant<scalar>("1/V", 1/set_.V()),
90  Function1s::Constant<scalar>("1", 1),
92  (
93  "Q",
94  mesh().time().userUnits(),
95  dimPower,
96  coeffs()
97  )()
98  )
99  );
100  }
101 }
102 
103 
104 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105 
107 (
108  const word& name,
109  const word& modelType,
110  const fvMesh& mesh,
111  const dictionary& dict
112 )
113 :
114  fvModel(name, modelType, mesh, dict),
115  set_(mesh, coeffs()),
116  q_(nullptr)
117 {
118  readCoeffs();
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
123 
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
131 {
132  const basicThermo& thermo =
133  mesh().lookupObject<basicThermo>(physicalProperties::typeName);
134 
135  return wordList(1, thermo.he().name());
136 }
137 
138 
140 (
141  const volScalarField& he,
142  fvMatrix<scalar>& eqn
143 ) const
144 {
145  const labelUList cells = set_.cells();
146 
147  const scalar q = q_->value(mesh().time().value());
148 
149  scalarField& eqnSource = eqn.source();
150  forAll(cells, i)
151  {
152  eqnSource[cells[i]] -= mesh().V()[cells[i]]*q;
153  }
154 }
155 
156 
158 (
159  const volScalarField& rho,
160  const volScalarField& he,
161  fvMatrix<scalar>& eqn
162 ) const
163 {
164  addSup(he, eqn);
165 }
166 
167 
169 {
170  set_.movePoints();
171  return true;
172 }
173 
174 
176 {
177  set_.topoChange(map);
178 }
179 
180 
182 {
183  set_.mapMesh(map);
184 }
185 
186 
188 {
189  set_.distribute(map);
190 }
191 
192 
194 {
195  if (fvModel::read(dict))
196  {
197  readCoeffs();
198  return true;
199  }
200  else
201  {
202  return false;
203  }
204 }
205 
206 
207 // ************************************************************************* //
bool found
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
static autoPtr< Function1< scalar > > New(const word &name, const Function1s::unitConversions &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
Generic GeometricField class.
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:78
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
scalar V() const
Return const access to the total cell volume.
Definition: fvCellSetI.H:28
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
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
Finite volume model abstract base class.
Definition: fvModel.H:59
const dictionary & coeffs() const
Return dictionary.
Definition: fvModelI.H:59
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:199
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:53
Model for applying a heat source. Requires either the power, Q, or the power per unit volume,...
Definition: heatSource.H:67
virtual bool movePoints()
Update for mesh motion.
Definition: heatSource.C:168
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
Definition: heatSource.C:130
virtual ~heatSource()
Destructor.
Definition: heatSource.C:124
virtual void addSup(const volScalarField &he, fvMatrix< scalar > &eqn) const
Source term to energy equation.
Definition: heatSource.C:140
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: heatSource.C:175
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: heatSource.C:187
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: heatSource.C:193
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: heatSource.C:181
heatSource(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: heatSource.C:107
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
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
const cellShapeList & cells
addToRunTimeSelectionTable(fvConstraint, bound, dictionary)
defineTypeNameAndDebug(bound, 0)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< word > wordList
A List of words.
Definition: fileName.H:54
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
const dimensionSet dimPower
const dimensionSet dimVolume
IOerror FatalIOError
thermo he()
labelList fv(nPoints)
dictionary dict
fluidMulticomponentThermo & thermo
Definition: createFields.H:31