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

step/stepcore

  • sources
  • kde-4.12
  • kdeedu
  • step
  • stepcore
coulombforce.cc
Go to the documentation of this file.
1 /* This file is part of StepCore library.
2  Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
3 
4  StepCore library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  StepCore library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with StepCore; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "coulombforce.h"
20 #include "particle.h"
21 
22 #include <cmath>
23 #include <QtGlobal>
24 
25 namespace StepCore {
26 
27 STEPCORE_META_OBJECT(CoulombForce, QT_TRANSLATE_NOOP("ObjectClass", "CoulombForce"), QT_TR_NOOP("Coulomb force"), 0,
28  STEPCORE_SUPER_CLASS(Item) STEPCORE_SUPER_CLASS(Force),
29  STEPCORE_PROPERTY_RW(double, coulombConst, QT_TRANSLATE_NOOP("PropertyName", "coulombConst"), STEPCORE_FROM_UTF8(QT_TRANSLATE_NOOP("Units", "N m²/C²")),
30  QT_TR_NOOP("Coulomb constant"), coulombConst, setCoulombConst))
31 
32 STEPCORE_META_OBJECT(CoulombForceErrors, QT_TRANSLATE_NOOP("ObjectClass", "CoulombForceErrors"), QT_TR_NOOP("Errors class for CoulombForce"), 0,
33  STEPCORE_SUPER_CLASS(ObjectErrors),
34  STEPCORE_PROPERTY_RW(double, coulombConstVariance, QT_TRANSLATE_NOOP("PropertyName", "coulombConstVariance"), STEPCORE_FROM_UTF8(QT_TRANSLATE_NOOP("Units", "N m²/C²")),
35  QT_TR_NOOP("Coulomb constant variance"), coulombConstVariance, setCoulombConstVariance))
36 
37 CoulombForce* CoulombForceErrors::coulombForce() const
38 {
39  return static_cast<CoulombForce*>(owner());
40 }
41 
42 CoulombForce::CoulombForce(double coulombConst)
43  : _coulombConst(coulombConst)
44 {
45  coulombForceErrors()->setCoulombConstVariance(
46  square(Constants::CoulombError));
47 }
48 
49 void CoulombForce::calcForce(bool calcVariances)
50 {
51  const BodyList::const_iterator end = world()->bodies().end();
52  for(BodyList::const_iterator b1 = world()->bodies().begin(); b1 != end; ++b1) {
53  if(!(*b1)->metaObject()->inherits<ChargedParticle>()) continue;
54  for(BodyList::const_iterator b2 = b1+1; b2 != end; ++b2) {
55  if(!(*b2)->metaObject()->inherits<ChargedParticle>()) continue;
56  ChargedParticle* p1 = static_cast<ChargedParticle*>(*b1);
57  ChargedParticle* p2 = static_cast<ChargedParticle*>(*b2);
58 
59  Vector2d r = p2->position() - p1->position();
60  double rnorm2 = r.squaredNorm();
61  Vector2d force = _coulombConst* p1->charge() * p2->charge() * r / (rnorm2*sqrt(rnorm2));
62  p2->applyForce(force);
63  force = -force;
64  p1->applyForce(force);
65 
66  if(calcVariances) {
67  // XXX: CHECKME
68  ChargedParticleErrors* pe1 = p1->chargedParticleErrors();
69  ChargedParticleErrors* pe2 = p2->chargedParticleErrors();
70  Vector2d rV = pe2->positionVariance() + pe1->positionVariance();
71  Vector2d forceV = force.cwise().square().cwise()* (
72  Vector2d(coulombForceErrors()->_coulombConstVariance / square(_coulombConst) +
73  pe1->chargeVariance() / square(p1->charge()) +
74  pe2->chargeVariance() / square(p2->charge())) +
75  Vector2d(rV[0] * square(1/r[0] - 3*r[0]/rnorm2) + rV[1] * square(3*r[1]/rnorm2),
76  rV[1] * square(1/r[1] - 3*r[1]/rnorm2) + rV[0] * square(3*r[0]/rnorm2)));
77  pe1->applyForceVariance(forceV);
78  pe2->applyForceVariance(forceV);
79  }
80  }
81  }
82 }
83 
84 } // namespace StepCore
85 
StepCore::World::bodies
const BodyList & bodies() const
Get list of all items (not including sub-items) in the World.
Definition: world.h:427
StepCore::Constants::CoulombError
static const double CoulombError
Error of Coulomb's constant.
Definition: constants.h:48
StepCore::Vector2d
Eigen::Vector2d Vector2d
Two-dimensional vector with double components.
Definition: vector.h:29
StepCore::CoulombForce::calcForce
void calcForce(bool calcVariances)
Calculate force.
Definition: coulombforce.cc:49
StepCore::ChargedParticle
ChargedParticle with mass and charge.
Definition: particle.h:206
StepCore::ParticleErrors::applyForceVariance
void applyForceVariance(const Vector2d &forceVariance)
Increment force variance.
Definition: particle.h:73
StepCore::STEPCORE_SUPER_CLASS
STEPCORE_SUPER_CLASS(CollisionSolver)
StepCore::ChargedParticle::charge
double charge() const
Charge of the particle.
Definition: particle.h:217
StepCore::STEPCORE_FROM_UTF8
setAngleVariance setAngularVelocityVariance STEPCORE_FROM_UTF8(QT_TRANSLATE_NOOP("Units","rad/s²"))
StepCore::Item::world
World * world() const
Get pointer to World in which this object lives.
Definition: world.h:91
StepCore::QT_TRANSLATE_NOOP
QT_TRANSLATE_NOOP("ObjectClass","GJKCollisionSolver")
coulombforce.h
CoulombForce class.
StepCore::CoulombForce::coulombForceErrors
CoulombForceErrors * coulombForceErrors()
Get (and possibly create) CoulombForceErrors object.
Definition: coulombforce.h:98
StepCore::ChargedParticleErrors::chargeVariance
double chargeVariance() const
Get charge variance.
Definition: particle.h:192
StepCore::ChargedParticle::chargedParticleErrors
ChargedParticleErrors * chargedParticleErrors()
Get (and possibly create) ChargedParticleErrors object.
Definition: particle.h:222
StepCore::ParticleErrors::positionVariance
const Vector2d & positionVariance() const
Get position variance.
Definition: particle.h:52
StepCore::QT_TR_NOOP
QT_TR_NOOP("Errors class for CoulombForce")
StepCore::CoulombForce::CoulombForce
CoulombForce(double coulombConst=Constants::Coulomb)
Constructs CoulombForce.
StepCore::STEPCORE_PROPERTY_RW
STEPCORE_PROPERTY_RW(double, depth, QT_TRANSLATE_NOOP("PropertyName","depth"), QT_TRANSLATE_NOOP("Units","J"), QT_TR_NOOP("Potential depth"), depth, setDepth) STEPCORE_PROPERTY_RW(double
StepCore::Particle::applyForce
void applyForce(const Vector2d &force)
Apply force to the body.
Definition: particle.h:135
particle.h
Particle and ChargedParticle classes.
StepCore::Particle::position
const Vector2d & position() const
Get position of the particle.
Definition: particle.h:117
StepCore::STEPCORE_META_OBJECT
STEPCORE_META_OBJECT(CollisionSolver, QT_TRANSLATE_NOOP("ObjectClass","CollisionSolver"),"CollisionSolver", MetaObject::ABSTRACT, STEPCORE_SUPER_CLASS(Object), STEPCORE_PROPERTY_RW(double, toleranceAbs, QT_TRANSLATE_NOOP("PropertyName","toleranceAbs"), STEPCORE_UNITS_1, QT_TR_NOOP("Allowed absolute tolerance"), toleranceAbs, setToleranceAbs) STEPCORE_PROPERTY_R_D(double, localError, QT_TRANSLATE_NOOP("PropertyName","localError"), STEPCORE_UNITS_1, QT_TR_NOOP("Maximal local error during last step"), localError)) STEPCORE_META_OBJECT(GJKCollisionSolver
StepCore::square
T square(T v)
Definition: util.h:30
StepCore::ChargedParticleErrors
Errors object for ChargedParticle.
Definition: particle.h:179
StepCore::CoulombForce::_coulombConst
double _coulombConst
Definition: coulombforce.h:104
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:43:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

step/stepcore

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal