00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
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
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
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
00089
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
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
00158
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