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

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