Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

FMEFunc.h
Go to the documentation of this file.
1 
32 #pragma once
33 
40 #include <list>
41 
42 namespace ogdf {
43 namespace fast_multipole_embedder {
44 
45 
48 {
49  std::list<LinearQuadtree::NodeID> nodes;
50  uint32_t pointCount;
51 
52  template<typename Func>
53  void for_loop(Func& func)
54  {
55  for (LinearQuadtree::NodeID id : nodes)
56  func(id);
57  }
58 };
59 
61 {
62  uint32_t begin;
63  uint32_t numNodes;
64 };
65 
66 
69 {
73 
74  float timeStep;
78  float normNodeSize;
79  uint32_t maxNumIterations;
80  uint32_t minNumIterations;
81 
84 
85  double stopCritForce;
87  double stopCritConstSq;
88 
90 };
91 
92 
94 struct FMELocalContext;
95 
100 {
102  uint32_t numThreads;
107  float* globalForceX;
108  float* globalForceY;
110  bool earlyExit;
111  float scaleFactor;
112  float coolDown;
113  float min_x;
114  float max_x;
115  float min_y;
116  float max_y;
118 };
119 
120 
125 {
127  float* forceX;
128  float* forceY;
129  double maxForceSq;
130  double avgForce;
131  float min_x;
132  float max_x;
133  float min_y;
134  float max_y;
139 
142  uint32_t numInnerNodes;
143 
146  uint32_t numLeaves;
147 };
148 
149 
152 {
153  return min_max_functor<float>(pLocalContext->pGlobalContext->pGraph->nodeXPos(), pLocalContext->min_x, pLocalContext->max_x);
154 }
155 
158 {
159  return min_max_functor<float>(pLocalContext->pGlobalContext->pGraph->nodeYPos(), pLocalContext->min_y, pLocalContext->max_y);
160 }
161 
163 {
164 public:
165  inline LQMortonFunctor ( FMELocalContext* pLocalContext )
166  {
167  x = pLocalContext->pGlobalContext->pGraph->nodeXPos();
168  y = pLocalContext->pGlobalContext->pGraph->nodeYPos();
169  s = pLocalContext->pGlobalContext->pGraph->nodeSize();
170  quadtree = pLocalContext->pGlobalContext->pQuadtree;
171  translate_x = -quadtree->minX();
172  translate_y = -quadtree->minY();
173  scale = quadtree->scaleInv();
174  }
175 
176  inline uint32_t operator()(void) const
177  {
178  return quadtree->numberOfPoints();
179  }
180 
181  inline void operator()(uint32_t i)
182  {
183  LinearQuadtree::LQPoint& p = quadtree->point(i);
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));
186  }
187 
188  inline void operator()(uint32_t begin, uint32_t end)
189  {
190  for (uint32_t i = begin; i <= end; i++)
191  {
192  this->operator()(i);
193  }
194  }
195 
196 private:
198  float translate_x;
199  float translate_y;
200  double scale;
201  float* x;
202  float* y;
203  float* s;
204 };
205 
206 
209 {
212 
213  p2m_functor(const LinearQuadtree& t, LinearQuadtreeExpansion& e) : tree(t), expansions(e) { }
214 
215  inline void operator()(LinearQuadtree::NodeID nodeIndex)
216  {
217  uint32_t numPointsInLeaf = tree.numberOfPoints(nodeIndex);
218  uint32_t firstPointOfLeaf = tree.firstPoint(nodeIndex);
219  for (uint32_t pointIndex=firstPointOfLeaf; pointIndex < (firstPointOfLeaf+numPointsInLeaf); pointIndex++)
220  {
221  expansions.P2M(pointIndex, nodeIndex);
222  }
223  }
224 };
225 
226 
228 static inline p2m_functor p2m_function(FMELocalContext* pLocalContext)
229 {
230  return p2m_functor(*pLocalContext->pGlobalContext->pQuadtree, *pLocalContext->pGlobalContext->pExpansion);
231 }
232 
233 
236 {
239 
240  m2m_functor(const LinearQuadtree& t, LinearQuadtreeExpansion& e) : tree(t), expansions(e) { }
241 
243  {
244  expansions.M2M(child, parent);
245  }
246 
247  inline void operator()(LinearQuadtree::NodeID nodeIndex)
248  {
249  tree.forall_children(pair_call(*this, nodeIndex))(nodeIndex);
250  }
251 };
252 
253 
255 static inline m2m_functor m2m_function(FMELocalContext* pLocalContext)
256 {
257  return m2m_functor(*pLocalContext->pGlobalContext->pQuadtree, *pLocalContext->pGlobalContext->pExpansion);
258 }
259 
260 
263 {
265 
266  m2l_functor(LinearQuadtreeExpansion& e) : expansions(e) { }
267 
268  inline void operator()(LinearQuadtree::NodeID nodeIndexSource, LinearQuadtree::NodeID nodeIndexReceiver)
269  {
270  expansions.M2L(nodeIndexSource, nodeIndexReceiver);
271  }
272 };
273 
274 
276 static inline m2l_functor m2l_function(FMELocalContext* pLocalContext)
277 {
278  return m2l_functor(*pLocalContext->pGlobalContext->pExpansion);
279 }
280 
281 
284 {
287 
288  l2l_functor(const LinearQuadtree& t, LinearQuadtreeExpansion& e) : tree(t), expansions(e) { }
289 
291  {
292  expansions.L2L(parent, child);
293  }
294 
295  inline void operator()(LinearQuadtree::NodeID nodeIndex)
296  {
297  tree.forall_children(pair_call(*this, nodeIndex))(nodeIndex);
298  }
299 };
300 
301 
303 static inline l2l_functor l2l_function(FMELocalContext* pLocalContext)
304 {
305  return l2l_functor(*pLocalContext->pGlobalContext->pQuadtree, *pLocalContext->pGlobalContext->pExpansion);
306 }
307 
308 
311 {
314  float* fx;
315  float* fy;
316 
317  l2p_functor(const LinearQuadtree& t, LinearQuadtreeExpansion& e, float* x, float* y) : tree(t), expansions(e), fx(x), fy(y) { }
318 
319  inline void operator()(LinearQuadtree::NodeID nodeIndex, LinearQuadtree::PointID pointIndex)
320  {
321  expansions.L2P(nodeIndex, pointIndex, fx[pointIndex], fy[pointIndex]);
322  }
323 
324  inline void operator()(LinearQuadtree::PointID pointIndex)
325  {
326  LinearQuadtree::NodeID nodeIndex = tree.pointLeaf(pointIndex);
327  this->operator ()(nodeIndex, pointIndex);
328  }
329 };
330 
331 
333 static inline l2p_functor l2p_function(FMELocalContext* pLocalContext)
334 {
335  return l2p_functor(*pLocalContext->pGlobalContext->pQuadtree, *pLocalContext->pGlobalContext->pExpansion, pLocalContext->forceX, pLocalContext->forceY);
336 }
337 
338 
341 {
343  float* fx;
344  float* fy;
345 
346  p2p_functor(const LinearQuadtree& t, float* x, float* y) : tree(t), fx(x), fy(y) { }
347 
348  inline void operator()(LinearQuadtree::NodeID nodeIndexA, LinearQuadtree::NodeID nodeIndexB)
349  {
350  uint32_t offsetA = tree.firstPoint(nodeIndexA);
351  uint32_t offsetB = tree.firstPoint(nodeIndexB);
352  uint32_t numPointsA = tree.numberOfPoints(nodeIndexA);
353  uint32_t numPointsB = tree.numberOfPoints(nodeIndexB);
354  eval_direct_fast(tree.pointX() + offsetA, tree.pointY() + offsetA,
355  tree.pointSize() + offsetA,
356  fx + offsetA, fy + offsetA, numPointsA,
357  tree.pointX() + offsetB, tree.pointY() + offsetB,
358  tree.pointSize() + offsetB,
359  fx + offsetB, fy + offsetB, numPointsB);
360  }
361 
362  inline void operator()(LinearQuadtree::NodeID nodeIndex)
363  {
364  uint32_t offset = tree.firstPoint(nodeIndex);
365  uint32_t numPoints = tree.numberOfPoints(nodeIndex);
366  eval_direct_fast(tree.pointX() + offset, tree.pointY() + offset, tree.pointSize() + offset, fx + offset, fy + offset, numPoints);
367  }
368 };
369 
370 
372 static inline p2p_functor p2p_function(FMELocalContext* pLocalContext)
373 {
374  return p2p_functor(*pLocalContext->pGlobalContext->pQuadtree, pLocalContext->forceX, pLocalContext->forceY);
375 }
376 
377 
380 {
381 public:
382  explicit LQPartitioner( FMELocalContext* pLocalContext )
383  {
384  numThreads = pLocalContext->pGlobalContext->numThreads;
385  tree = pLocalContext->pGlobalContext->pQuadtree;
386  localContexts = pLocalContext->pGlobalContext->pLocalContext;
387  }
388 
390  {
391  uint32_t numInnerNodesPerThread = tree->numberOfInnerNodes() / numThreads;
392  if (numInnerNodesPerThread < 25)
393  {
394  localContexts[0]->innerNodePartition.begin = tree->firstInnerNode();
395  localContexts[0]->innerNodePartition.numNodes = tree->numberOfInnerNodes();
396  for (uint32_t i=1; i< numThreads; i++)
397  {
398  localContexts[i]->innerNodePartition.numNodes = 0;
399  }
400  } else
401  {
402 
403  LinearQuadtree::NodeID curr = tree->firstInnerNode();
404  currThread = 0;
405  localContexts[0]->innerNodePartition.begin = curr;
406  localContexts[0]->innerNodePartition.numNodes = 0;
407  for (uint32_t i=0; i< tree->numberOfInnerNodes(); i++)
408  {
409  localContexts[currThread]->innerNodePartition.numNodes++;
410  curr = tree->nextNode(curr);
411  if ((localContexts[currThread]->innerNodePartition.numNodes>=numInnerNodesPerThread) && (currThread < numThreads-1))
412  {
413  currThread++;
414  localContexts[currThread]->innerNodePartition.numNodes = 0;
415  localContexts[currThread]->innerNodePartition.begin = curr;
416  }
417  }
418 
419  }
420 
421  uint32_t numLeavesPerThread = tree->numberOfLeaves() / numThreads;
422  if (numLeavesPerThread < 25)
423  {
424  localContexts[0]->leafPartition.begin = tree->firstLeaf();
425  localContexts[0]->leafPartition.numNodes = tree->numberOfLeaves();
426  for (uint32_t i=1; i< numThreads; i++)
427  {
428  localContexts[i]->leafPartition.numNodes = 0;
429  }
430  } else
431  {
432  LinearQuadtree::NodeID curr = tree->firstLeaf();
433  currThread = 0;
434  localContexts[0]->leafPartition.begin = curr;
435  localContexts[0]->leafPartition.numNodes = 0;
436  for (uint32_t i=0; i< tree->numberOfLeaves(); i++)
437  {
438  localContexts[currThread]->leafPartition.numNodes++;
439  curr = tree->nextNode(curr);
440  if ((localContexts[currThread]->leafPartition.numNodes>=numLeavesPerThread) && (currThread < numThreads-1))
441  {
442  currThread++;
443  localContexts[currThread]->leafPartition.numNodes = 0;
444  localContexts[currThread]->leafPartition.begin = curr;
445  }
446  }
447  }
448  }
449 
450  void partition()
451  {
452  partitionNodeChains();
453  currThread = 0;
454  numPointsPerThread = tree->numberOfPoints() / numThreads;
455  for (uint32_t i=0; i < numThreads; i++)
456  {
457  localContexts[i]->treePartition.nodes.clear();
458  localContexts[i]->treePartition.pointCount = 0;
459  }
460  if (numThreads>1)
461  newPartition();
462  }
463 
464  void newPartition(uint32_t nodeID)
465  {
466  uint32_t bound = tree->numberOfPoints() / (numThreads*numThreads);
467 
468  if (tree->isLeaf(nodeID) || (tree->numberOfPoints(nodeID) < bound))
469  l_par.push_back(nodeID);
470  else
471  for (uint32_t i = 0; i < tree->numberOfChilds(nodeID); i++)
472  newPartition(tree->child(nodeID, i));
473  }
474 
476  {
477  l_par.clear();
478  newPartition(tree->root());
479  uint32_t bound = (tree->numberOfPoints() / (numThreads)) + (tree->numberOfPoints() / (numThreads*numThreads*2));
480  while (!l_par.empty())
481  {
482  FMETreePartition* partition = currPartition();
483  uint32_t v = l_par.front();
484  if (((partition->pointCount + tree->numberOfPoints(v)) <= bound) ||
485  (currThread==numThreads-1))
486  {
487  partition->pointCount += tree->numberOfPoints(v);
488  partition->nodes.push_back(v);
489  tree->nodeFence(v);
490  l_par.pop_front();
491  } else
492  {
493  currThread++;
494  }
495  }
496  }
497 
499  {
500  return &localContexts[currThread]->treePartition;
501  }
502 
503 private:
505  uint32_t numThreads;
506  uint32_t currThread;
507  std::list<uint32_t> l_par;
510 };
511 
512 
514 {
515 public:
516  inline explicit LQPointUpdateFunctor ( FMELocalContext* pLocalContext )
517  {
518  x = pLocalContext->pGlobalContext->pGraph->nodeXPos();
519  y = pLocalContext->pGlobalContext->pGraph->nodeYPos();
520  s = pLocalContext->pGlobalContext->pGraph->nodeSize();
521  quadtree = pLocalContext->pGlobalContext->pQuadtree;
522  }
523 
524  inline uint32_t operator()(void) const
525  {
526  return quadtree->numberOfPoints();
527  }
528 
529  inline void operator()(uint32_t i)
530  {
531  LinearQuadtree::LQPoint& p = quadtree->point(i);
532  uint32_t ref = p.ref;
533  quadtree->setPoint(i, x[ref], y[ref], s[ref]);
534  }
535 
536  inline void operator()(uint32_t begin, uint32_t end)
537  {
538  for (uint32_t i = begin; i <= end; i++)
539  {
540  this->operator()(i);
541  }
542  }
543 
544 private:
546  float* x;
547  float* y;
548  float* s;
549 };
550 
551 
556 {
557 public:
558  inline explicit LQCoordsFunctor( FMELocalContext* pLocalContext )
559  {
560  quadtree = pLocalContext->pGlobalContext->pQuadtree;
561  quadtreeExp = pLocalContext->pGlobalContext->pExpansion;
562  }
563 
564  inline uint32_t operator()(void) const
565  {
566  return quadtree->numberOfNodes();
567  }
568 
569  inline void operator()( uint32_t i )
570  {
571  quadtree->computeCoords(i);
572  }
573 
574  inline void operator()(uint32_t begin, uint32_t end)
575  {
576  for (uint32_t i = begin; i <= end; i++)
577  {
578  this->operator()(i);
579  }
580  }
581 
582 private:
585 };
586 
587 
593 {
594 public:
595  inline explicit M2LFunctor( FMELocalContext* pLocalContext )
596  {
597  quadtree = pLocalContext->pGlobalContext->pQuadtree;
598  quadtreeExp = pLocalContext->pGlobalContext->pExpansion;
599  wspd = pLocalContext->pGlobalContext->pWSPD;
600  }
601 
602  inline uint32_t operator()(void) const
603  {
604  return quadtree->numberOfNodes();
605  }
606 
607  inline void operator()(uint32_t i)
608  {
609  uint32_t currEntryIndex = wspd->firstPairEntry(i);
610  for (uint32_t k = 0; k < wspd->numWSNodes(i); k++)
611  {
612  uint32_t j = wspd->wsNodeOfPair(currEntryIndex, i);
613  quadtreeExp->M2L(j, i);
614  currEntryIndex = wspd->nextPair(currEntryIndex, i);
615  }
616  }
617 
618  inline void operator()(uint32_t begin, uint32_t end)
619  {
620  for (uint32_t i = begin; i <= end; i++)
621  {
622  this->operator()(i);
623  }
624  }
625 
626 private:
630 };
631 
632 
637 {
638 public:
639  inline explicit NDFunctor( FMELocalContext* pLocalContext )
640  {
641  quadtree = pLocalContext->pGlobalContext->pQuadtree;
642  quadtreeExp = pLocalContext->pGlobalContext->pExpansion;
643  forceArrayX = pLocalContext->forceX;
644  forceArrayY = pLocalContext->forceY;
645  }
646 
647  inline uint32_t operator()(void) const
648  {
649  return quadtree->numberOfDirectNodes();
650  }
651 
652  inline void operator()(uint32_t i)
653  {
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);
658  }
659 
660  inline void operator()(uint32_t begin, uint32_t end)
661  {
662  for (uint32_t i = begin; i <= end; i++)
663  {
664  this->operator()(i);
665  }
666  }
667 
668 private:
671  float* forceArrayX;
672  float* forceArrayY;
673 };
674 
675 
680 {
681 public:
682  inline explicit D2DFunctor( FMELocalContext* pLocalContext )
683  {
684  quadtree = pLocalContext->pGlobalContext->pQuadtree;
685  quadtreeExp = pLocalContext->pGlobalContext->pExpansion;
686  forceArrayX = pLocalContext->forceX;
687  forceArrayY = pLocalContext->forceY;
688  }
689 
690  inline uint32_t operator()(void) const
691  {
692  return quadtree->numberOfDirectPairs();
693  }
694 
695  inline void operator()(uint32_t i)
696  {
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);
709  }
710 
711  inline void operator()(uint32_t begin, uint32_t end)
712  {
713  for (uint32_t i = begin; i <= end; i++)
714  {
715  this->operator()(i);
716  }
717  }
718 
719 private:
722  float* forceArrayX;
723  float* forceArrayY;
724 };
725 
726 enum class FMEEdgeForce {
727  SubRep = 0x2,
728  DivDegree = 0x8
729 };
730 
731 inline int operator & (int lhs, FMEEdgeForce rhs) {
732  return lhs & static_cast<int>(rhs);
733 }
734 
735 template<unsigned int FLAGS>
737 {
738 public:
739  inline explicit EdgeForceFunctor( FMELocalContext* pLocalContext )
740  {
741  pGraph = pLocalContext->pGlobalContext->pGraph;
742  x = pGraph->nodeXPos();
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;
750  }
751 
752  inline uint32_t operator()(void) const
753  {
754  return pGraph->numEdges();
755  }
756 
757  inline void operator()(uint32_t i)
758  {
759  const EdgeAdjInfo& e_info = edgeInfo[i];
760  const NodeAdjInfo& a_info = nodeInfo[e_info.a];
761  const NodeAdjInfo& b_info = nodeInfo[e_info.b];
762 
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;
766 
767  float f = (float)(logf(d_sq)*0.5f-logf(desiredEdgeLength[i]));
768 
769  float fa = f*0.25f;
770  float fb = f*0.25f;
771 
772  if (FLAGS & FMEEdgeForce::DivDegree)
773  {
774  fa = (float)(fa/((float)a_info.degree));
775  fb = (float)(fb/((float)b_info.degree));
776  }
777 
778  if (FLAGS & FMEEdgeForce::SubRep)
779  {
780  fa += (nodeSize[e_info.b] / d_sq);
781  fb += (nodeSize[e_info.a] / d_sq);
782  }
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;
787  }
788 
789  inline void operator()(uint32_t begin, uint32_t end)
790  {
791  for (uint32_t i = begin; i <= end; i++)
792  {
793  this->operator()(i);
794  }
795  }
796 
797 private:
798  float* x;
799  float* y;
802 
805  float* nodeSize;
806  float* forceArrayX;
807  float* forceArrayY;
808 };
809 
810 
811 template<unsigned int FLAGS>
813 {
814  return EdgeForceFunctor<FLAGS>( pLocalContext );
815 }
816 
817 
818 enum class FMECollect
819 {
820  NoFactor = 0x00,
821  EdgeFactor = 0x01,
822  RepulsiveFactor = 0x02,
823  EdgeFactorRep = 0x04,
824  Tree2GraphOrder = 0x08,
825  ZeroThreadArray = 0x10
826 };
827 
828 inline int operator & (int lhs, FMECollect rhs) {
829  return lhs & static_cast<int>(rhs);
830 }
831 
832 inline constexpr int operator | (int lhs, FMECollect rhs) {
833  return lhs | static_cast<int>(rhs);
834 }
835 
836 inline constexpr int operator | (FMECollect lhs, FMECollect rhs) {
837  return static_cast<int>(lhs) | static_cast<int>(rhs);
838 }
839 
840 template<unsigned int FLAGS>
842 {
843 public:
844 
845  inline explicit CollectForceFunctor( FMELocalContext* pLocalContext )
846  {
847  numContexts = pLocalContext->pGlobalContext->numThreads;
848  globalContext = pLocalContext->pGlobalContext;
849  localContexts = pLocalContext->pGlobalContext->pLocalContext;
850  globalArrayX = globalContext->globalForceX;
851  globalArrayY = globalContext->globalForceY;
852  pGraph = pLocalContext->pGlobalContext->pGraph;
853  if (FLAGS & FMECollect::EdgeFactor)
854  factor = pLocalContext->pGlobalContext->pOptions->edgeForceFactor;
855  else
856  if (FLAGS & FMECollect::RepulsiveFactor)
857  factor = pLocalContext->pGlobalContext->pOptions->repForceFactor;
858  else
859  if (FLAGS & FMECollect::EdgeFactorRep)
860  factor = pLocalContext->pGlobalContext->pOptions->preProcEdgeForceFactor;
861  else
862  factor = 1.0;
863  }
864 
865  inline uint32_t operator()(void) const
866  {
867  return pGraph->numNodes();
868  }
869 
870 
871  inline void operator()(uint32_t i)
872  {
873  float sumX = 0.0f;
874  float sumY = 0.0f;
875  for (uint32_t j=0; j < numContexts; j++)
876  {
877  float* localArrayX = localContexts[j]->forceX;
878  float* localArrayY = localContexts[j]->forceY;
879  sumX += localArrayX[i];
880  sumY += localArrayY[i];
881  if (FLAGS & FMECollect::ZeroThreadArray)
882  {
883  localArrayX[i] = 0.0f;
884  localArrayY[i] = 0.0f;
885  }
886  }
887 
888  if (FLAGS & FMECollect::Tree2GraphOrder) {
889  i = globalContext->pQuadtree->refOfPoint(i);
890  }
891  if (FLAGS & FMECollect::RepulsiveFactor
892  && pGraph->nodeInfo(i).degree > 100) {
893  // prevent some evil effects
894  sumX /= (float)pGraph->nodeInfo(i).degree;
895  sumY /= (float)pGraph->nodeInfo(i).degree;
896  }
897  globalArrayX[i] += sumX*factor;
898  globalArrayY[i] += sumY*factor;
899  }
900 
901  inline void operator()(uint32_t begin, uint32_t end)
902  {
903  for (uint32_t i = begin; i <= end; i++)
904  {
905  this->operator()(i);
906  }
907  }
908 
909 private:
913  float* globalArrayX;
914  float* globalArrayY;
915  uint32_t numContexts;
916  float factor;
917 };
918 
919 
920 template<unsigned int FLAGS>
922 {
923  return CollectForceFunctor<FLAGS>( pLocalContext );
924 }
925 
926 
927 static constexpr int TIME_STEP_NORMAL = 0x1;
928 static constexpr int TIME_STEP_PREP = 0x2;
929 static constexpr int ZERO_GLOBAL_ARRAY = 0x4;
930 static constexpr int USE_NODE_MOVE_RAD = 0x8;
931 
932 template<unsigned int FLAGS>
934 {
935 public:
936 #if 1
937  inline explicit NodeMoveFunctor(FMELocalContext* pLocalContext)
938 #else
939  inline NodeMoveFunctor(FMELocalContext* pLocalContext,
940  float* xCoords, float* yCoords,
941  float ftimeStep,
942  float* globalForceArray)
943  : x(xCoords), y(yCoords), timeStep(ftimeStep), forceArray(globalForceArray)
944 #endif
945  {
946  if (FLAGS & TIME_STEP_NORMAL)
947  timeStep = pLocalContext->pGlobalContext->pOptions->timeStep * pLocalContext->pGlobalContext->coolDown;
948  else
949  if (FLAGS & TIME_STEP_PREP)
950  timeStep = pLocalContext->pGlobalContext->pOptions->preProcTimeStep;
951  else
952  timeStep = 1.0;
953  pGraph = pLocalContext->pGlobalContext->pGraph;
954  x = pGraph->nodeXPos();
955  y = pGraph->nodeYPos();
956  nodeMoveRadius = pGraph->nodeMoveRadius();
957  forceArrayX = pLocalContext->pGlobalContext->globalForceX;
958  forceArrayY = pLocalContext->pGlobalContext->globalForceY;
959  localContext = pLocalContext;
960  currentEdgeLength = pLocalContext->pGlobalContext->pGraph->desiredEdgeLength();
961  }
962 
963 #if 0
964  inline void operator()(void) const
965  {
966  return pGraph->numNodes();
967  };
968 #endif
969 
970  inline void operator()(uint32_t i)
971  {
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);
976 
977  localContext->maxForceSq = max<double>(localContext->maxForceSq, (double)dsq );
978  localContext->avgForce += d;
979  if (d < FLT_MAX)
980  {
981  x[i] += d_x;
982  y[i] += d_y;
983  if (FLAGS & ZERO_GLOBAL_ARRAY)
984  {
985  forceArrayX[i] = 0.0;
986  forceArrayY[i] = 0.0;
987  } else
988  {
989  forceArrayX[i] = d_x;
990  forceArrayY[i] = d_y;
991  }
992  } else
993  {
994  forceArrayX[i] = 0.0;
995  forceArrayY[i] = 0.0;
996  }
997  }
998 
999  inline void operator()(uint32_t begin, uint32_t end)
1000  {
1001  for (uint32_t i = begin; i <= end; i++)
1002  {
1003  this->operator()(i);
1004  }
1005  }
1006 
1007 private:
1008  float timeStep;
1009  float* x;
1010  float* y;
1011  float* forceArrayX;
1012  float* forceArrayY;
1017 };
1018 
1019 
1020 template<unsigned int FLAGS>
1022 {
1023  return NodeMoveFunctor<FLAGS>( pLocalContext );
1024 }
1025 
1026 
1027 template<typename TYP>
1028 inline void for_loop_array_set(uint32_t threadNr, uint32_t numThreads, TYP* a, uint32_t n, TYP value)
1029 {
1030  uint32_t s = n/numThreads;
1031  uint32_t o = s*threadNr;
1032  if (threadNr == numThreads-1)
1033  s = s + (n % numThreads);
1034 
1035  for (uint32_t i = 0; i < s; i++ ) { a[o+i] = value; }
1036 }
1037 
1038 }
1039 }
int operator&(int lhs, FMEEdgeForce rhs)
Definition: FMEFunc.h:731
LQPartitioner(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:382
void operator()(LinearQuadtree::NodeID nodeIndex)
Definition: FMEFunc.h:247
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...
Definition: FMEKernel.h:172
LQPointUpdateFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:516
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
Definition: FMEFunc.h:930
NDFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:639
float * desiredEdgeLength()
Returns the edge length array for all edges.
Definition: ArrayGraph.h:186
static constexpr int TIME_STEP_PREP
Definition: FMEFunc.h:928
float * forceY
local force array for all nodes, points
Definition: FMEFunc.h:128
the main global options for a run
Definition: FMEFunc.h:68
double maxForceSq
local maximum force
Definition: FMEFunc.h:129
Declaration of class WSPD (well-separated pair decomposition).
static l2p_functor l2p_function(FMELocalContext *pLocalContext)
creates Local-to-Point functor
Definition: FMEFunc.h:333
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
Definition: FMEFunc.h:157
float min_y
global point, node min y coordinate for bounding box calculations
Definition: FMEFunc.h:133
FMENodeChainPartition leafPartition
chain of leaf nodes assigned to the thread
Definition: FMEFunc.h:138
uint32_t preProcMaxNumIterations
number of iterations the preprocessing is applied
Definition: FMEFunc.h:72
struct for distributing subtrees to the threads
Definition: FMEFunc.h:47
float max_y
global point, node max y coordinate for bounding box calculations
Definition: FMEFunc.h:134
Information about incident edges (16 bytes).
Definition: EdgeChain.h:42
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:618
LinearQuadtreeExpansion & expansions
Definition: FMEFunc.h:313
FMEGlobalOptions * pOptions
pointer to the global options
Definition: FMEFunc.h:109
void operator()(LinearQuadtree::NodeID nodeIndex)
Definition: FMEFunc.h:295
void operator()(LinearQuadtree::NodeID nodeIndexSource, LinearQuadtree::NodeID nodeIndexReceiver)
Definition: FMEFunc.h:268
LinearQuadtreeExpansion * quadtreeExp
Definition: FMEFunc.h:670
LinearQuadtreeExpansion * pExpansion
pointer to the coeefficients
Definition: FMEFunc.h:105
void operator()(LinearQuadtree::NodeID nodeIndexA, LinearQuadtree::NodeID nodeIndexB)
Definition: FMEFunc.h:348
CollectForceFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:845
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:999
FMENodeChainPartition innerNodePartition
chain of inner nodes assigned to the thread
Definition: FMEFunc.h:137
std::list< LinearQuadtree::NodeID > nodes
Definition: FMEFunc.h:49
static constexpr int ZERO_GLOBAL_ARRAY
Definition: FMEFunc.h:929
Calculates the repulsive forces acting between all nodes of the direct interacting cells of the i-th ...
Definition: FMEFunc.h:679
static p2p_functor p2p_function(FMELocalContext *pLocalContext)
creates Local-to-Point functor
Definition: FMEFunc.h:372
void operator()(LinearQuadtree::NodeID nodeIndex, LinearQuadtree::PointID pointIndex)
Definition: FMEFunc.h:319
void operator()(LinearQuadtree::NodeID parent, LinearQuadtree::NodeID child)
Definition: FMEFunc.h:290
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:789
m2l_functor(LinearQuadtreeExpansion &e)
Definition: FMEFunc.h:266
void P2M(uint32_t point, uint32_t receiver)
adds a point with the given charge to the receiver expansion
p2m_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e)
Definition: FMEFunc.h:213
l2p_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e, float *x, float *y)
Definition: FMEFunc.h:317
float min_x
global point, node min x coordinate for bounding box calculations
Definition: FMEFunc.h:113
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:901
static NodeMoveFunctor< FLAGS > node_move_function(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:1021
LinearQuadtreeExpansion & expansions
Definition: FMEFunc.h:286
static l2l_functor l2l_function(FMELocalContext *pLocalContext)
creates Local-to-Local functor
Definition: FMEFunc.h:303
void operator()(LinearQuadtree::NodeID nodeIndex)
Definition: FMEFunc.h:215
LinearQuadtreeExpansion * quadtreeExp
Definition: FMEFunc.h:584
forall_children_functor< F > forall_children(F f) const
creator
Converts the multipole expansion coefficients from all nodes which are well separated from the i-th n...
Definition: FMEFunc.h:592
LQMortonFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:165
float max_y
global point, node max y coordinate for bounding box calculations
Definition: FMEFunc.h:116
LinearQuadtreeExpansion * quadtreeExp
Definition: FMEFunc.h:721
static EdgeForceFunctor< FLAGS > edge_force_function(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:812
uint32_t numInnerNodes
number of inner nodes the thread prepared
Definition: FMEFunc.h:142
bool doPrepProcessing
enable preprocessing
Definition: FMEFunc.h:82
ArrayGraph * pGraph
pointer to the array graph
Definition: FMEFunc.h:103
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:536
LinearQuadtree::NodeID firstInnerNode
first inner nodes the thread prepared
Definition: FMEFunc.h:140
uint32_t maxNumIterations
maximum number of iterations in the main step
Definition: FMEFunc.h:79
float * nodeXPos()
Returns the x coord array for all nodes.
Definition: ArrayGraph.h:165
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:711
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:660
Information about an edge (16 bytes).
Definition: EdgeChain.h:51
void operator()(LinearQuadtree::NodeID parent, LinearQuadtree::NodeID child)
Definition: FMEFunc.h:242
float * forceX
local force array for all nodes, points
Definition: FMEFunc.h:127
float max_x
global point, node max x coordinate for bounding box calculations
Definition: FMEFunc.h:132
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:574
Declaration of class LinearQuadtreeBuilder.
EdgeForceFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:739
uint32_t degree
Total count of pairs where is either the first or second node.
Definition: EdgeChain.h:44
float timeStep
time step factor for the main step
Definition: FMEFunc.h:74
constexpr int operator|(int lhs, FMECollect rhs)
Definition: FMEFunc.h:832
Declaration of FME kernel.
LinearQuadtree * pQuadtree
pointer to the quadtree
Definition: FMEFunc.h:104
double stopCritAvgForce
stopping criteria
Definition: FMEFunc.h:86
static p2m_functor p2m_function(FMELocalContext *pLocalContext)
creates a Point-to-Multipole functor
Definition: FMEFunc.h:228
Calculates the repulsive forces acting between all nodes inside the cell of the i-th LinearQuadtree n...
Definition: FMEFunc.h:636
Declaration of class LinearQuadtree.
float * nodeSize()
Returns the node size array for all nodes.
Definition: ArrayGraph.h:177
uint32_t a
First node of the pair.
Definition: EdgeChain.h:53
uint32_t numThreads
number of threads, local contexts
Definition: FMEFunc.h:102
LinearQuadtreeExpansion & expansions
Definition: FMEFunc.h:211
Point-to-Multipole functor.
Definition: FMEFunc.h:208
Multipole-to-Multipole functor.
Definition: FMEFunc.h:235
float min_x
global point, node min x coordinate for bounding box calculations
Definition: FMEFunc.h:131
double avgForce
local maximum force
Definition: FMEFunc.h:130
NodeMoveFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:937
WSPD * pWSPD
pointer to the well separated pairs decomposition
Definition: FMEFunc.h:106
float min_y
global point, node min y coordinate for bounding box calculations
Definition: FMEFunc.h:115
Multipole-to-Local functor.
Definition: FMEFunc.h:262
static CollectForceFunctor< FLAGS > collect_force_function(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:921
float * globalForceY
the global node force y array
Definition: FMEFunc.h:108
m2m_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e)
Definition: FMEFunc.h:240
uint32_t minNumIterations
minimum number of iterations to be done regardless of any other conditions
Definition: FMEFunc.h:80
LQCoordsFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:558
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
Definition: FMEFunc.h:146
FMELocalContext ** pLocalContext
all local contexts
Definition: FMEFunc.h:101
static min_max_functor< float > min_max_x_function(FMELocalContext *pLocalContext)
creates a min max functor for the x coords of the node
Definition: FMEFunc.h:151
bool earlyExit
var for the main thread to notify the other threads that they are done
Definition: FMEFunc.h:110
The partitioner which partitions the quadtree into subtrees and partitions the sequence of inner node...
Definition: FMEFunc.h:379
LinearQuadtreeExpansion * quadtreeExp
Definition: FMEFunc.h:628
float * globalForceX
the global node force x array
Definition: FMEFunc.h:107
l2l_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e)
Definition: FMEFunc.h:288
D2DFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:682
FMETreePartition treePartition
tree partition assigned to the thread
Definition: FMEFunc.h:136
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
Definition: FMEFunc.h:77
static constexpr int TIME_STEP_NORMAL
Definition: FMEFunc.h:927
p2p_functor(const LinearQuadtree &t, float *x, float *y)
Definition: FMEFunc.h:346
float max_x
global point, node max x coordinate for bounding box calculations
Definition: FMEFunc.h:114
static m2l_functor m2l_function(FMELocalContext *pLocalContext)
creates Multipole-to-Local functor
Definition: FMEFunc.h:276
LinearQuadtreeExpansion & expansions
Definition: FMEFunc.h:264
Declaration of class LinearQuadtreeExpansion.
M2LFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:595
Class for the Well-Separated-Pairs-Decomposition (WSPD)
Definition: WSPD.h:41
static m2m_functor m2m_function(FMELocalContext *pLocalContext)
creates Multipole-to-Multipole functor
Definition: FMEFunc.h:255
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.
LinearQuadtree::NodeID lastInnerNode
last inner nodes the thread prepared
Definition: FMEFunc.h:141
float preProcEdgeForceFactor
edge force factor for the preprocessing step
Definition: FMEFunc.h:71
float preProcTimeStep
time step factor for the preprocessing step
Definition: FMEFunc.h:70
LinearQuadtree::NodeID lastLeaf
last leaves the thread prepared
Definition: FMEFunc.h:145
Computes the coords and size of the i-th node in the LinearQuadtree.
Definition: FMEFunc.h:555
void for_loop_array_set(uint32_t threadNr, uint32_t numThreads, TYP *a, uint32_t n, TYP value)
Definition: FMEFunc.h:1028
LinearQuadtree::NodeID firstLeaf
first leaves the thread prepared
Definition: FMEFunc.h:144
float repForceFactor
repulsive force factor for the main step
Definition: FMEFunc.h:76
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:188
void operator()(LinearQuadtree::NodeID nodeIndex)
Definition: FMEFunc.h:362
float * nodeYPos()
Returns the y coord array for all nodes.
Definition: ArrayGraph.h:171
float edgeForceFactor
edge force factor for the main step
Definition: FMEFunc.h:75
double stopCritConstSq
stopping criteria
Definition: FMEFunc.h:87
uint32_t b
Second node of the pair.
Definition: EdgeChain.h:54
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 ...
FMEGlobalContext * pGlobalContext
pointer to the global context
Definition: FMEFunc.h:126
double stopCritForce
stopping criteria
Definition: FMEFunc.h:85
void operator()(LinearQuadtree::PointID pointIndex)
Definition: FMEFunc.h:324
bool doPostProcessing
enable postprocessing
Definition: FMEFunc.h:83
float normNodeSize
average node size when node sizes are normalized
Definition: FMEFunc.h:78
LinearQuadtreeExpansion & expansions
Definition: FMEFunc.h:238