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

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