#include "Sundance.h"

//#define SHOW_MATLAB_DUMP_ERR  // Uncomment to show this error

int main( int argc, char* argv[] )
{

  using Sundance::List;

  const int
    u_basis_dim = 1,
    f_basis_dim = 1;

  Sundance::init(&argc,(void***)&argv);

  double   left    = 0.0;
  double   right   = 1.0;
  double   uRight  = 2.0*log(cosh(right/sqrt(2.0)));
  int      nx      = 2;
  double   bottom  = 0.0;
  double   top     = 1.0;
  int      ny      = 2;
	
  TSFVectorType vst = new DenseSerialVectorType();

  const Expr coord_x_ = new CoordExpr(0);
  const Expr coord_y_ = new CoordExpr(1);

  MeshGenerator mesher = new RectangleMesher(left, right, nx, bottom, top, ny);
  Mesh      mesh_     = mesher.getMesh();
  CellSet   boundary_ = new BoundaryCellSet();
  CellSet   right_    = boundary_.subset( fabs(coord_x_ - right) < 1.0e-10 );

  TSFVectorSpace discreteStateSpace
    = new SundanceVectorSpace(mesh_, new Lagrange(u_basis_dim), vst);

  TSFVectorSpace discreteControlSpace 
    = new SundanceVectorSpace(mesh_, new Lagrange(f_basis_dim), right_, vst);

  Expr u0 = new DiscreteFunction(discreteStateSpace, coord_x_, "u0");

  Expr alpha0 = new DiscreteFunction(discreteControlSpace, uRight, "alpha0");

  MatlabWriter("u_dump.dat").writeField(u0.name(),u0);
#ifdef SHOW_MATLAB_DUMP_ERR
  MatlabWriter("alpha_dump.dat",right_).writeField(alpha0.name(),alpha0);
#endif

  Sundance::finalize();

}

