diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files
index fefabee690..2f20fee7e8 100644
--- a/src/OpenFOAM/Make/files
+++ b/src/OpenFOAM/Make/files
@@ -584,6 +584,8 @@ algorithms/indexedOctree/indexedOctreeName.C
algorithms/indexedOctree/treeDataCell.C
+algorithms/dynamicIndexedOctree/dynamicIndexedOctreeName.C
+algorithms/dynamicIndexedOctree/dynamicTreeDataPoint.C
graph/curve/curve.C
graph/graph.C
diff --git a/src/OpenFOAM/algorithms/dynamicIndexedOctree/dynamicIndexedOctree.C b/src/OpenFOAM/algorithms/dynamicIndexedOctree/dynamicIndexedOctree.C
new file mode 100644
index 0000000000..0db3d8f472
--- /dev/null
+++ b/src/OpenFOAM/algorithms/dynamicIndexedOctree/dynamicIndexedOctree.C
@@ -0,0 +1,3018 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
+ \\/ M anipulation |
+-------------------------------------------------------------------------------
+License
+ This file is part of OpenFOAM.
+
+ OpenFOAM is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OpenFOAM. If not, see .
+
+\*---------------------------------------------------------------------------*/
+
+#include "dynamicIndexedOctree.H"
+#include "linePointRef.H"
+#include "OFstream.H"
+#include "ListOps.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+template
+Foam::scalar Foam::dynamicIndexedOctree::perturbTol_ = 10*SMALL;
+
+
+// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
+
+// Does bb intersect a sphere around sample? Or is any corner point of bb
+// closer than nearestDistSqr to sample.
+template
+bool Foam::dynamicIndexedOctree::overlaps
+(
+ const point& p0,
+ const point& p1,
+ const scalar nearestDistSqr,
+ const point& sample
+)
+{
+ // Find out where sample is in relation to bb.
+ // Find nearest point on bb.
+ scalar distSqr = 0;
+
+ for (direction dir = 0; dir < vector::nComponents; dir++)
+ {
+ scalar d0 = p0[dir] - sample[dir];
+ scalar d1 = p1[dir] - sample[dir];
+
+ if ((d0 > 0) != (d1 > 0))
+ {
+ // sample inside both extrema. This component does not add any
+ // distance.
+ }
+ else if (mag(d0) < mag(d1))
+ {
+ distSqr += d0*d0;
+ }
+ else
+ {
+ distSqr += d1*d1;
+ }
+
+ if (distSqr > nearestDistSqr)
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+// Does bb intersect a sphere around sample? Or is any corner point of bb
+// closer than nearestDistSqr to sample.
+template
+bool Foam::dynamicIndexedOctree::overlaps
+(
+ const treeBoundBox& parentBb,
+ const direction octant,
+ const scalar nearestDistSqr,
+ const point& sample
+)
+{
+ //- Accelerated version of
+ // treeBoundBox subBb(parentBb.subBbox(mid, octant))
+ // overlaps
+ // (
+ // subBb.min(),
+ // subBb.max(),
+ // nearestDistSqr,
+ // sample
+ // )
+
+ const point& min = parentBb.min();
+ const point& max = parentBb.max();
+
+ point other;
+
+ if (octant & treeBoundBox::RIGHTHALF)
+ {
+ other.x() = max.x();
+ }
+ else
+ {
+ other.x() = min.x();
+ }
+
+ if (octant & treeBoundBox::TOPHALF)
+ {
+ other.y() = max.y();
+ }
+ else
+ {
+ other.y() = min.y();
+ }
+
+ if (octant & treeBoundBox::FRONTHALF)
+ {
+ other.z() = max.z();
+ }
+ else
+ {
+ other.z() = min.z();
+ }
+
+ const point mid(0.5*(min+max));
+
+ return overlaps(mid, other, nearestDistSqr, sample);
+}
+
+
+//
+// Construction helper routines
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+
+// Split list of indices into 8 bins
+template
+void Foam::dynamicIndexedOctree::divide
+(
+ const autoPtr >& indices,
+ const treeBoundBox& bb,
+ contentListList& result
+) const
+{
+ for (direction octant = 0; octant < 8; octant++)
+ {
+ result.append
+ (
+ autoPtr >
+ (
+ new DynamicList