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-2025 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 "volFields.H"
28 
29 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const VolField<Type>& field,
35  fvMatrix<Type>& eqn
36 ) const
37 {
39  << "field=" << field.name()
40  << ", eqnField=" << eqn.psi().name() << endl;
41 
42  const labelList& cells = this->zone();
43 
44  const scalarField S
45  (
46  scalarField(mesh().V(), cells)/V()*this->S().value()
47  );
48 
49  // Check the dimensions
50  eqn.dimensions() = this->S().dimensions()*field.dimensions();
51 
52  if (&field == &eqn.psi())
53  {
54  // Get the field source coefficients
55  const Field<Type> sourceCoeff
56  (
57  field.sources()[name()].sourceCoeff(*this, S, cells)
58  );
59  const scalarField internalCoeff
60  (
61  field.sources()[name()].internalCoeff(*this, S, cells)
62  );
63 
64  // Apply the source
65  Field<Type>& eqnSource = eqn.source();
66  scalarField& eqnDiag = eqn.diag();
67  forAll(cells, i)
68  {
69  eqnSource[cells[i]] -= S[i]*sourceCoeff[i];
70  eqnDiag[cells[i]] += S[i]*internalCoeff[i];
71  }
72  }
73  else
74  {
75  // Get the field source value
76  const Field<Type> value
77  (
78  field.sources()[name()].value(*this, S, cells)
79  );
80 
81  // Apply the source
82  Field<Type>& eqnSource = eqn.source();
83  forAll(cells, i)
84  {
85  eqnSource[cells[i]] -= S[i]*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:433
const dimensionSet & dimensions() const
Return dimensions.
Generic GeometricField class.
const Sources & sources() const
Return const-reference to the sources.
const word & name() const
Return name.
Definition: IOobject.H:307
const dimensionSet & dimensions() const
Return const reference to dimensions.
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 fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:69
const word & name() const
Return const access to the source name.
Definition: fvModelI.H:57
void addSupType(const VolField< Type > &field, fvMatrix< Type > &eqn) const
Add a source term to an equation.
virtual const cellZone & zone() const =0
Return the cellZone that the source applies to.
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
const cellShapeList & cells
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:258
Field< scalar > scalarField
Specialisation of Field<T> for scalar.