/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2012                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    object      p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 2 -2 0 0 0 0];

internalField  uniform 0;

boundaryField
{

    right                  
    {                                              
        // Dirichlet boundary                        
        type        codedFixedValue;                 
        value       uniform 0;                      
                                                   
        name        p_dirichlet;                              
                                                   
        code                                         
        #{                                           
                                                   
            // Gets current patch                      
            const fvPatch& boundaryPatch = patch();    
                                                   
            // Gets the patch face centres values      
            const vectorField& Cf = boundaryPatch.Cf(); 
                                                   
            // Gets the current field                  
            scalarField& field = *this;                         
                                                   
            // MMS                                     
                                                 
            // Loops over the patch                    
            forAll(Cf, faceI)                          
            {                                          
                // Gets the x component of the current cell 
                const scalar x = Cf[faceI].x(); 
                                                 
                const scalar p = 0.5*(1 - Foam::exp(x*(5.0 - 2*Foam::sqrt(6.25 + 4*Foam::pow(M_PI, 2))))); 
                                                 
                field[faceI] = p ;                                       
            }                                          

        #};                                          
    }

    "(left|top|bottom)"  
    {                                              
        // Neumann boundary                          
        type            codedMixed;                  
        refValue        uniform 0;                  
        refGradient     uniform 0;                  
        valueFraction   uniform 0;                   
                                                   
        name        p_Neumann;                              
                                                   
        code                                         
        #{                                           
                                                   
            // Gets current patch                      
            const fvPatch& boundaryPatch = patch();    
                                                   
            // Gets the patch face centres values      
            const vectorField& Cf = boundaryPatch.Cf(); 
                                                   
            const vectorField nf = patch().nf();       
                                                   
            // MMS                                     
                                                   
                                                 
            // Loops over the patch                    
            forAll(this->patch(), faceI)               
            {                                          
                // Gets the x component of the current cell 
                const scalar x = Cf[faceI].x(); 
                                                 
                const scalar tmp0 = 5.0 - 2*Foam::sqrt(6.25 + 4*Foam::pow(M_PI, 2)); 
                const scalar dp_dx = -0.5*tmp0*Foam::exp(tmp0*x); 
                const scalar dp_dy = 0; 
                const scalar dp_dz = 0; 
                                                 

                const vector gradp (dp_dx, dp_dy, dp_dz);   

                const scalar normalGradient = gradp & nf[faceI] ; 
                this->refGrad()[faceI] = normalGradient; 
                this->valueFraction()[faceI] = scalar(0); 
                                                 
            }                                          

        #};                                          
    }

    frontAndBack
    {
        type            empty;
    }
}

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