Added 5d array

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@7400 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
athomps 2012-01-04 17:18:46 +00:00
parent ab090456b0
commit 108bc38489
1 changed files with 66 additions and 0 deletions

View File

@ -437,6 +437,72 @@ class Memory : protected Pointers {
sfree(array);
}
/* ----------------------------------------------------------------------
create a 5d array
------------------------------------------------------------------------- */
template <typename TYPE>
TYPE *****create(TYPE *****&array, int n1, int n2, int n3, int n4,
int n5, const char *name)
{
bigint nbytes = ((bigint) sizeof(TYPE)) * n1*n2*n3*n4*n5;
TYPE *data = (TYPE *) smalloc(nbytes,name);
nbytes = ((bigint) sizeof(TYPE *)) * n1*n2*n3*n4;
TYPE **level4 = (TYPE **) smalloc(nbytes,name);
nbytes = ((bigint) sizeof(TYPE **)) * n1*n2*n3;
TYPE ***level3 = (TYPE ***) smalloc(nbytes,name);
nbytes = ((bigint) sizeof(TYPE ***)) * n1*n2;
TYPE ****level2 = (TYPE ****) smalloc(nbytes,name);
nbytes = ((bigint) sizeof(TYPE ****)) * n1;
array = (TYPE *****) smalloc(nbytes,name);
int i,j,k,l;
bigint m1,m2,m3,m4,m5;
bigint n = 0;
for (i = 0; i < n1; i++) {
m2 = ((bigint) i) * n2;
array[i] = &level2[m2];
for (j = 0; j < n2; j++) {
m1 = ((bigint) i) * n2 + j;
m2 = ((bigint) i) * n2*n3 + ((bigint) j) * n3;
level2[m1] = &level3[m2];
for (k = 0; k < n3; k++) {
m1 = ((bigint) i) * n2*n3 + ((bigint) j) * n3 + k;
m2 = ((bigint) i) * n2*n3*n4 +
((bigint) j) * n3*n4 + ((bigint) k) * n4;
level3[m1] = &level4[m2];
for (l = 0; l < n4; l++) {
m1 = ((bigint) i) * n2*n3*n4 +
((bigint) j) * n3*n4 + ((bigint) k) * n4 + l;
level4[m1] = &data[n];
n += n5;
}
}
}
}
return array;
}
template <typename TYPE>
TYPE ******create(TYPE ******&array, int n1, int n2, int n3, int n4,
int n5, const char *name)
{fail(name);}
/* ----------------------------------------------------------------------
destroy a 5d array
------------------------------------------------------------------------- */
template <typename TYPE>
void destroy(TYPE *****array)
{
if (array == NULL) return;
sfree(array[0][0][0][0]);
sfree(array[0][0][0]);
sfree(array[0][0]);
sfree(array[0]);
sfree(array);
}
/* ----------------------------------------------------------------------
memory usage of arrays, including pointers
------------------------------------------------------------------------- */