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 #include "ListOps.H"
00037 #include "argList.H"
00038 #include "Time.H"
00039 #include "fvMesh.H"
00040 #include "volFields.H"
00041 #include "emptyPolyPatch.H"
00042 #include "symmetryPolyPatch.H"
00043 #include "wallPolyPatch.H"
00044 #include "SortableList.H"
00045 #include "cellSet.H"
00046
00047 #include <ccmio.h>
00048 #include <vector>
00049
00050 using namespace Foam;
00051
00052
00053
00054 static char const kDefaultState[] = "default";
00055 static int const kVertOffset = 2;
00056
00057
00058
00059 labelList getInternalFaceOrder
00060 (
00061 const cellList& cells,
00062 const labelList& owner,
00063 const labelList& neighbour
00064 )
00065 {
00066 labelList oldToNew(owner.size(), -1);
00067
00068
00069 label newFaceI = 0;
00070
00071 forAll(cells, cellI)
00072 {
00073 const labelList& cFaces = cells[cellI];
00074
00075 SortableList<label> nbr(cFaces.size());
00076
00077 forAll(cFaces, i)
00078 {
00079 label faceI = cFaces[i];
00080
00081 label nbrCellI = neighbour[faceI];
00082
00083 if (nbrCellI != -1)
00084 {
00085
00086 if (nbrCellI == cellI)
00087 {
00088 nbrCellI = owner[faceI];
00089 }
00090
00091 if (cellI < nbrCellI)
00092 {
00093
00094 nbr[i] = nbrCellI;
00095 }
00096 else
00097 {
00098
00099 nbr[i] = -1;
00100 }
00101 }
00102 else
00103 {
00104
00105 nbr[i] = -1;
00106 }
00107 }
00108
00109 nbr.sort();
00110
00111 forAll(nbr, i)
00112 {
00113 if (nbr[i] != -1)
00114 {
00115 oldToNew[cFaces[nbr.indices()[i]]] = newFaceI++;
00116 }
00117 }
00118 }
00119
00120
00121 for (label faceI = newFaceI; faceI < owner.size(); faceI++)
00122 {
00123 oldToNew[faceI] = faceI;
00124 }
00125
00126 return oldToNew;
00127 }
00128
00129
00130 void storeCellInZone
00131 (
00132 const label cellI,
00133 const label cellType,
00134 Map<label>& typeToZone,
00135 List<DynamicList<label> >& zoneCells
00136 )
00137 {
00138 if (cellType >= 0)
00139 {
00140 Map<label>::iterator zoneFnd = typeToZone.find(cellType);
00141
00142 if (zoneFnd == typeToZone.end())
00143 {
00144
00145 zoneCells.setSize(zoneCells.size() + 1);
00146
00147 label zoneI = zoneCells.size()-1;
00148
00149 Info<< "Mapping type " << cellType << " to Foam cellZone "
00150 << zoneI << endl;
00151 typeToZone.insert(cellType, zoneI);
00152
00153 zoneCells[zoneI].append(cellI);
00154 }
00155 else
00156 {
00157
00158 zoneCells[zoneFnd()].append(cellI);
00159 }
00160 }
00161 }
00162
00163
00164 void CheckError(CCMIOError const &err, const Foam::string& str)
00165 {
00166 if (err != kCCMIONoErr)
00167 {
00168 FatalErrorIn("CheckError")
00169 << str << exit(FatalError);
00170 }
00171 }
00172
00173
00174 void ReadVertices
00175 (
00176 CCMIOError &err,
00177 CCMIOID &vertices,
00178 labelList& foamPointMap,
00179 pointField& foamPoints
00180 )
00181 {
00182
00183
00184
00185
00186
00187
00188
00189 CCMIOSize nVertices;
00190 CCMIOEntitySize(&err, vertices, &nVertices, NULL);
00191
00192 List<int> mapData(nVertices, 0);
00193 List<float> verts(3*nVertices, 0);
00194
00195 int offset = 0;
00196 int offsetPlusSize = offset+nVertices;
00197
00198 int dims = 1;
00199 float scale;
00200 CCMIOID mapID;
00201 CCMIOReadVerticesf(&err, vertices, &dims, &scale, &mapID, verts.begin(),
00202 offset, offsetPlusSize);
00203 CCMIOReadMap(&err, mapID, mapData.begin(), offset, offsetPlusSize);
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 foamPoints.setSize(nVertices);
00214 foamPoints = vector::zero;
00215 foamPointMap.setSize(nVertices);
00216
00217 forAll(foamPointMap, i)
00218 {
00219 foamPointMap[i] = mapData[i];
00220 for (direction cmpt = 0; cmpt < dims; cmpt++)
00221 {
00222 foamPoints[i][cmpt] = verts[dims*i + cmpt]*scale;
00223 }
00224 }
00225 }
00226
00227
00228 void ReadProblem
00229 (
00230 CCMIOError &err,
00231 CCMIOID& problem,
00232
00233 const Map<label>& prostarToFoamPatch,
00234 Map<word>& foamCellTypeNames,
00235 wordList& foamPatchTypes,
00236 wordList& foamPatchNames
00237 )
00238 {
00239
00240 CCMIOID next;
00241 int i = 0;
00242 while
00243 (
00244 CCMIONextEntity(NULL, problem, kCCMIOCellType, &i, &next)
00245 == kCCMIONoErr
00246 )
00247 {
00248 char *name;
00249 int size;
00250 int cellType;
00251
00252
00253
00254
00255
00256
00257 if
00258 (
00259 CCMIOReadOptstr(NULL, next, "MaterialType", &size, NULL)
00260 == kCCMIONoErr
00261 )
00262 {
00263 name = new char[size + 1];
00264 CCMIOReadOptstr(&err, next, "MaterialType", &size, name);
00265 CCMIOGetEntityIndex(&err, next, &cellType);
00266
00267 foamCellTypeNames.insert(cellType, name);
00268 Pout<< "Celltype:" << cellType << " name:" << name << endl;
00269
00270 delete [] name;
00271 }
00272 }
00273
00274
00275
00276
00277 CCMIOID boundary;
00278 label regionI = 0;
00279 int k = 0;
00280 while
00281 (
00282 CCMIONextEntity(NULL, problem, kCCMIOBoundaryRegion, &k, &boundary)
00283 == kCCMIONoErr
00284 )
00285 {
00286
00287 label foamPatchI = -1;
00288
00289
00290
00291 int prostarI = -1;
00292 if
00293 (
00294 CCMIOReadOpti(NULL, boundary, "ProstarRegionNumber", &prostarI)
00295 == kCCMIONoErr
00296 )
00297 {
00298 Pout<< "For region:" << regionI
00299 << " found ProstarRegionNumber:" << prostarI << endl;
00300 }
00301 else
00302 {
00303 prostarI = regionI;
00304
00305 Pout<< "For region:" << regionI
00306 << "did not find ProstarRegionNumber entry. Assuming "
00307 << prostarI << endl;
00308 }
00309
00310
00311 if (prostarToFoamPatch.found(prostarI))
00312 {
00313 foamPatchI = prostarToFoamPatch[prostarI];
00314
00315
00316
00317 int size;
00318 if
00319 (
00320 CCMIOReadOptstr(NULL, boundary, "BoundaryType", &size, NULL)
00321 == kCCMIONoErr
00322 )
00323 {
00324 char* s = new char[size + 1];
00325 CCMIOReadOptstr(NULL, boundary, "BoundaryType", &size, s);
00326 s[size] = '\0';
00327 foamPatchTypes[foamPatchI] = string::validate<word>(string(s));
00328 delete [] s;
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 if
00341 (
00342 CCMIOReadOptstr(NULL, boundary, "BoundaryName", &size, NULL)
00343 == kCCMIONoErr
00344 )
00345 {
00346 char* name = new char[size + 1];
00347 CCMIOReadOptstr(NULL, boundary, "BoundaryName", &size, name);
00348 name[size] = '\0';
00349 foamPatchNames[foamPatchI] = string::validate<word>(string(name));
00350 delete [] name;
00351 }
00352 else if
00353 (
00354 CCMIOReadOptstr(NULL, boundary, "Label", &size, NULL)
00355 == kCCMIONoErr
00356 )
00357 {
00358 char* name = new char[size + 1];
00359 CCMIOReadOptstr(NULL, boundary, "Label", &size, name);
00360 name[size] = '\0';
00361 foamPatchNames[foamPatchI] = string::validate<word>(string(name));
00362 delete [] name;
00363 }
00364 else
00365 {
00366 foamPatchNames[foamPatchI] =
00367 foamPatchTypes[foamPatchI]
00368 + Foam::name(foamPatchI);
00369 Pout<< "Made up name:" << foamPatchNames[foamPatchI]
00370 << endl;
00371 }
00372
00373 Pout<< "Read patch:" << foamPatchI
00374 << " name:" << foamPatchNames[foamPatchI]
00375 << " foamPatchTypes:" << foamPatchTypes[foamPatchI]
00376 << endl;
00377 }
00378
00379 regionI++;
00380 }
00381 }
00382
00383
00384 void ReadCells
00385 (
00386 CCMIOError &err,
00387 CCMIOID& topology,
00388 labelList& foamCellMap,
00389 labelList& foamCellType,
00390 Map<label>& prostarToFoamPatch,
00391 DynamicList<label>& foamPatchSizes,
00392 DynamicList<label>& foamPatchStarts,
00393 labelList& foamFaceMap,
00394 labelList& foamOwner,
00395 labelList& foamNeighbour,
00396 faceList& foamFaces
00397 )
00398 {
00399
00400
00401
00402
00403
00404 CCMIOID id;
00405 CCMIOGetEntity(&err, topology, kCCMIOCells, 0, &id);
00406 CCMIOSize nCells;
00407 CCMIOEntitySize(&err, id, &nCells, NULL);
00408
00409 std::vector<int> mapData(nCells);
00410 std::vector<int> cellType(nCells);
00411
00412 CCMIOID mapID;
00413 CCMIOReadCells(&err, id, &mapID, &cellType[0], 0, nCells);
00414 CCMIOReadMap(&err, mapID, &mapData[0], 0, nCells);
00415 CheckError(err, "Error reading cells");
00416
00417 foamCellMap.setSize(nCells);
00418 foamCellType.setSize(nCells);
00419 forAll(foamCellMap, i)
00420 {
00421 foamCellMap[i] = mapData[i];
00422 foamCellType[i] = cellType[i];
00423 }
00424
00425
00426
00427
00428
00429 CCMIOGetEntity(&err, topology, kCCMIOInternalFaces, 0, &id);
00430 CCMIOSize nInternalFaces;
00431 CCMIOEntitySize(&err, id, &nInternalFaces, NULL);
00432 Pout<< "nInternalFaces:" << nInternalFaces << endl;
00433
00434
00435 label foamNFaces = nInternalFaces;
00436 int index = 0;
00437 while
00438 (
00439 CCMIONextEntity(NULL, topology, kCCMIOBoundaryFaces, &index, &id)
00440 == kCCMIONoErr
00441 )
00442 {
00443 CCMIOSize size;
00444 CCMIOEntitySize(&err, id, &size, NULL);
00445
00446 Pout<< "Read kCCMIOBoundaryFaces entry with " << size
00447 << " faces." << endl;
00448
00449 foamPatchStarts.append(foamNFaces);
00450 foamPatchSizes.append(size);
00451 foamNFaces += size;
00452 }
00453 foamPatchStarts.shrink();
00454 foamPatchSizes.shrink();
00455
00456 Pout<< "patchSizes:" << foamPatchSizes << endl;
00457 Pout<< "patchStarts:" << foamPatchStarts << endl;
00458 Pout<< "nFaces:" << foamNFaces << endl;
00459
00460 mapData.resize(nInternalFaces);
00461 CCMIOGetEntity(&err, topology, kCCMIOInternalFaces, 0, &id);
00462 CCMIOSize size;
00463 CCMIOReadFaces(&err, id, kCCMIOInternalFaces, NULL, &size, NULL,
00464 kCCMIOStart, kCCMIOEnd);
00465 std::vector<int> faces(size);
00466 CCMIOReadFaces(&err, id, kCCMIOInternalFaces, &mapID, NULL, &faces[0],
00467 kCCMIOStart, kCCMIOEnd);
00468 std::vector<int> faceCells(2*nInternalFaces);
00469 CCMIOReadFaceCells(&err, id, kCCMIOInternalFaces, &faceCells[0],
00470 kCCMIOStart, kCCMIOEnd);
00471 CCMIOReadMap(&err, mapID, &mapData[0], kCCMIOStart, kCCMIOEnd);
00472 CheckError(err, "Error reading internal faces");
00473
00474
00475 foamFaceMap.setSize(foamNFaces);
00476 foamFaces.setSize(foamNFaces);
00477 foamOwner.setSize(foamNFaces);
00478 foamNeighbour.setSize(foamNFaces);
00479
00480 unsigned int pos = 0;
00481
00482 for (unsigned int faceI = 0; faceI < nInternalFaces; faceI++)
00483 {
00484 foamFaceMap[faceI] = mapData[faceI];
00485 foamOwner[faceI] = faceCells[2*faceI];
00486 foamNeighbour[faceI] = faceCells[2*faceI+1];
00487 face& f = foamFaces[faceI];
00488
00489 f.setSize(faces[pos++]);
00490 forAll(f, fp)
00491 {
00492 f[fp] = faces[pos++];
00493 }
00494 }
00495
00496
00497
00498
00499 index = 0;
00500 label regionI = 0;
00501 while
00502 (
00503 CCMIONextEntity(NULL, topology, kCCMIOBoundaryFaces, &index, &id)
00504 == kCCMIONoErr
00505 )
00506 {
00507 CCMIOSize nFaces;
00508 CCMIOEntitySize(&err, id, &nFaces, NULL);
00509
00510 mapData.resize(nFaces);
00511 faceCells.resize(nFaces);
00512 CCMIOReadFaces(&err, id, kCCMIOBoundaryFaces, NULL, &size, NULL,
00513 kCCMIOStart, kCCMIOEnd);
00514 faces.resize(size);
00515 CCMIOReadFaces(&err, id, kCCMIOBoundaryFaces, &mapID, NULL, &faces[0],
00516 kCCMIOStart, kCCMIOEnd);
00517 CCMIOReadFaceCells(&err, id, kCCMIOBoundaryFaces, &faceCells[0],
00518 kCCMIOStart, kCCMIOEnd);
00519 CCMIOReadMap(&err, mapID, &mapData[0], kCCMIOStart, kCCMIOEnd);
00520 CheckError(err, "Error reading boundary faces");
00521
00522
00523 int prostarI;
00524 if
00525 (
00526 CCMIOReadOpti(NULL, id, "ProstarRegionNumber", &prostarI)
00527 == kCCMIONoErr
00528 )
00529 {
00530 Pout<< "For region:" << regionI
00531 << " found ProstarRegionNumber:" << prostarI << endl;
00532 }
00533 else
00534 {
00535 prostarI = regionI;
00536
00537 Pout<< "For region:" << regionI
00538 << " did not find ProstarRegionNumber entry. Assuming "
00539 << prostarI << endl;
00540 }
00541 prostarToFoamPatch.insert(prostarI, regionI);
00542
00543
00544 Pout<< "region:" << regionI
00545 << " ProstarRegionNumber:" << prostarI
00546 << " foamPatchStart:"
00547 << foamPatchStarts[regionI]
00548 << " size:"
00549 << foamPatchSizes[regionI]
00550 << endl;
00551
00552
00553 unsigned int pos = 0;
00554
00555 for (unsigned int i = 0; i < nFaces; i++)
00556 {
00557 label foamFaceI = foamPatchStarts[regionI] + i;
00558
00559 foamFaceMap[foamFaceI] = mapData[i];
00560 foamOwner[foamFaceI] = faceCells[i];
00561 foamNeighbour[foamFaceI] = -1;
00562 face& f = foamFaces[foamFaceI];
00563
00564 f.setSize(faces[pos++]);
00565 forAll(f, fp)
00566 {
00567 f[fp] = faces[pos++];
00568 }
00569 }
00570 Pout<< endl;
00571
00572 regionI++;
00573 }
00574 }
00575
00576
00577
00578
00579 int main(int argc, char *argv[])
00580 {
00581 argList::noParallel();
00582 argList::validArgs.append("ccm26 file");
00583
00584 # include "setRootCase.H"
00585 # include "createTime.H"
00586
00587
00588
00589
00590
00591
00592 pointField foamPoints;
00593 labelList foamPointMap;
00594
00595
00596 labelList foamCellType;
00597 labelList foamCellMap;
00598
00599
00600 Map<label> prostarToFoamPatch;
00601 DynamicList<label> foamPatchSizes;
00602 DynamicList<label> foamPatchStarts;
00603
00604 labelList foamFaceMap;
00605 labelList foamOwner;
00606 labelList foamNeighbour;
00607 faceList foamFaces;
00608
00609
00610
00611 Map<word> foamCellTypeNames;
00612 wordList foamPatchTypes;
00613 wordList foamPatchNames;
00614
00615 {
00616 fileName ccmFile(args.additionalArgs()[0]);
00617
00618 if (!isFile(ccmFile))
00619 {
00620 FatalErrorIn(args.executable())
00621 << "Cannot read file " << ccmFile
00622 << exit(FatalError);
00623 }
00624
00625 word ccmExt = ccmFile.ext();
00626
00627 if (ccmExt != "ccm" && ccmExt != "ccmg")
00628 {
00629 FatalErrorIn(args.executable())
00630 << "Illegal extension " << ccmExt << " for file " << ccmFile
00631 << nl << "Allowed extensions are '.ccm', '.ccmg'"
00632 << exit(FatalError);
00633 }
00634
00635
00636
00637
00638 CCMIOID root;
00639 CCMIOError err = CCMIOOpenFile(NULL, ccmFile.c_str(), kCCMIORead, &root);
00640
00641
00642
00643
00644 CCMIOID state;
00645 int stateI = 0;
00646 CCMIONextEntity(&err, root, kCCMIOState, &stateI, &state);
00647 CheckError(err, "Error opening state");
00648
00649 unsigned int size;
00650 CCMIOEntityDescription(&err, state, &size, NULL);
00651 char *desc = new char[size + 1];
00652 CCMIOEntityDescription(&err, state, NULL, desc);
00653 Pout<< "Reading state '" << kDefaultState << "' (" << desc << ")"
00654 << endl;
00655 delete [] desc;
00656
00657
00658
00659 int i = 0;
00660 CCMIOID processor;
00661 CCMIONextEntity(&err, state, kCCMIOProcessor, &i, &processor);
00662 CCMIOID solution, vertices, topology;
00663 CCMIOReadProcessor
00664 (
00665 &err,
00666 processor,
00667 &vertices,
00668 &topology,
00669 NULL,
00670 &solution
00671 );
00672
00673 if (err != kCCMIONoErr)
00674 {
00675
00676 err = kCCMIONoErr;
00677 CCMIOReadProcessor
00678 (
00679 &err,
00680 processor,
00681 &vertices,
00682 &topology,
00683 NULL,
00684 NULL
00685 );
00686 if (err != kCCMIONoErr)
00687 {
00688 FatalErrorIn(args.executable())
00689 << "Could not read the file."
00690 << exit(FatalError);
00691 }
00692 }
00693
00694 ReadVertices(err, vertices, foamPointMap, foamPoints);
00695
00696 Pout<< "nPoints:" << foamPoints.size() << endl
00697 << "bounding box:" << boundBox(foamPoints) << endl
00698 << endl;
00699
00700 ReadCells
00701 (
00702 err,
00703 topology,
00704 foamCellMap,
00705 foamCellType,
00706 prostarToFoamPatch,
00707 foamPatchSizes,
00708 foamPatchStarts,
00709 foamFaceMap,
00710 foamOwner,
00711 foamNeighbour,
00712 foamFaces
00713 );
00714
00715 Pout<< "nCells:" << foamCellMap.size() << endl
00716 << "nFaces:" << foamOwner.size() << endl
00717 << "nPatches:" << foamPatchStarts.size() << endl
00718 << "nInternalFaces:" << foamPatchStarts[0] << endl
00719 << endl;
00720
00721
00722
00723 foamPatchTypes.setSize(foamPatchStarts.size());
00724 foamPatchNames.setSize(foamPatchStarts.size());
00725
00726 forAll(foamPatchNames, i)
00727 {
00728 foamPatchNames[i] = word("patch") + Foam::name(i);
00729 foamPatchTypes[i] = "patch";
00730 }
00731
00732
00733
00734 CCMIOID problem;
00735 int problemI = 0;
00736 CCMIONextEntity
00737 (
00738 &err,
00739 root,
00740 kCCMIOProblemDescription,
00741 &problemI,
00742 &problem
00743 );
00744 CheckError(err, "Error stepping to first problem description");
00745
00746 if (CCMIOIsValidEntity(problem))
00747 {
00748 ReadProblem
00749 (
00750 err,
00751 problem,
00752 prostarToFoamPatch,
00753
00754 foamCellTypeNames,
00755 foamPatchTypes,
00756 foamPatchNames
00757 );
00758 }
00759
00760
00761 CCMIOCloseFile(&err, vertices);
00762 CCMIOCloseFile(&err, topology);
00763 CCMIOCloseFile(&err, solution);
00764 CCMIOCloseFile(&err, root);
00765 }
00766
00767
00768 Pout<< "foamPatchNames:" << foamPatchNames << endl;
00769
00770
00771 Pout<< "foamOwner : min:" << min(foamOwner)
00772 << " max:" << max(foamOwner)
00773 << nl
00774 << "foamNeighbour : min:" << min(foamNeighbour)
00775 << " max:" << max(foamNeighbour)
00776 << nl
00777 << "foamCellType : min:" << min(foamCellType)
00778 << " max:" << max(foamCellType)
00779 << nl << endl;
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791 {
00792 label maxCCMPointI = max(foamPointMap);
00793 labelList toFoamPoints(invert(maxCCMPointI+1, foamPointMap));
00794
00795 forAll(foamFaces, faceI)
00796 {
00797 inplaceRenumber(toFoamPoints, foamFaces[faceI]);
00798 }
00799 }
00800
00801
00802 {
00803 label maxCCMCellI = max(foamCellMap);
00804 labelList toFoamCells(invert(maxCCMCellI+1, foamCellMap));
00805
00806 inplaceRenumber(toFoamCells, foamOwner);
00807 inplaceRenumber(toFoamCells, foamNeighbour);
00808 }
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822 forAll(foamNeighbour, faceI)
00823 {
00824 label nbr = foamNeighbour[faceI];
00825 label own = foamOwner[faceI];
00826
00827 if (nbr >= foamCellType.size() || own >= foamCellType.size())
00828 {
00829 FatalErrorIn(args.executable())
00830 << "face:" << faceI
00831 << " nbr:" << nbr
00832 << " own:" << own
00833 << " nCells:" << foamCellType.size()
00834 << exit(FatalError);
00835 }
00836
00837 if (nbr >= 0)
00838 {
00839 if (nbr < own)
00840 {
00841 foamOwner[faceI] = foamNeighbour[faceI];
00842 foamNeighbour[faceI] = own;
00843 foamFaces[faceI] = foamFaces[faceI].reverseFace();
00844 }
00845 }
00846
00847
00848
00849 const face& f = foamFaces[faceI];
00850
00851 forAll(f, fp)
00852 {
00853 if (f[fp] < 0 || f[fp] >= foamPoints.size())
00854 {
00855 FatalErrorIn(args.executable()) << "face:" << faceI
00856 << " f:" << f << abort(FatalError);
00857 }
00858 }
00859 }
00860
00861
00862
00863
00864
00865 {
00866
00867 cellList foamCells;
00868 primitiveMesh::calcCells
00869 (
00870 foamCells,
00871 foamOwner,
00872 foamNeighbour,
00873 foamCellType.size()
00874 );
00875
00876
00877 labelList oldToNew
00878 (
00879 getInternalFaceOrder
00880 (
00881 foamCells,
00882 foamOwner,
00883 foamNeighbour
00884 )
00885 );
00886
00887
00888 forAll(foamCells, cellI)
00889 {
00890 inplaceRenumber(oldToNew, foamCells[cellI]);
00891 }
00892
00893
00894 inplaceReorder(oldToNew, foamFaces);
00895 inplaceReorder(oldToNew, foamOwner);
00896 inplaceReorder(oldToNew, foamNeighbour);
00897 }
00898
00899
00900
00901
00902
00903 fvMesh mesh
00904 (
00905 IOobject
00906 (
00907 fvMesh::defaultRegion,
00908 runTime.constant(),
00909 runTime
00910 ),
00911 foamPoints,
00912 foamFaces,
00913 foamOwner,
00914 foamNeighbour
00915 );
00916
00917
00918 List<polyPatch*> newPatches(foamPatchNames.size());
00919
00920 label meshFaceI = foamPatchStarts[0];
00921
00922 forAll(newPatches, patchI)
00923 {
00924 const word& patchName = foamPatchNames[patchI];
00925 const word& patchType = foamPatchTypes[patchI];
00926
00927 Pout<< "Patch:" << patchName << " start at:" << meshFaceI
00928 << " size:" << foamPatchSizes[patchI]
00929 << " end at:" << meshFaceI+foamPatchSizes[patchI]
00930 << endl;
00931
00932 if (patchType == "wall")
00933 {
00934 newPatches[patchI] =
00935 new wallPolyPatch
00936 (
00937 patchName,
00938 foamPatchSizes[patchI],
00939 meshFaceI,
00940 patchI,
00941 mesh.boundaryMesh()
00942 );
00943 }
00944 else if (patchType == "symmetryplane")
00945 {
00946 newPatches[patchI] =
00947 new symmetryPolyPatch
00948 (
00949 patchName,
00950 foamPatchSizes[patchI],
00951 meshFaceI,
00952 patchI,
00953 mesh.boundaryMesh()
00954 );
00955 }
00956 else if (patchType == "empty")
00957 {
00958
00959 newPatches[patchI] =
00960 new emptyPolyPatch
00961 (
00962 patchName,
00963 foamPatchSizes[patchI],
00964 meshFaceI,
00965 patchI,
00966 mesh.boundaryMesh()
00967 );
00968 }
00969 else
00970 {
00971
00972
00973 newPatches[patchI] =
00974 new polyPatch
00975 (
00976 patchName,
00977 foamPatchSizes[patchI],
00978 meshFaceI,
00979 patchI,
00980 mesh.boundaryMesh()
00981 );
00982 }
00983
00984 meshFaceI += foamPatchSizes[patchI];
00985 }
00986
00987 if (meshFaceI != foamOwner.size())
00988 {
00989 FatalErrorIn(args.executable())
00990 << "meshFaceI:" << meshFaceI
00991 << " nFaces:" << foamOwner.size()
00992 << abort(FatalError);
00993 }
00994 mesh.addFvPatches(newPatches);
00995
00996
00997
00998
00999
01000
01001 label maxType = max(foamCellType);
01002 label minType = min(foamCellType);
01003
01004 if (maxType > minType)
01005 {
01006
01007 Map<label> typeToZone;
01008
01009 List<DynamicList<label> > zoneCells(0);
01010
01011 forAll(foamCellType, cellI)
01012 {
01013 storeCellInZone
01014 (
01015 cellI,
01016 foamCellType[cellI],
01017 typeToZone,
01018 zoneCells
01019 );
01020 }
01021
01022 mesh.cellZones().clear();
01023 mesh.cellZones().setSize(typeToZone.size());
01024
01025 label nValidCellZones = 0;
01026
01027 forAllConstIter(Map<label>, typeToZone, iter)
01028 {
01029 label type = iter.key();
01030 label zoneI = iter();
01031
01032 zoneCells[zoneI].shrink();
01033
01034 word zoneName = "cellZone_" + name(type);
01035
01036 Info<< "Writing zone " << type
01037 << " size " << zoneCells[zoneI].size()
01038 << " to cellZone "
01039 << zoneName << " and cellSet " << zoneName
01040 << endl;
01041
01042 cellSet cset(mesh, zoneName, zoneCells[zoneI]);
01043 cset.write();
01044
01045 mesh.cellZones().set
01046 (
01047 nValidCellZones,
01048 new cellZone
01049 (
01050 zoneName,
01051 zoneCells[zoneI],
01052 nValidCellZones,
01053 mesh.cellZones()
01054 )
01055 );
01056 nValidCellZones++;
01057 }
01058 mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
01059 }
01060
01061
01062 Info<< "Writing mesh to " << mesh.objectRegistry::objectPath()
01063 << "..." << nl << endl;
01064
01065
01066
01067 volScalarField cellIdField
01068 (
01069 IOobject
01070 (
01071 "cellId",
01072 runTime.timeName(),
01073 mesh,
01074 IOobject::NO_READ,
01075 IOobject::AUTO_WRITE
01076 ),
01077 mesh,
01078 dimensionedScalar("cellId", dimless, 0.0)
01079 );
01080
01081 forAll(foamCellMap, cellI)
01082 {
01083 cellIdField[cellI] = foamCellMap[cellI];
01084 }
01085
01086
01087 volScalarField cellTypeField
01088 (
01089 IOobject
01090 (
01091 "cellType",
01092 runTime.timeName(),
01093 mesh,
01094 IOobject::NO_READ,
01095 IOobject::AUTO_WRITE
01096 ),
01097 mesh,
01098 dimensionedScalar("cellType", dimless, 0.0)
01099 );
01100
01101 forAll(foamCellType, cellI)
01102 {
01103 cellTypeField[cellI] = foamCellType[cellI];
01104 }
01105
01106 Info<< "Writing cellIds as volScalarField to " << cellIdField.objectPath()
01107 << "..." << nl << endl;
01108 mesh.write();
01109
01110 Info<< "End\n" << endl;
01111
01112 return 0;
01113 }
01114
01115
01116