Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

[diderot] View of /branches/lamont/test/implicit-surface/unit-circle.diderot
 [diderot] / branches / lamont / test / implicit-surface / unit-circle.diderot

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

Sat Mar 2 02:00:56 2013 UTC (7 years, 1 month ago) by lamonts
File size: 2145 byte(s)
`Fixed error for ceil, had it taking in 2 arguments rather than 1`
```// unit-circle
//
// Demo of distributing particles on the unit circle
//
int numOfParticles = length(initPosns)/2;
input real rr = 0.08;     // actual particle radius
input real RR = 0.15;     // neighbor query radius (MUST be bigger than rr, but should get same results for any RR > rr)
input real hh = 0.001;    // integration step size to control how quickly iterations change position.
input int MAX_ITER = 200; // maximum number of steps in the program
vec2 xDom = [-1,1];
vec2 yDom = [-1,1];
real xSamples = floor((xDom[1] - xDom[0])/RR); // Lamont verify logic floor vs ceil here
real ySamples = floor((yDom[1] - yDom[0])/RR);
vec4 qWinDim = [xDom[0],xDom[1],yDom[0],yDom[1]]; // i.e. [XMIN, XMAX, YMIN, YMAX]  (required for the query function)
vec2 qGridDim = [xSamples,ySamples];   // how many grid cells you want in each direction for the uniform grid (required for the query function)
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)
int iter = 1;

strand Particle (int ii, real posx, real posy) {
vec2 pos = normalize([posx,posy]);
output vec2 outPos  = pos;
int id = ii;
update {

/*
print(atan2(pos[1],pos[0]), " ");
if (i == numOfParticles-1) {
print("\n");
}
*/

real energy = 0;
vec2 force = [0,0];
foreach (Particle p_j in sphere(RR)) {
vec2 r_ij = (pos - p_j.pos)/rr;
vec2 d_ij = normalize(r_ij);
print("===== ", id, ": with ", p_j.id, "; |r_ij| = ", |r_ij|, "\n");

if (|r_ij| < 1) {
energy += (1 - |r_ij|)^4;
force += - (-4*(1 - |r_ij|)^3) * d_ij;
}
}

vec2 step = hh*force/rr;
pos = normalize(pos + step);

outPos = pos;

if (iter >= MAX_ITER) {
stabilize;
}

}
}

// can add statements in here to do some global computation
global{
iter+=1;
}

initially {Particle(ii, initPosns{ii*2}, initPosns{ii*2+1})
| ii in 0 .. numOfParticles-1 };

```