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 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 {
39  defineTypeNameAndDebug(heatSource, 0);
41  (
42  fvModel,
43  heatSource,
44  dictionary
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  {
56  FatalIOErrorInFunction(coeffs())
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  {
63  FatalIOErrorInFunction(coeffs())
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),
82  Function1<scalar>::New("Q", coeffs())()
83  )
84  );
85  }
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
92 (
93  const word& name,
94  const word& modelType,
95  const dictionary& dict,
96  const fvMesh& mesh
97 )
98 :
99  fvModel(name, modelType, dict, mesh),
100  set_(coeffs(), mesh),
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>(basicThermo::dictName);
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 labelList& cells = set_.cells();
131 
132  const scalar t = mesh().time().value();
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  if (fvModel::read(dict))
156  {
157  readCoeffs();
158  return true;
159  }
160  else
161  {
162  return false;
163  }
164 }
165 
166 
167 // ************************************************************************* //
virtual ~heatSource()
Destructor.
Definition: heatSource.C:109
defineTypeNameAndDebug(fixedTemperatureConstraint, 0)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const word & name() const
Return name.
Definition: IOobject.H:303
fluidReactionThermo & thermo
Definition: createFields.H:28
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:77
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
Definition: heatSource.C:115
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: heatSource.C:153
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:158
Finite volume model abstract base class.
Definition: fvModel.H:55
Macros for easy insertion into run-time selection tables.
virtual volScalarField & he()=0
Enthalpy/Internal energy [J/kg].
dynamicFvMesh & mesh
virtual void addSup(fvMatrix< scalar > &eqn, const word &fieldName) const
Source term to energy equation.
Definition: heatSource.C:125
const cellShapeList & cells
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
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
heatSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from dictionary.
Definition: heatSource.C:92
static const word dictName
Name of the thermophysical properties dictionary.
Definition: basicThermo.H:129
Field< Type > & source()
Definition: fvMatrix.H:292
addToRunTimeSelectionTable(fvConstraint, fixedTemperatureConstraint, dictionary)
List< word > wordList
A List of words.
Definition: fileName.H:54
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
bool found
Namespace for OpenFOAM.
static autoPtr< Function1< scalar > > New(const word &name, const dictionary &dict)
Selector.
Definition: Function1New.C:32
IOerror FatalIOError