jouleHeatingSource.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "jouleHeatingSource.H"
29 #include "fam.H"
30 #include "faScalarMatrix.H"
32 
33 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace fa
38 {
39  defineTypeNameAndDebug(jouleHeatingSource, 0);
40  addToRunTimeSelectionTable(option, jouleHeatingSource, dictionary);
41 }
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 (
49  const word& sourceName,
50  const word& modelType,
51  const dictionary& dict,
52  const fvMesh& m
53 )
54 :
55  fa::faceSetOption(sourceName, modelType, dict, m),
56  TName_(dict.getOrDefault<word>("T", "T")),
57  V_
58  (
59  IOobject
60  (
61  IOobject::scopedName(typeName, "V_" + regionName_),
62  regionMesh().thisDb().time().timeName(),
63  regionMesh().thisDb(),
64  IOobject::MUST_READ,
65  IOobject::AUTO_WRITE,
66  IOobject::REGISTER
67  ),
68  regionMesh()
69  ),
70  scalarSigmaVsTPtr_(nullptr),
71  tensorSigmaVsTPtr_(nullptr),
72  curTimeIndex_(-1),
73  nIter_(1),
74  anisotropicElectricalConductivity_(false)
75 {
76  fieldNames_.resize(1, TName_);
77 
79 
80  if (anisotropicElectricalConductivity_)
81  {
82  Info<< " Using tensor electrical conductivity" << endl;
83 
84  initialiseSigma(coeffs_, tensorSigmaVsTPtr_);
85  }
86  else
87  {
88  Info<< " Using scalar electrical conductivity" << endl;
89 
90  initialiseSigma(coeffs_, scalarSigmaVsTPtr_);
91  }
92 
94 }
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
100 (
101  const areaScalarField& h,
102  const areaScalarField& rho,
103  faMatrix<scalar>& eqn,
104  const label fieldi
105 )
106 {
107  if (isActive())
108  {
109  DebugInfo
110  << name() << ": applying source to "
111  << eqn.psi().name() << endl;
112 
113  if (curTimeIndex_ != mesh().time().timeIndex())
114  {
115  for (label i = 0; i < nIter_; ++i)
116  {
117  if (anisotropicElectricalConductivity_)
118  {
119  // Update sigma as a function of T if required
120  const areaTensorField& sigma =
121  updateSigma(tensorSigmaVsTPtr_);
122 
123  // Solve the electrical potential equation
125  VEqn.relax();
126  VEqn.solve();
127  }
128  else
129  {
130  // Update sigma as a function of T if required
131  const areaScalarField& sigma =
132  updateSigma(scalarSigmaVsTPtr_);
133 
134  // Solve the electrical potential equation
136  VEqn.relax();
137  VEqn.solve();
138  }
139  }
140 
141  curTimeIndex_ = mesh().time().timeIndex();
142  }
143 
144  // Add the Joule heating contribution
145  const word sigmaName
146  (
147  IOobject::scopedName(typeName, "sigma_" + regionName_)
148  );
149 
150  areaVectorField gradV("gradV", fac::grad(V_));
151 
152  if (debug > 1 && mesh().time().writeTime())
153  {
154  areaScalarField qgradV("gradVSource", (gradV & gradV));
155  qgradV.write();
156  }
157 
158  tmp<areaScalarField> tsource;
159 
160  const auto& obr = regionMesh().thisDb();
161 
162  if (anisotropicElectricalConductivity_)
163  {
164  const auto& sigma =
165  obr.lookupObject<areaTensorField>(sigmaName);
166 
167  tsource = (h*sigma & gradV) & gradV;
168  }
169  else
170  {
171  const auto& sigma =
172  obr.lookupObject<areaScalarField>(sigmaName);
173 
174  tsource = (h*sigma*gradV) & gradV;
175  }
176 
177  // Apply subMesh filter
178  faceSetOption::subsetFilter(tsource.ref().primitiveFieldRef());
179 
180  eqn += tsource;
181  }
182 }
183 
184 
186 {
187  if (fa::option::read(dict))
188  {
189  dict.readIfPresent("T", TName_);
190 
191  dict.readIfPresent("nIter", nIter_);
192 
193  anisotropicElectricalConductivity_ =
194  dict.get<bool>("anisotropicElectricalConductivity");
195 
196  return true;
197  }
198 
199  return false;
200 }
201 
202 
203 // ************************************************************************* //
addToRunTimeSelectionTable(option, limitHeight, dictionary)
dictionary dict
Namespace of functions to calculate implicit derivatives returning a matrix. Time derivatives are cal...
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: faOption.H:171
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:153
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
jouleHeatingSource(const word &sourceName, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from explicit source name and mesh.
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties)
Macros for easy insertion into run-time selection tables.
tmp< faMatrix< Type > > laplacian(const GeometricField< Type, faPatchField, areaMesh > &vf)
Definition: famLaplacian.C:42
word timeName
Definition: getTimeIndex.H:3
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:40
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
defineTypeNameAndDebug(limitHeight, 0)
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faOptionIO.C:47
GeometricField< tensor, faPatchField, areaMesh > areaTensorField
Definition: areaFieldsFwd.H:88
#define DebugInfo
Report an information message using Foam::Info.
virtual void addSup(const areaScalarField &h, const areaScalarField &rho, faMatrix< scalar > &eqn, const label fieldi)
Add explicit contribution to compressible momentum equation.
int debug
Static debugging option.
const dimensionedScalar h
Planck constant.
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: faOption.C:38
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A special matrix type and solver, designed for finite area solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: faMatricesFwd.H:37
Template specialisation for scalar faMatrix.
messageStream Info
Information stream (stdout output on master, null elsewhere)
void subsetFilter(List< Type > &field) const
Zero all non-selected locations within field.
const GeometricField< Type, faPatchField, areaMesh > & psi() const
Definition: faMatrix.H:348
virtual bool read(const dictionary &dict)
Read source dictionary.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
GeometricField< vector, faPatchField, areaMesh > areaVectorField
Definition: areaFieldsFwd.H:76
dictionary coeffs_
Dictionary containing source coefficients.
Definition: faOption.H:166
Namespace for OpenFOAM.
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:51
label timeIndex
Definition: getTimeIndex.H:24
GeometricField< scalar, faPatchField, areaMesh > areaScalarField
Definition: areaFieldsFwd.H:72