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

Site Contact