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-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 
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(Function1<scalar>::New("q", coeffs()).ptr());
72  }
73  else
74  {
75  q_.reset
76  (
77  new Function1s::Scale<scalar>
78  (
79  "q",
80  Function1s::Constant<scalar>("1/V", 1/set_.V()),
81  Function1s::Constant<scalar>("1", 1),
83  )
84  );
85  }
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
92 (
93  const word& name,
94  const word& modelType,
95  const fvMesh& mesh,
96  const dictionary& dict
97 )
98 :
99  fvModel(name, modelType, mesh, dict),
100  set_(mesh, coeffs()),
101  q_(nullptr)
102 {
103  readCoeffs();
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
108 
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
116 {
117  const basicThermo& thermo =
118  mesh().lookupObject<basicThermo>(physicalProperties::typeName);
119 
120  return wordList(1, thermo.he().name());
121 }
122 
123 
125 (
126  fvMatrix<scalar>& eqn,
127  const word& fieldName
128 ) const
129 {
130  const labelUList cells = set_.cells();
131 
132  const scalar t = mesh().time().userTimeValue();
133  const scalar q = q_->value(t);
134 
135  forAll(cells, i)
136  {
137  eqn.source()[cells[i]] -= mesh().V()[cells[i]]*q;
138  }
139 }
140 
141 
143 (
144  const volScalarField& rho,
145  fvMatrix<scalar>& eqn,
146  const word& fieldName
147 ) const
148 {
149  addSup(eqn, fieldName);
150 }
151 
152 
154 {
155  set_.movePoints();
156  return true;
157 }
158 
159 
161 {
162  set_.topoChange(map);
163 }
164 
165 
167 {
168  set_.mapMesh(map);
169 }
170 
171 
173 {
174  set_.distribute(map);
175 }
176 
177 
179 {
180  if (fvModel::read(dict))
181  {
182  readCoeffs();
183  return true;
184  }
185  else
186  {
187  return false;
188  }
189 }
190 
191 
192 // ************************************************************************* //
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< Type > > New(const word &name, const dictionary &dict)
Selector.
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:160
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:101
Finite volume model abstract base class.
Definition: fvModel.H:59
const dictionary & coeffs() const
Return dictionary.
Definition: fvModelI.H:40
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:187
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:153
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
Definition: heatSource.C:115
virtual ~heatSource()
Destructor.
Definition: heatSource.C:109
virtual void addSup(fvMatrix< scalar > &eqn, const word &fieldName) const
Source term to energy equation.
Definition: heatSource.C:125
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: heatSource.C:160
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: heatSource.C:172
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: heatSource.C:178
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: heatSource.C:166
heatSource(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: heatSource.C:92
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:318
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
IOerror FatalIOError
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
labelList fv(nPoints)
dictionary dict
fluidMulticomponentThermo & thermo
Definition: createFields.H:31