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 #include <InitialInterpolatedLineSearch.h>
00031 #include <IncrementalIntegrator.h>
00032 #include <LinearSOE.h>
00033 #include <Channel.h>
00034 #include <FEM_ObjectBroker.h>
00035 #include <Vector.h>
00036 #include <math.h>
00037
00038
00039 InitialInterpolatedLineSearch::InitialInterpolatedLineSearch(double tol, int mIter, double mnEta,
00040 double mxEta, int pFlag)
00041 :LineSearch(LINESEARCH_TAGS_InitialInterpolatedLineSearch),
00042 x(0), tolerance(tol), maxIter(mIter), minEta(mnEta), maxEta(mxEta), printFlag(pFlag)
00043 {
00044
00045 }
00046
00047 InitialInterpolatedLineSearch::~InitialInterpolatedLineSearch()
00048 {
00049 if (x != 0)
00050 delete x;
00051 }
00052
00053 int
00054 InitialInterpolatedLineSearch::newStep(LinearSOE &theSOE)
00055 {
00056 const Vector &dU = theSOE.getX();
00057
00058 if (x == 0)
00059 x = new Vector(dU);
00060
00061 if (x->Size() != dU.Size()) {
00062 delete x;
00063 x = new Vector(dU);
00064 }
00065
00066 return 0;
00067 }
00068
00069 int
00070 InitialInterpolatedLineSearch::search(double s0,
00071 double s1,
00072 LinearSOE &theSOE,
00073 IncrementalIntegrator &theIntegrator)
00074 {
00075 double s = s1;
00076
00077
00078 double r0 = 0.0;
00079
00080 if ( s0 != 0.0 )
00081 r0 = fabs( s / s0 );
00082
00083 if (r0 <= tolerance )
00084 return 0;
00085
00086 double eta = 1.0;
00087 double etaPrev = 1.0;
00088 double r = r0;
00089
00090 const Vector &dU = theSOE.getX();
00091
00092 int count = 0;
00093
00094 if (printFlag == 0) {
00095 opserr << "InitialInterpolated Line Search - initial "
00096 << " eta : " << eta
00097 << " , Ratio |s/s0| = " << r0 << endln;
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 while ( r > tolerance && count < maxIter ) {
00110
00111 count++;
00112
00113 eta *= s0 / (s0 - s);
00114
00115
00116 if (eta > maxEta) eta = maxEta;
00117 if (r > r0 ) eta = 1.0;
00118 if (eta < minEta) eta = minEta;
00119
00120
00121
00122 *x = dU;
00123 *x *= eta-etaPrev;
00124
00125 if (theIntegrator.update(*x) < 0) {
00126 opserr << "WARNInG InitialInterpolatedLineSearch::search() -";
00127 opserr << "the Integrator failed in update()\n";
00128 return -1;
00129 }
00130
00131 if (theIntegrator.formUnbalance() < 0) {
00132 opserr << "WARNInG InitialInterpolatedLineSearch::search() -";
00133 opserr << "the Integrator failed in formUnbalance()\n";
00134 return -2;
00135 }
00136
00137
00138 const Vector &ResidI = theSOE.getB();
00139
00140
00141 s = dU ^ ResidI;
00142
00143
00144 r = fabs( s / s0 );
00145
00146 if (printFlag == 0) {
00147 opserr << "InitialInterpolated Line Search - iteration: " << count
00148 << " , eta(j) : " << eta
00149 << " , Ratio |sj/s0| = " << r << endln;
00150 }
00151
00152
00153 if (eta == etaPrev)
00154 count = maxIter;
00155 else
00156 etaPrev = eta;
00157
00158 }
00159
00160
00161 *x = dU;
00162 *x *= eta;
00163 theSOE.setX(*x);
00164
00165 return 0;
00166 }
00167
00168
00169 int
00170 InitialInterpolatedLineSearch::sendSelf(int cTag, Channel &theChannel)
00171 {
00172 return 0;
00173 }
00174
00175 int
00176 InitialInterpolatedLineSearch::recvSelf(int cTag,
00177 Channel &theChannel,
00178 FEM_ObjectBroker &theBroker)
00179 {
00180 return 0;
00181 }
00182
00183
00184 void
00185 InitialInterpolatedLineSearch::Print(OPS_Stream &s, int flag)
00186 {
00187 if (flag == 0)
00188 s << "InitialInterpolatedLineSearch :: Line Search Tolerance = " << tolerance << endln;
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198