QList<char> productionRules(QVector<double> params) { switch((int)params[0]) { case 0: return T1().symbol({0,0}); break; case -1: return T2().symbol({0,0}); break; default: return r3.productionRules({params[0] - 1, 0}) + productionRules({params[0]-2,0}); } }
geometry_msgs::Pose Sensors::robot2sensorTransformation(geometry_msgs::Pose pose) { Eigen::Matrix4d robotPoseMat, robot2sensorMat, sensorPoseMat; //Robot matrix pose Eigen::Matrix3d R; Eigen::Vector3d T1(pose.position.x,pose.position.y,pose.position.z); tf::Quaternion qt(pose.orientation.x,pose.orientation.y,pose.orientation.z,pose.orientation.w); tf::Matrix3x3 R1(qt); tf::matrixTFToEigen(R1,R); robotPoseMat.setZero (); robotPoseMat.block (0, 0, 3, 3) = R; robotPoseMat.block (0, 3, 3, 1) = T1; robotPoseMat (3, 3) = 1; //transformation matrix qt = tf::createQuaternionFromRPY(sensorRPY[0],sensorRPY[1],sensorRPY[2]); tf::Matrix3x3 R2(qt);Eigen::Vector3d T2(sensorPose[0], sensorPose[1], sensorPose[2]); tf::matrixTFToEigen(R2,R); robot2sensorMat.setZero (); robot2sensorMat.block (0, 0, 3, 3) = R; robot2sensorMat.block (0, 3, 3, 1) = T2; robot2sensorMat (3, 3) = 1; //preform the transformation sensorPoseMat = robotPoseMat * robot2sensorMat; Eigen::Matrix4d sensor2sensorMat; //the frustum culling sensor needs this //the transofrmation is rotation by +90 around x axis of the sensor sensor2sensorMat << 1, 0, 0, 0, 0, 0,-1, 0, 0, 1, 0, 0, 0, 0, 0, 1; Eigen::Matrix4d newSensorPoseMat = sensorPoseMat * sensor2sensorMat; geometry_msgs::Pose p; Eigen::Vector3d T3;Eigen::Matrix3d Rd; tf::Matrix3x3 R3; Rd = newSensorPoseMat.block (0, 0, 3, 3); tf::matrixEigenToTF(Rd,R3); T3 = newSensorPoseMat.block (0, 3, 3, 1); p.position.x=T3[0];p.position.y=T3[1];p.position.z=T3[2]; R3.getRotation(qt); p.orientation.x = qt.getX(); p.orientation.y = qt.getY();p.orientation.z = qt.getZ();p.orientation.w = qt.getW(); return p; }
int sc_main(int ac, char *av[]) { // Signal Instantiation signal_bool_vector prime ("prime"); // Clock Instantiation sc_clock clk ("CLK", 6, SC_NS, 0.5, 0, SC_NS); // 167 Mhz // Process Instantiation displayp T2 ("T2", clk, prime); // Simulation Run Control sc_start( 30, SC_NS, SC_EXIT_ON_STARVATION ); cout << sc_time_stamp() << " : STOPPING SIM - start button" << endl; return 0; }
rgpprob1::rgpprob1() : rgp_base(NUM_VARS) { // Objective function: h^-1 w^-1 d^-1 (inverse of volume) { monomial<aaf> obj(NUM_VARS); obj._a[h] = aaf(-1.0); obj._a[w] = aaf(-1.0); obj._a[d] = aaf(-1.0); obj.set_coeff(aaf(1.0)); rgp_base::_M.push_back( posynomial<aaf>(obj) ); } // (2/Awall)hw + (2/Awall)hd <= 1 { monomial<aaf> T11(NUM_VARS); T11._a[h] = aaf(1.0); T11._a[w] = aaf(1.0); T11.set_coeff(2./Awall); monomial<aaf> T12(NUM_VARS); T12._a[h] = aaf(1.0); T12._a[d] = aaf(1.0); T12.set_coeff(2./Awall); posynomial<aaf> P1(T11); P1 += T12; rgp_base::_M.push_back(P1); } { monomial<aaf> T2(NUM_VARS); T2._a[w] = aaf(1.0); T2._a[d] = aaf(1.0); T2.set_coeff(1./Aflr); rgp_base::_M.push_back( posynomial<aaf>(T2) ); } { monomial<aaf> T3(NUM_VARS); T3._a[h] = aaf(-1.0); T3._a[w] = aaf(1.0); T3.set_coeff(alpha); rgp_base::_M.push_back( posynomial<aaf>(T3) ); } { monomial<aaf> T4(NUM_VARS); T4._a[h] = aaf(1.0); T4._a[w] = aaf(-1.0); T4.set_coeff(1./beta); rgp_base::_M.push_back( posynomial<aaf>(T4) ); } { monomial<aaf> T5(NUM_VARS); T5._a[w] = aaf(1.0); T5._a[d] = aaf(-1.0); T5.set_coeff(gamma2); rgp_base::_M.push_back( posynomial<aaf>(T5) ); } { monomial<aaf> T6(NUM_VARS); T6._a[w] = aaf(-1.0); T6._a[d] = aaf(1.0); T6.set_coeff(1./delta); rgp_base::_M.push_back( posynomial<aaf>(T6) ); } }
void generateRandomTransform_ccd(FCL_REAL extents[6], std::vector<Transform3f>& transforms, std::vector<Transform3f>& transforms2, FCL_REAL delta_trans[3], FCL_REAL delta_rot, std::size_t n, const std::vector<Vec3f>& vertices1, const std::vector<Triangle>& triangles1, const std::vector<Vec3f>& vertices2, const std::vector<Triangle>& triangles2) { transforms.resize(n); transforms2.resize(n); for(std::size_t i = 0; i < n;) { FCL_REAL x = rand_interval(extents[0], extents[3]); FCL_REAL y = rand_interval(extents[1], extents[4]); FCL_REAL z = rand_interval(extents[2], extents[5]); const FCL_REAL pi = 3.1415926; FCL_REAL a = rand_interval(0, 2 * pi); FCL_REAL b = rand_interval(0, 2 * pi); FCL_REAL c = rand_interval(0, 2 * pi); Matrix3f R; eulerToMatrix(a, b, c, R); Vec3f T(x, y, z); Transform3f tf(R, T); std::vector<std::pair<int, int> > results; { transforms[i] = tf; FCL_REAL deltax = rand_interval(-delta_trans[0], delta_trans[0]); FCL_REAL deltay = rand_interval(-delta_trans[1], delta_trans[1]); FCL_REAL deltaz = rand_interval(-delta_trans[2], delta_trans[2]); FCL_REAL deltaa = rand_interval(-delta_rot, delta_rot); FCL_REAL deltab = rand_interval(-delta_rot, delta_rot); FCL_REAL deltac = rand_interval(-delta_rot, delta_rot); Matrix3f R2; eulerToMatrix(a + deltaa, b + deltab, c + deltac, R2); Vec3f T2(x + deltax, y + deltay, z + deltaz); transforms2[i].setTransform(R2, T2); ++i; } } }
void start ( void) { //---------------------- begin --------------------- assert ( N ==0 ); //std::cout<<"1.-Begin main function \n"; N++ ; s.try_lock() ; N++ ; std::thread T1 ( function1); std::thread T2 ( function2); //std::cout<<"2.-Inside main function \n"; std::this_thread::sleep_for( std::chrono::seconds(3) ) ; assert ( N == 4 ); N++ ; s.unlock() ; T1.join() ; T2.join() ; assert ( N == 9); //std::cout<<"7.-End of main function \n"; }
int main() { std::mutex MX; std::condition_variable CV; auto F1 = [&] { std::cout << "Start F1" << std::endl; try { std::unique_lock<std::mutex> UL(MX); while (true) { interruptible_wait(CV, UL); } } catch (thread_interrupted& e) { std::cout << e.what() << std::endl; } std::cout << "Endof F1" << std::endl; }; interruptible_thread T1(F1); std::thread T2([&] { std::cout << "Start F2" << std::endl; std::this_thread::sleep_for(std::chrono::milliseconds(1000)); T1.interrupt(); //std::this_thread::sleep_for(std::chrono::milliseconds(10000)); //T1.interrupt(); std::cout << "Endof F2" << std::endl; }); T1.join(); T2.join(); return 0; }
template<class T2> void LinearTermBase<T2>::get(MElement *ele, int npts, IntPt *GP, fullVector<T2> &vec) const { std::vector<fullVector<T2> > vv; vv.resize(npts); get(ele,npts,GP,vv); int nbFF=vv[0].size(); vec.resize(nbFF); vec.setAll(T2()); double jac[3][3]; for(int i = 0; i < npts; i++) { const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2]; const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac); for(int j = 0; j < nbFF; j++) { double contrib = weight * detJ; vec(j) += contrib*vv[i](j); } } }
void main(){ cout << "201211305 이현규" << endl; time T1; T1.reset(4, 50); T1.show(); T1.addMin(100); T1.show(); time T2(1, 30); time T3 = T1.operator+(T2); T3.show(); time T4 = 2.5 * T2; T4.show(); //T1 = T2.operator*(T1); T4 << cout; cout << T4; // 연산자가 뒤에온다 해결방법은 friend 함수 }
Sphere::Sphere(const Point & pa, const Point & pb, const Point & pc, const Point & pd) { Point pad = pa - pd; Point pbd = pb - pd; Point pcd = pc - pd; TensorValue<Real> T(pad,pbd,pcd); Real D = T.det(); // The points had better not be coplanar libmesh_assert_greater (std::abs(D), 1e-12); Real e = 0.5*(pa.norm_sq() - pd.norm_sq()); Real f = 0.5*(pb.norm_sq() - pd.norm_sq()); Real g = 0.5*(pc.norm_sq() - pd.norm_sq()); TensorValue<Real> T1(e,pad(1),pad(2), f,pbd(1),pbd(2), g,pcd(1),pcd(2)); Real sx = T1.det()/D; TensorValue<Real> T2(pad(0),e,pad(2), pbd(0),f,pbd(2), pcd(0),g,pcd(2)); Real sy = T2.det()/D; TensorValue<Real> T3(pad(0),pad(1),e, pbd(0),pbd(1),f, pcd(0),pcd(1),g); Real sz = T3.det()/D; Point c(sx,sy,sz); Real r = (c-pa).norm(); this->create_from_center_radius(c,r); }
int sc_main(int ac, char *av[]) { // Signal Instantiation sc_signal<bool> reset ("reset"); sc_signal<bool> prime_ready ("prime_ready"); signal_bool_vector prime ("prime"); // Clock Instantiation sc_clock clk ("CLK", 6, SC_NS, 0.5, 10, SC_NS, false); // 167 Mhz // Process Instantiation prime_numgen D1 ("D1", clk, reset, prime_ready, prime); resetp T1 ("T1", clk, reset); displayp T2 ("T2", clk, prime_ready, prime); // Simulation Run Control sc_start(); return 0; }
int SM4_key_expansion(unsigned char* subkey, unsigned char* key) { unsigned CK[] = { 0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269, 0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9, 0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249, 0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9, 0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229, 0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299, 0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209, 0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279}; unsigned FK[] = { 0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc}; unsigned K[36]; int i; for(i = 0; i < 4; i ++) { K[i] = char_to_unsigned(key + i * 4); K[i] = key[i] ^ FK[i]; } for(i = 0; i < 32; i ++) { K[i + 4] = K[i] ^ T2(K[i + 1] ^ K[i + 2] ^ K[i + 3] ^ K[i]); unsigned_to_char(subkey + i * 4, K[i + 4]); } return 1; }
int VSSubphantom::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< double*>(_v) = T1(); break; case 1: *reinterpret_cast< double*>(_v) = T2(); break; case 2: *reinterpret_cast< double*>(_v) = chemicalShift(); break; } _id -= 3; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setT1(*reinterpret_cast< double*>(_v)); break; case 1: setT2(*reinterpret_cast< double*>(_v)); break; case 2: setChemicalShift(*reinterpret_cast< double*>(_v)); break; } _id -= 3; } else if (_c == QMetaObject::ResetProperty) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 3; } #endif // QT_NO_PROPERTIES return _id; }
void dotytab() { static tym_t _ptr[] = { TYnptr }; static tym_t _ptr_nflat[]= { TYsptr,TYcptr,TYf16ptr,TYfptr,TYhptr,TYvptr }; static tym_t _real[] = { TYfloat,TYdouble,TYdouble_alias,TYldouble, TYfloat4,TYdouble2, TYfloat8,TYdouble4, TYfloat16,TYdouble8, }; static tym_t _imaginary[] = { TYifloat,TYidouble,TYildouble, }; static tym_t _complex[] = { TYcfloat,TYcdouble,TYcldouble, }; static tym_t _integral[] = { TYbool,TYchar,TYschar,TYuchar,TYshort, TYwchar_t,TYushort,TYenum,TYint,TYuint, TYlong,TYulong,TYllong,TYullong,TYdchar, TYschar16,TYuchar16,TYshort8,TYushort8, TYlong4,TYulong4,TYllong2,TYullong2, TYschar32,TYuchar32,TYshort16,TYushort16, TYlong8,TYulong8,TYllong4,TYullong4, TYschar64,TYuchar64,TYshort32,TYushort32, TYlong16,TYulong16,TYllong8,TYullong8, TYchar16,TYcent,TYucent, }; static tym_t _ref[] = { TYnref,TYref }; static tym_t _func[] = { TYnfunc,TYnpfunc,TYnsfunc,TYifunc,TYmfunc,TYjfunc,TYhfunc }; static tym_t _ref_nflat[] = { TYfref }; static tym_t _func_nflat[]= { TYffunc,TYfpfunc,TYf16func,TYfsfunc,TYnsysfunc,TYfsysfunc, }; static tym_t _uns[] = { TYuchar,TYushort,TYuint,TYulong, TYwchar_t, TYuchar16,TYushort8,TYulong4,TYullong2, TYdchar,TYullong,TYucent,TYchar16 }; static tym_t _mptr[] = { TYmemptr }; static tym_t _nullptr[] = { TYnullptr }; static tym_t _fv[] = { TYfptr, TYvptr }; static tym_t _farfunc[] = { TYffunc,TYfpfunc,TYfsfunc,TYfsysfunc }; static tym_t _pasfunc[] = { TYnpfunc,TYnsfunc,TYmfunc,TYjfunc }; static tym_t _pasfunc_nf[] = { TYfpfunc,TYf16func,TYfsfunc, }; static tym_t _revfunc[] = { TYnpfunc,TYjfunc }; static tym_t _revfunc_nf[] = { TYfpfunc,TYf16func, }; static tym_t _short[] = { TYbool,TYchar,TYschar,TYuchar,TYshort, TYwchar_t,TYushort,TYchar16 }; static tym_t _aggregate[] = { TYstruct,TYarray }; static tym_t _xmmreg[] = { TYfloat,TYdouble,TYifloat,TYidouble, TYfloat4,TYdouble2, TYschar16,TYuchar16,TYshort8,TYushort8, TYlong4,TYulong4,TYllong2,TYullong2, TYfloat8,TYdouble4, TYschar32,TYuchar32,TYshort16,TYushort16, TYlong8,TYulong8,TYllong4,TYullong4, TYschar64,TYuchar64,TYshort32,TYushort32, TYlong16,TYulong16,TYllong8,TYullong8, TYfloat16,TYdouble8, }; static tym_t _simd[] = { TYfloat4,TYdouble2, TYschar16,TYuchar16,TYshort8,TYushort8, TYlong4,TYulong4,TYllong2,TYullong2, TYfloat8,TYdouble4, TYschar32,TYuchar32,TYshort16,TYushort16, TYlong8,TYulong8,TYllong4,TYullong4, TYschar64,TYuchar64,TYshort32,TYushort32, TYlong16,TYulong16,TYllong8,TYullong8, TYfloat16,TYdouble8, }; static struct { const char *string; /* name of type */ tym_t ty; /* TYxxxx */ tym_t unsty; /* conversion to unsigned type */ tym_t relty; /* type for relaxed type checking */ int size; int debtyp; /* Codeview 1 type in debugger record */ int debtyp4; /* Codeview 4 type in debugger record */ } typetab[] = { /* Note that chars are signed, here */ "bool", TYbool, TYbool, TYchar, 1, 0x80, 0x30, "char", TYchar, TYuchar, TYchar, 1, 0x80, 0x70, "signed char", TYschar, TYuchar, TYchar, 1, 0x80, 0x10, "unsigned char",TYuchar, TYuchar, TYchar, 1, 0x84, 0x20, "char16_t", TYchar16, TYchar16, TYint, 2, 0x85, 0x21, "short", TYshort, TYushort, TYint, SHORTSIZE, 0x81,0x11, "wchar_t", TYwchar_t, TYwchar_t, TYint, SHORTSIZE, 0x85,0x71, "unsigned short",TYushort, TYushort, TYint, SHORTSIZE, 0x85,0x21, // These values are adjusted for 32 bit ints in cv_init() and util_set32() "enum", TYenum, TYuint, TYint, -1, 0x81,0x72, "int", TYint, TYuint, TYint, 2, 0x81,0x72, "unsigned", TYuint, TYuint, TYint, 2, 0x85,0x73, "long", TYlong, TYulong, TYlong, LONGSIZE, 0x82,0x12, "unsigned long",TYulong, TYulong, TYlong, LONGSIZE, 0x86,0x22, "dchar", TYdchar, TYdchar, TYlong, 4, 0x86,0x22, "long long", TYllong, TYullong, TYllong, LLONGSIZE, 0x82,0x13, "uns long long",TYullong, TYullong, TYllong, LLONGSIZE, 0x86,0x23, "cent", TYcent, TYucent, TYcent, 16, 0x82,0x603, "ucent", TYucent, TYucent, TYcent, 16, 0x86,0x603, "float", TYfloat, TYfloat, TYfloat, FLOATSIZE, 0x88,0x40, "double", TYdouble, TYdouble, TYdouble, DOUBLESIZE,0x89,0x41, "double alias", TYdouble_alias, TYdouble_alias, TYdouble_alias,8, 0x89,0x41, "long double", TYldouble, TYldouble, TYldouble, -1, 0x89,0x42, "imaginary float", TYifloat, TYifloat, TYifloat, FLOATSIZE, 0x88,0x40, "imaginary double", TYidouble, TYidouble, TYidouble, DOUBLESIZE,0x89,0x41, "imaginary long double",TYildouble, TYildouble, TYildouble, -1,0x89,0x42, "complex float", TYcfloat, TYcfloat, TYcfloat, 2*FLOATSIZE, 0x88,0x50, "complex double", TYcdouble, TYcdouble, TYcdouble, 2*DOUBLESIZE,0x89,0x51, "complex long double", TYcldouble, TYcldouble, TYcldouble, -1,0x89,0x52, "float[4]", TYfloat4, TYfloat4, TYfloat4, 16, 0, 0, "double[2]", TYdouble2, TYdouble2, TYdouble2, 16, 0, 0, "signed char[16]", TYschar16, TYuchar16, TYschar16, 16, 0, 0, "unsigned char[16]", TYuchar16, TYuchar16, TYuchar16, 16, 0, 0, "short[8]", TYshort8, TYushort8, TYshort8, 16, 0, 0, "unsigned short[8]", TYushort8, TYushort8, TYushort8, 16, 0, 0, "long[4]", TYlong4, TYulong4, TYlong4, 16, 0, 0, "unsigned long[4]", TYulong4, TYulong4, TYulong4, 16, 0, 0, "long long[2]", TYllong2, TYullong2, TYllong2, 16, 0, 0, "unsigned long long[2]", TYullong2, TYullong2, TYullong2, 16, 0, 0, "float[8]", TYfloat8, TYfloat8, TYfloat8, 32, 0, 0, "double[4]", TYdouble4, TYdouble4, TYdouble4, 32, 0, 0, "signed char[32]", TYschar32, TYuchar32, TYschar32, 32, 0, 0, "unsigned char[32]", TYuchar32, TYuchar32, TYuchar32, 32, 0, 0, "short[16]", TYshort16, TYushort16, TYshort16, 32, 0, 0, "unsigned short[16]", TYushort16, TYushort16, TYushort16, 32, 0, 0, "long[8]", TYlong8, TYulong8, TYlong8, 32, 0, 0, "unsigned long[8]", TYulong8, TYulong8, TYulong8, 32, 0, 0, "long long[4]", TYllong4, TYullong4, TYllong4, 32, 0, 0, "unsigned long long[4]", TYullong4, TYullong4, TYullong4, 32, 0, 0, "float[16]", TYfloat16, TYfloat16, TYfloat16, 64, 0, 0, "double[8]", TYdouble8, TYdouble8, TYdouble8, 64, 0, 0, "signed char[64]", TYschar64, TYuchar64, TYschar64, 64, 0, 0, "unsigned char[64]", TYuchar64, TYuchar64, TYuchar64, 64, 0, 0, "short[32]", TYshort32, TYushort32, TYshort32, 64, 0, 0, "unsigned short[32]", TYushort32, TYushort32, TYushort32, 64, 0, 0, "long[16]", TYlong16, TYulong16, TYlong16, 64, 0, 0, "unsigned long[16]", TYulong16, TYulong16, TYulong16, 64, 0, 0, "long long[8]", TYllong8, TYullong8, TYllong8, 64, 0, 0, "unsigned long long[8]", TYullong8, TYullong8, TYullong8, 64, 0, 0, "nullptr_t", TYnullptr, TYnullptr, TYptr, 2, 0x20, 0x100, "*", TYnptr, TYnptr, TYnptr, 2, 0x20, 0x100, "&", TYref, TYref, TYref, -1, 0, 0, "void", TYvoid, TYvoid, TYvoid, -1, 0x85, 3, "struct", TYstruct, TYstruct, TYstruct, -1, 0, 0, "array", TYarray, TYarray, TYarray, -1, 0x78, 0, "C func", TYnfunc, TYnfunc, TYnfunc, -1, 0x63, 0, "Pascal func", TYnpfunc, TYnpfunc, TYnpfunc, -1, 0x74, 0, "std func", TYnsfunc, TYnsfunc, TYnsfunc, -1, 0x63, 0, "*", TYptr, TYptr, TYptr, 2, 0x20, 0x100, "member func", TYmfunc, TYmfunc, TYmfunc, -1, 0x64, 0, "D func", TYjfunc, TYjfunc, TYjfunc, -1, 0x74, 0, "C func", TYhfunc, TYhfunc, TYhfunc, -1, 0, 0, "__near &", TYnref, TYnref, TYnref, 2, 0, 0, "__ss *", TYsptr, TYsptr, TYsptr, 2, 0x20, 0x100, "__cs *", TYcptr, TYcptr, TYcptr, 2, 0x20, 0x100, "__far16 *", TYf16ptr, TYf16ptr, TYf16ptr, 4, 0x40, 0x200, "__far *", TYfptr, TYfptr, TYfptr, 4, 0x40, 0x200, "__huge *", TYhptr, TYhptr, TYhptr, 4, 0x40, 0x300, "__handle *", TYvptr, TYvptr, TYvptr, 4, 0x40, 0x200, "far C func", TYffunc, TYffunc, TYffunc, -1, 0x64, 0, "far Pascal func", TYfpfunc, TYfpfunc, TYfpfunc, -1, 0x73, 0, "far std func", TYfsfunc, TYfsfunc, TYfsfunc, -1, 0x64, 0, "_far16 Pascal func", TYf16func, TYf16func, TYf16func, -1, 0x63, 0, "sys func", TYnsysfunc, TYnsysfunc,TYnsysfunc, -1, 0x63, 0, "far sys func", TYfsysfunc, TYfsysfunc,TYfsysfunc, -1, 0x64, 0, "__far &", TYfref, TYfref, TYfref, 4, 0, 0, "interrupt func", TYifunc, TYifunc, TYifunc, -1, 0x64, 0, "memptr", TYmemptr, TYmemptr, TYmemptr, -1, 0, 0, "ident", TYident, TYident, TYident, -1, 0, 0, "template", TYtemplate, TYtemplate, TYtemplate, -1, 0, 0, "vtshape", TYvtshape, TYvtshape, TYvtshape, -1, 0, 0, }; FILE *f; static unsigned tytab[64 * 4]; static tym_t tytouns[64 * 4]; static tym_t _tyrelax[TYMAX]; static tym_t _tyequiv[TYMAX]; static signed char _tysize[64 * 4]; static const char *tystring[TYMAX]; static unsigned char dttab[TYMAX]; static unsigned short dttab4[TYMAX]; int i; #define T1(arr,mask) for (i=0; i<arraysize(arr); i++) \ { tytab[arr[i]] |= mask; \ }; #define T2(arr,mask) for (i=0; i<arraysize(arr); i++) \ { tytab[arr[i]] |= mask; \ }; T1(_ptr, TYFLptr); T1(_ptr_nflat,TYFLptr); T1(_real, TYFLreal); T1(_integral, TYFLintegral); T1(_imaginary,TYFLimaginary); T1(_complex, TYFLcomplex); T1(_uns, TYFLuns); T1(_mptr, TYFLmptr); T1(_fv, TYFLfv); T2(_farfunc, TYFLfarfunc); T2(_pasfunc, TYFLpascal); T2(_revfunc, TYFLrevparam); T2(_short, TYFLshort); T2(_aggregate,TYFLaggregate); T2(_ref, TYFLref); T2(_func, TYFLfunc); T2(_nullptr, TYFLnullptr); T2(_pasfunc_nf, TYFLpascal); T2(_revfunc_nf, TYFLrevparam); T2(_ref_nflat, TYFLref); T2(_func_nflat, TYFLfunc); T1(_xmmreg, TYFLxmmreg); T1(_simd, TYFLsimd); #undef T1 #undef T2 f = fopen("tytab.c","w"); fprintf(f,"unsigned tytab[] =\n{ "); for (i = 0; i < arraysize(tytab); i++) { fprintf(f,"0x%02x,",tytab[i]); if ((i & 7) == 7 && i < arraysize(tytab) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); #if 0 fprintf(f,"unsigned char tytab2[] =\n{ "); for (i = 0; i < arraysize(tytab2); i++) { fprintf(f,"0x%02x,",tytab2[i]); if ((i & 7) == 7 && i < arraysize(tytab2) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); #endif for (i = 0; i < arraysize(typetab); i++) { tytouns[typetab[i].ty] = typetab[i].unsty; } fprintf(f,"tym_t tytouns[] =\n{ "); for (i = 0; i < arraysize(tytouns); i++) { fprintf(f,"0x%02x,",tytouns[i]); if ((i & 7) == 7 && i < arraysize(tytouns) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); for (i = 0; i < arraysize(typetab); i++) { _tysize[typetab[i].ty | 0x00] = typetab[i].size; /*printf("_tysize[%d] = %d\n",typetab[i].ty,typetab[i].size);*/ } fprintf(f,"signed char _tysize[] =\n{ "); for (i = 0; i < arraysize(_tysize); i++) { fprintf(f,"%d,",_tysize[i]); if ((i & 7) == 7 && i < arraysize(_tysize) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); for (i = 0; i < arraysize(_tysize); i++) _tysize[i] = 0; for (i = 0; i < arraysize(typetab); i++) { signed char sz = typetab[i].size; switch (typetab[i].ty) { case TYldouble: case TYildouble: case TYcldouble: #if TARGET_OSX sz = 16; #elif TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS sz = 4; #elif TARGET_WINDOS sz = 2; #else #error "fix this" #endif break; case TYcent: case TYucent: sz = 8; break; } _tysize[typetab[i].ty | 0x00] = sz; /*printf("_tyalignsize[%d] = %d\n",typetab[i].ty,typetab[i].size);*/ } fprintf(f,"signed char _tyalignsize[] =\n{ "); for (i = 0; i < arraysize(_tysize); i++) { fprintf(f,"%d,",_tysize[i]); if ((i & 7) == 7 && i < arraysize(_tysize) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); for (i = 0; i < arraysize(typetab); i++) { _tyrelax[typetab[i].ty] = typetab[i].relty; /*printf("_tyrelax[%d] = %d\n",typetab[i].ty,typetab[i].relty);*/ } fprintf(f,"unsigned char _tyrelax[] =\n{ "); for (i = 0; i < arraysize(_tyrelax); i++) { fprintf(f,"0x%02x,",_tyrelax[i]); if ((i & 7) == 7 && i < arraysize(_tyrelax) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); /********** tyequiv[] ************/ for (i = 0; i < arraysize(_tyequiv); i++) _tyequiv[i] = i; _tyequiv[TYchar] = TYschar; /* chars are signed by default */ // These values are adjusted in util_set32() for 32 bit ints _tyequiv[TYint] = TYshort; _tyequiv[TYuint] = TYushort; fprintf(f,"unsigned char tyequiv[] =\n{ "); for (i = 0; i < arraysize(_tyequiv); i++) { fprintf(f,"0x%02x,",_tyequiv[i]); if ((i & 7) == 7 && i < arraysize(_tyequiv) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); for (i = 0; i < arraysize(typetab); i++) tystring[typetab[i].ty] = typetab[i].string; fprintf(f,"extern \"C\" { const char *tystring[] =\n{ "); for (i = 0; i < arraysize(tystring); i++) { fprintf(f,"\"%s\",",tystring[i]); if ((i & 7) == 7 && i < arraysize(tystring) - 1) fprintf(f,"\n "); } fprintf(f,"\n}; }\n"); for (i = 0; i < arraysize(typetab); i++) dttab[typetab[i].ty] = typetab[i].debtyp; fprintf(f,"unsigned char dttab[] =\n{ "); for (i = 0; i < arraysize(dttab); i++) { fprintf(f,"0x%02x,",dttab[i]); if ((i & 7) == 7 && i < arraysize(dttab) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); for (i = 0; i < arraysize(typetab); i++) dttab4[typetab[i].ty] = typetab[i].debtyp4; fprintf(f,"unsigned short dttab4[] =\n{ "); for (i = 0; i < arraysize(dttab4); i++) { fprintf(f,"0x%02x,",dttab4[i]); if ((i & 7) == 7 && i < arraysize(dttab4) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); fclose(f); }
inline void check_result(T2) { T1 a = T1(); T2 b = T2(); return check_result_imp(a, b); }
/***************************************************************************//** * Parallel application of Q using tile V - QR factorization (reduction Householder) * - dynamic scheduling **/ void plasma_pcunmqrrh_quark(PLASMA_enum side, PLASMA_enum trans, PLASMA_desc A, PLASMA_desc B, PLASMA_desc T, int BS, PLASMA_sequence *sequence, PLASMA_request *request) { plasma_context_t *plasma; Quark_Task_Flags task_flags = Quark_Task_Flags_Initializer; int k, m, n; int K, M, RD, lastRD; int ldaM, ldam, ldan, ldaMRD; int ldbM, ldbm, ldbMRD; int tempMm, tempkn, tempnn, tempmm, tempMRDm, tempkmin; int ib; plasma = plasma_context_self(); if (sequence->status != PLASMA_SUCCESS) return; QUARK_Task_Flag_Set(&task_flags, TASK_SEQUENCE, (intptr_t)sequence->quark_sequence); ib = PLASMA_IB; K = min(A.mt, A.nt); if (side == PlasmaLeft ) { if (trans == PlasmaConjTrans) { /* * PlasmaLeft / PlasmaConjTrans */ for (k = 0; k < K; k++) { tempkn = k == A.nt-1 ? A.n-k*A.nb : A.nb; for (M = k; M < A.mt-1 || M == k; /* No bottom single-row subdomain */ M += BS) { tempMm = M == A.mt-1 ? A.m-M*A.mb : A.mb; tempkmin = min(tempMm, tempkn); ldaM = BLKLDD(A, M); ldbM = BLKLDD(B, M); for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_cunmqr( plasma->quark, &task_flags, side, trans, tempMm, tempnn, tempkmin, ib, T.nb, A(M, k), ldaM, T(M, k), T.mb, B(M, n), ldbM); } for (m = M+1; (m < M+BS && m < A.mt) || m == A.mt-1; /* Suck in bottom single-row domain */ m++) { tempmm = m == A.mt-1 ? A.m-m*A.mb : A.mb; ldbm = BLKLDD(B, m); ldam = BLKLDD(A, m); for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_ctsmqr( plasma->quark, &task_flags, side, trans, A.nb, tempnn, tempmm, tempnn, tempkn, ib, T.nb, B(M, n), ldbM, B(m, n), ldbm, A(m, k), ldam, T(m, k), T.mb); } } } for (RD = BS; RD < A.mt-k; RD *= 2) { for (M = k; M+RD < A.mt-1; /* No reduction with bottom single-row subdomain */ M += 2*RD) { tempMRDm = M+RD == A.mt-1 ? A.m-(M+RD)*A.mb : A.mb; ldbM = BLKLDD(B, M ); ldbMRD = BLKLDD(B, M+RD); ldaMRD = BLKLDD(A, M+RD); for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_cttmqr( plasma->quark, &task_flags, side, trans, A.nb, tempnn, tempMRDm, tempnn, tempkn, ib, T.nb, B (M, n), ldbM, B (M+RD, n), ldbMRD, A (M+RD, k), ldaMRD, T2(M+RD, k), T.mb); } } } } } else { /* * PlasmaLeft / PlasmaNoTrans */ for (k = K-1; k >= 0; k--) { tempkn = k == A.nt-1 ? A.n-k*A.nb : A.nb; lastRD = 0; for (RD = BS; RD < A.mt-k; RD *= 2) lastRD = RD; for (RD = lastRD; RD >= BS; RD /= 2) { for (M = k; M+RD < A.mt-1; /* No reduction with bottom single-row subdomain */ M += 2*RD) { tempMRDm = M+RD == A.mt-1 ? A.m-(M+RD)*A.mb : A.mb; ldbM = BLKLDD(B, M ); ldbMRD = BLKLDD(B, M+RD); ldaMRD = BLKLDD(A, M+RD); for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_cttmqr( plasma->quark, &task_flags, side, trans, A.nb, tempnn, tempMRDm, tempnn, tempkn, ib, T.nb, B (M, n), ldbM, B (M+RD, n), ldbMRD, A (M+RD, k), ldaMRD, T2(M+RD, k), T.mb); } } } for (M = k; M < A.mt-1 || M == k; /* No bottom single-row subdomain */ M += BS) { tempMm = M == A.mt-1 ? A.m-M*A.mb : A.mb; tempkmin = min(tempMm, tempkn); ldaM = BLKLDD(A, M); ldbM = BLKLDD(B, M); for (m = M+BS-1 == A.mt-2 ? A.mt-1 : min(M+BS-1, A.mt-1); /* Suck in bottom single-row domain */ m >= M+1; m--) { tempmm = m == A.mt-1 ? A.m-m*A.mb : A.mb; ldbm = BLKLDD(B, m); ldam = BLKLDD(A, m); for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_ctsmqr( plasma->quark, &task_flags, side, trans, A.nb, tempnn, tempmm, tempnn, tempkn, ib, T.nb, B(M, n), ldbM, B(m, n), ldbm, A(m, k), ldam, T(m, k), T.mb); } } for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_cunmqr( plasma->quark, &task_flags, side, trans, tempMm, tempnn, tempkmin, ib, T.nb, A(M, k), ldaM, T(M, k), T.mb, B(M, n), ldbM); } } } } } else { if (trans == PlasmaConjTrans) { /* * PlasmaRight / PlasmaConjTrans */ for (k = K-1; k >= 0; k--) { tempkn = k == A.nt-1 ? A.n-k*A.nb : A.nb; lastRD = 0; for (RD = BS; RD < A.mt-k; RD *= 2) lastRD = RD; for (RD = lastRD; RD >= BS; RD /= 2) { for (M = k; M+RD < A.mt-1; /* No reduction with bottom single-row subdomain */ M += 2*RD) { tempMRDm = M+RD == A.mt-1 ? A.m-(M+RD)*A.mb : A.mb; ldaMRD = BLKLDD(A, M+RD); for (m = 0; m < B.mt; m++) { ldbm = BLKLDD(B, m); tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; QUARK_CORE_cttmqr( plasma->quark, &task_flags, side, trans, tempmm, B.nb, tempmm, tempMRDm, tempkn, ib, T.nb, B (m, M), ldbm, B (m, M+RD), ldbm, A (M+RD, k), ldaMRD, T2(M+RD, k), T.mb); } } } for (M = k; M < A.mt-1 || M == k; /* No bottom single-row subdomain */ M += BS) { tempMm = M == A.mt-1 ? A.m-M*A.mb : A.mb; tempkmin = min(tempMm, tempkn); ldaM = BLKLDD(A, M); ldbM = BLKLDD(B, M); for (n = M+BS-1 == A.mt-2 ? A.mt-1 : min(M+BS-1, A.mt-1); /* Suck in bottom single-row domain */ n >= M+1; n--) { ldan = BLKLDD(A, n); tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; for (m = 0; m < B.mt; m++) { ldbm = BLKLDD(B, m); tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; QUARK_CORE_ctsmqr( plasma->quark, &task_flags, side, trans, tempmm, tempMm, tempmm, tempnn, tempkn, ib, T.nb, B(m, M), ldbm, B(m, n), ldbm, A(n, k), ldan, T(n, k), T.mb); } } for (m = 0; m < B.mt; m++) { ldbm = BLKLDD(B, m); tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; QUARK_CORE_cunmqr( plasma->quark, &task_flags, side, trans, tempmm, tempMm, tempkmin, ib, T.nb, A(M, k), ldaM, T(M, k), T.mb, B(m, M), ldbm); } } } } else { /* * PlasmaRight / PlasmaNoTrans */ for (k = 0; k < K; k++) { tempkn = k == A.nt-1 ? A.n-k*A.nb : A.nb; for (M = k; M < A.mt-1 || M == k; /* No bottom single-row subdomain */ M += BS) { tempMm = M == A.mt-1 ? A.m-M*A.mb : A.mb; tempkmin = min(tempMm, tempkn); ldaM = BLKLDD(A, M); for (m = 0; m < B.mt; m++) { ldbm = BLKLDD(B, m); tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; QUARK_CORE_cunmqr( plasma->quark, &task_flags, side, trans, tempmm, tempMm, tempkmin, ib, T.nb, A(M, k), ldaM, T(M, k), T.mb, B(m, M), ldbm); } for (n = M+1; (n < M+BS && n < A.mt) || n == A.mt-1; /* Suck in bottom single-row domain */ n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; ldan = BLKLDD(A, n); for (m = 0; m < B.mt; m++) { tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; ldbm = BLKLDD(B, m); QUARK_CORE_ctsmqr( plasma->quark, &task_flags, side, trans, tempmm, tempMm, tempmm, tempnn, tempkn, ib, T.nb, B(m, M), ldbm, B(m, n), ldbm, A(n, k), ldan, T(n, k), T.mb); } } } for (RD = BS; RD < A.mt-k; RD *= 2) { for (M = k; M+RD < A.mt-1; /* No reduction with bottom single-row subdomain */ M += 2*RD) { tempMRDm = M+RD == A.mt-1 ? A.m-(M+RD)*A.mb : A.mb; ldaMRD = BLKLDD(A, M+RD); for (m = 0; m < B.mt; m++) { tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; ldbm = BLKLDD(B, m); QUARK_CORE_cttmqr( plasma->quark, &task_flags, side, trans, tempmm, B.nb, tempmm, tempMRDm, tempkn, ib, T.nb, B (m, M ), ldbm, B (m, M+RD), ldbm, A (M+RD, k), ldaMRD, T2(M+RD, k), T.mb); } } } } } } }
Pair() : first(T1()),second(T2()) {}
static SECStatus rijndael_encryptBlock128(AESContext *cx, unsigned char *output, const unsigned char *input) { unsigned int r; PRUint32 *roundkeyw; rijndael_state state; PRUint32 C0, C1, C2, C3; #if defined(NSS_X86_OR_X64) #define pIn input #define pOut output #else unsigned char *pIn, *pOut; PRUint32 inBuf[4], outBuf[4]; if ((ptrdiff_t)input & 0x3) { memcpy(inBuf, input, sizeof inBuf); pIn = (unsigned char *)inBuf; } else { pIn = (unsigned char *)input; } if ((ptrdiff_t)output & 0x3) { pOut = (unsigned char *)outBuf; } else { pOut = (unsigned char *)output; } #endif roundkeyw = cx->expandedKey; /* Step 1: Add Round Key 0 to initial state */ COLUMN_0(state) = *((PRUint32 *)(pIn )) ^ *roundkeyw++; COLUMN_1(state) = *((PRUint32 *)(pIn + 4 )) ^ *roundkeyw++; COLUMN_2(state) = *((PRUint32 *)(pIn + 8 )) ^ *roundkeyw++; COLUMN_3(state) = *((PRUint32 *)(pIn + 12)) ^ *roundkeyw++; /* Step 2: Loop over rounds [1..NR-1] */ for (r=1; r<cx->Nr; ++r) { /* Do ShiftRow, ByteSub, and MixColumn all at once */ C0 = T0(STATE_BYTE(0)) ^ T1(STATE_BYTE(5)) ^ T2(STATE_BYTE(10)) ^ T3(STATE_BYTE(15)); C1 = T0(STATE_BYTE(4)) ^ T1(STATE_BYTE(9)) ^ T2(STATE_BYTE(14)) ^ T3(STATE_BYTE(3)); C2 = T0(STATE_BYTE(8)) ^ T1(STATE_BYTE(13)) ^ T2(STATE_BYTE(2)) ^ T3(STATE_BYTE(7)); C3 = T0(STATE_BYTE(12)) ^ T1(STATE_BYTE(1)) ^ T2(STATE_BYTE(6)) ^ T3(STATE_BYTE(11)); /* Round key addition */ COLUMN_0(state) = C0 ^ *roundkeyw++; COLUMN_1(state) = C1 ^ *roundkeyw++; COLUMN_2(state) = C2 ^ *roundkeyw++; COLUMN_3(state) = C3 ^ *roundkeyw++; } /* Step 3: Do the last round */ /* Final round does not employ MixColumn */ C0 = ((BYTE0WORD(T2(STATE_BYTE(0)))) | (BYTE1WORD(T3(STATE_BYTE(5)))) | (BYTE2WORD(T0(STATE_BYTE(10)))) | (BYTE3WORD(T1(STATE_BYTE(15))))) ^ *roundkeyw++; C1 = ((BYTE0WORD(T2(STATE_BYTE(4)))) | (BYTE1WORD(T3(STATE_BYTE(9)))) | (BYTE2WORD(T0(STATE_BYTE(14)))) | (BYTE3WORD(T1(STATE_BYTE(3))))) ^ *roundkeyw++; C2 = ((BYTE0WORD(T2(STATE_BYTE(8)))) | (BYTE1WORD(T3(STATE_BYTE(13)))) | (BYTE2WORD(T0(STATE_BYTE(2)))) | (BYTE3WORD(T1(STATE_BYTE(7))))) ^ *roundkeyw++; C3 = ((BYTE0WORD(T2(STATE_BYTE(12)))) | (BYTE1WORD(T3(STATE_BYTE(1)))) | (BYTE2WORD(T0(STATE_BYTE(6)))) | (BYTE3WORD(T1(STATE_BYTE(11))))) ^ *roundkeyw++; *((PRUint32 *) pOut ) = C0; *((PRUint32 *)(pOut + 4)) = C1; *((PRUint32 *)(pOut + 8)) = C2; *((PRUint32 *)(pOut + 12)) = C3; #if defined(NSS_X86_OR_X64) #undef pIn #undef pOut #else if ((ptrdiff_t)output & 0x3) { memcpy(output, outBuf, sizeof outBuf); } #endif return SECSuccess; }
inline bool haveSameSign(const T1 theVal1, const T2 theVal2) { return (theVal1 >= T1(0) && theVal2 > T2(0)) || (theVal1 <= T1(0) && theVal2 < T2(0)); }
/***************************************************************************//** * Parallel application of Q using tile V - LQ factorization (reduction * Householder) - dynamic scheduling **/ void plasma_pzunmlqrh_quark(PLASMA_enum side, PLASMA_enum trans, PLASMA_desc A, PLASMA_desc B, PLASMA_desc T, int BS, PLASMA_sequence *sequence, PLASMA_request *request) { plasma_context_t *plasma; Quark_Task_Flags task_flags = Quark_Task_Flags_Initializer; int k, m, n; int K, N, RD, lastRD; int ldaN, ldak; int ldbN, ldbm, ldbNRD; int tempNn, tempkm, tempnn, tempmm, tempNRDn, tempkmin; int ib; plasma = plasma_context_self(); if (sequence->status != PLASMA_SUCCESS) return; QUARK_Task_Flag_Set(&task_flags, TASK_SEQUENCE, (intptr_t)sequence->quark_sequence); ib = PLASMA_IB; K = min(A.mt, A.nt); if (side == PlasmaLeft ) { if (trans == PlasmaNoTrans) { /* * PlasmaLeft / PlasmaNoTrans */ for (k = 0; k < K; k++) { tempkm = k == A.mt-1 ? A.m-k*A.mb : A.mb; ldak = BLKLDD(A, k); for (N = k; N < A.nt; N += BS) { tempNn = N == A.nt-1 ? A.n-N*A.nb : A.nb; tempkmin = min(tempkm,tempNn); ldaN = BLKLDD(A, N); ldbN = BLKLDD(B, N); for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_zunmlq( plasma->quark, &task_flags, side, trans, tempNn, tempnn, tempkmin, ib, T.nb, A(k, N), ldak, T(k, N), T.mb, B(N, n), ldbN); } for (m = N+1; m < min(N+BS, A.nt); m++) { tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; ldbm = BLKLDD(B, m); for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_ztsmlq( plasma->quark, &task_flags, side, trans, B.nb, tempnn, tempmm, tempnn, tempkm, ib, T.nb, B(N, n), ldbN, B(m, n), ldbm, A(k, m), ldak, T(k, m), T.mb); } } } for (RD = BS; RD < A.nt-k; RD *= 2) { for (N = k; N+RD < A.nt; N += 2*RD) { tempNRDn = N+RD == A.nt-1 ? A.n-(N+RD)*A.nb : A.nb; ldbN = BLKLDD(B, N ); ldbNRD = BLKLDD(B, N+RD); for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_zttmlq( plasma->quark, &task_flags, side, trans, B.mb, tempnn, tempNRDn, tempnn, tempkm, ib, T.nb, B (N, n), ldbN, B (N+RD, n), ldbNRD, A (k, N+RD), ldak, T2(k, N+RD), T.mb); } } } } } else { /* * PlasmaLeft / PlasmaConjTrans */ for (k = K-1; k >= 0; k--) { tempkm = k == A.mt-1 ? A.m-k*A.mb : A.mb; ldak = BLKLDD(A, k); lastRD = 0; for (RD = BS; RD < A.nt-k; RD *= 2) lastRD = RD; for (RD = lastRD; RD >= BS; RD /= 2) { for (N = k; N+RD < A.nt; N += 2*RD) { tempNRDn = N+RD == A.nt-1 ? A.n-(N+RD)*A.nb : A.nb; ldbN = BLKLDD(B, N ); ldbNRD = BLKLDD(B, N+RD); for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_zttmlq( plasma->quark, &task_flags, side, trans, B.nb, tempnn, tempNRDn, tempnn, tempkm, ib, T.nb, B (N, n), ldbN, B (N+RD, n), ldbNRD, A (k, N+RD), ldak, T2(k, N+RD), T.mb); } } } for (N = k; N < A.nt; N += BS) { tempNn = N == A.nt-1 ? A.n-N*A.nb : A.nb; tempkmin = min(tempkm,tempNn); ldaN = BLKLDD(A, N); ldbN = BLKLDD(B, N); for (m = min(N+BS, A.nt)-1; m > N; m--) { tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; ldbm = BLKLDD(B, m); for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_ztsmlq( plasma->quark, &task_flags, side, trans, B.mb, tempnn, tempmm, tempnn, tempkm, ib, T.nb, B(N, n), ldbN, B(m, n), ldbm, A(k, m), ldak, T(k, m), T.mb); } } for (n = 0; n < B.nt; n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; QUARK_CORE_zunmlq( plasma->quark, &task_flags, side, trans, tempNn, tempnn, tempkmin, ib, T.nb, A(k, N), ldak, T(k, N), T.mb, B(N, n), ldbN); } } } } } else { if (trans == PlasmaNoTrans) { /* * PlasmaRight / PlasmaNoTrans */ for (k = K-1; k >= 0; k--) { tempkm = k == A.mt-1 ? A.m-k*A.mb : A.mb; ldak = BLKLDD(A, k); lastRD = 0; for (RD = BS; RD < A.nt-k; RD *= 2) lastRD = RD; for (RD = lastRD; RD >= BS; RD /= 2) { for (N = k; N+RD < A.nt; N += 2*RD) { tempNRDn = N+RD == A.nt-1 ? A.n-(N+RD)*A.nb : A.nb; for (m = 0; m < B.mt; m++) { ldbm = BLKLDD(B, m); tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; QUARK_CORE_zttmlq( plasma->quark, &task_flags, side, trans, tempmm, B.nb, tempmm, tempNRDn, tempkm, ib, T.nb, B (m, N ), ldbm, B (m, N+RD), ldbm, A (k, N+RD), ldak, T2(k, N+RD), T.mb); } } } for (N = k; N < A.nt; N += BS) { tempNn = N == A.nt-1 ? A.n-N*A.nb : A.nb; tempkmin = min(tempkm,tempNn); for (n = min(N+BS, A.nt)-1; n > N; n--) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; for (m = 0; m < B.mt; m++) { tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; ldbm = BLKLDD(B, m); QUARK_CORE_ztsmlq( plasma->quark, &task_flags, side, trans, tempmm, B.nb, tempmm, tempnn, tempkm, ib, T.nb, B(m, N), ldbm, B(m, n), ldbm, A(k, n), ldak, T(k, n), T.mb); } } for (m = 0; m < B.mt; m++) { tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; ldbm = BLKLDD(B, m); QUARK_CORE_zunmlq( plasma->quark, &task_flags, side, trans, tempmm, tempNn, tempkmin, ib, T.nb, A(k, N), ldak, T(k, N), T.mb, B(m, N), ldbm); } } } } else { /* * PlasmaRight / PlasmaConjTrans */ for (k = 0; k < K; k++) { tempkm = k == A.mt-1 ? A.m-k*A.mb : A.mb; ldak = BLKLDD(A, k); for (N = k; N < A.nt; N += BS) { tempNn = N == A.nt-1 ? A.n-N*A.nb : A.nb; tempkmin = min(tempkm,tempNn); ldaN = BLKLDD(A, N); for (m = 0; m < B.mt; m++) { ldbm = BLKLDD(B, m); tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; QUARK_CORE_zunmlq( plasma->quark, &task_flags, side, trans, tempmm, tempNn, tempkmin, ib, T.nb, A(k, N), ldaN, T(k, N), T.mb, B(m, N), ldbm); } for (n = N+1; n < min(N+BS, A.nt); n++) { tempnn = n == B.nt-1 ? B.n-n*B.nb : B.nb; for (m = 0; m < B.mt; m++) { tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; ldbm = BLKLDD(B, m); QUARK_CORE_ztsmlq( plasma->quark, &task_flags, side, trans, tempmm, tempNn, tempmm, tempnn, tempkm, ib, T.nb, B(m, N), ldbm, B(m, n), ldbm, A(k, n), ldak, T(k, n), T.mb); } } } for (RD = BS; RD < A.nt-k; RD *= 2) { for (N = k; N+RD < A.nt; N += 2*RD) { tempNRDn = N+RD == A.nt-1 ? A.n-(N+RD)*A.nb : A.nb; for (m = 0; m < B.mt; m++) { tempmm = m == B.mt-1 ? B.m-m*B.mb : B.mb; ldbm = BLKLDD(B, m); QUARK_CORE_zttmlq( plasma->quark, &task_flags, side, trans, tempmm, B.nb, tempmm, tempNRDn, tempkm, ib, T.nb, B (m, N ), ldbm, B (m, N+RD), ldbm, A (k, N+RD), ldak, T2(k, N+RD), T.mb); } } } } } } }
int main() { vcg::Point3d p1(20.0, 25.0, 10.0); vcg::Point3d p2(-6.0, 25.0, 50.0); vcg::Shotd shot1; vcg::Shotd shot2; // Initialize camera 1 (C1) shot1.Intrinsics.cameraType = vcg::Camera<double>::PERSPECTIVE; shot1.Intrinsics.FocalMm = 30.0; shot1.Intrinsics.CenterPx[0] = 600.0; shot1.Intrinsics.CenterPx[1] = 400.0; shot1.Intrinsics.ViewportPx[0] = 1200; shot1.Intrinsics.ViewportPx[1] = 800; shot1.Intrinsics.PixelSizeMm[0] = 0.029166; shot1.Intrinsics.PixelSizeMm[1] = 0.029166; // no distorion is assumed (!) shot1.Intrinsics.DistorCenterPx[0] = shot1.Intrinsics.DistorCenterPx[1] = 0.0; shot1.Intrinsics.k[0] = 0.0; shot1.Intrinsics.k[1] = 0.0; shot1.Intrinsics.k[2] = 0.0; shot1.Intrinsics.k[3] = 0.0; vcg::Matrix44d R1; // -10 degree around Y axis double deg2rad = 0.01745329251994329576923690768489; R1.ElementAt(0,0) = vcg::math::Cos(-10.0*deg2rad); R1.ElementAt(0,1) = 0.0; R1.ElementAt(0,2) = vcg::math::Sin(-10.0*deg2rad); R1.ElementAt(0,3) = 0.0; R1.ElementAt(1,0) = 0.0; R1.ElementAt(1,1) = 1.0; R1.ElementAt(1,2) = 0.0; R1.ElementAt(1,3) = 0.0; R1.ElementAt(2,0) = -vcg::math::Sin(-10.0*deg2rad); R1.ElementAt(2,1) = 0.0; R1.ElementAt(2,2) = vcg::math::Cos(-10.0*deg2rad); R1.ElementAt(2,3) = 0.0; R1.ElementAt(3,0) = 0.0; R1.ElementAt(3,1) = 0.0; R1.ElementAt(3,2) = 0.0; R1.ElementAt(3,3) = 1.0; vcg::Point3d T1(30.0, 30.0, 80.0); shot1.Extrinsics.SetTra(T1); shot1.Extrinsics.SetRot(R1); // Initialize camera 2 (C2) shot2.Intrinsics.cameraType = vcg::Camera<double>::PERSPECTIVE; shot2.Intrinsics.FocalMm = 30.0; shot2.Intrinsics.CenterPx[0] = 600.0; shot2.Intrinsics.CenterPx[1] = 400.0; shot2.Intrinsics.ViewportPx[0] = 1200; shot2.Intrinsics.ViewportPx[1] = 800; shot2.Intrinsics.PixelSizeMm[0] = 0.029166; shot2.Intrinsics.PixelSizeMm[1] = 0.029166; // no distortion is assumed (!) shot2.Intrinsics.DistorCenterPx[0] = shot2.Intrinsics.DistorCenterPx[1] = 0.0; shot2.Intrinsics.k[0] = 0.0; shot2.Intrinsics.k[1] = 0.0; shot2.Intrinsics.k[2] = 0.0; shot2.Intrinsics.k[3] = 0.0; vcg::Matrix44d R2; // 18 degree around Y axis (+ 180 degree for the correct orientation of the camera) R2.ElementAt(0,0) = vcg::math::Cos(-45.0*deg2rad); R2.ElementAt(0,1) = 0.0; R2.ElementAt(0,2) = vcg::math::Sin(-45.0*deg2rad); R2.ElementAt(0,3) = 0.0; R2.ElementAt(1,0) = 0.0; R2.ElementAt(1,1) = 1.0; R2.ElementAt(1,2) = 0.0; R2.ElementAt(1,3) = 0.0; R2.ElementAt(2,0) = -vcg::math::Sin(-45.0*deg2rad); R2.ElementAt(2,1) = 0.0; R2.ElementAt(2,2) = vcg::math::Cos(-45.0*deg2rad); R2.ElementAt(2,3) = 0.0; R2.ElementAt(3,0) = 0.0; R2.ElementAt(3,1) = 0.0; R2.ElementAt(3,2) = 0.0; R2.ElementAt(3,3) = 1.0; vcg::Point3d T2(50.0, 30.0, 80.0); shot2.Extrinsics.SetTra(T2); shot2.Extrinsics.SetRot(R2); // TEST 1 - project a 3D point in World coordinates on the image plane if (test1(shot1, shot2, p1, p2)) { std::cout << "TEST 1 (projection) - PASSED(!)" << std::endl; } else std::cout << "TEST 1 (projection) - FAILED(!)" << std::endl; // TEST 2 - projection and unprojection if (test2(shot1, shot2, p1, p2)) { std::cout << "TEST 2 (unprojection) - PASSED(!)" << std::endl; } else { std::cout << "TEST 2 (unprojection) - FAILED(!)" << std::endl; } // TEST 3 - DEPTH COMPUTATION if (test3(shot1, shot2, p1, p2)) { std::cout << "TEST 3 (depth computation) - PASSED(!)" << std::endl; } else { std::cout << "TEST 3 (depth computation) - FAILED(!)" << std::endl; } // TEST 4 - CAMERA CONVERSION - CONVERT FOCAL IN PIXELS IN FOCAL IN MM if (test4(shot1, p1)) { std::cout << "TEST 4 (focal in px to focal in mm) - PASSED(!)" << std::endl; } else { std::cout << "TEST 4 (focal in px to focal in mm) - FAILED(!)" << std::endl; } // TEST 5 - CAMERA-SHOT MODIFICATION - CHANGE SCALE FACTOR OF THE WORLD if (test5(shot1, p1, p2)) { std::cout << "TEST 5 (scaling the World) - PASSED(!)" << std::endl; } else { std::cout << "TEST 5 (scaling the World) - FAILED(!)" << std::endl; } // TEST 6 - WORLD-TO-EXTRINSICS AND EXTRINSICS-TO-WORLD TRANSFORMATIONS if (test6(shot1, shot2, p1, p2)) { std::cout << "TEST 6 (World-to-Extrinsics and Extrinsics-to-World) - PASSED(!)" << std::endl; } else { std::cout << "TEST 6 (World-to-Extrinsics and Extrinsics-to-World) - FAILE(!)" << std::endl; } // TEST 7 - SHOT MODIFICATION - ROTO-TRANSLATION OF THE SHOT COORDINATES SYSTEM if (test7(shot1, p1, p2)) { std::cout << "TEST 7 (roto-translation of the Shot coordinates system) - PASSED(!)" << std::endl; } else { std::cout << "TEST 7 (roto-translation of the Shot coordinates system) - FAILED(!)" << std::endl; } // TEST 7 - SHOT MODIFICATION - ROTO-TRANSLATION OF THE SHOT COORDINATES SYSTEM if (test8(shot1, shot2, p1, p2)) { std::cout << "TEST 8 (roto-translation of the Shot coordinates system) - PASSED(!)" << std::endl; } else { std::cout << "TEST 8 (roto-translation of the Shot coordinates system) - FAILED(!)" << std::endl; } // TEST 9 - SHOT MODIFICATION - ROTO-TRANSLATION OF THE SHOT COORDINATES SYSTEM if (test9(shot1, shot2, p1, p2)) { std::cout << "TEST 9 (roto-translation of the Shot coordinates system) - PASSED(!)" << std::endl; } else { std::cout << "TEST 9 (roto-translation of the Shot coordinates system) - FAILED(!)" << std::endl; } // TEST 10 - SHOT MODIFICATION - SIMILARITY TRANSFORMATION if (test10(shot1, shot2, p1, p2)) { std::cout << "TEST 10 (similarity transform of the Shot coordinates system) - PASSED(!)" << std::endl; } else { std::cout << "TEST 10 (similarity transform of the Shot coordinates system) - FAILED(!)" << std::endl; } return 0; }
void ZeroLengthContact3D::formResidAndTangent( int tang_flag ) { // trial displacement vectors Vector DispTrialS(3); // trial disp for slave node Vector DispTrialM(3); // trial disp for master node // trial frictional force vectors (in local coordinate) Vector t_trial(2); double TtrNorm; // Coulomb friction law surface double Phi; int i, j; //zero stiffness and residual stiff.Zero( ) ; resid.Zero( ) ; // detect contact and set flag ContactFlag = contactDetect(); //opserr<<this->getTag()<< " ZeroLengthContact3D::ContactFlag=" << ContactFlag<<endln; if (ContactFlag == 1) // contacted { // contact presure; pressure = Kn*gap; // Kn : normal penalty DispTrialS=nodePointers[0]->getTrialDisp(); DispTrialM=nodePointers[1]->getTrialDisp(); //nodal displacements double ul[6]; ul[0]=DispTrialS(0); ul[1]=DispTrialS(1); ul[2]=DispTrialS(2); ul[3]=DispTrialM(0); ul[4]=DispTrialM(1); ul[5]=DispTrialM(2); t_trial.Zero(); xi.Zero(); for (i=0; i<6; i++){ xi(0) += T1(i)*ul[i]; xi(1) += T2(i)*ul[i]; } // Compute trial shear force for (i=0; i<2; i++) t_trial(i)=Kt * (xi(i)-stickPt(i)); //Kt: tangential penalty TtrNorm=t_trial.Norm(); // Coulomb friction law, trial state Phi = TtrNorm - (fs * pressure + cohesion); // add cohesion if (Phi <= 0 ) { // stick case //opserr<< "stick ...." << endln; if ( tang_flag == 1 ) { // stiff for (i=0; i<6; i++) { for (j=0; j<6; j++) { stiff(i,j) = Kn*(N(i)*N(j)) + Kt*(T1(i)*T1(j)+T2(i)*T2(j)); } } } //endif tang_flag // force for (i=0; i<6; i++) resid(i)= (-1*pressure)*N(i) + t_trial(0)*T1(i) + t_trial(1)*T2(i) ; // resid(i)= (-1*pressure)*N(i) - t_trial(0)*T1(i) - t_trial(1)*T2(i) ; } // end if stick else { // slide case, non-symmetric stiff ContactFlag=2; // set the contactFlag for sliding // opserr<< "sliding ...." << endln; if ( tang_flag == 1 ) { // stiff double Pt1, Pt2; Pt1=t_trial(0)/TtrNorm; Pt2=t_trial(1)/TtrNorm; double C1=fs*Kn; double C2=Kt*(fs*pressure+cohesion)/TtrNorm; // add cohesion, sept. 7, 2005 for (i=0; i<6; i++) { for (j=0; j<6; j++) { stiff(i,j) = Kn*(N(i)*N(j)) - C1*(Pt1*T1(i)*N(j)+Pt2*T2(i)*N(j)) + C2*( (1-Pt1*Pt1)*T1(i)*T1(j) - Pt1*Pt2 *T1(i)*T2(j) - Pt1*Pt2 *T2(i)*T1(j) + (1-Pt1*Pt2)*T2(i)*T2(j) ); } //endfor i } //endfor j } // endif tang_flag // force double t1, t2; t1 = (fs*pressure+cohesion) * t_trial(0)/TtrNorm; // add cohesion t2 = (fs*pressure+cohesion) * t_trial(1)/TtrNorm; // add cohesion //opserr<<"gap=" << gap <<endln; //opserr<<"pressure= "<<pressure <<endln; for (i=0; i<6; i++) { resid(i) = (-1*pressure)*N(i)+t1*T1(i)+t2*T2(i) ; // resid(i) = (-1*pressure)*N(i)-t1*T1(i)-t2*T2(i) ; } } //endif slide } // endif ContactFlag // for NOT contact, do nothing, stiff and resid are zeroes }
inline T2 ModPowerOf2(const T1 &a, const T2 &b) { assert(IsPowerOf2(b)); return T2(a) & (b-1); }
// Private methods // determine the slave/master pair in contact, and setup Vectors (N,T1,T2) int ZeroLengthContact3D::contactDetect(void) { int transientgap; transientgap = 1; // 1: transient gap; 0: dynamic gap Vector slaveNd; Vector masterNd; //+--------------+-----------------+----------------+----------------+---------------+ // NOTES: some methods to get displacements from nodes //+--------------+-----------------+----------------+----------------+---------------+ // getDisp() : get commit(k-1) disp, will be commit(k) after commit // getTrialDisp(): get Trial(k) disp // getIncrDisp(): get Trial(k)-Commit(k-1), will be 0 after commit // getIncrDeltaDisp(): get Trial(k)-Trial(k-1), will be 0 after commit //+--------------+-----------------+----------------+----------------+---------------+ if (transientgap) { ///////////// for transient gap ////////////////////////// slaveNd = nodePointers[0]->getCrds() + nodePointers[0]->getTrialDisp(); masterNd= nodePointers[1]->getCrds() + nodePointers[1]->getTrialDisp(); } else { ///////////// for dynamic gap //////////////////////////// slaveNd = nodePointers[0]->getCrds() + nodePointers[0]->getIncrDisp(); masterNd= nodePointers[1]->getCrds() + nodePointers[1]->getIncrDisp(); } double Xs=slaveNd(0) - origin(0); double Ys=slaveNd(1) - origin(1); double Zs=slaveNd(2); double Rs=sqrt(Xs*Xs +Ys*Ys); double Xm=masterNd(0) - origin(0); double Ym=masterNd(1) - origin(1); double Zm=masterNd(2); double Rm=sqrt(Xm*Xm +Ym*Ym); switch (directionID) { case 0: // circular contact plane if (transientgap) { gap = Rs-Rm; } else { gap= gap_n + Rs - Rm; // dynamic gap } if (gap< 0) { // Not in contact return 0; } else { // contact occur, setup contact vectors N(0) = -Xm/Rm ; N(1) = -Ym/Rm ; N(2) = 0 ; N(3) = Xm/Rm ; N(4) = Ym/Rm ; N(5) = 0 ; T1(0) = 0; T1(1) = 0; T1(2) = 1; T1(3) = 0; T1(4) = 0; T1(5) = -1; T2(0) = -Ym/Rm ; T2(1) = Xm/Rm ; T2(2) = 0 ; T2(3) = Ym/Rm ; T2(4) = -Xm/Rm ; T2(5) = 0 ; return 1; } case 1: // normal of master plane pointing to +X direction if (transientgap) { gap= Xm -Xs; // transient gap } else { gap= gap_n + Xm - Xs; // dynamic gap } if (gap< 0) {// Not in contact return 0; } else { // contact occur, setup contact vectors N(0) = 1; N(1) = 0 ; N(2) = 0 ; N(3) = -1 ; N(4) = 0 ; N(5) = 0 ; T1(0) = 0; T1(1) = 1; T1(2) = 0; T1(3) = 0; T1(4) = -1; T1(5) = 0; T2(0) = 0 ; T2(1) = 0 ; T2(2) = 1 ; T2(3) = 0 ; T2(4) = 0 ; T2(5) = -1 ; return 1; } case 2: // normal of master plane pointing to +Y direction if (transientgap) { gap= Ym - Ys; // transient gap } else { gap= gap_n + Ym - Ys; // dynamic gap } if (gap<=0) { // Not in contact return 0; } else { // contact occur, setup contact vectors N(0) = 0; N(1) = 1 ; N(2) = 0 ; N(3) = 0 ; N(4) = -1 ; N(5) = 0 ; T1(0) = 0; T1(1) = 0; T1(2) = 1; T1(3) = 0; T1(4) = 0; T1(5) = -1; T2(0) = 1 ; T2(1) = 0 ; T2(2) = 0 ; T2(3) = -1 ; T2(4) = 0 ; T2(5) = 0 ; return 1; } case 3: // normal of master plane pointing to +Z direction // ___________ // | | // | slave | // |___________| // | | // | Master | // | | // ----------- // if (transientgap) { gap= Zm - Zs; // transient gap } else { gap= gap_n + Zm - Zs; // dynamic gap } if (gap < 0) // Not in contact return 0; else { N(0) = 0 ; N(1) = 0 ; N(2) = 1 ; N(3) = 0 ; N(4) = 0 ; N(5) = -1 ; T1(0) = 1; T1(1) = 0; T1(2) = 0; T1(3) = -1; T1(4) = 0; T1(5) = 0; T2(0) = 0 ; T2(1) = 1 ; T2(2) = 0 ; T2(3) = 0 ; T2(4) = -1 ; T2(5) = 0 ; return 1; } default: opserr << "ERROR!!!! ZeroLengthContact3D::ZeroLengthContact3D - the only available contact directions are 0,1,2,3\n"; return -1; } // end switch directionID }
/// @brief /// Main evaluation routine. Computes the inverse of the /// matrix representation of the mimetic inner product in a /// single cell with kown permeability @f$K@f$. Adds a /// regularization term in order to guarantee a positive /// definite matrix. /// /// @tparam RockInterface /// Type representing rock properties. Assumed to /// expose a method @code permeability(i) @endcode which /// retrieves the static permeability tensor of cell @code /// i @endcode. The permeability tensor, @$K@$, is in /// turn, assumed to expose a method @code operator()(int /// i, int j) @endcode such that the call @code K(i,j) /// @endcode retrieves the @f$ij@f$'th component of the /// cell permeability @f$K@f$. /// /// @param [in] c /// Cell for which to evaluate the inverse of the mimetic /// inner product. /// /// @param [in] r /// Specific reservoir properties. Only the permeability /// is used in method @code buildMatrix() @endcode. /// /// @param [in] nf /// Number of faces (i.e., number of neighbours) of cell /// @code *c @endcode. void buildStaticContrib(const CellIter& c, const RockInterface& r, const typename CellIter::Vector& grav, const int nf) { // Binv = (N*lambda*K*N' + t*diag(A)*(I - Q*Q')*diag(A))/vol // ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ // precompute: n_ precompute: second_term_ // t = 6/dim * trace(lambda*K) typedef typename CellIter::FaceIterator FI; typedef typename CellIter::Vector CV; typedef typename FI ::Vector FV; // Now we need to remember the rocks, since we will need // the permeability for dynamic assembly. prock_ = &r; const int ci = c->index(); static_assert (FV::dimension == int(dim), ""); assert (int(t1_.size()) >= nf * dim); assert (int(t2_.size()) >= nf * dim); assert (int(fa_.size()) >= nf * nf); SharedFortranMatrix T2 (nf, dim, &t2_ [0]); SharedFortranMatrix fa (nf, nf , &fa_ [0]); SharedFortranMatrix second_term(nf, nf, &second_term_[ci][0]); SharedFortranMatrix n(nf, dim, &n_[ci][0]); // Clear matrices of any residual data. zero(second_term); zero(n); zero(T2); zero(fa); // Setup: second_term <- I, n <- N, T2 <- C const CV cc = c->centroid(); int i = 0; for (FI f = c->facebegin(); f != c->faceend(); ++f, ++i) { second_term(i,i) = Scalar(1.0); fa(i,i) = f->area(); FV fc = f->centroid(); fc -= cc; fc *= fa(i,i); FV fn = f->normal (); fn *= fa(i,i); for (int j = 0; j < dim; ++j) { n (i,j) = fn[j]; T2(i,j) = fc[j]; } } assert (i == nf); // T2 <- orth(T2) if (orthogonalizeColumns(T2) != 0) { assert (false); } // second_term <- second_term - T2*T2' == I - Q*Q' symmetricUpdate(Scalar(-1.0), T2, Scalar(1.0), second_term); // second_term <- diag(A) * second_term * diag(A) symmetricUpdate(fa, second_term); // Gravity term: Kg_ = K * grav vecMulAdd_N(Scalar(1.0), r.permeability(ci), &grav[0], Scalar(0.0), &Kg_[ci][0]); }
template <typename T2> int Baz () { return static_cast <int> (operator T2 ()); }
void dotytab() { static tym_t _ptr[] = { TYjhandle,TYnptr,TYsptr,TYcptr,TYf16ptr,TYfptr,TYhptr, TYvptr }; static tym_t _real[] = { TYfloat,TYdouble,TYdouble_alias,TYldouble, }; static tym_t _imaginary[] = { TYifloat,TYidouble,TYildouble, }; static tym_t _complex[] = { TYcfloat,TYcdouble,TYcldouble, }; static tym_t _integral[] = { TYbool,TYchar,TYschar,TYuchar,TYshort, TYwchar_t,TYushort,TYenum,TYint,TYuint, TYlong,TYulong,TYllong,TYullong,TYdchar, TYchar16, TYcent, TYucent }; static tym_t _ref[] = { TYnref,TYfref,TYref }; #if TARGET_MAC static tym_t _func[] = { TYnfunc,TYffunc,TYnpfunc,TYfpfunc,TYpsfunc, TYnsfunc,TYfsfunc }; #else static tym_t _func[] = { TYnfunc,TYffunc,TYnpfunc,TYfpfunc,TYf16func, TYnsfunc,TYfsfunc,TYifunc,TYmfunc,TYjfunc, TYnsysfunc,TYfsysfunc, TYhfunc }; #endif static tym_t _uns[] = { TYuchar,TYushort,TYuint,TYulong, #if MARS TYwchar_t, #endif TYdchar,TYullong,TYucent,TYchar16 }; static tym_t _mptr[] = { TYmemptr }; static tym_t _nullptr[] = { TYnullptr }; static tym_t _fv[] = { TYfptr, TYvptr }; #if TARGET_WINDOS static tym_t _farfunc[] = { TYffunc,TYfpfunc,TYfsfunc,TYfsysfunc }; #endif #if TARGET_MAC static tym_t _pasfunc[] = { TYnpfunc,TYfpfunc,TYpsfunc,TYnsfunc,TYfsfunc }; static tym_t _revfunc[] = { TYnpfunc,TYfpfunc,TYpsfunc }; #else static tym_t _pasfunc[] = { TYnpfunc,TYfpfunc,TYf16func,TYnsfunc,TYfsfunc,TYmfunc,TYjfunc }; static tym_t _revfunc[] = { TYnpfunc,TYfpfunc,TYf16func,TYjfunc }; #endif static tym_t _short[] = { TYbool,TYchar,TYschar,TYuchar,TYshort, TYwchar_t,TYushort,TYchar16 }; static tym_t _aggregate[] = { TYstruct,TYarray }; static struct { const char *string; /* name of type */ tym_t ty; /* TYxxxx */ tym_t unsty; /* conversion to unsigned type */ tym_t relty; /* type for relaxed type checking */ int size; int debtyp; /* Codeview 1 type in debugger record */ int debtyp4; /* Codeview 4 type in debugger record */ } typetab[] = { /* Note that chars are signed, here */ "bool", TYbool, TYbool, TYchar, 1, 0x80, 0x30, "char", TYchar, TYuchar, TYchar, 1, 0x80, 0x70, "signed char", TYschar, TYuchar, TYchar, 1, 0x80, 0x10, "unsigned char",TYuchar, TYuchar, TYchar, 1, 0x84, 0x20, "char16_t", TYchar16, TYchar16, TYint, 2, 0x85, 0x21, "short", TYshort, TYushort, TYint, SHORTSIZE, 0x81,0x11, "wchar_t", TYwchar_t, TYwchar_t, TYint, SHORTSIZE, 0x85,0x71, "unsigned short",TYushort, TYushort, TYint, SHORTSIZE, 0x85,0x21, // These values are adjusted for 32 bit ints in cv_init() and util_set386() "enum", TYenum, TYuint, TYint, -1, 0x81,0x72, "int", TYint, TYuint, TYint, 2, 0x81,0x72, "unsigned", TYuint, TYuint, TYint, 2, 0x85,0x73, "long", TYlong, TYulong, TYlong, LONGSIZE, 0x82,0x12, "unsigned long",TYulong, TYulong, TYlong, LONGSIZE, 0x86,0x22, "dchar", TYdchar, TYdchar, TYlong, 4, 0x86,0x78, "long long", TYllong, TYullong, TYllong, LLONGSIZE, 0x82,0x13, "uns long long",TYullong, TYullong, TYllong, LLONGSIZE, 0x86,0x23, "cent", TYcent, TYucent, TYcent, 16, 0x82,0x13, "ucent", TYucent, TYucent, TYcent, 16, 0x86,0x23, "float", TYfloat, TYfloat, TYfloat, FLOATSIZE, 0x88,0x40, "double", TYdouble, TYdouble, TYdouble, DOUBLESIZE,0x89,0x41, "double alias", TYdouble_alias, TYdouble_alias, TYdouble_alias,8, 0x89,0x41, "long double", TYldouble, TYldouble, TYldouble, LNGDBLSIZE, 0x89,0x42, "imaginary float", TYifloat, TYifloat, TYifloat, FLOATSIZE, 0x88,0x40, "imaginary double", TYidouble, TYidouble, TYidouble, DOUBLESIZE,0x89,0x41, "imaginary long double",TYildouble, TYildouble, TYildouble, LNGDBLSIZE,0x89,0x42, "complex float", TYcfloat, TYcfloat, TYcfloat, 2*FLOATSIZE, 0x88,0x50, "complex double", TYcdouble, TYcdouble, TYcdouble, 2*DOUBLESIZE,0x89,0x51, "complex long double", TYcldouble, TYcldouble, TYcldouble, 2*LNGDBLSIZE,0x89,0x52, "*", TYptr, TYptr, TYptr, 2, 0x20, 0x100, "__near *", TYjhandle, TYjhandle, TYjhandle, 2, 0x20, 0x100, "nullptr_t", TYnullptr, TYnullptr, TYptr, 2, 0x20, 0x100, "*", TYnptr, TYnptr, TYnptr, 2, 0x20, 0x100, "__ss *", TYsptr, TYsptr, TYsptr, 2, 0x20, 0x100, "__cs *", TYcptr, TYcptr, TYcptr, 2, 0x20, 0x100, "__far16 *", TYf16ptr, TYf16ptr, TYf16ptr, 4, 0x40, 0x200, "__far *", TYfptr, TYfptr, TYfptr, 4, 0x40, 0x200, "__huge *", TYhptr, TYhptr, TYhptr, 4, 0x40, 0x300, "__handle *", TYvptr, TYvptr, TYvptr, 4, 0x40, 0x200, "struct", TYstruct, TYstruct, TYstruct, -1, 0, 0, "array", TYarray, TYarray, TYarray, -1, 0x78, 0, "&", TYref, TYref, TYref, -1, 0, 0, "__near &", TYnref, TYnref, TYnref, 2, 0, 0, "__far &", TYfref, TYfref, TYfref, 4, 0, 0, "C func", TYnfunc, TYnfunc, TYnfunc, -1, 0x63, 0, "C func", TYhfunc, TYhfunc, TYhfunc, -1, 0, 0, "far C func", TYffunc, TYffunc, TYffunc, -1, 0x64, 0, "std func", TYnsfunc, TYnsfunc, TYnsfunc, -1, 0x63, 0, "far std func", TYfsfunc, TYfsfunc, TYfsfunc, -1, 0x64, 0, "sys func", TYnsysfunc, TYnsysfunc,TYnsysfunc, -1, 0x63, 0, "far sys func", TYfsysfunc, TYfsysfunc,TYfsysfunc, -1, 0x64, 0, "member func", TYmfunc, TYmfunc, TYmfunc, -1, 0x64, 0, "D func", TYjfunc, TYjfunc, TYjfunc, -1, 0x74, 0, "interrupt func", TYifunc, TYifunc, TYifunc, -1, 0x64, 0, #if TARGET_MAC "near Cpp func", TYnpfunc, TYnpfunc, TYnpfunc, -1, 0x74, 0, "far Cpp func", TYfpfunc, TYfpfunc, TYfpfunc, -1, 0x73, 0, "far pascal func", TYpsfunc, TYpsfunc, TYpsfunc, -1, 0x75, 0, #else "_far16 Pascal func", TYf16func, TYf16func, TYf16func, -1, 0x63, 0, "Pascal func", TYnpfunc, TYnpfunc, TYnpfunc, -1, 0x74, 0, "far Pascal func", TYfpfunc, TYfpfunc, TYfpfunc, -1, 0x73, 0, #endif "void", TYvoid, TYvoid, TYvoid, -1, 0x85, 3, "memptr", TYmemptr, TYmemptr, TYmemptr, -1, 0, 0, "ident", TYident, TYident, TYident, -1, 0, 0, "template", TYtemplate, TYtemplate, TYtemplate, -1, 0, 0, "vtshape", TYvtshape, TYvtshape, TYvtshape, -1, 0, 0, }; FILE *f; static unsigned tytab[64 * 4]; static tym_t tytouns[64 * 4]; static tym_t _tyrelax[TYMAX]; static tym_t _tyequiv[TYMAX]; static signed char tysize[64 * 4]; static const char *tystring[TYMAX]; static unsigned char dttab[TYMAX]; static unsigned short dttab4[TYMAX]; int i; /* Repeat everything 4 times to account for the mTYconst and mTYvolatile bits */ #define T1(arr,mask) for (i=0; i<arraysize(arr); i++) \ { tytab[arr[i]] |= mask; \ tytab[arr[i] + 64] |= mask; \ tytab[arr[i] + 128] |= mask; \ tytab[arr[i] + 192] |= mask; \ }; #define T2(arr,mask) for (i=0; i<arraysize(arr); i++) \ { tytab[arr[i]] |= mask; \ tytab[arr[i] + 64] |= mask; \ tytab[arr[i] + 128] |= mask; \ tytab[arr[i] + 192] |= mask; \ }; T1(_ptr, TYFLptr); T1(_real, TYFLreal); T1(_integral, TYFLintegral); T1(_imaginary,TYFLimaginary); T1(_complex, TYFLcomplex); T1(_uns, TYFLuns); T1(_mptr, TYFLmptr); #if OMFOBJ T1(_fv, TYFLfv); T2(_farfunc, TYFLfarfunc); #endif T2(_pasfunc, TYFLpascal); T2(_revfunc, TYFLrevparam); T2(_short, TYFLshort); T2(_aggregate,TYFLaggregate); T2(_ref, TYFLref); T2(_func, TYFLfunc); T2(_nullptr, TYFLnullptr); #undef T1 #undef T2 f = fopen("tytab.c","w"); fprintf(f,"unsigned tytab[] =\n{ "); for (i = 0; i < arraysize(tytab); i++) { fprintf(f,"0x%02x,",tytab[i]); if ((i & 7) == 7 && i < arraysize(tytab) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); #if 0 fprintf(f,"unsigned char tytab2[] =\n{ "); for (i = 0; i < arraysize(tytab2); i++) { fprintf(f,"0x%02x,",tytab2[i]); if ((i & 7) == 7 && i < arraysize(tytab2) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); #endif for (i = 0; i < arraysize(typetab); i++) { tytouns[typetab[i].ty] = typetab[i].unsty; tytouns[typetab[i].ty | mTYconst] = typetab[i].unsty | mTYconst; tytouns[typetab[i].ty | mTYvolatile] = typetab[i].unsty | mTYvolatile; tytouns[typetab[i].ty | mTYconst | mTYvolatile] = typetab[i].unsty | mTYconst | mTYvolatile; } fprintf(f,"const tym_t tytouns[] =\n{ "); for (i = 0; i < arraysize(tytouns); i++) { fprintf(f,"0x%02x,",tytouns[i]); if ((i & 7) == 7 && i < arraysize(tytouns) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); for (i = 0; i < arraysize(typetab); i++) { tysize[typetab[i].ty | 0x00] = typetab[i].size; tysize[typetab[i].ty | 0x40] = typetab[i].size; tysize[typetab[i].ty | 0x80] = typetab[i].size; tysize[typetab[i].ty | 0xC0] = typetab[i].size; /*printf("tysize[%d] = %d\n",typetab[i].ty,typetab[i].size);*/ } fprintf(f,"signed char tysize[] =\n{ "); for (i = 0; i < arraysize(tysize); i++) { fprintf(f,"%d,",tysize[i]); if ((i & 7) == 7 && i < arraysize(tysize) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); for (i = 0; i < arraysize(typetab); i++) { _tyrelax[typetab[i].ty] = typetab[i].relty; /*printf("_tyrelax[%d] = %d\n",typetab[i].ty,typetab[i].relty);*/ } fprintf(f,"unsigned char _tyrelax[] =\n{ "); for (i = 0; i < arraysize(_tyrelax); i++) { fprintf(f,"0x%02x,",_tyrelax[i]); if ((i & 7) == 7 && i < arraysize(_tyrelax) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); /********** tyequiv[] ************/ for (i = 0; i < arraysize(_tyequiv); i++) _tyequiv[i] = i; _tyequiv[TYchar] = TYschar; /* chars are signed by default */ // These values are adjusted in util_set386() for 32 bit ints _tyequiv[TYint] = TYshort; _tyequiv[TYuint] = TYushort; fprintf(f,"unsigned char tyequiv[] =\n{ "); for (i = 0; i < arraysize(_tyequiv); i++) { fprintf(f,"0x%02x,",_tyequiv[i]); if ((i & 7) == 7 && i < arraysize(_tyequiv) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); for (i = 0; i < arraysize(typetab); i++) tystring[typetab[i].ty] = typetab[i].string; fprintf(f,"const char *tystring[] =\n{ "); for (i = 0; i < arraysize(tystring); i++) { fprintf(f,"\"%s\",",tystring[i]); if ((i & 7) == 7 && i < arraysize(tystring) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); for (i = 0; i < arraysize(typetab); i++) dttab[typetab[i].ty] = typetab[i].debtyp; fprintf(f,"unsigned char dttab[] =\n{ "); for (i = 0; i < arraysize(dttab); i++) { fprintf(f,"0x%02x,",dttab[i]); if ((i & 7) == 7 && i < arraysize(dttab) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); for (i = 0; i < arraysize(typetab); i++) dttab4[typetab[i].ty] = typetab[i].debtyp4; fprintf(f,"unsigned short dttab4[] =\n{ "); for (i = 0; i < arraysize(dttab4); i++) { fprintf(f,"0x%02x,",dttab4[i]); if ((i & 7) == 7 && i < arraysize(dttab4) - 1) fprintf(f,"\n "); } fprintf(f,"\n};\n"); fclose(f); }
int main() { Poly A(3, 3); Poly B(3, 2); Poly C(2, 1); Poly D(B); Poly Z; Poly A2, B2, Z1, Z2; cout << "A= " << A << endl; cout << "B= " << B << endl << endl; Poly Y (0, 0); Poly X (0, 0); cout << "X1= " << X << endl; Poly T1; Poly T2(2, 2); cout << "T1= " << T1 << endl; cout << "T2= " << T2 << endl; X = T1 - T2; cout << "X1= " << X << endl; X = T2 - T1; cout << "X2= " << X << endl; /* X = X + A; cout << "X2= " << X << endl; X = A; cout << "X3= " << X << endl; X = A + B; cout << "X4= " << X << endl; X = A; X += B; cout << "X5= " << X << endl; X = X - A; cout << "X6= " << X << endl; X = A; cout << "X7= " << X << endl; X = A - B; cout << "X8= " << X << endl; X = A; X -= B; cout << "X9= " << X << endl; X = Y; cout << "X10= " << X << endl; X = X * A; cout << "X11= " << X << endl; X = Y; X *= A; cout << "X12= " << X << endl; X = A * B; cout << "X13= " << X << endl; X = A; X *= B; cout << "X14= " << X << endl; X = A; X *= B; cout << "X= " << X << endl; X *= B; cout << "X= " << X << endl; cout << "X= " << X << endl; X = A * B; cout << "X= " << X << endl; X = A; X *= B; cout << "X= " << X << endl; */ //X *= C; //cout << "X= " << X << endl; //D = A * B * C; //cout << "D= " << D << endl; //X = Y; //cout << "X= " << X << endl; //X -= B; //cout << "X= " << X << endl; //X -= C; //cout << "X= " << X << endl; //cout << "C= " << C << endl; //cin >> A; //cout << endl; //A2 = A; //cout << "A= " << A << endl; //cout << "A2= " << A2 << endl; return 0; }
Triple() : first(T1()), second(T2()), third(T3()) {}
bool test_subtract( T1 v1, T2 v2, const char *av1, const char *av2, char expected_result ){ std::cout << "testing " << av1 << " - " << av2 << std::endl; boost::numeric::safe<T1> t1 = v1; BOOST_TYPEOF_TPL(T1() - T2()) result; try{ result = t1 - v2; if(expected_result == 'x'){ std::cout << "failed to detect error in subtraction " << std::hex << result << "(" << std::dec << result << ")" << " ! = "<< av1 << " - " << av2 << std::endl; try{ result = t1 - v2; } catch(...){} return false; } } catch(std::range_error){ if(expected_result == '.'){ std::cout << "erroneously detected error in subtraction " << std::hex << result << "(" << std::dec << result << ")" << " == "<< av1 << " - " << av2 << std::endl; try{ result = t1 - v2; } catch(...){} return false; } } boost::numeric::safe<T2> t2 = v2; try{ result = t1 - t2; if(expected_result == 'x'){ std::cout << "failed to detect error in subtraction " << std::hex << result << "(" << std::dec << result << ")" << " ! = "<< av1 << " - " << av2 << std::endl; try{ result = t1 - t2; } catch(...){} return false; } } catch(std::range_error){ if(expected_result == '.'){ std::cout << "erroneously detected error in subtraction " << std::hex << result << "(" << std::dec << result << ")" << " == "<< av1 << " - " << av2 << std::endl; try{ result = t1 - t2; } catch(...){} return false; } } return true; // correct result }