43 namespace fast_multipole_embedder {
49 std::list<LinearQuadtree::NodeID>
nodes;
52 template<
typename Func>
171 translate_x = -quadtree->
minX();
172 translate_y = -quadtree->minY();
173 scale = quadtree->scaleInv();
178 return quadtree->numberOfPoints();
184 uint32_t ref = p.
ref;
185 p.
mortonNr = mortonNumber<uint64_t, uint32_t>((uint32_t)((x[ref] + translate_x)*scale), (uint32_t)((y[ref] + translate_y)*scale));
190 for (uint32_t i = begin; i <= end; i++)
218 uint32_t firstPointOfLeaf = tree.
firstPoint(nodeIndex);
219 for (uint32_t pointIndex=firstPointOfLeaf; pointIndex < (firstPointOfLeaf+numPointsInLeaf); pointIndex++)
221 expansions.
P2M(pointIndex, nodeIndex);
244 expansions.
M2M(child, parent);
270 expansions.
M2L(nodeIndexSource, nodeIndexReceiver);
292 expansions.
L2L(parent, child);
321 expansions.
L2P(nodeIndex, pointIndex, fx[pointIndex], fy[pointIndex]);
327 this->operator ()(nodeIndex, pointIndex);
350 uint32_t offsetA = tree.
firstPoint(nodeIndexA);
351 uint32_t offsetB = tree.
firstPoint(nodeIndexB);
356 fx + offsetA, fy + offsetA, numPointsA,
359 fx + offsetB, fy + offsetB, numPointsB);
391 uint32_t numInnerNodesPerThread =
tree->numberOfInnerNodes() / numThreads;
392 if (numInnerNodesPerThread < 25)
394 localContexts[0]->innerNodePartition.begin =
tree->firstInnerNode();
395 localContexts[0]->innerNodePartition.numNodes =
tree->numberOfInnerNodes();
396 for (uint32_t i=1; i< numThreads; i++)
398 localContexts[i]->innerNodePartition.numNodes = 0;
405 localContexts[0]->innerNodePartition.begin = curr;
406 localContexts[0]->innerNodePartition.numNodes = 0;
407 for (uint32_t i=0; i<
tree->numberOfInnerNodes(); i++)
409 localContexts[currThread]->innerNodePartition.numNodes++;
410 curr =
tree->nextNode(curr);
411 if ((localContexts[currThread]->innerNodePartition.numNodes>=numInnerNodesPerThread) && (currThread < numThreads-1))
414 localContexts[currThread]->innerNodePartition.numNodes = 0;
415 localContexts[currThread]->innerNodePartition.begin = curr;
421 uint32_t numLeavesPerThread =
tree->numberOfLeaves() / numThreads;
422 if (numLeavesPerThread < 25)
424 localContexts[0]->leafPartition.begin =
tree->firstLeaf();
425 localContexts[0]->leafPartition.numNodes =
tree->numberOfLeaves();
426 for (uint32_t i=1; i< numThreads; i++)
428 localContexts[i]->leafPartition.numNodes = 0;
434 localContexts[0]->leafPartition.begin = curr;
435 localContexts[0]->leafPartition.numNodes = 0;
436 for (uint32_t i=0; i<
tree->numberOfLeaves(); i++)
438 localContexts[currThread]->leafPartition.numNodes++;
439 curr =
tree->nextNode(curr);
440 if ((localContexts[currThread]->leafPartition.numNodes>=numLeavesPerThread) && (currThread < numThreads-1))
443 localContexts[currThread]->leafPartition.numNodes = 0;
444 localContexts[currThread]->leafPartition.begin = curr;
452 partitionNodeChains();
454 numPointsPerThread =
tree->numberOfPoints() / numThreads;
455 for (uint32_t i=0; i < numThreads; i++)
457 localContexts[i]->treePartition.nodes.clear();
458 localContexts[i]->treePartition.pointCount = 0;
466 uint32_t bound =
tree->numberOfPoints() / (numThreads*numThreads);
468 if (
tree->isLeaf(nodeID) || (
tree->numberOfPoints(nodeID) < bound))
469 l_par.push_back(nodeID);
471 for (uint32_t i = 0; i <
tree->numberOfChilds(nodeID); i++)
472 newPartition(
tree->child(nodeID, i));
478 newPartition(
tree->root());
479 uint32_t bound = (
tree->numberOfPoints() / (numThreads)) + (
tree->numberOfPoints() / (numThreads*numThreads*2));
480 while (!l_par.empty())
483 uint32_t v = l_par.front();
484 if (((partition->
pointCount +
tree->numberOfPoints(v)) <= bound) ||
485 (currThread==numThreads-1))
488 partition->
nodes.push_back(v);
500 return &localContexts[currThread]->treePartition;
526 return quadtree->numberOfPoints();
532 uint32_t ref = p.
ref;
533 quadtree->setPoint(i, x[ref], y[ref], s[ref]);
538 for (uint32_t i = begin; i <= end; i++)
566 return quadtree->numberOfNodes();
571 quadtree->computeCoords(i);
576 for (uint32_t i = begin; i <= end; i++)
604 return quadtree->numberOfNodes();
609 uint32_t currEntryIndex = wspd->firstPairEntry(i);
610 for (uint32_t k = 0; k < wspd->numWSNodes(i); k++)
612 uint32_t j = wspd->wsNodeOfPair(currEntryIndex, i);
613 quadtreeExp->M2L(j, i);
614 currEntryIndex = wspd->nextPair(currEntryIndex, i);
620 for (uint32_t i = begin; i <= end; i++)
643 forceArrayX = pLocalContext->
forceX;
644 forceArrayY = pLocalContext->
forceY;
649 return quadtree->numberOfDirectNodes();
654 uint32_t nodeI = quadtree->directNode(i);
655 uint32_t offset = quadtree->firstPoint(nodeI);
656 uint32_t numPoints = quadtree->numberOfPoints(nodeI);
657 eval_direct_fast(quadtree->pointX() + offset, quadtree->pointY() + offset, quadtree->pointSize() + offset, forceArrayX + offset, forceArrayY + offset, numPoints);
662 for (uint32_t i = begin; i <= end; i++)
686 forceArrayX = pLocalContext->
forceX;
687 forceArrayY = pLocalContext->
forceY;
692 return quadtree->numberOfDirectPairs();
697 uint32_t nodeA = quadtree->directNodeA(i);
698 uint32_t nodeB = quadtree->directNodeB(i);
699 uint32_t offsetA = quadtree->firstPoint(nodeA);
700 uint32_t offsetB = quadtree->firstPoint(nodeB);
701 uint32_t numPointsA = quadtree->numberOfPoints(nodeA);
702 uint32_t numPointsB = quadtree->numberOfPoints(nodeB);
703 eval_direct_fast(quadtree->pointX() + offsetA, quadtree->pointY() + offsetA,
704 quadtree->pointSize() + offsetA,
705 forceArrayX + offsetA, forceArrayY + offsetA, numPointsA,
706 quadtree->pointX() + offsetB, quadtree->pointY() + offsetB,
707 quadtree->pointSize() + offsetB,
708 forceArrayX + offsetB, forceArrayY + offsetB, numPointsB);
713 for (uint32_t i = begin; i <= end; i++)
732 return lhs &
static_cast<int>(rhs);
735 template<
unsigned int FLAGS>
743 y = pGraph->nodeYPos();
744 edgeInfo = pGraph->edgeInfo();
745 nodeInfo = pGraph->nodeInfo();
746 desiredEdgeLength = pGraph->desiredEdgeLength();
747 nodeSize = pGraph->nodeSize();
748 forceArrayX = pLocalContext->
forceX;
749 forceArrayY = pLocalContext->
forceY;
754 return pGraph->numEdges();
763 float d_x = x[e_info.
a] - x[e_info.
b];
764 float d_y = y[e_info.
a] - y[e_info.
b];
765 float d_sq = d_x*d_x + d_y*d_y;
767 float f = (float)(logf(d_sq)*0.5f-logf(desiredEdgeLength[i]));
774 fa = (float)(fa/((
float)a_info.
degree));
775 fb = (float)(fb/((
float)b_info.
degree));
780 fa += (nodeSize[e_info.
b] / d_sq);
781 fb += (nodeSize[e_info.
a] / d_sq);
783 forceArrayX[e_info.
a] -= fa*d_x;
784 forceArrayY[e_info.
a] -= fa*d_y;
785 forceArrayX[e_info.
b] += fb*d_x;
786 forceArrayY[e_info.
b] += fb*d_y;
791 for (uint32_t i = begin; i <= end; i++)
811 template<
unsigned int FLAGS>
829 return lhs &
static_cast<int>(rhs);
833 return lhs |
static_cast<int>(rhs);
837 return static_cast<int>(lhs) | static_cast<int>(rhs);
840 template<
unsigned int FLAGS>
850 globalArrayX = globalContext->globalForceX;
851 globalArrayY = globalContext->globalForceY;
867 return pGraph->numNodes();
875 for (uint32_t j=0; j < numContexts; j++)
877 float* localArrayX = localContexts[j]->forceX;
878 float* localArrayY = localContexts[j]->forceY;
879 sumX += localArrayX[i];
880 sumY += localArrayY[i];
883 localArrayX[i] = 0.0f;
884 localArrayY[i] = 0.0f;
889 i = globalContext->pQuadtree->refOfPoint(i);
892 && pGraph->nodeInfo(i).degree > 100) {
894 sumX /= (float)pGraph->nodeInfo(i).degree;
895 sumY /= (float)pGraph->nodeInfo(i).degree;
897 globalArrayX[i] += sumX*factor;
898 globalArrayY[i] += sumY*factor;
903 for (uint32_t i = begin; i <= end; i++)
920 template<
unsigned int FLAGS>
932 template<
unsigned int FLAGS>
940 float* xCoords,
float* yCoords,
942 float* globalForceArray)
943 : x(xCoords), y(yCoords), timeStep(ftimeStep), forceArray(globalForceArray)
946 if (FLAGS & TIME_STEP_NORMAL)
949 if (FLAGS & TIME_STEP_PREP)
955 y = pGraph->nodeYPos();
956 nodeMoveRadius = pGraph->nodeMoveRadius();
959 localContext = pLocalContext;
964 inline void operator()(
void)
const 966 return pGraph->numNodes();
972 float d_x = forceArrayX[i]* timeStep;
973 float d_y = forceArrayY[i]* timeStep;
974 double dsq = (d_x*d_x + d_y*d_y);
975 double d = sqrt(dsq);
977 localContext->maxForceSq = max<double>(localContext->maxForceSq, (double)dsq );
978 localContext->avgForce += d;
983 if (FLAGS & ZERO_GLOBAL_ARRAY)
985 forceArrayX[i] = 0.0;
986 forceArrayY[i] = 0.0;
989 forceArrayX[i] = d_x;
990 forceArrayY[i] = d_y;
994 forceArrayX[i] = 0.0;
995 forceArrayY[i] = 0.0;
1001 for (uint32_t i = begin; i <= end; i++)
1003 this->operator()(i);
1020 template<
unsigned int FLAGS>
1027 template<
typename TYP>
1030 uint32_t s = n/numThreads;
1031 uint32_t o = s*threadNr;
1032 if (threadNr == numThreads-1)
1033 s = s + (n % numThreads);
1035 for (uint32_t i = 0; i < s; i++ ) { a[o+i] = value; }
int operator&(int lhs, FMEEdgeForce rhs)
LQPartitioner(FMELocalContext *pLocalContext)
void operator()(LinearQuadtree::NodeID nodeIndex)
void eval_direct_fast(float *x, float *y, float *s, float *fx, float *fy, size_t n)
kernel function to evaluate forces between n points with coords x, y directly. result is stored in fx...
LQPointUpdateFunctor(FMELocalContext *pLocalContext)
uint32_t numberOfPoints(NodeID nodeID) const
returns the number of points contained in the subtree of node nodeID
static constexpr int USE_NODE_MOVE_RAD
float pointSize(PointID point) const
NDFunctor(FMELocalContext *pLocalContext)
void partitionNodeChains()
float * desiredEdgeLength()
Returns the edge length array for all edges.
static constexpr int TIME_STEP_PREP
std::list< uint32_t > l_par
float * forceY
local force array for all nodes, points
uint32_t operator()(void) const
the main global options for a run
double maxForceSq
local maximum force
Declaration of class WSPD (well-separated pair decomposition).
static l2p_functor l2p_function(FMELocalContext *pLocalContext)
creates Local-to-Point functor
Declaration of class ArrayGraph.
static min_max_functor< float > min_max_y_function(FMELocalContext *pLocalContext)
creates a min max functor for the y coords of the node
float min_y
global point, node min y coordinate for bounding box calculations
uint32_t operator()(void) const
void operator()(uint32_t i)
FMENodeChainPartition leafPartition
chain of leaf nodes assigned to the thread
uint32_t preProcMaxNumIterations
number of iterations the preprocessing is applied
struct for distributing subtrees to the threads
float max_y
global point, node max y coordinate for bounding box calculations
Information about incident edges (16 bytes).
void operator()(uint32_t begin, uint32_t end)
LinearQuadtreeExpansion & expansions
FMEGlobalOptions * pOptions
pointer to the global options
void operator()(LinearQuadtree::NodeID nodeIndex)
void operator()(LinearQuadtree::NodeID nodeIndexSource, LinearQuadtree::NodeID nodeIndexReceiver)
LinearQuadtreeExpansion * quadtreeExp
LinearQuadtreeExpansion * pExpansion
pointer to the coeefficients
void operator()(LinearQuadtree::NodeID nodeIndexA, LinearQuadtree::NodeID nodeIndexB)
FMELocalContext ** localContexts
CollectForceFunctor(FMELocalContext *pLocalContext)
PointID firstPoint(NodeID nodeID) const
void operator()(uint32_t begin, uint32_t end)
FMENodeChainPartition innerNodePartition
chain of inner nodes assigned to the thread
void operator()(uint32_t i)
std::list< LinearQuadtree::NodeID > nodes
static constexpr int ZERO_GLOBAL_ARRAY
Calculates the repulsive forces acting between all nodes of the direct interacting cells of the i-th ...
uint32_t operator()(void) const
FMEGlobalContext * globalContext
void operator()(uint32_t i)
void newPartition(uint32_t nodeID)
static p2p_functor p2p_function(FMELocalContext *pLocalContext)
creates Local-to-Point functor
void operator()(LinearQuadtree::NodeID nodeIndex, LinearQuadtree::PointID pointIndex)
void operator()(LinearQuadtree::NodeID parent, LinearQuadtree::NodeID child)
void operator()(uint32_t begin, uint32_t end)
m2l_functor(LinearQuadtreeExpansion &e)
FMETreePartition * currPartition()
void P2M(uint32_t point, uint32_t receiver)
adds a point with the given charge to the receiver expansion
LinearQuadtree * quadtree
p2m_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e)
l2p_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e, float *x, float *y)
void for_loop(Func &func)
float min_x
global point, node min x coordinate for bounding box calculations
void operator()(uint32_t begin, uint32_t end)
static NodeMoveFunctor< FLAGS > node_move_function(FMELocalContext *pLocalContext)
LinearQuadtreeExpansion & expansions
static l2l_functor l2l_function(FMELocalContext *pLocalContext)
creates Local-to-Local functor
void operator()(LinearQuadtree::NodeID nodeIndex)
LinearQuadtreeExpansion * quadtreeExp
forall_children_functor< F > forall_children(F f) const
creator
uint32_t operator()(void) const
const LinearQuadtree & tree
Converts the multipole expansion coefficients from all nodes which are well separated from the i-th n...
LQMortonFunctor(FMELocalContext *pLocalContext)
FMELocalContext * localContext
float max_y
global point, node max y coordinate for bounding box calculations
LinearQuadtreeExpansion * quadtreeExp
static EdgeForceFunctor< FLAGS > edge_force_function(FMELocalContext *pLocalContext)
uint32_t numInnerNodes
number of inner nodes the thread prepared
bool doPrepProcessing
enable preprocessing
ArrayGraph * pGraph
pointer to the array graph
uint32_t operator()(void) const
void operator()(uint32_t begin, uint32_t end)
LinearQuadtree::NodeID firstInnerNode
first inner nodes the thread prepared
uint32_t maxNumIterations
maximum number of iterations in the main step
float * nodeXPos()
Returns the x coord array for all nodes.
void operator()(uint32_t begin, uint32_t end)
float pointY(PointID point) const
void operator()(uint32_t begin, uint32_t end)
Information about an edge (16 bytes).
const LinearQuadtree & tree
void operator()(LinearQuadtree::NodeID parent, LinearQuadtree::NodeID child)
float * forceX
local force array for all nodes, points
NodeID pointLeaf(PointID point) const
float max_x
global point, node max x coordinate for bounding box calculations
void operator()(uint32_t begin, uint32_t end)
float pointX(PointID point) const
Declaration of class LinearQuadtreeBuilder.
EdgeForceFunctor(FMELocalContext *pLocalContext)
uint32_t degree
Total count of pairs where is either the first or second node.
float timeStep
time step factor for the main step
LinearQuadtree * quadtree
constexpr int operator|(int lhs, FMECollect rhs)
Declaration of FME kernel.
LinearQuadtree * pQuadtree
pointer to the quadtree
double stopCritAvgForce
stopping criteria
void operator()(uint32_t i)
void operator()(uint32_t i)
static p2m_functor p2m_function(FMELocalContext *pLocalContext)
creates a Point-to-Multipole functor
uint32_t operator()(void) const
void operator()(uint32_t i)
uint32_t operator()(void) const
Calculates the repulsive forces acting between all nodes inside the cell of the i-th LinearQuadtree n...
Declaration of class LinearQuadtree.
float * nodeSize()
Returns the node size array for all nodes.
uint32_t a
First node of the pair.
const LinearQuadtree & tree
uint32_t numThreads
number of threads, local contexts
LinearQuadtreeExpansion & expansions
Point-to-Multipole functor.
Multipole-to-Multipole functor.
float min_x
global point, node min x coordinate for bounding box calculations
double avgForce
local maximum force
NodeMoveFunctor(FMELocalContext *pLocalContext)
WSPD * pWSPD
pointer to the well separated pairs decomposition
LinearQuadtree * quadtree
float min_y
global point, node min y coordinate for bounding box calculations
Multipole-to-Local functor.
static CollectForceFunctor< FLAGS > collect_force_function(FMELocalContext *pLocalContext)
float * globalForceY
the global node force y array
uint32_t multipolePrecision
m2m_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e)
uint32_t minNumIterations
minimum number of iterations to be done regardless of any other conditions
void operator()(uint32_t i)
LQCoordsFunctor(FMELocalContext *pLocalContext)
void L2L(uint32_t source, uint32_t receiver)
shifts the source local coefficient to the center of the receiver and adds them
uint32_t numLeaves
number of leaves the thread prepared
FMELocalContext ** pLocalContext
all local contexts
LinearQuadtree * quadtree
uint32_t numPointsPerThread
static min_max_functor< float > min_max_x_function(FMELocalContext *pLocalContext)
creates a min max functor for the x coords of the node
bool earlyExit
var for the main thread to notify the other threads that they are done
The partitioner which partitions the quadtree into subtrees and partitions the sequence of inner node...
LinearQuadtreeExpansion * quadtreeExp
float * globalForceX
the global node force x array
l2l_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e)
D2DFunctor(FMELocalContext *pLocalContext)
void operator()(uint32_t i)
LinearQuadtree * quadtree
FMETreePartition treePartition
tree partition assigned to the thread
static pair_call_functor< F, A > pair_call(F f, A a)
creates a pair call resulting in a call f(a, *)
float normEdgeLength
average edge length when desired edge length are normalized
static constexpr int TIME_STEP_NORMAL
float * currentEdgeLength
uint32_t operator()(void) const
p2p_functor(const LinearQuadtree &t, float *x, float *y)
float max_x
global point, node max x coordinate for bounding box calculations
static m2l_functor m2l_function(FMELocalContext *pLocalContext)
creates Multipole-to-Local functor
LinearQuadtreeExpansion & expansions
Declaration of class LinearQuadtreeExpansion.
M2LFunctor(FMELocalContext *pLocalContext)
Class for the Well-Separated-Pairs-Decomposition (WSPD)
static m2m_functor m2m_function(FMELocalContext *pLocalContext)
creates Multipole-to-Multipole functor
FMELocalContext ** localContexts
void L2P(uint32_t source, uint32_t point, float &fx, float &fy)
evaluates the derivate of the local expansion at the point and adds the forces to fx fy ...
for every hyperedge e a minimal subcubic tree connecting all hypernodes incident with e together is a...
generic min max functor for an array
The namespace for all OGDF objects.
float * desiredEdgeLength
LinearQuadtree::NodeID lastInnerNode
last inner nodes the thread prepared
float preProcEdgeForceFactor
edge force factor for the preprocessing step
float preProcTimeStep
time step factor for the preprocessing step
const LinearQuadtree & tree
LinearQuadtree::NodeID lastLeaf
last leaves the thread prepared
Computes the coords and size of the i-th node in the LinearQuadtree.
void for_loop_array_set(uint32_t threadNr, uint32_t numThreads, TYP *a, uint32_t n, TYP value)
LinearQuadtree::NodeID firstLeaf
first leaves the thread prepared
float repForceFactor
repulsive force factor for the main step
void operator()(uint32_t begin, uint32_t end)
void operator()(LinearQuadtree::NodeID nodeIndex)
float * nodeYPos()
Returns the y coord array for all nodes.
float edgeForceFactor
edge force factor for the main step
double stopCritConstSq
stopping criteria
uint32_t b
Second node of the pair.
void M2L(uint32_t source, uint32_t receiver)
converts the source multipole coefficient in to a local coefficients at the center of the receiver an...
void M2M(uint32_t source, uint32_t receiver)
shifts the source multipole coefficient to the center of the receiver and adds them ...
void operator()(uint32_t i)
FMEGlobalContext * pGlobalContext
pointer to the global context
double stopCritForce
stopping criteria
void operator()(LinearQuadtree::PointID pointIndex)
const LinearQuadtree & tree
bool doPostProcessing
enable postprocessing
float normNodeSize
average node size when node sizes are normalized
LinearQuadtree * quadtree
LinearQuadtreeExpansion & expansions