Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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 
98 {
100  uint32_t numThreads;
105  float* globalForceX;
106  float* globalForceY;
108  bool earlyExit;
109  float scaleFactor;
110  float coolDown;
111  float min_x;
112  float max_x;
113  float min_y;
114  float max_y;
116 };
117 
120 {
122  float* forceX;
123  float* forceY;
124  double maxForceSq;
125  double avgForce;
126  float min_x;
127  float max_x;
128  float min_y;
129  float max_y;
134 
137  uint32_t numInnerNodes;
138 
141  uint32_t numLeaves;
142 };
143 
146 {
147  return min_max_functor<float>(pLocalContext->pGlobalContext->pGraph->nodeXPos(), pLocalContext->min_x, pLocalContext->max_x);
148 }
149 
152 {
153  return min_max_functor<float>(pLocalContext->pGlobalContext->pGraph->nodeYPos(), pLocalContext->min_y, pLocalContext->max_y);
154 }
155 
157 {
158 public:
159  inline LQMortonFunctor ( FMELocalContext* pLocalContext )
160  {
161  x = pLocalContext->pGlobalContext->pGraph->nodeXPos();
162  y = pLocalContext->pGlobalContext->pGraph->nodeYPos();
163  s = pLocalContext->pGlobalContext->pGraph->nodeSize();
164  quadtree = pLocalContext->pGlobalContext->pQuadtree;
165  translate_x = -quadtree->minX();
166  translate_y = -quadtree->minY();
167  scale = quadtree->scaleInv();
168  }
169 
170  inline uint32_t operator()(void) const
171  {
172  return quadtree->numberOfPoints();
173  }
174 
175  inline void operator()(uint32_t i)
176  {
177  LinearQuadtree::LQPoint& p = quadtree->point(i);
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));
180  }
181 
182  inline void operator()(uint32_t begin, uint32_t end)
183  {
184  for (uint32_t i = begin; i <= end; i++)
185  {
186  this->operator()(i);
187  }
188  }
189 
190 private:
192  float translate_x;
193  float translate_y;
194  double scale;
195  float* x;
196  float* y;
197  float* s;
198 };
199 
200 
203 {
206 
207  p2m_functor(const LinearQuadtree& t, LinearQuadtreeExpansion& e) : tree(t), expansions(e) { }
208 
209  inline void operator()(LinearQuadtree::NodeID nodeIndex)
210  {
211  uint32_t numPointsInLeaf = tree.numberOfPoints(nodeIndex);
212  uint32_t firstPointOfLeaf = tree.firstPoint(nodeIndex);
213  for (uint32_t pointIndex=firstPointOfLeaf; pointIndex < (firstPointOfLeaf+numPointsInLeaf); pointIndex++)
214  {
215  expansions.P2M(pointIndex, nodeIndex);
216  }
217  }
218 };
219 
220 
222 static inline p2m_functor p2m_function(FMELocalContext* pLocalContext)
223 {
224  return p2m_functor(*pLocalContext->pGlobalContext->pQuadtree, *pLocalContext->pGlobalContext->pExpansion);
225 }
226 
227 
230 {
233 
234  m2m_functor(const LinearQuadtree& t, LinearQuadtreeExpansion& e) : tree(t), expansions(e) { }
235 
237  {
238  expansions.M2M(child, parent);
239  }
240 
241  inline void operator()(LinearQuadtree::NodeID nodeIndex)
242  {
243  tree.forall_children(pair_call(*this, nodeIndex))(nodeIndex);
244  }
245 };
246 
247 
249 static inline m2m_functor m2m_function(FMELocalContext* pLocalContext)
250 {
251  return m2m_functor(*pLocalContext->pGlobalContext->pQuadtree, *pLocalContext->pGlobalContext->pExpansion);
252 }
253 
254 
257 {
259 
260  m2l_functor(LinearQuadtreeExpansion& e) : expansions(e) { }
261 
262  inline void operator()(LinearQuadtree::NodeID nodeIndexSource, LinearQuadtree::NodeID nodeIndexReceiver)
263  {
264  expansions.M2L(nodeIndexSource, nodeIndexReceiver);
265  }
266 };
267 
268 
270 static inline m2l_functor m2l_function(FMELocalContext* pLocalContext)
271 {
272  return m2l_functor(*pLocalContext->pGlobalContext->pExpansion);
273 }
274 
275 
278 {
281 
282  l2l_functor(const LinearQuadtree& t, LinearQuadtreeExpansion& e) : tree(t), expansions(e) { }
283 
285  {
286  expansions.L2L(parent, child);
287  }
288 
289  inline void operator()(LinearQuadtree::NodeID nodeIndex)
290  {
291  tree.forall_children(pair_call(*this, nodeIndex))(nodeIndex);
292  }
293 };
294 
295 
297 static inline l2l_functor l2l_function(FMELocalContext* pLocalContext)
298 {
299  return l2l_functor(*pLocalContext->pGlobalContext->pQuadtree, *pLocalContext->pGlobalContext->pExpansion);
300 }
301 
302 
305 {
308  float* fx;
309  float* fy;
310 
311  l2p_functor(const LinearQuadtree& t, LinearQuadtreeExpansion& e, float* x, float* y) : tree(t), expansions(e), fx(x), fy(y) { }
312 
313  inline void operator()(LinearQuadtree::NodeID nodeIndex, LinearQuadtree::PointID pointIndex)
314  {
315  expansions.L2P(nodeIndex, pointIndex, fx[pointIndex], fy[pointIndex]);
316  }
317 
318  inline void operator()(LinearQuadtree::PointID pointIndex)
319  {
320  LinearQuadtree::NodeID nodeIndex = tree.pointLeaf(pointIndex);
321  this->operator ()(nodeIndex, pointIndex);
322  }
323 };
324 
325 
327 static inline l2p_functor l2p_function(FMELocalContext* pLocalContext)
328 {
329  return l2p_functor(*pLocalContext->pGlobalContext->pQuadtree, *pLocalContext->pGlobalContext->pExpansion, pLocalContext->forceX, pLocalContext->forceY);
330 }
331 
332 
335 {
337  float* fx;
338  float* fy;
339 
340  p2p_functor(const LinearQuadtree& t, float* x, float* y) : tree(t), fx(x), fy(y) { }
341 
342  inline void operator()(LinearQuadtree::NodeID nodeIndexA, LinearQuadtree::NodeID nodeIndexB)
343  {
344  uint32_t offsetA = tree.firstPoint(nodeIndexA);
345  uint32_t offsetB = tree.firstPoint(nodeIndexB);
346  uint32_t numPointsA = tree.numberOfPoints(nodeIndexA);
347  uint32_t numPointsB = tree.numberOfPoints(nodeIndexB);
348  eval_direct_fast(tree.pointX() + offsetA, tree.pointY() + offsetA,
349  tree.pointSize() + offsetA,
350  fx + offsetA, fy + offsetA, numPointsA,
351  tree.pointX() + offsetB, tree.pointY() + offsetB,
352  tree.pointSize() + offsetB,
353  fx + offsetB, fy + offsetB, numPointsB);
354  }
355 
356  inline void operator()(LinearQuadtree::NodeID nodeIndex)
357  {
358  uint32_t offset = tree.firstPoint(nodeIndex);
359  uint32_t numPoints = tree.numberOfPoints(nodeIndex);
360  eval_direct_fast(tree.pointX() + offset, tree.pointY() + offset, tree.pointSize() + offset, fx + offset, fy + offset, numPoints);
361  }
362 };
363 
364 
366 static inline p2p_functor p2p_function(FMELocalContext* pLocalContext)
367 {
368  return p2p_functor(*pLocalContext->pGlobalContext->pQuadtree, pLocalContext->forceX, pLocalContext->forceY);
369 }
370 
371 
374 {
375 public:
376  explicit LQPartitioner( FMELocalContext* pLocalContext )
377  : numPointsPerThread(0)
378  , numThreads(pLocalContext->pGlobalContext->numThreads)
379  , currThread(0)
380  , tree(pLocalContext->pGlobalContext->pQuadtree)
381  , localContexts(pLocalContext->pGlobalContext->pLocalContext)
382  { }
383 
385  {
386  uint32_t numInnerNodesPerThread = tree->numberOfInnerNodes() / numThreads;
387  if (numInnerNodesPerThread < 25)
388  {
389  localContexts[0]->innerNodePartition.begin = tree->firstInnerNode();
390  localContexts[0]->innerNodePartition.numNodes = tree->numberOfInnerNodes();
391  for (uint32_t i=1; i< numThreads; i++)
392  {
393  localContexts[i]->innerNodePartition.numNodes = 0;
394  }
395  } else
396  {
397 
398  LinearQuadtree::NodeID curr = tree->firstInnerNode();
399  currThread = 0;
400  localContexts[0]->innerNodePartition.begin = curr;
401  localContexts[0]->innerNodePartition.numNodes = 0;
402  for (uint32_t i=0; i< tree->numberOfInnerNodes(); i++)
403  {
404  localContexts[currThread]->innerNodePartition.numNodes++;
405  curr = tree->nextNode(curr);
406  if (localContexts[currThread]->innerNodePartition.numNodes >= numInnerNodesPerThread && currThread < numThreads - 1)
407  {
408  currThread++;
409  localContexts[currThread]->innerNodePartition.numNodes = 0;
410  localContexts[currThread]->innerNodePartition.begin = curr;
411  }
412  }
413 
414  }
415 
416  uint32_t numLeavesPerThread = tree->numberOfLeaves() / numThreads;
417  if (numLeavesPerThread < 25)
418  {
419  localContexts[0]->leafPartition.begin = tree->firstLeaf();
420  localContexts[0]->leafPartition.numNodes = tree->numberOfLeaves();
421  for (uint32_t i=1; i< numThreads; i++)
422  {
423  localContexts[i]->leafPartition.numNodes = 0;
424  }
425  } else
426  {
427  LinearQuadtree::NodeID curr = tree->firstLeaf();
428  currThread = 0;
429  localContexts[0]->leafPartition.begin = curr;
430  localContexts[0]->leafPartition.numNodes = 0;
431  for (uint32_t i=0; i< tree->numberOfLeaves(); i++)
432  {
433  localContexts[currThread]->leafPartition.numNodes++;
434  curr = tree->nextNode(curr);
435  if (localContexts[currThread]->leafPartition.numNodes >= numLeavesPerThread && currThread < numThreads - 1)
436  {
437  currThread++;
438  localContexts[currThread]->leafPartition.numNodes = 0;
439  localContexts[currThread]->leafPartition.begin = curr;
440  }
441  }
442  }
443  }
444 
445  void partition()
446  {
447  partitionNodeChains();
448  currThread = 0;
449  numPointsPerThread = tree->numberOfPoints() / numThreads;
450  for (uint32_t i=0; i < numThreads; i++)
451  {
452  localContexts[i]->treePartition.nodes.clear();
453  localContexts[i]->treePartition.pointCount = 0;
454  }
455  if (numThreads>1)
456  newPartition();
457  }
458 
459  void newPartition(uint32_t nodeID)
460  {
461  uint32_t bound = tree->numberOfPoints() / (numThreads*numThreads);
462 
463  if (tree->isLeaf(nodeID) || tree->numberOfPoints(nodeID) < bound)
464  l_par.push_back(nodeID);
465  else
466  for (uint32_t i = 0; i < tree->numberOfChilds(nodeID); i++)
467  newPartition(tree->child(nodeID, i));
468  }
469 
471  {
472  l_par.clear();
473  newPartition(tree->root());
474  uint32_t bound = (tree->numberOfPoints() / (numThreads)) + (tree->numberOfPoints() / (numThreads*numThreads*2));
475  while (!l_par.empty())
476  {
477  FMETreePartition* partition = currPartition();
478  uint32_t v = l_par.front();
479  if (((partition->pointCount + tree->numberOfPoints(v)) <= bound) ||
480  (currThread==numThreads-1))
481  {
482  partition->pointCount += tree->numberOfPoints(v);
483  partition->nodes.push_back(v);
484  tree->nodeFence(v);
485  l_par.pop_front();
486  } else
487  {
488  currThread++;
489  }
490  }
491  }
492 
494  {
495  return &localContexts[currThread]->treePartition;
496  }
497 
498 private:
500  uint32_t numThreads;
501  uint32_t currThread;
502  std::list<uint32_t> l_par;
505 };
506 
507 
509 {
510 public:
511  inline explicit LQPointUpdateFunctor ( FMELocalContext* pLocalContext )
512  {
513  x = pLocalContext->pGlobalContext->pGraph->nodeXPos();
514  y = pLocalContext->pGlobalContext->pGraph->nodeYPos();
515  s = pLocalContext->pGlobalContext->pGraph->nodeSize();
516  quadtree = pLocalContext->pGlobalContext->pQuadtree;
517  }
518 
519  inline uint32_t operator()(void) const
520  {
521  return quadtree->numberOfPoints();
522  }
523 
524  inline void operator()(uint32_t i)
525  {
526  LinearQuadtree::LQPoint& p = quadtree->point(i);
527  uint32_t ref = p.ref;
528  quadtree->setPoint(i, x[ref], y[ref], s[ref]);
529  }
530 
531  inline void operator()(uint32_t begin, uint32_t end)
532  {
533  for (uint32_t i = begin; i <= end; i++)
534  {
535  this->operator()(i);
536  }
537  }
538 
539 private:
541  float* x;
542  float* y;
543  float* s;
544 };
545 
546 
551 {
552 public:
553  inline explicit LQCoordsFunctor( FMELocalContext* pLocalContext )
554  {
555  quadtree = pLocalContext->pGlobalContext->pQuadtree;
556  quadtreeExp = pLocalContext->pGlobalContext->pExpansion;
557  }
558 
559  inline uint32_t operator()(void) const
560  {
561  return quadtree->numberOfNodes();
562  }
563 
564  inline void operator()( uint32_t i )
565  {
566  quadtree->computeCoords(i);
567  }
568 
569  inline void operator()(uint32_t begin, uint32_t end)
570  {
571  for (uint32_t i = begin; i <= end; i++)
572  {
573  this->operator()(i);
574  }
575  }
576 
577 private:
580 };
581 
582 
588 {
589 public:
590  inline explicit M2LFunctor( FMELocalContext* pLocalContext )
591  {
592  quadtree = pLocalContext->pGlobalContext->pQuadtree;
593  quadtreeExp = pLocalContext->pGlobalContext->pExpansion;
594  wspd = pLocalContext->pGlobalContext->pWSPD;
595  }
596 
597  inline uint32_t operator()(void) const
598  {
599  return quadtree->numberOfNodes();
600  }
601 
602  inline void operator()(uint32_t i)
603  {
604  uint32_t currEntryIndex = wspd->firstPairEntry(i);
605  for (uint32_t k = 0; k < wspd->numWSNodes(i); k++)
606  {
607  uint32_t j = wspd->wsNodeOfPair(currEntryIndex, i);
608  quadtreeExp->M2L(j, i);
609  currEntryIndex = wspd->nextPair(currEntryIndex, i);
610  }
611  }
612 
613  inline void operator()(uint32_t begin, uint32_t end)
614  {
615  for (uint32_t i = begin; i <= end; i++)
616  {
617  this->operator()(i);
618  }
619  }
620 
621 private:
625 };
626 
627 
632 {
633 public:
634  inline explicit NDFunctor( FMELocalContext* pLocalContext )
635  {
636  quadtree = pLocalContext->pGlobalContext->pQuadtree;
637  quadtreeExp = pLocalContext->pGlobalContext->pExpansion;
638  forceArrayX = pLocalContext->forceX;
639  forceArrayY = pLocalContext->forceY;
640  }
641 
642  inline uint32_t operator()(void) const
643  {
644  return quadtree->numberOfDirectNodes();
645  }
646 
647  inline void operator()(uint32_t i)
648  {
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);
653  }
654 
655  inline void operator()(uint32_t begin, uint32_t end)
656  {
657  for (uint32_t i = begin; i <= end; i++)
658  {
659  this->operator()(i);
660  }
661  }
662 
663 private:
666  float* forceArrayX;
667  float* forceArrayY;
668 };
669 
670 
675 {
676 public:
677  inline explicit D2DFunctor( FMELocalContext* pLocalContext )
678  {
679  quadtree = pLocalContext->pGlobalContext->pQuadtree;
680  quadtreeExp = pLocalContext->pGlobalContext->pExpansion;
681  forceArrayX = pLocalContext->forceX;
682  forceArrayY = pLocalContext->forceY;
683  }
684 
685  inline uint32_t operator()(void) const
686  {
687  return quadtree->numberOfDirectPairs();
688  }
689 
690  inline void operator()(uint32_t i)
691  {
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);
704  }
705 
706  inline void operator()(uint32_t begin, uint32_t end)
707  {
708  for (uint32_t i = begin; i <= end; i++)
709  {
710  this->operator()(i);
711  }
712  }
713 
714 private:
717  float* forceArrayX;
718  float* forceArrayY;
719 };
720 
721 enum class FMEEdgeForce {
722  SubRep = 0x2,
723  DivDegree = 0x8
724 };
725 
726 inline int operator & (int lhs, FMEEdgeForce rhs) {
727  return lhs & static_cast<int>(rhs);
728 }
729 
730 template<unsigned int FLAGS>
732 {
733 public:
734  inline explicit EdgeForceFunctor( FMELocalContext* pLocalContext )
735  {
736  pGraph = pLocalContext->pGlobalContext->pGraph;
737  x = pGraph->nodeXPos();
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;
745  }
746 
747  inline uint32_t operator()(void) const
748  {
749  return pGraph->numEdges();
750  }
751 
752  inline void operator()(uint32_t i)
753  {
754  const EdgeAdjInfo& e_info = edgeInfo[i];
755  const NodeAdjInfo& a_info = nodeInfo[e_info.a];
756  const NodeAdjInfo& b_info = nodeInfo[e_info.b];
757 
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;
761 
762  float f = (float)(logf(d_sq)*0.5f-logf(desiredEdgeLength[i]));
763 
764  float fa = f*0.25f;
765  float fb = f*0.25f;
766 
767  if (FLAGS & FMEEdgeForce::DivDegree)
768  {
769  fa = (float)(fa/((float)a_info.degree));
770  fb = (float)(fb/((float)b_info.degree));
771  }
772 
773  if (FLAGS & FMEEdgeForce::SubRep)
774  {
775  fa += (nodeSize[e_info.b] / d_sq);
776  fb += (nodeSize[e_info.a] / d_sq);
777  }
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;
782  }
783 
784  inline void operator()(uint32_t begin, uint32_t end)
785  {
786  for (uint32_t i = begin; i <= end; i++)
787  {
788  this->operator()(i);
789  }
790  }
791 
792 private:
793  float* x;
794  float* y;
797 
800  float* nodeSize;
801  float* forceArrayX;
802  float* forceArrayY;
803 };
804 
805 
806 template<unsigned int FLAGS>
808 {
809  return EdgeForceFunctor<FLAGS>( pLocalContext );
810 }
811 
812 
813 enum class FMECollect
814 {
815  NoFactor = 0x00,
816  EdgeFactor = 0x01,
817  RepulsiveFactor = 0x02,
818  EdgeFactorRep = 0x04,
819  Tree2GraphOrder = 0x08,
820  ZeroThreadArray = 0x10
821 };
822 
823 inline int operator & (int lhs, FMECollect rhs) {
824  return lhs & static_cast<int>(rhs);
825 }
826 
827 inline constexpr int operator | (int lhs, FMECollect rhs) {
828  return lhs | static_cast<int>(rhs);
829 }
830 
831 inline constexpr int operator | (FMECollect lhs, FMECollect rhs) {
832  return static_cast<int>(lhs) | static_cast<int>(rhs);
833 }
834 
835 template<unsigned int FLAGS>
837 {
838 public:
839 
840  inline explicit CollectForceFunctor( FMELocalContext* pLocalContext )
841  {
842  numContexts = pLocalContext->pGlobalContext->numThreads;
843  globalContext = pLocalContext->pGlobalContext;
844  localContexts = pLocalContext->pGlobalContext->pLocalContext;
845  globalArrayX = globalContext->globalForceX;
846  globalArrayY = globalContext->globalForceY;
847  pGraph = pLocalContext->pGlobalContext->pGraph;
848  if (FLAGS & FMECollect::EdgeFactor)
849  factor = pLocalContext->pGlobalContext->pOptions->edgeForceFactor;
850  else
851  if (FLAGS & FMECollect::RepulsiveFactor)
852  factor = pLocalContext->pGlobalContext->pOptions->repForceFactor;
853  else
854  if (FLAGS & FMECollect::EdgeFactorRep)
855  factor = pLocalContext->pGlobalContext->pOptions->preProcEdgeForceFactor;
856  else
857  factor = 1.0;
858  }
859 
860  inline uint32_t operator()(void) const
861  {
862  return pGraph->numNodes();
863  }
864 
865 
866  inline void operator()(uint32_t i)
867  {
868  float sumX = 0.0f;
869  float sumY = 0.0f;
870  for (uint32_t j=0; j < numContexts; j++)
871  {
872  float* localArrayX = localContexts[j]->forceX;
873  float* localArrayY = localContexts[j]->forceY;
874  sumX += localArrayX[i];
875  sumY += localArrayY[i];
876  if (FLAGS & FMECollect::ZeroThreadArray)
877  {
878  localArrayX[i] = 0.0f;
879  localArrayY[i] = 0.0f;
880  }
881  }
882 
883  if (FLAGS & FMECollect::Tree2GraphOrder) {
884  i = globalContext->pQuadtree->refOfPoint(i);
885  }
886  if (FLAGS & FMECollect::RepulsiveFactor
887  && pGraph->nodeInfo(i).degree > 100) {
888  // prevent some evil effects
889  sumX /= (float)pGraph->nodeInfo(i).degree;
890  sumY /= (float)pGraph->nodeInfo(i).degree;
891  }
892  globalArrayX[i] += sumX*factor;
893  globalArrayY[i] += sumY*factor;
894  }
895 
896  inline void operator()(uint32_t begin, uint32_t end)
897  {
898  for (uint32_t i = begin; i <= end; i++)
899  {
900  this->operator()(i);
901  }
902  }
903 
904 private:
908  float* globalArrayX;
909  float* globalArrayY;
910  uint32_t numContexts;
911  float factor;
912 };
913 
914 
915 template<unsigned int FLAGS>
917 {
918  return CollectForceFunctor<FLAGS>( pLocalContext );
919 }
920 
921 
922 static constexpr int TIME_STEP_NORMAL = 0x1;
923 static constexpr int TIME_STEP_PREP = 0x2;
924 static constexpr int ZERO_GLOBAL_ARRAY = 0x4;
925 static constexpr int USE_NODE_MOVE_RAD = 0x8;
926 
927 template<unsigned int FLAGS>
929 {
930 public:
931 #if 1
932  inline explicit NodeMoveFunctor(FMELocalContext* pLocalContext)
933 #else
934  inline NodeMoveFunctor(FMELocalContext* pLocalContext,
935  float* xCoords, float* yCoords,
936  float ftimeStep,
937  float* globalForceArray)
938  : x(xCoords), y(yCoords), timeStep(ftimeStep), forceArray(globalForceArray)
939 #endif
940  {
941  if (FLAGS & TIME_STEP_NORMAL)
942  timeStep = pLocalContext->pGlobalContext->pOptions->timeStep * pLocalContext->pGlobalContext->coolDown;
943  else
944  if (FLAGS & TIME_STEP_PREP)
945  timeStep = pLocalContext->pGlobalContext->pOptions->preProcTimeStep;
946  else
947  timeStep = 1.0;
948  pGraph = pLocalContext->pGlobalContext->pGraph;
949  x = pGraph->nodeXPos();
950  y = pGraph->nodeYPos();
951  nodeMoveRadius = pGraph->nodeMoveRadius();
952  forceArrayX = pLocalContext->pGlobalContext->globalForceX;
953  forceArrayY = pLocalContext->pGlobalContext->globalForceY;
954  localContext = pLocalContext;
955  currentEdgeLength = pLocalContext->pGlobalContext->pGraph->desiredEdgeLength();
956  }
957 
958 #if 0
959  inline void operator()(void) const
960  {
961  return pGraph->numNodes();
962  };
963 #endif
964 
965  inline void operator()(uint32_t i)
966  {
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);
971 
972  localContext->maxForceSq = max<double>(localContext->maxForceSq, (double)dsq );
973  localContext->avgForce += d;
974  if (d < FLT_MAX)
975  {
976  x[i] += d_x;
977  y[i] += d_y;
978  if (FLAGS & ZERO_GLOBAL_ARRAY)
979  {
980  forceArrayX[i] = 0.0;
981  forceArrayY[i] = 0.0;
982  } else
983  {
984  forceArrayX[i] = d_x;
985  forceArrayY[i] = d_y;
986  }
987  } else
988  {
989  forceArrayX[i] = 0.0;
990  forceArrayY[i] = 0.0;
991  }
992  }
993 
994  inline void operator()(uint32_t begin, uint32_t end)
995  {
996  for (uint32_t i = begin; i <= end; i++)
997  {
998  this->operator()(i);
999  }
1000  }
1001 
1002 private:
1003  float timeStep;
1004  float* x;
1005  float* y;
1006  float* forceArrayX;
1007  float* forceArrayY;
1012 };
1013 
1014 
1015 template<unsigned int FLAGS>
1017 {
1018  return NodeMoveFunctor<FLAGS>( pLocalContext );
1019 }
1020 
1021 
1022 template<typename TYP>
1023 inline void for_loop_array_set(uint32_t threadNr, uint32_t numThreads, TYP* a, uint32_t n, TYP value)
1024 {
1025  uint32_t s = n/numThreads;
1026  uint32_t o = s*threadNr;
1027  if (threadNr == numThreads-1)
1028  s = s + (n % numThreads);
1029 
1030  for (uint32_t i = 0; i < s; i++ ) { a[o+i] = value; }
1031 }
1032 
1033 }
1034 }
int operator&(int lhs, FMEEdgeForce rhs)
Definition: FMEFunc.h:726
LQPartitioner(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:376
void operator()(LinearQuadtree::NodeID nodeIndex)
Definition: FMEFunc.h:241
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:511
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:925
NDFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:634
float * desiredEdgeLength()
Returns the edge length array for all edges.
Definition: ArrayGraph.h:186
static constexpr int TIME_STEP_PREP
Definition: FMEFunc.h:923
float * forceY
local force array for all nodes, points
Definition: FMEFunc.h:123
the main global options for a run
Definition: FMEFunc.h:68
double maxForceSq
local maximum force
Definition: FMEFunc.h:124
Declaration of class WSPD (well-separated pair decomposition).
static l2p_functor l2p_function(FMELocalContext *pLocalContext)
creates Local-to-Point functor
Definition: FMEFunc.h:327
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:151
float min_y
global point, node min y coordinate for bounding box calculations
Definition: FMEFunc.h:128
FMENodeChainPartition leafPartition
chain of leaf nodes assigned to the thread
Definition: FMEFunc.h:133
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:129
Information about incident edges (16 bytes).
Definition: EdgeChain.h:42
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:613
LinearQuadtreeExpansion & expansions
Definition: FMEFunc.h:307
FMEGlobalOptions * pOptions
pointer to the global options
Definition: FMEFunc.h:107
void operator()(LinearQuadtree::NodeID nodeIndex)
Definition: FMEFunc.h:289
void operator()(LinearQuadtree::NodeID nodeIndexSource, LinearQuadtree::NodeID nodeIndexReceiver)
Definition: FMEFunc.h:262
LinearQuadtreeExpansion * quadtreeExp
Definition: FMEFunc.h:665
LinearQuadtreeExpansion * pExpansion
pointer to the coeefficients
Definition: FMEFunc.h:103
void operator()(LinearQuadtree::NodeID nodeIndexA, LinearQuadtree::NodeID nodeIndexB)
Definition: FMEFunc.h:342
CollectForceFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:840
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:994
FMENodeChainPartition innerNodePartition
chain of inner nodes assigned to the thread
Definition: FMEFunc.h:132
std::list< LinearQuadtree::NodeID > nodes
Definition: FMEFunc.h:49
static constexpr int ZERO_GLOBAL_ARRAY
Definition: FMEFunc.h:924
Calculates the repulsive forces acting between all nodes of the direct interacting cells of the i-th ...
Definition: FMEFunc.h:674
static p2p_functor p2p_function(FMELocalContext *pLocalContext)
creates Local-to-Point functor
Definition: FMEFunc.h:366
void operator()(LinearQuadtree::NodeID nodeIndex, LinearQuadtree::PointID pointIndex)
Definition: FMEFunc.h:313
void operator()(LinearQuadtree::NodeID parent, LinearQuadtree::NodeID child)
Definition: FMEFunc.h:284
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:784
m2l_functor(LinearQuadtreeExpansion &e)
Definition: FMEFunc.h:260
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:207
l2p_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e, float *x, float *y)
Definition: FMEFunc.h:311
float min_x
global point, node min x coordinate for bounding box calculations
Definition: FMEFunc.h:111
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:896
static NodeMoveFunctor< FLAGS > node_move_function(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:1016
LinearQuadtreeExpansion & expansions
Definition: FMEFunc.h:280
static l2l_functor l2l_function(FMELocalContext *pLocalContext)
creates Local-to-Local functor
Definition: FMEFunc.h:297
void operator()(LinearQuadtree::NodeID nodeIndex)
Definition: FMEFunc.h:209
LinearQuadtreeExpansion * quadtreeExp
Definition: FMEFunc.h:579
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:587
LQMortonFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:159
float max_y
global point, node max y coordinate for bounding box calculations
Definition: FMEFunc.h:114
LinearQuadtreeExpansion * quadtreeExp
Definition: FMEFunc.h:716
static EdgeForceFunctor< FLAGS > edge_force_function(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:807
uint32_t numInnerNodes
number of inner nodes the thread prepared
Definition: FMEFunc.h:137
bool doPrepProcessing
enable preprocessing
Definition: FMEFunc.h:82
ArrayGraph * pGraph
pointer to the array graph
Definition: FMEFunc.h:101
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:531
LinearQuadtree::NodeID firstInnerNode
first inner nodes the thread prepared
Definition: FMEFunc.h:135
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:706
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:655
Information about an edge (16 bytes).
Definition: EdgeChain.h:51
void operator()(LinearQuadtree::NodeID parent, LinearQuadtree::NodeID child)
Definition: FMEFunc.h:236
float * forceX
local force array for all nodes, points
Definition: FMEFunc.h:122
float max_x
global point, node max x coordinate for bounding box calculations
Definition: FMEFunc.h:127
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:569
Declaration of class LinearQuadtreeBuilder.
EdgeForceFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:734
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:827
Declaration of FME kernel.
LinearQuadtree * pQuadtree
pointer to the quadtree
Definition: FMEFunc.h:102
double stopCritAvgForce
stopping criteria
Definition: FMEFunc.h:86
static p2m_functor p2m_function(FMELocalContext *pLocalContext)
creates a Point-to-Multipole functor
Definition: FMEFunc.h:222
Calculates the repulsive forces acting between all nodes inside the cell of the i-th LinearQuadtree n...
Definition: FMEFunc.h:631
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:100
LinearQuadtreeExpansion & expansions
Definition: FMEFunc.h:205
Point-to-Multipole functor.
Definition: FMEFunc.h:202
Multipole-to-Multipole functor.
Definition: FMEFunc.h:229
float min_x
global point, node min x coordinate for bounding box calculations
Definition: FMEFunc.h:126
double avgForce
local maximum force
Definition: FMEFunc.h:125
NodeMoveFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:932
WSPD * pWSPD
pointer to the well separated pairs decomposition
Definition: FMEFunc.h:104
float min_y
global point, node min y coordinate for bounding box calculations
Definition: FMEFunc.h:113
Multipole-to-Local functor.
Definition: FMEFunc.h:256
static CollectForceFunctor< FLAGS > collect_force_function(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:916
float * globalForceY
the global node force y array
Definition: FMEFunc.h:106
m2m_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e)
Definition: FMEFunc.h:234
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:553
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:141
FMELocalContext ** pLocalContext
all local contexts
Definition: FMEFunc.h:99
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:145
bool earlyExit
var for the main thread to notify the other threads that they are done
Definition: FMEFunc.h:108
The partitioner which partitions the quadtree into subtrees and partitions the sequence of inner node...
Definition: FMEFunc.h:373
LinearQuadtreeExpansion * quadtreeExp
Definition: FMEFunc.h:623
float * globalForceX
the global node force x array
Definition: FMEFunc.h:105
l2l_functor(const LinearQuadtree &t, LinearQuadtreeExpansion &e)
Definition: FMEFunc.h:282
D2DFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:677
FMETreePartition treePartition
tree partition assigned to the thread
Definition: FMEFunc.h:131
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:922
p2p_functor(const LinearQuadtree &t, float *x, float *y)
Definition: FMEFunc.h:340
float max_x
global point, node max x coordinate for bounding box calculations
Definition: FMEFunc.h:112
static m2l_functor m2l_function(FMELocalContext *pLocalContext)
creates Multipole-to-Local functor
Definition: FMEFunc.h:270
LinearQuadtreeExpansion & expansions
Definition: FMEFunc.h:258
Declaration of class LinearQuadtreeExpansion.
M2LFunctor(FMELocalContext *pLocalContext)
Definition: FMEFunc.h:590
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:249
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:136
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:140
Computes the coords and size of the i-th node in the LinearQuadtree.
Definition: FMEFunc.h:550
void for_loop_array_set(uint32_t threadNr, uint32_t numThreads, TYP *a, uint32_t n, TYP value)
Definition: FMEFunc.h:1023
LinearQuadtree::NodeID firstLeaf
first leaves the thread prepared
Definition: FMEFunc.h:139
float repForceFactor
repulsive force factor for the main step
Definition: FMEFunc.h:76
void operator()(uint32_t begin, uint32_t end)
Definition: FMEFunc.h:182
void operator()(LinearQuadtree::NodeID nodeIndex)
Definition: FMEFunc.h:356
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:121
double stopCritForce
stopping criteria
Definition: FMEFunc.h:85
void operator()(LinearQuadtree::PointID pointIndex)
Definition: FMEFunc.h:318
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:232