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 #include <CTestRelativeNormDispIncr.h>
00027 #include <Vector.h>
00028 #include <Channel.h>
00029 #include <EquiSolnAlgo.h>
00030 #include <LinearSOE.h>
00031
00032
00033 CTestRelativeNormDispIncr::CTestRelativeNormDispIncr()
00034 : ConvergenceTest(CONVERGENCE_TEST_CTestRelativeNormDispIncr),
00035 theSOE(0), tol(0), maxNumIter(0), currentIter(0), printFlag(0),
00036 norms(1), norm0(0.0), nType(2)
00037 {
00038
00039 }
00040
00041
00042 CTestRelativeNormDispIncr::CTestRelativeNormDispIncr(double theTol, int maxIter, int printIt, int normType)
00043 : ConvergenceTest(CONVERGENCE_TEST_CTestRelativeNormDispIncr),
00044 theSOE(0), tol(theTol), maxNumIter(maxIter), currentIter(0), printFlag(printIt),
00045 norms(maxIter), norm0(0.0), nType(normType)
00046 {
00047
00048 }
00049
00050
00051 CTestRelativeNormDispIncr::~CTestRelativeNormDispIncr()
00052 {
00053
00054 }
00055
00056
00057 ConvergenceTest* CTestRelativeNormDispIncr::getCopy(int iterations)
00058 {
00059 CTestRelativeNormDispIncr *theCopy ;
00060 theCopy = new CTestRelativeNormDispIncr(this->tol, iterations, this->printFlag, this->nType) ;
00061
00062 theCopy->theSOE = this->theSOE ;
00063
00064 return theCopy ;
00065
00066 }
00067
00068
00069 void CTestRelativeNormDispIncr::setTolerance(double newTol)
00070 {
00071 tol = newTol;
00072 }
00073
00074
00075 int CTestRelativeNormDispIncr::setEquiSolnAlgo(EquiSolnAlgo &theAlgo)
00076 {
00077 theSOE = theAlgo.getLinearSOEptr();
00078 if (theSOE == 0) {
00079 opserr << "WARNING: CTestRelativeNormDispIncr::setEquiSolnAlgo() - no SOE\n";
00080 return -1;
00081 }
00082 else
00083 return 0;
00084 }
00085
00086
00087 int CTestRelativeNormDispIncr::test(void)
00088 {
00089
00090
00091 if (theSOE == 0)
00092 return -2;
00093
00094
00095
00096 if (currentIter == 0) {
00097 opserr << "WARNING: CTestRelativeNormDispIncr::test() - start() was never invoked.\n";
00098 return -2;
00099 }
00100
00101
00102 const Vector &x = theSOE->getX();
00103 double norm = x.pNorm(nType);
00104 if (currentIter <= maxNumIter)
00105 norms(currentIter-1) = norm;
00106
00107
00108 if (currentIter == 1) {
00109 norm0 = norm;
00110 }
00111
00112
00113 if (norm0 != 0.0)
00114 norm /= norm0;
00115
00116
00117 if (printFlag == 1) {
00118 opserr << "CTestRelativeNormDispIncr::test() - iteration: " << currentIter;
00119 opserr << " current Ratio (|dR|/|dR1|): " << norm << " (max: " << tol << ")\n";
00120 }
00121 if (printFlag == 4) {
00122 opserr << "CTestRelativeNormDispIncr::test() - iteration: " << currentIter;
00123 opserr << " current Ratio (|dR|/|dR1|): " << norm << " (max: " << tol << ")\n";
00124 opserr << "\tNorm deltaX: " << norm << ", Norm deltaR: " << theSOE->getB().pNorm(nType) << endln;
00125 opserr << "\tdeltaX: " << x << "\tdeltaR: " << theSOE->getB();
00126 }
00127
00128
00129
00130
00131
00132
00133 if (norm <= tol){
00134
00135
00136 if (printFlag != 0) {
00137 if (printFlag == 1 || printFlag == 4)
00138 opserr << endln;
00139 else if (printFlag == 2 || printFlag == 6) {
00140 opserr << "CTestRelativeNormDispIncr::test() - iteration: " << currentIter;
00141 opserr << " current Ratio (|dR|/|dR1|): " << norm << " (max: " << tol << ")\n";
00142 }
00143 }
00144
00145
00146 return currentIter;
00147 }
00148
00149
00150 else if ((printFlag == 5 || printFlag == 6) && currentIter >= maxNumIter) {
00151 opserr << "WARNING: CTestRelativeNormDispIncr::test() - failed to converge but going on -";
00152 opserr << " current Ratio (|dR|/|dR1|): " << norm << " (max: " << tol;
00153 opserr << ", Norm deltaR: " << theSOE->getB().pNorm(nType) << ")\n";
00154 return currentIter;
00155 }
00156
00157
00158 else if (currentIter >= maxNumIter) {
00159 opserr << "WARNING: CTestRelativeNormDispIncr::test() - failed to converge \n";
00160 opserr << "after: " << currentIter << " iterations\n";
00161 currentIter++;
00162 return -2;
00163 }
00164
00165
00166 else {
00167 currentIter++;
00168 return -1;
00169 }
00170 }
00171
00172
00173 int CTestRelativeNormDispIncr::start(void)
00174 {
00175 if (theSOE == 0) {
00176 opserr << "WARNING: CTestRelativeNormDispIncr::test() - no SOE returning true\n";
00177 return -1;
00178 }
00179
00180
00181 norms.Zero();
00182 currentIter = 1;
00183 norm0 = 0.0;
00184
00185 return 0;
00186 }
00187
00188
00189 int CTestRelativeNormDispIncr::getNumTests()
00190 {
00191 return currentIter;
00192 }
00193
00194
00195 int CTestRelativeNormDispIncr::getMaxNumTests(void)
00196 {
00197 return maxNumIter;
00198 }
00199
00200
00201 double CTestRelativeNormDispIncr::getRatioNumToMax(void)
00202 {
00203 double div = maxNumIter;
00204 return currentIter/div;
00205 }
00206
00207
00208 const Vector& CTestRelativeNormDispIncr::getNorms()
00209 {
00210 return norms;
00211 }
00212
00213
00214 int CTestRelativeNormDispIncr::sendSelf(int cTag, Channel &theChannel)
00215 {
00216 int res = 0;
00217 Vector x(4);
00218 x(0) = tol;
00219 x(1) = maxNumIter;
00220 x(2) = printFlag;
00221 x(3) = nType;
00222 res = theChannel.sendVector(this->getDbTag(), cTag, x);
00223 if (res < 0)
00224 opserr << "CTestRelativeNormDispIncr::sendSelf() - failed to send data\n";
00225
00226 return res;
00227 }
00228
00229
00230 int CTestRelativeNormDispIncr::recvSelf(int cTag, Channel &theChannel,
00231 FEM_ObjectBroker &theBroker)
00232 {
00233 int res = 0;
00234 Vector x(4);
00235 res = theChannel.recvVector(this->getDbTag(), cTag, x);
00236
00237 if (res < 0) {
00238 opserr << "CTestRelativeNormDispIncr::sendSelf() - failed to send data\n";
00239 tol = 1.0e-8;
00240 maxNumIter = 25;
00241 printFlag = 0;
00242 nType = 2;
00243 }
00244 else {
00245 tol = x(0);
00246 maxNumIter = (int) x(1);
00247 printFlag = (int) x(2);
00248 nType = (int) x(3);
00249 norms.resize(maxNumIter);
00250 }
00251 return res;
00252 }