jouleHeatingSourceTemplates.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-2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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 "emptyFaPatch.H"
29
30// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31
32template<class Type>
33void Foam::fa::jouleHeatingSource::initialiseSigma
34(
35 const dictionary& dict,
36 autoPtr<Function1<Type>>& sigmaVsTPtr
37)
38{
39 typedef GeometricField<Type, faPatchField, areaMesh> AreaFieldType;
40
41 if (dict.found("sigma"))
42 {
43 // Sigma to be defined using a Function1 type
44 sigmaVsTPtr = Function1<Type>::New("sigma", dict, &mesh_);
45
46 auto tsigma = tmp<AreaFieldType>::New
47 (
48 IOobject
49 (
50 typeName + ":sigma_" + regionName_,
52 mesh_,
55 ),
56 regionMesh(),
57 dimensioned<Type>(sqr(dimCurrent)/dimPower/dimLength, Zero)
58 );
59
60 mesh_.objectRegistry::store(tsigma.ptr());
61
62 Info<< " Conductivity 'sigma' read from dictionary as f(T)"
63 << nl << endl;
64 }
65 else
66 {
67 // Sigma to be defined by user input
68 auto tsigma = tmp<AreaFieldType>::New
69 (
70 IOobject
71 (
72 typeName + ":sigma_" + regionName_,
73 mesh().time().timeName(),
74 mesh(),
77 ),
79 );
80
81 mesh().objectRegistry::store(tsigma.ptr());
82
83 Info<< " Conductivity 'sigma' read from file" << nl << endl;
84 }
85}
86
87
88template<class Type>
90Foam::fa::jouleHeatingSource::updateSigma
91(
92 const autoPtr<Function1<Type>>& sigmaVsTPtr
93) const
94{
96
97 auto& sigma =
98 mesh().lookupObjectRef<AreaFieldType>
99 (
100 typeName + ":sigma_" + regionName_
101 );
102
103 if (!sigmaVsTPtr.valid())
104 {
105 // Electrical conductivity field, sigma, was specified by the user
106 return sigma;
107 }
108
109 const auto& T = mesh().lookupObject<areaScalarField>(TName_);
110
111 // Internal field
112 forAll(sigma, i)
113 {
114 sigma[i] = sigmaVsTPtr->value(T[i]);
115 }
116
117
118 // Boundary field
119 typename AreaFieldType::Boundary& bf = sigma.boundaryFieldRef();
120 forAll(bf, patchi)
121 {
122 faPatchField<Type>& pf = bf[patchi];
123 if (!isA<emptyFaPatch>(bf[patchi]))
124 {
125 const scalarField& Tbf = T.boundaryField()[patchi];
126 forAll(pf, facei)
127 {
128 pf[facei] = sigmaVsTPtr->value(Tbf[facei]);
129 }
130 }
131 }
132
133 // Update processor patches
134 sigma.correctBoundaryConditions();
135
136 return sigma;
137}
138
139
140// ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:96
Generic GeometricField class.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
const Type & value() const
Return const reference to value.
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: faPatchField.H:82
const fvMesh & mesh_
Reference to the mesh database.
Definition: faOption.H:152
word regionName_
Region name (finite-area)
Definition: faOption.H:170
const fvMesh & mesh() const noexcept
Return const access to the mesh database.
Definition: faOptionI.H:36
const faMesh & regionMesh() const
Return the region mesh database (demand-driven)
Definition: faOptionI.H:80
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
const volScalarField & T
dynamicFvMesh & mesh
word timeName
Definition: getTimeIndex.H:3
const dimensionSet dimPower
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
const dimensionSet dimCurrent(0, 0, 0, 0, 0, 1, 0)
Definition: dimensionSets.H:56
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333