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