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

CTestNormUnbalance.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/CTestNormUnbalance.cpp,v $
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   // 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     cerr << "WARNING: CTestNormDisp::test() - start() was never invoked.\n"; 
00097     return -2;
00098   }
00099 
00100 
00101   // get the B vector & determine it's norm & save the value in norms vector
00102   const Vector &x = theSOE->getB();
00103   double norm = x.Norm();
00104   if (currentIter <= maxNumIter) 
00105     norms(currentIter-1) = norm;
00106 
00107   // print the data if required
00108   if (printFlag == 1) {
00109     cerr << "\t CTestNormUnbalance::test() - iteration: " << currentIter;
00110     cerr << " current Norm: " << norm << " (max: " << tol << ")\n";
00111   }
00112   // print the data if required
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   // check if the algorithm converged
00122   //
00123 
00124   // if converged - print & return ok
00125   if (norm <= tol) { // the algorithm converged
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 CTestNormUnbalance::test() - iteration: " << currentIter;
00133  cerr << " last Norm: " << norm << " (max: " << 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: 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   // algo failed to converged after specified number of iterations - return FAILURE -2
00150   else if (currentIter >= maxNumIter) { // the algorithm failed to converge
00151     cerr << "WARNING: CTestNormUnbalance::test() - failed to converge \n";
00152     cerr << "after: " << currentIter << " iterations\n"; 
00153     currentIter++;  // we increment in case analysis does not check for convergence
00154     return -2;
00155   } 
00156 
00157   // algo not yet converged - increment counter and return -1
00158   else { // the algorithm has not converged yet
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     // set iteration count = 1
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 
Copyright Contact Us