35namespace energybased {
38template<
int Dim,
typename ForceFunc,
bool UseForcePrime>
39class DTreeWSPDCallback;
44 template<
int _Dim,
typename ForceFunc,
bool UseForcePrime>
63 double mass(
int i)
const;
69 double force(
int i,
int d)
const;
75 template<
typename ForceFunc,
bool UseForcePrime>
148template<
int Dim,
typename ForceFunc,
bool UseForcePrime>
169 for (
int d = 0;
d <
Dim;
d++) {
202 m_pWSPD =
new WSPD(m_numPoints);
204 m_pointData =
new PointData[m_numPoints];
207 for (
int i = 0; i < m_numPoints; i++) {
208 m_pointData[i].
mass = 1.0;
216 delete[] m_pointData;
231 return wspd().
tree();
236 return wspd().
point(i).x[
d];
241 wspd().setPoint(i,
d, c);
246 return m_pointData[i].mass;
251 m_pointData[i].mass = m;
256 return m_pointData[i].force[
d];
261 return m_pointData[i].force_prime;
265template<
typename ForceFunc,
bool UseForcePrime>
270 if (numPoints() <= 1) {
278 bottomUpPhase(
tree().rootIndex());
286 topDownPhase(
tree().rootIndex());
292 for (
int d = 0;
d <
Dim;
d++) {
293 m_nodeData[
curr].force[
d] = 0.0;
294 m_nodeData[
curr].force_prime = 0.0;
295 m_nodeData[
curr].centerOfMass[
d] = 0.0;
299 m_nodeData[
curr].mass = 0.0;
304 for (
int i = 0; i <
tree().numChilds(
curr); i++) {
306 const int child =
tree().child(
curr, i);
309 bottomUpPhase(child);
312 for (
int d = 0;
d <
Dim;
d++) {
314 m_nodeData[
curr].centerOfMass[
d] +=
315 m_nodeData[child].centerOfMass[
d] * m_nodeData[child].mass;
319 m_nodeData[
curr].mass += m_nodeData[child].mass;
324 for (
int i = 0; i <
tree().numPoints(
curr); ++i) {
327 for (
int d = 0;
d <
Dim;
d++) {
335 for (
int d = 0;
d <
Dim;
d++) {
336 m_nodeData[
curr].centerOfMass[
d] /= m_nodeData[
curr].mass;
345 for (
int i = 0; i <
tree().numChilds(
curr); i++) {
347 const int child =
tree().child(
curr, i);
350 for (
int d = 0;
d <
Dim;
d++) {
352 m_nodeData[child].force[
d] += m_nodeData[
curr].force[
d];
355 m_nodeData[child].force_prime += m_nodeData[
curr].force_prime;
363 for (
int i = 0; i <
tree().numPoints(
curr); ++i) {
368 for (
int d = 0;
d <
Dim;
d++) {
380 for (
int i = 0; i < m_numPoints; i++) {
381 for (
int d = 0;
d <
Dim;
d++) {
382 m_pointData[i].force[
d] = 0.0;
384 m_pointData[i].force_prime = 0.0;
void setMass(int i, double m)
sets the mass of the i-th point
void bottomUpPhase(int curr)
internal function for computing the mass and center of mass of quadtree nodes
virtual ~DTreeForce()
destructor
const WSPD & wspd() const
returns a const ref to the wspd
void deallocate()
internal for allocating mem
void topDownPhase(int curr)
internal function for accumulating forces in the leaves
const Tree & tree() const
returns a const reference to the tree
WSPD * m_pWSPD
the WSPD instance
NodeData * m_nodeData
array for the node related data
void allocate()
internal for allocating mem
void resetPointForces()
reset the point forces
int numPoints() const
returns the number of points
PointData * m_pointData
array for the point related data
void setPosition(int i, int d, double c)
sets the d-th coordinate of the i-th point
double mass(int i) const
returns the mass of the i-th point
void computeForces(ForceFunc forceFunc)
main call
void resetTreeNodes()
reset the tree nodes
int m_numPoints
the number of points
double position(int i, int d) const
returns d-th coordinate of the i-th point
double force(int i, int d) const
returns d-th coordinate of the i-th force vector
DTreeForce(int numPoints)
constructs a new WSPD (well-separated pair decomposition) for numPoints
double force_prime(int i) const
returns derivation of the d-th coordinate of the i-th force vector
int point(int i, int j) const
returns the index of the jth point covered by i's subtree.
virtual void onWellSeparatedPair(int a, int b)
called by the WSPD for well separated pair
DTreeForce< Dim > & m_treeForce
DTreeWSPDCallback(DTreeForce< Dim > &treeForce, ForceFunc forceFunc)
const Tree & tree() const
returns the corresponding Dtree
DTree< IntType, Dim > Tree
void setSeparationFactor(double s)
sets the parameter s of the WSPD (default is 1.0)
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
@ tree
for every hyperedge e a minimal subcubic tree connecting all hypernodes incident with e together is a...
double force_prime
the first derivation of the distance based force function
double centerOfMass[Dim]
center of mass of the subtree
double force[Dim]
the force
double mass
mass of this node
double force[Dim]
the force
double mass
mass of this point