Skip to content
Snippets Groups Projects
Commit 0a526dd7 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

check particle position sanity when initializing the space, this avoids problems downstream.

Former-commit-id: 5b078c03983e09461e12729551919f2cc8faa404
parent d8fbdc2d
No related branches found
No related tags found
No related merge requests found
......@@ -1158,6 +1158,21 @@ void space_init ( struct space *s , double dim[3] , struct part *parts , int N ,
s->nr_queues = 1;
s->size_parts_foreign = 0;
/* Check that all the particle positions are reasonable, wrap if periodic. */
if ( periodic ) {
for ( int k = 0 ; k < N ; k++ )
for ( int j = 0 ; j < 3 ; j++ ) {
while ( parts[k].x[j] < 0 ) parts[k].x[j] += dim[j];
while ( parts[k].x[j] >= dim[j] ) parts[k].x[j] -= dim[j];
}
}
else {
for ( int k = 0 ; k < N ; k++ )
for ( int j = 0 ; j < 3 ; j++ )
if ( parts[k].x[j] < 0 || parts[k].x[j] >= dim[j] )
error( "Not all particles are within the specified domain." );
}
/* Allocate the xtra parts array. */
if ( posix_memalign( (void *)&s->xparts , 32 , N * sizeof(struct xpart) ) != 0 )
error( "Failed to allocate xparts." );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment