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