Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses the array data structure for ParticleField and pullbacks for AD #13

Open
wants to merge 229 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
229 commits
Select commit Hold shift + click to select a range
2dfb484
add FLOWFMM compatibility functions
rymanderson Sep 29, 2023
0f3923b
prepare for workstation test
rymanderson Oct 3, 2023
19e4867
remove DifferentialEquations dependency
rymanderson Oct 4, 2023
e2240f0
add benchmark script
rymanderson Oct 6, 2023
3b41d05
use MVectors
rymanderson Oct 6, 2023
6271257
add more benchmarks to script
rymanderson Oct 6, 2023
5ff91fc
update FMM
rymanderson Oct 11, 2023
2b99805
passing unit tests with FLOWFMM
rymanderson Nov 4, 2023
bf0682c
replace abstract ::Function type definition with concrete parameteric…
rymanderson Nov 8, 2023
b96b2e8
bug fix
rymanderson Nov 8, 2023
e7edc2c
made UJ type-stable (matching ExaFMM benchmarks)
rymanderson Nov 8, 2023
2e4de05
bug fix
rymanderson Nov 8, 2023
97daa09
prepare benchmark
rymanderson Nov 8, 2023
189b009
prep new benchmark
rymanderson Nov 9, 2023
40f856f
passing unit tests
rymanderson Nov 15, 2023
b31c96f
make expansion_order consistent and prep benchmark
rymanderson Nov 25, 2023
1caa44d
prep benchmark with fmm
rymanderson Nov 25, 2023
78bf00b
specify julia-1.6
rymanderson Nov 25, 2023
56d5d34
allow changing pfield.Uinf by using less restrictive type
rymanderson Nov 27, 2023
c106932
bug fix
rymanderson Nov 27, 2023
69bcba8
remove duplicate eltype definition
rymanderson Nov 27, 2023
2c8f93d
add nonzero_sigma parameter
rymanderson Nov 27, 2023
8b6271e
change nonzero_sigma default =false
rymanderson Nov 28, 2023
d9b28e7
initialize particle field with custom float type
rymanderson Dec 5, 2023
1101eb6
merge conflict on workstation
rymanderson Nov 27, 2023
c163a52
ForwardDiff compatibility
rymanderson Dec 6, 2023
ceeaac6
add custom_UJ function
rymanderson Dec 14, 2023
ad44787
working with panels
rymanderson Jan 10, 2024
df9de1a
fix viscous and SFS syntax error
rymanderson Jan 13, 2024
4fdbf47
update fields explicitly in remove_particle
rymanderson Feb 14, 2024
2ec569a
toggle saving particle field
rymanderson Feb 15, 2024
73c6d13
update fmm syntax
rymanderson Feb 21, 2024
07da72c
add custom_UJ function
rymanderson Dec 14, 2023
712650f
working with panels
rymanderson Jan 10, 2024
99ef2f7
fix viscous and SFS syntax error
rymanderson Jan 13, 2024
4acd689
update fmm syntax
rymanderson Feb 21, 2024
9b355c8
merge conflict
rymanderson Feb 23, 2024
29360c1
Remove unused tests
cibinjoseph Feb 26, 2024
0ee4bef
Take out vol
cibinjoseph Feb 26, 2024
03f8065
Remove field sigma
cibinjoseph Feb 26, 2024
710eb00
Comment out field vol
cibinjoseph Feb 26, 2024
859bfba
Remove field circulation
cibinjoseph Feb 26, 2024
27415bc
Remove field Gamma
cibinjoseph Feb 26, 2024
6ddaa10
Remove field X
cibinjoseph Feb 26, 2024
ee6ec70
Remove field U
cibinjoseph Feb 26, 2024
7546d40
Remove field W
cibinjoseph Feb 26, 2024
5049e6c
Remove field PSE
cibinjoseph Feb 26, 2024
7c4202b
Remove field PSE
cibinjoseph Feb 26, 2024
5529f0b
Remove field C
cibinjoseph Feb 26, 2024
9eba49a
Remove field SFS
cibinjoseph Feb 26, 2024
88d928b
Remove field J
cibinjoseph Feb 26, 2024
4264836
Remove field M
cibinjoseph Mar 1, 2024
dbc6203
Correct typo
cibinjoseph Mar 1, 2024
f57754d
Remove field static
cibinjoseph Mar 3, 2024
26726c6
Remove index field
cibinjoseph Mar 4, 2024
01eec2c
Remove Particle struct and maintain an array of particles
cibinjoseph Mar 7, 2024
2a7d0e7
Remove particle file
cibinjoseph Mar 7, 2024
beaf02f
Remove debug statements and correct setindex and getindex functions t…
cibinjoseph Mar 12, 2024
6a49638
Generalize buffer_element() for the particle and remove Particle typing
cibinjoseph Mar 12, 2024
b7895be
Remove comment
cibinjoseph Mar 12, 2024
285b5f4
Add getter and setter functions
cibinjoseph Mar 12, 2024
b6c70dd
Use getter and setter functions in FMM definitions
cibinjoseph Mar 13, 2024
24fca7d
Use the getter and setter functions for resetting the particles
cibinjoseph Mar 13, 2024
0fe84da
Add get and set for the other fields
cibinjoseph Mar 13, 2024
3ad5366
Use getter and setter functions everywhere
cibinjoseph Mar 13, 2024
afba95d
Replace some more functions with getter and setter functions
cibinjoseph Mar 13, 2024
28e5abf
Use the views to make code readability better and improve perf
cibinjoseph Mar 13, 2024
67833ac
Add a variable replacer script for ease of use later if necessary
cibinjoseph Mar 14, 2024
9771fbb
Remove replacer script from later commits
cibinjoseph Mar 14, 2024
ef01eee
Unroll 1:3 loops
cibinjoseph Mar 14, 2024
5602198
Variable substitution using the get functions
cibinjoseph Mar 14, 2024
00b95a3
Remove index field from xdmf file
cibinjoseph Mar 14, 2024
51a0324
Undo the vectorization on 1-3 loops
cibinjoseph Mar 29, 2024
ad595e6
Convert direct to use getter functions
cibinjoseph Mar 29, 2024
12c6c91
Merge pull request #7 from cibinjoseph/cibin
cibinjoseph Apr 4, 2024
e070b22
pullbacks for direct! and timestepping
Apr 11, 2024
9614d1f
actually add rrules
Apr 11, 2024
1e0264b
update rrules
Apr 16, 2024
819b1f0
Change particle field to store particle states in one big matrix. Thi…
Apr 26, 2024
cc54df3
Remove manifest file
cibinjoseph Apr 29, 2024
4da0b74
Ignore manifest.toml
cibinjoseph Apr 29, 2024
4d1089c
Remove indexing that allocates
cibinjoseph Apr 29, 2024
082772a
Merge branch 'master' into derivatives
cibinjoseph Apr 29, 2024
a6b917f
Use getter setter functions
cibinjoseph Apr 29, 2024
f1993eb
Use getter setter functions
cibinjoseph Apr 29, 2024
ab48b2a
Remove particle.jl file
cibinjoseph Apr 29, 2024
bd25b6c
Change Jexa to J in src/ and examples/
cibinjoseph Apr 30, 2024
995db11
remove PyPlot dependency
rymanderson Apr 30, 2024
cf066d6
remove BenchmarkTools from dependencies
rymanderson Apr 30, 2024
a16fb46
update FMM interface
rymanderson Apr 30, 2024
2a3435a
Use get_Gamma() for particle
cibinjoseph Apr 30, 2024
719a7f3
add .swp files to gitignore
rymanderson Apr 30, 2024
2cb847f
remove allocations from inviscid simulation and remove redundant UJ_d…
rymanderson May 1, 2024
1141a5f
add viscous and reformulation unit tests to single_vortexring
rymanderson May 1, 2024
e9e083a
Corrected SFS methods and added tests for them
BTV25 May 2, 2024
9b0954b
shorten testing time, added leapfrog tests but not using them
BTV25 May 2, 2024
5591e5d
Activated leapfrogging tests
BTV25 May 2, 2024
caac7c4
update syntax for specifying float type
rymanderson May 13, 2024
68f0cda
Fix access to C variables in particle states.
May 16, 2024
db9af8a
Merge branch 'derivatives' of https://github.com/byuflowlab/FLOWVPM.j…
May 16, 2024
8f7f849
update FMM argument names
rymanderson May 18, 2024
7f05995
isolate euler step function and add velocity gradient to output files
rymanderson May 22, 2024
9422cad
change FMM default to include shrinking method
rymanderson May 30, 2024
5151a85
Remove Manifest file
cibinjoseph Jun 18, 2024
ebca213
Add simple test for trying out gpu stuff
cibinjoseph Jun 18, 2024
3db3c83
Function direct based on environment variable
cibinjoseph Jun 18, 2024
0d3e75f
Add gpu kernel framework
rymanderson Jun 18, 2024
48194f2
Add julia_history to giignore
rymanderson Jun 18, 2024
597e1cc
Remove obsolete reference to particle struct
rymanderson Jun 19, 2024
a5e69ed
Add gpu based interaction kernel
rymanderson Jun 20, 2024
488f11f
fmm.direct function overloaded with GPU kernel. Ensure ENV works.
rymanderson Jun 20, 2024
34e9da9
Add a useGPU flag, but not robust yet
rymanderson Jun 21, 2024
c1a9b3e
Add function signature for targets
cibinjoseph Jun 22, 2024
e28a9f5
Make changes to handle running on GPU architecture inside ParticleFie…
cibinjoseph Jun 25, 2024
0d2cf4f
Add a basic test for gpu and cpu particlefields
cibinjoseph Jun 25, 2024
c66f4c5
Add SFS contribution to GPU kernel but in CPU
rymanderson Jun 25, 2024
b0308a8
Add useGPU option
rymanderson Jun 25, 2024
6ba47f9
Add Cuda functions for verification
rymanderson Jun 25, 2024
8d4b64d
Remove unnecessary target variables
rymanderson Jun 25, 2024
6fe45b7
Substitute SpecialFunctions.erf() for custom_erf() and remove Special…
rymanderson Jun 25, 2024
af107d9
Comment out custom g_sgm_dgdr() function for gpu
rymanderson Jun 25, 2024
e2bbdc7
Remove obsolete gpu_g_dgdr function
rymanderson Jun 25, 2024
fefe405
Remove obsolete gpu_g_dgdr function
rymanderson Jun 25, 2024
48a5abd
Pass the g_dgdr() kernel function to the GPU kernel
rymanderson Jun 25, 2024
fb48eb8
Add tests for GPU if device is functional
rymanderson Jun 25, 2024
c0d2f6a
Add tests for GPU if device is functional
rymanderson Jun 25, 2024
e38dcac
Copy only 1:24 fields in target matrix
cibinjoseph Jun 26, 2024
5c225bc
Extend compatibility of custom_erf() to ForwardDiff.Dual type
cibinjoseph Jun 27, 2024
1f29f1c
Add provision for specifying p_max and q_max in get_launch_config
cibinjoseph Jun 29, 2024
41afd04
Bandaid fix for @atomic incompatibility by forcing q=1
cibinjoseph Jun 29, 2024
43139db
Example to test derivatives
cibinjoseph Jun 29, 2024
e945fb9
Typo in arguments
rymanderson Jun 29, 2024
41e150a
Add ForwardDiff import inside gpu_erf definition
rymanderson Jun 29, 2024
0169bf7
Use JacobiElliptic instead of Elliptic for ForwardDiff compatibility
rymanderson Jun 29, 2024
38af91a
Add JacobiElliptic to requirements
rymanderson Jun 29, 2024
d2d63ff
Add flag for no testing
rymanderson Jun 29, 2024
dd8d8ae
Make cross() AD compatible
rymanderson Jun 30, 2024
f6091ff
Replace Cubature for AD compatible HCubature
rymanderson Jun 30, 2024
b5b19ce
Replace JacobiElliptic with EllipticFunctions for better AD compatibi…
cibinjoseph Jun 30, 2024
4efcf35
Changes for AD compatibility of vortexring examples
cibinjoseph Jun 30, 2024
59c6344
Make GPU kernel AD compatible by removing type conversion and shared …
rymanderson Jun 30, 2024
0299bd2
Andrew changes
rymanderson Jul 1, 2024
f5c6ffd
FLOWVPM.jl
rymanderson Jul 1, 2024
71c7a7a
No changes
rymanderson Jul 1, 2024
a354056
Sync all examples and Project.toml file from gpu branch
rymanderson Jul 1, 2024
ee19619
Second set of sync with gpu branch
rymanderson Jul 1, 2024
adb75d2
Second set of sync with gpu branch
rymanderson Jul 1, 2024
cdc3bec
Sync with gpu branch and correct presence of obsolete pfield.particles
rymanderson Jul 1, 2024
11a3730
Next round of syncs with gpu branch
rymanderson Jul 1, 2024
7ad6f04
Sync gpu branch
rymanderson Jul 1, 2024
da1ebd3
Change VectorStrength to Strength for FastMultipole compatibility
rymanderson Jul 1, 2024
eee5f27
Change VectorStrength to Strength for fmm
rymanderson Jul 1, 2024
9aeeb45
Add reset particle function
rymanderson Jul 1, 2024
ce6b5c0
Remove manifest
rymanderson Jul 1, 2024
d9f782c
Remove installation docs python notebook
rymanderson Jul 1, 2024
0ce30d1
Merge changes for AD compatibility for trajectory optimization
rymanderson Jul 1, 2024
f42c0a7
Easy defaults for ncrit and useGPU
rymanderson Jul 1, 2024
0d699c6
Remove ncrit_default
rymanderson Jul 2, 2024
00296bb
Do not use GPU by default
cibinjoseph Jul 2, 2024
b58503a
Add parallel reductions but have to reduce shared memory size later
rymanderson Jul 2, 2024
e17a150
Add elementwise operation for removing particle
cibinjoseph Jul 3, 2024
89eaed8
Basic test for VPM
cibinjoseph Jul 3, 2024
ce318ab
Add convenience function for precompiling GPU kernel
rymanderson Jul 3, 2024
bf0e764
Rename convenience function to warmup_gpu()
rymanderson Jul 3, 2024
99035d8
Set concurrent_direct to pfield.useGPU
cibinjoseph Jul 3, 2024
ec884e0
fmm updated syntax
rymanderson Jul 4, 2024
c85efb3
fix remove particles bug
rymanderson Jul 4, 2024
d0e2205
static particle field is no longer boolean bug
rymanderson Jul 4, 2024
ca41fc6
Ignore bson files
rymanderson Jul 5, 2024
d0abccb
correction to function call
BTV25 Jul 5, 2024
55dae46
use is_static function
rymanderson Jul 5, 2024
c651099
Add parallel reduction for Duals
cibinjoseph Jul 6, 2024
98d7e81
Add @atomic to atomic reduction kernel
rymanderson Jul 6, 2024
00226c7
Correct errors in parallel reduction kernel
rymanderson Jul 7, 2024
24191e2
Correct ncrit setting with useGPU
rymanderson Jul 7, 2024
2d3cd97
Reduce ncrit for gpu for Duals to fit in shared memory
rymanderson Jul 7, 2024
b7d372b
Update example with chunk size
cibinjoseph Jul 7, 2024
f80e1a4
Add ncrit reduction to shared mem overflow error message
cibinjoseph Jul 7, 2024
30b6fa6
Comment out parallel reduction until ForwardDiff.Dual type check is f…
cibinjoseph Jul 7, 2024
34ea879
Correct error in q selection logic
rymanderson Jul 7, 2024
57afc83
Merge gpu branch
cibinjoseph Jul 8, 2024
91d09fc
Change max_threads_per_block for Float32 to 1024
cibinjoseph Jul 9, 2024
ff14ad5
Run function call
cibinjoseph Jul 9, 2024
2b02566
Add max_threads argument to function calls
rymanderson Jul 9, 2024
10a4da6
Changes for target_indices function signature
cibinjoseph Jul 9, 2024
ffce682
Force concurrent_direct=true
rymanderson Jul 9, 2024
7d456ca
Change GPU kernel to cater to target_indices argument
rymanderson Jul 10, 2024
ee74349
Extend to 2 gpus
rymanderson Jul 10, 2024
6aaf266
Add warnings if using low number of GPUs
rymanderson Jul 10, 2024
dff39b3
Bug fix in 2 gpu kernel
rymanderson Jul 10, 2024
3917a25
Bug fix in 2 gpu kernel
rymanderson Jul 10, 2024
41c60ed
Use an hcat with a view
cibinjoseph Jul 10, 2024
6006d19
Make useGPU an integer
rymanderson Jul 10, 2024
ffe74aa
Use expanded target_indices with views for copying data to GPU
rymanderson Jul 10, 2024
a2b6996
Correct typo in expanded_indices
rymanderson Jul 10, 2024
37efc00
Correct typos in 2GPU kernel
rymanderson Jul 10, 2024
51bae8d
Improve warmup_gpu function for multiple gpus
rymanderson Jul 10, 2024
116f611
Correct target_indices typo in warmup_gpu()
rymanderson Jul 10, 2024
2453334
Make ngpu an Int when running code
rymanderson Jul 11, 2024
35dcf3e
Add padding to target size to nearest multiple of 10 for efficient p,…
rymanderson Jul 12, 2024
bfa671b
Benchmarking
rymanderson Jul 12, 2024
3caadbd
Add max threads per block for Pascal
rymanderson Jul 12, 2024
be1036a
update fmm.direct! syntax to use multiple target indices
rymanderson Jul 12, 2024
e5aa5e8
backwards-compatibility for DynamicSFS convenience syntax
rymanderson Jul 12, 2024
b5db201
Add sort function to divisors
rymanderson Jul 12, 2024
9be1cb9
merge conflict
rymanderson Jul 12, 2024
bf7de7c
Fix tests for numerical useGPU
Jul 13, 2024
d494f76
Ignore runfiles and scripts
Jul 13, 2024
35856cb
Add max thread limits and padding in multiples of 32
Jul 13, 2024
b910152
Revert to target_index for cpu direct()
cibinjoseph Jul 16, 2024
ab6f5dc
Make direct_gpu!() use source_indices and target_indices and revert d…
rymanderson Jul 16, 2024
c7eff92
Make compatible with new direct_gpu!() in FastMultipole
rymanderson Jul 17, 2024
398d35a
Add GPU kernel for multiple gpus
rymanderson Jul 17, 2024
5905f85
Correct leapfrog example to use multiple gpus
rymanderson Jul 17, 2024
75b2f65
Bug fixes for multiple gpus
Jul 17, 2024
d8fbc94
Use gpu array list to avoid variable scoping issue in multiple-gpu ke…
Jul 17, 2024
450baec
Set useGPU to 2 as default
Jul 17, 2024
e0acfd4
Reduce parsing of for loops. Break fast
Jul 18, 2024
164d7be
Fix for massive allocations in check_launch()
Jul 18, 2024
bad13ac
Remove T=T in arguments inside kernel
Jul 18, 2024
971a15a
Move toggle_sfs condition outside loops
Jul 19, 2024
dbbf6ab
Adapt warmup function so that it compiles on all available gpus
rymanderson Jul 19, 2024
5456de9
addition to fluiddomain to allow Uinf included
BTV25 Jul 19, 2024
a34bafd
Perform self-interaction on one gpu for entire particle field when le…
rymanderson Jul 28, 2024
0d5243d
Add additional conditions for single self-interaction on gpu
rymanderson Jul 28, 2024
a11c782
Remove unnecessary view for GPU DtoH copy
Jul 28, 2024
ca301de
Reduce register pressure by using Int32 indices
rymanderson Jul 29, 2024
9d211ea
Correct dimension of target_system particles in gpu kernel
Jul 29, 2024
cf387d4
merge conflicts
rymanderson Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Manifest.toml
.ipynb_checkpoints
*.mem
temps
fmm.so
28 changes: 18 additions & 10 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@ authors = ["Eduardo J. Alvarez <[email protected]>"]
version = "3.0.2"

[deps]
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
JLD = "4138dd39-2aa7-5051-a626-17a0bb65d9c8"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
FastMultipole = "ce07d0d3-2b9f-49ba-89eb-12c800257c85"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
ImplicitAD = "e7cbb90b-9b31-4eb2-a8c8-45099c074ee1"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
FLOWExaFMM = "a07d1f4e-0e34-4d8b-bfef-e5b961477d34"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[compat]
julia = "1.6"
FLOWExaFMM = "2.1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
Cubature = "667455a9-e2ce-5579-9412-b964f529a492"
Elliptic = "b305315f-e792-5b7a-8f41-49f472929428"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
Elliptic = "b305315f-e792-5b7a-8f41-49f472929428"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Roots", "Cubature", "Elliptic", "LinearAlgebra", "DifferentialEquations", "ForwardDiff"]
3 changes: 1 addition & 2 deletions examples/roundjet/roundjet_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ function probeline_UW!(pfield, U, W, lines; Gamma=1e-10, sigma=1)
end

# Evaluate UJ
vpm._reset_particles(pfield)
pfield.UJ(pfield)
pfield.UJ(pfield; reset=true)

# Calculate freestream
Uinf::Array{<:Real, 1} = pfield.Uinf(pfield.t)
Expand Down
7 changes: 3 additions & 4 deletions examples/roundjet/roundjet_simulation.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#=##############################################################################
# DESCRIPTION
#=############################################################################## # DESCRIPTIO
Driver of round jet simulations.

