示例#1
0
CellSet connectedNodeSet(const CellFilter& f, const Mesh& mesh)
{
  CellSet cells = f.getCells(mesh);
  int dim = cells.dimension();
  if (dim==0) return cells;


  Array<int> cellLID;

  for (CellIterator i=cells.begin(); i!=cells.end(); i++)
  {
    cellLID.append(*i);
  }

  Array<int> nodes;
  Array<int> fo;

  mesh.getFacetLIDs(dim, cellLID, 0, nodes, fo);

  Set<int> nodeSet;

  for (int i=0; i<nodes.size(); i++)
  {
    nodeSet.put(nodes[i]);
  }
  
  return CellSet(mesh, 0, PointCell, nodeSet);
}
示例#2
0
bool PoissonOnDisk()
{
#ifdef HAVE_SUNDANCE_EXODUS

  /* We will do our linear algebra using Epetra */
  VectorType<double> vecType = new EpetraVectorType();

  /* Get a mesh */
  MeshType meshType = new BasicSimplicialMeshType();
  MeshSource meshReader = new ExodusNetCDFMeshReader("disk.ncdf", meshType);
  Mesh mesh = meshReader.getMesh();

  /* Create a cell filter that will identify the maximal cells
   * in the interior of the domain */
  CellFilter interior = new MaximalCellFilter();
  CellFilter bdry = new BoundaryCellFilter();


      
  /* Create unknown and test functions, discretized using first-order
   * Lagrange interpolants */
  Expr u = new UnknownFunction(new Lagrange(1), "u");
  Expr v = new TestFunction(new Lagrange(1), "v");

  /* Create differential operator and coordinate functions */
  Expr dx = new Derivative(0);
  Expr dy = new Derivative(1);
  Expr grad = List(dx, dy);
  Expr x = new CoordExpr(0);
  Expr y = new CoordExpr(1);

  /* We need a quadrature rule for doing the integrations */
  QuadratureFamily quad2 = new GaussianQuadrature(2);
  QuadratureFamily quad4 = new GaussianQuadrature(4);

  /* Define the weak form */
  Expr eqn = Integral(interior, (grad*v)*(grad*u)  + v, quad2);
  /* Define the Dirichlet BC */
  Expr bc = EssentialBC(bdry, v*u, quad4);


  /* We can now set up the linear problem! */
  LinearProblem prob(mesh, eqn, bc, v, u, vecType);

  LinearSolver<double> solver 
    = LinearSolverBuilder::createSolver("amesos.xml");

  Expr soln = prob.solve(solver);

  double R = 1.0;
  Expr exactSoln = 0.25*(x*x + y*y - R*R);

  DiscreteSpace discSpace(mesh, new Lagrange(1), vecType);
  Expr du = L2Projector(discSpace, exactSoln-soln).project();

  /* Write the field in VTK format */
  FieldWriter w = new VTKWriter("PoissonOnDisk");
  w.addMesh(mesh);
  w.addField("soln", new ExprFieldWrapper(soln[0]));
  w.addField("error", new ExprFieldWrapper(du));
  w.write();

      
  Expr errExpr = Integral(interior, 
    pow(soln-exactSoln, 2),
    new GaussianQuadrature(4));

  double errorSq = evaluateIntegral(mesh, errExpr);
  std::cerr << "soln error norm = " << sqrt(errorSq) << std::endl << std::endl;


  /* Check error in automatically-computed cell normals */
  /* Create a cell normal expression. Note that this is NOT a constructor
   * call, hence no "new" before the CellNormalExpr() function. The
   * argument "2" is the spatial dimension (mandatory), and 
   * the "n" is the name of the expression (optional). 
   */
  Expr n = CellNormalExpr(2, "n");
  Expr nExact = List(x, y)/sqrt(x*x + y*y);
  Expr nErrExpr = Integral(bdry, pow(n-nExact, 2.0), new GaussianQuadrature(1));
  double nErrorSq = evaluateIntegral(mesh, nErrExpr);
  Out::root() << "normalVector error norm = " 
              << sqrt(nErrorSq) << std::endl << std::endl;

  double tol = 1.0e-4;
  return SundanceGlobal::checkTest(sqrt(errorSq + nErrorSq), tol);
#else
  std::cout << "dummy PoissonOnDisk PASSED. Enable Exodus to run the actual test" << std::endl;
  return true;
#endif
}
 Expr jacobian() const {return Expr(1.0);}
