#include "Sundance.h"

/**
 * Test of whether we are computing definite integrals correctly. Several
 * parallel bugs were introduced when the FucntionalEvaluator system was added.
 */

int main(int argc, void** argv)
{
  try
    {
      Sundance::init(&argc, &argv);

      /* create a simple mesh on the rectangle */

      int nx = 32;
      int ny = 32;
      int npx = MPIComm::world().getNProc();
      int npy = 1;
			
      MeshGenerator mesher 
        = new PartitionedRectangleMesher(0.0, 1.0, npx*nx, npx, 
                                         0.0, 1.0, npy*ny, npy);
      Mesh mesh = mesher.getMesh();
			

      /* define coordinate functions for x and y coordinates */
      Expr x = new CoordExpr(0);
      Expr y = new CoordExpr(1);

      /* we will take the 2-norm of the function 3.0*x*y over the unit square. 
       * The exact 2-norm is 1.0 */
      Expr f = 3.0*x*y;

      double q = f.norm(2, mesh);

      TSFOut::println("the norm is " + TSF::toString(q));
      
      double errorNorm = fabs(q - 1.0);
      double tolerance = 1.0e-13;
				
      Testing::passFailCheck(__FILE__, errorNorm, tolerance);
    }
  catch(exception& e)
    {
      Sundance::handleError(e, __FILE__);
    }
  Sundance::finalize();
}

