in reply to Particle movement question

So this would be the C code I need to implement into the code.

if (strcmp(streakfile,"none") || strcmp(tracefile,"none")) Particlelines = SET_PARTICLES(N,pos1x,pos1y,pos2x,pos2y); Particlelines = INIT_PARTICLES(&N,imax,jmax,delx,dely,ppc,problem,U,V +); SETBCOND(U,V,P,TEMP,FLAG,imax,jmax,wW,wE,wN,wS); SETSPECBCOND(problem,U,V,P,TEMP,imax,jmax,UI,VI); struct particleline *INIT_PARTICLES (int *N,int imax,int jmax, REAL delx,REAL dely, int ppc,char *problem,REAL **U,RE +AL **V) { int i,j,ip,jp; struct particleline *Particlelines; REAL x,y; REAL height=0,rad=0,mpx=0,mpy=0,vstart=0; if((Particlelines=(struct particleline *) malloc((unsigned)(*N) * sizeof(struct particleline))) == +NULL) { printf("no memory"); exit(0); } Particlelines -= 1; /* Particlelines from 1 to N */ for (i=1;i<=*N;i++) { Particlelines[i].length = 0; Particlelines[i].Particles = PARTALLOC(-1.,-1.); } /* Set the particles */ for (i=1;i<=imax;i++) for (j=1;j<=jmax;j++) for (ip=1;ip<=ppc;ip++) { x = (i-1)*delx+(ip-.5)/((REAL)ppc)*delx; for (jp=1;jp<=ppc;jp++) { y = (j-1)*dely+(jp-.5)/((REAL)ppc)*dely; if(strcmp(problem, "dam")==0) if (x<0.2*imax*delx) SET_PART(&Particlelines[1],x,y); if(strcmp(problem, "drop")==0) { if (y<height) { SET_PART(&Particlelines[1],x,y); } else if ((x-mpx)*(x-mpx)+(y-mpy)*(y-mpy) <= rad*rad) { SET_PART(&Particlelines[2],x,y); V[i][j] = vstart; } } } } return (Particlelines); } /*----------------------------------------------------------------*/ /* Add particle to "Partline" at (x,y) */ /*----------------------------------------------------------------*/ void SET_PART(struct particleline *Partline, REAL x,REAL y) { struct particle *part; part = PARTALLOC(x,y); /* create particle +*/ part->next = (*Partline).Particles->next; /* add it to "Partline" +*/ (*Partline).Particles->next = part; /* in the first position +*/ (*Partline).length++; }

Replies are listed 'Best First'.
Re^2: Particle movement question
by Anonymous Monk on Apr 25, 2017 at 23:03 UTC
    Requirements are far more useful. What are the rules you go by to determine how a particle behaves?

      The particle will act as a fluid being confined by a free boundary. The first processing step is marking all of the cells with particles in them as fluid cells, and then marking the rest of the cells depending on their neightbor (1 empty cell, 2 empty cells etc etc.) , also specifying the direction. I have that code as well if that wll clarify things. So given an initial velocity, I will make a series of calculations that give me new velocites and pressure at Tn+1. Then I can reassign the boundary conditions for the free boundary, and then re mark the Fluid cells (particle cells) and so on. I hope that answers your question .

        I am also having trouble making sense of this structure and converting it.

        /* Mark cells containing particles as fluid cells (loop over particle +s) */ /*------------------------------------------------------------------- +---*/ for (n=1;n<=N;n++) for(part=Particlelines[n].Particles; part->next != NULL; part=part +->next) { x = part->next->x; y = part->next->y; i = (int)(x/delx)+1; j = (int)(y/dely)+1; if (FLAG[i][j] < C_F) { /* delete particles in obstacle cells */ help = part->next->next; free(part->next); part->next = help; Particlelines[n].length--; } else FLAG[i][j] = FLAG[i][j] & ~C_E; }