Chris Beaumont's IDL Library

Download source code

single page | use frames     summary     class     fields     routine details     file attributes

./

otree__define.pro

The otree class implements the oct tree data structure, used for calculating the potential energy of a system of point masses. The data structure, and its utility in N body simulations, is discussed by Barnes and Hut 1986 (Nature v324 p446).

The oct tree recursively partitions a 3D cell into 8 subsells. New points are added to the tree such that each point corresponds to a leaf, and all points are separate from one another.

Class description for otree

Routines

result = otree::init(pos, mass, bounds)

create a new oct tree node

otree::addEmptyChild, index

Initialize one of this child's nodes as an empty leaf.

otree::cleanup
result = otree::getChild(index)

return one of the children

result = otree::getChildren()

get all of the children

otree::insert, pos, mass

This procedure inserts a new point mass into the system, re-arranging leaves if necessary

result = otree::calcPotential(pos, mass [, neval=neval] [, theta=theta])

This function calculates the potential energy between a point mass and the system of particles already added to the tree.

result = otree::enforceAssertions(verbose=verbose)

This function ensures that the tree structure is still sane.

otree::pickChild, pos, ind1, ind3

This procedure determines which of the 8 sub-cells a point belongs in

result = otree::isLeaf()

Determines if the current node is a leaf

result = otree::getTotalMass()
result = otree::getCOM()
result = otree::getLeafMass()

get the mass uniquely associated with this node.

result = otree::getPos()

Get the position of the point mass located in this leaf.

otree__define
test

Routine details

topotree::init

result = otree::init(pos, mass, bounds)

create a new oct tree node

Return value

1 for success

Parameters

pos in required

A 3-element vector, defining a particle position

mass in required

The particle's mass

bounds in required

A [2,3] array denoting the lower and upper bounds for each dimension. Note that pos must lie within this boundary.

topotree::addEmptyChild

otree::addEmptyChild, index

Initialize one of this child's nodes as an empty leaf.

INDEX: The index (0-7) of the node to create

If child[index] already exists, the program exists quietly. Otherwise, an empty node with the appropriate boundaries is created.

Parameters

index

topotree::cleanup

otree::cleanup

topotree::getChild

result = otree::getChild(index)

return one of the children

Parameters

index in required

The index to return

topotree::getChildren

result = otree::getChildren()

get all of the children

topotree::insert

otree::insert, pos, mass

This procedure inserts a new point mass into the system, re-arranging leaves if necessary

The tree is traversed recursively until an appropriate empty leaf is found, and the new particle is added. If the leaf is non-empty, then the leaf is expanded into a node, and both masses are inserted into one of the sub-cells

Parameters

pos in required

A 3 element position array

mass in required

A scalar mass

topotree::calcPotential

result = otree::calcPotential(pos, mass [, neval=neval] [, theta=theta])

This function calculates the potential energy between a point mass and the system of particles already added to the tree.

This is based on the Barnes Hut algorithm, which treates sub-trees as single point masses if the center of mass is sufficiently distant from the input position. This reduces the number of computations to O(N log N).

Note that interactions of particles within 10^-12 of each other are ignored. This is meant handle the case when one wants to calculate the potential energy of a particle already in the system; the interaction with itself is ignored.

Return value

The potential energy between the input point and the system.

Parameters

pos in required

A 3 element position

mass in required

A scalar mass

Keywords

neval in optional

On output, will hold the total number of inter-particle interactions.

theta in optional

Set to a value to control the precision of the algorithm. Smaller numbers lead to higher accuracies and longer calculations. theta=1 gives about 1% error for most input. theta=1.5 is just as good for a uniform grid of particles, when n_particle > 10^3

topotree::enforceAssertions

result = otree::enforceAssertions(verbose=verbose)

This function ensures that the tree structure is still sane. It traverses the tree, checking a variety of assumptions

Keywords

verbose

topotree::pickChild

otree::pickChild, pos, ind1, ind3

This procedure determines which of the 8 sub-cells a point belongs in

Parameters

pos in required

The position of the point

ind1
ind3

topotree::isLeaf

result = otree::isLeaf()

Determines if the current node is a leaf

topotree::getTotalMass

result = otree::getTotalMass()

topotree::getCOM

result = otree::getCOM()

topotree::getLeafMass

result = otree::getLeafMass()

get the mass uniquely associated with this node. This is nonzero if and only if the node is a leaf

topotree::getPos

result = otree::getPos()

Get the position of the point mass located in this leaf. If the node is not a leaf, this number is meaningless (and probably [0,0,0])

topotree__define

otree__define

toptest

test

File attributes

Modifcation date: Mon Jul 26 21:22:26 2010
Lines: 387