Пример #1
0
int main() {
  body b1, b2;
  double rhs1[BODY_VECTOR_SIZE], rhs2[BODY_VECTOR_SIZE];
  gsl_rng *rng;
  double eps;
  const double epsabs = 1e-8;
  double ori1, ori2;
  double magdot1, magdot2;

  rng = gsl_rng_alloc(gsl_rng_ranlxd2);
  eps = gsl_rng_uniform(rng);

  init_random_body(rng, &b1, 1e-1*gsl_rng_uniform(rng), 1.0+gsl_rng_uniform(rng), 1.0/0.0, 0.0, 0.0, 0.0);
  init_random_body(rng, &b2, 2e-2*gsl_rng_uniform(rng), 2.0+gsl_rng_uniform(rng), 1.0/0.0, 0.0, 0.0, 0.0);

  average_rhs(eps, &b1, &b2, epsabs, rhs1);
  average_rhs(eps, &b2, &b1, epsabs, rhs2);

  magdot1 = dot(b1.A, &(rhs1[BODY_A_INDEX])) + dot(b1.L, &(rhs1[BODY_L_INDEX]));
  magdot2 = dot(b2.A, &(rhs2[BODY_A_INDEX])) + dot(b2.L, &(rhs2[BODY_L_INDEX]));

  if (!check_close(10.0*epsabs, 0.0, magdot1, 0.0)) {
    fprintf(stderr, "L1*L1dot + A1*A1dot != 0 (%g)\n", magdot1);
    return 1;
  }

  if (!check_close(10.0*epsabs, 0.0, magdot2, 0.0)) {
    fprintf(stderr, "L2*L2dot + A2*A2dot != 0\n");
    return 2;
  }

  ori1 = dot(b1.A, &(rhs1[BODY_L_INDEX])) + dot(b1.L, &(rhs1[BODY_A_INDEX]));
  ori2 = dot(b2.A, &(rhs2[BODY_L_INDEX])) + dot(b2.L, &(rhs2[BODY_A_INDEX]));

  if (!check_close(10.0*epsabs, 0.0, ori1, 0.0)) {
    fprintf(stderr, "L1*A1dot + A1*L1dot != 0\n");
    return 1;
  }

  if (!check_close(10.0*epsabs, 0.0, ori2, 0.0)) {
    fprintf(stderr, "L2*A2dot + A2*L2dot != 0\n");
    return 1;
  }
    
  gsl_rng_free(rng);

  return 0;
}
Пример #2
0
void test_hankel(T, const char* name)
{
   std::cout << "Testing type " << name << std::endl;

   static const boost::array<boost::array<std::complex<T>, 4>, 16> data = 
   {{
      // Values are v, z, J, and Y.
      // H1 and H2 are calculated from functions.wolfram.com.
      {{ 0, 1, static_cast<T>(0.765197686557966551449717526102663220909274289755325241861548L), static_cast<T>(0.0882569642156769579829267660235151628278175230906755467110438L) }},
      {{ 20, 15.5, static_cast<T>(0.0114685669049540880132573889173945340441319848974792913849131L), static_cast<T>(-2.23357703561803241011539677726233479433825678625142168545338L) }},
      {{ 202, 65, static_cast<T>(4.03123907894335908039069177339845754619082182624766366629474e-77L), static_cast<T>(-4.12853948338543234456930697819285129000267780751856135651604e73L) }},
      {{ 1.25, 2.25, static_cast<T>(0.548918751190427983177518806565451279306141559548962787802891L), static_cast<T>(-0.125900744882628421758627761371862848797979705547465002154794L) }},
      {{ -20, 15.5, static_cast<T>(0.0114685669049540880132573889173945340441319848974792913849131L), static_cast<T>(-2.23357703561803241011539677726233479433825678625142168545338L) }},
      {{ -20, -15.5,  static_cast<T>(0.0114685669049540880132573889173945340441319848974792913849131L), std::complex<T>(static_cast<T>(-2.23357703561803241011539677726233479433825678625142168545338L), static_cast<T>(0.02293713380990817602651477783478906808826396979495858276983L))}},
      {{ 1.25, -1.5, std::complex<T>(static_cast<T>(-0.335713500965919366139805990226845134897000581426417882156072L),  static_cast<T>(-0.335713500965919366139805990226845134897000581426417882156072L)), std::complex<T>(static_cast<T>(0.392747687664481978664420363126684555843062241632017696636768L), static_cast<T>(-1.064174689596320710944032343580374825637063404484853460948911L)) }},
      {{ -1.25, -1.5, std::complex<T>(static_cast<T>(0.515099846311769525023685454389374962206960751452481078650112L),  static_cast<T>(-0.515099846311769525023685454389374962206960751452481078650112L)), std::complex<T>(static_cast<T>(-0.040329260174013212604062774398331485097569895404765001721544L), static_cast<T>(0.989870432449525837443308134380418439316351607500197155578680L)) }},
      {{ 4, 4, static_cast<T>(0.281129064961360106322277160229942806897088617059328870629222L), static_cast<T>(-0.488936768533842510615657398339913206218740182079627974737267L) }},
      {{ 4, -4, static_cast<T>(0.281129064961360106322277160229942806897088617059328870629222L), std::complex<T>(static_cast<T>(-0.488936768533842510615657398339913206218740182079627974737267L), static_cast<T>(0.562258129922720212644554320459885613794177234118657741258443L)) }},
      {{ -4, 4, static_cast<T>(0.281129064961360106322277160229942806897088617059328870629222L), static_cast<T>(-0.488936768533842510615657398339913206218740182079627974737267L) }},
      {{ -4, -4, static_cast<T>(0.281129064961360106322277160229942806897088617059328870629222), std::complex<T>(static_cast<T>(-0.488936768533842510615657398339913206218740182079627974737267), static_cast<T>(0.562258129922720212644554320459885613794177234118657741258443L)) }},
      {{ 3, 3, static_cast<T>(0.309062722255251643618260194946833149429135935993056794354475L), static_cast<T>(-0.538541616105031618004703905338594463807957863604859251481262L) }},
      {{ 3, -3, static_cast<T>(-0.309062722255251643618260194946833149429135935993056794354475L), std::complex<T>(static_cast<T>(0.538541616105031618004703905338594463807957863604859251481262L), static_cast<T>(-0.618125444510503287236520389893666298858271871986113588708949L)) }},
      {{ -3, 3, static_cast<T>(-0.309062722255251643618260194946833149429135935993056794354475L), static_cast<T>(0.538541616105031618004703905338594463807957863604859251481262L) }},
      {{ -3, -3, static_cast<T>(0.309062722255251643618260194946833149429135935993056794354475L), std::complex<T>(static_cast<T>(-0.538541616105031618004703905338594463807957863604859251481262L), static_cast<T>(0.618125444510503287236520389893666298858271871986113588708949L)) }},
   }};

   std::complex<T> im(0, 1);
   for(unsigned i = 0; i < data.size(); ++i)
   {
      if((i != 2) || (std::numeric_limits<T>::max_exponent10 > 80))
      {
         check_close(boost::math::cyl_hankel_1(data[i][0].real(), data[i][1].real()), data[i][2] + im * data[i][3]);
         check_close(boost::math::cyl_hankel_2(data[i][0].real(), data[i][1].real()), data[i][2] - im * data[i][3]);

         check_close(
            boost::math::cyl_hankel_1(data[i][0].real() + 0.5f, data[i][1].real()) * boost::math::constants::root_half_pi<T>() / sqrt(data[i][1]),
            boost::math::sph_hankel_1(data[i][0].real(), data[i][1].real()));
         check_close(
            boost::math::cyl_hankel_2(data[i][0].real() + 0.5f, data[i][1].real()) * boost::math::constants::root_half_pi<T>() / sqrt(data[i][1]),
            boost::math::sph_hankel_2(data[i][0].real(), data[i][1].real()));
      }
   }
}
Пример #3
0
int main(int argv, char** argc)
{
  check_init();
  check_start("clib -- libdatrie -- trie");
  test_trie_tree_states();
  test_datrie_states();
  test_datrie();
  check_end();
  check_close();
  return 0;
}
int main() {
  body b1, b2;
  gsl_rng *rng;
  double eps;
  const double epsabs = 1e-8;
  double rhs1[BODY_VECTOR_SIZE], rhs2[BODY_VECTOR_SIZE];
  double Ldot[3];
  double n1, n2;
  double m1, m2;
  double a1, a2;
  int i;

  rng = gsl_rng_alloc(gsl_rng_ranlxd2);

  eps = gsl_rng_uniform(rng);

  a1 = 1.0+gsl_rng_uniform(rng);
  a2 = 2.0+gsl_rng_uniform(rng);
  m1 = 1e-3*gsl_rng_uniform(rng);
  m2 = 1e-4*gsl_rng_uniform(rng);

  init_random_body(rng, &b1, m1, a1, 1.0/0.0, 0.0, 0.0, 0.0);
  init_random_body(rng, &b2, m2, a2, 1.0/0.0, 0.0, 0.0, 0.0);

  n1 = mean_motion(&b1);
  n2 = mean_motion(&b2);

  average_rhs(eps, &b1, &b2, epsabs, rhs1);
  average_rhs(eps, &b2, &b1, epsabs, rhs2);

  for (i = 0; i < 3; i++) {
    Ldot[i] = m1*n1*a1*a1*rhs1[BODY_L_INDEX+i] + m2*n2*a2*a2*rhs2[BODY_L_INDEX+i];
  }

  if (!check_close(10.0*epsabs, 0.0, norm(Ldot), 0.0)) {
    fprintf(stderr, "Ldot != 0, instead {%g, %g, %g}\n", Ldot[0], Ldot[1], Ldot[2]);
    return 1;
  }

  gsl_rng_free(rng);
  return 0;
}
Пример #5
0
int main() {
  const double RScale = 0.1;
  const double AScale = 1.0;
  const double IScale = 1e-2;
  const double MScale = 1.0;
  const double tVScale = 1.0;
  const double kScale = 0.1;

  const double eps = 1e-12;

  gsl_rng *rng;

  double SpinSun[3];
  double tVSun, kSun, ISun, MSun, RSun;

  double zerov[3] = {0.0, 0.0, 0.0};

  body b;
  central_body bc;

  double n;
  double a2;
  double adot;
  double ndot;
  double mu;

  double body_rhs[BODY_VECTOR_SIZE];
  double sun_rhs[3];

  double Ldot[3], hdot[3], bLdot[3], sLdot[3];

  int i;

  rng = gsl_rng_alloc(gsl_rng_ranlxd2);
  assert(rng);

  seed_random(rng);

  init_body_from_elements(&b, MScale*gsl_rng_uniform(rng), AScale*gsl_rng_uniform(rng), gsl_rng_uniform(rng),
                          180.0*gsl_rng_uniform(rng), 360.0*gsl_rng_uniform(rng), 360.0*gsl_rng_uniform(rng), 
                          zerov, tVScale*gsl_rng_uniform(rng), kScale*gsl_rng_uniform(rng), 
                          IScale*gsl_rng_uniform(rng), RScale*gsl_rng_uniform(rng));

  random_vector(rng, b.spin, 1.0);
  random_vector(rng, SpinSun, 1.0);
  
  tVSun = tVScale*gsl_rng_uniform(rng);
  kSun = kScale*gsl_rng_uniform(rng);
  ISun = IScale*gsl_rng_uniform(rng);
  RSun = RScale*gsl_rng_uniform(rng);

  init_central_body(&bc, tVSun, kSun, ISun, RSun, SpinSun);

  tidal_rhs(&b, &bc, body_rhs, sun_rhs);

  n = mean_motion(&b);
  a2 = b.a*b.a;

  adot = body_rhs[BODY_a_INDEX];
  ndot = -3.0/2.0*adot/b.a*n;

  mu = b.m/(1.0+b.m);

  for (i = 0; i < 3; i++) {
    hdot[i] = mu*n*a2*(body_rhs[BODY_L_INDEX+i] + 0.5*(adot/b.a)*b.L[i]);
    bLdot[i] = b.I*body_rhs[BODY_SPIN_INDEX+i];
    sLdot[i] = ISun*sun_rhs[i];
    Ldot[i] = hdot[i] + bLdot[i] + sLdot[i];
  }

  if (!check_close(eps, eps, norm(Ldot), 0.0)) {
    fprintf(stderr, "Ldot = {%g, %g, %g} not close to zero!\n",
            Ldot[0], Ldot[1], Ldot[2]);
    fprintf(stderr, "mu*hdot = {%g, %g, %g}\n", hdot[0], hdot[1], hdot[2]);
    fprintf(stderr, "Body LDot = {%g, %g, %g}\n", bLdot[0], bLdot[1], bLdot[2]);
    fprintf(stderr, "Sun  LDot = {%g, %g, %g}\n", sLdot[0], sLdot[1], sLdot[2]);
    gsl_rng_free(rng);
    exit(1);
  }

  if (!check_close(eps, eps, dot(b.L, body_rhs + BODY_L_INDEX) + dot(b.A, body_rhs + BODY_A_INDEX), 0.0)) {
    fprintf(stderr, "A^2 + L^2 = 1.0 magnitude constraint violated!\n");
    exit(1);
  }

  if (!check_close(eps, eps, dot(b.L, body_rhs + BODY_A_INDEX) + dot(b.A, body_rhs + BODY_L_INDEX), 0.0)) {
    fprintf(stderr, "A*L = 0 constraint violated!\n");
    exit(1);
  }

  gsl_rng_free(rng);
  return 0;
}
static void test_close(skiatest::Reporter* reporter) {
    SkPath closePt;
    closePt.moveTo(0, 0);
    closePt.close();
    check_close(reporter, closePt);

    SkPath openPt;
    openPt.moveTo(0, 0);
    check_close(reporter, openPt);

    SkPath empty;
    check_close(reporter, empty);
    empty.close();
    check_close(reporter, empty);

    SkPath rect;
    rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
    check_close(reporter, rect);
    rect.close();
    check_close(reporter, rect);

    SkPath quad;
    quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
    check_close(reporter, quad);
    quad.close();
    check_close(reporter, quad);

    SkPath cubic;
    quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 
                 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1);
    check_close(reporter, cubic);
    cubic.close();
    check_close(reporter, cubic);

    SkPath line;
    line.moveTo(SK_Scalar1, SK_Scalar1);
    line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1);
    check_close(reporter, line);
    line.close();
    check_close(reporter, line);

    SkPath rect2;
    rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
    rect2.close();
    rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
    check_close(reporter, rect2);
    rect2.close();
    check_close(reporter, rect2);

    SkPath oval3;
    oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100));
    oval3.close();
    oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200));
    check_close(reporter, oval3);
    oval3.close();
    check_close(reporter, oval3);

    SkPath moves;
    moves.moveTo(SK_Scalar1, SK_Scalar1);
    moves.moveTo(5 * SK_Scalar1, SK_Scalar1);
    moves.moveTo(SK_Scalar1, 10 * SK_Scalar1);
    moves.moveTo(10 *SK_Scalar1, SK_Scalar1);
    check_close(reporter, moves);

    stroke_tiny_cubic();
}
Пример #7
0
int 
_read(SSL_CTX *ctx, int sockfd) {
  char buf[2000];
  struct sockaddr_in6 src;
  int len, ifindex, i;
  char addr[INET6_ADDRSTRLEN];
  char port[6];
  socklen_t sz = sizeof(struct sockaddr_in6);
#ifdef WITH_DTLS
  SSL *ssl;
  int err;
#endif

  /* Retrieve remote address and interface index as well as the first
     few bytes of the message to demultiplex protocols. */
  memset(&src, 0, sizeof(struct sockaddr_in6));
  len = check_connect(sockfd, buf, 4, (struct sockaddr *)&src, &ifindex);

  if (len < 0)			/* error */
    return len;

#ifndef NDEBUG
  fprintf(stderr,"received packet");
  
  if (getnameinfo((struct sockaddr *)&src, sizeof(src), 
		  addr, sizeof(addr), port, sizeof(port), 
		  NI_NUMERICHOST | NI_NUMERICSERV) == 0)
    fprintf(stderr," from [%s]:%s", addr, port);
  
  fprintf(stderr," on interface %d\n", ifindex);
#endif

  switch (demux_protocol(buf, len)) {
#ifdef WITH_DTLS
  case DTLS :
    ssl = get_ssl(ctx, sockfd, (struct sockaddr *)&src, ifindex);
    if (!ssl) {
      fprintf(stderr, "cannot create new SSL object\n");
      /*      return recv(sockfd, buf, sizeof(buf), MSG_DONTWAIT);*/
      len = recvfrom(sockfd, buf, sizeof(buf), MSG_DONTWAIT,
		     (struct sockaddr *)&src, &sz);
      getnameinfo((struct sockaddr *)&src, sz, 
		  addr, sizeof(addr), port, sizeof(port), 
		  NI_NUMERICHOST | NI_NUMERICSERV);
      printf("discarded %d bytes from [%s]:%s\n", len, addr, port);      
      return len;
    }
    len = SSL_read(ssl, buf, sizeof(buf));
    break;
#endif
  case UNKNOWN:
  default :
    len = recv(sockfd, buf, sizeof(buf), MSG_DONTWAIT);
  }

  if (len > 0) {
    printf("here is the data:\n");
    for (i=0; i<len; i++)
      printf("%c",buf[i]);
  } if (len == 0) {		/* session closed? */
#ifdef WITH_DTLS
    if (check_close(ssl) <= 0) {
      fprintf(stderr, "not closed\n");
    }
#endif
  } else {
#ifdef WITH_DTLS
    err = SSL_get_error(ssl,len);
    switch (err) {
    case SSL_ERROR_WANT_READ:
      fprintf(stderr, "SSL_ERROR_WANT_READ\n");
      return 0;
    case SSL_ERROR_WANT_WRITE:
      fprintf(stderr, "SSL_ERROR_WANT_WRITE\n");
      return 0;
    default:
      fprintf(stderr, "read: SSL error %d: %s\n", err,
	      ERR_error_string(err, NULL));
      return 0;
    }
#else
    perror("recv");
#endif
  }

  return len;
}