00001 #include "QuadraticCyclic.h"
00002 #include <math.h>
00003
00004 Matrix QuadraticCyclic::X(3,3);
00005 Vector QuadraticCyclic::Y(3);
00006 Vector QuadraticCyclic::A(3);
00007
00008 QuadraticCyclic::QuadraticCyclic(int tag, double wt, double fac_y)
00009 :CyclicModel(tag, -1), weightFactor(wt), facty(fac_y),
00010 qx1(0.0), qy1(0.0), qx2(0.0), qy2(0.0), qx3(0.0), qy3(0.0)
00011 {
00012
00013 }
00014
00015 QuadraticCyclic::~QuadraticCyclic()
00016 {
00017
00018 }
00019
00020 int QuadraticCyclic::createFullCycleTask()
00021 {
00022 int res = this->CyclicModel::createFullCycleTask();
00023 res+= createTask();
00024
00025 return res;
00026 }
00027
00028 int QuadraticCyclic::createHalfCycleTask()
00029 {
00030 int res = this->CyclicModel::createHalfCycleTask();
00031 res+= createTask();
00032
00033 return res;
00034 }
00035
00036
00037 CyclicModel *QuadraticCyclic::getCopy()
00038 {
00039 CyclicModel *newModel = new QuadraticCyclic(getTag(), weightFactor, facty);
00040 return newModel;
00041 }
00042
00043
00044 int QuadraticCyclic::createTask()
00045 {
00046 if(f_bgn*f_end < 0)
00047 {
00048 double k0 = k_init;
00049 double delx0 = f_bgn/(resFactor*k0);
00050
00051 double qy = facty;
00052 double x1 = d_bgn, y1 = f_bgn;
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 double delx2 = delx0*(1 - qy);
00064 double x2 = d_bgn - delx2;
00065 double y2 = qy*f_bgn;
00066
00067 double x0 = d_bgn - delx0;
00068 double y0 = 0.0;
00069
00070 double R = sqrt( (x2 - x0)*(x2 - x0) + (y2 - y0)*(y2 - y0));
00071 double delx_end = d_end - x0;
00072 double dely_end = f_end - y0;
00073
00074 double R_end = sqrt(delx_end*delx_end + dely_end*dely_end);
00075
00076 double delx3 = delx_end*R/R_end;
00077 double y3 = f_end*R/R_end;
00078 double x3 = x0 + delx3;
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 qx1 = x1; qy1 = y1;
00090 qx2 = x2; qy2 = y2;
00091 qx3 = x3; qy3 = y3;
00092
00093 solveQuad(x1, y1, x2, y2, x3, y3);
00094 }
00095
00096 return 0;
00097 }
00098
00099
00100 int QuadraticCyclic::solveQuad(double x1, double y1, double x2,
00101 double y2, double x3, double y3)
00102 {
00103
00104 X(0,0) = x1*x1; X(0,1) = x1; X(0,2) = 1.0;
00105 X(1,0) = x2*x2; X(1,1) = x2; X(1,2) = 1.0;
00106 X(2,0) = x3*x3; X(2,1) = x3; X(2,2) = 1.0;
00107
00108 Y(0) = y1; Y(1) = y2; Y(2) = y3;
00109
00110 A = Y/X;
00111 a = A(0);
00112 b = A(1);
00113 c = A(2);
00114
00115
00116
00117 return 0;
00118 }
00119
00120 double QuadraticCyclic::getQuadFactor(double x1, double y1, double dx)
00121 {
00122
00123 double x_nxt = x1 + dx;
00124 double y_nxt = a*x_nxt*x_nxt + b*x_nxt + c;
00125 double x_prv = x1 - dx;
00126 double y_prv = a*x_prv*x_prv + b*x_prv + c;
00127
00128
00129
00130 return (rationalize(x_prv, y_prv, x_nxt, y_nxt));
00131
00132 }
00133
00134
00135 double QuadraticCyclic::getTaskFactor()
00136 {
00137 double tfactor;
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 if(yielding )
00148
00149 tfactor = cycFactor_hist;
00150 else
00151 {
00152 if(f_bgn*f_end < 0)
00153 {
00154
00155 if(contains(qy1, qy3, f_curr))
00156 tfactor = getQuadFactor(d_curr, f_curr, (d_curr - d_hist)/2);
00157 else
00158 {
00159 tfactor=rationalize(d_curr, f_curr, d_end, f_end);
00160 tfactor = weightFactor*tfactor + (1 - weightFactor)*resFactor;
00161 }
00162 }
00163 else
00164 {
00165 tfactor = rationalize(d_bgn, f_bgn, d_end, f_end);
00166 tfactor = weightFactor*tfactor + (1 - weightFactor)*resFactor;
00167 }
00168 }
00169
00170
00171 return tfactor;
00172 }
00173
00174 void QuadraticCyclic::Print (OPS_Stream &s, int flag)
00175 {
00176 this->CyclicModel::Print (s, flag);
00177 s << "+QuadraticCyclic\n";
00178 s << " taskFactor = " << cycFactor << endln;
00179 s << " a=" << a <<", b=" << b <<", c=" << c << endln;
00180 s << "----------------------------------------"
00181 << "----------------------------------------"
00182 << endln;
00183 }
00184
00185
00186