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 | Copyright (C) 2012-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 "CodedSource.H"
27 #include "fvMesh.H"
28 #include "fvMatrices.H"
29 #include "dynamicCode.H"
30 #include "dynamicCodeContext.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  dynamicCode& dynCode,
38  const dynamicCodeContext& context
39 ) const
40 {
41  word sourceType(pTraits<Type>::typeName);
42 
43  // Set additional rewrite rules
44  dynCode.setFilterVariable("typeName", name_);
45  dynCode.setFilterVariable("TemplateType", sourceType);
46  dynCode.setFilterVariable("SourceType", sourceType + "Source");
47 
48  //dynCode.removeFilterVariable("code");
49  dynCode.setFilterVariable("codeCorrect", codeCorrect_);
50  dynCode.setFilterVariable("codeAddSup", codeAddSup_);
51  dynCode.setFilterVariable("codeSetValue", codeSetValue_);
52 
53  // compile filtered C template
54  dynCode.addCompileFile("codedFvOptionTemplate.C");
55 
56  // copy filtered H template
57  dynCode.addCopyFile("codedFvOptionTemplate.H");
58 
59  // debugging: make BC verbose
60  // dynCode.setFilterVariable("verbose", "true");
61  // Info<<"compile " << name_ << " sha1: "
62  // << context.sha1() << endl;
63 
64  // define Make/options
65  dynCode.setMakeOptions
66  (
67  "EXE_INC = -g \\\n"
68  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
69  "-I$(LIB_SRC)/meshTools/lnInclude \\\n"
70  "-I$(LIB_SRC)/sampling/lnInclude \\\n"
71  + context.options()
72  + "\n\nLIB_LIBS = \\\n"
73  + " -lmeshTools \\\n"
74  + " -lfvOptions \\\n"
75  + " -lsampling \\\n"
76  + " -lfiniteVolume \\\n"
77  + context.libs()
78  );
79 }
80 
81 
82 template<class Type>
84 {
85  return const_cast<Time&>(mesh_.time()).libs();
86 }
87 
88 
89 template<class Type>
91 {
92  return "fvOption:: " + name_;
93 }
94 
95 
96 template<class Type>
98 {
99  redirectFvOptionPtr_.clear();
100 }
101 
102 
103 template<class Type>
105 {
106  return coeffs_;
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
111 
112 template<class Type>
114 (
115  const word& name,
116  const word& modelType,
117  const dictionary& dict,
118  const fvMesh& mesh
119 )
120 :
121  cellSetOption(name, modelType, dict, mesh)
122 {
123  read(dict);
124 }
125 
126 
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 
129 template<class Type>
131 {
132  if (!redirectFvOptionPtr_.valid())
133  {
134  dictionary constructDict(dict_);
135  constructDict.set("type", name_);
136 
137  redirectFvOptionPtr_ = option::New
138  (
139  name_,
140  constructDict,
141  mesh_
142  );
143  }
144  return redirectFvOptionPtr_();
145 }
146 
147 
148 template<class Type>
150 (
152 )
153 {
154  if (debug)
155  {
156  Info<< "CodedSource<"<< pTraits<Type>::typeName
157  << ">::correct for source " << name_ << endl;
158  }
159 
160  updateLibrary(name_);
161  redirectFvOption().correct(field);
162 }
163 
164 
165 template<class Type>
167 (
168  fvMatrix<Type>& eqn,
169  const label fieldi
170 )
171 {
172  if (debug)
173  {
174  Info<< "CodedSource<"<< pTraits<Type>::typeName
175  << ">::addSup for source " << name_ << endl;
176  }
177 
178  updateLibrary(name_);
179  redirectFvOption().addSup(eqn, fieldi);
180 }
181 
182 
183 template<class Type>
185 (
186  const volScalarField& rho,
187  fvMatrix<Type>& eqn,
188  const label fieldi
189 )
190 {
191  if (debug)
192  {
193  Info<< "CodedSource<"<< pTraits<Type>::typeName
194  << ">::addSup for source " << name_ << endl;
195  }
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  if (debug)
210  {
211  Info<< "CodedSource<"<< pTraits<Type>::typeName
212  << ">::constrain for source " << name_ << endl;
213  }
214 
215  updateLibrary(name_);
216  redirectFvOption().constrain(eqn, fieldi);
217 }
218 
219 
220 // ************************************************************************* //
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
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedSource.C:36
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
void setMakeOptions(const std::string &content)
Define contents for Make/options.
Definition: dynamicCode.C:394
virtual void correct(GeometricField< Type, fvPatchField, volMesh > &)
Correct field.
Definition: CodedSource.C:150
const string & libs() const
Return the code-libs.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Traits class for primitives.
Definition: pTraits.H:50
Generic GeometricField class.
virtual string description() const
Definition: CodedSource.C:90
virtual void constrain(fvMatrix< Type > &eqn, const label fieldi)
Set value.
Definition: CodedSource.C:204
void addCompileFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:350
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
const string & options() const
Return the code-options.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
virtual void clearRedirect() const
Definition: CodedSource.C:97
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
virtual dlLibraryTable & libs() const
Get the loaded dynamic libraries.
Definition: CodedSource.C:83
A table of dynamically loaded libraries.
CodedSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: CodedSource.C:114
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
virtual void addSup(fvMatrix< Type > &eqn, const label fieldi)
Explicit and implicit matrix contributions.
Definition: CodedSource.C:167
Encapsulation of dynamic code dictionaries.
void setFilterVariable(const word &key, const std::string &value)
Define a filter variable.
Definition: dynamicCode.C:385
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
void addCopyFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:356
A special matrix type and solver, designed for finite volume solutions of scalar equations.
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:864
messageStream Info
Cell-set options abtract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:72
A class for handling character strings derived from std::string.
Definition: string.H:74
virtual const dictionary & codeDict() const
Definition: CodedSource.C:104
option & redirectFvOption() const
Dynamically compiled fvOption.
Definition: CodedSource.C:130
Finite volume options abstract base class. Provides a base set of controls, e.g.: ...
Definition: fvOption.H:66