Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/lamont/test/implicit-surface/unit-circle.diderot
ViewVC logotype

Annotation of /branches/lamont/test/implicit-surface/unit-circle.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2229 - (view) (download)

1 : lamonts 2131 // unit-circle
2 :     //
3 :     // Demo of distributing particles on the unit circle
4 :     //
5 : lamonts 2224 real{} initPosns = load("../../data/implicit-surface/circlePosns.nrrd"); // file has 300 particle positions
6 : lamonts 2226 input int numOfParticles = 100; // But I'm only look at 100 for right now.
7 :     input real r = 0.08; // particle radius
8 :     input real d = 0.16; // desired difference of radius (d < r && d > 0)
9 :     input real R = 0.15; // neighbor radius
10 : lamonts 2224 real MAX_FORCE = 2;
11 : lamonts 2226 input real h = 0.09; // integration step size to control how quickly iterations change position.
12 :     input int MAX_ITER = 10; // maximum number of steps in the program
13 : lamonts 2224 vec4 qWinDim = [-1,1,-1,1]; // i.e. [XMIN, XMAX, YMIN, YMAX] (required for the query function)
14 : lamonts 2226 vec2 qGridDim = [12,12]; // how many grid cells you want in each direction for the uniform grid (required for the query function)
15 :     vec2 qCellDim = [r,r]; // the length in each direction for a cell (required for the query function)
16 : lamonts 2224 int steps = 1;
17 : lamonts 2131
18 : lamonts 2224 strand Particle (int i, real posx, real posy) {
19 : lamonts 2138 vec2 pos = [posx,posy];
20 : lamonts 2224 output vec2 outPos = pos;
21 : lamonts 2225 int id = i;
22 : lamonts 2131 update {
23 :    
24 : lamonts 2224 vec2 energy =[0.0,0.0];
25 :     vec2 force = [0.0,0.0];
26 :    
27 : lamonts 2138 foreach(Particle neighbor in sphere(R)){
28 : lamonts 2224 real neighborDist = dist (pos,neighbor.pos);
29 :     vec2 unitDirection = normalize(pos-neighbor.pos);
30 :    
31 :     if(neighborDist >= 0 && neighborDist <= 1) {
32 :     force += ((-4.0 * ((1 - neighborDist)^3)) * unitDirection);
33 :     energy += (((1 - neighborDist)^4) * unitDirection);
34 : lamonts 2137 }
35 : lamonts 2132 }
36 : lamonts 2224 real angle = 0.0;
37 :    
38 :     force *= h;
39 :    
40 :     real isZero = force • force;
41 :    
42 :     // limit the force
43 :     if ( isZero != 0 && |force| > MAX_FORCE) {
44 :     force = normalize(force);
45 :     force *= MAX_FORCE;
46 :     }
47 :    
48 :     pos += force;
49 :     pos = normalize(pos);
50 :    
51 : lamonts 2229 angle = atan2(pos[1],pos[0]);
52 :     print(angle, " ");
53 :    
54 : lamonts 2138 outPos = pos;
55 : lamonts 2226
56 :     if(steps >= MAX_ITER) {
57 : lamonts 2224 stabilize;
58 :     }
59 : lamonts 2229
60 : lamonts 2131 }
61 :     }
62 :    
63 : lamonts 2224 // can add statements in here to do some global computation
64 :     global{
65 :     steps+=1;
66 :     }
67 :    
68 :     initially {Particle(i,initPosns{i*2},initPosns{i*2+1}) | i in 0 .. numOfParticles-1 };
69 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0