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
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #include <finiteVolume/fvMeshSubset.H>
00067 #include <OpenFOAM/argList.H>
00068 #include <meshTools/cellSet.H>
00069 #include <OpenFOAM/IOobjectList.H>
00070 #include <finiteVolume/volFields.H>
00071
00072 using namespace Foam;
00073
00074
00075
00076
00077 template<class Type>
00078 void subsetVolFields
00079 (
00080 const fvMeshSubset& subsetter,
00081 const wordList& fieldNames,
00082 PtrList<GeometricField<Type, fvPatchField, volMesh> >& subFields
00083 )
00084 {
00085 const fvMesh& baseMesh = subsetter.baseMesh();
00086
00087 forAll(fieldNames, i)
00088 {
00089 const word& fieldName = fieldNames[i];
00090
00091 Info<< "Subsetting field " << fieldName << endl;
00092
00093 GeometricField<Type, fvPatchField, volMesh> fld
00094 (
00095 IOobject
00096 (
00097 fieldName,
00098 baseMesh.time().timeName(),
00099 baseMesh,
00100 IOobject::MUST_READ,
00101 IOobject::NO_WRITE
00102 ),
00103 baseMesh
00104 );
00105
00106 subFields.set(i, subsetter.interpolate(fld));
00107 }
00108 }
00109
00110
00111 template<class Type>
00112 void subsetSurfaceFields
00113 (
00114 const fvMeshSubset& subsetter,
00115 const wordList& fieldNames,
00116 PtrList<GeometricField<Type, fvsPatchField, surfaceMesh> >& subFields
00117 )
00118 {
00119 const fvMesh& baseMesh = subsetter.baseMesh();
00120
00121 forAll(fieldNames, i)
00122 {
00123 const word& fieldName = fieldNames[i];
00124
00125 Info<< "Subsetting field " << fieldName << endl;
00126
00127 GeometricField<Type, fvsPatchField, surfaceMesh> fld
00128 (
00129 IOobject
00130 (
00131 fieldName,
00132 baseMesh.time().timeName(),
00133 baseMesh,
00134 IOobject::MUST_READ,
00135 IOobject::NO_WRITE
00136 ),
00137 baseMesh
00138 );
00139
00140 subFields.set(i, subsetter.interpolate(fld));
00141 }
00142 }
00143
00144
00145 template<class Type>
00146 void subsetPointFields
00147 (
00148 const fvMeshSubset& subsetter,
00149 const pointMesh& pMesh,
00150 const wordList& fieldNames,
00151 PtrList<GeometricField<Type, pointPatchField, pointMesh> >& subFields
00152 )
00153 {
00154 const fvMesh& baseMesh = subsetter.baseMesh();
00155
00156 forAll(fieldNames, i)
00157 {
00158 const word& fieldName = fieldNames[i];
00159
00160 Info<< "Subsetting field " << fieldName << endl;
00161
00162 GeometricField<Type, pointPatchField, pointMesh> fld
00163 (
00164 IOobject
00165 (
00166 fieldName,
00167 baseMesh.time().timeName(),
00168 baseMesh,
00169 IOobject::MUST_READ,
00170 IOobject::NO_WRITE
00171 ),
00172 pMesh
00173 );
00174
00175 subFields.set(i, subsetter.interpolate(fld));
00176 }
00177 }
00178
00179
00180
00181
00182 int main(int argc, char *argv[])
00183 {
00184 argList::validArgs.append("set");
00185 argList::validOptions.insert("patch", "patch name");
00186 argList::validOptions.insert("overwrite", "");
00187
00188 # include <OpenFOAM/setRootCase.H>
00189 # include <OpenFOAM/createTime.H>
00190 runTime.functionObjects().off();
00191 # include <OpenFOAM/createMesh.H>
00192 const word oldInstance = mesh.pointsInstance();
00193
00194 word setName(args.additionalArgs()[0]);
00195 bool overwrite = args.optionFound("overwrite");
00196
00197
00198 Info<< "Reading cell set from " << setName << endl << endl;
00199
00200
00201 fvMeshSubset subsetter(mesh);
00202
00203 label patchI = -1;
00204
00205 if (args.optionFound("patch"))
00206 {
00207 word patchName(args.option("patch"));
00208
00209 patchI = mesh.boundaryMesh().findPatchID(patchName);
00210
00211 if (patchI == -1)
00212 {
00213 FatalErrorIn(args.executable()) << "Illegal patch " << patchName
00214 << nl << "Valid patches are " << mesh.boundaryMesh().names()
00215 << exit(FatalError);
00216 }
00217
00218 Info<< "Adding exposed internal faces to patch " << patchName << endl
00219 << endl;
00220 }
00221 else
00222 {
00223 Info<< "Adding exposed internal faces to a patch called"
00224 << " \"oldInternalFaces\" (created if nessecary)" << endl
00225 << endl;
00226 }
00227
00228
00229 cellSet currentSet(mesh, setName);
00230
00231 subsetter.setLargeCellSubset(currentSet, patchI, true);
00232
00233 IOobjectList objects(mesh, runTime.timeName());
00234
00235
00236
00237
00238
00239 wordList scalarNames(objects.names(volScalarField::typeName));
00240 PtrList<volScalarField> scalarFlds(scalarNames.size());
00241 subsetVolFields(subsetter, scalarNames, scalarFlds);
00242
00243 wordList vectorNames(objects.names(volVectorField::typeName));
00244 PtrList<volVectorField> vectorFlds(vectorNames.size());
00245 subsetVolFields(subsetter, vectorNames, vectorFlds);
00246
00247 wordList sphericalTensorNames
00248 (
00249 objects.names(volSphericalTensorField::typeName)
00250 );
00251 PtrList<volSphericalTensorField> sphericalTensorFlds
00252 (
00253 sphericalTensorNames.size()
00254 );
00255 subsetVolFields(subsetter, sphericalTensorNames, sphericalTensorFlds);
00256
00257 wordList symmTensorNames(objects.names(volSymmTensorField::typeName));
00258 PtrList<volSymmTensorField> symmTensorFlds(symmTensorNames.size());
00259 subsetVolFields(subsetter, symmTensorNames, symmTensorFlds);
00260
00261 wordList tensorNames(objects.names(volTensorField::typeName));
00262 PtrList<volTensorField> tensorFlds(tensorNames.size());
00263 subsetVolFields(subsetter, tensorNames, tensorFlds);
00264
00265
00266
00267
00268
00269 wordList surfScalarNames(objects.names(surfaceScalarField::typeName));
00270 PtrList<surfaceScalarField> surfScalarFlds(surfScalarNames.size());
00271 subsetSurfaceFields(subsetter, surfScalarNames, surfScalarFlds);
00272
00273 wordList surfVectorNames(objects.names(surfaceVectorField::typeName));
00274 PtrList<surfaceVectorField> surfVectorFlds(surfVectorNames.size());
00275 subsetSurfaceFields(subsetter, surfVectorNames, surfVectorFlds);
00276
00277 wordList surfSphericalTensorNames
00278 (
00279 objects.names(surfaceSphericalTensorField::typeName)
00280 );
00281 PtrList<surfaceSphericalTensorField> surfSphericalTensorFlds
00282 (
00283 surfSphericalTensorNames.size()
00284 );
00285 subsetSurfaceFields
00286 (
00287 subsetter,
00288 surfSphericalTensorNames,
00289 surfSphericalTensorFlds
00290 );
00291
00292 wordList surfSymmTensorNames
00293 (
00294 objects.names(surfaceSymmTensorField::typeName)
00295 );
00296 PtrList<surfaceSymmTensorField> surfSymmTensorFlds
00297 (
00298 surfSymmTensorNames.size()
00299 );
00300 subsetSurfaceFields(subsetter, surfSymmTensorNames, surfSymmTensorFlds);
00301
00302 wordList surfTensorNames(objects.names(surfaceTensorField::typeName));
00303 PtrList<surfaceTensorField> surfTensorFlds(surfTensorNames.size());
00304 subsetSurfaceFields(subsetter, surfTensorNames, surfTensorFlds);
00305
00306
00307
00308
00309
00310 const pointMesh& pMesh = pointMesh::New(mesh);
00311
00312 wordList pointScalarNames(objects.names(pointScalarField::typeName));
00313 PtrList<pointScalarField> pointScalarFlds(pointScalarNames.size());
00314 subsetPointFields(subsetter, pMesh, pointScalarNames, pointScalarFlds);
00315
00316 wordList pointVectorNames(objects.names(pointVectorField::typeName));
00317 PtrList<pointVectorField> pointVectorFlds(pointVectorNames.size());
00318 subsetPointFields(subsetter, pMesh, pointVectorNames, pointVectorFlds);
00319
00320 wordList pointSphericalTensorNames
00321 (
00322 objects.names(pointSphericalTensorField::typeName)
00323 );
00324 PtrList<pointSphericalTensorField> pointSphericalTensorFlds
00325 (
00326 pointSphericalTensorNames.size()
00327 );
00328 subsetPointFields
00329 (
00330 subsetter,
00331 pMesh,
00332 pointSphericalTensorNames,
00333 pointSphericalTensorFlds
00334 );
00335
00336 wordList pointSymmTensorNames
00337 (
00338 objects.names(pointSymmTensorField::typeName)
00339 );
00340 PtrList<pointSymmTensorField> pointSymmTensorFlds
00341 (
00342 pointSymmTensorNames.size()
00343 );
00344 subsetPointFields
00345 (
00346 subsetter,
00347 pMesh,
00348 pointSymmTensorNames,
00349 pointSymmTensorFlds
00350 );
00351
00352 wordList pointTensorNames(objects.names(pointTensorField::typeName));
00353 PtrList<pointTensorField> pointTensorFlds(pointTensorNames.size());
00354 subsetPointFields(subsetter, pMesh, pointTensorNames, pointTensorFlds);
00355
00356
00357
00358
00359
00360
00361 if (!overwrite)
00362 {
00363 runTime++;
00364 }
00365 else
00366 {
00367 subsetter.subMesh().setInstance(oldInstance);
00368 }
00369
00370 Info<< "Writing subsetted mesh and fields to time " << runTime.timeName()
00371 << endl;
00372 subsetter.subMesh().write();
00373
00374
00375
00376 forAll(scalarFlds, i)
00377 {
00378 scalarFlds[i].rename(scalarNames[i]);
00379
00380 scalarFlds[i].write();
00381 }
00382 forAll(vectorFlds, i)
00383 {
00384 vectorFlds[i].rename(vectorNames[i]);
00385
00386 vectorFlds[i].write();
00387 }
00388 forAll(sphericalTensorFlds, i)
00389 {
00390 sphericalTensorFlds[i].rename(sphericalTensorNames[i]);
00391
00392 sphericalTensorFlds[i].write();
00393 }
00394 forAll(symmTensorFlds, i)
00395 {
00396 symmTensorFlds[i].rename(symmTensorNames[i]);
00397
00398 symmTensorFlds[i].write();
00399 }
00400 forAll(tensorFlds, i)
00401 {
00402 tensorFlds[i].rename(tensorNames[i]);
00403
00404 tensorFlds[i].write();
00405 }
00406
00407
00408 forAll(surfScalarFlds, i)
00409 {
00410 surfScalarFlds[i].rename(surfScalarNames[i]);
00411
00412 surfScalarFlds[i].write();
00413 }
00414 forAll(surfVectorFlds, i)
00415 {
00416 surfVectorFlds[i].rename(surfVectorNames[i]);
00417
00418 surfVectorFlds[i].write();
00419 }
00420 forAll(surfSphericalTensorFlds, i)
00421 {
00422 surfSphericalTensorFlds[i].rename(surfSphericalTensorNames[i]);
00423
00424 surfSphericalTensorFlds[i].write();
00425 }
00426 forAll(surfSymmTensorFlds, i)
00427 {
00428 surfSymmTensorFlds[i].rename(surfSymmTensorNames[i]);
00429
00430 surfSymmTensorFlds[i].write();
00431 }
00432 forAll(surfTensorNames, i)
00433 {
00434 surfTensorFlds[i].rename(surfTensorNames[i]);
00435
00436 surfTensorFlds[i].write();
00437 }
00438
00439
00440 forAll(pointScalarFlds, i)
00441 {
00442 pointScalarFlds[i].rename(pointScalarNames[i]);
00443
00444 pointScalarFlds[i].write();
00445 }
00446 forAll(pointVectorFlds, i)
00447 {
00448 pointVectorFlds[i].rename(pointVectorNames[i]);
00449
00450 pointVectorFlds[i].write();
00451 }
00452 forAll(pointSphericalTensorFlds, i)
00453 {
00454 pointSphericalTensorFlds[i].rename(pointSphericalTensorNames[i]);
00455
00456 pointSphericalTensorFlds[i].write();
00457 }
00458 forAll(pointSymmTensorFlds, i)
00459 {
00460 pointSymmTensorFlds[i].rename(pointSymmTensorNames[i]);
00461
00462 pointSymmTensorFlds[i].write();
00463 }
00464 forAll(pointTensorNames, i)
00465 {
00466 pointTensorFlds[i].rename(pointTensorNames[i]);
00467
00468 pointTensorFlds[i].write();
00469 }
00470
00471
00472 Info << nl << "End" << endl;
00473
00474 return 0;
00475 }
00476
00477
00478