1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Utility to change dictionary entries, e.g. can be used to change the patch
30 type in the field and polyMesh/boundary files.
32 Reads dictionaries (fields) and entries to change from a dictionary.
33 E.g. to make the @em movingWall a @em fixedValue for @em p, the
34 @c system/changeDictionaryDict would contain the following:
42 movingWall // entry to change
53 \*---------------------------------------------------------------------------*/
56 #include "IOobjectList.H"
57 #include "IOPtrList.H"
58 #include "volFields.H"
62 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 defineTemplateTypeNameAndDebug(IOPtrList<entry>, 0);
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 int main(int argc, char *argv[])
75 # include "addRegionOption.H"
76 # include "setRootCase.H"
77 # include "createTime.H"
78 # include "createNamedMesh.H"
80 fileName regionPrefix = "";
81 if (regionName != fvMesh::defaultRegion)
83 regionPrefix = regionName;
86 // Get the replacement rules from a dictionary
91 "changeDictionaryDict",
98 const dictionary& replaceDicts = dict.subDict("dictionaryReplacement");
99 Info<< "Read dictionary " << dict.name()
100 << " with replacements for dictionaries "
101 << replaceDicts.toc() << endl;
104 // Every replacement is a dictionary name and a keyword in this
106 forAllConstIter(dictionary, replaceDicts, fieldIter)
108 const word& fieldName = fieldIter().keyword();
109 Info<< "Replacing entries in dictionary " << fieldName << endl;
111 // Handle 'boundary' specially:
112 // - is PtrList of dictionaries
114 if (fieldName == "boundary")
116 Info<< "Special handling of " << fieldName
117 << " as polyMesh/boundary file." << endl;
119 // Read PtrList of dictionary as dictionary.
120 const word oldTypeName = IOPtrList<entry>::typeName;
121 const_cast<word&>(IOPtrList<entry>::typeName) = word::null;
122 IOPtrList<entry> dictList
129 regionPrefix/polyMesh::meshSubDir,
132 polyMesh::meshSubDir,
139 const_cast<word&>(IOPtrList<entry>::typeName) = oldTypeName;
140 // Fake type back to what was in field
141 const_cast<word&>(dictList.type()) = dictList.headerClassName();
143 // Temporary convert to dictionary
144 dictionary fieldDict;
147 fieldDict.add(dictList[i].keyword(), dictList[i].dict());
150 Info<< "Loaded dictionary " << fieldName
151 << " with entries " << fieldDict.toc() << endl;
153 // Get the replacement dictionary for the field
154 const dictionary& replaceDict = fieldIter().dict();
155 Info<< "Merging entries from " << replaceDict.toc() << endl;
157 // Merge the replacements in
158 fieldDict.merge(replaceDict);
160 Info<< "fieldDict:" << fieldDict << endl;
162 // Convert back into dictList
163 wordList doneKeys(dictList.size());
165 label nEntries = fieldDict.size();
168 doneKeys[i] = dictList[i].keyword();
172 fieldDict.lookupEntry
179 fieldDict.remove(doneKeys[i]);
181 // Add remaining entries
182 label sz = dictList.size();
183 dictList.setSize(nEntries);
184 forAllConstIter(dictionary, fieldDict, iter)
186 dictList.set(sz, iter().clone());
189 Info<< "Writing modified fieldDict " << fieldName << endl;
194 // Read dictionary. (disable class type checking so we can load
196 Info<< "Loading dictionary " << fieldName << endl;
197 const word oldTypeName = IOdictionary::typeName;
198 const_cast<word&>(IOdictionary::typeName) = word::null;
199 IOdictionary fieldDict
211 const_cast<word&>(IOdictionary::typeName) = oldTypeName;
212 // Fake type back to what was in field
213 const_cast<word&>(fieldDict.type()) = fieldDict.headerClassName();
215 Info<< "Loaded dictionary " << fieldName
216 << " with entries " << fieldDict.toc() << endl;
218 // Get the replacement dictionary for the field
219 const dictionary& replaceDict = fieldIter().dict();
220 Info<< "Merging entries from " << replaceDict.toc() << endl;
222 // Merge the replacements in
223 fieldDict.merge(replaceDict);
225 Info<< "Writing modified fieldDict " << fieldName << endl;
226 fieldDict.regIOobject::write();
232 Info<< "End\n" << endl;
238 // ************************************************************************* //