#include"BF.h"

int BF::GetNbrBF(int dim, int GeoType, int BFType, int order)
{
	_mDim = dim;
	_mGeoType = GeoType;
	_mBFType = BFType;

	if (dim == ONEDIM)
	{
		if (GeoType == LINE)
		{
			if (order == BF_LINEFUNC)
				_mNbrBF = 2;
			else if (order == BF_QUADFUNC)
				_mNbrBF = 3;
			else
			_mNbrBF = 0;
		}
		else
		{
			_mNbrBF = 0;
		}
	}
	else if (dim == TWODIM)
	{
		if (GeoType == TRIANGLE)
		{
			if ((BFType >= BF_LAGRANGE) && (BFType <= BF_CURL_LAGRANGE))
			{
				order = Limit_Int(order, BF_MIMORDER, BF_MAXORDER);
				_mNbrBF = (order + 1) * (order + 2) / 2;
			}
			else if ((BFType >= BF_NEDELEC) && (BFType <= BF_CURL_NEDELEC))
			{
				order = Limit_Int(order, BF_MIMORDER, BF_MAXORDER);
				_mNbrBF = order * (order + 2);
			}
			else
			{
				_mNbrBF = 0;
			}
		}
		else if (GeoType == QUADRANGLE)
		{
			if ((BFType >= BF_LAGRANGE) && (BFType <= BF_CURL_LAGRANGE))
			{
				_mNbrBF = 0;
				//order = LimitInt(order, BF_MIMORDER, BF_MAXORDER);
			}
			else if ((BFType >= BF_NEDELEC) && (BFType <= BF_CURL_NEDELEC))
			{
				_mNbrBF = 0;
				//order = LimitInt(order, BF_MIMORDER, BF_MAXORDER);
			}
			else
			{
				_mNbrBF = 0;
			}
		}
		else
		{
			_mNbrBF = 0;
		}
	}
	else if (dim == THREEDIM)
	{
		if (GeoType == TETRAHEDRON)
		{
			if ((BFType >= BF_NEDELEC) && (BFType <= BF_CURL_NEDELEC))
			{
				order = Limit_Int(order, BF_MIMORDER, BF_MAXORDER);
				_mNbrBF = order * (order + 2) * (order + 3) / 2;
			}
			else
			{
				_mNbrBF = 0;
			}
		}
		else if (GeoType == PRISM)
		{
			if ((BFType >= BF_NEDELEC) && (BFType <= BF_CURL_NEDELEC))
			{
				order = Limit_Int(order, BF_MIMORDER, BF_MAXORDER);
				_mNbrBF = 3 * order * (order + 1) * (order + 2) / 2;
			}
			else
			{
				_mNbrBF = 0;
			}
		}
		else
		{
			_mNbrBF = 0;
		}
	}
	else
	{
		_mNbrBF = 0;
	}

	_mOrder = order;
	return _mNbrBF;
}

int BF::GetNbrBF()
{
	return _mNbrBF;
}

void BF::GetValueBF(int numBF, double u, double v, double w, Eigen::Vector3d& o)
{
	if (_mDim == ONEDIM)
	{
		if (_mGeoType == LINE)
		{
			if (_mBFType == BF_LAGRANGE)
			{
				BF_Line_Lagrange(_mOrder, numBF, u, v, w, o);
			}
			else if (_mBFType == BF_GRAD_LAGRANGE)
			{
				BF_Line_Grad_Lagrange(_mOrder, numBF, u, v, w, o);
			}
			else if (_mBFType == BF_CURL_LAGRANGE)
			{
				BF_Line_Curl_Lagrange(_mOrder, numBF, u, v, w, o);
			}
		}
	}
	else if (_mDim == TWODIM)
	{
		if (_mGeoType == TRIANGLE)
		{
			if (_mBFType == BF_LAGRANGE)
			{
				BF_Triangle_Lagrange(_mOrder, numBF, u, v, w, o);
			}
			else if (_mBFType == BF_GRAD_LAGRANGE)
			{
				BF_Triangle_Grad_Lagrange(_mOrder, numBF, u, v, w, o);
			}
			else if (_mBFType == BF_CURL_LAGRANGE)
			{
				BF_Triangle_Curl_Lagrange(_mOrder, numBF, u, v, w, o);
			}
			else if (_mBFType == BF_NEDELEC)
			{
				BF_Triangle_Nedelec(_mOrder, numBF, u, v, w, o);
			}
			else if (_mBFType == BF_CURL_NEDELEC)
			{
				BF_Triangle_Curl_Nedelec(_mOrder, numBF, u, v, w, o);
			}
		}
		else if (_mGeoType == QUADRANGLE)
		{

		}
	}
	else if (_mDim == THREEDIM)
	{
		if (_mGeoType == TETRAHEDRON)
		{
			if (_mBFType == BF_NEDELEC)
			{
				BF_Tetrahedron_Nedelec(_mOrder, numBF, u, v, w, o);
			}
			else if (_mBFType == BF_CURL_NEDELEC)
			{
				BF_Tetrahedron_Curl_Nedelec(_mOrder, numBF, u, v, w, o);
			}
		}
		else if (_mGeoType == PRISM)
		{
			if (_mBFType == BF_NEDELEC)
			{
				BF_Prism_Nedelec(_mOrder, numBF, u, v, w, o);
			}
			else if (_mBFType == BF_CURL_NEDELEC)
			{
				BF_Prism_Curl_Nedelec(_mOrder, numBF, u, v, w, o);
			}
		}
	}
}
