35 namespace energybased {
38 template<
int Dim,
typename ForceFunc,
bool UseForcePrime>
45 template<
int _Dim,
typename ForceFunc,
bool UseForcePrime>
58 double position(
int i ,
int d)
const;
64 double mass(
int i)
const;
70 double force(
int i ,
int d)
const;
76 template<
typename ForceFunc,
bool UseForcePrime>
105 double centerOfMass[Dim];
148 template<
int Dim,
typename ForceFunc,
bool UseForcePrime>
153 : m_treeForce(treeForce), m_forceFunc(forceFunc)
165 double dist = computeDeltaAndDistance<Dim>(m_treeForce.m_nodeData[a].centerOfMass,
166 m_treeForce.m_nodeData[b].centerOfMass,
168 m_forceFunc(dist, force, force_prime);
170 m_forceFunc(m_treeForce.m_nodeData[a].centerOfMass, m_treeForce.m_nodeData[b].centerOfMass, force, force_prime);
174 for (
int d = 0; d < Dim; d++) {
175 m_treeForce.m_nodeData[a].force[d] += force * delta[d] / dist * m_treeForce.m_nodeData[b].mass;
176 m_treeForce.m_nodeData[b].force[d] -= force * delta[d] / dist * m_treeForce.m_nodeData[a].mass;
180 m_treeForce.m_nodeData[a].force_prime += force_prime * m_treeForce.m_nodeData[b].mass;
181 m_treeForce.m_nodeData[b].force_prime += force_prime * m_treeForce.m_nodeData[a].mass;
283 template<
typename ForceFunc,
bool UseForcePrime>
312 for (
int d = 0; d < Dim; d++) {
322 if (
tree().numChilds(curr)) {
324 for (
int i = 0; i <
tree().numChilds(curr); i++) {
326 const int child =
tree().child(curr, i);
332 for (
int d = 0; d < Dim; d++) {
343 for (
int i = 0; i <
tree().numPoints(curr); ++i) {
344 int pointIndex =
tree().point(curr, i);
346 for (
int d = 0; d < Dim; d++) {
354 for (
int d = 0; d < Dim; d++) {
363 if (
tree().numChilds(curr)) {
365 for (
int i = 0; i <
tree().numChilds(curr); i++) {
367 const int child =
tree().child(curr, i);
370 for (
int d = 0; d < Dim; d++) {
383 for (
int i = 0; i <
tree().numPoints(curr); ++i) {
385 int pointIndex =
tree().point(curr, i);
388 for (
int d = 0; d < Dim; d++) {
402 for (
int d = 0; d < Dim; d++) {
virtual void onWellSeparatedPair(int a, int b)
called by the WSPD for well separated pair
void computeForces(ForceFunc forceFunc)
main call
WSPD * m_pWSPD
the WSPD instance
const Tree & tree() const
returns the corresponding Dtree
double position(int i, int d) const
returns d-th coordinate of the i-th point
double force_prime(int i) const
returns derivation of the d-th coordinate of the i-th force vector
DTreeWSPDCallback(DTreeForce< Dim > &treeForce, ForceFunc forceFunc)
void bottomUpPhase(int curr)
internal function for computing the mass and center of mass of quadtree nodes
const WSPD & wspd() const
returns a const ref to the wspd
double force[Dim]
the force
void resetPointForces()
reset the point forces
double force_prime
the first derivation of the distance based force function
PointData * m_pointData
array for the point related data
virtual ~DTreeForce()
destructor
int numPoints() const
returns the number of points
double mass(int i) const
returns the mass of the i-th point
void resetTreeNodes()
reset the tree nodes
DTreeForce(int numPoints)
constructs a new WSPD (well-separated pair decomposition) for numPoints
void setSeparationFactor(double s)
sets the parameter s of the WSPD (default is 1.0)
void setPosition(int i, int d, double c)
sets the d-th coordinate of the i-th point
double mass
mass of this node
double mass
mass of this point
void update()
call this when the point set has been updated.
void allocate()
internal for allocating mem
DTree< IntType, Dim > Tree
void setPoint(int i, int d, double coord)
sets the point to the given coords
void computeWSPD(IWSPD *m_pIWSPD)
void deallocate()
internal for allocating mem
const Tree & tree() const
returns a const reference to the tree
NodeData * m_nodeData
array for the node related data
double centerOfMass[Dim]
center of mass of the subtree
The namespace for all OGDF objects.
DTreeForce< Dim > & m_treeForce
void setMass(int i, double m)
sets the mass of the i-th point
double force(int i, int d) const
returns d-th coordinate of the i-th force vector
void topDownPhase(int curr)
internal function for accumulating forces in the leaves
const PointData & point(int i) const
return ith point
double force[Dim]
the force
int m_numPoints
the number of points