RMPCDMD
test_elastic_network_0.f90
Go to the documentation of this file.
1 ! This file is part of RMPCDMD
2 ! Copyright (c) 2016 Pierre de Buyl and contributors
3 ! License: BSD 3-clause (see file LICENSE)
4 
15 
17  use particle_system
18  use md
19  use iso_c_binding
20  use tester
21  implicit none
22 
23  type(tester_t) :: test
24 
25  type(particle_system_t) :: p
26  integer, parameter :: N = 4
27  integer, parameter :: n_links = 3
28  double precision, parameter :: k = 7
29  integer :: links(2,n_links)
30  double precision :: links_d(n_links)
31 
32  double precision :: L(3), e, expected_e
33 
34  call test%init()
35 
36  call p% init(n)
37  l = 5.d0
38 
39  p%force = 0
40  p%pos = 1
41  p%pos(1,1) = 1
42 
43  expected_e = 0
44  ! first link
45  ! r0 = 1/2
46  ! distance = 2
47  p%pos(1,2) = 3
48  links(:,1) = [1, 2]
49  links_d(1) = 0.5d0
50  expected_e = expected_e + 1.5d0**2
51  ! second link
52  ! r0 = 1
53  ! distance = 1
54  p%pos(2,3) = 2
55  links(:,2) = [1, 3]
56  links_d(2) = 1
57  expected_e = expected_e + 0
58  ! third link
59  ! r0 = 1
60  ! distance = 1.5
61  p%pos(1,4) = 4.5d0
62  links(:,3) = [1, 4]
63  links_d(3) = 1
64  expected_e = expected_e + 0.5d0**2
65 
66  expected_e = expected_e*k/2
67 
68  e = elastic_network(p, links, links_d, k, l)
69 
70  write(*,*) 'expected_e', expected_e
71  write(*,*) 'e', e
72  call test%assert_close(e, expected_e)
73 
74  call test%assert_close(p%force(:,1), [k, 0.d0, 0.d0])
75 
76  call test%assert_close(maxval(abs(sum(p%force, dim=2))), 0.d0)
77 
78  call test% print()
79 
80 end program test_elastic_network_0
Data for particles.
double precision function, public elastic_network(p, links, distances, k, edges)
Definition: md.f90:517
Routines to perform Molecular Dynamics integration.
Definition: md.f90:13
program test_elastic_network_0
Test the elastic network force routine.