home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / xgas / xgas.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-12  |  3.8 KB  |  141 lines

  1. /*
  2.  * xgas.h
  3.  *   gas: Copyright 1990 Larry Medwin: @(#)gas.h    1.6 2/9/90
  4.  *   Larry Medwin Dec. 15, 1989, April 1991
  5.  */
  6.  
  7. #include <X11/StringDefs.h>
  8. #include <X11/Intrinsic.h>
  9. #include <X11/Xaw/Form.h>
  10. #include <X11/Xaw/Command.h>
  11. #include <X11/Xaw/Label.h>
  12. #include <X11/Xaw/Scrollbar.h>
  13. #include <X11/Xaw/Box.h>
  14. #include <X11/Xaw/AsciiText.h>
  15. #include <X11/Xaw/Toggle.h>
  16. #include "XGas.h"
  17. #include <X11/Xutil.h>
  18. #include <X11/Xlib.h>
  19. #include <math.h>
  20.  
  21. /* Force the numerical instability out into the open */
  22. #define double float
  23.  
  24. #define NWALLS 6
  25. #define MOLECULE_SIZE 4
  26. #define KB 1.38062e-16        /* Boltzmann's constant in ergs/degree */
  27. #define MASS 3.32e-24        /* H2 molecule mass in grams */
  28. #define MAXTEMP 500        /* degrees K */
  29. #define INITTEMP 300            /* initial value */
  30. #define SMALL 1.0e-10        /* effectively zero */
  31. #define TWO_PI 2.0 * 3.14159265358979323846
  32. #ifndef M_PI_2
  33. #define M_PI_2 1.57079632679489661923
  34. #endif
  35.  
  36. typedef struct _Coord {
  37.     int x, y;
  38. } Coord;
  39.  
  40. /* Walls and Corners */
  41. typedef struct _WallType {
  42.     Coord wallReflect;        /* to compute reflection angle */
  43.     int toRotate[2][2];        /* rotate to canonical orientation */
  44.     int fromRotate[2][2];        /* rotate from canonical orientation */
  45. } WallType;
  46.  
  47. /* Wall orientations */
  48. #define TOP 0
  49. #define RIGHT 1
  50. #define BOTTOM 2
  51. #define LEFT 3
  52.  
  53. /* Corner orientations */
  54. #define NW 4
  55. #define SW 5
  56. #define SE 6
  57. #define NE 7
  58.  
  59. extern WallType WallParam[];    /* Defined in gas.c */
  60.  
  61. typedef struct _Wall {
  62.     Coord end[2];        /* endpoints of line (first nearer origin) */
  63.     int type;            /* TOP, RIGHT, BOTTOM, LEFT */
  64. } Wall;
  65.  
  66. /* Molecules */
  67.  
  68. typedef struct _Molecule {
  69.     float temperature;        /* Kinetic energy in degrees Kelvin */
  70.     double xCoeff[2];        /* coefficients of parametric equation */
  71.     double yCoeff[2];        /* coefficients of parametric equation */
  72.     Coord pos;            /* current position */
  73.     Coord collisionPos;        /* point on wall of next collision */
  74.     float collisionTime;        /* microseconds until next collision */
  75.     Wall *collisionWall;    /* wall of next collision */
  76.     int thisBox;        /* array index of box the molecule is "in" */
  77. } Molecule;
  78.  
  79. #ifdef ENHANCEMENT
  80. /* Enhancement: different kinds of molecules: */
  81.     GC thisGC;            /* Graphics Context for this molecule */
  82.     Pixmap thisPixmap;        /* Pixmap for this molecule */
  83.     float mass;            /* Molecular mass */
  84. #endif
  85.  
  86. /* Chamber */
  87.  
  88. typedef struct _Box {
  89.     Wall walls[ NWALLS ];    /* walls[0] is the hole */
  90.     Widget control;        /* scrollbar to control temperature */
  91.     Widget display;        /* readout of temperature */
  92.     float temperature;        /* in degrees K */
  93. } Box;
  94.  
  95. /* Client data structure */
  96. typedef struct _labData {
  97.     Dimension width, height;    /* in pixels */
  98.     float widthMM, heightMM;    /* in millimeters */
  99.     Coord scale;
  100.     Box chamber[2];
  101.     int nmolecules;
  102.     Molecule *molecules;    /* was [MAXMOLECULES] */
  103.     XRectangle *allPos;        /* was [MAXMOLECULES][2]last & current pos */
  104.     float time;            /* Simulated time */
  105.     int timestep;        /* number of this timestep */
  106.  
  107.     /* Resources */
  108.     float timestepSize;    /* resolution of simulated time in microseconds */
  109.     int delay;        /* delay between calls to doTimestep */
  110.     float randomBounce;    /* randomness of collision: 0 none, 1 all */
  111.     float equilibrium;    /* approach to equilibrium: 0 never,1 immediate */
  112.     int maxMolecules;    /* number allowed */
  113.     Pixel background, foreground;
  114.  
  115.     /* X stuff */
  116.     Widget lab;
  117.     Widget clock;
  118.     GC WallGC, MoleculeGC;
  119.     XtIntervalId timer;
  120. } LabData, *LabDataPtr;
  121.  
  122. /* Forward references */
  123. /* in dynamics.c: */
  124.     void findNextCollision();
  125.     void dynamics();
  126.     void doTimestep();
  127.     void run_callback();
  128.     void pause_callback();
  129.     void oneTimestep();
  130. /* in chamber.c */
  131.     int whichCorner();
  132.     void labInit();
  133.     void labResize();
  134.     void labExpose();
  135.     void addMolecules();
  136.     void changeTemp();
  137.     float vEquilibrium();
  138.     float frand();
  139. /* in util.c */
  140.     void quit_callback();
  141.