fvTotalSourceTemplates.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) 2021-2024 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 
26 #include "fvTotalSource.H"
27 #include "fvCellSet.H"
28 #include "fvMatrices.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const VolField<Type>& field,
36  fvMatrix<Type>& eqn
37 ) const
38 {
40  << "field=" << field.name()
41  << ", eqnField=" << eqn.psi().name() << endl;
42 
43  const labelUList cells = this->cells();
44  const scalar V = this->V();
45  const dimensionedScalar S = this->S();
46 
47  // Check the dimensions
48  eqn.dimensions() = S.dimensions()*field.dimensions();
49 
50  if (&field == &eqn.psi())
51  {
52  // Get the field source coefficients
53  const Field<Type> sourceCoeff
54  (
55  field.sources()[name()].sourceCoeff(*this)
56  );
57  const scalarField internalCoeff
58  (
59  field.sources()[name()].internalCoeff(*this)
60  );
61 
62  // Apply the source
63  Field<Type>& eqnSource = eqn.source();
64  scalarField& eqnDiag = eqn.diag();
65  forAll(cells, i)
66  {
67  const scalar f = mesh().V()[cells[i]]/V;
68  eqnSource[cells[i]] -= f*S.value()*sourceCoeff[i];
69  eqnDiag[cells[i]] += f*S.value()*internalCoeff[i];
70  }
71  }
72  else
73  {
74  // Get the field source value
75  const Field<Type> value
76  (
77  field.sources()[name()].value(*this)
78  );
79 
80  // Apply the source
81  Field<Type>& eqnSource = eqn.source();
82  forAll(cells, i)
83  {
84  const scalar f = mesh().V()[cells[i]]/V;
85  eqnSource[cells[i]] -= f*S.value()*value[i];
86  }
87  }
88 }
89 
90 
91 template<class Type>
93 (
94  const volScalarField& rho,
95  const VolField<Type>& field,
96  fvMatrix<Type>& eqn
97 ) const
98 {
100  << "rho=" << rho.name()
101  << ", field=" << field.name()
102  << ", eqnField=" << eqn.psi().name() << endl;
103 
104  addSupType(field, eqn);
105 }
106 
107 
108 template<class Type>
110 (
111  const volScalarField& alpha,
112  const volScalarField& rho,
113  const VolField<Type>& field,
114  fvMatrix<Type>& eqn
115 ) const
116 {
118  << "alpha=" << alpha.name()
119  << ", rho=" << rho.name()
120  << ", field=" << field.name()
121  << ", eqnField=" << eqn.psi().name() << endl;
122 
123  addSupType(rho, field, eqn);
124 }
125 
126 
127 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const dimensionSet & dimensions() const
Return dimensions.
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic GeometricField class.
const Sources & sources() const
Return const-reference to the sources.
const word & name() const
Return name.
Definition: IOobject.H:310
const dimensionSet & dimensions() const
Return const reference to dimensions.
const Type & value() const
Return const reference to value.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
Field< Type > & source()
Definition: fvMatrix.H:307
VolField< Type > & psi()
Definition: fvMatrix.H:289
const dimensionSet & dimensions() const
Definition: fvMatrix.H:302
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:53
const word & name() const
Return const access to the source name.
Definition: fvModelI.H:47
virtual labelUList cells() const =0
Return the cells that the source applies to.
void addSupType(const VolField< Type > &field, fvMatrix< Type > &eqn) const
Add a source term to an equation.
virtual scalar V() const =0
Return the volume of cells that the source applies to.
virtual dimensionedScalar S() const =0
Return the source value.
scalarField & diag()
Definition: lduMatrix.C:186
A special matrix type and solver, designed for finite volume solutions of scalar equations.
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
#define DebugInFunction
Report an information message using Foam::Info.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
labelList f(nPoints)