Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
particles.f90
Go to the documentation of this file.
1! Copyright (c) 2026, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
35 use num_types, only : rp
36 use vector, only : vector_t
37 use utils, only : neko_error
38 implicit none
39 private
40
42 type, public :: particles_t
43 type(vector_t) :: x, y, z
44 type(vector_t) :: u, v, w
45 integer, allocatable :: ids(:)
46 type(vector_t) :: u_lag, v_lag, w_lag
47 type(vector_t) :: u_laglag, v_laglag, w_laglag
48 integer :: time_order, lag_len
49 integer :: n = 0
50 integer :: n_global = 0
51 logical :: inertia = .false.
52 type(vector_t) :: acc_x, acc_y, acc_z
53 type(vector_t) :: d
54 type(vector_t) :: rho
55 type(vector_t) :: acc_xlag, acc_ylag, acc_zlag
56 type(vector_t) :: acc_xlaglag, acc_ylaglag, acc_zlaglag
57 contains
58 procedure, pass(this) :: init => particles_init
59 procedure, pass(this) :: free => particles_free
60 procedure, pass(this) :: device_sync => particles_device_sync
61 end type particles_t
62
63contains
64
65 subroutine particles_init(this, x, y, z, time_order, u, v, w, diameter, &
66 density)
67 class(particles_t), intent(inout) :: this
68 real(kind=rp), intent(in) :: x(:), y(:), z(:)
69 integer, intent(in) :: time_order
70 real(kind=rp), intent(in), optional :: u(:), v(:), w(:)
71 real(kind=rp), intent(in), optional :: diameter(:)
72 real(kind=rp), intent(in), optional :: density(:)
73
74 integer :: i
75
76 if (size(y) .ne. size(x) .or. size(z) .ne. size(x)) then
77 call neko_error("particle coordinate arrays must have the same size")
78 end if
79
80 call this%free()
81
82 this%n = size(x)
83 this%n_global = this%n
84 this%time_order = time_order
85 this%lag_len = time_order - 1
86
87 if (present(diameter) .neqv. present(density)) then
88 call neko_error("particle diameter and density must both be provided")
89 end if
90 this%inertia = present(diameter)
91 call this%x%init(this%n)
92 call this%y%init(this%n)
93 call this%z%init(this%n)
94 call this%u%init(this%n)
95 call this%v%init(this%n)
96 call this%w%init(this%n)
97 call this%acc_x%init(this%n)
98 call this%acc_y%init(this%n)
99 call this%acc_z%init(this%n)
100 allocate(this%ids(this%n))
101 call this%u_lag%init(this%n)
102 call this%v_lag%init(this%n)
103 call this%w_lag%init(this%n)
104 call this%u_laglag%init(this%n)
105 call this%v_laglag%init(this%n)
106 call this%w_laglag%init(this%n)
107 call this%acc_xlag%init(this%n)
108 call this%acc_ylag%init(this%n)
109 call this%acc_zlag%init(this%n)
110 call this%acc_xlaglag%init(this%n)
111 call this%acc_ylaglag%init(this%n)
112 call this%acc_zlaglag%init(this%n)
113 call this%d%init(this%n)
114 call this%rho%init(this%n)
115 this%x = x
116 this%y = y
117 this%z = z
118 if (present(u) .and. present(v) .and. present(w)) then
119 this%u = u
120 this%v = v
121 this%w = w
122 else
123 this%u = 0.0_rp
124 this%v = 0.0_rp
125 this%w = 0.0_rp
126 end if
127 if (present(diameter)) then
128 this%d = diameter
129 else
130 this%d = 0.0_rp
131 end if
132 if (present(density)) then
133 this%rho = density
134 else
135 this%rho = 0.0_rp
136 end if
137 do i = 1, this%n
138 this%ids(i) = i
139 end do
140 end subroutine particles_init
141
142 subroutine particles_free(this)
143 class(particles_t), intent(inout) :: this
144
145 call this%x%free()
146 call this%y%free()
147 call this%z%free()
148 if (allocated(this%ids)) deallocate(this%ids)
149 call this%u%free()
150 call this%v%free()
151 call this%w%free()
152 call this%acc_x%free()
153 call this%acc_y%free()
154 call this%acc_z%free()
155 call this%u_lag%free()
156 call this%v_lag%free()
157 call this%w_lag%free()
158 call this%u_laglag%free()
159 call this%v_laglag%free()
160 call this%w_laglag%free()
161 call this%acc_xlag%free()
162 call this%acc_ylag%free()
163 call this%acc_zlag%free()
164 call this%acc_xlaglag%free()
165 call this%acc_ylaglag%free()
166 call this%acc_zlaglag%free()
167 call this%d%free()
168 call this%rho%free()
169 this%n = 0
170 this%n_global = 0
171 end subroutine particles_free
172
174 subroutine particles_device_sync(this, memdir)
175 class(particles_t), intent(inout) :: this
176 integer, intent(in) :: memdir
177
178 call this%x%copy_from(memdir, .false.)
179 call this%y%copy_from(memdir, .false.)
180 call this%z%copy_from(memdir, .false.)
181 call this%u%copy_from(memdir, .false.)
182 call this%v%copy_from(memdir, .false.)
183 call this%w%copy_from(memdir, .true.)
184 call this%acc_x%copy_from(memdir, .false.)
185 call this%acc_y%copy_from(memdir, .false.)
186 call this%acc_z%copy_from(memdir, .true.)
187 call this%u_lag%copy_from(memdir, .false.)
188 call this%v_lag%copy_from(memdir, .false.)
189 call this%w_lag%copy_from(memdir, .true.)
190 call this%u_laglag%copy_from(memdir, .false.)
191 call this%v_laglag%copy_from(memdir, .false.)
192 call this%w_laglag%copy_from(memdir, .true.)
193 call this%acc_xlag%copy_from(memdir, .false.)
194 call this%acc_ylag%copy_from(memdir, .false.)
195 call this%acc_zlag%copy_from(memdir, .true.)
196 call this%acc_xlaglag%copy_from(memdir, .false.)
197 call this%acc_ylaglag%copy_from(memdir, .false.)
198 call this%acc_zlaglag%copy_from(memdir, .true.)
199 call this%d%copy_from(memdir, .false.)
200 call this%rho%copy_from(memdir, .true.)
201
202 end subroutine particles_device_sync
203
204end module particles
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Defines a collection of Lagrangian particles.
Definition particles.f90:34
subroutine particles_init(this, x, y, z, time_order, u, v, w, diameter, density)
Definition particles.f90:67
subroutine particles_device_sync(this, memdir)
Synchronise the host and device data for particles.
subroutine particles_free(this)
Utilities.
Definition utils.f90:35
Defines a vector.
Definition vector.f90:34
Particle positions, velocities, properties, and time-history data.
Definition particles.f90:42