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 -------------------------------------------------------------------------------
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 "emptyFaPatch.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 template<class Type>
33 void 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_,
51  mesh_.time().timeName(),
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  ),
78  regionMesh()
79  );
80 
81  mesh().objectRegistry::store(tsigma.ptr());
82 
83  Info<< " Conductivity 'sigma' read from file" << nl << endl;
84  }
85 }
86 
87 
88 template<class Type>
90 Foam::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 // ************************************************************************* //
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::faPatchField
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:50
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::fa::option::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: faOption.H:152
Foam::dimCurrent
const dimensionSet dimCurrent(0, 0, 0, 0, 0, 1, 0)
Definition: dimensionSets.H:56
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::fa::option::regionMesh
const faMesh & regionMesh() const
Return the region mesh database (demand-driven)
Definition: faOptionI.H:80
Foam::dimPower
const dimensionSet dimPower
timeName
word timeName
Definition: getTimeIndex.H:3
dict
dictionary dict
Definition: searchingEngine.H:14
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fa::option::regionName_
word regionName_
Region name (finite-area)
Definition: faOption.H:170
Foam::fa::option::mesh
const fvMesh & mesh() const noexcept
Return const access to the mesh database.
Definition: faOptionI.H:36
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
sigma
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties)
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::IOobject::NO_READ
Definition: IOobject.H:188
emptyFaPatch.H
Foam::IOobject::MUST_READ
Definition: IOobject.H:185