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/>.
28 Converts all IOobjects associated with a case into the format specified
31 Mainly used to convert binary mesh/field files to ASCII.
33 Problem: any zero-size List written binary gets written as '0'. When
34 reading the file as a dictionary this is interpreted as a label. This
35 is (usually) not a problem when doing patch fields since these get the
36 'uniform', 'nonuniform' prefix. However zone contents are labelLists
37 not labelFields and these go wrong. For now hacked a solution where
38 we detect the keywords in zones and redo the dictionary entries
41 \*---------------------------------------------------------------------------*/
44 #include "timeSelector.H"
46 #include "volFields.H"
47 #include "surfaceFields.H"
48 #include "pointFields.H"
49 #include "cellIOList.H"
50 #include "IOobjectList.H"
51 #include "IOPtrList.H"
53 #include "writeMeshObject.H"
54 #include "fieldDictionary.H"
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 defineTemplateTypeNameAndDebug(IOPtrList<entry>, 0);
66 // Hack to do zones which have Lists in them. See above.
67 bool writeZones(const word& name, const fileName& meshDir, Time& runTime)
84 Info<< " Reading " << io.headerClassName()
85 << " : " << name << endl;
87 // Switch off type checking (for reading e.g. faceZones as
88 // generic list of dictionaries).
89 const word oldTypeName = IOPtrList<entry>::typeName;
90 const_cast<word&>(IOPtrList<entry>::typeName) = word::null;
92 IOPtrList<entry> meshObject(io);
96 if (meshObject[i].isDict())
98 dictionary& d = meshObject[i].dict();
100 if (d.found("faceLabels"))
102 d.set("faceLabels", labelList(d.lookup("faceLabels")));
105 if (d.found("flipMap"))
107 d.set("flipMap", boolList(d.lookup("flipMap")));
110 if (d.found("cellLabels"))
112 d.set("cellLabels", labelList(d.lookup("cellLabels")));
115 if (d.found("pointLabels"))
117 d.set("pointLabels", labelList(d.lookup("pointLabels")));
122 const_cast<word&>(IOPtrList<entry>::typeName) = oldTypeName;
123 // Fake type back to what was in field
124 const_cast<word&>(meshObject.type()) = io.headerClassName();
126 Info<< " Writing " << name << endl;
128 // Force writing as ascii
129 writeOk = meshObject.regIOobject::writeObject
132 IOstream::currentVersion,
133 runTime.writeCompression()
144 int main(int argc, char *argv[])
146 timeSelector::addOptions();
147 argList::addBoolOption
150 "exclude the 'constant/' dir in the times list"
153 # include "addRegionOption.H"
154 # include "setRootCase.H"
156 // enable noConstant by switching
157 if (!args.optionFound("noConstant"))
159 args.setOption("constant", "");
163 args.unsetOption("constant");
164 Info<< "Excluding the constant directory." << nl << endl;
168 # include "createTime.H"
171 // Make sure we do not use the master-only reading since we read
172 // fields (different per processor) as dictionaries.
173 regIOobject::fileModificationChecking = regIOobject::timeStamp;
176 fileName meshDir = polyMesh::meshSubDir;
177 fileName regionPrefix = "";
178 word regionName = polyMesh::defaultRegion;
179 if (args.optionReadIfPresent("region", regionName))
181 Info<< "Using region " << regionName << nl << endl;
182 regionPrefix = regionName;
183 meshDir = regionName/polyMesh::meshSubDir;
186 Foam::instantList timeDirs = Foam::timeSelector::select0(runTime, args);
188 forAll(timeDirs, timeI)
190 runTime.setTime(timeDirs[timeI], timeI);
191 Info<< "Time = " << runTime.timeName() << endl;
193 // Convert all the standard mesh files
194 writeMeshObject<cellCompactIOList>("cells", meshDir, runTime);
195 writeMeshObject<labelIOList>("owner", meshDir, runTime);
196 writeMeshObject<labelIOList>("neighbour", meshDir, runTime);
197 writeMeshObject<faceCompactIOList>("faces", meshDir, runTime);
198 writeMeshObject<pointIOField>("points", meshDir, runTime);
199 writeMeshObject<labelIOList>("pointProcAddressing", meshDir, runTime);
200 writeMeshObject<labelIOList>("faceProcAddressing", meshDir, runTime);
201 writeMeshObject<labelIOList>("cellProcAddressing", meshDir, runTime);
202 writeMeshObject<labelIOList>
204 "boundaryProcAddressing",
209 if (runTime.writeFormat() == IOstream::ASCII)
211 // Only do zones when converting from binary to ascii
212 // The other way gives problems since working on dictionary level.
213 writeZones("cellZones", meshDir, runTime);
214 writeZones("faceZones", meshDir, runTime);
215 writeZones("pointZones", meshDir, runTime);
218 // Get list of objects from the database
219 IOobjectList objects(runTime, runTime.timeName(), regionPrefix);
221 forAllConstIter(IOobjectList, objects, iter)
223 const word& headerClassName = iter()->headerClassName();
227 headerClassName == volScalarField::typeName
228 || headerClassName == volVectorField::typeName
229 || headerClassName == volSphericalTensorField::typeName
230 || headerClassName == volSymmTensorField::typeName
231 || headerClassName == volTensorField::typeName
233 || headerClassName == surfaceScalarField::typeName
234 || headerClassName == surfaceVectorField::typeName
235 || headerClassName == surfaceSphericalTensorField::typeName
236 || headerClassName == surfaceSymmTensorField::typeName
237 || headerClassName == surfaceTensorField::typeName
239 || headerClassName == pointScalarField::typeName
240 || headerClassName == pointVectorField::typeName
241 || headerClassName == pointSphericalTensorField::typeName
242 || headerClassName == pointSymmTensorField::typeName
243 || headerClassName == pointTensorField::typeName
246 Info<< " Reading " << headerClassName
247 << " : " << iter()->name() << endl;
249 fieldDictionary fDict
255 Info<< " Writing " << iter()->name() << endl;
256 fDict.regIOobject::write();
263 Info<< "End\n" << endl;
269 // ************************************************************************* //