CTestRelativeTotalNormDispIncr.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.1 $
00022 // $Date: 2005/12/15 00:15:13 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/convergenceTest/CTestRelativeTotalNormDispIncr.cpp,v $
00024 
00025 // Written: Andreas Schellenberg (andreas.schellenberg@gmx.net)
00026 // Created: 05/05
00027 // Revision: A
00028 //
00029 // Purpose: This file contains the class implementation of CTestRelativeTotalNormDispIncr.
00030 //
00031 // What: "@(#) CTestRelativeTotalNormDispIncr.cpp, revA"
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     // check to ensure the SOE has been set - this should not happen if the 
00097     // return from start() is checked
00098     if (theSOE == 0)
00099         return -2;
00100     
00101     // check to ensure the algo does invoke start() - this is needed otherwise
00102     // may never get convergence later on in analysis!
00103     if (currentIter == 0)  {
00104         opserr << "WARNING: CTestRelativeTotalNormDispIncr::test() - start() was never invoked.\n";     
00105         return -2;
00106     }
00107     
00108     // get the X vector & determine it's norm & save the value in norms vector
00109     const Vector &x = theSOE->getX();
00110     double norm = x.pNorm(nType);
00111     if (currentIter <= maxNumIter) 
00112         norms(currentIter-1) = norm;
00113     
00114     // add current norm to total norm
00115     totNorm += norm;
00116     
00117     // get ratio
00118     if (totNorm != 0.0)
00119         norm /= totNorm;
00120     
00121     // print the data if required
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     // check if the algorithm converged
00135     //
00136     
00137     // if converged - print & return ok
00138     if (norm <= tol)  { 
00139         
00140         // do some printing first
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         // return the number of times test has been called
00151         return currentIter;
00152     }
00153     
00154     // algo failed to converged after specified number of iterations - but RETURN OK
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     // algo failed to converged after specified number of iterations - return FAILURE -2
00163     else if (currentIter >= maxNumIter)  { // failes to converge
00164         opserr << "WARNING: CTestRelativeTotalNormDispIncr::test() - failed to converge \n";
00165         opserr << "after: " << currentIter << " iterations\n";  
00166         currentIter++;    
00167         return -2;
00168     } 
00169     
00170     // algorithm not yet converged - increment counter and return -1
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     // set iteration count = 1
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 }

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