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_AnasaziOperator_ShiftInvert.H"
00043 #include "Teuchos_ParameterList.hpp"
00044 #include "LOCA_GlobalData.H"
00045 #include "LOCA_ErrorCheck.H"
00046
00047 LOCA::AnasaziOperator::ShiftInvert::ShiftInvert(
00048 const Teuchos::RCP<LOCA::GlobalData>& global_data,
00049 const Teuchos::RCP<LOCA::Parameter::SublistParser>& topParams,
00050 const Teuchos::RCP<Teuchos::ParameterList>& eigenParams_,
00051 const Teuchos::RCP<Teuchos::ParameterList>& solverParams_,
00052 const Teuchos::RCP<LOCA::TimeDependent::AbstractGroup>& grp_)
00053 : globalData(global_data),
00054 myLabel("Shift-Invert"),
00055 eigenParams(eigenParams_),
00056 solverParams(solverParams_),
00057 grp(grp_),
00058 tmp_r(),
00059 tmp_i(),
00060 shift(0.0)
00061 {
00062 shift = eigenParams->get("Shift",0.0);
00063 }
00064
00065 LOCA::AnasaziOperator::ShiftInvert::~ShiftInvert()
00066 {
00067 }
00068
00069 const string&
00070 LOCA::AnasaziOperator::ShiftInvert::label() const
00071 {
00072 return myLabel;
00073 }
00074
00075 void
00076 LOCA::AnasaziOperator::ShiftInvert::apply(
00077 const NOX::Abstract::MultiVector& input,
00078 NOX::Abstract::MultiVector& output) const
00079 {
00080 string callingFunction =
00081 "LOCA::AnasaziOperator::ShiftInvert::apply()";
00082
00083 NOX::Abstract::Group::ReturnType finalStatus = NOX::Abstract::Group::Ok;
00084 NOX::Abstract::Group::ReturnType status;
00085
00086
00087 if (tmp_r == Teuchos::null || tmp_r->numVectors() != input.numVectors())
00088 tmp_r = input.clone(NOX::ShapeCopy);
00089
00090
00091 status = grp->computeShiftedMatrix(0.0, 1.0);
00092 finalStatus =
00093 globalData->locaErrorCheck->combineAndCheckReturnTypes(status,
00094 finalStatus,
00095 callingFunction);
00096
00097
00098 status = grp->applyShiftedMatrixMultiVector(input, *tmp_r);
00099 finalStatus =
00100 globalData->locaErrorCheck->combineAndCheckReturnTypes(status,
00101 finalStatus,
00102 callingFunction);
00103
00104
00105 status = grp->computeShiftedMatrix(1.0, -shift);
00106 finalStatus =
00107 globalData->locaErrorCheck->combineAndCheckReturnTypes(status,
00108 finalStatus,
00109 callingFunction);
00110
00111
00112 status = grp->applyShiftedMatrixInverseMultiVector(*solverParams, *tmp_r,
00113 output);
00114 finalStatus =
00115 globalData->locaErrorCheck->combineAndCheckReturnTypes(status,
00116 finalStatus,
00117 callingFunction);
00118 }
00119
00120 void
00121 LOCA::AnasaziOperator::ShiftInvert::transformEigenvalue(double& ev_r,
00122 double& ev_i) const
00123 {
00124
00125 double mag = ev_r*ev_r + ev_i*ev_i;
00126 ev_r = ev_r / mag + shift;
00127 ev_i = -ev_i / mag;
00128 }
00129
00130 NOX::Abstract::Group::ReturnType
00131 LOCA::AnasaziOperator::ShiftInvert::rayleighQuotient(
00132 const NOX::Abstract::Vector& evec_r,
00133 const NOX::Abstract::Vector& evec_i,
00134 double& rq_r, double& rq_i) const
00135 {
00136 string callingFunction =
00137 "LOCA::AnasaziOperator::ShiftInvert::rayleighQuotient()";
00138
00139
00140 if (tmp_r == Teuchos::null)
00141 tmp_r = evec_r.createMultiVector(1, NOX::ShapeCopy);
00142 if (tmp_i == Teuchos::null)
00143 tmp_i = evec_i.createMultiVector(1, NOX::ShapeCopy);
00144
00145 NOX::Abstract::Group::ReturnType finalStatus = NOX::Abstract::Group::Ok;
00146 NOX::Abstract::Group::ReturnType status;
00147
00148
00149 status = grp->computeJacobian();
00150 finalStatus =
00151 globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
00152 callingFunction);
00153
00154
00155 status = grp->applyJacobian(evec_r, (*tmp_r)[0]);
00156 finalStatus =
00157 globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
00158 callingFunction);
00159
00160 status = grp->applyJacobian(evec_i, (*tmp_i)[0]);
00161 finalStatus =
00162 globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
00163 callingFunction);
00164
00165 rq_r = evec_r.innerProduct((*tmp_r)[0]) + evec_i.innerProduct((*tmp_i)[0]);
00166 rq_i = evec_r.innerProduct((*tmp_i)[0]) - evec_i.innerProduct((*tmp_r)[0]);
00167
00168
00169 status = grp->computeShiftedMatrix(0.0, 1.0);
00170 finalStatus =
00171 globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
00172 callingFunction);
00173
00174
00175 status = grp->applyShiftedMatrix(evec_r, (*tmp_r)[0]);
00176 finalStatus =
00177 globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
00178 callingFunction);
00179
00180 status = grp->applyShiftedMatrix(evec_i, (*tmp_i)[0]);
00181 finalStatus =
00182 globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
00183 callingFunction);
00184
00185 double m_r =
00186 evec_r.innerProduct((*tmp_r)[0]) + evec_i.innerProduct((*tmp_i)[0]);
00187 double m_i =
00188 evec_r.innerProduct((*tmp_i)[0]) - evec_i.innerProduct((*tmp_r)[0]);
00189 double m = m_r*m_r + m_i*m_i;
00190
00191
00192 rq_r = (rq_r*m_r + rq_i*m_i) / m;
00193 rq_i = (rq_i*m_r - rq_r*m_i) / m;
00194
00195 return finalStatus;
00196 }