25 procedure:: force_field
35 SUBROUTINE init (self, name)
37 character(len=*),
optional:: name
39 call self%dll_t%init (name)
46 SUBROUTINE append (self, new)
52 call self%dll_t%append (new_dll)
58 FUNCTION force (self, p)
64 integer:: i, i0, i1, j
65 real(8):: rp(3), pt, qt, r(3), r1, r2, r3
70 do while (
associated(o))
71 if (.not.
associated (o, p))
then 76 if (o%t(i1) > p%time)
exit 79 pt = (p%time-o%t(i0))/max(o%t(i1)-o%t(i0),tiny(1d0))
83 r(j) = (qt*o%r(j,i0) + pt*o%r(j,i1)) - rp(j)
88 force = force - o%mass*r*r3
97 SUBROUTINE force_field (self, patch)
102 real(8),
allocatable:: rp(:,:), m(:)
103 real(8):: force(3), pt, qt, rc(3), r(3), r1, r3
104 integer:: i, i0, i1, ip, ix, iy, iz
109 allocate (rp(self%n,3), m(self%n))
112 do while (
associated(p))
119 if (p%t(i1) > patch%time)
exit 121 pt = (patch%time - p%t(i0))/max(p%t(i1)-p%t(i0),tiny(1d0))
123 rp(:,ip) = qt*p%r(:,i0) + pt*p%r(:,i1)
131 associate(m1=>patch%mesh(1), m2=>patch%mesh(2), m3=>patch%mesh(3))
133 rc(3) = m3%p + m3%r(iz)
135 rc(2) = m2%p + m2%r(iy)
137 rc(1) = m1%p + m1%r(ix)
141 r1 = 1d0/sqrt(r(1)**2 + r(2)**2 + r(3)**2 + tiny(1d0))
143 force = force - m(ip)*r*r3
145 patch%force_per_unit_mass(ix,iy,iz,:) = &
146 patch%force_per_unit_mass(ix,iy,iz,:) + force
152 END SUBROUTINE force_field
157 SUBROUTINE test (self)
160 class(particle_t),
pointer:: p
161 class(dll_node_t),
pointer :: node, next, new
178 call self%append (node)
180 used = wallclock()-used
181 print *,
'particle list n =', self%n, used/self%n
188 do while (
associated(node))
195 call self%remove (node)
201 used = wallclock()-used
202 print *,
'particle list n =', self%n, used/self%n
209 do while (
associated(node))
214 call self%insert_before (node, new)
219 used = wallclock()-used
220 print *,
'particle list n =', self%n, used/self%n
226 SUBROUTINE print (self)
228 class(dll_node_t),
pointer:: p
230 do while (
associated(p))
232 class is (particle_t)
233 print *, p%id, p%r(:,p%it)
Support tic/toc timing, as in MATLAB, and accurate wallclock() function. The timing is generally much...
Particle data type, extends a dll_node data type, so it can become part of a particle_list_t data typ...
Template module for patches, which adds pointers to memory and mesh, and number of dimensions and var...
Doubly linked list (DLL), carrying anything, as simply as possible.
Particle list, extending a doubly-linked list. Each particle maintains arrays with previous positions...