SundanceNLOp.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_NLOP_H
00032 #define SUNDANCE_NLOP_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceMesh.hpp"
00036 #include "SundanceExpr.hpp"
00037 #include "SundanceBlock.hpp"
00038 #include "SundanceDiscreteFunction.hpp"
00039 #include "SundanceObjectWithVerbosity.hpp"
00040 #include "PlayaNonlinearOperatorBase.hpp"
00041 #include "PlayaLinearOperatorDecl.hpp"
00042 #include "PlayaVectorDecl.hpp"
00043 #include "PlayaVectorType.hpp"
00044 
00045 namespace Sundance
00046 {
00047 using namespace Teuchos;
00048 
00049 class Assembler;
00050 
00051 
00052 /** 
00053  * NLOp encapsulates a discrete nonlinear problem, and can
00054  * be passed to a nonlinear solver such as NOX.
00055  */
00056 class NLOp 
00057   : public ObjectWithClassVerbosity<NLOp>,
00058     public Playa::NonlinearOperatorBase<double>
00059 {
00060 public:
00061   /** Empty ctor */
00062   NLOp();
00063 
00064   /** Construct with a mesh, equation set, bcs, test and unknown funcs,
00065    * and a vector type */
00066   NLOp(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00067     const Expr& test, const Expr& unk, const Expr& u0, 
00068     const Playa::VectorType<double>& vecType,
00069     bool partitionBCs = false);
00070 
00071   /** Construct with a mesh, equation set, bcs, test and unknown funcs,
00072    * and a vector type */
00073   NLOp(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00074     const BlockArray& test, const BlockArray& unk, const Expr& u0);
00075 
00076 
00077   /** Construct with a mesh, equation set, bcs, test and unknown funcs,
00078    * parameters, and a vector type */
00079   NLOp(const Mesh& mesh, const Expr& eqn, const Expr& bc,
00080     const Expr& test, const Expr& unk, const Expr& u0, 
00081     const Expr& params, const Expr& paramVals,  
00082     const Playa::VectorType<double>& vecType,
00083     bool partitionBCs = false);
00084 
00085 
00086   /** */
00087   NLOp(const RCP<Assembler>& assembler, 
00088     const Expr& u0);
00089 
00090   /** Compute the residual and Jacobian at the current evaluation point */
00091   LinearOperator<double> computeJacobianAndFunction(Vector<double>& functionValue) const ;
00092 
00093   /** Write the Jacobian and residual into the objects provided */
00094   void computeJacobianAndFunction(LinearOperator<double>& J,
00095     Vector<double>& resid) const ;
00096 
00097   /** Compute direct sensitivities to parameters */
00098   Expr computeSensitivities(const LinearSolver<double>& solver) const ;
00099       
00100 
00101   /** Return the current evaluation point as a Sundance expression */
00102   Expr getU0() const {return u0_;}
00103 
00104   /** Compute the residual at the current eval point */
00105   Playa::Vector<double> computeFunctionValue() const ;
00106       
00107   /** Write the residual into the object provided */
00108   void computeFunctionValue(Vector<double>& resid) const ;
00109 
00110   /** Get an initial guess */
00111   Playa::Vector<double> getInitialGuess() const ;
00112 
00113   /** Create the Jacobian object, but don't fill it in. */
00114   LinearOperator<double> allocateJacobian() const ;
00115 
00116   /** Set an initial guess */
00117   void setInitialGuess(const Expr& u0New);
00118 
00119   /** This function forces the assembler to reassemble the matrix */
00120   void reAssembleProblem() const;
00121 
00122   /* Handle boilerplate */
00123   GET_RCP(Playa::NonlinearOperatorBase<double>);
00124 
00125 protected:
00126   /** */
00127   void updateDiscreteFunctionValue(const Vector<double>& vec) const ;
00128 private:
00129       
00130   /** */
00131   RCP<Assembler> assembler_;
00132 
00133   /** */
00134   mutable Playa::LinearOperator<double> J_;
00135 
00136   /** */
00137   Expr u0_;
00138 
00139   /** */
00140   Expr params_;
00141 
00142   /** */
00143   Expr paramVals_;
00144 };
00145 }
00146 
00147 
00148 
00149 
00150 #endif

Site Contact