void create_widget(const dictionary_t&       parameters,
                   size_enum_t               size,
                   display_number_t*&        display_number)
{
    std::string name;
    std::string alt_text;
    theme_t     theme(implementation::size_to_theme(size));
    long        characters(5);
    unit_t      default_unit(to_unit(parameters));

    std::vector<unit_t> unit_set;

    get_value(parameters, key_name, name);
    get_value(parameters, key_alt_text, alt_text);
    get_value(parameters, key_characters, characters);

    if (parameters.count(key_units) == 0)
    {
        unit_set.push_back(default_unit);
    }
    else
    {
        array_t unit_array(get_value(parameters, key_units).cast<array_t>());

        for (array_t::iterator iter(unit_array.begin()), last(unit_array.end());
             iter != last; ++iter)
            unit_set.push_back(to_unit(iter->cast<dictionary_t>(), default_unit));
    }

    display_number = new display_number_t(name, alt_text, unit_set.begin(),
                                          unit_set.end(), theme, characters);
}
bool write_ctx::writeAngleValue(value v)
{
    UNIT_TYPE u;
    int n = to_unit(v,u);
    return s->put(CsFaslTagAngle)
        && s->put_int( n )
        && s->put_int( u );
}
bool write_ctx::writeLengthValue(value v)
{
    UNIT_TYPE u;
    int n = to_unit(v,u);
    return s->put(CsFaslTagLength)
        && s->put_int( n )
        && s->put_int( u );
}
  constexpr void build_vertices(OutputIt output, Function func) const noexcept
  {
    const auto dir = vec3<float_type>{0, 0, 1};
    const auto top = [&dir]() noexcept
    {
      auto top = dir.cross({0, 1, 0});
      if(top.magnitude() == 0) {
        top = {0, 0, 1};
      }
      return top.to_unit();
    }
    ();
    const auto right = top.cross(dir);

    for(auto i = size_type{0}; i < latitude_divs; ++i) {
      constexpr auto pi = M_PI;

      const auto theta = pi / latitude_divs * i;
      const auto sin_theta = std::sin(theta);
      const auto cos_theta = std::cos(theta);

      const auto next_i = i + 1;
      const auto next_theta = pi / latitude_divs * next_i;
      const auto next_sint = std::sin(next_theta);
      const auto next_cost = std::cos(next_theta);

      for(auto j = size_type{0}; j <= longitude_divs; ++j) {
        const auto phi = pi * 2 * j / longitude_divs;
        const auto sin_phi = std::sin(phi);
        const auto cos_phi = std::cos(phi);

        const auto vx = right * cos_phi;
        const auto vy = top * sin_phi;
        const auto n = vx + vy;

        {
          const auto norm = dir * cos_theta + n * sin_theta;

          *output++ = func(norm);

          if(j == 0) {
            *output++ = func(norm);
          }
        }

        {
          const auto norm = dir * next_cost + n * next_sint;

          *output++ = func(norm);

          if(j == longitude_divs) {
            *output++ = func(norm);
          }
        }
      }
    }
  }
