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 class LinearProblem 
00049 {
00050 public:
00051   /** Empty ctor */
00052   LinearProblem();
00053     
00054   /** Construct with a mesh, equation set, bcs, test and unknown funcs,
00055    * and a vector type. */
00056   LinearProblem(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00057     const Expr& test, const Expr& unk, 
00058     const TSFExtended::VectorType<double>& vecType
00059     );
00060     
00061   /** Construct with a mesh, equation set, bcs, and blocks of variables */
00062   LinearProblem(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00063     const BlockArray& test, const BlockArray& unk);
00064     
00065   /** Construct with a mesh, equation set, bcs, test and unknown funcs,
00066    * parameters, and a vector type. */
00067   LinearProblem(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00068     const Expr& test, const Expr& unk, 
00069     const Expr& unkParams, const Expr& unkParamVals, 
00070     const TSFExtended::VectorType<double>& vecType);
00071     
00072   /** Construct with a mesh, equation set, bcs, parameters, and blocks of
00073       variables */
00074   LinearProblem(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00075     const BlockArray& test, const BlockArray& unk, 
00076     const Expr& unkParams, const Expr& unkParamVals);
00077 
00078   /** */
00079   LinearProblem(const RCP<Assembler>& assembler);
00080 
00081   /** Solve the problem using the specified solver algorithm */
00082   Expr solve(const LinearSolver<double>& solver) const ;
00083 
00084   /** Solve the problem, writing the solution into the given function */
00085   SolverState<double> solve(const LinearSolver<double>& solver,
00086     Expr& soln) const ;
00087 
00088   /** Return the multivector on the right-hand side of the linear equation */
00089   Array<Vector<double> > getRHS() const ;
00090 
00091   /** Return the vector on the right-hand side of the linear equation */
00092   Vector<double> getSingleRHS() const {return getRHS()[0];}
00093 
00094   /** Return the operator on the left-hand side of the equation */
00095   LinearOperator<double> getOperator() const ;
00096 
00097   /** Return the map from cells and functions to row indices */
00098   const RCP<DOFMapBase>& rowMap(int blockRow) const ;
00099     
00100   /** Return the map from cells and functions to column indices */
00101   const RCP<DOFMapBase>& colMap(int blockCol) const ;
00102 
00103   /** Return the discrete space in which solutions live */
00104   const Array<RCP<DiscreteSpace> >& solnSpace() const ;
00105 
00106     
00107   /** Return the set of row indices marked as 
00108    * essential boundary conditions */
00109   const RCP<Set<int> >& bcRows(int blockRow) const ;
00110 
00111   /** Return the number of block rows in the problem  */
00112   int numBlockRows() const ;
00113 
00114   /** Return the number of block cols in the problem  */
00115   int numBlockCols() const ;
00116 
00117 
00118   /** Convert from a BC-partitioned solution vector to a 
00119    * monolithic vector */
00120   Vector<double> 
00121   convertToMonolithicVector(const Array<Vector<double> >& internalBlock,
00122     const Array<Vector<double> >& bcBlock) const ;
00123 
00124   /** */
00125   Expr formSolutionExpr(const Array<Vector<double> >& vec) const ;
00126 
00127   /** Flag indicating whether to stop on a solve failure */
00128   static bool& solveFailureIsFatal()
00129     {return LinearSolveDriver::solveFailureIsFatal();}
00130     
00131 
00132   /** Flag indicating whether to write out the matrix and vector
00133    * after a solve failure */
00134   static bool& dumpBadMatrix() 
00135     {return LinearSolveDriver::dumpBadMatrix();}
00136 
00137   /** Filename for dump of bad matrix */
00138   static std::string& badMatrixFilename() 
00139     {return LinearSolveDriver::badMatrixFilename();}
00140 
00141   /** Filename for dump of bad vector */
00142   static std::string& badVectorFilename() 
00143     {return LinearSolveDriver::badVectorFilename();}
00144 
00145     
00146 
00147 private:
00148 
00149       
00150   /** */
00151   RCP<Assembler> assembler_;
00152 
00153   /** */
00154   mutable LinearOperator<double> A_;
00155 
00156   /** */
00157   mutable Array<Vector<double> > rhs_;
00158 
00159   /** */
00160   Array<Array<string> > names_;
00161 
00162   /** */
00163   LinearSolveDriver solveDriver_;
00164     
00165 };
00166 }
00167 
00168 
00169 #endif

Site Contact