/
observable.tcl
176 lines (152 loc) · 5.79 KB
/
observable.tcl
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
# Copyright (C) 2010,2011,2012 The ESPResSo project
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
source "tests_common.tcl"
require_feature ELECTROSTATICS
require_feature MASS
require_feature EXTERNAL_FORCES
proc veccompare { a b } {
# puts "$a $b"
if { [ llength $a ] != [ llength $b ] } {
return 0
}
for { set i 0 } { $i < [ llength $a ] } { incr i } {
set A [ lindex $a $i ]
set B [ lindex $b $i ]
if { !( $A == $B || [ expr abs($A - $B) < 1e-6 ]) } {
return 0
}
}
return 1
}
puts "---------------------------------------------------------------"
puts "- Testcase observable.tcl running on [format %02d [setmd n_nodes]] nodes"
puts "---------------------------------------------------------------"
setmd box_l 8 8 8
setmd skin 0.5
setmd time_step 0.01
thermostat off
part 0 pos 1 0 0 v 2 0 0 type 0 q 1 mass 1 ext_force 1 0 0
part 1 pos 2 0 0 v 4 0 0 type 0 q -1 ext_force -2 0 0
part 2 pos 1 1 0 v 2 2 0 type 1
part 3 pos 2 1 0 v 4 2 0 type 1
part 4 pos 3 0 0 v 6 0 0 type 0 mass 2
integrate 0
############### Observable particle_position ##########################
## Here we are checking if particle specifications are working
# position particle 0
set p0 [ observable new particle_positions id 0 ]
if { ![ veccompare [ observable $p0 print ] { 1 0 0 } ] } {
error "P0 is not working"
}
# position particle 0, 3
set p1 [ observable new particle_positions id { 2 3 } ]
if { ![ veccompare [ observable $p1 print ] { 1 1 0 2 1 0} ] } {
error "P1 is not working"
}
# positions particle 0 1
set p2 [ observable new particle_positions type { 0 } ]
if { ![ veccompare [ observable $p2 print ] { 1 0 0 2 0 0 3 0 0 } ] } {
error "P2 is not working"
}
# position particle 0-3
set p3 [ observable new particle_positions type { 0 1 } ]
if { ![ veccompare [ observable $p3 print ] { 1 0 0 2 0 0 1 1 0 2 1 0 3 0 0 } ] } {
error "P3 is not working"
}
############## Observable particle velocities #######################
set v0 [ observable new particle_velocities id 0 ]
if { ![ veccompare [ observable $v0 print ] { 2 0 0 } ] } {
error "V0 is not working"
}
# position particle 0, 3
set v1 [ observable new particle_velocities id { 2 3 } ]
if { ![ veccompare [ observable $v1 print ] { 2 2 0 4 2 0} ] } {
error "V1 is not working"
}
# positions particle 0 1
set v2 [ observable new particle_velocities type { 0 } ]
if { ![ veccompare [ observable $v2 print ] { 2 0 0 4 0 0 6 0 0 } ] } {
error "V2 is not working"
}
# position particle 0-3
set v3 [ observable new particle_velocities type { 0 1 } ]
if { ![ veccompare [ observable $v3 print ] { 2 0 0 4 0 0 2 2 0 4 2 0 6 0 0 } ] } {
error "V3 is not working"
}
# position all particles
set v4 [ observable new particle_velocities all ]
if { ![ veccompare [ observable $v4 print ] { 2 0 0 4 0 0 2 2 0 4 2 0 6 0 0 } ] } {
error "V3 is not working"
}
############# Observable com_position ##########
set com_pos1 [ observable new com_position id { 0 1 } ]
if { ![ veccompare [ observable $com_pos1 print ] { 1.5 0 0 } ] } {
error "com_pos1 is not working"
}
set com_pos2 [ observable new com_position type 0 ]
if { ![ veccompare [ observable $com_pos2 print ] { 2.25 0 0 } ] } {
error "com_pos2 is not working"
}
############# Observable com_position ##########
set com_vel1 [ observable new com_velocity id { 0 1 } ]
if { ![ veccompare [ observable $com_vel1 print ] { 3 0 0 } ] } {
error "com_vel1 is not working"
}
set com_vel2 [ observable new com_velocity type 0 ]
if { ![ veccompare [ observable $com_vel2 print ] { 4.5 0 0 } ] } {
error "com_vel2 is not working"
}
############# Observable dipole_moment #####################
set dipm [ observable new dipole_moment id { 0 1 } ]
if { ![ veccompare [ observable $dipm print ] { -1 0 0 } ] } {
error "dipm is not working"
}
############# Observable current #####################
set current [ observable new current id { 0 1 } ]
if { ![ veccompare [ observable $current print ] { -2 0 0 } ] } {
error "current is not working"
}
############# Observable particle_currents #####################
set particle_currents [ observable new particle_currents id { 0 1 } ]
if { ![ veccompare [ observable $particle_currents print ] { 2 0 0 -4 0 0 } ] } {
error "particle_currents is not working"
}
############# Observable stress tensor ##########
set stress_tensor [ observable new stress_tensor ]
if { ![ veccompare [ observable $stress_tensor print ] [ lreplace [ lindex [ analyze stress ] 0 ] 0 0 ] ] } {
error "stress_tensor is not working"
}
############# Observable com force and particle force ######
set particle_forces [ observable new particle_forces id { 0 1 } ]
if { ![ veccompare [ observable $particle_forces print ] { 1 0 0 -2 0 0 } ] } {
error "particle_forces is not working"
}
set com_force [ observable new com_force id { 0 1 } ]
if { ![ veccompare [ observable $com_force print ] { -1 0 0 } ] } {
error "particle_forces is not working"
}
############# Observable tcl command #######################
proc p1 {} {
return { 1 2 3 }
}
set tclcommand [ observable new tclcommand 3 "p1" ]
puts [ p1 ]
puts "This is the output [ observable $tclcommand print ]"
if { ![ veccompare [ observable $tclcommand print ] { 1 2 3 } ] } {
error "tclcommand is not working"
}