/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  13
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "system";
    object      createZonesDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

inner
{
    type        union;

    // Create inner baffles along the length of the pipe
    #codeStream
    {
        code
        #{
            const label nBaffles = $<label>blockMeshDict!nBaffles;
            for (label i = 1; i < nBaffles; i += 2)
            {
                const scalar y =
                    scalar(2*i + 1)/(2*nBaffles)*$<scalar>blockMeshDict!height;

                os <<
                    dictionaryEntry
                    (
                        word("baffle" + word(i)),
                        dict,
                        dictionary::entries
                        (
                            "type", "plane",
                            "point", vector(0, y, 0),
                            "normal", vector(0, 1, 0)
                        )
                    );
            }
        #};
    }
}

outer
{
    type        union;

    // Create outer baffles along the length of the pipe
    #codeStream
    {
        code
        #{
            const label nBaffles = $<label>blockMeshDict!nBaffles;
            for (label i = 0; i < nBaffles; i += 2)
            {
                const scalar y =
                    scalar(2*i + 1)/(2*nBaffles)*$<scalar>blockMeshDict!height;

                os <<
                    dictionaryEntry
                    (
                        word("baffle" + word(i)),
                        dict,
                        dictionary::entries
                        (
                            "type", "plane",
                            "point", vector(0, y, 0),
                            "normal", vector(0, 1, 0)
                        )
                    );
            }
        #};
    }
}

// Combine inner and outer baffles into a single zone
baffles
{
    type        union;

    // Cut away the outer portion of the inner baffles
    innerBaffles
    {
        type        annulus;
        zoneType    face;
        select      outside;
        point1      (0 0 0);
        point2      (0 $blockMeshDict!height 0);
        innerRadius $blockMeshDict!innerBaffleOuterRadius;
        outerRadius $blockMeshDict!radius;

        zone        inner;
    }

    // Cut away the outer portion of the inner baffles
    outerBaffles
    {
        type        cylinder;
        zoneType    face;
        select      outside;
        point1      (0 0 0);
        point2      (0 $blockMeshDict!height 0);
        radius      $blockMeshDict!outerBaffleInnerRadius;

        zone        outer;
    }
}

// Remove temporary faceZones
remove
{
    faceZones   (inner outer);
}

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