1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh 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 3 of the License, or (at your
14 option) any later version.
16 cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
28 #include "checkMeshDict.H"
29 #include "patchRefinementList.H"
32 #include "objectRefinement.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 void checkMeshDict::checkPatchCellSize() const
43 if( meshDict_.found("patchCellSize") )
45 if( meshDict_.isDict("patchCellSize") )
47 const dictionary& dict = meshDict_.subDict("patchCellSize");
49 const wordList patchNames = dict.toc();
54 patchRefinementList prl(meshDict_.lookup("patchCellSize"));
60 void checkMeshDict::checkSubsetCellSize() const
62 if( meshDict_.found("subsetCellSize") )
64 if( meshDict_.isDict("subsetCellSize") )
66 const dictionary& dict = meshDict_.subDict("subsetCellSize");
68 const wordList subsetNames = dict.toc();
73 patchRefinementList prl(meshDict_.lookup("patchCellSize"));
78 void checkMeshDict::checkLocalRefinementLevel() const
80 if( meshDict_.found("localRefinement") )
82 if( meshDict_.isDict("localRefinement") )
84 const dictionary& refDict = meshDict_.subDict("localRefinement");
85 const wordList entries = refDict.toc();
87 forAll(entries, dictI)
89 const dictionary& dict = refDict.subDict(entries[dictI]);
91 if( dict.found("cellSize") )
93 const scalar cs = readScalar(dict.lookup("cellSize"));
100 "void checkMeshDict::checkLocalRefinementLevel() const"
101 ) << "Cell size for " << entries[dictI]
102 << " is negative" << endl;
104 else if( dict.found("additionalRefinementLevels") )
106 const label nLevels =
107 readLabel(dict.lookup("additionalRefinementLevels"));
114 "void checkMeshDict::checkLocalRefinementLevel() const"
115 ) << "Refinement level for " << entries[dictI]
116 << " is negative" << endl;
122 "void checkMeshDict::checkLocalRefinementLevel() const"
123 ) << "Cannot read keyword"
124 << " additionalRefinementLevels or cellSize"
125 << "for " << entries[dictI] << exit(FatalError);
133 "void checkMeshDict::checkLocalRefinementLevel() const"
134 ) << "Cannot read localRefinement" << exit(FatalError);
139 void checkMeshDict::checkKeepCellsIntersectingPatches() const
141 if( meshDict_.found("keepCellsIntersectingPatches") )
143 if( meshDict_.isDict("keepCellsIntersectingPatches") )
145 const dictionary& dict =
146 meshDict_.subDict("keepCellsIntersectingPatches");
148 const wordList patchNames = dict.toc();
153 wordList kcip(meshDict_.lookup("keepCellsIntersectingPatches"));
158 void checkMeshDict::checkRemoveCellsIntersectingPatches() const
160 if( meshDict_.found("removeCellsIntersectingPatches") )
162 if( meshDict_.isDict("removeCellsIntersectingPatches") )
164 const dictionary& dict =
165 meshDict_.subDict("removeCellsIntersectingPatches");
167 const wordList patchNames = dict.toc();
172 wordList kcip(meshDict_.lookup("removeCellsIntersectingPatches"));
177 void checkMeshDict::checkObjectRefinements() const
179 if( meshDict_.found("objectRefinements") )
181 PtrList<objectRefinement> refObjects;
183 if( meshDict_.isDict("objectRefinements") )
185 const dictionary& dict = meshDict_.subDict("objectRefinements");
186 const wordList objectNames = dict.toc();
188 refObjects.setSize(objectNames.size());
190 forAll(refObjects, objectI)
192 const entry& objectEntry =
193 dict.lookupEntry(objectNames[objectI], false, false);
198 objectRefinement::New
200 objectEntry.keyword(),
208 Istream& is = meshDict_.lookup("objectRefinements");
210 PtrList<entry> objectEntries(is);
211 refObjects.setSize(objectEntries.size());
213 forAll(refObjects, objectI)
218 objectRefinement::New
220 objectEntries[objectI].keyword(),
221 objectEntries[objectI].dict()
229 void checkMeshDict::checkBoundaryLayers() const
231 if( meshDict_.found("boundaryLayers") )
233 const dictionary& bndLayers = meshDict_.subDict("boundaryLayers");
235 //- read global properties
236 if( bndLayers.found("nLayers") )
238 readLabel(bndLayers.lookup("nLayers"));
240 if( bndLayers.found("thicknessRatio") )
242 readScalar(bndLayers.lookup("thicknessRatio"));
244 if( bndLayers.found("maxFirstLayerThickness") )
246 readScalar(bndLayers.lookup("maxFirstLayerThickness"));
249 //- patch-based properties
250 if( bndLayers.isDict("patchBoundaryLayers") )
252 const dictionary& patchBndLayers =
253 bndLayers.subDict("patchBoundaryLayers");
254 const wordList patchNames = patchBndLayers.toc();
256 forAll(patchNames, patchI)
258 const word pName = patchNames[patchI];
260 if( patchBndLayers.isDict(pName) )
262 const dictionary& patchDict =
263 patchBndLayers.subDict(pName);
265 if( patchDict.found("nLayers") )
267 readLabel(patchDict.lookup("nLayers"));
269 if( patchDict.found("thicknessRatio") )
271 readScalar(patchDict.lookup("thicknessRatio"));
273 if( patchDict.found("maxFirstLayerThickness") )
275 readScalar(patchDict.lookup("maxFirstLayerThickness"));
277 if( patchDict.found("allowDiscontinuity") )
279 readBool(patchDict.lookup("allowDiscontinuity"));
284 Warning << "Cannot refine layer for patch "
285 << patchNames[patchI] << endl;
292 void checkMeshDict::checkRenameBoundary() const
294 if( meshDict_.found("renameBoundary") )
296 const dictionary& dict = meshDict_.subDict("renameBoundary");
297 if( dict.found("newPatchNames") )
299 if( dict.isDict("newPatchNames") )
301 const dictionary& patchDicts = dict.subDict("newPatchNames");
303 const wordList patchNames = patchDicts.toc();
305 forAll(patchNames, patchI)
307 const word& pName = patchNames[patchI];
309 if( !patchDicts.isDict(pName) )
312 "void checkMeshDict::checkRenameBoundary() const"
313 ) << "Entry " << pName
314 << " is not a dictionary" << exit(FatalError);
316 const dictionary dict = patchDicts.subDict(pName);
318 if( !dict.found("newName") )
321 "void checkMeshDict::checkRenameBoundary() const"
322 ) << "Dictionary " << pName
323 << " does not contain a newName keyword"
329 const PtrList<entry> patchesToRename
331 dict.lookup("newPatchNames")
334 forAll(patchesToRename, patchI)
336 const word& pName = patchesToRename[patchI].keyword();
338 const dictionary dict = patchesToRename[patchI].dict();
340 if( !dict.found("newName") )
343 "void checkMeshDict::checkRenameBoundary() const"
344 ) << "Dictionary " << pName
345 << " does not contain a newName keyword"
353 void checkMeshDict::checkEntries() const
355 checkPatchCellSize();
357 checkSubsetCellSize();
359 checkKeepCellsIntersectingPatches();
361 checkRemoveCellsIntersectingPatches();
363 checkObjectRefinements();
365 checkBoundaryLayers();
367 checkRenameBoundary();
370 void checkMeshDict::updatePatchCellSize
372 const std::map<word, wordList>& patchesFromPatch
375 if( meshDict_.found("patchCellSize") )
377 LongList<patchRefinement> updatedPatchRefinement;
379 if( meshDict_.isDict("patchCellSize") )
381 const dictionary dict = meshDict_.subDict("patchCellSize");
383 const wordList patchNames = dict.toc();
385 forAll(patchNames, patchI)
387 const word& pName = patchNames[patchI];
389 std::map<word, wordList>::const_iterator it =
390 patchesFromPatch.find(pName);
391 if( it == patchesFromPatch.end() )
394 const wordList& updatedPatchNames = it->second;
396 const dictionary& pDict = dict.subDict(pName);
397 const scalar cellSize = readScalar(pDict.lookup("cellSize"));
399 forAll(updatedPatchNames, nameI)
400 updatedPatchRefinement.append
404 updatedPatchNames[nameI],
412 patchRefinementList prl(meshDict_.lookup("patchCellSize"));
415 const word& pName = prl[prlI].patchName();
416 const scalar cellSize = prl[prlI].cellSize();
418 std::map<word, wordList>::const_iterator it =
419 patchesFromPatch.find(pName);
421 if( it == patchesFromPatch.end() )
424 const wordList& updatedPatchNames = it->second;
425 forAll(updatedPatchNames, nameI)
426 updatedPatchRefinement.append
430 updatedPatchNames[nameI],
437 meshDict_.add("patchCellSize", updatedPatchRefinement, true);
441 void checkMeshDict::updateSubsetCellSize
443 const std::map<word, wordList>& patchesFromPatch
449 void checkMeshDict::updateLocalRefinementLevel
451 const std::map<word, wordList>& patchesFromPatch
454 if( meshDict_.found("localRefinement") )
456 if( meshDict_.isDict("localRefinement") )
458 dictionary& dict = meshDict_.subDict("localRefinement");
460 const wordList entries = dict.toc();
462 forAll(entries, dictI)
464 const word& pName = entries[dictI];
466 std::map<word, wordList>::const_iterator it =
467 patchesFromPatch.find(pName);
468 if( it == patchesFromPatch.end() )
471 const wordList& updatedPatchNames = it->second;
473 const dictionary& pDict = dict.subDict(pName);
475 if( pDict.found("additionalRefinementLevels") )
477 const label nLevels =
478 readLabel(pDict.lookup("additionalRefinementLevels"));
480 copy.add("additionalRefinementLevels", nLevels);
482 else if( pDict.found("cellSize") )
484 const scalar cs = readScalar(pDict.lookup("cellSize"));
486 copy.add("cellSize", cs);
490 forAll(updatedPatchNames, nameI)
491 dict.add(updatedPatchNames[nameI], copy);
493 //- remove the current patch
500 void checkMeshDict::updateKeepCellsIntersectingPatches
502 const std::map<word, wordList>& patchesFromPatch
505 if( meshDict_.found("keepCellsIntersectingPatches") )
507 LongList<word> updatedPatchNames;
508 if( meshDict_.isDict("keepCellsIntersectingPatches") )
510 const dictionary& dict =
511 meshDict_.subDict("keepCellsIntersectingPatches");
513 const wordList patchNames = dict.toc();
514 forAll(patchNames, patchI)
516 const word& pName = patchNames[patchI];
518 std::map<word, wordList>::const_iterator it =
519 patchesFromPatch.find(pName);
521 if( it == patchesFromPatch.end() )
522 updatedPatchNames.append(pName);
524 const wordList& newPatchNames = it->second;
526 forAll(newPatchNames, nameI)
527 updatedPatchNames.append(newPatchNames[nameI]);
532 wordList kcip(meshDict_.lookup("keepCellsIntersectingPatches"));
536 const word& pName = kcip[i];
538 std::map<word, wordList>::const_iterator it =
539 patchesFromPatch.find(pName);
541 if( it == patchesFromPatch.end() )
542 updatedPatchNames.append(pName);
544 const wordList& newPatchNames = it->second;
546 forAll(newPatchNames, nameI)
547 updatedPatchNames.append(newPatchNames[nameI]);
551 meshDict_.add("keepCellsIntersectingPatches", updatedPatchNames, true);
556 void checkMeshDict::updateRemoveCellsIntersectingPatches
558 const std::map<word, wordList>& patchesFromPatch
561 if( meshDict_.found("removeCellsIntersectingPatches") )
563 LongList<word> updatedPatchNames;
564 if( meshDict_.isDict("removeCellsIntersectingPatches") )
566 const dictionary& dict =
567 meshDict_.subDict("removeCellsIntersectingPatches");
569 const wordList patchNames = dict.toc();
570 forAll(patchNames, patchI)
572 const word& pName = patchNames[patchI];
574 std::map<word, wordList>::const_iterator it =
575 patchesFromPatch.find(pName);
577 if( it == patchesFromPatch.end() )
578 updatedPatchNames.append(pName);
580 const wordList& newPatchNames = it->second;
582 forAll(newPatchNames, nameI)
583 updatedPatchNames.append(newPatchNames[nameI]);
588 wordList kcip(meshDict_.lookup("removeCellsIntersectingPatches"));
592 const word& pName = kcip[i];
594 std::map<word, wordList>::const_iterator it =
595 patchesFromPatch.find(pName);
597 if( it == patchesFromPatch.end() )
598 updatedPatchNames.append(pName);
600 const wordList& newPatchNames = it->second;
602 forAll(newPatchNames, nameI)
603 updatedPatchNames.append(newPatchNames[nameI]);
609 "removeCellsIntersectingPatches",
616 void checkMeshDict::updateObjectRefinements
618 const std::map<word, wordList>& patchesFromPatch
624 void checkMeshDict::updateBoundaryLayers
626 const std::map<word, wordList>& patchesFromPatch
629 if( meshDict_.isDict("boundaryLayers") )
631 dictionary& bndLayersDict = meshDict_.subDict("boundaryLayers");
632 if( bndLayersDict.isDict("patchBoundaryLayers") )
634 dictionary& patchBndLayers =
635 bndLayersDict.subDict("patchBoundaryLayers");
637 const wordList patchLayers = patchBndLayers.toc();
639 forAll(patchLayers, patchI)
641 const word& pName = patchLayers[patchI];
643 dictionary dict = patchBndLayers.subDict(pName);
645 const std::map<word, wordList>::const_iterator it =
646 patchesFromPatch.find(pName);
647 const wordList& newNames = it->second;
651 patchBndLayers.add(newNames[i], dict);
654 patchBndLayers.remove(pName);
660 void checkMeshDict::updateRenameBoundary
662 const std::map<word, wordList>& patchesFromPatch,
663 const std::map<word, word>& patchTypes
668 newDict.add("newPatchNames", dictionary());
670 if( meshDict_.found("renameBoundary") )
672 const dictionary& dict = meshDict_.subDict("renameBoundary");
674 //- transfer or generate the default name entry
675 if( dict.found("defaultName") )
677 const word name(dict.lookup("defaultName"));
678 newDict.add("defaultName", name);
682 newDict.add("defaultName", "walls");
685 //- transfer or generate the defaultType entry
686 if( dict.found("defaultType") )
688 const word type(dict.lookup("defaultType"));
689 newDict.add("defaultType", type);
693 newDict.add("defaultType", "wall");
696 if( dict.found("newPatchNames") )
698 //- stores the updated dictionary
699 dictionary& newPatchesDict = newDict.subDict("newPatchNames");
701 if( dict.isDict("newPatchNames") )
703 //- current state of the dictionary
704 const dictionary& patchDicts = dict.subDict("newPatchNames");
706 std::map<word, wordList>::const_iterator it;
707 for(it=patchesFromPatch.begin();it!=patchesFromPatch.end();++it)
709 const word& pName = it->first;
710 const wordList& newNames = it->second;
712 if( patchDicts.found(pName) )
714 //- patch renaming is already requested by the user
715 //- use the new name for all newly created patches
716 const dictionary& patchDict = patchDicts.subDict(pName);
717 if( !patchDict.found("newName") )
719 if( !patchDict.found("type") )
722 const word newName(patchDict.lookup("newName"));
723 const word newType(patchDict.lookup("type"));
727 dictionary newPatchDict;
728 newPatchDict.add("newName", newName);
729 newPatchDict.add("type", newType);
731 newPatchesDict.add(newNames[i], newPatchDict);
736 //- rename all newly create patches
737 //- with the original name
740 dictionary newPatchDict;
742 newPatchDict.add("newName", it->first);
743 std::map<word, word>::const_iterator tIter =
744 patchTypes.find(it->first);
745 newPatchDict.add("type", tIter->second);
747 newPatchesDict.add(newNames[i], newPatchDict);
754 const PtrList<entry> patchEntries(dict.lookup("newPatchNames"));
756 forAll(patchEntries, entryI)
758 const word& pName = patchEntries[entryI].keyword();
759 dictionary patchDict(patchEntries[entryI].dict());
761 std::map<word, wordList>::const_iterator it =
762 patchesFromPatch.find(pName);
764 if( it == patchesFromPatch.end() )
767 const wordList& newNames = it->second;
770 newPatchesDict.add(newNames[i], patchDict, true);
773 std::map<word, wordList>::const_iterator it;
774 for(it=patchesFromPatch.begin();it!=patchesFromPatch.end();++it)
776 const word& pName = it->first;
777 const wordList& newNames = it->second;
779 if( newPatchesDict.found(pName) )
782 //- rename all newly created patches
783 //- with the original name
786 dictionary newPatchDict;
788 newPatchDict.add("newName", it->first);
789 std::map<word, word>::const_iterator tIter =
790 patchTypes.find(it->first);
791 newPatchDict.add("type", tIter->second);
793 newPatchesDict.add(newNames[i], newPatchDict);
800 //- newPatchNames is not used
801 dictionary& newPatchesDict = newDict.subDict("newPatchNames");
803 std::map<word, wordList>::const_iterator it;
804 for(it=patchesFromPatch.begin();it!=patchesFromPatch.end();++it)
806 const wordList& newPatchNames = it->second;
808 forAll(newPatchNames, i)
810 const word& pName = newPatchNames[i];
811 dictionary newPatchDict;
812 newPatchDict.add("newName", it->first);
813 std::map<word, word>::const_iterator tIter =
814 patchTypes.find(it->first);
815 newPatchDict.add("type", tIter->second);
817 newPatchesDict.add(pName, newPatchDict);
822 //- delete all previus entries from the dictionary
823 meshDict_.subDict("renameBoundary").clear();
827 //- create the dictionary if it has not existed before
828 newDict.add("defaultName", "walls");
829 newDict.add("defaultType", "wall");
831 dictionary& newPatchesDict = newDict.subDict("newPatchNames");
833 std::map<word, wordList>::const_iterator it;
834 for(it=patchesFromPatch.begin();it!=patchesFromPatch.end();++it)
836 const wordList& newPatchNames = it->second;
838 forAll(newPatchNames, i)
840 const word& pName = newPatchNames[i];
841 dictionary newPatchDict;
842 newPatchDict.add("newName", it->first);
843 std::map<word, word>::const_iterator tIter =
844 patchTypes.find(it->first);
845 newPatchDict.add("type", tIter->second);
847 newPatchesDict.add(pName, newPatchDict);
852 meshDict_.add("renameBoundary", newDict, true);
855 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
857 checkMeshDict::checkMeshDict
859 IOdictionary& meshDict
867 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
869 checkMeshDict::~checkMeshDict()
872 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
874 void checkMeshDict::updateDictionaries
876 const std::map<word, wordList>& patchesFromPatch,
877 const std::map<word, word>& patchTypes,
878 const bool renamePatches
881 updatePatchCellSize(patchesFromPatch);
883 updateSubsetCellSize(patchesFromPatch);
885 updateLocalRefinementLevel(patchesFromPatch);
887 updateKeepCellsIntersectingPatches(patchesFromPatch);
889 updateRemoveCellsIntersectingPatches(patchesFromPatch);
891 updateObjectRefinements(patchesFromPatch);
893 updateBoundaryLayers(patchesFromPatch);
896 updateRenameBoundary(patchesFromPatch, patchTypes);
899 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
901 } // End namespace Foam
903 // ************************************************************************* //