solidElectricalConduction.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include "basicThermo.H"
29 #include "fvmLaplacian.H"
31 
32 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace fv
37 {
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void Foam::fv::solidElectricalConduction::readCoeffs(const dictionary& dict)
47 {
48  const word sigmaKey = "sigma";
49  const word sigmaScalarKey =
50  sigmaKey + '<' + pTraits<scalar>::typeName + '>';
51  const word sigmaTensorKey =
52  sigmaKey + '<' + pTraits<tensor>::typeName + '>';
53 
54  const bool haveSigma = dict.found(sigmaKey);
55  const bool haveScalarSigma = dict.found(sigmaScalarKey);
56  const bool haveTensorSigma = dict.found(sigmaTensorKey);
57 
58  const label nHaveSigmas =
59  label(haveSigma) + label(haveScalarSigma) + label(haveTensorSigma);
60 
61  if (nHaveSigmas != 1)
62  {
64  << (nHaveSigmas ? "multiple" : "none")
65  << " of keywords " << sigmaKey << ", " << sigmaScalarKey << ' '
66  << (nHaveSigmas ? "and" : "or") << ' ' << sigmaTensorKey
67  << " defined in dictionary " << dict.name()
68  << exit(FatalIOError);
69  }
70 
71  if (haveSigma || haveScalarSigma)
72  {
73  sigmaScalarPtr_.reset
74  (
75  new FunctionalGeometricField<scalar, fvMesh>
76  (
77  sigmaKey,
78  haveSigma ? sigmaKey : sigmaScalarKey,
79  mesh(),
81  dict
82  )
83  );
84  }
85  else
86  {
87  sigmaTensorPtr_.reset
88  (
89  new FunctionalGeometricField<tensor, fvMesh>
90  (
91  sigmaKey,
92  sigmaTensorKey,
93  mesh(),
95  dict
96  )
97  );
98  }
99 
100  writeSigma_ = dict.lookupOrDefault<bool>("writeSigma", false);
101 }
102 
103 
104 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105 
107 (
108  const word& name,
109  const word& modelType,
110  const fvMesh& mesh,
111  const dictionary& dict
112 )
113 :
114  fvModel(name, modelType, mesh, dict),
115  phi_
116  (
117  IOobject
118  (
119  "phi",
120  mesh().time().name(),
121  mesh(),
122  IOobject::MUST_READ,
123  IOobject::AUTO_WRITE
124  ),
125  mesh()
126  ),
127  I_
128  (
129  IOobject
130  (
131  "I",
132  mesh().time().name(),
133  mesh(),
134  IOobject::READ_IF_PRESENT,
135  IOobject::AUTO_WRITE
136  ),
137  mesh(),
138  dimensionedScalar(dimCurrent, scalar(0))
139  ),
140  sigmaScalarPtr_(),
141  sigmaTensorPtr_(),
142  writeSigma_(false),
143  meshChanged_(true)
144 {
145  readCoeffs(dict);
146 
147  mesh().schemes().setFluxRequired(phi_.name());
148 }
149 
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
154 {
155  const basicThermo& thermo =
157 
158  return wordList(1, thermo.he().name());
159 }
160 
161 
163 (
164  const volScalarField& rho,
165  const volScalarField& he,
166  fvMatrix<scalar>& eqn
167 ) const
168 {
169  eqn += fvc::div(I_*fvc::interpolate(phi_));
170 }
171 
172 
174 {
175  const bool sigmaChanged =
176  sigmaScalarPtr_.valid()
177  ? sigmaScalarPtr_->update()
178  : sigmaTensorPtr_->update();
179 
180  if (sigmaChanged || meshChanged_)
181  {
182  const label nCorr =
183  mesh()
184  .solution()
185  .solverDict(phi_.name())
186  .lookupOrDefault<label>("nCorr", 0);
187 
188  for (label i = 0; i <= nCorr; ++ i)
189  {
190  fvMatrix<scalar> phiEqn
191  (
192  sigmaScalarPtr_.valid()
193  ? fvm::laplacian(sigmaScalarPtr_(), phi_)
194  : fvm::laplacian(sigmaTensorPtr_(), phi_)
195  );
196 
197  phiEqn.solve();
198 
199  if (i == nCorr) I_ = phiEqn.flux();
200  }
201  }
202 
204  {
205  meshChanged_ = false;
206  }
207 }
208 
209 
211 {
212  meshChanged_ = true;
213 
214  return true;
215 }
216 
217 
219 {
220  sigmaScalarPtr_.valid()
221  ? sigmaScalarPtr_->reset()
222  : sigmaTensorPtr_->reset();
223 
224  meshChanged_ = true;
225 }
226 
227 
229 {
230  sigmaScalarPtr_.valid()
231  ? sigmaScalarPtr_->reset()
232  : sigmaTensorPtr_->reset();
233 
234  meshChanged_ = true;
235 }
236 
237 
239 {
240  sigmaScalarPtr_.valid()
241  ? sigmaScalarPtr_->reset()
242  : sigmaTensorPtr_->reset();
243 
244  meshChanged_ = true;
245 }
246 
247 
249 {
250  if (fvModel::read(dict))
251  {
252  readCoeffs(coeffs(dict));
253  return true;
254  }
255  else
256  {
257  return false;
258  }
259 }
260 
261 
263 {
264  if (write && writeSigma_)
265  {
266  sigmaScalarPtr_.valid()
267  ? sigmaScalarPtr_->write()
268  : sigmaTensorPtr_->write();
269  }
270 
271  return write;
272 }
273 
274 
275 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Generic GeometricField class.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const word & name() const
Return name.
Definition: IOobject.H:307
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:78
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
T lookupOrDefault(const word &, const T &) const
Find and return a T, if not found return the given default.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
SolverPerformance< Type > solve(const dictionary &)
Solve segregated or coupled returning the solution statistics.
Definition: fvMatrixSolve.C:58
tmp< SurfaceField< Type > > flux() const
Return the face-flux field from the matrix.
Definition: fvMatrix.C:963
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
const fvSchemes & schemes() const
Return the fvSchemes.
Definition: fvMesh.C:1792
const fvSolution & solution() const
Return the fvSolution.
Definition: fvMesh.C:1803
Finite volume model abstract base class.
Definition: fvModel.H:60
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:196
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:69
void setFluxRequired(const word &name) const
Definition: fvSchemes.C:434
This fvModel represents conduction through a solid region. It solves for the electric potential,...
virtual bool movePoints()
Update for mesh motion.
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
solidElectricalConduction(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from explicit source name and mesh.
virtual void correct()
Solve for the electric potential.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual bool read(const dictionary &dict)
Read source dictionary.
virtual void addSup(const volScalarField &rho, const volScalarField &he, fvMatrix< scalar > &eqn) const
Add explicit contribution to compressible energy equation.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual bool write(const bool write=true) const
Write fvModel data.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
static bool finalIteration(const objectRegistry &registry)
Lookup solutionControl from the objectRegistry and return finalIter.
const dictionary & solverDict(const word &name) const
Return the solver controls dictionary for the given field.
Definition: solution.C:238
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
Calculate the matrix for the laplacian of the field.
rho
Definition: pEqn.H:1
const dimensionSet time
addToRunTimeSelectionTable(fvConstraint, bound, dictionary)
defineTypeNameAndDebug(bound, 0)
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
tmp< VolField< Type > > div(const SurfaceField< Type > &ssf)
Definition: fvcDiv.C:47
tmp< fvMatrix< Type > > laplacian(const VolField< Type > &vf, const word &name)
Definition: fvmLaplacian.C:47
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< word > wordList
A List of words.
Definition: fileName.H:54
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:59
const dimensionSet & dimLength
Definition: dimensions.C:141
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
const dimensionSet & dimCurrent
Definition: dimensions.C:145
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
const dimensionSet & dimPower
Definition: dimensions.C:161
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
labelList fv(nPoints)
dictionary dict
fluidMulticomponentThermo & thermo
Definition: createFields.H:15