/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  7
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile {
  version     2.0;
  format      ascii;
  class       volVectorField;
  location    "0/cylinder";
  object      D;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 0 0 0 0 0];

internalField   uniform (0 0 0);

boundaryField {

  consoleFixed
  {
    type    fixedValue;
    value    uniform (0 0 0);
  }

  solid_to_fluid
  {
    type             codedMixed;
    refValue         uniform (0 0 0);
    refGradient      uniform (0 0 0);
    valueFraction    uniform 0;
    name             coupledPressure;

    code
#{
    const fvPatchField<scalar>& mu =
    this->patch().lookupPatchField<volScalarField, scalar>("mu_sM");
    const fvPatchField<scalar>& lambda =
    this->patch().lookupPatchField<volScalarField, scalar>
    (
        "lambda_sM"
    );
    vectorField n(this->patch().nf());
    const fvPatchField<tensor>& gradField =
    this->patch().lookupPatchField<volTensorField, tensor>("gradD");

    const mappedPatchBase& mpp =
    refCast<const mappedPatchBase>(this->patch().patch());
    const polyMesh& nbrMesh = mpp.sampleMesh();

    const label samplePatchI = mpp.samplePolyPatch().index();
    const fvPatch& nbrPatch =
    refCast<const fvMesh>(nbrMesh).boundary()[samplePatchI];

    const fvPatchField<scalar>& nbrField =
    nbrPatch.lookupPatchField
    <
    GeometricField<scalar, fvPatchField, volMesh>,
    scalar
    >
    ("p");
    tmp<Field<scalar>> nbrIntFld
    (
        new Field<scalar>(nbrField.size(), pTraits<scalar>::zero)
    );
    nbrIntFld.ref() = nbrField.patchInternalField();

    const scalar rho = 1; // Reference density. Need to be changed for incompressible
    scalarField pressure = nbrIntFld.ref();
    this->refValue() = Zero;
    this->refGrad() =
    (
        - n*pressure*rho
        - (n & (mu * (twoSymm(gradField) - gradField)
    - (mu + lambda)*gradField))
        - n*lambda*tr(gradField)
    )/(2.0*mu + lambda);
    this->valueFraction() = 0.0;
#};

    codeInclude
#{
#include "mappedPatchBase.H"
#};

    codeOptions
#{
    -I$(LIB_SRC)/meshTools/lnInclude
#};



  }

  frontAndBack
  {
    type            empty;
  }
}


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