リビジョン | c4a68e721236d95bb9a398678120b101126669b3 (tree) |
---|---|
日時 | 2009-01-15 23:59:04 |
作者 | iselllo |
コミッター | iselllo |
I wrote a new fortran routine which again calculates molecule absorption for a given system snapshot.
@@ -0,0 +1,146 @@ | ||
1 | +subroutine absorption_snap_calc(trajectories_arr,N_trajectories, x_arr,y_arr, & | |
2 | + z_arr, r1_arr, N_spheres,k, results, old_results) | |
3 | + | |
4 | +implicit none | |
5 | + | |
6 | +integer :: N_trajectories, i, j, k, N_spheres ! , count_abso, count_abso_0 ! , step_absorption, flag | |
7 | + | |
8 | +real(kind=8) :: trajectories_arr((3*N_trajectories)), x_arr(N_spheres),y_arr(N_spheres) | |
9 | +!real(kind=8) :: t_abso_bis | |
10 | +real(kind=8) :: my_dist, z_arr(N_spheres), surviving_molecules(N_trajectories),r1_arr(N_spheres) | |
11 | +integer, intent(out) :: results(2,N_trajectories) | |
12 | +integer :: old_results(2,N_trajectories) | |
13 | + | |
14 | + | |
15 | +!compile it using: | |
16 | +! f2py -c --fcompiler=gfortran absorbe_snapshot.f90 -m --f90flags='-O2' absorbe_snap | |
17 | + | |
18 | + | |
19 | + | |
20 | +! count_abso=0 | |
21 | +! count_abso_0=0 | |
22 | + | |
23 | +! I will initialize this array within the main code now | |
24 | + | |
25 | +!initialize the array with the results | |
26 | + | |
27 | + | |
28 | + | |
29 | +! do i=1, 2 | |
30 | + | |
31 | +! do j=1, N_trajectories | |
32 | + | |
33 | +! results(i,j)=-1 !I initialize this array with an "impossible" value | |
34 | + | |
35 | +! enddo | |
36 | +! enddo | |
37 | + | |
38 | + | |
39 | + | |
40 | + | |
41 | +results=old_results | |
42 | + | |
43 | + | |
44 | + | |
45 | +!Now check if each single ray touches a circle (first neighbor of our circle) | |
46 | + | |
47 | + | |
48 | + | |
49 | +trajectory_loop : do i=1, N_trajectories !go on all the molecule trajectories | |
50 | + | |
51 | +!I need to be careful here: I should check only trajectories of molecule which have not been absorbed yet. | |
52 | + | |
53 | + | |
54 | +if (old_results(1,i) .eq. -1) then | |
55 | + | |
56 | +!if (k .eq. 20) then | |
57 | + | |
58 | +!print * ,"old_results(1,i) == -1 and k", old_results(1,i) == -1, k | |
59 | + | |
60 | +!endif | |
61 | + | |
62 | +!Now I introduce a condition: I am looking for collisions only for | |
63 | +!molecules which have NOT already been absorbed. The condition of non-absorption | |
64 | +!means that surviving_molecules(i) is positive | |
65 | + | |
66 | +!if (surviving_molecules(i)>dble(0.0d0)) then | |
67 | + | |
68 | +!print *, "Dealing with trajectory number,", i | |
69 | + | |
70 | + | |
71 | +!time_loop : do k=1, NN !go down in time | |
72 | + | |
73 | +!!!! It is important not to swap the loops on time and monomers, otherwise I may end up | |
74 | +!! seeing a molecule collide with the wrong monomer (in reality it would have been | |
75 | +!! absorbed at a previous time) | |
76 | + | |
77 | + | |
78 | + | |
79 | +monomer_loop : do j=1, N_spheres !check for collisions with a monomer | |
80 | + | |
81 | + | |
82 | + | |
83 | + | |
84 | +my_dist=dsqrt(((trajectories_arr((3*i-2))-x_arr(j)))*(trajectories_arr((3*i-2))-x_arr(j))+ & | |
85 | + (trajectories_arr((3*i-1))-y_arr(j))*(trajectories_arr((3*i-1))-y_arr(j)) + & | |
86 | +(trajectories_arr((3*i))-z_arr(j))*(trajectories_arr((3*i))-z_arr(j))) | |
87 | + | |
88 | +! if (k .eq. 0) then | |
89 | + | |
90 | +! print *, "k, r1_arr(j),x_arr(j),y_arr(j),z_arr(j), and my_dist are", k, r1_arr(j),x_arr(j),y_arr(j),z_arr(j), my_dist | |
91 | + | |
92 | +! print *, "traj((3*i-2)),traj((3*i-1)), traj((3*i)) are, ", trajectories_arr((3*i-2)), & | |
93 | +! trajectories_arr((3*i-1)), trajectories_arr((3*i)) | |
94 | + | |
95 | +! endif | |
96 | + | |
97 | +if (my_dist .le. r1_arr(j)) then | |
98 | + | |
99 | +!count_abso=count_abso+1 | |
100 | + | |
101 | + ! if (k .eq. 1) then | |
102 | + | |
103 | +! count_abso_0=count_abso_0+1 | |
104 | + | |
105 | +! endif | |
106 | + | |
107 | +!print * , "my_dist is, traj, time, count_abso, count_abso_0 are ", my_dist, i, k, count_abso,count_abso_0 | |
108 | + | |
109 | + | |
110 | +results(1,i)=k !absorption time (which is now given as an input; I do not have time any longer in this routine) | |
111 | +results(2,i)=j !id of the absorbing monomer | |
112 | + | |
113 | +end if | |
114 | + | |
115 | + | |
116 | +!if (my_dist .le. r1_arr(j)) exit monomer_loop !leave loop on monomers; the molecule has been absorbed | |
117 | +!if (my_dist .le. -25.3) exit | |
118 | + | |
119 | + | |
120 | +enddo monomer_loop | |
121 | + | |
122 | + | |
123 | + | |
124 | + | |
125 | + | |
126 | +!if (my_dist .le. r1_arr(j)) exit time_loop ! I should also leave the loop on time and go back to the trajectories | |
127 | + | |
128 | +!if (my_dist .le. -25.3) exit | |
129 | + | |
130 | + | |
131 | +!enddo time_loop | |
132 | + | |
133 | +endif | |
134 | + | |
135 | + | |
136 | +enddo trajectory_loop | |
137 | + | |
138 | + | |
139 | + | |
140 | + | |
141 | + | |
142 | + | |
143 | +return | |
144 | + | |
145 | +end subroutine absorption_snap_calc | |
146 | + |