#include "vector.H"
#include "IOstreams.H"

#include "scalar.H"
#include "fvCFD.H"
#include "OFstream.H"

#define FIELDSIZE 4

using namespace Foam;

typedef Field<scalar> binningField;
typedef Field<vector> binningVField;

int main()
{
	
	binningField 	particleBins(FIELDSIZE, 0.0);
	binningVField 	velBins(FIELDSIZE, vector::zero);
	
	for(uint it=0; it<FIELDSIZE; it++)
	{
			particleBins[it] +=it;
			velBins[it]      +=vector(it, it, it);
	}
	
    Info<< vector::zero << endl
        << vector::one << endl
        << vector::dim << endl
        << vector::rank << endl;

    vector d(0.5, 0.5, 0.5);
    d /= mag(d);

    vector dSmall = (1e-100)*d;
    dSmall /= mag(dSmall);

    Info<< (dSmall - d) << endl;

    d *= 4.0;

    Info<< d << endl;

    Info<< d + d << endl;

    Info<< magSqr(d) << endl;

    vector d2(0.5, 0.51, -0.5);
    Info<< cmptMax(d2) << " "
        << cmptSum(d2) << " "
        << cmptProduct(d2) << " "
        << cmptMag(d2)
        << endl;
    Info<< min(d, d2) << endl;
	
Info << "~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
	Info << "particleBins: " << particleBins << endl;
	Info << "particleBins.size(): " << particleBins.size() << endl;
	Info << "sum(particleBins): " << sum(particleBins) << endl;
	Info << "min(particleBins): " << min(particleBins) << endl;
	Info << "max(particleBins): " << max(particleBins) << endl;
	Info << "normalized particleBins: " << particleBins/sum(particleBins) << endl;
	
	Info << "Writing to disk now..." << endl;
	OFstream* sPtrBinLog = new OFstream("binLog.dat");
	*sPtrBinLog << particleBins << endl;
	OFstream* sPtrBinVLog = new OFstream("binVLog.dat");
	*sPtrBinVLog << velBins << endl;
	
    return 0;
}
