1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "codedFunctionObject.H"
27 #include "volFields.H"
28 #include "dictionary.H"
30 #include "SHA1Digest.H"
31 #include "dynamicCode.H"
32 #include "dynamicCodeContext.H"
33 #include "stringOps.H"
34 #include "addToRunTimeSelectionTable.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(codedFunctionObject, 0);
42 addToRunTimeSelectionTable
50 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
53 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
55 void Foam::codedFunctionObject::prepare
58 const dynamicCodeContext& context
61 // Set additional rewrite rules
62 dynCode.setFilterVariable("typeName", redirectType_);
63 dynCode.setFilterVariable("codeRead", codeRead_);
64 dynCode.setFilterVariable("codeExecute", codeExecute_);
65 dynCode.setFilterVariable("codeEnd", codeEnd_);
66 //dynCode.setFilterVariable("codeWrite", codeWrite_);
68 // compile filtered C template
69 dynCode.addCompileFile("functionObjectTemplate.C");
70 dynCode.addCompileFile("FilterFunctionObjectTemplate.C");
72 // copy filtered H template
73 dynCode.addCopyFile("FilterFunctionObjectTemplate.H");
74 dynCode.addCopyFile("functionObjectTemplate.H");
75 dynCode.addCopyFile("IOfunctionObjectTemplate.H");
77 // debugging: make BC verbose
78 // dynCode.setFilterVariable("verbose", "true");
79 // Info<<"compile " << redirectType_ << " sha1: "
80 // << context.sha1() << endl;
82 // define Make/options
83 dynCode.setMakeOptions
86 "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
88 + "\n\nLIB_LIBS = \\\n"
90 + " -lfiniteVolume \\\n"
96 Foam::dlLibraryTable& Foam::codedFunctionObject::libs() const
98 return const_cast<Time&>(time_).libs();
102 Foam::string Foam::codedFunctionObject::description() const
104 return "functionObject " + name();
108 void Foam::codedFunctionObject::clearRedirect() const
110 redirectFunctionObjectPtr_.clear();
114 const Foam::dictionary& Foam::codedFunctionObject::codeDict() const
120 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
122 Foam::codedFunctionObject::codedFunctionObject
126 const dictionary& dict,
130 functionObject(name),
141 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
143 Foam::codedFunctionObject::~codedFunctionObject()
147 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
149 Foam::functionObject&
150 Foam::codedFunctionObject::redirectFunctionObject() const
152 if (!redirectFunctionObjectPtr_.valid())
154 dictionary constructDict(dict_);
155 constructDict.set("type", redirectType_);
157 redirectFunctionObjectPtr_ = functionObject::New
164 return redirectFunctionObjectPtr_();
168 bool Foam::codedFunctionObject::start()
170 updateLibrary(redirectType_);
171 return redirectFunctionObject().start();
175 bool Foam::codedFunctionObject::execute(const bool forceWrite)
177 updateLibrary(redirectType_);
178 return redirectFunctionObject().execute(forceWrite);
182 bool Foam::codedFunctionObject::end()
184 updateLibrary(redirectType_);
185 return redirectFunctionObject().end();
189 bool Foam::codedFunctionObject::read(const dictionary& dict)
191 dict.lookup("redirectType") >> redirectType_;
193 const entry* readPtr = dict.lookupEntryPtr
201 codeRead_ = stringOps::trim(readPtr->stream());
202 stringOps::inplaceExpand(codeRead_, dict);
203 dynamicCodeContext::addLineDirective
206 readPtr->startLineNumber(),
211 const entry* execPtr = dict.lookupEntryPtr
219 codeExecute_ = stringOps::trim(execPtr->stream());
220 stringOps::inplaceExpand(codeExecute_, dict);
221 dynamicCodeContext::addLineDirective
224 execPtr->startLineNumber(),
229 const entry* endPtr = dict.lookupEntryPtr
237 codeEnd_ = stringOps::trim(endPtr->stream());
238 stringOps::inplaceExpand(codeEnd_, dict);
239 dynamicCodeContext::addLineDirective
242 endPtr->startLineNumber(),
247 updateLibrary(redirectType_);
248 return redirectFunctionObject().read(dict);
252 // ************************************************************************* //