step/stepcore
gas.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #ifndef STEPCORE_GAS_H
00024 #define STEPCORE_GAS_H
00025
00026 #include "particle.h"
00027 #include "world.h"
00028 #include <cmath>
00029
00030 namespace StepCore {
00031
00032 class GasParticle;
00033 class GasLJForce;
00034 class Gas;
00035
00039 class GasParticle: public Particle
00040 {
00041 STEPCORE_OBJECT(GasParticle)
00042
00043 public:
00045 explicit GasParticle(Vector2d position = Vector2d(0), Vector2d velocity = Vector2d(0), double mass = 1)
00046 : Particle(position, velocity, mass) {}
00047 };
00048
00052 class GasLJForceErrors: public ObjectErrors
00053 {
00054 STEPCORE_OBJECT(GasLJForceErrors)
00055
00056 public:
00058 GasLJForceErrors(Item* owner = 0)
00059 : ObjectErrors(owner), _depthVariance(0), _rminVariance(0) {}
00060
00062 GasLJForce* gasLJForce() const;
00063
00065 double depthVariance() const { return _depthVariance; }
00067 void setDepthVariance(double depthVariance) { _depthVariance = depthVariance; }
00068
00070 double rminVariance() const { return _rminVariance; }
00072 void setRminVariance(double rminVariance) { _rminVariance = rminVariance; }
00073
00074 protected:
00075 double _depthVariance;
00076 double _rminVariance;
00077 friend class GasLJForce;
00078 };
00079
00099 class GasLJForce: public Item, public Force
00100 {
00101 STEPCORE_OBJECT(GasLJForce)
00102
00103 public:
00105 explicit GasLJForce(double depth = 1, double rmin = 1, double cutoff = HUGE_VAL);
00106
00107 void calcForce(bool calcVariances);
00108
00110 double depth() const { return _depth; }
00112 void setDepth(double depth) { _depth = depth; calcABC(); }
00113
00115 double rmin() const { return _rmin; }
00117 void setRmin(double rmin) { _rmin = rmin; calcABC(); }
00118
00120 double cutoff() const { return _cutoff; }
00122 void setCutoff(double cutoff) { _cutoff = cutoff; calcABC(); }
00123
00125 GasLJForceErrors* gasLJForceErrors() {
00126 return static_cast<GasLJForceErrors*>(objectErrors()); }
00127
00128 protected:
00129 ObjectErrors* createObjectErrors() { return new GasLJForceErrors(this); }
00130 void calcABC();
00131
00132 double _depth;
00133 double _rmin;
00134 double _cutoff;
00135 double _a, _b, _c;
00136 double _rmin6, _rmin12;
00137 };
00138
00139 typedef std::vector<GasParticle*> GasParticleList;
00140
00144 class GasErrors: public ObjectErrors
00145 {
00146 STEPCORE_OBJECT(GasErrors)
00147
00148 public:
00150 GasErrors(Item* owner = 0)
00151 : ObjectErrors(owner) {}
00152
00154 Gas* gas() const;
00155
00156 double rectTemperatureVariance() const;
00157 double rectPressureVariance() const;
00158 Vector2d rectMeanVelocityVariance() const;
00159 double rectMeanKineticEnergyVariance() const;
00160 double rectMeanParticleMassVariance() const;
00161 double rectMassVariance() const;
00162
00163 protected:
00164 friend class Gas;
00165 };
00166
00170 class Gas: public ItemGroup
00171 {
00172 STEPCORE_OBJECT(Gas)
00173
00174 public:
00175 Gas() : _measureRectCenter(0), _measureRectSize(1,1) {
00176 setColor(0xffff0000); objectErrors();
00177 }
00178
00181 GasParticleList rectCreateParticles(int count,
00182 double mass, double temperature,
00183 const Vector2d& meanVelocity);
00184
00185 void addParticles(const GasParticleList& particles);
00186
00187 double rectVolume() const;
00188 double rectParticleCount() const;
00189 double rectConcentration() const;
00190 double rectTemperature() const;
00191 double rectPressure() const;
00192 Vector2d rectMeanVelocity() const;
00193 double rectMeanKineticEnergy() const;
00194 double rectMeanParticleMass() const;
00195 double rectMass() const;
00196
00197 const Vector2d& measureRectCenter() const { return _measureRectCenter; }
00198 void setMeasureRectCenter(const Vector2d& measureRectCenter) { _measureRectCenter = measureRectCenter; }
00199
00200 const Vector2d& measureRectSize() const { return _measureRectSize; }
00201 void setMeasureRectSize(const Vector2d& measureRectSize) { _measureRectSize = measureRectSize.cAbs(); }
00202
00204 GasErrors* gasErrors() {
00205 return static_cast<GasErrors*>(objectErrors()); }
00206
00207 protected:
00208 ObjectErrors* createObjectErrors() { return new GasErrors(this); }
00209
00210 double randomUniform(double min=0, double max=1);
00211 double randomGauss(double mean=0, double deviation=1);
00212
00213 Vector2d _measureRectCenter;
00214 Vector2d _measureRectSize;
00215
00216 friend class GasErrors;
00217 };
00218
00219 }
00220
00221 #endif
00222