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