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

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.4 $
00022 // $Date: 2001/03/29 05:30:30 $
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 
00052 #include <fstream.h>
00053 
00054 // Constructor
00055 NewtonRaphson::NewtonRaphson(int theTangentToUse)
00056 :EquiSolnAlgo(EquiALGORITHM_TAGS_NewtonRaphson),
00057  theTest(0), tangent(theTangentToUse)
00058 {
00059 
00060 }
00061 
00062 
00063 NewtonRaphson::NewtonRaphson(ConvergenceTest &theT, int theTangentToUse)
00064 :EquiSolnAlgo(EquiALGORITHM_TAGS_NewtonRaphson),
00065  theTest(&theT), tangent(theTangentToUse)
00066 {
00067 
00068 }
00069 
00070 // Destructor
00071 NewtonRaphson::~NewtonRaphson()
00072 {
00073   
00074 
00075 }
00076 
00077 void 
00078 NewtonRaphson::setTest(ConvergenceTest &newTest)
00079 {
00080     theTest = &newTest;
00081 }
00082 
00083 
00084 
00085 int 
00086 NewtonRaphson::solveCurrentStep(void)
00087 {
00088     // set up some pointers and check they are valid
00089     // NOTE this could be taken away if we set Ptrs as protecetd in superclass
00090     AnalysisModel   *theAnaModel = this->getAnalysisModelPtr();
00091     IncrementalIntegrator *theIntegrator = this->getIncrementalIntegratorPtr();
00092     LinearSOE  *theSOE = this->getLinearSOEptr();
00093 
00094     if ((theAnaModel == 0) || (theIntegrator == 0) || (theSOE == 0)
00095  || (theTest == 0)){
00096  cerr << "WARNING NewtonRaphson::solveCurrentStep() - setLinks() has";
00097  cerr << " not been called - or no ConvergenceTest has been set\n";
00098  return -5;
00099     } 
00100 
00101 
00102     if (theIntegrator->formUnbalance() < 0) {
00103       cerr << "WARNING NewtonRaphson::solveCurrentStep() -";
00104       cerr << "the Integrator failed in formUnbalance()\n"; 
00105       return -2;
00106     }     
00107 
00108 
00109     // set itself as the ConvergenceTest objects EquiSolnAlgo
00110     theTest->setEquiSolnAlgo(*this);
00111     if (theTest->start() < 0) {
00112       cerr << "NewtnRaphson::solveCurrentStep() -";
00113       cerr << "the ConvergenceTest object failed in start()\n";
00114       return -3;
00115     }
00116 
00117 
00118     int result = -1;
00119     int count = 0;
00120     do {
00121  if (theIntegrator->formTangent(tangent) < 0){
00122      cerr << "WARNING NewtonRaphson::solveCurrentStep() -";
00123      cerr << "the Integrator failed in formTangent()\n";
00124      return -1;
00125  }      
00126  
00127  if (theSOE->solve() < 0) {
00128      cerr << "WARNING NewtonRaphson::solveCurrentStep() -";
00129      cerr << "the LinearSysOfEqn failed in solve()\n"; 
00130      return -3;
00131  }     
00132 
00133 
00134  if (theIntegrator->update(theSOE->getX()) < 0) {
00135      cerr << "WARNING NewtonRaphson::solveCurrentStep() -";
00136      cerr << "the Integrator failed in update()\n"; 
00137      return -4;
00138  }         
00139 
00140  if (theIntegrator->formUnbalance() < 0) {
00141      cerr << "WARNING NewtonRaphson::solveCurrentStep() -";
00142      cerr << "the Integrator failed in formUnbalance()\n"; 
00143      return -2;
00144  } 
00145 
00146  result = theTest->test();
00147  this->record(count++);
00148 
00149     } while (result == -1);
00150 
00151     if (result == -2) {
00152       cerr << "NewtnRaphson::solveCurrentStep() -";
00153       cerr << "the ConvergenceTest object failed in test()\n";
00154       return -3;
00155     }
00156 
00157     // note - if postive result we are returning what the convergence test returned
00158     // which should be the number of iterations
00159     return result;
00160 }
00161 
00162 ConvergenceTest *
00163 NewtonRaphson::getTest(void)
00164 {
00165   return theTest;
00166 }
00167 
00168 int
00169 NewtonRaphson::sendSelf(int cTag, Channel &theChannel)
00170 {
00171   int result = 0;
00172   int dataTag = this->getDbTag();
00173   ID data(2);
00174   data(0) = theTest->getClassTag();
00175   data(1) = theTest->getDbTag();
00176   result = theChannel.sendID(dataTag, cTag, data);
00177   if (result != 0) {
00178     cerr << "NewtonRaphson::sendSelf() - failed to send ID\n";
00179     return result;
00180   }
00181 
00182   result = theTest->sendSelf(cTag, theChannel);
00183   if (result != 0) {
00184     cerr << "NewtonRaphson::sendSelf() - failed to send CTest object\n";
00185     return result;
00186   }
00187   
00188   return 0;
00189 }
00190 
00191 int
00192 NewtonRaphson::recvSelf(int cTag, 
00193    Channel &theChannel, 
00194    FEM_ObjectBroker &theBroker)
00195 {
00196     ID data(2);
00197     int result;
00198     int dataTag = this->getDbTag();
00199 
00200     result = theChannel.recvID(dataTag, cTag, data);    
00201     if (result != 0) {
00202       cerr << "NewtonRaphson::recvSelf() - failed to receive ID\n";
00203       return result;
00204     }
00205     int ctType = data(0);
00206     int ctDb = data(1);
00207     
00208     theTest = theBroker.getNewConvergenceTest(ctType);
00209     theTest->setDbTag(ctDb);
00210     result = theTest->recvSelf(cTag, theChannel, theBroker);
00211     if (result != 0) {
00212       cerr << "NewtonRaphson::recvSelf() - failed to recv CTest object\n";
00213       return result;
00214     }
00215     
00216     return 0;
00217 }
00218 
00219 
00220 void
00221 NewtonRaphson::Print(ostream &s, int flag)
00222 {
00223     if (flag == 0) {
00224  s << "ModifiedNewton";
00225     }
00226 }
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
Copyright Contact Us