//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= // Program orbital //=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= #include "cip.h" #include "nxgraph.h" //---- definition of fundermental constants //---- physical settings const double Z = 1.0; //---- experimental settings const double DX = 0.0625; // size of cell const int R_NUM = 256; // total number of cell const int R_FAR = R_NUM-1; // index of farthest cell const double R_O = 160; // index of Bohr radius const int TH_NUM = 128; // number of polar cell const double DTH = M_PI/TH_NUM; // step of polar angle const int PH_NUM = 128; // number of azimuthal cell const double DPH = 2*M_PI/PH_NUM; // step of azimuthal angle //---- graphics settings const int PLOT_NUM = 2048; const int WIN_HEIGHT = 256; const int WIN_WIDTH = 256; const double MAG = 8.0; //---- prototypes of functions void CalcRadial( int n, int l, double Frad[] ); void CalcPolar( int l, int m, double Fthe[] ); void CalcAzimuthal( int m, double Fphi[] ); void Accumulate( int n, double f[], double S[] ); int Sample( int n, double S[] ); void DetectOrbital( short x[], short y[], short z[], double Srad[], double Sthe[], double Sphi[] ); void DrawOrbital( double the, short x[], short y[], short z[] ); //---- table of Radius class RTable { double r[R_NUM]; public: RTable( void ){ for( int i=0 ; i<=R_FAR ; i++ ){ r[i] = (1.0/Z)*exp(DX*(i-R_O)); } } inline double operator [] ( int i ){ return r[i]; } } R; //---- main function int main( void ) { int n, l, m; double Frad[R_NUM], Fthe[TH_NUM], Fphi[PH_NUM]; double Srad[R_NUM], Sthe[TH_NUM], Sphi[PH_NUM]; short x[PLOT_NUM], y[PLOT_NUM], z[PLOT_NUM]; XEvent ev; NXOpenWindow("Orbital of Hydrogen Atom", WIN_WIDTH, WIN_HEIGHT ); NXEnable( NX_DOUBLEBUFFER ); for( l=0 ; l<=2 ; l++ ){ n = l+1; for( m=+l ; m>=-l ; m-- ){ printf("(n,l,m)=(% d,% d,% d)\n", n, l, m ); CalcRadial( n, l, Frad ); Accumulate( R_NUM, Frad, Srad ); CalcPolar( l, m, Fthe ); Accumulate( TH_NUM, Fthe, Sthe ); CalcAzimuthal( m, Fphi ); Accumulate( PH_NUM, Fphi, Sphi ); DetectOrbital( x, y, z, Srad, Sthe, Sphi ); for( double the=0.0 ; the < 2*M_PI ; the+=0.0625 ){ DrawOrbital( the, x, y, z ); NXCheckEvent( NX_NOWAIT, ev ); if( ev.type == KeyPress ){ if( ev.xkey.keycode == 'q' ) goto LOOPOUT; if( ev.xkey.keycode == 'n' ) break; } } } } LOOPOUT:; NXCloseWindow(); return 0; } //---- calculate distribution of radial wave function void CalcRadial( int n, int l, double Frad[] ) { if( n==1 ){ for( int i=0 ; i 0 ){ Fphi[i] = sqr(cos(m*DPH*i)); }else if( m < 0 ){ Fphi[i] = sqr(sin(m*DPH*i)); } } } //---- accumulate distribution void Accumulate( int n, double f[], double S[] ) { int i; double sum, norm; // accumulate area for( i=0, sum=0.0 ; i r ) break; return i; } //---- detect electron many times void DetectOrbital( short x[], short y[], short z[], double Srad[], double Sthe[], double Sphi[] ) { for( int i=0 ; i