• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

step/stepcore

gas.cc

Go to the documentation of this file.
00001 /* This file is part of StepCore library.
00002    Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
00003 
00004    StepCore library is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2 of the License, or
00007    (at your option) any later version.
00008 
00009    StepCore library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with StepCore; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 */
00018 
00019 #include "gas.h"
00020 #include "types.h"
00021 #include "constants.h"
00022 #include <cstdlib>
00023 
00024 namespace StepCore
00025 {
00026 
00027 STEPCORE_META_OBJECT(GasParticle, "Gas particle", 0, STEPCORE_SUPER_CLASS(Particle),)
00028 
00029 STEPCORE_META_OBJECT(GasLJForce, "Lennard-Jones force", 0,
00030     STEPCORE_SUPER_CLASS(Item) STEPCORE_SUPER_CLASS(Force),
00031     STEPCORE_PROPERTY_RW(double, depth, "J", "Potential depth", depth, setDepth)
00032     STEPCORE_PROPERTY_RW(double, rmin, "m", "Distance at which the force is zero", rmin, setRmin)
00033     STEPCORE_PROPERTY_RW(double, cutoff, "m", "Cut-off distance", cutoff, setCutoff))
00034 
00035 STEPCORE_META_OBJECT(GasLJForceErrors, "Errors class for GasLJForce", 0,
00036     STEPCORE_SUPER_CLASS(ObjectErrors),
00037     STEPCORE_PROPERTY_RW(double, depthVariance, "J",
00038             "Potential depth variance", depthVariance, setDepthVariance)
00039     STEPCORE_PROPERTY_RW(double, rminVariance, "m",
00040             "Variance of the distance at which the force is zero", rminVariance, setRminVariance))
00041 
00042 // XXX: Check units for 2d
00043 // XXX: add cmPosition and cmVelocity
00044 STEPCORE_META_OBJECT(Gas, "Particle gas", 0, STEPCORE_SUPER_CLASS(ItemGroup),
00045     STEPCORE_PROPERTY_RW(StepCore::Vector2d, measureRectCenter, "m",
00046                 "Center of the rect for measurements", measureRectCenter, setMeasureRectCenter)
00047     STEPCORE_PROPERTY_RW(StepCore::Vector2d, measureRectSize, "m",
00048                 "Size of the rect for measurements", measureRectSize, setMeasureRectSize)
00049     STEPCORE_PROPERTY_R_D(double, rectVolume, STEPCORE_FROM_UTF8("m²"),
00050                 "Volume of the measureRect", rectVolume)
00051     STEPCORE_PROPERTY_R_D(double, rectParticleCount, STEPCORE_UNITS_1,
00052                 "Count of particles in the measureRect", rectParticleCount)
00053     STEPCORE_PROPERTY_R_D(double, rectConcentration, STEPCORE_FROM_UTF8("1/m²"),
00054                 "Concentration of particles in the measureRect", rectConcentration)
00055     STEPCORE_PROPERTY_R_D(double, rectPressure, "Pa",
00056                 "Pressure of particles in the measureRect", rectPressure)
00057     STEPCORE_PROPERTY_R_D(double, rectTemperature, "K",
00058                 "Temperature of particles in the measureRect", rectTemperature)
00059     STEPCORE_PROPERTY_R_D(double, rectMeanKineticEnergy, "J",
00060                 "Mean kinetic energy of particles in the measureRect", rectMeanKineticEnergy)
00061     STEPCORE_PROPERTY_R_D(StepCore::Vector2d, rectMeanVelocity, "m/s",
00062                 "Mean velocity of particles in the measureRect", rectMeanVelocity)
00063     STEPCORE_PROPERTY_R_D(double, rectMeanParticleMass, "kg",
00064                 "Mean mass of particles in the measureRect", rectMeanParticleMass)
00065     STEPCORE_PROPERTY_R_D(double, rectMass, "kg",
00066                 "Total mass of particles in the measureRect", rectMass)
00067     )
00068 
00069 STEPCORE_META_OBJECT(GasErrors, "Errors class for Gas", 0, STEPCORE_SUPER_CLASS(ObjectErrors),
00070     STEPCORE_PROPERTY_R_D(double, rectPressureVariance, "Pa",
00071                 "Variance of pressure of particles in the measureRect", rectPressureVariance)
00072     STEPCORE_PROPERTY_R_D(double, rectTemperatureVariance, "K",
00073                 "Variance of temperature of particles in the measureRect", rectTemperatureVariance)
00074     STEPCORE_PROPERTY_R_D(double, rectMeanKineticEnergyVariance, "J",
00075                 "Variance of mean kinetic energy of particles in the measureRect", rectMeanKineticEnergyVariance)
00076     STEPCORE_PROPERTY_R_D(StepCore::Vector2d, rectMeanVelocityVariance, "m/s",
00077                 "Variance of mean velocity of particles in the measureRect", rectMeanVelocityVariance)
00078     STEPCORE_PROPERTY_R_D(double, rectMeanParticleMassVariance, "kg",
00079                 "Variance of mean mass of particles in the measureRect", rectMeanParticleMassVariance)
00080     STEPCORE_PROPERTY_R_D(double, rectMassVariance, "kg",
00081                 "Variance of total mass of particles in the measureRect", rectMassVariance)
00082     )
00083 
00084 GasLJForce* GasLJForceErrors::gasLJForce() const
00085 {
00086     return static_cast<GasLJForce*>(owner());
00087 }
00088 
00089 GasLJForce::GasLJForce(double depth, double rmin, double cutoff)
00090     : _depth(depth), _rmin(rmin), _cutoff(cutoff)
00091 {
00092     calcABC();
00093 }
00094 
00095 void GasLJForce::calcABC()
00096 {
00097     double m = 12*_depth;
00098     _rmin6 = pow(_rmin, 6);
00099     _rmin12 = _rmin6*_rmin6;
00100     _a = m*_rmin12; _b = m*_rmin6;
00101     _c = _cutoff*_cutoff;
00102 }
00103 
00104 void GasLJForce::calcForce(bool calcVariances)
00105 {
00106     if(!group()) return;
00107 
00108     // NOTE: Currently we are handling only children of the same group
00109     const ItemList::const_iterator end = group()->items().end();
00110     for(ItemList::const_iterator i1 = group()->items().begin(); i1 != end; ++i1) {
00111         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00112         for(ItemList::const_iterator i2 = i1+1; i2 != end; ++i2) {
00113             if(!(*i2)->metaObject()->inherits<GasParticle>()) continue;
00114 
00115             GasParticle* p1 = static_cast<GasParticle*>(*i1);
00116             GasParticle* p2 = static_cast<GasParticle*>(*i2);
00117             Vector2d r = p2->position() - p1->position();
00118             double rnorm2 = r.norm2();
00119             if(rnorm2 < _c) {
00120                 double rnorm6 = rnorm2*rnorm2*rnorm2;
00121                 double rnorm8 = rnorm6*rnorm2;
00122                 Vector2d force = r * ((_a/rnorm6 - _b)/rnorm8);
00123                 p2->applyForce(force);
00124                 force.invert();
00125                 p1->applyForce(force);
00126 
00127                 if(calcVariances) {
00128                     ParticleErrors* pe1 = p1->particleErrors();
00129                     ParticleErrors* pe2 = p2->particleErrors();
00130                     Vector2d rV = pe2->positionVariance() + pe1->positionVariance();
00131 
00132                     GasLJForceErrors* ge = gasLJForceErrors();
00133                     Vector2d forceV = r.cSquare() * (
00134                         ge->_rminVariance * square( (12*_a/_rmin/rnorm6 - 6*_b/_rmin)/rnorm8 ) +
00135                         ge->_depthVariance * square( 12*(_rmin12/rnorm6 - _rmin6)/rnorm8 ) );
00136 
00137                     forceV[0] += rV[0] * square( (_a/rnorm6*( 1 - 14*r[0]*r[0]/rnorm2 ) -
00138                                                   _b*( 1 - 8*r[0]*r[0]/rnorm2 ))/rnorm8 ) +
00139                                  rV[1] * square( (_a/rnorm6*14 - _b*8)*r[0]*r[1]/(rnorm8*rnorm2) );
00140                     forceV[1] += rV[1] * square( (_a/rnorm6*( 1 - 14*r[1]*r[1]/rnorm2 ) -
00141                                                   _b*( 1 - 8*r[1]*r[1]/rnorm2 ))/rnorm8 ) +
00142                                  rV[0] * square( (_a/rnorm6*14 - _b*8)*r[0]*r[1]/(rnorm8*rnorm2) );
00143 
00144                     pe1->applyForceVariance(forceV);
00145                     pe2->applyForceVariance(forceV);
00146                 }
00147             }
00148         }
00149     }
00150 }
00151 
00152 Gas* GasErrors::gas() const
00153 {
00154     return static_cast<Gas*>(owner());
00155 }
00156 
00157 double Gas::rectVolume() const
00158 {
00159     return _measureRectSize[0]*_measureRectSize[1];
00160 }
00161 
00162 double Gas::randomUniform(double min, double max)
00163 {
00164     return double(std::rand())/RAND_MAX*(max-min) + min;
00165 }
00166 
00167 double Gas::randomGauss(double mean, double deviation)
00168 {
00169     // Polar Box-Muller algorithm
00170     double x1, x2, w;
00171  
00172     do {
00173         x1 = 2.0 * double(std::rand())/RAND_MAX - 1.0;
00174         x2 = 2.0 * double(std::rand())/RAND_MAX - 1.0;
00175         w = x1 * x1 + x2 * x2;
00176     } while( w >= 1.0 || w == 0 );
00177 
00178     w = sqrt( (-2.0 * log( w ) ) / w );
00179     return x1 * w * deviation + mean;
00180 }
00181 
00182 GasParticleList Gas::rectCreateParticles(int count,
00183                                 double mass, double temperature,
00184                                 const Vector2d& meanVelocity)
00185 {
00186     GasParticleList particles;
00187 
00188     Vector2d r0 = _measureRectCenter-_measureRectSize/2.0;
00189     Vector2d r1 = _measureRectCenter+_measureRectSize/2.0;
00190     double deviation = std::sqrt( Constants::Boltzmann * temperature / mass );
00191 
00192     for(int i=0; i<count; ++i) {
00193         Vector2d pos(randomUniform(r0[0], r1[0]), randomUniform(r0[1], r1[1]));
00194         Vector2d vel(randomGauss(meanVelocity[0], deviation), randomGauss(meanVelocity[1], deviation));
00195         GasParticle* particle = new GasParticle(pos, vel, mass);
00196         particles.push_back(particle);
00197     }
00198 
00199     return particles;
00200 }
00201 
00202 void Gas::addParticles(const GasParticleList& particles)
00203 {
00204     const GasParticleList::const_iterator end = particles.end();
00205     for(GasParticleList::const_iterator it = particles.begin(); it != end; ++it) {
00206         addItem(*it);
00207     }
00208 }
00209 
00210 double Gas::rectParticleCount() const
00211 {
00212     Vector2d r0 = _measureRectCenter-_measureRectSize/2.0;
00213     Vector2d r1 = _measureRectCenter+_measureRectSize/2.0;
00214 
00215     double count = 0;
00216     const ItemList::const_iterator end = items().end();
00217     for(ItemList::const_iterator i1 = items().begin(); i1 != end; ++i1) {
00218         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00219         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00220         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00221             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00222         ++count;
00223     }
00224 
00225     return count;
00226 }
00227 
00228 double Gas::rectMeanParticleMass() const
00229 {
00230     Vector2d r0 = _measureRectCenter-_measureRectSize/2.0;
00231     Vector2d r1 = _measureRectCenter+_measureRectSize/2.0;
00232 
00233     double count = 0;
00234     double mass = 0;
00235 
00236     const ItemList::const_iterator end = items().end();
00237     for(ItemList::const_iterator i1 = items().begin(); i1 != end; ++i1) {
00238         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00239         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00240         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00241             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00242         mass += p1->mass();
00243         ++count;
00244     }
00245 
00246     mass /= count;
00247     return mass;
00248 }
00249 
00250 double GasErrors::rectMeanParticleMassVariance() const
00251 {
00252     Vector2d r0 = gas()->_measureRectCenter-gas()->_measureRectSize/2.0;
00253     Vector2d r1 = gas()->_measureRectCenter+gas()->_measureRectSize/2.0;
00254 
00255     double count = 0;
00256 
00257     double mass = gas()->rectMeanParticleMass();
00258     double massVariance = 0;
00259 
00260     const ItemList::const_iterator end = gas()->items().end();
00261     for(ItemList::const_iterator i1 = gas()->items().begin(); i1 != end; ++i1) {
00262         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00263         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00264         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00265             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00266 
00267         massVariance += square(p1->mass() - mass);
00268 
00269         ParticleErrors* pe1 = static_cast<ParticleErrors*>(p1->tryGetObjectErrors());
00270         if(pe1) massVariance += pe1->massVariance();
00271 
00272         ++count;
00273     }
00274 
00275     massVariance /= square(count);
00276     return massVariance;
00277 }
00278 
00279 double Gas::rectMass() const
00280 {
00281     Vector2d r0 = _measureRectCenter-_measureRectSize/2.0;
00282     Vector2d r1 = _measureRectCenter+_measureRectSize/2.0;
00283 
00284     double mass = 0;
00285 
00286     const ItemList::const_iterator end = items().end();
00287     for(ItemList::const_iterator i1 = items().begin(); i1 != end; ++i1) {
00288         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00289         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00290         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00291             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00292         mass += p1->mass();
00293     }
00294 
00295     return mass;
00296 }
00297 
00298 double GasErrors::rectMassVariance() const
00299 {
00300     Vector2d r0 = gas()->_measureRectCenter-gas()->_measureRectSize/2.0;
00301     Vector2d r1 = gas()->_measureRectCenter+gas()->_measureRectSize/2.0;
00302 
00303     double massVariance = 0;
00304 
00305     const ItemList::const_iterator end = gas()->items().end();
00306     for(ItemList::const_iterator i1 = gas()->items().begin(); i1 != end; ++i1) {
00307         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00308         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00309         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00310             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00311 
00312         ParticleErrors* pe1 = static_cast<ParticleErrors*>(p1->tryGetObjectErrors());
00313         if(pe1) massVariance += pe1->massVariance();
00314     }
00315 
00316     return massVariance;
00317 }
00318 
00319 double Gas::rectConcentration() const
00320 {
00321     return rectParticleCount() / rectVolume();
00322 }
00323 
00324 Vector2d Gas::rectMeanVelocity() const
00325 {
00326     Vector2d r0 = _measureRectCenter-_measureRectSize/2.0;
00327     Vector2d r1 = _measureRectCenter+_measureRectSize/2.0;
00328 
00329     double count = 0;
00330     Vector2d velocity(0);
00331 
00332     const ItemList::const_iterator end = items().end();
00333     for(ItemList::const_iterator i1 = items().begin(); i1 != end; ++i1) {
00334         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00335         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00336         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00337             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00338         velocity += p1->velocity();
00339         ++count;
00340     }
00341 
00342     velocity /= count;
00343     return velocity;
00344 }
00345 
00346 Vector2d GasErrors::rectMeanVelocityVariance() const
00347 {
00348     Vector2d r0 = gas()->_measureRectCenter-gas()->_measureRectSize/2.0;
00349     Vector2d r1 = gas()->_measureRectCenter+gas()->_measureRectSize/2.0;
00350 
00351     double count = 0;
00352 
00353     Vector2d velocity = gas()->rectMeanVelocity();
00354     Vector2d velocityVariance(0);
00355 
00356     const ItemList::const_iterator end = gas()->items().end();
00357     for(ItemList::const_iterator i1 = gas()->items().begin(); i1 != end; ++i1) {
00358         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00359         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00360         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00361             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00362 
00363         velocityVariance += (p1->velocity() - velocity).cSquare(); 
00364 
00365         ParticleErrors* pe1 = static_cast<ParticleErrors*>(p1->tryGetObjectErrors());
00366         if(pe1) velocityVariance += pe1->velocityVariance();
00367 
00368         ++count;
00369     }
00370 
00371     velocityVariance /= square(count);
00372     return velocityVariance;
00373 }
00374 
00375 double Gas::rectMeanKineticEnergy() const
00376 {
00377     Vector2d r0 = _measureRectCenter-_measureRectSize/2.0;
00378     Vector2d r1 = _measureRectCenter+_measureRectSize/2.0;
00379 
00380     double count = 0;
00381     double energy = 0;
00382 
00383     const ItemList::const_iterator end = items().end();
00384     for(ItemList::const_iterator i1 = items().begin(); i1 != end; ++i1) {
00385         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00386         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00387         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00388             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00389         energy += p1->mass() * p1->velocity().norm2();
00390         ++count;
00391     }
00392 
00393     energy /= (2.0*count);
00394     return energy;
00395 }
00396 
00397 double GasErrors::rectMeanKineticEnergyVariance() const
00398 {
00399     Vector2d r0 = gas()->_measureRectCenter-gas()->_measureRectSize/2.0;
00400     Vector2d r1 = gas()->_measureRectCenter+gas()->_measureRectSize/2.0;
00401 
00402     double count = 0;
00403 
00404     double energy = 2*gas()->rectMeanKineticEnergy();
00405     double energyVariance = 0;
00406 
00407     const ItemList::const_iterator end = gas()->items().end();
00408     for(ItemList::const_iterator i1 = gas()->items().begin(); i1 != end; ++i1) {
00409         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00410         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00411         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00412             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00413 
00414         double pEnergy = p1->mass() * p1->velocity().norm2();
00415         energyVariance += square(pEnergy - energy);
00416 
00417         ParticleErrors* pe1 = static_cast<ParticleErrors*>(p1->tryGetObjectErrors());
00418         if(pe1) {
00419             energyVariance +=
00420                 pe1->massVariance() * square(p1->velocity().norm2()) +
00421                 pe1->velocityVariance().innerProduct(
00422                     (2*p1->mass()*p1->velocity()).cSquare() );
00423         }
00424 
00425         ++count;
00426     }
00427 
00428     energyVariance /= square(2.0*count);
00429     return energyVariance;
00430 }
00431 
00432 double Gas::rectTemperature() const
00433 {
00434     Vector2d r0 = _measureRectCenter-_measureRectSize/2.0;
00435     Vector2d r1 = _measureRectCenter+_measureRectSize/2.0;
00436 
00437     double count = 0;
00438     double temperature = 0;
00439 
00440     StepCore::Vector2d meanVelocity = rectMeanVelocity();
00441     const ItemList::const_iterator end = items().end();
00442     for(ItemList::const_iterator i1 = items().begin(); i1 != end; ++i1) {
00443         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00444         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00445         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00446             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00447         temperature += p1->mass() * (p1->velocity() - meanVelocity).norm2();
00448         ++count;
00449     }
00450 
00451     // no 3/2 factor since we live in 2d
00452     temperature /= (2.0*count*Constants::Boltzmann);
00453     return temperature;
00454 }
00455 
00456 double GasErrors::rectTemperatureVariance() const
00457 {
00458     Vector2d r0 = gas()->_measureRectCenter-gas()->_measureRectSize/2.0;
00459     Vector2d r1 = gas()->_measureRectCenter+gas()->_measureRectSize/2.0;
00460 
00461     double count = 0;
00462 
00463     StepCore::Vector2d meanVelocity = gas()->rectMeanVelocity();
00464     double temperature = 2.0*Constants::Boltzmann*gas()->rectTemperature();
00465     double temperatureVariance = 0;
00466 
00467     const ItemList::const_iterator end = gas()->items().end();
00468     for(ItemList::const_iterator i1 = gas()->items().begin(); i1 != end; ++i1) {
00469         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00470         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00471         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00472             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00473 
00474         double pTemperature = p1->mass() * (p1->velocity() - meanVelocity).norm2();
00475         temperatureVariance += square(pTemperature - temperature);
00476 
00477         ParticleErrors* pe1 = static_cast<ParticleErrors*>(p1->tryGetObjectErrors());
00478         if(pe1) {
00479             temperatureVariance +=
00480                 pe1->massVariance() * square((p1->velocity() - meanVelocity).norm2()) +
00481                 pe1->velocityVariance().innerProduct(
00482                     (p1->mass()*(p1->velocity() - meanVelocity)).cSquare() );
00483         }
00484 
00485         ++count;
00486     }
00487 
00488     temperatureVariance /= square(2.0*Constants::Boltzmann*count);
00489     // XXX: We could easily take into account BoltzmannError here
00490     // but this can confuse users so for now we don't do it
00491     
00492     return temperatureVariance;
00493 }
00494 
00495 // XXX: this formula is incorrect when forces are big
00496 // XXX: use better formula (for example from lammps)
00497 double Gas::rectPressure() const
00498 {
00499     Vector2d r0 = _measureRectCenter-_measureRectSize/2.0;
00500     Vector2d r1 = _measureRectCenter+_measureRectSize/2.0;
00501 
00502     double pressure = 0;
00503 
00504     StepCore::Vector2d meanVelocity = rectMeanVelocity();
00505     const ItemList::const_iterator end = items().end();
00506     for(ItemList::const_iterator i1 = items().begin(); i1 != end; ++i1) {
00507         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00508         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00509         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00510             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00511         pressure += p1->mass() * (p1->velocity() - meanVelocity).norm2();
00512     }
00513 
00514     pressure /= (2.0 * rectVolume());
00515     return pressure;
00516 }
00517 
00518 double GasErrors::rectPressureVariance() const
00519 {
00520     Vector2d r0 = gas()->_measureRectCenter-gas()->_measureRectSize/2.0;
00521     Vector2d r1 = gas()->_measureRectCenter+gas()->_measureRectSize/2.0;
00522 
00523     StepCore::Vector2d meanVelocity = gas()->rectMeanVelocity();
00524     double pressure = gas()->rectPressure();
00525     double pressureVariance = 0;
00526 
00527     const ItemList::const_iterator end = gas()->items().end();
00528     for(ItemList::const_iterator i1 = gas()->items().begin(); i1 != end; ++i1) {
00529         if(!(*i1)->metaObject()->inherits<GasParticle>()) continue;
00530         GasParticle* p1 = static_cast<GasParticle*>(*i1);
00531         if(p1->position()[0] < r0[0] || p1->position()[0] > r1[0] ||
00532             p1->position()[1] < r0[1] || p1->position()[1] > r1[1]) continue;
00533 
00534         double pPressure = p1->mass() * (p1->velocity() - meanVelocity).norm2();
00535         pressureVariance += square(pPressure - pressure);
00536 
00537         ParticleErrors* pe1 = static_cast<ParticleErrors*>(p1->tryGetObjectErrors());
00538         if(pe1) {
00539             pressureVariance +=
00540                 pe1->massVariance() * square((p1->velocity() - meanVelocity).norm2()) +
00541                 pe1->velocityVariance().innerProduct(
00542                     (p1->mass()*(p1->velocity() - meanVelocity)).cSquare() );
00543         }
00544     }
00545 
00546     pressureVariance /= square(2.0*gas()->rectVolume());
00547     return pressureVariance;
00548 }
00549 
00550 }
00551 

step/stepcore

Skip menu "step/stepcore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal