NitschePoisson2D.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
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    * Specify which linear solvers are to be used.
00102    */
00103   Array<LPTestSpec> specs() const
00104     {
00105       double tol = 0.05;
00106       return tuple(
00107         LPTestSpec("amesos.xml", tol, makeSet<int>(1))/*,
00108                                                         LPTestSpec("aztec-ifpack.xml", tol), 
00109                                                         LPTestSpec("aztec-ml.xml", tol),
00110                                           LPTestSpec("belos-ml.xml", tol),
00111                                           LPTestSpec("bicgstab.xml", tol) */
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 }

Site Contact