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-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 "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  auto& obr = regionMesh().thisDb();
42 
43  if (dict.found("sigma"))
44  {
45  // Sigma to be defined using a Function1 type
46  sigmaVsTPtr = Function1<Type>::New("sigma", dict, &mesh_);
47 
48  auto tsigma = tmp<AreaFieldType>::New
49  (
50  IOobject
51  (
52  typeName + ":sigma_" + regionName_,
53  obr.time().timeName(),
54  obr,
57  ),
58  regionMesh(),
59  dimensioned<Type>(sqr(dimCurrent)/dimPower/dimLength, Zero)
60  );
61 
62  regIOobject::store(tsigma.ptr());
63 
64  Info<< " Conductivity 'sigma' read from dictionary as f(T)"
65  << nl << endl;
66  }
67  else
68  {
69  // Sigma to be defined by user input
70  auto tsigma = tmp<AreaFieldType>::New
71  (
72  IOobject
73  (
74  typeName + ":sigma_" + regionName_,
75  obr.time().timeName(),
76  obr,
79  ),
80  regionMesh()
81  );
82 
83  regIOobject::store(tsigma.ptr());
84 
85  Info<< " Conductivity 'sigma' read from file" << nl << endl;
86  }
87 }
88 
89 
90 template<class Type>
92 Foam::fa::jouleHeatingSource::updateSigma
93 (
94  const autoPtr<Function1<Type>>& sigmaVsTPtr
95 ) const
96 {
98 
99  const auto& obr = regionMesh().thisDb();
100 
101  auto& sigma =
102  obr.lookupObjectRef<AreaFieldType>(typeName + ":sigma_" + regionName_);
103 
104  if (!sigmaVsTPtr)
105  {
106  // Electrical conductivity field, sigma, was specified by the user
107  return sigma;
108  }
109 
110  const auto& T = obr.lookupObject<areaScalarField>(TName_);
111 
112  // Internal field
113  forAll(sigma, i)
114  {
115  sigma[i] = sigmaVsTPtr->value(T[i]);
116  }
117 
118 
119  // Boundary field
120  typename AreaFieldType::Boundary& bf = sigma.boundaryFieldRef();
121  forAll(bf, patchi)
122  {
123  faPatchField<Type>& pf = bf[patchi];
124  if (!isA<emptyFaPatch>(bf[patchi]))
125  {
126  const scalarField& Tbf = T.boundaryField()[patchi];
127  forAll(pf, facei)
128  {
129  pf[facei] = sigmaVsTPtr->value(Tbf[facei]);
130  }
131  }
132  }
133 
134  // Update processor patches
135  sigma.correctBoundaryConditions();
136 
137  return sigma;
138 }
139 
140 
141 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
dictionary dict
const fvMesh & mesh_
Reference to the mesh database.
Definition: faOption.H:156
dimensionedSymmTensor sqr(const dimensionedVector &dv)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
bool store()
Register object with its registry and transfer ownership to the registry.
Definition: regIOobjectI.H:36
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties)
virtual const objectRegistry & thisDb() const
Return reference to the mesh database.
Definition: faMesh.C:815
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
const dimensionSet dimPower
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
word regionName_
Region name (finite-area)
Definition: faOption.H:181
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
const dimensionSet dimCurrent(0, 0, 0, 0, 0, 1, 0)
Definition: dimensionSets.H:54
Nothing to be read.
Automatically write from objectRegistry::writeObject()
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
const faMesh & regionMesh() const
Return the region mesh database (demand-driven)
Definition: faOptionI.H:67
GeometricField< scalar, faPatchField, areaMesh > areaScalarField
Definition: areaFieldsFwd.H:80
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127