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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2230 - (download) (annotate)
Fri Mar 1 22:56:17 2013 UTC (7 years, 4 months ago) by glk
File size: 2160 byte(s)
made notation consistent with Feb 28 email (r_ij, d_ij)
cleaned up / re-ordered code (printing at start of iter not end)
removed MAX_FORCE stuff (will implement limit on "step" later)
rethought how grid is specified, discovered absence of floor
// unit-circle
//
// Demo of distributing particles on the unit circle
//
real{} initPosns = load("-");
int numOfParticles = length(initPosns)/2;
input real rr = 0.08;       // particle radius
input real dd = 0.16;       // desired difference of radius (d < r && d > 0)
input real RR = 0.15;       // neighbor radius
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];
// HEY we need floor
int xSamples = floor((xDom[1] - xDom[0])/RR); // Lamont verify logic floor vs ceil here
int 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;
            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;
        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 };


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