root/Multipole/trunk/multipole.h @ 1

Revision 1, 4.2 KB (checked in by cristy, 3 months ago)


RevLine 
[1]1/*
2  Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License.
6  obtain a copy of the License at
7 
8    http://www.imagemagick.org/script/license.php
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15
16  MagickCore methods to interactively animate an image sequence.
17*/
18#ifdef hpux
19#define _HPUX_SOURCE 1
20#endif
21#include <stdarg.h>
22#include <stdio.h>
23#include <stdlib.h>
24#if defined(__STDC__) || defined(sgi) || defined(_AIX)
25#include <unistd.h>
26#else
27#include <malloc.h>
28#include <memory.h>
29#endif
30#include <ctype.h>
31#include <string.h>
32#include <time.h>
33#include <math.h>
34/*
35  Define declarations for the N-body program.
36*/
37#ifdef WIN32
38#undef stderr
39#define stderr stdout
40#endif
41#define AbsoluteValue(x)  ((x) < 0 ? -(x) : (x))
42#ifndef False
43#define False  0
44#endif
45#define CircumscribedSphereRadius  1.5  /* choose from: 3.0, 2.5, 2.0, 1.5 */
46#define GravitationalConstant  1.0e-3
47#define HighestDegreeHarmonic  20
48#define Max(x,y)  (((x) > (y)) ? (x) : (y))
49#define MaxChildren  8
50#define MaxNodesInteractiveField  189  /* choose from: 140, 119, 77, 56 */
51#define MaxNodesNearField  26  /* choose from: 80, 56, 32, 26 */
52#define MaxTreeDepth  8  /* Log2(MaxRange) */
53#define Min(x,y)  (((x) < (y)) ? (x) : (y))
54#define NodesInAQueue  4681  /* 1+8+64+512+4096 */
55#ifndef RAND_MAX
56#define RAND_MAX  32767
57#endif
58#define TetrahedralArray(array,i,j,k)  \
59  array[cube.tetra_three[i]-cube.tetra_two[(i)+(j)]+(k)]
60#ifndef True
61#define True  1
62#endif
63#define Warning(message,qualifier)  \
64{  \
65  (void) fprintf(stderr,"%s: %s",application_name,message);  \
66  if (qualifier != (char *) NULL)  \
67    (void) fprintf(stderr," (%s)",qualifier);  \
68  (void) fprintf(stderr,".\n");  \
69}
70
71/*
72  Structures.
73*/
74typedef struct _Particle
75{
76  float
77    x,
78    y,
79    z;
80
81  struct _Particle
82    *next;
83} Particle;
84
85typedef struct _Node
86{
87  struct _Node
88    *parent,
89    *child[MaxChildren],
90    *near_field[MaxNodesNearField+1],
91    *interactive_field[MaxNodesInteractiveField+8];
92
93  unsigned long
94    id,
95    level;
96
97  float
98    mid_x,
99    mid_y,
100    mid_z,
101    *phi,
102    *psi;
103
104  Particle
105    *particle;
106} Node;
107
108typedef struct _Nodes
109{
110  Node
111    nodes[NodesInAQueue];
112
113  float
114    *phi,
115    *psi;
116
117  struct _Nodes
118    *next;
119} Nodes;
120
121typedef struct _Cube
122{
123  Node
124    *root;
125
126  unsigned long
127    depth;
128
129  long
130    level;
131
132  Node
133    **near_neighbor;
134
135  unsigned long
136    nodes,
137    free_nodes;
138
139  Node
140    *next_node;
141
142  Nodes
143    *node_queue;
144
145  float
146    edge_length[MaxTreeDepth],
147    diagonal_length[MaxTreeDepth],
148    binomial[HighestDegreeHarmonic+1][HighestDegreeHarmonic+1],
149    one_power[HighestDegreeHarmonic+1],
150    x_power[HighestDegreeHarmonic+1],
151    y_power[HighestDegreeHarmonic+1],
152    z_power[HighestDegreeHarmonic+1];
153
154  unsigned long
155    tetra_two[HighestDegreeHarmonic+3],
156    tetra_three[HighestDegreeHarmonic+3],
157    precision,
158    coefficients;
159
160  float
161    *ijk_binomial,
162    *ijk_factorial,
163    *phi,
164    *phi_tilde,
165    *psi,
166    *psi_tilde;
167
168  double
169    near_potential,
170    far_potential;
171} Cube;
172/*
173  Variable declarations.
174*/
175char
176  *application_name;
177/*
178  Forward declarations.
179*/
180static double
181  MultipolePotential(Particle *,unsigned long,unsigned long,unsigned long,
182    double,double),
183  NaivePotential(Particle *,unsigned long);
184
185static long
186  ProcessTime(void);
187
188static Node
189  *InitializeNode(unsigned long,unsigned long,Node *,double,double,double);
190
191static unsigned long
192  Binomial(long,long),
193  InNearField(register Node *,register Node *);
194
195static void
196  Classification(Particle *,unsigned long),
197  ComputePhi(register Node *),
198  ComputePsi(register Node *),
199  CreateCube(register Node *),
200  DefineInteractiveField(register Node *),
201  DefineNearField(register Node *),
202  Error(char *,char *),
203  EvaluatePotential(Node *node),
204  FindNeighbors(register Node *,register Node *),
205  LocalExpansion(Node *, Node *,float *),
206  MultipoleExpansion(Node *,Node *,register float *);
Note: See TracBrowser for help on using the browser.