src/statics.hpp

Go to the documentation of this file.
00001 //
00002 // Ephi - simulation of magnetic fields and particles
00003 // Copyright (C) 2007 Indrek Mandre <indrek(at)mare.ee>
00004 // For more information please see http://www.mare.ee/indrek/ephi/
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License along
00017 // with this program; if not, write to the Free Software Foundation, Inc.,
00018 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00019 //
00020 
00021 #ifndef __statics_hpp__
00022 #define __statics_hpp__
00023 
00024 #include <vector>
00025 #include <string>
00026 
00027 #include "math3d.hpp"
00028 #include "utils.hpp"
00029 #include "screen.hpp"
00030 
00031 class Screen;
00032 class CoilData;
00033 
00035 class StaticElement
00036 {
00037 public:
00038   virtual ~StaticElement ();
00039 
00041   virtual void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield) = 0;
00042 
00044   virtual void addPotential (const vect3d& pos, prec_t& potential) = 0;
00045 
00047   virtual void draw(Screen& screen, const Screen::color& c = Screen::BLACK) = 0;
00049   virtual std::string get_povray_script () = 0;
00051   virtual bool inContact (const vect3d& pos) = 0;
00052 };
00053 
00055 class StaticIntegrated : public StaticElement
00056 {
00057 public:
00059   struct POSF
00060   {
00061     virtual void get_pos (prec_t t, vect3d& out) = 0;
00062     virtual void get_slope (prec_t t, vect3d& out) = 0;
00063     virtual ~POSF() { }
00064   };
00065 
00068   void setCharge (prec_t qpm);
00069 
00070 protected:
00071   StaticIntegrated (prec_t currentAMPS, prec_t wire_radius, POSF *posf);
00072   virtual ~StaticIntegrated ();
00073 
00074   // StaticElement interface
00075   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00076   void draw(Screen& screen, const Screen::color& c = Screen::BLACK);
00077   bool inContact (const vect3d& pos);
00078 
00079   void addPotential (const vect3d& pos, prec_t& potential) { }
00080 
00081 protected:
00082   POSF *posf;
00083   prec_t currentAMPS;
00084   prec_t wr;
00085 
00086 private:
00087   prec_t qpm;
00088 
00089   prec_t KmI;
00090 
00091   struct entry
00092   {
00093     vect3d middle;
00094     vect3d slope;
00095     prec_t qmod;
00096   };
00097 
00098   std::vector<entry> elist;
00099 
00100   void *calcmap_mem;
00101   entry *calcmap_begin;
00102   entry *calcmap_end;
00103 
00104   array16<prec_t> sse2_data;
00105   size_t sse2_consume;
00106 
00107   vect3d mid;
00108   prec_t gr;
00109   prec_t max_rm;
00110 
00111   vect3d plane_normal;
00112   prec_t pi_plane_d;
00113   prec_t min_d, max_d;
00114 };
00115 
00117 class StaticBezier : public StaticIntegrated
00118 {
00119 public:
00120   StaticBezier (prec_t currentAMPS, prec_t wire_radius,
00121       const vect3d& p0, const vect3d& p1, const vect3d& p2, const vect3d& p3);
00122   virtual ~StaticBezier ();
00123 
00124   std::string get_povray_script ();
00125 
00126 private:
00127   vect3d p0, p1, p2, p3;
00128 };
00129 
00131 class RingBase : public StaticIntegrated::POSF
00132 {
00133 public:
00134   RingBase (prec_t currentAMPS, const vect3d& pos, prec_t radius, prec_t wire_radius, const vect3d& normal);
00135   virtual ~RingBase () { }
00136 
00137   std::string get_povray_script ();
00138   bool inContact (const vect3d& pos);
00139   void ringbase_draw (Screen& screen, const Screen::color& c);
00140 
00141 protected:
00142   prec_t current;
00143   vect3d pos;
00144   prec_t radius;
00145   prec_t wire_radius;
00146   vect3d normal;
00147   prec_t plane_d;
00148 
00149   prec_t wrwr;
00150   prec_t min_rr, max_rr;
00151   vect3d nr;
00152   vect3d runit;
00153   vect3d lr;
00154 
00155   void get_pos (prec_t t, vect3d& out);
00156   void get_slope (prec_t t, vect3d& out);
00157   void get_closest (prec_t cosphi, vect3d& out1, vect3d& out2);
00158 
00159 protected:
00160   vect3d p0;
00161   vect3d p0_pc;
00162   vect3d nXp0_pc;
00163 };
00164 
00166 class StaticRingIntegrated : public RingBase, public StaticIntegrated
00167 {
00168 public:
00169   StaticRingIntegrated (prec_t currentAMPS, const vect3d& pos, prec_t radius, prec_t wire_radius, const vect3d& normal);
00170   virtual ~StaticRingIntegrated ();
00171 
00172   std::string get_povray_script ();
00173   bool inContact (const vect3d& pos);
00174 };
00175 
00177 class StaticRing : public RingBase, public StaticElement
00178 {
00179 public:
00180   StaticRing (prec_t currentAMPS, const vect3d& pos, prec_t radius, prec_t wire_radius, const vect3d& normal);
00181   virtual ~StaticRing ();
00182 
00183   // StaticElement interface
00184   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00185   void draw(Screen& screen, const Screen::color& c = Screen::BLACK);
00186   std::string get_povray_script ();
00187   bool inContact (const vect3d& pos);
00188   void setCharge (prec_t qpm);
00189   void addPotential (const vect3d& pos, prec_t& potential) { }
00190 
00191 private:
00192   prec_t bfact;
00193   prec_t efact;
00194   prec_t charge;
00195   prec_t R, RR;
00196 };
00197 
00199 class StaticLineBase : public StaticElement
00200 {
00201 public:
00202   StaticLineBase (const vect3d& p0, const vect3d& p1, prec_t radius);
00203 
00204   void draw(Screen& screen, const Screen::color& c = Screen::BLACK);
00205   std::string get_povray_script ();
00206   bool inContact (const vect3d& pos);
00207 
00208 protected:
00209   vect3d p0, p1;
00210   prec_t radius;
00211   vect3d l;
00212   prec_t l_len;
00213   vect3d ln;
00214 
00215   vect3d mid;
00216   vect3d lr;
00217   prec_t rr, dfms;
00218 };
00219 
00221 class StaticLine : public StaticLineBase
00222 {
00223 public:
00224   StaticLine (prec_t currentAMPS, const vect3d& p0, const vect3d& p1, prec_t radius);
00225 
00226   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00227   void addPotential (const vect3d& pos, prec_t& potential) { }
00228 
00229 private:
00230   prec_t currentAMPS;
00231   prec_t KmI;
00232 };
00233 
00235 class StaticLineInfinite : public StaticElement
00236 {
00237 public:
00238   StaticLineInfinite (prec_t currentAMPS, const vect3d& p0, const vect3d& dir, prec_t radius);
00239 
00240   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00241   void draw(Screen& screen, const Screen::color& c = Screen::BLACK);
00242   std::string get_povray_script ();
00243   bool inContact (const vect3d& pos);
00244   void addPotential (const vect3d& pos, prec_t& potential) { }
00245 
00246 private:
00247   prec_t currentAMPS;
00248   vect3d p0;
00249   vect3d normal;
00250   prec_t radius;
00251   vect3d lnormal;
00252   prec_t KmI2;
00253   prec_t rr;
00254 };
00255 
00257 class StaticRectangle : public StaticElement
00258 {
00259 public:
00260   StaticRectangle(prec_t currentAMPS, const vect3d& pos, const vect3d& right, const vect3d& up, prec_t wr);
00261   virtual ~StaticRectangle ();
00262 
00263   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00264   void draw(Screen& screen, const Screen::color& c = Screen::BLACK);
00265   std::string get_povray_script ();
00266   bool inContact (const vect3d& pos);
00267   void addPotential (const vect3d& pos, prec_t& potential) { }
00268 
00269 private:
00270   vect3d p1, p2, p3, p4;
00271   prec_t wr;
00272   StaticLine *l1, *l2, *l3, *l4;
00273 
00274   std::string make_povsegment (const vect3d& n1, prec_t d1, const vect3d& n2, prec_t d2,
00275       const vect3d& p1, const vect3d& p2);
00276 };
00277 
00278 class StaticCIBase : public StaticElement
00279 {
00280 public:
00281   StaticCIBase (const CoilData& cd, const vect3d& pos, const vect3d& normal, prec_t realI, prec_t realqpm);
00282   virtual ~StaticCIBase ();
00283 
00284   void draw(Screen& screen, const Screen::color& c = Screen::BLACK);
00285   std::string get_povray_script ();
00286   bool inContact (const vect3d& pos);
00287   void addPotential (const vect3d& pos, prec_t& potential) { }
00288 
00289 protected:
00290   const CoilData& data;
00291   vect3d pos, normal;
00292   prec_t realI, realQ;
00293   vect3d lr;
00294 };
00295 
00297 class StaticCINN : public StaticCIBase
00298 {
00299 public:
00300   StaticCINN (const CoilData& cd, const vect3d& pos, const vect3d& normal, prec_t realI, prec_t realqpm);
00301   virtual ~StaticCINN();
00302 
00303   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00304 };
00305 
00307 class StaticCICU : public StaticCIBase
00308 {
00309 public:
00310   StaticCICU (const CoilData& cd, const vect3d& pos, const vect3d& normal, prec_t realI, prec_t realqpm);
00311   virtual ~StaticCICU();
00312 
00313   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00314 };
00315 
00317 class StaticCIL : public StaticCIBase
00318 {
00319 public:
00320   StaticCIL (const CoilData& cd, const vect3d& pos, const vect3d& normal, prec_t realI, prec_t realqpm);
00321   virtual ~StaticCIL();
00322 
00323   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00324 };
00325 
00326 class StaticLineCharge : public StaticLineBase
00327 {
00328 public:
00329   StaticLineCharge (const vect3d& p0, const vect3d& p1, prec_t rho0, prec_t rho1, prec_t blotradius = 0.0);
00330 
00331   void addPotential (const vect3d& pos, prec_t& potential);
00332   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00333 
00334 private:
00335   prec_t rho0, rho1;
00336   prec_t rhodiff;
00337   prec_t rhodiff_by_llen;
00338   prec_t mod;
00339 };
00340 
00342 class StaticChargedSphere : public StaticElement
00343 {
00344 public:
00345   StaticChargedSphere (const vect3d& pos, prec_t radius, prec_t q);
00346   virtual ~StaticChargedSphere ();
00347 
00348   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00349   void addPotential (const vect3d& pos, prec_t& potential);
00350   void draw(Screen& screen, const Screen::color& c = Screen::BLACK);
00351   std::string get_povray_script ();
00352   bool inContact (const vect3d& pos);
00353 
00354 private:
00355   vect3d pos;
00356   prec_t radius;
00357   prec_t q;
00358   prec_t qmod;
00359   prec_t radiusradius;
00360 };
00361 
00362 class Octree;
00363 
00365 class StaticCubePolywellOctree : public StaticElement
00366 {
00367 public:
00368   StaticCubePolywellOctree (Octree& tree, bool do_bfield, bool do_efield,
00369       prec_t radius, prec_t wr, prec_t spacing);
00370   void addFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00371   void addPotential (const vect3d& pos, prec_t& potential);
00372   virtual void draw(Screen& screen, const Screen::color& c = Screen::BLACK);
00373   virtual std::string get_povray_script ();
00374   virtual bool inContact (const vect3d& pos);
00375 
00376 private:
00377   Octree &tree;
00378   bool do_bfield, do_efield;
00379   std::vector<RingBase*> bases;
00380 };
00381 
00383 class Statics
00384 {
00385 public:
00386   Statics ();
00387   ~Statics ();
00388 
00391   void addStaticElement (StaticElement *addElement);
00392 
00394   void getFields (const vect3d& pos, vect3d& bfield, vect3d& efield);
00395 
00397   bool inContact (const vect3d& pos);
00398 
00400   void setAmbientBField (const vect3d& abfield) { ambient_bfield = abfield; }
00402   void setAmbientEField (const vect3d& aefield) { ambient_efield = aefield; }
00403 
00405   void draw(Screen& screen, const Screen::color& c = Screen::BLACK);
00406 
00408   std::string get_povray_script ();
00409 
00411   static prec_t get_ddsq ();
00413   static void set_ddsq (prec_t ddsq);
00414 
00416   prec_t getPotential(const vect3d& pos);
00417 
00418 private:
00419   vect3d ambient_bfield, ambient_efield;
00420   typedef std::vector<StaticElement *> strips_t;
00421   strips_t strips;
00422 };
00423 
00424 #endif // !__statics_hpp__
00425 

Generated on Thu Dec 6 20:31:14 2007 for Ephi by  doxygen 1.5.0