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