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

// Volumetric heat source
scalarSemiImplicitSource
{
    type            scalarSemiImplicitSource;
    selectionMode   all;
    volumeMode      specific;
    sources
    {
    	T           ( 1e6 0);
    }
}

convectiveHeatTransferAsVolumeSource
{
    type            scalarCodedSource;
    name            htcHack;

    scalarCodedSourceCoeffs
    {
        selectionMode   all;

        fields          (T);

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

        codeCorrect
        #{
        #};

        codeAddSup
        #{
        	const scalar AoV = 1/0.0002; // 1 / thickness
			const dimensionedScalar Tinf(dimTemperature,  300);
			const volScalarField& Tval = mesh().lookupObject<volScalarField>("T");
			volScalarField htc
	        (
	            IOobject
	            (
	                "htc",
	                mesh().time().timeName(),
	                mesh(),
	                IOobject::NO_READ,
	                IOobject::NO_WRITE
	            ),
	            mesh(),
	            dimensionedScalar("htc", dimless/dimTime,  Zero)
	        );

			// Set internal field, boundaries not needed
			const volVectorField& C = mesh().C(); 
			forAll (htc, cellI)
			{
				scalar r = Foam::sqrt(pow(C[cellI][0], 2) + pow(C[cellI][1], 2)); 
				if (r < 0.025) {
					htc[cellI] = 110; // htc 100+10
				} else {
					htc[cellI] = 20;  // htc 10+10 	
				}
			}
			htc.write();

			const volScalarField htcAoV(htc*AoV);

			// Add source        	
        	eqn +=  htcAoV*Tinf - fvm::Sp(htcAoV, Tval);
			
        #};

        codeConstrain
        #{
        #};
    }
}





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

