Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

AdaptiveRepulsionData.cpp

Go to the documentation of this file.
00001 /**
00002  * Implementation of AdaptiveRepulsionData.
00003  * @file AdaptiveRepulsionData.cpp
00004  * @author Ed Bachta
00005  */
00006 
00007 #include "AdaptiveRepulsionData.h"
00008 
00009 REGISTER_PARTICLESTUFF(AdaptiveRepulsionData,"Attribute:AdaptiveRepulsionData");
00010 
00011 // Witkin-Heckbert recommended values.
00012 #define WH_ALPHA 6.0
00013 
00014 int AdaptiveRepulsionData::qlen() { return 6; }
00015 
00016 void AdaptiveRepulsionData::getq(double *q)
00017 {
00018         q[0] = sigma_hat;
00019         q[1] = sigma_max;
00020         q[2] = diameter;
00021         q[3] = alpha;
00022         q[4] = Ehat;
00023         q[5] = sdmul;
00024 }
00025 
00026 void AdaptiveRepulsionData::setq(double *q)
00027 {
00028         sigma_hat = q[0];
00029         sigma_max = q[1];
00030         diameter = q[2];
00031         alpha = q[3];
00032         Ehat = q[4];
00033         sdmul = q[5];
00034 }
00035 
00036 void AdaptiveRepulsionData::qname(char **qn)
00037 {
00038         qn[0] = "Desired repulsion radius (sigma hat)";
00039         qn[1] = "Max repulation radius (sigma max)";
00040         qn[2] = "Expected surface diameter";
00041         qn[3] = "Repulsion amplitude (alpha)";
00042         qn[4] = "Desired energy (Ehat)";
00043         qn[5] = "# of StdDev's away that repul = 0";
00044 }
00045 
00046 int AdaptiveRepulsionData::qlenpp()
00047 {
00048         return 3;
00049 }
00050 
00051 void AdaptiveRepulsionData::getqpp(double *q, int i)
00052 {       
00053         q[0] = r[i];
00054         q[1] = dr[i];
00055         q[2] = D[i];
00056 }
00057 
00058 void AdaptiveRepulsionData::setqpp(double *q, int i)
00059 {
00060         r[i] = q[0];
00061         dr[i] = q[1];
00062         D[i] = q[2];
00063 }
00064 
00065 void AdaptiveRepulsionData::qnamepp(char **qn)
00066 {
00067         qn[0] = "Repulsion radius (sigma)";
00068         qn[1] = "Repulsion radius change (sigma dot)";
00069         qn[2] = "Energy (D)"; 
00070 }
00071 
00072 /** Sets the particle system for which the
00073  * AdaptiveRepulsionData applies.
00074  * If new_ps is not NULL, then the lengths of internal arrays
00075  * of particle data are set to the size of the the particle
00076  * system.
00077  */
00078 void AdaptiveRepulsionData::setParticleSystem(Particles *new_ps)
00079 {
00080         ParticleAttribute::setParticleSystem(new_ps);
00081         if (ps)
00082         {
00083                 r.resize(ps->size(), 1.0);
00084                 dr.resize(ps->size(), 0.0);
00085                 D.resize(ps->size(), 0.0);
00086         }
00087 }
00088 
00089 
00090 /**
00091  * Attach to a particle system. Sets default constant values and 
00092  * initializes particle data.
00093  * @param ps   The owning particle system.
00094  * @param name The name of this attribute.
00095  */
00096 AdaptiveRepulsionData::AdaptiveRepulsionData(Particles* ps, std::string name)
00097   : ParticleAttribute(ps, name)
00098 {
00099         alpha = WH_ALPHA;
00100         Ehat = 0.8 * alpha;     
00101         sdmul = 3.0;
00102 }
00103 
00104 
00105 /**
00106  * Callback for particle removal.
00107  * @param i Index of particle to be removed.
00108  * @see ParticleAttribute::particleRemoved
00109  */
00110 void AdaptiveRepulsionData::particleRemoved(unsigned int i)
00111 {
00112 
00113         // Copy end element to ith position
00114         r[i]  = r.back();
00115         dr[i] = dr.back();
00116         D[i]  = D.back();
00117 
00118         // Pop off the end
00119         r.pop_back();
00120         dr.pop_back();
00121         D.pop_back();
00122 
00123 }
00124 
00125 /** 
00126  * Callback for particle addition.
00127  * @param i Index of the particle that has been added.
00128  */
00129 void AdaptiveRepulsionData::particleAdded(unsigned int i) 
00130 {
00131         double rad = 1.0;
00132 
00133         r.push_back(rad);
00134         dr.push_back(0.0);
00135         D.push_back(0.0);
00136 } 
00137 
00138 void AdaptiveRepulsionData::clear()
00139 {
00140         r.clear();
00141         dr.clear();
00142         D.clear();
00143 }
00144 
00145 void AdaptiveRepulsionData::integrate(double dt)
00146 {
00147         for(unsigned int i=0;i<r.size();i++) 
00148         {
00149                 r[i] += dr[i]*dt;
00150                 // Seems to be more stable if I do not make all of them positive here
00151                 //r[i] = fabs(r[i]);
00152                 //if (r[i] > .5)
00153                 //      r[i] = sigma_max;
00154                 //if (r[i] < -.5)
00155                 //      r[i] = -sigma_max;
00156         }
00157 }

Generated on Mon Jun 28 14:58:12 2004 for Advanced Surface Library by doxygen 1.3.4