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

#codeBlock

inner
{
    type        union;

    // Create inner baffles along the length of the pipe
    #codeDict
    {
        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;

                dict.set
                (
                    word("baffle" + name(i)),
                    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
    #codeDict
    {
        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;

                dict.set
                (
                    word("baffle" + name(i)),
                    dictionary::entries
                    (
                        "type", "plane",
                        "point", vector(0, y, 0),
                        "normal", vector(0, 1, 0)
                    )
                );
            }
        #};
    }
}

#endCodeBlock


// 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;
    }
}

print;

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

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