Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define CONST_CELERITY (double(299792458.0))
- #define CONST_BOLTZMANN (double(1.3806503e-23))
- #define CONST_PLANCK (double(1.054571726e-34))
- #define CONST_PI (double(3.141592653589793238))
- #define CONST_STEFAN (double(5.670400e-8))
- #define CONST_MAXSTEPS (100000)
- #define CONST_SPECTRAL_LUM (double(683.0))
- #define CONST_CALC (CONST_PLANCK/(CONST_PI*CONST_PI*CONST_CELERITY*CONST_CELERITY))
- // find the pulsation matching to a given wavelength in the vacuum
- #define omega(l) (2*CONST_PI*CONST_CELERITY/l)
- #define wavelength(o) (2*CONST_PI*CONST_CELERITY/o)
- #define I(t,o) (o*o*o/(exp(CONST_PLANCK*o/(CONST_BOLTZMANN*t))-1))
- // gaussian approximation
- #define V(o) (exp(-pow((wavelength(o)-559.1e-9)/42.4e-9, 2.0)/2))
- #define F(i,o) (i*V(o))
- int main( int argc, const char* argv[] )
- {
- if(argc < 5)
- {
- printf("missing parameters");
- return 1;
- }
- double temperature = strtod(argv[1], NULL), om_from = omega(strtod(argv[2], NULL)), om_to = omega(strtod(argv[3], NULL));
- if(om_from > om_to) { double aux = om_from; om_from = om_to; om_to = aux; }
- int steps = atoi(argv[4]);
- if(steps <= 0) return 1;
- double power = 0, power_coef = 0, cur = 0;
- double step = (om_to-om_from)/double((steps <= CONST_MAXSTEPS ? steps : CONST_MAXSTEPS));
- for(double omega = om_from; omega < om_to; omega += step)
- {
- cur = (1.0/4.0)*I(temperature, omega);
- power += cur;
- power_coef += F(cur, omega);
- }
- power *= CONST_CALC * step;
- power_coef *= CONST_CALC * step;
- double lum = CONST_SPECTRAL_LUM * power_coef;
- double total = CONST_STEFAN * temperature * temperature * temperature * temperature;
- // power.calculated(W/m²) total.power(W/m²) error visible.power(W/m²) visible.power/total, efficiency(L/W)
- printf("%lf %lf %lf %lf %lf %lf", power, total, power/total, power_coef, power_coef/total, lum/total);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement