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 #include <finiteVolume/fvCFD.H>
00033 #include <OpenFOAM/IFstream.H>
00034
00035
00036
00037
00038 int main(int argc, char *argv[])
00039 {
00040 argList::noParallel();
00041 argList::validArgs.append("SMAP fileName");
00042
00043 argList args(argc, argv);
00044
00045 if (!args.check())
00046 {
00047 FatalError.exit();
00048 }
00049
00050 # include <OpenFOAM/createTime.H>
00051
00052 fileNameList fieldNames = readDir(runTime.timePath(), fileName::FILE);
00053 dictionary fieldNameDict;
00054 forAll (fieldNames, i)
00055 {
00056 fieldNameDict.add(fieldNames[i], word(fieldNames[i]));
00057 }
00058
00059 dictionary nameMap;
00060 if (fieldNameDict.found("U")) nameMap.add("SU", word("U"));
00061 if (fieldNameDict.found("p")) nameMap.add("P", word("p"));
00062 if (fieldNameDict.found("T")) nameMap.add("T", word("T"));
00063 if (fieldNameDict.found("rho")) nameMap.add("DENS", word("rho"));
00064 if (fieldNameDict.found("k")) nameMap.add("TE", word("k"));
00065 if (fieldNameDict.found("epsilon")) nameMap.add("ED", word("epsilon"));
00066 if (fieldNameDict.found("nuEff")) nameMap.add("VIS", word("nuEff"));
00067
00068 # include <OpenFOAM/createMesh.H>
00069
00070 IFstream smapFile(args.additionalArgs()[0]);
00071
00072 if (!smapFile.good())
00073 {
00074 FatalErrorIn(args.executable())
00075 << "Cannot open SMAP file " << smapFile.name()
00076 << exit(FatalError);
00077 }
00078
00079 while (!smapFile.eof())
00080 {
00081 wordList starFieldNames(10);
00082
00083 token fieldName(smapFile);
00084
00085 if (!smapFile.good())
00086 {
00087 break;
00088 }
00089
00090 if
00091 (
00092 fieldName.type() != token::WORD
00093 && fieldName.wordToken() != "CELL"
00094 )
00095 {
00096 FatalErrorIn(args.executable())
00097 << "Expected first CELL, found "
00098 << fieldName
00099 << exit(FatalError);
00100 }
00101
00102 label nCols = 0;
00103 smapFile >> fieldName;
00104 while (fieldName.type() == token::WORD)
00105 {
00106 starFieldNames[nCols++] = fieldName.wordToken();
00107 smapFile >> fieldName;
00108 }
00109
00110 List<volScalarField*> sFields
00111 (
00112 nCols,
00113 reinterpret_cast<volScalarField*>(0)
00114 );
00115
00116 List<volVectorField*> vFields
00117 (
00118 nCols,
00119 reinterpret_cast<volVectorField*>(0)
00120 );
00121
00122 label i=0;
00123 while (i < nCols)
00124 {
00125 if (nameMap.found(starFieldNames[i]))
00126 {
00127 if (starFieldNames[i] == "SU")
00128 {
00129 vFields[i] =
00130 new volVectorField
00131 (
00132 IOobject
00133 (
00134 nameMap.lookup(starFieldNames[i]),
00135 runTime.timeName(),
00136 mesh,
00137 IOobject::MUST_READ,
00138 IOobject::AUTO_WRITE
00139 ),
00140 mesh
00141 );
00142
00143 i += 3;
00144 }
00145 else
00146 {
00147 sFields[i] =
00148 new volScalarField
00149 (
00150 IOobject
00151 (
00152 nameMap.lookup(starFieldNames[i]),
00153 runTime.timeName(),
00154 mesh,
00155 IOobject::MUST_READ,
00156 IOobject::AUTO_WRITE
00157 ),
00158 mesh
00159 );
00160
00161 i++;
00162 }
00163 }
00164 else
00165 {
00166 i++;
00167 }
00168 }
00169
00170
00171 label cell;
00172 scalar value;
00173 forAll (mesh.cells(), celli)
00174 {
00175 if (celli > 0)
00176 {
00177 smapFile >> cell;
00178 }
00179
00180 label i=0;
00181 while (i < nCols)
00182 {
00183 if (sFields[i])
00184 {
00185 smapFile >> (*sFields[i])[celli];
00186 i++;
00187 }
00188 else if (vFields[i])
00189 {
00190 smapFile >> (*vFields[i])[celli].x();
00191 smapFile >> (*vFields[i])[celli].y();
00192 smapFile >> (*vFields[i])[celli].z();
00193 i += 3;
00194 }
00195 else
00196 {
00197 smapFile >> value;
00198 i++;
00199 }
00200 }
00201 }
00202
00203 for (label i=0; i<nCols; i++)
00204 {
00205 if (sFields[i])
00206 {
00207 sFields[i]->correctBoundaryConditions();
00208 sFields[i]->write();
00209 delete sFields[i];
00210 sFields[i] = NULL;
00211 }
00212 else if (vFields[i])
00213 {
00214 vFields[i]->correctBoundaryConditions();
00215 vFields[i]->write();
00216 delete vFields[i];
00217 vFields[i] = NULL;
00218 }
00219 }
00220
00221
00222 smapFile >> cell;
00223
00224 if (cell != 0)
00225 {
00226 FatalErrorIn(args.executable())
00227 << "Expected first SMAP dummy entry to be cell 0, found "
00228 << cell
00229 << exit(FatalError);
00230 }
00231
00232 for (label i=0; i<nCols; i++)
00233 {
00234 smapFile >> value;
00235 }
00236 }
00237
00238 Info << "End\n" << endl;
00239
00240 return 0;
00241 }
00242
00243
00244