Exemple #5
0
int progressbar::update(double now)
{
  time_t tnow;

  time(&tnow);

  const time_t elapsed = tnow - _time_started;

  bool force_update = false;

#ifdef WITH_RESIZE
  if (recv_sigwinch && _mode == normal)
    {
      const size_t old_term_width = _term_width;

      _term_width = get_term_width();

      if (!_term_width)
        _term_width = default_term_width;

      if (_term_width != old_term_width)
        {
          _width = _term_width;
          force_update = true;
        }

      recv_sigwinch = 0;
    }
#endif // WITH_RESIZE

  const bool inactive = now == 0;

  if (!_done)
    {
      if ((elapsed - _last_update) < _update_interval
          && !force_update)
        {
          return 0;
        }
    }
  else
    now = _expected_bytes;

  // Current size.

  const double size =
    (!_done)
    ? _initial_bytes + now
    : now;

  std::stringstream size_s;

  size_s.setf(std::ios::fixed);

  size_s
      << std::setprecision(1)
      << to_mb(size)
      << "M";

  // Rate.

  double rate = elapsed ? (now/elapsed):0;

  std::stringstream rate_s, eta_s;

  rate_s.setf(std::ios::fixed);
  eta_s.setf(std::ios::fixed);

  if (!inactive)
    {
      // ETA.

      std::string eta;

      if (!_done)
        {
          const double left =
            (_expected_bytes - (now + _initial_bytes)) / rate;

          eta = to_s(static_cast<int>(left+0.5));
        }
      else
        {
          rate = (_expected_bytes - _initial_bytes) / elapsed;
          eta  = to_s(elapsed);
        }

      std::string unit = to_unit(rate);

      rate_s
          << std::setw(4)
          << std::setprecision(1)
          << rate
          << unit;

      eta_s
          << std::setw(6)
          << eta;
    }
  else   // ETA: inactive (default).
    {
      rate_s << "--.-K/s";
      eta_s << "--:--:--";
    }

  // Percent.

  std::stringstream percent_s;
  int percent = 0;

  if (_expected_bytes > 0)
    {
      percent = static_cast<int>(100.0*size/_expected_bytes);

      if (percent < 100)
        percent_s << std::setw(2) << percent << "%";
      else
        percent_s << "100%";
    }

  // Filename.

  fs::path p = fs::system_complete(_file.path());

#if BOOST_FILESYSTEM_VERSION > 2
  std::string fname = p.filename().string();
#else
  std::string fname = p.filename();
#endif

  switch (_mode)
    {
    default:
    case  normal:
      _normal(size_s, rate_s, eta_s, percent, percent_s);
      break;
    case dotline:
      _dotline(size_s, rate_s, eta_s, percent_s);
      break;
    case simple:
      _simple(size_s, percent_s);
      break;
    }

  _last_update = elapsed;
  _count       = now;

  return 0;
}
Exemple #6
0
/* Calculate SCF coefficients based on particle distribution */ 
void SCF_calc_from_particles(void)
{
 double r, un, unm1, costh, sinth, phi, xi;
 double plm1m,plm2m,temp1,temp2,temp3;
 int n,l,m;
 int i;
 double x, y, z, mass;

  
 for(i = 0; i < NumPart; i++)
  { 
   /* consider only DM particles of SCF coefficients */
   if (P[i].Type != 1)
    continue;

   /* scale to unit hernquist sphere */
   to_unit(P[i].Pos[0], P[i].Pos[1], P[i].Pos[2], &x, &y, &z);
   mass = P[i].Mass /SCF_HQ_MASS;
   
   /* OR: not */
   //x = P[i].Pos[0]; y = P[i].Pos[1]; z = P[i].Pos[2];
   //mass = P[i].Mass;

   /* particle coordinate transformation */
   r = sqrt(x * x + y * y + z * z);
   costh=z/r; 
   phi=atan2(y,x);
   xi=(r-1.)/(r+1.);
   sinth=sqrt(1.-costh*costh);
      
   for (m=0; m<=SCF_LMAX; m++) 
    {
     cosmphi[m]=cos(m*phi);           
     sinmphi[m]=sin(m*phi);
    } 

   /* Ultraspherical polynomials */
   for (l=0; l<=SCF_LMAX; l++) 
    {
     ultrasp[nl(0,l)]=1.0;
     if (SCF_NMAX>0)
      {
       ultrasp[nl(1,l)]=(2.0*(2.*l+1.5))*xi;     
       un=ultrasp[nl(1,l)];
       unm1=1.0;       

       /* recursion */
       for(n=1; n<=SCF_NMAX-1; n++)
        {
         ultrasp[nl(n+1,l)]=((2.0*n+(2.0*(2.*l+1.5)))*xi*un-(1.0*n-1.0+(2.0*(2.*l+1.5)))*unm1)*1.0/(n+1.0);
         unm1=un;
         un=ultrasp[nl(n+1,l)];                
        }
      }   

     for (n=0; n<=SCF_NMAX; n++) 
      {
       ultraspt[nl(n,l)]=ultrasp[nl(n,l)]*Anltilde[nl(n,l)];
      }
    }
  
   /* Legendre polynomials */  
   for (m=0; m<=SCF_LMAX; m++) 
    {
     plm[lm(m,m)]=1.0;
     if (m>0) 
      plm[lm(m,m)]=-pow(1,m)*dblfact[m]*pow(sinth,m);
     plm1m=plm[lm(m,m)];
     plm2m=0.0;
     /* recursion */
     for (l=m+1; l<=SCF_LMAX; l++) 
      {
       plm[lm(l,m)]=(costh*(2.*l-1.)*plm1m-(l+m-1.)*plm2m)/(l-m);
       plm2m=plm1m;
       plm1m=plm[lm(l,m)];
     }       
    }

   for (l=0; l<=SCF_LMAX; l++) 
    {
     temp1=pow(r,l)/pow(1.+r,2*l+1)*mass;        
     for (m=0; m<=l; m++) 
      {
       temp2=temp1*plm[lm(l,m)]*coeflm[lm(l,m)]*sinmphi[m];
       temp3=temp1*plm[lm(l,m)]*coeflm[lm(l,m)]*cosmphi[m];
       for (n=0; n<=SCF_NMAX; n++) 
        {
	 sinsum[nlm(n,l,m)]+=temp2*ultraspt[nl(n,l)];
	 cossum[nlm(n,l,m)]+=temp3*ultraspt[nl(n,l)];
        } 
      } 
    }
  }  
}