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

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