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-2024 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> FieldType;
40 
41  auto& obr = regionMesh().thisDb();
42 
43  IOobject io
44  (
45  IOobject::scopedName(typeName, "sigma_" + regionName_),
46  obr.time().timeName(),
47  obr,
51  );
52 
53  autoPtr<FieldType> tsigma;
54 
55  if (dict.found("sigma"))
56  {
57  // Sigma to be defined using a Function1 type
58  sigmaVsTPtr = Function1<Type>::New("sigma", dict, &mesh_);
59 
60  tsigma.reset
61  (
62  new FieldType
63  (
64  io,
65  regionMesh(),
66  Foam::zero{}, // value
68  )
69  );
70 
71  Info<< " Conductivity 'sigma' read from dictionary as f(T)"
72  << nl << endl;
73  }
74  else
75  {
76  // Sigma to be defined by user input
77  io.readOpt(IOobject::MUST_READ);
78 
79  tsigma.reset(new FieldType(io, regionMesh()));
80 
81  Info<< " Conductivity 'sigma' read from file" << nl << endl;
82  }
83 
85 }
86 
87 
88 template<class Type>
90 Foam::fa::jouleHeatingSource::updateSigma
91 (
92  const autoPtr<Function1<Type>>& sigmaVsTPtr
93 ) const
94 {
96 
97  const auto& obr = regionMesh().thisDb();
98 
99  auto& sigma =
100  obr.lookupObjectRef<FieldType>
101  (
102  IOobject::scopedName(typeName, "sigma_" + regionName_)
103  );
104 
105  if (!sigmaVsTPtr)
106  {
107  // Electrical conductivity field, sigma, was specified by the user
108  return sigma;
109  }
110 
111  const auto& T = obr.lookupObject<areaScalarField>(TName_);
112 
113  // Internal field
114  forAll(sigma, i)
115  {
116  sigma[i] = sigmaVsTPtr->value(T[i]);
117  }
118 
119 
120  // Boundary field
121  auto& bf = sigma.boundaryFieldRef();
122  forAll(bf, patchi)
123  {
124  faPatchField<Type>& pf = bf[patchi];
125  if (!isA<emptyFaPatch>(pf))
126  {
127  const scalarField& Tbf = T.boundaryField()[patchi];
128  forAll(pf, facei)
129  {
130  pf[facei] = sigmaVsTPtr->value(Tbf[facei]);
131  }
132  }
133  }
134 
135  // Update processor patches
136  sigma.correctBoundaryConditions();
137 
138  return sigma;
139 }
140 
141 
142 // ************************************************************************* //
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.
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties)
virtual const objectRegistry & thisDb() const
Reference to the mesh database.
Definition: faMesh.H:1203
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:40
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
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)
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Request registration (bool: true)
const faMesh & regionMesh() const
Return the region mesh database (demand-driven)
Definition: faOptionI.H:67