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/>.
25 Interpolate fields between time-steps e.g. for animation.
27 \*---------------------------------------------------------------------------*/
30 #include "timeSelector.H"
35 #include "surfaceMesh.H"
36 #include "volFields.H"
37 #include "surfaceFields.H"
38 #include "pointFields.H"
39 #include "ReadFields.H"
43 class fieldInterpolator
47 const IOobjectList& objects_;
48 const HashSet<word>& selectedFields_;
59 const IOobjectList& objects,
60 const HashSet<word>& selectedFields,
69 selectedFields_(selectedFields),
75 template<class GeoFieldType>
80 template<class GeoFieldType>
81 void fieldInterpolator::interpolate()
83 const word& fieldClassName = GeoFieldType::typeName;
85 IOobjectList fields = objects_.lookupClass(fieldClassName);
89 Info<< " " << fieldClassName << "s:";
91 forAllConstIter(IOobjectList, fields, fieldIter)
95 selectedFields_.empty()
96 || selectedFields_.found(fieldIter()->name())
99 Info<< " " << fieldIter()->name() << '(';
129 scalar deltaT = (ti1_.value() - ti_.value())/(divisions_ + 1);
131 for (int j=0; j<divisions_; j++)
133 instant timej = instant(ti_.value() + (j + 1)*deltaT);
135 runTime_.setTime(timej.name(), 0);
139 if (j < divisions_-1)
144 scalar lambda = scalar(j + 1)/scalar(divisions_ + 1);
157 (1.0 - lambda)*fieldi + lambda*fieldi1
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 int main(int argc, char *argv[])
177 timeSelector::addOptions();
182 "specify a list of fields to be interpolated. Eg, '(U T p)' - "
183 "regular expressions not currently supported"
189 "specify number of temporal sub-divisions to create (default = 1)."
192 #include "setRootCase.H"
193 #include "createTime.H"
194 runTime.functionObjects().off();
196 HashSet<word> selectedFields;
197 if (args.optionFound("fields"))
199 args.optionLookup("fields")() >> selectedFields;
203 if (args.optionFound("divisions"))
205 args.optionLookup("divisions")() >> divisions;
208 instantList timeDirs = timeSelector::select0(runTime, args);
210 #include "createMesh.H"
212 Info<< "Interpolating fields for times:" << endl;
214 for (label timei = 0; timei < timeDirs.size() - 1; timei++)
216 runTime.setTime(timeDirs[timei], timei);
218 // Read objects in time directory
219 IOobjectList objects(mesh, runTime.timeName());
221 fieldInterpolator interpolator
232 // Interpolate vol fields
233 interpolator.interpolate<volScalarField>();
234 interpolator.interpolate<volVectorField>();
235 interpolator.interpolate<volSphericalTensorField>();
236 interpolator.interpolate<volSymmTensorField>();
237 interpolator.interpolate<volTensorField>();
239 // Interpolate surface fields
240 interpolator.interpolate<surfaceScalarField>();
241 interpolator.interpolate<surfaceVectorField>();
242 interpolator.interpolate<surfaceSphericalTensorField>();
243 interpolator.interpolate<surfaceSymmTensorField>();
244 interpolator.interpolate<surfaceTensorField>();
247 Info<< "End\n" << endl;
253 // ************************************************************************* //