From be9fb841a19b351f415c23ba35f3da8bd606efd6 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 15 Jun 2021 13:20:44 +0100 Subject: [PATCH] snappyHexMesh: Simplified and rationalised the region refinement level specification The inside or outside region refinement level is now specified using the simple "level " entry in refinementRegions e.g. refinementRegions { refinementBox { mode inside; level 5; } } rather than refinementRegions { refinementBox { mode inside; levels ((1E15 5)); } } where the spurious "1E15" number is not used and the '((...))' is unnecessary clutter. --- .../mesh/generation/snappyHexMeshDict | 4 +- .../closedVolume/system/snappyHexMeshDict | 4 +- .../system/snappyHexMeshDict | 4 +- .../system/snappyHexMeshDict | 4 +- .../inflowOutflow/system/snappyHexMeshDict | 4 +- .../system/snappyHexMeshDict | 4 +- .../singleFluidCHT/system/snappyHexMeshDict | 4 +- .../shellSurfaces/shellSurfaces.C | 178 ++++++++++++------ .../shellSurfaces/shellSurfaces.H | 8 +- .../RAS/propeller/system/snappyHexMeshDict | 8 +- .../motorBike/system/snappyHexMeshDict | 4 +- .../system/snappyHexMeshDict.orig | 12 +- .../motorBike/system/snappyHexMeshDict | 4 +- .../system/snappyHexMeshDict | 4 +- .../blob/system/snappyHexMeshDict | 4 +- .../flange/system/snappyHexMeshDict | 4 +- .../flange/system/snappyHexMeshDict | 4 +- .../pipe/system/snappyHexMeshDict | 4 +- .../RAS/propeller/system/snappyHexMeshDict | 8 +- .../sloshingCylinder/system/snappyHexMeshDict | 4 +- 20 files changed, 167 insertions(+), 107 deletions(-) diff --git a/etc/caseDicts/mesh/generation/snappyHexMeshDict b/etc/caseDicts/mesh/generation/snappyHexMeshDict index 981db9b37d..5cf4385825 100644 --- a/etc/caseDicts/mesh/generation/snappyHexMeshDict +++ b/etc/caseDicts/mesh/generation/snappyHexMeshDict @@ -77,8 +77,8 @@ castellatedMeshControls { CAD { - mode inside; - levels ((1E15 2)); + mode inside; + level 2; } } diff --git a/etc/templates/closedVolume/system/snappyHexMeshDict b/etc/templates/closedVolume/system/snappyHexMeshDict index e08cd3c579..117314aa2c 100644 --- a/etc/templates/closedVolume/system/snappyHexMeshDict +++ b/etc/templates/closedVolume/system/snappyHexMeshDict @@ -49,8 +49,8 @@ castellatedMeshControls { CAD { - mode inside; - levels ((1E15 2)); + mode inside; + level 2; } } diff --git a/etc/templates/closedVolumeRotating/system/snappyHexMeshDict b/etc/templates/closedVolumeRotating/system/snappyHexMeshDict index 4444073374..2c02254534 100644 --- a/etc/templates/closedVolumeRotating/system/snappyHexMeshDict +++ b/etc/templates/closedVolumeRotating/system/snappyHexMeshDict @@ -75,8 +75,8 @@ castellatedMeshControls /* rotatingZone { - mode inside; - levels ((1E15 2)); + mode inside; + level 2; } */ } diff --git a/etc/templates/compressibleInflowOutflow/system/snappyHexMeshDict b/etc/templates/compressibleInflowOutflow/system/snappyHexMeshDict index f9c1894dbc..f90775e703 100644 --- a/etc/templates/compressibleInflowOutflow/system/snappyHexMeshDict +++ b/etc/templates/compressibleInflowOutflow/system/snappyHexMeshDict @@ -77,8 +77,8 @@ castellatedMeshControls { CAD { - mode inside; - levels ((1E15 2)); + mode inside; + level 2; } } diff --git a/etc/templates/inflowOutflow/system/snappyHexMeshDict b/etc/templates/inflowOutflow/system/snappyHexMeshDict index f9c1894dbc..f90775e703 100644 --- a/etc/templates/inflowOutflow/system/snappyHexMeshDict +++ b/etc/templates/inflowOutflow/system/snappyHexMeshDict @@ -77,8 +77,8 @@ castellatedMeshControls { CAD { - mode inside; - levels ((1E15 2)); + mode inside; + level 2; } } diff --git a/etc/templates/inflowOutflowRotating/system/snappyHexMeshDict b/etc/templates/inflowOutflowRotating/system/snappyHexMeshDict index 7af586c19d..7ac8778f60 100644 --- a/etc/templates/inflowOutflowRotating/system/snappyHexMeshDict +++ b/etc/templates/inflowOutflowRotating/system/snappyHexMeshDict @@ -104,8 +104,8 @@ castellatedMeshControls /* rotatingZone { - mode inside; - levels ((1E15 2)); + mode inside; + level 2; } */ } diff --git a/etc/templates/singleFluidCHT/system/snappyHexMeshDict b/etc/templates/singleFluidCHT/system/snappyHexMeshDict index 11f47a38c4..61189b7627 100644 --- a/etc/templates/singleFluidCHT/system/snappyHexMeshDict +++ b/etc/templates/singleFluidCHT/system/snappyHexMeshDict @@ -96,8 +96,8 @@ castellatedMeshControls { CAD { - mode inside; - levels ((1E15 1)); + mode inside; + level 1; } } diff --git a/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C b/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C index 339dd2777a..7e0923fa9b 100644 --- a/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C +++ b/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C @@ -57,74 +57,56 @@ const Foam::NamedEnum void Foam::shellSurfaces::setAndCheckLevels ( const label shelli, - const List>& distLevels + const dictionary& dict ) { - if (modes_[shelli] != refineMode::distance && distLevels.size() != 1) + const searchableSurface& shell = allGeometry_[shells_[shelli]]; + + if + ( + modes_[shelli] == refineMode::inside + || modes_[shelli] == refineMode::outside + ) { - FatalErrorInFunction - << "For refinement mode " - << refineModeNames_[modes_[shelli]] - << " specify only one distance+level." - << " (its distance gets discarded)" - << exit(FatalError); - } - - // Extract information into separate distance and level - distances_[shelli].setSize(distLevels.size()); - levels_[shelli].setSize(distLevels.size()); - - forAll(distLevels, j) - { - distances_[shelli][j] = distLevels[j].first(); - levels_[shelli][j] = distLevels[j].second(); - - // Check in incremental order - if (j > 0) + if (!allGeometry_[shells_[shelli]].hasVolumeType()) { - if - ( - (distances_[shelli][j] <= distances_[shelli][j-1]) - || (levels_[shelli][j] > levels_[shelli][j-1]) - ) + WarningInFunction + << "Shell " << shell.name() + << " is not closed so testing for '" + << refineModeNames_[modes_[shelli]] + << "' may fail." << endl; + } + + distances_[shelli].setSize(0); + levels_[shelli].setSize(1); + + if (dict.found("levels") && !(dict.found("level"))) + { + // Support 'levels' for backward compatibility + const List> distLevels(dict.lookup("levels")); + + if (distLevels.size() != 1) { FatalErrorInFunction << "For refinement mode " << refineModeNames_[modes_[shelli]] - << " : Refinement should be specified in order" - << " of increasing distance" - << " (and decreasing refinement level)." << endl - << "Distance:" << distances_[shelli][j] - << " refinementLevel:" << levels_[shelli][j] + << " specify only one distance+level." + << " (its distance gets discarded)" << exit(FatalError); } + + levels_[shelli][0] = distLevels[0].second(); } - } - - const searchableSurface& shell = allGeometry_[shells_[shelli]]; - - if (modes_[shelli] == refineMode::distance) - { - Info<< "Refinement level according to distance to " - << shell.name() << endl; - - forAll(levels_[shelli], j) + else { - Info<< " level " << levels_[shelli][j] - << " for all cells within " << distances_[shelli][j] - << " metre." << endl; - } - } - else - { - if (!allGeometry_[shells_[shelli]].hasVolumeType()) - { - FatalErrorInFunction - << "Shell " << shell.name() - << " does not support testing for " - << refineModeNames_[modes_[shelli]] << endl - << "Probably it is not closed." - << exit(FatalError); + if (dict.found("levels")) + { + IOWarningInFunction(dict) + << "Found both 'level' and 'levels' entries, using 'level'." + << endl; + } + + levels_[shelli][0] = readLabel(dict.lookup("level")); } if (modes_[shelli] == refineMode::inside) @@ -138,6 +120,88 @@ void Foam::shellSurfaces::setAndCheckLevels << " for all cells outside " << shell.name() << endl; } } + else if + ( + modes_[shelli] == refineMode::insideSpan + || modes_[shelli] == refineMode::outsideSpan + ) + { + if (!allGeometry_[shells_[shelli]].hasVolumeType()) + { + WarningInFunction + << "Shell " << shell.name() + << " is not closed so testing for '" + << refineModeNames_[modes_[shelli]] + << "' may fail." << endl; + } + + distances_[shelli].setSize(1); + levels_[shelli].setSize(1); + const Tuple2 distLevel(dict.lookup("level")); + distances_[shelli][0] = distLevel.first(); + levels_[shelli][0] = distLevel.second(); + + if (modes_[shelli] == refineMode::insideSpan) + { + Info<< "Refinement level " << levels_[shelli][0] + << " for all cells inside " << shell.name() + << " within distance " << distances_[shelli][0] << endl; + } + else + { + Info<< "Refinement level " << levels_[shelli][0] + << " for all cells outside " << shell.name() + << " within distance " << distances_[shelli][0] << endl; + } + } + else + { + const List> distLevels(dict.lookup("levels")); + + // Extract information into separate distance and level + distances_[shelli].setSize(distLevels.size()); + levels_[shelli].setSize(distLevels.size()); + + forAll(distLevels, j) + { + distances_[shelli][j] = distLevels[j].first(); + levels_[shelli][j] = distLevels[j].second(); + + // Check in incremental order + if (j > 0) + { + if + ( + (distances_[shelli][j] <= distances_[shelli][j-1]) + || (levels_[shelli][j] > levels_[shelli][j-1]) + ) + { + FatalErrorInFunction + << "For refinement mode " + << refineModeNames_[modes_[shelli]] + << " : Refinement should be specified in order" + << " of increasing distance" + << " (and decreasing refinement level)." << endl + << "Distance:" << distances_[shelli][j] + << " refinementLevel:" << levels_[shelli][j] + << exit(FatalError); + } + } + } + + if (modes_[shelli] == refineMode::distance) + { + Info<< "Refinement level according to distance to " + << shell.name() << endl; + + forAll(levels_[shelli], j) + { + Info<< " level " << levels_[shelli][j] + << " for all cells within " << distances_[shelli][j] + << " metre." << endl; + } + } + } } @@ -499,7 +563,7 @@ Foam::shellSurfaces::shellSurfaces modes_[shelli] = refineModeNames_.read(dict.lookup("mode")); // Read pairs of distance+level - setAndCheckLevels(shelli, dict.lookup("levels")); + setAndCheckLevels(shelli, dict); if ( diff --git a/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.H b/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.H index 7c0304b3ed..4390ad143f 100644 --- a/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.H +++ b/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -103,11 +103,7 @@ private: // Private Member Functions //- Helper function for initialisation. - void setAndCheckLevels - ( - const label shelli, - const List>& - ); + void setAndCheckLevels(const label shelli, const dictionary& dict); //- Specifically orient triSurfaces using a calculated point outside. // Done since quite often triSurfaces not of consistent orientation diff --git a/tutorials/incompressible/pimpleFoam/RAS/propeller/system/snappyHexMeshDict b/tutorials/incompressible/pimpleFoam/RAS/propeller/system/snappyHexMeshDict index b06d2bc570..3fcbce8189 100644 --- a/tutorials/incompressible/pimpleFoam/RAS/propeller/system/snappyHexMeshDict +++ b/tutorials/incompressible/pimpleFoam/RAS/propeller/system/snappyHexMeshDict @@ -229,13 +229,13 @@ castellatedMeshControls { innerCylinder { - mode inside; - levels ((1E15 4)); + mode inside; + level 4; } middleCylinder { - mode inside; - levels ((1E15 3)); + mode inside; + level 3; } } diff --git a/tutorials/incompressible/pisoFoam/LES/motorBike/motorBike/system/snappyHexMeshDict b/tutorials/incompressible/pisoFoam/LES/motorBike/motorBike/system/snappyHexMeshDict index 105fc0b9fb..dd82bdd508 100644 --- a/tutorials/incompressible/pisoFoam/LES/motorBike/motorBike/system/snappyHexMeshDict +++ b/tutorials/incompressible/pisoFoam/LES/motorBike/motorBike/system/snappyHexMeshDict @@ -138,8 +138,8 @@ castellatedMeshControls { refinementBox { - mode inside; - levels ((1E15 5)); + mode inside; + level 5; } } diff --git a/tutorials/incompressible/simpleFoam/drivaerFastback/system/snappyHexMeshDict.orig b/tutorials/incompressible/simpleFoam/drivaerFastback/system/snappyHexMeshDict.orig index 6786f0c062..93d3250550 100644 --- a/tutorials/incompressible/simpleFoam/drivaerFastback/system/snappyHexMeshDict.orig +++ b/tutorials/incompressible/simpleFoam/drivaerFastback/system/snappyHexMeshDict.orig @@ -92,20 +92,20 @@ castellatedMeshControls { body { - mode distance; - levels ((0.2 5)); + mode distance; + levels ((0.2 5)); } "(wake|underbody)" { - mode inside; - levels ((1E15 4)); + mode inside; + level 4; } ".*stream" { - mode inside; - levels ((1E15 3)); + mode inside; + level 3; } } diff --git a/tutorials/incompressible/simpleFoam/motorBike/system/snappyHexMeshDict b/tutorials/incompressible/simpleFoam/motorBike/system/snappyHexMeshDict index 6bcae35348..7fb43db8f7 100644 --- a/tutorials/incompressible/simpleFoam/motorBike/system/snappyHexMeshDict +++ b/tutorials/incompressible/simpleFoam/motorBike/system/snappyHexMeshDict @@ -145,8 +145,8 @@ castellatedMeshControls { refinementBox { - mode inside; - levels ((1E15 4)); + mode inside; + level 4; } } diff --git a/tutorials/incompressible/simpleFoam/windAroundBuildings/system/snappyHexMeshDict b/tutorials/incompressible/simpleFoam/windAroundBuildings/system/snappyHexMeshDict index 89622b7854..16c3ba586d 100644 --- a/tutorials/incompressible/simpleFoam/windAroundBuildings/system/snappyHexMeshDict +++ b/tutorials/incompressible/simpleFoam/windAroundBuildings/system/snappyHexMeshDict @@ -56,8 +56,8 @@ castellatedMeshControls { refinementBox { - mode inside; - levels ((1E15 2)); + mode inside; + level 2; } } diff --git a/tutorials/mesh/foamyHexMesh/blob/system/snappyHexMeshDict b/tutorials/mesh/foamyHexMesh/blob/system/snappyHexMeshDict index 17ed86632b..e0e393b45e 100644 --- a/tutorials/mesh/foamyHexMesh/blob/system/snappyHexMeshDict +++ b/tutorials/mesh/foamyHexMesh/blob/system/snappyHexMeshDict @@ -145,8 +145,8 @@ castellatedMeshControls { // refinementBox // { -// mode inside; -// levels ((1E15 4)); +// mode inside; +// level 4; // } } diff --git a/tutorials/mesh/foamyHexMesh/flange/system/snappyHexMeshDict b/tutorials/mesh/foamyHexMesh/flange/system/snappyHexMeshDict index 096874477c..71623fd40a 100644 --- a/tutorials/mesh/foamyHexMesh/flange/system/snappyHexMeshDict +++ b/tutorials/mesh/foamyHexMesh/flange/system/snappyHexMeshDict @@ -126,8 +126,8 @@ castellatedMeshControls { refineHole { - mode inside; - levels ((1E15 3)); + mode inside; + level 3; } } diff --git a/tutorials/mesh/snappyHexMesh/flange/system/snappyHexMeshDict b/tutorials/mesh/snappyHexMesh/flange/system/snappyHexMeshDict index 8694697045..f4c609518a 100644 --- a/tutorials/mesh/snappyHexMesh/flange/system/snappyHexMeshDict +++ b/tutorials/mesh/snappyHexMesh/flange/system/snappyHexMeshDict @@ -131,8 +131,8 @@ castellatedMeshControls { refineHole { - mode inside; - levels ((1E15 3)); + mode inside; + level 3; } } diff --git a/tutorials/mesh/snappyHexMesh/pipe/system/snappyHexMeshDict b/tutorials/mesh/snappyHexMesh/pipe/system/snappyHexMeshDict index 41f87f5070..4d903b0656 100644 --- a/tutorials/mesh/snappyHexMesh/pipe/system/snappyHexMeshDict +++ b/tutorials/mesh/snappyHexMesh/pipe/system/snappyHexMeshDict @@ -61,8 +61,8 @@ castellatedMeshControls { pipeWall { - mode insideSpan; - levels ((1000 2)); + mode insideSpan; + level (1000 2); cellsAcrossSpan 40; } } diff --git a/tutorials/multiphase/interFoam/RAS/propeller/system/snappyHexMeshDict b/tutorials/multiphase/interFoam/RAS/propeller/system/snappyHexMeshDict index b06d2bc570..3fcbce8189 100644 --- a/tutorials/multiphase/interFoam/RAS/propeller/system/snappyHexMeshDict +++ b/tutorials/multiphase/interFoam/RAS/propeller/system/snappyHexMeshDict @@ -229,13 +229,13 @@ castellatedMeshControls { innerCylinder { - mode inside; - levels ((1E15 4)); + mode inside; + level 4; } middleCylinder { - mode inside; - levels ((1E15 3)); + mode inside; + level 3; } } diff --git a/tutorials/multiphase/interFoam/laminar/sloshingCylinder/system/snappyHexMeshDict b/tutorials/multiphase/interFoam/laminar/sloshingCylinder/system/snappyHexMeshDict index c237fb9d33..948fcaade4 100644 --- a/tutorials/multiphase/interFoam/laminar/sloshingCylinder/system/snappyHexMeshDict +++ b/tutorials/multiphase/interFoam/laminar/sloshingCylinder/system/snappyHexMeshDict @@ -48,8 +48,8 @@ castellatedMeshControls { sloshingCylinder { - mode inside; - levels ((1E15 1)); + mode inside; + level 1; } }