00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "Teuchos_ParameterList.hpp"
00043 #include "LOCA_GlobalData.H"
00044 #include "LOCA_ErrorCheck.H"
00045 #include "LOCA_Parameter_SublistParser.H"
00046
00047 #include "LOCA_MultiPredictor_Factory.H"
00048 #include "LOCA_MultiPredictor_AbstractStrategy.H"
00049 #include "LOCA_MultiPredictor_Constant.H"
00050 #include "LOCA_MultiPredictor_Tangent.H"
00051 #include "LOCA_MultiPredictor_Secant.H"
00052 #include "LOCA_MultiPredictor_Random.H"
00053 #include "LOCA_MultiPredictor_Restart.H"
00054
00055 LOCA::MultiPredictor::Factory::Factory(
00056 const Teuchos::RCP<LOCA::GlobalData>& global_data) :
00057 globalData(global_data)
00058 {
00059 }
00060
00061 LOCA::MultiPredictor::Factory::~Factory()
00062 {
00063 }
00064
00065 Teuchos::RCP<LOCA::MultiPredictor::AbstractStrategy>
00066 LOCA::MultiPredictor::Factory::create(
00067 const Teuchos::RCP<LOCA::Parameter::SublistParser>& topParams,
00068 const Teuchos::RCP<Teuchos::ParameterList>& predictorParams)
00069 {
00070 string methodName = "LOCA::MultiPredictor::Factory::create()";
00071 Teuchos::RCP<LOCA::MultiPredictor::AbstractStrategy> strategy;
00072
00073
00074 Teuchos::RCP<Teuchos::ParameterList> solverParams =
00075 topParams->getSublist("Linear Solver");
00076
00077
00078 const string& name = strategyName(*predictorParams);
00079
00080 if (name == "Constant")
00081 strategy =
00082 Teuchos::rcp(new LOCA::MultiPredictor::Constant(globalData,
00083 predictorParams));
00084
00085 else if (name == "Tangent")
00086 strategy =
00087 Teuchos::rcp(new LOCA::MultiPredictor::Tangent(globalData,
00088 predictorParams,
00089 solverParams));
00090 else if (name == "Secant")
00091 strategy =
00092 Teuchos::rcp(new LOCA::MultiPredictor::Secant(globalData,
00093 topParams,
00094 predictorParams));
00095 else if (name == "Random")
00096 strategy =
00097 Teuchos::rcp(new LOCA::MultiPredictor::Random(globalData,
00098 predictorParams));
00099 else if (name == "Restart")
00100 strategy =
00101 Teuchos::rcp(new LOCA::MultiPredictor::Restart(globalData,
00102 predictorParams));
00103
00104 else if (name == "User-Defined") {
00105
00106
00107 string userDefinedName = predictorParams->get("User-Defined Name",
00108 "???");
00109 if ((*predictorParams).INVALID_TEMPLATE_QUALIFIER
00110 isType< Teuchos::RCP<LOCA::MultiPredictor::AbstractStrategy> >(userDefinedName))
00111 strategy = (*predictorParams).INVALID_TEMPLATE_QUALIFIER
00112 get< Teuchos::RCP<LOCA::MultiPredictor::AbstractStrategy> >(userDefinedName);
00113 else
00114 globalData->locaErrorCheck->throwError(
00115 methodName,
00116 "Cannot find user-defined strategy: " +
00117 userDefinedName);
00118 }
00119 else
00120 globalData->locaErrorCheck->throwError(
00121 methodName,
00122 "Invalid predictor strategy: " +
00123 name);
00124
00125 return strategy;
00126 }
00127
00128 const string&
00129 LOCA::MultiPredictor::Factory::strategyName(
00130 Teuchos::ParameterList& predictorParams) const
00131 {
00132 return predictorParams.get("Method", "Secant");
00133 }