SundanceLinearProblem.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_LINEARPROBLEM_H
00032 #define SUNDANCE_LINEARPROBLEM_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceLinearSolveDriver.hpp"
00036 #include "SundanceObjectWithVerbosity.hpp"
00037 
00038 namespace Sundance
00039 {
00040 using namespace Teuchos;
00041 
00042 class Assembler;
00043 
00044 /** 
00045  * LinearProblem encapsulates all information needed to form
00046  * a discrete linear problem. 
00047  *
00048  */
00049 class LinearProblem 
00050 {
00051 public:
00052   /** Empty ctor */
00053   LinearProblem();
00054     
00055   /** Construct with a mesh, equation set, bcs, test and unknown funcs,
00056    * and a vector type. */
00057   LinearProblem(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00058     const Expr& test, const Expr& unk, 
00059     const Playa::VectorType<double>& vecType
00060     );
00061     
00062   /** Construct with a mesh, equation set, bcs, and blocks of variables */
00063   LinearProblem(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00064     const BlockArray& test, const BlockArray& unk);
00065     
00066   /** Construct with a mesh, equation set, bcs, test and unknown funcs,
00067    * parameters, and a vector type. */
00068   LinearProblem(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00069     const Expr& test, const Expr& unk, 
00070     const Expr& unkParams, const Expr& unkParamVals, 
00071     const Playa::VectorType<double>& vecType);
00072     
00073   /** Construct with a mesh, equation set, bcs, parameters, and blocks of
00074       variables */
00075   LinearProblem(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00076     const BlockArray& test, const BlockArray& unk, 
00077     const Expr& unkParams, const Expr& unkParamVals);
00078 
00079   /** */
00080   LinearProblem(const RCP<Assembler>& assembler);
00081 
00082   /** Solve the problem using the specified solver algorithm */
00083   Expr solve(const LinearSolver<double>& solver) const ;
00084 
00085   /** Solve the problem, writing the solution into the given function */
00086   SolverState<double> solve(const LinearSolver<double>& solver,
00087     Expr& soln) const ;
00088 
00089 
00090   /** Return the multivector on the right-hand side of the linear equation */
00091   Array<Vector<double> > getRHS() const ;
00092 
00093   /** Return the vector on the right-hand side of the linear equation */
00094   Vector<double> getSingleRHS() const {return getRHS()[0];}
00095 
00096   /** Return the operator on the left-hand side of the equation */
00097   LinearOperator<double> getOperator() const ;
00098 
00099   /** Return the map from cells and functions to row indices */
00100   const RCP<DOFMapBase>& rowMap(int blockRow) const ;
00101     
00102   /** Return the map from cells and functions to column indices */
00103   const RCP<DOFMapBase>& colMap(int blockCol) const ;
00104 
00105   /** Return the discrete space in which solutions live */
00106   const Array<RCP<DiscreteSpace> >& solnSpace() const ;
00107 
00108     
00109   /** Return the set of row indices marked as 
00110    * essential boundary conditions */
00111   const RCP<Set<int> >& bcRows(int blockRow) const ;
00112 
00113   /** Return the number of block rows in the problem  */
00114   int numBlockRows() const ;
00115 
00116   /** Return the number of block cols in the problem  */
00117   int numBlockCols() const ;
00118 
00119   /** with this function we can force the assembler to reassemble the matrix */
00120   void reAssembleProblem() const ;
00121 
00122   /** */
00123   Expr formSolutionExpr(const Array<Vector<double> >& vec) const ;
00124 
00125   /** Flag indicating whether to stop on a solve failure */
00126   static bool& solveFailureIsFatal()
00127     {return LinearSolveDriver::solveFailureIsFatal();}
00128     
00129 
00130   /** Flag indicating whether to write out the matrix and vector
00131    * after a solve failure */
00132   static bool& dumpBadMatrix() 
00133     {return LinearSolveDriver::dumpBadMatrix();}
00134 
00135   /** Filename for dump of bad matrix */
00136   static std::string& badMatrixFilename() 
00137     {return LinearSolveDriver::badMatrixFilename();}
00138 
00139   /** Filename for dump of bad vector */
00140   static std::string& badVectorFilename() 
00141     {return LinearSolveDriver::badVectorFilename();}
00142 
00143     
00144 
00145 private:
00146 
00147       
00148   /** */
00149   RCP<Assembler> assembler_;
00150 
00151   /** */
00152   mutable LinearOperator<double> A_;
00153 
00154   /** */
00155   mutable Array<Vector<double> > rhs_;
00156 
00157   /** */
00158   Array<Array<string> > names_;
00159 
00160   /** */
00161   LinearSolveDriver solveDriver_;
00162 
00163   /** */
00164   Expr params_;
00165 
00166 };
00167 
00168 }
00169 
00170 
00171 #endif

Site Contact