Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "Sundance.hpp"
00044 #include "SundanceProblemTesting.hpp"
00045
00046
00047 class NitschePoisson2DTest : public LPRectTestBase
00048 {
00049 public:
00050
00051 NitschePoisson2DTest(const Array<int>& n, int k, double C)
00052 : LPRectTestBase(n), k_(k), C_(C) {}
00053
00054
00055 std::string name() const {return "NitschePoisson2D";}
00056
00057
00058 Expr exactSoln() const
00059 {
00060 Expr x = new CoordExpr(0);
00061 Expr y = new CoordExpr(1);
00062 const double pi = 4.0*atan(1.0);
00063 return cos(pi*x/2.0)*sin(pi*y);
00064 }
00065
00066
00067 Array<int> pExpected() const {return tuple<int>(k_+1);}
00068
00069
00070 LinearProblem prob(const Mesh& mesh) const
00071 {
00072 Expr dx = new Derivative(0);
00073 Expr dy = new Derivative(1);
00074 Expr x = new CoordExpr(0);
00075 Expr y = new CoordExpr(1);
00076 Expr grad = List( dx , dy );
00077
00078 CellFilter allBdry = domain().north() + domain().south()
00079 + domain().east() + domain().west();
00080
00081 BasisFamily L = new Lagrange( k_ );
00082
00083 Expr u = new UnknownFunction( L , "u" );
00084 Expr v = new TestFunction( L , "v" );
00085 QuadratureFamily quad = new GaussianQuadrature( 2 * k_ );
00086
00087 const double pi = 4.0*atan(1.0);
00088 Expr force = 1.25*pi*pi*cos(pi*x/2.0)*sin(pi*y);
00089 Expr eqn = Integral( interior(),
00090 (grad*v) * (grad*u) - force * v , quad )
00091 + NitschePoissonDirichletBC(2, allBdry, quad,
00092 1.0, v, u, exactSoln(), C_);
00093
00094
00095 Expr bc;
00096
00097 return LinearProblem(mesh, eqn, bc, v, u, vecType());
00098 }
00099
00100
00101
00102
00103 Array<LPTestSpec> specs() const
00104 {
00105 double tol = 0.05;
00106 return tuple(
00107 LPTestSpec("amesos.xml", tol, makeSet<int>(1))
00108
00109
00110
00111
00112 );
00113 }
00114
00115 void postRunCallback(int meshID, const Mesh& mesh,
00116 const string& solverFile,
00117 const Expr& soln) const
00118 {
00119 string solverName = StrUtils::before(solverFile, ".");
00120 string file = "NitschePoisson2D-mesh-" + Teuchos::toString(meshID)
00121 + "-" + solverName + "-p-" + Teuchos::toString(k_)
00122 + "-C-" + Teuchos::toString(C_);
00123
00124 DiscreteSpace discSpace(mesh, new Lagrange(1), vecType());
00125 Expr uEx = exactSoln();
00126 L2Projector proj(discSpace, soln - uEx);
00127 Expr err = proj.project();
00128
00129 FieldWriter w = new VTKWriter(file);
00130 w.addMesh(mesh);
00131 w.addField("soln", new ExprFieldWrapper(soln));
00132 w.addField("error", new ExprFieldWrapper(err));
00133 w.write();
00134 }
00135 private:
00136 int k_;
00137 double C_;
00138
00139 };
00140
00141
00142 int main( int argc , char **argv )
00143 {
00144
00145 try
00146 {
00147 Sundance::init(&argc, &argv);
00148 Tabs::showDepth() = false;
00149 LinearSolveDriver::solveFailureIsFatal() = false;
00150 int np = MPIComm::world().getNProc();
00151
00152 LPTestSuite tests;
00153
00154 Array<int> nx = tuple(4, 8, 16, 32, 64);
00155 double C = 100.0;
00156
00157 for (int p=1; p<=3; p++)
00158 {
00159 tests.registerTest(rcp(new NitschePoisson2DTest(nx, p, C)));
00160 }
00161
00162 bool pass = tests.run();
00163
00164 Out::root() << "total test status: " << pass << std::endl;
00165
00166 Sundance::passFailTest(pass);
00167 }
00168 catch(std::exception& e)
00169 {
00170 Sundance::handleException(e);
00171 }
00172 Sundance::finalize();
00173 return Sundance::testStatus();
00174 }