// Reading adjoint properties
IOdictionary adjDict
(
    IOobject
    (
        "adjointProperties",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ,
         IOobject::NO_WRITE
     )
 );

word patchName = adjDict.lookup("patchName");
label patchID = mesh.boundaryMesh().findPatchID(patchName);
bool maxDisplacement = adjDict.lookupOrDefault<bool>("maxDisplacement",false);
scalar eta = adjDict.lookupOrDefault<scalar>("eta",1.);

volScalarField sens
(
    IOobject
    (
        "sens",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    mesh
);

const scalarField& sensb = sens.boundaryField()[patchID];
if(maxDisplacement)
{
    eta = eta/(max(max(sensb),-min(sensb)));
}

Info << "Using eta: " << eta << endl;

volVectorField displacement
(   
    IOobject
    (
        "displacement",
        mesh.time().timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE,
        false
    ),
    mesh,
    dimensionedVector("dist",dimensionSet(0,1,0,0,0,0,0),vector::zero),
    "fixedValue"
);  

displacement.boundaryField()[patchID] == mesh.boundary()[patchID].nf() 
                                      * sensb * eta;

dimensionedScalar epsilon 
(
    adjDict.lookup("epsilon")
);

surfaceScalarField diffusion
(
    IOobject
    (
        "diffusion",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    mesh,
    epsilon
);

const pointMesh& pMesh = pointMesh::New(mesh);

volPointInterpolation vpi(mesh);

pointVectorField pDisplacement
(   
    IOobject
    (
        "pointDisplacement",
        mesh.time().timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE,
        false
    ),
    pMesh,
    dimensionedVector("vector", dimensionSet(0,1,0,0,0,0,0), vector::zero)
);

