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