// Construct from components
Foam::repatchCoverage::repatchCoverage
(
    const word& name,
    const label index,
    const polyTopoChanger& mme,
    const word& masterCoveredPatchName,
    const word& masterUncoveredPatchName,
    const word& slaveCoveredPatchName,
    const word& slaveUncoveredPatchName,
    const scalar repatchThreshold
)
:
    polyMeshModifier(name, index, mme, true),
    masterCoveredPatchID_(masterCoveredPatchName, mme.mesh().boundaryMesh()),
    masterUncoveredPatchID_
    (
        masterUncoveredPatchName,
        mme.mesh().boundaryMesh()
    ),
    slaveCoveredPatchID_(slaveCoveredPatchName, mme.mesh().boundaryMesh()),
    slaveUncoveredPatchID_
    (
        slaveUncoveredPatchName,
        mme.mesh().boundaryMesh()
    ),
    repatchThreshold_
    (
        Foam::max(SMALL, Foam::min(repatchThreshold, 1 - SMALL))
    ),
    uncMaster_(),
    uncSlave_()
{
    checkDefinition();
}
void Check_PriorDeclaration_Base::addDefList(
        const AST_BaseDeclaration::vec_shared_ptr &defList)
{
    for(
        AST_BaseDeclaration::vec_shared_ptr::const_iterator it = defList.begin();
        it != defList.end();
        ++it)
    {
        const AST_BaseDeclaration::shared_ptr& varIncomingDecl = *it;
        checkDefinition(varIncomingDecl);
    }
}
// Construct from components
Foam::repatchCoverage::repatchCoverage
(
    const word& name,
    const dictionary& dict,
    const label index,
    const polyTopoChanger& mme
)
:
    polyMeshModifier(name, index, mme, Switch(dict.lookup("active"))),
    masterCoveredPatchID_
    (
        dict.lookup("masterCoveredPatchName"),
        mme.mesh().boundaryMesh()
    ),
    masterUncoveredPatchID_
    (
        dict.lookup("masterUncoveredPatchName"),
        mme.mesh().boundaryMesh()
    ),
    slaveCoveredPatchID_
    (
        dict.lookup("slaveCoveredPatchName"),
        mme.mesh().boundaryMesh()
    ),
    slaveUncoveredPatchID_
    (
        dict.lookup("slaveUncoveredPatchName"),
        mme.mesh().boundaryMesh()
    ),
    repatchThreshold_
    (
        Foam::max
        (
            SMALL,
            Foam::min(readScalar(dict.lookup("repatchThreshold")), 1 - SMALL)
        )
    ),
    uncMaster_(),
    uncSlave_()
{
    checkDefinition();
}
// Construct from dictionary
Foam::layerAdditionRemoval::layerAdditionRemoval
(
    const word& name,
    const dictionary& dict,
    const label index,
    const polyTopoChanger& mme
)
:
    polyMeshModifier(name, index, mme, Switch(dict.lookup("active"))),
    faceZoneID_(dict.lookup("faceZoneName"), mme.mesh().faceZones()),
    minLayerThickness_(readScalar(dict.lookup("minLayerThickness"))),
    maxLayerThickness_(readScalar(dict.lookup("maxLayerThickness"))),
    oldLayerThickness_(readOldThickness(dict)),
    pointsPairingPtr_(NULL),
    facesPairingPtr_(NULL),
    triggerRemoval_(-1),
    triggerAddition_(-1)
{
    checkDefinition();
}
// Construct from components
Foam::layerAdditionRemoval::layerAdditionRemoval
(
    const word& name,
    const label index,
    const polyTopoChanger& mme,
    const word& zoneName,
    const scalar minThickness,
    const scalar maxThickness
)
:
    polyMeshModifier(name, index, mme, true),
    faceZoneID_(zoneName, mme.mesh().faceZones()),
    minLayerThickness_(minThickness),
    maxLayerThickness_(maxThickness),
    oldLayerThickness_(-1.0),
    pointsPairingPtr_(NULL),
    facesPairingPtr_(NULL),
    triggerRemoval_(-1),
    triggerAddition_(-1)
{
    checkDefinition();
}
void Foam::cyclicGgiPolyPatch::calcTransforms() const
{
    if (active() && debug)
    {
        // Check definition of the cyclic pair
        checkDefinition();
    }

    // For computing the rotation tensors forwardT and reverseT, we
    // can see from Robert Magnan's post on the Forum dated
    // 27/May/2008 that we cannot use the actual implementation of
    // calcTransformTensors and rotationTensor.
    //
    // It is also not possible to use Robert solution because for
    // non-conformal cyclic meshes, we cannot usualy find a pair of
    // matching faces for computing the tensors. So we are using
    // user-supplied values instead.
    //
    // Since these tensors are defined as private in the
    // coupledPolyPatch class definition, we will override these
    // values here and compute the tensors ourselves using the
    // Rodrigues Rotation formula.

    // We compute the rotationTensor from rotationAxis_ and
    // rotationAngle_ We compute the separation vector from
    // separationOffset_

    // All transforms are constant: size = 1.  HJ, 18/Feb/2009

    if (mag(rotationAngle_) > SMALL)
    {
        // Rotation tensor computed from rotationAxis_ and rotationAngle_
        // Note: cyclics already have opposing signs for the rotation
        //       so there is no need for a special practice.  HJ, 30/Jun/2009
        forwardT_ = tensorField
        (
            1,
            RodriguesRotation(rotationAxis_,  -rotationAngle_)
        );

        reverseT_ = tensorField
        (
            1,
            RodriguesRotation(rotationAxis_, rotationAngle_)
        );
    }
    else
    {
        forwardT_.setSize(0);
        reverseT_.setSize(0);
    }

    // Handling the separation offset separatly
    if (mag(separationOffset_) > SMALL)
    {
        separation_ = vectorField(1, separationOffset_);
    }
    else
    {
        separation_.setSize(0);
    }

    if (debug > 1 && master())
    {
        if (patchToPatch().uncoveredMasterFaces().size() > 0)
        {
            // Write uncovered master faces
            Info<< "Writing uncovered master faces for patch "
                << name() << " as VTK." << endl;

            const polyMesh& mesh = boundaryMesh().mesh();

            fileName fvPath(mesh.time().path()/"VTK");
            mkDir(fvPath);

            indirectPrimitivePatch::writeVTK
            (
                fvPath/fileName("uncoveredCyclicGgiFaces" + name()),
                IndirectList<face>
                (
                    localFaces(),
                    patchToPatch().uncoveredMasterFaces()
                ),
                localPoints()
            );
        }

        if (patchToPatch().uncoveredSlaveFaces().size() > 0)
        {
            // Write uncovered master faces
            Info<< "Writing uncovered shadow faces for patch "
                << shadowName() << " as VTK." << endl;

            const polyMesh& mesh = boundaryMesh().mesh();

            fileName fvPath(mesh.time().path()/"VTK");
            mkDir(fvPath);

            indirectPrimitivePatch::writeVTK
            (
                fvPath/fileName("uncoveredCyclicGgiFaces" + shadowName()),
                IndirectList<face>
                (
                    shadow().localFaces(),
                    patchToPatch().uncoveredSlaveFaces()
                ),
                shadow().localPoints()
            );
        }

        // Check for bridge overlap
        if (!bridgeOverlap())
        {
            if
            (
                patchToPatch().uncoveredMasterFaces().size() > 0
             || patchToPatch().uncoveredSlaveFaces().size() > 0
            )
            {
                FatalErrorIn("label cyclicGgiPolyPatch::shadowIndex() const")
                    << "cyclic ggi patch " << name() << " with shadow "
                    << shadowName() << " has "
                    << patchToPatch().uncoveredMasterFaces().size()
                    << " uncovered master faces and "
                    << patchToPatch().uncoveredSlaveFaces().size()
                    << " uncovered slave faces.  Bridging is switched off. "
                    << abort(FatalError);
            }
        }
    }
}