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  dimensions::electricPotential
127  ),
128  I_
129  (
130  IOobject
131  (
132  "I",
133  mesh().time().name(),
134  mesh(),
135  IOobject::READ_IF_PRESENT,
136  IOobject::AUTO_WRITE
137  ),
138  mesh(),
139  dimensionedScalar(dimensions::current, scalar(0))
140  ),
141  sigmaScalarPtr_(),
142  sigmaTensorPtr_(),
143  writeSigma_(false),
144  meshChanged_(true)
145 {
146  readCoeffs(dict);
147 
148  mesh().schemes().setFluxRequired(phi_.name());
149 }
150 
151 
152 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
153 
155 {
156  const basicThermo& thermo =
158 
159  return wordList(1, thermo.he().name());
160 }
161 
162 
164 (
165  const volScalarField& rho,
166  const volScalarField& he,
167  fvMatrix<scalar>& eqn
168 ) const
169 {
170  eqn += fvc::div(I_*fvc::interpolate(phi_));
171 }
172 
173 
175 {
176  const bool sigmaChanged =
177  sigmaScalarPtr_.valid()
178  ? sigmaScalarPtr_->update()
179  : sigmaTensorPtr_->update();
180 
181  if (sigmaChanged || meshChanged_)
182  {
183  const label nCorr =
184  mesh()
185  .solution()
186  .solverDict(phi_.name())
187  .lookupOrDefault<label>("nCorr", 0);
188 
189  for (label i = 0; i <= nCorr; ++ i)
190  {
191  fvMatrix<scalar> phiEqn
192  (
193  sigmaScalarPtr_.valid()
194  ? fvm::laplacian(sigmaScalarPtr_(), phi_)
195  : fvm::laplacian(sigmaTensorPtr_(), phi_)
196  );
197 
198  phiEqn.solve();
199 
200  if (i == nCorr) I_ = phiEqn.flux();
201  }
202  }
203 
205  {
206  meshChanged_ = false;
207  }
208 }
209 
210 
212 {
213  meshChanged_ = true;
214 
215  return true;
216 }
217 
218 
220 {
221  sigmaScalarPtr_.valid()
222  ? sigmaScalarPtr_->reset()
223  : sigmaTensorPtr_->reset();
224 
225  meshChanged_ = true;
226 }
227 
228 
230 {
231  sigmaScalarPtr_.valid()
232  ? sigmaScalarPtr_->reset()
233  : sigmaTensorPtr_->reset();
234 
235  meshChanged_ = true;
236 }
237 
238 
240 {
241  sigmaScalarPtr_.valid()
242  ? sigmaScalarPtr_->reset()
243  : sigmaTensorPtr_->reset();
244 
245  meshChanged_ = true;
246 }
247 
248 
250 {
251  if (fvModel::read(dict))
252  {
253  readCoeffs(coeffs(dict));
254  return true;
255  }
256  else
257  {
258  return false;
259  }
260 }
261 
262 
264 {
265  if (write && writeSigma_)
266  {
267  sigmaScalarPtr_.valid()
268  ? sigmaScalarPtr_->write()
269  : sigmaTensorPtr_->write();
270  }
271 
272  return write;
273 }
274 
275 
276 // ************************************************************************* //
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:1795
const fvSolution & solution() const
Return the fvSolution.
Definition: fvMesh.C:1806
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
const dimensionSet current
const dimensionSet power
const dimensionSet length
const dimensionSet electricPotential
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
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
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