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 2235 - (view) (download)

1 : lamonts 2131 // unit-circle
2 :     //
3 : glk 2230 // Demo of distributing particles on the unit circle
4 : lamonts 2131 //
5 : glk 2230 real{} initPosns = load("-");
6 :     int numOfParticles = length(initPosns)/2;
7 : glk 2235 input real rr = 0.08; // actual particle radius
8 :     input real RR = 0.15; // neighbor query radius (MUST be bigger than rr, but should get same results for any RR > rr)
9 :     input real hh = 0.001; // integration step size to control how quickly iterations change position.
10 :     input int MAX_ITER = 200; // maximum number of steps in the program
11 : glk 2230 vec2 xDom = [-1,1];
12 :     vec2 yDom = [-1,1];
13 :     // HEY we need floor
14 :     int xSamples = floor((xDom[1] - xDom[0])/RR); // Lamont verify logic floor vs ceil here
15 :     int ySamples = floor((yDom[1] - yDom[0])/RR);
16 :     vec4 qWinDim = [xDom[0],xDom[1],yDom[0],yDom[1]]; // i.e. [XMIN, XMAX, YMIN, YMAX] (required for the query function)
17 :     vec2 qGridDim = [xSamples,ySamples]; // how many grid cells you want in each direction for the uniform grid (required for the query function)
18 :     vec2 qCellDim = [(xDom[1] - xDom[0])/xSamples,(yDom[1] - yDom[0])/ySamples]; // the length in each direction for a cell (required for the query function)
19 :     int iter = 1;
20 : lamonts 2131
21 : glk 2230 strand Particle (int ii, real posx, real posy) {
22 :     vec2 pos = normalize([posx,posy]);
23 : lamonts 2224 output vec2 outPos = pos;
24 : glk 2230 int id = ii;
25 : lamonts 2131 update {
26 :    
27 : glk 2230 /*
28 :     print(atan2(pos[1],pos[0]), " ");
29 :     if (i == numOfParticles-1) {
30 :     print("\n");
31 :     }
32 :     */
33 : lamonts 2224
34 : glk 2230 real energy = 0;
35 :     vec2 force = [0,0];
36 :     foreach (Particle p_j in sphere(RR)) {
37 : glk 2235 vec2 r_ij = (pos - p_j.pos)/rr;
38 : glk 2230 vec2 d_ij = normalize(r_ij);
39 :     print("===== ", id, ": with ", p_j.id, "; |r_ij| = ", |r_ij|, "\n");
40 : lamonts 2224
41 : glk 2230 if (|r_ij| < 1) {
42 :     energy += (1 - |r_ij|)^4;
43 :     force += - (-4*(1 - |r_ij|)^3) * d_ij;
44 :     }
45 : lamonts 2132 }
46 : lamonts 2224
47 : glk 2235 vec2 step = hh*force/rr;
48 : glk 2230 pos = normalize(pos + step);
49 : lamonts 2224
50 : glk 2230 outPos = pos;
51 : lamonts 2224
52 : glk 2230 if (iter >= MAX_ITER) {
53 : lamonts 2224 stabilize;
54 :     }
55 : glk 2230
56 : lamonts 2131 }
57 :     }
58 :    
59 : lamonts 2224 // can add statements in here to do some global computation
60 :     global{
61 : glk 2230 iter+=1;
62 :     }
63 : lamonts 2224
64 : glk 2230 initially {Particle(ii, initPosns{ii*2}, initPosns{ii*2+1})
65 :     | ii in 0 .. numOfParticles-1 };
66 : lamonts 2224

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