-
Notifications
You must be signed in to change notification settings - Fork 1
/
constraint.F
886 lines (834 loc) · 42.9 KB
/
constraint.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \par History
!> Teodoro Laino [tlaino] 2007 - Extension to Intermolecular constraints
! **************************************************************************************************
MODULE constraint
USE atomic_kind_types, ONLY: atomic_kind_type,&
get_atomic_kind
USE cell_types, ONLY: cell_type
USE colvar_types, ONLY: colvar_counters
USE constraint_3x3, ONLY: rattle_3x3_ext,&
rattle_3x3_int,&
rattle_roll_3x3_ext,&
rattle_roll_3x3_int,&
shake_3x3_ext,&
shake_3x3_int,&
shake_roll_3x3_ext,&
shake_roll_3x3_int
USE constraint_4x6, ONLY: rattle_4x6_ext,&
rattle_4x6_int,&
rattle_roll_4x6_ext,&
rattle_roll_4x6_int,&
shake_4x6_ext,&
shake_4x6_int,&
shake_roll_4x6_ext,&
shake_roll_4x6_int
USE constraint_clv, ONLY: &
rattle_colv_ext, rattle_colv_int, rattle_roll_colv_ext, rattle_roll_colv_int, &
shake_colv_ext, shake_colv_int, shake_roll_colv_ext, shake_roll_colv_int, &
shake_update_colv_ext, shake_update_colv_int
USE constraint_util, ONLY: check_tol,&
get_roll_matrix,&
restore_temporary_set,&
update_temporary_set
USE constraint_vsite, ONLY: shake_vsite_ext,&
shake_vsite_int
USE cp_log_handling, ONLY: cp_to_string
USE distribution_1d_types, ONLY: distribution_1d_type
USE input_constants, ONLY: npt_f_ensemble,&
npt_i_ensemble,&
npt_ia_ensemble
USE input_section_types, ONLY: section_vals_get_subs_vals,&
section_vals_type
USE kinds, ONLY: default_string_length,&
dp
USE memory_utilities, ONLY: reallocate
USE message_passing, ONLY: mp_comm_type,&
mp_para_env_type
USE molecule_kind_types, ONLY: get_molecule_kind,&
get_molecule_kind_set,&
molecule_kind_type
USE molecule_types, ONLY: global_constraint_type,&
molecule_type
USE particle_types, ONLY: particle_type
USE simpar_types, ONLY: simpar_type
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
PUBLIC :: shake_control, &
rattle_control, &
shake_roll_control, &
rattle_roll_control, &
shake_update_targets
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'constraint'
INTEGER, PARAMETER, PRIVATE :: Max_Shake_Iter = 1000
CONTAINS
! **************************************************************************************************
!> \brief ...
!> \param gci ...
!> \param local_molecules ...
!> \param molecule_set ...
!> \param molecule_kind_set ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param dt ...
!> \param shake_tol ...
!> \param log_unit ...
!> \param lagrange_mult ...
!> \param dump_lm ...
!> \param cell ...
!> \param group ...
!> \param local_particles ...
!> \par History
!> Teodoro Laino [tlaino] 2007 - Extension to Intermolecular constraints
! **************************************************************************************************
SUBROUTINE shake_control(gci, local_molecules, molecule_set, molecule_kind_set, &
particle_set, pos, vel, dt, shake_tol, log_unit, lagrange_mult, dump_lm, &
cell, group, local_particles)
TYPE(global_constraint_type), POINTER :: gci
TYPE(distribution_1d_type), POINTER :: local_molecules
TYPE(molecule_type), POINTER :: molecule_set(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
REAL(kind=dp), INTENT(in) :: dt, shake_tol
INTEGER, INTENT(in) :: log_unit, lagrange_mult
LOGICAL, INTENT(IN) :: dump_lm
TYPE(cell_type), POINTER :: cell
CLASS(mp_comm_type), INTENT(in) :: group
TYPE(distribution_1d_type), POINTER :: local_particles
CHARACTER(LEN=*), PARAMETER :: routineN = 'shake_control'
INTEGER :: handle, i, ikind, imol, ishake_ext, &
ishake_int, k, n3x3con, n4x6con, &
nconstraint, nkind, nmol_per_kind, &
nvsitecon
LOGICAL :: do_ext_constraint
REAL(KIND=dp) :: int_max_sigma, mass, max_sigma
REAL(KIND=dp), DIMENSION(SIZE(pos, 2)) :: imass
TYPE(atomic_kind_type), POINTER :: atomic_kind
TYPE(colvar_counters) :: ncolv
TYPE(molecule_kind_type), POINTER :: molecule_kind
TYPE(molecule_type), POINTER :: molecule
CALL timeset(routineN, handle)
nkind = SIZE(molecule_kind_set)
DO k = 1, SIZE(pos, 2)
atomic_kind => particle_set(k)%atomic_kind
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
imass(k) = 1.0_dp/MAX(mass, EPSILON(0.0_dp))
END DO
do_ext_constraint = (gci%ntot /= 0)
ishake_ext = 0
max_sigma = -1.0E+10_dp
Shake_Inter_Loop: DO WHILE ((ABS(max_sigma) >= shake_tol) .AND. (ishake_ext <= Max_Shake_Iter))
max_sigma = 0.0_dp
ishake_ext = ishake_ext + 1
! Intramolecular Constraints
MOL: DO ikind = 1, nkind
nmol_per_kind = local_molecules%n_el(ikind)
DO imol = 1, nmol_per_kind
i = local_molecules%list(ikind)%array(imol)
molecule => molecule_set(i)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ncolv=ncolv, &
ng3x3=n3x3con, ng4x6=n4x6con, &
nconstraint=nconstraint, nvsite=nvsitecon)
IF (nconstraint == 0) CYCLE
ishake_int = 0
int_max_sigma = -1.0E+10_dp
Shake_Intra_Loop: DO WHILE ((ABS(int_max_sigma) >= shake_tol) .AND. (ishake_int <= Max_Shake_Iter))
int_max_sigma = 0.0_dp
ishake_int = ishake_int + 1
! 3x3
IF (n3x3con /= 0) &
CALL shake_3x3_int(molecule, particle_set, pos, vel, dt, ishake_int, &
int_max_sigma)
! 4x6
IF (n4x6con /= 0) &
CALL shake_4x6_int(molecule, particle_set, pos, vel, dt, ishake_int, &
int_max_sigma)
! Collective Variables
IF (ncolv%ntot /= 0) &
CALL shake_colv_int(molecule, particle_set, pos, vel, dt, ishake_int, &
cell, imass, int_max_sigma)
END DO Shake_Intra_Loop
max_sigma = MAX(max_sigma, int_max_sigma)
CALL shake_int_info(log_unit, i, ishake_int, max_sigma)
! Virtual Site
IF (nvsitecon /= 0) &
CALL shake_vsite_int(molecule, pos)
END DO
END DO MOL
! Intermolecular constraints
IF (do_ext_constraint) THEN
CALL update_temporary_set(group, pos=pos, vel=vel)
! 3x3
IF (gci%ng3x3 /= 0) &
CALL shake_3x3_ext(gci, particle_set, pos, vel, dt, ishake_ext, &
max_sigma)
! 4x6
IF (gci%ng4x6 /= 0) &
CALL shake_4x6_ext(gci, particle_set, pos, vel, dt, ishake_ext, &
max_sigma)
! Collective Variables
IF (gci%ncolv%ntot /= 0) &
CALL shake_colv_ext(gci, particle_set, pos, vel, dt, ishake_ext, &
cell, imass, max_sigma)
! Virtual Site
IF (gci%nvsite /= 0) &
CALL shake_vsite_ext(gci, pos)
CALL restore_temporary_set(particle_set, local_particles, pos=pos, vel=vel)
END IF
CALL shake_ext_info(log_unit, ishake_ext, max_sigma)
END DO Shake_Inter_Loop
CALL dump_lagrange_mult(dump_lm, lagrange_mult, local_molecules, molecule_set, gci, &
molecule_kind_set, group, "S")
CALL timestop(handle)
END SUBROUTINE shake_control
! **************************************************************************************************
!> \brief ...
!> \param gci ...
!> \param local_molecules ...
!> \param molecule_set ...
!> \param molecule_kind_set ...
!> \param particle_set ...
!> \param vel ...
!> \param dt ...
!> \param rattle_tol ...
!> \param log_unit ...
!> \param lagrange_mult ...
!> \param dump_lm ...
!> \param cell ...
!> \param group ...
!> \param local_particles ...
!> \par History
!> Teodoro Laino [tlaino] 2007 - Extension to Intermolecular constraints
! **************************************************************************************************
SUBROUTINE rattle_control(gci, local_molecules, molecule_set, molecule_kind_set, &
particle_set, vel, dt, rattle_tol, log_unit, lagrange_mult, dump_lm, cell, group, &
local_particles)
TYPE(global_constraint_type), POINTER :: gci
TYPE(distribution_1d_type), POINTER :: local_molecules
TYPE(molecule_type), POINTER :: molecule_set(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: vel(:, :)
REAL(kind=dp), INTENT(in) :: dt, rattle_tol
INTEGER, INTENT(in) :: log_unit, lagrange_mult
LOGICAL, INTENT(IN) :: dump_lm
TYPE(cell_type), POINTER :: cell
CLASS(mp_comm_type), INTENT(in) :: group
TYPE(distribution_1d_type), POINTER :: local_particles
CHARACTER(LEN=*), PARAMETER :: routineN = 'rattle_control'
INTEGER :: handle, i, ikind, imol, irattle_ext, &
irattle_int, k, n3x3con, n4x6con, &
nconstraint, nkind, nmol_per_kind
LOGICAL :: do_ext_constraint
REAL(KIND=dp) :: int_max_sigma, mass, max_sigma
REAL(KIND=dp), DIMENSION(SIZE(vel, 2)) :: imass
TYPE(atomic_kind_type), POINTER :: atomic_kind
TYPE(colvar_counters) :: ncolv
TYPE(molecule_kind_type), POINTER :: molecule_kind
TYPE(molecule_type), POINTER :: molecule
CALL timeset(routineN, handle)
nkind = SIZE(molecule_kind_set)
DO k = 1, SIZE(vel, 2)
atomic_kind => particle_set(k)%atomic_kind
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
imass(k) = 1.0_dp/MAX(mass, EPSILON(0.0_dp))
END DO
do_ext_constraint = (gci%ntot /= 0)
irattle_ext = 0
max_sigma = -1.0E+10_dp
Rattle_Inter_Loop: DO WHILE (ABS(max_sigma) >= rattle_tol)
max_sigma = 0.0_dp
irattle_ext = irattle_ext + 1
! Intramolecular Constraints
MOL: DO ikind = 1, nkind
nmol_per_kind = local_molecules%n_el(ikind)
DO imol = 1, nmol_per_kind
i = local_molecules%list(ikind)%array(imol)
molecule => molecule_set(i)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ncolv=ncolv, ng3x3=n3x3con, &
ng4x6=n4x6con, nconstraint=nconstraint)
IF (nconstraint == 0) CYCLE
irattle_int = 0
int_max_sigma = -1.0E+10_dp
Rattle_Intra_Loop: DO WHILE (ABS(int_max_sigma) >= rattle_tol)
int_max_sigma = 0.0_dp
irattle_int = irattle_int + 1
! 3x3
IF (n3x3con /= 0) &
CALL rattle_3x3_int(molecule, particle_set, vel, dt)
! 4x6
IF (n4x6con /= 0) &
CALL rattle_4x6_int(molecule, particle_set, vel, dt)
! Collective Variables
IF (ncolv%ntot /= 0) &
CALL rattle_colv_int(molecule, particle_set, vel, dt, &
irattle_int, cell, imass, int_max_sigma)
END DO Rattle_Intra_Loop
max_sigma = MAX(max_sigma, int_max_sigma)
CALL rattle_int_info(log_unit, i, irattle_int, max_sigma)
END DO
END DO MOL
! Intermolecular Constraints
IF (do_ext_constraint) THEN
CALL update_temporary_set(group, vel=vel)
! 3x3
IF (gci%ng3x3 /= 0) &
CALL rattle_3x3_ext(gci, particle_set, vel, dt)
! 4x6
IF (gci%ng4x6 /= 0) &
CALL rattle_4x6_ext(gci, particle_set, vel, dt)
! Collective Variables
IF (gci%ncolv%ntot /= 0) &
CALL rattle_colv_ext(gci, particle_set, vel, dt, &
irattle_ext, cell, imass, max_sigma)
CALL restore_temporary_set(particle_set, local_particles, vel=vel)
END IF
CALL rattle_ext_info(log_unit, irattle_ext, max_sigma)
END DO Rattle_Inter_Loop
CALL dump_lagrange_mult(dump_lm, lagrange_mult, local_molecules, molecule_set, gci, &
molecule_kind_set, group, "R")
CALL timestop(handle)
END SUBROUTINE rattle_control
! **************************************************************************************************
!> \brief ...
!> \param gci ...
!> \param local_molecules ...
!> \param molecule_set ...
!> \param molecule_kind_set ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param dt ...
!> \param simpar ...
!> \param roll_tol ...
!> \param iroll ...
!> \param vector_r ...
!> \param vector_v ...
!> \param group ...
!> \param u ...
!> \param cell ...
!> \param local_particles ...
!> \par History
!> Teodoro Laino [tlaino] 2007 - Extension to Intermolecular constraints
! **************************************************************************************************
SUBROUTINE shake_roll_control(gci, local_molecules, molecule_set, &
molecule_kind_set, particle_set, pos, vel, dt, simpar, roll_tol, iroll, &
vector_r, vector_v, group, u, cell, local_particles)
TYPE(global_constraint_type), POINTER :: gci
TYPE(distribution_1d_type), POINTER :: local_molecules
TYPE(molecule_type), POINTER :: molecule_set(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
REAL(KIND=dp), INTENT(IN) :: dt
TYPE(simpar_type), INTENT(IN) :: simpar
REAL(KIND=dp), INTENT(OUT) :: roll_tol
INTEGER, INTENT(INOUT) :: iroll
REAL(KIND=dp), DIMENSION(:), INTENT(IN) :: vector_r, vector_v
CLASS(mp_comm_type), INTENT(IN) :: group
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN), &
OPTIONAL :: u
TYPE(cell_type), POINTER :: cell
TYPE(distribution_1d_type), POINTER :: local_particles
CHARACTER(LEN=*), PARAMETER :: routineN = 'shake_roll_control'
INTEGER :: handle, i, ikind, imol, ishake_ext, ishake_int, k, lagrange_mult, log_unit, &
n3x3con, n4x6con, nconstraint, nkind, nmol_per_kind, nvsitecon
LOGICAL :: do_ext_constraint, dump_lm
REAL(KIND=dp) :: int_max_sigma, mass, max_sigma, shake_tol
REAL(KIND=dp), DIMENSION(3, 3) :: r_shake, v_shake
REAL(KIND=dp), DIMENSION(SIZE(pos, 2)) :: imass
TYPE(atomic_kind_type), POINTER :: atomic_kind
TYPE(colvar_counters) :: ncolv
TYPE(molecule_kind_type), POINTER :: molecule_kind
TYPE(molecule_type), POINTER :: molecule
CALL timeset(routineN, handle)
nkind = SIZE(molecule_kind_set)
shake_tol = simpar%shake_tol
log_unit = simpar%info_constraint
lagrange_mult = simpar%lagrange_multipliers
dump_lm = simpar%dump_lm
! setting up for roll
IF (simpar%ensemble == npt_i_ensemble .OR. simpar%ensemble == npt_ia_ensemble) THEN
CALL get_roll_matrix('SHAKE', r_shake, v_shake, vector_r, vector_v)
ELSE IF (simpar%ensemble == npt_f_ensemble) THEN
CALL get_roll_matrix('SHAKE', r_shake, v_shake, vector_r, vector_v, u)
END IF
DO k = 1, SIZE(pos, 2)
atomic_kind => particle_set(k)%atomic_kind
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
imass(k) = 1.0_dp/MAX(mass, EPSILON(0.0_dp))
END DO
do_ext_constraint = (gci%ntot /= 0)
ishake_ext = 0
max_sigma = -1.0E+10_dp
Shake_Inter_Loop: DO WHILE (ABS(max_sigma) >= shake_tol)
max_sigma = 0.0_dp
ishake_ext = ishake_ext + 1
! Intramolecular Constraints
MOL: DO ikind = 1, nkind
nmol_per_kind = local_molecules%n_el(ikind)
DO imol = 1, nmol_per_kind
i = local_molecules%list(ikind)%array(imol)
molecule => molecule_set(i)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ncolv=ncolv, &
ng3x3=n3x3con, ng4x6=n4x6con, &
nconstraint=nconstraint, nvsite=nvsitecon)
IF (nconstraint == 0) CYCLE
ishake_int = 0
int_max_sigma = -1.0E+10_dp
Shake_Roll_Intra_Loop: DO WHILE (ABS(int_max_sigma) >= shake_tol)
int_max_sigma = 0.0_dp
ishake_int = ishake_int + 1
! 3x3
IF (n3x3con /= 0) &
CALL shake_roll_3x3_int(molecule, particle_set, pos, vel, r_shake, &
v_shake, dt, ishake_int, int_max_sigma)
! 4x6
IF (n4x6con /= 0) &
CALL shake_roll_4x6_int(molecule, particle_set, pos, vel, r_shake, &
dt, ishake_int, int_max_sigma)
! Collective Variables
IF (ncolv%ntot /= 0) &
CALL shake_roll_colv_int(molecule, particle_set, pos, vel, r_shake, &
v_shake, dt, ishake_int, cell, imass, int_max_sigma)
END DO Shake_Roll_Intra_Loop
max_sigma = MAX(max_sigma, int_max_sigma)
CALL shake_int_info(log_unit, i, ishake_int, max_sigma)
! Virtual Site
IF (nvsitecon /= 0) THEN
CPABORT("Virtual Site Constraint/Restraint not implemented for SHAKE_ROLL!")
END IF
END DO
END DO MOL
! Intermolecular constraints
IF (do_ext_constraint) THEN
CALL update_temporary_set(group, pos=pos, vel=vel)
! 3x3
IF (gci%ng3x3 /= 0) &
CALL shake_roll_3x3_ext(gci, particle_set, pos, vel, r_shake, &
v_shake, dt, ishake_ext, max_sigma)
! 4x6
IF (gci%ng4x6 /= 0) &
CALL shake_roll_4x6_ext(gci, particle_set, pos, vel, r_shake, &
dt, ishake_ext, max_sigma)
! Collective Variables
IF (gci%ncolv%ntot /= 0) &
CALL shake_roll_colv_ext(gci, particle_set, pos, vel, r_shake, &
v_shake, dt, ishake_ext, cell, imass, max_sigma)
! Virtual Site
IF (gci%nvsite /= 0) &
CPABORT("Virtual Site Constraint/Restraint not implemented for SHAKE_ROLL!")
CALL restore_temporary_set(particle_set, local_particles, pos=pos, vel=vel)
END IF
CALL shake_ext_info(log_unit, ishake_ext, max_sigma)
END DO Shake_Inter_Loop
CALL dump_lagrange_mult(dump_lm, lagrange_mult, local_molecules, molecule_set, gci, &
molecule_kind_set, group, "S")
CALL check_tol(roll_tol, iroll, 'SHAKE', r_shake)
CALL timestop(handle)
END SUBROUTINE shake_roll_control
! **************************************************************************************************
!> \brief ...
!> \param gci ...
!> \param local_molecules ...
!> \param molecule_set ...
!> \param molecule_kind_set ...
!> \param particle_set ...
!> \param vel ...
!> \param dt ...
!> \param simpar ...
!> \param vector ...
!> \param veps ...
!> \param roll_tol ...
!> \param iroll ...
!> \param para_env ...
!> \param u ...
!> \param cell ...
!> \param local_particles ...
!> \par History
!> Teodoro Laino [tlaino] 2007 - Extension to Intermolecular constraints
! **************************************************************************************************
SUBROUTINE rattle_roll_control(gci, local_molecules, molecule_set, &
molecule_kind_set, particle_set, vel, dt, simpar, vector, &
veps, roll_tol, iroll, para_env, u, cell, local_particles)
TYPE(global_constraint_type), POINTER :: gci
TYPE(distribution_1d_type), POINTER :: local_molecules
TYPE(molecule_type), POINTER :: molecule_set(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: vel(:, :)
REAL(KIND=dp), INTENT(IN) :: dt
TYPE(simpar_type), INTENT(IN) :: simpar
REAL(KIND=dp), DIMENSION(:), INTENT(IN) :: vector
REAL(KIND=dp), DIMENSION(:, :), INTENT(INOUT) :: veps
REAL(KIND=dp), INTENT(OUT) :: roll_tol
INTEGER, INTENT(INOUT) :: iroll
TYPE(mp_para_env_type), INTENT(IN) :: para_env
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN), &
OPTIONAL :: u
TYPE(cell_type), POINTER :: cell
TYPE(distribution_1d_type), POINTER :: local_particles
CHARACTER(LEN=*), PARAMETER :: routineN = 'rattle_roll_control'
INTEGER :: handle, i, ikind, imol, irattle_ext, irattle_int, k, lagrange_mult, log_unit, &
n3x3con, n4x6con, nconstraint, nkind, nmol_per_kind
LOGICAL :: do_ext_constraint, dump_lm
REAL(KIND=dp) :: int_max_sigma, mass, max_sigma, &
rattle_tol
REAL(KIND=dp), DIMENSION(3, 3) :: r_rattle
REAL(KIND=dp), DIMENSION(SIZE(vel, 2)) :: imass
TYPE(atomic_kind_type), POINTER :: atomic_kind
TYPE(colvar_counters) :: ncolv
TYPE(molecule_kind_type), POINTER :: molecule_kind
TYPE(molecule_type), POINTER :: molecule
CALL timeset(routineN, handle)
! initialize locals
nkind = SIZE(molecule_kind_set)
rattle_tol = simpar%shake_tol
log_unit = simpar%info_constraint
lagrange_mult = simpar%lagrange_multipliers
dump_lm = simpar%dump_lm
! setting up for roll
IF (simpar%ensemble == npt_i_ensemble .OR. simpar%ensemble == npt_ia_ensemble) THEN
CALL get_roll_matrix('RATTLE', v_shake=r_rattle, vector_v=vector)
ELSE IF (simpar%ensemble == npt_f_ensemble) THEN
CALL get_roll_matrix('RATTLE', v_shake=r_rattle, vector_v=vector, u=u)
END IF
DO k = 1, SIZE(vel, 2)
atomic_kind => particle_set(k)%atomic_kind
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
imass(k) = 1.0_dp/MAX(mass, EPSILON(0.0_dp))
END DO
do_ext_constraint = (gci%ntot /= 0)
irattle_ext = 0
max_sigma = -1.0E+10_dp
Rattle_Inter_Loop: DO WHILE (ABS(max_sigma) >= rattle_tol)
max_sigma = 0.0_dp
irattle_ext = irattle_ext + 1
! Intramolecular Constraints
MOL: DO ikind = 1, nkind
nmol_per_kind = local_molecules%n_el(ikind)
DO imol = 1, nmol_per_kind
i = local_molecules%list(ikind)%array(imol)
molecule => molecule_set(i)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ncolv=ncolv, &
ng3x3=n3x3con, ng4x6=n4x6con, &
nconstraint=nconstraint)
IF (nconstraint == 0) CYCLE
int_max_sigma = -1.0E+10_dp
irattle_int = 0
Rattle_Roll_Intramolecular: DO WHILE (ABS(int_max_sigma) >= rattle_tol)
int_max_sigma = 0.0_dp
irattle_int = irattle_int + 1
! 3x3
IF (n3x3con /= 0) &
CALL rattle_roll_3x3_int(molecule, particle_set, vel, r_rattle, dt, &
veps)
! 4x6
IF (n4x6con /= 0) &
CALL rattle_roll_4x6_int(molecule, particle_set, vel, r_rattle, dt, &
veps)
! Collective Variables
IF (ncolv%ntot /= 0) &
CALL rattle_roll_colv_int(molecule, particle_set, vel, r_rattle, dt, &
irattle_int, veps, cell, imass, int_max_sigma)
END DO Rattle_Roll_Intramolecular
max_sigma = MAX(max_sigma, int_max_sigma)
CALL rattle_int_info(log_unit, i, irattle_int, max_sigma)
END DO
END DO MOL
! Intermolecular Constraints
IF (do_ext_constraint) THEN
CALL update_temporary_set(para_env, vel=vel)
! 3x3
IF (gci%ng3x3 /= 0) &
CALL rattle_roll_3x3_ext(gci, particle_set, vel, r_rattle, dt, &
veps)
! 4x6
IF (gci%ng4x6 /= 0) &
CALL rattle_roll_4x6_ext(gci, particle_set, vel, r_rattle, dt, &
veps)
! Collective Variables
IF (gci%ncolv%ntot /= 0) &
CALL rattle_roll_colv_ext(gci, particle_set, vel, r_rattle, dt, &
irattle_ext, veps, cell, imass, max_sigma)
CALL restore_temporary_set(particle_set, local_particles, vel=vel)
END IF
CALL rattle_ext_info(log_unit, irattle_ext, max_sigma)
END DO Rattle_Inter_Loop
CALL dump_lagrange_mult(dump_lm, lagrange_mult, local_molecules, molecule_set, gci, &
molecule_kind_set, para_env, "R")
CALL check_tol(roll_tol, iroll, 'RATTLE', veps=veps)
CALL timestop(handle)
END SUBROUTINE rattle_roll_control
! **************************************************************************************************
!> \brief ...
!> \param dump_lm ...
!> \param log_unit ...
!> \param local_molecules ...
!> \param molecule_set ...
!> \param gci ...
!> \param molecule_kind_set ...
!> \param group ...
!> \param id_type ...
!> \par History
!> Teodoro Laino [tlaino] 2007 - Dumps lagrange multipliers
! **************************************************************************************************
SUBROUTINE dump_lagrange_mult(dump_lm, log_unit, local_molecules, molecule_set, gci, &
molecule_kind_set, group, id_type)
LOGICAL, INTENT(IN) :: dump_lm
INTEGER, INTENT(IN) :: log_unit
TYPE(distribution_1d_type), POINTER :: local_molecules
TYPE(molecule_type), POINTER :: molecule_set(:)
TYPE(global_constraint_type), POINTER :: gci
TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
CLASS(mp_comm_type), INTENT(IN) :: group
CHARACTER(LEN=1), INTENT(IN) :: id_type
CHARACTER(LEN=*), PARAMETER :: routineN = 'dump_lagrange_mult'
CHARACTER(LEN=default_string_length) :: label
INTEGER :: handle, i, ikind, imol, j, my_index, &
n3x3con, n4x6con, nconstraint, nkind
LOGICAL :: do_ext_constraint, do_int_constraint
REAL(KIND=dp), DIMENSION(:), POINTER :: lagr
TYPE(colvar_counters) :: ncolv
TYPE(molecule_kind_type), POINTER :: molecule_kind
TYPE(molecule_type), POINTER :: molecule
CALL timeset(routineN, handle)
! Total number of intramolecular constraints (distributed)
CALL get_molecule_kind_set(molecule_kind_set=molecule_kind_set, &
nconstraint=nconstraint)
do_int_constraint = (nconstraint > 0)
do_ext_constraint = (gci%ntot > 0)
IF (dump_lm .AND. (do_int_constraint .OR. do_ext_constraint)) THEN
nkind = SIZE(molecule_kind_set)
ALLOCATE (lagr(nconstraint))
lagr = 0.0_dp
! Dump lagrange multipliers for Intramolecular Constraints
my_index = 0
IF (do_int_constraint) THEN
MOL: DO ikind = 1, nkind
molecule_kind => molecule_kind_set(ikind)
CALL get_molecule_kind(molecule_kind, &
ncolv=ncolv, &
ng3x3=n3x3con, &
ng4x6=n4x6con)
DO imol = 1, molecule_kind%nmolecule
i = molecule_kind%molecule_list(imol)
IF (ANY(local_molecules%list(ikind)%array == i)) THEN
molecule => molecule_set(i)
! Collective Variables
DO j = 1, ncolv%ntot
lagr(my_index + 1) = molecule%lci%lcolv(j)%lambda
my_index = my_index + 1
END DO
! 3x3
DO j = 1, n3x3con
lagr(my_index + 1:my_index + 3) = molecule%lci%lg3x3(j)%lambda(:)
my_index = my_index + 3
END DO
! 4x6
DO j = 1, n4x6con
lagr(my_index + 1:my_index + 6) = molecule%lci%lg4x6(j)%lambda(:)
my_index = my_index + 6
END DO
ELSE
my_index = my_index + ncolv%ntot + 3*n3x3con + 6*n4x6con
END IF
END DO
END DO MOL
CALL group%sum(lagr)
END IF
! Intermolecular constraints
IF (do_ext_constraint) THEN
CALL reallocate(lagr, 1, SIZE(lagr) + gci%ntot)
! Collective Variables
DO j = 1, gci%ncolv%ntot
lagr(my_index + 1) = gci%lcolv(j)%lambda
my_index = my_index + 1
END DO
! 3x3
DO j = 1, gci%ng3x3
lagr(my_index + 1:my_index + 3) = gci%lg3x3(j)%lambda(:)
my_index = my_index + 3
END DO
! 4x6
DO j = 1, gci%ng4x6
lagr(my_index + 1:my_index + 6) = gci%lg4x6(j)%lambda(:)
my_index = my_index + 6
END DO
END IF
IF (log_unit > 0) THEN
IF (id_type == "S") THEN
label = "Shake Lagrangian Multipliers:"
ELSEIF (id_type == "R") THEN
label = "Rattle Lagrangian Multipliers:"
ELSE
CPABORT("")
END IF
WRITE (log_unit, FMT='(A,T40,4F15.9)') TRIM(label), lagr(1:MIN(4, SIZE(lagr)))
DO j = 5, SIZE(lagr), 4
WRITE (log_unit, FMT='(T40,4F15.9)') lagr(j:MIN(j + 3, SIZE(lagr)))
END DO
END IF
DEALLOCATE (lagr)
END IF
CALL timestop(handle)
END SUBROUTINE dump_lagrange_mult
! **************************************************************************************************
!> \brief Dumps convergence info about shake - intramolecular constraint loop
!> \param log_unit ...
!> \param i ...
!> \param ishake_int ...
!> \param max_sigma ...
!> \par History
!> Teodoro Laino [tlaino] 2007 - University of Zurich
! **************************************************************************************************
SUBROUTINE shake_int_info(log_unit, i, ishake_int, max_sigma)
INTEGER, INTENT(IN) :: log_unit, i, ishake_int
REAL(KIND=dp), INTENT(IN) :: max_sigma
IF (log_unit > 0) THEN
! Dump info if requested
WRITE (log_unit, '("SHAKE_INFO|",2X,2(A,I6),A,F15.9)') &
"Molecule Nr.:", i, " Nr. Iterations:", ishake_int, " Max. Err.:", max_sigma
END IF
! Notify a not converged SHAKE
IF (ishake_int > Max_Shake_Iter) &
CALL cp_warn(__LOCATION__, &
"Shake NOT converged in "//cp_to_string(Max_Shake_Iter)//" iterations in the "// &
"intramolecular constraint loop for Molecule nr. "//cp_to_string(i)// &
". CP2K continues but results could be meaningless. ")
END SUBROUTINE shake_int_info
! **************************************************************************************************
!> \brief Dumps convergence info about shake - intermolecular constraint loop
!> \param log_unit ...
!> \param ishake_ext ...
!> \param max_sigma ...
!> \par History
!> Teodoro Laino [tlaino] 2007 - University of Zurich
! **************************************************************************************************
SUBROUTINE shake_ext_info(log_unit, ishake_ext, max_sigma)
INTEGER, INTENT(IN) :: log_unit, ishake_ext
REAL(KIND=dp), INTENT(IN) :: max_sigma
IF (log_unit > 0) THEN
! Dump info if requested
WRITE (log_unit, '("SHAKE_INFO|",2X,A,I6,A,F15.9)') &
"External Shake Nr. Iterations:", ishake_ext, &
" Max. Err.:", max_sigma
END IF
! Notify a not converged SHAKE
IF (ishake_ext > Max_Shake_Iter) &
CALL cp_warn(__LOCATION__, &
"Shake NOT converged in "//cp_to_string(Max_Shake_Iter)//" iterations in the "// &
"intermolecular constraint. CP2K continues but results could be meaningless.")
END SUBROUTINE shake_ext_info
! **************************************************************************************************
!> \brief Dumps convergence info about rattle - intramolecular constraint loop
!> \param log_unit ...
!> \param i ...
!> \param irattle_int ...
!> \param max_sigma ...
!> \par History
!> Teodoro Laino [tlaino] 2007 - University of Zurich
! **************************************************************************************************
SUBROUTINE rattle_int_info(log_unit, i, irattle_int, max_sigma)
INTEGER, INTENT(IN) :: log_unit, i, irattle_int
REAL(KIND=dp), INTENT(IN) :: max_sigma
IF (log_unit > 0) THEN
! Dump info if requested
WRITE (log_unit, '("RATTLE_INFO|",1X,2(A,I6),A,F15.9)') &
"Molecule Nr.:", i, " Nr. Iterations:", irattle_int, " Max. Err.:", max_sigma
END IF
! Notify a not converged RATTLE
IF (irattle_int > Max_shake_Iter) &
CALL cp_warn(__LOCATION__, &
"Rattle NOT converged in "//cp_to_string(Max_Shake_Iter)//" iterations in the "// &
"intramolecular constraint loop for Molecule nr. "//cp_to_string(i)// &
". CP2K continues but results could be meaningless.")
END SUBROUTINE rattle_int_info
! **************************************************************************************************
!> \brief Dumps convergence info about rattle - intermolecular constraint loop
!> \param log_unit ...
!> \param irattle_ext ...
!> \param max_sigma ...
!> \par History
!> Teodoro Laino [tlaino] 2007 - University of Zurich
! **************************************************************************************************
SUBROUTINE rattle_ext_info(log_unit, irattle_ext, max_sigma)
INTEGER, INTENT(IN) :: log_unit, irattle_ext
REAL(KIND=dp), INTENT(IN) :: max_sigma
IF (log_unit > 0) THEN
! Dump info if requested
WRITE (log_unit, '("RATTLE_INFO|",1X,A,I6,A,F15.9)') &
"External Rattle Nr. Iterations:", irattle_ext, &
" Max. Err.:", max_sigma
END IF
! Notify a not converged RATTLE
IF (irattle_ext > Max_shake_Iter) &
CALL cp_warn(__LOCATION__, &
"Rattle NOT converged in "//cp_to_string(Max_Shake_Iter)//" iterations in the "// &
"intermolecular constraint. CP2K continues but results could be meaningless.")
END SUBROUTINE rattle_ext_info
! **************************************************************************************************
!> \brief Updates the TARGET of the COLLECTIVE constraints if the growth speed
!> is different from zero.
!> \param gci ...
!> \param local_molecules ...
!> \param molecule_set ...
!> \param molecule_kind_set ...
!> \param dt ...
!> \param root_section ...
!> \date 02.2008
!> \author Teodoro Laino [tlaino] - University of Zurich
! **************************************************************************************************
SUBROUTINE shake_update_targets(gci, local_molecules, molecule_set, &
molecule_kind_set, dt, root_section)
TYPE(global_constraint_type), POINTER :: gci
TYPE(distribution_1d_type), POINTER :: local_molecules
TYPE(molecule_type), POINTER :: molecule_set(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
REAL(kind=dp), INTENT(in) :: dt
TYPE(section_vals_type), POINTER :: root_section
CHARACTER(LEN=*), PARAMETER :: routineN = 'shake_update_targets'
INTEGER :: handle, i, ikind, imol, nkind, &
nmol_per_kind
LOGICAL :: do_ext_constraint
TYPE(colvar_counters) :: ncolv
TYPE(molecule_kind_type), POINTER :: molecule_kind
TYPE(molecule_type), POINTER :: molecule
TYPE(section_vals_type), POINTER :: motion_section
CALL timeset(routineN, handle)
motion_section => section_vals_get_subs_vals(root_section, "MOTION")
nkind = SIZE(molecule_kind_set)
do_ext_constraint = (gci%ntot /= 0)
! Intramolecular Constraints
MOL: DO ikind = 1, nkind
nmol_per_kind = local_molecules%n_el(ikind)
DO imol = 1, nmol_per_kind
i = local_molecules%list(ikind)%array(imol)
molecule => molecule_set(i)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ncolv=ncolv)
! Updating TARGETS for Collective Variables only
IF (ncolv%ntot /= 0) CALL shake_update_colv_int(molecule, dt, motion_section)
END DO
END DO MOL
! Intermolecular constraints
IF (do_ext_constraint) THEN
! Collective Variables
IF (gci%ncolv%ntot /= 0) CALL shake_update_colv_ext(gci, dt, motion_section)
END IF
CALL timestop(handle)
END SUBROUTINE shake_update_targets
END MODULE constraint