20
20
! TODO: Include coul and kspace terms in subroutine update_forces.
21
21
! TODO: Discount long-range electrostatic terms of bonds, angles, and dihedrals
22
22
! TODO: Change name of exported Julia wrapper
23
- ! TODO: Add option of automatic versus manual force calculations
24
23
! TODO: Replace type(c_ptr) arguments by array arguments when possible
25
24
! TODO: Create indexing for having sequential body particles and free particles in arrays
26
25
@@ -33,9 +32,9 @@ module EmDeeCode
33
32
34
33
private
35
34
36
- character (11 ), parameter :: VERSION = " 27 Feb 2017"
35
+ character (11 ), parameter :: VERSION = " 28 Feb 2017"
37
36
38
- type, bind(C) :: tOpts
37
+ type, bind(C), public :: tOpts
39
38
logical (lb) :: Translate ! Flag to activate/deactivate translations
40
39
logical (lb) :: Rotate ! Flag to activate/deactivate rotations
41
40
integer (ib) :: RotationMode ! Algorithm used for free rotation of rigid bodies
@@ -45,7 +44,7 @@ module EmDeeCode
45
44
real (rb) :: Alpha_P ! Momentum-multiplying constant in momentum equations
46
45
end type tOpts
47
46
48
- type, bind(C) :: tEnergy
47
+ type, bind(C), public :: tEnergy
49
48
real (rb) :: Potential ! Total potential energy of the system
50
49
real (rb) :: Dispersion ! Dispersion (vdW) part of the potential energy
51
50
real (rb) :: Coulomb ! Electrostatic part of the potential energy
@@ -59,7 +58,7 @@ module EmDeeCode
59
58
logical (lb) :: UpToDate ! Flag to attest whether energies have been computed
60
59
end type tEnergy
61
60
62
- type, bind(C) :: tEmDee
61
+ type, bind(C), public :: tEmDee
63
62
integer (ib) :: Builds ! Number of neighbor list builds
64
63
real (rb) :: PairTime ! Time taken in force calculations
65
64
real (rb) :: TotalTime ! Total time since initialization
@@ -219,7 +218,9 @@ subroutine EmDee_switch_model_layer( md, layer ) bind(C,name="EmDee_switch_model
219
218
220
219
call c_f_pointer( md% data , me )
221
220
if (layer /= me% layer) then
222
- if ((layer < 1 ).or. (layer > me% nlayers)) call error( " switch_model_layer" , " out of range" )
221
+ if ((layer < 1 ).or. (layer > me% nlayers)) then
222
+ call error( " model layer switch" , " selected layer is out of range" )
223
+ end if
223
224
if (me% initialized) call update_forces( md, layer )
224
225
me% layer = layer
225
226
me% other_layer = [(i,i= 1 ,layer-1 ), (i,i= layer+1 ,me% nlayers)]
@@ -624,7 +625,7 @@ subroutine EmDee_upload( md, option, address ) bind(C,name="EmDee_upload")
624
625
me% initialized = allocated ( me% R )
625
626
if (me% initialized) call perform_initialization( me, md% DOF, md% RotDoF )
626
627
end if
627
- if (me% initialized) call update_forces
628
+ if (me% initialized) call compute_all_forces( md )
628
629
629
630
case (" coordinates" )
630
631
if (.not. allocated ( me% R )) allocate ( me% R(3 ,me% natoms) )
@@ -636,7 +637,7 @@ subroutine EmDee_upload( md, option, address ) bind(C,name="EmDee_upload")
636
637
me% initialized = me% Lbox > zero
637
638
if (me% initialized) call perform_initialization( me, md% DOF, md% RotDoF )
638
639
end if
639
- if (me% initialized) call update_forces
640
+ if (me% initialized) call compute_all_forces( md )
640
641
641
642
case (" momenta" )
642
643
if (.not. me% initialized) call error( " upload" , " box and coordinates have not been defined" )
@@ -687,11 +688,6 @@ subroutine assign_charges( thread, Qext )
687
688
me% charged(first:last) = abs (Qext(first:last)) > epsilon (one)
688
689
end subroutine assign_charges
689
690
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
690
- subroutine update_forces
691
- call compute_all_forces( md )
692
- if (me% respa_active) call compute_fast_forces( md )
693
- end subroutine update_forces
694
- !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
695
691
subroutine upload ( thread , origin , destination )
696
692
integer , intent (in ) :: thread
697
693
real (rb), intent (in ) :: origin(3 ,me% natoms)
@@ -972,6 +968,8 @@ subroutine EmDee_advance( md, dt ) bind(C,name="EmDee_advance")
972
968
973
969
allocate ( F_slow(3 ,me% natoms) )
974
970
971
+ if (me% fast_required) call compute_fast_forces( md )
972
+
975
973
! $omp parallel num_threads(me%nthreads)
976
974
block
977
975
integer :: thread, i
@@ -999,6 +997,7 @@ subroutine EmDee_advance( md, dt ) bind(C,name="EmDee_advance")
999
997
me% Lbox = CR* me% Lbox
1000
998
me% InvL = one/ me% Lbox
1001
999
me% invL2 = me% invL* me% invL
1000
+ me% Lbox3 = me% Lbox
1002
1001
end if
1003
1002
1004
1003
call compute_fast_forces( md )
@@ -1045,6 +1044,7 @@ subroutine EmDee_advance( md, dt ) bind(C,name="EmDee_advance")
1045
1044
me% Lbox = CR* me% Lbox
1046
1045
me% InvL = one/ me% Lbox
1047
1046
me% invL2 = me% invL* me% invL
1047
+ me% Lbox3 = me% Lbox
1048
1048
end if
1049
1049
1050
1050
call compute_all_forces( md )
@@ -1071,8 +1071,6 @@ subroutine EmDee_advance( md, dt ) bind(C,name="EmDee_advance")
1071
1071
md% Energy% Kinetic = sum (md% Energy% TransPart) + md% Energy% Rotational
1072
1072
end if
1073
1073
1074
- if (changeBox) me% Lbox3 = me% Lbox
1075
-
1076
1074
end subroutine EmDee_advance
1077
1075
1078
1076
! ===================================================================================================
@@ -1131,6 +1129,8 @@ subroutine compute_all_forces( md )
1131
1129
me% Energy = sum (me% threadEnergy,2 )
1132
1130
end if
1133
1131
1132
+ me% fast_required = me% respa_active
1133
+
1134
1134
md% Energy% UpToDate = compute
1135
1135
time = omp_get_wtime()
1136
1136
md% pairTime = md% pairTime + time
@@ -1170,26 +1170,6 @@ subroutine compute_fast_forces( md )
1170
1170
1171
1171
end subroutine compute_fast_forces
1172
1172
1173
- ! ===================================================================================================
1174
-
1175
- ! subroutine compute_fast_forces( me )
1176
- ! type(tData), intent(inout) :: me
1177
-
1178
- ! real(rb) :: Rs(3,me%natoms), Fs(3,me%natoms,me%nthreads)
1179
-
1180
- ! Rs = me%invL*me%R
1181
- ! !$omp parallel num_threads(me%nthreads)
1182
- ! block
1183
- ! integer :: thread
1184
- ! thread = omp_get_thread_num() + 1
1185
- ! call compute_short_range_forces( me, thread, Rs, Fs(:,:,thread) )
1186
- ! end block
1187
- ! !$omp end parallel
1188
- ! me%F = sum(Fs,3)
1189
- ! ! if (me%nbodies /= 0) call rigid_body_forces( me )
1190
-
1191
- ! end subroutine compute_fast_forces
1192
-
1193
1173
! ===================================================================================================
1194
1174
1195
1175
subroutine update_forces ( md , layer )
@@ -1227,58 +1207,4 @@ end subroutine update_forces
1227
1207
1228
1208
! ===================================================================================================
1229
1209
1230
- ! function total_virial( md ) result( virial ) bind(C,name="total_virial")
1231
- ! type(tEmDee), intent(in) :: md
1232
- ! real(rb) :: virial
1233
-
1234
- ! integer :: ib, jb, ik, jk, i, j, itype, jtype
1235
- ! real(rb) :: Fij(3), Rij(3), r2, invR2, invR, Wij, QiQj, WCij, rFc, fshift
1236
- ! type(tData), pointer :: me
1237
-
1238
- ! call c_f_pointer( md%data, me )
1239
- ! fshift = one/me%RcSq
1240
-
1241
- ! virial = zero
1242
- ! do ib = 1, me%nbodies-1
1243
- ! do jb = ib+1, me%nbodies
1244
- ! Fij = zero
1245
- ! do ik = 1, me%body(ib)%NP
1246
- ! i = me%body(ib)%index(ik)
1247
- ! itype = me%atomType(i)
1248
- ! do jk = 1, me%body(jb)%NP
1249
- ! j = me%body(jb)%index(jk)
1250
- ! Rij = me%R(:,i) - me%R(:,j)
1251
- ! Rij = Rij - me%Lbox*anint(me%invL*Rij)
1252
- ! r2 = sum(Rij*Rij)
1253
- ! if (r2 < me%RcSq) then
1254
- ! invR2 = one/r2
1255
- ! invR = sqrt(invR2)
1256
- ! jtype = me%atomType(j)
1257
- ! associate( pair => me%pair(itype,jtype,me%layer) )
1258
- ! select type ( model => pair%model )
1259
- ! include "virial_compute_pair.f90"
1260
- ! end select
1261
- ! if (pair%model%shifted_force) then
1262
- ! rFc = pair%model%fshift/invR
1263
- ! Wij = Wij - rFc
1264
- ! end if
1265
- ! if (me%charged(i).and.me%charged(j).and.pair%coulomb) then
1266
- ! QiQj = pair%kCoul*me%charge(i)*me%charge(j)
1267
- ! WCij = QiQj*(invR - fshift/invR)
1268
- ! Wij = Wij + WCij
1269
- ! end if
1270
- ! end associate
1271
- ! Fij = Fij + Wij*invR2*Rij
1272
- ! end if
1273
- ! end do
1274
- ! end do
1275
- ! Rij = me%body(ib)%rcm - me%body(jb)%rcm
1276
- ! Rij = Rij - me%Lbox*anint(me%invL*Rij)
1277
- ! Virial = Virial + sum(Fij*Rij)
1278
- ! end do
1279
- ! end do
1280
- ! end function total_virial
1281
-
1282
- ! ===================================================================================================
1283
-
1284
1210
end module EmDeeCode
0 commit comments