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 "LOCA_Epetra_TransposeLinearSystem_LeftPreconditioning.H"
00043 #include "NOX_Epetra_LinearSystem.H"
00044 #include "NOX_Epetra_Vector.H"
00045 #include "LOCA_Epetra_LeftPreconditionedOp.H"
00046 #include "LOCA_Epetra_IdentityOp.H"
00047 #include "LOCA_GlobalData.H"
00048 #include "LOCA_ErrorCheck.H"
00049 #include "Epetra_Vector.h"
00050 #include "Epetra_Comm.h"
00051 #include "Epetra_Map.h"
00052
00053 LOCA::Epetra::TransposeLinearSystem::LeftPreconditioning::
00054 LeftPreconditioning(
00055 const Teuchos::RCP<LOCA::GlobalData>& global_data,
00056 const Teuchos::RCP<Teuchos::ParameterList>& solverParams,
00057 const Teuchos::RCP<NOX::Epetra::LinearSystem>& linsys_) :
00058 globalData(global_data),
00059 linsys(linsys_),
00060 jac(),
00061 prec()
00062 {
00063
00064
00065 if (!linsys->hasPreconditioner())
00066 globalData->locaErrorCheck->throwError(
00067 string("LOCA::Epetra::TransposeLinearSystem::LeftPreconditioning") +
00068 string("::LeftPreconditioning()"),
00069 string("Left preconditioning for transpose solve is valid only") +
00070 string(" when the linear system defines a preconditioner"));
00071 }
00072
00073 LOCA::Epetra::TransposeLinearSystem::LeftPreconditioning::
00074 ~LeftPreconditioning()
00075 {
00076 }
00077
00078 bool
00079 LOCA::Epetra::TransposeLinearSystem::LeftPreconditioning::
00080 applyJacobianTransposeInverse(Teuchos::ParameterList ¶ms,
00081 const NOX::Epetra::Vector &input,
00082 NOX::Epetra::Vector &result)
00083 {
00084
00085 Teuchos::RCP<Epetra_Operator> left_prec_jac =
00086 Teuchos::rcp(new LOCA::Epetra::LeftPreconditionedOp(jac, prec));
00087
00088
00089 linsys->setJacobianOperatorForSolve(left_prec_jac);
00090
00091
00092 Teuchos::RCP<Epetra_Operator> identity_prec =
00093 Teuchos::rcp(new LOCA::Epetra::IdentityOp(
00094 Teuchos::rcp(&(jac->Comm()), false),
00095 Teuchos::rcp(&(jac->OperatorDomainMap()), false)));
00096
00097
00098 linsys->setPrecOperatorForSolve(identity_prec);
00099
00100
00101 NOX::Epetra::Vector prec_input(input);
00102 prec->ApplyInverse(input.getEpetraVector(), prec_input.getEpetraVector());
00103
00104
00105 bool res = linsys->applyJacobianInverse(params, prec_input, result);
00106
00107 return res;
00108 }
00109
00110 bool
00111 LOCA::Epetra::TransposeLinearSystem::LeftPreconditioning::
00112 createJacobianTranspose()
00113 {
00114
00115 jac = linsys->getJacobianOperator();
00116 jac->SetUseTranspose(true);
00117
00118 return true;
00119 }
00120
00121 bool
00122 LOCA::Epetra::TransposeLinearSystem::LeftPreconditioning::
00123 createTransposePreconditioner(const NOX::Epetra::Vector& x,
00124 Teuchos::ParameterList& p)
00125 {
00126
00127 bool res1 = linsys->destroyPreconditioner();
00128 linsys->setJacobianOperatorForSolve(jac);
00129 bool res2 = linsys->createPreconditioner(x, p, true);
00130 prec = linsys->getGeneratedPrecOperator();
00131 prec->SetUseTranspose(true);
00132
00133 return res1 && res2;
00134 }
00135
00136 Teuchos::RCP<Epetra_Operator>
00137 LOCA::Epetra::TransposeLinearSystem::LeftPreconditioning::
00138 getJacobianTransposeOperator()
00139 {
00140 return jac;
00141 }
00142
00143 Teuchos::RCP<Epetra_Operator>
00144 LOCA::Epetra::TransposeLinearSystem::LeftPreconditioning::
00145 getTransposePreconditioner()
00146 {
00147 return prec;
00148 }
00149
00150 void
00151 LOCA::Epetra::TransposeLinearSystem::LeftPreconditioning::
00152 setJacobianTransposeOperator(
00153 const Teuchos::RCP<Epetra_Operator>& new_jac_trans)
00154 {
00155 jac = new_jac_trans;
00156 }
00157
00158 void
00159 LOCA::Epetra::TransposeLinearSystem::LeftPreconditioning::
00160 setTransposePreconditioner(
00161 const Teuchos::RCP<Epetra_Operator>& new_prec_trans)
00162 {
00163 prec = new_prec_trans;
00164 }