changeDictionary.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include "argList.H"
00056 #include "IOobjectList.H"
00057 #include "IOPtrList.H"
00058 #include "volFields.H"
00059
00060 using namespace Foam;
00061
00062
00063
00064 namespace Foam
00065 {
00066 defineTemplateTypeNameAndDebug(IOPtrList<entry>, 0);
00067 }
00068
00069
00070
00071
00072
00073 int main(int argc, char *argv[])
00074 {
00075 # include "addRegionOption.H"
00076 # include "setRootCase.H"
00077 # include "createTime.H"
00078 # include "createNamedMesh.H"
00079
00080 fileName regionPrefix = "";
00081 if (regionName != fvMesh::defaultRegion)
00082 {
00083 regionPrefix = regionName;
00084 }
00085
00086
00087 IOdictionary dict
00088 (
00089 IOobject
00090 (
00091 "changeDictionaryDict",
00092 runTime.system(),
00093 mesh,
00094 IOobject::MUST_READ,
00095 IOobject::NO_WRITE
00096 )
00097 );
00098 const dictionary& replaceDicts = dict.subDict("dictionaryReplacement");
00099 Info<< "Read dictionary " << dict.name()
00100 << " with replacements for dictionaries "
00101 << replaceDicts.toc() << endl;
00102
00103
00104
00105
00106 forAllConstIter(dictionary, replaceDicts, fieldIter)
00107 {
00108 const word& fieldName = fieldIter().keyword();
00109 Info<< "Replacing entries in dictionary " << fieldName << endl;
00110
00111
00112
00113
00114 if (fieldName == "boundary")
00115 {
00116 Info<< "Special handling of " << fieldName
00117 << " as polyMesh/boundary file." << endl;
00118
00119
00120 const word oldTypeName = IOPtrList<entry>::typeName;
00121 const_cast<word&>(IOPtrList<entry>::typeName) = word::null;
00122 IOPtrList<entry> dictList
00123 (
00124 IOobject
00125 (
00126 fieldName,
00127 runTime.findInstance
00128 (
00129 regionPrefix/polyMesh::meshSubDir,
00130 fieldName
00131 ),
00132 polyMesh::meshSubDir,
00133 mesh,
00134 IOobject::MUST_READ,
00135 IOobject::NO_WRITE,
00136 false
00137 )
00138 );
00139 const_cast<word&>(IOPtrList<entry>::typeName) = oldTypeName;
00140
00141 const_cast<word&>(dictList.type()) = dictList.headerClassName();
00142
00143
00144 dictionary fieldDict;
00145 forAll(dictList, i)
00146 {
00147 fieldDict.add(dictList[i].keyword(), dictList[i].dict());
00148 }
00149
00150 Info<< "Loaded dictionary " << fieldName
00151 << " with entries " << fieldDict.toc() << endl;
00152
00153
00154 const dictionary& replaceDict = fieldIter().dict();
00155 Info<< "Merging entries from " << replaceDict.toc() << endl;
00156
00157
00158 fieldDict.merge(replaceDict);
00159
00160 Info<< "fieldDict:" << fieldDict << endl;
00161
00162
00163 wordList doneKeys(dictList.size());
00164
00165 label nEntries = fieldDict.size();
00166 forAll(dictList, i)
00167 {
00168 doneKeys[i] = dictList[i].keyword();
00169 dictList.set
00170 (
00171 i,
00172 fieldDict.lookupEntry
00173 (
00174 doneKeys[i],
00175 false,
00176 true
00177 ).clone()
00178 );
00179 fieldDict.remove(doneKeys[i]);
00180 }
00181
00182 label sz = dictList.size();
00183 dictList.setSize(nEntries);
00184 forAllConstIter(dictionary, fieldDict, iter)
00185 {
00186 dictList.set(sz, iter().clone());
00187 }
00188
00189 Info<< "Writing modified fieldDict " << fieldName << endl;
00190 dictList.write();
00191 }
00192 else
00193 {
00194
00195
00196 Info<< "Loading dictionary " << fieldName << endl;
00197 const word oldTypeName = IOdictionary::typeName;
00198 const_cast<word&>(IOdictionary::typeName) = word::null;
00199 IOdictionary fieldDict
00200 (
00201 IOobject
00202 (
00203 fieldName,
00204 runTime.timeName(),
00205 mesh,
00206 IOobject::MUST_READ,
00207 IOobject::NO_WRITE,
00208 false
00209 )
00210 );
00211 const_cast<word&>(IOdictionary::typeName) = oldTypeName;
00212
00213 const_cast<word&>(fieldDict.type()) = fieldDict.headerClassName();
00214
00215 Info<< "Loaded dictionary " << fieldName
00216 << " with entries " << fieldDict.toc() << endl;
00217
00218
00219 const dictionary& replaceDict = fieldIter().dict();
00220 Info<< "Merging entries from " << replaceDict.toc() << endl;
00221
00222
00223 fieldDict.merge(replaceDict);
00224
00225 Info<< "Writing modified fieldDict " << fieldName << endl;
00226 fieldDict.regIOobject::write();
00227 }
00228 }
00229
00230 Info<< endl;
00231
00232 Info<< "End\n" << endl;
00233
00234 return 0;
00235 }
00236
00237
00238
Copyright © 2000-2009 OpenCFD Ltd