fvModel.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 "fvModel.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
35 }
36 
37 
38 const Foam::wordHashSet Foam::fvModel::keywords({"type", "libs"});
39 
40 
41 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42 
43 template<class Type>
45 (
46  const VolField<Type>& field,
47  fvMatrix<Type>& eqn
48 ) const
49 {}
50 
51 
52 template<class Type>
54 (
55  const volScalarField& rho,
56  const VolField<Type>& field,
57  fvMatrix<Type>& eqn
58 ) const
59 {}
60 
61 
62 template<class Type>
64 (
65  const volScalarField& alpha,
66  const volScalarField& rho,
67  const VolField<Type>& field,
68  fvMatrix<Type>& eqn
69 ) const
70 {}
71 
72 
73 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 
76 (
77  const word& name,
78  const word& modelType,
79  const fvMesh& mesh,
80  const dictionary& dict
81 )
82 :
83  name_(name),
84  modelType_(modelType),
85  mesh_(mesh)
86 {
87  Info<< incrIndent << indent << "Name: " << name_
88  << endl << decrIndent;
89 }
90 
91 
92 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
93 
95 (
96  const word& name,
97  const fvMesh& mesh,
98  const dictionary& dict
99 )
100 {
101  const word modelType(dict.lookup("type"));
102 
103  Info<< indent
104  << "Selecting finite volume model type " << modelType << endl;
105 
106  if
107  (
108  !dictionaryConstructorTablePtr_
109  || dictionaryConstructorTablePtr_->find(modelType)
110  == dictionaryConstructorTablePtr_->end()
111  )
112  {
113  if
114  (
115  !libs.open
116  (
117  dict,
118  "libs",
119  dictionaryConstructorTablePtr_
120  )
121  )
122  {
123  libs.open("lib" + modelType.remove(':') + ".so", false);
124  }
125 
126  if (!dictionaryConstructorTablePtr_)
127  {
129  << "Unknown model type "
130  << modelType << nl << nl
131  << "Table of fvModels is empty"
132  << exit(FatalError);
133  }
134  }
135 
136  dictionaryConstructorTable::iterator cstrIter =
137  dictionaryConstructorTablePtr_->find(modelType);
138 
139  if (cstrIter == dictionaryConstructorTablePtr_->end())
140  {
142  << "Unknown fvModel " << modelType << nl << nl
143  << "Valid fvModels are:" << nl
144  << dictionaryConstructorTablePtr_->sortedToc()
145  << exit(FatalIOError);
146  }
147 
148  return autoPtr<fvModel>
149  (
150  cstrIter()(name, modelType, mesh, dict)
151  );
152 }
153 
154 
156 {}
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
162 {
163  return wordList::null();
164 }
165 
166 
167 bool Foam::fvModel::addsSupToField(const word& fieldName) const
168 {
169  return findIndex(addSupFields(), fieldName) != -1;
170 }
171 
172 
173 Foam::scalar Foam::fvModel::maxDeltaT() const
174 {
175  return vGreat;
176 }
177 
178 
180 {}
181 
182 
184 
185 
187 
188 
190 
191 
192 void Foam::fvModel::preUpdateMesh()
193 {}
194 
195 
197 {}
198 
199 
201 {
202  return true;
203 }
204 
205 
206 bool Foam::fvModel::write(const bool write) const
207 {
208  return true;
209 }
210 
211 
212 // ************************************************************************* //
Generic GeometricField class.
A HashTable with keys but without contents.
Definition: HashSet.H:62
static const List< word > & null()
Return a null List.
Definition: ListI.H:118
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:740
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
Finite volume model abstract base class.
Definition: fvModel.H:60
static autoPtr< fvModel > New(const word &name, const fvMesh &mesh, const dictionary &dict)
Return a reference to the selected fvModel.
Definition: fvModel.C:95
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
Definition: fvModel.C:161
void addSupType(const VolField< Type > &field, fvMatrix< Type > &eqn) const
Add a source term to an equation.
Definition: fvModel.C:45
virtual ~fvModel()
Destructor.
Definition: fvModel.C:155
virtual void correct()
Correct the fvModel.
Definition: fvModel.C:196
virtual scalar maxDeltaT() const
Return the maximum time-step for stable operation.
Definition: fvModel.C:173
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:200
static const wordHashSet keywords
The keywords read by this class.
Definition: fvModel.H:121
virtual bool write(const bool write=true) const
Write fvModel data.
Definition: fvModel.C:206
virtual void addSup(fvMatrix< scalar > &eqn) const
Add a source term to a field-less proxy equation.
Definition: fvModel.C:179
fvModel(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from components.
Definition: fvModel.C:76
virtual bool addsSupToField(const word &fieldName) const
Return true if the fvModel adds a source term to the given.
Definition: fvModel.C:167
bool remove(const char)
Remove all occurrences of character returning true if string changed.
Definition: string.C:132
A class for handling words, derived from string.
Definition: word.H:62
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
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define IMPLEMENT_FV_MODEL_ADD_FIELD_SUP(Type, modelType)
Definition: fvModelM.H:33
#define IMPLEMENT_FV_MODEL_ADD_ALPHA_RHO_FIELD_SUP(Type, modelType)
Definition: fvModelM.H:71
#define IMPLEMENT_FV_MODEL_ADD_RHO_FIELD_SUP(Type, modelType)
Definition: fvModelM.H:51
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
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
dlLibraryTable libs
Table of loaded dynamic libraries.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:242
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:235
defineTypeNameAndDebug(combustionModel, 0)
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
error FatalError
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:228
static const char nl
Definition: Ostream.H:267
dictionary dict