CTestFixedNumIter.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:13:51 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/convergenceTest/CTestFixedNumIter.cpp,v $
00024 
00025 // Written: Andreas Schellenberg (andreas.schellenberg@gmx.net)
00026 // Created: 09/05
00027 // Revision: A
00028 //
00029 // Purpose: This file contains the class implementation of CTestFixedNumIter.
00030 //
00031 // What: "@(#) CTestFixedNumIter.cpp, revA"
00032 
00033 
00034 #include <CTestFixedNumIter.h>
00035 #include <Vector.h>
00036 #include <Channel.h>
00037 #include <EquiSolnAlgo.h>
00038 #include <LinearSOE.h>
00039 
00040 
00041 CTestFixedNumIter::CTestFixedNumIter()          
00042     : ConvergenceTest(CONVERGENCE_TEST_CTestFixedNumIter),
00043     theSOE(0), maxNumIter(0), currentIter(0), printFlag(0),
00044     norms(1), nType(2)
00045 {
00046     
00047 }
00048 
00049 
00050 CTestFixedNumIter::CTestFixedNumIter(int maxIter, int printIt, int normType)
00051     : ConvergenceTest(CONVERGENCE_TEST_CTestFixedNumIter),
00052     theSOE(0), maxNumIter(maxIter), currentIter(0), printFlag(printIt),
00053     norms(maxNumIter), nType(normType)
00054 {
00055     
00056 }
00057 
00058 
00059 CTestFixedNumIter::~CTestFixedNumIter()
00060 {
00061     
00062 }
00063 
00064 
00065 ConvergenceTest* CTestFixedNumIter::getCopy(int iterations)
00066 {
00067     CTestFixedNumIter *theCopy ;
00068     theCopy = new CTestFixedNumIter(iterations, this->printFlag, this->nType) ;
00069     
00070     theCopy->theSOE = this->theSOE ;
00071     
00072     return theCopy ;
00073 }
00074 
00075 
00076 int CTestFixedNumIter::setEquiSolnAlgo(EquiSolnAlgo &theAlgo)
00077 {
00078     theSOE = theAlgo.getLinearSOEptr();
00079     if (theSOE == 0)  {
00080         opserr << "WARNING: CTestFixedNumIter::setEquiSolnAlgo() - no SOE\n";   
00081         return -1;
00082     }
00083     else
00084         return 0;
00085 }
00086 
00087 
00088 int CTestFixedNumIter::test(void)
00089 {
00090     // check to ensure the SOE has been set - this should not happen if the 
00091     // return from start() is checked
00092     if (theSOE == 0)
00093         return -2;
00094     
00095     // check to ensure the algo does invoke start() - this is needed otherwise
00096     // may never get convergence later on in analysis!
00097     if (currentIter == 0)  {
00098         opserr << "WARNING: CTestFixedNumIter::test() - start() was never invoked.\n";  
00099         return -2;
00100     }
00101         
00102     // determine the energy & save value in norms vector
00103     const Vector &b = theSOE->getB();
00104     const Vector &x = theSOE->getX();    
00105     double product = x ^ b;
00106     if (product < 0.0)
00107         product *= -0.5;
00108     else
00109         product *= 0.5;
00110     
00111     if (currentIter <= maxNumIter) 
00112         norms(currentIter-1) = product;
00113 
00114     // print the data if required
00115     if (printFlag == 1)  {
00116         opserr << "CTestFixedNumIter::test() - iteration: " << currentIter;
00117         opserr << " current EnergyIncr: " << product;
00118         opserr << " (Norm deltaX: " << x.pNorm(nType) << ", Norm deltaR: " << b.pNorm(nType) << ")\n";
00119     } 
00120     if (printFlag == 4)  {
00121         opserr << "CTestFixedNumIter::test() - iteration: " << currentIter;
00122         opserr << " current EnergyIncr: " << product;
00123         opserr << " (Norm deltaX: " << x.pNorm(nType) << ", Norm deltaR: " << b.pNorm(nType) << ")\n";
00124         opserr << "\tdeltaX: " << x << "\tdeltaR: " << b;
00125     } 
00126     
00127     //
00128     // check if the algorithm converged
00129     //
00130     
00131     // if converged - print & return ok
00132     if (currentIter == maxNumIter)  { 
00133         
00134         // do some printing first
00135         if (printFlag != 0) {
00136             if (printFlag == 1 || printFlag == 4) 
00137                 opserr << endln;
00138             else if (printFlag == 2 || printFlag == 6)  {
00139                 opserr << "CTestFixedNumIter::test() - iteration: " << currentIter;
00140                 opserr << " last EnergyIncr: " << product;
00141                 opserr << " (Norm deltaX: " << x.pNorm(nType) << ", Norm deltaR: " << b.pNorm(nType) << ")\n";
00142             }
00143         }
00144         
00145         // return the number of times test has been called
00146         return currentIter;
00147     }
00148         
00149     // algorithm not yet converged - increment counter and return -1
00150     else {
00151         currentIter++;    
00152         return -1;
00153     }
00154 }
00155 
00156 
00157 int CTestFixedNumIter::start(void)
00158 {
00159     if (theSOE == 0) {
00160         opserr << "WARNING: CTestFixedNumIter::test() - no SOE returning true\n";
00161         return -1;
00162     }
00163     
00164     // set iteration count = 1
00165     currentIter = 1;
00166     norms.Zero();
00167     return 0;
00168 }
00169 
00170 
00171 int CTestFixedNumIter::getNumTests()
00172 {
00173     return currentIter;
00174 }
00175 
00176 
00177 int CTestFixedNumIter::getMaxNumTests(void)
00178 {
00179     return maxNumIter;
00180 }
00181 
00182 
00183 double CTestFixedNumIter::getRatioNumToMax(void)
00184 {
00185     double div = maxNumIter;
00186     return currentIter/div;
00187 }
00188 
00189 
00190 const Vector& CTestFixedNumIter::getNorms() 
00191 {
00192     return norms;
00193 }
00194 
00195 
00196 int CTestFixedNumIter::sendSelf(int cTag, Channel &theChannel)
00197 {
00198     int res = 0;
00199     Vector x(3);
00200     x(0) = maxNumIter;
00201     x(1) = printFlag;
00202     x(2) = nType;
00203     res = theChannel.sendVector(this->getDbTag(), cTag, x);
00204     if (res < 0) 
00205         opserr << "CTestFixedNumIter::sendSelf() - failed to send data\n";
00206     
00207     return res;
00208 }
00209 
00210 
00211 int CTestFixedNumIter::recvSelf(int cTag, Channel &theChannel, 
00212     FEM_ObjectBroker &theBroker)
00213 {
00214     int res = 0;
00215     Vector x(3);
00216     res = theChannel.recvVector(this->getDbTag(), cTag, x);    
00217     
00218     if (res < 0) {
00219         opserr << "CTestFixedNumIter::sendSelf() - failed to send data\n";
00220         maxNumIter = 25;
00221         printFlag = 0;
00222         nType = 2;
00223     } else  {
00224         maxNumIter = (int) x(0);
00225         printFlag = (int) x(1);
00226         nType = (int) x(2);
00227         norms.resize(maxNumIter);
00228     }
00229     return res;
00230 }

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