}
moldyn->atom=ptr;
+#ifdef LOWMEM_LISTS
+ ptr=realloc(moldyn->lc.subcell->list,(count+1)*sizeof(int));
+ if(!ptr) {
+ perror("[moldyn] list realloc (add atom)");
+ return -1;
+ }
+ moldyn->lc.subcell->list=ptr;
+#endif
+
atom=moldyn->atom;
/* initialize new atom */
int link_cell_init(t_moldyn *moldyn,u8 vol) {
t_linkcell *lc;
+#ifndef LOWMEM_LISTS
int i;
+#endif
lc=&(moldyn->lc);
#ifdef STATIC_LISTS
lc->subcell=malloc(lc->cells*sizeof(int*));
-#elif LOWMEM_LIST
- lc->subcell=malloc(t_lowmem_list);
+#elif LOWMEM_LISTS
+ lc->subcell=malloc(sizeof(t_lowmem_list));
#else
lc->subcell=malloc(lc->cells*sizeof(t_list));
#endif
#ifdef STATIC_LISTS
printf("[moldyn] initializing 'static' linked cells (%d)\n",
lc->cells);
-#elif LOWMEM_LIST
+#elif LOWMEM_LISTS
printf("[moldyn] initializing 'lowmem' linked cells (%d)\n",
lc->cells);
#else
i,lc->subcell[0],lc->subcell);
*/
}
-#elif LOWMEM_LIST
+#elif LOWMEM_LISTS
lc->subcell->head=malloc(lc->cells*sizeof(int));
if(lc->subcell->head==NULL) {
perror("[moldyn] head init (malloc)");
int link_cell_update(t_moldyn *moldyn) {
int count,i,j,k;
- int nx,ny;
+ int nx,nxy;
t_atom *atom;
t_linkcell *lc;
#ifdef STATIC_LISTS
int p;
+#elif LOWMEM_LISTS
+ int p;
#endif
atom=moldyn->atom;
lc=&(moldyn->lc);
nx=lc->nx;
- ny=lc->ny;
+ nxy=nx*lc->ny;
for(i=0;i<lc->cells;i++)
#ifdef STATIC_LISTS
memset(lc->subcell[i],-1,(MAX_ATOMS_PER_LIST+1)*sizeof(int));
-#elif LOWMEM_LIST
+#elif LOWMEM_LISTS
lc->subcell->head[i]=-1;
#else
list_destroy_f(&(lc->subcell[i]));
#ifdef STATIC_LISTS
p=0;
- while(lc->subcell[i+j*nx+k*nx*ny][p]!=-1)
+ while(lc->subcell[i+j*nx+k*nxy][p]!=-1)
p++;
if(p>=MAX_ATOMS_PER_LIST) {
return -1;
}
- lc->subcell[i+j*nx+k*nx*ny][p]=count;
-#elif LOWMEM_LIST
- lc->subcell->list[count]=list->subcell->head[i+j*nx+k*nx*ny];
- list->subcell->head=count;
+ lc->subcell[i+j*nx+k*nxy][p]=count;
+#elif LOWMEM_LISTS
+ p=i+j*nx+k*nxy;
+ lc->subcell->list[count]=lc->subcell->head[p];
+ lc->subcell->head[p]=count;
#else
- list_add_immediate_f(&(lc->subcell[i+j*nx+k*nx*ny]),
+ list_add_immediate_f(&(lc->subcell[i+j*nx+k*nxy]),
&(atom[count]));
/*
if(j==0&&k==0)
int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,
#ifdef STATIC_LISTS
int **cell
+#elif LOWMEM_LISTS
+ int *cell
#else
t_list *cell
#endif
printf("[moldyn] WARNING: lcni %d/%d %d/%d %d/%d\n",
i,nx,j,ny,k,nz);
+#ifndef LOWMEM_LISTS
cell[0]=lc->subcell[i+j*nx+k*a];
+#else
+ cell[0]=lc->subcell->head[i+j*nx+k*a];
+#endif
for(ci=-1;ci<=1;ci++) {
bx=0;
x=i+ci;
}
if(!(ci|cj|ck)) continue;
if(bx|by|bz) {
+#ifndef LOWMEM_LISTS
cell[--count2]=lc->subcell[x+y*nx+z*a];
+#else
+ cell[--count2]=lc->subcell->head[x+y*nx+z*a];
+#endif
+
}
else {
+#ifndef LOWMEM_LISTS
cell[count1++]=lc->subcell[x+y*nx+z*a];
+#else
+ cell[count1++]=lc->subcell->head[x+y*nx+z*a];
+#endif
}
}
}
int link_cell_shutdown(t_moldyn *moldyn) {
+#ifndef LOWMEM_LISTS
int i;
+#endif
t_linkcell *lc;
lc=&(moldyn->lc);
+#if LOWMEM_LISTS
+ free(lc->subcell->head);
+ free(lc->subcell->list);
+
+#else
+
for(i=0;i<lc->cells;i++) {
#ifdef STATIC_LISTS
free(lc->subcell[i]);
list_destroy_f(&(lc->subcell[i]));
#endif
}
+#endif
free(lc->subcell);
int *neighbour_i[27];
int p,q;
t_atom *atom;
+#elif LOWMEM_LISTS
+ int neighbour_i[27];
+ int p,q;
#else
t_list neighbour_i[27];
t_list neighbour_i2[27];
jtom=&(atom[neighbour_i[j][p]]);
p++;
+#elif LOWMEM_LISTS
+ p=neighbour_i[j];
+
+ while(p!=-1) {
+
+ jtom=&(itom[p]);
+ p=lc->subcell->list[p];
#else
this=&(neighbour_i[j]);
list_reset_f(this);
}
#ifdef STATIC_LISTS
}
+#elif LOWMEM_LISTS
+ }
#else
} while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
#endif
/* copy the neighbour lists */
#ifdef STATIC_LISTS
/* no copy needed for static lists */
+#elif LOWMEM_LISTS
+ /* no copy needed for lowmem lists */
#else
memcpy(neighbour_i2,neighbour_i,27*sizeof(t_list));
#endif
jtom=&(atom[neighbour_i[j][p]]);
p++;
+#elif LOWMEM_LISTS
+ p=neighbour_i[j];
+
+ while(p!=-1) {
+
+ jtom=&(itom[p]);
+ p=lc->subcell->list[p];
#else
this=&(neighbour_i[j]);
list_reset_f(this);
ktom=&(atom[neighbour_i[k][q]]);
q++;
+#elif LOWMEM_LISTS
+ q=neighbour_i[k];
+
+ while(q!=-1) {
+
+ ktom=&(itom[q]);
+ q=lc->subcell->list[q];
#else
that=&(neighbour_i2[k]);
list_reset_f(that);
bc_ik|bc_ij);
#ifdef STATIC_LISTS
}
+#elif LOWMEM_LISTS
+ }
#else
} while(list_next_f(that)!=\
L_NO_NEXT_ELEMENT);
ktom=&(atom[neighbour_i[k][q]]);
q++;
+#elif LOWMEM_LISTS
+ q=neighbour_i[k];
+
+ while(q!=-1) {
+
+ ktom=&(itom[q]);
+ q=lc->subcell->list[q];
#else
that=&(neighbour_i2[k]);
list_reset_f(that);
#ifdef STATIC_LISTS
}
+#elif LOWMEM_LISTS
+ }
#else
} while(list_next_f(that)!=\
L_NO_NEXT_ELEMENT);
}
#ifdef STATIC_LISTS
}
+#elif LOWMEM_LISTS
+ }
#else
} while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
#endif
#ifdef STATIC_LISTS
int *neighbour[27];
int p;
+#elif LOWMEM_LISTS
+ int neighbour[27];
+ int p;
#else
t_list neighbour[27];
t_list *this;
jtom=&(moldyn->atom[neighbour[j][p]]);
p++;
+#elif LOWMEM_LISTS
+ p=neighbour[j];
+
+ while(p!=-1) {
+
+ jtom=&(itom[p]);
+ p=lc->subcell->list[p];
#else
this=&(neighbour[j]);
list_reset_f(this);
#ifdef STATIC_LISTS
}
+#elif LOWMEM_LISTS
+ }
#else
} while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
#endif
#define DEFAULT_ATOM_ATTR 0x74 // 1,2,3 body interaction + visualize
+/* special list structure for low mem approach */
+typedef struct s_lowmem_list {
+ int *head;
+ int *list;
+} t_lowmem_list;
+
/* cell lists */
typedef struct s_linkcell {
int nx,ny,nz; /* amount of cells in x, y and z direction */
double x,y,z; /* the actual cell lengthes */
#ifdef STATIC_LISTS
int **subcell; /* pointer to the cell lists */
+#elif LOWMEM_LISTS
+ t_lowmem_list *subcell; /* low mem approach list */
#else
t_list *subcell; /* pointer to the cell lists */
#endif
int link_cell_update(t_moldyn *moldyn);
#ifdef STATIC_LISTS
int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,int **cell);
+#elif LOWMEM_LISTS
+int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,int *cell);
#else
int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell);
#endif
#ifdef STATIC_LISTS
int *neighbour_i[27];
int p,q;
- t_atom *atom;
+#elif LOWMEM_LISTS
+ int neighbour_i[27];
+ int p,q;
#else
t_list neighbour_i[27];
t_list neighbour_i2[27];
count=moldyn->count;
itom=moldyn->atom;
lc=&(moldyn->lc);
-#ifdef STATIC_LISTS
- atom=moldyn->atom;
-#endif
// optimized
params=moldyn->pot_params;
dnlc=lc->dnlc;
/* copy the neighbour lists */
-#ifndef STATIC_LISTS
+#ifdef STATIC_LISTS
+#elif LOWMEM_LISTS
+#else
memcpy(neighbour_i2,neighbour_i,27*sizeof(t_list));
#endif
while(neighbour_i[j][p]!=-1) {
- jtom=&(atom[neighbour_i[j][p]]);
+ jtom=&(itom[neighbour_i[j][p]]);
p++;
+#elif LOWMEM_LISTS
+ p=neighbour_i[j];
+
+ while(p!=-1) {
+
+ jtom=&(itom[p]);
+ p=lc->subcell->list[p];
#else
this=&(neighbour_i[j]);
list_reset_f(this);
while(neighbour_i[k][q]!=-1) {
- ktom=&(atom[neighbour_i[k][q]]);
+ ktom=&(itom[neighbour_i[k][q]]);
q++;
+#elif LOWMEM_LISTS
+ q=neighbour_i[k];
+
+ while(q!=-1) {
+
+ ktom=&(itom[q]);
+ q=lc->subcell->list[q];
#else
that=&(neighbour_i2[k]);
list_reset_f(that);
#ifdef STATIC_LISTS
}
+#elif LOWMEM_LISTS
+ }
#else
} while(list_next_f(that)!=\
L_NO_NEXT_ELEMENT);
while(neighbour_i[k][q]!=-1) {
- ktom=&(atom[neighbour_i[k][q]]);
+ ktom=&(itom[neighbour_i[k][q]]);
q++;
+#elif LOWMEM_LISTS
+ q=neighbour_i[k];
+
+ while(q!=-1) {
+
+ ktom=&(itom[q]);
+ q=lc->subcell->list[q];
#else
that=&(neighbour_i2[k]);
list_reset_f(that);
#ifdef STATIC_LISTS
}
+#elif LOWMEM_LISTS
+ }
#else
} while(list_next_f(that)!=\
L_NO_NEXT_ELEMENT);
#ifdef STATIC_LISTS
}
+#elif LOWMEM_LISTS
+ }
#else
} while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
#endif