forked from cp2k/cp2k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constraint_3x3.F
862 lines (785 loc) · 39.9 KB
/
constraint_3x3.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
!--------------------------------------------------------------------------------------------------!
! 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
!> none
! **************************************************************************************************
MODULE constraint_3x3
USE atomic_kind_types, ONLY: atomic_kind_type,&
get_atomic_kind
USE constraint_fxd, ONLY: check_fixed_atom_cns_g3x3
USE kinds, ONLY: dp
USE linear_systems, ONLY: solve_system
USE molecule_kind_types, ONLY: fixd_constraint_type,&
g3x3_constraint_type,&
get_molecule_kind,&
molecule_kind_type
USE molecule_types, ONLY: get_molecule,&
global_constraint_type,&
local_g3x3_constraint_type,&
molecule_type
USE particle_types, ONLY: particle_type
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
PUBLIC :: shake_3x3_int, &
rattle_3x3_int, &
shake_roll_3x3_int, &
rattle_roll_3x3_int, &
shake_3x3_ext, &
rattle_3x3_ext, &
shake_roll_3x3_ext, &
rattle_roll_3x3_ext
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'constraint_3x3'
CONTAINS
! **************************************************************************************************
!> \brief ...
!> \param molecule ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_3x3_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, ng3x3
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind
NULLIFY (fixd_list)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ng3x3=ng3x3, &
g3x3_list=g3x3_list, fixd_list=fixd_list)
CALL get_molecule(molecule, first_atom=first_atom, lg3x3=lg3x3)
! Real Shake
CALL shake_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, ng3x3, &
particle_set, pos, vel, dt, ishake, max_sigma)
END SUBROUTINE shake_3x3_int
! **************************************************************************************************
!> \brief ...
!> \param molecule ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param r_shake ...
!> \param v_shake ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_roll_3x3_int(molecule, particle_set, pos, vel, r_shake, &
v_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, v_shake
REAL(kind=dp), INTENT(in) :: dt
INTEGER, INTENT(IN) :: ishake
REAL(KIND=dp), INTENT(INOUT) :: max_sigma
INTEGER :: first_atom, ng3x3
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind
NULLIFY (fixd_list)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, ng3x3=ng3x3, &
g3x3_list=g3x3_list, fixd_list=fixd_list)
CALL get_molecule(molecule, first_atom=first_atom, lg3x3=lg3x3)
! Real Shake
CALL shake_roll_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, ng3x3, &
particle_set, pos, vel, r_shake, v_shake, dt, ishake, max_sigma)
END SUBROUTINE shake_roll_3x3_int
! **************************************************************************************************
!> \brief ...
!> \param molecule ...
!> \param particle_set ...
!> \param vel ...
!> \param r_rattle ...
!> \param dt ...
!> \param veps ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_roll_3x3_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
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind
NULLIFY (fixd_list)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, &
g3x3_list=g3x3_list, fixd_list=fixd_list)
CALL get_molecule(molecule, first_atom=first_atom, lg3x3=lg3x3)
! Real Rattle
CALL rattle_roll_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, &
particle_set, vel, r_rattle, dt, veps)
END SUBROUTINE rattle_roll_3x3_int
! **************************************************************************************************
!> \brief ...
!> \param molecule ...
!> \param particle_set ...
!> \param vel ...
!> \param dt ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_3x3_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
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
TYPE(molecule_kind_type), POINTER :: molecule_kind
NULLIFY (fixd_list)
molecule_kind => molecule%molecule_kind
CALL get_molecule_kind(molecule_kind, &
g3x3_list=g3x3_list, fixd_list=fixd_list)
CALL get_molecule(molecule, first_atom=first_atom, lg3x3=lg3x3)
! Real Rattle
CALL rattle_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, &
particle_set, vel, dt)
END SUBROUTINE rattle_3x3_int
! **************************************************************************************************
!> \brief ...
!> \param gci ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_3x3_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, ng3x3
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
first_atom = 1
ng3x3 = gci%ng3x3
g3x3_list => gci%g3x3_list
fixd_list => gci%fixd_list
lg3x3 => gci%lg3x3
! Real Shake
CALL shake_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, ng3x3, &
particle_set, pos, vel, dt, ishake, max_sigma)
END SUBROUTINE shake_3x3_ext
! **************************************************************************************************
!> \brief ...
!> \param gci ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param r_shake ...
!> \param v_shake ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_roll_3x3_ext(gci, particle_set, pos, vel, r_shake, &
v_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, v_shake
REAL(kind=dp), INTENT(in) :: dt
INTEGER, INTENT(IN) :: ishake
REAL(KIND=dp), INTENT(INOUT) :: max_sigma
INTEGER :: first_atom, ng3x3
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
first_atom = 1
ng3x3 = gci%ng3x3
g3x3_list => gci%g3x3_list
fixd_list => gci%fixd_list
lg3x3 => gci%lg3x3
! Real Shake
CALL shake_roll_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, ng3x3, &
particle_set, pos, vel, r_shake, v_shake, dt, ishake, max_sigma)
END SUBROUTINE shake_roll_3x3_ext
! **************************************************************************************************
!> \brief ...
!> \param gci ...
!> \param particle_set ...
!> \param vel ...
!> \param r_rattle ...
!> \param dt ...
!> \param veps ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_roll_3x3_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
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
first_atom = 1
g3x3_list => gci%g3x3_list
fixd_list => gci%fixd_list
lg3x3 => gci%lg3x3
! Real Rattle
CALL rattle_roll_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, &
particle_set, vel, r_rattle, dt, veps)
END SUBROUTINE rattle_roll_3x3_ext
! **************************************************************************************************
!> \brief ...
!> \param gci ...
!> \param particle_set ...
!> \param vel ...
!> \param dt ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_3x3_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
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
first_atom = 1
g3x3_list => gci%g3x3_list
fixd_list => gci%fixd_list
lg3x3 => gci%lg3x3
! Real Rattle
CALL rattle_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, &
particle_set, vel, dt)
END SUBROUTINE rattle_3x3_ext
! **************************************************************************************************
!> \brief ...
!> \param fixd_list ...
!> \param g3x3_list ...
!> \param lg3x3 ...
!> \param first_atom ...
!> \param ng3x3 ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, ng3x3, &
particle_set, pos, vel, dt, ishake, max_sigma)
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
INTEGER, INTENT(IN) :: first_atom, ng3x3
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
REAL(KIND=dp) :: dtby2, dtsqby2, idtsq, imass1, imass2, &
imass3, sigma
REAL(KIND=dp), DIMENSION(3) :: fc1, fc2, fc3, r0_12, r0_13, r0_23, r1, &
r12, r13, r2, r23, r3, v1, v2, v3, vec
REAL(KIND=dp), DIMENSION(3, 1) :: bvec
REAL(KIND=dp), DIMENSION(3, 3) :: 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, ng3x3
IF (g3x3_list(iconst)%restraint%active) CYCLE
index_a = g3x3_list(iconst)%a + first_atom - 1
index_b = g3x3_list(iconst)%b + first_atom - 1
index_c = g3x3_list(iconst)%c + 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)
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
lg3x3(iconst)%fa = -2.0_dp*(lg3x3(iconst)%ra_old - &
lg3x3(iconst)%rb_old)
lg3x3(iconst)%fb = -2.0_dp*(lg3x3(iconst)%ra_old - &
lg3x3(iconst)%rc_old)
lg3x3(iconst)%fc = -2.0_dp*(lg3x3(iconst)%rb_old - &
lg3x3(iconst)%rc_old)
! Check for fixed atom constraints
CALL check_fixed_atom_cns_g3x3(imass1, imass2, imass3, &
index_a, index_b, index_c, fixd_list, lg3x3(iconst))
! construct matrix
amat(1, 1) = (imass1 + imass2)*DOT_PRODUCT(r0_12, lg3x3(iconst)%fa)
amat(1, 2) = imass1*DOT_PRODUCT(r0_12, lg3x3(iconst)%fb)
amat(1, 3) = -imass2*DOT_PRODUCT(r0_12, lg3x3(iconst)%fc)
amat(2, 1) = imass1*DOT_PRODUCT(r0_13, lg3x3(iconst)%fa)
amat(2, 2) = (imass1 + imass3)*DOT_PRODUCT(r0_13, lg3x3(iconst)%fb)
amat(2, 3) = imass3*DOT_PRODUCT(r0_13, lg3x3(iconst)%fc)
amat(3, 1) = -imass2*DOT_PRODUCT(r0_23, lg3x3(iconst)%fa)
amat(3, 2) = imass3*DOT_PRODUCT(r0_23, lg3x3(iconst)%fb)
amat(3, 3) = (imass3 + imass2)*DOT_PRODUCT(r0_23, lg3x3(iconst)%fc)
! Store values
lg3x3(iconst)%r0_12 = r0_12
lg3x3(iconst)%r0_13 = r0_13
lg3x3(iconst)%r0_23 = r0_23
lg3x3(iconst)%amat = amat
lg3x3(iconst)%lambda_old = 0.0_dp
lg3x3(iconst)%del_lambda = 0.0_dp
ELSE
! Retrieve values
r0_12 = lg3x3(iconst)%r0_12
r0_13 = lg3x3(iconst)%r0_13
r0_23 = lg3x3(iconst)%r0_23
amat = lg3x3(iconst)%amat
imass1 = lg3x3(iconst)%imass1
imass2 = lg3x3(iconst)%imass2
imass3 = lg3x3(iconst)%imass3
END IF
! Iterate until convergence
vec = lg3x3(iconst)%lambda(1)*lg3x3(iconst)%fa*(imass1 + imass2) + &
lg3x3(iconst)%lambda(2)*imass1*lg3x3(iconst)%fb - &
lg3x3(iconst)%lambda(3)*imass2*lg3x3(iconst)%fc
bvec(1, 1) = g3x3_list(iconst)%dab*g3x3_list(iconst)%dab &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_12, r0_12)
vec = lg3x3(iconst)%lambda(1)*lg3x3(iconst)%fa*imass1 + &
lg3x3(iconst)%lambda(2)*(imass1 + imass3)*lg3x3(iconst)%fb + &
lg3x3(iconst)%lambda(3)*imass3*lg3x3(iconst)%fc
bvec(2, 1) = g3x3_list(iconst)%dac*g3x3_list(iconst)%dac &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_13, r0_13)
vec = -lg3x3(iconst)%lambda(1)*lg3x3(iconst)%fa*imass2 + &
lg3x3(iconst)%lambda(2)*imass3*lg3x3(iconst)%fb + &
lg3x3(iconst)%lambda(3)*(imass2 + imass3)*lg3x3(iconst)%fc
bvec(3, 1) = g3x3_list(iconst)%dbc*g3x3_list(iconst)%dbc &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_23, r0_23)
bvec = bvec*idtsq
! get lambda
atemp = amat
CALL solve_system(atemp, 3, bvec)
lg3x3(iconst)%lambda(:) = bvec(:, 1)
lg3x3(iconst)%del_lambda(:) = lg3x3(iconst)%lambda(:) - &
lg3x3(iconst)%lambda_old(:)
lg3x3(iconst)%lambda_old(:) = lg3x3(iconst)%lambda(:)
fc1 = lg3x3(iconst)%del_lambda(1)*lg3x3(iconst)%fa + &
lg3x3(iconst)%del_lambda(2)*lg3x3(iconst)%fb
fc2 = -lg3x3(iconst)%del_lambda(1)*lg3x3(iconst)%fa + &
lg3x3(iconst)%del_lambda(3)*lg3x3(iconst)%fc
fc3 = -lg3x3(iconst)%del_lambda(2)*lg3x3(iconst)%fb - &
lg3x3(iconst)%del_lambda(3)*lg3x3(iconst)%fc
r1(:) = pos(:, index_a) + imass1*dtsqby2*fc1(:)
r2(:) = pos(:, index_b) + imass2*dtsqby2*fc2(:)
r3(:) = pos(:, index_c) + imass3*dtsqby2*fc3(:)
v1(:) = vel(:, index_a) + imass1*dtby2*fc1(:)
v2(:) = vel(:, index_b) + imass2*dtby2*fc2(:)
v3(:) = vel(:, index_c) + imass3*dtby2*fc3(:)
r12 = r1 - r2
r13 = r1 - r3
r23 = r2 - r3
! compute the tolerance:
sigma = DOT_PRODUCT(r12, r12) - g3x3_list(iconst)%dab* &
g3x3_list(iconst)%dab
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r13, r13) - g3x3_list(iconst)%dac* &
g3x3_list(iconst)%dac
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r23, r23) - g3x3_list(iconst)%dbc* &
g3x3_list(iconst)%dbc
max_sigma = MAX(max_sigma, ABS(sigma))
! update positions with full multiplier
pos(:, index_a) = r1(:)
pos(:, index_b) = r2(:)
pos(:, index_c) = r3(:)
! update velocites with full multiplier
vel(:, index_a) = v1(:)
vel(:, index_b) = v2(:)
vel(:, index_c) = v3(:)
END DO
END SUBROUTINE shake_3x3_low
! **************************************************************************************************
!> \brief ...
!> \param fixd_list ...
!> \param g3x3_list ...
!> \param lg3x3 ...
!> \param first_atom ...
!> \param ng3x3 ...
!> \param particle_set ...
!> \param pos ...
!> \param vel ...
!> \param r_shake ...
!> \param v_shake ...
!> \param dt ...
!> \param ishake ...
!> \param max_sigma ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE shake_roll_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, ng3x3, &
particle_set, pos, vel, r_shake, v_shake, dt, ishake, max_sigma)
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
INTEGER, INTENT(IN) :: first_atom, ng3x3
TYPE(particle_type), POINTER :: particle_set(:)
REAL(KIND=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: r_shake, v_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
REAL(KIND=dp) :: dtby2, dtsqby2, idtsq, imass1, imass2, &
imass3, sigma
REAL(KIND=dp), DIMENSION(3) :: f_roll1, f_roll2, f_roll3, fc1, fc2, &
fc3, r0_12, r0_13, r0_23, r1, r12, &
r13, r2, r23, r3, v1, v2, v3, vec
REAL(KIND=dp), DIMENSION(3, 1) :: bvec
REAL(KIND=dp), DIMENSION(3, 3) :: 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, ng3x3
IF (g3x3_list(iconst)%restraint%active) CYCLE
index_a = g3x3_list(iconst)%a + first_atom - 1
index_b = g3x3_list(iconst)%b + first_atom - 1
index_c = g3x3_list(iconst)%c + 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)
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
lg3x3(iconst)%fa = -2.0_dp*(lg3x3(iconst)%ra_old - &
lg3x3(iconst)%rb_old)
lg3x3(iconst)%fb = -2.0_dp*(lg3x3(iconst)%ra_old - &
lg3x3(iconst)%rc_old)
lg3x3(iconst)%fc = -2.0_dp*(lg3x3(iconst)%rb_old - &
lg3x3(iconst)%rc_old)
! Check for fixed atom constraints
CALL check_fixed_atom_cns_g3x3(imass1, imass2, imass3, &
index_a, index_b, index_c, fixd_list, lg3x3(iconst))
! rotate fconst:
f_roll1 = MATMUL(r_shake, lg3x3(iconst)%fa)
f_roll2 = MATMUL(r_shake, lg3x3(iconst)%fb)
f_roll3 = MATMUL(r_shake, lg3x3(iconst)%fc)
! 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) = -imass2*DOT_PRODUCT(r0_12, f_roll3)
amat(2, 1) = imass1*DOT_PRODUCT(r0_13, f_roll1)
amat(2, 2) = (imass1 + imass3)*DOT_PRODUCT(r0_13, f_roll2)
amat(2, 3) = imass3*DOT_PRODUCT(r0_13, f_roll3)
amat(3, 1) = -imass2*DOT_PRODUCT(r0_23, f_roll1)
amat(3, 2) = imass3*DOT_PRODUCT(r0_23, f_roll2)
amat(3, 3) = (imass3 + imass2)*DOT_PRODUCT(r0_23, f_roll3)
! Store values
lg3x3(iconst)%r0_12 = r0_12
lg3x3(iconst)%r0_13 = r0_13
lg3x3(iconst)%r0_23 = r0_23
lg3x3(iconst)%f_roll1 = f_roll1
lg3x3(iconst)%f_roll2 = f_roll2
lg3x3(iconst)%f_roll3 = f_roll3
lg3x3(iconst)%amat = amat
lg3x3(iconst)%lambda_old = 0.0_dp
lg3x3(iconst)%del_lambda = 0.0_dp
ELSE
! Retrieve values
r0_12 = lg3x3(iconst)%r0_12
r0_13 = lg3x3(iconst)%r0_13
r0_23 = lg3x3(iconst)%r0_23
f_roll1 = lg3x3(iconst)%f_roll1
f_roll2 = lg3x3(iconst)%f_roll2
f_roll3 = lg3x3(iconst)%f_roll3
amat = lg3x3(iconst)%amat
imass1 = lg3x3(iconst)%imass1
imass2 = lg3x3(iconst)%imass2
imass3 = lg3x3(iconst)%imass3
END IF
! Iterate until convergence
vec = lg3x3(iconst)%lambda(1)*f_roll1*(imass1 + imass2) + &
lg3x3(iconst)%lambda(2)*imass1*f_roll2 - &
lg3x3(iconst)%lambda(3)*imass2*f_roll3
bvec(1, 1) = g3x3_list(iconst)%dab*g3x3_list(iconst)%dab &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_12, r0_12)
vec = lg3x3(iconst)%lambda(1)*f_roll1*imass1 + &
lg3x3(iconst)%lambda(2)*(imass1 + imass3)*f_roll2 + &
lg3x3(iconst)%lambda(3)*imass3*f_roll3
bvec(2, 1) = g3x3_list(iconst)%dac*g3x3_list(iconst)%dac &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_13, r0_13)
vec = -lg3x3(iconst)%lambda(1)*f_roll1*imass2 + &
lg3x3(iconst)%lambda(2)*imass3*f_roll2 + &
lg3x3(iconst)%lambda(3)*(imass2 + imass3)*f_roll3
bvec(3, 1) = g3x3_list(iconst)%dbc*g3x3_list(iconst)%dbc &
- dtsqby2*dtsqby2*DOT_PRODUCT(vec, vec) - DOT_PRODUCT(r0_23, r0_23)
bvec = bvec*idtsq
! get lambda
atemp = amat
CALL solve_system(atemp, 3, bvec)
lg3x3(iconst)%lambda(:) = bvec(:, 1)
lg3x3(iconst)%del_lambda(:) = lg3x3(iconst)%lambda(:) - &
lg3x3(iconst)%lambda_old(:)
lg3x3(iconst)%lambda_old(:) = lg3x3(iconst)%lambda(:)
fc1 = lg3x3(iconst)%del_lambda(1)*lg3x3(iconst)%fa + &
lg3x3(iconst)%del_lambda(2)*lg3x3(iconst)%fb
fc2 = -lg3x3(iconst)%del_lambda(1)*lg3x3(iconst)%fa + &
lg3x3(iconst)%del_lambda(3)*lg3x3(iconst)%fc
fc3 = -lg3x3(iconst)%del_lambda(2)*lg3x3(iconst)%fb - &
lg3x3(iconst)%del_lambda(3)*lg3x3(iconst)%fc
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)
v1(:) = vel(:, index_a) + imass1*dtby2*MATMUL(v_shake, fc1)
v2(:) = vel(:, index_b) + imass2*dtby2*MATMUL(v_shake, fc2)
v3(:) = vel(:, index_c) + imass3*dtby2*MATMUL(v_shake, fc3)
r12 = r1 - r2
r13 = r1 - r3
r23 = r2 - r3
! compute the tolerance:
sigma = DOT_PRODUCT(r12, r12) - g3x3_list(iconst)%dab* &
g3x3_list(iconst)%dab
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r13, r13) - g3x3_list(iconst)%dac* &
g3x3_list(iconst)%dac
max_sigma = MAX(max_sigma, ABS(sigma))
sigma = DOT_PRODUCT(r23, r23) - g3x3_list(iconst)%dbc* &
g3x3_list(iconst)%dbc
max_sigma = MAX(max_sigma, ABS(sigma))
! update positions with full multiplier
pos(:, index_a) = r1(:)
pos(:, index_b) = r2(:)
pos(:, index_c) = r3(:)
! update velocites with full multiplier
vel(:, index_a) = v1(:)
vel(:, index_b) = v2(:)
vel(:, index_c) = v3(:)
END DO
END SUBROUTINE shake_roll_3x3_low
! **************************************************************************************************
!> \brief ...
!> \param fixd_list ...
!> \param g3x3_list ...
!> \param lg3x3 ...
!> \param first_atom ...
!> \param particle_set ...
!> \param vel ...
!> \param r_rattle ...
!> \param dt ...
!> \param veps ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_roll_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, &
particle_set, vel, r_rattle, dt, veps)
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
INTEGER, INTENT(IN) :: first_atom
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 :: iconst, index_a, index_b, index_c
REAL(KIND=dp) :: dtby2, idt, imass1, imass2, imass3, mass
REAL(KIND=dp), DIMENSION(3) :: f_roll1, f_roll2, f_roll3, fc1, fc2, &
fc3, lambda, r12, r13, r23, v12, v13, &
v23
REAL(KIND=dp), DIMENSION(3, 1) :: bvec
REAL(KIND=dp), DIMENSION(3, 3) :: amat
TYPE(atomic_kind_type), POINTER :: atomic_kind
idt = 1.0_dp/dt
dtby2 = dt*.5_dp
DO iconst = 1, SIZE(g3x3_list)
IF (g3x3_list(iconst)%restraint%active) CYCLE
index_a = g3x3_list(iconst)%a + first_atom - 1
index_b = g3x3_list(iconst)%b + first_atom - 1
index_c = g3x3_list(iconst)%c + first_atom - 1
v12(:) = vel(:, index_a) - vel(:, index_b)
v13(:) = vel(:, index_a) - vel(:, index_c)
v23(:) = vel(:, index_b) - vel(:, index_c)
r12(:) = particle_set(index_a)%r(:) - particle_set(index_b)%r(:)
r13(:) = particle_set(index_a)%r(:) - particle_set(index_c)%r(:)
r23(:) = particle_set(index_b)%r(:) - particle_set(index_c)%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
lg3x3(iconst)%fa = -2.0_dp*r12
lg3x3(iconst)%fb = -2.0_dp*r13
lg3x3(iconst)%fc = -2.0_dp*r23
! Check for fixed atom constraints
CALL check_fixed_atom_cns_g3x3(imass1, imass2, imass3, &
index_a, index_b, index_c, fixd_list, lg3x3(iconst))
! roll the fc
f_roll1 = MATMUL(r_rattle, lg3x3(iconst)%fa)
f_roll2 = MATMUL(r_rattle, lg3x3(iconst)%fb)
f_roll3 = MATMUL(r_rattle, lg3x3(iconst)%fc)
! construct matrix
amat(1, 1) = (imass1 + imass2)*DOT_PRODUCT(r12, f_roll1)
amat(1, 2) = imass1*DOT_PRODUCT(r12, f_roll2)
amat(1, 3) = -imass2*DOT_PRODUCT(r12, f_roll3)
amat(2, 1) = imass1*DOT_PRODUCT(r13, f_roll1)
amat(2, 2) = (imass1 + imass3)*DOT_PRODUCT(r13, f_roll2)
amat(2, 3) = imass3*DOT_PRODUCT(r13, f_roll3)
amat(3, 1) = -imass2*DOT_PRODUCT(r23, f_roll1)
amat(3, 2) = imass3*DOT_PRODUCT(r23, f_roll2)
amat(3, 3) = (imass2 + imass3)*DOT_PRODUCT(r23, f_roll3)
! construct solution vector
bvec(1, 1) = DOT_PRODUCT(r12, v12 + MATMUL(veps, r12))
bvec(2, 1) = DOT_PRODUCT(r13, v13 + MATMUL(veps, r13))
bvec(3, 1) = DOT_PRODUCT(r23, v23 + MATMUL(veps, r23))
bvec = -bvec*2.0_dp*idt
! get lambda
CALL solve_system(amat, 3, bvec)
lambda(:) = bvec(:, 1)
lg3x3(iconst)%lambda(:) = lambda
fc1 = lambda(1)*f_roll1 + &
lambda(2)*f_roll2
fc2 = -lambda(1)*f_roll1 + &
lambda(3)*f_roll3
fc3 = -lambda(2)*f_roll2 - &
lambda(3)*f_roll3
vel(:, index_a) = vel(:, index_a) + imass1*dtby2*fc1(:)
vel(:, index_b) = vel(:, index_b) + imass2*dtby2*fc2(:)
vel(:, index_c) = vel(:, index_c) + imass3*dtby2*fc3(:)
END DO
END SUBROUTINE rattle_roll_3x3_low
! **************************************************************************************************
!> \brief ...
!> \param fixd_list ...
!> \param g3x3_list ...
!> \param lg3x3 ...
!> \param first_atom ...
!> \param particle_set ...
!> \param vel ...
!> \param dt ...
!> \par History
!> none
! **************************************************************************************************
SUBROUTINE rattle_3x3_low(fixd_list, g3x3_list, lg3x3, first_atom, &
particle_set, vel, dt)
TYPE(fixd_constraint_type), DIMENSION(:), POINTER :: fixd_list
TYPE(g3x3_constraint_type), POINTER :: g3x3_list(:)
TYPE(local_g3x3_constraint_type), POINTER :: lg3x3(:)
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
REAL(KIND=dp) :: dtby2, idt, imass1, imass2, imass3, mass
REAL(KIND=dp), DIMENSION(3) :: fc1, fc2, fc3, r12, r13, r23, v12, v13, &
v23
REAL(KIND=dp), DIMENSION(3, 1) :: bvec
REAL(KIND=dp), DIMENSION(3, 3) :: amat
TYPE(atomic_kind_type), POINTER :: atomic_kind
idt = 1.0_dp/dt
dtby2 = dt*.5_dp
DO iconst = 1, SIZE(g3x3_list)
IF (g3x3_list(iconst)%restraint%active) CYCLE
index_a = g3x3_list(iconst)%a + first_atom - 1
index_b = g3x3_list(iconst)%b + first_atom - 1
index_c = g3x3_list(iconst)%c + first_atom - 1
v12(:) = vel(:, index_a) - vel(:, index_b)
v13(:) = vel(:, index_a) - vel(:, index_c)
v23(:) = vel(:, index_b) - vel(:, index_c)
r12(:) = particle_set(index_a)%r(:) - particle_set(index_b)%r(:)
r13(:) = particle_set(index_a)%r(:) - particle_set(index_c)%r(:)
r23(:) = particle_set(index_b)%r(:) - particle_set(index_c)%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
lg3x3(iconst)%fa = -2.0_dp*r12
lg3x3(iconst)%fb = -2.0_dp*r13
lg3x3(iconst)%fc = -2.0_dp*r23
! Check for fixed atom constraints
CALL check_fixed_atom_cns_g3x3(imass1, imass2, imass3, &
index_a, index_b, index_c, fixd_list, lg3x3(iconst))
! construct matrix
amat(1, 1) = (imass1 + imass2)*DOT_PRODUCT(r12, lg3x3(iconst)%fa)
amat(1, 2) = imass1*DOT_PRODUCT(r12, lg3x3(iconst)%fb)
amat(1, 3) = -imass2*DOT_PRODUCT(r12, lg3x3(iconst)%fc)
amat(2, 1) = imass1*DOT_PRODUCT(r13, lg3x3(iconst)%fa)
amat(2, 2) = (imass1 + imass3)*DOT_PRODUCT(r13, lg3x3(iconst)%fb)
amat(2, 3) = imass3*DOT_PRODUCT(r13, lg3x3(iconst)%fc)
amat(3, 1) = -imass2*DOT_PRODUCT(r23, lg3x3(iconst)%fa)
amat(3, 2) = imass3*DOT_PRODUCT(r23, lg3x3(iconst)%fb)
amat(3, 3) = (imass2 + imass3)*DOT_PRODUCT(r23, lg3x3(iconst)%fc)
! construct solution vector
bvec(1, 1) = DOT_PRODUCT(r12, v12)
bvec(2, 1) = DOT_PRODUCT(r13, v13)
bvec(3, 1) = DOT_PRODUCT(r23, v23)
bvec = -bvec*2.0_dp*idt
! get lambda
CALL solve_system(amat, 3, bvec)
lg3x3(iconst)%lambda(:) = bvec(:, 1)
fc1 = lg3x3(iconst)%lambda(1)*lg3x3(iconst)%fa + &
lg3x3(iconst)%lambda(2)*lg3x3(iconst)%fb
fc2 = -lg3x3(iconst)%lambda(1)*lg3x3(iconst)%fa + &
lg3x3(iconst)%lambda(3)*lg3x3(iconst)%fc
fc3 = -lg3x3(iconst)%lambda(2)*lg3x3(iconst)%fb - &
lg3x3(iconst)%lambda(3)*lg3x3(iconst)%fc
vel(:, index_a) = vel(:, index_a) + imass1*dtby2*fc1(:)
vel(:, index_b) = vel(:, index_b) + imass2*dtby2*fc2(:)
vel(:, index_c) = vel(:, index_c) + imass3*dtby2*fc3(:)
END DO
END SUBROUTINE rattle_3x3_low
END MODULE constraint_3x3