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  typeName + ":V_" + regionName_,
62  regionMesh().thisDb().time().timeName(),
63  regionMesh().thisDb(),
64  IOobject::MUST_READ,
65  IOobject::AUTO_WRITE
66  ),
67  regionMesh()
68  ),
69  scalarSigmaVsTPtr_(nullptr),
70  tensorSigmaVsTPtr_(nullptr),
71  curTimeIndex_(-1),
72  nIter_(1),
73  anisotropicElectricalConductivity_(false)
74 {
75  fieldNames_.resize(1, TName_);
76 
78 
79  if (anisotropicElectricalConductivity_)
80  {
81  Info<< " Using tensor electrical conductivity" << endl;
82 
83  initialiseSigma(coeffs_, tensorSigmaVsTPtr_);
84  }
85  else
86  {
87  Info<< " Using scalar electrical conductivity" << endl;
88 
89  initialiseSigma(coeffs_, scalarSigmaVsTPtr_);
90  }
91 
93 }
94 
95 
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 
99 (
100  const areaScalarField& h,
101  const areaScalarField& rho,
102  faMatrix<scalar>& eqn,
103  const label fieldi
104 )
105 {
106  if (isActive())
107  {
108  DebugInfo
109  << name() << ": applying source to "
110  << eqn.psi().name() << endl;
111 
112  if (curTimeIndex_ != mesh().time().timeIndex())
113  {
114  for (label i = 0; i < nIter_; ++i)
115  {
116  if (anisotropicElectricalConductivity_)
117  {
118  // Update sigma as a function of T if required
119  const areaTensorField& sigma =
120  updateSigma(tensorSigmaVsTPtr_);
121 
122  // Solve the electrical potential equation
124  VEqn.relax();
125  VEqn.solve();
126  }
127  else
128  {
129  // Update sigma as a function of T if required
130  const areaScalarField& sigma =
131  updateSigma(scalarSigmaVsTPtr_);
132 
133  // Solve the electrical potential equation
135  VEqn.relax();
136  VEqn.solve();
137  }
138  }
139 
140  curTimeIndex_ = mesh().time().timeIndex();
141  }
142 
143  // Add the Joule heating contribution
144  areaVectorField gradV("gradV", fac::grad(V_));
145 
146  if (debug > 1 && mesh().time().writeTime())
147  {
148  areaScalarField qgradV("gradVSource", (gradV & gradV));
149  qgradV.write();
150  }
151 
152  tmp<areaScalarField> tsource;
153 
154  const auto& obr = regionMesh().thisDb();
155 
156  if (anisotropicElectricalConductivity_)
157  {
158  const auto& sigma =
159  obr.lookupObject<areaTensorField>
160  (
161  typeName + ":sigma_" + regionName_
162  );
163 
164  tsource = (h*sigma & gradV) & gradV;
165  }
166  else
167  {
168  const auto& sigma =
169  obr.lookupObject<areaScalarField>
170  (
171  typeName + ":sigma_" + regionName_
172  );
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:160
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
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:85
#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:352
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:172
GeometricField< vector, faPatchField, areaMesh > areaVectorField
Definition: areaFieldsFwd.H:81
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:80