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 | Copyright (C) 2011-2016 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 "SemiImplicitSource.H"
27 #include "fvMesh.H"
28 #include "fvMatrices.H"
29 #include "DimensionedField.H"
30 #include "fvmSup.H"
31 
32 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  IStringStream("(absolute specific)")()
38 );
39 
40 
41 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42 
43 template<class Type>
46 (
47  const word& vmtName
48 ) const
49 {
50  forAll(volumeModeTypeNames_, i)
51  {
52  if (vmtName == volumeModeTypeNames_[i])
53  {
54  return volumeModeType(i);
55  }
56  }
57 
59  << "Unknown volumeMode type " << vmtName
60  << ". Valid volumeMode types are:" << nl << volumeModeTypeNames_
61  << exit(FatalError);
62 
63  return volumeModeType(0);
64 }
65 
66 
67 template<class Type>
69 (
70  const volumeModeType& vmtType
71 ) const
72 {
73  if (vmtType > volumeModeTypeNames_.size())
74  {
75  return "UNKNOWN";
76  }
77  else
78  {
79  return volumeModeTypeNames_[vmtType];
80  }
81 }
82 
83 
84 template<class Type>
86 {
87  fieldNames_.setSize(dict.toc().size());
88  injectionRate_.setSize(fieldNames_.size());
89 
90  applied_.setSize(fieldNames_.size(), false);
91 
92  label i = 0;
93  forAllConstIter(dictionary, dict, iter)
94  {
95  fieldNames_[i] = iter().keyword();
96  dict.lookup(iter().keyword()) >> injectionRate_[i];
97  i++;
98  }
99 
100  // Set volume normalisation
101  if (volumeMode_ == vmAbsolute)
102  {
103  VDash_ = V_;
104  }
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
109 
110 template<class Type>
112 (
113  const word& name,
114  const word& modelType,
115  const dictionary& dict,
116  const fvMesh& mesh
117 )
118 :
119  cellSetOption(name, modelType, dict, mesh),
120  volumeMode_(vmAbsolute),
121  VDash_(1.0),
122  injectionRate_()
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  (
158  "zero",
159  eqn.dimensions()/dimVolume,
160  Zero
161  ),
162  false
163  );
164 
165  UIndirectList<Type>(Su, cells_) = injectionRate_[fieldi].first()/VDash_;
166 
168  (
169  IOobject
170  (
171  name_ + fieldNames_[fieldi] + "Sp",
172  mesh_.time().timeName(),
173  mesh_,
174  IOobject::NO_READ,
175  IOobject::NO_WRITE
176  ),
177  mesh_,
179  (
180  "zero",
181  Su.dimensions()/psi.dimensions(),
182  0.0
183  ),
184  false
185  );
186 
187  UIndirectList<scalar>(Sp, cells_) = injectionRate_[fieldi].second()/VDash_;
188 
189  eqn += Su + fvm::SuSp(Sp, psi);
190 }
191 
192 
193 template<class Type>
195 (
196  const volScalarField& rho,
197  fvMatrix<Type>& eqn,
198  const label fieldi
199 )
200 {
201  if (debug)
202  {
203  Info<< "SemiImplicitSource<" << pTraits<Type>::typeName
204  << ">::addSup for source " << name_ << endl;
205  }
206 
207  return this->addSup(eqn, fieldi);
208 }
209 
210 
211 // ************************************************************************* //
volumeModeType wordToVolumeModeType(const word &vtName) const
Helper function to convert from a word to a volumeModeType.
wordList toc() const
Return the table of contents.
Definition: dictionary.C:699
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
tmp< GeometricField< Type, fvPatchField, volMesh > > SuSp(const volScalarField &sp, const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: fvcSup.C:102
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const GeometricField< Type, fvPatchField, volMesh > & psi() const
Definition: fvMatrix.H:281
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Traits class for primitives.
Definition: pTraits.H:50
tmp< GeometricField< Type, fvPatchField, volMesh > > Sp(const volScalarField &sp, const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: fvcSup.C:67
Generic GeometricField class.
Generic dimensioned Type class.
static const wordList volumeModeTypeNames_
Word list of volume mode type names.
word volumeModeTypeToWord(const volumeModeType &vtType) const
Helper function to convert from a volumeModeType to a word.
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:58
bool read(const char *, int32_t &)
Definition: int32IO.C:85
const dimensionSet & dimensions() const
Definition: fvMatrix.H:286
A class for handling words, derived from string.
Definition: word.H:59
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:71
static const zero Zero
Definition: zero.H:91
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
const dimensionSet & dimensions() const
Return dimensions.
static const char nl
Definition: Ostream.H:262
volumeModeType
Enumeration for volume types.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A List with indirect addressing.
Definition: fvMatrix.H:106
virtual void addSup(fvMatrix< Type > &eqn, const label fieldi)
Add explicit contribution to equation.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
A special matrix type and solver, designed for finite volume solutions of scalar equations.
messageStream Info
Cell-set options abtract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:72
const volScalarField & psi
tmp< GeometricField< Type, fvPatchField, volMesh > > Su(const GeometricField< Type, fvPatchField, volMesh > &su, const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: fvcSup.C:44
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
SemiImplicitSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
void setFieldData(const dictionary &dict)
Set the local field data.
Calculate the matrix for implicit and explicit sources.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451