checkMeshDict.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "checkMeshDict.H"
29 #include "patchRefinementList.H"
30 #include "PtrList.H"
31 #include "LongList.H"
32 #include "objectRefinement.H"
33 #include "coordinateModification.H"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
43 {
44  //- check if maxCellSize is valid
45  const scalar maxCellSize = readScalar(meshDict_.lookup("maxCellSize"));
46 
47  if( maxCellSize < 0 )
49  (
50  "void checkMeshDict::checkBasicSettings() const"
51  ) << "maxCellSize is negative! Cannot generate the mesh!!"
52  << exit(FatalError);
53 
54  //- check if boundaryCellSize makes sense
55  if( meshDict_.found("boundaryCellSize") )
56  {
57  const scalar bcs = readScalar(meshDict_.lookup("boundaryCellSize"));
58 
59  if( bcs < 0 )
60  {
61  WarningIn
62  (
63  "void checkMeshDict::checkBasicSettings() const"
64  ) << "Boundary cell size is negative!!" << endl;
65  }
66 
67  if( meshDict_.found("boundaryCellSizeRefinementThickness") )
68  {
69  const scalar thickness =
71  (
72  meshDict_.lookup("boundaryCellSizeRefinementThickness")
73  );
74 
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  }
85 
86  //- check if minCellSize is valid
87  if( meshDict_.found("minCellSize") )
88  {
89  const scalar mcs = readScalar(meshDict_.lookup("minCellSize"));
90 
91  if( mcs < 0 )
92  {
94  (
95  "void checkMeshDict::checkBasicSettings() const"
96  ) << "Minimum cell size for automatic refinement is negative!!"
97  << exit(FatalError);
98  }
99 
100  }
101 
102  //- check if keepCellsIntersectingBoundary can be read correctly
103  if( meshDict_.found("keepCellsIntersectingBoundary") )
104  {
105  const bool keep =
106  readBool(meshDict_.lookup("keepCellsIntersectingBoundary"));
107 
108  if( keep && meshDict_.found("checkForGluedMesh") )
109  {
110  readBool(meshDict_.lookup("checkForGluedMesh"));
111  }
112  }
113 
114  //- check if enforceConstraints is available
115  if( meshDict_.found("enforceGeometryConstraints") )
116  {
117  readBool(meshDict_.lookup("enforceGeometryConstraints"));
118  }
119 }
120 
122 {
123  if( meshDict_.found("patchCellSize") )
124  {
125  if( meshDict_.isDict("patchCellSize") )
126  {
127  const dictionary& dict = meshDict_.subDict("patchCellSize");
128 
129  const wordList patchNames = dict.toc();
130  patchNames.size();
131  }
132  else
133  {
134  patchRefinementList prl(meshDict_.lookup("patchCellSize"));
135  prl.size();
136  }
137  }
138 }
139 
141 {
142  if( meshDict_.found("subsetCellSize") )
143  {
144  if( meshDict_.isDict("subsetCellSize") )
145  {
146  const dictionary& dict = meshDict_.subDict("subsetCellSize");
147 
148  const wordList subsetNames = dict.toc();
149  subsetNames.size();
150  }
151  else
152  {
153  patchRefinementList prl(meshDict_.lookup("patchCellSize"));
154  }
155  }
156 }
157 
159 {
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();
166 
167  forAll(entries, dictI)
168  {
169  const dictionary& dict = refDict.subDict(entries[dictI]);
170 
171  if( dict.found("cellSize") )
172  {
173  const scalar cs = readScalar(dict.lookup("cellSize"));
174 
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"));
188 
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  {
201  (
202  "void checkMeshDict::checkLocalRefinementLevel() const"
203  ) << "Cannot read keyword"
204  << " additionalRefinementLevels or cellSize"
205  << "for " << entries[dictI] << exit(FatalError);
206  }
207 
208  if( dict.found("refinementThickness") )
209  {
210  const scalar s =
211  readScalar(dict.lookup("refinementThickness"));
212 
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  {
227  (
228  "void checkMeshDict::checkLocalRefinementLevel() const"
229  ) << "Cannot read localRefinement" << exit(FatalError);
230  }
231  }
232 }
233 
235 {
236  if( meshDict_.found("keepCellsIntersectingPatches") )
237  {
238  if( meshDict_.isDict("keepCellsIntersectingPatches") )
239  {
240  const dictionary& dict =
241  meshDict_.subDict("keepCellsIntersectingPatches");
242 
243  const wordList patchNames = dict.toc();
244  patchNames.size();
245  }
246  else
247  {
248  wordList kcip(meshDict_.lookup("keepCellsIntersectingPatches"));
249  }
250  }
251 }
252 
254 {
255  if( meshDict_.found("removeCellsIntersectingPatches") )
256  {
257  if( meshDict_.isDict("removeCellsIntersectingPatches") )
258  {
259  const dictionary& dict =
260  meshDict_.subDict("removeCellsIntersectingPatches");
261 
262  const wordList patchNames = dict.toc();
263  patchNames.size();
264  }
265  else
266  {
267  wordList kcip(meshDict_.lookup("removeCellsIntersectingPatches"));
268  }
269  }
270 }
271 
273 {
274  if( meshDict_.found("objectRefinements") )
275  {
276  PtrList<objectRefinement> refObjects;
277 
278  if( meshDict_.isDict("objectRefinements") )
279  {
280  const dictionary& dict = meshDict_.subDict("objectRefinements");
281  const wordList objectNames = dict.toc();
282 
283  refObjects.setSize(objectNames.size());
284 
285  forAll(refObjects, objectI)
286  {
287  const entry& objectEntry =
288  dict.lookupEntry(objectNames[objectI], false, false);
289 
290  refObjects.set
291  (
292  objectI,
294  (
295  objectEntry.keyword(),
296  objectEntry.dict()
297  )
298  );
299  }
300  }
301  else
302  {
303  Istream& is = meshDict_.lookup("objectRefinements");
304 
305  PtrList<entry> objectEntries(is);
306  refObjects.setSize(objectEntries.size());
307 
308  forAll(refObjects, objectI)
309  {
310  refObjects.set
311  (
312  objectI,
314  (
315  objectEntries[objectI].keyword(),
316  objectEntries[objectI].dict()
317  )
318  );
319  }
320  }
321 
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  }
334 }
335 
337 {
338  if( meshDict_.found("anisotropicSources") )
339  {
340  PtrList<coordinateModification> anisotropicObjects;
341 
342  if( meshDict_.isDict("anisotropicSources") )
343  {
344  const dictionary& dict = meshDict_.subDict("anisotropicSources");
345  const wordList objectNames = dict.toc();
346 
347  anisotropicObjects.setSize(objectNames.size());
348 
349  forAll(anisotropicObjects, objectI)
350  {
351  const entry& objectEntry =
352  dict.lookupEntry(objectNames[objectI], false, false);
353 
354  anisotropicObjects.set
355  (
356  objectI,
358  (
359  objectEntry.keyword(),
360  objectEntry.dict()
361  )
362  );
363  }
364  }
365  }
366 }
367 
369 {
370  if( meshDict_.found("surfaceMeshRefinement") )
371  {
372  const dictionary& surfaces = meshDict_.subDict("surfaceMeshRefinement");
373 
374  const wordList surfaceSources = surfaces.toc();
375 
376  forAll(surfaceSources, surfI)
377  {
378  if( surfaces.isDict(surfaceSources[surfI]) )
379  {
380  const dictionary& dict =
381  surfaces.subDict(surfaceSources[surfI]);
382 
383  if( dict.found("surfaceFile") )
384  {
385  const fileName fName(dict.lookup("surfaceFile"));
386 
387  if( !isFile(fName) )
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  {
398  (
399  "void checkMeshDict::checkSurfaceRefinements() const"
400  ) << "Missing surfaceFile for entry "
401  << surfaceSources[surfI] << exit(FatalError);
402  }
403 
404  if( dict.found("cellSize") )
405  {
406  const scalar cs = readScalar(dict.lookup("cellSize"));
407 
408  if( cs < VSMALL )
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"));
421 
422  if( nLev < 0 )
423  {
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  {
436  (
437  "void checkMeshDict::checkSurfaceRefinements() const"
438  ) << "Missing cellSize or additionalRefinementLevels"
439  << " for entry " << surfaceSources[surfI]
440  << exit(FatalError);
441  }
442 
443  if( dict.found("refinementThickness") )
444  {
445  const scalar cs =
446  readScalar(dict.lookup("refinementThickness"));
447 
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  {
461  (
462  "void checkMeshDict::checkSurfaceRefinements() const"
463  ) << "Dictionary " << surfaceSources[surfI]
464  << " does not exist!!"
465  << exit(FatalError);
466  }
467  }
468  }
469 }
470 
472 {
473  if( meshDict_.found("edgeMeshRefinement") )
474  {
475  const dictionary& edgeMeshes = meshDict_.subDict("edgeMeshRefinement");
476 
477  const wordList edgeMeshSources = edgeMeshes.toc();
478 
479  forAll(edgeMeshSources, emI)
480  {
481  if( edgeMeshes.isDict(edgeMeshSources[emI]) )
482  {
483  const dictionary& dict =
484  edgeMeshes.subDict(edgeMeshSources[emI]);
485 
486  if( dict.found("edgeFile") )
487  {
488  const fileName fName(dict.lookup("edgeFile"));
489 
490  if( !isFile(fName) )
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  {
501  (
502  "void checkMeshDict::checkEdgeMeshRefinements() const"
503  ) << "Missing edgeFilw for entry "
504  << edgeMeshSources[emI] << exit(FatalError);
505  }
506 
507  if( dict.found("cellSize") )
508  {
509  const scalar cs = readScalar(dict.lookup("cellSize"));
510 
511  if( cs < VSMALL )
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"));
524 
525  if( nLev < 0 )
526  {
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  {
539  (
540  "void checkMeshDict::checkEdgeMeshRefinements() const"
541  ) << "Missing cellSize or additionalRefinementLevels"
542  << " for entry " << edgeMeshSources[emI]
543  << exit(FatalError);
544  }
545 
546  if( dict.found("refinementThickness") )
547  {
548  const scalar cs =
549  readScalar(dict.lookup("refinementThickness"));
550 
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  {
564  (
565  "void checkMeshDict::checkEdgeMeshRefinements() const"
566  ) << "Dictionary " << edgeMeshSources[emI]
567  << " does not exist!!"
568  << exit(FatalError);
569  }
570  }
571  }
572 }
573 
575 {
576  if( meshDict_.found("boundaryLayers") )
577  {
578  const dictionary& bndLayers = meshDict_.subDict("boundaryLayers");
579 
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  }
593 
594  //- patch-based properties
595  if( bndLayers.isDict("patchBoundaryLayers") )
596  {
597  const dictionary& patchBndLayers =
598  bndLayers.subDict("patchBoundaryLayers");
599  const wordList patchNames = patchBndLayers.toc();
600 
601  forAll(patchNames, patchI)
602  {
603  const word pName = patchNames[patchI];
604 
605  if( patchBndLayers.isDict(pName) )
606  {
607  const dictionary& patchDict =
608  patchBndLayers.subDict(pName);
609 
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  }
634 
635  //- check for existence of boundary layer smoothing
636  if( bndLayers.found("optimiseLayer") )
637  {
638  readBool(bndLayers.lookup("optimiseLayer"));
639  }
640 
641  if( bndLayers.found("optimisationParameters") )
642  {
643  const dictionary& optParams =
644  bndLayers.subDict("optimisationParameters");
645 
646  if( optParams.found("reCalculateNormals") )
647  {
648  readBool(optParams.lookup("reCalculateNormals"));
649  }
650 
651  if( optParams.found("nSmoothNormals") )
652  {
653  const label nSmoothNormals =
654  readLabel(optParams.lookup("nSmoothNormals"));
655 
656  if( nSmoothNormals < 0 )
658  (
659  "void checkMeshDict::checkBoundaryLayers() const"
660  ) << "nSmoothNormals must not be negative!"
661  << exit(FatalError);
662  }
663 
664  if( optParams.found("featureSizeFactor") )
665  {
666  const scalar featureSizeFactor =
667  readScalar(optParams.lookup("featureSizeFactor"));
668 
669  if( featureSizeFactor >= 1.0 || featureSizeFactor < 0.0 )
671  (
672  "void checkMeshDict::checkBoundaryLayers() const"
673  ) << "Feature size factor is out"
674  << " of a valid range 0 to 1" << exit(FatalError);
675  }
676 
677  if( optParams.found("relThicknessTol") )
678  {
679  const scalar relThicknessTol =
680  readScalar(optParams.lookup("relThicknessTol"));
681 
682  if( relThicknessTol >= 1.0 || relThicknessTol < 0.0 )
684  (
685  "void checkMeshDict::checkBoundaryLayers() const"
686  ) << "Relative thickness tolerance is out"
687  << " of a valid range 0 to 1" << exit(FatalError);
688  }
689 
690  if( optParams.found("maxNumIterations") )
691  {
692  const label maxNumIterations =
693  readLabel(optParams.lookup("maxNumIterations"));
694 
695  if( maxNumIterations < 0 )
697  (
698  "void checkMeshDict::checkBoundaryLayers() const"
699  ) << "maxNumIterations must not be negative!"
700  << exit(FatalError);
701  }
702  }
703  }
704 }
705 
707 {
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");
716 
717  const wordList patchNames = patchDicts.toc();
718 
719  forAll(patchNames, patchI)
720  {
721  const word& pName = patchNames[patchI];
722 
723  if( !patchDicts.isDict(pName) )
725  (
726  "void checkMeshDict::checkRenameBoundary() const"
727  ) << "Entry " << pName
728  << " is not a dictionary" << exit(FatalError);
729 
730  const dictionary dict = patchDicts.subDict(pName);
731 
732  if( !dict.found("newName") )
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  );
747 
748  forAll(patchesToRename, patchI)
749  {
750  const word& pName = patchesToRename[patchI].keyword();
751 
752  const dictionary dict = patchesToRename[patchI].dict();
753 
754  if( !dict.found("newName") )
756  (
757  "void checkMeshDict::checkRenameBoundary() const"
758  ) << "Dictionary " << pName
759  << " does not contain a newName keyword"
760  << exit(FatalError);
761  }
762  }
763  }
764  }
765 }
766 
768 {
770 
772 
774 
776 
778 
780 
782 
784 
786 
788 }
789 
791 (
792  const std::map<word, wordList>& patchesFromPatch
793 )
794 {
795  if( meshDict_.found("patchCellSize") )
796  {
797  LongList<patchRefinement> updatedPatchRefinement;
798 
799  if( meshDict_.isDict("patchCellSize") )
800  {
801  const dictionary dict = meshDict_.subDict("patchCellSize");
802 
803  const wordList patchNames = dict.toc();
804 
805  forAll(patchNames, patchI)
806  {
807  const word& pName = patchNames[patchI];
808 
809  std::map<word, wordList>::const_iterator it =
810  patchesFromPatch.find(pName);
811  if( it == patchesFromPatch.end() )
812  continue;
813 
814  const wordList& updatedPatchNames = it->second;
815 
816  const dictionary& pDict = dict.subDict(pName);
817  const scalar cellSize = readScalar(pDict.lookup("cellSize"));
818 
819  forAll(updatedPatchNames, nameI)
820  updatedPatchRefinement.append
821  (
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();
837 
838  std::map<word, wordList>::const_iterator it =
839  patchesFromPatch.find(pName);
840 
841  if( it == patchesFromPatch.end() )
842  continue;
843 
844  const wordList& updatedPatchNames = it->second;
845  forAll(updatedPatchNames, nameI)
846  updatedPatchRefinement.append
847  (
849  (
850  updatedPatchNames[nameI],
851  cellSize
852  )
853  );
854  }
855  }
856 
857  meshDict_.add("patchCellSize", updatedPatchRefinement, true);
858  }
859 }
860 
862 (
863  const std::map<word, wordList>& /*patchesFromPatch*/
864 )
865 {
866 
867 }
868 
870 (
871  const std::map<word, wordList>& patchesFromPatch
872 )
873 {
874  if( meshDict_.found("localRefinement") )
875  {
876  if( meshDict_.isDict("localRefinement") )
877  {
878  dictionary& dict = meshDict_.subDict("localRefinement");
879 
880  const wordList entries = dict.toc();
881 
882  forAll(entries, dictI)
883  {
884  const word& pName = entries[dictI];
885 
886  std::map<word, wordList>::const_iterator it =
887  patchesFromPatch.find(pName);
888  if( it == patchesFromPatch.end() )
889  continue;
890 
891  const wordList& updatedPatchNames = it->second;
892 
893  const dictionary& pDict = dict.subDict(pName);
894  dictionary copy = pDict;
895 
896  //- add new patches
897  forAll(updatedPatchNames, nameI)
898  dict.add(updatedPatchNames[nameI], copy);
899 
900  //- remove the current patch
901  dict.remove(pName);
902  }
903  }
904  }
905 }
906 
908 (
909  const std::map<word, wordList>& patchesFromPatch
910 )
911 {
912  if( meshDict_.found("keepCellsIntersectingPatches") )
913  {
914  LongList<word> updatedPatchNames;
915  if( meshDict_.isDict("keepCellsIntersectingPatches") )
916  {
917  const dictionary& dict =
918  meshDict_.subDict("keepCellsIntersectingPatches");
919 
920  const wordList patchNames = dict.toc();
921  forAll(patchNames, patchI)
922  {
923  const word& pName = patchNames[patchI];
924 
925  std::map<word, wordList>::const_iterator it =
926  patchesFromPatch.find(pName);
927 
928  if( it == patchesFromPatch.end() )
929  {
930  updatedPatchNames.append(pName);
931  continue;
932  }
933 
934  const wordList& newPatchNames = it->second;
935 
936  forAll(newPatchNames, nameI)
937  updatedPatchNames.append(newPatchNames[nameI]);
938  }
939  }
940  else
941  {
942  wordList kcip(meshDict_.lookup("keepCellsIntersectingPatches"));
943 
944  forAll(kcip, i)
945  {
946  const word& pName = kcip[i];
947 
948  std::map<word, wordList>::const_iterator it =
949  patchesFromPatch.find(pName);
950 
951  if( it == patchesFromPatch.end() )
952  updatedPatchNames.append(pName);
953 
954  const wordList& newPatchNames = it->second;
955 
956  forAll(newPatchNames, nameI)
957  updatedPatchNames.append(newPatchNames[nameI]);
958  }
959  }
960 
961  meshDict_.add("keepCellsIntersectingPatches", updatedPatchNames, true);
962  }
963 }
964 
965 
967 (
968  const std::map<word, wordList>& patchesFromPatch
969 )
970 {
971  if( meshDict_.found("removeCellsIntersectingPatches") )
972  {
973  LongList<word> updatedPatchNames;
974  if( meshDict_.isDict("removeCellsIntersectingPatches") )
975  {
976  const dictionary& dict =
977  meshDict_.subDict("removeCellsIntersectingPatches");
978 
979  const wordList patchNames = dict.toc();
980  forAll(patchNames, patchI)
981  {
982  const word& pName = patchNames[patchI];
983 
984  std::map<word, wordList>::const_iterator it =
985  patchesFromPatch.find(pName);
986 
987  if( it == patchesFromPatch.end() )
988  {
989  updatedPatchNames.append(pName);
990  continue;
991  }
992 
993  const wordList& newPatchNames = it->second;
994 
995  forAll(newPatchNames, nameI)
996  updatedPatchNames.append(newPatchNames[nameI]);
997  }
998  }
999  else
1000  {
1001  wordList kcip(meshDict_.lookup("removeCellsIntersectingPatches"));
1002 
1003  forAll(kcip, i)
1004  {
1005  const word& pName = kcip[i];
1006 
1007  std::map<word, wordList>::const_iterator it =
1008  patchesFromPatch.find(pName);
1009 
1010  if( it == patchesFromPatch.end() )
1011  updatedPatchNames.append(pName);
1012 
1013  const wordList& newPatchNames = it->second;
1014 
1015  forAll(newPatchNames, nameI)
1016  updatedPatchNames.append(newPatchNames[nameI]);
1017  }
1018  }
1019 
1020  meshDict_.add
1021  (
1022  "removeCellsIntersectingPatches",
1023  updatedPatchNames,
1024  true
1025  );
1026  }
1027 }
1028 
1031  const std::map<word, wordList>& /*patchesFromPatch*/
1032 )
1033 {
1034 
1035 }
1036 
1039  const std::map<word, wordList>& patchesFromPatch
1040 )
1041 {
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");
1049 
1050  const wordList patchLayers = patchBndLayers.toc();
1051 
1052  forAll(patchLayers, patchI)
1053  {
1054  const word& pName = patchLayers[patchI];
1055 
1056  dictionary dict = patchBndLayers.subDict(pName);
1057 
1058  const std::map<word, wordList>::const_iterator it =
1059  patchesFromPatch.find(pName);
1060 
1061  //- patch name may be a regex
1062  if( it != patchesFromPatch.end() )
1063  {
1064  const wordList& newNames = it->second;
1065 
1066  forAll(newNames, i)
1067  {
1068  patchBndLayers.add(newNames[i], dict);
1069  }
1070 
1071  patchBndLayers.remove(pName);
1072  }
1073  }
1074  }
1075  }
1076 }
1077 
1080  const std::map<word, wordList>& patchesFromPatch,
1081  const std::map<word, word>& patchTypes
1082 )
1083 {
1084  dictionary newDict;
1085 
1086  newDict.add("newPatchNames", dictionary());
1087 
1088  if( meshDict_.found("renameBoundary") )
1089  {
1090  const dictionary& dict = meshDict_.subDict("renameBoundary");
1091 
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  }
1098 
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  }
1105 
1106  if( dict.found("newPatchNames") )
1107  {
1108  //- stores the updated dictionary
1109  dictionary& newPatchesDict = newDict.subDict("newPatchNames");
1110 
1111  if( dict.isDict("newPatchNames") )
1112  {
1113  //- current state of the dictionary
1114  const dictionary& patchDicts = dict.subDict("newPatchNames");
1115 
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;
1121 
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;
1131 
1132  const word newName(patchDict.lookup("newName"));
1133  const word newType(patchDict.lookup("type"));
1134 
1135  forAll(newNames, i)
1136  {
1137  dictionary newPatchDict;
1138  newPatchDict.add("newName", newName);
1139  newPatchDict.add("type", newType);
1140 
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;
1151 
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);
1156 
1157  newPatchesDict.add(newNames[i], newPatchDict);
1158  }
1159  }
1160  }
1161  }
1162  else
1163  {
1164  const PtrList<entry> patchEntries(dict.lookup("newPatchNames"));
1165 
1166  forAll(patchEntries, entryI)
1167  {
1168  const word& pName = patchEntries[entryI].keyword();
1169  dictionary patchDict(patchEntries[entryI].dict());
1170 
1171  std::map<word, wordList>::const_iterator it =
1172  patchesFromPatch.find(pName);
1173 
1174  if( it == patchesFromPatch.end() )
1175  continue;
1176 
1177  const wordList& newNames = it->second;
1178 
1179  forAll(newNames, i)
1180  newPatchesDict.add(newNames[i], patchDict, true);
1181  }
1182 
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;
1188 
1189  if( newPatchesDict.found(pName) )
1190  continue;
1191 
1192  //- rename all newly created patches
1193  //- with the original name
1194  forAll(newNames, i)
1195  {
1196  dictionary newPatchDict;
1197 
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);
1202 
1203  newPatchesDict.add(newNames[i], newPatchDict);
1204  }
1205  }
1206  }
1207  }
1208  else
1209  {
1210  //- newPatchNames is not used
1211  dictionary& newPatchesDict = newDict.subDict("newPatchNames");
1212 
1213  std::map<word, wordList>::const_iterator it;
1214  for(it=patchesFromPatch.begin();it!=patchesFromPatch.end();++it)
1215  {
1216  const wordList& newPatchNames = it->second;
1217 
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);
1226 
1227  newPatchesDict.add(pName, newPatchDict);
1228  }
1229  }
1230  }
1231 
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");
1239 
1240  std::map<word, wordList>::const_iterator it;
1241  for(it=patchesFromPatch.begin();it!=patchesFromPatch.end();++it)
1242  {
1243  const wordList& newPatchNames = it->second;
1244 
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);
1253 
1254  newPatchesDict.add(pName, newPatchDict);
1255  }
1256  }
1257  }
1258 
1259  meshDict_.add("renameBoundary", newDict, true);
1260 }
1261 
1262 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
1263 
1266  IOdictionary& meshDict
1267 )
1268 :
1269  meshDict_(meshDict)
1270 {
1271  checkEntries();
1272 }
1273 
1274 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
1275 
1277 {}
1278 
1279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1280 
1283  const std::map<word, wordList>& patchesFromPatch,
1284  const std::map<word, word>& patchTypes,
1285  const bool renamePatches
1286 )
1287 {
1288  updatePatchCellSize(patchesFromPatch);
1289 
1290  updateSubsetCellSize(patchesFromPatch);
1291 
1292  updateLocalRefinement(patchesFromPatch);
1293 
1294  updateKeepCellsIntersectingPatches(patchesFromPatch);
1295 
1296  updateRemoveCellsIntersectingPatches(patchesFromPatch);
1297 
1298  updateObjectRefinements(patchesFromPatch);
1299 
1300  updateBoundaryLayers(patchesFromPatch);
1301 
1302  if( renamePatches )
1303  updateRenameBoundary(patchesFromPatch, patchTypes);
1304 }
1305 
1306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1307 
1308 } // End namespace Foam
1309 
1310 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:65
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::checkMeshDict::checkRenameBoundary
void checkRenameBoundary() const
check renameBoundary entry
Definition: checkMeshDict.C:706
LongList.H
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
Foam::checkMeshDict::checkPatchCellSize
void checkPatchCellSize() const
check patchCellSize entry
Definition: checkMeshDict.C:121
Foam::checkMeshDict::updateLocalRefinement
void updateLocalRefinement(const std::map< word, wordList > &)
update local refinement
Definition: checkMeshDict.C:870
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::checkMeshDict::updateRenameBoundary
void updateRenameBoundary(const std::map< word, wordList > &, const std::map< word, word > &)
check renameBoundary entry
Definition: checkMeshDict.C:1079
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::entry::keyword
const keyType & keyword() const
Return keyword.
Definition: entry.H:120
Foam::checkMeshDict::checkEdgeMeshRefinements
void checkEdgeMeshRefinements() const
check edgeMeshRefinements entry
Definition: checkMeshDict.C:471
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::checkMeshDict::checkKeepCellsIntersectingPatches
void checkKeepCellsIntersectingPatches() const
check keepCellsIntersectingPatches entry
Definition: checkMeshDict.C:234
Foam::Warning
messageStream Warning
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::dictionary::remove
bool remove(const word &)
Remove an entry specified by keyword.
Definition: dictionary.C:881
Foam::checkMeshDict::~checkMeshDict
~checkMeshDict()
Definition: checkMeshDict.C:1276
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::checkMeshDict::checkAnisotropicSources
void checkAnisotropicSources() const
check anisotropic sources
Definition: checkMeshDict.C:336
Foam::coordinateModification::New
static autoPtr< coordinateModification > New(const word &name, const dictionary &dict)
Select constructed from dictionary.
Definition: newCoordinateModification.C:38
Foam::dictionary::isDict
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:600
Foam::checkMeshDict::updatePatchCellSize
void updatePatchCellSize(const std::map< word, wordList > &)
update patchCellSize entry
Definition: checkMeshDict.C:791
patchDicts
PtrList< dictionary > patchDicts
Definition: readKivaGrid.H:537
Foam::checkMeshDict::checkBoundaryLayers
void checkBoundaryLayers() const
check entry for boundary layers
Definition: checkMeshDict.C:574
patchTypes
wordList patchTypes(nPatches)
patchRefinementList.H
Foam::LongList
Definition: LongList.H:55
Foam::checkMeshDict::checkMeshDict
checkMeshDict(IOdictionary &meshDict)
Construct from IOdictionary.
Definition: checkMeshDict.C:1265
Foam::patchRefinement
Definition: patchRefinement.H:55
Foam::PtrList::set
bool set(const label) const
Is element set.
checkMeshDict.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::checkMeshDict::checkSubsetCellSize
void checkSubsetCellSize() const
check subsetCellSize entry
Definition: checkMeshDict.C:140
Foam::checkMeshDict::checkSurfaceRefinements
void checkSurfaceRefinements() const
check surfaceRefinements entry
Definition: checkMeshDict.C:368
patchNames
wordList patchNames(nPatches)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::checkMeshDict::checkLocalRefinementLevel
void checkLocalRefinementLevel() const
check local refinement level
Definition: checkMeshDict.C:158
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
coordinateModification.H
Foam::checkMeshDict::checkEntries
void checkEntries() const
perform all checks
Definition: checkMeshDict.C:767
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::isFile
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
Definition: POSIX.C:622
Foam::entry::dict
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::checkMeshDict::updateRemoveCellsIntersectingPatches
void updateRemoveCellsIntersectingPatches(const std::map< word, wordList > &)
check removeCellsIntersectingPatches entry
Definition: checkMeshDict.C:967
Foam::checkMeshDict::updateKeepCellsIntersectingPatches
void updateKeepCellsIntersectingPatches(const std::map< word, wordList > &)
check keepCellsIntersectingPatches entry
Definition: checkMeshDict.C:908
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::checkMeshDict::checkBasicSettings
void checkBasicSettings() const
check settings for cell size in meshDict
Definition: checkMeshDict.C:42
Foam::checkMeshDict::checkRemoveCellsIntersectingPatches
void checkRemoveCellsIntersectingPatches() const
check removeCellsIntersectingPatches entry
Definition: checkMeshDict.C:253
Foam::checkMeshDict::updateSubsetCellSize
void updateSubsetCellSize(const std::map< word, wordList > &)
update subsetCellSize entry
Definition: checkMeshDict.C:862
Foam::checkMeshDict::updateDictionaries
void updateDictionaries(const std::map< word, wordList > &patchesForPatch, const std::map< word, word > &patchTypes, const bool renamePatches=true)
update meshDict based on modification of patches in the surface
Definition: checkMeshDict.C:1282
Foam::checkMeshDict::updateObjectRefinements
void updateObjectRefinements(const std::map< word, wordList > &)
check objectRefinements entry
Definition: checkMeshDict.C:1030
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::checkMeshDict::checkObjectRefinements
void checkObjectRefinements() const
check objectRefinements entry
Definition: checkMeshDict.C:272
Foam::objectRefinement::New
static autoPtr< objectRefinement > New(const word &name, const dictionary &dict)
Select constructed from dictionary.
Definition: newObjectRefinement.C:38
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::PtrList::setSize
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:142
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
PtrList.H
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
WarningIn
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Definition: messageStream.H:254
Foam::readBool
bool readBool(Istream &)
Definition: boolIO.C:60
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:697
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
objectRefinement.H
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::checkMeshDict::updateBoundaryLayers
void updateBoundaryLayers(const std::map< word, wordList > &)
check entry for boundary layers
Definition: checkMeshDict.C:1038
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729
Foam::checkMeshDict::meshDict_
IOdictionary & meshDict_
Reference to the mesh.
Definition: checkMeshDict.H:53