00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef EPETRA_EXT_MODEL_EVALUATOR_SCALING_TOOLS_H
00030 #define EPETRA_EXT_MODEL_EVALUATOR_SCALING_TOOLS_H
00031
00032
00033 #include "EpetraExt_ModelEvaluator.h"
00034 #include "Teuchos_Utils.hpp"
00035
00036
00037 namespace EpetraExt {
00038
00039
00165
00166
00174 void gatherModelNominalValues(
00175 const ModelEvaluator &model,
00176 ModelEvaluator::InArgs *nominalValues
00177 );
00178
00179
00187 void gatherModelBounds(
00188 const ModelEvaluator &model,
00189 ModelEvaluator::InArgs *lowerBounds,
00190 ModelEvaluator::InArgs *upperBounds
00191 );
00192
00193
00228 void scaleModelVars(
00229 const ModelEvaluator::InArgs &origVars,
00230 const ModelEvaluator::InArgs &varScalings,
00231 ModelEvaluator::InArgs *scaledVars,
00232 Teuchos::FancyOStream *out = 0,
00233 Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_LOW
00234 );
00235
00240 void scaleModelBounds(
00241 const ModelEvaluator::InArgs &origLowerBounds,
00242 const ModelEvaluator::InArgs &origUpperBounds,
00243 const double infBnd,
00244 const ModelEvaluator::InArgs &varScalings,
00245 ModelEvaluator::InArgs *scaledLowerBounds,
00246 ModelEvaluator::InArgs *scaledUpperBounds,
00247 Teuchos::FancyOStream *out = 0,
00248 Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_LOW
00249 );
00250
00251
00282 void unscaleModelVars(
00283 const ModelEvaluator::InArgs &scaledVars,
00284 const ModelEvaluator::InArgs &varScalings,
00285 ModelEvaluator::InArgs *origVars,
00286 Teuchos::FancyOStream *out = 0,
00287 Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_LOW
00288 );
00289
00290
00348 void scaleModelFuncs(
00349 const ModelEvaluator::OutArgs &origFuncs,
00350 const ModelEvaluator::InArgs &varScalings,
00351 const ModelEvaluator::OutArgs &funcScalings,
00352 ModelEvaluator::OutArgs *scaledFuncs,
00353 bool *allFuncsWhereScaled,
00354 Teuchos::FancyOStream *out = 0,
00355 Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_LOW
00356 );
00357
00358
00364 Teuchos::RefCountPtr<const Epetra_Vector>
00365 createInverseModelScalingVector(
00366 Teuchos::RefCountPtr<const Epetra_Vector> const& scalingVector
00367 );
00368
00369
00392 void scaleModelVarsGivenInverseScaling(
00393 const Epetra_Vector &origVars,
00394 const Epetra_Vector &invVarScaling,
00395 Epetra_Vector *scaledVars
00396 );
00397
00398
00400 void scaleModelVarBoundsGivenInverseScaling(
00401 const Epetra_Vector &origLowerBounds,
00402 const Epetra_Vector &origUpperBounds,
00403 const double infBnd,
00404 const Epetra_Vector &invVarScaling,
00405 Epetra_Vector *scaledLowerBounds,
00406 Epetra_Vector *scaledUpperBounds
00407 );
00408
00409
00432 void unscaleModelVarsGivenInverseScaling(
00433 const Epetra_Vector &origVars,
00434 const Epetra_Vector &invVarScaling,
00435 Epetra_Vector *scaledVars
00436 );
00437
00438
00457 void scaleModelFuncGivenForwardScaling(
00458 const Epetra_Vector &fwdFuncScaling,
00459 Epetra_Vector *funcs
00460 );
00461
00462
00491 void scaleModelFuncFirstDerivOp(
00492 const Epetra_Vector *invVarScaling,
00493 const Epetra_Vector *fwdFuncScaling,
00494 Epetra_Operator *funcDerivOp,
00495 bool *didScaling
00496 );
00497
00498
00534 void scaleModelFuncFirstDeriv(
00535 const ModelEvaluator::Derivative &origFuncDeriv,
00536 const Epetra_Vector *invVarScaling,
00537 const Epetra_Vector *fwdFuncScaling,
00538 ModelEvaluator::Derivative *scaledFuncDeriv,
00539 bool *didScaling
00540 );
00541
00542
00544 class InArgsGetterSetter_x_dot {
00545 public:
00546
00547 std::string getName() const { return "x_dot"; }
00548
00549 Teuchos::RefCountPtr<const Epetra_Vector>
00550 getVector( const ModelEvaluator::InArgs &inArgs ) const
00551 {
00552 return inArgs.get_x_dot();
00553 }
00554
00555 void setVector(
00556 const Teuchos::RefCountPtr<const Epetra_Vector> &x_dot,
00557 ModelEvaluator::InArgs *inArgs
00558 ) const
00559 {
00560 #ifdef TEUCHOS_DEBUG
00561 TEST_FOR_EXCEPT(!inArgs);
00562 #endif
00563 inArgs->set_x_dot(x_dot);
00564 }
00565
00566 };
00567
00568
00570 class InArgsGetterSetter_x {
00571 public:
00572
00573 std::string getName() const { return "x"; }
00574
00575 Teuchos::RefCountPtr<const Epetra_Vector>
00576 getVector( const ModelEvaluator::InArgs &inArgs ) const
00577 {
00578 return inArgs.get_x();
00579 }
00580
00581 void setVector(
00582 const Teuchos::RefCountPtr<const Epetra_Vector> &x,
00583 ModelEvaluator::InArgs *inArgs
00584 ) const
00585 {
00586 #ifdef TEUCHOS_DEBUG
00587 TEST_FOR_EXCEPT(!inArgs);
00588 #endif
00589 inArgs->set_x(x);
00590 }
00591
00592 };
00593
00594
00596 class InArgsGetterSetter_p {
00597 public:
00598
00599 InArgsGetterSetter_p( int l ) : l_(l) {}
00600
00601 std::string getName() const
00602 { return "p["+Teuchos::Utils::toString(l_)+"]"; }
00603
00604 Teuchos::RefCountPtr<const Epetra_Vector>
00605 getVector( const ModelEvaluator::InArgs &inArgs ) const
00606 {
00607 return inArgs.get_p(l_);
00608 }
00609
00610 void setVector(
00611 const Teuchos::RefCountPtr<const Epetra_Vector> &p_l,
00612 ModelEvaluator::InArgs *inArgs
00613 ) const
00614 {
00615 #ifdef TEUCHOS_DEBUG
00616 TEST_FOR_EXCEPT(!inArgs);
00617 #endif
00618 inArgs->set_p(l_,p_l);
00619 }
00620
00621 private:
00622
00623 int l_;
00624
00625 InArgsGetterSetter_p();
00626
00627 };
00628
00629
00631 class OutArgsGetterSetter_f {
00632 public:
00633
00634 Teuchos::RefCountPtr<Epetra_Vector>
00635 getVector( const ModelEvaluator::OutArgs &outArgs ) const
00636 {
00637 return outArgs.get_f();
00638 }
00639
00640 void setVector(
00641 const Teuchos::RefCountPtr<Epetra_Vector> &f,
00642 ModelEvaluator::OutArgs *outArgs
00643 ) const
00644 {
00645 #ifdef TEUCHOS_DEBUG
00646 TEST_FOR_EXCEPT(!outArgs);
00647 #endif
00648 outArgs->set_f(f);
00649 }
00650
00651 };
00652
00653
00655 class OutArgsGetterSetter_g {
00656 public:
00657
00658 OutArgsGetterSetter_g( int j ) : j_(j) {}
00659
00660 Teuchos::RefCountPtr<Epetra_Vector>
00661 getVector( const ModelEvaluator::OutArgs &outArgs ) const
00662 {
00663 return outArgs.get_g(j_);
00664 }
00665
00666 void setVector(
00667 const Teuchos::RefCountPtr<Epetra_Vector> &g_j,
00668 ModelEvaluator::OutArgs *outArgs
00669 ) const
00670 {
00671 #ifdef TEUCHOS_DEBUG
00672 TEST_FOR_EXCEPT(!outArgs);
00673 #endif
00674 outArgs->set_g(j_,g_j);
00675 }
00676
00677 private:
00678
00679 int j_;
00680
00681 OutArgsGetterSetter_g();
00682
00683 };
00684
00685
00687
00688
00689 }
00690
00691
00692 #endif // EPETRA_EXT_MODEL_EVALUATOR_SCALING_TOOLS_H