Thyra Package Browser (Single Doxygen Collection)  Version of the Day
Thyra_EpetraModelEvaluator.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
43 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
45 #include "Thyra_EpetraLinearOp.hpp"
46 #include "Thyra_DetachedMultiVectorView.hpp"
47 #include "Thyra_ModelEvaluatorDelegatorBase.hpp" // Gives verbose macros!
48 #include "EpetraExt_ModelEvaluatorScalingTools.h"
49 #include "Epetra_RowMatrix.h"
50 #include "Teuchos_Time.hpp"
52 #include "Teuchos_Assert.hpp"
55 
56 
57 namespace {
58 
59 
60 const std::string StateFunctionScaling_name = "State Function Scaling";
64  >
65  >
66 stateFunctionScalingValidator;
67 const std::string StateFunctionScaling_default = "None";
68 
69 
70 // Extract out the Epetra_RowMatrix from the set W in an Epetra OutArgs object
72 get_Epetra_RowMatrix(
73  const EpetraExt::ModelEvaluator::OutArgs &epetraOutArgs
74  )
75 {
76  using Teuchos::RCP;
77  const RCP<Epetra_Operator>
78  eW = epetraOutArgs.get_W();
79  const RCP<Epetra_RowMatrix>
80  ermW = Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(eW,false);
82  is_null(ermW), std::logic_error,
83  "Thyra::EpetraModelEvaluator::evalModel(...): Error, if\n"
84  "scaling is turned on, the underlying Epetra_Operator created\n"
85  "an initialized by the underlying epetra model evaluator\n"
86  "\"" << epetraOutArgs.modelEvalDescription() << "\"\n"
87  "must support the Epetra_RowMatrix interface through a dynamic cast.\n"
88  "The concrete type " << Teuchos::typeName(*eW) << " does not support\n"
89  "Epetra_RowMatrix!"
90  );
91  return ermW;
92 }
93 
94 
96 create_and_assert_W(
97  const EpetraExt::ModelEvaluator &epetraModel
98  )
99 {
100  using Teuchos::RCP;
101  RCP<Epetra_Operator>
102  eW = epetraModel.create_W();
104  is_null(eW), std::logic_error,
105  "Error, the call to create_W() returned null on the "
106  "EpetraExt::ModelEvaluator object "
107  "\"" << epetraModel.description() << "\". This may mean that "
108  "the underlying model does not support more than one copy of "
109  "W at one time!" );
110  return eW;
111 }
112 
113 
114 } // namespace
115 
116 
117 namespace Thyra {
118 
119 
120 // Constructors/initializers/accessors.
121 
122 
124  :nominalValuesAndBoundsAreUpdated_(false), stateFunctionScaling_(STATE_FUNC_SCALING_NONE),
125  currentInArgsOutArgs_(false), finalPointWasSolved_(false)
126 {}
127 
128 
130  const RCP<const EpetraExt::ModelEvaluator> &epetraModel,
131  const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
132  )
135 {
136  initialize(epetraModel,W_factory);
137 }
138 
139 
141  const RCP<const EpetraExt::ModelEvaluator> &epetraModel,
142  const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
143  )
144 {
146  typedef ModelEvaluatorBase MEB;
147  //
148  epetraModel_ = epetraModel;
149  //
150  W_factory_ = W_factory;
151  //
152  x_map_ = epetraModel_->get_x_map();
153  f_map_ = epetraModel_->get_f_map();
154  if (!is_null(x_map_)) {
157  }
158  //
159  EpetraExt::ModelEvaluator::InArgs inArgs = epetraModel_->createInArgs();
160  p_map_.resize(inArgs.Np()); p_space_.resize(inArgs.Np());
161  p_map_is_local_.resize(inArgs.Np(),false);
162  for( int l = 0; l < implicit_cast<int>(p_space_.size()); ++l ) {
164  p_map_l = ( p_map_[l] = epetraModel_->get_p_map(l) );
165 #ifdef TEUCHOS_DEBUG
167  is_null(p_map_l), std::logic_error,
168  "Error, the the map p["<<l<<"] for the model \""
169  <<epetraModel->description()<<"\" can not be null!");
170 #endif
171 
172  p_map_is_local_[l] = !p_map_l->DistributedGlobal();
173  p_space_[l] = create_VectorSpace(p_map_l);
174  }
175  //
176  EpetraExt::ModelEvaluator::OutArgs outArgs = epetraModel_->createOutArgs();
177  g_map_.resize(outArgs.Ng()); g_space_.resize(outArgs.Ng());
178  g_map_is_local_.resize(outArgs.Ng(),false);
179  for( int j = 0; j < implicit_cast<int>(g_space_.size()); ++j ) {
181  g_map_j = ( g_map_[j] = epetraModel_->get_g_map(j) );
182  g_map_is_local_[j] = !g_map_j->DistributedGlobal();
183  g_space_[j] = create_VectorSpace( g_map_j );
184  }
185  //
186  epetraInArgsScaling_ = epetraModel_->createInArgs();
187  epetraOutArgsScaling_ = epetraModel_->createOutArgs();
189  finalPointWasSolved_ = false;
190  stateFunctionScalingVec_ = Teuchos::null; // Must set new scaling!
191  //
192  currentInArgsOutArgs_ = false;
193 }
194 
195 
198 {
199  return epetraModel_;
200 }
201 
202 
204  const ModelEvaluatorBase::InArgs<double>& nominalValues
205  )
206 {
207  nominalValues_.setArgs(nominalValues);
208  // Note: These must be the scaled values so we don't need to scale!
209 }
210 
211 
213  const RCP<const Epetra_Vector> &stateVariableScalingVec
214  )
215 {
216  typedef ModelEvaluatorBase MEB;
217 #ifdef TEUCHOS_DEBUG
218  TEUCHOS_TEST_FOR_EXCEPT( !this->createInArgs().supports(MEB::IN_ARG_x) );
219 #endif
220  stateVariableScalingVec_ = stateVariableScalingVec.assert_not_null();
221  invStateVariableScalingVec_ = Teuchos::null;
223 }
224 
225 
228 {
230 }
231 
232 
235 {
238 }
239 
240 
242  const RCP<const Epetra_Vector> &stateFunctionScalingVec
243  )
244 {
245  stateFunctionScalingVec_ = stateFunctionScalingVec;
246 }
247 
248 
251 {
253 }
254 
255 
258  RCP<LinearOpWithSolveFactoryBase<double> > *W_factory
259  )
260 {
261  if(epetraModel) *epetraModel = epetraModel_;
262  if(W_factory) *W_factory = W_factory_;
263  epetraModel_ = Teuchos::null;
264  W_factory_ = Teuchos::null;
265  stateFunctionScalingVec_ = Teuchos::null;
266  stateVariableScalingVec_ = Teuchos::null;
267  invStateVariableScalingVec_ = Teuchos::null;
268  currentInArgsOutArgs_ = false;
269 }
270 
271 
272 const ModelEvaluatorBase::InArgs<double>&
274 {
275  return finalPoint_;
276 }
277 
278 
280 {
281  return finalPointWasSolved_;
282 }
283 
284 
285 // Public functions overridden from Teuchos::Describable
286 
287 
289 {
290  std::ostringstream oss;
291  oss << "Thyra::EpetraModelEvaluator{";
292  oss << "epetraModel=";
293  if(epetraModel_.get())
294  oss << "\'"<<epetraModel_->description()<<"\'";
295  else
296  oss << "NULL";
297  oss << ",W_factory=";
298  if(W_factory_.get())
299  oss << "\'"<<W_factory_->description()<<"\'";
300  else
301  oss << "NULL";
302  oss << "}";
303  return oss.str();
304 }
305 
306 
307 // Overridden from Teuchos::ParameterListAcceptor
308 
309 
311  RCP<Teuchos::ParameterList> const& paramList
312  )
313 {
314  TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
315  paramList->validateParameters(*getValidParameters(),0); // Just validate my params
316  paramList_ = paramList;
317  const EStateFunctionScaling stateFunctionScaling_old = stateFunctionScaling_;
318  stateFunctionScaling_ = stateFunctionScalingValidator->getIntegralValue(
319  *paramList_, StateFunctionScaling_name, StateFunctionScaling_default
320  );
321  if( stateFunctionScaling_ != stateFunctionScaling_old )
322  stateFunctionScalingVec_ = Teuchos::null;
323  Teuchos::readVerboseObjectSublist(&*paramList_,this);
324 #ifdef TEUCHOS_DEBUG
326 #endif // TEUCHOS_DEBUG
327 }
328 
329 
332 {
333  return paramList_;
334 }
335 
336 
339 {
341  paramList_ = Teuchos::null;
342  return _paramList;
343 }
344 
345 
348 {
349  return paramList_;
350 }
351 
352 
355 {
356  using Teuchos::rcp;
358  using Teuchos::tuple;
359  using Teuchos::rcp_implicit_cast;
361  static RCP<const Teuchos::ParameterList> validPL;
362  if(is_null(validPL)) {
365  stateFunctionScalingValidator = rcp(
366  new StringToIntegralParameterEntryValidator<EStateFunctionScaling>(
367  tuple<std::string>(
368  "None",
369  "Row Sum"
370  ),
371  tuple<std::string>(
372  "Do not scale the state function f(...) in this class.",
373 
374  "Scale the state function f(...) and all its derivatives\n"
375  "using the row sum scaling from the initial Jacobian\n"
376  "W=d(f)/d(x). Note, this only works with Epetra_CrsMatrix\n"
377  "currently."
378  ),
379  tuple<EStateFunctionScaling>(
382  ),
383  StateFunctionScaling_name
384  )
385  );
386  pl->set(StateFunctionScaling_name,StateFunctionScaling_default,
387  "Determines if and how the state function f(...) and all of its\n"
388  "derivatives are scaled. The scaling is done explicitly so there should\n"
389  "be no impact on the meaning of inner products or tolerances for\n"
390  "linear solves.",
391  rcp_implicit_cast<const PEV>(stateFunctionScalingValidator)
392  );
393  Teuchos::setupVerboseObjectSublist(&*pl);
394  validPL = pl;
395  }
396  return validPL;
397 }
398 
399 
400 // Overridden from ModelEvaulator.
401 
402 
404 {
405  return p_space_.size();
406 }
407 
408 
410 {
411  return g_space_.size();
412 }
413 
414 
417 {
418  return x_space_;
419 }
420 
421 
424 {
425  return f_space_;
426 }
427 
428 
431 {
432 #ifdef TEUCHOS_DEBUG
434 #endif
435  return p_space_[l];
436 }
437 
438 
441 {
442 #ifdef TEUCHOS_DEBUG
444 #endif
445  return epetraModel_->get_p_names(l);
446 }
447 
448 
451 {
452  TEUCHOS_TEST_FOR_EXCEPT( ! ( 0 <= j && j < this->Ng() ) );
453  return g_space_[j];
454 }
455 
456 
457 ModelEvaluatorBase::InArgs<double>
459 {
461  return nominalValues_;
462 }
463 
464 
465 ModelEvaluatorBase::InArgs<double>
467 {
469  return lowerBounds_;
470 }
471 
472 
473 ModelEvaluatorBase::InArgs<double>
475 {
477  return upperBounds_;
478 }
479 
480 
483 {
484  return this->create_epetra_W_op();
485 }
486 
487 
490 {
491  return Teuchos::null;
492 }
493 
494 
497 {
498  return W_factory_;
499 }
500 
501 
502 ModelEvaluatorBase::InArgs<double> EpetraModelEvaluator::createInArgs() const
503 {
506  return prototypeInArgs_;
507 }
508 
509 
511  const ModelEvaluatorBase::InArgs<double> &finalPoint,
512  const bool wasSolved
513  )
514 {
515  finalPoint_ = this->createInArgs();
516  finalPoint_.setArgs(finalPoint);
517  finalPointWasSolved_ = wasSolved;
518 }
519 
520 
521 // Private functions overridden from ModelEvaulatorDefaultBase
522 
523 
526 {
528  return Teuchos::null;
529 }
530 
531 
534 {
536  return Teuchos::null;
537 }
538 
539 
542 {
544  return Teuchos::null;
545 }
546 
547 
550 {
552  return Teuchos::null;
553 }
554 
555 
556 ModelEvaluatorBase::OutArgs<double>
558 {
561  return prototypeOutArgs_;
562 }
563 
564 
566  const ModelEvaluatorBase::InArgs<double>& inArgs_in,
567  const ModelEvaluatorBase::OutArgs<double>& outArgs
568  ) const
569 {
570 
571  using Teuchos::rcp;
572  using Teuchos::rcp_const_cast;
573  using Teuchos::rcp_dynamic_cast;
574  using Teuchos::OSTab;
576  typedef EpetraExt::ModelEvaluator EME;
577 
578  //
579  // A) Initial setup
580  //
581 
582  // Make sure that we are fully initialized!
584 
585  // Make sure we grab the initial guess first!
586  InArgs<double> inArgs = this->getNominalValues();
587  // Now, copy the parameters from the input inArgs_in object to the inArgs
588  // object. Any input objects that are set in inArgs_in will overwrite those
589  // in inArgs that will already contain the nominal values. This will insure
590  // that all input parameters are set and those that are not set by the
591  // client will be at their nominal values (as defined by the underlying
592  // EpetraExt::ModelEvaluator object). The full set of Thyra input arguments
593  // must be set before these can be translated into Epetra input arguments.
594  inArgs.setArgs(inArgs_in);
595 
596  // This is a special exception: see evalModel() in Thyra::ME
597  // documentation. If inArgs() supports x_dot but the evaluate call
598  // passes in a null value, then we need to make sure the null value
599  // gets passed on instead of the nominal value.
600  if (inArgs.supports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot)) {
601  if (is_null(inArgs_in.get_x_dot()))
602  inArgs.set_x_dot(Teuchos::null);
603  }
604 
605  // Print the header and the values of the inArgs and outArgs objects!
606  typedef double Scalar; // Needed for below macro!
607  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(
608  "Thyra::EpetraModelEvaluator",inArgs,outArgs,Teuchos::null
609  );
610 
611  // State function Scaling
612  const bool firstTimeStateFuncScaling
613  = (
616  );
617 
619  VOTSLOWSF W_factory_outputTempState(W_factory_,out,verbLevel);
620 
621  Teuchos::Time timer("");
622 
623  //
624  // B) Prepressess the InArgs and OutArgs in preparation to call
625  // the underlying EpetraExt::ModelEvaluator
626  //
627 
628  //
629  // B.1) Translate InArgs from Thyra to Epetra objects
630  //
631 
632  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
633  *out << "\nSetting-up/creating input arguments ...\n";
634  timer.start(true);
635 
636  // Unwrap input Thyra objects to get Epetra objects
637  EME::InArgs epetraScaledInArgs = epetraModel_->createInArgs();
638  convertInArgsFromThyraToEpetra( inArgs, &epetraScaledInArgs );
639 
640  // Unscale the input Epetra objects which will be passed to the underlying
641  // EpetraExt::ModelEvaluator object.
642  EME::InArgs epetraInArgs = epetraModel_->createInArgs();
643  EpetraExt::unscaleModelVars(
644  epetraScaledInArgs, epetraInArgsScaling_, &epetraInArgs,
645  out.get(), verbLevel
646  );
647 
648  timer.stop();
649  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
650  OSTab(out).o() << "\nTime to setup InArgs = "<<timer.totalElapsedTime()<<" sec\n";
651 
652  //
653  // B.2) Convert from Thyra to Epetra OutArgs
654  //
655 
656  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
657  *out << "\nSetting-up/creating output arguments ...\n";
658  timer.start(true);
659 
660  // The unscaled Epetra OutArgs that will be passed to the
661  // underlying EpetraExt::ModelEvaluator object
662  EME::OutArgs epetraUnscaledOutArgs = epetraModel_->createOutArgs();
663 
664  // Various objects that are needed later (see documentation in
665  // the function convertOutArgsFromThyraToEpetra(...)
667  RCP<EpetraLinearOp> efwdW;
669 
670  // Convert from Thyra to Epetra OutArgs and grap some of the intermediate
671  // objects accessed along the way that are needed later.
673  outArgs,
674  &epetraUnscaledOutArgs,
675  &W_op, &efwdW, &eW
676  );
677 
678  //
679  // B.3) Setup OutArgs to computing scaling if needed
680  //
681 
682  if (firstTimeStateFuncScaling) {
683  preEvalScalingSetup(&epetraInArgs,&epetraUnscaledOutArgs,out,verbLevel);
684  }
685 
686  timer.stop();
687  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
688  OSTab(out).o()
689  << "\nTime to setup OutArgs = "
690  << timer.totalElapsedTime() <<" sec\n";
691 
692  //
693  // C) Evaluate the underlying EpetraExt model to compute the Epetra outputs
694  //
695 
696  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
697  *out << "\nEvaluating the Epetra output functions ...\n";
698  timer.start(true);
699 
700  epetraModel_->evalModel(epetraInArgs,epetraUnscaledOutArgs);
701 
702  timer.stop();
703  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
704  OSTab(out).o()
705  << "\nTime to evaluate Epetra output functions = "
706  << timer.totalElapsedTime() <<" sec\n";
707 
708  //
709  // D) Postprocess the output objects
710  //
711 
712  //
713  // D.1) Compute the scaling factors if needed
714  //
715 
716  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
717  *out << "\nCompute scale factors if needed ...\n";
718  timer.start(true);
719 
720  if (firstTimeStateFuncScaling) {
721  postEvalScalingSetup(epetraUnscaledOutArgs,out,verbLevel);
722  }
723 
724  timer.stop();
725  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
726  OSTab(out).o()
727  << "\nTime to compute scale factors = "
728  << timer.totalElapsedTime() <<" sec\n";
729 
730  //
731  // D.2) Scale the output Epetra objects
732  //
733 
734  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
735  *out << "\nScale the output objects ...\n";
736  timer.start(true);
737 
738  EME::OutArgs epetraOutArgs = epetraModel_->createOutArgs();
739  bool allFuncsWhereScaled = false;
740  EpetraExt::scaleModelFuncs(
741  epetraUnscaledOutArgs, epetraInArgsScaling_, epetraOutArgsScaling_,
742  &epetraOutArgs, &allFuncsWhereScaled,
743  out.get(), verbLevel
744  );
746  !allFuncsWhereScaled, std::logic_error,
747  "Error, we can not currently handle epetra output objects that could not be"
748  " scaled. Special code will have to be added to handle this (i.e. using"
749  " implicit diagonal and multiplied linear operators to implicitly do"
750  " the scaling."
751  );
752 
753  timer.stop();
754  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
755  OSTab(out).o()
756  << "\nTime to scale the output objects = "
757  << timer.totalElapsedTime() << " sec\n";
758 
759  //
760  // D.3) Convert any Epetra objects to Thyra OutArgs objects that still need to
761  // be converted
762  //
763 
764  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
765  *out << "\nFinish processing and wrapping the output objects ...\n";
766  timer.start(true);
767 
769  epetraOutArgs, W_op, efwdW, eW,
770  outArgs
771  );
772 
773  timer.stop();
774  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
775  OSTab(out).o()
776  << "\nTime to finish processing and wrapping the output objects = "
777  << timer.totalElapsedTime() <<" sec\n";
778 
779  //
780  // E) Print footer to end the function
781  //
782 
783  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
784 
785 }
786 
787 
788 // private
789 
790 
792  const EpetraExt::ModelEvaluator::InArgs &epetraInArgs,
793  ModelEvaluatorBase::InArgs<double> *inArgs
794  ) const
795 {
796 
798  typedef ModelEvaluatorBase MEB;
799 
800  TEUCHOS_TEST_FOR_EXCEPT(!inArgs);
801 
802  if(inArgs->supports(MEB::IN_ARG_x)) {
803  inArgs->set_x( create_Vector( epetraInArgs.get_x(), x_space_ ) );
804  }
805 
806  if(inArgs->supports(MEB::IN_ARG_x_dot)) {
807  inArgs->set_x_dot( create_Vector( epetraInArgs.get_x_dot(), x_space_ ) );
808  }
809 
810  const int l_Np = inArgs->Np();
811  for( int l = 0; l < l_Np; ++l ) {
812  inArgs->set_p( l, create_Vector( epetraInArgs.get_p(l), p_space_[l] ) );
813  }
814 
815  if(inArgs->supports(MEB::IN_ARG_t)) {
816  inArgs->set_t(epetraInArgs.get_t());
817  }
818 
819 }
820 
821 
823  const ModelEvaluatorBase::InArgs<double> &inArgs,
824  EpetraExt::ModelEvaluator::InArgs *epetraInArgs
825  ) const
826 {
827 
828  using Teuchos::rcp;
829  using Teuchos::rcp_const_cast;
830 #ifdef HAVE_THYRA_ME_POLYNOMIAL
831  using Teuchos::Polynomial;
832 #endif // HAVE_THYRA_ME_POLYNOMIAL
833 
834 
835  TEUCHOS_TEST_FOR_EXCEPT(0==epetraInArgs);
836 
838  if( inArgs.supports(IN_ARG_x_dot) && (x_dot = inArgs.get_x_dot()).get() ) {
840  epetraInArgs->set_x_dot(e_x_dot);
841  }
842 
844  if( inArgs.supports(IN_ARG_x) && (x = inArgs.get_x()).get() ) {
846  epetraInArgs->set_x(e_x);
847  }
848 
850  for(int l = 0; l < inArgs.Np(); ++l ) {
851  p_l = inArgs.get_p(l);
852  if(p_l.get()) epetraInArgs->set_p(l,get_Epetra_Vector(*p_map_[l],p_l));
853  }
854 
855 #ifdef HAVE_THYRA_ME_POLYNOMIAL
856 
858  RCP<Epetra_Vector> epetra_ptr;
859  if(
860  inArgs.supports(IN_ARG_x_dot_poly)
861  && (x_dot_poly = inArgs.get_x_dot_poly()).get()
862  )
863  {
864  RCP<Polynomial<Epetra_Vector> > epetra_x_dot_poly =
865  rcp(new Polynomial<Epetra_Vector>(x_dot_poly->degree()));
866  for (unsigned int i=0; i<=x_dot_poly->degree(); i++) {
867  epetra_ptr = rcp_const_cast<Epetra_Vector>(
868  get_Epetra_Vector(*x_map_, x_dot_poly->getCoefficient(i)) );
869  epetra_x_dot_poly->setCoefficientPtr(i,epetra_ptr);
870  }
871  epetraInArgs->set_x_dot_poly(epetra_x_dot_poly);
872  }
873 
875  if(
876  inArgs.supports(IN_ARG_x_poly)
877  && (x_poly = inArgs.get_x_poly()).get()
878  )
879  {
880  RCP<Polynomial<Epetra_Vector> > epetra_x_poly =
881  rcp(new Polynomial<Epetra_Vector>(x_poly->degree()));
882  for (unsigned int i=0; i<=x_poly->degree(); i++) {
883  epetra_ptr = rcp_const_cast<Epetra_Vector>(
884  get_Epetra_Vector(*x_map_, x_poly->getCoefficient(i)) );
885  epetra_x_poly->setCoefficientPtr(i,epetra_ptr);
886  }
887  epetraInArgs->set_x_poly(epetra_x_poly);
888  }
889 
890 #endif // HAVE_THYRA_ME_POLYNOMIAL
891 
892  if( inArgs.supports(IN_ARG_t) )
893  epetraInArgs->set_t(inArgs.get_t());
894 
895  if( inArgs.supports(IN_ARG_alpha) )
896  epetraInArgs->set_alpha(inArgs.get_alpha());
897 
898  if( inArgs.supports(IN_ARG_beta) )
899  epetraInArgs->set_beta(inArgs.get_beta());
900 
901 }
902 
903 
905  const ModelEvaluatorBase::OutArgs<double> &outArgs,
906  EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs_inout,
907  RCP<LinearOpBase<double> > *W_op_out,
908  RCP<EpetraLinearOp> *efwdW_out,
909  RCP<Epetra_Operator> *eW_out
910  ) const
911 {
912 
913  using Teuchos::rcp;
914  using Teuchos::rcp_const_cast;
915  using Teuchos::rcp_dynamic_cast;
916  using Teuchos::OSTab;
919  typedef EpetraExt::ModelEvaluator EME;
920 
921  // Assert input
922 #ifdef TEUCHOS_DEBUG
923  TEUCHOS_ASSERT(epetraUnscaledOutArgs_inout);
924  TEUCHOS_ASSERT(W_op_out);
925  TEUCHOS_ASSERT(efwdW_out);
926  TEUCHOS_ASSERT(eW_out);
927 #endif
928 
929  // Create easy to use references
930  EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs = *epetraUnscaledOutArgs_inout;
931  RCP<LinearOpBase<double> > &W_op = *W_op_out;
932  RCP<EpetraLinearOp> &efwdW = *efwdW_out;
933  RCP<Epetra_Operator> &eW = *eW_out;
934 
935  // f
936  {
938  if( outArgs.supports(OUT_ARG_f) && (f = outArgs.get_f()).get() )
939  epetraUnscaledOutArgs.set_f(get_Epetra_Vector(*f_map_,f));
940  }
941 
942  // g
943  {
945  for(int j = 0; j < outArgs.Ng(); ++j ) {
946  g_j = outArgs.get_g(j);
947  if(g_j.get()) epetraUnscaledOutArgs.set_g(j,get_Epetra_Vector(*g_map_[j],g_j));
948  }
949  }
950 
951  // W_op
952  {
953 
954  if (outArgs.supports(OUT_ARG_W_op) && nonnull(W_op = outArgs.get_W_op())) {
955  if (nonnull(W_op) && is_null(efwdW)) {
956  efwdW = rcp_const_cast<EpetraLinearOp>(
957  rcp_dynamic_cast<const EpetraLinearOp>(W_op, true));
958  }
959  }
960 
961  if (nonnull(efwdW)) {
962  // By the time we get here, if we have an object in efwdW, then it
963  // should already be embeadded with an underlying Epetra_Operator object
964  // that was allocated by the EpetraExt::ModelEvaluator object.
965  // Therefore, we should just have to grab this object and be on our way.
966  eW = efwdW->epetra_op();
967  epetraUnscaledOutArgs.set_W(eW);
968  }
969 
970  // Note: The following derivative objects update in place!
971 
972  }
973 
974  // DfDp
975  {
976  Derivative<double> DfDp_l;
977  for(int l = 0; l < outArgs.Np(); ++l ) {
978  if( !outArgs.supports(OUT_ARG_DfDp,l).none()
979  && !(DfDp_l = outArgs.get_DfDp(l)).isEmpty() )
980  {
981  epetraUnscaledOutArgs.set_DfDp(l,convert(DfDp_l,f_map_,p_map_[l]));
982  }
983  }
984  }
985 
986  // DgDx_dot
987  {
988  Derivative<double> DgDx_dot_j;
989  for(int j = 0; j < outArgs.Ng(); ++j ) {
990  if( !outArgs.supports(OUT_ARG_DgDx_dot,j).none()
991  && !(DgDx_dot_j = outArgs.get_DgDx_dot(j)).isEmpty() )
992  {
993  epetraUnscaledOutArgs.set_DgDx_dot(j,convert(DgDx_dot_j,g_map_[j],x_map_));
994  }
995  }
996  }
997 
998  // DgDx
999  {
1000  Derivative<double> DgDx_j;
1001  for(int j = 0; j < outArgs.Ng(); ++j ) {
1002  if( !outArgs.supports(OUT_ARG_DgDx,j).none()
1003  && !(DgDx_j = outArgs.get_DgDx(j)).isEmpty() )
1004  {
1005  epetraUnscaledOutArgs.set_DgDx(j,convert(DgDx_j,g_map_[j],x_map_));
1006  }
1007  }
1008  }
1009 
1010  // DgDp
1011  {
1012  DerivativeSupport DgDp_j_l_support;
1013  Derivative<double> DgDp_j_l;
1014  for (int j = 0; j < outArgs.Ng(); ++j ) {
1015  for (int l = 0; l < outArgs.Np(); ++l ) {
1016  if (!(DgDp_j_l_support = outArgs.supports(OUT_ARG_DgDp,j,l)).none()
1017  && !(DgDp_j_l = outArgs.get_DgDp(j,l)).isEmpty() )
1018  {
1019  epetraUnscaledOutArgs.set_DgDp(j,l,convert(DgDp_j_l,g_map_[j],p_map_[l]));
1020  }
1021  }
1022  }
1023  }
1024 
1025 #ifdef HAVE_THYRA_ME_POLYNOMIAL
1026 
1027  // f_poly
1029  if( outArgs.supports(OUT_ARG_f_poly) && (f_poly = outArgs.get_f_poly()).get() )
1030  {
1031  RCP<Teuchos::Polynomial<Epetra_Vector> > epetra_f_poly =
1032  Teuchos::rcp(new Teuchos::Polynomial<Epetra_Vector>(f_poly->degree()));
1033  for (unsigned int i=0; i<=f_poly->degree(); i++) {
1034  RCP<Epetra_Vector> epetra_ptr
1035  = Teuchos::rcp_const_cast<Epetra_Vector>(get_Epetra_Vector(*f_map_,
1036  f_poly->getCoefficient(i)));
1037  epetra_f_poly->setCoefficientPtr(i,epetra_ptr);
1038  }
1039  epetraUnscaledOutArgs.set_f_poly(epetra_f_poly);
1040  }
1041 
1042 #endif // HAVE_THYRA_ME_POLYNOMIAL
1043 
1044 }
1045 
1046 
1048  EpetraExt::ModelEvaluator::InArgs *epetraInArgs_inout,
1049  EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs_inout,
1050  const RCP<Teuchos::FancyOStream> &out,
1051  const Teuchos::EVerbosityLevel verbLevel
1052  ) const
1053 {
1054 
1055  typedef EpetraExt::ModelEvaluator EME;
1056 
1057 #ifdef TEUCHOS_DEBUG
1058  TEUCHOS_ASSERT(epetraInArgs_inout);
1059  TEUCHOS_ASSERT(epetraUnscaledOutArgs_inout);
1060 #endif
1061 
1062  EpetraExt::ModelEvaluator::InArgs
1063  &epetraInArgs = *epetraInArgs_inout;
1064  EpetraExt::ModelEvaluator::OutArgs
1065  &epetraUnscaledOutArgs = *epetraUnscaledOutArgs_inout;
1066 
1067  if (
1069  &&
1070  (
1071  epetraUnscaledOutArgs.supports(EME::OUT_ARG_f)
1072  &&
1073  epetraUnscaledOutArgs.funcOrDerivesAreSet(EME::OUT_ARG_f)
1074  )
1075  &&
1076  (
1077  epetraUnscaledOutArgs.supports(EME::OUT_ARG_W)
1078  &&
1079  is_null(epetraUnscaledOutArgs.get_W())
1080  )
1081  )
1082  {
1083  // This is the first pass through with scaling turned on and the client
1084  // turned on automatic scaling but did not ask for W. We must compute W
1085  // in order to compute the scale factors so we must allocate a temporary W
1086  // just to compute the scale factors and then throw it away. If the
1087  // client wants to evaluate W at the same point, then it should have
1088  // passed W in but that is not our problem here. The ModelEvaluator
1089  // relies on the client to set up the calls to allow for efficient
1090  // evaluation.
1091 
1092  if(out.get() && verbLevel >= Teuchos::VERB_LOW)
1093  *out
1094  << "\nCreating a temporary Epetra W to compute scale factors"
1095  << " for f(...) ...\n";
1096  epetraUnscaledOutArgs.set_W(create_and_assert_W(*epetraModel_));
1097  if( epetraInArgs.supports(EME::IN_ARG_beta) )
1098  epetraInArgs.set_beta(1.0);
1099  if( epetraInArgs.supports(EME::IN_ARG_alpha) )
1100  epetraInArgs.set_alpha(0.0);
1101  }
1102 
1103 }
1104 
1105 
1107  const EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs,
1108  const RCP<Teuchos::FancyOStream> &out,
1109  const Teuchos::EVerbosityLevel verbLevel
1110  ) const
1111 {
1112 
1113  using Teuchos::OSTab;
1114  using Teuchos::rcp;
1115  using Teuchos::rcp_const_cast;
1117 
1118  // Compute the scale factors for the state function f(...)
1119  switch(stateFunctionScaling_) {
1120 
1122 
1123  // Compute the inverse row-sum scaling from W
1124 
1125  const RCP<Epetra_RowMatrix>
1126  ermW = get_Epetra_RowMatrix(epetraUnscaledOutArgs);
1127  // Note: Above, we get the Epetra W object directly from the Epetra
1128  // OutArgs object since this might be a temporary matrix just to
1129  // compute scaling factors. In this case, the stack funtion variable
1130  // eW might be empty!
1131 
1133  invRowSums = rcp(new Epetra_Vector(ermW->OperatorRangeMap()));
1134  // Above: From the documentation is seems that the RangeMap should be
1135  // okay but who knows for sure!
1136 
1137  ermW->InvRowSums(*invRowSums);
1138 
1139  if (out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW)) {
1140  *out
1141  << "\nComputed inverse row sum scaling from W that"
1142  " will be used to scale f(...) and its derivatives:\n";
1143  double minVal = 0, maxVal = 0, avgVal = 0;
1144  invRowSums->MinValue(&minVal);
1145  invRowSums->MaxValue(&maxVal);
1146  invRowSums->MeanValue(&avgVal);
1147  OSTab tab(out);
1148  *out
1149  << "min(invRowSums) = " << minVal << "\n"
1150  << "max(invRowSums) = " << maxVal << "\n"
1151  << "avg(invRowSums) = " << avgVal << "\n";
1152  }
1153 
1154  stateFunctionScalingVec_ = invRowSums;
1155 
1156  break;
1157 
1158  }
1159 
1160  default:
1161  TEUCHOS_TEST_FOR_EXCEPT("Should never get here!");
1162 
1163  }
1164 
1165  epetraOutArgsScaling_ = epetraModel_->createOutArgs();
1166 
1167  epetraOutArgsScaling_.set_f(
1168  rcp_const_cast<Epetra_Vector>(stateFunctionScalingVec_) );
1169 
1170 }
1171 
1172 
1174  const EpetraExt::ModelEvaluator::OutArgs &epetraOutArgs,
1175  RCP<LinearOpBase<double> > &W_op,
1176  RCP<EpetraLinearOp> &efwdW,
1178  const ModelEvaluatorBase::OutArgs<double> &outArgs
1179  ) const
1180 {
1181 
1182  using Teuchos::rcp_dynamic_cast;
1183  typedef EpetraExt::ModelEvaluator EME;
1184 
1185  if (nonnull(efwdW)) {
1186  efwdW->setFullyInitialized(true);
1187  // NOTE: Above will directly update W_op also if W.get()==NULL!
1188  }
1189 
1190  if (nonnull(W_op)) {
1191  if (W_op.shares_resource(efwdW)) {
1192  // W_op was already updated above since *efwdW is the same object as *W_op
1193  }
1194  else {
1195  rcp_dynamic_cast<EpetraLinearOp>(W_op, true)->setFullyInitialized(true);
1196  }
1197  }
1198 
1199 }
1200 
1201 
1203 {
1204 
1205  using Teuchos::rcp;
1206  using Teuchos::implicit_cast;
1207  typedef ModelEvaluatorBase MEB;
1208  typedef EpetraExt::ModelEvaluator EME;
1209 
1211 
1212  // Gather the nominal values and bounds into Epetra InArgs objects
1213 
1214  EME::InArgs epetraOrigNominalValues;
1215  EpetraExt::gatherModelNominalValues(
1216  *epetraModel_, &epetraOrigNominalValues );
1217 
1218  EME::InArgs epetraOrigLowerBounds;
1219  EME::InArgs epetraOrigUpperBounds;
1220  EpetraExt::gatherModelBounds(
1221  *epetraModel_, &epetraOrigLowerBounds, &epetraOrigUpperBounds );
1222 
1223  // Set up Epetra InArgs scaling object
1224 
1225  epetraInArgsScaling_ = epetraModel_->createInArgs();
1226 
1229  = EpetraExt::createInverseModelScalingVector(stateVariableScalingVec_);
1230  if( epetraOrigNominalValues.supports(EME::IN_ARG_x_dot) ) {
1232  }
1233  if( epetraOrigNominalValues.supports(EME::IN_ARG_x) ) {
1235  }
1236  }
1237 
1238  // Scale the original variables and bounds
1239 
1240  EME::InArgs epetraScaledNominalValues = epetraModel_->createInArgs();
1241  EpetraExt::scaleModelVars(
1242  epetraOrigNominalValues, epetraInArgsScaling_, &epetraScaledNominalValues
1243  );
1244 
1245  EME::InArgs epetraScaledLowerBounds = epetraModel_->createInArgs();
1246  EME::InArgs epetraScaledUpperBounds = epetraModel_->createInArgs();
1247  EpetraExt::scaleModelBounds(
1248  epetraOrigLowerBounds, epetraOrigUpperBounds, epetraModel_->getInfBound(),
1250  &epetraScaledLowerBounds, &epetraScaledUpperBounds
1251  );
1252 
1253  // Wrap the scaled epetra InArgs objects as Thyra InArgs objects!
1254 
1255  nominalValues_ = this->createInArgs();
1256  lowerBounds_ = this->createInArgs();
1257  upperBounds_ = this->createInArgs();
1258  convertInArgsFromEpetraToThyra(epetraScaledNominalValues, &nominalValues_);
1259  convertInArgsFromEpetraToThyra(epetraScaledLowerBounds, &lowerBounds_);
1260  convertInArgsFromEpetraToThyra(epetraScaledUpperBounds, &upperBounds_);
1261 
1263 
1264  }
1265  else {
1266 
1267  // The nominal values and bounds should already be updated an should have
1268  // the currect scaling!
1269 
1270  }
1271 
1272 }
1273 
1274 
1276 {
1277 
1278  typedef EpetraExt::ModelEvaluator EME;
1279 
1280  const EpetraExt::ModelEvaluator &epetraModel = *epetraModel_;
1281  EME::InArgs epetraInArgs = epetraModel.createInArgs();
1282  EME::OutArgs epetraOutArgs = epetraModel.createOutArgs();
1283  const int l_Np = epetraOutArgs.Np();
1284  const int l_Ng = epetraOutArgs.Ng();
1285 
1286  //
1287  // InArgs
1288  //
1289 
1290  InArgsSetup<double> inArgs;
1291  inArgs.setModelEvalDescription(this->description());
1292  inArgs.set_Np(epetraInArgs.Np());
1293  inArgs.setSupports(IN_ARG_x_dot, epetraInArgs.supports(EME::IN_ARG_x_dot));
1294  inArgs.setSupports(IN_ARG_x, epetraInArgs.supports(EME::IN_ARG_x));
1295 #ifdef HAVE_THYRA_ME_POLYNOMIAL
1296  inArgs.setSupports(IN_ARG_x_dot_poly,
1297  epetraInArgs.supports(EME::IN_ARG_x_dot_poly));
1298  inArgs.setSupports(IN_ARG_x_poly, epetraInArgs.supports(EME::IN_ARG_x_poly));
1299 #endif // HAVE_THYRA_ME_POLYNOMIAL
1300  inArgs.setSupports(IN_ARG_t, epetraInArgs.supports(EME::IN_ARG_t));
1301  inArgs.setSupports(IN_ARG_alpha, epetraInArgs.supports(EME::IN_ARG_alpha));
1302  inArgs.setSupports(IN_ARG_beta, epetraInArgs.supports(EME::IN_ARG_beta));
1303  prototypeInArgs_ = inArgs;
1304 
1305  //
1306  // OutArgs
1307  //
1308 
1309  OutArgsSetup<double> outArgs;
1310  outArgs.setModelEvalDescription(this->description());
1311  outArgs.set_Np_Ng(l_Np, l_Ng);
1312  // f
1313  outArgs.setSupports(OUT_ARG_f, epetraOutArgs.supports(EME::OUT_ARG_f));
1314  if (outArgs.supports(OUT_ARG_f)) {
1315  // W_op
1316  outArgs.setSupports(OUT_ARG_W_op, epetraOutArgs.supports(EME::OUT_ARG_W));
1317  outArgs.set_W_properties(convert(epetraOutArgs.get_W_properties()));
1318  // DfDp
1319  for(int l=0; l<l_Np; ++l) {
1320  outArgs.setSupports(OUT_ARG_DfDp, l,
1321  convert(epetraOutArgs.supports(EME::OUT_ARG_DfDp, l)));
1322  if(!outArgs.supports(OUT_ARG_DfDp, l).none())
1323  outArgs.set_DfDp_properties(l,
1324  convert(epetraOutArgs.get_DfDp_properties(l)));
1325  }
1326  }
1327  // DgDx_dot and DgDx
1328  for(int j=0; j<l_Ng; ++j) {
1329  if (inArgs.supports(IN_ARG_x_dot))
1330  outArgs.setSupports(OUT_ARG_DgDx_dot, j,
1331  convert(epetraOutArgs.supports(EME::OUT_ARG_DgDx_dot, j)));
1332  if(!outArgs.supports(OUT_ARG_DgDx_dot, j).none())
1333  outArgs.set_DgDx_dot_properties(j,
1334  convert(epetraOutArgs.get_DgDx_dot_properties(j)));
1335  if (inArgs.supports(IN_ARG_x))
1336  outArgs.setSupports(OUT_ARG_DgDx, j,
1337  convert(epetraOutArgs.supports(EME::OUT_ARG_DgDx, j)));
1338  if(!outArgs.supports(OUT_ARG_DgDx, j).none())
1339  outArgs.set_DgDx_properties(j,
1340  convert(epetraOutArgs.get_DgDx_properties(j)));
1341  }
1342  // DgDp
1343  for(int j=0; j < l_Ng; ++j) for(int l=0; l < l_Np; ++l) {
1344  const EME::DerivativeSupport epetra_DgDp_j_l_support =
1345  epetraOutArgs.supports(EME::OUT_ARG_DgDp, j, l);
1346  outArgs.setSupports(OUT_ARG_DgDp, j, l,
1347  convert(epetra_DgDp_j_l_support));
1348  if(!outArgs.supports(OUT_ARG_DgDp, j, l).none())
1349  outArgs.set_DgDp_properties(j, l,
1350  convert(epetraOutArgs.get_DgDp_properties(j, l)));
1351  }
1352 #ifdef HAVE_THYRA_ME_POLYNOMIAL
1353  outArgs.setSupports(OUT_ARG_f_poly,
1354  epetraOutArgs.supports(EME::OUT_ARG_f_poly));
1355 #endif // HAVE_THYRA_ME_POLYNOMIAL
1356  prototypeOutArgs_ = outArgs;
1357 
1358  // We are current!
1359  currentInArgsOutArgs_ = true;
1360 
1361 }
1362 
1363 
1366 {
1367  return Thyra::partialNonconstEpetraLinearOp(
1368  this->get_f_space(), this->get_x_space(),
1369  create_and_assert_W(*epetraModel_)
1370  );
1371 }
1372 
1373 
1374 } // namespace Thyra
1375 
1376 
1377 //
1378 // Non-member utility functions
1379 //
1380 
1381 
1383 Thyra::epetraModelEvaluator(
1384  const RCP<const EpetraExt::ModelEvaluator> &epetraModel,
1385  const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
1386  )
1387 {
1388  return Teuchos::rcp(new EpetraModelEvaluator(epetraModel,W_factory));
1389 }
1390 
1391 
1392 Thyra::ModelEvaluatorBase::EDerivativeMultiVectorOrientation
1393 Thyra::convert(
1394  const EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation &mvOrientation
1395  )
1396 {
1397  switch(mvOrientation) {
1398  case EpetraExt::ModelEvaluator::DERIV_MV_BY_COL :
1399  return ModelEvaluatorBase::DERIV_MV_BY_COL;
1400  case EpetraExt::ModelEvaluator::DERIV_TRANS_MV_BY_ROW :
1401  return ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW;
1402  default:
1404  }
1405  return ModelEvaluatorBase::DERIV_MV_BY_COL; // Should never be called!
1406 }
1407 
1408 
1409 EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation
1410 Thyra::convert(
1411  const ModelEvaluatorBase::EDerivativeMultiVectorOrientation &mvOrientation
1412  )
1413 {
1414  switch(mvOrientation) {
1415  case ModelEvaluatorBase::DERIV_MV_BY_COL :
1416  return EpetraExt::ModelEvaluator::DERIV_MV_BY_COL;
1417  case ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW :
1418  return EpetraExt::ModelEvaluator::DERIV_TRANS_MV_BY_ROW;
1419  default:
1421  }
1422  return EpetraExt::ModelEvaluator::DERIV_MV_BY_COL; // Should never be called!
1423 }
1424 
1425 
1426 Thyra::ModelEvaluatorBase::DerivativeProperties
1427 Thyra::convert(
1428  const EpetraExt::ModelEvaluator::DerivativeProperties &derivativeProperties
1429  )
1430 {
1431  ModelEvaluatorBase::EDerivativeLinearity linearity;
1432  switch(derivativeProperties.linearity) {
1433  case EpetraExt::ModelEvaluator::DERIV_LINEARITY_UNKNOWN:
1434  linearity = ModelEvaluatorBase::DERIV_LINEARITY_UNKNOWN;
1435  break;
1436  case EpetraExt::ModelEvaluator::DERIV_LINEARITY_CONST:
1437  linearity = ModelEvaluatorBase::DERIV_LINEARITY_CONST;
1438  break;
1439  case EpetraExt::ModelEvaluator::DERIV_LINEARITY_NONCONST:
1440  linearity = ModelEvaluatorBase::DERIV_LINEARITY_NONCONST;
1441  break;
1442  default:
1444  }
1445  ModelEvaluatorBase::ERankStatus rank;
1446  switch(derivativeProperties.rank) {
1447  case EpetraExt::ModelEvaluator::DERIV_RANK_UNKNOWN:
1448  rank = ModelEvaluatorBase::DERIV_RANK_UNKNOWN;
1449  break;
1450  case EpetraExt::ModelEvaluator::DERIV_RANK_FULL:
1451  rank = ModelEvaluatorBase::DERIV_RANK_FULL;
1452  break;
1453  case EpetraExt::ModelEvaluator::DERIV_RANK_DEFICIENT:
1454  rank = ModelEvaluatorBase::DERIV_RANK_DEFICIENT;
1455  break;
1456  default:
1458  }
1459  return ModelEvaluatorBase::DerivativeProperties(
1460  linearity,rank,derivativeProperties.supportsAdjoint);
1461 }
1462 
1463 
1464 Thyra::ModelEvaluatorBase::DerivativeSupport
1465 Thyra::convert(
1466  const EpetraExt::ModelEvaluator::DerivativeSupport &derivativeSupport
1467  )
1468 {
1469  ModelEvaluatorBase::DerivativeSupport ds;
1470  if(derivativeSupport.supports(EpetraExt::ModelEvaluator::DERIV_LINEAR_OP))
1471  ds.plus(ModelEvaluatorBase::DERIV_LINEAR_OP);
1472  if(derivativeSupport.supports(EpetraExt::ModelEvaluator::DERIV_MV_BY_COL))
1473  ds.plus(ModelEvaluatorBase::DERIV_MV_BY_COL);
1474  if(derivativeSupport.supports(EpetraExt::ModelEvaluator::DERIV_TRANS_MV_BY_ROW))
1475  ds.plus(ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW);
1476  return ds;
1477 }
1478 
1479 
1480 EpetraExt::ModelEvaluator::Derivative
1481 Thyra::convert(
1482  const ModelEvaluatorBase::Derivative<double> &derivative,
1483  const RCP<const Epetra_Map> &fnc_map,
1484  const RCP<const Epetra_Map> &var_map
1485  )
1486 {
1487  typedef ModelEvaluatorBase MEB;
1488  if(derivative.getLinearOp().get()) {
1489  return EpetraExt::ModelEvaluator::Derivative(
1490  Teuchos::rcp_const_cast<Epetra_Operator>(
1491  Teuchos::dyn_cast<const EpetraLinearOp>(*derivative.getLinearOp()).epetra_op()
1492  )
1493  );
1494  }
1495  else if(derivative.getDerivativeMultiVector().getMultiVector().get()) {
1496  return EpetraExt::ModelEvaluator::Derivative(
1497  EpetraExt::ModelEvaluator::DerivativeMultiVector(
1499  ( derivative.getDerivativeMultiVector().getOrientation() == MEB::DERIV_MV_BY_COL
1500  ? *fnc_map
1501  : *var_map
1502  )
1503  ,derivative.getDerivativeMultiVector().getMultiVector()
1504  )
1505  ,convert(derivative.getDerivativeMultiVector().getOrientation())
1506  )
1507  );
1508  }
1509  return EpetraExt::ModelEvaluator::Derivative();
1510 }
RCP< Epetra_MultiVector > get_Epetra_MultiVector(const Epetra_Map &map, const RCP< MultiVectorBase< double > > &mv)
Get a non-const Epetra_MultiVector view from a non-const MultiVectorBase object if possible...
const ModelEvaluatorBase::InArgs< double > & getFinalPoint() const
ModelEvaluatorBase::InArgs< double > getLowerBounds() const
void setNominalValues(const ModelEvaluatorBase::InArgs< double > &nominalValues)
Set the nominal values.
void convertInArgsFromEpetraToThyra(const EpetraExt::ModelEvaluator::InArgs &epetraInArgs, ModelEvaluatorBase::InArgs< double > *inArgs) const
Concrete LinearOpBase adapter subclass for Epetra_Operator object.
RCP< const EpetraExt::ModelEvaluator > getEpetraModel() const
void f()
std::string typeName(const T &t)
void reportFinalPoint(const ModelEvaluatorBase::InArgs< double > &finalPoint, const bool wasSolved)
bool is_null(const boost::shared_ptr< T > &p)
void preEvalScalingSetup(EpetraExt::ModelEvaluator::InArgs *epetraInArgs, EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs, const RCP< Teuchos::FancyOStream > &out, const Teuchos::EVerbosityLevel verbLevel) const
ModelEvaluatorBase::OutArgs< double > createOutArgsImpl() const
RCP< LinearOpBase< double > > create_DgDx_dot_op_impl(int j) const
RCP< const Teuchos::ParameterList > getValidParameters() const
RCP< LinearOpBase< double > > create_W_op() const
ModelEvaluatorBase::InArgs< double > getNominalValues() const
RCP< Teuchos::ParameterList > getNonconstParameterList()
RCP< LinearOpWithSolveFactoryBase< double > > W_factory_
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
RCP< const VectorSpaceBase< double > > create_VectorSpace(const RCP< const Epetra_Map > &epetra_map)
Create an VectorSpaceBase object given an Epetra_Map object.
void convertOutArgsFromThyraToEpetra(const ModelEvaluatorBase::OutArgs< double > &outArgs, EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs, RCP< LinearOpBase< double > > *W_op, RCP< EpetraLinearOp > *efwdW, RCP< Epetra_Operator > *eW) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< PreconditionerBase< double > > create_W_prec() const
Returns null currently.
T * get() const
void setStateVariableScalingVec(const RCP< const Epetra_Vector > &stateVariableScalingVec)
Set the state variable scaling vector s_x (see above).
ModelEvaluatorBase::InArgs< double > createInArgs() const
RCP< VectorBase< double > > create_Vector(const RCP< Epetra_Vector > &epetra_v, const RCP< const VectorSpaceBase< double > > &space)
Create a non-const VectorBase object from a non-const Epetra_Vector object.
basic_OSTab< char > OSTab
EpetraExt::ModelEvaluator::OutArgs epetraOutArgsScaling_
void convertInArgsFromThyraToEpetra(const ModelEvaluatorBase::InArgs< double > &inArgs, EpetraExt::ModelEvaluator::InArgs *epetraInArgs) const
RCP< const VectorSpaceBase< double > > x_space_
RCP< const Epetra_Vector > getStateVariableScalingVec() const
Get the inverse state variable scaling vector inv_s_x (see above).
ModelEvaluatorBase::OutArgs< double > prototypeOutArgs_
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
void start(bool reset=false)
RCP< const Teuchos::ParameterList > getParameterList() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< const LinearOpWithSolveFactoryBase< double > > get_W_factory() const
RCP< const Epetra_Vector > getStateVariableInvScalingVec() const
Get the state variable scaling vector s_x (see above).
RCP< const VectorSpaceBase< double > > f_space_
double stop()
ModelEvaluatorBase::InArgs< double > getUpperBounds() const
ModelEvaluatorBase::InArgs< double > finalPoint_
void setStateFunctionScalingVec(const RCP< const Epetra_Vector > &stateFunctionScalingVec)
Set the state function scaling vector s_f (see above).
RCP< LinearOpBase< double > > create_DgDx_op_impl(int j) const
ModelEvaluatorBase::InArgs< double > lowerBounds_
RCP< const Epetra_Vector > getStateFunctionScalingVec() const
Get the state function scaling vector s_f (see above).
RCP< Epetra_Vector > get_Epetra_Vector(const Epetra_Map &map, const RCP< VectorBase< double > > &v)
Get a non-const Epetra_Vector view from a non-const VectorBase object if possible.
RCP< EpetraLinearOp > create_epetra_W_op() const
void initialize(const RCP< const EpetraExt::ModelEvaluator > &epetraModel, const RCP< LinearOpWithSolveFactoryBase< double > > &W_factory)
RCP< const VectorSpaceBase< double > > get_f_space() const
RCP< LinearOpBase< double > > create_DfDp_op_impl(int l) const
RCP< const VectorSpaceBase< double > > get_x_space() const
RCP< const VectorSpaceBase< double > > get_g_space(int j) const
EpetraExt::ModelEvaluator::InArgs epetraInArgsScaling_
RCP< const VectorSpaceBase< double > > get_p_space(int l) const
void resize(size_type new_size, const value_type &x=value_type())
RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
void setParameterList(RCP< Teuchos::ParameterList > const &paramList)
TEUCHOSCORE_LIB_DLL_EXPORT bool includesVerbLevel(const EVerbosityLevel verbLevel, const EVerbosityLevel requestedVerbLevel, const bool isDefaultLevel=false)
TypeTo implicit_cast(const TypeFrom &t)
const RCP< T > & assert_not_null() const
RCP< LinearOpBase< double > > create_DgDp_op_impl(int j, int l) const
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
RCP< const Epetra_Vector > stateFunctionScalingVec_
ModelEvaluatorBase::EDerivativeMultiVectorOrientation convert(const EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation &mvOrientation)
void postEvalScalingSetup(const EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs, const RCP< Teuchos::FancyOStream > &out, const Teuchos::EVerbosityLevel verbLevel) const
void uninitialize(RCP< const EpetraExt::ModelEvaluator > *epetraModel=NULL, RCP< LinearOpWithSolveFactoryBase< double > > *W_factory=NULL)
bool nonnull(const boost::shared_ptr< T > &p)
void evalModelImpl(const ModelEvaluatorBase::InArgs< double > &inArgs, const ModelEvaluatorBase::OutArgs< double > &outArgs) const
void finishConvertingOutArgsFromEpetraToThyra(const EpetraExt::ModelEvaluator::OutArgs &epetraOutArgs, RCP< LinearOpBase< double > > &W_op, RCP< EpetraLinearOp > &efwdW, RCP< Epetra_Operator > &eW, const ModelEvaluatorBase::OutArgs< double > &outArgs) const
ModelEvaluatorBase::InArgs< double > prototypeInArgs_
size_type size() const
double totalElapsedTime(bool readCurrentTime=false) const
RCP< const Epetra_Vector > stateVariableScalingVec_
RCP< const EpetraExt::ModelEvaluator > epetraModel_
RCP< Teuchos::ParameterList > paramList_
ModelEvaluatorBase::InArgs< double > nominalValues_
#define TEUCHOS_ASSERT(assertion_test)
RCP< Teuchos::ParameterList > unsetParameterList()
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
RCP< const Epetra_Vector > invStateVariableScalingVec_
ModelEvaluatorBase::InArgs< double > upperBounds_