CTestNormDispIncr.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.8 $
00022 // $Date: 2006/01/10 18:13:19 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/convergenceTest/CTestNormDispIncr.cpp,v $
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     // check to ensure the SOE has been set - this should not happen if the 
00089     // return from start() is checked
00090     if (theSOE == 0)
00091         return -2;
00092     
00093     // check to ensure the algo does invoke start() - this is needed otherwise
00094     // may never get convergence later on in analysis!
00095     if (currentIter == 0) {
00096         opserr << "WARNING: CTestNormDispIncr::test() - start() was never invoked.\n";  
00097         return -2;
00098     }
00099     
00100     // get the X vector & determine it's norm & save the value in norms vector
00101     const Vector &x = theSOE->getX();
00102     double norm = x.pNorm(nType);
00103     if (currentIter <= maxNumIter) 
00104         norms(currentIter-1) = norm;
00105     
00106     // print the data if required
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     // check if the algorithm converged
00121     //
00122     
00123     // if converged - print & return ok
00124     if (norm <= tol) { 
00125         
00126         // do some printing first
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         // return the number of times test has been called
00138         return currentIter;
00139     }
00140     
00141     // algo failed to converged after specified number of iterations - but RETURN OK
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     // algo failed to converged after specified number of iterations - return FAILURE -2
00150     else if (currentIter >= maxNumIter) { // failes to converge
00151         opserr << "WARNING: CTestNormDispIncr::test() - failed to converge \n";
00152         opserr << "after: " << currentIter << " iterations\n";  
00153         currentIter++;    
00154         return -2;
00155     } 
00156     
00157     // algorithm not yet converged - increment counter and return -1
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     // set iteration count = 1
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 

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