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) 2016-2018 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 "fvMatrices.H"
30 #include "fvmLaplacian.H"
31 #include "fvcGrad.H"
33 #include "basicThermo.H"
35 
36 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace fv
41 {
42  defineTypeNameAndDebug(jouleHeatingSource, 0);
43 
45  (
46  option,
47  jouleHeatingSource,
48  dictionary
49  );
50 }
51 }
52 
53 const Foam::word Foam::fv::jouleHeatingSource::sigmaName(typeName + ":sigma");
54 
55 
56 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
57 
58 const Foam::coordinateSystem& Foam::fv::jouleHeatingSource::csys() const
59 {
60  if (!csysPtr_ || !csysPtr_.valid())
61  {
63  << "Coordinate system invalid"
64  << abort(FatalError);
65  }
66 
67  return *csysPtr_;
68 }
69 
70 
72 Foam::fv::jouleHeatingSource::transformSigma
73 (
74  const volVectorField& sigmaLocal
75 ) const
76 {
77  auto tsigma = tmp<volSymmTensorField>::New
78  (
79  IOobject
80  (
81  sigmaName,
82  mesh_.time().timeName(),
83  mesh_,
86  false
87  ),
88  mesh_,
89  dimensionedSymmTensor(sigmaLocal.dimensions(), Zero),
90  zeroGradientFvPatchField<symmTensor>::typeName
91  );
92  auto& sigma = tsigma.ref();
93 
94  if (csys().uniform())
95  {
96  sigma.primitiveFieldRef() =
97  csys().transformPrincipal(sigmaLocal);
98  }
99  else
100  {
101  sigma.primitiveFieldRef() =
102  csys().transformPrincipal(mesh_.cellCentres(), sigmaLocal);
103  }
104 
105  sigma.correctBoundaryConditions();
106 
107  return tsigma;
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
112 
113 Foam::fv::jouleHeatingSource::jouleHeatingSource
114 (
115  const word& sourceName,
116  const word& modelType,
117  const dictionary& dict,
118  const fvMesh& mesh
119 )
120 :
121  option(sourceName, modelType, dict, mesh),
122  TName_("T"),
123  V_
124  (
125  IOobject
126  (
127  typeName + ":V",
128  mesh.time().timeName(),
129  mesh,
132  ),
133  mesh
134  ),
135  anisotropicElectricalConductivity_(false),
136  scalarSigmaVsTPtr_(nullptr),
137  vectorSigmaVsTPtr_(nullptr),
138  csysPtr_(nullptr),
139  curTimeIndex_(-1)
140 {
141  // Set the field name to that of the energy field from which the temperature
142  // is obtained
143 
144  const basicThermo& thermo =
145  mesh_.lookupObject<basicThermo>(basicThermo::dictName);
146 
147  fieldNames_.setSize(1, thermo.he().name());
148 
149  applied_.setSize(fieldNames_.size(), false);
150 
151  read(dict);
152 }
153 
154 
155 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 
158 {}
159 
160 
161 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
162 
164 (
165  const volScalarField& rho,
166  fvMatrix<scalar>& eqn,
167  const label fieldi
168 )
169 {
170  DebugInfo<< name() << ": applying source to " << eqn.psi().name() << endl;
171 
172  if (curTimeIndex_ != mesh_.time().timeIndex())
173  {
174  if (anisotropicElectricalConductivity_)
175  {
176  // Update sigma as a function of T if required
177  const volVectorField& sigmaLocal = updateSigma(vectorSigmaVsTPtr_);
178 
179  tmp<volSymmTensorField> sigma = transformSigma(sigmaLocal);
180 
181  // Solve the electrical potential equation
183  VEqn.relax();
184  VEqn.solve();
185  }
186  else
187  {
188  // Update sigma as a function of T if required
189  const volScalarField& sigma = updateSigma(scalarSigmaVsTPtr_);
190 
191  // Solve the electrical potential equation
193  VEqn.relax();
194  VEqn.solve();
195  }
196 
197  curTimeIndex_ = mesh_.time().timeIndex();
198  }
199 
200  // Add the Joule heating contribution
201 
202  const volVectorField gradV(fvc::grad(V_));
203  if (anisotropicElectricalConductivity_)
204  {
205  const volVectorField& sigmaLocal =
206  mesh_.lookupObject<volVectorField>(sigmaName);
207 
208  tmp<volSymmTensorField> sigma = transformSigma(sigmaLocal);
209 
210  eqn += (sigma & gradV) & gradV;
211  }
212  else
213  {
214  const volScalarField& sigma =
215  mesh_.lookupObject<volScalarField>(sigmaName);
216 
217  eqn += (sigma*gradV) & gradV;
218  }
219 }
220 
221 
223 {
224  if (option::read(dict))
225  {
226  coeffs_.readIfPresent("T", TName_);
227 
228  anisotropicElectricalConductivity_ =
229  coeffs_.get<bool>("anisotropicElectricalConductivity");
230 
231  if (anisotropicElectricalConductivity_)
232  {
233  Info<< " Using vector electrical conductivity" << endl;
234 
235  initialiseSigma(coeffs_, vectorSigmaVsTPtr_);
236 
237  csysPtr_ =
239  (
240  mesh_,
241  coeffs_,
242  coordinateSystem::typeName_()
243  );
244  }
245  else
246  {
247  Info<< " Using scalar electrical conductivity" << endl;
248 
249  initialiseSigma(coeffs_, scalarSigmaVsTPtr_);
250  }
251 
252  return true;
253  }
254 
255  return false;
256 }
257 
258 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
basicThermo.H
Foam::fvc::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:54
Foam::fv::jouleHeatingSource::~jouleHeatingSource
virtual ~jouleHeatingSource()
Destructor.
Definition: jouleHeatingSource.C:157
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::dimensionedSymmTensor
dimensioned< symmTensor > dimensionedSymmTensor
Dimensioned tensor obtained from generic dimensioned type.
Definition: dimensionedSymmTensor.H:50
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::basicThermo
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:63
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
zeroGradientFvPatchField.H
rho
rho
Definition: readInitialConditions.H:96
Foam::fvMatrix::psi
const GeometricField< Type, fvPatchField, volMesh > & psi() const
Definition: fvMatrix.H:285
fvMatrices.H
A special matrix type and solver, designed for finite volume solutions of scalar equations.
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::fv::option
Finite volume options abstract base class. Provides a base set of controls, e.g.:
Definition: fvOption.H:69
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::fvm::laplacian
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmLaplacian.C:48
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fv::jouleHeatingSource::addSup
virtual void addSup(const volScalarField &rho, fvMatrix< scalar > &eqn, const label fieldi)
Add explicit contribution to compressible momentum equation.
Definition: jouleHeatingSource.C:164
Foam::fvMatrix::relax
void relax(const scalar alpha)
Relax matrix (for steady-state solution).
Definition: fvMatrix.C:574
fvmLaplacian.H
Calculate the matrix for the laplacian of the field.
Foam::coordinateSystem::New
static autoPtr< coordinateSystem > New(word modelType, const objectRegistry &obr, const dictionary &dict)
Definition: coordinateSystemNew.C:82
Foam::dictionary::dictName
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionary.H:458
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::fv::option::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvOptionIO.C:55
Foam::volVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:60
fv
labelList fv(nPoints)
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(option, 0)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, fixedTemperatureConstraint, dictionary)
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:350
Foam::fv::jouleHeatingSource::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: jouleHeatingSource.C:222
jouleHeatingSource.H
fvcGrad.H
Calculate the gradient of the given field.
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:76
Foam::fvMatrix::solve
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
Definition: fvMatrixSolve.C:298
sigma
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties)
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::coordinateSystem
Base class for coordinate system specification, the default coordinate system type is cartesian .
Definition: coordinateSystem.H:122
Foam::IOobject::MUST_READ
Definition: IOobject.H:120