CTestRelativeNormDispIncr.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020 
00021 // $Revision: 1.3 $
00022 // $Date: 2005/12/15 00:19:28 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/convergenceTest/CTestRelativeNormDispIncr.cpp,v $
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     // check to ensure the SOE has been set - this should not happen if the 
00090     // return from start() is checked
00091     if (theSOE == 0)
00092         return -2;
00093     
00094     // check to ensure the algo does invoke start() - this is needed otherwise
00095     // may never get convergence later on in analysis!
00096     if (currentIter == 0) {
00097         opserr << "WARNING: CTestRelativeNormDispIncr::test() - start() was never invoked.\n";  
00098         return -2;
00099     }
00100     
00101     // get the X vector & determine it's norm & save the value in norms vector
00102     const Vector &x = theSOE->getX();
00103     double norm = x.pNorm(nType);
00104     if (currentIter <= maxNumIter) 
00105         norms(currentIter-1) = norm;
00106     
00107     // if first pass through .. set norm0
00108     if (currentIter == 1) {
00109         norm0 = norm;
00110     }
00111     
00112     // get ratio
00113     if (norm0 != 0.0)
00114         norm /= norm0;
00115     
00116     // print the data if required
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     // check if the algorithm converged
00130     //
00131     
00132     // if converged - print & return ok
00133     if (norm <= tol){ 
00134         
00135         // do some printing first
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         // return the number of times test has been called
00146         return currentIter;
00147     }
00148     
00149     // algo failed to converged after specified number of iterations - but RETURN OK
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     // algo failed to converged after specified number of iterations - return FAILURE -2
00158     else if (currentIter >= maxNumIter) { // failes to converge
00159         opserr << "WARNING: CTestRelativeNormDispIncr::test() - failed to converge \n";
00160         opserr << "after: " << currentIter << " iterations\n";  
00161         currentIter++;    
00162         return -2;
00163     } 
00164     
00165     // algorithm not yet converged - increment counter and return -1
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     // set iteration count = 1
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 }

Generated on Mon Oct 23 15:04:59 2006 for OpenSees by doxygen 1.5.0