Esempio n. 1
0
Real
RndSmoothCircleIC::computeCircleValue(const Point & p, const Point & center, const Real & radius)
{
  Point l_center = center;
  Point l_p = p;
  if (!_3D_spheres) //Create 3D cylinders instead of spheres
  {
    l_p(2) = 0.0;
    l_center(2) = 0.0;
  }
  //Compute the distance between the current point and the center
  Real dist = _mesh.minPeriodicDistance(_var.number(), l_p, l_center);

  //Return value
  Real value = 0.0;

  if (dist <= radius - _int_width / 2.0) //Random value inside circle
    value = _invalue - _variation_invalue + 2.0 * _random.rand(_tid) * _variation_invalue;
  else if (dist < radius + _int_width / 2.0) //Smooth interface
  {
    Real int_pos = (dist - radius + _int_width/2.0) / _int_width;
    value = _outvalue + (_invalue - _outvalue) * (1.0 + std::cos(int_pos * libMesh::pi)) / 2.0;
  }
  else //Random value outside circle
    value = _outvalue - _variation_outvalue + 2.0 * _random.rand(_tid) * _variation_outvalue;

  return value;
}
Esempio n. 2
0
Point
SmoothCircleBaseIC::computeCircleGradient(const Point & p, const Point & center, const Real & radius)
{
  Point l_center = center;
  Point l_p = p;
  if (!_3D_spheres) //Create 3D cylinders instead of spheres
  {
    l_p(2) = 0.0;
    l_center(2) = 0.0;
  }
  //Compute the distance between the current point and the center
  Real dist = _mesh.minPeriodicDistance(_var.number(), l_p, l_center);

  Real DvalueDr = 0.0;

  if (dist < radius + _int_width/2.0 && dist > radius - _int_width/2.0)
  {
    Real int_pos = (dist - radius + _int_width / 2.0) / _int_width;
    Real Dint_posDr = 1.0 / _int_width;
    DvalueDr = Dint_posDr * (_invalue - _outvalue) * (-std::sin(int_pos * libMesh::pi) * libMesh::pi) / 2.0;
  }

  //Set gradient over the smooth interface
  if (dist != 0.0)
    return _mesh.minPeriodicVector(_var.number(), center, p) * (DvalueDr / dist);
  else
    return Gradient(0.0, 0.0, 0.0);

}
Esempio n. 3
0
RealGradient
SmoothCircleBaseIC::computeCircleGradient(const Point & p,
                                          const Point & center,
                                          const Real & radius)
{
  Point l_center = center;
  Point l_p = p;
  if (!_3D_spheres) // Create 3D cylinders instead of spheres
  {
    l_p(2) = 0.0;
    l_center(2) = 0.0;
  }
  // Compute the distance between the current point and the center
  Real dist = _mesh.minPeriodicDistance(_var.number(), l_p, l_center);

  // early return if we are probing the center of the circle
  if (dist == 0.0)
    return 0.0;

  Real DvalueDr = 0.0;
  switch (_profile)
  {
    case ProfileType::COS:
      if (dist < radius + _int_width / 2.0 && dist > radius - _int_width / 2.0)
      {
        const Real int_pos = (dist - radius + _int_width / 2.0) / _int_width;
        const Real Dint_posDr = 1.0 / _int_width;
        DvalueDr = Dint_posDr * (_invalue - _outvalue) *
                   (-std::sin(int_pos * libMesh::pi) * libMesh::pi) / 2.0;
      }
      break;

    case ProfileType::TANH:
      DvalueDr = -(_invalue - _outvalue) * 0.5 / _int_width * libMesh::pi *
                 (1.0 - Utility::pow<2>(std::tanh(4.0 * (radius - dist) / _int_width)));
      break;

    default:
      mooseError("Internal error.");
  }

  return _mesh.minPeriodicVector(_var.number(), center, p) * (DvalueDr / dist);
}
Esempio n. 4
0
Real
SmoothCircleBaseIC::computeCircleValue(const Point & p, const Point & center, const Real & radius)
{
  Point l_center = center;
  Point l_p = p;
  if (!_3D_spheres) // Create 3D cylinders instead of spheres
  {
    l_p(2) = 0.0;
    l_center(2) = 0.0;
  }
  // Compute the distance between the current point and the center
  Real dist = _mesh.minPeriodicDistance(_var.number(), l_p, l_center);

  switch (_profile)
  {
    case ProfileType::COS:
    {
      // Return value
      Real value = _outvalue; // Outside circle

      if (dist <= radius - _int_width / 2.0) // Inside circle
        value = _invalue;
      else if (dist < radius + _int_width / 2.0) // Smooth interface
      {
        Real int_pos = (dist - radius + _int_width / 2.0) / _int_width;
        value = _outvalue + (_invalue - _outvalue) * (1.0 + std::cos(int_pos * libMesh::pi)) / 2.0;
      }
      return value;
    }

    case ProfileType::TANH:
      return (_invalue - _outvalue) * 0.5 *
                 (std::tanh(libMesh::pi * (radius - dist) / _int_width) + 1.0) +
             _outvalue;

    default:
      mooseError("Internal error.");
  }
}
Esempio n. 5
0
  vector< pair< string, float > > distance::recherche(string s)
  {
    vector< pair< string, float > > to_return;
    float vec[max_size];
    for (a = 0; a < N; a++) bestd[a] = 0;
    for (a = 0; a < N; a++) bestw[a][0] = 0;
//     printf("Enter word or sentence (EXIT to break): ");
    a = 0;
//     while (1) {
//       st1[a] = fgetc(stdin);
//       if ((st1[a] == '\n') || (a >= max_size - 1)) {
//         st1[a] = 0;
//         break;
//       }
//       a++;
//     }
    char st1[max_size];
    strcpy(st1, s.c_str());
//     st1 = s.c_str();
//     if (!strcmp(st1, "EXIT")) break;
    cn = 0;
    b = 0;
    c = 0;
    while (1) {
      st[cn][b] = st1[c];
      b++;
      c++;
      st[cn][b] = 0;
      if (st1[c] == 0) break;
      if (st1[c] == ' ') {
        cn++;
        b = 0;
        c++;
      }
    }
    cn++;
    for (a = 0; a < cn; a++) {
      for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break;
      if (b == words) b = -1;
      bi[a] = b;
//       printf("\nWord: %s  Position in vocabulary: %lld\n", st[a], bi[a]);
      if (b == -1) {
// 	printf("%s: Out of dictionary word!\n",st[a]);
        return to_return;
      }
    }
    if (b == -1) return to_return;
//     printf("\n                                              Word       Cosine distance\n------------------------------------------------------------------------\n");
    for (a = 0; a < size; a++) vec[a] = 0;
    for (b = 0; b < cn; b++) {
      if (bi[b] == -1) continue;
      for (a = 0; a < size; a++) vec[a] += M[a + bi[b] * size];
    }
    len = 0;
    for (a = 0; a < size; a++) len += vec[a] * vec[a];
    len = sqrt(len);
    for (a = 0; a < size; a++) vec[a] /= len;
    for (a = 0; a < N; a++) bestd[a] = -1;
    for (a = 0; a < N; a++) bestw[a][0] = 0;
    for (c = 0; c < words; c++) {
      a = 0;
      for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
      if (a == 1) continue;
      dist = 0;
      for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size];
      for (a = 0; a < N; a++) {
        if (dist > bestd[a]) {
          for (d = N - 1; d > a; d--) {
            bestd[d] = bestd[d - 1];
            strcpy(bestw[d], bestw[d - 1]);
          }
          bestd[a] = dist;
          strcpy(bestw[a], &vocab[c * max_w]);
          break;
        }
      }
    }
    
//       for (a = 0; a < N && a < 10 ; a++) 
// 	printf("%50s\t\t%f\n", bestw[a], bestd[a]);
    for (a = 0; a < N; a++) 
    {
      pair<string,float> l_p( string(bestw[a]), bestd[a]);
//       printf("%50s\t\t%f\n", bestw[a], bestd[a]);
      to_return.push_back(l_p);
    }
    return to_return;
  }