/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  5                                     |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     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
{
    sq
    {
        type triSurfaceMesh;
        file "sq.stl";
/*        transform
        {	
        	coordinateSystem
        	{
        		trpe	cartesian;
        		origin	(0 0 0);
			coordinateRotation 
        		{ 
            		type 	axesRotation; 
            		e1 (1 1 0); 
            		e3 (0 0 1);
            		}
            	}
        }
*/
    }/*
    	ground
        {	
        	type searchableBox;
        	min ( -3 -1 0);
        	max ( 3   1 0.05);
        }*/
     
 	 ground1
        {	
        	type searchableBox;
        	min ( -0.714 -0.5355 0.2);
        	max ( 2.142   0.5355 1.2);
        }
        ground2
        {
        	type searchableBox;
        	min ( -0.714  -0.2856  0.2);
        	max ( 1.428   0.2856  1.2);
        }
 	 ground3
        {	
        	type searchableBox;
        	min ( -0.357 -0.1071 0.2);
        	max ( 0.714   0.1071 1.2);
        }
         /* 
        ground3
        {
        	type searchableBox;
        	min ( -4  4  0);
        	max ( 4   10  0.6);
        }
        ground4
        {
        	type searchableBox;
        	min ( -4  -10  0);
        	max ( 4   4  0.6);
      	 }
    */
    
  /*  refinementBox_tail1
    {
        type searchableBox; //searchableRotatedBox
        min ( -0.5  -0.5  0);
        max ( 0.5   0.5  1);
    }
    refinementBox_tail2
    {
        type searchableBox;
        min ( -0.25  -0.25 0);
        max ( 0.25   0.25  0.7);
    }*/
    /*corner1
    {
        type searchableBox;
        min ( -0.055  -0.055 0.495);
        max ( -0.045   0.055  0.505);
    }
    corner2
    {
        type searchableBox;
        min ( 0.045  -0.055 0.495);
        max ( 0.055   0.055  0.505);
    }*/

 /*    refinementBox_tail3
    {
        type searchableBox;
        min ( -0.15  -0.15  0);
        max ( 0.15   0.15	 0.6);
     }
     refinementBox_tail4
    {
        type searchableBox;
        min ( -0.08  -0.08  0);
        max ( 0.08   0.08	 0.53);
     }
     */
     /*
      refinementBox_tail5
    {
        type searchableBox;
        min ( -0.06  -0.06  0);
        max ( 0.06   0.06	0.51);
     }*/
        
        
       /* sq
        {
            mode distance;
            levels 
            (
                (0.02 5)0.01 5//
                (0.05 4)0.03 4//
                (0.1 3)0.06 3//
                (0.3 2)0.2  2//
                (0.5 1)0.4  1//
            );
        }
*/   
/*
    refinementBox_tail2
    {
        type searchableBox;
        min ( 1  -2.5	 -0.5);
        max ( 10  2.5	  0.5);
    }
    refinementBox_around
    {
        type searchableCylinder;
        point1 ( 0  0	 -0.5);
        point2 ( 0  0	  0.5);
        radius  4;
    }
 */
}



// Settings for the castellatedMesh generation.
castellatedMeshControls
{

    // Refinement parameters
    // ~~~~~~~~~~~~~~~~~~~~~

    // If local number of cells is >= maxLocalCells on any processor
    // switches from from refinement followed by balancing
    // (current method) to (weighted) balancing before refinement.
    maxLocalCells 20000000;

    // Overall cell limit (approximately). Refinement will stop immediately
    // upon reaching this number so a refinement level might not complete.
    // Note that this is the number of cells before removing the part which
    // is not 'visible' from the keepPoint. The final number of cells might
    // actually be a lot less.
    maxGlobalCells 70000000;

    // The surface refinement loop might spend lots of iterations refining just a
    // few cells. This setting will cause refinement to stop if <= minimumRefine
    // are selected for refinement. Note: it will at least do one iteration
    // (unless the number of cells to refine is 0)
    minRefinementCells 5;           /////5

    // Allow a certain level of imbalance during refining
    // (since balancing is quite expensive)
    // Expressed as fraction of perfect balance (= overall number of cells /
    // nProcs). 0=balance always.
    maxLoadUnbalance 0.05;   /////0.1


    // Number of buffer layers between different levels.
    // 1 means normal 2:1 refinement restriction, larger means slower
    // refinement.
    nCellsBetweenLevels 1;///////////////////////////////////////////////////////////////////////was 3



    // Explicit feature edge refinement
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    // Specifies a level for any cell intersected by its edges.
    // This is a featureEdgeMesh, read from constant/triSurface for now.
    features
    (
    );



    // Surface based refinement
    // ~~~~~~~~~~~~~~~~~~~~~~~~

    // Specifies two levels for every surface. The first is the minimum level,
    // every cell intersecting a surface gets refined up to the minimum level.
    // The second level is the maximum level. Cells that 'see' multiple
    // intersections where the intersections make an
    // angle > resolveFeatureAngle get refined up to the maximum level.

    refinementSurfaces
    {
        sq
        {
            // Surface-wise min and max refinement level
            level (4 5);//level (4 4);
           /* regions 
            {
               Face_12 
               { 
                level(5 5) 
               } 
             }
         */
            // Optional specification of patch type (default is wall). No
            // constraint types (cyclic, symmetry) etc. are allowed.
        /*    patchInfo
            {
                type wall;
                inGroups (roof);
            }
         */
        }
    }

    // Resolve sharp angles 
    // angle < resolveFeatureAngle, no refinement
    resolveFeatureAngle 30;//was 60  20  面或边折角小于该角度则会采用上述最大细化等级，否则最小等级，但implicitFeatureSnap要true


    // Region-wise refinement
    // ~~~~~~~~~~~~~~~~~~~~~~

    // Specifies refinement level for cells in relation to a surface. One of
    // three modes
    // - distance. 'levels' specifies per distance to the surface the
    //   wanted refinement level. The distances need to be specified in
    //   descending order.
    // - inside. 'levels' is only one entry and only the level is used. All
    //   cells inside the surface get refined up to the level. The surface
    //   needs to be closed for this to be possible.
    // - outside. Same but cells outside.

    refinementRegions
    {
    /*
    	ground
 	{
            mode inside;
            levels ((1E15 1));
        }*/
    
    	ground1
 	{
            mode inside;
            levels ((1E15 1));
        }
        ground2
 	{
            mode inside;
            levels ((1E15 2));
/*            levelIncrement (0 2 (1 1 0));*/
        }
         ground3
 	{
            mode inside;
            levels ((1E15 3));
        }
        /*
        ground3
 	{
            mode inside;
            levels ((1E15 1));
        }
        ground4
 	{
            mode inside;
            levels ((1E15 1));
        }
*/
	
 /*       refinementBox_tail1
        {
            mode inside;
            levels ((1E15 1));
        }
        refinementBox_tail2
        {
            mode inside;
            levels ((1E15 2));
        }*/
       /* corner1
        {
            mode inside;
            levels ((1E15 6));
        }
        corner2
        {
            mode inside;
            levels ((1E15 6));
        }*/
      /*  refinementBox_tail3
        {
            mode inside;
            levels ((1E15 3));
        }
        
        refinementBox_tail4
        {
            mode inside;
            levels ((1E15 4));
        }
        
  	refinementBox_tail5
        {
            mode inside;
            levels ((1E15 5));
        }*/
        sq
        {
            mode distance;
            levels 
            (	
            (0.01875 4)
             //   (0.025 4)//0.01 5
//                (0.1 3)//0.03 4//
 //               (0.2 2)//0.06 3//
 //               (0.4 1)//0.2  2//
            //    (0.5 1)0.4  1//
            );
        }
/*        
        sq
        {
            mode distance;
            levels 
            (
                (0.02 5)
                (0.1 4)
                (0.2 3)
                (0.4 2)
                (0.6 1)
            );
        }
*/
    }


    // Mesh selection
    // ~~~~~~~~~~~~~~

    // After refinement patches get added for all refinementSurfaces and
    // all cells intersecting the surfaces get put into these patches. The
    // section reachable from the locationInMesh is kept.
    // NOTE: This point should never be on a face, always inside a cell, even
    // after refinement.
    locationInMesh (-0.5 0.8 0.8);


    // Whether any faceZones (as specified in the refinementSurfaces)
    // are only on the boundary of corresponding cellZones or also allow
    // free-standing zone faces. Not used if there are no faceZones.
    allowFreeStandingZoneFaces false;
}



// Settings for the snapping.
snapControls
{
    //- Number of patch smoothing iterations before finding correspondence
    //  to surface
    nSmoothPatch 8;   ////5

    //- Relative distance for points to be attracted by surface feature point
    //  or edge. True distance is this factor times local
    //  maximum edge length.
    tolerance 3.0;

    //- Number of mesh displacement relaxation iterations.
    nSolveIter 250;//for complex model, this value is supposed to be higher.

    //- Maximum number of snapping relaxation iterations. Should stop
    //  before upon reaching a correct mesh.
    nRelaxIter 8;

    // Feature snapping

        //- Number of feature edge snapping iterations.
        //  Leave out altogether to disable.
        nFeatureSnapIter 20;   ///////10

        //- Detect (geometric) features by sampling the surface
        implicitFeatureSnap true;         ////////////////////////////true

        //- Use castellatedMeshControls::features
        explicitFeatureSnap false;             ////////////////////////////false

        //- Detect features between multiple surfaces
        //  (only for explicitFeatureSnap, default = false)
        multiRegionFeatureSnap false;
}



// Settings for the layer addition.
addLayersControls
{
    // Are the thickness parameters below relative to the undistorted
    // size of the refined cell outside layer (true) or absolute sizes (false).
    
    relativeSizes false;//relativeSizes true;

    // Per final patch (so not geometry!) the layer information
    layers
    {
        sq
        {
            nSurfaceLayers 3;//was 10
        }
    }

    // Expansion factor for layer mesh
    expansionRatio 1.05;

    // Wanted thickness of final added cell layer. If multiple layers
    // is the thickness of the layer furthest away from the wall.
    // Relative to undistorted size of cell outside layer.
    // See relativeSizes parameter.
    firstLayerThickness 0.00015;//0.0002,0.0004
  /////////////  finalLayerThickness 0.8;

    // Minimum thickness of cell layer. If for any reason layer
    // cannot be above minThickness do not add layer.
    // Relative to undistorted size of cell outside layer.
    minThickness 0.000001;

    // If points get not extruded do nGrow layers of connected faces that are
    // also not grown. This helps convergence of the layer addition process
    // close to features.
    nGrow 0;


    // Advanced settings

    // When not to extrude surface. 0 is flat surface, 90 is when two faces
    // are perpendicular
    featureAngle 350;   /////180

    // Maximum number of snapping relaxation iterations. Should stop
    // before upon reaching a correct mesh.
    nRelaxIter 20;//was 3 20

    // Number of smoothing iterations of surface normals
    nSmoothSurfaceNormals 20;//3

    // Number of smoothing iterations of interior mesh movement direction
    nSmoothNormals 3;

    // Smooth layer thickness over surface patches
    nSmoothThickness 20;//was 3

    // Stop layer growth on highly warped cells
    maxFaceThicknessRatio 0.5;///////////////////////////////////////////////was 0.5

    // Reduce layer growth where ratio thickness to medial
    // distance is large
    maxThicknessToMedialRatio 0.3;//was 0.3

    // Angle used to pick up medial axis points
    minMedianAxisAngle 90;//5

    // Create buffer region for new layer terminations
    nBufferCellsNoExtrude 0      ;/////////////////0

    // Overall max number of layer addition iterations
    nLayerIter 100;
    nRelaxedIter 10;            /////20

    slipFeatureAngle 20;//20

/*/ for openfoam v20  // not used for of7
    //- Use displacementMotionSolver to shrink mesh
    meshShrinker displacementMotionSolver;

    //- Use laplacian for shrinking
    solver displacementLaplacian;   //solver for dynamic mesh?

    displacementLaplacianCoeffs
    {
        diffusivity quadratic inverseDistance (sq);
    }
*/
}



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

    // Advanced

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


// Advanced

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

writeFlags
(
    scalarLevels
    layerSets
    layerFields
);


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