fvFieldSource.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) 2023 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 "fvFieldSource.H"
27 #include "fvSource.H"
28 #include "volMesh.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
36 )
37 :
38  libs_(fileNameList::null()),
39  internalField_(iF)
40 {}
41 
42 
43 template<class Type>
45 (
47  const dictionary& dict
48 )
49 :
50  libs_(dict.lookupOrDefault("libs", fileNameList::null())),
51  internalField_(iF)
52 {}
53 
54 
55 template<class Type>
57 (
58  const fvFieldSource<Type>& field,
60 )
61 :
62  libs_(field.libs_),
63  internalField_(iF)
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
68 
69 template<class Type>
72 (
73  const word& fieldSourceType,
75 )
76 {
77  typename nullConstructorTable::iterator cstrIter =
78  nullConstructorTablePtr_->find(fieldSourceType);
79 
80  if (cstrIter == nullConstructorTablePtr_->end())
81  {
83  << "Unknown null-constructable fieldSource type " << fieldSourceType
84  << nl << nl << "Valid fieldSource types are :" << endl
85  << nullConstructorTablePtr_->sortedToc()
86  << exit(FatalIOError);
87  }
88 
89  return cstrIter()(iF);
90 }
91 
92 
93 template<class Type>
96 (
98  const dictionary& dict
99 )
100 {
101  const word fieldSourceType(dict.lookup("type"));
102 
103  libs.open(dict, "libs", dictionaryConstructorTablePtr_);
104 
105  typename dictionaryConstructorTable::iterator cstrIter =
106  dictionaryConstructorTablePtr_->find(fieldSourceType);
107 
108  if (cstrIter == dictionaryConstructorTablePtr_->end())
109  {
110  if (!disallowGenericFvFieldSource)
111  {
112  cstrIter = dictionaryConstructorTablePtr_->find("generic");
113  }
114 
115  if (cstrIter == dictionaryConstructorTablePtr_->end())
116  {
118  << "Unknown fieldSource type " << fieldSourceType
119  << " for model " << dict.dictName() << nl << nl
120  << "Valid fieldSource types are :" << endl
121  << dictionaryConstructorTablePtr_->sortedToc()
122  << exit(FatalIOError);
123  }
124  }
125 
126  return cstrIter()(iF, dict);
127 }
128 
129 
130 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
131 
132 template<class Type>
134 {}
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
139 template<class Type>
141 {
142  return internalField_.mesh();
143 }
144 
145 
146 template<class Type>
149 {
150  return internalField_;
151 }
152 
153 
154 template<class Type>
156 (
157  const fvSource& source
158 ) const
159 {
160  return (1 - internalCoeff(source))*sourceValue(source);
161 }
162 
163 
164 template<class Type>
166 (
167  const fvSource& source
168 ) const
169 {
170  const Field<Type> setInternalField
171  (
172  UIndirectList<Type>(internalField(), source.cells())
173  );
174 
175  return sourceCoeff(source) + internalCoeff(source)*setInternalField;
176 }
177 
178 
179 template<class Type>
180 template<class OtherType>
182 (
183  const word& name,
184  const fvSource& source
185 ) const
186 {
187  const VolField<OtherType>& vf =
188  db().template lookupObject<VolField<OtherType>>(name);
189 
190  return vf.sources()[source.name()];
191 }
192 
193 
194 template<class Type>
195 template<class OtherType>
197 (
198  const word& name,
199  const fvSource& source
200 ) const
201 {
202  return fieldSource<OtherType>(name, source).value(source);
203 }
204 
205 
206 template<class Type>
208 {
209  writeEntry(os, "type", type());
210 
211  if (libs_.size())
212  {
213  writeEntry(os, "libs", libs_);
214  }
215 }
216 
217 
218 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
219 
220 template<class Type>
222 {
223  ptf.write(os);
224 
225  os.check("Ostream& operator<<(Ostream&, const fvFieldSource<Type>&");
226 
227  return os;
228 }
229 
230 
231 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic GeometricField class.
const Sources & sources() const
Return const-reference to the sources.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A List with indirect addressing.
Definition: UIndirectList.H:60
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:123
A list of keyword definitions, which are a keyword followed by any number of values (e....
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:710
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
Base class for finite-volume field sources.
Definition: fvFieldSource.H:62
virtual void write(Ostream &) const
Write.
tmp< Field< Type > > value(const fvSource &) const
Return the value.
fvFieldSource(const DimensionedField< Type, volMesh > &)
Construct from internal field.
Definition: fvFieldSource.C:34
const objectRegistry & db() const
Return the local object registry.
const fvFieldSource< OtherType > & fieldSource(const word &name, const fvSource &) const
Lookup and return another field source.
static autoPtr< fvFieldSource< Type > > New(const word &fieldSourceType, const DimensionedField< Type, volMesh > &)
Return a pointer to a new field source.
Definition: fvFieldSource.C:72
virtual ~fvFieldSource()
Destructor.
tmp< Field< Type > > sourceCoeff(const fvSource &) const
Return the source coefficient.
const DimensionedField< Type, volMesh > & internalField() const
Return the internal field reference.
const word & name() const
Return const access to the source name.
Definition: fvModelI.H:47
Base class for finite volume sources.
Definition: fvSource.H:52
virtual labelUList cells() const =0
Return the cells that the source applies to.
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
#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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dlLibraryTable libs
Table of loaded dynamic libraries.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
IOerror FatalIOError
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
static const char nl
Definition: Ostream.H:266
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict