/*--------------------------------*- C++ -*----------------------------------*\

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

castellatedMesh true;
snap            true;
addLayers       true;


geometry
{
	20260430_CRC1615_C01_Gyroid-TPnS_0_CFD.stl{ type triSurfaceMesh; name latticeStructure; scale 0.001;}
}

castellatedMeshControls
{
	maxLocalCells 1000000;
	maxGlobalCells 100000000;
	minRefinementCells 0;
	maxLoadUnbalance 0.10;
	nCellsBetweenLevels 4;

	features
	(
		{ file "20260430_CRC1615_C01_Gyroid-TPnS_0_CFD.eMesh"; level 4;}
	);

	refinementSurfaces
	{	
		latticeStructure{ level (3 4);}
    }

    refinementRegions
    {
        latticeStructure
        {
            mode        distance;
            levels
            (
                (1.50e-4 3)
                (6.00e-4 2)
         	);
        }
    }

    resolveFeatureAngle 45;

    locationInMesh (0 0 1e-3);
    allowFreeStandingZoneFaces false;
}

snapControls
{
    nSmoothPatch 5; // 3
    tolerance 2.0;
    nSolveIter 40;
    nRelaxIter 5;
    nFeatureSnapIter 10;
    implicitFeatureSnap false;
    explicitFeatureSnap true;
    multiRegionFeatureSnap false;
}

addLayersControls
{
    relativeSizes true; // false

    layers
    {
        latticeStructure{ nSurfaceLayers 5;
                finalLayerThickness 0.2;
              }
    }

	expansionRatio 1.2;
	finalLayerThickness 0.3;

	// Minimum overall thickness of total layers. If for any reason layer
	// cannot be above minThickness do not add layer
	// If relativeSizes this is relative to undistorted size of cell 
	// outside layer..
	minThickness 0.1;

	// BL advanced settings - Quality parameters - A game of numbers

	nGrow 0; // Generally recommended to switch off gradual layer termination for nOuterIter

	featureAngle 150;		// recommended 130
	//featureAngle 330;		// improved

	maxFaceThicknessRatio 0.5; // 0.5

	//slipFeatureAngle 30;		// 0.5*featureAngle

	nSmoothSurfaceNormals 2; // 1
	nSmoothNormals 3;
	nSmoothThickness 10; // 10

	maxThicknessToMedialRatio 0.7;	//0.3 - 0.6

	minMedialAxisAngle 90;

	//nMedialAxisIter 10;

	nBufferCellsNoExtrude 0;

	//nSmoothDisplacement 0;
	//detectExtrusionIsland 0;

	nLayerIter 50;		//******* Disable quality check 50
	nRelaxedIter 50;
	nRelaxIter 20;	// 5

	nOuterIter 10; // Higher -> more layers, lower -> faster process
}

meshQualityControls
{
    maxNonOrtho 70;
    maxBoundarySkewness 20;
    maxInternalSkewness 4;
    maxConcave 80;
    minVol -1e30;
    minTetQuality -1e30;
    minArea 1e-30; // -1
    minTwist 0.02; // 0.02
    minDeterminant 0.001;
    minFaceWeight 0.05; // 0.05
    minVolRatio 0.01;
    minTriangleTwist -1;
    nSmoothScale 4;
    errorReduction 0.75;
}
writeFlags
(
    scalarLevels
    layerSets
    layerFields
);
mergeTolerance 1e-6;


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