CodedSource.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) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2020 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 "CodedSource.H"
30 #include "fvMesh.H"
31 #include "fvMatrices.H"
32 #include "dynamicCode.H"
33 #include "dynamicCodeContext.H"
34 
35 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
36 
37 template<class Type>
39 (
40  dynamicCode& dynCode,
41  const dynamicCodeContext& context
42 ) const
43 {
44  const word sourceType(pTraits<Type>::typeName);
45 
46  // Set additional rewrite rules
47  dynCode.setFilterVariable("typeName", name_);
48  dynCode.setFilterVariable("TemplateType", sourceType);
49  dynCode.setFilterVariable("SourceType", sourceType + "Source");
50 
51  //dynCode.removeFilterVariable("code");
52  dynCode.setFilterVariable("codeCorrect", codeCorrect_);
53  dynCode.setFilterVariable("codeAddSup", codeAddSup_);
54  dynCode.setFilterVariable("codeConstrain", codeConstrain_);
55 
56  // compile filtered C template
57  dynCode.addCompileFile("codedFvOptionTemplate.C");
58 
59  // copy filtered H template
60  dynCode.addCopyFile("codedFvOptionTemplate.H");
61 
62  // debugging: make verbose
63  // dynCode.setFilterVariable("verbose", "true");
64  // DetailInfo
65  // <<"compile " << name_ << " sha1: "
66  // << context.sha1() << endl;
67 
68  // define Make/options
69  dynCode.setMakeOptions
70  (
71  "EXE_INC = -g \\\n"
72  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
73  "-I$(LIB_SRC)/fvOptions/lnInclude \\\n"
74  "-I$(LIB_SRC)/meshTools/lnInclude \\\n"
75  "-I$(LIB_SRC)/sampling/lnInclude \\\n"
76  + context.options()
77  + "\n\nLIB_LIBS = \\\n"
78  " -lfvOptions \\\n"
79  " -lmeshTools \\\n"
80  " -lsampling \\\n"
81  " -lfiniteVolume \\\n"
82  + context.libs()
83  );
84 }
85 
86 
87 template<class Type>
89 {
90  return mesh_.time().libs();
91 }
92 
93 
94 template<class Type>
96 {
97  return "fvOption::" + name_;
98 }
99 
100 
101 template<class Type>
103 {
104  redirectFvOptionPtr_.clear();
105 }
106 
107 
108 template<class Type>
110 {
111  return coeffs_;
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 
117 template<class Type>
119 (
120  const word& name,
121  const word& modelType,
122  const dictionary& dict,
123  const fvMesh& mesh
124 )
125 :
126  cellSetOption(name, modelType, dict, mesh)
127 {
128  read(dict);
129 }
130 
131 
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 
134 template<class Type>
136 {
137  if (!redirectFvOptionPtr_)
138  {
139  dictionary constructDict(dict_);
140  constructDict.set("type", name_);
141  constructDict.changeKeyword(modelType_ & "Coeffs", name_ & "Coeffs");
142 
143  redirectFvOptionPtr_ = option::New
144  (
145  name_,
146  constructDict,
147  mesh_
148  );
149  }
150  return *redirectFvOptionPtr_;
151 }
152 
153 
154 template<class Type>
156 (
158 )
159 {
160  DebugInfo
161  << "CodedSource<" << pTraits<Type>::typeName
162  << ">::correct for source " << name_ << endl;
163 
164  updateLibrary(name_);
165  redirectFvOption().correct(field);
166 }
167 
168 
169 template<class Type>
171 (
172  fvMatrix<Type>& eqn,
173  const label fieldi
174 )
175 {
176  DebugInfo
177  << "CodedSource<" << pTraits<Type>::typeName
178  << ">::addSup for source " << name_ << endl;
179 
180  updateLibrary(name_);
181  redirectFvOption().addSup(eqn, fieldi);
182 }
183 
184 
185 template<class Type>
187 (
188  const volScalarField& rho,
189  fvMatrix<Type>& eqn,
190  const label fieldi
191 )
192 {
193  DebugInfo
194  << "CodedSource<" << pTraits<Type>::typeName
195  << ">::addSup for source " << name_ << endl;
196 
197  updateLibrary(name_);
198  redirectFvOption().addSup(rho, eqn, fieldi);
199 }
200 
201 
202 template<class Type>
204 (
205  fvMatrix<Type>& eqn,
206  const label fieldi
207 )
208 {
209  DebugInfo
210  << "CodedSource<" << pTraits<Type>::typeName
211  << ">::constrain for source " << name_ << endl;
212 
213  updateLibrary(name_);
214  redirectFvOption().constrain(eqn, fieldi);
215 }
216 
217 
218 // ************************************************************************* //
Foam::dynamicCodeContext::libs
const string & libs() const
Return the code-libs.
Definition: dynamicCodeContext.H:146
Foam::fv::CodedSource::libs
virtual dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition: CodedSource.C:88
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:63
Foam::dictionary::changeKeyword
bool changeKeyword(const keyType &oldKeyword, const keyType &newKeyword, bool overwrite=false)
Change the keyword for an entry,.
Definition: dictionarySearch.C:611
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fv::cellSetOption
Intermediate abstract class for handling cell-set options for the derived fvOptions.
Definition: cellSetOption.H:163
Foam::dynamicCode
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:59
Foam::fv::CodedSource::redirectFvOption
option & redirectFvOption() const
Dynamically compiled fvOption.
Definition: CodedSource.C:135
Foam::dynamicCodeContext
Encapsulation of dynamic code dictionaries.
Definition: dynamicCodeContext.H:53
Foam::fv::CodedSource::clearRedirect
virtual void clearRedirect() const
Clear any redirected objects.
Definition: CodedSource.C:102
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:73
Foam::dictionary::set
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:847
dynamicCodeContext.H
rho
rho
Definition: readInitialConditions.H:88
Foam::dynamicCode::addCopyFile
void addCopyFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:357
fvMatrices.H
A special matrix type and solver, designed for finite volume solutions of scalar equations.
Foam::dynamicCode::addCompileFile
void addCompileFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:351
Foam::fv::CodedSource::correct
virtual void correct(GeometricField< Type, fvPatchField, volMesh > &)
Correct field.
Definition: CodedSource.C:156
Foam::fv::option
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:126
CodedSource.H
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
dynamicCode.H
field
rDeltaTY field()
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::dynamicCodeContext::options
const string & options() const
Return the code-options.
Definition: dynamicCodeContext.H:140
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
fvMesh.H
Foam::fv::CodedSource::CodedSource
CodedSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: CodedSource.C:119
Foam::dynamicCode::setFilterVariable
void setFilterVariable(const word &key, const std::string &value)
Define a filter variable.
Definition: dynamicCode.C:386
Foam::dlLibraryTable::libs
static dlLibraryTable & libs()
Table of global libraries.
Definition: dlLibraryTable.C:80
Foam::fv::CodedSource::codeDict
virtual const dictionary & codeDict() const
Get the dictionary to initialize the codeContext.
Definition: CodedSource.C:109
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::dynamicCode::setMakeOptions
void setMakeOptions(const std::string &content)
Define contents for Make/options.
Definition: dynamicCode.C:395
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:359
Foam::fv::CodedSource::description
virtual string description() const
Return a description (type + name) for the output.
Definition: CodedSource.C:95
Foam::fv::CodedSource::constrain
virtual void constrain(fvMatrix< Type > &eqn, const label fieldi)
Set value.
Definition: CodedSource.C:204
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:54
Foam::fv::CodedSource::addSup
virtual void addSup(fvMatrix< Type > &eqn, const label fieldi)
Explicit/implicit matrix contributions.
Definition: CodedSource.C:171
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:76
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::fv::CodedSource::prepare
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedSource.C:39