SHARE
TWEET

Rendement filament

lucasgautheron Nov 3rd, 2012 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define CONST_CELERITY (double(299792458.0))
  6. #define CONST_BOLTZMANN (double(1.3806503e-23))
  7. #define CONST_PLANCK (double(1.054571726e-34))
  8. #define CONST_PI (double(3.141592653589793238))
  9. #define CONST_STEFAN (double(5.670400e-8))
  10. #define CONST_MAXSTEPS (100000)
  11. #define CONST_SPECTRAL_LUM (double(683.0))
  12.  
  13. #define CONST_CALC (CONST_PLANCK/(CONST_PI*CONST_PI*CONST_CELERITY*CONST_CELERITY))
  14.  
  15. // find the pulsation matching to a given wavelength in the vacuum
  16. #define omega(l) (2*CONST_PI*CONST_CELERITY/l)
  17. #define wavelength(o) (2*CONST_PI*CONST_CELERITY/o)
  18.  
  19. #define I(t,o) (o*o*o/(exp(CONST_PLANCK*o/(CONST_BOLTZMANN*t))-1))
  20.  
  21. // gaussian approximation
  22. #define V(o) (exp(-pow((wavelength(o)-559.1e-9)/42.4e-9, 2.0)/2))
  23.  
  24. #define F(i,o) (i*V(o))
  25.  
  26. int main( int argc, const char* argv[] )
  27. {
  28.     if(argc < 5)
  29.     {
  30.         printf("missing parameters");
  31.         return 1;
  32.     }
  33.  
  34.     double temperature = strtod(argv[1], NULL), om_from = omega(strtod(argv[2], NULL)), om_to = omega(strtod(argv[3], NULL));
  35.     if(om_from > om_to) { double aux = om_from; om_from = om_to; om_to = aux; }
  36.     int steps = atoi(argv[4]);
  37.     if(steps <= 0) return 1;
  38.  
  39.     double power = 0, power_coef = 0, cur = 0;
  40.     double step = (om_to-om_from)/double((steps <= CONST_MAXSTEPS ? steps : CONST_MAXSTEPS));
  41.  
  42.     for(double omega = om_from; omega < om_to; omega += step)
  43.     {
  44.         cur = (1.0/4.0)*I(temperature, omega);
  45.         power += cur;
  46.         power_coef += F(cur, omega);
  47.     }
  48.  
  49.     power *= CONST_CALC * step;
  50.     power_coef *= CONST_CALC * step;
  51.     double lum = CONST_SPECTRAL_LUM * power_coef;
  52.  
  53.     double total = CONST_STEFAN * temperature * temperature * temperature * temperature;
  54.  
  55.     // power.calculated(W/m²)   total.power(W/m²)   error   visible.power(W/m²) visible.power/total, efficiency(L/W)
  56.     printf("%lf %lf %lf %lf %lf %lf", power, total, power/total, power_coef, power_coef/total, lum/total);
  57. }
RAW Paste Data
Top