43 namespace fast_multipole_embedder {
49 std::list<LinearQuadtree::NodeID>
nodes;
52 template<
typename Func>
165 translate_x = -quadtree->
minX();
166 translate_y = -quadtree->minY();
167 scale = quadtree->scaleInv();
172 return quadtree->numberOfPoints();
178 uint32_t ref = p.
ref;
179 p.
mortonNr = mortonNumber<uint64_t, uint32_t>((uint32_t)((x[ref] + translate_x)*scale), (uint32_t)((y[ref] + translate_y)*scale));
184 for (uint32_t i = begin; i <= end; i++)
212 uint32_t firstPointOfLeaf = tree.
firstPoint(nodeIndex);
213 for (uint32_t pointIndex=firstPointOfLeaf; pointIndex < (firstPointOfLeaf+numPointsInLeaf); pointIndex++)
215 expansions.
P2M(pointIndex, nodeIndex);
238 expansions.
M2M(child, parent);
264 expansions.
M2L(nodeIndexSource, nodeIndexReceiver);
286 expansions.
L2L(parent, child);
315 expansions.
L2P(nodeIndex, pointIndex, fx[pointIndex], fy[pointIndex]);
321 this->operator ()(nodeIndex, pointIndex);
344 uint32_t offsetA = tree.
firstPoint(nodeIndexA);
345 uint32_t offsetB = tree.
firstPoint(nodeIndexB);
350 fx + offsetA, fy + offsetA, numPointsA,
353 fx + offsetB, fy + offsetB, numPointsB);
377 : numPointsPerThread(0)
378 , numThreads(pLocalContext->pGlobalContext->numThreads)
380 ,
tree(pLocalContext->pGlobalContext->pQuadtree)
381 , localContexts(pLocalContext->pGlobalContext->pLocalContext)
386 uint32_t numInnerNodesPerThread =
tree->numberOfInnerNodes() / numThreads;
387 if (numInnerNodesPerThread < 25)
389 localContexts[0]->innerNodePartition.begin =
tree->firstInnerNode();
390 localContexts[0]->innerNodePartition.numNodes =
tree->numberOfInnerNodes();
391 for (uint32_t i=1; i< numThreads; i++)
393 localContexts[i]->innerNodePartition.numNodes = 0;
400 localContexts[0]->innerNodePartition.begin = curr;
401 localContexts[0]->innerNodePartition.numNodes = 0;
402 for (uint32_t i=0; i<
tree->numberOfInnerNodes(); i++)
404 localContexts[currThread]->innerNodePartition.numNodes++;
405 curr =
tree->nextNode(curr);
406 if (localContexts[currThread]->innerNodePartition.numNodes >= numInnerNodesPerThread && currThread < numThreads - 1)
409 localContexts[currThread]->innerNodePartition.numNodes = 0;
410 localContexts[currThread]->innerNodePartition.begin = curr;
416 uint32_t numLeavesPerThread =
tree->numberOfLeaves() / numThreads;
417 if (numLeavesPerThread < 25)
419 localContexts[0]->leafPartition.begin =
tree->firstLeaf();
420 localContexts[0]->leafPartition.numNodes =
tree->numberOfLeaves();
421 for (uint32_t i=1; i< numThreads; i++)
423 localContexts[i]->leafPartition.numNodes = 0;
429 localContexts[0]->leafPartition.begin = curr;
430 localContexts[0]->leafPartition.numNodes = 0;
431 for (uint32_t i=0; i<
tree->numberOfLeaves(); i++)
433 localContexts[currThread]->leafPartition.numNodes++;
434 curr =
tree->nextNode(curr);
435 if (localContexts[currThread]->leafPartition.numNodes >= numLeavesPerThread && currThread < numThreads - 1)
438 localContexts[currThread]->leafPartition.numNodes = 0;
439 localContexts[currThread]->leafPartition.begin = curr;
447 partitionNodeChains();
449 numPointsPerThread =
tree->numberOfPoints() / numThreads;
450 for (uint32_t i=0; i < numThreads; i++)
452 localContexts[i]->treePartition.nodes.clear();
453 localContexts[i]->treePartition.pointCount = 0;
461 uint32_t bound =
tree->numberOfPoints() / (numThreads*numThreads);
463 if (
tree->isLeaf(nodeID) ||
tree->numberOfPoints(nodeID) < bound)
464 l_par.push_back(nodeID);
466 for (uint32_t i = 0; i <
tree->numberOfChilds(nodeID); i++)
467 newPartition(
tree->child(nodeID, i));
473 newPartition(
tree->root());
474 uint32_t bound = (
tree->numberOfPoints() / (numThreads)) + (
tree->numberOfPoints() / (numThreads*numThreads*2));
475 while (!l_par.empty())
478 uint32_t v = l_par.front();
479 if (((partition->
pointCount +
tree->numberOfPoints(v)) <= bound) ||
480 (currThread==numThreads-1))
483 partition->
nodes.push_back(v);
495 return &localContexts[currThread]->treePartition;
521 return quadtree->numberOfPoints();
527 uint32_t ref = p.
ref;
528 quadtree->setPoint(i, x[ref], y[ref], s[ref]);
533 for (uint32_t i = begin; i <= end; i++)
561 return quadtree->numberOfNodes();
566 quadtree->computeCoords(i);
571 for (uint32_t i = begin; i <= end; i++)
599 return quadtree->numberOfNodes();
604 uint32_t currEntryIndex = wspd->firstPairEntry(i);
605 for (uint32_t k = 0; k < wspd->numWSNodes(i); k++)
607 uint32_t j = wspd->wsNodeOfPair(currEntryIndex, i);
608 quadtreeExp->M2L(j, i);
609 currEntryIndex = wspd->nextPair(currEntryIndex, i);
615 for (uint32_t i = begin; i <= end; i++)
638 forceArrayX = pLocalContext->
forceX;
639 forceArrayY = pLocalContext->
forceY;
644 return quadtree->numberOfDirectNodes();
649 uint32_t nodeI = quadtree->directNode(i);
650 uint32_t offset = quadtree->firstPoint(nodeI);
651 uint32_t numPoints = quadtree->numberOfPoints(nodeI);
652 eval_direct_fast(quadtree->pointX() + offset, quadtree->pointY() + offset, quadtree->pointSize() + offset, forceArrayX + offset, forceArrayY + offset, numPoints);
657 for (uint32_t i = begin; i <= end; i++)
681 forceArrayX = pLocalContext->
forceX;
682 forceArrayY = pLocalContext->
forceY;
687 return quadtree->numberOfDirectPairs();
692 uint32_t nodeA = quadtree->directNodeA(i);
693 uint32_t nodeB = quadtree->directNodeB(i);
694 uint32_t offsetA = quadtree->firstPoint(nodeA);
695 uint32_t offsetB = quadtree->firstPoint(nodeB);
696 uint32_t numPointsA = quadtree->numberOfPoints(nodeA);
697 uint32_t numPointsB = quadtree->numberOfPoints(nodeB);
698 eval_direct_fast(quadtree->pointX() + offsetA, quadtree->pointY() + offsetA,
699 quadtree->pointSize() + offsetA,
700 forceArrayX + offsetA, forceArrayY + offsetA, numPointsA,
701 quadtree->pointX() + offsetB, quadtree->pointY() + offsetB,
702 quadtree->pointSize() + offsetB,
703 forceArrayX + offsetB, forceArrayY + offsetB, numPointsB);
708 for (uint32_t i = begin; i <= end; i++)
727 return lhs &
static_cast<int>(rhs);
730 template<
unsigned int FLAGS>
738 y = pGraph->nodeYPos();
739 edgeInfo = pGraph->edgeInfo();
740 nodeInfo = pGraph->nodeInfo();
741 desiredEdgeLength = pGraph->desiredEdgeLength();
742 nodeSize = pGraph->nodeSize();
743 forceArrayX = pLocalContext->
forceX;
744 forceArrayY = pLocalContext->
forceY;
749 return pGraph->numEdges();
758 float d_x = x[e_info.
a] - x[e_info.
b];
759 float d_y = y[e_info.
a] - y[e_info.
b];
760 float d_sq = d_x*d_x + d_y*d_y;
762 float f = (float)(logf(d_sq)*0.5f-logf(desiredEdgeLength[i]));
769 fa = (float)(fa/((
float)a_info.
degree));
770 fb = (float)(fb/((
float)b_info.
degree));
775 fa += (nodeSize[e_info.
b] / d_sq);
776 fb += (nodeSize[e_info.
a] / d_sq);
778 forceArrayX[e_info.
a] -= fa*d_x;
779 forceArrayY[e_info.
a] -= fa*d_y;
780 forceArrayX[e_info.
b] += fb*d_x;
781 forceArrayY[e_info.
b] += fb*d_y;
786 for (uint32_t i = begin; i <= end; i++)
806 template<
unsigned int FLAGS>
824 return lhs &
static_cast<int>(rhs);
828 return lhs |
static_cast<int>(rhs);
832 return static_cast<int>(lhs) | static_cast<int>(rhs);
835 template<
unsigned int FLAGS>
845 globalArrayX = globalContext->globalForceX;
846 globalArrayY = globalContext->globalForceY;
862 return pGraph->numNodes();
870 for (uint32_t j=0; j < numContexts; j++)
872 float* localArrayX = localContexts[j]->forceX;
873 float* localArrayY = localContexts[j]->forceY;
874 sumX += localArrayX[i];
875 sumY += localArrayY[i];
878 localArrayX[i] = 0.0f;
879 localArrayY[i] = 0.0f;
884 i = globalContext->pQuadtree->refOfPoint(i);
887 && pGraph->nodeInfo(i).degree > 100) {
889 sumX /= (float)pGraph->nodeInfo(i).degree;
890 sumY /= (float)pGraph->nodeInfo(i).degree;
892 globalArrayX[i] += sumX*factor;
893 globalArrayY[i] += sumY*factor;
898 for (uint32_t i = begin; i <= end; i++)
915 template<
unsigned int FLAGS>
927 template<
unsigned int FLAGS>
935 float* xCoords,
float* yCoords,
937 float* globalForceArray)
938 : x(xCoords), y(yCoords), timeStep(ftimeStep), forceArray(globalForceArray)
941 if (FLAGS & TIME_STEP_NORMAL)
944 if (FLAGS & TIME_STEP_PREP)
950 y = pGraph->nodeYPos();
951 nodeMoveRadius = pGraph->nodeMoveRadius();
954 localContext = pLocalContext;
959 inline void operator()(
void)
const 961 return pGraph->numNodes();
967 float d_x = forceArrayX[i]* timeStep;
968 float d_y = forceArrayY[i]* timeStep;
969 double dsq = (d_x*d_x + d_y*d_y);
970 double d = sqrt(dsq);
972 localContext->maxForceSq = max<double>(localContext->maxForceSq, (double)dsq );
973 localContext->avgForce += d;
978 if (FLAGS & ZERO_GLOBAL_ARRAY)
980 forceArrayX[i] = 0.0;
981 forceArrayY[i] = 0.0;
984 forceArrayX[i] = d_x;
985 forceArrayY[i] = d_y;
989 forceArrayX[i] = 0.0;
990 forceArrayY[i] = 0.0;
996 for (uint32_t i = begin; i <= end; i++)
1015 template<
unsigned int FLAGS>
1022 template<
typename TYP>
1025 uint32_t s = n/numThreads;
1026 uint32_t o = s*threadNr;
1027 if (threadNr == numThreads-1)
1028 s = s + (n % numThreads);
1030 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