SemiImplicitSource.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "SemiImplicitSource.H"
30 #include "fvMesh.H"
31 #include "fvMatrices.H"
32 #include "fvmSup.H"
33 #include "Constant.H"
34 
35 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
36 
37 template<class Type>
38 const Foam::Enum
39 <
41 >
43 ({
44  { volumeModeType::vmAbsolute, "absolute" },
45  { volumeModeType::vmSpecific, "specific" },
46 });
47 
48 
49 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
50 
51 template<class Type>
53 {
54  label count = dict.size();
55 
56  fieldNames_.resize(count);
57  Su_.resize(fieldNames_.size());
58  Sp_.resize(fieldNames_.size());
59 
60  fv::option::resetApplied();
61 
62  count = 0;
63  for (const entry& dEntry : dict)
64  {
65  fieldNames_[count] = dEntry.keyword();
66 
67  if (!dEntry.isDict())
68  {
69  Tuple2<Type, scalar> injectionRate;
70  dEntry.readEntry(injectionRate);
71 
72  Su_.set
73  (
74  count,
76  (
77  "Su",
78  injectionRate.first()
79  )
80  );
81  Sp_.set
82  (
83  count,
85  (
86  "Sp",
87  injectionRate.second()
88  )
89  );
90  }
91  else
92  {
93  const dictionary& Sdict = dEntry.dict();
94  Su_.set(count, Function1<Type>::New("Su", Sdict, &mesh_));
95  Sp_.set(count, Function1<scalar>::New("Sp", Sdict, &mesh_));
96  }
97 
98  ++count;
99  }
100 
101  // Set volume normalisation
102  if (volumeMode_ == vmAbsolute)
103  {
104  VDash_ = V_;
105  }
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
110 
111 template<class Type>
113 (
114  const word& name,
115  const word& modelType,
116  const dictionary& dict,
117  const fvMesh& mesh
118 )
119 :
120  fv::cellSetOption(name, modelType, dict, mesh),
121  volumeMode_(vmAbsolute),
122  VDash_(1.0)
123 {
124  read(dict);
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
130 template<class Type>
132 (
133  fvMatrix<Type>& eqn,
134  const label fieldi
135 )
136 {
137  if (debug)
138  {
139  Info<< "SemiImplicitSource<" << pTraits<Type>::typeName
140  << ">::addSup for source " << name_ << endl;
141  }
142 
144 
146  (
147  IOobject
148  (
149  name_ + fieldNames_[fieldi] + "Su",
150  mesh_.time().timeName(),
151  mesh_,
152  IOobject::NO_READ,
153  IOobject::NO_WRITE
154  ),
155  mesh_,
157  false
158  );
159 
160  const scalar tmVal = mesh_.time().timeOutputValue();
161 
162  UIndirectList<Type>(Su, cells_) = Su_[fieldi].value(tmVal)/VDash_;
163 
165  (
166  IOobject
167  (
168  name_ + fieldNames_[fieldi] + "Sp",
169  mesh_.time().timeName(),
170  mesh_,
171  IOobject::NO_READ,
172  IOobject::NO_WRITE
173  ),
174  mesh_,
175  dimensioned<scalar>(Su.dimensions()/psi.dimensions(), Zero),
176  false
177  );
178 
179  UIndirectList<scalar>(Sp, cells_) = Sp_[fieldi].value(tmVal)/VDash_;
180 
181  eqn += Su + fvm::SuSp(Sp, psi);
182 }
183 
184 
185 template<class Type>
187 (
188  const volScalarField& rho,
189  fvMatrix<Type>& eqn,
190  const label fieldi
191 )
192 {
193  if (debug)
194  {
195  Info<< "SemiImplicitSource<" << pTraits<Type>::typeName
196  << ">::addSup for source " << name_ << endl;
197  }
198 
199  return this->addSup(eqn, fieldi);
200 }
201 
202 
203 template<class Type>
205 {
207  {
208  volumeMode_ = volumeModeTypeNames_.get("volumeMode", coeffs_);
209  setFieldData(coeffs_.subDict("injectionRateSuSp"));
210 
211  return true;
212  }
213 
214  return false;
215 }
216 
217 
218 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fv::cellSetOption
Intermediate abstract class for handling cell-set options for the derived fvOptions.
Definition: cellSetOption.H:163
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::fvMatrix::dimensions
const dimensionSet & dimensions() const
Definition: fvMatrix.H:440
Sp
zeroField Sp
Definition: alphaSuSp.H:2
Foam::fv::SemiImplicitSource::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: SemiImplicitSource.C:204
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dictionary::set
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:780
rho
rho
Definition: readInitialConditions.H:88
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::fam::SuSp
tmp< faMatrix< Type > > SuSp(const areaScalarField &sp, const GeometricField< Type, faPatchField, areaMesh > &vf)
Definition: famSup.C:151
fvMatrices.H
A special matrix type and solver, designed for finite volume solutions of scalar equations.
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Su
zeroField Su
Definition: alphaSuSp.H:1
Foam::Function1Types::Constant
Templated function that returns a constant value.
Definition: Constant.H:72
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fvMatrix::psi
const GeometricField< Type, fvPatchField, volMesh > & psi(const label i=0) const
Return psi.
Definition: fvMatrix.H:399
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:42
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
fvmSup.H
Calculate the matrix for implicit and explicit sources.
Foam::fv::SemiImplicitSource::volumeModeTypeNames_
static const Enum< volumeModeType > volumeModeTypeNames_
Names for volumeModeType.
Definition: SemiImplicitSource.H:200
Foam::fv::SemiImplicitSource::setFieldData
void setFieldData(const dictionary &dict)
Set the local field data.
Definition: SemiImplicitSource.C:52
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
SemiImplicitSource.H
Foam::fv::SemiImplicitSource::addSup
virtual void addSup(fvMatrix< Type > &eqn, const label fieldi)
Add explicit contribution to equation.
Definition: SemiImplicitSource.C:132
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
Foam::Tuple2::second
const T2 & second() const noexcept
Return second.
Definition: Tuple2.H:130
Constant.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
Foam::fv::SemiImplicitSource::SemiImplicitSource
SemiImplicitSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: SemiImplicitSource.C:113
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:60
Foam::dimVolume
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:60
Foam::GeometricField< Type, fvPatchField, volMesh >
psi
const volScalarField & psi
Definition: createFieldRefs.H:1
Foam::Tuple2::first
const T1 & first() const noexcept
Return first.
Definition: Tuple2.H:118
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::fv::SemiImplicitSource::volumeModeType
volumeModeType
Options for the volume mode type.
Definition: SemiImplicitSource.H:193