-
Notifications
You must be signed in to change notification settings - Fork 0
/
constraint_4x6.F
1201 lines (1104 loc) · 57.8 KB
/
constraint_4x6.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
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2023 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \par History
!> none
! **************************************************************************************************
MODULE constraint_4x6
USE atomic_kind_types, ONLY: atomic_kind_type,&
get_atomic_kind
USE constraint_fxd, ONLY: check_fixed_atom_cns_g4x6
USE kinds, ONLY: dp
USE linear_systems, ONLY: solve_system
USE molecule_kind_types, ONLY: fixd_constraint_type,&
g4x6_constraint_type,&
get_molecule_kind,&
molecule_kind_type
USE molecule_types, ONLY: get_molecule,&
global_constraint_type,&
local_g4x6_constraint_type,&
molecule_type
USE particle_types, ONLY: particle_type
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
PUBLIC :: shake_4x6_int, &
rattle_4x6_int, &
shake_roll_4x6_int, &
rattle_roll_4x6_int, &
shake_4x6_ext, &
rattle_4x6_ext, &
shake_roll_4x6_ext, &
rattle_roll_4x6_ext
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'constraint_4x6'
CONTAINS
! **************************************************************************************************
!> \brief Intramolecular shake_4x6
!> \param molecule ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_4x6_int(molecule, particle_set, pos, vel, dt, ishake, &
max_sigma)
TYPE(molecule_type), POINTER :: molecule
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
REAL(kind=dp), INTENT(in) :: dt
INTEGER, INTENT(IN) :: ishake
REAL(KIND=dp), INTENT(INOUT) :: max_sigma
INTEGER :: first_atom, ng4x6
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind
NULLIFY (fixd_list)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ng4x6=ng4x6, &
fixd_list=fixd_list, g4x6_list=g4x6_list)
CALL get_molecule(molecule, first_atom=first_atom, lg4x6=lg4x6)
! Real Shake
CALL shake_4x6_low(fixd_list, g4x6_list, lg4x6, ng4x6, first_atom, &
particle_set, pos, vel, dt, ishake, max_sigma)
END SUBROUTINE shake_4x6_int
! **************************************************************************************************
!> \brief Intramolecular shake_4x6_roll
!> \param molecule ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param r_shake ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_roll_4x6_int(molecule, particle_set, pos, vel, r_shake, &
dt, ishake, max_sigma)
TYPE(molecule_type), POINTER :: molecule
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: r_shake
REAL(kind=dp), INTENT(in) :: dt
INTEGER, INTENT(IN) :: ishake
REAL(KIND=dp), INTENT(INOUT) :: max_sigma
INTEGER :: first_atom, ng4x6
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind
NULLIFY (fixd_list)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ng4x6=ng4x6, &
fixd_list=fixd_list, g4x6_list=g4x6_list)
CALL get_molecule(molecule, first_atom=first_atom, lg4x6=lg4x6)
! Real Shake
CALL shake_roll_4x6_low(fixd_list, g4x6_list, lg4x6, ng4x6, first_atom, &
particle_set, pos, vel, r_shake, dt, ishake, max_sigma)
END SUBROUTINE shake_roll_4x6_int
! **************************************************************************************************
!> \brief Intramolecular rattle_4x6
!> \param molecule ...
!> \param particle_set ...
!> \param vel ...
!> \param dt ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_4x6_int(molecule, particle_set, vel, dt)
TYPE(molecule_type), POINTER :: molecule
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: vel(:, :)
REAL(kind=dp), INTENT(in) :: dt
INTEGER :: first_atom, ng4x6
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind
NULLIFY (fixd_list)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ng4x6=ng4x6, &
fixd_list=fixd_list, g4x6_list=g4x6_list)
CALL get_molecule(molecule, first_atom=first_atom, lg4x6=lg4x6)
! Real Rattle
CALL rattle_4x6_low(fixd_list, g4x6_list, lg4x6, first_atom, &
particle_set, vel, dt)
END SUBROUTINE rattle_4x6_int
! **************************************************************************************************
!> \brief Intramolecular rattle_4x6_roll
!> \param molecule ...
!> \param particle_set ...
!> \param vel ...
!> \param r_rattle ...
!> \param dt ...
!> \param veps ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_roll_4x6_int(molecule, particle_set, vel, r_rattle, dt, veps)
TYPE(molecule_type), POINTER :: molecule
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: vel(:, :)
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: r_rattle
REAL(kind=dp), INTENT(in) :: dt
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: veps
INTEGER :: first_atom, ng4x6
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind
NULLIFY (fixd_list)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ng4x6=ng4x6, &
fixd_list=fixd_list, g4x6_list=g4x6_list)
CALL get_molecule(molecule, first_atom=first_atom, lg4x6=lg4x6)
! Real Rattle
CALL rattle_roll_4x6_low(fixd_list, g4x6_list, lg4x6, first_atom, &
particle_set, vel, r_rattle, dt, veps)
END SUBROUTINE rattle_roll_4x6_int
! **************************************************************************************************
!> \brief Intramolecular shake_4x6
!> \param gci ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_4x6_ext(gci, particle_set, pos, vel, dt, ishake, &
max_sigma)
TYPE(global_constraint_type), POINTER :: gci
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
REAL(kind=dp), INTENT(in) :: dt
INTEGER, INTENT(IN) :: ishake
REAL(KIND=dp), INTENT(INOUT) :: max_sigma
INTEGER :: first_atom, ng4x6
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
first_atom = 1
ng4x6 = gci%ng4x6
fixd_list => gci%fixd_list
g4x6_list => gci%g4x6_list
lg4x6 => gci%lg4x6
! Real Shake
CALL shake_4x6_low(fixd_list, g4x6_list, lg4x6, ng4x6, first_atom, &
particle_set, pos, vel, dt, ishake, max_sigma)
END SUBROUTINE shake_4x6_ext
! **************************************************************************************************
!> \brief Intramolecular shake_4x6_roll
!> \param gci ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param r_shake ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_roll_4x6_ext(gci, particle_set, pos, vel, r_shake, &
dt, ishake, max_sigma)
TYPE(global_constraint_type), POINTER :: gci
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: r_shake
REAL(kind=dp), INTENT(in) :: dt
INTEGER, INTENT(IN) :: ishake
REAL(KIND=dp), INTENT(INOUT) :: max_sigma
INTEGER :: first_atom, ng4x6
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
first_atom = 1
ng4x6 = gci%ng4x6
fixd_list => gci%fixd_list
g4x6_list => gci%g4x6_list
lg4x6 => gci%lg4x6
! Real Shake
CALL shake_roll_4x6_low(fixd_list, g4x6_list, lg4x6, ng4x6, first_atom, &
particle_set, pos, vel, r_shake, dt, ishake, max_sigma)
END SUBROUTINE shake_roll_4x6_ext
! **************************************************************************************************
!> \brief Intramolecular rattle_4x6
!> \param gci ...
!> \param particle_set ...
!> \param vel ...
!> \param dt ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_4x6_ext(gci, particle_set, vel, dt)
TYPE(global_constraint_type), POINTER :: gci
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: vel(:, :)
REAL(kind=dp), INTENT(in) :: dt
INTEGER :: first_atom, ng4x6
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
first_atom = 1
ng4x6 = gci%ng4x6
fixd_list => gci%fixd_list
g4x6_list => gci%g4x6_list
lg4x6 => gci%lg4x6
! Real Rattle
CALL rattle_4x6_low(fixd_list, g4x6_list, lg4x6, first_atom, &
particle_set, vel, dt)
END SUBROUTINE rattle_4x6_ext
! **************************************************************************************************
!> \brief Intramolecular rattle_4x6_roll
!> \param gci ...
!> \param particle_set ...
!> \param vel ...
!> \param r_rattle ...
!> \param dt ...
!> \param veps ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_roll_4x6_ext(gci, particle_set, vel, r_rattle, dt, veps)
TYPE(global_constraint_type), POINTER :: gci
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: vel(:, :)
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: r_rattle
REAL(kind=dp), INTENT(in) :: dt
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: veps
INTEGER :: first_atom, ng4x6
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
first_atom = 1
ng4x6 = gci%ng4x6
fixd_list => gci%fixd_list
g4x6_list => gci%g4x6_list
lg4x6 => gci%lg4x6
! Real Rattle
CALL rattle_roll_4x6_low(fixd_list, g4x6_list, lg4x6, first_atom, &
particle_set, vel, r_rattle, dt, veps)
END SUBROUTINE rattle_roll_4x6_ext
! **************************************************************************************************
!> \brief ...
!> \param fixd_list ...
!> \param g4x6_list ...
!> \param lg4x6 ...
!> \param ng4x6 ...
!> \param first_atom ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_4x6_low(fixd_list, g4x6_list, lg4x6, ng4x6, first_atom, &
particle_set, pos, vel, dt, ishake, max_sigma)
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
INTEGER, INTENT(IN) :: ng4x6, first_atom
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
REAL(kind=dp), INTENT(in) :: dt
INTEGER, INTENT(IN) :: ishake
REAL(KIND=dp), INTENT(INOUT) :: max_sigma
INTEGER :: iconst, index_a, index_b, index_c, &
index_d
REAL(KIND=dp) :: dtby2, dtsqby2, idtsq, imass1, imass2, &
imass3, imass4, sigma
REAL(KIND=dp), DIMENSION(3) :: fc1, fc2, fc3, fc4, r0_12, r0_13, r0_14, &
r0_23, r0_24, r0_34, r1, r12, r13, &
r14, r2, r23, r24, r3, r34, r4, v1, &
v2, v3, v4, vec
REAL(KIND=dp), DIMENSION(6, 1) :: bvec
REAL(KIND=dp), DIMENSION(6, 6) :: amat, atemp
TYPE(atomic_kind_type), POINTER :: atomic_kind
dtsqby2 = dt*dt*.5_dp
idtsq = 1.0_dp/dt/dt
dtby2 = dt*.5_dp
DO iconst = 1, ng4x6
IF (g4x6_list(iconst)%restraint%active) CYCLE
index_a = g4x6_list(iconst)%a + first_atom - 1
index_b = g4x6_list(iconst)%b + first_atom - 1
index_c = g4x6_list(iconst)%c + first_atom - 1
index_d = g4x6_list(iconst)%d + first_atom - 1
IF (ishake == 1) THEN
r0_12(:) = pos(:, index_a) - pos(:, index_b)
r0_13(:) = pos(:, index_a) - pos(:, index_c)
r0_14(:) = pos(:, index_a) - pos(:, index_d)
r0_23(:) = pos(:, index_b) - pos(:, index_c)
r0_24(:) = pos(:, index_b) - pos(:, index_d)
r0_34(:) = pos(:, index_c) - pos(:, index_d)
atomic_kind => particle_set(index_a)%atomic_kind
imass1 = 1.0_dp/atomic_kind%mass
atomic_kind => particle_set(index_b)%atomic_kind
imass2 = 1.0_dp/atomic_kind%mass
atomic_kind => particle_set(index_c)%atomic_kind
imass3 = 1.0_dp/atomic_kind%mass
atomic_kind => particle_set(index_d)%atomic_kind
imass4 = 1.0_dp/atomic_kind%mass
lg4x6(iconst)%fa = -2.0_dp*(lg4x6(iconst)%ra_old - &
lg4x6(iconst)%rb_old)
lg4x6(iconst)%fb = -2.0_dp*(lg4x6(iconst)%ra_old - &
lg4x6(iconst)%rc_old)
lg4x6(iconst)%fc = -2.0_dp*(lg4x6(iconst)%ra_old - &
lg4x6(iconst)%rd_old)
lg4x6(iconst)%fd = -2.0_dp*(lg4x6(iconst)%rb_old - &
lg4x6(iconst)%rc_old)
lg4x6(iconst)%fe = -2.0_dp*(lg4x6(iconst)%rb_old - &
lg4x6(iconst)%rd_old)
lg4x6(iconst)%ff = -2.0_dp*(lg4x6(iconst)%rc_old - &
lg4x6(iconst)%rd_old)
! Check for fixed atom constraints
CALL check_fixed_atom_cns_g4x6(imass1, imass2, imass3, imass4, &
index_a, index_b, index_c, index_d, fixd_list, lg4x6(iconst))
! construct matrix
amat(1, 1) = (imass1 + imass2)*DOT_PRODUCT(r0_12, lg4x6(iconst)%fa)
amat(1, 2) = imass1*DOT_PRODUCT(r0_12, lg4x6(iconst)%fb)
amat(1, 3) = imass1*DOT_PRODUCT(r0_12, lg4x6(iconst)%fc)
amat(1, 4) = -imass2*DOT_PRODUCT(r0_12, lg4x6(iconst)%fd)
amat(1, 5) = -imass2*DOT_PRODUCT(r0_12, lg4x6(iconst)%fe)
amat(1, 6) = 0.0_dp
amat(2, 1) = imass1*DOT_PRODUCT(r0_13, lg4x6(iconst)%fa)
amat(2, 2) = (imass1 + imass3)*DOT_PRODUCT(r0_13, lg4x6(iconst)%fb)
amat(2, 3) = imass1*DOT_PRODUCT(r0_13, lg4x6(iconst)%fc)
amat(2, 4) = imass3*DOT_PRODUCT(r0_13, lg4x6(iconst)%fd)
amat(2, 5) = 0.0_dp
amat(2, 6) = -imass3*DOT_PRODUCT(r0_13, lg4x6(iconst)%ff)
amat(3, 1) = imass1*DOT_PRODUCT(r0_14, lg4x6(iconst)%fa)
amat(3, 2) = imass1*DOT_PRODUCT(r0_14, lg4x6(iconst)%fb)
amat(3, 3) = (imass1 + imass4)*DOT_PRODUCT(r0_14, lg4x6(iconst)%fc)
amat(3, 4) = 0.0_dp
amat(3, 5) = imass4*DOT_PRODUCT(r0_14, lg4x6(iconst)%fe)
amat(3, 6) = imass4*DOT_PRODUCT(r0_14, lg4x6(iconst)%ff)
amat(4, 1) = -imass2*DOT_PRODUCT(r0_23, lg4x6(iconst)%fa)
amat(4, 2) = imass3*DOT_PRODUCT(r0_23, lg4x6(iconst)%fb)
amat(4, 3) = 0.0_dp
amat(4, 4) = (imass3 + imass2)*DOT_PRODUCT(r0_23, lg4x6(iconst)%fd)
amat(4, 5) = imass2*DOT_PRODUCT(r0_23, lg4x6(iconst)%fe)
amat(4, 6) = -imass3*DOT_PRODUCT(r0_23, lg4x6(iconst)%ff)
amat(5, 1) = -imass2*DOT_PRODUCT(r0_24, lg4x6(iconst)%fa)
amat(5, 2) = 0.0_dp
amat(5, 3) = imass4*DOT_PRODUCT(r0_24, lg4x6(iconst)%fc)
amat(5, 4) = imass2*DOT_PRODUCT(r0_24, lg4x6(iconst)%fd)
amat(5, 5) = (imass4 + imass2)*DOT_PRODUCT(r0_24, lg4x6(iconst)%fe)
amat(5, 6) = imass4*DOT_PRODUCT(r0_24, lg4x6(iconst)%ff)
amat(6, 1) = 0.0_dp
amat(6, 2) = -imass3*DOT_PRODUCT(r0_34, lg4x6(iconst)%fb)
amat(6, 3) = imass4*DOT_PRODUCT(r0_34, lg4x6(iconst)%fc)
amat(6, 4) = -imass3*DOT_PRODUCT(r0_34, lg4x6(iconst)%fd)
amat(6, 5) = imass4*DOT_PRODUCT(r0_34, lg4x6(iconst)%fe)
amat(6, 6) = (imass3 + imass4)*DOT_PRODUCT(r0_34, lg4x6(iconst)%ff)
! Store values
lg4x6(iconst)%r0_12 = r0_12
lg4x6(iconst)%r0_13 = r0_13
lg4x6(iconst)%r0_14 = r0_14
lg4x6(iconst)%r0_23 = r0_23
lg4x6(iconst)%r0_24 = r0_24
lg4x6(iconst)%r0_34 = r0_34
lg4x6(iconst)%amat = amat
lg4x6(iconst)%imass1 = imass1
lg4x6(iconst)%imass2 = imass2
lg4x6(iconst)%imass3 = imass3
lg4x6(iconst)%imass4 = imass4
lg4x6(iconst)%lambda_old = 0.0_dp
lg4x6(iconst)%del_lambda = 0.0_dp
ELSE
! Retrieve values
r0_12 = lg4x6(iconst)%r0_12
r0_13 = lg4x6(iconst)%r0_13
r0_14 = lg4x6(iconst)%r0_14
r0_23 = lg4x6(iconst)%r0_23
r0_24 = lg4x6(iconst)%r0_24
r0_34 = lg4x6(iconst)%r0_34
amat = lg4x6(iconst)%amat
imass1 = lg4x6(iconst)%imass1
imass2 = lg4x6(iconst)%imass2
imass3 = lg4x6(iconst)%imass3
imass4 = lg4x6(iconst)%imass4
END IF
! Iterate until convergence:
vec = lg4x6(iconst)%lambda(1)*lg4x6(iconst)%fa*(imass1 + imass2) + &
lg4x6(iconst)%lambda(2)*imass1*lg4x6(iconst)%fb + &
lg4x6(iconst)%lambda(3)*imass1*lg4x6(iconst)%fc - &
lg4x6(iconst)%lambda(4)*imass2*lg4x6(iconst)%fd - &
lg4x6(iconst)%lambda(5)*imass2*lg4x6(iconst)%fe
bvec(1, 1) = g4x6_list(iconst)%dab*g4x6_list(iconst)%dab &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_12, r0_12)
vec = lg4x6(iconst)%lambda(2)*lg4x6(iconst)%fb*(imass1 + imass3) + &
lg4x6(iconst)%lambda(1)*imass1*lg4x6(iconst)%fa + &
lg4x6(iconst)%lambda(3)*imass1*lg4x6(iconst)%fc + &
lg4x6(iconst)%lambda(4)*imass3*lg4x6(iconst)%fd - &
lg4x6(iconst)%lambda(6)*imass3*lg4x6(iconst)%ff
bvec(2, 1) = g4x6_list(iconst)%dac*g4x6_list(iconst)%dac &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_13, r0_13)
vec = lg4x6(iconst)%lambda(3)*lg4x6(iconst)%fc*(imass1 + imass4) + &
lg4x6(iconst)%lambda(1)*imass1*lg4x6(iconst)%fa + &
lg4x6(iconst)%lambda(2)*imass1*lg4x6(iconst)%fb + &
lg4x6(iconst)%lambda(5)*imass4*lg4x6(iconst)%fe + &
lg4x6(iconst)%lambda(6)*imass4*lg4x6(iconst)%ff
bvec(3, 1) = g4x6_list(iconst)%dad*g4x6_list(iconst)%dad &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_14, r0_14)
vec = lg4x6(iconst)%lambda(4)*lg4x6(iconst)%fd*(imass2 + imass3) - &
lg4x6(iconst)%lambda(1)*imass2*lg4x6(iconst)%fa + &
lg4x6(iconst)%lambda(2)*imass3*lg4x6(iconst)%fb + &
lg4x6(iconst)%lambda(5)*imass2*lg4x6(iconst)%fe - &
lg4x6(iconst)%lambda(6)*imass3*lg4x6(iconst)%ff
bvec(4, 1) = g4x6_list(iconst)%dbc*g4x6_list(iconst)%dbc &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_23, r0_23)
vec = lg4x6(iconst)%lambda(5)*lg4x6(iconst)%fe*(imass2 + imass4) - &
lg4x6(iconst)%lambda(1)*imass2*lg4x6(iconst)%fa + &
lg4x6(iconst)%lambda(3)*imass4*lg4x6(iconst)%fc + &
lg4x6(iconst)%lambda(4)*imass2*lg4x6(iconst)%fd + &
lg4x6(iconst)%lambda(6)*imass4*lg4x6(iconst)%ff
bvec(5, 1) = g4x6_list(iconst)%dbd*g4x6_list(iconst)%dbd &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_24, r0_24)
vec = lg4x6(iconst)%lambda(6)*lg4x6(iconst)%ff*(imass3 + imass4) - &
lg4x6(iconst)%lambda(2)*imass3*lg4x6(iconst)%fb + &
lg4x6(iconst)%lambda(3)*imass4*lg4x6(iconst)%fc - &
lg4x6(iconst)%lambda(4)*imass3*lg4x6(iconst)%fd + &
lg4x6(iconst)%lambda(5)*imass4*lg4x6(iconst)%fe
bvec(6, 1) = g4x6_list(iconst)%dcd*g4x6_list(iconst)%dcd &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_34, r0_34)
bvec = bvec*idtsq
! get lambda
atemp = amat
CALL solve_system(atemp, 6, bvec)
lg4x6(iconst)%lambda(:) = bvec(:, 1)
lg4x6(iconst)%del_lambda(:) = lg4x6(iconst)%lambda(:) - &
lg4x6(iconst)%lambda_old(:)
lg4x6(iconst)%lambda_old(:) = lg4x6(iconst)%lambda(:)
fc1 = lg4x6(iconst)%del_lambda(1)*lg4x6(iconst)%fa + &
lg4x6(iconst)%del_lambda(2)*lg4x6(iconst)%fb + &
lg4x6(iconst)%del_lambda(3)*lg4x6(iconst)%fc
fc2 = -lg4x6(iconst)%del_lambda(1)*lg4x6(iconst)%fa + &
lg4x6(iconst)%del_lambda(4)*lg4x6(iconst)%fd + &
lg4x6(iconst)%del_lambda(5)*lg4x6(iconst)%fe
fc3 = -lg4x6(iconst)%del_lambda(2)*lg4x6(iconst)%fb - &
lg4x6(iconst)%del_lambda(4)*lg4x6(iconst)%fd + &
lg4x6(iconst)%del_lambda(6)*lg4x6(iconst)%ff
fc4 = -lg4x6(iconst)%del_lambda(3)*lg4x6(iconst)%fc - &
lg4x6(iconst)%del_lambda(5)*lg4x6(iconst)%fe - &
lg4x6(iconst)%del_lambda(6)*lg4x6(iconst)%ff
r1(:) = pos(:, index_a) + imass1*dtsqby2*fc1(:)
r2(:) = pos(:, index_b) + imass2*dtsqby2*fc2(:)
r3(:) = pos(:, index_c) + imass3*dtsqby2*fc3(:)
r4(:) = pos(:, index_d) + imass4*dtsqby2*fc4(:)
v1(:) = vel(:, index_a) + imass1*dtby2*fc1(:)
v2(:) = vel(:, index_b) + imass2*dtby2*fc2(:)
v3(:) = vel(:, index_c) + imass3*dtby2*fc3(:)
v4(:) = vel(:, index_d) + imass4*dtby2*fc4(:)
r12 = r1 - r2
r13 = r1 - r3
r14 = r1 - r4
r23 = r2 - r3
r24 = r2 - r4
r34 = r3 - r4
! compute the tolerance:
sigma = DOT_PRODUCT(r12, r12) - g4x6_list(iconst)%dab* &
g4x6_list(iconst)%dab
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r13, r13) - g4x6_list(iconst)%dac* &
g4x6_list(iconst)%dac
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r14, r14) - g4x6_list(iconst)%dad* &
g4x6_list(iconst)%dad
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r23, r23) - g4x6_list(iconst)%dbc* &
g4x6_list(iconst)%dbc
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r24, r24) - g4x6_list(iconst)%dbd* &
g4x6_list(iconst)%dbd
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r34, r34) - g4x6_list(iconst)%dcd* &
g4x6_list(iconst)%dcd
max_sigma = MAX(max_sigma, ABS(sigma))
! update positions with full multiplier
pos(:, index_a) = r1(:)
pos(:, index_b) = r2(:)
pos(:, index_c) = r3(:)
pos(:, index_d) = r4(:)
! update velocites with full multiplier
vel(:, index_a) = v1(:)
vel(:, index_b) = v2(:)
vel(:, index_c) = v3(:)
vel(:, index_d) = v4(:)
END DO
END SUBROUTINE shake_4x6_low
! **************************************************************************************************
!> \brief ...
!> \param fixd_list ...
!> \param g4x6_list ...
!> \param lg4x6 ...
!> \param ng4x6 ...
!> \param first_atom ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param r_shake ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_roll_4x6_low(fixd_list, g4x6_list, lg4x6, ng4x6, first_atom, &
particle_set, pos, vel, r_shake, dt, ishake, max_sigma)
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
INTEGER, INTENT(IN) :: ng4x6, first_atom
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: r_shake
REAL(kind=dp), INTENT(in) :: dt
INTEGER, INTENT(IN) :: ishake
REAL(KIND=dp), INTENT(INOUT) :: max_sigma
INTEGER :: iconst, index_a, index_b, index_c, &
index_d
REAL(KIND=dp) :: dtby2, dtsqby2, idtsq, imass1, imass2, &
imass3, imass4, sigma
REAL(KIND=dp), DIMENSION(3) :: f_roll1, f_roll2, f_roll3, f_roll4, f_roll5, f_roll6, fc1, &
fc2, fc3, fc4, r0_12, r0_13, r0_14, r0_23, r0_24, r0_34, r1, r12, r13, r14, r2, r23, r24, &
r3, r34, r4, v1, v2, v3, v4, vec
REAL(KIND=dp), DIMENSION(6, 1) :: bvec
REAL(KIND=dp), DIMENSION(6, 6) :: amat, atemp
TYPE(atomic_kind_type), POINTER :: atomic_kind
dtsqby2 = dt*dt*.5_dp
idtsq = 1.0_dp/dt/dt
dtby2 = dt*.5_dp
DO iconst = 1, ng4x6
IF (g4x6_list(iconst)%restraint%active) CYCLE
index_a = g4x6_list(iconst)%a + first_atom - 1
index_b = g4x6_list(iconst)%b + first_atom - 1
index_c = g4x6_list(iconst)%c + first_atom - 1
index_d = g4x6_list(iconst)%d + first_atom - 1
IF (ishake == 1) THEN
r0_12(:) = pos(:, index_a) - pos(:, index_b)
r0_13(:) = pos(:, index_a) - pos(:, index_c)
r0_23(:) = pos(:, index_b) - pos(:, index_c)
r0_14(:) = pos(:, index_a) - pos(:, index_d)
r0_24(:) = pos(:, index_b) - pos(:, index_d)
r0_34(:) = pos(:, index_c) - pos(:, index_d)
atomic_kind => particle_set(index_a)%atomic_kind
imass1 = 1.0_dp/atomic_kind%mass
atomic_kind => particle_set(index_b)%atomic_kind
imass2 = 1.0_dp/atomic_kind%mass
atomic_kind => particle_set(index_c)%atomic_kind
imass3 = 1.0_dp/atomic_kind%mass
atomic_kind => particle_set(index_d)%atomic_kind
imass4 = 1.0_dp/atomic_kind%mass
lg4x6(iconst)%fa = -2.0_dp*(lg4x6(iconst)%ra_old - &
lg4x6(iconst)%rb_old)
lg4x6(iconst)%fb = -2.0_dp*(lg4x6(iconst)%ra_old - &
lg4x6(iconst)%rc_old)
lg4x6(iconst)%fc = -2.0_dp*(lg4x6(iconst)%ra_old - &
lg4x6(iconst)%rd_old)
lg4x6(iconst)%fd = -2.0_dp*(lg4x6(iconst)%rb_old - &
lg4x6(iconst)%rc_old)
lg4x6(iconst)%fe = -2.0_dp*(lg4x6(iconst)%rb_old - &
lg4x6(iconst)%rd_old)
lg4x6(iconst)%ff = -2.0_dp*(lg4x6(iconst)%rc_old - &
lg4x6(iconst)%rd_old)
! Check for fixed atom constraints
CALL check_fixed_atom_cns_g4x6(imass1, imass2, imass3, imass4, &
index_a, index_b, index_c, index_d, fixd_list, lg4x6(iconst))
! rotate fconst:
f_roll1 = MATMUL(r_shake, lg4x6(iconst)%fa)
f_roll2 = MATMUL(r_shake, lg4x6(iconst)%fb)
f_roll3 = MATMUL(r_shake, lg4x6(iconst)%fc)
f_roll4 = MATMUL(r_shake, lg4x6(iconst)%fd)
f_roll5 = MATMUL(r_shake, lg4x6(iconst)%fe)
f_roll6 = MATMUL(r_shake, lg4x6(iconst)%ff)
! construct matrix
amat(1, 1) = (imass1 + imass2)*DOT_PRODUCT(r0_12, f_roll1)
amat(1, 2) = imass1*DOT_PRODUCT(r0_12, f_roll2)
amat(1, 3) = imass1*DOT_PRODUCT(r0_12, f_roll3)
amat(1, 4) = -imass2*DOT_PRODUCT(r0_12, f_roll4)
amat(1, 5) = -imass2*DOT_PRODUCT(r0_12, f_roll5)
amat(1, 6) = 0.0_dp
amat(2, 1) = imass1*DOT_PRODUCT(r0_13, f_roll1)
amat(2, 2) = (imass1 + imass3)*DOT_PRODUCT(r0_13, f_roll2)
amat(2, 3) = imass1*DOT_PRODUCT(r0_13, f_roll3)
amat(2, 4) = imass3*DOT_PRODUCT(r0_13, f_roll4)
amat(2, 5) = 0.0_dp
amat(2, 6) = -imass3*DOT_PRODUCT(r0_13, f_roll6)
amat(3, 1) = imass1*DOT_PRODUCT(r0_14, f_roll1)
amat(3, 2) = imass1*DOT_PRODUCT(r0_14, f_roll2)
amat(3, 3) = (imass1 + imass4)*DOT_PRODUCT(r0_14, f_roll3)
amat(3, 4) = 0.0_dp
amat(3, 5) = imass4*DOT_PRODUCT(r0_14, f_roll5)
amat(3, 6) = imass4*DOT_PRODUCT(r0_14, f_roll6)
amat(4, 1) = -imass2*DOT_PRODUCT(r0_23, f_roll1)
amat(4, 2) = imass3*DOT_PRODUCT(r0_23, f_roll2)
amat(4, 3) = 0.0_dp
amat(4, 4) = (imass3 + imass2)*DOT_PRODUCT(r0_23, f_roll4)
amat(4, 5) = imass2*DOT_PRODUCT(r0_23, f_roll5)
amat(4, 6) = -imass3*DOT_PRODUCT(r0_23, f_roll6)
amat(5, 1) = -imass2*DOT_PRODUCT(r0_24, f_roll1)
amat(5, 2) = 0.0_dp
amat(5, 3) = imass4*DOT_PRODUCT(r0_24, f_roll3)
amat(5, 4) = imass2*DOT_PRODUCT(r0_24, f_roll4)
amat(5, 5) = (imass4 + imass2)*DOT_PRODUCT(r0_24, f_roll5)
amat(5, 6) = imass4*DOT_PRODUCT(r0_24, f_roll6)
amat(6, 1) = 0.0_dp
amat(6, 2) = -imass3*DOT_PRODUCT(r0_34, f_roll2)
amat(6, 3) = imass4*DOT_PRODUCT(r0_34, f_roll3)
amat(6, 4) = -imass3*DOT_PRODUCT(r0_34, f_roll4)
amat(6, 5) = imass4*DOT_PRODUCT(r0_34, f_roll5)
amat(6, 6) = (imass3 + imass4)*DOT_PRODUCT(r0_34, f_roll6)
! Store values
lg4x6(iconst)%r0_12 = r0_12
lg4x6(iconst)%r0_13 = r0_13
lg4x6(iconst)%r0_14 = r0_14
lg4x6(iconst)%r0_23 = r0_23
lg4x6(iconst)%r0_24 = r0_24
lg4x6(iconst)%r0_34 = r0_34
lg4x6(iconst)%f_roll1 = f_roll1
lg4x6(iconst)%f_roll2 = f_roll2
lg4x6(iconst)%f_roll3 = f_roll3
lg4x6(iconst)%f_roll4 = f_roll4
lg4x6(iconst)%f_roll5 = f_roll5
lg4x6(iconst)%f_roll6 = f_roll6
lg4x6(iconst)%amat = amat
lg4x6(iconst)%imass1 = imass1
lg4x6(iconst)%imass2 = imass2
lg4x6(iconst)%imass3 = imass3
lg4x6(iconst)%imass4 = imass4
lg4x6(iconst)%lambda_old = 0.0_dp
lg4x6(iconst)%del_lambda = 0.0_dp
ELSE
! Retrieve values
r0_12 = lg4x6(iconst)%r0_12
r0_13 = lg4x6(iconst)%r0_13
r0_14 = lg4x6(iconst)%r0_14
r0_23 = lg4x6(iconst)%r0_23
r0_24 = lg4x6(iconst)%r0_24
r0_34 = lg4x6(iconst)%r0_34
f_roll1 = lg4x6(iconst)%f_roll1
f_roll2 = lg4x6(iconst)%f_roll2
f_roll3 = lg4x6(iconst)%f_roll3
f_roll4 = lg4x6(iconst)%f_roll4
f_roll5 = lg4x6(iconst)%f_roll5
f_roll6 = lg4x6(iconst)%f_roll6
amat = lg4x6(iconst)%amat
imass1 = lg4x6(iconst)%imass1
imass2 = lg4x6(iconst)%imass2
imass3 = lg4x6(iconst)%imass3
imass4 = lg4x6(iconst)%imass4
END IF
! Iterate until convergence:
vec = lg4x6(iconst)%lambda(1)*f_roll1*(imass1 + imass2) + &
lg4x6(iconst)%lambda(2)*imass1*f_roll2 + &
lg4x6(iconst)%lambda(3)*imass1*f_roll3 - &
lg4x6(iconst)%lambda(4)*imass2*f_roll4 - &
lg4x6(iconst)%lambda(5)*imass2*f_roll5
bvec(1, 1) = g4x6_list(iconst)%dab*g4x6_list(iconst)%dab &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_12, r0_12)
vec = lg4x6(iconst)%lambda(2)*f_roll2*(imass1 + imass3) + &
lg4x6(iconst)%lambda(1)*imass1*f_roll1 + &
lg4x6(iconst)%lambda(3)*imass1*f_roll3 + &
lg4x6(iconst)%lambda(4)*imass3*f_roll4 - &
lg4x6(iconst)%lambda(6)*imass3*f_roll6
bvec(2, 1) = g4x6_list(iconst)%dac*g4x6_list(iconst)%dac &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_13, r0_13)
vec = lg4x6(iconst)%lambda(3)*f_roll3*(imass1 + imass4) + &
lg4x6(iconst)%lambda(1)*imass1*f_roll1 + &
lg4x6(iconst)%lambda(2)*imass1*f_roll2 + &
lg4x6(iconst)%lambda(5)*imass4*f_roll5 + &
lg4x6(iconst)%lambda(6)*imass4*f_roll6
bvec(3, 1) = g4x6_list(iconst)%dad*g4x6_list(iconst)%dad &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_14, r0_14)
vec = lg4x6(iconst)%lambda(4)*f_roll4*(imass2 + imass3) - &
lg4x6(iconst)%lambda(1)*imass2*f_roll1 + &
lg4x6(iconst)%lambda(2)*imass3*f_roll2 + &
lg4x6(iconst)%lambda(5)*imass2*f_roll5 - &
lg4x6(iconst)%lambda(6)*imass3*f_roll6
bvec(4, 1) = g4x6_list(iconst)%dbc*g4x6_list(iconst)%dbc &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_23, r0_23)
vec = lg4x6(iconst)%lambda(5)*f_roll5*(imass2 + imass4) - &
lg4x6(iconst)%lambda(1)*imass2*f_roll1 + &
lg4x6(iconst)%lambda(3)*imass4*f_roll3 + &
lg4x6(iconst)%lambda(4)*imass2*f_roll4 + &
lg4x6(iconst)%lambda(6)*imass4*f_roll6
bvec(5, 1) = g4x6_list(iconst)%dbd*g4x6_list(iconst)%dbd &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_24, r0_24)
vec = lg4x6(iconst)%lambda(6)*f_roll6*(imass3 + imass4) - &
lg4x6(iconst)%lambda(2)*imass3*f_roll2 + &
lg4x6(iconst)%lambda(3)*imass4*f_roll3 - &
lg4x6(iconst)%lambda(4)*imass3*f_roll4 + &
lg4x6(iconst)%lambda(5)*imass4*f_roll5
bvec(6, 1) = g4x6_list(iconst)%dcd*g4x6_list(iconst)%dcd &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_34, r0_34)
bvec = bvec*idtsq
! get lambda
atemp = amat
CALL solve_system(atemp, 6, bvec)
lg4x6(iconst)%lambda(:) = bvec(:, 1)
lg4x6(iconst)%del_lambda(:) = lg4x6(iconst)%lambda(:) - &
lg4x6(iconst)%lambda_old(:)
lg4x6(iconst)%lambda_old(:) = lg4x6(iconst)%lambda(:)
fc1 = lg4x6(iconst)%del_lambda(1)*lg4x6(iconst)%fa + &
lg4x6(iconst)%del_lambda(2)*lg4x6(iconst)%fb + &
lg4x6(iconst)%del_lambda(3)*lg4x6(iconst)%fc
fc2 = -lg4x6(iconst)%del_lambda(1)*lg4x6(iconst)%fa + &
lg4x6(iconst)%del_lambda(4)*lg4x6(iconst)%fd + &
lg4x6(iconst)%del_lambda(5)*lg4x6(iconst)%fe
fc3 = -lg4x6(iconst)%del_lambda(2)*lg4x6(iconst)%fb - &
lg4x6(iconst)%del_lambda(4)*lg4x6(iconst)%fd + &
lg4x6(iconst)%del_lambda(6)*lg4x6(iconst)%ff
fc4 = -lg4x6(iconst)%del_lambda(3)*lg4x6(iconst)%fc - &
lg4x6(iconst)%del_lambda(5)*lg4x6(iconst)%fe - &
lg4x6(iconst)%del_lambda(6)*lg4x6(iconst)%ff
r1(:) = pos(:, index_a) + imass1*dtsqby2*MATMUL(r_shake, fc1)
r2(:) = pos(:, index_b) + imass2*dtsqby2*MATMUL(r_shake, fc2)
r3(:) = pos(:, index_c) + imass3*dtsqby2*MATMUL(r_shake, fc3)
r4(:) = pos(:, index_d) + imass4*dtsqby2*MATMUL(r_shake, fc4)
v1(:) = vel(:, index_a) + imass1*dtby2*MATMUL(r_shake, fc1)
v2(:) = vel(:, index_b) + imass2*dtby2*MATMUL(r_shake, fc2)
v3(:) = vel(:, index_c) + imass3*dtby2*MATMUL(r_shake, fc3)
v4(:) = vel(:, index_d) + imass4*dtby2*MATMUL(r_shake, fc4)
r12 = r1 - r2
r13 = r1 - r3
r23 = r2 - r3
r14 = r1 - r4
r24 = r2 - r4
r34 = r3 - r4
! compute the tolerance:
sigma = DOT_PRODUCT(r12, r12) - g4x6_list(iconst)%dab* &
g4x6_list(iconst)%dab
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r13, r13) - g4x6_list(iconst)%dac* &
g4x6_list(iconst)%dac
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r14, r14) - g4x6_list(iconst)%dad* &
g4x6_list(iconst)%dad
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r23, r23) - g4x6_list(iconst)%dbc* &
g4x6_list(iconst)%dbc
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r24, r24) - g4x6_list(iconst)%dbd* &
g4x6_list(iconst)%dbd
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r34, r34) - g4x6_list(iconst)%dcd* &
g4x6_list(iconst)%dcd
max_sigma = MAX(max_sigma, ABS(sigma))
! update positions with full multiplier
pos(:, index_a) = r1(:)
pos(:, index_b) = r2(:)
pos(:, index_c) = r3(:)
pos(:, index_d) = r4(:)
! update velocites with full multiplier
vel(:, index_a) = v1(:)
vel(:, index_b) = v2(:)
vel(:, index_c) = v3(:)
vel(:, index_d) = v4(:)
END DO
END SUBROUTINE shake_roll_4x6_low
! **************************************************************************************************
!> \brief ...
!> \param fixd_list ...
!> \param g4x6_list ...
!> \param lg4x6 ...
!> \param first_atom ...
!> \param particle_set ...
!> \param vel ...
!> \param dt ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_4x6_low(fixd_list, g4x6_list, lg4x6, first_atom, &
particle_set, vel, dt)
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g4x6_constraint_type), POINTER :: g4x6_list(:)
TYPE(local_g4x6_constraint_type), POINTER :: lg4x6(:)
INTEGER, INTENT(IN) :: first_atom
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: vel(:, :)
REAL(kind=dp), INTENT(in) :: dt
INTEGER :: iconst, index_a, index_b, index_c, &
index_d
REAL(KIND=dp) :: dtby2, idt, imass1, imass2, imass3, &
imass4, mass
REAL(KIND=dp), DIMENSION(3) :: fc1, fc2, fc3, fc4, r12, r13, r14, r23, &
r24, r34, v12, v13, v14, v23, v24, v34
REAL(KIND=dp), DIMENSION(6, 1) :: bvec
REAL(KIND=dp), DIMENSION(6, 6) :: amat
TYPE(atomic_kind_type), POINTER :: atomic_kind
idt = 1.0_dp/dt
dtby2 = dt*.5_dp
DO iconst = 1, SIZE(g4x6_list)
IF (g4x6_list(iconst)%restraint%active) CYCLE
index_a = g4x6_list(iconst)%a + first_atom - 1
index_b = g4x6_list(iconst)%b + first_atom - 1
index_c = g4x6_list(iconst)%c + first_atom - 1
index_d = g4x6_list(iconst)%d + first_atom - 1
v12(:) = vel(:, index_a) - vel(:, index_b)
v13(:) = vel(:, index_a) - vel(:, index_c)
v14(:) = vel(:, index_a) - vel(:, index_d)
v23(:) = vel(:, index_b) - vel(:, index_c)
v24(:) = vel(:, index_b) - vel(:, index_d)
v34(:) = vel(:, index_c) - vel(:, index_d)
r12(:) = particle_set(index_a)%r(:) - particle_set(index_b)%r(:)
r13(:) = particle_set(index_a)%r(:) - particle_set(index_c)%r(:)
r14(:) = particle_set(index_a)%r(:) - particle_set(index_d)%r(:)
r23(:) = particle_set(index_b)%r(:) - particle_set(index_c)%r(:)
r24(:) = particle_set(index_b)%r(:) - particle_set(index_d)%r(:)
r34(:) = particle_set(index_c)%r(:) - particle_set(index_d)%r(:)
atomic_kind => particle_set(index_a)%atomic_kind
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
imass1 = 1.0_dp/mass
atomic_kind => particle_set(index_b)%atomic_kind
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
imass2 = 1.0_dp/mass
atomic_kind => particle_set(index_c)%atomic_kind
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
imass3 = 1.0_dp/mass
atomic_kind => particle_set(index_d)%atomic_kind
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
imass4 = 1.0_dp/mass
lg4x6(iconst)%fa = -2.0_dp*r12
lg4x6(iconst)%fb = -2.0_dp*r13
lg4x6(iconst)%fc = -2.0_dp*r14
lg4x6(iconst)%fd = -2.0_dp*r23
lg4x6(iconst)%fe = -2.0_dp*r24
lg4x6(iconst)%ff = -2.0_dp*r34
! Check for fixed atom constraints
CALL check_fixed_atom_cns_g4x6(imass1, imass2, imass3, imass4, &
index_a, index_b, index_c, index_d, fixd_list, lg4x6(iconst))
! construct matrix
amat(1, 1) = (imass1 + imass2)*DOT_PRODUCT(r12, lg4x6(iconst)%fa)
amat(1, 2) = imass1*DOT_PRODUCT(r12, lg4x6(iconst)%fb)
amat(1, 3) = imass1*DOT_PRODUCT(r12, lg4x6(iconst)%fc)
amat(1, 4) = -imass2*DOT_PRODUCT(r12, lg4x6(iconst)%fd)
amat(1, 5) = -imass2*DOT_PRODUCT(r12, lg4x6(iconst)%fe)
amat(1, 6) = 0.0_dp
amat(2, 1) = imass1*DOT_PRODUCT(r13, lg4x6(iconst)%fa)
amat(2, 2) = (imass1 + imass3)*DOT_PRODUCT(r13, lg4x6(iconst)%fb)
amat(2, 3) = imass1*DOT_PRODUCT(r13, lg4x6(iconst)%fc)
amat(2, 4) = imass3*DOT_PRODUCT(r13, lg4x6(iconst)%fd)
amat(2, 5) = 0.0_dp
amat(2, 6) = -imass3*DOT_PRODUCT(r13, lg4x6(iconst)%ff)
amat(3, 1) = imass1*DOT_PRODUCT(r14, lg4x6(iconst)%fa)
amat(3, 2) = imass1*DOT_PRODUCT(r14, lg4x6(iconst)%fb)
amat(3, 3) = (imass1 + imass4)*DOT_PRODUCT(r14, lg4x6(iconst)%fc)
amat(3, 4) = 0.0_dp
amat(3, 5) = imass4*DOT_PRODUCT(r14, lg4x6(iconst)%fe)
amat(3, 6) = imass4*DOT_PRODUCT(r14, lg4x6(iconst)%ff)
amat(4, 1) = -imass2*DOT_PRODUCT(r23, lg4x6(iconst)%fa)
amat(4, 2) = imass3*DOT_PRODUCT(r23, lg4x6(iconst)%fb)
amat(4, 3) = 0.0_dp
amat(4, 4) = (imass3 + imass2)*DOT_PRODUCT(r23, lg4x6(iconst)%fd)
amat(4, 5) = imass2*DOT_PRODUCT(r23, lg4x6(iconst)%fe)
amat(4, 6) = -imass3*DOT_PRODUCT(r23, lg4x6(iconst)%ff)
amat(5, 1) = -imass2*DOT_PRODUCT(r24, lg4x6(iconst)%fa)
amat(5, 2) = 0.0_dp
amat(5, 3) = imass4*DOT_PRODUCT(r24, lg4x6(iconst)%fc)
amat(5, 4) = imass2*DOT_PRODUCT(r24, lg4x6(iconst)%fd)
amat(5, 5) = (imass4 + imass2)*DOT_PRODUCT(r24, lg4x6(iconst)%fe)
amat(5, 6) = imass4*DOT_PRODUCT(r24, lg4x6(iconst)%ff)
amat(6, 1) = 0.0_dp
amat(6, 2) = -imass3*DOT_PRODUCT(r34, lg4x6(iconst)%fb)
amat(6, 3) = imass4*DOT_PRODUCT(r34, lg4x6(iconst)%fc)
amat(6, 4) = -imass3*DOT_PRODUCT(r34, lg4x6(iconst)%fd)