Forward compatibility: flex
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / checkMeshDict / checkMeshDict.C
blob8d154e10bfcfe3eaac0e31c1b07257ed2d00c97c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | cfMesh: A library for mesh generation
4    \\    /   O peration     |
5     \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6      \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "checkMeshDict.H"
29 #include "patchRefinementList.H"
30 #include "PtrList.H"
31 #include "LongList.H"
32 #include "objectRefinement.H"
33 #include "coordinateModification.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace Foam
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 void checkMeshDict::checkBasicSettings() const
44     //- check if maxCellSize is valid
45     const scalar maxCellSize = readScalar(meshDict_.lookup("maxCellSize"));
47     if( maxCellSize < 0 )
48         FatalErrorIn
49         (
50             "void checkMeshDict::checkBasicSettings() const"
51         ) << "maxCellSize is negative! Cannot generate the mesh!!"
52           << exit(FatalError);
54     //- check if boundaryCellSize makes sense
55     if( meshDict_.found("boundaryCellSize") )
56     {
57         const scalar bcs = readScalar(meshDict_.lookup("boundaryCellSize"));
59         if( bcs < 0 )
60         {
61             WarningIn
62             (
63                 "void checkMeshDict::checkBasicSettings() const"
64             ) << "Boundary cell size is negative!!" << endl;
65         }
67         if( meshDict_.found("boundaryCellSizeRefinementThickness") )
68         {
69             const scalar thickness =
70                 readScalar
71                 (
72                     meshDict_.lookup("boundaryCellSizeRefinementThickness")
73                 );
75             if( thickness < 0 )
76             {
77                 WarningIn
78                 (
79                     "void checkMeshDict::checkBasicSettings() const"
80                 ) << "Boundary cell size refinement thickness is negative!!"
81                   << endl;
82             }
83         }
84     }
86     //- check if minCellSize is valid
87     if( meshDict_.found("minCellSize") )
88     {
89         const scalar mcs = readScalar(meshDict_.lookup("minCellSize"));
91         if( mcs < 0 )
92         {
93             FatalErrorIn
94             (
95                 "void checkMeshDict::checkBasicSettings() const"
96             ) << "Minimum cell size for automatic refinement is negative!!"
97               << exit(FatalError);
98         }
100     }
102     //- check if keepCellsIntersectingBoundary can be read correctly
103     if( meshDict_.found("keepCellsIntersectingBoundary") )
104     {
105         const bool keep =
106             readBool(meshDict_.lookup("keepCellsIntersectingBoundary"));
108         if( keep && meshDict_.found("checkForGluedMesh") )
109         {
110             readBool(meshDict_.lookup("checkForGluedMesh"));
111         }
112     }
114     //- check if enforceConstraints is available
115     if( meshDict_.found("enforceGeometryConstraints") )
116     {
117         readBool(meshDict_.lookup("enforceGeometryConstraints"));
118     }
121 void checkMeshDict::checkPatchCellSize() const
123     if( meshDict_.found("patchCellSize") )
124     {
125         if( meshDict_.isDict("patchCellSize") )
126         {
127             const dictionary& dict = meshDict_.subDict("patchCellSize");
129             const wordList patchNames = dict.toc();
130             patchNames.size();
131         }
132         else
133         {
134             patchRefinementList prl(meshDict_.lookup("patchCellSize"));
135             prl.size();
136         }
137     }
140 void checkMeshDict::checkSubsetCellSize() const
142     if( meshDict_.found("subsetCellSize") )
143     {
144         if( meshDict_.isDict("subsetCellSize") )
145         {
146             const dictionary& dict = meshDict_.subDict("subsetCellSize");
148             const wordList subsetNames = dict.toc();
149             subsetNames.size();
150         }
151         else
152         {
153             patchRefinementList prl(meshDict_.lookup("patchCellSize"));
154         }
155     }
158 void checkMeshDict::checkLocalRefinementLevel() const
160     if( meshDict_.found("localRefinement") )
161     {
162         if( meshDict_.isDict("localRefinement") )
163         {
164             const dictionary& refDict = meshDict_.subDict("localRefinement");
165             const wordList entries = refDict.toc();
167             forAll(entries, dictI)
168             {
169                 const dictionary& dict = refDict.subDict(entries[dictI]);
171                 if( dict.found("cellSize") )
172                 {
173                     const scalar cs = readScalar(dict.lookup("cellSize"));
175                     if( cs < 0.0 )
176                     {
177                         WarningIn
178                         (
179                         "void checkMeshDict::checkLocalRefinementLevel() const"
180                         ) << "Cell size for " << entries[dictI]
181                              << " is negative" << endl;
182                     }
183                 }
184                 else if( dict.found("additionalRefinementLevels") )
185                 {
186                     const label nLevels =
187                         readLabel(dict.lookup("additionalRefinementLevels"));
189                     if( nLevels < 0 )
190                     {
191                         WarningIn
192                         (
193                         "void checkMeshDict::checkLocalRefinementLevel() const"
194                         ) << "Refinement level for " << entries[dictI]
195                              << " is negative" << endl;
196                     }
197                 }
198                 else
199                 {
200                     FatalErrorIn
201                     (
202                         "void checkMeshDict::checkLocalRefinementLevel() const"
203                     ) << "Cannot read keyword"
204                       << " additionalRefinementLevels or cellSize"
205                       << "for " << entries[dictI] << exit(FatalError);
206                 }
208                 if( dict.found("refinementThickness") )
209                 {
210                     const scalar s =
211                         readScalar(dict.lookup("refinementThickness"));
213                     if( s < 0 )
214                     {
215                         WarningIn
216                         (
217                         "void checkMeshDict::checkLocalRefinementLevel() const"
218                         ) << "Refinement thickness for " << entries[dictI]
219                              << " is negative" << endl;
220                     }
221                 }
222             }
223         }
224         else
225         {
226             FatalErrorIn
227             (
228                 "void checkMeshDict::checkLocalRefinementLevel() const"
229             ) << "Cannot read localRefinement" << exit(FatalError);
230         }
231     }
234 void checkMeshDict::checkKeepCellsIntersectingPatches() const
236     if( meshDict_.found("keepCellsIntersectingPatches") )
237     {
238         if( meshDict_.isDict("keepCellsIntersectingPatches") )
239         {
240             const dictionary& dict =
241                 meshDict_.subDict("keepCellsIntersectingPatches");
243             const wordList patchNames = dict.toc();
244             patchNames.size();
245         }
246         else
247         {
248             wordList kcip(meshDict_.lookup("keepCellsIntersectingPatches"));
249         }
250     }
253 void checkMeshDict::checkRemoveCellsIntersectingPatches() const
255     if( meshDict_.found("removeCellsIntersectingPatches") )
256     {
257         if( meshDict_.isDict("removeCellsIntersectingPatches") )
258         {
259             const dictionary& dict =
260                 meshDict_.subDict("removeCellsIntersectingPatches");
262             const wordList patchNames = dict.toc();
263             patchNames.size();
264         }
265         else
266         {
267             wordList kcip(meshDict_.lookup("removeCellsIntersectingPatches"));
268         }
269     }
272 void checkMeshDict::checkObjectRefinements() const
274     if( meshDict_.found("objectRefinements") )
275     {
276         PtrList<objectRefinement> refObjects;
278         if( meshDict_.isDict("objectRefinements") )
279         {
280             const dictionary& dict = meshDict_.subDict("objectRefinements");
281             const wordList objectNames = dict.toc();
283             refObjects.setSize(objectNames.size());
285             forAll(refObjects, objectI)
286             {
287                 const entry& objectEntry =
288                     dict.lookupEntry(objectNames[objectI], false, false);
290                 refObjects.set
291                 (
292                     objectI,
293                     objectRefinement::New
294                     (
295                         objectEntry.keyword(),
296                         objectEntry.dict()
297                     )
298                 );
299             }
300         }
301         else
302         {
303             Istream& is = meshDict_.lookup("objectRefinements");
305             PtrList<entry> objectEntries(is);
306             refObjects.setSize(objectEntries.size());
308             forAll(refObjects, objectI)
309             {
310                 refObjects.set
311                 (
312                     objectI,
313                     objectRefinement::New
314                     (
315                         objectEntries[objectI].keyword(),
316                         objectEntries[objectI].dict()
317                     )
318                 );
319             }
320         }
322         forAll(refObjects, oI)
323         {
324             if( refObjects[oI].refinementThickness() < 0.0 )
325             {
326                 WarningIn
327                 (
328                     "void checkMeshDict::checkObjectRefinements() const"
329                 ) << "Refinement thickness specified for object "
330                   << refObjects[oI].name() << " is negative!!" << endl;
331             }
332         }
333     }
336 void checkMeshDict::checkAnisotropicSources() const
338     if( meshDict_.found("anisotropicSources") )
339     {
340         PtrList<coordinateModification> anisotropicObjects;
342         if( meshDict_.isDict("anisotropicSources") )
343         {
344             const dictionary& dict = meshDict_.subDict("anisotropicSources");
345             const wordList objectNames = dict.toc();
347             anisotropicObjects.setSize(objectNames.size());
349             forAll(anisotropicObjects, objectI)
350             {
351                 const entry& objectEntry =
352                     dict.lookupEntry(objectNames[objectI], false, false);
354                 anisotropicObjects.set
355                 (
356                     objectI,
357                     coordinateModification::New
358                     (
359                         objectEntry.keyword(),
360                         objectEntry.dict()
361                     )
362                 );
363             }
364         }
365     }
368 void checkMeshDict::checkSurfaceRefinements() const
370     if( meshDict_.found("surfaceMeshRefinement") )
371     {
372         const dictionary& surfaces = meshDict_.subDict("surfaceMeshRefinement");
374         const wordList surfaceSources = surfaces.toc();
376         forAll(surfaceSources, surfI)
377         {
378             if( surfaces.isDict(surfaceSources[surfI]) )
379             {
380                 const dictionary& dict =
381                     surfaces.subDict(surfaceSources[surfI]);
383                 if( dict.found("surfaceFile") )
384                 {
385                     const fileName fName(dict.lookup("surfaceFile"));
387                     if( !isFile(fName) )
388                         FatalErrorIn
389                         (
390                         "void checkMeshDict::checkSurfaceRefinements() const"
391                         ) << "Surface file " << fName
392                           << " does not exist or is not readable!!"
393                           << exit(FatalError);
394                 }
395                 else
396                 {
397                     FatalErrorIn
398                     (
399                         "void checkMeshDict::checkSurfaceRefinements() const"
400                     ) << "Missing surfaceFile for entry "
401                       << surfaceSources[surfI] << exit(FatalError);
402                 }
404                 if( dict.found("cellSize") )
405                 {
406                     const scalar cs = readScalar(dict.lookup("cellSize"));
408                     if( cs < VSMALL )
409                         FatalErrorIn
410                         (
411                             "void checkMeshDict::"
412                             "checkSurfaceRefinements() const"
413                         ) << "Cell size for entry " << surfaceSources[surfI]
414                           << " is extremely small or negative!!"
415                           << exit(FatalError);
416                 }
417                 else if( dict.found("additionalRefinementLevels") )
418                 {
419                     const label nLev =
420                         readLabel(dict.lookup("additionalRefinementLevels"));
422                     if( nLev < 0 )
423                     {
424                         FatalErrorIn
425                         (
426                             "void checkMeshDict::"
427                             "checkSurfaceRefinements() const"
428                         ) << "Number refinement levels for entry "
429                           << surfaceSources[surfI] << " is negative!!"
430                           << exit(FatalError);
431                     }
432                 }
433                 else
434                 {
435                     FatalErrorIn
436                     (
437                         "void checkMeshDict::checkSurfaceRefinements() const"
438                     ) << "Missing cellSize or additionalRefinementLevels"
439                       << " for entry " << surfaceSources[surfI]
440                       << exit(FatalError);
441                 }
443                 if( dict.found("refinementThickness") )
444                 {
445                     const scalar cs =
446                         readScalar(dict.lookup("refinementThickness"));
448                     if( cs < VSMALL )
449                         WarningIn
450                         (
451                             "void checkMeshDict::"
452                             "checkSurfaceRefinements() const"
453                         ) << "Refinement thickness for entry "
454                           << surfaceSources[surfI]
455                           << " is extremely small or negative!!" << endl;
456                 }
457             }
458             else
459             {
460                 FatalErrorIn
461                 (
462                     "void checkMeshDict::checkSurfaceRefinements() const"
463                 ) << "Dictionary " << surfaceSources[surfI]
464                   << " does not exist!!"
465                   << exit(FatalError);
466             }
467         }
468     }
471 void checkMeshDict::checkEdgeMeshRefinements() const
473     if( meshDict_.found("edgeMeshRefinement") )
474     {
475         const dictionary& edgeMeshes = meshDict_.subDict("edgeMeshRefinement");
477         const wordList edgeMeshSources = edgeMeshes.toc();
479         forAll(edgeMeshSources, emI)
480         {
481             if( edgeMeshes.isDict(edgeMeshSources[emI]) )
482             {
483                 const dictionary& dict =
484                     edgeMeshes.subDict(edgeMeshSources[emI]);
486                 if( dict.found("edgeFile") )
487                 {
488                     const fileName fName(dict.lookup("edgeFile"));
490                     if( !isFile(fName) )
491                         FatalErrorIn
492                         (
493                         "void checkMeshDict::checkEdgeMeshRefinements() const"
494                         ) << "Edge mesh file " << fName
495                           << " does not exist or is not readable!!"
496                           << exit(FatalError);
497                 }
498                 else
499                 {
500                     FatalErrorIn
501                     (
502                         "void checkMeshDict::checkEdgeMeshRefinements() const"
503                     ) << "Missing edgeFilw for entry "
504                       << edgeMeshSources[emI] << exit(FatalError);
505                 }
507                 if( dict.found("cellSize") )
508                 {
509                     const scalar cs = readScalar(dict.lookup("cellSize"));
511                     if( cs < VSMALL )
512                         FatalErrorIn
513                         (
514                             "void checkMeshDict::"
515                             "checkEdgeMeshRefinements() const"
516                         ) << "Cell size for entry " << edgeMeshSources[emI]
517                           << " is extremely small or negative!!"
518                           << exit(FatalError);
519                 }
520                 else if( dict.found("additionalRefinementLevels") )
521                 {
522                     const label nLev =
523                         readLabel(dict.lookup("additionalRefinementLevels"));
525                     if( nLev < 0 )
526                     {
527                         FatalErrorIn
528                         (
529                             "void checkMeshDict::"
530                             "checkEdgeMeshRefinements() const"
531                         ) << "Number refinement levels for entry "
532                           << edgeMeshSources[emI] << " is negative!!"
533                           << exit(FatalError);
534                     }
535                 }
536                 else
537                 {
538                     FatalErrorIn
539                     (
540                         "void checkMeshDict::checkEdgeMeshRefinements() const"
541                     ) << "Missing cellSize or additionalRefinementLevels"
542                       << " for entry " << edgeMeshSources[emI]
543                       << exit(FatalError);
544                 }
546                 if( dict.found("refinementThickness") )
547                 {
548                     const scalar cs =
549                         readScalar(dict.lookup("refinementThickness"));
551                     if( cs < VSMALL )
552                         WarningIn
553                         (
554                             "void checkMeshDict::"
555                             "checkEdgeMeshRefinements() const"
556                         ) << "Refinement thickness for entry "
557                           << edgeMeshSources[emI]
558                           << " is extremely small or negative!!" << endl;
559                 }
560             }
561             else
562             {
563                 FatalErrorIn
564                 (
565                     "void checkMeshDict::checkEdgeMeshRefinements() const"
566                 ) << "Dictionary " << edgeMeshSources[emI]
567                   << " does not exist!!"
568                   << exit(FatalError);
569             }
570         }
571     }
574 void checkMeshDict::checkBoundaryLayers() const
576     if( meshDict_.found("boundaryLayers") )
577     {
578         const dictionary& bndLayers = meshDict_.subDict("boundaryLayers");
580         //- read global properties
581         if( bndLayers.found("nLayers") )
582         {
583             readLabel(bndLayers.lookup("nLayers"));
584         }
585         if( bndLayers.found("thicknessRatio") )
586         {
587             readScalar(bndLayers.lookup("thicknessRatio"));
588         }
589         if( bndLayers.found("maxFirstLayerThickness") )
590         {
591             readScalar(bndLayers.lookup("maxFirstLayerThickness"));
592         }
594         //- patch-based properties
595         if( bndLayers.isDict("patchBoundaryLayers") )
596         {
597             const dictionary& patchBndLayers =
598                 bndLayers.subDict("patchBoundaryLayers");
599             const wordList patchNames = patchBndLayers.toc();
601             forAll(patchNames, patchI)
602             {
603                 const word pName = patchNames[patchI];
605                 if( patchBndLayers.isDict(pName) )
606                 {
607                     const dictionary& patchDict =
608                         patchBndLayers.subDict(pName);
610                     if( patchDict.found("nLayers") )
611                     {
612                         readLabel(patchDict.lookup("nLayers"));
613                     }
614                     if( patchDict.found("thicknessRatio") )
615                     {
616                         readScalar(patchDict.lookup("thicknessRatio"));
617                     }
618                     if( patchDict.found("maxFirstLayerThickness") )
619                     {
620                         readScalar(patchDict.lookup("maxFirstLayerThickness"));
621                     }
622                     if( patchDict.found("allowDiscontinuity") )
623                     {
624                         readBool(patchDict.lookup("allowDiscontinuity"));
625                     }
626                 }
627                 else
628                 {
629                     Warning << "Cannot refine layer for patch "
630                         << patchNames[patchI] << endl;
631                 }
632             }
633         }
635         //- check for existence of boundary layer smoothing
636         if( bndLayers.found("optimiseLayer") )
637         {
638             readBool(bndLayers.lookup("optimiseLayer"));
639         }
641         if( bndLayers.found("optimisationParameters") )
642         {
643             const dictionary& optParams =
644                 bndLayers.subDict("optimisationParameters");
646             if( optParams.found("reCalculateNormals") )
647             {
648                 readBool(optParams.lookup("reCalculateNormals"));
649             }
651             if( optParams.found("nSmoothNormals") )
652             {
653                 const label nSmoothNormals =
654                     readLabel(optParams.lookup("nSmoothNormals"));
656                 if( nSmoothNormals < 0 )
657                     FatalErrorIn
658                     (
659                         "void checkMeshDict::checkBoundaryLayers() const"
660                     ) << "nSmoothNormals must not be negative!"
661                       << exit(FatalError);
662             }
664             if( optParams.found("featureSizeFactor") )
665             {
666                 const scalar featureSizeFactor =
667                     readScalar(optParams.lookup("featureSizeFactor"));
669                 if( featureSizeFactor >= 1.0 || featureSizeFactor < 0.0 )
670                     FatalErrorIn
671                     (
672                         "void checkMeshDict::checkBoundaryLayers() const"
673                     ) << "Feature size factor is out"
674                       << " of a valid range 0 to 1" << exit(FatalError);
675             }
677             if( optParams.found("relThicknessTol") )
678             {
679                 const scalar relThicknessTol =
680                     readScalar(optParams.lookup("relThicknessTol"));
682                 if( relThicknessTol >= 1.0 || relThicknessTol < 0.0 )
683                     FatalErrorIn
684                     (
685                         "void checkMeshDict::checkBoundaryLayers() const"
686                     ) << "Relative thickness tolerance is out"
687                       << " of a valid range 0 to 1" << exit(FatalError);
688             }
690             if( optParams.found("maxNumIterations") )
691             {
692                 const label maxNumIterations =
693                     readLabel(optParams.lookup("maxNumIterations"));
695                 if( maxNumIterations < 0 )
696                     FatalErrorIn
697                     (
698                         "void checkMeshDict::checkBoundaryLayers() const"
699                     ) << "maxNumIterations must not be negative!"
700                       << exit(FatalError);
701             }
702         }
703     }
706 void checkMeshDict::checkRenameBoundary() const
708     if( meshDict_.found("renameBoundary") )
709     {
710         const dictionary& dict = meshDict_.subDict("renameBoundary");
711         if( dict.found("newPatchNames") )
712         {
713             if( dict.isDict("newPatchNames") )
714             {
715                 const dictionary& patchDicts = dict.subDict("newPatchNames");
717                 const wordList patchNames = patchDicts.toc();
719                 forAll(patchNames, patchI)
720                 {
721                     const word& pName = patchNames[patchI];
723                     if( !patchDicts.isDict(pName) )
724                         FatalErrorIn
725                         (
726                             "void checkMeshDict::checkRenameBoundary() const"
727                         ) << "Entry " << pName
728                           << " is not a dictionary" << exit(FatalError);
730                     const dictionary dict = patchDicts.subDict(pName);
732                     if( !dict.found("newName") )
733                         FatalErrorIn
734                         (
735                             "void checkMeshDict::checkRenameBoundary() const"
736                         ) << "Dictionary " << pName
737                           << " does not contain a newName keyword"
738                           << exit(FatalError);
739                 }
740             }
741             else
742             {
743                 const PtrList<entry> patchesToRename
744                 (
745                     dict.lookup("newPatchNames")
746                 );
748                 forAll(patchesToRename, patchI)
749                 {
750                     const word& pName = patchesToRename[patchI].keyword();
752                     const dictionary dict = patchesToRename[patchI].dict();
754                     if( !dict.found("newName") )
755                         FatalErrorIn
756                         (
757                             "void checkMeshDict::checkRenameBoundary() const"
758                         ) << "Dictionary " << pName
759                           << " does not contain a newName keyword"
760                           << exit(FatalError);
761                 }
762             }
763         }
764     }
767 void checkMeshDict::checkEntries() const
769     checkBasicSettings();
771     checkPatchCellSize();
773     checkSubsetCellSize();
775     checkSurfaceRefinements();
777     checkKeepCellsIntersectingPatches();
779     checkRemoveCellsIntersectingPatches();
781     checkObjectRefinements();
783     checkAnisotropicSources();
785     checkBoundaryLayers();
787     checkRenameBoundary();
790 void checkMeshDict::updatePatchCellSize
792     const std::map<word, wordList>& patchesFromPatch
795     if( meshDict_.found("patchCellSize") )
796     {
797         LongList<patchRefinement> updatedPatchRefinement;
799         if( meshDict_.isDict("patchCellSize") )
800         {
801             const dictionary dict = meshDict_.subDict("patchCellSize");
803             const wordList patchNames = dict.toc();
805             forAll(patchNames, patchI)
806             {
807                 const word& pName = patchNames[patchI];
809                 std::map<word, wordList>::const_iterator it =
810                     patchesFromPatch.find(pName);
811                 if( it == patchesFromPatch.end() )
812                     continue;
814                 const wordList& updatedPatchNames = it->second;
816                 const dictionary& pDict = dict.subDict(pName);
817                 const scalar cellSize = readScalar(pDict.lookup("cellSize"));
819                 forAll(updatedPatchNames, nameI)
820                     updatedPatchRefinement.append
821                     (
822                         patchRefinement
823                         (
824                             updatedPatchNames[nameI],
825                             cellSize
826                         )
827                     );
828             }
829         }
830         else
831         {
832             patchRefinementList prl(meshDict_.lookup("patchCellSize"));
833             forAll(prl, prlI)
834             {
835                 const word& pName = prl[prlI].patchName();
836                 const scalar cellSize = prl[prlI].cellSize();
838                 std::map<word, wordList>::const_iterator it =
839                     patchesFromPatch.find(pName);
841                 if( it == patchesFromPatch.end() )
842                     continue;
844                 const wordList& updatedPatchNames = it->second;
845                 forAll(updatedPatchNames, nameI)
846                     updatedPatchRefinement.append
847                     (
848                         patchRefinement
849                         (
850                             updatedPatchNames[nameI],
851                             cellSize
852                         )
853                     );
854             }
855         }
857         meshDict_.add("patchCellSize", updatedPatchRefinement, true);
858     }
861 void checkMeshDict::updateSubsetCellSize
863     const std::map<word, wordList>& patchesFromPatch
869 void checkMeshDict::updateLocalRefinement
871     const std::map<word, wordList>& patchesFromPatch
874     if( meshDict_.found("localRefinement") )
875     {
876         if( meshDict_.isDict("localRefinement") )
877         {
878             dictionary& dict = meshDict_.subDict("localRefinement");
880             const wordList entries = dict.toc();
882             forAll(entries, dictI)
883             {
884                 const word& pName = entries[dictI];
886                 std::map<word, wordList>::const_iterator it =
887                     patchesFromPatch.find(pName);
888                 if( it == patchesFromPatch.end() )
889                     continue;
891                 const wordList& updatedPatchNames = it->second;
893                 const dictionary& pDict = dict.subDict(pName);
894                 dictionary copy = pDict;
896                 //- add new patches
897                 forAll(updatedPatchNames, nameI)
898                     dict.add(updatedPatchNames[nameI], copy);
900                 //- remove the current patch
901                 dict.remove(pName);
902             }
903         }
904     }
907 void checkMeshDict::updateKeepCellsIntersectingPatches
909     const std::map<word, wordList>& patchesFromPatch
912     if( meshDict_.found("keepCellsIntersectingPatches") )
913     {
914         LongList<word> updatedPatchNames;
915         if( meshDict_.isDict("keepCellsIntersectingPatches") )
916         {
917             const dictionary& dict =
918                 meshDict_.subDict("keepCellsIntersectingPatches");
920             const wordList patchNames = dict.toc();
921             forAll(patchNames, patchI)
922             {
923                 const word& pName = patchNames[patchI];
925                 std::map<word, wordList>::const_iterator it =
926                     patchesFromPatch.find(pName);
928                 if( it == patchesFromPatch.end() )
929                 {
930                     updatedPatchNames.append(pName);
931                     continue;
932                 }
934                 const wordList& newPatchNames = it->second;
936                 forAll(newPatchNames, nameI)
937                     updatedPatchNames.append(newPatchNames[nameI]);
938             }
939         }
940         else
941         {
942             wordList kcip(meshDict_.lookup("keepCellsIntersectingPatches"));
944             forAll(kcip, i)
945             {
946                 const word& pName = kcip[i];
948                 std::map<word, wordList>::const_iterator it =
949                     patchesFromPatch.find(pName);
951                 if( it == patchesFromPatch.end() )
952                     updatedPatchNames.append(pName);
954                 const wordList& newPatchNames = it->second;
956                 forAll(newPatchNames, nameI)
957                     updatedPatchNames.append(newPatchNames[nameI]);
958             }
959         }
961         meshDict_.add("keepCellsIntersectingPatches", updatedPatchNames, true);
962     }
966 void checkMeshDict::updateRemoveCellsIntersectingPatches
968     const std::map<word, wordList>& patchesFromPatch
971     if( meshDict_.found("removeCellsIntersectingPatches") )
972     {
973         LongList<word> updatedPatchNames;
974         if( meshDict_.isDict("removeCellsIntersectingPatches") )
975         {
976             const dictionary& dict =
977                 meshDict_.subDict("removeCellsIntersectingPatches");
979             const wordList patchNames = dict.toc();
980             forAll(patchNames, patchI)
981             {
982                 const word& pName = patchNames[patchI];
984                 std::map<word, wordList>::const_iterator it =
985                     patchesFromPatch.find(pName);
987                 if( it == patchesFromPatch.end() )
988                 {
989                     updatedPatchNames.append(pName);
990                     continue;
991                 }
993                 const wordList& newPatchNames = it->second;
995                 forAll(newPatchNames, nameI)
996                     updatedPatchNames.append(newPatchNames[nameI]);
997             }
998         }
999         else
1000         {
1001             wordList kcip(meshDict_.lookup("removeCellsIntersectingPatches"));
1003             forAll(kcip, i)
1004             {
1005                 const word& pName = kcip[i];
1007                 std::map<word, wordList>::const_iterator it =
1008                     patchesFromPatch.find(pName);
1010                 if( it == patchesFromPatch.end() )
1011                     updatedPatchNames.append(pName);
1013                 const wordList& newPatchNames = it->second;
1015                 forAll(newPatchNames, nameI)
1016                     updatedPatchNames.append(newPatchNames[nameI]);
1017             }
1018         }
1020         meshDict_.add
1021         (
1022             "removeCellsIntersectingPatches",
1023             updatedPatchNames,
1024             true
1025         );
1026     }
1029 void checkMeshDict::updateObjectRefinements
1031     const std::map<word, wordList>& patchesFromPatch
1037 void checkMeshDict::updateBoundaryLayers
1039     const std::map<word, wordList>& patchesFromPatch
1042     if( meshDict_.isDict("boundaryLayers") )
1043     {
1044         dictionary& bndLayersDict = meshDict_.subDict("boundaryLayers");
1045         if( bndLayersDict.isDict("patchBoundaryLayers") )
1046         {
1047             dictionary& patchBndLayers =
1048                 bndLayersDict.subDict("patchBoundaryLayers");
1050             const wordList patchLayers = patchBndLayers.toc();
1052             forAll(patchLayers, patchI)
1053             {
1054                 const word& pName = patchLayers[patchI];
1056                 dictionary dict = patchBndLayers.subDict(pName);
1058                 const std::map<word, wordList>::const_iterator it =
1059                     patchesFromPatch.find(pName);
1061                 //- patch name may be a regex
1062                 if( it != patchesFromPatch.end() )
1063                 {
1064                     const wordList& newNames = it->second;
1066                     forAll(newNames, i)
1067                     {
1068                         patchBndLayers.add(newNames[i], dict);
1069                     }
1071                     patchBndLayers.remove(pName);
1072                 }
1073             }
1074         }
1075     }
1078 void checkMeshDict::updateRenameBoundary
1080     const std::map<word, wordList>& patchesFromPatch,
1081     const std::map<word, word>& patchTypes
1084     dictionary newDict;
1086     newDict.add("newPatchNames", dictionary());
1088     if( meshDict_.found("renameBoundary") )
1089     {
1090         const dictionary& dict = meshDict_.subDict("renameBoundary");
1092         //- transfer or generate the default name entry
1093         if( dict.found("defaultName") )
1094         {
1095             const word name(dict.lookup("defaultName"));
1096             newDict.add("defaultName", name);
1097         }
1099         //- transfer or generate the defaultType entry
1100         if( dict.found("defaultType") )
1101         {
1102             const word type(dict.lookup("defaultType"));
1103             newDict.add("defaultType", type);
1104         }
1106         if( dict.found("newPatchNames") )
1107         {
1108             //- stores the updated dictionary
1109             dictionary& newPatchesDict = newDict.subDict("newPatchNames");
1111             if( dict.isDict("newPatchNames") )
1112             {
1113                 //- current state of the dictionary
1114                 const dictionary& patchDicts = dict.subDict("newPatchNames");
1116                 std::map<word, wordList>::const_iterator it;
1117                 for(it=patchesFromPatch.begin();it!=patchesFromPatch.end();++it)
1118                 {
1119                     const word& pName = it->first;
1120                     const wordList& newNames = it->second;
1122                     if( patchDicts.found(pName) )
1123                     {
1124                         //- patch renaming is already requested by the user
1125                         //- use the new name for all newly created patches
1126                         const dictionary& patchDict = patchDicts.subDict(pName);
1127                         if( !patchDict.found("newName") )
1128                             continue;
1129                         if( !patchDict.found("type") )
1130                             continue;
1132                         const word newName(patchDict.lookup("newName"));
1133                         const word newType(patchDict.lookup("type"));
1135                         forAll(newNames, i)
1136                         {
1137                             dictionary newPatchDict;
1138                             newPatchDict.add("newName", newName);
1139                             newPatchDict.add("type", newType);
1141                             newPatchesDict.add(newNames[i], newPatchDict);
1142                         }
1143                     }
1144                     else
1145                     {
1146                         //- rename all newly create patches
1147                         //- with the original name
1148                         forAll(newNames, i)
1149                         {
1150                             dictionary newPatchDict;
1152                             newPatchDict.add("newName", it->first);
1153                             std::map<word, word>::const_iterator tIter =
1154                                 patchTypes.find(it->first);
1155                             newPatchDict.add("type", tIter->second);
1157                             newPatchesDict.add(newNames[i], newPatchDict);
1158                         }
1159                     }
1160                 }
1161             }
1162             else
1163             {
1164                 const PtrList<entry> patchEntries(dict.lookup("newPatchNames"));
1166                 forAll(patchEntries, entryI)
1167                 {
1168                     const word& pName = patchEntries[entryI].keyword();
1169                     dictionary patchDict(patchEntries[entryI].dict());
1171                     std::map<word, wordList>::const_iterator it =
1172                         patchesFromPatch.find(pName);
1174                     if( it == patchesFromPatch.end() )
1175                         continue;
1177                     const wordList& newNames = it->second;
1179                     forAll(newNames, i)
1180                         newPatchesDict.add(newNames[i], patchDict, true);
1181                 }
1183                 std::map<word, wordList>::const_iterator it;
1184                 for(it=patchesFromPatch.begin();it!=patchesFromPatch.end();++it)
1185                 {
1186                     const word& pName = it->first;
1187                     const wordList& newNames = it->second;
1189                     if( newPatchesDict.found(pName) )
1190                         continue;
1192                     //- rename all newly created patches
1193                     //- with the original name
1194                     forAll(newNames, i)
1195                     {
1196                         dictionary newPatchDict;
1198                         newPatchDict.add("newName", it->first);
1199                         std::map<word, word>::const_iterator tIter =
1200                             patchTypes.find(it->first);
1201                         newPatchDict.add("type", tIter->second);
1203                         newPatchesDict.add(newNames[i], newPatchDict);
1204                     }
1205                 }
1206             }
1207         }
1208         else
1209         {
1210             //- newPatchNames is not used
1211             dictionary& newPatchesDict = newDict.subDict("newPatchNames");
1213             std::map<word, wordList>::const_iterator it;
1214             for(it=patchesFromPatch.begin();it!=patchesFromPatch.end();++it)
1215             {
1216                 const wordList& newPatchNames = it->second;
1218                 forAll(newPatchNames, i)
1219                 {
1220                     const word& pName = newPatchNames[i];
1221                     dictionary newPatchDict;
1222                     newPatchDict.add("newName", it->first);
1223                     std::map<word, word>::const_iterator tIter =
1224                         patchTypes.find(it->first);
1225                     newPatchDict.add("type", tIter->second);
1227                     newPatchesDict.add(pName, newPatchDict);
1228                 }
1229             }
1230         }
1232         //- delete all previus entries from the dictionary
1233         meshDict_.subDict("renameBoundary").clear();
1234     }
1235     else
1236     {
1237         //- create the dictionary if it has not existed before
1238         dictionary& newPatchesDict = newDict.subDict("newPatchNames");
1240         std::map<word, wordList>::const_iterator it;
1241         for(it=patchesFromPatch.begin();it!=patchesFromPatch.end();++it)
1242         {
1243             const wordList& newPatchNames = it->second;
1245             forAll(newPatchNames, i)
1246             {
1247                 const word& pName = newPatchNames[i];
1248                 dictionary newPatchDict;
1249                 newPatchDict.add("newName", it->first);
1250                 std::map<word, word>::const_iterator tIter =
1251                     patchTypes.find(it->first);
1252                 newPatchDict.add("type", tIter->second);
1254                 newPatchesDict.add(pName, newPatchDict);
1255             }
1256         }
1257     }
1259     meshDict_.add("renameBoundary", newDict, true);
1262 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
1264 checkMeshDict::checkMeshDict
1266     IOdictionary& meshDict
1269     meshDict_(meshDict)
1271     checkEntries();
1274 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
1276 checkMeshDict::~checkMeshDict()
1279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1281 void checkMeshDict::updateDictionaries
1283     const std::map<word, wordList>& patchesFromPatch,
1284     const std::map<word, word>& patchTypes,
1285     const bool renamePatches
1288     updatePatchCellSize(patchesFromPatch);
1290     updateSubsetCellSize(patchesFromPatch);
1292     updateLocalRefinement(patchesFromPatch);
1294     updateKeepCellsIntersectingPatches(patchesFromPatch);
1296     updateRemoveCellsIntersectingPatches(patchesFromPatch);
1298     updateObjectRefinements(patchesFromPatch);
1300     updateBoundaryLayers(patchesFromPatch);
1302     if( renamePatches )
1303         updateRenameBoundary(patchesFromPatch, patchTypes);
1306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1308 } // End namespace Foam
1310 // ************************************************************************* //