void ON_BezierCage::Dump( ON_TextLog& dump ) const { dump.Print( "ON_BezierCage dim = %d is_rat = %d\n" " order = (%d, %d, %d) \n", m_dim, m_is_rat, m_order[0], m_order[1], m_order[2] ); dump.Print( "Control Points %d %s points\n" " index value\n", m_order[0]*m_order[1]*m_order[2], (m_is_rat) ? "rational" : "non-rational" ); if ( !m_cv ) { dump.Print(" NULL cv array\n"); } else { int i,j; char sPreamble[128]; memset(sPreamble,0,sizeof(sPreamble)); for ( i = 0; i < m_order[0]; i++ ) { for ( j = 0; j < m_order[1]; j++ ) { if ( i > 0 || j > 0) dump.Print("\n"); sPreamble[0] = 0; sprintf(sPreamble," CV[%2d][%2d]",i,j); dump.PrintPointList( m_dim, m_is_rat, m_order[2], m_cv_stride[2], CV(i,j,0), sPreamble ); } if ( i < m_order[0]-1) dump.Print("\n"); } } }
v16 v16_broadcast_cst_128 () __attribute__ ((const)); v16 v16_broadcast_cst_255 () __attribute__ ((const)); v16 v16_broadcast_cst_257 () __attribute__ ((const)); v8 v8_broadcast_cst_0 () __attribute__ ((const)); v16 v16_broadcast_cst_128 () { return v16_broadcast_cst(128); } v16 v16_broadcast_cst_255 () { return v16_broadcast_cst(255); } v16 v16_broadcast_cst_257 () { return v16_broadcast_cst(257); } v8 v8_broadcast_cst_0 () { return v8_broadcast_cst(0); } #define V128 v16_broadcast_cst_128() #define V255 v16_broadcast_cst_255() #define V257 v16_broadcast_cst_257() #define V0 v8_broadcast_cst_0() #else static const union cv v128 = CV(128); static const union cv v255 = CV(255); static const union cv v257 = CV(257); static const union cv8 v0 = CV(0); #define V128 v128.v16 #define V255 v255.v16 #define V257 v257.v16 #define V0 v0.v8 #endif #ifdef PRINT_HARDER void print_v32(v32 x) { union u32 u; u.v = x; printf ("%08x %08x %08x %08x\n", u.u[0], u.u[1], u.u[2], u.u[3]); }
int crypto_aead_encrypt(unsigned char *c,unsigned long long *clen, const unsigned char *m,unsigned long long mlen, const unsigned char *ad,unsigned long long adlen, const unsigned char *nsec, const unsigned char *npub, const unsigned char *k) { v16qi data[16]; uint8_t buffer[16*16] = {0}; v16qi tweakey[16*TWEAKEY_SIZE]; uint8_t pad[16]; v16qi *checksum = (v16qi*) &buffer[ 16 * (((mlen+15)/16)%16) ]; v16qi auth = CV(0); // Associated Data if (adlen > 0) { size_t idx=0; tweakey_schedule(k, npub, TWEAK_AD, tweakey); for (idx=0; idx+256<adlen; idx+=16*16) { read128(ad+idx, data); encrypt_tweakey(data, tweakey); tweakey_increment(tweakey, idx); write128_checksum(data, NULL, &auth, 16); } // Final chunk uint8_t buffer2[16*16] = {0}; memcpy(buffer2, ad+idx, adlen-idx); if ((adlen % 16) == 0) { tweakey_set(tweakey, (adlen-idx-1)/16, 12, TWEAK_AD_LAST_FULL); } else { tweakey_set(tweakey, (adlen-idx-1)/16, 12, TWEAK_AD_LAST_PARTIAL); buffer2[adlen-idx] = 0x80; } tweakey_set(tweakey, (adlen-idx-1)/16, 13, 0); tweakey_set(tweakey, (adlen-idx-1)/16, 14, 0); tweakey_set(tweakey, (adlen-idx-1)/16, 15, 0); read128(buffer2, data); encrypt_tweakey(data, tweakey); write128_checksum(data, NULL, &auth, (adlen-idx+15)/16); } size_t idx=0; tweakey_schedule(k, npub, TWEAK_MESSAGE, tweakey); if (mlen > 0) { for (idx=0; idx+16*16<mlen; idx+=16*16) { read128_with_checksum(m+idx, data, checksum, 16); encrypt_tweakey(data, tweakey); tweakey_increment(tweakey, idx); write128(data, c+idx); } // Final chunk(s) if ((mlen % 16) == 0) { tweakey_set(tweakey, (mlen-idx-1)/16, 12, TWEAK_MESSAGE_LAST_FULL); } else { tweakey_set(tweakey, (mlen-idx-1)/16, 12, TWEAK_MESSAGE_LAST_PARTIAL); } tweakey_set(tweakey, (mlen-idx-1)/16, 13, 0); tweakey_set(tweakey, (mlen-idx-1)/16, 14, 0); tweakey_set(tweakey, (mlen-idx-1)/16, 15, 0); if (mlen > idx+240) { // Almost full chunk: encrypt length for final block; extra chunk for checksum uint8_t buffer2[16*16] = {0}; memcpy(buffer2, m+idx, 240); buffer2[255] = 8*((mlen-1)%16)+8; read128_with_checksum(buffer2, data, checksum, 15); update_checksum(m+idx+240, checksum, mlen-idx-240); encrypt_tweakey(data, tweakey); tweakey_increment(tweakey, idx); write128(data, buffer2); memcpy(c+idx, buffer2, 240); memcpy(pad, buffer2+240, 16); idx = mlen; } else { // Partial chunk: encrypt length for final block; checksum included memcpy(buffer, m+idx, mlen-idx); update_checksum(buffer, checksum, mlen-idx); // Encrypt partial block length memset(&buffer[((mlen-idx-1)|15)-15], 0, 16); buffer[(mlen-idx-1)|15] = 8*((mlen-1)%16)+8; } } int l = mlen%16? mlen%16: mlen? 16: 0; int fullblocks = (mlen-idx-1)/16; // Tag generation tweakey_set(tweakey, ((mlen-idx+15)/16), 15, 0); tweakey_set(tweakey, ((mlen-idx+15)/16), 14, 0); tweakey_set(tweakey, ((mlen-idx+15)/16), 13, 0); if (mlen%16) { tweakey_set(tweakey, ((mlen-idx+15)/16), 12, TWEAK_TAG_LAST_PARTIAL); } else { tweakey_set(tweakey, ((mlen-idx+15)/16), 12, TWEAK_TAG_LAST_FULL); } read128(buffer, data); encrypt_tweakey(data, tweakey); write128(data, buffer); *checksum ^= auth; memcpy(c+mlen, checksum, CRYPTO_ABYTES); if (mlen-idx) { memcpy(c+idx, buffer, 16*fullblocks); memcpy(pad, buffer+16*fullblocks, l); } unsigned i; for (i=0; i < l; i++) c[16*((mlen-1)/16)+i] = m[16*((mlen-1)/16)+i] ^ pad[i]; *clen = mlen+CRYPTO_ABYTES; return 0; }
int crypto_aead_decrypt(unsigned char *m,unsigned long long *outputmlen, unsigned char *nsec, const unsigned char *c,unsigned long long clen, const unsigned char *ad,unsigned long long adlen, const unsigned char *npub, const unsigned char *k) { v16qi data[16]; uint8_t buffer[16*16] = {0}; v16qi tweakey[16*TWEAKEY_SIZE]; *outputmlen = clen-CRYPTO_ABYTES; v16qi auth = CV(0); v16qi checksum = CV(0); // Associated Data if (adlen > 0) { size_t idx=0; tweakey_schedule(k, npub, TWEAK_AD, tweakey); for (idx=0; idx+256<adlen; idx+=16*16) { read128(ad+idx, data); encrypt_tweakey(data, tweakey); tweakey_increment(tweakey, idx); write128_checksum(data, NULL, &auth, 16); } // Final chunk uint8_t buffer2[16*16] = {0}; memcpy(buffer2, ad+idx, adlen-idx); if ((adlen % 16) == 0) { tweakey_set(tweakey, (adlen-idx-1)/16, 12, TWEAK_AD_LAST_FULL); } else { tweakey_set(tweakey, (adlen-idx-1)/16, 12, TWEAK_AD_LAST_PARTIAL); buffer2[adlen-idx] = 0x80; } tweakey_set(tweakey, (adlen-idx-1)/16, 13, 0); tweakey_set(tweakey, (adlen-idx-1)/16, 14, 0); tweakey_set(tweakey, (adlen-idx-1)/16, 15, 0); read128(buffer2, data); encrypt_tweakey(data, tweakey); write128_checksum(data, NULL, &auth, (adlen-idx+15)/16); } auth ^= sse_load(c+*outputmlen); // Message size_t idx=0; tweakey_schedule(k, npub, TWEAK_MESSAGE, tweakey); for (idx=0; idx+256 < *outputmlen; idx+=256) { read128(c+idx, data); decrypt_tweakey(data, tweakey); tweakey_increment(tweakey, idx); write128_checksum(data, m+idx, &checksum, 16); } int l = *outputmlen%16? *outputmlen%16: *outputmlen? 16: 0; int fullblocks = (*outputmlen-l-idx)/16; // Final block // use slot fullblocks (tweak will be used for tag generation) tweakey_set(tweakey, fullblocks, 13, 0); tweakey_set(tweakey, fullblocks, 14, 0); tweakey_set(tweakey, fullblocks, 15, 0); if (*outputmlen) { if (*outputmlen%16) { tweakey_set(tweakey, fullblocks, 12, TWEAK_MESSAGE_LAST_PARTIAL); } else { tweakey_set(tweakey, fullblocks, 12, TWEAK_MESSAGE_LAST_FULL); } uint8_t buffer2[16*16] = {0}; buffer2[16*fullblocks+15] = 8*l; read128(buffer2, data); encrypt_tweakey(data, tweakey); write128(data, buffer2); unsigned i; for (i=0; i<l; i++) m[*outputmlen-l+i] = c[*outputmlen-l+i] ^ buffer2[16*fullblocks+i]; update_checksum(m+*outputmlen-l, &checksum, l); } // Last chunk: remaining full blocks, and checksum memcpy(buffer, c+idx, 16*fullblocks); sse_store(buffer+16*fullblocks, auth); if (*outputmlen%16) { tweakey_set(tweakey, fullblocks, 12, TWEAK_TAG_LAST_PARTIAL); } else { tweakey_set(tweakey, fullblocks, 12, TWEAK_TAG_LAST_FULL); } read128(buffer, data); decrypt_tweakey(data, tweakey); write128_checksum2(data, buffer, &checksum, fullblocks+1, fullblocks); memcpy(m+idx, buffer, 16*fullblocks); // Verify tag if (memcmp(&checksum, buffer+16*fullblocks, 16) != 0) { memset(m, 0, *outputmlen); return -1; } return 0; }
void Curve<T>::addPoint(double position, const T& val, InterpType type) { prepared = false; _cvData.push_back(CV(position, val, type)); }
Curve<T>::Curve() : cacheCV(0), prepared(false) { _cvData.push_back(CV(-FLT_MAX, T(), kNone)); _cvData.push_back(CV(FLT_MAX, T(), kNone)); }
bool ON_BezierCage::Read(ON_BinaryArchive& archive) { Destroy(); int major_version = 0; int minor_version = 0; bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version); if ( rc ) { while(rc) { if ( major_version != 1 ) { ON_ERROR("ON_BezierCage::Read - old code unable to read new version of chunk"); rc = false; break; } int dim=0,order0=0,order1=0,order2=0; bool is_rat=false; rc = archive.ReadInt(&dim); if (!rc) break; if (dim < 1 || dim > 10000) { ON_ERROR("ON_BezierCage::Read - invalid dim"); rc=false; break; } rc = archive.ReadBool(&is_rat); if (!rc) break; rc = archive.ReadInt(&order0); if (!rc) break; if ( order0 < 2 || order0 > 10000 ) { ON_ERROR("ON_BezierCage::Read - invalid order0"); rc=false; break; } rc = archive.ReadInt(&order1); if (!rc) break; if ( order1 < 2 || order1 > 10000 ) { ON_ERROR("ON_BezierCage::Read - invalid order1"); rc=false; break; } rc = archive.ReadInt(&order2); if (!rc) break; if ( order2 < 2 || order2 > 10000 ) { ON_ERROR("ON_BezierCage::Read - invalid order2"); rc=false; break; } rc = Create(dim,is_rat,order0,order1,order2); if (!rc) break; int i,j,k; const int cv_dim = m_is_rat?(m_dim+1):m_dim; for(i = 0; i < order0 && rc; i++) { for(j = 0; j < order1 && rc; j++) { for ( k = 0; k < order2 && rc; k++) { rc = archive.ReadDouble(cv_dim,CV(i,j,k)); } } } break; } if ( !archive.EndRead3dmChunk() ) { rc = false; } } return rc; }
/* * Determine whether a device has decomposed pixels with the components * in the standard PostScript order, and a 1-for-1 color map * (possibly inverted). Return 0 if not true color, 1 if true color, * -1 if inverted true color. */ static int device_is_true_color(gx_device * dev) { int ncomp = dev->color_info.num_components; int depth = dev->color_info.depth; int i, max_v; #define CV(i) (gx_color_value)((ulong)gx_max_color_value * i / max_v) #define CV0 ((gx_color_value)0) /****** DOESN'T HANDLE INVERSION YET ******/ switch (ncomp) { case 1: /* gray-scale */ max_v = dev->color_info.max_gray; if (max_v != (1 << depth) - 1) return 0; for (i = 0; i <= max_v; ++i) { gx_color_value v[3]; v[0] = v[1] = v[2] = CV(i); if ((*dev_proc(dev, map_rgb_color)) (dev, v) != i) return 0; } return true; case 3: /* RGB */ max_v = dev->color_info.max_color; if (depth % 3 != 0 || max_v != (1 << (depth / 3)) - 1) return false; { const int gs = depth / 3, rs = gs * 2; for (i = 0; i <= max_v; ++i) { gx_color_value red[3]; gx_color_value green[3]; gx_color_value blue[3]; red[0] = CV(i); red[1] = CV0, red[2] = CV0; green[0] = CV0; green[1] = CV(i); green[2] = CV0; blue[0] = CV0; blue[1] = CV0; blue[2] = CV(i); if ((*dev_proc(dev, map_rgb_color)) (dev, red) != i << rs || (*dev_proc(dev, map_rgb_color)) (dev, green) != i << gs || (*dev_proc(dev, map_rgb_color)) (dev, blue) != i /*<< bs */ ) return 0; } } return true; case 4: /* CMYK */ max_v = dev->color_info.max_color; if ((depth & 3) != 0 || max_v != (1 << (depth / 4)) - 1) return false; { const int ys = depth / 4, ms = ys * 2, cs = ys * 3; for (i = 0; i <= max_v; ++i) { gx_color_value cyan[4]; gx_color_value magenta[4]; gx_color_value yellow[4]; gx_color_value black[4]; cyan[0] = CV(i); cyan[1] = cyan[2] = cyan[3] = CV0; magenta[1] = CV(i); magenta[0] = magenta[2] = magenta[3] = CV0; yellow[2] = CV(i); yellow[0] = yellow[1] = yellow[3] = CV0; black[3] = CV(i); black[0] = black[1] = black[2] = CV0; if ((*dev_proc(dev, map_cmyk_color)) (dev, cyan) != i << cs || (*dev_proc(dev, map_cmyk_color)) (dev, magenta) != i << ms || (*dev_proc(dev, map_cmyk_color)) (dev, yellow) != i << ys || (*dev_proc(dev, map_cmyk_color)) (dev, black) != i /*<< ks */ ) return 0; } } return 1; default: return 0; /* DeviceN */ } #undef CV #undef CV0 }
int main(int argc, char* argv[]) { // FILES FOR RESULTS std::ofstream CV("CV_Output.txt"); std::ofstream Profiles("CV_Profiles.txt"); std::ofstream Grid("CV_checking.txt"); int Guardar = 1000;//Npoints to save in file //Set system parameters double K0 = 1.e4;//dimensionless (= k0*re/DA) double alpha = 0.5;//transfer coefficient double dB = 1.;//dimensionles (=DB/DA) double CB = 0.;//dimensionless (=cB*/cA*) int NSpecies = 2; // Specify simulation parameters double theta_i = 6.;//dimensionaless initial potential (=F(Ei-E0)/RT) double theta_v = -6.;//dimensionless vertex potential (=F(Ev-E0)/RT) // double sigma = 0.1;//dimensionless scan rate (=v(F/RT)(re^2/D)) double sigma = 0.1;//dimensionless scan rate (=v(F/RT)(re^2/D)) double h0 = 1.e-4;//first dimensionless interval double omega = 1.08;//expanding factor // double deltaTheta = 0.005;//"time resolution" double deltaTheta = 0.005;//"time resolution" // Determine other parameters double deltaT = deltaTheta / sigma; double maxT = 2*fabs(theta_v - theta_i) / sigma; double maxR = 6 * sqrt(maxT) + 1; double maxZ = 6 * sqrt(maxT); int t = (int)( maxT / deltaT ); // number of timesteps int CadaCuantos = int(t/Guardar); //*********************************************************************** //SPATIAL GRIDS // Make Z grid std::vector<double> Z; double h = h0; Z.push_back(0.0); while( Z.back() <= maxZ ) { Z.push_back( Z.back() + h ); h *= omega; } int m = Z.size(); // number of spacesteps (Z) printf("m:%d\n", m); // Make R grid std::vector<double> R; h = h0; R.push_back(0); while( R.back() < 0.5 ) { R.push_back( R.back() + h ); h *= omega; } R.back() = 0.5; for(int i = R.size()-2; i>=0; i--) { R.push_back( 1 - R[i] ); } int n_e = R.size(); // number spacesteps over electrode printf("n_e:%d\n", n_e); h = h0; while( R.back() <= maxR ) { R.push_back( R.back() + h ); h *= omega; } int n = R.size(); //total number of spacesteps (R) printf("n:%d\n", n); //print out grid for(int i=0; i<n; i++) { for(int j=0; j<m*NSpecies; j++) { Grid << R[i] << "\t" << Z[j] << "\n"; } } // CONCENTRATION MATRICES (and initial conc. values) //double** Ck = new double*[n]; //double** C_ = new double*[n]; double Ck[303][147*2]; double C_[303][147*2]; for(int i=0; i<n; ++i) { // Ck[i] = new double[m*NSpecies];//new timestep // C_[i] = new double[m*NSpecies];//previous timestep // set initial concentrations for(int j=0; j<(m*NSpecies); j++) { if(j<m) { Ck[i][j] = 1.0; C_[i][j] = 1.0; } else { Ck[i][j] = CB;//species B C_[i][j] = CB; } } } // THOMAS COEFFICIENTS //std::vector<double> z_al(m*NSpecies,0.0), z_be(m*NSpecies,0.0), z_ga(m*NSpecies,0.0); double *z_al = (double *)malloc(sizeof(double) * m*NSpecies); double *z_be = (double *)malloc(sizeof(double) * m*NSpecies); double *z_ga = (double *)malloc(sizeof(double) * m*NSpecies); //std::vector<double> z2_al(m*NSpecies,0.0), z2_be(m*NSpecies,0.0), z2_ga(m*NSpecies,0.0); double *z2_al = (double *)malloc(sizeof(double) * m*NSpecies); double *z2_be = (double *)malloc(sizeof(double) * m*NSpecies); double *z2_ga = (double *)malloc(sizeof(double) * m*NSpecies); //std::vector<double> ga_modZ1(m*NSpecies, 0.0), ga_modZ2(m*NSpecies, 0.0); double *ga_modZ1 = (double *)malloc(sizeof(double) * m*NSpecies); double *ga_modZ2 = (double *)malloc(sizeof(double) * m*NSpecies); for (int ww=0; ww < m*NSpecies; ww++) { z_al[ww]=0.0; z_be[ww]=0.0; z_ga[ww]=0.0; z2_al[ww]=0.0; z2_be[ww]=0.0; z2_ga[ww]=0.0; ga_modZ1[ww]=0.0; ga_modZ2[ww]=0.0; } //std::vector<double> r_al(n,0.0), r_be(n,0.0), r_ga(n,0.0); double *r_al = (double*) malloc(sizeof(double) *n); double *r_be = (double*) malloc(sizeof(double) *n); double *r_ga = (double*) malloc(sizeof(double) *n); //std::vector<double> r_alB(n,0.0), r_beB(n,0.0), r_gaB(n,0.0); double *r_alB = (double*) malloc(sizeof(double) *n); double *r_beB = (double*) malloc(sizeof(double) *n); double *r_gaB = (double*) malloc(sizeof(double) *n); //std::vector<double> ga_modR(n, 0.0); //std::vector<double> ga_modRB(n, 0.0); double *ga_modR = (double*) malloc(sizeof(double) *n); double *ga_modRB = (double*) malloc(sizeof(double) *n); for (int ww=0; ww < n; ww++ ) { r_al [ww]=0.0; r_be [ww]=0.0; r_ga [ww]=0.0; r_alB [ww]=0.0; r_beB [ww]=0.0; r_gaB [ww]=0.0; ga_modR [ww]=0.0; ga_modRB[ww]=0.0; } //Z-direction (A and B coupled problems) //species A ("inverted" coefficients) z_be[0] = 1.;//corresponding to j=m-1 for A z_ga[0] = 0.; z2_be[0] = 1.; z2_ga[0] = 0.; for(int j=1; j<m-1; j++) { z_ga[m-j-1] = 2.0 / ( (Z[j+1]-Z[j-1]) * (Z[j] - Z[j-1]) ); z_al[m-j-1] = 2.0 / ( (Z[j+1]-Z[j-1]) * (Z[j+1] - Z[j]) ); z_be[m-j-1] = -z_al[m-j-1] - z_ga[m-j-1] - 2.0 / deltaT; z2_ga[m-j-1] = 2.0 / ( (Z[j+1]-Z[j-1]) * (Z[j] - Z[j-1]) ); z2_al[m-j-1] = 2.0 / ( (Z[j+1]-Z[j-1]) * (Z[j+1] - Z[j]) ); z2_be[m-j-1] = -z2_al[m-j-1] - z2_ga[m-j-1] - 2.0 / deltaT; } //species B for(int j=1; j<m-1; j++) { z_al[j+m] = dB*(2.0 / ( (Z[j+1]-Z[j-1]) * (Z[j] - Z[j-1]) )); z_ga[j+m] = dB*(2.0 / ( (Z[j+1]-Z[j-1]) * (Z[j+1] - Z[j]) )); z_be[j+m] = (-z_al[j+m] - z_ga[j+m]) - 2.0 / deltaT; z2_al[j+m] = dB*(2.0 / ( (Z[j+1]-Z[j-1]) * (Z[j] - Z[j-1]) )); z2_ga[j+m] = dB*(2.0 / ( (Z[j+1]-Z[j-1]) * (Z[j+1] - Z[j]) )); z2_be[j+m] = (-z2_al[j+m] - z2_ga[j+m]) - 2.0 / deltaT; } z2_al[m*NSpecies-1] = 0.;//corresponding to j=m-1 for B z2_be[m*NSpecies-1] = 1.; //R-direction (A and B independent problems) //species A r_be[0] = -1.; r_ga[0] = 1.; for(int i=1; i<n-1; i++) { r_al[i] = ( 1.0 / (R[i+1]-R[i-1]) ) * ( 2.0/(R[i] - R[i-1]) - 1.0/R[i] ); r_ga[i] = ( 1.0 / (R[i+1]-R[i-1]) ) * ( 2.0/(R[i+1] - R[i]) + 1.0/R[i] ); r_be[i] = -r_al[i] - r_ga[i] - 2.0 / deltaT; } r_al[n-1] = 0.; r_be[n-1] = 1.; //species B r_beB[0] = -1.; r_gaB[0] = 1.; for(int i=1; i<n-1; i++) { r_alB[i] = dB*( 1.0 / (R[i+1]-R[i-1]) ) * ( 2.0/(R[i] - R[i-1]) - 1.0/R[i] ); r_gaB[i] = dB*( 1.0 / (R[i+1]-R[i-1]) ) * ( 2.0/(R[i+1] - R[i]) + 1.0/R[i] ); r_beB[i] = (-r_alB[i] - r_gaB[i]) - 2.0 / deltaT; } r_alB[n-1] = 0.; r_beB[n-1] = 1.; // THOMAS: gamma' coefficients - Z sweep (potential independent, independent problems) //electroinactive zone //species A z2_al[m-1] = 1.; z2_be[m-1] = -1.; z2_ga[m-1] = 0.; ga_modZ2[0] = z2_ga[0]/z2_be[0]; // bulk condition for(int j=1; j<m; j++) { ga_modZ2[j] = z2_ga[j] / (z2_be[j] - ga_modZ2[j-1] * z2_al[j]); } //species B z2_al[m] = 0; // no flux boundary condition z2_be[m] = -1.; z2_ga[m] = 1.; for(int j=0; j<m-1; j++) { ga_modZ2[j+m] = z2_ga[j+m] / (z2_be[j+m] - ga_modZ2[j+m-1] * z2_al[j+m]); } //species A - R sweep ga_modR[0] = -1; // boundary condition (zero flux) for(int i=1; i<n-1; i++) { ga_modR[i] = r_ga[i] / (r_be[i] - ga_modR[i-1] * r_al[i]); } //species B - R sweep ga_modRB[0] = -1; // boundary condition (zero flux) for(int i=1; i<n-1; i++) { ga_modRB[i] = r_gaB[i] / (r_beB[i] - ga_modRB[i-1] * r_alB[i]); } /************************************************************************/ /************************************************************************/ // BEGIN SIMULATION int stop = t; double Theta = theta_i; #pragma acc data copy(z_al[0:m*NSpecies], z_be[0:m*NSpecies],z_ga[0:m*NSpecies],ga_modZ1[0:m*NSpecies], \ z_ga[0:m*NSpecies],C_, Ck, z2_al[0:m*NSpecies], z2_be[0:m*NSpecies], z2_ga[0:m*NSpecies], \ ga_modZ2[0:m*NSpecies], r_al[0:n], r_be[0:n], r_ga[0:n], r_alB[0:n], \ r_beB[0:n], r_gaB[0:n], ga_modR[0:n], ga_modRB[0:n]) { for(int k=0; k<stop; k++) { if( k < t/2 ) { Theta -= deltaTheta; } else { Theta += deltaTheta; } // THOMAS: gamma' coefficients for Z sweep //electroactive zone //species A ("inverted") z_al[m-1] = -1.; z_be[m-1] = 1.+h0*expl(-alpha*Theta)*K0; z_ga[m-1] = -h0*expl((1.-alpha)*Theta)*K0; ga_modZ1[0] = z_ga[0]/z_be[0]; // bulk condition for(int j=1; j<m; j++) { ga_modZ1[j] = z_ga[j] / (z_be[j] - ga_modZ1[j-1] * z_al[j]); } //species B z_al[m] = -h0*expl(-alpha*Theta)*K0/dB; z_be[m] = 1. + h0*expl((1.-alpha)*Theta)*K0/dB; z_ga[m] = -1.; for(int j=0; j<m-1; j++) { ga_modZ1[j+m] = z_ga[j+m] / (z_be[j+m] - ga_modZ1[j+m-1] * z_al[j+m]); } //copy concentration grid for(int i=0; i<n; i++) { for(int j=0; j<(m*NSpecies); j++) { C_[i][j] = Ck[i][j]; } } //--- Z SWEEP--- //#pragma omp parallel for #pragma acc kernels copyin(z_al[0:m*NSpecies], z_be[0:m*NSpecies],z_ga[0:m*NSpecies],ga_modZ1[0:m*NSpecies], \ z_ga[0:m*NSpecies],C_, Ck) { #pragma acc loop independent worker(32) #pragma omp parallel for for(int i=1; i<n-1; i++) { //Delta species A Ck[i][0] = 1.0;//bulk concentration for(int j=1; j<m-1; j++) { Ck[i][j] = - C_[i-1][j] * r_al[i] - C_[i][j] * (-r_al[i] - r_ga[i]) - C_[i][j] * 2.0/deltaT - C_[i+1][j] * r_ga[i]; } Ck[i][m-1] = 0.;//surface conditions species A //Delta species B Ck[i][m] = 0.;//surface conditions species B for(int j=1; j<m-1; j++) { Ck[i][j+m] = - C_[i-1][j+m] * r_alB[i] - C_[i][j+m] * (-r_alB[i] - r_gaB[i]) - C_[i][j+m] * 2.0/deltaT - C_[i+1][j+m] * r_gaB[i]; } Ck[i][m*NSpecies-1] = CB; // Set Delta'[0] and pointer to gamma_mod //std::vector<double>* ga_modZ; if(i < n_e) { //Ck[i][0] = 1.0 / (1.0 + exp(-Theta));//Nernst Ck[i][0] = 1.;//bulk condition (inverted coefficients) //ga_modZ = &ga_modZ1; } else { Ck[i][0] = 1.;//bulk condition (inverted coefficients) //ga_modZ = &ga_modZ2; } // Delta'[m>0] (we use the same vector as for concentrations...) //species A for(int j=1; j<m; j++) { if(i < n_e) { /* Ck[i][j] = ( Ck[i][j] - Ck[i][j-1] * z_al[j] ) / ( z_be[j] - (*ga_modZ)[j-1] * z_al[j] ); */ Ck[i][j] = ( Ck[i][j] - Ck[i][j-1] * z_al[j] ) / ( z_be[j] - ga_modZ1[j-1] * z_al[j] ); } else { /* Ck[i][j] = ( Ck[i][j] - Ck[i][j-1] * z2_al[j] ) / ( z2_be[j] - (*ga_modZ)[j-1] * z2_al[j] ); */ Ck[i][j] = ( Ck[i][j] - Ck[i][j-1] * z2_al[j] ) / ( z2_be[j] - ga_modZ2[j-1] * z2_al[j] ); } } //species B for(int j=0; j<m; j++) { if(i < n_e) { /*Ck[i][j+m] = ( Ck[i][j+m] - Ck[i][j+m-1] * z_al[j+m] ) / ( z_be[j+m] - (*ga_modZ)[j+m-1] * z_al[j+m] );*/ Ck[i][j+m] = ( Ck[i][j+m] - Ck[i][j+m-1] * z_al[j+m] ) / ( z_be[j+m] - ga_modZ1[j+m-1] * z_al[j+m] ); } else { /* Ck[i][j+m] = ( Ck[i][j+m] - Ck[i][j+m-1] * z2_al[j+m] ) / ( z2_be[j+m] - (*ga_modZ)[j+m-1] * z2_al[j+m] ); */ Ck[i][j+m] = ( Ck[i][j+m] - Ck[i][j+m-1] * z2_al[j+m] ) / ( z2_be[j+m] - ga_modZ2[j+m-1] * z2_al[j+m] ); } } //solve by back substitution Ck[i][m*NSpecies-1] = CB; for(int j=m*NSpecies-2; j>=0; j--) { if (i < n_e) Ck[i][j] = Ck[i][j]-ga_modZ1[j]*Ck[i][j+1]; else Ck[i][j] = Ck[i][j]-ga_modZ2[j]*Ck[i][j+1]; } } } // acc //copy concentration grid for(int i=0; i<n; i++) { for(int j=0; j<m*NSpecies; j++) { C_[i][j] = Ck[i][j]; } } // if (k % 100 == 0) { // #pragma acc update host(Ck) // for(int i=0; i<n; i++) // for(int j=0; j<m*NSpecies; j++) // Profiles << R[i] << "\t" << Z[j] << "\t" << Ck[i][j] << "\t" << Ck[i][j*NSpecies-1] << "\n"; // } // //Output current if (k % CadaCuantos == 0) { double flux = 0.0; for(int i=1; i<n_e; i++) { double J2 = (Ck[i][m-2] - Ck[i][m-1]) * R[i]; double J1 = (Ck[i-1][m-2] - Ck[i-1][m-1])*R[i-1]; flux -= (0.5/h0)*(J2+J1)*(R[i] - R[i-1]); } CV << Theta << "\t" << flux << "\n"; } //Output concentration profiles (only at the end) // if(k == stop - 1) // { // for(int j=0; j<m; j++) // { // for(int i=0; i<n; i++) // { // Profiles << R[i] << "\t" << Z[j] << "\t" << Ck[i][m-j-1] << "\t" << Ck[i][j+m] << "\n"; // } // } // } // //--- R SWEEP--- //#pragma omp parallel for //species A #pragma acc loop #pragma omp parallel for for(int j=1; j<m-1; j++) { // set Deltas Ck[0][j] = 0; Ck[n-1][j] = 1.0; for(int i=1; i<n-1; i++) { if(i < n_e) { Ck[i][j] = - C_[i][j-1] * z_al[j] - C_[i][j] * (-z_al[j] - z_ga[j]) - C_[i][j] * 2.0/deltaT - C_[i][j+1] * z_ga[j]; } else { Ck[i][j] = - C_[i][j-1] * z2_al[j] - C_[i][j] * (-z2_al[j] - z2_ga[j]) - C_[i][j] * 2.0/deltaT - C_[i][j+1] * z2_ga[j]; } } // modify deltas for(int i=1; i<n-1; i++) { Ck[i][j] = ( Ck[i][j] - Ck[i-1][j] * r_al[i] ) / ( r_be[i] - ga_modR[i-1] * r_al[i] ); } //solve by back substitution for(int i=n-2; i>=0; i--) { Ck[i][j] = Ck[i][j] - ga_modR[i]*Ck[i+1][j]; } } //species B //#pragma acc loop #pragma omp parallel for for(int j=1; j<m-1; j++) { // set Deltas Ck[0][j+m] = 0; Ck[n-1][j+m] = CB; for(int i=1; i<n-1; i++) { if(i < n_e) { Ck[i][j+m] = - C_[i][j+m-1] * z_al[j+m] - C_[i][j+m] * (-z_al[j+m] - z_ga[j+m]) - C_[i][j+m] * 2.0/deltaT - C_[i][j+m+1] * z_ga[j+m]; } else { Ck[i][j+m] = - C_[i][j+m-1] * z2_al[j+m] - C_[i][j+m] * (-z2_al[j+m] - z2_ga[j+m]) - C_[i][j+m] * 2.0/deltaT - C_[i][j+m+1] * z2_ga[j+m]; } } // modify deltas for(int i=1; i<n-1; i++) { Ck[i][j+m] = ( Ck[i][j+m] - Ck[i-1][j+m] * r_alB[i] ) / ( r_beB[i] - ga_modRB[i-1] * r_alB[i] ); } //solve by back substitution for(int i=n-2; i>=0; i--) { Ck[i][j+m] = Ck[i][j+m] - ga_modRB[i]*Ck[i+1][j+m]; } } } } // end of pragma acc data /****************** end simulation *************************************/ }
const char* abscode2string(__u16 code) { const char* result = "?"; #define CV(v) case v:result=#v;break; switch(code) { CV(ABS_X ); CV(ABS_Y ); CV(ABS_Z ); CV(ABS_RX ); CV(ABS_RY ); CV(ABS_RZ ); CV(ABS_THROTTLE ); CV(ABS_RUDDER ); CV(ABS_WHEEL ); CV(ABS_GAS ); CV(ABS_BRAKE ); CV(ABS_HAT0X ); CV(ABS_HAT0Y ); CV(ABS_HAT1X ); CV(ABS_HAT1Y ); CV(ABS_HAT2X ); CV(ABS_HAT2Y ); CV(ABS_HAT3X ); CV(ABS_HAT3Y ); CV(ABS_PRESSURE ); CV(ABS_DISTANCE ); CV(ABS_TILT_X ); CV(ABS_TILT_Y ); CV(ABS_TOOL_WIDTH ); CV(ABS_VOLUME ); CV(ABS_MISC ); CV(ABS_MT_SLOT ); CV(ABS_MT_TOUCH_MAJOR ); CV(ABS_MT_TOUCH_MINOR ); CV(ABS_MT_WIDTH_MAJOR ); CV(ABS_MT_WIDTH_MINOR ); CV(ABS_MT_ORIENTATION ); CV(ABS_MT_POSITION_X ); CV(ABS_MT_POSITION_Y ); CV(ABS_MT_TOOL_TYPE ); CV(ABS_MT_BLOB_ID ); CV(ABS_MT_TRACKING_ID ); CV(ABS_MT_PRESSURE ); CV(ABS_MT_DISTANCE ); } return result; }
const char* keycode2string(__u16 code) { const char* result = "?"; #define CV(v) case v:result=#v;break; switch(code) { // CV(BTN_DIGI); CV(BTN_TOOL_PEN); CV(BTN_TOOL_RUBBER); CV(BTN_TOOL_BRUSH); CV(BTN_TOOL_PENCIL); CV(BTN_TOOL_AIRBRUSH); CV(BTN_TOOL_FINGER); CV(BTN_TOOL_MOUSE); CV(BTN_TOOL_LENS); CV(BTN_TOOL_QUINTTAP); CV(BTN_TOUCH); CV(BTN_STYLUS); CV(BTN_STYLUS2); CV(BTN_TOOL_DOUBLETAP); CV(BTN_TOOL_TRIPLETAP); CV(BTN_TOOL_QUADTAP); } return result; }
[in[0][3] in[1][3] ...] [in[0][5] in[1][5] ...] ... [in[0][15] in[1][15] ...] */ #define key_idx(j) (((j)>>1)+8*((j)&1)) /* TK is expandeded Tweakey */ static void encrypt_tweakey (v16qu *restrict X, v16qu *restrict TK) { #if NSTEPS > 15 #error Round constant not implemented #endif static const v16qu RC[64] = { CV( 0), CV( 27), CV( 54), CV( 81), CV(108), CV(135), CV(162), CV(189), CV(216), CV(243), CV( 14), CV( 41), CV( 68), CV( 95), CV(122), CV(149), CV(176), CV(203), CV(230), CV( 1), CV( 28), CV( 55), CV( 82), CV(109), CV(136), CV(163), CV(190), CV(217), CV(244), CV( 15), CV( 42), CV( 69), CV( 96), CV(123), CV(150), CV(177), CV(204), CV(231), CV( 2), CV( 29), CV( 56), CV( 83), CV(110), CV(137), CV(164), CV(191), CV(218), CV(245), CV( 16), CV( 43), CV( 70), CV( 97), CV(124), CV(151), CV(178), CV(205), CV(232), CV( 3), CV( 30), CV( 57), CV( 84), CV(111), CV(138), CV(165), }; int t=0; int i,j; for (i=0; i<NSTEPS; i++) { // Key addition for (j=0; j<8; j++) {
void applyTemplate(uint8_t idx) #endif { MixData *md = &g_model.mixData[0]; //CC(STK) -> vSTK //ICC(vSTK) -> STK #define ICC(x) icc[(x)-1] uint8_t icc[4] = {0}; for(uint8_t i=1; i<=4; i++) //generate inverse array for(uint8_t j=1; j<=4; j++) if(CC(i)==j) icc[j-1]=i; #ifndef NO_TEMPLATES uint8_t j = 0; //Simple 4-Ch if(idx==j++) { #endif clearMixes(); md=setDest(ICC(STK_RUD)); md->srcRaw=CM(STK_RUD); md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_ELE); md=setDest(ICC(STK_THR)); md->srcRaw=CM(STK_THR); md=setDest(ICC(STK_AIL)); md->srcRaw=CM(STK_AIL); #ifndef NO_TEMPLATES } //T-Cut if(idx==j++) { md=setDest(ICC(STK_THR)); md->srcRaw=MIX_MAX; md->weight=-100; md->swtch=DSW_THR; md->mltpx=MLTPX_REP; } //sticky t-cut if(idx==j++) { md=setDest(ICC(STK_THR)); md->srcRaw=MIX_MAX; md->weight=-100; md->swtch=DSW_SWC; md->mltpx=MLTPX_REP; md=setDest(14); md->srcRaw=CH(14); md=setDest(14); md->srcRaw=MIX_MAX; md->weight=-100; md->swtch=DSW_SWB; md->mltpx=MLTPX_REP; md=setDest(14); md->srcRaw=MIX_MAX; md->swtch=DSW_THR; md->mltpx=MLTPX_REP; setSwitch(0xB,CS_VNEG, CM(STK_THR), -99); setSwitch(0xC,CS_VPOS, CH(14), 0); } //V-Tail if(idx==j++) { clearMixes(); md=setDest(ICC(STK_RUD)); md->srcRaw=CM(STK_RUD); md=setDest(ICC(STK_RUD)); md->srcRaw=CM(STK_ELE); md->weight=-100; md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_RUD); md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_ELE); } //Elevon\\Delta if(idx==j++) { clearMixes(); md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_ELE); md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_AIL); md=setDest(ICC(STK_AIL)); md->srcRaw=CM(STK_ELE); md=setDest(ICC(STK_AIL)); md->srcRaw=CM(STK_AIL); md->weight=-100; } //Heli Setup if(idx==j++) { clearMixes(); //This time we want a clean slate clearCurves(); //Set up Mixes //3 cyclic channels md=setDest(1); md->srcRaw=MIX_CYC1; md=setDest(2); md->srcRaw=MIX_CYC2; md=setDest(3); md->srcRaw=MIX_CYC3; //rudder md=setDest(4); md->srcRaw=CM(STK_RUD); //Throttle md=setDest(5); md->srcRaw=CM(STK_THR); md->swtch= DSW_ID0; md->curve=CV(1); md->carryTrim=TRIM_OFF; md=setDest(5); md->srcRaw=CM(STK_THR); md->swtch= DSW_ID1; md->curve=CV(2); md->carryTrim=TRIM_OFF; md=setDest(5); md->srcRaw=CM(STK_THR); md->swtch= DSW_ID2; md->curve=CV(3); md->carryTrim=TRIM_OFF; md=setDest(5); md->srcRaw=MIX_MAX; md->weight=-100; md->swtch= DSW_THR; md->mltpx=MLTPX_REP; //gyro gain md=setDest(6); md->srcRaw=MIX_FULL; md->weight=30; md->swtch=-DSW_GEA; //collective md=setDest(11); md->srcRaw=CM(STK_THR); md->weight=70; md->swtch= DSW_ID0; md->curve=CV(4); md->carryTrim=TRIM_OFF; md=setDest(11); md->srcRaw=CM(STK_THR); md->weight=70; md->swtch= DSW_ID1; md->curve=CV(5); md->carryTrim=TRIM_OFF; md=setDest(11); md->srcRaw=CM(STK_THR); md->weight=70; md->swtch= DSW_ID2; md->curve=CV(6); md->carryTrim=TRIM_OFF; g_model.swashType = SWASH_TYPE_120; g_model.swashCollectiveSource = CH(11); //Set up Curves setCurve(CURVE5(1),heli_ar1); setCurve(CURVE5(2),heli_ar2); setCurve(CURVE5(3),heli_ar3); setCurve(CURVE5(4),heli_ar4); setCurve(CURVE5(5),heli_ar5); setCurve(CURVE5(6),heli_ar5); } //Gyro Gain if(idx==j++) { md=setDest(6); md->srcRaw=STK_P2; md->weight= 50; md->swtch=-DSW_GEA; md->sOffset=100; md=setDest(6); md->srcRaw=STK_P2; md->weight=-50; md->swtch= DSW_GEA; md->sOffset=100; } //Servo Test if(idx==j++) { md=setDest(15); md->srcRaw=CH(16); md->speedUp = 8; md->speedDown = 8; md=setDest(16); md->srcRaw=MIX_FULL; md->weight= 110; md->swtch=DSW_SW1; md=setDest(16); md->srcRaw=MIX_MAX; md->weight=-110; md->swtch=DSW_SW2; md->mltpx=MLTPX_REP; md=setDest(16); md->srcRaw=MIX_MAX; md->weight= 110; md->swtch=DSW_SW3; md->mltpx=MLTPX_REP; setSwitch(1,CS_LESS,CH(15),CH(16)); setSwitch(2,CS_VPOS,CH(15), 105); setSwitch(3,CS_VNEG,CH(15), -105); } STORE_MODELVARS; eeWaitComplete() ; #endif }
#include <stdlib.h> #include <stdio.h> //#include "compat.h" #include "vector.h" //#define PRINT_SOME 0 // #define CV(x) { .u16 = {x, x, x, x, x, x, x, x}} const union cv V128 = CV(128); const union cv V255 = CV(255); const union cv V257 = CV(257); //static const union cv8 V0 = CV(0); /* Twiddle tables */ static const union cv FFT64_Twiddle[] = { {{1, 2, 4, 8, 16, 32, 64, 128}}, {{1, 60, 2, 120, 4, -17, 8, -34}}, {{1, 120, 8, -68, 64, -30, -2, 17}}, {{1, 46, 60, -67, 2, 92, 120, 123}}, {{1, 92, -17, -22, 32, 117, -30, 67}}, {{1, -67, 120, -73, 8, -22, -68, -70}}, {{1, 123, -34, -70, 128, 67, 17, 35}}, }; static const union cv FFT128_Twiddle[] = { {{ 1, -118, 46, -31, 60, 116, -67, -61}}, {{ 2, 21, 92, -62, 120, -25, 123, -122}}, {{ 4, 42, -73, -124, -17, -50, -11, 13}},