ModifiedNewton.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.7 $
00022 // $Date: 2005/11/29 22:42:41 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/analysis/algorithm/equiSolnAlgo/ModifiedNewton.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/OOP/analysis/algorithm/ModifiedNewton.C 
00027 // 
00028 // Written: fmk 
00029 // Created: 11/96 
00030 // Revision: A 
00031 //
00032 // Description: This file contains the class definition for 
00033 // ModifiedNewton. ModifiedNewton is a class which uses the
00034 // Newton-Raphson solution algorihm
00035 // to solve the equations. No member functions are declared as virtual as 
00036 // it is not expected that this class will be subclassed.
00037 // 
00038 // What: "@(#)ModifiedNewton.C, revA"
00039 
00040 #include <ModifiedNewton.h>
00041 #include <AnalysisModel.h>
00042 #include <StaticAnalysis.h>
00043 #include <IncrementalIntegrator.h>
00044 #include <LinearSOE.h>
00045 #include <ID.h>
00046 #include <Channel.h>
00047 #include <FEM_ObjectBroker.h>
00048 #include <ConvergenceTest.h>
00049 #include <Timer.h>
00050 
00051 // Constructor
00052 ModifiedNewton::ModifiedNewton(int theTangentToUse)
00053 :EquiSolnAlgo(EquiALGORITHM_TAGS_ModifiedNewton),
00054  theTest(0), tangent(theTangentToUse)
00055 {
00056   
00057 }
00058 
00059 
00060 ModifiedNewton::ModifiedNewton(ConvergenceTest &theT, int theTangentToUse)
00061 :EquiSolnAlgo(EquiALGORITHM_TAGS_ModifiedNewton),
00062  theTest(&theT), tangent(theTangentToUse)
00063 {
00064 
00065 }
00066 
00067 // Destructor
00068 ModifiedNewton::~ModifiedNewton()
00069 {
00070 
00071 }
00072 
00073 int
00074 ModifiedNewton::setConvergenceTest(ConvergenceTest *newTest)
00075 {
00076     theTest = newTest;
00077     return 0;
00078 }
00079 
00080 int 
00081 ModifiedNewton::solveCurrentStep(void)
00082 {
00083     // set up some pointers and check they are valid
00084     // NOTE this could be taken away if we set Ptrs as protecetd in superclass
00085     AnalysisModel       *theAnalysisModel = this->getAnalysisModelPtr();
00086     IncrementalIntegrator *theIncIntegratorr = this->getIncrementalIntegratorPtr();
00087     LinearSOE           *theSOE = this->getLinearSOEptr();
00088 
00089     if ((theAnalysisModel == 0) || (theIncIntegratorr == 0) || (theSOE == 0)
00090         || (theTest == 0)){
00091         opserr << "WARNING ModifiedNewton::solveCurrentStep() - setLinks() has";
00092         opserr << " not been called - or no ConvergenceTest has been set\n";
00093         return -5;
00094     }   
00095 
00096     // we form the tangent
00097     //    Timer timer1;
00098     // timer1.start();
00099 
00100     if (theIncIntegratorr->formUnbalance() < 0) {
00101         opserr << "WARNING ModifiedNewton::solveCurrentStep() -";
00102         opserr << "the Integrator failed in formUnbalance()\n"; 
00103         return -2;
00104     }   
00105 
00106     if (theIncIntegratorr->formTangent(tangent) < 0){
00107         opserr << "WARNING ModifiedNewton::solveCurrentStep() -";
00108         opserr << "the Integrator failed in formTangent()\n";
00109         return -1;
00110     }               
00111 
00112     // set itself as the ConvergenceTest objects EquiSolnAlgo
00113     theTest->setEquiSolnAlgo(*this);
00114     if (theTest->start() < 0) {
00115       opserr << "ModifiedNewton::solveCurrentStep() -";
00116       opserr << "the ConvergenceTest object failed in start()\n";
00117       return -3;
00118     }
00119 
00120     // repeat until convergence is obtained or reach max num iterations
00121     int result = -1;
00122     int count = 0;
00123     do {
00124       //Timer timer2;
00125       //timer2.start();
00126         if (theSOE->solve() < 0) {
00127             opserr << "WARNING ModifiedNewton::solveCurrentStep() -";
00128             opserr << "the LinearSysOfEqn failed in solve()\n"; 
00129             return -3;
00130         }           
00131         //timer2.pause();
00132         //opserr << "TIMER::SOLVE()- " << timer2;
00133         
00134         if (theIncIntegratorr->update(theSOE->getX()) < 0) {
00135             opserr << "WARNING ModifiedNewton::solveCurrentStep() -";
00136             opserr << "the Integrator failed in update()\n";    
00137             return -4;
00138         }               
00139 
00140         if (theIncIntegratorr->formUnbalance() < 0) {
00141             opserr << "WARNING ModifiedNewton::solveCurrentStep() -";
00142             opserr << "the Integrator failed in formUnbalance()\n";     
00143             return -2;
00144         }       
00145 
00146         this->record(count++);
00147         result = theTest->test();
00148 
00149     } while (result == -1);
00150 
00151     //timer1.pause();
00152     //opserr << "TIMER::solveCurrentStep - " << timer1;
00153 
00154     if (result == -2) {
00155       opserr << "ModifiedNewton::solveCurrentStep() -";
00156       opserr << "the ConvergenceTest object failed in test()\n";
00157       return -3;
00158     }
00159 
00160     return result;
00161 }
00162 
00163 ConvergenceTest *
00164 ModifiedNewton::getConvergenceTest(void)
00165 {
00166   return theTest;
00167 }
00168 
00169 int
00170 ModifiedNewton::sendSelf(int cTag, Channel &theChannel)
00171 {
00172   static ID data(1);
00173   data(0) = tangent;
00174   return theChannel.sendID(this->getDbTag(), cTag, data);
00175 }
00176 
00177 int
00178 ModifiedNewton::recvSelf(int cTag, 
00179                         Channel &theChannel, 
00180                         FEM_ObjectBroker &theBroker)
00181 {
00182   static ID data(1);
00183   theChannel.recvID(this->getDbTag(), cTag, data);
00184   tangent = data(0);
00185   return 0;
00186 }
00187 
00188 void
00189 ModifiedNewton::Print(OPS_Stream &s, int flag)
00190 {
00191     if (flag == 0) {
00192         s << "ModifiedNewton";
00193     }
00194 }

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