|
EpetraExt
Development
|
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 { 00584 public: 00585 00586 std::string getName() const { return "x"; } 00587 00588 Teuchos::RefCountPtr<const Epetra_Vector> 00589 getVector( const ModelEvaluator::InArgs &inArgs ) const 00590 { 00591 return inArgs.get_x(); 00592 } 00593 00594 void setVector( 00595 const Teuchos::RefCountPtr<const Epetra_Vector> &x, 00596 ModelEvaluator::InArgs *inArgs 00597 ) const 00598 { 00599 #ifdef TEUCHOS_DEBUG 00600 TEUCHOS_TEST_FOR_EXCEPT(!inArgs); 00601 #endif 00602 inArgs->set_x(x); 00603 } 00604 00605 }; 00606 00607 00609 class InArgsGetterSetter_p { 00610 public: 00611 00612 InArgsGetterSetter_p( int l ) : l_(l) {} 00613 00614 std::string getName() const 00615 { return "p["+Teuchos::Utils::toString(l_)+"]"; } 00616 00617 Teuchos::RefCountPtr<const Epetra_Vector> 00618 getVector( const ModelEvaluator::InArgs &inArgs ) const 00619 { 00620 return inArgs.get_p(l_); 00621 } 00622 00623 void setVector( 00624 const Teuchos::RefCountPtr<const Epetra_Vector> &p_l, 00625 ModelEvaluator::InArgs *inArgs 00626 ) const 00627 { 00628 #ifdef TEUCHOS_DEBUG 00629 TEUCHOS_TEST_FOR_EXCEPT(!inArgs); 00630 #endif 00631 inArgs->set_p(l_,p_l); 00632 } 00633 00634 private: 00635 00636 int l_; 00637 00638 InArgsGetterSetter_p(); // Not defined! 00639 00640 }; 00641 00642 00644 class OutArgsGetterSetter_f { 00645 public: 00646 00647 Teuchos::RefCountPtr<Epetra_Vector> 00648 getVector( const ModelEvaluator::OutArgs &outArgs ) const 00649 { 00650 return outArgs.get_f(); 00651 } 00652 00653 void setVector( 00654 const Teuchos::RefCountPtr<Epetra_Vector> &f, 00655 ModelEvaluator::OutArgs *outArgs 00656 ) const 00657 { 00658 #ifdef TEUCHOS_DEBUG 00659 TEUCHOS_TEST_FOR_EXCEPT(!outArgs); 00660 #endif 00661 outArgs->set_f(f); 00662 } 00663 00664 }; 00665 00666 00668 class OutArgsGetterSetter_g { 00669 public: 00670 00671 OutArgsGetterSetter_g( int j ) : j_(j) {} 00672 00673 Teuchos::RefCountPtr<Epetra_Vector> 00674 getVector( const ModelEvaluator::OutArgs &outArgs ) const 00675 { 00676 return outArgs.get_g(j_); 00677 } 00678 00679 void setVector( 00680 const Teuchos::RefCountPtr<Epetra_Vector> &g_j, 00681 ModelEvaluator::OutArgs *outArgs 00682 ) const 00683 { 00684 #ifdef TEUCHOS_DEBUG 00685 TEUCHOS_TEST_FOR_EXCEPT(!outArgs); 00686 #endif 00687 outArgs->set_g(j_,g_j); 00688 } 00689 00690 private: 00691 00692 int j_; 00693 00694 OutArgsGetterSetter_g(); // Not defined! 00695 00696 }; 00697 00698 00700 00701 00702 } // namespace EpetraExt 00703 00704 00705 #endif // EPETRA_EXT_MODEL_EVALUATOR_SCALING_TOOLS_H
1.7.6.1