@@ -49,20 +49,20 @@ Base.convert(T::Type{ElectricField}, x::NamedTuple) = T(x)
4949
5050
5151
52- function ElectricField (epot:: ElectricPotential{T, 3, S} , point_types:: PointTypes{T} ) where {T, S}
53- return ElectricField {T, 3, S, typeof(grid.axes)} (get_electric_field_from_potential ( epot, point_types ), epot. grid)
52+ function ElectricField (epot:: ElectricPotential{T, 3, S} , point_types:: PointTypes{T} ; use_nthreads :: Int = Base . Threads . nthreads () ) where {T, S}
53+ return ElectricField {T, 3, S, typeof(grid.axes)} (get_electric_field_from_potential ( epot, point_types; use_nthreads ), epot. grid)
5454end
5555
5656
57- function get_electric_field_from_potential (epot:: ElectricPotential{T, 3, Cylindrical} , point_types:: PointTypes{T} , fieldvector_coordinates= :xyz ):: ElectricField{T, 3, Cylindrical} where {T <: SSDFloat }
57+ function get_electric_field_from_potential (epot:: ElectricPotential{T, 3, Cylindrical} , point_types:: PointTypes{T} , fieldvector_coordinates= :xyz ; use_nthreads :: Int = Base . Threads . threadid () ):: ElectricField{T, 3, Cylindrical} where {T <: SSDFloat }
5858 p = epot. data
5959 axr:: Vector{T} = collect (epot. grid. axes[1 ])
6060 axφ:: Vector{T} = collect (epot. grid. axes[2 ])
6161 axz:: Vector{T} = collect (epot. grid. axes[3 ])
6262
6363 cyclic:: T = epot. grid. axes[2 ]. interval. right
6464 ef = Array {SVector{3, T}} (undef, size (p)... )
65- for iz in 1 : size (ef, 3 )
65+ @onthreads 1 : use_nthreads for ix in workpart ( 1 : size (ef, 3 ), 1 : use_nthreads, Base . Threads . threadid () )
6666 for iφ in 1 : size (ef, 2 )
6767 for ir in 1 : size (ef, 1 )
6868 # ## r ###
212212
213213
214214
215- function get_electric_field_from_potential (epot:: ElectricPotential{T, 3, Cartesian} , point_types:: PointTypes{T} ):: ElectricField{T, 3, Cartesian} where {T <: SSDFloat }
215+ function get_electric_field_from_potential (epot:: ElectricPotential{T, 3, Cartesian} , point_types:: PointTypes{T} ; use_nthreads :: Int = Base . Threads . nthreads () ):: ElectricField{T, 3, Cartesian} where {T <: SSDFloat }
216216 axx:: Vector{T} = collect (epot. grid. axes[1 ])
217217 axy:: Vector{T} = collect (epot. grid. axes[2 ])
218218 axz:: Vector{T} = collect (epot. grid. axes[3 ])
@@ -222,7 +222,7 @@ function get_electric_field_from_potential(epot::ElectricPotential{T, 3, Cartesi
222222
223223 ef:: Array{SVector{3, T}} = Array {SVector{3, T}} (undef, size (epot. data))
224224
225- for ix in eachindex (axx)
225+ @onthreads 1 : use_nthreads for ix in workpart ( eachindex (axx), 1 : use_nthreads, Base . Threads . threadid () )
226226 for iy in eachindex (axy)
227227 for iz in eachindex (axz)
228228 if ix - 1 < 1
0 commit comments