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),
142 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
144 Foam::codedFunctionObject::~codedFunctionObject()
148 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
150 Foam::functionObject&
151 Foam::codedFunctionObject::redirectFunctionObject() const
153 if (!redirectFunctionObjectPtr_.valid())
155 dictionary constructDict(dict_);
156 constructDict.set("type", redirectType_);
158 redirectFunctionObjectPtr_ = functionObject::New
165 return redirectFunctionObjectPtr_();
169 bool Foam::codedFunctionObject::start()
171 updateLibrary(redirectType_);
172 return redirectFunctionObject().start();
176 bool Foam::codedFunctionObject::execute(const bool forceWrite)
178 updateLibrary(redirectType_);
179 return redirectFunctionObject().execute(forceWrite);
183 bool Foam::codedFunctionObject::end()
185 updateLibrary(redirectType_);
186 return redirectFunctionObject().end();
190 bool Foam::codedFunctionObject::read(const dictionary& dict)
192 dict.lookup("redirectType") >> redirectType_;
194 const entry* readPtr = dict.lookupEntryPtr
202 codeRead_ = stringOps::trim(readPtr->stream());
203 stringOps::inplaceExpand(codeRead_, dict);
204 dynamicCodeContext::addLineDirective
207 readPtr->startLineNumber(),
212 const entry* execPtr = dict.lookupEntryPtr
220 codeExecute_ = stringOps::trim(execPtr->stream());
221 stringOps::inplaceExpand(codeExecute_, dict);
222 dynamicCodeContext::addLineDirective
225 execPtr->startLineNumber(),
230 const entry* endPtr = dict.lookupEntryPtr
238 codeEnd_ = stringOps::trim(endPtr->stream());
239 stringOps::inplaceExpand(codeEnd_, dict);
240 dynamicCodeContext::addLineDirective
243 endPtr->startLineNumber(),
248 updateLibrary(redirectType_);
249 return redirectFunctionObject().read(dict);
253 // ************************************************************************* //