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
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 #include "Teko_InverseFactory.hpp"
00093
00094
00095 #include "Thyra_DefaultLinearOpSource.hpp"
00096 #include "Thyra_DefaultInverseLinearOp.hpp"
00097 #include "Thyra_DefaultPreconditioner.hpp"
00098
00099
00100 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
00101
00102
00103 #include "Teko_Utilities.hpp"
00104 #include "Teko_BlockPreconditionerFactory.hpp"
00105 #include "Teko_Preconditioner.hpp"
00106 #include "Teko_PreconditionerLinearOp.hpp"
00107 #include "Teko_SolveInverseFactory.hpp"
00108 #include "Teko_PreconditionerInverseFactory.hpp"
00109
00110 using Teuchos::rcp;
00111 using Teuchos::rcp_const_cast;
00112 using Teuchos::rcp_dynamic_cast;
00113 using Teuchos::RCP;
00114
00115 namespace Teko {
00116
00118 InverseLinearOp buildInverse(const InverseFactory & factory,const LinearOp & A)
00119 {
00120 InverseLinearOp inv;
00121 try {
00122 inv = factory.buildInverse(A);
00123 }
00124 catch(std::exception & e) {
00125 RCP<Teuchos::FancyOStream> out = Teko::getOutputStream();
00126
00127 *out << "Teko: \"buildInverse\" could not construct the inverse operator using ";
00128 *out << "\"" << factory.toString() << "\"" << std::endl;
00129 *out << std::endl;
00130 *out << "*** THROWN EXCEPTION ***\n";
00131 *out << e.what() << std::endl;
00132 *out << "************************\n";
00133
00134 throw e;
00135 }
00136
00137 return inv;
00138 }
00139
00151 InverseLinearOp buildInverse(const InverseFactory & factory,const LinearOp & A,const LinearOp & precOp)
00152 {
00153 Teko_DEBUG_SCOPE("buildInverse(factory,A,precOp)",10);
00154 InverseLinearOp inv;
00155 try {
00156 inv = factory.buildInverse(A,precOp);
00157 }
00158 catch(std::exception & e) {
00159 RCP<Teuchos::FancyOStream> out = Teko::getOutputStream();
00160
00161 *out << "Teko: \"buildInverse\" could not construct the inverse operator using ";
00162 *out << "\"" << factory.toString() << "\"" << std::endl;
00163 *out << std::endl;
00164 *out << "*** THROWN EXCEPTION ***\n";
00165 *out << e.what() << std::endl;
00166 *out << "************************\n";
00167
00168 throw e;
00169 }
00170
00171 return inv;
00172 }
00173
00177 void rebuildInverse(const InverseFactory & factory, const LinearOp & A, InverseLinearOp & invA)
00178 {
00179 InverseLinearOp inv;
00180 try {
00181 factory.rebuildInverse(A,invA);
00182 }
00183 catch(std::exception & e) {
00184 RCP<Teuchos::FancyOStream> out = Teko::getOutputStream();
00185
00186 *out << "Teko: \"rebuildInverse\" could not construct the inverse operator using ";
00187 *out << "\"" << factory.toString() << "\"" << std::endl;
00188 *out << std::endl;
00189 *out << "*** THROWN EXCEPTION ***\n";
00190 *out << e.what() << std::endl;
00191 *out << "************************\n";
00192
00193 throw e;
00194 }
00195 }
00196
00212 void rebuildInverse(const InverseFactory & factory, const LinearOp & A,const LinearOp & precOp, InverseLinearOp & invA)
00213 {
00214 InverseLinearOp inv;
00215 try {
00216 factory.rebuildInverse(A,precOp,invA);
00217 }
00218 catch(std::exception & e) {
00219 RCP<Teuchos::FancyOStream> out = Teko::getOutputStream();
00220
00221 *out << "Teko: \"rebuildInverse\" could not construct the inverse operator using ";
00222 *out << "\"" << factory.toString() << "\"" << std::endl;
00223 *out << std::endl;
00224 *out << "*** THROWN EXCEPTION ***\n";
00225 *out << e.what() << std::endl;
00226 *out << "************************\n";
00227
00228 throw e;
00229 }
00230 }
00231
00243 RCP<InverseFactory> invFactoryFromParamList(const Teuchos::ParameterList & list,const std::string & type)
00244 {
00245 RCP<Teuchos::ParameterList> myList = rcp(new Teuchos::ParameterList(list));
00246
00247 Stratimikos::DefaultLinearSolverBuilder strat;
00248 strat.setParameterList(myList);
00249
00250 try {
00251
00252 RCP<Thyra::PreconditionerFactoryBase<double> > precFact = strat.createPreconditioningStrategy(type);
00253
00254
00255 return rcp(new PreconditionerInverseFactory(precFact,Teuchos::null));
00256 }
00257 catch(const Teuchos::Exceptions::InvalidParameterValue & exp) { }
00258
00259 try {
00260
00261 RCP<Thyra::LinearOpWithSolveFactoryBase<double> > solveFact = strat.createLinearSolveStrategy(type);
00262
00263
00264 return rcp(new SolveInverseFactory(solveFact));
00265 }
00266 catch(const Teuchos::Exceptions::InvalidParameterValue & exp) { }
00267
00268 return Teuchos::null;;
00269 }
00270
00279 Teuchos::RCP<const Teuchos::ParameterList> invFactoryValidParameters()
00280 {
00281 Stratimikos::DefaultLinearSolverBuilder strat;
00282
00283
00284 return strat.getValidParameters();
00285 }
00286
00287 }