Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

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.4 $
00022 // $Date: 2001/06/14 05:26:47 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/convergenceTest/CTestNormDispIncr.cpp,v $
00024                                                                         
00025                                                                         
00026 
00027 #include <CTestNormDispIncr.h>
00028 #include <Vector.h>
00029 #include <Channel.h>
00030 #include <EquiSolnAlgo.h>
00031 #include <LinearSOE.h>
00032 
00033 CTestNormDispIncr::CTestNormDispIncr()      
00034 :ConvergenceTest(CONVERGENCE_TEST_CTestNormDispIncr),
00035  theSOE(0), tol(0), maxNumIter(0), currentIter(0), printFlag(0), 
00036  norms(1)
00037 {
00038     
00039 }
00040 
00041 CTestNormDispIncr::CTestNormDispIncr(double theTol, int maxIter, int printIt)
00042 :ConvergenceTest(CONVERGENCE_TEST_CTestNormDispIncr),
00043  theSOE(0), tol(theTol), maxNumIter(maxIter), currentIter(0), printFlag(printIt),
00044  norms(maxIter)
00045 {
00046     tol = theTol;
00047 }
00048 
00049 CTestNormDispIncr::~CTestNormDispIncr()
00050 {
00051     
00052 }
00053 
00054 ConvergenceTest*
00055 CTestNormDispIncr::getCopy( int iterations )
00056 {
00057   CTestNormDispIncr *theCopy ;
00058   theCopy = new CTestNormDispIncr( this->tol, iterations, this->printFlag ) ;
00059 
00060   theCopy->theSOE = this->theSOE ;
00061 
00062   return theCopy ;
00063 
00064 }
00065 
00066 
00067 void
00068 CTestNormDispIncr::setTolerance(double newTol)
00069 {
00070     tol = newTol;
00071 }
00072 
00073 int
00074 CTestNormDispIncr::setEquiSolnAlgo(EquiSolnAlgo &theAlgo)
00075 {
00076     theSOE = theAlgo.getLinearSOEptr();
00077     if (theSOE == 0) {
00078  cerr << "WARNING: CTestNormDisp::setEquiSolnAlgo() - no SOE\n"; 
00079  return -1;
00080     }
00081     else
00082  return 0;
00083 }
00084 
00085     
00086 int
00087 CTestNormDispIncr::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     cerr << "WARNING: CTestNormDisp::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.Norm();
00104   if (currentIter <= maxNumIter) 
00105     norms(currentIter-1) = norm;
00106 
00107 
00108   // print the data if required
00109   if (printFlag == 1) {
00110     cerr << "\t CTestNormDispIncr::test() - iteration: " << currentIter;
00111     cerr << " current Norm: " << norm << " (max: " << tol << ")\n";
00112   } 
00113   if (printFlag == 4) {
00114     cerr << "\t CTestNormDispIncr::test() - iteration: " << currentIter;
00115     cerr << " current Norm: " << norm << " (max: " << tol << ")\n";
00116     cerr << " Norm deltaX: " << norm << "  Norm deltaR: " << (theSOE->getB()).Norm() << endl;
00117     cerr << "deltaX: " << x << "deltaR: " << theSOE->getB();
00118   } 
00119 
00120   //
00121   // check if the algorithm converged
00122   //
00123 
00124   // if converged - print & return ok
00125   if (norm <= tol){ 
00126 
00127     // do some printing first
00128     if (printFlag != 0) {
00129       if (printFlag == 1) 
00130  cerr << endl;
00131       else if (printFlag == 2) {
00132  cerr << "\t CTestNormDispIncr::test() - iteration: " << currentIter;
00133  cerr << " current Norm: " << norm << " (max permissable: " << tol << ")\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 && currentIter >= maxNumIter) {
00143     cerr << "WARNING: CTestDispIncr::test() - failed to converge but going on - ";
00144     cerr << " current Norm: " << norm << " (max: " << tol << ")\n";
00145     cerr << " Norm deltaX: " << norm << "  Norm deltaR: " << (theSOE->getB()).Norm() << endl;
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     cerr << "WARNING: CTestDispIncr::test() - failed to converge \n";
00152     cerr << "after: " << currentIter << " iterations\n"; 
00153     currentIter++;    
00154     return -2;
00155   } 
00156 
00157   // algo not yet converged - increment counter and return -1
00158   else { // has not yet converged
00159     currentIter++;    
00160     return -1;
00161   }
00162 }
00163 
00164 
00165 int
00166 CTestNormDispIncr::start(void)
00167 {
00168     if (theSOE == 0) {
00169  cerr << "WARNING: CTestNormDispIncr::test() - no SOE returning true\n";
00170  return -1;
00171     }
00172 
00173     // set iteration count = 1
00174     norms.Zero();
00175     currentIter = 1;
00176     return 0;
00177 }
00178 
00179 
00180 int 
00181 CTestNormDispIncr::getNumTests()
00182 {
00183   return currentIter;
00184 }
00185 
00186 
00187 int 
00188 CTestNormDispIncr::getMaxNumTests(void)
00189 {
00190   return maxNumIter;
00191 }
00192 
00193 double 
00194 CTestNormDispIncr::getRatioNumToMax(void)
00195 {
00196     double div = maxNumIter;
00197     return currentIter/div;
00198 }
00199 
00200 
00201 const Vector &
00202 CTestNormDispIncr::getNorms() 
00203 {
00204   return norms;
00205 }
00206 
00207 int 
00208 CTestNormDispIncr::sendSelf(int cTag, Channel &theChannel)
00209 {
00210   int res = 0;
00211   Vector x(2);
00212   x(0) = tol;
00213   x(1) = maxNumIter;
00214   res = theChannel.sendVector(this->getDbTag(), cTag, x);
00215   if (res < 0) 
00216     cerr << "CTestNormDispIncr::sendSelf() - failed to send data\n";
00217     
00218   return res;
00219 }
00220 
00221 int 
00222 CTestNormDispIncr::recvSelf(int cTag, Channel &theChannel, 
00223      FEM_ObjectBroker &theBroker)
00224 {
00225   int res = 0;
00226   Vector x(2);
00227   res = theChannel.recvVector(this->getDbTag(), cTag, x);    
00228 
00229   if (res < 0) {
00230       cerr << "CTestNormDispIncr::sendSelf() - failed to send data\n";
00231       tol = 1.0e-8;
00232       maxNumIter = 25;
00233   }
00234   else {
00235       tol = x(0);
00236       maxNumIter = x(1);
00237       norms.resize(maxNumIter);
00238   }
00239   return res;
00240 }
00241 
Copyright Contact Us