/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2412                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      snappyHexMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Which of the steps to run
castellatedMesh true;
snap            true;
addLayers       true;


// Geometry. Definition of all surfaces. All surfaces are of class
// searchableSurface.
// Surfaces are used
// - to specify refinement for any mesh cell intersecting it
// - to specify refinement for any mesh cell inside/outside/near
// - to 'snap' the mesh boundary to the surface
geometry
{
    whole.stl
    {
        type triSurfaceMesh;
        name whole;

        regions
        {
            inlet_one
            {
                name inlet_one;
            }
            inlet_two
            {
                name inlet_two;
            }
            inlet_three
            {
                name inlet_three;
            }
            inlet_four
            {
                name inlet_four;
            }
            cold_outlet
            {
                name cold_outlet;
            }
            hot_outlet
            {
                name hot_outlet;
            }
            wall
            {
                name wall;
            }
            
        }
    }

    refinementBox
    {
        type            searchableCylinder;
        point1          (0 0 -15);
        point2          (0 0 105);
        radius          4;
    }
}


// Settings for the castellatedMesh generation.
castellatedMeshControls
{

    maxLocalCells 2000000;

    maxGlobalCells 10000000;

    minRefinementCells 0;

    maxLoadUnbalance 0.10;

    nCellsBetweenLevels 3;

    features
    (   
        {
            file "whole.eMesh";
            level  4;
        }

        {
            file "base.eMesh";
            level  6;
        }
    );


    refinementSurfaces
    {
        whole
        {
            level (2 2);

            regions
            {
                wall
                {
                    level (2 3);

                    patchInfo
                    {
                        type wall;
                    }
                }
                cold_outlet
                {
                    level (2 3);

                    patchInfo
                    {
                        type patch;
                    }
                }
                inlet_one
                {
                    level (2 3);

                    patchInfo
                    {
                        type patch;
                    }
                }
                inlet_two
                {
                    level (2 3);

                    patchInfo
                    {
                        type patch;
                    }
                }
                inlet_three
                {
                    level (2 3);

                    patchInfo
                    {
                        type patch;
                    }
                }
                inlet_four
                {
                    level (2 3);

                    patchInfo
                    {
                        type patch;
                    }
                }
                hot_outlet
                {
                    level (2 3);

                    patchInfo
                    {
                        type patch;
                    }
                }
            }
        }
        
    }

    resolveFeatureAngle 10;

    refinementRegions
    {
       refinementBox
        {
            mode inside;
            levels ((2 2));
        }
    }

    locationInMesh (0 0 50);

    allowFreeStandingZoneFaces true;
}



// Settings for the snapping.
snapControls
{
    
    nSmoothPatch 3;

    tolerance 2;

    nSolveIter 300;

    nRelaxIter 25;

    // Feature snapping

        nFeatureSnapIter 50;

        implicitFeatureSnap false;

        explicitFeatureSnap true;

        multiRegionFeatureSnap false;
}



// Settings for the layer addition.
addLayersControls
{
    
    relativeSizes true;

    layers
    {
        wall
        {
            nSurfaceLayers 5 ;
        }
    }

    expansionRatio 1.2;

    firstLayerThickness 0.02;

    minThickness 0.003;

    nGrow 0;

    featureAngle 150;

    slipFeatureAngle 30;

    nRelaxIter 5;

    nSmoothSurfaceNormals 1;

    nSmoothNormals 3;

    nSmoothThickness 10;

    maxFaceThicknessRatio 0.5;

    maxThicknessToMedialRatio 0.3;

    minMedialAxisAngle 90;

    nBufferCellsNoExtrude 0;

    nLayerIter 50;
}



// Generic mesh quality settings. At any undoable phase these determine
// where to undo.
meshQualityControls
{
    #include "meshQualityDict"

    // Advanced

    //- Number of error distribution iterations
    nSmoothScale 4;
    //- Amount to scale back displacement at error points
    errorReduction 0.75;
}


debugFlags
(
    //mesh            // write intermediate meshes
    //intersections   // write current mesh intersections as .obj files
    //featureSeeds    // write information about explicit feature edge
                    // refinement
    //attraction      // write attraction as .obj files
    //layerInfo       // write information about layers
);


// Advanced

debug 1; 

// Write flags
writeFlags
(
    scalarLevels
    layerSets
    layerFields     // write volScalarField for layer coverage
);


// Merge tolerance. Is fraction of overall bounding box of initial mesh.
// Note: the write tolerance needs to be higher than this.
mergeTolerance 1e-6;


// ************************************************************************* //
