|
Rythmos - Transient Integration for Differential Equations Version of the Day
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // Rythmos Package 00005 // Copyright (2006) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 00029 00030 #ifndef Rythmos_INTEGRATOR_BUILDER_DEF_H 00031 #define Rythmos_INTEGRATOR_BUILDER_DEF_H 00032 00033 // Rythmos classes: 00034 #include "Rythmos_IntegratorBuilder_decl.hpp" 00035 #include "Rythmos_IntegrationControlStrategyAcceptingIntegratorBase.hpp" 00036 #include "Rythmos_SolverAcceptingStepperBase.hpp" 00037 00038 // Teuchos: 00039 #include "Teuchos_as.hpp" 00040 00041 // Specific objects to seed the builder: 00042 #include "Rythmos_DefaultIntegrator.hpp" 00043 #include "Rythmos_SimpleIntegrationControlStrategy.hpp" 00044 #include "Rythmos_ImplicitBDFStepperStepControl.hpp" 00045 #include "Rythmos_InterpolationBuffer.hpp" 00046 #include "Rythmos_PointwiseInterpolationBufferAppender.hpp" 00047 //#include "Rythmos_SmartInterpolationBufferAppender.hpp" 00048 #include "Rythmos_ImplicitBDFStepperErrWtVecCalc.hpp" 00049 #include "Rythmos_LinearInterpolator.hpp" 00050 #include "Rythmos_HermiteInterpolator.hpp" 00051 #include "Rythmos_CubicSplineInterpolator.hpp" 00052 00053 // Includes for the Forward Sensitivity Integrator Builder: 00054 #include "Rythmos_ForwardSensitivityStepper.hpp" 00055 00056 00057 namespace { 00058 00059 // Valid ParameterList names: 00060 static std::string integratorSettings_name = "Integrator Settings"; 00061 static std::string integratorSettings_docs = 00062 "These parameters are used directly in setting up the Integrator"; 00063 static std::string integratorSelection_name = "Integrator Selection"; 00064 static std::string integrationControlSelection_name = 00065 "Integration Control Strategy Selection"; 00066 static std::string integrationControlSelection_docs = 00067 "Note that some settings conflict between step control and integration control.\n" 00068 "In general, the integration control decides which steps will be fixed or variable,\n" 00069 "not the stepper. When the integration control decides to take variable steps, the\n" 00070 "step control is then responsible for choosing appropriate step-sizes."; 00071 static std::string stepperSettings_name = "Stepper Settings"; 00072 static std::string stepperSelection_name = "Stepper Selection"; 00073 static std::string stepperSelection_docs = 00074 "Special note for Implicit RK Stepper: If a fully implicit RK Butcher tableau is\n" 00075 "chosen, then the stepper will not be fully initialized unless a W factory object\n" 00076 "is set on the IntegratorBuilder through setWFactoryObject."; 00077 static std::string stepControlSettings_name = "Step Control Settings"; 00078 static std::string stepControlSettings_docs = 00079 "Not all step control strategies are compatible with each stepper. If the strategy\n" 00080 "has the name of a stepper in its name, then it only works with that stepper."; 00081 static std::string stepControlSelection_name = "Step Control Strategy Selection"; 00082 static std::string errWtVecSelection_name = "Error Weight Vector Calculator Selection"; 00083 static std::string errWtVecSelection_docs = 00084 "Not all ErrWtVec calculators are compatible with each step control strategy.\n" 00085 "If the calculator has the name of a stepper or another step control strategy in\n" 00086 "its name, then it only works with that step control strategy."; 00087 static std::string interpolationBufferSettings_name = "Interpolation Buffer Settings"; 00088 static std::string interpolationBufferSelection_name = "Trailing Interpolation Buffer Selection"; 00089 static std::string interpolationBufferAppenderSelection_name = "Interpolation Buffer Appender Selection"; 00090 static std::string finalTime_name = "Final Time"; 00091 static int finalTime_default = 1; // Should be Scalar(1.0) 00092 static std::string landOnFinalTime_name = "Land On Final Time"; 00093 static bool landOnFinalTime_default = true; 00094 static std::string interpolatorSelection_name = "Interpolator Selection"; 00095 static std::string stepperInterpolatorSelection_docs = 00096 "Note all Steppers accept an interpolator. Currently, only the BackwardEuler\n" 00097 "stepper does."; 00098 static std::string rkButcherTableauSelection_name = "Runge Kutta Butcher Tableau Selection"; 00099 static std::string rkButcherTableauSelection_docs = 00100 "Only the Explicit RK Stepper and the Implicit RK Stepper accept an RK Butcher\n" 00101 "Tableau."; 00102 00103 // Builder names: 00104 static std::string integratorBuilder_name = "Rythmos::Integrator"; 00105 static std::string integratorBuilderType_name = "Integrator Type"; 00106 static std::string integrationControlBuilder_name = "Rythmos::IntegrationControlStrategy"; 00107 static std::string integrationControlBuilderType_name = "Integration Control Strategy Type"; 00108 static std::string stepControlBuilder_name = "Rythmos::StepControlStrategy"; 00109 static std::string stepControlBuilderType_name = "Step Control Strategy Type"; 00110 static std::string interpolationBufferBuilder_name = "Rythmos::InterpolationBuffer"; 00111 static std::string interpolationBufferBuilderType_name = "Interpolation Buffer Type"; 00112 static std::string interpolationBufferAppenderBuilder_name = "Rythmos::InterpolationBufferAppender"; 00113 static std::string interpolationBufferAppenderBuilderType_name = "Interpolation Buffer Appender Type"; 00114 static std::string errWtVecCalcBuilder_name = "Rythmos::ErrWtVecCalc"; 00115 static std::string errWtVecCalcBuilderType_name = "Error Weight Vector Calculator Type"; 00116 static std::string interpolatorBuilder_name = "Rythmos::Interpolator"; 00117 static std::string interpolatorBuilderType_name = "Interpolator Type"; 00118 00119 // Specific object names: 00120 static std::string defaultIntegrator_name = "Default Integrator"; 00121 static std::string simpleIntegrationControl_name = "Simple Integration Control Strategy"; 00122 static std::string implicitBDFStepControl_name = "Implicit BDF Stepper Step Control Strategy"; 00123 static std::string defaultInterpolationBuffer_name = "Interpolation Buffer"; 00124 static std::string pointwiseInterpolationBufferAppender_name = "Pointwise Interpolation Buffer Appender"; 00125 // static std::string smartInterpolationBufferAppender_name = "Smart Interpolation Buffer Appender"; 00126 static std::string implicitBDFStepperErrWtVecCalc_name = "Implicit BDF Stepper Error Weight Vector Calculator"; 00127 static std::string linearInterpolator_name = "Linear Interpolator"; 00128 static std::string hermiteInterpolator_name = "Hermite Interpolator"; 00129 static std::string cubicSplineInterpolator_name = "Cubic Spline Interpolator"; 00130 00131 } // namespace 00132 00133 00134 namespace Rythmos { 00135 00136 00137 template<class Scalar> 00138 IntegratorBuilder<Scalar>::IntegratorBuilder() 00139 { 00140 this->initializeDefaults_(); 00141 } 00142 00143 00144 template<class Scalar> 00145 IntegratorBuilder<Scalar>::~IntegratorBuilder() 00146 { 00147 } 00148 00149 00150 template<class Scalar> 00151 void IntegratorBuilder<Scalar>::setIntegratorFactory( 00152 const RCP<const Teuchos::AbstractFactory<IntegratorBase<Scalar> > > &integratorFactory, 00153 const std::string &integratorName 00154 ) 00155 { 00156 integratorBuilder_->setObjectFactory(integratorFactory, integratorName); 00157 validPL_ = Teuchos::null; 00158 } 00159 00160 00161 template<class Scalar> 00162 void IntegratorBuilder<Scalar>::setIntegrationControlFactory( 00163 const RCP<const Teuchos::AbstractFactory<IntegrationControlStrategyBase<Scalar> > > &integrationControlFactory, 00164 const std::string &integrationControlName 00165 ) 00166 { 00167 integrationControlBuilder_->setObjectFactory(integrationControlFactory, integrationControlName); 00168 validPL_ = Teuchos::null; 00169 } 00170 00171 00172 template<class Scalar> 00173 void IntegratorBuilder<Scalar>::setStepperBuilder( 00174 const RCP<StepperBuilder<Scalar> > &stepperBuilder 00175 ) 00176 { 00177 TEST_FOR_EXCEPT(is_null(stepperBuilder)); 00178 stepperBuilder_ = stepperBuilder; 00179 validPL_ = Teuchos::null; 00180 } 00181 00182 00183 template<class Scalar> 00184 RCP<StepperBuilder<Scalar> > IntegratorBuilder<Scalar>::getStepperBuilder() 00185 { 00186 return stepperBuilder_; 00187 } 00188 00189 00190 template<class Scalar> 00191 void IntegratorBuilder<Scalar>::setRKButcherTableauBuilder( 00192 const RCP<RKButcherTableauBuilder<Scalar> > & rkbtBuilder 00193 ) 00194 { 00195 TEST_FOR_EXCEPT(is_null(rkbtBuilder)); 00196 rkbtBuilder_ = rkbtBuilder; 00197 validPL_ = Teuchos::null; 00198 } 00199 00200 00201 template<class Scalar> 00202 void IntegratorBuilder<Scalar>::setStepControlFactory( 00203 const RCP<const Teuchos::AbstractFactory<StepControlStrategyBase<Scalar> > > &stepControlStrategyFactory, 00204 const std::string &stepControlName 00205 ) 00206 { 00207 stepControlBuilder_->setObjectFactory(stepControlStrategyFactory, stepControlName); 00208 validPL_ = Teuchos::null; 00209 } 00210 00211 00212 template<class Scalar> 00213 void IntegratorBuilder<Scalar>::setInterpolationBufferFactory( 00214 const RCP<const Teuchos::AbstractFactory<InterpolationBufferBase<Scalar> > > &interpolationBufferFactory, 00215 const std::string &interpolationBufferName 00216 ) 00217 { 00218 interpolationBufferBuilder_->setObjectFactory(interpolationBufferFactory, interpolationBufferName); 00219 validPL_ = Teuchos::null; 00220 } 00221 00222 00223 template<class Scalar> 00224 void IntegratorBuilder<Scalar>::setInterpolationBufferAppenderFactory( 00225 const RCP<const Teuchos::AbstractFactory<InterpolationBufferAppenderBase<Scalar> > > &interpolationBufferAppenderFactory, 00226 const std::string &interpolationBufferAppenderName 00227 ) 00228 { 00229 interpolationBufferAppenderBuilder_->setObjectFactory(interpolationBufferAppenderFactory, interpolationBufferAppenderName); 00230 validPL_ = Teuchos::null; 00231 } 00232 00233 00234 template<class Scalar> 00235 void IntegratorBuilder<Scalar>::setErrWtVecCalcFactory( 00236 const RCP<const Teuchos::AbstractFactory<ErrWtVecCalcBase<Scalar> > > &errWtVecCalcFactory, 00237 const std::string &errWtVecCalcFactoryName 00238 ) 00239 { 00240 errWtVecCalcBuilder_->setObjectFactory(errWtVecCalcFactory,errWtVecCalcFactoryName); 00241 validPL_ = Teuchos::null; 00242 } 00243 00244 00245 template<class Scalar> 00246 void IntegratorBuilder<Scalar>::setInterpolatorFactory( 00247 const RCP<const Teuchos::AbstractFactory<InterpolatorBase<Scalar> > > &interpolatorFactory, 00248 const std::string &interpolatorFactoryName 00249 ) 00250 { 00251 interpolatorBuilder_->setObjectFactory(interpolatorFactory,interpolatorFactoryName); 00252 validPL_ = Teuchos::null; 00253 } 00254 00255 00256 template<class Scalar> 00257 void IntegratorBuilder<Scalar>::setWFactoryObject( 00258 const RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > &wFactoryObject 00259 ) 00260 { 00261 TEUCHOS_ASSERT( !is_null(wFactoryObject) ); 00262 wFactoryObject_ = wFactoryObject; 00263 } 00264 00265 00266 template<class Scalar> 00267 void IntegratorBuilder<Scalar>::setParameterList( 00268 RCP<Teuchos::ParameterList> const& paramList 00269 ) 00270 { 00271 TEST_FOR_EXCEPT(is_null(paramList)); 00272 paramList->validateParameters(*this->getValidParameters()); 00273 paramList_ = paramList; 00274 } 00275 00276 00277 template<class Scalar> 00278 RCP<const Teuchos::ParameterList> 00279 IntegratorBuilder<Scalar>::getValidParameters() const 00280 { 00281 if (is_null(validPL_)) { 00282 RCP<ParameterList> pl = Teuchos::parameterList(); 00283 00284 // Integrator Settings 00285 ParameterList& integratorSettingsPL = pl->sublist(integratorSettings_name,false,integratorSettings_docs); 00286 { 00287 // Final Time 00288 integratorSettingsPL.set(finalTime_name,Teuchos::as<Scalar>(finalTime_default)); 00289 // Land On Final Time 00290 integratorSettingsPL.set(landOnFinalTime_name,landOnFinalTime_default); 00291 // Integrator Selection 00292 ParameterList& integratorSelectionPL = 00293 integratorSettingsPL.sublist(integratorSelection_name).disableRecursiveValidation(); 00294 integratorSelectionPL.setParameters(*(integratorBuilder_->getValidParameters())); 00295 } 00296 // Integration Control Selection 00297 ParameterList& integrationControlSelectionPL = pl->sublist(integrationControlSelection_name,false,integrationControlSelection_docs).disableRecursiveValidation(); 00298 integrationControlSelectionPL.setParameters(*(integrationControlBuilder_->getValidParameters())); 00299 // Stepper Settings 00300 ParameterList& stepperSettingsPL = pl->sublist(stepperSettings_name); 00301 { 00302 // Stepper Selection 00303 ParameterList& stepperSelectionPL = stepperSettingsPL.sublist(stepperSelection_name).disableRecursiveValidation(); 00304 stepperSelectionPL.setParameters(*(stepperBuilder_->getValidParameters())); 00305 // Step Control Settings 00306 ParameterList& stepControlSettingsPL = stepperSettingsPL.sublist(stepControlSettings_name, false, stepControlSettings_docs); 00307 { 00308 // Step Control Selection 00309 ParameterList& stepControlSelectionPL = stepControlSettingsPL.sublist(stepControlSelection_name).disableRecursiveValidation(); 00310 stepControlSelectionPL.setParameters(*(stepControlBuilder_->getValidParameters())); 00311 // ErrWtVec Selection 00312 ParameterList& errWtVecSelectionPL = stepControlSettingsPL.sublist(errWtVecSelection_name,false,errWtVecSelection_docs).disableRecursiveValidation(); 00313 errWtVecSelectionPL.setParameters(*(errWtVecCalcBuilder_->getValidParameters())); 00314 } 00315 // Interpolator Selection 00316 ParameterList& interpolatorSelectionPL = stepperSettingsPL.sublist(interpolatorSelection_name,false,stepperInterpolatorSelection_docs).disableRecursiveValidation(); 00317 interpolatorSelectionPL.setParameters(*(interpolatorBuilder_->getValidParameters())); 00318 // RKBT Selection 00319 ParameterList& rkbtSelectionPL = stepperSettingsPL.sublist(rkButcherTableauSelection_name,false,rkButcherTableauSelection_docs).disableRecursiveValidation(); 00320 rkbtSelectionPL.setParameters(*(rkbtBuilder_->getValidParameters())); 00321 // Nonlinear Solver Selection (TODO) 00322 } 00323 ParameterList& interpolationBufferSettingsPL = pl->sublist(interpolationBufferSettings_name); 00324 { 00325 // Interpolation Buffer Selection 00326 ParameterList& interpolationBufferSelectionPL = interpolationBufferSettingsPL.sublist(interpolationBufferSelection_name).disableRecursiveValidation(); 00327 interpolationBufferSelectionPL.setParameters(*(interpolationBufferBuilder_->getValidParameters())); 00328 // Interpolation Buffer Appender Selection 00329 ParameterList& interpolationBufferAppenderSelectionPL = interpolationBufferSettingsPL.sublist(interpolationBufferAppenderSelection_name).disableRecursiveValidation(); 00330 interpolationBufferAppenderSelectionPL.setParameters(*(interpolationBufferAppenderBuilder_->getValidParameters())); 00331 // Interpolator Selection 00332 ParameterList& interpolatorSelectionPL = interpolationBufferSettingsPL.sublist(interpolatorSelection_name).disableRecursiveValidation(); 00333 interpolatorSelectionPL.setParameters(*(interpolatorBuilder_->getValidParameters())); 00334 } 00335 // Integration Observer Settings 00336 00337 validPL_ = pl; 00338 } 00339 return validPL_; 00340 } 00341 00342 00343 template<class Scalar> 00344 RCP<ParameterList> IntegratorBuilder<Scalar>::getNonconstParameterList() 00345 { 00346 return paramList_; 00347 } 00348 00349 00350 template<class Scalar> 00351 RCP<ParameterList> IntegratorBuilder<Scalar>::unsetParameterList() 00352 { 00353 RCP<ParameterList> pl = paramList_; 00354 paramList_ = Teuchos::null; 00355 return pl; 00356 } 00357 00358 00359 template<class Scalar> 00360 RCP<const ParameterList> IntegratorBuilder<Scalar>::getParameterList() const 00361 { 00362 return paramList_; 00363 } 00364 00365 00366 // Where should we throw exceptions? 00367 // 1. If the integrator comes back null (done) 00368 // 2. If the stepper comes back null (done) 00369 // 3. If model is null (done) 00370 // 4. If the stepper is implicit and nlSolver is null (done) 00371 // 5. If the stepper accepts an RKBT but "None" is selected (done) 00372 // 00373 // a. Its okay if the integration control comes back null, the 00374 // IntegrationControlStrategyAcceptingIntegratorBase will deal with it 00375 // b. Its okay if the step control comes back null, the 00376 // StepControlStrategyAcceptingStepperBase will deal with it 00377 template<class Scalar> 00378 RCP<IntegratorBase<Scalar> > 00379 IntegratorBuilder<Scalar>::create( 00380 const RCP<const Thyra::ModelEvaluator<Scalar> >& model, 00381 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& initialCondition, 00382 const RCP<Thyra::NonlinearSolverBase<Scalar> >& nlSolver 00383 ) const 00384 { 00385 TEST_FOR_EXCEPTION( is_null(model), std::logic_error, 00386 "Error! IntegratorBuilder::create(...) The model passed in is null!" 00387 ); 00388 TEST_FOR_EXCEPTION( is_null(paramList_), std::logic_error, 00389 "Error! IntegratorBuilder::create(...) Please set a parameter list on this class before calling create." 00390 ); 00391 RCP<ParameterList> integratorSettingsPL = sublist(paramList_,integratorSettings_name); 00392 00393 // Create the integrator first 00394 RCP<ParameterList> integratorSelectionPL = sublist(integratorSettingsPL,integratorSelection_name); 00395 integratorBuilder_->setParameterList(integratorSelectionPL); 00396 RCP<IntegratorBase<Scalar> > integrator = integratorBuilder_->create(); 00397 TEST_FOR_EXCEPTION( is_null(integrator), std::logic_error, 00398 "Error! IntegratorBuilder::create(...) The integrator came back null from the ObjectBuilder!" 00399 ); 00400 00401 // Check for IntegrationControlStrategy and set it on the integrator 00402 RCP<IntegrationControlStrategyAcceptingIntegratorBase<Scalar> > icsaIntegrator = 00403 Teuchos::rcp_dynamic_cast<IntegrationControlStrategyAcceptingIntegratorBase<Scalar> >(integrator,false); 00404 if (!is_null(icsaIntegrator)) { 00405 RCP<ParameterList> integrationControlSelectionPL = sublist(paramList_,integrationControlSelection_name); 00406 integrationControlBuilder_->setParameterList(integrationControlSelectionPL); 00407 RCP<IntegrationControlStrategyBase<Scalar> > integrationControl = integrationControlBuilder_->create(); 00408 if (!is_null(integrationControl)) { 00409 icsaIntegrator->setIntegrationControlStrategy(integrationControl); 00410 } 00411 } 00412 RCP<ParameterList> interpolationBufferSettingsPL = sublist(paramList_,interpolationBufferSettings_name); 00413 00414 // Check for a trailing interpolation buffer and set it on the integrator 00415 RCP<TrailingInterpolationBufferAcceptingIntegratorBase<Scalar> > tibaIntegrator = 00416 Teuchos::rcp_dynamic_cast<TrailingInterpolationBufferAcceptingIntegratorBase<Scalar> >(integrator,false); 00417 if (!is_null(tibaIntegrator)) { 00418 RCP<ParameterList> interpolationBufferSelectionPL = sublist(interpolationBufferSettingsPL,interpolationBufferSelection_name); 00419 interpolationBufferBuilder_->setParameterList(interpolationBufferSelectionPL); 00420 RCP<InterpolationBufferBase<Scalar> > ib = interpolationBufferBuilder_->create(); 00421 if (!is_null(ib)) { 00422 // Check for an interpolator 00423 RCP<InterpolatorAcceptingObjectBase<Scalar> > iaobIB = 00424 Teuchos::rcp_dynamic_cast<InterpolatorAcceptingObjectBase<Scalar> >(ib,false); 00425 if (!is_null(iaobIB)) { 00426 RCP<ParameterList> interpolatorSelectionPL = sublist(interpolationBufferSettingsPL,interpolatorSelection_name); 00427 interpolatorBuilder_->setParameterList(interpolatorSelectionPL); 00428 RCP<InterpolatorBase<Scalar> > interpolator = interpolatorBuilder_->create(); 00429 if (!is_null(interpolator)) { 00430 iaobIB->setInterpolator(interpolator); 00431 } 00432 } 00433 tibaIntegrator->setTrailingInterpolationBuffer(ib); 00434 } 00435 } 00436 00437 // Check for an InterpolationBufferAppender and set it on the integrator 00438 RCP<InterpolationBufferAppenderAcceptingIntegratorBase<Scalar> > ibaaIntegrator = 00439 Teuchos::rcp_dynamic_cast<InterpolationBufferAppenderAcceptingIntegratorBase<Scalar> >(integrator,false); 00440 if (!is_null(ibaaIntegrator)) { 00441 RCP<ParameterList> interpolationBufferAppenderSelectionPL = sublist(interpolationBufferSettingsPL,interpolationBufferAppenderSelection_name); 00442 interpolationBufferAppenderBuilder_->setParameterList(interpolationBufferAppenderSelectionPL); 00443 RCP<InterpolationBufferAppenderBase<Scalar> > interpolationBufferAppender = interpolationBufferAppenderBuilder_->create(); 00444 if (!is_null(interpolationBufferAppender)) { 00445 ibaaIntegrator->setInterpolationBufferAppender(interpolationBufferAppender); 00446 } 00447 } 00448 RCP<ParameterList> stepperSettingsPL = sublist(paramList_,stepperSettings_name); 00449 00450 // Create the Stepper 00451 RCP<ParameterList> stepperSelectionPL = sublist(stepperSettingsPL,stepperSelection_name); 00452 stepperBuilder_->setParameterList(stepperSelectionPL); 00453 RCP<StepperBase<Scalar> > stepper = stepperBuilder_->create(); 00454 TEST_FOR_EXCEPTION( is_null(stepper), std::logic_error, 00455 "Error! IntegratorBuilder::create(...) The stepper came back null from the StepperBuilder!" 00456 ); 00457 00458 // Create the Step Control 00459 RCP<ParameterList> stepControlSettingsPL = sublist(stepperSettingsPL,stepControlSettings_name); 00460 RCP<StepControlStrategyAcceptingStepperBase<Scalar> > scsaStepper = 00461 Teuchos::rcp_dynamic_cast<StepControlStrategyAcceptingStepperBase<Scalar> >(stepper,false); 00462 if (!is_null(scsaStepper)) { 00463 RCP<ParameterList> stepControlSelectionPL = sublist(stepControlSettingsPL,stepControlSelection_name); 00464 stepControlBuilder_->setParameterList(stepControlSelectionPL); 00465 RCP<StepControlStrategyBase<Scalar> > stepControl = stepControlBuilder_->create(); 00466 if (!is_null(stepControl)) { 00467 // Create the ErrWtVecCalc 00468 RCP<ErrWtVecCalcAcceptingStepControlStrategyBase<Scalar> > ewvcaStepControl = 00469 Teuchos::rcp_dynamic_cast<ErrWtVecCalcAcceptingStepControlStrategyBase<Scalar> >(stepControl,false); 00470 if (!is_null(ewvcaStepControl)) { 00471 RCP<ParameterList> errWtVecSelectionPL = sublist(stepControlSettingsPL,errWtVecSelection_name); 00472 errWtVecCalcBuilder_->setParameterList(errWtVecSelectionPL); 00473 RCP<ErrWtVecCalcBase<Scalar> > errWtVecCalc = errWtVecCalcBuilder_->create(); 00474 if (!is_null(errWtVecCalc)) { 00475 ewvcaStepControl->setErrWtVecCalc(errWtVecCalc); 00476 } 00477 } 00478 scsaStepper->setStepControlStrategy(stepControl); 00479 } 00480 } 00481 00482 // Check for an Interpolator 00483 RCP<InterpolatorAcceptingObjectBase<Scalar> > iaobStepper = 00484 Teuchos::rcp_dynamic_cast<InterpolatorAcceptingObjectBase<Scalar> >(stepper,false); 00485 if (!is_null(iaobStepper)) { 00486 RCP<ParameterList> interpolatorSelectionPL = sublist(stepperSettingsPL,interpolatorSelection_name); 00487 interpolatorBuilder_->setParameterList(interpolatorSelectionPL); 00488 RCP<InterpolatorBase<Scalar> > interpolator = interpolatorBuilder_->create(); 00489 if (!is_null(interpolator)) { 00490 iaobStepper->setInterpolator(interpolator); 00491 } 00492 } 00493 00494 // Check for an RKBT Selection 00495 RCP<RKButcherTableauAcceptingStepperBase<Scalar> > rkbtaStepper = 00496 Teuchos::rcp_dynamic_cast<RKButcherTableauAcceptingStepperBase<Scalar> >(stepper,false); 00497 if (!is_null(rkbtaStepper)) { 00498 RCP<ParameterList> rkButcherTableauSelectionPL = 00499 sublist(stepperSettingsPL,rkButcherTableauSelection_name); 00500 rkbtBuilder_->setParameterList(rkButcherTableauSelectionPL); 00501 RCP<RKButcherTableauBase<Scalar> > rkbt = rkbtBuilder_->create(); 00502 TEST_FOR_EXCEPTION( is_null(rkbt), std::logic_error, 00503 "Error! IntegratorBuilder::create(...) The Stepper accepts a RK Butcher" 00504 " Tableau, but none were specified!" 00505 ); 00506 rkbtaStepper->setRKButcherTableau(rkbt); 00507 } 00508 00509 // Check for a W Factory 00510 RCP<ImplicitRKStepper<Scalar> > irkStepper = 00511 Teuchos::rcp_dynamic_cast<ImplicitRKStepper<Scalar> >(stepper,false); 00512 if (!is_null(irkStepper)) { 00513 if (!is_null(wFactoryObject_)) { 00514 irkStepper->set_W_factory(wFactoryObject_); 00515 } 00516 } 00517 00518 // Check for Nonlinear Solver Selection (TODO) 00519 // Set model on stepper 00520 stepper->setModel(model); 00521 // Set initial condition on stepper 00522 stepper->setInitialCondition(initialCondition); 00523 // Set nonlinear solver on stepper 00524 RCP<SolverAcceptingStepperBase<Scalar> > saStepper = 00525 Teuchos::rcp_dynamic_cast<SolverAcceptingStepperBase<Scalar> >(stepper,false); 00526 if(!is_null(saStepper)) { 00527 TEST_FOR_EXCEPTION( is_null(nlSolver), std::logic_error, 00528 "Error! IntegratorBuilder::create(...) The nonlinear solver passed in is" 00529 " null and the stepper is implicit!" 00530 ); 00531 saStepper->setSolver(nlSolver); 00532 } 00533 Scalar finalTime = integratorSettingsPL->get<Scalar>( 00534 finalTime_name, Teuchos::as<Scalar>(finalTime_default)); 00535 bool landOnFinalTime = integratorSettingsPL->get<bool>( 00536 landOnFinalTime_name, landOnFinalTime_default); 00537 integrator->setStepper(stepper,finalTime,landOnFinalTime); 00538 return integrator; 00539 00540 } 00541 00542 00543 template<class Scalar> 00544 void IntegratorBuilder<Scalar>::initializeDefaults_() 00545 { 00546 00547 using Teuchos::abstractFactoryStd; 00548 00549 // Integrator 00550 integratorBuilder_ = Teuchos::objectBuilder<IntegratorBase<Scalar> >(); 00551 integratorBuilder_->setObjectName(integratorBuilder_name); 00552 integratorBuilder_->setObjectTypeName(integratorBuilderType_name); 00553 integratorBuilder_->setObjectFactory( 00554 abstractFactoryStd< IntegratorBase<Scalar>, DefaultIntegrator<Scalar> >(), 00555 defaultIntegrator_name 00556 ); 00557 00558 // Integration Control Strategy 00559 integrationControlBuilder_ = Teuchos::objectBuilder<IntegrationControlStrategyBase<Scalar> >(); 00560 integrationControlBuilder_->setObjectName(integrationControlBuilder_name); 00561 integrationControlBuilder_->setObjectTypeName(integrationControlBuilderType_name); 00562 integrationControlBuilder_->setObjectFactory( 00563 abstractFactoryStd< IntegrationControlStrategyBase<Scalar>, SimpleIntegrationControlStrategy<Scalar> >(), 00564 simpleIntegrationControl_name 00565 ); 00566 integrationControlBuilder_->setDefaultObject("None"); 00567 00568 // Stepper Builder 00569 stepperBuilder_ = stepperBuilder<Scalar>(); 00570 00571 // RKBT Builder 00572 rkbtBuilder_ = rKButcherTableauBuilder<Scalar>(); 00573 00574 // Step Control Strategy 00575 stepControlBuilder_ = Teuchos::objectBuilder<StepControlStrategyBase<Scalar> >(); 00576 stepControlBuilder_->setObjectName(stepControlBuilder_name); 00577 stepControlBuilder_->setObjectTypeName(stepControlBuilderType_name); 00578 stepControlBuilder_->setObjectFactory( 00579 abstractFactoryStd< StepControlStrategyBase<Scalar>, ImplicitBDFStepperStepControl<Scalar> >(), 00580 implicitBDFStepControl_name 00581 ); 00582 stepControlBuilder_->setDefaultObject("None"); 00583 00584 // Trailing Interpolation Buffer 00585 interpolationBufferBuilder_ = Teuchos::objectBuilder<InterpolationBufferBase<Scalar> >(); 00586 interpolationBufferBuilder_->setObjectName(interpolationBufferBuilder_name); 00587 interpolationBufferBuilder_->setObjectTypeName(interpolationBufferBuilderType_name); 00588 interpolationBufferBuilder_->setObjectFactory( 00589 abstractFactoryStd< InterpolationBufferBase<Scalar>, InterpolationBuffer<Scalar> >(), 00590 defaultInterpolationBuffer_name 00591 ); 00592 interpolationBufferBuilder_->setDefaultObject("None"); 00593 00594 // Interpolation Buffer Appender 00595 interpolationBufferAppenderBuilder_ = Teuchos::objectBuilder<InterpolationBufferAppenderBase<Scalar> >(); 00596 interpolationBufferAppenderBuilder_->setObjectName(interpolationBufferAppenderBuilder_name); 00597 interpolationBufferAppenderBuilder_->setObjectTypeName(interpolationBufferAppenderBuilderType_name); 00598 // interpolationBufferAppenderBuilder_->setObjectFactory( 00599 // abstractFactoryStd< InterpolationBufferAppenderBase<Scalar>, SmartInterpolationBufferAppender<Scalar> >(), 00600 // smartInterpolationBufferAppender_name 00601 // ); 00602 interpolationBufferAppenderBuilder_->setObjectFactory( 00603 abstractFactoryStd< InterpolationBufferAppenderBase<Scalar>, PointwiseInterpolationBufferAppender<Scalar> >(), 00604 pointwiseInterpolationBufferAppender_name 00605 ); 00606 interpolationBufferAppenderBuilder_->setDefaultObject("None"); 00607 00608 // ErrWtVecCalc 00609 errWtVecCalcBuilder_ = Teuchos::objectBuilder<ErrWtVecCalcBase<Scalar> >(); 00610 errWtVecCalcBuilder_->setObjectName(errWtVecCalcBuilder_name); 00611 errWtVecCalcBuilder_->setObjectTypeName(errWtVecCalcBuilderType_name); 00612 errWtVecCalcBuilder_->setObjectFactory( 00613 abstractFactoryStd< ErrWtVecCalcBase<Scalar>, ImplicitBDFStepperErrWtVecCalc<Scalar> >(), 00614 implicitBDFStepperErrWtVecCalc_name 00615 ); 00616 errWtVecCalcBuilder_->setDefaultObject("None"); 00617 00618 // Interpolator 00619 interpolatorBuilder_ = Teuchos::objectBuilder<InterpolatorBase<Scalar> >(); 00620 interpolatorBuilder_->setObjectName(interpolatorBuilder_name); 00621 interpolatorBuilder_->setObjectTypeName(interpolatorBuilderType_name); 00622 interpolatorBuilder_->setObjectFactory( 00623 abstractFactoryStd< InterpolatorBase<Scalar>, LinearInterpolator<Scalar> >(), 00624 linearInterpolator_name 00625 ); 00626 interpolatorBuilder_->setObjectFactory( 00627 abstractFactoryStd< InterpolatorBase<Scalar>, HermiteInterpolator<Scalar> >(), 00628 hermiteInterpolator_name 00629 ); 00630 interpolatorBuilder_->setObjectFactory( 00631 abstractFactoryStd< InterpolatorBase<Scalar>, CubicSplineInterpolator<Scalar> >(), 00632 cubicSplineInterpolator_name 00633 ); 00634 interpolatorBuilder_->setDefaultObject("None"); 00635 00636 } 00637 00638 00639 } // namespace Rythmos 00640 00641 00642 template<class Scalar> 00643 Teuchos::RCP<Rythmos::IntegratorBuilder<Scalar> > 00644 Rythmos::integratorBuilder() 00645 { 00646 return rcp(new IntegratorBuilder<Scalar>); 00647 } 00648 00649 00650 template<class Scalar> 00651 Teuchos::RCP<Rythmos::IntegratorBuilder<Scalar> > 00652 Rythmos::integratorBuilder(const RCP<ParameterList> ¶mList) 00653 { 00654 const RCP<IntegratorBuilder<Scalar> > ib = integratorBuilder<Scalar>(); 00655 ib->setParameterList(paramList); 00656 return ib; 00657 } 00658 00659 template<class Scalar> 00660 Teuchos::RCP<Rythmos::IntegratorBase<Scalar> > Rythmos::createForwardSensitivityIntegrator( 00661 const RCP<const Thyra::ModelEvaluator<Scalar> >& model, 00662 const int& p_index, 00663 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& model_ic, 00664 const RCP<Thyra::NonlinearSolverBase<Scalar> >& nlSolver, 00665 const RCP<Teuchos::ParameterList>& integratorBuilderPL 00666 ) 00667 { 00668 RCP<IntegratorBuilder<Scalar> > ib = integratorBuilder<Scalar>(integratorBuilderPL); 00669 RCP<IntegratorBase<Scalar> > sensIntegrator = ib->create(model,model_ic,nlSolver); 00670 RCP<ForwardSensitivityStepper<Scalar> > stateAndSensStepper = 00671 forwardSensitivityStepper<Scalar>(); 00672 stateAndSensStepper->initializeSyncedSteppers( 00673 model, p_index, model_ic, sensIntegrator->getNonconstStepper(), nlSolver 00674 ); 00675 typedef Thyra::ModelEvaluatorBase MEB; 00676 MEB::InArgs<Scalar> state_and_sens_ic = 00677 createStateAndSensInitialCondition(*stateAndSensStepper, model_ic); 00678 stateAndSensStepper->setInitialCondition(state_and_sens_ic); 00679 sensIntegrator->setStepper(stateAndSensStepper, sensIntegrator->getFwdTimeRange().upper()); 00680 return sensIntegrator; 00681 } 00682 00683 00684 00685 // 00686 // Explicit Instantiation macro 00687 // 00688 // Must be expanded from within the Rythmos namespace! 00689 // 00690 00691 #define RYTHMOS_INTEGRATOR_BUILDER_INSTANT(SCALAR) \ 00692 \ 00693 template class IntegratorBuilder< SCALAR >; \ 00694 \ 00695 template RCP<IntegratorBuilder< SCALAR > > \ 00696 integratorBuilder(); \ 00697 \ 00698 template RCP<IntegratorBuilder< SCALAR > > \ 00699 integratorBuilder(const RCP<ParameterList> ¶List); \ 00700 \ 00701 template RCP<IntegratorBase< SCALAR > > \ 00702 createForwardSensitivityIntegrator( \ 00703 const RCP<const Thyra::ModelEvaluator< SCALAR > >& model, \ 00704 const int& p_index, \ 00705 const Thyra::ModelEvaluatorBase::InArgs< SCALAR >& model_ic, \ 00706 const RCP<Thyra::NonlinearSolverBase< SCALAR > >& nlSolver, \ 00707 const RCP<ParameterList>& integratorBuilderPL \ 00708 ); 00709 00710 00711 #endif //Rythmos_INTEGRATOR_BUILDER_DEF_H
1.7.4