EpetraExt Package Browser (Single Doxygen Collection) Development
EpetraExt_ModelEvaluatorScalingTools.h
Go to the documentation of this file.
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
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 Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 
00042 #ifndef EPETRA_EXT_MODEL_EVALUATOR_SCALING_TOOLS_H
00043 #define EPETRA_EXT_MODEL_EVALUATOR_SCALING_TOOLS_H
00044 
00045 
00046 #include "EpetraExt_ModelEvaluator.h"
00047 #include "Teuchos_Utils.hpp"
00048 
00049 
00050 namespace EpetraExt {
00051 
00052 
00178 
00179 
00187 void gatherModelNominalValues(
00188   const ModelEvaluator &model,
00189   ModelEvaluator::InArgs *nominalValues
00190   );
00191 
00192 
00200 void gatherModelBounds(
00201   const ModelEvaluator &model,
00202   ModelEvaluator::InArgs *lowerBounds,
00203   ModelEvaluator::InArgs *upperBounds
00204   );
00205 
00206 
00241 void scaleModelVars(
00242   const ModelEvaluator::InArgs &origVars,
00243   const ModelEvaluator::InArgs &varScalings,
00244   ModelEvaluator::InArgs *scaledVars,
00245   Teuchos::FancyOStream *out = 0,
00246   Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_LOW
00247   );
00248 
00253 void scaleModelBounds(
00254   const ModelEvaluator::InArgs &origLowerBounds,
00255   const ModelEvaluator::InArgs &origUpperBounds,
00256   const double infBnd,
00257   const ModelEvaluator::InArgs &varScalings,
00258   ModelEvaluator::InArgs *scaledLowerBounds,
00259   ModelEvaluator::InArgs *scaledUpperBounds,
00260   Teuchos::FancyOStream *out = 0,
00261   Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_LOW
00262   );
00263 
00264 
00295 void unscaleModelVars(
00296   const ModelEvaluator::InArgs &scaledVars,
00297   const ModelEvaluator::InArgs &varScalings,
00298   ModelEvaluator::InArgs *origVars,
00299   Teuchos::FancyOStream *out = 0,
00300   Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_LOW
00301   );
00302 
00303 
00361 void scaleModelFuncs(
00362   const ModelEvaluator::OutArgs &origFuncs,
00363   const ModelEvaluator::InArgs &varScalings,
00364   const ModelEvaluator::OutArgs &funcScalings,
00365   ModelEvaluator::OutArgs *scaledFuncs,
00366   bool *allFuncsWhereScaled,
00367   Teuchos::FancyOStream *out = 0,
00368   Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_LOW
00369   );
00370 
00371 
00377 Teuchos::RefCountPtr<const Epetra_Vector>
00378 createInverseModelScalingVector(
00379   Teuchos::RefCountPtr<const Epetra_Vector> const& scalingVector
00380   );
00381 
00382 
00405 void scaleModelVarsGivenInverseScaling(
00406   const Epetra_Vector &origVars,
00407   const Epetra_Vector &invVarScaling,
00408   Epetra_Vector *scaledVars
00409   );
00410 
00411 
00413 void scaleModelVarBoundsGivenInverseScaling(
00414   const Epetra_Vector &origLowerBounds,
00415   const Epetra_Vector &origUpperBounds,
00416   const double infBnd,
00417   const Epetra_Vector &invVarScaling,
00418   Epetra_Vector *scaledLowerBounds,
00419   Epetra_Vector *scaledUpperBounds
00420   );
00421 
00422 
00445 void unscaleModelVarsGivenInverseScaling(
00446   const Epetra_Vector &origVars,
00447   const Epetra_Vector &invVarScaling,
00448   Epetra_Vector *scaledVars
00449   );
00450 
00451 
00470 void scaleModelFuncGivenForwardScaling(
00471   const Epetra_Vector &fwdFuncScaling,
00472   Epetra_Vector *funcs
00473   );
00474 
00475 
00504 void scaleModelFuncFirstDerivOp(
00505   const Epetra_Vector *invVarScaling,
00506   const Epetra_Vector *fwdFuncScaling,
00507   Epetra_Operator *funcDerivOp,
00508   bool *didScaling
00509   );
00510 
00511 
00547 void scaleModelFuncFirstDeriv(
00548   const ModelEvaluator::Derivative &origFuncDeriv,
00549   const Epetra_Vector *invVarScaling,
00550   const Epetra_Vector *fwdFuncScaling,
00551   ModelEvaluator::Derivative *scaledFuncDeriv,
00552   bool *didScaling
00553   );
00554 
00555 
00557 class InArgsGetterSetter_x_dot {
00558 public:
00559 
00560   std::string getName() const { return "x_dot"; }
00561 
00562   Teuchos::RefCountPtr<const Epetra_Vector>
00563   getVector( const ModelEvaluator::InArgs &inArgs ) const
00564   {
00565     return inArgs.get_x_dot();
00566   }
00567 
00568   void setVector(
00569     const Teuchos::RefCountPtr<const Epetra_Vector> &x_dot,
00570     ModelEvaluator::InArgs *inArgs
00571     ) const
00572   {
00573 #ifdef TEUCHOS_DEBUG
00574     TEUCHOS_TEST_FOR_EXCEPT(!inArgs);
00575 #endif
00576     inArgs->set_x_dot(x_dot);
00577   }
00578 
00579 };
00580 
00581 
00583 class InArgsGetterSetter_x_dotdot {
00584 public:
00585 
00586   std::string getName() const { return "x_dotdot"; }
00587 
00588   Teuchos::RefCountPtr<const Epetra_Vector>
00589   getVector( const ModelEvaluator::InArgs &inArgs ) const
00590   {
00591     return inArgs.get_x_dotdot();
00592   }
00593 
00594   void setVector(
00595     const Teuchos::RefCountPtr<const Epetra_Vector> &x_dotdot,
00596     ModelEvaluator::InArgs *inArgs
00597     ) const
00598   {
00599 #ifdef TEUCHOS_DEBUG
00600     TEUCHOS_TEST_FOR_EXCEPT(!inArgs);
00601 #endif
00602     inArgs->set_x_dotdot(x_dotdot);
00603   }
00604 
00605 };
00606 
00607 
00609 class InArgsGetterSetter_x {
00610 public:
00611 
00612   std::string getName() const { return "x"; }
00613 
00614   Teuchos::RefCountPtr<const Epetra_Vector>
00615   getVector( const ModelEvaluator::InArgs &inArgs ) const
00616   {
00617     return inArgs.get_x();
00618   }
00619 
00620   void setVector(
00621     const Teuchos::RefCountPtr<const Epetra_Vector> &x,
00622     ModelEvaluator::InArgs *inArgs
00623     ) const
00624   {
00625 #ifdef TEUCHOS_DEBUG
00626     TEUCHOS_TEST_FOR_EXCEPT(!inArgs);
00627 #endif
00628     inArgs->set_x(x);
00629   }
00630 
00631 };
00632 
00633 
00635 class InArgsGetterSetter_p {
00636 public:
00637 
00638   InArgsGetterSetter_p( int l ) : l_(l) {}
00639 
00640   std::string getName() const
00641   { return "p["+Teuchos::Utils::toString(l_)+"]"; }
00642 
00643   Teuchos::RefCountPtr<const Epetra_Vector>
00644   getVector( const ModelEvaluator::InArgs &inArgs ) const
00645   {
00646     return inArgs.get_p(l_);
00647   }
00648 
00649   void setVector(
00650     const Teuchos::RefCountPtr<const Epetra_Vector> &p_l,
00651     ModelEvaluator::InArgs *inArgs
00652     ) const
00653   {
00654 #ifdef TEUCHOS_DEBUG
00655     TEUCHOS_TEST_FOR_EXCEPT(!inArgs);
00656 #endif
00657     inArgs->set_p(l_,p_l);
00658   }
00659 
00660 private:
00661 
00662   int l_;
00663 
00664   InArgsGetterSetter_p(); // Not defined!
00665 
00666 };
00667 
00668 
00670 class OutArgsGetterSetter_f {
00671 public:
00672 
00673   Teuchos::RefCountPtr<Epetra_Vector>
00674   getVector( const ModelEvaluator::OutArgs &outArgs ) const
00675   {
00676     return outArgs.get_f();
00677   }
00678 
00679   void setVector(
00680     const Teuchos::RefCountPtr<Epetra_Vector> &f,
00681     ModelEvaluator::OutArgs *outArgs
00682     ) const
00683   {
00684 #ifdef TEUCHOS_DEBUG
00685     TEUCHOS_TEST_FOR_EXCEPT(!outArgs);
00686 #endif
00687     outArgs->set_f(f);
00688   }
00689 
00690 };
00691 
00692 
00694 class OutArgsGetterSetter_g {
00695 public:
00696 
00697   OutArgsGetterSetter_g( int j ) : j_(j) {}
00698 
00699   Teuchos::RefCountPtr<Epetra_Vector>
00700   getVector( const ModelEvaluator::OutArgs &outArgs ) const
00701   {
00702     return outArgs.get_g(j_);
00703   }
00704 
00705   void setVector(
00706     const Teuchos::RefCountPtr<Epetra_Vector> &g_j,
00707     ModelEvaluator::OutArgs *outArgs
00708     ) const
00709   {
00710 #ifdef TEUCHOS_DEBUG
00711     TEUCHOS_TEST_FOR_EXCEPT(!outArgs);
00712 #endif
00713     outArgs->set_g(j_,g_j);
00714   }
00715 
00716 private:
00717 
00718   int j_;
00719 
00720   OutArgsGetterSetter_g(); // Not defined!
00721 
00722 };
00723 
00724 
00726 
00727 
00728 } // namespace EpetraExt
00729 
00730 
00731 #endif // EPETRA_EXT_MODEL_EVALUATOR_SCALING_TOOLS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines