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 // * * * * * * * * * * * * Protected 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  "-I$(LIB_SRC)/fvOptions/lnInclude \\\n"
72  + context.options()
73  + "\n\nLIB_LIBS = \\\n"
74  + " -lmeshTools \\\n"
75  + " -lfvOptions \\\n"
76  + " -lsampling \\\n"
77  + " -lfiniteVolume \\\n"
78  + context.libs()
79  );
80 }
81 
82 
83 template<class Type>
85 {
86  return const_cast<Time&>(mesh_.time()).libs();
87 }
88 
89 
90 template<class Type>
92 {
93  return "fvOption:: " + name_;
94 }
95 
96 
97 template<class Type>
99 {
100  redirectFvOptionPtr_.clear();
101 }
102 
103 
104 template<class Type>
106 {
107  return coeffs_;
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
112 
113 template<class Type>
115 (
116  const word& name,
117  const word& modelType,
118  const dictionary& dict,
119  const fvMesh& mesh
120 )
121 :
122  cellSetOption(name, modelType, dict, mesh)
123 {
124  read(dict);
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
130 template<class Type>
132 {
133  if (!redirectFvOptionPtr_.valid())
134  {
135  dictionary constructDict(dict_);
136  constructDict.set("type", name_);
137 
138  redirectFvOptionPtr_ = option::New
139  (
140  name_,
141  constructDict,
142  mesh_
143  );
144  }
145  return redirectFvOptionPtr_();
146 }
147 
148 
149 template<class Type>
151 (
153 )
154 {
155  if (debug)
156  {
157  Info<< "CodedSource<"<< pTraits<Type>::typeName
158  << ">::correct for source " << name_ << endl;
159  }
160 
161  updateLibrary(name_);
162  redirectFvOption().correct(field);
163 }
164 
165 
166 template<class Type>
168 (
169  fvMatrix<Type>& eqn,
170  const label fieldi
171 )
172 {
173  if (debug)
174  {
175  Info<< "CodedSource<"<< pTraits<Type>::typeName
176  << ">::addSup for source " << name_ << endl;
177  }
178 
179  updateLibrary(name_);
180  redirectFvOption().addSup(eqn, fieldi);
181 }
182 
183 
184 template<class Type>
186 (
187  const volScalarField& rho,
188  fvMatrix<Type>& eqn,
189  const label fieldi
190 )
191 {
192  if (debug)
193  {
194  Info<< "CodedSource<"<< pTraits<Type>::typeName
195  << ">::addSup for source " << name_ << endl;
196  }
197 
198  updateLibrary(name_);
199  redirectFvOption().addSup(rho, eqn, fieldi);
200 }
201 
202 
203 template<class Type>
205 (
206  fvMatrix<Type>& eqn,
207  const label fieldi
208 )
209 {
210  if (debug)
211  {
212  Info<< "CodedSource<"<< pTraits<Type>::typeName
213  << ">::constrain for source " << name_ << endl;
214  }
215 
216  updateLibrary(name_);
217  redirectFvOption().constrain(eqn, fieldi);
218 }
219 
220 
221 // ************************************************************************* //
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
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:151
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
virtual const dictionary & codeDict() const
Definition: CodedSource.C:105
Traits class for primitives.
Definition: pTraits.H:50
virtual void clearRedirect() const
Definition: CodedSource.C:98
Generic GeometricField class.
virtual void constrain(fvMatrix< Type > &eqn, const label fieldi)
Set value.
Definition: CodedSource.C:205
void addCompileFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:350
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
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)
option & redirectFvOption() const
Dynamically compiled fvOption.
Definition: CodedSource.C:131
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:72
virtual string description() const
Definition: CodedSource.C:91
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedSource.C:36
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:115
const string & libs() const
Return the code-libs.
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:168
Encapsulation of dynamic code dictionaries.
void setFilterVariable(const word &key, const std::string &value)
Define a filter variable.
Definition: dynamicCode.C:385
const string & options() const
Return the code-options.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual dlLibraryTable & libs() const
Get the loaded dynamic libraries.
Definition: CodedSource.C:84
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:941
messageStream Info
Cell-set options abtract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:69
A class for handling character strings derived from std::string.
Definition: string.H:74
Finite volume options abstract base class. Provides a base set of controls, e.g.: ...
Definition: fvOption.H:66