Skip to content

Commit

Permalink
Inline append_neighbor and add energy calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Ravedutti <[email protected]>
rafaelravedutti committed Jul 10, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
Czaki Grzegorz Bokota
1 parent 9aa7c33 commit 1a3c014
Showing 2 changed files with 22 additions and 14 deletions.
25 changes: 11 additions & 14 deletions core/neighborlist.impala
Original file line number Diff line number Diff line change
@@ -15,19 +15,6 @@ fn @(?half_nb) neighbor_cells(index: i32, nx: i32, ny: i32, ncells: i32, half_nb
});
}

fn @append_neighbor(grid: Grid, particle_index: i32, neighbor_index: i32) -> () {
let neighbors_sizes = get_array_i32_ref(array_dev, grid.neighbors_sizes);
let nb_list_size = neighbors_sizes(particle_index);

if nb_list_size >= grid.neighborlist_capacity {
grow_resize(nb_list_size, grid);
} else {
array_2d_set_i32(array_dev, NeighborlistLayout(), grid.neighborlists, particle_index, nb_list_size, neighbor_index);
}

neighbors_sizes(particle_index)++;
}

fn @(?half_nb) assemble_neighborlists(grid: &mut Grid, half_nb: i32, cutoff_distance: real_t) -> () {
let mut resize = 1;

@@ -49,7 +36,17 @@ fn @(?half_nb) assemble_neighborlists(grid: &mut Grid, half_nb: i32, cutoff_dist
let del = vector_sub(pos, pos_neighbor);
let rsq = vector_len2(del);
if rsq <= cutoff_distance * cutoff_distance {
@@append_neighbor(const_grid, particle_index, neighbor_particle_index);
let nb_list_size = neighbors_sizes(particle_index);

if nb_list_size >= const_grid.neighborlist_capacity {
grow_resize(nb_list_size, const_grid);
} else {
array_2d_set_i32(
array_dev, NeighborlistLayout(), const_grid.neighborlists,
particle_index, nb_list_size, neighbor_particle_index);
}

neighbors_sizes(particle_index)++;
}
}
}
11 changes: 11 additions & 0 deletions core/thermo.impala
Original file line number Diff line number Diff line change
@@ -14,3 +14,14 @@ fn temperature(grid: Grid) -> real_t {
reduce_f64_sum(t, &mut t_sum);
t_sum * t_scale
}

fn energy(eng_vdwl: real_t, half_nb: i32, grid: Grid) -> real_t {
let e_act = eng_vdwl * 0.5 * select(half_nb == 0, 1.0, 2.0);
let mut eng = 0.0;
let mut nparticles = 0;

reduce_f64_sum(e_act, &mut eng);
reduce_i32_sum(grid.nparticles, &mut nparticles);

eng / nparticles as real_t
}

0 comments on commit 1a3c014

Please sign in to comment.