41 namespace fast_multipole_embedder {
67 #define OGDF_FME_KERNEL_USE_OLD 69 #define OGDF_FME_KERNEL_COMPUTE_FORCE_PROTECTION_FACTOR 0.25f 71 #define OGDF_FME_KERNEL_MM_COMPUTE_FORCE(dx,dy,s) \ 73 _mm_max_ps(_mm_mul_ps((s), \ 74 _mm_set1_ps(OGDF_FME_KERNEL_COMPUTE_FORCE_PROTECTION_FACTOR)), \ 75 _mm_add_ps(_mm_mul_ps((dx),(dx)), \ 76 _mm_mul_ps((dy),(dy))))) 77 #define OGDF_FME_KERNEL_COMPUTE_FORCE(dx,dy,s) \ 78 (s/(max<float>(s*OGDF_FME_KERNEL_COMPUTE_FORCE_PROTECTION_FACTOR, (dx)*(dx) + (dy)*(dy)))) 80 inline double move_nodes(
float* x,
float* y,
const uint32_t begin,
const uint32_t end,
const float* fx,
const float* fy,
const float t)
83 for (uint32_t i=begin; i <= end; i++)
85 double dsq = fx[i]*fx[i] + fy[i]*fy[i];
88 dsq_max = max(dsq_max, dsq);
94 inline void eval_edges(
const ArrayGraph& graph,
const uint32_t begin,
const uint32_t end,
float* fx,
float* fy)
99 for (uint32_t i=begin; i <= end; i++)
101 const auto& e_info = graph.
edgeInfo(i);
102 const uint32_t a = e_info.
a;
103 const uint32_t b = e_info.b;
104 const auto& a_info = graph.
nodeInfo(a);
105 const auto& b_info = graph.
nodeInfo(b);
107 float dx = x[a] - x[b];
108 float dy = y[a] - y[b];
109 float dsq = dx*dx + dy*dy;
110 float f = (logf(dsq)*0.5f-logf(e[i])) * 0.25f;
111 float fa = (float)(f/((
float)a_info.degree));
112 float fb = (float)(f/((
float)b_info.degree));
122 inline void eval_direct(
float* x,
float* y,
float* s,
float* fx,
float* fy,
size_t n)
124 for (uint32_t i=0; i < n; i++)
126 for (uint32_t j=i+1; j < n; j++)
128 float dx = x[i] - x[j];
129 float dy = y[i] - y[j];
130 #ifdef OGDF_FME_KERNEL_USE_OLD 131 float s_sum = s[i]+s[j];
133 float s_sum = s[i]*s[j];
146 inline void eval_direct(
float* x1,
float* y1,
float* s1,
float* fx1,
float* fy1,
size_t n1,
147 float* x2,
float* y2,
float* s2,
float* fx2,
float* fy2,
size_t n2)
149 for (uint32_t i=0; i < n1; i++)
151 for (uint32_t j=0; j < n2; j++)
153 float dx = x1[i] - x2[j];
154 float dy = y1[i] - y2[j];
155 #ifdef OGDF_FME_KERNEL_USE_OLD 156 float s_sum = s1[i]+s2[j];
158 float s_sum = s1[i]*s2[j];
170 #ifndef OGDF_FME_KERNEL_USE_SSE_DIRECT 171 inline void eval_direct_fast(
float* x,
float* y,
float* s,
float* fx,
float* fy,
size_t n)
178 inline void eval_direct_fast(
float* x1,
float* y1,
float* s1,
float* fx1,
float* fy1,
size_t n1,
179 float* x2,
float* y2,
float* s2,
float* fx2,
float* fy2,
size_t n2)
182 x2, y2, s2, fx2, fy2, n2);
186 void eval_direct_fast(
float* x,
float* y,
float* s,
float* fx,
float* fy,
size_t n);
190 float* x1,
float* y1,
float* s1,
float* fx1,
float* fy1,
size_t n1,
191 float* x2,
float* y2,
float* s2,
float* fx2,
float* fy2,
size_t n2);
195 void fast_multipole_l2p(
double* localCoeffiecients, uint32_t numCoeffiecients,
double centerX,
double centerY,
196 float x,
float y,
float q,
float& fx,
float &fy);
198 void fast_multipole_p2m(
double* mulitCoeffiecients, uint32_t numCoeffiecients,
double centerX,
double centerY,
199 float x,
float y,
float q);
221 repForces(graph, fx, fy);
222 edgeForces(graph, fx, fy);
223 return moveNodes(graph, fx, fy, timeStep);
229 edgeForces(graph, fx, fy);
230 return moveNodes(graph, fx, fy, timeStep);
236 bool earlyExit =
false;
240 for (uint32_t i = 0; i<preProcIt; i++)
242 for (uint32_t j = 0; j<graph.
numNodes(); j++)
247 simpleEdgeIteration(graph, fx, fy, timeStep);
249 for(uint32_t i = 0; (i<maxIt) && (!earlyExit); i++)
251 for (uint32_t j = 0; j<graph.
numNodes(); j++)
256 double dsq = simpleIteration(graph, fx, fy, timeStep);
257 if (dsq < threshold && i>(minIt))
278 simpleForceDirected(graph, timeStep, minIt, maxIt, 20, threshold);
void simpleForceDirected(ArrayGraph &graph, float timeStep, uint32_t minIt, uint32_t maxIt, uint32_t preProcIt, double threshold)
uint32_t numEdges() const
Returns the number of edges.
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...
double move_nodes(float *x, float *y, const uint32_t begin, const uint32_t end, const float *fx, const float *fy, const float t)
uint32_t threadNr() const
returns the index of the thread ( 0.. numThreads()-1 )
float * desiredEdgeLength()
Returns the edge length array for all edges.
void eval_edges(const ArrayGraph &graph, const uint32_t begin, const uint32_t end, float *fx, float *fy)
Definition of utility functions for FME layout.
void fast_multipole_p2m(double *mulitCoeffiecients, uint32_t numCoeffiecients, double centerX, double centerY, float x, float y, float q)
Declaration of class ArrayGraph.
double simpleEdgeIteration(ArrayGraph &graph, float *fx, float *fy, float timeStep)
uint32_t numThreads() const
returns the total number of threads in the pool
void edgeForces(const ArrayGraph &graph, float *fx, float *fy)
uint32_t threadNr() const
returns the index of the thread ( 0.. numThreads()-1 )
bool isMainThread() const
returns true if this is the main thread ( the main thread is always the first thread ) ...
void repForces(ArrayGraph &graph, float *fx, float *fy)
Declaration of class FMEThread.
bool isSingleThreaded() const
returns true if this run only uses one thread )
NodeAdjInfo & nodeInfo(uint32_t i)
Returns the adjacency information for the node at index i in m_nodeAdj.
float * nodeXPos()
Returns the x coord array for all nodes.
uint32_t numNodes() const
Returns the number of nodes.
void operator()(ArrayGraph &graph, float timeStep, uint32_t minIt, uint32_t maxIt, double threshold)
The fast multipole embedder work thread class.
float * nodeSize()
Returns the node size array for all nodes.
uint32_t a
First node of the pair.
EdgeAdjInfo & edgeInfo(uint32_t i)
Returns the adjacency information for the edge at index i in m_edgeAdj.
bool isMainThread() const
returns true if this is the main thread ( the main thread is always the first thread ) ...
void fast_multipole_l2p(double *localCoeffiecients, uint32_t numCoeffiecients, double centerX, double centerY, float x, float y, float q, float &fx, float &fy)
kernel function to evalute a local expansion at point x,y result is added to fx, fy ...
Basic declarations, included by all source files.
double simpleIteration(ArrayGraph &graph, float *fx, float *fy, float timeStep)
double moveNodes(ArrayGraph &graph, float *fx, float *fy, float timeStep)
void eval_direct(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...
FMEKernel(FMEThread *pThread)
#define OGDF_MALLOC_16(s)
16-byte aligned memory allocation macro
void sync()
thread sync call
uint32_t numThreads() const
returns the total number of threads in the pool
The namespace for all OGDF objects.
float * nodeYPos()
Returns the y coord array for all nodes.
#define OGDF_FREE_16(ptr)
16-byte aligned memory deallocation macro
#define OGDF_FME_KERNEL_COMPUTE_FORCE(dx, dy, s)