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 2226 - (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 2226 if(id == 0)
37 :     print(steps, "\n");
38 : lamonts 2224 real angle = 0.0;
39 : lamonts 2226 angle = atan2(pos[1],pos[0])* 180/π;
40 :     angle = (angle + 360) if angle < 0 else angle; // atan2 rangs from (π,-π] so need to range from [0,2π)
41 :     //print("Angle = ", angle, "\n");
42 : lamonts 2224 //Looking at how strand #0 changes for 30 iterations.
43 : lamonts 2225 /*if(id == 0) {
44 : lamonts 2224 print("pos before = ", pos, "\n");
45 :     print("force = ", force, "\n");
46 :     angle = atan2(pos[1],pos[0])* 180/π;
47 :     angle = (angle + 360) if angle < 0 else angle; // atan2 rangs from (π,-π] so need to range from [0,2π)
48 :     print("Angle = ", angle, "\n");
49 :     }*/
50 :    
51 :     force *= h;
52 :    
53 :     real isZero = force • force;
54 :    
55 :     // limit the force
56 :     if ( isZero != 0 && |force| > MAX_FORCE) {
57 :     force = normalize(force);
58 :     force *= MAX_FORCE;
59 :     }
60 :    
61 :     pos += force;
62 :     pos = normalize(pos);
63 :    
64 : lamonts 2225 /* if(id == 0) {
65 : lamonts 2224 print("new pos = ", pos, "\n");
66 :     angle = atan2(pos[1],pos[0])* 180/π;
67 :     angle = (angle + 360) if angle < 0 else angle;
68 :     print("new angle = ", angle, "\n");
69 :     print("========= iteration done ==================\n");
70 : lamonts 2225 } */
71 : lamonts 2138 outPos = pos;
72 : lamonts 2226
73 :     if(steps >= MAX_ITER) {
74 : lamonts 2224 stabilize;
75 :     }
76 : lamonts 2131 }
77 :     }
78 :    
79 : lamonts 2224 // can add statements in here to do some global computation
80 :     global{
81 :     steps+=1;
82 :     }
83 :    
84 :     initially {Particle(i,initPosns{i*2},initPosns{i*2+1}) | i in 0 .. numOfParticles-1 };
85 :    

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