int main(int argc, char** argv)
{
  try
  {
    /*
     * Initialization code
     */
    std::string meshFile="plateWithHole2D-1";
    std::string solverFile = "nox-aztec.xml";
    Sundance::setOption("meshFile", meshFile, "mesh file");
    Sundance::setOption("solver", solverFile, 
      "name of XML file for solver");

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

    // This next line is just a hack to deal with some 
    // transitional code in the
    // element integration logic. 
    Sundance::ElementIntegral::alwaysUseCofacets() = false;

    /* 
     * Creation of vector type
     */
    VectorType<double> vecType = new EpetraVectorType();

    /* 
     * Creation of mesh
     */
    MeshType meshType = new BasicSimplicialMeshType();
      
    MeshSource meshSrc
      =  new ExodusMeshReader(meshFile, meshType);
    Mesh mesh = meshSrc.getMesh();

    /* 
     * Specification of cell filters
     */
    CellFilter interior = new MaximalCellFilter();
    CellFilter edges = new DimensionalCellFilter(1);

    CellFilter south = edges.labeledSubset(1);
    CellFilter east = edges.labeledSubset(2);
    CellFilter north = edges.labeledSubset(3);
    CellFilter west = edges.labeledSubset(4);

    /* 
     * <Header level="subsubsection" name="symb_setup">
     * Setup of symbolic problem description
     * </Header>
     * 
     * Create unknown and test functions discretized on the space
     * first-order Lagrange polynomials. 
     */
    BasisFamily basis = new Lagrange(2);
    Expr u = new UnknownFunction(basis, "u");
    Expr v = new TestFunction(basis, "v");

    /* 
     * Create differential operators and coordinate functions. Directions
     * are indexed starting from zero. The \verb+List()+ function can 
     * collect expressions into a vector. 
     */
    Expr dx = new Derivative(0);
    Expr dy = new Derivative(1);
    Expr grad = List(dx, dy);

    Expr x = new CoordExpr(0);
    Expr y = new CoordExpr(1);

    /* 
     * We need a quadrature rule for doing the integrations 
     */
    QuadratureFamily quad2 = new GaussianQuadrature(2);
    QuadratureFamily quad4 = new GaussianQuadrature(4);

    /* 
     * Create the weak form and the BCs
     */
    Expr source=exp(u);
    Expr eqn 
      = Integral(interior, (grad*u)*(grad*v)+v*source, quad4);

    Expr h = new CellDiameterExpr();
    Expr bc = EssentialBC(west+east, v*(u-1.0)/h, quad2);

    /* 
     * <Header level="subsubsection" name="lin_prob">
     * Creation of initial guess
     * </Header>
     *
     * So far the setup has been almost identical to that for the linear
     * problem, the only difference being the nonlinear term in the
     * equation set. 
     */
    DiscreteSpace discSpace(mesh, basis, vecType);
    L2Projector proj(discSpace, 1.0);
    Expr u0 = proj.project();

    /* 
     * <Header level="subsubsection" name="lin_prob">
     * Creation of nonlinear problem
     * </Header>
     *
     * Similar to the setup of a \verb+LinearProblem+, the equation, BCs,
     * and mesh are put into a \verb+NonlinearProblem+ object which
     * controls the construction of the \verb+Assembler+ and its use
     * in building Jacobians and residuals during a nonlinear solve.
     */
    NonlinearProblem prob(mesh, eqn, bc, v, u, u0, vecType);

    /*
     *
     */
    
    ParameterXMLFileReader reader(solverFile);
    ParameterList solverParams = reader.getParameters();
    NOXSolver solver(solverParams); 
    
    prob.solve(solver);
    
    /* 
     * Visualization output
     */
    FieldWriter w = new VTKWriter("PoissonBoltzmannDemo2D");
    w.addMesh(mesh);
    w.addField("soln", new ExprFieldWrapper(u0));
    w.write();


    /* 
     * <Header level="subsubsection" name="postproc">
     * Postprocessing
     * </Header>
     *
     * Postprocessing can be done using the same symbolic language
     * as was used for the problem specification. Here, we define
     * an integral giving the flux, then evaluate it on the mesh. 
     */
    Expr n = CellNormalExpr(2, "n");
    Expr fluxExpr 
      = Integral(east + west, (n*grad)*u0, quad2); 
    double flux = evaluateIntegral(mesh, fluxExpr);
    Out::os() << "numerical flux = " << flux << std::endl;
    Expr sourceExpr 
      = Integral(interior, exp(u0), quad4); 
    double src = evaluateIntegral(mesh, sourceExpr);
    Out::os() << "numerical integrated source = " << src << std::endl;


    /*
     * Check that the flux is acceptably close to zero. This
     * is just a sanity check to ensure the code doesn't get completely 
     * broken after a change to the library. 
     */
    Sundance::passFailTest(fabs(flux-src), 1.0e-3);

    /*
     * <Header level="subsubsection" name="finalize">
     * Finalization boilerplate
     * </Header>
     * Finally, we have boilerplate code for exception handling
     * and finalization. 
     */

  }
	catch(std::exception& e) 
  {
    Sundance::handleException(e);
  }
  Sundance::finalize(); return Sundance::testStatus(); 

  return Sundance::testStatus();
}
示例#5
0
int main(int argc, char** argv)
{
  try
		{
      int depth = 0;
      bool useCCode = false;
      Sundance::ElementIntegral::alwaysUseCofacets() = true;
      Sundance::clp().setOption("depth", &depth, "expression depth");
      Sundance::clp().setOption("C", "symb", &useCCode, "Code type (C or symbolic)");
      Sundance::init(&argc, &argv);

      /* We will do our linear algebra using Epetra */
      VectorType<double> vecType = new EpetraVectorType();

      /* Read the mesh */
      MeshType meshType = new BasicSimplicialMeshType();

      MeshSource mesher 
        = new ExodusMeshReader("cube-0.1", meshType);
      Mesh mesh = mesher.getMesh();

      /* Create a cell filter that will identify the maximal cells
       * in the interior of the domain */
      CellFilter interior = new MaximalCellFilter();
      CellFilter faces = new DimensionalCellFilter(2);
      CellFilter side1 = faces.labeledSubset(1);
      CellFilter side2 = faces.labeledSubset(2);
      CellFilter side3 = faces.labeledSubset(3);
      CellFilter side4 = faces.labeledSubset(4);
      CellFilter side5 = faces.labeledSubset(5);
      CellFilter side6 = faces.labeledSubset(6);

      
      /* Create unknown and test functions, discretized using second-order
       * Lagrange interpolants */
      Expr u = new UnknownFunction(new Lagrange(1), "u");
      Expr v = new TestFunction(new Lagrange(1), "v");

      /* Create differential operator and coordinate functions */
      Expr dx = new Derivative(0);
      Expr dy = new Derivative(1);
      Expr dz = new Derivative(2);
      Expr grad = List(dx, dy, dz);
      Expr x = new CoordExpr(0);
      Expr y = new CoordExpr(1);
      Expr z = new CoordExpr(2);

      /* We need a quadrature rule for doing the integrations */
      QuadratureFamily quad2 = new GaussianQuadrature(2);
      QuadratureFamily quad4 = new GaussianQuadrature(4);

      /* Define the weak form */
      //Expr eqn = Integral(interior, (grad*v)*(grad*u) + v, quad);
      
      Expr coeff = 1.0;
#ifdef FOR_TIMING
      if (useCCode)
      {
        coeff = Poly(depth, x);
      }
      else
      {
        for (int i=0; i<depth; i++)
        {
          Expr t = 1.0;
          for (int j=0; j<depth; j++) t = t*x;
          coeff = coeff + 2.0*t - t - t;
        }
      }
#endif
      Expr eqn = Integral(interior, coeff*(grad*v)*(grad*u) /*+ 2.0*v*/, quad2);

      /* Define the Dirichlet BC */
      Expr exactSoln = x;//(x + 1.0)*x - 1.0/4.0;
      Expr h = new CellDiameterExpr();

      WatchFlag watchBC("watch BCs");
      watchBC.setParam("integration setup", 6);
      watchBC.setParam("integration", 6);
      watchBC.setParam("fill", 6);
      watchBC.setParam("evaluation", 6);
      watchBC.deactivate();

      Expr bc = EssentialBC(side4, v*(u-exactSoln), quad4)
        + EssentialBC(side6, v*(u-exactSoln), quad4, watchBC);

      /* We can now set up the linear problem! */
      LinearProblem prob(mesh, eqn, bc, v, u, vecType);

#ifdef HAVE_CONFIG_H
      ParameterXMLFileReader reader(searchForFile("SolverParameters/aztec-ml.xml"));
#else
      ParameterXMLFileReader reader("aztec-ml.xml");
#endif
      ParameterList solverParams = reader.getParameters();
      std::cerr << "params = " << solverParams << std::endl;


      LinearSolver<double> solver 
        = LinearSolverBuilder::createSolver(solverParams);

      Expr soln = prob.solve(solver);

#ifndef FOR_TIMING

      DiscreteSpace discSpace(mesh, new Lagrange(1), vecType);
      L2Projector proj1(discSpace, exactSoln);
      L2Projector proj2(discSpace, soln-exactSoln);
      L2Projector proj3(discSpace, pow(soln-exactSoln, 2.0));
      Expr exactDisc = proj1.project();
      Expr errorDisc = proj2.project();
//      Expr errorSqDisc = proj3.project();

      std::cerr << "writing fields" << std::endl;
      /* Write the field in VTK format */
      FieldWriter w = new VTKWriter("Poisson3d");
      w.addMesh(mesh);
      w.addField("soln", new ExprFieldWrapper(soln[0]));
      w.addField("exact soln", new ExprFieldWrapper(exactDisc));
      w.addField("error", new ExprFieldWrapper(errorDisc));
//      w.addField("errorSq", new ExprFieldWrapper(errorSqDisc));
      w.write();

      std::cerr << "computing error" << std::endl;

      Expr errExpr = Integral(interior, 
                              pow(soln-exactSoln, 2.0),
                              new GaussianQuadrature(4));

      double errorSq = evaluateIntegral(mesh, errExpr);
      std::cerr << "error norm = " << sqrt(errorSq) << std::endl << std::endl;
#else
      double errorSq = 1.0;
#endif
      double tol = 1.0e-10;
      Sundance::passFailTest(sqrt(errorSq), tol);
    }
	catch(std::exception& e)
		{
      Sundance::handleException(e);
		}
  Sundance::finalize(); return Sundance::testStatus(); 
}
示例#6
0
int main(int argc, char** argv)
{
  int stat = 0;
  try
		{
      GlobalMPISession session(&argc, &argv);
      Tabs tabs;
      TimeMonitor timer(totalTimer());

      Expr::showAllParens() = true;

      EvalVector::shadowOps() = true;

      ProductTransformation::optimizeFunctionDiffOps() = true;

      Expr dx = new Derivative(0);
      Expr dy = new Derivative(1);
      Expr dz = new Derivative(2);

      ADField U(ADBasis(1), sqrt(2.0));
      ADField W(ADBasis(2), sqrt(3.0));

      ADCoord X(0);
      ADCoord Y(1);
      ADCoord Z(2);

      ADDerivative Dx(0);
      ADDerivative Dy(1);
      ADDerivative Dz(2);

      ADReal C_old = sin(X)*sin(Y);

			Expr u = new TestUnknownFunction(U, "u");
			Expr w = new TestUnknownFunction(W, "w");

      Expr x = new CoordExpr(0);
      Expr y = new CoordExpr(1);

      Expr p = 2.0*(dx*u) + w;
      Expr q = 2.0*u*w + x*w;
      Expr f = new UserDefOp(List(p, q, x), rcp(new MyFunc()));
      Expr F2 = new UserDefOp(List(p, q, x), rcp(new MyFunc2()));


      ADReal P = 2.0*(Dx*U) + W;
      ADReal Q = 2.0*U*W + X*W;
      ADReal adF = P*sin(Q) + 2.0*P*X;
      ADReal adF2 = (P*sin(Q) + 2.0*P*X)*X + (P*Q*X)*Y;
      


      Array<double> df1(2);
      Array<double> df2(2);
      Array<double> df5(2);
      Array<double> df6(2);

      cout << "============== Function #2: R3 --> R1 =======================" << std::endl;
      cout << "evaluating symb expr, eval1()" << std::endl;
      EvaluationTester fTester2(p*sin(q) + 2.0*p*x, 1);
      double f2 = fTester2.evaluate(df2);
      cout << "value (symb)    = " << f2 << std::endl;
      cout << "deriv (symb)    = " << df2 << std::endl;

      //verbosity<Evaluator>() = 5;
      cout << "evaluating user def expr, eval1()" << std::endl;

      EvaluationTester fTester1(f, 1);
      double f1 = fTester1.evaluate(df1);

      cout << "value (functor) = " << f1 << std::endl;
      cout << "deriv (functor) = " << df1 << std::endl;

      cout << "evaluating symb expr, eval0()" << std::endl;
      EvaluationTester fTester3(p*sin(q) + 2.0*p*x, 0);
      double f3 = fTester3.evaluate();
      cout << "value (symb)    = " << f3 << std::endl;

      cout << "value (AD)      = " << adF.value() << std::endl;


      cout << "evaluating user def expr, eval0()" << std::endl;
      EvaluationTester fTester4(f, 0);
      double f4 = fTester4.evaluate();
      cout << "value (functor)    = " << f4 << std::endl;

      cout << "============== Function #2: R3 --> R2 =======================" << std::endl;
      cout << "evaluating symb expr, eval1()" << std::endl;
      EvaluationTester fTester5(x*(p*sin(q) + 2.0*p*x)+y*(p*q*x), 1);
      double f5 = fTester5.evaluate(df5);
      cout << "value (symb)    = " << f5 << std::endl;
      cout << "deriv (symb)    = " << df5 << std::endl;

      //verbosity<Evaluator>() = 5;
      cout << "evaluating user def expr, eval1()" << std::endl;

      EvaluationTester fTester6(F2*List(x,y), 1);
      double f6 = fTester6.evaluate(df6);

      cout << "value (functor) = " << f6 << std::endl;
      cout << "deriv (functor) = " << df6 << std::endl;

      cout << "evaluating symb expr, eval0()" << std::endl;
      EvaluationTester fTester7((p*sin(q) + 2.0*p*x)*x + y*(p*q*x), 0);
      double f7 = fTester7.evaluate();
      cout << "value (symb)    = " << f7 << std::endl;


      cout << "evaluating user def expr, eval0()" << std::endl;
      EvaluationTester fTester8(F2*List(x,y), 0);
      double f8 = fTester8.evaluate();
      cout << "value (functor)    = " << f8 << std::endl;




      

      double tol = 1.0e-10;

      bool isOK = ::fabs(f2 - f1) < tol;
      isOK = ::fabs(f3-f4) < tol && isOK;
      isOK = ::fabs(f5-f6) < tol && isOK;
      isOK = ::fabs(f7-f8) < tol && isOK;
      for (int i=0; i<df1.size(); i++)
        {
          isOK = isOK && ::fabs(df2[i]-df1[i]) < tol;
          isOK = isOK && ::fabs(df5[i]-df6[i]) < tol;
        }


      if (isOK)
        {
          std::cerr << "all tests PASSED!" << std::endl;
        }
      else
        {
          stat = -1;
          std::cerr << "overall test FAILED!" << std::endl;
        }
      TimeMonitor::summarize();
    }
	catch(std::exception& e)
		{
      stat = -1;
      std::cerr << "overall test FAILED!" << std::endl;
      std::cerr << "detected exception: " << e.what() << std::endl;
		}

  return stat;
}
示例#7
0
int main(int argc, char** argv)
{
  
  try
  {
    GlobalMPISession session(&argc, &argv);

    TimeMonitor t(totalTimer());

    verbosity<SymbolicTransformation>() = 0;
    verbosity<Evaluator>() = 0;
    verbosity<EvalVector>() = 0;
    verbosity<EvaluatableExpr>() = 0;
    Expr::showAllParens() = true;
    ProductTransformation::optimizeFunctionDiffOps() = false;

    EvalVector::shadowOps() = true;

    Expr dx = new Derivative(0);
    Expr dy = new Derivative(1);
    Expr grad = List(dx, dy);

    Expr u = new UnknownFunctionStub("u");
    Expr lambda_u = new UnknownFunctionStub("lambda_u");
    Expr T = new UnknownFunctionStub("T");
    Expr lambda_T = new UnknownFunctionStub("lambda_T");
    Expr alpha = new UnknownParameter("alpha");

    Expr u0 = new DiscreteFunctionStub("u0");
    Expr lambda_u0 = new DiscreteFunctionStub("lambda_u0");
    Expr T0 = new DiscreteFunctionStub("T0");
    Expr lambda_T0 = new DiscreteFunctionStub("lambda_T0");
    Expr zero = new ZeroExpr();
    Expr alpha0 = new Parameter(3.14, "alpha0");

    Expr x = new CoordExpr(0);
    Expr y = new CoordExpr(1);

    Expr empty;

    Array<Expr> tests;

//#define BLAHBLAH 1
#ifdef BLAHBLAH
    verbosity<Evaluator>() = 5;
    verbosity<SparsitySuperset>() = 5;
    verbosity<EvaluatableExpr>() = 5;
#endif

    tests.append( 0.5*(u-1.404)*(u-1.404)
      + 0.5*(grad*u)*(grad*u)
      + 0.5*alpha*alpha
      + (grad*lambda_u)*(grad*u)
      + lambda_u*alpha);


    std::cerr << std::endl << "============== u STATE EQUATIONS =================" << std::endl;

    for (int i=0; i<tests.length(); i++)
    {
      RegionQuadCombo rqc(rcp(new CellFilterStub()), 
        rcp(new QuadratureFamilyStub(1)));
      EvalContext context(rqc, makeSet(1,2), EvalContext::nextID());
      testVariations(tests[i], 
        List(lambda_u),
        List(zero),
        List(u),
        List(u0),
        empty,
        empty,
        empty,
        empty,
        alpha,
        alpha0,
        context);
    }

    std::cerr << std::endl << "=============== u ADJOINT EQUATIONS =================" << std::endl;
    for (int i=0; i<tests.length(); i++)
    {
      RegionQuadCombo rqc(rcp(new CellFilterStub()), 
        rcp(new QuadratureFamilyStub(1)));
      EvalContext context(rqc, makeSet(1,2), EvalContext::nextID());
      testVariations(tests[i], 
        List(u),
        List(u0),
        List(lambda_u),
        List(zero),
        empty,
        empty,
        empty,
        empty,
        alpha,
        alpha0,
        context);
    }


    std::cerr << std::endl << "================ REDUCED GRADIENT ====================" << std::endl;
    for (int i=0; i<tests.length(); i++)
    {
      RegionQuadCombo rqc(rcp(new CellFilterStub()), 
        rcp(new QuadratureFamilyStub(1)));
      EvalContext context(rqc, makeSet(0,1), EvalContext::nextID());
      testGradient(tests[i], 
        alpha, 
        alpha0,
        empty,
        empty,
        List(u, lambda_u),
        List(u0, zero),
        context);
    }

    std::cerr << std::endl << "=================== FUNCTIONAL ====================" << std::endl;
    for (int i=0; i<tests.length(); i++)
    {
      RegionQuadCombo rqc(rcp(new CellFilterStub()), 
        rcp(new QuadratureFamilyStub(1)));
      EvalContext context(rqc, makeSet(0), EvalContext::nextID());
      testFunctional(tests[i], 
        alpha,
        alpha0,
        List(u, lambda_u),
        List(u0, zero),
        context);
    }

    std::cerr << std::endl << "=================== ALL-AT-ONCE ====================" << std::endl;
    for (int i=0; i<tests.length(); i++)
    {
      RegionQuadCombo rqc(rcp(new CellFilterStub()), 
        rcp(new QuadratureFamilyStub(1)));
      EvalContext context(rqc, makeSet(1,2), EvalContext::nextID());
      testVariations(tests[i], 
        List(lambda_u, u, alpha), 
        List(zero, zero, zero), 
        List(lambda_u, u, alpha), 
        List(lambda_u0, u0, alpha0), 
        empty,
        empty,
        empty,
        empty,
        empty,
        empty,
        context);
      
    }
    TimeMonitor::summarize();
  }
	catch(std::exception& e)
  {
    Out::println(e.what());
  }


  
}
bool NonlinReducedIntegration()
{
  int np = MPIComm::world().getNProc();

  int n = 4;
  bool increaseProbSize = true;
  if ( (np % 4)==0 ) increaseProbSize = false;

  Array<double> h;
  Array<double> errQuad;
  Array<double> errReduced;

  for (int i=0; i<4; i++)
  {
    n *= 2;
    int nx = n;
    int ny = n;

    VectorType<double> vecType = new EpetraVectorType();

    MeshType meshType = new BasicSimplicialMeshType();
      
    int npx = -1;
    int npy = -1;
    PartitionedRectangleMesher::balanceXY(np, &npx, &npy);
    TEUCHOS_TEST_FOR_EXCEPT(npx < 1);
    TEUCHOS_TEST_FOR_EXCEPT(npy < 1);
    TEUCHOS_TEST_FOR_EXCEPT(npx * npy != np);
    if (increaseProbSize)
    {
      nx = nx*npx;
      ny = ny*npy;
    }
    MeshSource mesher = new PartitionedRectangleMesher(0.0, 1.0, nx, npx, 
      0.0,  1.0, ny, npy, meshType);
    Mesh mesh = mesher.getMesh();


    WatchFlag watchMe("watch eqn");
    watchMe.setParam("integration setup", 0);
    watchMe.setParam("integration", 0);
    watchMe.setParam("fill", 0);
    watchMe.setParam("evaluation", 0);
    watchMe.deactivate();

    WatchFlag watchBC("watch BCs");
    watchBC.setParam("integration setup", 0);
    watchBC.setParam("integration", 0);
    watchBC.setParam("fill", 0);
    watchBC.setParam("evaluation", 0);
    watchBC.deactivate();
    


    CellFilter interior = new MaximalCellFilter();
    CellFilter edges = new DimensionalCellFilter(1);

    CellFilter left = edges.subset(new CoordinateValueCellPredicate(0,0.0));
    CellFilter right = edges.subset(new CoordinateValueCellPredicate(0,1.0));
    CellFilter top = edges.subset(new CoordinateValueCellPredicate(1,1.0));
    CellFilter bottom = edges.subset(new CoordinateValueCellPredicate(1,0.0));

    BasisFamily basis = new Lagrange(1);
    Expr u = new UnknownFunction(basis, "u");
    Expr v = new TestFunction(basis, "v");

    Expr dx = new Derivative(0);
    Expr dy = new Derivative(1);
    Expr grad = List(dx, dy);
    Expr x = new CoordExpr(0);
    Expr y = new CoordExpr(1);

    QuadratureFamily quad = new ReducedQuadrature();
    QuadratureFamily quad2 = new GaussianQuadrature(2);

    /* Define the weak form */
    const double pi = 4.0*atan(1.0);

    Expr c = cos(pi*x);
    Expr s = sin(pi*x);
    Expr ch = cosh(y);
    Expr sh = sinh(y);
    Expr s2 = s*s; 
    Expr c2 = c*c;
    Expr sh2 = sh*sh;
    Expr ch2 = ch*ch;
    Expr pi2 = pi*pi;
    Expr uEx = s*ch;
    Expr eu = exp(uEx);
    Expr f = -(ch*eu*(-1 + pi2)*s) + ch2*(c2*eu*pi2 - s2) + eu*s2*sh2;

    Expr eqn = Integral(interior, exp(u)*(grad*u)*(grad*v)
      + v*f + v*u*u, quad, watchMe)
      + Integral(right, v*exp(u)*pi*cosh(y), quad,watchBC);
    /* Define the Dirichlet BC */
    Expr bc = EssentialBC(left+top, v*(u-uEx), quad, watchBC);

    Expr eqn2 = Integral(interior, exp(u)*(grad*u)*(grad*v)
      + v*f + v*u*u, quad2, watchMe)
      + Integral(right, v*exp(u)*pi*cosh(y), quad2,watchBC);
    /* Define the Dirichlet BC */
    Expr bc2 = EssentialBC(left+top, v*(u-uEx), quad2, watchBC);


    DiscreteSpace discSpace(mesh, new Lagrange(1), vecType);
    Expr soln1 = new DiscreteFunction(discSpace, 0.0, "u0");
    Expr soln2 = new DiscreteFunction(discSpace, 0.0, "u0");
    L2Projector proj(discSpace, uEx);
    Expr uEx0 = proj.project();

    NonlinearProblem nlp(mesh, eqn, bc, v, u, soln1, vecType);
    NonlinearProblem nlp2(mesh, eqn2, bc2, v, u, soln2, vecType);
    
    ParameterXMLFileReader reader("nox-aztec.xml");
    ParameterList noxParams = reader.getParameters();
    NOXSolver solver(noxParams);
    nlp.solve(solver);
    nlp2.solve(solver);

    FieldWriter w = new VTKWriter("NonlinReduced-n" + Teuchos::toString(n));
    w.addMesh(mesh);
    w.addField("soln1", new ExprFieldWrapper(soln1[0]));
    w.addField("soln2", new ExprFieldWrapper(soln2[0]));
    w.addField("exact", new ExprFieldWrapper(uEx0[0]));
    w.write();

    Expr err1 = uEx - soln1;
    Expr errExpr1 = Integral(interior, 
      err1*err1,
      new GaussianQuadrature(4));

    Expr err2 = uEx - soln2;
    Expr errExpr2 = Integral(interior, 
      err2*err2,
      new GaussianQuadrature(4));

    Expr err12 = soln2 - soln1;
    Expr errExpr12 = Integral(interior, 
      err12*err12,
      new GaussianQuadrature(4));
      
    double error1 = ::sqrt(evaluateIntegral(mesh, errExpr1));
    double error2 = ::sqrt(evaluateIntegral(mesh, errExpr2));
    double error12 = ::sqrt(evaluateIntegral(mesh, errExpr12));

    Out::root() << "final result: " << n << " "  << error1 << " " << error2 << " " << error12
                << endl;
        
    h.append(1.0/((double) n));
    errQuad.append(error2);
    errReduced.append(error1);
  }
    
  double pQuad = fitPower(h, errQuad);
  double pRed = fitPower(h, errReduced);
  Out::root() << "exponent (reduced integration) " << pRed << endl;
  Out::root() << "exponent (full integration) " << pQuad << endl;
    

  return SundanceGlobal::checkTest(::fabs(pRed-2.0), 0.1);

}