# AUTHORSHIP
Expand Down Expand Up @@ -252,7 +251,7 @@ function run_roundjet_simulation(pfield::vpm.ParticleField,

if restart_sigma != nothing

# Evaluate current vorticity field (gets stored under P.Jexa[1:3])
# Evaluate current vorticity field (gets stored under get_J(P)[1:3])
vpm.zeta_fmm(pfield)

# Resize particle cores and store target vorticity under P.M[7:9]
Expand All @@ -261,7 +260,7 @@ function run_roundjet_simulation(pfield::vpm.ParticleField,
P.sigma[1] = restart_sigma

for i in 1:3
P.M[i+6] = P.Jexa[i]
P.M[i+6] = get_J(P)[i]
end
end

Expand Down
9 changes: 4 additions & 5 deletions examples/utilities/utilities_fluiddomain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ function computefluiddomain(pfield::vpm.ParticleField,
end

# Evaluate particle field
vpm._reset_particles(pfield)
t = @elapsed pfield.UJ(pfield)
t = @elapsed pfield.UJ(pfield; reset=true)

if verbose
println("\t"^(v_lvl)*"Evaluate UJ:\t\t$(round(t, digits=1)) s")
Expand Down Expand Up @@ -185,7 +184,7 @@ function computefluiddomain(pfield::vpm.ParticleField,

if add_Wapprox
Wapprox = grid.field["Wapprox"]["field_data"]
Wapprox .= (P.Jexa[i] for i in 1:3, P in particles)
Wapprox .= (get_J(P)[i] for i in 1:3, P in particles)
end

# Save fluid domain as VTK file
Expand Down Expand Up @@ -336,7 +335,7 @@ end
"""
computefluiddomain(maxparticles::Int, args...;
UJ::Function=vpm.UJ_fmm,
fmm::FLOWVPM.FMM=vpm.FMM(; p=4, ncrit=50, theta=0.4, phi=0.5),
fmm::FLOWVPM.FMM=vpm.FMM(; p=4, ncrit=50, theta=0.4, nonzero_sigma=true),
pfield_optargs=[]
optargs...)

Expand All @@ -350,7 +349,7 @@ field constructor.
"""
function computefluiddomain(maxparticles::Int, args...;
UJ=vpm.UJ_fmm,
fmm=vpm.FMM(; p=4, ncrit=50, theta=0.4, phi=0.5),
fmm=vpm.FMM(; p=4, ncrit=50, theta=0.4, nonzero_sigma=true),
pfield_optargs=[],
verbose=true, v_lvl=0,
optargs...)
Expand Down
2 changes: 1 addition & 1 deletion examples/vortexrings/run_leapfrog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ solver = (
transposed = true,
integration = vpm.rungekutta3,
UJ = vpm.UJ_fmm,
fmm = vpm.FMM(; p=4, ncrit=50, theta=0.4, phi=0.5)
fmm = vpm.FMM(; p=4, ncrit=50, theta=0.4, nonzero_sigma=true)
)


Expand Down
1 change: 0 additions & 1 deletion examples/vortexrings/vortexrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Roots
import Cubature
import Elliptic
import LinearAlgebra: I
import DifferentialEquations

try
# If this variable exist, we know we are running this as a unit test
Expand Down
47 changes: 23 additions & 24 deletions examples/vortexrings/vortexrings_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function calc_rings_unweighted!(outZ, outR, outsgm, pfield, nrings, intervals)
for pi in (intervals[ri]+1):(intervals[ri+1])

P = vpm.get_particle(pfield, pi)
outZ[ri] .+= P.X
outZ[ri] .+= vpm.get_X(P)

end
outZ[ri] ./= Np
Expand All @@ -248,8 +248,8 @@ function calc_rings_unweighted!(outZ, outR, outsgm, pfield, nrings, intervals)

P = vpm.get_particle(pfield, pi)

outR[ri] += sqrt((P.X[1] - outZ[ri][1])^2 + (P.X[2] - outZ[ri][2])^2 + (P.X[3] - outZ[ri][3])^2)
outsgm[ri] += P.sigma[1]
outR[ri] += sqrt((vpm.get_X(P)[1] - outZ[ri][1])^2 + (vpm.get_X(P)[2] - outZ[ri][2])^2 + (vpm.get_X(P)[3] - outZ[ri][3])^2)
outsgm[ri] += P[7]

end
outR[ri] /= Np
Expand All @@ -276,11 +276,11 @@ function calc_rings_weighted!(outZ, outR, outsgm, pfield, nrings, intervals)
for pi in (intervals[ri]+1):(intervals[ri+1])

P = vpm.get_particle(pfield, pi)
normGamma = norm(P.Gamma)
normGamma = norm(vpm.get_Gamma(P))
magGammatot += normGamma

for i in 1:3
outZ[ri][i] += normGamma*P.X[i]
outZ[ri][i] += normGamma*vpm.get_X(P)[i]
end

end
Expand All @@ -291,10 +291,10 @@ function calc_rings_weighted!(outZ, outR, outsgm, pfield, nrings, intervals)
for pi in (intervals[ri]+1):(intervals[ri+1])

P = vpm.get_particle(pfield, pi)
normGamma = norm(P.Gamma)
normGamma = norm(vpm.get_Gamma(P))

outR[ri] += normGamma*sqrt((P.X[1] - outZ[ri][1])^2 + (P.X[2] - outZ[ri][2])^2 + (P.X[3] - outZ[ri][3])^2)
outsgm[ri] += normGamma*P.sigma[1]
outR[ri] += normGamma*sqrt((vpm.get_X(P)[1] - outZ[ri][1])^2 + (vpm.get_X(P)[2] - outZ[ri][2])^2 + (vpm.get_X(P)[3] - outZ[ri][3])^2)
outsgm[ri] += normGamma*vpm.get_sigma(P)[]

end
outR[ri] /= magGammatot
Expand Down Expand Up @@ -325,7 +325,7 @@ function calc_rings_weightedW2!(outZ, outR, outsgm, pfield, nrings, intervals; z
magW2tot += W2

for i in 1:3
outZ[ri][i] += W2*P.X[i]
outZ[ri][i] += W2*vpm.get_X(P)[i]
end

end
Expand All @@ -341,12 +341,12 @@ function calc_rings_weightedW2!(outZ, outR, outsgm, pfield, nrings, intervals; z
P = vpm.get_particle(pfield, pi)

r = 0
for i in 1:3; r += (i!=zdir)*(P.X[i] - outZ[ri][i])^2; end;
for i in 1:3; r += (i!=zdir)*(vpm.get_X(P)[i] - outZ[ri][i])^2; end;
r = sqrt(r)

tht = zdir==1 ? atan(P.X[3], P.X[2]) :
zdir==2 ? atan(P.X[1], P.X[3]) :
atan(P.X[2], P.X[1])
tht = zdir==1 ? atan(vpm.get_X(P)[3], vpm.get_X(P)[2]) :
zdir==2 ? atan(vpm.get_X(P)[1], vpm.get_X(P)[3]) :
atan(vpm.get_X(P)[2], vpm.get_X(P)[1])

Wtht = zdir==1 ? vpm.get_W2(P)*cos(tht) + vpm.get_W3(P)*sin(tht) :
zdir==2 ? vpm.get_W3(P)*cos(tht) + vpm.get_W1(P)*sin(tht) :
Expand Down Expand Up @@ -386,22 +386,22 @@ function calc_elliptic_radius(outRm, outRp, Z, pfield, nrings, intervals;
for pi in (intervals[ri]+1):(intervals[ri+1])

P = vpm.get_particle(pfield, pi)
weightx = dot(P.Gamma, unity)
weighty = dot(P.Gamma, unitx)
weightx = dot(P[4:6], unity)
cibinjoseph marked this conversation as resolved.
Show resolved Hide resolved
weighty = dot(P[4:6], unitx)

if P.X[1]-Z[ri][1] < 0
outRm[ri][1] -= abs(weightx*P.X[1])
if vpm.get_X(P)[1]-Z[ri][1] < 0
outRm[ri][1] -= abs(weightx*vpm.get_X(P)[1])
weightxmtot += abs(weightx)
else
outRp[ri][1] += abs(weightx*P.X[1])
outRp[ri][1] += abs(weightx*vpm.get_X(P)[1])
weightxptot += abs(weightx)
end

if P.X[2]-Z[ri][2] < 0
outRm[ri][2] -= abs(weighty*P.X[2])
if vpm.get_X(P)[2]-Z[ri][2] < 0
outRm[ri][2] -= abs(weighty*vpm.get_X(P)[2])
weightymtot += abs(weighty)
else
outRp[ri][2] += abs(weighty*P.X[2])
outRp[ri][2] += abs(weighty*vpm.get_X(P)[2])
weightyptot += abs(weighty)
end

Expand Down Expand Up @@ -545,8 +545,7 @@ function calc_vorticity!(pfield, ws, Xs, xoRs, nrings, Z, R, probedir;
end

# Evaluate UJ
vpm._reset_particles(pfield)
pfield.UJ(pfield)
pfield.UJ(pfield; reset=true)

# Save vorticity at probes
for ri in 1:nrings
Expand All @@ -556,7 +555,7 @@ function calc_vorticity!(pfield, ws, Xs, xoRs, nrings, Z, R, probedir;
ws[1, pi, ri] = vpm.get_W1(P)
ws[2, pi, ri] = vpm.get_W2(P)
ws[3, pi, ri] = vpm.get_W3(P)
Xs[:, pi, ri] .= P.X
Xs[:, pi, ri] .= P[1:3]
cibinjoseph marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down
80 changes: 72 additions & 8 deletions examples/vortexrings/vortexrings_postprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,70 @@ end

plot_dynamics1n2 = plot_dynamics

"""
solve(derivative!, u0, tspan; dt, verbose, p)

Solve the ode using a simple forward euler step. (Eliminates DifferentialEquations as a dependency.)

# Arguments

- `derivative!::Function`- computes the derivative in place, as `derivative!(du, u, p, t)`, where `du` is the derivative, `u` the current state, `p` parameters, and `t` the current time
- `u0::Vector{Float64}`- vector of the initial states
- `tspan::Tuple{Float64,Float64}`- tuple containing the initial and final times
- `dt::Float64`- time step
- `verbose::Bool`- whether or not to use verbose output
- `p::NTuple{N,Any}`- tuple of parameters required by the `derivative!` function

# Returns

- `t::Range`- time vector
- `u::Vector{Vector{Float64}}`- vector of time solutions of each state; `u[i][j]` contains the value of the i-th state at the j-th time
"""
function solve(derivative!, u0, tspan; dt=1e-7, verbose=false, p=())
verbose && (println("== SOLVE DIFFERENTIAL EQUATION ==\n"))
t = range(tspan[1], tspan[2], step=dt)
if t[end] != tspan[2]
t = vcat(collect(t), tspan[end])
end
n_points = length(t)
n_states = length(u0)
u = [zeros(n_points) for _ in 1:n_states]

# initial conditions
for i_state in eachindex(u0)
u[i_state][1] = u0[i_state]
end

# set up state and derivative containers
this_u = deepcopy(u0)
this_u_dot = similar(u0)

# step through time
verbose && (println("\tBegin Euler steps:"))
for i_point in 2:n_points
previous_time = t[i_point-1]
this_dt = t[i_point] - previous_time
# verbose && (println("\t\tt=$(round(previous_time,digits=4)), u=$(this_u)"))

# update this_u
for i_state in eachindex(u0)
this_u[i_state] = u[i_state][i_point-1]
end

# update derivative
derivative!(this_u_dot, this_u, p, previous_time)

# euler step
for i_state in 1:n_states
u[i_state][i_point] = u[i_state][i_point-1] + this_u_dot[i_state] * this_dt
end
# i_point == n_points && verbose && (println("\t\tt=$(round(t[n_points],digits=4)), u=$(this_u)"))
end

verbose && (println("== DONE =="))
# return result
return t, u
end

"""
Solve dynamics of a system of coaxial inviscid rings using the analytic system
Expand All @@ -124,7 +188,7 @@ associated with vorticity distribution inside the ring core (Winckelmans' kernel
corresponds to `Delta=0`).
"""
function analytic_coaxialrings(nrings, Gammas, Rs, Zs, as, Deltas;
tend=20.0, dtmax=0.1, dynamica=true, nu=nothing,
tend=20.0, dtmax=1e-3, dynamica=true, nu=nothing,
thickgaussian=false)

# Initial conditions
Expand Down Expand Up @@ -207,15 +271,15 @@ function analytic_coaxialrings(nrings, Gammas, Rs, Zs, as, Deltas;
# Time span
tspan = (0.0, tend)

prob = DifferentialEquations.ODEProblem(borisov2013!, u0, tspan)
sol = DifferentialEquations.solve(prob; dtmax=dtmax, verbose=true)
# prob = DifferentialEquations.ODEProblem(borisov2013!, u0, tspan)
# sol = DifferentialEquations.solve(prob; dtmax=dtmax, verbose=true)
t, u = solve(borisov2013!, u0, tspan; dt=dtmax/10, verbose=true)

ts = sol.t
solRs = [[u[5*(ri-1) + 2] for u in sol.u] for ri in 1:nrings]
solZs = [[u[5*(ri-1) + 3] for u in sol.u] for ri in 1:nrings]
solas = [[u[5*(ri-1) + 4] for u in sol.u] for ri in 1:nrings]
solRs = [u[5*(ri-1) + 2] for ri in 1:nrings]
solZs = [u[5*(ri-1) + 3] for ri in 1:nrings]
solas = [u[5*(ri-1) + 4] for ri in 1:nrings]

return sol.t, solRs, solZs, solas, sol
return t, solRs, solZs, solas
end

K(k) = Elliptic.K(k^2)
Expand Down
4 changes: 2 additions & 2 deletions examples/vortexrings/vortexrings_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function run_vortexring_simulation(pfield::vpm.ParticleField,

if restart_sigma != nothing

# Evaluate current vorticity field (gets stored under P.Jexa[1:3])
# Evaluate current vorticity field (gets stored under get_J(P)[1:3])
vpm.zeta_fmm(pfield)

# Resize particle cores and store target vorticity under P.M[7:9]
Expand All @@ -136,7 +136,7 @@ function run_vortexring_simulation(pfield::vpm.ParticleField,
P.sigma[1] = restart_sigma

for i in 1:3
P.M[i+6] = P.Jexa[i]
P.M[i+6] = get_J(P)[i]
end
end

Expand Down
Loading