BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / postProcessing / functionObjects / utilities / codedFunctionObject / codedFunctionObject.C
blob7745c7e308bbd2f13519d060950e4fa46b39921f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
29 #include "Time.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 * * * * * * * * * * * * * //
38 namespace Foam
40     defineTypeNameAndDebug(codedFunctionObject, 0);
42     addToRunTimeSelectionTable
43     (
44         functionObject,
45         codedFunctionObject,
46         dictionary
47     );
50 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
53 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
55 void Foam::codedFunctionObject::prepare
57     dynamicCode& dynCode,
58     const dynamicCodeContext& context
59 ) const
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
84         (
85             "EXE_INC = -g \\\n"
86             "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
87             + context.options()
88             + "\n\nLIB_LIBS = \\\n"
89             + "    -lOpenFOAM \\\n"
90             + "    -lfiniteVolume \\\n"
91             + context.libs()
92         );
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
116     return dict_;
120 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
122 Foam::codedFunctionObject::codedFunctionObject
124     const word& name,
125     const Time& time,
126     const dictionary& dict,
127     bool readNow
130     functionObject(name),
131     codedBase(),
132     time_(time),
133     dict_(dict)
135     if (readNow)
136     {
137         read(dict_);
138     }
142 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
144 Foam::codedFunctionObject::~codedFunctionObject()
148 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
150 Foam::functionObject&
151 Foam::codedFunctionObject::redirectFunctionObject() const
153     if (!redirectFunctionObjectPtr_.valid())
154     {
155         dictionary constructDict(dict_);
156         constructDict.set("type", redirectType_);
158         redirectFunctionObjectPtr_ = functionObject::New
159         (
160             redirectType_,
161             time_,
162             constructDict
163         );
164     }
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
195     (
196         "codeRead",
197         false,
198         false
199     );
200     if (readPtr)
201     {
202         codeRead_ = stringOps::trim(readPtr->stream());
203         stringOps::inplaceExpand(codeRead_, dict);
204         dynamicCodeContext::addLineDirective
205         (
206             codeRead_,
207             readPtr->startLineNumber(),
208             dict.name()
209         );
210     }
212     const entry* execPtr = dict.lookupEntryPtr
213     (
214         "codeExecute",
215         false,
216         false
217     );
218     if (execPtr)
219     {
220         codeExecute_ = stringOps::trim(execPtr->stream());
221         stringOps::inplaceExpand(codeExecute_, dict);
222         dynamicCodeContext::addLineDirective
223         (
224             codeExecute_,
225             execPtr->startLineNumber(),
226             dict.name()
227         );
228     }
230     const entry* endPtr = dict.lookupEntryPtr
231     (
232         "codeEnd",
233         false,
234         false
235     );
236     if (execPtr)
237     {
238         codeEnd_ = stringOps::trim(endPtr->stream());
239         stringOps::inplaceExpand(codeEnd_, dict);
240         dynamicCodeContext::addLineDirective
241         (
242             codeEnd_,
243             endPtr->startLineNumber(),
244             dict.name()
245         );
246     }
248     updateLibrary(redirectType_);
249     return redirectFunctionObject().read(dict);
253 // ************************************************************************* //