Skip to content

Commit f4deed1

Browse files
committed
Improve envelope handling and add 2-body far envelope
1 parent 675f5be commit f4deed1

2 files changed

Lines changed: 40 additions & 17 deletions

File tree

src/fortran/lib/mod_distribs_container.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,10 +2773,10 @@ subroutine evolve(this, system)
27732773

27742774
this%viability_2body_default = sum( this%gdf%df_2body ) / &
27752775
real( size( this%gdf%df_2body ), real32 )
2776-
this%viability_3body_default = 1._real32 / ( sum( this%gdf%df_3body ) / &
2777-
real( size( this%gdf%df_3body ), real32 ) )
2778-
this%viability_4body_default = 1._real32 / ( sum( this%gdf%df_4body ) / &
2779-
real( size( this%gdf%df_4body ), real32 ) )
2776+
this%viability_3body_default = sum( this%gdf%df_3body ) / &
2777+
real( size( this%gdf%df_3body ), real32 )
2778+
this%viability_4body_default = sum( this%gdf%df_4body ) / &
2779+
real( size( this%gdf%df_4body ), real32 )
27802780

27812781
end subroutine evolve
27822782
!###############################################################################

src/fortran/lib/mod_evaluator.f90

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pure function evaluate_point( distribs_container, &
5555
!! Viability of the test point for 2-body interactions.
5656
real(real32) :: viability_3body, viability_4body
5757
!! Viability of the test point for 3- and 4-body interactions.
58-
real(real32) :: bondlength, rtmp1, min_distance
58+
real(real32) :: bondlength, rtmp1, min_distance, min_from_max_cutoff
5959
!! Temporary variables.
6060
logical :: has_4body
6161
!! Boolean whether the system has 4-body interactions.
@@ -77,6 +77,7 @@ pure function evaluate_point( distribs_container, &
7777
output = 0._real32
7878
viability_2body = 0._real32
7979
min_distance = distribs_container%cutoff_max(1)
80+
min_from_max_cutoff = 0._real32
8081

8182

8283
!---------------------------------------------------------------------------
@@ -170,6 +171,11 @@ pure function evaluate_point( distribs_container, &
170171
if(bondlength - tolerances(1) .lt. min_distance)then
171172
min_distance = bondlength - tolerances(1)
172173
end if
174+
if(distribs_container%cutoff_max(1) - bondlength .gt. &
175+
min_from_max_cutoff)then
176+
min_from_max_cutoff = distribs_container%cutoff_max(1) - &
177+
bondlength
178+
end if
173179
viability_2body = viability_2body + &
174180
evaluate_2body_contributions( &
175181
distribs_container, bondlength, pair_index(species,is) &
@@ -221,6 +227,11 @@ pure function evaluate_point( distribs_container, &
221227
if(bondlength - tolerances(1) .lt. min_distance)then
222228
min_distance = bondlength - tolerances(1)
223229
end if
230+
if(distribs_container%cutoff_max(1) - bondlength .gt. &
231+
min_from_max_cutoff)then
232+
min_from_max_cutoff = distribs_container%cutoff_max(1) - &
233+
bondlength
234+
end if
224235
viability_2body = viability_2body + &
225236
evaluate_2body_contributions( &
226237
distribs_container, bondlength, pair_index(species,is) &
@@ -248,17 +259,25 @@ pure function evaluate_point( distribs_container, &
248259
!---------------------------------------------------------------------------
249260
! Normalise the bond length viability
250261
!---------------------------------------------------------------------------
251-
if(min_distance .lt. 0.25_real32 )then
252-
viability_2body = viability_2body * 0.5_real32 * &
253-
( 1._real32 - cos( pi * min_distance / 0.25_real32 ) )
254-
end if
255262
if(num_2body.eq.0)then
256263
! This does not matter as, if there are no 2-body bonds, the point is
257264
! not meant to be included in the viability set.
258265
! The evaluator cannot comment on the viability of the point.
259266
viability_2body = distribs_container%viability_2body_default
260267
else
261268
viability_2body = viability_2body / real( num_2body, real32 )
269+
if(min_distance .lt. 0.25_real32 )then
270+
viability_2body = viability_2body * 0.5_real32 * &
271+
( 1._real32 - cos( pi * min_distance / 0.25_real32 ) )
272+
end if
273+
if( min_from_max_cutoff .lt. 0.5_real32 )then
274+
rtmp1 = 0.5_real32 * ( 1._real32 - &
275+
cos( pi * min_from_max_cutoff / 0.5_real32 ) )
276+
viability_2body = &
277+
distribs_container%viability_2body_default * &
278+
abs( 1._real32 - rtmp1 ) + &
279+
rtmp1 * viability_2body
280+
end if
262281
end if
263282

264283

@@ -303,9 +322,9 @@ pure function evaluate_point( distribs_container, &
303322
! check improperdihedral angle between test point and all
304323
! other atoms
305324
!------------------------------------------------------------
306-
rtmp1 = max( &
307-
0._real32, &
308-
evaluate_4body_contributions( distribs_container, &
325+
rtmp1 = max( &
326+
0._real32, &
327+
evaluate_4body_contributions( distribs_container, &
309328
position_1, &
310329
position_2, &
311330
[ neighbour_basis%spec(js)%atom(ja,1:4) ], &
@@ -327,11 +346,15 @@ pure function evaluate_point( distribs_container, &
327346
viability_3body = viability_3body ** ( &
328347
1._real32 / real(num_3body,real32) &
329348
)
349+
else
350+
viability_3body = distribs_container%viability_3body_default
330351
end if
331352
if(num_4body.gt.0)then
332353
viability_4body = viability_4body ** ( &
333354
1._real32 / real(num_4body,real32) &
334355
)
356+
else
357+
viability_4body = distribs_container%viability_4body_default
335358
end if
336359

337360

@@ -412,7 +435,7 @@ pure function evaluate_3body_contributions( distribs_container, &
412435
num_3body_local = sum(basis%spec(current_idx(1):)%num) - current_idx(2)
413436
output = 1._real32
414437
power = 1._real32 / real( num_3body_local, real32 )
415-
weight_2 = sqrt( position_2(4) )
438+
weight_2 = sqrt( position_2(4) )
416439
species_loop: do js = current_idx(1), basis%nspec, 1
417440
start_idx = merge(current_idx(2) + 1, 1, js .eq. current_idx(1))
418441
atom_loop: do ja = start_idx, basis%spec(js)%num
@@ -425,9 +448,9 @@ pure function evaluate_3body_contributions( distribs_container, &
425448
)
426449
rtmp1 = weight_2 * sqrt( basis%spec(js)%atom(ja,4) )
427450
output = output * ( &
451+
distribs_container%viability_3body_default * &
428452
abs( 1._real32 - rtmp1 ) + &
429-
rtmp1 * distribs_container%gdf%df_3body( bin, element_idx ) * &
430-
distribs_container%viability_3body_default &
453+
rtmp1 * distribs_container%gdf%df_3body( bin, element_idx ) &
431454
) ** power
432455
end do atom_loop
433456
end do species_loop
@@ -485,9 +508,9 @@ pure function evaluate_4body_contributions( distribs_container, &
485508
)
486509
rtmp1 = weight_2_3 * ( basis%image_spec(ks)%atom(ka,4) ) ** third
487510
output = output * ( &
511+
distribs_container%viability_4body_default * &
488512
abs( 1._real32 - rtmp1 ) + &
489-
rtmp1 * distribs_container%gdf%df_4body( bin, element_idx ) * &
490-
distribs_container%viability_4body_default &
513+
rtmp1 * distribs_container%gdf%df_4body( bin, element_idx ) &
491514
) ** power
492515
end do atom_loop
493516
end do species_loop

0 commit comments

Comments
 (0)