PDEOptPDEConstrainedObjBase.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 
00043 #ifndef PDEOPT_PDECONSTRAINEDOBJBASE_H
00044 #define PDEOPT_PDECONSTRAINEDOBJBASE_H
00045 
00046 #include "PlayaObjectiveBase.hpp"
00047 #include "SundanceExpr.hpp"
00048 #include "SundanceFunctional.hpp"
00049 #include "PDEOptIterCallbackBase.hpp"
00050 
00051 namespace Sundance
00052 {
00053 using namespace Playa;
00054 
00055 
00056 /**
00057  * PDEConstrainedObj is a base class for objective functions of the
00058  * reduced-space variable where the constraint is a PDE in the
00059  * state variables. 
00060  * Objects of this type are suitable for use in adjoint gradient methods.
00061  *
00062  * One constructs such an objective function by giving it a Lagrangian in the
00063  * form of a %Sundance Functional, along with a specification of which functions
00064  * are to be regarded as the adjoint, state, and design variables. 
00065  */
00066 class PDEConstrainedObjBase : public ObjectiveBase
00067 {
00068 public:
00069       
00070   /** Constructor */
00071   PDEConstrainedObjBase(
00072     const Functional& lagrangian,
00073     const Array<Expr>& stateVarVals,
00074     const Array<Expr>& adjointVarVals,
00075     const Expr& designVarVal,
00076     const RCP<IterCallbackBase>& iterCallback,
00077     int verb = 0);
00078       
00079   /** Constructor */
00080   PDEConstrainedObjBase(
00081     const Functional& lagrangian,
00082     const Array<Expr>& stateVarVals,
00083     const Array<Expr>& adjointVarVals,
00084     const Expr& designVarVal,
00085     int verb = 0);
00086 
00087   /** virtual dtor */
00088   virtual ~PDEConstrainedObjBase(){;}
00089 
00090   /** evaluate objective function and gradient */
00091   void  evalGrad(const Vector<double>& x, double& f, 
00092     Vector<double>& grad) const ;
00093 
00094   /** evaluate objective function without gradient. */
00095   void eval(const Vector<double>& x, double& f) const ;
00096 
00097   /** return an initial guess for the design vector  */
00098   Vector<double> getInit() const ;
00099 
00100   /** Hook for anything that needs to be done between the solution
00101    * of the state equations and the evaluation of the functional or
00102    * solution of adjoints. 
00103    *
00104    * Default is a no-op. */
00105   virtual void statePostprocCallback() const {;}
00106 
00107   /** */
00108   virtual void iterationCallback(const Vector<double>& x, int iter) const ;
00109 
00110   /** */
00111   const Mesh& mesh() const {return Lagrangian_.mesh();}
00112 
00113   /** */
00114   int numFuncEvals() const {return numFuncEvals_;}
00115 
00116   /** Solve the state equations, followed by postprocessing.
00117    * At the end of this call, the system is ready for evaluation of
00118    * the objective function or solution of the adjoint equations. */
00119   virtual void solveState(const Vector<double>& x) const = 0 ;
00120 
00121   /** Solve the state equations, then do postprocessing,
00122    * then finally the adjoint equations in <b>reverse</b> order. 
00123    * At the end of this call, the system is ready for evaluation
00124    * of the objective function and its gradient. */
00125   virtual void solveStateAndAdjoint(const Vector<double>& x) const = 0 ;
00126 
00127   /** Set up the state and adjoint equations. This is left to the derived
00128    * class, because we can't know at this level whether the equations
00129    * are linear or nonlinear */
00130   virtual void initEquations(
00131     const Array<Expr>& stateVars,
00132     const Array<Expr>& adjointVars,
00133     const Array<Array<Expr> >& fixedVarsInStateEqns,
00134     const Array<Array<Expr> >& fixedVarsInStateEqnsVals,
00135     const Array<Array<Expr> >& fixedVarsInAdjointEqns,
00136     const Array<Array<Expr> >& fixedVarsInAdjointEqnsVals
00137     ) = 0 ;
00138 
00139   /** Set the scale of the Hessian */
00140   void setHScale(const double& H) {invHScale_ = 1.0/H;}
00141 
00142   /** return an initial approximation to the scale for the 
00143    * inverse of the Hessian */
00144   double getInvHScale() const {return invHScale_;}
00145   
00146 
00147   /** Access to the design variable */
00148   const Expr& designVar() const
00149     {return designVarVal_;}
00150 
00151   /** Access to the state variables */
00152   const Array<Expr>& stateVars() const
00153     {return stateVarVals_;}
00154 
00155   /** Access to the adjoint variables */
00156   const Array<Expr>& adjointVars() const
00157     {return adjointVarVals_;}
00158 
00159 protected:  
00160   /** */
00161   void init(
00162     const Array<Expr>& stateVars,
00163     const Array<Expr>& adjointVars,
00164     const Expr& designVar);
00165 
00166   /** Access to the design variable */
00167   Expr& designVarVal() const
00168     {return designVarVal_;}
00169 
00170   /** Access to the state variables */
00171   Expr& stateVarVals(int i) const
00172     {return stateVarVals_[i];}
00173 
00174   /** Access to the adjoint variables */
00175   Expr& adjointVarVals(int i) const
00176     {return adjointVarVals_[i];}
00177 
00178   const Functional& Lagrangian() const {return Lagrangian_;}
00179       
00180 private:
00181 
00182   Functional Lagrangian_;
00183 
00184   mutable Expr designVarVal_;
00185 
00186   mutable Array<Expr> stateVarVals_;
00187 
00188   mutable Array<Expr> adjointVarVals_;
00189 
00190   FunctionalEvaluator fEval_;
00191 
00192   mutable int numFuncEvals_;
00193 
00194   mutable int numGradEvals_;
00195 
00196   double invHScale_;
00197 
00198   RCP<IterCallbackBase> iterCallback_;
00199 };
00200 
00201 }
00202 
00203 #endif

Site Contact