licenses
sequencelengths
1
3
version
stringclasses
677 values
tree_hash
stringlengths
40
40
path
stringclasses
1 value
type
stringclasses
2 values
size
stringlengths
2
8
text
stringlengths
25
67.1M
package_name
stringlengths
2
41
repo
stringlengths
33
86
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
1890
## ## A stegosaur with a top hat? ## """ function stegosaurus() A stegosaur with a top hat? # Example ```jldoctest julia> cowsay("How do you do?", cow=Cowsay.stegosaurus) ________________ < How do you do? > ---------------- \\ . . \\ / `. .' " \\ .---. < > < > .---. \\ | \\ \\ - ~ ~ - / / | _____ ..-~ ~-..-~ | | \\~~~\\.' `./~~~/ --------- \\__/ \\__/ .' O \\ / / \\ " (_____, `._.' | } \\/~~~/ `----. / } | / \\__/ `-. | / | / `. ,~~| ~-.__| /_ - ~ ^| /- _ `..-' | / | / ~-. `-. _ _ _ |_____| |_____| ~ - . _ _ _ _ _> ``` """ function stegosaurus(;eyes="oo", tongue=" ", thoughts="\\") the_cow = """ $thoughts . . $thoughts / `. .' " $thoughts .---. < > < > .---. $thoughts | \\ \\ - ~ ~ - / / | _____ ..-~ ~-..-~ | | \\~~~\\.' `./~~~/ --------- \\__/ \\__/ .' O \\ / / \\ " (_____, `._.' | } \\/~~~/ `----. / } | / \\__/ `-. | / | / `. ,~~| ~-.__| /_ - ~ ^| /- _ `..-' | / | / ~-. `-. _ _ _ |_____| |_____| ~ - . _ _ _ _ _> """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
687
""" function supermilker() A cow being milked, probably from Lars Smith ([email protected]) # Example ```jldoctest julia> cowsay("Paying the bills", cow=Cowsay.supermilker) __________________ < Paying the bills > ------------------ \\ ^__^ \\ (oo)\\_______ ________ (__)\\ )\\/\\ |Super | ||----W | |Milker| || UDDDDDDDDD|______| ``` """ function supermilker(;eyes="oo", tongue=" ", thoughts="\\") the_cow = """ $thoughts ^__^ $thoughts ($eyes)\\_______ ________ (__)\\ )\\/\\ |Super | $tongue ||----W | |Milker| || UDDDDDDDDD|______| """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
1467
## ## A cow operation, artist unknown ## """ function surgery() A cow operation, artist unknown # Example ```jldoctest julia> cowsay("Removing the last bit of net wrap now", cow=Cowsay.surgery) _______________________________________ < Removing the last bit of net wrap now > --------------------------------------- \\ \\ / \\ \\/ (__) /\\ (oo) O O _\\/_ // * ( ) // \\ (\\\\ // \\( \\\\ ) ( \\\\ ) /\\ ___[\\______/^^^^^^^\\__/) o-)__ |\\__[=======______//________)__\\ \\|_______________//____________| ||| || //|| ||| ||| || @.|| ||| || \\/ .\\/ || . . '.'.` COW-OPERATION ``` """ function surgery(;eyes="oo", tongue=" ", thoughts="\\") the_cow = """ $thoughts \\ / $thoughts \\/ (__) /\\ ($eyes) O O _\\/_ // * ( ) // \\ (\\\\ // \\( \\\\ ) ( \\\\ ) /\\ ___[\\______/^^^^^^^\\__/) o-)__ |\\__[=======______//________)__\\ \\|_______________//____________| ||| || //|| ||| ||| || @.|| ||| || \\/ .\\/ || . . '.'.` COW-OPERATION """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
717
""" function three_eyes() A cow with three eyes, brought to you by [email protected] # Example ```jldoctest julia> cowsay("The better to see you with...", cow=Cowsay.three_eyes) _______________________________ < The better to see you with... > ------------------------------- \\ ^___^ \\ (ooo)\\_______ (___)\\ )\\/\\ ||----w | || || ``` """ function three_eyes(;eyes="oo", tongue=" ", thoughts="\\") eye = first(eyes) eyes = repeat(eye, 3) the_cow = """ $thoughts ^___^ $thoughts ($eyes)\\_______ (___)\\ )\\/\\ $tongue ||----w | || || """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
2779
## ## Turkey! ## """ function turkey() Turkey! # Example ```jldoctest julia> cowsay("Gobble, gobble", cow=Cowsay.turkey) ________________ < Gobble, gobble > ---------------- \\ ,+*^^*+___+++_ \\ ,*^^^^ ) \\ _+* ^**+_ \\ +^ _ _++*+_+++_, ) _+^^*+_ ( ,+*^ ^ \\+_ ) { ) ( ,( ,_+--+--, ^) ^\\ { (@) } f ,( ,+-^ __*_*_ ^^\\_ ^\\ ) {:;-/ (_+*-+^^^^^+*+*<_ _++_)_ ) ) / ( / ( ( ,___ ^*+_+* ) < < \\ U _/ ) *--< ) ^\\-----++__) ) ) ) ( ) _(^)^^)) ) )\\^^^^^))^*+/ / / ( / (_))_^)) ) ) ))^^^^^))^^^)__/ +^^ ( ,/ (^))^)) ) ) ))^^^^^^^))^^) _) *+__+* (_))^) ) ) ))^^^^^^))^^^^^)____*^ \\ \\_)^)_)) ))^^^^^^^^^^))^^^^) (_ ^\\__^^^^^^^^^^^^))^^^^^^^) ^\\___ ^\\__^^^^^^))^^^^^^^^)\\\\ ^^^^^\\uuu/^^\\uuu/^^^^\\^\\^\\^\\^\\^\\^\\^\\ ___) >____) >___ ^\\_\\_\\_\\_\\_\\_\\) ^^^//\\\\_^^//\\\\_^ ^(\\_\\_\\_\\) ^^^ ^^ ^^^ ^ ``` """ function turkey(;eyes="oo", tongue=" ", thoughts="\\") the_cow = """ $thoughts ,+*^^*+___+++_ $thoughts ,*^^^^ ) $thoughts _+* ^**+_ $thoughts +^ _ _++*+_+++_, ) _+^^*+_ ( ,+*^ ^ \\+_ ) { ) ( ,( ,_+--+--, ^) ^\\ { (@) } f ,( ,+-^ __*_*_ ^^\\_ ^\\ ) {:;-/ (_+*-+^^^^^+*+*<_ _++_)_ ) ) / ( / ( ( ,___ ^*+_+* ) < < \\ U _/ ) *--< ) ^\\-----++__) ) ) ) ( ) _(^)^^)) ) )\\^^^^^))^*+/ / / ( / (_))_^)) ) ) ))^^^^^))^^^)__/ +^^ ( ,/ (^))^)) ) ) ))^^^^^^^))^^) _) *+__+* (_))^) ) ) ))^^^^^^))^^^^^)____*^ \\ \\_)^)_)) ))^^^^^^^^^^))^^^^) (_ ^\\__^^^^^^^^^^^^))^^^^^^^) ^\\___ ^\\__^^^^^^))^^^^^^^^)\\\\ ^^^^^\\uuu/^^\\uuu/^^^^\\^\\^\\^\\^\\^\\^\\^\\ ___) >____) >___ ^\\_\\_\\_\\_\\_\\_\\) ^^^//\\\\_^^//\\\\_^ ^(\\_\\_\\_\\) ^^^ ^^ ^^^ ^ """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
2414
""" function turtle() A mysterious turtle... # Example ```jldoctest julia> cowsay("Where is that pesky rabbit?", cow=Cowsay.turtle) _____________________________ < Where is that pesky rabbit? > ----------------------------- \\ ___-------___ \\ _-~~ ~~-_ \\ _-~ /~-_ /^\\__/^\\ /~ \\ / \\ /| O|| O| / \\_______________/ \\ | |___||__| / / \\ \\ | \\ / / \\ \\ | (_______) /______/ \\_________ \\ | / / \\ / \\ \\ \\^\\\\ \\ / \\ / \\ || \\______________/ _-_ //\\__// \\ ||------_-~~-_ ------------- \\ --/~ ~\\ || __/ ~-----||====/~ |==================| |/~~~~~ (_(__/ ./ / \\_\\ \\. (_(___/ \\_____)_) ``` """ function turtle(;eyes="oo", tongue=" ", thoughts="\\") the_cow = """ $thoughts ___-------___ $thoughts _-~~ ~~-_ $thoughts _-~ /~-_ /^\\__/^\\ /~ \\ / \\ /| O|| O| / \\_______________/ \\ | |___||__| / / \\ \\ | \\ / / \\ \\ | (_______) /______/ \\_________ \\ | / / \\ / \\ \\ \\^\\\\ \\ / \\ / \\ || \\______________/ _-_ //\\__// \\ ||------_-~~-_ ------------- \\ --/~ ~\\ || __/ ~-----||====/~ |==================| |/~~~~~ (_(__/ ./ / \\_\\ \\. (_(___/ \\_____)_) """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
630
## ## """ function tux() TuX (c) [email protected] # Example ```jldoctest julia> cowsay("Talk is cheap. Show me the code.", cow=Cowsay.tux) __________________________________ < Talk is cheap. Show me the code. > ---------------------------------- \\ \\ .--. |o_o | |:_/ | // \\ \\ (| | ) /'\\_ _/`\\ \\___)=(___/ ``` """ function tux(;eyes="oo", tongue=" ", thoughts="\\") the_cow = """ $thoughts $thoughts .--. |o_o | |:_/ | // \\ \\ (| | ) /'\\_ _/`\\ \\___)=(___/ """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
770
""" function udder() The cow from a file called cow-n-horn, artist unknown. # Example ```jldoctest julia> cowsay("Milking time!", cow=Cowsay.udder) _______________ < Milking time! > --------------- \\ \\ (__) o o\\ ('') \\--------- \\ \\ | |\\ ||---( )_|| * || UU || == == ``` """ function udder(;eyes="oo", tongue=" ", thoughts="\\") eye1 = first(eyes) eye2 = last(eyes) botheyes = string(eye1, " ", eye2) the_cow = """ $thoughts $thoughts (__) $botheyes\\ ('') \\--------- $tongue\\ \\ | |\\ ||---( )_|| * || UU || == == """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
589
""" function vader_koala Another canonical koala? # Example ```jldoctest julia> cowsay("Luke, you are my joey!", cow=Cowsay.vader_koala) ________________________ < Luke, you are my joey! > ------------------------ \\ \\ . .---. // Y|o o|Y// /_(i=i)K/ ~()~*~()~ (_)-(_) Darth Vader koala ``` """ function vader_koala(;eyes="oo", tongue=" ", thoughts="\\") the_cow = """ $thoughts $thoughts . .---. // Y|o o|Y// /_(i=i)K/ ~()~*~()~ (_)-(_) Darth Vader koala """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
723
""" function vader() Cowth Vader, from [email protected] # Example ```jldoctest julia> cowsay("Luke, I am your father!", cow=Cowsay.vader) _________________________ < Luke, I am your father! > ------------------------- \\ ,-^-. \\ !oYo! \\ /./=\\.\\______ ## )\\/\\ ||-----w|| || || Cowth Vader ``` """ function vader(;eyes="oo", tongue=" ", thoughts="\\") the_cow = """ $thoughts ,-^-. $thoughts !oYo! $thoughts /./=\\.\\______ ## )\\/\\ ||-----w|| || || Cowth Vader """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
648
""" function www() A cow wadvertising the World Wide Web, from [email protected] # Example ```jldoctest julia> cowsay("My favorite site is MooTube", cow=Cowsay.www) _____________________________ < My favorite site is MooTube > ----------------------------- \\ ^__^ \\ (oo)\\_______ (__)\\ )\\/\\ ||--WWW | || || ``` """ function www(;eyes="oo", tongue=" ", thoughts="\\") the_cow = """ $thoughts ^__^ $thoughts ($eyes)\\_______ (__)\\ )\\/\\ $tongue ||--WWW | || || """ return the_cow end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
code
4240
using Cowsay using Test using Documenter DocMeta.setdocmeta!(Cowsay, :DocTestSetup, :(using Cowsay); recursive=true) @testset "cowsay" begin @testset "Doctests" begin doctest(Cowsay) end @testset "Balloon Formation" begin # One-liner say balloon @test Cowsay.sayballoon("One line") == " __________\n< One line >\n ----------\n" # Two-liner say balloon @test Cowsay.sayballoon("One line\nTwo line") == " __________\n/ One line \\\n\\ Two line /\n ----------\n" # Multi-liner say balloon @test Cowsay.sayballoon("One line\nTwo line\nRed line\nBlue line") == " ___________\n/ One line \\\n| Two line |\n| Red line |\n\\ Blue line /\n -----------\n" end @testset "IO Funkiness" begin # Cowsay with io redirection @test_warn cowsaid("Moo") cowsay(stderr, "Moo") # Cowthink with io redirection @test_warn cowthunk("Moo") cowthink(stderr, "Moo") end @testset "Word Wrapping" begin # Long text, default wrap @test cowsaid("Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo") == " _________________________________________\n/ Rollin' down a long highway out through \\\n| New Mexico driftin' down to Santa Fe to |\n\\ ride a bull in a rodeo /\n -----------------------------------------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||\n" # Long text, no wrap @test cowsaid("Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo", nowrap=true) == " ________________________________________________________________________________________________________\n< Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo >\n --------------------------------------------------------------------------------------------------------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||\n" # Long text, conflicting wrap instructions (nowrap should win) @test cowsaid("Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo", wrap=80, nowrap=true) == " ________________________________________________________________________________________________________\n< Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo >\n --------------------------------------------------------------------------------------------------------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||\n" # Long text, different wrap amount @test cowsaid("Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo", wrap=80) == " _________________________________________________________________________________\n/ Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to \\\n\\ ride a bull in a rodeo /\n ---------------------------------------------------------------------------------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||\n" end @testset "Cow Modes" begin @test Cowsay.construct_face!("oo", " ") == ("oo", " ") @test Cowsay.construct_face!("oo", " "; borg=true) == ("==", " ") @test Cowsay.construct_face!("oo", " "; dead=true) == ("xx", "U ") @test Cowsay.construct_face!("oo", " "; greedy=true) == ("\$\$", " ") @test Cowsay.construct_face!("oo", " "; paranoid=true) == ("@@", " ") @test Cowsay.construct_face!("oo", " "; stoned=true) == ("**", "U ") @test Cowsay.construct_face!("oo", " "; tired=true) == ("--", " ") @test Cowsay.construct_face!("oo", " "; wired=true) == ("OO", " ") @test Cowsay.construct_face!("oo", " "; young=true) == ("..", " ") end end
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
docs
1862
# Changelog All notable changes to Cowsay.jl will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased ### Added - Cow "modes" (Borg, dead, greedy, etc.) ## [v0.3.1] - 2022-02-01 ### Fixed - Newlines in input message are no longer stripped out during text wrapping ## [v0.3.0] - 2022-02-01 ### Added - `cowsaid` and `cowthunk` functions for getting cow art without printing it - Optional IO choice for `cowsay` and `cowthink` functions - Automatic text wrapping ## [v0.2.1] - 2022-01-11 ### Added - `cowthink` function ## [v0.2.0] - 2021-11-29 ### Added - Unit testing via `jldoctest` - Ability to customize cow art - Ability to customize cow eyes - Ability to customize cow tongue - New cow artwork - blowfish - bunny - cower - dragon_and_cow - dragon - elephant_in_snake - elephant - eyes - flaming_sheep - fox - kitty - koala - mech_and_cow - meow - moofasa - moose - mutilated - sheep - skeleton - small - stegosaurus - supermilker - surgery - three_eyes - turkey - turtle - tux - udder - vader_koala - vader - www ### Changed - Default cow abstracted to `Cowsay.default` function ## [v0.1.0] - 2021-09-23 (Unregistered) ### Added - `cowsay` function for Julia in package format [unreleased]: https://github.com/MillironX/Cowsay.jl/compare/v0.3.1...HEAD [v0.3.0]: https://github.com/MillironX/Cowsay.jl/compare/v0.3.0...v0.3.1 [v0.3.0]: https://github.com/MillironX/Cowsay.jl/compare/v0.2.1...v0.3.0 [v0.2.1]: https://github.com/MillironX/Cowsay.jl/compare/v0.2.0...v0.2.1 [v0.2.0]: https://github.com/MillironX/Cowsay.jl/compare/v0.1.0...v0.2.0 [v0.1.0]: https://github.com/MillironX/Cowsay.jl/releases/tag/v0.1.0
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
docs
4523
# Cowsay.jl ```plaintext ___________________ < Cowsay for Juila! > ------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || ``` [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://millironx.com/Cowsay.jl/stable) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://millironx.com/Cowsay.jl/dev) [![Build Status](https://github.com/MillironX/Cowsay.jl/workflows/CI/badge.svg)](https://github.com/MillironX/Cowsay.jl/actions) [![Coverage](https://codecov.io/gh/MillironX/Cowsay.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/MillironX/Cowsay.jl) [![Genie Downloads](https://shields.io/endpoint?url=https://pkgs.genieframework.com/api/v1/badge/Cowsay)](https://pkgs.genieframework.com?packages=Cowsay) A talking cow library for Julia, based on the [Fedora release of cowsay](https://src.fedoraproject.org/rpms/cowsay). ## Installation You can install straight from the [Julia REPL]. Press `]` to enter [pkg mode], then: ```julia add Cowsay ``` ## Usage Complete usage info can be found in [the documentation]. Cowsay.jl exports two functions: `cowsay` and `cowthink`, which print an ASCII cow saying or thinking a message, respectively. ```julia-repl julia> using Cowsay julia> cowsay("Bessie the heifer\nthe queen of all the cows.") ____________________________ / Bessie the heifer: \ \ the queen of all the cows. / ---------------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || julia> cowthink("The farmers who have no livestock,\ntheir lives simply aren't the best") ____________________________________ ( The farmers who have no livestock, ) ( their lives simply aren't the best ) ------------------------------------ o ^__^ o (oo)\_______ (__)\ )\/\ ||----w | || || ``` If you want to use talking cows in your program, use the `cowsaid` and `cowthunk` functions to get strings of the cow art. ```julia-repl julia> @info string("\n", cowsaid("And the longhorns lowed him a welcome\nAs a new voice cried from the buckboard")) ┌ Info: │ _________________________________________ │ / And the longhorns lowed him a welcome \ │ \ As a new voice cried from the buckboard / │ ----------------------------------------- │ \ ^__^ │ \ (oo)\_______ │ (__)\ )\/\ │ ||----w | └ || || ``` There are also plenty of [unexported Cowfiles] that you can use to customize your art. ```julia-repl julia> cowsay("This heifer must be empty\n'Cuz she ain't puttin' out", cow=Cowsay.udder) ____________________________ / This heifer must be empty \ \ 'Cuz she ain't puttin' out / ---------------------------- \ \ (__) o o\ ('') \--------- \ \ | |\ ||---( )_|| * || UU || == == ``` You can also change the eyeballs and tongue of your cow. ```julia-repl julia> cowsay("You better watch your step\nwhen you know the chips are down!", tongue=" U", eyes="00") ___________________________________ / You better watch your step \ \ when you know the chips are down! / ----------------------------------- \ ^__^ \ (00)\_______ (__)\ )\/\ U ||----w | || || ``` And even change its emotional or physical state using modes. ```julia-repl julia> cowsay("He mooed we must fight\nEscape or we'll die\nCows gathered around\n'Cause the steaks were so high"; dead=true) ________________________________ / He mooed we must fight \ | Escape or we'll die | | Cows gathered around | \ 'Cause the steaks were so high / -------------------------------- \ ^__^ \ (xx)\_______ (__)\ )\/\ U ||----w | || || ``` ## Contributing If you find a bug in Cowsay.jl, please [file an issue]. I will not be accepting any requests for new cowfiles in this repo, though. [file an issue]: https://github.com/MillironX/Cowsay.jl/issues [julia repl]: https://docs.julialang.org/en/v1/manual/getting-started/ [pkg mode]: https://docs.julialang.org/en/v1/stdlib/Pkg/ [the documentation]: https://millironx.com/Cowsay.jl/stable [unexported cowfiles]: https://millironx.com/Cowsay.jl/stable/cows/
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
docs
1671
# Making a cow function The original cowsay used Perl scripts (called 'cowfiles') to allow for creating more ASCII cow art. Cowsay.jl uses Julia functions, instead. In order to be usable by `Cowsay.cowsay`, a cow function **must** 1. Take the correct arguments The function must take three (3) [keyword arguments](https://docs.julialang.org/en/v1/manual/functions/#Keyword-Arguments) of the form - `eyes::AbstractString="oo"` - `tongue::AbstractString=" "` - `thoughts::AbstractString="\\"` When drawing the cow artwork, you may then use the variables `eyes` in place of the eyes, `tongue` in place of the tongue, and `thoughts` in place of the speech ballon trail. Use of these variables in constructing the cow is optional (but makes the use of your cow function far more fun), but all three arguments must be present in the signature, regardless. 2. Return a string The cow artwork must be returned from the function as a string. This is distinctly different from how the original cowsay modified the `$the_cow` variable. ## Helpful hints for making cow functions 1. Include one function per file, with the extension `.cow.jl` 2. Do not indent within a `.cow.jl` file to better see the artwork 3. Make use of string literals (`"""`) and string interpolation (`$`) to build the cow art 4. Be sure to escape backslashes (`\`) and dollar signs (`$`) within your artwork 5. When converting from Perl cowfiles, _unescape_ at symbols (`@`), as these are **not** special in Julia strings 6. Split the `eyes` variable to get individual left- and right-eye when creating large cow functions 7. Have fun!
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
docs
647
# Cows Examples of all the cowfiles available. ## Bovine ```@docs Cowsay.default Cowsay.cower Cowsay.moofasa Cowsay.mutilated Cowsay.skeleton Cowsay.small Cowsay.supermilker Cowsay.three_eyes Cowsay.udder Cowsay.vader Cowsay.www ``` ## Mascots ```@docs Cowsay.blowfish Cowsay.elephant Cowsay.tux ``` ## Cows and friends ```@docs Cowsay.dragon_and_cow Cowsay.mech_and_cow Cowsay.surgery ``` ## Other ```@docs Cowsay.bunny Cowsay.dragon Cowsay.elephant_in_snake Cowsay.eyes Cowsay.flaming_sheep Cowsay.fox Cowsay.kitty Cowsay.koala Cowsay.meow Cowsay.moose Cowsay.sheep Cowsay.stegosaurus Cowsay.turkey Cowsay.turtle Cowsay.vader_koala ```
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
1.0.0
193ec7cad29c4099823e7a0d853b4173ad5d3ab1
docs
208
```@meta CurrentModule = Cowsay ``` # Cowsay.jl A Julia package that lets you use [cowsay](https://en.wikipedia.org/wiki/Cowsay) in your Julia programs! ## Usage ```@docs Cowsay.cowsay Cowsay.cowsaid ```
Cowsay
https://github.com/MillironX/Cowsay.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
311
using Pkg; Pkg.add("Documenter") using Documenter, GeneralizedSasakiNakamura makedocs( sitename="GeneralizedSasakiNakamura.jl", format = Documenter.HTML( prettyurls = get(ENV, "CI", nothing) == "true" ) ) deploydocs( repo = "github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git", )
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
114325
module AsymptoticExpansionCoefficients using TaylorSeries using ..Kerr using ..Coordinates export outgoing_coefficient_at_inf, ingoing_coefficient_at_inf export outgoing_coefficient_at_hor, ingoing_coefficient_at_hor const I = 1im # Mathematica being Mathematica _DEFAULTDATATYPE = ComplexF64 # Double precision by default function PminusInf_z(s::Int, m::Int, a, omega, lambda, z) if s == 0 return begin -((2*I*(omega + a^2*z^4*(-I + a^2*omega) + z^2*(I + 2*a^2*omega)))/ ((1 + a^2*z^2)*(1 - 2*z + a^2*z^2))) end elseif s == 1 return begin ((1 + a^2*z^2)*(-((2*(-1 + z)*z)/(1 + a^2*z^2)) - (2*z*(1 - 2*z + a^2*z^2))/ (1 + a^2*z^2)^2 + (2*a*z^2*(1 - 2*z + a^2*z^2)*((-I)*m*(1 + 3*a^2*z^2) + a*z*(3 + 3*z + 2*lambda + 2*a^2*z^2*(1 + lambda))))/((1 + a^2*z^2)* (2 - 2*I*a*m*z - 2*I*a^3*m*z^3 + lambda + a^4*z^4*(1 + lambda) + a^2*z^2*(3 + 2*z + 2*lambda))) - 2*I*omega))/(1 - 2*z + a^2*z^2) end elseif s == -1 return begin (1/(1 - 2*z + a^2*z^2))*((1 + a^2*z^2)*(-((2*(-1 + z)*z)/(1 + a^2*z^2)) - (2*z*(1 - 2*z + a^2*z^2))/(1 + a^2*z^2)^2 + (2*a*z^2*(1 - 2*z + a^2*z^2)*(I*m*(1 + 3*a^2*z^2) + a*z*(-1 + 3*z + 2*a^2*z^2*(-1 + lambda) + 2*lambda)))/ ((1 + a^2*z^2)*(2*I*a*m*z + 2*I*a^3*m*z^3 + a^4*z^4*(-1 + lambda) + lambda + a^2*z^2*(-1 + 2*z + 2*lambda))) - 2*I*omega)) end elseif s == 2 return begin (1/(1 - 2*z + a^2*z^2))*((1 + a^2*z^2)*(-((2*(-1 + z)*z)/(1 + a^2*z^2)) - (2*z*(1 - 2*z + a^2*z^2))/(1 + a^2*z^2)^2 - 2*I*omega + (8*a*z^2*(1 - 2*z + a^2*z^2)*(-6*a*m^2*z + I*m*(-4 + 9*a^2*z^2 - lambda + z*(-6 - 12*I*a^2*omega)) + a*(6*a^2*z^3 + I*(1 + lambda)*omega + z^2*(-9 - 9*I*a^2*omega) + z*(3 + 6*I*omega - 6*a^2*omega^2))))/((1 + a^2*z^2)*(24 + 10*lambda + lambda^2 - 4*I*a*m*(6*z^2 + 2*z*(4 + lambda) + 3*I*omega) + 12*I*omega + 24*a^3*m*z^2*(I*z + 2*omega) + 12*a^4*z^2*(z^2 - 2*I*z*omega - 2*omega^2) - 4*a^2*(6*z^3 + z^2*(-3 + 6*m^2 - 6*I*omega) - 2*I*z*(1 + lambda)*omega + 3*omega^2))))) end elseif s == -2 return begin (1/(1 - 2*z + a^2*z^2))*((1 + a^2*z^2)*(-((2*(-1 + z)*z)/(1 + a^2*z^2)) - (2*z*(1 - 2*z + a^2*z^2))/(1 + a^2*z^2)^2 - 2*I*omega + (8*a*z^2*(1 - 2*z + a^2*z^2)*(I*m*(6*z + lambda) + 3*a^2*m*z*(-3*I*z + 4*omega) - a*(9*z^2 + z*(-3 + 6*m^2 + 6*I*omega) + I*(-3 + lambda)*omega) + 3*a^3*z*(2*z^2 + 3*I*z*omega - 2*omega^2)))/ ((1 + a^2*z^2)*(2*lambda + lambda^2 - 12*I*omega + 24*a^3*m*z^2*((-I)*z + 2*omega) + 4*a*m*(6*I*z^2 + 2*I*z*lambda + 3*omega) + 12*a^4*z^2*(z^2 + 2*I*z*omega - 2*omega^2) - 4*a^2*(6*z^3 + z^2*(-3 + 6*m^2 + 6*I*omega) + 2*I*z*(-3 + lambda)*omega + 3*omega^2))))) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function QminusInf_z(s::Int, m::Int, a, omega, lambda, z) if s == 0 return begin -((z^2*(-2*z*(-1 + lambda) + lambda - 4*a^2*z^3*(1 + lambda) - 2*a^4*z^5*(3 + lambda) + 2*a*m*omega + a^6*z^6*(1 - m^2 + lambda + 2*a*m*omega) + a^2*z^4*(8 + a^2*(2 - 2*m^2 + 3*lambda) + 6*a^3*m*omega) + z^2*(-4 + a^2*(1 - m^2 + 3*lambda) + 6*a^3*m*omega)))/ ((1 + a^2*z^2)^2*(1 - 2*z + a^2*z^2)^2)) end elseif s == 1 return begin (z^2*(-4 - lambda^2 + 2*a^12*z^12*(1 + lambda) - 8*a*m*omega - 4*I*a^10*z^11*(1 + lambda)* (-3*I + a^2*omega) - 2*lambda*(2 + a*m*omega) - a^4*z^6*(52 + 32*lambda + 2*I*a*m*(31 + 6*lambda) + a^2*(71 + 10*lambda^2 - 3*m^2*(3 + 2*lambda) + 8*lambda*(7 - 6*I*omega)) + 4*a^3*m*(17 + 5*lambda)*omega) + 2*a^6*z^9*(8 - 6*I*a*m + a^2*(-3 + 3*m^2 - 4*lambda + lambda^2 + 4*I*omega) + 2*I*a^4*(m^2 - 5*(1 + lambda))*omega + a^3*m*(4*I - I*m^2 + I*lambda + 2*omega)) + 2*z*((2 + lambda)^2 + 2*I*a^2*(-1 + m^2 - lambda)*omega + a*m*(2*I + I*lambda + 4*omega)) + 2*a^3*z^5*(14*I*m + a*(69 - m^2 + 48*lambda + 6*lambda^2 + 28*I*omega) + 4*I*a^3*(3*m^2 - 5*(1 + lambda))*omega + 3*a^2*m*(6*I - I*m^2 + 2*I*lambda + 6*omega)) + 2*a^4*z^7*(-4 + 8*I*a*m + 4*a^2*(10 + m^2 + 7*lambda + lambda^2 + 5*I*omega) + 4*I*a^4*(2*m^2 - 5*(1 + lambda))*omega + a^3*m*(14*I - 3*I*m^2 + 4*I*lambda + 10*omega)) + 2*a^2*z^3*(36 - 2*m^2 + 26*lambda + 4*lambda^2 + 12*I*omega + 2*I*a^2*(4*m^2 - 5*(1 + lambda))*omega + a*m*(10*I - I*m^2 + 4*I*lambda + 14*omega)) - a^8*z^10*(-6*I*a*m - 8*(1 + 2*lambda) + 2*a^3*m*(3 + lambda)*omega + a^2*(1 - m^2*(-1 + lambda) + lambda^2 - 4*I*omega - 8*I*lambda*omega)) - a*z^2*(4*I*m*(2 + lambda) + 2*a^2*m*(19 + 5*lambda)*omega + a*(28 + 24*lambda + 5*lambda^2 - m^2*(4 + lambda) + 4*I*omega - 8*I*lambda*omega)) - a^2*z^4*(24*(2 + lambda) + 2*I*a*m*(23 + 6*lambda) + 4*a^3*m*(18 + 5*lambda)*omega + a^2*(67 + 54*lambda + 10*lambda^2 - m^2*(11 + 4*lambda) + 8*I*omega - 32*I*lambda*omega)) + a^6*z^8*(4 + 8*lambda - 2*I*a*m*(9 + 2*lambda) - 2*a^3*m*(16 + 5*lambda)*omega + a^2*(-31 - 24*lambda - 5*lambda^2 + m^2*(1 + 4*lambda) + 8*I*omega + 32*I*lambda*omega))))/ ((1 + a^2*z^2)^2*(1 - 2*z + a^2*z^2)^2*(2 - 2*I*a*m*z - 2*I*a^3*m*z^3 + lambda + a^4*z^4*(1 + lambda) + a^2*z^2*(3 + 2*z + 2*lambda))) end elseif s == -1 return begin (z^2*((-1 + 2*z)*lambda^2 + a^2*z*(m^2*(-4*z^2 + z*(2 + lambda) - 4*I*omega) + lambda*(-24*z^3 + 4*z^2*(5 + 2*lambda) + z*(-4 - 5*lambda + 8*I*omega) - 4*I*omega)) + 2*I*a*m*lambda*(-z + 2*z^2 + I*omega) + 2*a^12*z^11*(-1 + lambda)*(z - 2*I*omega) - 2*a^11*m*z^10*(-5 + lambda)*omega + 2*a^9*m*z^8*(-3*I*z^2 + I*z*(-2 + m^2 - lambda + 10*I*omega) - 5*(-4 + lambda)*omega) + 2*I*a^7*m*z^6*(6*z^3 + z^2*(5 + 2*lambda) + z*(-6 + 3*m^2 - 4*lambda + 30*I*omega) + 10*I*(-3 + lambda)*omega) + 2*I*a^5*m*z^4*(-8*z^3 + z^2*(19 + 6*lambda) + 3*z*(-2 + m^2 - 2*lambda + 10*I*omega) + 10*I*(-2 + lambda)*omega) + 2*I*a^3*m*z^2*(-14*z^3 + z^2*(11 + 6*lambda) + z*(-2 + m^2 - 4*lambda + 10*I*omega) + 5*I*(-1 + lambda)*omega) - a^10*z^9*(12*z^2*(-1 + lambda) + 4*I*(-4 + m^2 + 5*lambda)*omega + z*(5 - m^2*(-3 + lambda) - 4*lambda + lambda^2 + 16*I*omega - 8*I*lambda*omega)) + a^4*z^3*(-8*z^4 - 4*z^3*(-3 + 8*lambda) - 2*z^2*(3 + m^2 - 24*lambda - 6*lambda^2 - 8*I*omega) - 4*I*(-1 + 4*m^2 + 5*lambda)*omega + z*(1 - 14*lambda - 10*lambda^2 + m^2*(3 + 4*lambda) - 16*I*omega + 32*I*lambda*omega)) + a^8*z^7*(8*z^3*(-3 + 2*lambda) + 2*z^2*(9 + 3*m^2 - 8*lambda + lambda^2 + 8*I*omega) - 8*I*(-3 + 2*m^2 + 5*lambda)*omega + z*(-3 - 4*lambda - 5*lambda^2 + m^2*(-7 + 4*lambda) - 48*I*omega + 32*I*lambda*omega)) + a^6*z^5*(16*z^4 + 4*z^3*(-3 + 2*lambda) + 8*z^2*(m^2 + 3*lambda + lambda^2 + 4*I*omega) - 8*I*(-2 + 3*m^2 + 5*lambda)*omega + z*(1 - 16*lambda - 10*lambda^2 + m^2*(-3 + 6*lambda) - 48*I*omega + 48*I*lambda*omega))))/((1 + a^2*z^2)^2*(1 - 2*z + a^2*z^2)^2* (2*I*a*m*z + 2*I*a^3*m*z^3 + a^4*z^4*(-1 + lambda) + lambda + a^2*z^2*(-1 + 2*z + 2*lambda))) end elseif s == 2 return begin (z^2*(24*a^12*z^12 - lambda^3 - 48*I*a^10*z^11*(-3*I + a^2*omega) - 2*lambda^2*(8 + a*m*omega) + 4*lambda*(-21 - 3*(I + 4*a*m)*omega + 7*a^2*omega^2) - 12*a^8*z^10*(-24 + 6*I*a*m - a^2*(5 + 3*m^2 + 20*I*omega) + 4*a^4*omega^2) + 8*I*a^6*z^9*(24*I + 18*a*m + 3*I*a^2*(9 + m^2 + 12*I*omega) + a^3*m*(19 - 3*m^2 + 4*lambda + 18*I*omega) + a^4*(-31 + 15*m^2 - 4*lambda - 24*I*omega)*omega - 24*a^5*m*omega^2 + 12*a^6*omega^3) + 8*(-18 - (9*I + 23*a*m)*omega + a*(-3*I*m + a*(11 - 3*m^2))*omega^2 + 3*a^3*m*omega^3) + a^3*z^6*(384*I*m + 8*I*a^2*m*(-177 + 18*m^2 - 53*lambda - 2*lambda^2 + 24*I*omega) + 16*a*(-33 + 12*m^2 - 10*lambda - lambda^2 - 36*I*omega) + a^3*(-756 - 48*m^4 - lambda^3 + lambda^2*(-41 + 16*I*omega) + lambda*(-334 + 364*I*omega) + m^2*(564 + 106*lambda + lambda^2 - 756*I*omega) + 780*I*omega) + 2*a^4*m*(-506 + 126*m^2 - 132*lambda - lambda^2 + 588*I*omega)*omega + 4*a^5*(49 - 93*m^2 + 37*lambda - 144*I*omega)*omega^2 + 168*a^6*m*omega^3) + a*z^4*(96*I*m + 8*I*a^2*m*(-202 + 9*m^2 - 65*lambda - 4*lambda^2) - 8*a*(120 + 50*lambda + 5*lambda^2 + 72*I*omega) + a^3*(-1068 - 24*m^4 - 3*lambda^3 + lambda^2*(-74 + 32*I*omega) + 2*m^2*(246 + 58*lambda + lambda^2 - 288*I*omega) + lambda*(-512 + 388*I*omega) + 488*I*omega) + 6*a^4*m*(-224 + 36*m^2 - 60*lambda - lambda^2 + 172*I*omega)*omega + 12*a^5*(38 - 34*m^2 + 17*lambda - 48*I*omega)*omega^2 + 216*a^6*m*omega^3) + 4*I*a*z^3*(12*m*(3 + lambda) + I*a*(-408 - 194*lambda - 27*lambda^2 - lambda^3 + 16*m^2*(4 + lambda) - 168*I*omega) - 12*a^4*m*(17 + lambda)*omega^2 + 96*a^5*omega^3 + 2*a^3*omega*(-53 - 26*lambda - 3*lambda^2 + m^2*(79 + 7*lambda) + 60*I*omega + 24*I*lambda*omega) - 2*a^2*m*(-98 - 35*lambda - 3*lambda^2 + m^2*(10 + lambda) + 128*I*omega + 32*I*lambda*omega)) + 2*I*a^3*z^5*(24*m*(9 + 4*lambda) - 24*a^4*m*(25 + lambda)*omega^2 + 288*a^5*omega^3 + 4*a^3*omega*(-89 - 35*lambda - 3*lambda^2 + m^2*(113 + 8*lambda) + 51*I*omega + 27*I*lambda*omega) - 4*a^2*m*(-143 - 44*lambda - 3*lambda^2 + m^2*(23 + 2*lambda) + 181*I*omega + 43*I*lambda*omega) + I*a*(-924 - 394*lambda - 47*lambda^2 - lambda^3 + 4*m^2*(91 + 16*lambda) - 300*I*omega + 84*I*lambda*omega)) + 4*a^6*z^8*(36 - 24*m^2 + 6*a^3*m*(4*m^2 - 3*(4 + lambda - 6*I*omega))* omega - 2*a^4*(7 + 15*m^2 - 5*lambda + 24*I*omega)*omega^2 + 12*a^5*m*omega^3 + 2*a*m*(-44*I + 9*I*m^2 - 11*I*lambda + 36*omega) - a^2*(39 + 6*m^4 + 20*lambda + 2*lambda^2 + m^2*(-65 - 8*lambda + 78*I*omega) - 142*I*omega - 22*I*lambda*omega + 48*omega^2)) + 8*I*a^4*z^7*(-12*I + 6*a*m*(-5 + lambda) + I*a^2*(m^2*(62 + 8*lambda) - 3*(24 + lambda^2 + 2*lambda*(5 - I*omega) + 10*I*omega)) + a^3*m*(88 + lambda^2 - m^2*(16 + lambda) + lambda*(23 - 18*I*omega) - 66*I*omega) - 2*a^5*m*(49 + lambda)*omega^2 + 48*a^6*omega^3 + a^4*omega*(-73 - lambda^2 + 3*m^2*(23 + lambda) - 14*I*omega + 10*I*lambda*(2*I + omega))) + 2*z*((9 + lambda)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 8*I*a^3*m*(13 + lambda)*omega^2 + 48*I*a^4*omega^3 - 4*a^2*omega*(12*I + I*lambda^2 - 2*I*m^2*(10 + lambda) + 19*omega + 7*lambda*(I + omega)) + 4*a*m*(24*I + I*lambda^2 + 31*omega + lambda*(10*I + 7*omega))) + z^2*(-8*I*a*m*(60 + 23*lambda + 2*lambda^2 + 6*I*omega) - 12*(24 + 10*lambda + lambda^2 + 12*I*omega) + 6*a^3*m*(-134 + 10*m^2 - 36*lambda - lambda^2 + 44*I*omega)*omega + 4*a^4*(85 - 45*m^2 + 31*lambda - 48*I*omega)*omega^2 + 120*a^5*m*omega^3 + a^2*(-3*lambda^3 + lambda^2*(-57 + 16*I*omega) + lambda*(-342 + 100*I*omega) + m^2*(152 + 42*lambda + lambda^2 - 132*I*omega) - 12*(54 + 3*I*omega + 4*omega^2)))))/ ((1 + a^2*z^2)^2*(1 - 2*z + a^2*z^2)^2*(24 + 10*lambda + lambda^2 - 4*I*a*m*(6*z^2 + 2*z*(4 + lambda) + 3*I*omega) + 12*I*omega + 24*a^3*m*z^2*(I*z + 2*omega) + 12*a^4*z^2*(z^2 - 2*I*z*omega - 2*omega^2) - 4*a^2*(6*z^3 + z^2*(-3 + 6*m^2 - 6*I*omega) - 2*I*z*(1 + lambda)*omega + 3*omega^2))) end elseif s == -2 return begin (z^2*(-((-1 + 2*z)*(-2 + 6*z - lambda)*(2*lambda + lambda^2 - 12*I*omega)) - 48*a^11*m*z^8*omega*(3*z^2 - omega^2) + 24*a^12*z^10*(z^2 - 2*I*z*omega + 4*omega^2) - 4*a^10*z^8*(36*z^3 - 3*z^2*(5 + 3*m^2 + 8*I*omega) + 6*(-17 + 5*m^2 - lambda)*omega^2 + 2*z*omega*(39*I + 3*I*m^2 - 4*I*lambda + 24*omega)) + 8*a^9*m*z^6*(9*I*z^4 + z^2*(-72 + 12*m^2 - 7*lambda - 6*I*omega)*omega + 2*I*z*(-3 + lambda)*omega^2 + 21*omega^3 + z^3*(-3*I + 3*I*m^2 - 4*I*lambda + 30*omega)) - 2*I*a^7*m*z^4*(72*z^5 + 4*z^4*(9*m^2 - 11*lambda + 12*I*omega) + I*z^2*(-426 + 126*m^2 - 92*lambda - lambda^2 - 12*I*omega)*omega - 24*z*(-3 + lambda)*omega^2 + 108*I*omega^3 + 4*z^3*(12 + 15*lambda + lambda^2 - m^2*(12 + lambda) + 150*I*omega + 14*I*lambda*omega)) - 2*I*a^3*m*(192*z^6 + 24*z^5*(-7 + 4*lambda) + 4*z^4*(-6 + 9*m^2 - 33*lambda - 4*lambda^2 - 72*I*omega) - 8*z*(-3 + lambda)*omega^2 + 12*I*omega^3 - z^2*omega*(90*I - 30*I*m^2 + 52*I*lambda + 3*I*lambda^2 + 60*omega) + 4*z^3*(6 + 11*lambda + 3*lambda^2 - m^2*(6 + lambda) + 84*I*omega + 20*I*lambda*omega)) - 2*I*a^5*m*z^2*(24*z^5*(-9 + lambda) + 4*z^4*(3 + 18*m^2 - 37*lambda - 2*lambda^2 - 96*I*omega) + 3*I*z^2*(-96 + 36*m^2 - 36*lambda - lambda^2 + 20*I*omega)*omega - 24*z*(-3 + lambda)*omega^2 + 60*I*omega^3 + 4*z^3*(15 + 20*lambda + 3*lambda^2 - m^2*(15 + 2*lambda) + 189*I*omega + 31*I*lambda*omega)) + 4*a^8*z^6*(-6*(9 + m^2)*z^3 + 72*z^4 + z^2*(9 - 6*m^4 - 2*lambda^2 + lambda*(-4 - 22*I*omega) + m^2*(33 + 8*lambda + 30*I*omega) + 258*I*omega) + 3*(55 - 31*m^2 + 7*lambda)*omega^2 - 2*z*omega*(87*I - I*lambda^2 + 3*I*m^2*(3 + lambda) + 114*omega + 6*lambda*(-2*I + omega))) + 2*a*m*(-48*I*z^4 - 24*I*z^3*(-1 + lambda) + 4*I*z^2*(7*lambda + 2*lambda^2 + 18*I*omega) - (12 + 8*lambda + lambda^2 - 12*I*omega)*omega + 4*z*((-I)*lambda^2 + 15*omega + lambda*(-2*I + 3*omega))) - a^2*(8*z^4*(10*lambda + 5*lambda^2 - 72*I*omega) - 4*z^3*((26 - 16*m^2)*lambda + 15*lambda^2 + lambda^3 - 240*I*omega) + 12*(-2 + 2*m^2 - lambda)*omega^2 + z^2*(3*lambda^3 + lambda^2*(21 - m^2 + 16*I*omega) + lambda*(30 - 34*m^2 - 28*I*omega) + 12*I*(-35 + 5*m^2 + 12*I*omega)*omega) + 8*z*omega*(6*I - I*lambda^2 + 15*omega + lambda*(I + 2*I*m^2 + 3*omega))) + a^4*z^2*(96*z^5 + 16*z^4*(-9 + 12*m^2 - 2*lambda - lambda^2 + 36*I*omega) + 60*(3 - 3*m^2 + lambda)*omega^2 + 2*z^3*(36 + 66*lambda + 35*lambda^2 + lambda^3 - 4*m^2*(27 + 16*lambda) - 1068*I*omega + 84*I*lambda*omega) - 8*z*omega*(39*I - 3*I*lambda^2 + I*m^2*(3 + 7*lambda) + 84*omega + 2*lambda*(-I + 6*omega)) - z^2*(24*m^4 + 3*lambda^3 - 2*m^2*(30 + 50*lambda + lambda^2) + lambda^2*(38 + 32*I*omega) + 4*lambda*(16 + 33*I*omega) - 12*(-1 + 134*I*omega + 48*omega^2))) - a^6*z^4*(48*(-3 + 2*m^2)*z^4 + 192*z^5 + 8*z^3*(m^2*(30 + 8*lambda) - 3*(lambda^2 + lambda*(2 + 2*I*omega) - 54*I*omega)) + 12*(-42 + 34*m^2 - 9*lambda)*omega^2 + 8*z*omega*(87*I - 3*I*lambda^2 + I*m^2*(9 + 8*lambda) + 159*omega + lambda*(-11*I + 15*omega)) + z^2*(48*m^4 + lambda^3 + lambda^2*(29 + 16*I*omega) - m^2*(156 + 98*lambda + lambda^2 + 180*I*omega) + lambda*(54 + 236*I*omega) - 12*(-1 + 179*I*omega + 48*omega^2)))))/((1 + a^2*z^2)^2*(1 - 2*z + a^2*z^2)^2* (2*lambda + lambda^2 - 12*I*omega + 24*a^3*m*z^2*((-I)*z + 2*omega) + 4*a*m*(6*I*z^2 + 2*I*z*lambda + 3*omega) + 12*a^4*z^2*(z^2 + 2*I*z*omega - 2*omega^2) - 4*a^2*(6*z^3 + z^2*(-3 + 6*m^2 + 6*I*omega) + 2*I*z*(-3 + lambda)*omega + 3*omega^2))) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end # Cache mechanism for the ingoing coefficients at infinity # Initialize the cache with a set of fiducial parameters _cached_ingoing_coefficients_at_inf_params::NamedTuple{(:s, :m, :a, :omega, :lambda), Tuple{Int, Int, _DEFAULTDATATYPE, _DEFAULTDATATYPE, _DEFAULTDATATYPE}} = (s=-2, m=2, a=0, omega=0.5, lambda=1) _cached_ingoing_coefficients_at_inf::NamedTuple{(:expansion_coeffs, :Pcoeffs, :Qcoeffs), Tuple{Vector{_DEFAULTDATATYPE}, Vector{_DEFAULTDATATYPE}, Vector{_DEFAULTDATATYPE}}} = ( expansion_coeffs = [_DEFAULTDATATYPE(1.0)], Pcoeffs = [_DEFAULTDATATYPE(0.0)], Qcoeffs = [_DEFAULTDATATYPE(0.0)] ) function ingoing_coefficient_at_inf(s::Int, m::Int, a, omega, lambda, order::Int) #= We have derived/shown the explicit expression for different physically-relevant spin weight (s=0, \pm 1, \pm2) for up to (1/r)^3, which is probably more than enough But we have also shown a recurrence relation where one can generate as higher an order as one pleases. However, the recurrence relation that we have actually depends *all* previous terms so this function is designed to be evaluated recursively to build the full list of coefficients =# global _cached_ingoing_coefficients_at_inf_params global _cached_ingoing_coefficients_at_inf if order < 0 throw(DomainError(order, "Only positive expansion order is supported")) end if order == 0 return 1.0 # This is always 1.0 elseif order == 1 if s == 0 return (-(1/2))*I*(lambda + 2*a*m*omega) elseif s == +1 return begin -((I*(4 + lambda^2 + 8*a*m*omega + 2*lambda*(2 + a*m*omega)))/ (2*(2 + lambda))) end elseif s == -1 return (-(1/2))*I*(lambda + 2*a*m*omega) elseif s == +2 return begin (I*(-lambda^3 - 2*lambda^2*(8 + a*m*omega) + 4*lambda*(-21 - 3*(I + 4*a*m)*omega + 7*a^2*omega^2) + 8*(-18 - (9*I + 23*a*m)*omega + a*(11*a - 3*I*m - 3*a*m^2)*omega^2 + 3*a^3*m*omega^3)))/(2*(10*lambda + lambda^2 + 12*(2 + (I + a*m)*omega - a^2*omega^2))) end elseif s == -2 return (-(1/2))*I*(2 + lambda + 2*a*m*omega) else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end elseif order == 2 if s == 0 return begin (1/8)*(-((-2 + lambda)*lambda) - 4*(I + a*m*(-1 + lambda))*omega - 4*a*m*(2*I + a*m)*omega^2) end elseif s == +1 return begin -((lambda^3 + 4*lambda^2*(1 + a*m*omega) + 8*a*omega*(m*(2 + 2*I*omega) - a*omega + 3*a*m^2*omega) + 4*lambda*(1 + a*m*(5 + 2*I*omega)*omega + a^2*(-2 + m^2)*omega^2))/ (8*(2 + lambda))) end elseif s == -1 return begin (1/8)*(-lambda^2 + lambda*(2 - 4*a*m*omega) + 4*a*omega*(m + 2*a*omega - m*(2*I + a*m)*omega)) end elseif s == +2 return begin -((lambda^4 + 4*lambda^3*(5 + a*m*omega) + 4*lambda^2*(37 + 2*a*m*(13 + I*omega)*omega + a^2*(-11 + m^2)*omega^2) - 8*lambda*(-60 + 8*a*m*(-11 - 2*I*omega)*omega + a^2*(39 - 19*m^2)*omega^2 + 14*a^3*m*omega^3) - 16*(a^2*(34 + m^2*(-49 - 9*I*omega) + 3*I*omega)* omega^2 + a^3*m*(43 - 3*m^2 + 6*I*omega)*omega^3 + 3*a^4*(-4 + m^2)*omega^4 - 9*(4 + omega^2) + 2*a*m*omega*(-44 - 15*I*omega + 3*omega^2)))/ (8*(10*lambda + lambda^2 + 12*(2 + (I + a*m)*omega - a^2*omega^2)))) end elseif s == -2 return begin (1/8)*((-lambda)*(2 + lambda) - 4*(-3*I + a*m*(1 + lambda))*omega - 4*a*m*(2*I + a*m)*omega^2) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end elseif order == 3 if s == 0 return begin (1/48)*(I*(-6 + lambda)*(-2 + lambda)*lambda + 2*(12 - 18*lambda + I*a*m*(12 + lambda*(-16 + 3*lambda)))*omega + 4*I*a*(3*a*m^2*(-2 + lambda) + 2*a*(-1 + lambda) + 6*I*m*(1 + lambda))*omega^2 + 8*I*a*m*(-8 + 6*I*a*m + a^2*(2 + m^2))*omega^3) end elseif s == +1 return begin (1/(48*(2 + lambda)))*(I*(lambda^4 + 6*a*m*lambda^3*omega + 4*lambda^2*(-3 + (6*I + 4*a*m)*omega + a*(-4*a + 6*I*m + 3*a*m^2)*omega^2) + 8*lambda*(-2 + (12*I - 5*a*m)*omega + a*(12*I*m + a*(-4 + 9*m^2))*omega^2 + a*m*(-8 + 6*I*a*m + a^2*(-4 + m^2))*omega^3) + 16*omega*(6*I + a^3*m*(-1 + 4*m^2)*omega^2 + 3*I*a^2*omega*(I - 2*omega + 4*m^2*omega) + a*m*(-3 + 12*I*omega - 8*omega^2)))) end elseif s == -1 return begin (1/48)*I*(lambda^3 + lambda^2*(-8 + 6*a*m*omega) + 8*a*omega*(a*omega + m*(2 - 3*a*m*omega + (-8 + 6*I*a*m + a^2*(-4 + m^2))*omega^2)) + 4*lambda*(3 + omega*(6*I + a*(-4*a*omega + m*(-8 + 3*(2*I + a*m)*omega))))) end elseif s == +2 return begin -((I*(-lambda^5 - 2*lambda^4*(10 + 3*a*m*omega) - 4*lambda^3*(37 + 2*a*m*(20 + 3*I*omega)*omega + a^2*(-13 + 3*m^2)*omega^2) - 8*lambda^2*(60 + 2*a^2*(-29 + 3*m^2*(9 + I*omega))* omega^2 + a^3*m*(-31 + m^2)*omega^3 + a*m*omega*(157 + 48*I*omega - 8*omega^2)) + 16*lambda*(a^2*(91 + m^2*(-210 - 81*I*omega) + 9*I*omega)* omega^2 + 2*a^3*m*(73 - 13*m^2 + 21*I*omega)* omega^3 + 3*a^4*(-10 + 7*m^2)*omega^4 - 9*(4 + omega^2) + 2*a*m*omega*(-116 - 63*I*omega + 29*omega^2)) + 96*a*omega*((-a^3)*m^4*omega^3 + a*omega*(18 + 9*I*omega - 11*a^2*omega^2) + a^2*m^3*omega^2*(-28 - 7*I*omega + a^2*omega^2) + a*m^2*omega*(-70 - 55*I*omega + 2*(7 + 15*a^2)* omega^2 + 6*I*a^2*omega^3) + m*(-36 - 36*I*omega + (25 + 47*a^2)*omega^2 + I*(8 + 23*a^2)*omega^3 - 2*a^2*(4 + 5*a^2)* omega^4))))/(48*(10*lambda + lambda^2 + 12*(2 + (I + a*m)*omega - a^2*omega^2)))) end elseif s == -2 return begin (1/48)*(I*(-4 + lambda)*lambda*(2 + lambda) + 2*(6*(-4 + lambda) + I*a*m*(-24 + lambda*(-4 + 3*lambda)))* omega + 4*a*(-6*m*(-1 + lambda) + I*a*(-6 + (2 + 3*m^2)*lambda))*omega^2 + 8*I*a*m*(-8 + 6*I*a*m + a^2*(2 + m^2))*omega^3) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end else # Evaluate higher order corrections using AD # Specifically we use TaylorSeries.jl for a much more performant AD _this_params = (s=s, m=m, a=a, omega=omega, lambda=lambda) # Check if we can use the cached results if _cached_ingoing_coefficients_at_inf_params == _this_params expansion_coeffs = _cached_ingoing_coefficients_at_inf.expansion_coeffs Pcoeffs = _cached_ingoing_coefficients_at_inf.Pcoeffs Qcoeffs = _cached_ingoing_coefficients_at_inf.Qcoeffs else # Cannot re-use the cached results, re-compute from zero expansion_coeffs = [_DEFAULTDATATYPE(1.0)] # order 0 Pcoeffs = [_DEFAULTDATATYPE(PminusInf_z(s, m, a, omega, lambda, 0))] # order 0 Qcoeffs = [_DEFAULTDATATYPE(0.0), _DEFAULTDATATYPE(0.0)] # the recurrence relation takes Q_{r+1} end # Compute Pcoeffs to the necessary order _P(z) = PminusInf_z(s, m, a, omega, lambda, z) _P_taylor = taylor_expand(_P, 0, order=order) # FIXME This is not the most efficient way to do this for i in length(Pcoeffs):order append!(Pcoeffs, getcoeff(_P_taylor, i)) end # Compute Qcoeffs to the necessary order (to current order + 1) _Q(z) = QminusInf_z(s, m, a, omega, lambda, z) _Q_taylor = taylor_expand(_Q, 0, order=order+1) for i in length(Qcoeffs):order+1 append!(Qcoeffs, getcoeff(_Q_taylor, i)) end # Note that the expansion coefficients we store is scaled by \omega^{i} for i in length(expansion_coeffs):order _P0 = Pcoeffs[1] # P0 sum = 0.0 for k in 1:i sum += (Qcoeffs[k+2] - (i-k)*Pcoeffs[k+1])*(expansion_coeffs[i-k+1]/omega^(i-k)) end append!(expansion_coeffs, omega^(i)*((i*(i-1)*(expansion_coeffs[i]/omega^(i-1)) + sum)/(_P0*i))) end # Update cache _cached_ingoing_coefficients_at_inf_params = _this_params _cached_ingoing_coefficients_at_inf = ( expansion_coeffs = expansion_coeffs, Pcoeffs = Pcoeffs, Qcoeffs = Qcoeffs ) return expansion_coeffs[order+1] end end function PplusInf_z(s::Int, m::Int, a, omega, lambda, z) if s == 0 return begin (2*I*(omega + a^2*z^4*(I + a^2*omega) + z^2*(-I + 2*a^2*omega)))/ ((1 + a^2*z^2)*(1 - 2*z + a^2*z^2)) end elseif s == 1 return begin ((1 + a^2*z^2)*(-((2*(-1 + z)*z)/(1 + a^2*z^2)) - (2*z*(1 - 2*z + a^2*z^2))/ (1 + a^2*z^2)^2 + (2*a*z^2*(1 - 2*z + a^2*z^2)*((-I)*m*(1 + 3*a^2*z^2) + a*z*(3 + 3*z + 2*lambda + 2*a^2*z^2*(1 + lambda))))/((1 + a^2*z^2)* (2 - 2*I*a*m*z - 2*I*a^3*m*z^3 + lambda + a^4*z^4*(1 + lambda) + a^2*z^2*(3 + 2*z + 2*lambda))) + 2*I*omega))/(1 - 2*z + a^2*z^2) end elseif s == -1 return begin (1/(1 - 2*z + a^2*z^2))*((1 + a^2*z^2)*(-((2*(-1 + z)*z)/(1 + a^2*z^2)) - (2*z*(1 - 2*z + a^2*z^2))/(1 + a^2*z^2)^2 + (2*a*z^2*(1 - 2*z + a^2*z^2)*(I*m*(1 + 3*a^2*z^2) + a*z*(-1 + 3*z + 2*a^2*z^2*(-1 + lambda) + 2*lambda)))/ ((1 + a^2*z^2)*(2*I*a*m*z + 2*I*a^3*m*z^3 + a^4*z^4*(-1 + lambda) + lambda + a^2*z^2*(-1 + 2*z + 2*lambda))) + 2*I*omega)) end elseif s == 2 return begin (1/(1 - 2*z + a^2*z^2))*((1 + a^2*z^2)*(-((2*(-1 + z)*z)/(1 + a^2*z^2)) - (2*z*(1 - 2*z + a^2*z^2))/(1 + a^2*z^2)^2 + 2*I*omega + (8*a*z^2*(1 - 2*z + a^2*z^2)*(-6*a*m^2*z + I*m*(-4 + 9*a^2*z^2 - lambda + z*(-6 - 12*I*a^2*omega)) + a*(6*a^2*z^3 + I*(1 + lambda)*omega + z^2*(-9 - 9*I*a^2*omega) + z*(3 + 6*I*omega - 6*a^2*omega^2))))/((1 + a^2*z^2)*(24 + 10*lambda + lambda^2 - 4*I*a*m*(6*z^2 + 2*z*(4 + lambda) + 3*I*omega) + 12*I*omega + 24*a^3*m*z^2*(I*z + 2*omega) + 12*a^4*z^2*(z^2 - 2*I*z*omega - 2*omega^2) - 4*a^2*(6*z^3 + z^2*(-3 + 6*m^2 - 6*I*omega) - 2*I*z*(1 + lambda)*omega + 3*omega^2))))) end elseif s == -2 return begin (1/(1 - 2*z + a^2*z^2))*((1 + a^2*z^2)*(-((2*(-1 + z)*z)/(1 + a^2*z^2)) - (2*z*(1 + z*(-2 + a^2*z)))/(1 + a^2*z^2)^2 + 2*I*omega + (8*a*z^2*(1 + z*(-2 + a^2*z))*(-3*a*z*(-1 + 2*m^2 + 3*z) + I*m*(6*z + lambda) - I*a*(-3 + 6*z + lambda)*omega + 3*a^2*m*z*(-3*I*z + 4*omega) + 3*a^3*z*(2*z^2 + 3*I*z*omega - 2*omega^2)))/((1 + a^2*z^2)*(lambda*(2 + lambda) - 12*I*omega + 12*a^4*z^2*(z - (1 - I)*omega)*(z + (1 + I)*omega) + 24*a^3*m*z^2*((-I)*z + 2*omega) + 4*a*m*(2*I*z*(3*z + lambda) + 3*omega) + 4*a^2*(-3*z^2*(-1 + 2*m^2 + 2*z) - 2*I*z*(-3 + 3*z + lambda)*omega - 3*omega^2))))) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function QplusInf_z(s::Int, m::Int, a, omega, lambda, z) if s == 0 return begin -((z^2*(-2*z*(-1 + lambda) + lambda - 4*a^2*z^3*(1 + lambda) - 2*a^4*z^5*(3 + lambda) + 2*a*m*omega + a^6*z^6*(1 - m^2 + lambda + 2*a*m*omega) + a^2*z^4*(8 + a^2*(2 - 2*m^2 + 3*lambda) + 6*a^3*m*omega) + z^2*(-4 + a^2*(1 - m^2 + 3*lambda) + 6*a^3*m*omega)))/ ((1 + a^2*z^2)^2*(1 - 2*z + a^2*z^2)^2)) end elseif s == 1 return begin (z^2*(2*a^12*z^12*(1 + lambda) + 4*I*a^10*z^11*(1 + lambda)*(3*I + a^2*omega) - (2 + lambda)*(2 + lambda + 2*a*m*omega) - a^6*z^8*(-4 - 8*lambda + 2*I*a*m*(9 + 2*lambda) + a^2*(31 + 5*lambda^2 - m^2*(1 + 4*lambda) + 8*lambda*(3 + 4*I*omega) + 16*I*omega) + 10*a^3*m*(-2 + lambda)*omega) - a^4*z^6*(52 + 32*lambda + 2*I*a*m*(31 + 6*lambda) + a^2*(71 + 10*lambda^2 - 3*m^2*(3 + 2*lambda) + 8*lambda*(7 + 6*I*omega) + 48*I*omega) + 20*a^3*m*(-1 + lambda)*omega) - a*z^2*(4*I*m*(2 + lambda) - a*m^2*(4 + lambda) + a*(2 + lambda)*(14 + 5*lambda + 8*I*omega) + 10*a^2*m*(1 + lambda)*omega) + 2*z*(I*a*m*(2 + lambda) + (2 + lambda)^2 + 2*I*a^2*(2 + m^2 + lambda)*omega) + 2*a^6*z^9*(8 - 6*I*a*m + a^2*(-3 + 3*m^2 - 4*lambda + lambda^2 - 8*I*omega) - I*a^3*m*(-4 + m^2 - lambda - 10*I*omega) + 2*I*a^4*(6 + m^2 + 5*lambda)*omega) + 2*a^4*z^7*(-4 + 8*I*a*m + a^3*m*(14*I - 3*I*m^2 + 4*I*lambda - 30*omega) + 4*a^2*(10 + m^2 + 7*lambda + lambda^2 - 4*I*omega) + 4*I*a^4*(7 + 2*m^2 + 5*lambda)*omega) + 2*I*a^3*z^5*(14*m + a^2*(-3*m^3 + 6*m*(3 + lambda + 5*I*omega)) + I*a*(-69 + m^2 - 48*lambda - 6*lambda^2 + 8*I*omega) + 4*a^3*(8 + 3*m^2 + 5*lambda)*omega) + 2*a^2*z^3*(36 - 2*m^2 + 26*lambda + 4*lambda^2 - I*a*(m^3 - 2*m*(5 + 2*lambda + 5*I*omega)) + 2*I*a^2*(9 + 4*m^2 + 5*lambda)*omega) - a^8*z^10*(-6*I*a*m - 8*(1 + 2*lambda) + 2*a^3*m*(-3 + lambda)*omega + a^2*(1 - m^2*(-1 + lambda) + lambda^2 + 8*I*lambda*omega)) - a^2*z^4*(24*(2 + lambda) + 2*I*a*m*(23 + 6*lambda) + 20*a^3*m*lambda*omega + a^2*(67 + 54*lambda + 10*lambda^2 - m^2*(11 + 4*lambda) + 48*I*omega + 32*I*lambda*omega))))/ ((1 + a^2*z^2)^2*(1 - 2*z + a^2*z^2)^2*(2 - 2*I*a*m*z - 2*I*a^3*m*z^3 + lambda + a^4*z^4*(1 + lambda) + a^2*z^2*(3 + 2*z + 2*lambda))) end elseif s == -1 return begin (z^2*((-1 + 2*z)*lambda^2 + 2*a^12*z^11*(-1 + lambda)*(z + 2*I*omega) - 2*a^11*m*z^10*(1 + lambda)*omega + 2*a^9*m*z^8*(-3*I*z^2 + I*z*(-2 + m^2 - lambda - 2*I*omega) - (6 + 5*lambda)*omega) + 2*I*a^7*m*z^6*(3*m^2*z + 6*z^3 + z^2*(5 + 2*lambda) - 2*z*(3 + 2*lambda + 5*I*omega) + 2*I*(7 + 5*lambda)*omega) + 2*I*a^5*m*z^4*(-8*z^3 + z^2*(19 + 6*lambda) + 3*z*(m^2 - 2*(1 + lambda + 3*I*omega)) + 2*I*(8 + 5*lambda)*omega) + 2*I*a^3*m*z^2*(-14*z^3 + z^2*(11 + 6*lambda) + z*(m^2 - 2*(1 + 2*lambda + 7*I*omega)) + I*(9 + 5*lambda)*omega) + 2*a*m*(2*I*z^2*lambda - (2 + lambda)*omega + z*((-I)*lambda + 4*omega)) - a^10*z^9*(12*z^2*(-1 + lambda) + 4*I*(5 + m^2 - 5*lambda)*omega + z*(5 - m^2*(-3 + lambda) - 4*lambda + lambda^2 - 12*I*omega + 8*I*lambda*omega)) + a^2*z*(-24*z^3*lambda + m^2*(-4*z^2 + z*(2 + lambda) - 4*I*omega) + 4*z^2*(5*lambda + 2*lambda^2 - 6*I*omega) + 4*I*(-1 + lambda)*omega - z*(4*lambda + 5*lambda^2 - 20*I*omega + 8*I*lambda*omega)) + a^8*z^7*(8*z^3*(-3 + 2*lambda) + 2*z^2*(9 + 3*m^2 - 8*lambda + lambda^2 - 4*I*omega) - 8*I*(5 + 2*m^2 - 5*lambda)*omega + z*(-3 - 4*lambda - 5*lambda^2 + m^2*(-7 + 4*lambda) + 56*I*omega - 32*I*lambda*omega)) + a^4*z^3*(-8*z^4 - 4*z^3*(-3 + 8*lambda) - 2*z^2*(3 + m^2 - 24*lambda - 6*lambda^2 + 28*I*omega) - 4*I*(5 + 4*m^2 - 5*lambda)*omega + z*(1 - 14*lambda - 10*lambda^2 + m^2*(3 + 4*lambda) + 72*I*omega - 32*I*lambda*omega)) + a^6*z^5*(16*z^4 + 4*z^3*(-3 + 2*lambda) + 8*z^2*(m^2 + 3*lambda + lambda^2 - 5*I*omega) - 8*I*(5 + 3*m^2 - 5*lambda)*omega + z*(1 - 16*lambda - 10*lambda^2 + m^2*(-3 + 6*lambda) + 96*I*omega - 48*I*lambda*omega))))/((1 + a^2*z^2)^2*(1 - 2*z + a^2*z^2)^2* (2*I*a*m*z + 2*I*a^3*m*z^3 + a^4*z^4*(-1 + lambda) + lambda + a^2*z^2*(-1 + 2*z + 2*lambda))) end elseif s == 2 return begin (z^2*(24*a^12*z^12 - lambda^3 + 48*I*a^10*z^11*(3*I + a^2*omega) - 2*lambda^2*(8 + a*m*omega) + 8*I*a^6*z^9*(24*I + 18*a*m + 3*I*a^2*(9 + m^2) + a^3*m*(19 - 3*m^2 + 4*lambda - 30*I*omega) + a^4*(23 + 3*m^2 - 4*lambda + 24*I*omega)*omega) + 4*lambda*(-21 - (3*I + 8*a*m)*omega + 3*a^2*omega^2) + 12*a^8*z^10*(24 - 6*I*a*m + a^2*(5 + 3*m^2 - 8*I*omega) - 12*a^3*m*omega + 8*a^4*omega^2) - 2*I*a^3*z^5*(-24*m*(9 + 4*lambda) + a*(-4*I*m^2*(91 + 16*lambda) + I*(924 + 47*lambda^2 + lambda^3 + lambda*(394 - 84*I*omega) + 732*I*omega)) + 4*a^2*m*(-143 - 3*lambda^2 + m^2*(23 + 2*lambda) + lambda*(-44 + 31*I*omega) + 313*I*omega) + 4*a^3*(5 + 3*lambda^2 - m^2*(41 + 8*lambda) + 5*lambda*(7 - 3*I*omega) - 219*I*omega)*omega + 24*a^4*m*(1 + lambda)*omega^2) + 24*(-6 - (3*I + 5*a*m)*omega - a*(I*m + a*(-3 + m^2))*omega^2 + a^3*m*omega^3) - 4*I*a*z^3*(-12*m*(3 + lambda) + I*a*(408 + 194*lambda + 27*lambda^2 + lambda^3 - 16*m^2*(4 + lambda) + 240*I*omega) + 12*a^4*m*(1 + lambda)*omega^2 + 2*a^3*omega*(17 + 26*lambda + 3*lambda^2 - m^2*(31 + 7*lambda) - 132*I*omega - 12*I*lambda*omega) + 2*a^2*m*(-98 - 35*lambda - 3*lambda^2 + m^2*(10 + lambda) + 164*I*omega + 20*I*lambda*omega)) + 4*a^6*z^8*(36 - 24*m^2 + 2*a^3*m*(-100 + 12*m^2 - 7*lambda + 6*I*omega)*omega + 6*a^4*(21 - 5*m^2 + lambda)*omega^2 + 12*a^5*m*omega^3 + 2*a*m*(-44*I + 9*I*m^2 - 11*I*lambda + 12*omega) - a^2*(39 + 6*m^4 + 20*lambda + 2*lambda^2 + m^2*(-65 - 8*lambda + 30*I*omega) + 170*I*omega - 22*I*lambda*omega)) + 2*z*((9 + lambda)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 8*I*a^3*m*(1 + lambda)*omega^2 + 4*a*m*(24*I + 10*I*lambda + I*lambda^2 + 27*omega + 3*lambda*omega) - 4*a^2*omega*(6*I + 7*I*lambda + I*lambda^2 - 2*I*m^2*(4 + lambda) + 27*omega + 3*lambda*omega)) + a^3*z^6*(384*I*m + 16*a*(-33 + 12*m^2 - 10*lambda - lambda^2 - 36*I*omega) + 8*I*a^2*m*(-177 + 18*m^2 - 53*lambda - 2*lambda^2 + 96*I*omega) + 2*a^4*m*(-810 + 126*m^2 - 100*lambda - lambda^2 + 12*I*omega)*omega + 12*a^5*(83 - 31*m^2 + 7*lambda)*omega^2 + 168*a^6*m*omega^3 - a^3*(756 + 48*m^4 + lambda^3 + lambda^2*(41 - 16*I*omega) - m^2*(564 + 106*lambda + lambda^2 - 180*I*omega) + lambda*(334 - 364*I*omega) + 948*I*omega - 576*omega^2)) + a*z^4*(96*I*m + 8*I*a^2*m*(-202 + 9*m^2 - 65*lambda - 4*lambda^2 + 72*I*omega) - 8*a*(120 + 50*lambda + 5*lambda^2 + 72*I*omega) + 6*a^4*m*(-256 + 36*m^2 - 44*lambda - lambda^2 - 20*I*omega)*omega - 12*a^5*(-78 + 34*m^2 - 9*lambda)* omega^2 + 216*a^6*m*omega^3 + a^3*(-1068 - 24*m^4 - 3*lambda^3 + 2*m^2*(246 + 58*lambda + lambda^2) + lambda^2*(-74 + 32*I*omega) + lambda*(-512 + 388*I*omega) - 568*I*omega + 576*omega^2)) - 8*I*a^4*z^7*(12*I - 6*a*m*(-5 + lambda) + 2*a^5*m*(1 + lambda)*omega^2 + a^4*omega*(-23 + 20*lambda + lambda^2 - 3*m^2*(7 + lambda) - 138*I*omega - 6*I*lambda*omega) + a^3*m*(-88 - 23*lambda - lambda^2 + m^2*(16 + lambda) + 206*I*omega + 14*I*lambda*omega) + a^2*(-2*I*m^2*(31 + 4*lambda) + 3*I*(24 + 10*lambda + lambda^2 + 46*I*omega - 2*I*lambda*omega))) + z^2*(-12*(24 + 10*lambda + lambda^2 + 12*I*omega) - 8*I*a*m*(60 + 23*lambda + 2*lambda^2 - 18*I*omega) + 2*a^3*m*(-346 + 30*m^2 - 76*lambda - 3*lambda^2 - 60*I*omega)*omega - 60*a^4*(-7 + 3*m^2 - lambda)*omega^2 + 120*a^5*m*omega^3 + a^2*(-3*lambda^3 + lambda^2*(-57 + 16*I*omega) + m^2*(152 + 42*lambda + lambda^2 + 60*I*omega) + lambda*(-342 + 100*I*omega) + 12*(-54 - 23*I*omega + 12*omega^2)))))/ ((1 + a^2*z^2)^2*(1 - 2*z + a^2*z^2)^2*(24 + 10*lambda + lambda^2 - 4*I*a*m*(6*z^2 + 2*z*(4 + lambda) + 3*I*omega) + 12*I*omega + 24*a^3*m*z^2*(I*z + 2*omega) + 12*a^4*z^2*(z^2 - 2*I*z*omega - 2*omega^2) - 4*a^2*(6*z^3 + z^2*(-3 + 6*m^2 - 6*I*omega) - 2*I*z*(1 + lambda)*omega + 3*omega^2))) end elseif s == -2 return begin (z^2*(-((-1 + 2*z)*(-2 + 6*z - lambda)*(2*lambda + lambda^2 - 12*I*omega)) + 48*a^11*m*z^8*omega^2*(4*I*z + omega) + 24*a^12*z^9*(z^3 + 2*I*z^2*omega - 2*z*omega^2 - 4*I*omega^3) + 8*I*a^9*m*z^6*(9*z^4 + z^3*(-3 + 3*m^2 - 4*lambda + 18*I*omega) + 3*z^2*(-4*I*m^2 + 3*I*lambda - 18*omega)*omega + 2*z*(45 + lambda)*omega^2 - 21*I*omega^3) + a^4*z*(96*z^6 + 16*z^5*(-9 + 12*m^2 - 2*lambda - lambda^2 + 36*I*omega) - z^3*(12 + 24*m^4 + 3*lambda^3 + lambda^2*(38 + 32*I*omega) + 4*lambda*(16 + 33*I*omega) - 2*m^2*(30 + 50*lambda + lambda^2 + 288*I*omega) - 552*I*omega) + 2*z^4*(36 + 35*lambda^2 + lambda^3 - 4*m^2*(27 + 16*lambda) + lambda*(66 + 84*I*omega) - 636*I*omega) - 8*I*z^2*(3 - 3*lambda^2 + m^2*(51 + 7*lambda) + lambda*(-2 - 24*I*omega) + 36*I*omega)*omega + 4*z*(-39 - 45*m^2 + 31*lambda + 48*I*omega)*omega^2 - 96*I*omega^3) - 2*I*a^7*m*z^4*(72*z^5 + 4*z^3*(12 + lambda^2 - m^2*(12 + lambda) + 3*lambda*(5 + 6*I*omega) - 6*I*omega) + 4*z^4*(9*m^2 - 11*lambda + 36*I*omega) + I*z^2*(6 + 126*m^2 - 124*lambda - lambda^2 - 588*I*omega)*omega - 24*z*(21 + lambda)*omega^2 + 108*I*omega^3) - a^6*z^3*(48*(-3 + 2*m^2)*z^5 + 192*z^6 + 8*z^4*(m^2*(30 + 8*lambda) - 3*(lambda^2 + lambda*(2 + 2*I*omega) - 18*I*omega)) + z^3*(12 + 48*m^4 + lambda^3 + lambda^2*(29 + 16*I*omega) + lambda*(54 + 236*I*omega) - m^2*(156 + 98*lambda + lambda^2 + 756*I*omega) - 420*I*omega) + 8*I*z^2*(3 - 3*lambda^2 + m^2*(81 + 8*lambda) + lambda*(-11 - 27*I*omega) + 57*I*omega)*omega + 12*z*(30 + 34*m^2 - 17*lambda - 48*I*omega)*omega^2 + 384*I*omega^3) - 4*a^10*z^7*(36*z^4 - 3*z^3*(5 + 3*m^2 - 20*I*omega) + 2*z*(27 + 15*m^2 - 5*lambda - 24*I*omega)*omega^2 + 96*I*omega^3 - 2*z^2*omega*(15*I - 15*I*m^2 + 4*I*lambda + 24*omega)) - 2*I*a^3*m*(192*z^6 + 24*z^5*(-7 + 4*lambda) + 4*z^4*(-6 + 9*m^2 - 33*lambda - 4*lambda^2) + 3*I*z^2*(-6 + 10*m^2 - 28*lambda - lambda^2 - 44*I*omega)*omega - 8*z*(9 + lambda)*omega^2 + 12*I*omega^3 - 4*z^3*(-6 - 11*lambda - 3*lambda^2 + m^2*(6 + lambda) - 32*I*lambda*omega)) - 2*I*a^5*m*z^2*(24*z^5*(-9 + lambda) + 4*z^4*(3 + 18*m^2 - 37*lambda - 2*lambda^2 - 24*I*omega) + 3*z^2*(36*I*m^2 - I*(52*lambda + lambda^2 + 172*I*omega))*omega - 24*z*(13 + lambda)*omega^2 + 60*I*omega^3 + 4*z^3*(15 + 20*lambda + 3*lambda^2 - m^2*(15 + 2*lambda) + 9*I*omega + 43*I*lambda*omega)) - a^2*(8*z^4*(10*lambda + 5*lambda^2 - 72*I*omega) - 4*z^3*((26 - 16*m^2)*lambda + 15*lambda^2 + lambda^3 - 168*I*omega) + 4*(6 + 6*m^2 - 7*lambda)*omega^2 + 8*I*z*omega*(lambda - lambda^2 + 2*m^2*(6 + lambda) + 9*I*omega - 7*I*lambda*omega) + z^2*(3*lambda^3 + lambda^2*(21 - m^2 + 16*I*omega) + lambda*(30 - 34*m^2 - 28*I*omega) - 12*I*(15 + 11*m^2 + 4*I*omega)*omega)) + 4*a^8*z^5*(72*z^5 - 6*z^4*(9 + m^2 - 12*I*omega) + z*(-99 - 93*m^2 + 37*lambda + 144*I*omega)* omega^2 - 144*I*omega^3 - 2*I*z^2*omega*(-9 - 12*lambda - lambda^2 + 3*m^2*(19 + lambda) + 54*I*omega - 10*I*lambda*omega) - z^3*(-9 + 6*m^4 + 4*lambda + 2*lambda^2 - m^2*(33 + 8*lambda + 78*I*omega) + 54*I*omega + 22*I*lambda*omega + 48*omega^2)) + 2*a*m*(-48*I*z^4 - 24*I*z^3*(-1 + lambda) - (12 + 16*lambda + lambda^2 - 12*I*omega)*omega + 4*z^2*(7*I*lambda + 2*I*lambda^2 + 6*omega) + 4*z*((-I)*lambda^2 + 3*omega + lambda*(-2*I + 7*omega)))))/ ((1 + a^2*z^2)^2*(1 - 2*z + a^2*z^2)^2*(2*lambda + lambda^2 - 12*I*omega + 24*a^3*m*z^2*((-I)*z + 2*omega) + 4*a*m*(6*I*z^2 + 2*I*z*lambda + 3*omega) + 12*a^4*z^2*(z^2 + 2*I*z*omega - 2*omega^2) - 4*a^2*(6*z^3 + z^2*(-3 + 6*m^2 + 6*I*omega) + 2*I*z*(-3 + lambda)*omega + 3*omega^2))) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end # Cache mechanism for the outgoing coefficients at infinity # Initialize the cache with a set of fiducial parameters _cached_outgoing_coefficients_at_inf_params::NamedTuple{(:s, :m, :a, :omega, :lambda), Tuple{Int, Int, _DEFAULTDATATYPE, _DEFAULTDATATYPE, _DEFAULTDATATYPE}} = (s=-2, m=2, a=0, omega=0.5, lambda=1) _cached_outgoing_coefficients_at_inf::NamedTuple{(:expansion_coeffs, :Pcoeffs, :Qcoeffs), Tuple{Vector{_DEFAULTDATATYPE}, Vector{_DEFAULTDATATYPE}, Vector{_DEFAULTDATATYPE}}} = ( expansion_coeffs = [_DEFAULTDATATYPE(1.0)], Pcoeffs = [_DEFAULTDATATYPE(0.0)], Qcoeffs = [_DEFAULTDATATYPE(0.0)] ) function outgoing_coefficient_at_inf(s::Int, m::Int, a, omega, lambda, order::Int) #= We have derived/shown the explicit expression for different physically-relevant spin weight (s=0, \pm 1, \pm2) for up to (1/r)^3, which is probably more than enough But we have also shown a recurrence relation where one can generate as higher an order as one pleases. However, the recurrence relation that we have actually depends *all* previous terms so this function is designed to be evaluated recursively to build the full list of coefficients =# global _cached_outgoing_coefficients_at_inf_params global _cached_outgoing_coefficients_at_inf if order < 0 throw(DomainError(order, "Only positive expansion order is supported")) end if order == 0 return 1.0 # This is always 1.0 elseif order == 1 if s == 0 return (1/2)*I*(lambda + 2*a*m*omega) elseif s == +1 return (1/2)*I*(2 + lambda + 2*a*m*omega) elseif s == -1 return (I*(lambda^2 + 2*a*m*(2 + lambda)*omega))/(2*lambda) elseif s == +2 return (1/2)*I*(6 + lambda + 2*a*m*omega) elseif s == -2 return begin (1/6)*I*(-6 + 7*lambda) + I*a*m*omega + (2*I*(-3 + lambda)*lambda*(2 + lambda) + 24*(-3 - 3*I*a*m + lambda)*omega)/(-3*lambda*(2 + lambda) + 36*omega*(I - a*m + a^2*omega)) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end elseif order == 2 if s == 0 return begin (1/8)*(-lambda^2 + lambda*(2 - 4*a*m*omega) + 4*omega*(I + a*m + a*m*(2*I - a*m)*omega)) end elseif s == +1 return begin (1/8)*(-lambda^2 - 2*lambda*(1 + 2*a*m*omega) - 4*a*omega*(m - 2*a*omega - 2*I*m*omega + a*m^2*omega)) end elseif s == -1 return begin -((1/(8*lambda))*((-2 + lambda)*lambda^2 + 4*a*m*(-2 + lambda + lambda^2)*omega + 4*a*(-2*I*m*lambda + a*(2 - 2*lambda + m^2*(4 + lambda)))*omega^2)) end elseif s == +2 return begin (1/8)*(-lambda^2 - 2*lambda*(5 + 2*a*m*omega) - 4*(6 + (3*I + 5*a*m)*omega + a*m*(-2*I + a*m)*omega^2)) end elseif s == -2 return begin -((1/(8*lambda*(2 + lambda) - 96*omega*(I - a*m + a^2*omega)))* (lambda^2*(2 + lambda)^2 + 4*a*m*lambda*(16 + lambda*(14 + lambda))* omega + 4*(36 + a*(a*(10 - 11*lambda)*lambda - 2*I*m*(2 + lambda)*(6 + lambda) + a*m^2*(60 + lambda*(30 + lambda))))*omega^2 + 16*a*(-6*m + a*(3*I - 9*I*m^2 + a*m*(-15 + 3*m^2 - 7*lambda)))*omega^3 - 48*a^3*(-2*I*m + a*(-4 + m^2))*omega^4)) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end elseif order == 3 if s == 0 return begin (1/2)*(1 - I*a*m)*omega - (1/48)*I*((-6 + lambda)*(-2 + lambda)*lambda + 2*lambda*(-18*I + a*m*(-16 + 3*lambda))*omega + 4*a*(3*a*m^2*(-2 + lambda) + 2*a*(-1 + lambda) - 6*I*m*(1 + lambda))*omega^2 + 8*a*m*(-8 - 6*I*a*m + a^2*(2 + m^2))*omega^3) end elseif s == +1 return begin (-(1/48))*I*(lambda^3 + lambda^2*(-2 + 6*a*m*omega) + 4*lambda*(-2 - 2*(3*I + a*m)*omega + a*(-4*a - 6*I*m + 3*a*m^2)*omega^2) + 8*omega*(-6*I + a^3*m*(-4 + m^2)*omega^2 + 3*a^2*omega*(-1 - 2*I*m^2*omega) - a*m*(3 + 6*I*omega + 8*omega^2))) end elseif s == -1 return begin -((1/(48*lambda))*(I*((-6 + lambda)*(-2 + lambda)*lambda^2 + 48*a*m*omega + 2*lambda*(-12*I*lambda + a*m*(-16 + lambda*(-10 + 3*lambda)))*omega + 4*a*(3*a*m^2*(-2 + lambda)*(4 + lambda) - 4*a*(3 + (-2 + lambda)*lambda) - 6*I*m*(4 + lambda^2))*omega^2 + 8*a*(-8*m*lambda - 6*I*a*(-2 + m^2*(2 + lambda)) + a^2*m*(6 - 4*lambda + m^2*(6 + lambda)))*omega^3))) end elseif s == +2 return begin (-(1/48))*I*(lambda^3 + 2*lambda^2*(5 + 3*a*m*omega) + 4*lambda*(6 + (3*I + 10*a*m)*omega + a*(2*a - 6*I*m + 3*a*m^2)*omega^2) + 8*a*omega*(a*omega + 6*a*m^2*(1 - I*omega)*omega + a^2*m^3*omega^2 + m*(2 - 9*I*omega + 2*(-4 + a^2)* omega^2))) end elseif s == -2 return begin -((1/(48*(lambda*(2 + lambda) - 12*omega*(I - a*m + a^2*omega))))* (I*(-4 + lambda)*lambda^2*(2 + lambda)^2 + 2*I*a*m*lambda*(-96 + lambda*(-44 + lambda*(32 + 3*lambda)))* omega + 4*I*(36*(-4 + lambda) + a*(-6*I*m*lambda*(2 + lambda)^2 + a*lambda*(-60 + (40 - 13*lambda)*lambda) + 3*a*m^2*(-48 + lambda*(40 + lambda*(24 + lambda)))))* omega^2 + 8*I*a*(-6*I*a*(-3*(2 + lambda) + m^2*(1 + lambda)*(18 + lambda)) - 4*m*(-9 + lambda*(13 + 2*lambda)) + a^2*m*(108 - lambda*(44 + 31*lambda) + m^2*(144 + lambda*(44 + lambda))))*omega^3 - 48*a*(16*m + 28*I*a*m^2 - 2*a^2*m* (5 + 7*m^2 - 7*lambda) - I*a^3*(2*m^4 + 2*(-9 + 5*lambda) - m^2*(32 + 7*lambda)))*omega^4 - 96*I*a^3*m*(-8 - 6*I*a*m + a^2*(-10 + m^2))* omega^5)) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end else # Evaluate higher order corrections using AD _this_params = (s=s, m=m, a=a, omega=omega, lambda=lambda) # Check if we can use the cached results if _cached_outgoing_coefficients_at_inf_params == _this_params expansion_coeffs = _cached_outgoing_coefficients_at_inf.expansion_coeffs Pcoeffs = _cached_outgoing_coefficients_at_inf.Pcoeffs Qcoeffs = _cached_outgoing_coefficients_at_inf.Qcoeffs else # Cannot re-use the cached results, re-compute from zero expansion_coeffs = [_DEFAULTDATATYPE(1.0)] # order 0 Pcoeffs = [_DEFAULTDATATYPE(PplusInf_z(s, m, a, omega, lambda, 0))] # order 0 Qcoeffs = [_DEFAULTDATATYPE(0.0), _DEFAULTDATATYPE(0.0)] # the recurrence relation takes Q_{r+1} end # Compute Pcoeffs to the necessary order _P(z) = PplusInf_z(s, m, a, omega, lambda, z) _P_taylor = taylor_expand(_P, 0, order=order) for i in length(Pcoeffs):order append!(Pcoeffs, getcoeff(_P_taylor, i)) end # Compute Qcoeffs to the necessary order (to current order + 1) _Q(z) = QplusInf_z(s, m, a, omega, lambda, z) _Q_taylor = taylor_expand(_Q, 0, order=order+1) for i in length(Qcoeffs):order+1 append!(Qcoeffs, getcoeff(_Q_taylor, i)) end # Note that the expansion coefficients we store is scaled by \omega^{i} for i in length(expansion_coeffs):order _P0 = Pcoeffs[1] # P0 sum = 0.0 for k in 1:i sum += (Qcoeffs[k+2] - (i-k)*Pcoeffs[k+1])*(expansion_coeffs[i-k+1]/omega^(i-k)) end append!(expansion_coeffs, omega^(i)*((i*(i-1)*(expansion_coeffs[i]/omega^(i-1)) + sum)/(_P0*i))) end # Update cache _cached_outgoing_coefficients_at_inf_params = _this_params _cached_outgoing_coefficients_at_inf = ( expansion_coeffs = expansion_coeffs, Pcoeffs = Pcoeffs, Qcoeffs = Qcoeffs ) return expansion_coeffs[order+1] end end function PplusH(s::Int, m::Int, a, omega, lambda, x) if s == 0 return begin ((a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-((2*x*(1 + sqrt(1 - a^2) + x)*(2*sqrt(1 - a^2) + x))/ (2*(1 + sqrt(1 - a^2)) + 2*(1 + sqrt(1 - a^2))*x + x^2)^2) + (2*(sqrt(1 - a^2) + x))/(a^2 + (1 + sqrt(1 - a^2) + x)^2) + 2*I*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)))/(2*sqrt(1 - a^2) + x) end elseif s == 1 return begin (1/(2*sqrt(1 - a^2) + x))*((a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-((2*x*(1 + sqrt(1 - a^2) + x)*(2*sqrt(1 - a^2) + x))/ (2*(1 + sqrt(1 - a^2)) + 2*(1 + sqrt(1 - a^2))*x + x^2)^2) + (2*(sqrt(1 - a^2) + x))/(a^2 + (1 + sqrt(1 - a^2) + x)^2) + (2*a*x*(2*sqrt(1 - a^2) + x)*(-3*I*a^2*m*(1 + sqrt(1 - a^2) + x) - I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(1 + lambda) + a*(1 + sqrt(1 - a^2) + x)* (3 + (1 + sqrt(1 - a^2) + x)*(3 + 2*lambda))))/((1 + sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*(-2*I*a^3*m*(1 + sqrt(1 - a^2) + x) - 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(1 + lambda) + (1 + sqrt(1 - a^2) + x)^4* (2 + lambda) + a^2*(1 + sqrt(1 - a^2) + x)*(2 + (1 + sqrt(1 - a^2) + x)* (3 + 2*lambda)))) + 2*I*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega))) end elseif s == -1 return begin (1/(2*sqrt(1 - a^2) + x))*((a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-((2*x*(1 + sqrt(1 - a^2) + x)*(2*sqrt(1 - a^2) + x))/ (2*(1 + sqrt(1 - a^2)) + 2*(1 + sqrt(1 - a^2))*x + x^2)^2) + (2*(sqrt(1 - a^2) + x))/(a^2 + (1 + sqrt(1 - a^2) + x)^2) + (2*a*x*(2*sqrt(1 - a^2) + x)*(3*I*a^2*m*(1 + sqrt(1 - a^2) + x) + I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(-1 + lambda) + a*(1 + sqrt(1 - a^2) + x)* (3 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda))))/((1 + sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*(2*I*a^3*m*(1 + sqrt(1 - a^2) + x) + 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(-1 + lambda) + (1 + sqrt(1 - a^2) + x)^4* lambda + a^2*(1 + sqrt(1 - a^2) + x)*(2 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda)))) + 2*I*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega))) end elseif s == 2 return begin (1/(2*sqrt(1 - a^2) + x))*((a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-((2*x*(1 + sqrt(1 - a^2) + x)*(2*sqrt(1 - a^2) + x))/ (2*(1 + sqrt(1 - a^2)) + 2*(1 + sqrt(1 - a^2))*x + x^2)^2) + (2*(sqrt(1 - a^2) + x))/(a^2 + (1 + sqrt(1 - a^2) + x)^2) + 2*I*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega) + (8*a*x*(2*sqrt(1 - a^2) + x)*(I*m*(1 + sqrt(1 - a^2) + x)^2* (6 + (1 + sqrt(1 - a^2) + x)*(4 + lambda)) - 3*a^2*m*(1 + sqrt(1 - a^2) + x)* (3*I + 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)* (9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 - 6*I*omega) - I*(1 + sqrt(1 - a^2) + x)^2* (1 + lambda)*omega) + a^3*(-6 + 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/((1 + sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*((-(1 + sqrt(1 - a^2) + x)^4)* (24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*(1 + sqrt(1 - a^2) + x)* (I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2* (6*I + 2*I*(1 + sqrt(1 - a^2) + x)*(4 + lambda) - 3*(1 + sqrt(1 - a^2) + x)^2*omega) + 12*a^4*(-1 + 2*I*(1 + sqrt(1 - a^2) + x)*omega + 2*(1 + sqrt(1 - a^2) + x)^2*omega^2) + 4*a^2*(1 + sqrt(1 - a^2) + x)*(6 + (1 + sqrt(1 - a^2) + x)* (-3 + 6*m^2 - 6*I*omega) - 2*I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3*omega^2))))) end elseif s == -2 return begin (1/(2*sqrt(1 - a^2) + x))*((a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-((2*x*(1 + sqrt(1 - a^2) + x)*(2*sqrt(1 - a^2) + x))/ (2*(1 + sqrt(1 - a^2)) + 2*(1 + sqrt(1 - a^2))*x + x^2)^2) + (2*(sqrt(1 - a^2) + x))/(a^2 + (1 + sqrt(1 - a^2) + x)^2) + 2*I*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega) - (8*a*x*(2*sqrt(1 - a^2) + x)*((-I)*m*(1 + sqrt(1 - a^2) + x)^2* (6 + (1 + sqrt(1 - a^2) + x)*lambda) + 3*a^2*m*(1 + sqrt(1 - a^2) + x)* (3*I - 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)* (9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + I*(1 + sqrt(1 - a^2) + x)^2* (-3 + lambda)*omega) + a^3*(-6 - 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/((1 + sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*((1 + sqrt(1 - a^2) + x)^4* (2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*(1 + sqrt(1 - a^2) + x)* (-I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2* (6*I + 2*I*(1 + sqrt(1 - a^2) + x)*lambda + 3*(1 + sqrt(1 - a^2) + x)^2*omega) + a^4*(12 + 24*I*(1 + sqrt(1 - a^2) + x)*omega - 24*(1 + sqrt(1 - a^2) + x)^2*omega^2) - 4*a^2*(1 + sqrt(1 - a^2) + x)*(6 + (1 + sqrt(1 - a^2) + x)* (-3 + 6*m^2 + 6*I*omega) + 2*I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3*omega^2))))) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function QplusH(s::Int, m::Int, a, omega, lambda, x) if s == 0 return begin (1/(2*sqrt(1 - a^2) + x)^2)*((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (-(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)^2 - (1/(a^2 + (1 + sqrt(1 - a^2) + x)^2)^4)* (x^2*(1 + sqrt(1 - a^2) + x)^2*(2*sqrt(1 - a^2) + x)^2 + x*(2*sqrt(1 - a^2) + x)*(a^4 - 4*a^2*(1 + sqrt(1 - a^2) + x) - (-3 + sqrt(1 - a^2) + x)*(1 + sqrt(1 - a^2) + x)^3) + (a^2 + (1 + sqrt(1 - a^2) + x)^2)^2*(x*(2*sqrt(1 - a^2) + x)*lambda - (a*m - (a^2 + (1 + sqrt(1 - a^2) + x)^2)*omega)^2)))) end elseif s == 1 return begin (1/(2*sqrt(1 - a^2) + x)^2)*((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* ((2*I*a*x*(2*sqrt(1 - a^2) + x)*(-3*I*a^2*m*(1 + sqrt(1 - a^2) + x) - I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(1 + lambda) + a*(1 + sqrt(1 - a^2) + x)* (3 + (1 + sqrt(1 - a^2) + x)*(3 + 2*lambda)))*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega))/((1 + sqrt(1 - a^2) + x)*(a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-2*I*a^3*m*(1 + sqrt(1 - a^2) + x) - 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(1 + lambda) + (1 + sqrt(1 - a^2) + x)^4*(2 + lambda) + a^2*(1 + sqrt(1 - a^2) + x)* (2 + (1 + sqrt(1 - a^2) + x)*(3 + 2*lambda)))) - (-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)^2 - (1/(a^2 + (1 + sqrt(1 - a^2) + x)^2)^4)* (2*x*(2*sqrt(1 - a^2) + x)*(a^4 - a^2*(1 + sqrt(1 - a^2) + x) - (-2 + sqrt(1 - a^2) + x)*(1 + sqrt(1 - a^2) + x)^3) + ((1 + sqrt(1 - a^2) + x)^2*(-1 + 2*sqrt(1 - a^2) + 2*x) + a^2*(1 + 2*sqrt(1 - a^2) + 2*x))^2 + (2*a*x*(2*sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*((1 + sqrt(1 - a^2) + x)^2* (-1 + 2*sqrt(1 - a^2) + 2*x) + a^2*(1 + 2*sqrt(1 - a^2) + 2*x))* (-3*I*a^2*m*(1 + sqrt(1 - a^2) + x) - I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(1 + lambda) + a*(1 + sqrt(1 - a^2) + x)*(3 + (1 + sqrt(1 - a^2) + x)* (3 + 2*lambda))))/((1 + sqrt(1 - a^2) + x)*(-2*I*a^3*m*(1 + sqrt(1 - a^2) + x) - 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(1 + lambda) + (1 + sqrt(1 - a^2) + x)^4* (2 + lambda) + a^2*(1 + sqrt(1 - a^2) + x)*(2 + (1 + sqrt(1 - a^2) + x)* (3 + 2*lambda)))) - ((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (2*a^7*m*(1 + sqrt(1 - a^2) + x)^2*omega*(-lambda - I*(1 + sqrt(1 - a^2) + x)*omega) + a^8*(1 + lambda)*(2 + (1 + sqrt(1 - a^2) + x)^2*omega^2) - 2*I*a^5*m*(1 + sqrt(1 - a^2) + x)^2*(-6 + (1 + sqrt(1 - a^2) + x)* (4 + m^2 - lambda - 4*I*omega) - 3*I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3*omega^2) - 2*I*a*m*(1 + sqrt(1 - a^2) + x)^5* (3 + (1 + sqrt(1 - a^2) + x)*(-5 + 2*lambda) + (1 + sqrt(1 - a^2) + x)^2* (2 - lambda + 2*I*omega) - I*(1 + sqrt(1 - a^2) + x)^3*(3 + lambda)*omega + (1 + sqrt(1 - a^2) + x)^4*omega^2) - 2*I*a^3*m*(1 + sqrt(1 - a^2) + x)^3* (13 + (1 + sqrt(1 - a^2) + x)*(-17 + 2*lambda) + (1 + sqrt(1 - a^2) + x)^2* (6 + m^2 - 2*lambda - 2*I*omega) - 3*I*(1 + sqrt(1 - a^2) + x)^3*(2 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^4*omega^2) + (1 + sqrt(1 - a^2) + x)^6* (-3*(2 + lambda) - (1 + sqrt(1 - a^2) + x)^2*lambda*(2 + lambda) + 2*(1 + sqrt(1 - a^2) + x)*(2 + 3*lambda + lambda^2) + (1 + sqrt(1 - a^2) + x)^4* (2 + lambda)*omega^2) + a^6*(1 + sqrt(1 - a^2) + x)*(-16*(1 + lambda) + (1 + sqrt(1 - a^2) + x)*(5 + m^2*(-1 + lambda) + 6*lambda - lambda^2 + 2*I*omega) + (1 + sqrt(1 - a^2) + x)^3*(5 + 4*lambda)*omega^2 + 2*(1 + sqrt(1 - a^2) + x)^2*omega* (I + 2*I*m^2 + omega)) + a^4*(1 + sqrt(1 - a^2) + x)^2* (11 + 25*lambda + 2*(1 + sqrt(1 - a^2) + x)*(-5 + 3*m^2 - 13*lambda + lambda^2 - 2*I*omega) + (1 + sqrt(1 - a^2) + x)^2*(5 + 4*lambda - 3*lambda^2 + m^2*(3 + 2*lambda) - 8*I*omega) + 3*(1 + sqrt(1 - a^2) + x)^4*(3 + 2*lambda)*omega^2 + 4*(1 + sqrt(1 - a^2) + x)^3*omega* (I + 2*I*m^2 + omega)) + a^2*(1 + sqrt(1 - a^2) + x)^3* (30 + 5*(1 + sqrt(1 - a^2) + x)*(-7 + 2*lambda) - 4*(1 + sqrt(1 - a^2) + x)^2* (-2 + m^2 + lambda - lambda^2 - 3*I*omega) + (1 + sqrt(1 - a^2) + x)^3* (2 - 2*lambda - 3*lambda^2 + m^2*(4 + lambda) - 10*I*omega) + (1 + sqrt(1 - a^2) + x)^5* (7 + 4*lambda)*omega^2 + 2*(1 + sqrt(1 - a^2) + x)^4*omega*(I + 2*I*m^2 + omega))))/ ((1 + sqrt(1 - a^2) + x)^2*(-2*I*a^3*m*(1 + sqrt(1 - a^2) + x) - 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(1 + lambda) + (1 + sqrt(1 - a^2) + x)^4* (2 + lambda) + a^2*(1 + sqrt(1 - a^2) + x)*(2 + (1 + sqrt(1 - a^2) + x)* (3 + 2*lambda))))))) end elseif s == -1 return begin (1/(2*sqrt(1 - a^2) + x)^2)*((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* ((2*I*a*x*(2*sqrt(1 - a^2) + x)*(3*I*a^2*m*(1 + sqrt(1 - a^2) + x) + I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(-1 + lambda) + a*(1 + sqrt(1 - a^2) + x)* (3 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda)))*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega))/((1 + sqrt(1 - a^2) + x)*(a^2 + (1 + sqrt(1 - a^2) + x)^2)* (2*I*a^3*m*(1 + sqrt(1 - a^2) + x) + 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(-1 + lambda) + (1 + sqrt(1 - a^2) + x)^4*lambda + a^2*(1 + sqrt(1 - a^2) + x)* (2 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda)))) - (-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)^2 - (1/(a^2 + (1 + sqrt(1 - a^2) + x)^2)^4)* ((a^2 - (1 + sqrt(1 - a^2) + x)^2)^2 + 2*x*(1 + sqrt(1 - a^2) + x)* (2*sqrt(1 - a^2) + x)*(-3*a^2 + (1 + sqrt(1 - a^2) + x)^2) + (2*a*x*(2*sqrt(1 - a^2) + x)*(a^2 - (1 + sqrt(1 - a^2) + x)^2)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*(3*I*a^2*m*(1 + sqrt(1 - a^2) + x) + I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(-1 + lambda) + a*(1 + sqrt(1 - a^2) + x)* (3 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda))))/((1 + sqrt(1 - a^2) + x)* (2*I*a^3*m*(1 + sqrt(1 - a^2) + x) + 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(-1 + lambda) + (1 + sqrt(1 - a^2) + x)^4*lambda + a^2*(1 + sqrt(1 - a^2) + x)* (2 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda)))) - ((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2*(2*a^7*m*(1 + sqrt(1 - a^2) + x)^2*omega* (2 - lambda + I*(1 + sqrt(1 - a^2) + x)*omega) + a^8*(-1 + lambda)* (2 + (1 + sqrt(1 - a^2) + x)^2*omega^2) + 2*I*a^5*m*(1 + sqrt(1 - a^2) + x)^3* (-2 + m^2 - lambda + 4*I*omega - 3*I*(1 + sqrt(1 - a^2) + x)*omega + 3*I*(1 + sqrt(1 - a^2) + x)*lambda*omega + 3*(1 + sqrt(1 - a^2) + x)^2*omega^2) + (1 + sqrt(1 - a^2) + x)^6*lambda*(-3 - (1 + sqrt(1 - a^2) + x)^2*lambda + 2*(1 + sqrt(1 - a^2) + x)*(1 + lambda) + (1 + sqrt(1 - a^2) + x)^4*omega^2) + 2*I*a*m*(1 + sqrt(1 - a^2) + x)^5*(sqrt(1 - a^2) + x + 2*(1 + sqrt(1 - a^2) + x)*lambda - (1 + sqrt(1 - a^2) + x)^2*(lambda + 2*I*omega) + I*(1 + sqrt(1 - a^2) + x)^3*(1 + lambda)*omega + (1 + sqrt(1 - a^2) + x)^4*omega^2) + 2*I*a^3*m*(1 + sqrt(1 - a^2) + x)^3*(1 + (1 + sqrt(1 - a^2) + x)*(3 + 2*lambda) + (1 + sqrt(1 - a^2) + x)^2*(-2 + m^2 - 2*lambda + 2*I*omega) + 3*I*(1 + sqrt(1 - a^2) + x)^3*lambda*omega + 3*(1 + sqrt(1 - a^2) + x)^4*omega^2) + a^6*(1 + sqrt(1 - a^2) + x)*(8 - 8*lambda + (1 + sqrt(1 - a^2) + x)* (-1 + m^2*(-3 + lambda) - lambda^2 - 2*I*omega) + (1 + sqrt(1 - a^2) + x)^3*(-3 + 4*lambda)* omega^2 + 2*(1 + sqrt(1 - a^2) + x)^2*omega*(-I - 2*I*m^2 + omega)) + a^4*(1 + sqrt(1 - a^2) + x)^2*(-11 + 9*lambda + 2*(1 + sqrt(1 - a^2) + x)* (1 + 3*m^2 + lambda + lambda^2 + 2*I*omega) + (1 + sqrt(1 - a^2) + x)^2* (1 - 6*lambda - 3*lambda^2 + m^2*(-1 + 2*lambda) + 8*I*omega) + 3*(1 + sqrt(1 - a^2) + x)^4* (-1 + 2*lambda)*omega^2 + 4*(1 + sqrt(1 - a^2) + x)^3*omega*(-I - 2*I*m^2 + omega)) + a^2*(1 + sqrt(1 - a^2) + x)^3*(6 - 3*(1 + sqrt(1 - a^2) + x)*(1 + 2*lambda) - 4*(1 + sqrt(1 - a^2) + x)^2*(m^2 - 3*lambda - lambda^2 + 3*I*omega) + (1 + sqrt(1 - a^2) + x)^3*(-4*lambda - 3*lambda^2 + m^2*(2 + lambda) + 10*I*omega) + (1 + sqrt(1 - a^2) + x)^5*(-1 + 4*lambda)*omega^2 + 2*(1 + sqrt(1 - a^2) + x)^4*omega* (-I - 2*I*m^2 + omega))))/((1 + sqrt(1 - a^2) + x)^2* (2*I*a^3*m*(1 + sqrt(1 - a^2) + x) + 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(-1 + lambda) + (1 + sqrt(1 - a^2) + x)^4*lambda + a^2*(1 + sqrt(1 - a^2) + x)* (2 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda))))))) end elseif s == 2 return begin (1/(2*sqrt(1 - a^2) + x)^2)*((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (-(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)^2 - (8*I*a*x*(2*sqrt(1 - a^2) + x)*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)* (I*m*(1 + sqrt(1 - a^2) + x)^2*(6 + (1 + sqrt(1 - a^2) + x)*(4 + lambda)) - 3*a^2*m*(1 + sqrt(1 - a^2) + x)*(3*I + 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)*(9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 - 6*I*omega) - I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega) + a^3*(-6 + 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/ ((1 + sqrt(1 - a^2) + x)*(a^2 + (1 + sqrt(1 - a^2) + x)^2)* ((1 + sqrt(1 - a^2) + x)^4*(24 + 10*lambda + lambda^2 + 12*I*omega) + 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(-6*I - 2*I*(1 + sqrt(1 - a^2) + x)*(4 + lambda) + 3*(1 + sqrt(1 - a^2) + x)^2*omega) - 12*a^4*(-1 + 2*I*(1 + sqrt(1 - a^2) + x)*omega + 2*(1 + sqrt(1 - a^2) + x)^2*omega^2) - 4*a^2*(1 + sqrt(1 - a^2) + x)* (6 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 - 6*I*omega) - 2*I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3* omega^2))) - (((1 + sqrt(1 - a^2) + x)^2*(-1 + 3*sqrt(1 - a^2) + 3*x) + a^2*(1 + 3*sqrt(1 - a^2) + 3*x))^2 + x*(2*sqrt(1 - a^2) + x)* (3*a^4 + (1 + sqrt(1 - a^2) + x)^3*(8 - 3*(1 + sqrt(1 - a^2) + x))) + (8*a*x*(2*sqrt(1 - a^2) + x)*(a^2 + (1 + sqrt(1 - a^2) + x)^2)* ((1 + sqrt(1 - a^2) + x)^2*(-1 + 3*sqrt(1 - a^2) + 3*x) + a^2*(1 + 3*sqrt(1 - a^2) + 3*x))*(I*m*(1 + sqrt(1 - a^2) + x)^2* (6 + (1 + sqrt(1 - a^2) + x)*(4 + lambda)) - 3*a^2*m*(1 + sqrt(1 - a^2) + x)* (3*I + 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)* (9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 - 6*I*omega) - I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega) + a^3*(-6 + 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/ ((1 + sqrt(1 - a^2) + x)*((-(1 + sqrt(1 - a^2) + x)^4)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(I + 2*(1 + sqrt(1 - a^2) + x)* omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(6*I + 2*I*(1 + sqrt(1 - a^2) + x)* (4 + lambda) - 3*(1 + sqrt(1 - a^2) + x)^2*omega) + 12*a^4*(-1 + 2*I*(1 + sqrt(1 - a^2) + x)*omega + 2*(1 + sqrt(1 - a^2) + x)^2* omega^2) + 4*a^2*(1 + sqrt(1 - a^2) + x)*(6 + (1 + sqrt(1 - a^2) + x)* (-3 + 6*m^2 - 6*I*omega) - 2*I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3*omega^2))) - ((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (24*a^7*m*(1 + sqrt(1 - a^2) + x)^2*omega*(3 + 3*I*(1 + sqrt(1 - a^2) + x)*omega - 4*(1 + sqrt(1 - a^2) + x)^2*omega^2) - (1 + sqrt(1 - a^2) + x)^6* (24 + 10*lambda + lambda^2 + 12*I*omega)*(-12 - (1 + sqrt(1 - a^2) + x)^2*lambda + 2*(1 + sqrt(1 - a^2) + x)*(4 + lambda) + (1 + sqrt(1 - a^2) + x)^4*omega^2) - 4*a^5*m*(1 + sqrt(1 - a^2) + x)^2*(-54*I - 2*I*(1 + sqrt(1 - a^2) + x)* (-55 + 3*m^2 - 4*lambda - 18*I*omega) + 2*(1 + sqrt(1 - a^2) + x)^2* (4 + 12*m^2 - 8*lambda + 27*I*omega)*omega - 6*I*(1 + sqrt(1 - a^2) + x)^3*(8 + lambda)* omega^2 + 45*(1 + sqrt(1 - a^2) + x)^4*omega^3) + 12*a^8*(-2 - 3*(1 + sqrt(1 - a^2) + x)^2*omega^2 - 2*I*(1 + sqrt(1 - a^2) + x)^3* omega^3 + 2*(1 + sqrt(1 - a^2) + x)^4*omega^4) + 4*a^6*(1 + sqrt(1 - a^2) + x)* (60 - 3*(1 + sqrt(1 - a^2) + x)*(16 + 3*m^2 + 18*I*omega) + (1 + sqrt(1 - a^2) + x)^3*(1 + 36*m^2 - 8*lambda + 18*I*omega)*omega^2 - 2*I*(1 + sqrt(1 - a^2) + x)^4*(7 + lambda)*omega^3 + 15*(1 + sqrt(1 - a^2) + x)^5* omega^4 - 2*(1 + sqrt(1 - a^2) + x)^2*omega*(-40*I + 9*I*m^2 - 4*I*lambda + 9*omega)) + 2*a*m*(1 + sqrt(1 - a^2) + x)^4*(144*I + 8*I*(1 + sqrt(1 - a^2) + x)* (-38 + lambda) + (1 + sqrt(1 - a^2) + x)^4*(40 + 20*lambda + lambda^2 + 24*I*omega)*omega + 4*I*(1 + sqrt(1 - a^2) + x)^5*(4 + lambda)*omega^2 - 6*(1 + sqrt(1 - a^2) + x)^6* omega^3 + 4*(1 + sqrt(1 - a^2) + x)^2*(16*I + 3*I*lambda + 2*I*lambda^2 + 6*omega) - 4*I*(1 + sqrt(1 - a^2) + x)^3*(-12 + lambda + lambda^2 - 14*I*omega - 5*I*lambda*omega)) - 2*a^3*m*(1 + sqrt(1 - a^2) + x)^3*(312*I + (1 + sqrt(1 - a^2) + x)^3* (84 + 30*m^2 - 52*lambda - lambda^2 + 36*I*omega)*omega - 4*I*(1 + sqrt(1 - a^2) + x)^4* (19 + 4*lambda)*omega^2 + 48*(1 + sqrt(1 - a^2) + x)^5*omega^3 + 12*(1 + sqrt(1 - a^2) + x)*(-63*I + 3*I*m^2 - 3*I*lambda + 32*omega) + 4*(1 + sqrt(1 - a^2) + x)^2*(71*I + I*lambda^2 - I*m^2*(10 + lambda) - 104*omega + lambda*(9*I + 16*omega))) + a^2*(1 + sqrt(1 - a^2) + x)^3* (576 + 96*(1 + sqrt(1 - a^2) + x)*(-12 + 4*m^2 - 3*I*omega) + 8*(1 + sqrt(1 - a^2) + x)^2*(18 - 3*lambda^2 + m^2*(-58 + 8*lambda) + lambda*(-30 - 2*I*omega) + 46*I*omega) - 8*I*(1 + sqrt(1 - a^2) + x)^4* (-lambda^2 + 2*m^2*(7 + lambda) + lambda*(2 + 5*I*omega) + 11*I*omega)*omega + 2*(1 + sqrt(1 - a^2) + x)^5*(-34 + 24*m^2 - 20*lambda - lambda^2 - 24*I*omega)*omega^2 - 8*I*(1 + sqrt(1 - a^2) + x)^6*(1 + lambda)*omega^3 + 12*(1 + sqrt(1 - a^2) + x)^7* omega^4 + (1 + sqrt(1 - a^2) + x)^3*(lambda^3 + 36*lambda*(4 + I*omega) + 2*lambda^2*(11 - 8*I*omega) - m^2*(-136 + 42*lambda + lambda^2 - 36*I*omega) - 8*(-18 + 19*I*omega + 6*omega^2))) + a^4*(1 + sqrt(1 - a^2) + x)^2* (-672 + (1 + sqrt(1 - a^2) + x)*(960 - 72*m^2 + 624*I*omega) + (1 + sqrt(1 - a^2) + x)^4*(44 + 180*m^2 - 62*lambda - lambda^2 + 36*I*omega)*omega^2 - 8*I*(1 + sqrt(1 - a^2) + x)^5*(5 + 2*lambda)*omega^3 + 48*(1 + sqrt(1 - a^2) + x)^6* omega^4 + 8*(1 + sqrt(1 - a^2) + x)^3*omega*(56*I + I*lambda^2 - 3*I*m^2*(9 + lambda) - 46*omega + lambda*(6*I + 8*omega)) + 4*(1 + sqrt(1 - a^2) + x)^2* (6*m^4 + m^2*(7 - 8*lambda + 54*I*omega) + 2*(-15 + 10*lambda + lambda^2 - 144*I*omega - 9*I* lambda*omega + 48*omega^2)))))/((1 + sqrt(1 - a^2) + x)^2* ((-(1 + sqrt(1 - a^2) + x)^4)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(6*I + 2*I*(1 + sqrt(1 - a^2) + x)*(4 + lambda) - 3*(1 + sqrt(1 - a^2) + x)^2*omega) + 12*a^4*(-1 + 2*I*(1 + sqrt(1 - a^2) + x)* omega + 2*(1 + sqrt(1 - a^2) + x)^2*omega^2) + 4*a^2*(1 + sqrt(1 - a^2) + x)* (6 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 - 6*I*omega) - 2*I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3* omega^2))))/(a^2 + (1 + sqrt(1 - a^2) + x)^2)^4)) end elseif s == -2 return begin (1/(2*sqrt(1 - a^2) + x)^2)*((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (-(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)^2 - (8*I*a*x*(2*sqrt(1 - a^2) + x)*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)* ((-I)*m*(1 + sqrt(1 - a^2) + x)^2*(6 + (1 + sqrt(1 - a^2) + x)*lambda) + 3*a^2*m*(1 + sqrt(1 - a^2) + x)*(3*I - 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)*(9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega) + a^3*(-6 - 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/ ((1 + sqrt(1 - a^2) + x)*(a^2 + (1 + sqrt(1 - a^2) + x)^2)* ((1 + sqrt(1 - a^2) + x)^4*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(-I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(6*I + 2*I*(1 + sqrt(1 - a^2) + x)*lambda + 3*(1 + sqrt(1 - a^2) + x)^2*omega) + a^4*(12 + 24*I*(1 + sqrt(1 - a^2) + x)*omega - 24*(1 + sqrt(1 - a^2) + x)^2*omega^2) - 4*a^2*(1 + sqrt(1 - a^2) + x)* (6 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + 2*I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3* omega^2))) - (1/(a^2 + (1 + sqrt(1 - a^2) + x)^2)^4)* ((a^2*(-1 + sqrt(1 - a^2) + x) + (1 + sqrt(1 - a^2) + x)^3)^2 + x*(2*sqrt(1 - a^2) + x)*(-a^4 - 8*a^2*(1 + sqrt(1 - a^2) + x) + (1 + sqrt(1 - a^2) + x)^4) + (8*a*x*(2*sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*(a^2*(-1 + sqrt(1 - a^2) + x) + (1 + sqrt(1 - a^2) + x)^3)*((-I)*m*(1 + sqrt(1 - a^2) + x)^2* (6 + (1 + sqrt(1 - a^2) + x)*lambda) + 3*a^2*m*(1 + sqrt(1 - a^2) + x)* (3*I - 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)* (9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega) + a^3*(-6 - 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/ ((1 + sqrt(1 - a^2) + x)*((1 + sqrt(1 - a^2) + x)^4*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(-I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(6*I + 2*I*(1 + sqrt(1 - a^2) + x)*lambda + 3*(1 + sqrt(1 - a^2) + x)^2*omega) + a^4*(12 + 24*I*(1 + sqrt(1 - a^2) + x)*omega - 24*(1 + sqrt(1 - a^2) + x)^2*omega^2) - 4*a^2*(1 + sqrt(1 - a^2) + x)* (6 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + 2*I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3* omega^2))) - ((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (-24*a^7*m*(1 + sqrt(1 - a^2) + x)^2*omega*(-3 + 3*I*(1 + sqrt(1 - a^2) + x)*omega + 4*(1 + sqrt(1 - a^2) + x)^2*omega^2) - 2*a^3*m*(1 + sqrt(1 - a^2) + x)^3* (72*I - 4*I*(1 + sqrt(1 - a^2) + x)*(15 + 9*m^2 - 13*lambda) + 4*(1 + sqrt(1 - a^2) + x)^2*(I*m^2*(6 + lambda) - I*(3 + lambda^2 + lambda* (9 + 16*I*omega) + 24*I*omega)) + (1 + sqrt(1 - a^2) + x)^3* (-36 + 30*m^2 - 44*lambda - lambda^2 - 36*I*omega)*omega + 4*I*(1 + sqrt(1 - a^2) + x)^4* (3 + 4*lambda)*omega^2 + 48*(1 + sqrt(1 - a^2) + x)^5*omega^3) + 12*a^8*(-2 - 3*(1 + sqrt(1 - a^2) + x)^2*omega^2 + 2*I*(1 + sqrt(1 - a^2) + x)^3* omega^3 + 2*(1 + sqrt(1 - a^2) + x)^4*omega^4) + 4*a^6*(1 + sqrt(1 - a^2) + x)* (12 - 3*(1 + sqrt(1 - a^2) + x)*(-4 + 3*m^2 + 6*I*omega) + (1 + sqrt(1 - a^2) + x)^3*(-39 + 36*m^2 - 8*lambda - 18*I*omega)*omega^2 + 2*I*(1 + sqrt(1 - a^2) + x)^4*(3 + lambda)*omega^3 + 15*(1 + sqrt(1 - a^2) + x)^5* omega^4 + 2*(1 + sqrt(1 - a^2) + x)^2*omega*(24*I + 9*I*m^2 - 4*I*lambda + 15*omega)) - 4*a^5*m*(1 + sqrt(1 - a^2) + x)^2*(-18*I + 2*(1 + sqrt(1 - a^2) + x)^2* (-36 + 12*m^2 - 8*lambda - 27*I*omega)*omega + 6*I*(1 + sqrt(1 - a^2) + x)^3*(4 + lambda)* omega^2 + 45*(1 + sqrt(1 - a^2) + x)^4*omega^3 + 2*(1 + sqrt(1 - a^2) + x)* (9*I + 3*I*m^2 - 4*I*lambda + 30*omega)) - 2*a*m*(1 + sqrt(1 - a^2) + x)^4* (-48*I - 24*I*(1 + sqrt(1 - a^2) + x)*(-2 + lambda) + 4*I*(1 + sqrt(1 - a^2) + x)^2*(7*lambda + 2*lambda^2 + 6*I*omega) - (1 + sqrt(1 - a^2) + x)^4*(12*lambda + lambda^2 - 24*I*omega)*omega + 4*I*(1 + sqrt(1 - a^2) + x)^5*lambda*omega^2 + 6*(1 + sqrt(1 - a^2) + x)^6*omega^3 - 4*I*(1 + sqrt(1 - a^2) + x)^3*(lambda + lambda^2 + 6*I*omega + 5*I*lambda*omega)) + a^4*(1 + sqrt(1 - a^2) + x)^3*(24*m^4*(1 + sqrt(1 - a^2) + x) + 48*(-4 + 3*I*omega) + 8*(1 + sqrt(1 - a^2) + x)*(9 + lambda^2 + lambda*(2 + 13*I*omega) - 72*I*omega) - (1 + sqrt(1 - a^2) + x)^3*(60 + 54*lambda + lambda^2 + 36*I*omega)*omega^2 + 8*I*(1 + sqrt(1 - a^2) + x)^4*(-3 + 2*lambda)*omega^3 + 48*(1 + sqrt(1 - a^2) + x)^5* omega^4 + 8*(1 + sqrt(1 - a^2) + x)^2*omega*(24*I - 6*I*lambda - I*lambda^2 + 18*omega + 8*lambda*omega) + 4*m^2*(30 - (1 + sqrt(1 - a^2) + x)*(33 + 8*lambda + 54*I*omega) + 6*I*(1 + sqrt(1 - a^2) + x)^2*(5 + lambda)*omega + 45*(1 + sqrt(1 - a^2) + x)^3* omega^2)) + (1 + sqrt(1 - a^2) + x)^6*((-1 + sqrt(1 - a^2) + x)* (1 + sqrt(1 - a^2) + x)*lambda^3 + lambda^2*(12 - 12*(1 + sqrt(1 - a^2) + x) + 2*(1 + sqrt(1 - a^2) + x)^2 - (1 + sqrt(1 - a^2) + x)^4*omega^2) + 12*I*omega*(-12 + 8*(1 + sqrt(1 - a^2) + x) + (1 + sqrt(1 - a^2) + x)^4*omega^2) - 2*lambda*(-12 + 4*(1 + sqrt(1 - a^2) + x)*(2 - 3*I*omega) + 6*I*(1 + sqrt(1 - a^2) + x)^2*omega + (1 + sqrt(1 - a^2) + x)^4*omega^2)) + a^2*(1 + sqrt(1 - a^2) + x)^4*(96 + 8*(1 + sqrt(1 - a^2) + x)* (m^2*(6 + 8*lambda) - 3*(2 + lambda^2 + lambda*(2 + 2*I*omega) - 22*I*omega)) - 96*I*omega + 2*(1 + sqrt(1 - a^2) + x)^4*(6 + 24*m^2 - 12*lambda - lambda^2 + 24*I*omega)*omega^2 + 8*I*(1 + sqrt(1 - a^2) + x)^5*(-3 + lambda)*omega^3 + 12*(1 + sqrt(1 - a^2) + x)^6* omega^4 + (1 + sqrt(1 - a^2) + x)^2*(lambda^3 + lambda*(24 - 34*m^2 - 4*I*omega) + lambda^2*(14 - m^2 + 16*I*omega) - 12*I*(22 + 3*m^2 - 4*I*omega)*omega) + 8*(1 + sqrt(1 - a^2) + x)^3*omega*((-I)*lambda^2 + 2*I*m^2*(3 + lambda) + 3*omega + lambda*(2*I + 5*omega)))))/((1 + sqrt(1 - a^2) + x)^2* ((-(1 + sqrt(1 - a^2) + x)^4)*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(I - 2*(1 + sqrt(1 - a^2) + x)*omega) - 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(6*I + 2*I*(1 + sqrt(1 - a^2) + x)*lambda + 3*(1 + sqrt(1 - a^2) + x)^2*omega) + 12*a^4*(-1 - 2*I*(1 + sqrt(1 - a^2) + x)* omega + 2*(1 + sqrt(1 - a^2) + x)^2*omega^2) + 4*a^2*(1 + sqrt(1 - a^2) + x)* (6 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + 2*I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3* omega^2)))))) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end # Cache mechanism for the outgoing coefficients at horizon # Initialize the cache with a set of fiducial parameters _cached_outgoing_coefficients_at_hor_params::NamedTuple{(:s, :m, :a, :omega, :lambda), Tuple{Int, Int, _DEFAULTDATATYPE, _DEFAULTDATATYPE, _DEFAULTDATATYPE}} = (s=-2, m=2, a=0, omega=0.5, lambda=1) _cached_outgoing_coefficients_at_hor::NamedTuple{(:expansion_coeffs, :Pcoeffs, :Qcoeffs), Tuple{Vector{_DEFAULTDATATYPE}, Vector{_DEFAULTDATATYPE}, Vector{_DEFAULTDATATYPE}}} = ( expansion_coeffs = [_DEFAULTDATATYPE(1.0)], Pcoeffs = [_DEFAULTDATATYPE(0.0)], Qcoeffs = [_DEFAULTDATATYPE(0.0)] ) function outgoing_coefficient_at_hor(s::Int, m::Int, a, omega, lambda, order::Int) global _cached_outgoing_coefficients_at_hor_params global _cached_outgoing_coefficients_at_hor if order < 0 throw(DomainError(order, "Only positive expansion order is supported")) end _this_params = (s=s, m=m, a=a, omega=omega, lambda=lambda) # Check if we can use the cached results if _cached_outgoing_coefficients_at_hor_params == _this_params expansion_coeffs = _cached_outgoing_coefficients_at_hor.expansion_coeffs Pcoeffs = _cached_outgoing_coefficients_at_hor.Pcoeffs Qcoeffs = _cached_outgoing_coefficients_at_hor.Qcoeffs else # Cannot re-use the cached results, re-compute from zero expansion_coeffs = [_DEFAULTDATATYPE(1.0)] # order 0 Pcoeffs = [_DEFAULTDATATYPE(PplusH(s, m, a, omega, lambda, 0))] # order 0 Qcoeffs = [_DEFAULTDATATYPE(0.0)] # order 0 end if order > 0 # Compute series expansion coefficients for P and Q _P(x) = PplusH(s, m, a, omega, lambda, x) _Q(x) = QplusH(s, m, a, omega, lambda, x) _P_taylor = taylor_expand(_P, 0, order=order) _Q_taylor = taylor_expand(_Q, 0, order=order) for i in length(Pcoeffs):order append!(Pcoeffs, getcoeff(_P_taylor, i)) append!(Qcoeffs, getcoeff(_Q_taylor, i)) end end # Define the indicial polynomial indicial(nu) = nu*(nu - 1) + Pcoeffs[1]*nu + Qcoeffs[1] if order > 0 # Evaluate the C coefficients for i in length(expansion_coeffs):order sum = 0.0 for r in 0:i-1 sum += expansion_coeffs[r+1]*(r*Pcoeffs[i-r+1] + Qcoeffs[i-r+1]) end append!(expansion_coeffs, -sum/indicial(i)) end end # Update cache _cached_outgoing_coefficients_at_hor_params = _this_params _cached_outgoing_coefficients_at_hor = ( expansion_coeffs = expansion_coeffs, Pcoeffs = Pcoeffs, Qcoeffs = Qcoeffs ) return expansion_coeffs[order+1] end function PminusH(s::Int, m::Int, a, omega, lambda, x) if s == 0 return begin ((a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-((2*x*(1 + sqrt(1 - a^2) + x)*(2*sqrt(1 - a^2) + x))/ (2*(1 + sqrt(1 - a^2)) + 2*(1 + sqrt(1 - a^2))*x + x^2)^2) + (2*(sqrt(1 - a^2) + x))/(a^2 + (1 + sqrt(1 - a^2) + x)^2) + I*((a*m)/(1 + sqrt(1 - a^2)) - 2*omega)))/(2*sqrt(1 - a^2) + x) end elseif s == 1 return begin (1/(2*sqrt(1 - a^2) + x))*((a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-((2*x*(1 + sqrt(1 - a^2) + x)*(2*sqrt(1 - a^2) + x))/ (2*(1 + sqrt(1 - a^2)) + 2*(1 + sqrt(1 - a^2))*x + x^2)^2) + (2*(sqrt(1 - a^2) + x))/(a^2 + (1 + sqrt(1 - a^2) + x)^2) + (2*a*x*(2*sqrt(1 - a^2) + x)*(-3*I*a^2*m*(1 + sqrt(1 - a^2) + x) - I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(1 + lambda) + a*(1 + sqrt(1 - a^2) + x)* (3 + (1 + sqrt(1 - a^2) + x)*(3 + 2*lambda))))/((1 + sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*(-2*I*a^3*m*(1 + sqrt(1 - a^2) + x) - 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(1 + lambda) + (1 + sqrt(1 - a^2) + x)^4* (2 + lambda) + a^2*(1 + sqrt(1 - a^2) + x)*(2 + (1 + sqrt(1 - a^2) + x)* (3 + 2*lambda)))) + I*((a*m)/(1 + sqrt(1 - a^2)) - 2*omega))) end elseif s == -1 return begin (1/(2*sqrt(1 - a^2) + x))*((a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-((2*x*(1 + sqrt(1 - a^2) + x)*(2*sqrt(1 - a^2) + x))/ (2*(1 + sqrt(1 - a^2)) + 2*(1 + sqrt(1 - a^2))*x + x^2)^2) + (2*(sqrt(1 - a^2) + x))/(a^2 + (1 + sqrt(1 - a^2) + x)^2) + (2*a*x*(2*sqrt(1 - a^2) + x)*(3*I*a^2*m*(1 + sqrt(1 - a^2) + x) + I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(-1 + lambda) + a*(1 + sqrt(1 - a^2) + x)* (3 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda))))/((1 + sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*(2*I*a^3*m*(1 + sqrt(1 - a^2) + x) + 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(-1 + lambda) + (1 + sqrt(1 - a^2) + x)^4* lambda + a^2*(1 + sqrt(1 - a^2) + x)*(2 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda)))) + I*((a*m)/(1 + sqrt(1 - a^2)) - 2*omega))) end elseif s == 2 return begin (1/(2*sqrt(1 - a^2) + x))*((a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-((2*x*(1 + sqrt(1 - a^2) + x)*(2*sqrt(1 - a^2) + x))/ (2*(1 + sqrt(1 - a^2)) + 2*(1 + sqrt(1 - a^2))*x + x^2)^2) + (2*(sqrt(1 - a^2) + x))/(a^2 + (1 + sqrt(1 - a^2) + x)^2) + I*((a*m)/(1 + sqrt(1 - a^2)) - 2*omega) + (8*a*x*(2*sqrt(1 - a^2) + x)*(I*m*(1 + sqrt(1 - a^2) + x)^2* (6 + (1 + sqrt(1 - a^2) + x)*(4 + lambda)) - 3*a^2*m*(1 + sqrt(1 - a^2) + x)* (3*I + 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)* (9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 - 6*I*omega) - I*(1 + sqrt(1 - a^2) + x)^2* (1 + lambda)*omega) + a^3*(-6 + 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/((1 + sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*((-(1 + sqrt(1 - a^2) + x)^4)* (24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*(1 + sqrt(1 - a^2) + x)* (I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2* (6*I + 2*I*(1 + sqrt(1 - a^2) + x)*(4 + lambda) - 3*(1 + sqrt(1 - a^2) + x)^2*omega) + 12*a^4*(-1 + 2*I*(1 + sqrt(1 - a^2) + x)*omega + 2*(1 + sqrt(1 - a^2) + x)^2*omega^2) + 4*a^2*(1 + sqrt(1 - a^2) + x)*(6 + (1 + sqrt(1 - a^2) + x)* (-3 + 6*m^2 - 6*I*omega) - 2*I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3*omega^2))))) end elseif s == -2 return begin (1/(2*sqrt(1 - a^2) + x))*((a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-((2*x*(1 + sqrt(1 - a^2) + x)*(2*sqrt(1 - a^2) + x))/ (2*(1 + sqrt(1 - a^2)) + 2*(1 + sqrt(1 - a^2))*x + x^2)^2) + (2*(sqrt(1 - a^2) + x))/(a^2 + (1 + sqrt(1 - a^2) + x)^2) + I*((a*m)/(1 + sqrt(1 - a^2)) - 2*omega) - (8*a*x*(2*sqrt(1 - a^2) + x)*((-I)*m*(1 + sqrt(1 - a^2) + x)^2* (6 + (1 + sqrt(1 - a^2) + x)*lambda) + 3*a^2*m*(1 + sqrt(1 - a^2) + x)* (3*I - 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)* (9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + I*(1 + sqrt(1 - a^2) + x)^2* (-3 + lambda)*omega) + a^3*(-6 - 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/((1 + sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*((1 + sqrt(1 - a^2) + x)^4* (2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*(1 + sqrt(1 - a^2) + x)* (-I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2* (6*I + 2*I*(1 + sqrt(1 - a^2) + x)*lambda + 3*(1 + sqrt(1 - a^2) + x)^2*omega) + a^4*(12 + 24*I*(1 + sqrt(1 - a^2) + x)*omega - 24*(1 + sqrt(1 - a^2) + x)^2*omega^2) - 4*a^2*(1 + sqrt(1 - a^2) + x)*(6 + (1 + sqrt(1 - a^2) + x)* (-3 + 6*m^2 + 6*I*omega) + 2*I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3*omega^2))))) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function QminusH(s::Int, m::Int, a, omega, lambda, x) if s == 0 return begin (1/(2*sqrt(1 - a^2) + x)^2)*((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (-(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)^2 - (1/(a^2 + (1 + sqrt(1 - a^2) + x)^2)^4)* (x^2*(1 + sqrt(1 - a^2) + x)^2*(2*sqrt(1 - a^2) + x)^2 + x*(2*sqrt(1 - a^2) + x)*(a^4 - 4*a^2*(1 + sqrt(1 - a^2) + x) - (-3 + sqrt(1 - a^2) + x)*(1 + sqrt(1 - a^2) + x)^3) + (a^2 + (1 + sqrt(1 - a^2) + x)^2)^2*(x*(2*sqrt(1 - a^2) + x)*lambda - (a*m - (a^2 + (1 + sqrt(1 - a^2) + x)^2)*omega)^2)))) end elseif s == 1 return begin (1/(2*sqrt(1 - a^2) + x)^2)*((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (-((2*I*a*x*(2*sqrt(1 - a^2) + x)*(-3*I*a^2*m*(1 + sqrt(1 - a^2) + x) - I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(1 + lambda) + a*(1 + sqrt(1 - a^2) + x)* (3 + (1 + sqrt(1 - a^2) + x)*(3 + 2*lambda)))*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega))/((1 + sqrt(1 - a^2) + x)*(a^2 + (1 + sqrt(1 - a^2) + x)^2)* (-2*I*a^3*m*(1 + sqrt(1 - a^2) + x) - 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(1 + lambda) + (1 + sqrt(1 - a^2) + x)^4*(2 + lambda) + a^2*(1 + sqrt(1 - a^2) + x)* (2 + (1 + sqrt(1 - a^2) + x)*(3 + 2*lambda))))) - (-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)^2 - (1/(a^2 + (1 + sqrt(1 - a^2) + x)^2)^4)* (2*x*(2*sqrt(1 - a^2) + x)*(a^4 - a^2*(1 + sqrt(1 - a^2) + x) - (-2 + sqrt(1 - a^2) + x)*(1 + sqrt(1 - a^2) + x)^3) + ((1 + sqrt(1 - a^2) + x)^2*(-1 + 2*sqrt(1 - a^2) + 2*x) + a^2*(1 + 2*sqrt(1 - a^2) + 2*x))^2 + (2*a*x*(2*sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*((1 + sqrt(1 - a^2) + x)^2* (-1 + 2*sqrt(1 - a^2) + 2*x) + a^2*(1 + 2*sqrt(1 - a^2) + 2*x))* (-3*I*a^2*m*(1 + sqrt(1 - a^2) + x) - I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(1 + lambda) + a*(1 + sqrt(1 - a^2) + x)*(3 + (1 + sqrt(1 - a^2) + x)* (3 + 2*lambda))))/((1 + sqrt(1 - a^2) + x)*(-2*I*a^3*m*(1 + sqrt(1 - a^2) + x) - 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(1 + lambda) + (1 + sqrt(1 - a^2) + x)^4* (2 + lambda) + a^2*(1 + sqrt(1 - a^2) + x)*(2 + (1 + sqrt(1 - a^2) + x)* (3 + 2*lambda)))) - ((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (2*a^7*m*(1 + sqrt(1 - a^2) + x)^2*omega*(-lambda - I*(1 + sqrt(1 - a^2) + x)*omega) + a^8*(1 + lambda)*(2 + (1 + sqrt(1 - a^2) + x)^2*omega^2) - 2*I*a^5*m*(1 + sqrt(1 - a^2) + x)^2*(-6 + (1 + sqrt(1 - a^2) + x)* (4 + m^2 - lambda - 4*I*omega) - 3*I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3*omega^2) - 2*I*a*m*(1 + sqrt(1 - a^2) + x)^5* (3 + (1 + sqrt(1 - a^2) + x)*(-5 + 2*lambda) + (1 + sqrt(1 - a^2) + x)^2* (2 - lambda + 2*I*omega) - I*(1 + sqrt(1 - a^2) + x)^3*(3 + lambda)*omega + (1 + sqrt(1 - a^2) + x)^4*omega^2) - 2*I*a^3*m*(1 + sqrt(1 - a^2) + x)^3* (13 + (1 + sqrt(1 - a^2) + x)*(-17 + 2*lambda) + (1 + sqrt(1 - a^2) + x)^2* (6 + m^2 - 2*lambda - 2*I*omega) - 3*I*(1 + sqrt(1 - a^2) + x)^3*(2 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^4*omega^2) + (1 + sqrt(1 - a^2) + x)^6* (-3*(2 + lambda) - (1 + sqrt(1 - a^2) + x)^2*lambda*(2 + lambda) + 2*(1 + sqrt(1 - a^2) + x)*(2 + 3*lambda + lambda^2) + (1 + sqrt(1 - a^2) + x)^4* (2 + lambda)*omega^2) + a^6*(1 + sqrt(1 - a^2) + x)*(-16*(1 + lambda) + (1 + sqrt(1 - a^2) + x)*(5 + m^2*(-1 + lambda) + 6*lambda - lambda^2 + 2*I*omega) + (1 + sqrt(1 - a^2) + x)^3*(5 + 4*lambda)*omega^2 + 2*(1 + sqrt(1 - a^2) + x)^2*omega* (I + 2*I*m^2 + omega)) + a^4*(1 + sqrt(1 - a^2) + x)^2* (11 + 25*lambda + 2*(1 + sqrt(1 - a^2) + x)*(-5 + 3*m^2 - 13*lambda + lambda^2 - 2*I*omega) + (1 + sqrt(1 - a^2) + x)^2*(5 + 4*lambda - 3*lambda^2 + m^2*(3 + 2*lambda) - 8*I*omega) + 3*(1 + sqrt(1 - a^2) + x)^4*(3 + 2*lambda)*omega^2 + 4*(1 + sqrt(1 - a^2) + x)^3*omega* (I + 2*I*m^2 + omega)) + a^2*(1 + sqrt(1 - a^2) + x)^3* (30 + 5*(1 + sqrt(1 - a^2) + x)*(-7 + 2*lambda) - 4*(1 + sqrt(1 - a^2) + x)^2* (-2 + m^2 + lambda - lambda^2 - 3*I*omega) + (1 + sqrt(1 - a^2) + x)^3* (2 - 2*lambda - 3*lambda^2 + m^2*(4 + lambda) - 10*I*omega) + (1 + sqrt(1 - a^2) + x)^5* (7 + 4*lambda)*omega^2 + 2*(1 + sqrt(1 - a^2) + x)^4*omega*(I + 2*I*m^2 + omega))))/ ((1 + sqrt(1 - a^2) + x)^2*(-2*I*a^3*m*(1 + sqrt(1 - a^2) + x) - 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(1 + lambda) + (1 + sqrt(1 - a^2) + x)^4* (2 + lambda) + a^2*(1 + sqrt(1 - a^2) + x)*(2 + (1 + sqrt(1 - a^2) + x)* (3 + 2*lambda))))))) end elseif s == -1 return begin (1/(2*sqrt(1 - a^2) + x)^2)*((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (-((2*I*a*x*(2*sqrt(1 - a^2) + x)*(3*I*a^2*m*(1 + sqrt(1 - a^2) + x) + I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(-1 + lambda) + a*(1 + sqrt(1 - a^2) + x)* (3 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda)))*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega))/((1 + sqrt(1 - a^2) + x)*(a^2 + (1 + sqrt(1 - a^2) + x)^2)* (2*I*a^3*m*(1 + sqrt(1 - a^2) + x) + 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(-1 + lambda) + (1 + sqrt(1 - a^2) + x)^4*lambda + a^2*(1 + sqrt(1 - a^2) + x)* (2 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda))))) - (-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)^2 - (1/(a^2 + (1 + sqrt(1 - a^2) + x)^2)^4)* ((a^2 - (1 + sqrt(1 - a^2) + x)^2)^2 + 2*x*(1 + sqrt(1 - a^2) + x)* (2*sqrt(1 - a^2) + x)*(-3*a^2 + (1 + sqrt(1 - a^2) + x)^2) + (2*a*x*(2*sqrt(1 - a^2) + x)*(a^2 - (1 + sqrt(1 - a^2) + x)^2)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*(3*I*a^2*m*(1 + sqrt(1 - a^2) + x) + I*m*(1 + sqrt(1 - a^2) + x)^3 + 2*a^3*(-1 + lambda) + a*(1 + sqrt(1 - a^2) + x)* (3 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda))))/((1 + sqrt(1 - a^2) + x)* (2*I*a^3*m*(1 + sqrt(1 - a^2) + x) + 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(-1 + lambda) + (1 + sqrt(1 - a^2) + x)^4*lambda + a^2*(1 + sqrt(1 - a^2) + x)* (2 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda)))) - ((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2*(2*a^7*m*(1 + sqrt(1 - a^2) + x)^2*omega* (2 - lambda + I*(1 + sqrt(1 - a^2) + x)*omega) + a^8*(-1 + lambda)* (2 + (1 + sqrt(1 - a^2) + x)^2*omega^2) + 2*I*a^5*m*(1 + sqrt(1 - a^2) + x)^3* (-2 + m^2 - lambda + 4*I*omega - 3*I*(1 + sqrt(1 - a^2) + x)*omega + 3*I*(1 + sqrt(1 - a^2) + x)*lambda*omega + 3*(1 + sqrt(1 - a^2) + x)^2*omega^2) + (1 + sqrt(1 - a^2) + x)^6*lambda*(-3 - (1 + sqrt(1 - a^2) + x)^2*lambda + 2*(1 + sqrt(1 - a^2) + x)*(1 + lambda) + (1 + sqrt(1 - a^2) + x)^4*omega^2) + 2*I*a*m*(1 + sqrt(1 - a^2) + x)^5*(sqrt(1 - a^2) + x + 2*(1 + sqrt(1 - a^2) + x)*lambda - (1 + sqrt(1 - a^2) + x)^2*(lambda + 2*I*omega) + I*(1 + sqrt(1 - a^2) + x)^3*(1 + lambda)*omega + (1 + sqrt(1 - a^2) + x)^4*omega^2) + 2*I*a^3*m*(1 + sqrt(1 - a^2) + x)^3*(1 + (1 + sqrt(1 - a^2) + x)*(3 + 2*lambda) + (1 + sqrt(1 - a^2) + x)^2*(-2 + m^2 - 2*lambda + 2*I*omega) + 3*I*(1 + sqrt(1 - a^2) + x)^3*lambda*omega + 3*(1 + sqrt(1 - a^2) + x)^4*omega^2) + a^6*(1 + sqrt(1 - a^2) + x)*(8 - 8*lambda + (1 + sqrt(1 - a^2) + x)* (-1 + m^2*(-3 + lambda) - lambda^2 - 2*I*omega) + (1 + sqrt(1 - a^2) + x)^3*(-3 + 4*lambda)* omega^2 + 2*(1 + sqrt(1 - a^2) + x)^2*omega*(-I - 2*I*m^2 + omega)) + a^4*(1 + sqrt(1 - a^2) + x)^2*(-11 + 9*lambda + 2*(1 + sqrt(1 - a^2) + x)* (1 + 3*m^2 + lambda + lambda^2 + 2*I*omega) + (1 + sqrt(1 - a^2) + x)^2* (1 - 6*lambda - 3*lambda^2 + m^2*(-1 + 2*lambda) + 8*I*omega) + 3*(1 + sqrt(1 - a^2) + x)^4* (-1 + 2*lambda)*omega^2 + 4*(1 + sqrt(1 - a^2) + x)^3*omega*(-I - 2*I*m^2 + omega)) + a^2*(1 + sqrt(1 - a^2) + x)^3*(6 - 3*(1 + sqrt(1 - a^2) + x)*(1 + 2*lambda) - 4*(1 + sqrt(1 - a^2) + x)^2*(m^2 - 3*lambda - lambda^2 + 3*I*omega) + (1 + sqrt(1 - a^2) + x)^3*(-4*lambda - 3*lambda^2 + m^2*(2 + lambda) + 10*I*omega) + (1 + sqrt(1 - a^2) + x)^5*(-1 + 4*lambda)*omega^2 + 2*(1 + sqrt(1 - a^2) + x)^4*omega* (-I - 2*I*m^2 + omega))))/((1 + sqrt(1 - a^2) + x)^2* (2*I*a^3*m*(1 + sqrt(1 - a^2) + x) + 2*I*a*m*(1 + sqrt(1 - a^2) + x)^3 + a^4*(-1 + lambda) + (1 + sqrt(1 - a^2) + x)^4*lambda + a^2*(1 + sqrt(1 - a^2) + x)* (2 + (1 + sqrt(1 - a^2) + x)*(-1 + 2*lambda))))))) end elseif s == 2 return begin (1/(2*sqrt(1 - a^2) + x)^2)*((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (-(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)^2 + (8*I*a*x*(2*sqrt(1 - a^2) + x)*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)* (I*m*(1 + sqrt(1 - a^2) + x)^2*(6 + (1 + sqrt(1 - a^2) + x)*(4 + lambda)) - 3*a^2*m*(1 + sqrt(1 - a^2) + x)*(3*I + 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)*(9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 - 6*I*omega) - I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega) + a^3*(-6 + 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/ ((1 + sqrt(1 - a^2) + x)*(a^2 + (1 + sqrt(1 - a^2) + x)^2)* ((1 + sqrt(1 - a^2) + x)^4*(24 + 10*lambda + lambda^2 + 12*I*omega) + 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(-6*I - 2*I*(1 + sqrt(1 - a^2) + x)*(4 + lambda) + 3*(1 + sqrt(1 - a^2) + x)^2*omega) - 12*a^4*(-1 + 2*I*(1 + sqrt(1 - a^2) + x)*omega + 2*(1 + sqrt(1 - a^2) + x)^2*omega^2) - 4*a^2*(1 + sqrt(1 - a^2) + x)* (6 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 - 6*I*omega) - 2*I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3* omega^2))) - (((1 + sqrt(1 - a^2) + x)^2*(-1 + 3*sqrt(1 - a^2) + 3*x) + a^2*(1 + 3*sqrt(1 - a^2) + 3*x))^2 + x*(2*sqrt(1 - a^2) + x)* (3*a^4 + (1 + sqrt(1 - a^2) + x)^3*(8 - 3*(1 + sqrt(1 - a^2) + x))) + (8*a*x*(2*sqrt(1 - a^2) + x)*(a^2 + (1 + sqrt(1 - a^2) + x)^2)* ((1 + sqrt(1 - a^2) + x)^2*(-1 + 3*sqrt(1 - a^2) + 3*x) + a^2*(1 + 3*sqrt(1 - a^2) + 3*x))*(I*m*(1 + sqrt(1 - a^2) + x)^2* (6 + (1 + sqrt(1 - a^2) + x)*(4 + lambda)) - 3*a^2*m*(1 + sqrt(1 - a^2) + x)* (3*I + 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)* (9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 - 6*I*omega) - I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega) + a^3*(-6 + 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/ ((1 + sqrt(1 - a^2) + x)*((-(1 + sqrt(1 - a^2) + x)^4)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(I + 2*(1 + sqrt(1 - a^2) + x)* omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(6*I + 2*I*(1 + sqrt(1 - a^2) + x)* (4 + lambda) - 3*(1 + sqrt(1 - a^2) + x)^2*omega) + 12*a^4*(-1 + 2*I*(1 + sqrt(1 - a^2) + x)*omega + 2*(1 + sqrt(1 - a^2) + x)^2* omega^2) + 4*a^2*(1 + sqrt(1 - a^2) + x)*(6 + (1 + sqrt(1 - a^2) + x)* (-3 + 6*m^2 - 6*I*omega) - 2*I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3*omega^2))) - ((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (24*a^7*m*(1 + sqrt(1 - a^2) + x)^2*omega*(3 + 3*I*(1 + sqrt(1 - a^2) + x)*omega - 4*(1 + sqrt(1 - a^2) + x)^2*omega^2) - (1 + sqrt(1 - a^2) + x)^6* (24 + 10*lambda + lambda^2 + 12*I*omega)*(-12 - (1 + sqrt(1 - a^2) + x)^2*lambda + 2*(1 + sqrt(1 - a^2) + x)*(4 + lambda) + (1 + sqrt(1 - a^2) + x)^4*omega^2) - 4*a^5*m*(1 + sqrt(1 - a^2) + x)^2*(-54*I - 2*I*(1 + sqrt(1 - a^2) + x)* (-55 + 3*m^2 - 4*lambda - 18*I*omega) + 2*(1 + sqrt(1 - a^2) + x)^2* (4 + 12*m^2 - 8*lambda + 27*I*omega)*omega - 6*I*(1 + sqrt(1 - a^2) + x)^3*(8 + lambda)* omega^2 + 45*(1 + sqrt(1 - a^2) + x)^4*omega^3) + 12*a^8*(-2 - 3*(1 + sqrt(1 - a^2) + x)^2*omega^2 - 2*I*(1 + sqrt(1 - a^2) + x)^3* omega^3 + 2*(1 + sqrt(1 - a^2) + x)^4*omega^4) + 4*a^6*(1 + sqrt(1 - a^2) + x)* (60 - 3*(1 + sqrt(1 - a^2) + x)*(16 + 3*m^2 + 18*I*omega) + (1 + sqrt(1 - a^2) + x)^3*(1 + 36*m^2 - 8*lambda + 18*I*omega)*omega^2 - 2*I*(1 + sqrt(1 - a^2) + x)^4*(7 + lambda)*omega^3 + 15*(1 + sqrt(1 - a^2) + x)^5* omega^4 - 2*(1 + sqrt(1 - a^2) + x)^2*omega*(-40*I + 9*I*m^2 - 4*I*lambda + 9*omega)) + 2*a*m*(1 + sqrt(1 - a^2) + x)^4*(144*I + 8*I*(1 + sqrt(1 - a^2) + x)* (-38 + lambda) + (1 + sqrt(1 - a^2) + x)^4*(40 + 20*lambda + lambda^2 + 24*I*omega)*omega + 4*I*(1 + sqrt(1 - a^2) + x)^5*(4 + lambda)*omega^2 - 6*(1 + sqrt(1 - a^2) + x)^6* omega^3 + 4*(1 + sqrt(1 - a^2) + x)^2*(16*I + 3*I*lambda + 2*I*lambda^2 + 6*omega) - 4*I*(1 + sqrt(1 - a^2) + x)^3*(-12 + lambda + lambda^2 - 14*I*omega - 5*I*lambda*omega)) - 2*a^3*m*(1 + sqrt(1 - a^2) + x)^3*(312*I + (1 + sqrt(1 - a^2) + x)^3* (84 + 30*m^2 - 52*lambda - lambda^2 + 36*I*omega)*omega - 4*I*(1 + sqrt(1 - a^2) + x)^4* (19 + 4*lambda)*omega^2 + 48*(1 + sqrt(1 - a^2) + x)^5*omega^3 + 12*(1 + sqrt(1 - a^2) + x)*(-63*I + 3*I*m^2 - 3*I*lambda + 32*omega) + 4*(1 + sqrt(1 - a^2) + x)^2*(71*I + I*lambda^2 - I*m^2*(10 + lambda) - 104*omega + lambda*(9*I + 16*omega))) + a^2*(1 + sqrt(1 - a^2) + x)^3* (576 + 96*(1 + sqrt(1 - a^2) + x)*(-12 + 4*m^2 - 3*I*omega) + 8*(1 + sqrt(1 - a^2) + x)^2*(18 - 3*lambda^2 + m^2*(-58 + 8*lambda) + lambda*(-30 - 2*I*omega) + 46*I*omega) - 8*I*(1 + sqrt(1 - a^2) + x)^4* (-lambda^2 + 2*m^2*(7 + lambda) + lambda*(2 + 5*I*omega) + 11*I*omega)*omega + 2*(1 + sqrt(1 - a^2) + x)^5*(-34 + 24*m^2 - 20*lambda - lambda^2 - 24*I*omega)*omega^2 - 8*I*(1 + sqrt(1 - a^2) + x)^6*(1 + lambda)*omega^3 + 12*(1 + sqrt(1 - a^2) + x)^7* omega^4 + (1 + sqrt(1 - a^2) + x)^3*(lambda^3 + 36*lambda*(4 + I*omega) + 2*lambda^2*(11 - 8*I*omega) - m^2*(-136 + 42*lambda + lambda^2 - 36*I*omega) - 8*(-18 + 19*I*omega + 6*omega^2))) + a^4*(1 + sqrt(1 - a^2) + x)^2* (-672 + (1 + sqrt(1 - a^2) + x)*(960 - 72*m^2 + 624*I*omega) + (1 + sqrt(1 - a^2) + x)^4*(44 + 180*m^2 - 62*lambda - lambda^2 + 36*I*omega)*omega^2 - 8*I*(1 + sqrt(1 - a^2) + x)^5*(5 + 2*lambda)*omega^3 + 48*(1 + sqrt(1 - a^2) + x)^6* omega^4 + 8*(1 + sqrt(1 - a^2) + x)^3*omega*(56*I + I*lambda^2 - 3*I*m^2*(9 + lambda) - 46*omega + lambda*(6*I + 8*omega)) + 4*(1 + sqrt(1 - a^2) + x)^2* (6*m^4 + m^2*(7 - 8*lambda + 54*I*omega) + 2*(-15 + 10*lambda + lambda^2 - 144*I*omega - 9*I* lambda*omega + 48*omega^2)))))/((1 + sqrt(1 - a^2) + x)^2* ((-(1 + sqrt(1 - a^2) + x)^4)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(6*I + 2*I*(1 + sqrt(1 - a^2) + x)*(4 + lambda) - 3*(1 + sqrt(1 - a^2) + x)^2*omega) + 12*a^4*(-1 + 2*I*(1 + sqrt(1 - a^2) + x)* omega + 2*(1 + sqrt(1 - a^2) + x)^2*omega^2) + 4*a^2*(1 + sqrt(1 - a^2) + x)* (6 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 - 6*I*omega) - 2*I*(1 + sqrt(1 - a^2) + x)^2*(1 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3* omega^2))))/(a^2 + (1 + sqrt(1 - a^2) + x)^2)^4)) end elseif s == -2 return begin (1/(2*sqrt(1 - a^2) + x)^2)*((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (-(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)^2 + (8*I*a*x*(2*sqrt(1 - a^2) + x)*(-((a*m)/(2*(1 + sqrt(1 - a^2)))) + omega)* ((-I)*m*(1 + sqrt(1 - a^2) + x)^2*(6 + (1 + sqrt(1 - a^2) + x)*lambda) + 3*a^2*m*(1 + sqrt(1 - a^2) + x)*(3*I - 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)*(9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega) + a^3*(-6 - 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/ ((1 + sqrt(1 - a^2) + x)*(a^2 + (1 + sqrt(1 - a^2) + x)^2)* ((1 + sqrt(1 - a^2) + x)^4*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(-I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(6*I + 2*I*(1 + sqrt(1 - a^2) + x)*lambda + 3*(1 + sqrt(1 - a^2) + x)^2*omega) + a^4*(12 + 24*I*(1 + sqrt(1 - a^2) + x)*omega - 24*(1 + sqrt(1 - a^2) + x)^2*omega^2) - 4*a^2*(1 + sqrt(1 - a^2) + x)* (6 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + 2*I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3* omega^2))) - (1/(a^2 + (1 + sqrt(1 - a^2) + x)^2)^4)* ((a^2*(-1 + sqrt(1 - a^2) + x) + (1 + sqrt(1 - a^2) + x)^3)^2 + x*(2*sqrt(1 - a^2) + x)*(-a^4 - 8*a^2*(1 + sqrt(1 - a^2) + x) + (1 + sqrt(1 - a^2) + x)^4) + (8*a*x*(2*sqrt(1 - a^2) + x)* (a^2 + (1 + sqrt(1 - a^2) + x)^2)*(a^2*(-1 + sqrt(1 - a^2) + x) + (1 + sqrt(1 - a^2) + x)^3)*((-I)*m*(1 + sqrt(1 - a^2) + x)^2* (6 + (1 + sqrt(1 - a^2) + x)*lambda) + 3*a^2*m*(1 + sqrt(1 - a^2) + x)* (3*I - 4*(1 + sqrt(1 - a^2) + x)*omega) + a*(1 + sqrt(1 - a^2) + x)* (9 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega) + a^3*(-6 - 9*I*(1 + sqrt(1 - a^2) + x)*omega + 6*(1 + sqrt(1 - a^2) + x)^2*omega^2)))/ ((1 + sqrt(1 - a^2) + x)*((1 + sqrt(1 - a^2) + x)^4*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(-I + 2*(1 + sqrt(1 - a^2) + x)*omega) + 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(6*I + 2*I*(1 + sqrt(1 - a^2) + x)*lambda + 3*(1 + sqrt(1 - a^2) + x)^2*omega) + a^4*(12 + 24*I*(1 + sqrt(1 - a^2) + x)*omega - 24*(1 + sqrt(1 - a^2) + x)^2*omega^2) - 4*a^2*(1 + sqrt(1 - a^2) + x)* (6 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + 2*I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3* omega^2))) - ((a^2 + (1 + sqrt(1 - a^2) + x)^2)^2* (-24*a^7*m*(1 + sqrt(1 - a^2) + x)^2*omega*(-3 + 3*I*(1 + sqrt(1 - a^2) + x)*omega + 4*(1 + sqrt(1 - a^2) + x)^2*omega^2) - 2*a^3*m*(1 + sqrt(1 - a^2) + x)^3* (72*I - 4*I*(1 + sqrt(1 - a^2) + x)*(15 + 9*m^2 - 13*lambda) + 4*(1 + sqrt(1 - a^2) + x)^2*(I*m^2*(6 + lambda) - I*(3 + lambda^2 + lambda* (9 + 16*I*omega) + 24*I*omega)) + (1 + sqrt(1 - a^2) + x)^3* (-36 + 30*m^2 - 44*lambda - lambda^2 - 36*I*omega)*omega + 4*I*(1 + sqrt(1 - a^2) + x)^4* (3 + 4*lambda)*omega^2 + 48*(1 + sqrt(1 - a^2) + x)^5*omega^3) + 12*a^8*(-2 - 3*(1 + sqrt(1 - a^2) + x)^2*omega^2 + 2*I*(1 + sqrt(1 - a^2) + x)^3* omega^3 + 2*(1 + sqrt(1 - a^2) + x)^4*omega^4) + 4*a^6*(1 + sqrt(1 - a^2) + x)* (12 - 3*(1 + sqrt(1 - a^2) + x)*(-4 + 3*m^2 + 6*I*omega) + (1 + sqrt(1 - a^2) + x)^3*(-39 + 36*m^2 - 8*lambda - 18*I*omega)*omega^2 + 2*I*(1 + sqrt(1 - a^2) + x)^4*(3 + lambda)*omega^3 + 15*(1 + sqrt(1 - a^2) + x)^5* omega^4 + 2*(1 + sqrt(1 - a^2) + x)^2*omega*(24*I + 9*I*m^2 - 4*I*lambda + 15*omega)) - 4*a^5*m*(1 + sqrt(1 - a^2) + x)^2*(-18*I + 2*(1 + sqrt(1 - a^2) + x)^2* (-36 + 12*m^2 - 8*lambda - 27*I*omega)*omega + 6*I*(1 + sqrt(1 - a^2) + x)^3*(4 + lambda)* omega^2 + 45*(1 + sqrt(1 - a^2) + x)^4*omega^3 + 2*(1 + sqrt(1 - a^2) + x)* (9*I + 3*I*m^2 - 4*I*lambda + 30*omega)) - 2*a*m*(1 + sqrt(1 - a^2) + x)^4* (-48*I - 24*I*(1 + sqrt(1 - a^2) + x)*(-2 + lambda) + 4*I*(1 + sqrt(1 - a^2) + x)^2*(7*lambda + 2*lambda^2 + 6*I*omega) - (1 + sqrt(1 - a^2) + x)^4*(12*lambda + lambda^2 - 24*I*omega)*omega + 4*I*(1 + sqrt(1 - a^2) + x)^5*lambda*omega^2 + 6*(1 + sqrt(1 - a^2) + x)^6*omega^3 - 4*I*(1 + sqrt(1 - a^2) + x)^3*(lambda + lambda^2 + 6*I*omega + 5*I*lambda*omega)) + a^4*(1 + sqrt(1 - a^2) + x)^3*(24*m^4*(1 + sqrt(1 - a^2) + x) + 48*(-4 + 3*I*omega) + 8*(1 + sqrt(1 - a^2) + x)*(9 + lambda^2 + lambda*(2 + 13*I*omega) - 72*I*omega) - (1 + sqrt(1 - a^2) + x)^3*(60 + 54*lambda + lambda^2 + 36*I*omega)*omega^2 + 8*I*(1 + sqrt(1 - a^2) + x)^4*(-3 + 2*lambda)*omega^3 + 48*(1 + sqrt(1 - a^2) + x)^5* omega^4 + 8*(1 + sqrt(1 - a^2) + x)^2*omega*(24*I - 6*I*lambda - I*lambda^2 + 18*omega + 8*lambda*omega) + 4*m^2*(30 - (1 + sqrt(1 - a^2) + x)*(33 + 8*lambda + 54*I*omega) + 6*I*(1 + sqrt(1 - a^2) + x)^2*(5 + lambda)*omega + 45*(1 + sqrt(1 - a^2) + x)^3* omega^2)) + (1 + sqrt(1 - a^2) + x)^6*((-1 + sqrt(1 - a^2) + x)* (1 + sqrt(1 - a^2) + x)*lambda^3 + lambda^2*(12 - 12*(1 + sqrt(1 - a^2) + x) + 2*(1 + sqrt(1 - a^2) + x)^2 - (1 + sqrt(1 - a^2) + x)^4*omega^2) + 12*I*omega*(-12 + 8*(1 + sqrt(1 - a^2) + x) + (1 + sqrt(1 - a^2) + x)^4*omega^2) - 2*lambda*(-12 + 4*(1 + sqrt(1 - a^2) + x)*(2 - 3*I*omega) + 6*I*(1 + sqrt(1 - a^2) + x)^2*omega + (1 + sqrt(1 - a^2) + x)^4*omega^2)) + a^2*(1 + sqrt(1 - a^2) + x)^4*(96 + 8*(1 + sqrt(1 - a^2) + x)* (m^2*(6 + 8*lambda) - 3*(2 + lambda^2 + lambda*(2 + 2*I*omega) - 22*I*omega)) - 96*I*omega + 2*(1 + sqrt(1 - a^2) + x)^4*(6 + 24*m^2 - 12*lambda - lambda^2 + 24*I*omega)*omega^2 + 8*I*(1 + sqrt(1 - a^2) + x)^5*(-3 + lambda)*omega^3 + 12*(1 + sqrt(1 - a^2) + x)^6* omega^4 + (1 + sqrt(1 - a^2) + x)^2*(lambda^3 + lambda*(24 - 34*m^2 - 4*I*omega) + lambda^2*(14 - m^2 + 16*I*omega) - 12*I*(22 + 3*m^2 - 4*I*omega)*omega) + 8*(1 + sqrt(1 - a^2) + x)^3*omega*((-I)*lambda^2 + 2*I*m^2*(3 + lambda) + 3*omega + lambda*(2*I + 5*omega)))))/((1 + sqrt(1 - a^2) + x)^2* ((-(1 + sqrt(1 - a^2) + x)^4)*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*(1 + sqrt(1 - a^2) + x)*(I - 2*(1 + sqrt(1 - a^2) + x)*omega) - 4*a*m*(1 + sqrt(1 - a^2) + x)^2*(6*I + 2*I*(1 + sqrt(1 - a^2) + x)*lambda + 3*(1 + sqrt(1 - a^2) + x)^2*omega) + 12*a^4*(-1 - 2*I*(1 + sqrt(1 - a^2) + x)* omega + 2*(1 + sqrt(1 - a^2) + x)^2*omega^2) + 4*a^2*(1 + sqrt(1 - a^2) + x)* (6 + (1 + sqrt(1 - a^2) + x)*(-3 + 6*m^2 + 6*I*omega) + 2*I*(1 + sqrt(1 - a^2) + x)^2*(-3 + lambda)*omega + 3*(1 + sqrt(1 - a^2) + x)^3* omega^2)))))) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end # Cache mechanism for the ingoing coefficients at horizon # Initialize the cache with a set of fiducial parameters _cached_ingoing_coefficients_at_hor_params::NamedTuple{(:s, :m, :a, :omega, :lambda), Tuple{Int, Int, _DEFAULTDATATYPE, _DEFAULTDATATYPE, _DEFAULTDATATYPE}} = (s=-2, m=2, a=0, omega=0.5, lambda=1) _cached_ingoing_coefficients_at_hor::NamedTuple{(:expansion_coeffs, :Pcoeffs, :Qcoeffs), Tuple{Vector{_DEFAULTDATATYPE}, Vector{_DEFAULTDATATYPE}, Vector{_DEFAULTDATATYPE}}} = ( expansion_coeffs = [_DEFAULTDATATYPE(1.0)], Pcoeffs = [_DEFAULTDATATYPE(0.0)], Qcoeffs = [_DEFAULTDATATYPE(0.0)] ) function ingoing_coefficient_at_hor(s::Int, m::Int, a, omega, lambda, order::Int) global _cached_ingoing_coefficients_at_hor_params global _cached_ingoing_coefficients_at_hor if order < 0 throw(DomainError(order, "Only positive expansion order is supported")) end _this_params = (s=s, m=m, a=a, omega=omega, lambda=lambda) # Check if we can use the cached results if _cached_ingoing_coefficients_at_hor_params == _this_params expansion_coeffs = _cached_ingoing_coefficients_at_hor.expansion_coeffs Pcoeffs = _cached_ingoing_coefficients_at_hor.Pcoeffs Qcoeffs = _cached_ingoing_coefficients_at_hor.Qcoeffs else # Cannot re-use the cached results, re-compute from zero expansion_coeffs = [_DEFAULTDATATYPE(1.0)] # order 0 Pcoeffs = [_DEFAULTDATATYPE(PminusH(s, m, a, omega, lambda, 0))] # order 0 Qcoeffs = [_DEFAULTDATATYPE(0.0)] # order 0 end if order > 0 # Compute series expansion coefficients for P and Q _P(x) = PminusH(s, m, a, omega, lambda, x) _Q(x) = QminusH(s, m, a, omega, lambda, x) _P_taylor = taylor_expand(_P, 0, order=order) _Q_taylor = taylor_expand(_Q, 0, order=order) for i in length(Pcoeffs):order append!(Pcoeffs, getcoeff(_P_taylor, i)) append!(Qcoeffs, getcoeff(_Q_taylor, i)) end end # Define the indicial polynomial indicial(nu) = nu*(nu - 1) + Pcoeffs[1]*nu + Qcoeffs[1] if order > 0 # Evaluate the C coefficients for i in length(expansion_coeffs):order sum = 0.0 for r in 0:i-1 sum += expansion_coeffs[r+1]*(r*Pcoeffs[i-r+1] + Qcoeffs[i-r+1]) end append!(expansion_coeffs, -sum/indicial(i)) end end # Update cache _cached_ingoing_coefficients_at_hor_params = _this_params _cached_ingoing_coefficients_at_hor = ( expansion_coeffs = expansion_coeffs, Pcoeffs = Pcoeffs, Qcoeffs = Qcoeffs ) return expansion_coeffs[order+1] end end
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
6678
module ConversionFactors const I = 1im #= The conversion factors here are *always* defined as the ratio of the coefficient in Teukosky equation *over* the coefficient in the Sasaki-Nakamura formalism =# function Ctrans(s::Int, m::Int, a, omega, lambda) if s == 0 return 1 elseif s == +1 inv = 2*I*omega return 1/inv elseif s == -1 return (2*I*omega)/lambda elseif s == +2 inv = -(4*omega^2) return 1/inv elseif s == -2 return begin (4*omega^2)/(-lambda*(2+lambda)+12*I*omega-12*a*m*omega+12*(a*omega)^2) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function Binc(s::Int, m::Int, a, omega, lambda) if s == 0 return 1 elseif s == +1 return -((2*I*omega)/(2 + lambda)) elseif s == -1 inv = -(2*I*omega) return 1/inv elseif s == +2 return begin (4*omega^2)/(-24 - 10*lambda - lambda^2 - 12*I*omega - 12*a*m*omega + 12*a^2*omega^2) end elseif s == -2 inv = -(4*omega^2) return 1/inv else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function Btrans(s::Int, m::Int, a, omega, lambda) if s == 0 inv = sqrt(2)*sqrt(1 + sqrt(1 - a^2)) return 1/inv elseif s == +1 return begin (sqrt(2)*sqrt(1 + sqrt(1 - a^2))*((-a)*m + 2*(1 + sqrt(1 - a^2))*omega))/ (2*a*m + 2*I*(2 + lambda)) end elseif s == -1 inv = begin (1/(1 + sqrt(1 - a^2))^(5/2))*(4*sqrt(2)*(2 - 2*a^2 + 2*sqrt(1 - a^2) - a^2*sqrt(1 - a^2) + 2*I*a*m - I*a^3*m + 2*I*a*sqrt(1 - a^2)*m - 8*I*omega + 6*I*a^2*omega - 8*I*sqrt(1 - a^2)*omega + 2*I*a^2*sqrt(1 - a^2)*omega)) end return 1/inv elseif s == +2 return begin (2*sqrt(2)*(1 + sqrt(1 - a^2))^(3/2)*(2*a*(1 + sqrt(1 - a^2))*m*(1 + 8*I*omega) - 8*I*(1 + sqrt(1 - a^2))*omega*(-I + 4*omega) + a^3*m*(-2 - sqrt(1 - a^2) - 4*I*(3 + sqrt(1 - a^2))*omega) + I*a^4*(m^2 + 2*(I - 2*omega)*omega) + 2*a^2*((-I)*(1 + sqrt(1 - a^2))*m^2 + omega*(5 + 3*sqrt(1 - a^2) + 8*I*(2 + sqrt(1 - a^2))*omega))))/ (16*a*(1 + sqrt(1 - a^2))*m*(11 + 2*lambda + 6*I*omega) + 8*I*(1 + sqrt(1 - a^2))* (24 + lambda*(10 + lambda) + 12*I*omega) - 36*I*a^5*m*omega + 12*I*a^6*omega^2 - 8*a^3*m*(18 + 7*sqrt(1 - a^2) + (3 + sqrt(1 - a^2))*lambda - 6*I*sqrt(1 - a^2)*omega) + a^4*(24*I*m^2 + I*(4 + lambda)*(6 + lambda) + 32*sqrt(1 - a^2)*omega + 8*sqrt(1 - a^2)*lambda*omega + 12*(5 + 2*lambda)*omega + 48*I*omega^2) + 4*a^2*(-24*I*(2 + sqrt(1 - a^2)) - 12*I*(1 + sqrt(1 - a^2))*m^2 - 10*I*(2 + sqrt(1 - a^2))*lambda - I*(2 + sqrt(1 - a^2))*lambda^2 - 8*(1 + sqrt(1 - a^2))*lambda*omega + 4*omega*(1 - 2*sqrt(1 - a^2) - 6*I*(1 + sqrt(1 - a^2))*omega))) end elseif s == -2 inv = begin -((1/(1 + sqrt(1 - a^2))^(3/2))*(4*(sqrt(2)*(-4 + 6*a^2 - 2*a^4 - 4*sqrt(1 - a^2) + 4*a^2*sqrt(1 - a^2) - 6*I*a*m + 6*I*a^3*m - 6*I*a*sqrt(1 - a^2)*m + 3*I*a^3*sqrt(1 - a^2)*m + 2*a^2*m^2 - a^4*m^2 + 2*a^2*sqrt(1 - a^2)*m^2 + 24*I*omega - 30*I*a^2*omega + 6*I*a^4*omega + 24*I*sqrt(1 - a^2)*omega - 18*I*a^2*sqrt(1 - a^2)*omega - 16*a*m*omega + 12*a^3*m*omega - 16*a*sqrt(1 - a^2)*m*omega + 4*a^3*sqrt(1 - a^2)*m*omega + 32*omega^2 - 32*a^2*omega^2 + 4*a^4*omega^2 + 32*sqrt(1 - a^2)*omega^2 - 16*a^2*sqrt(1 - a^2)*omega^2)))) end return 1/inv else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function Cinc(s::Int, m::Int, a, omega, lambda) if s == 0 return 1/(sqrt(2)*sqrt(1 + sqrt(1 - a^2))) elseif s == +1 inv = begin (4*sqrt(2)*((-I)*a*(1 + sqrt(1 - a^2))*m + a^2*(-1 - 2*I*omega) + (1 + sqrt(1 - a^2))*(1 + 4*I*omega)))/(1 + sqrt(1 - a^2))^(3/2) end return 1/inv elseif s == -1 return begin (-4*a*m + 3*a^3*m - 4*a*sqrt(1 - a^2)*m + a^3*sqrt(1 - a^2)*m + 16*omega - 16*a^2*omega + 2*a^4*omega + 16*sqrt(1 - a^2)*omega - 8*a^2*sqrt(1 - a^2)*omega)/ (sqrt(2)*sqrt(1 + sqrt(1 - a^2))*(2 - a^2 + 2*sqrt(1 - a^2))*(a*m - I*lambda)) end elseif s == +2 inv = begin -((1/(1 + sqrt(1 - a^2))^(3/2))*(4*sqrt(2)*(-2*a*(1 + sqrt(1 - a^2))*m*(-3*I + 8*omega) + a^3*m*(-3*I*(2 + sqrt(1 - a^2)) + 4*(3 + sqrt(1 - a^2))*omega) - a^4*(2 + m^2 + 6*I*omega - 4*omega^2) + 4*(1 + sqrt(1 - a^2))*(-1 - 6*I*omega + 8*omega^2) + 2*a^2*(3 + 2*sqrt(1 - a^2) + (1 + sqrt(1 - a^2))*m^2 + omega*(3*I*(5 + 3*sqrt(1 - a^2)) - 8*(2 + sqrt(1 - a^2))*omega))))) end return 1/inv elseif s == -2 return begin -((2*sqrt(2)*(1 + sqrt(1 - a^2))^(3/2)*(-2*I*a*m + 2*I*a^3*m - 2*I*a*sqrt(1 - a^2)*m + I*a^3*sqrt(1 - a^2)*m + 2*a^2*m^2 - a^4*m^2 + 2*a^2*sqrt(1 - a^2)*m^2 + 8*I*omega - 10*I*a^2*omega + 2*I*a^4*omega + 8*I*sqrt(1 - a^2)*omega - 6*I*a^2*sqrt(1 - a^2)*omega - 16*a*m*omega + 12*a^3*m*omega - 16*a*sqrt(1 - a^2)*m*omega + 4*a^3*sqrt(1 - a^2)*m*omega + 32*omega^2 - 32*a^2*omega^2 + 4*a^4*omega^2 + 32*sqrt(1 - a^2)*omega^2 - 16*a^2*sqrt(1 - a^2)*omega^2))/((1 + sqrt(1 - a^2))^4*(lambda*(2 + lambda) - 12*I*omega) + 24*a^3*(1 + sqrt(1 - a^2))*m*(-I + 2*(1 + sqrt(1 - a^2))*omega) + 4*a*(1 + sqrt(1 - a^2))^2*m*(6*I + 2*I*(1 + sqrt(1 - a^2))*lambda + 3*(1 + sqrt(1 - a^2))^2*omega) - 4*a^2*(1 + sqrt(1 - a^2))* (6 + (1 + sqrt(1 - a^2))*(-3 + 6*m^2) + 2*I*(1 + sqrt(1 - a^2))* (3 + (1 + sqrt(1 - a^2))*(-3 + lambda))*omega + 3*(1 + sqrt(1 - a^2))^3*omega^2) + 12*a^4*(1 - 2*(1 + sqrt(1 - a^2))*omega*(-I + omega + sqrt(1 - a^2)*omega)))) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end # These functions are redundant and are defined for convenience # The conversion factor for Cref is identical to Btrans function Cref(s::Int, m::Int, a, omega, lambda) return Btrans(s, m, a, omega, lambda) end # The conversion factor for Bref is identical to Ctrans function Bref(s::Int, m::Int, a, omega, lambda) return Ctrans(s, m, a, omega, lambda) end end
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
2167
module Coordinates using ..Kerr using Roots using Interpolations export rstar_from_r, r_from_rstar function rstar_from_rp(a, r_from_rp) rp = r_plus(a) rm = r_minus(a) return rp + r_from_rp + (2*1*rp)/(rp-rm) * log(r_from_rp/(2*1)) - (2*1*rm)/(rp-rm) * log((r_from_rp+rp-rm)/(2*1)) end @doc raw""" rstar_from_r(a, r) Convert a Boyer-Lindquist coordinate `r` to the corresponding tortoise coordinate `rstar`. """ function rstar_from_r(a, r) rp = r_plus(a) return rstar_from_rp(a, r-rp) end @doc raw""" r_from_rstar(a, rstar) Convert a tortoise coordinate `rstar` to the corresponding Boyer-Lindquist coordiante `r`. It uses a bisection method when `rstar <= 0`, and Newton method otherwise. The function assumes that $r \geq r_{+}$ where $r_{+}$ is the outer event horizon. """ function r_from_rstar(a, rstar) rp = r_plus(a) #= To find r' that solves the equation rstar_from_r(r') = rstar, we first write r' = rp + h' and instead solve for h', then add back rp i.e. we solve the equation rstar_from_rp(h') = rstar =# # The root-finding algorithm might try a negative x, which is not allowed # We rectify this by taking an absolute value, i.e. we solve for distance from rp f(x) = rstar_from_rp(a, abs(x)) - rstar if rstar <= 0 #= When rstar <= 0, it is more efficient to use bisection method, this is because in this case h' is bounded (weakly), h' cannot be smaller than 0 (since r=rp maps to rstar=-Inf), and suppose h'_u solves the equation rstar_from_rp(h'_u) = 0.0, in which h'_u is a function of |a| The maximum of h'_u occurs when |a| -> 1 with value ~ 1.328 =# return rp + find_zero(f, (0, 1.4)) else # Use Newton method instead; for large rstar, rstar \approx r return rp + abs(find_zero((f, x -> sign(x)*((rp + abs(x))^2 + a^2)/Delta(a, rp+abs(x))), rstar, Roots.Newton())) end end function build_r_from_rstar_interpolant(a, rsin, rsout; rsstep::Float64=0.01) rsgrid = collect(rsin:rsstep:rsout) return linear_interpolation(rsgrid, (x -> r_from_rstar(a, x)).(rsgrid)) end end
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
26674
module GeneralizedSasakiNakamura include("Kerr.jl") include("Coordinates.jl") include("AsymptoticExpansionCoefficients.jl") include("InitialConditions.jl") include("ConversionFactors.jl") include("Potentials.jl") include("Transformation.jl") include("Solutions.jl") using .Coordinates export r_from_rstar, rstar_from_r # Useful to be exposed using .Solutions using SpinWeightedSpheroidalHarmonics using DifferentialEquations # Should have been compiled by now export GSN_radial, Teukolsky_radial # Default values _DEFAULT_rsin = -50 _DEFAULT_rsout = 1000 _DEFAULT_horizon_expansion_order = 3 _DEFAULT_infinity_expansion_order = 6 # IN for purely-ingoing at the horizon and UP for purely-outgoing at infinity # OUT for purely-outgoing at the horizon and DOWN for purely-ingoing at infinity @enum BoundaryCondition begin IN = 1 UP = 2 OUT = 3 DOWN = 4 end export IN, UP, OUT, DOWN # Use these to specify the BC # Normalization convention, UNIT_GSN_TRANS means that the transmission amplitude for GSN functions is normalized to 1, vice versa @enum NormalizationConvention begin UNIT_GSN_TRANS = 1 UNIT_TEUKOLSKY_TRANS = 2 end export UNIT_GSN_TRANS, UNIT_TEUKOLSKY_TRANS struct Mode s::Int # spin weight l::Int # harmonic index m::Int # azimuthal index a # Kerr spin parameter omega # frequency lambda # SWSH eigenvalue end # Implement pretty-printing for Mode type # REPL function Base.show(io::IO, ::MIME"text/plain", mode::Mode) print(io, "Mode(s=$(mode.s), l=$(mode.l), m=$(mode.m), a=$(mode.a), omega=$(mode.omega), lambda=$(mode.lambda))") end struct GSNRadialFunction mode::Mode # Information about the mode boundary_condition::BoundaryCondition # The boundary condition that this radial function statisfies rsin # The numerical inner boundary where the GSN equation is numerically evolved rsout # The numerical outer boundary where the GSN equation is numerically evolved horizon_expansion_order::Union{Int, Missing} # The order of the asymptotic expansion at the horizon infinity_expansion_order::Union{Int, Missing} # The order of the asymptotic expansion at infinity transmission_amplitude # In GSN formalism incidence_amplitude # In GSN formalism reflection_amplitude # In GSN formalism numerical_GSN_solution::Union{ODESolution, Missing} # Store the numerical solution to the GSN equation in [rsin, rsout] numerical_Riccati_solution::Union{ODESolution, Missing} # Store the numerical solution to the GSN equation in the Riccati form if applicable GSN_solution # Store the *full* GSN solution where asymptotic solutions are smoothly attached normalization_convention::NormalizationConvention # The normalization convention used for the *stored* GSN solution end # Implement pretty-printing for GSNRadialFunction # Mostly to suppress the printing of the numerical solution function Base.show(io::IO, ::MIME"text/plain", gsn_func::GSNRadialFunction) println(io, "GSNRadialFunction(") print(io, " mode="); show(io, "text/plain", gsn_func.mode); println(io, ",") println(io, " boundary_condition=$(gsn_func.boundary_condition),") println(io, " rsin=$(gsn_func.rsin),") println(io, " rsout=$(gsn_func.rsout),") println(io, " horizon_expansion_order=$(gsn_func.horizon_expansion_order),") println(io, " infinity_expansion_order=$(gsn_func.infinity_expansion_order),") println(io, " transmission_amplitude=$(gsn_func.transmission_amplitude),") println(io, " incidence_amplitude=$(gsn_func.incidence_amplitude),") println(io, " reflection_amplitude=$(gsn_func.reflection_amplitude),") println(io, " normalization_convention=$(gsn_func.normalization_convention)") print(io, ")") end function Base.show(io::IO, gsn_func::GSNRadialFunction) print(io, "GSNRadialFunction(mode="); show(io, "text/plain", gsn_func.mode); print(", boundary_condition=$(gsn_func.boundary_condition))") end struct TeukolskyRadialFunction mode::Mode # Information about the mode boundary_condition::BoundaryCondition # The boundary condition that this radial function statisfies transmission_amplitude # In Teukolsky formalism incidence_amplitude # In Teukolsky formalism reflection_amplitude # In Teukolsky formalism GSN_solution::Union{GSNRadialFunction, Missing} # Store the full GSN solution Teukolsky_solution # Store the full Teukolsky solution normalization_convention::NormalizationConvention # The normalization convention used for the *stored* Teukolsky solution end # Implement pretty-printing for TeukolskyRadialFunction # Mostly to suppress the printing of the numerical solution function Base.show(io::IO, ::MIME"text/plain", teuk_func::TeukolskyRadialFunction) println(io, "TeukolskyRadialFunction(") print(io, " mode="); show(io, "text/plain", teuk_func.mode); println(io, ",") println(io, " boundary_condition=$(teuk_func.boundary_condition),") println(io, " transmission_amplitude=$(teuk_func.transmission_amplitude),") println(io, " incidence_amplitude=$(teuk_func.incidence_amplitude),") println(io, " reflection_amplitude=$(teuk_func.reflection_amplitude),") println(io, " normalization_convention=$(teuk_func.normalization_convention)") print(io, ")") end function Base.show(io::IO, teuk_func::TeukolskyRadialFunction) print(io, "TeukolskyRadialFunction(mode="); show(io, "text/plain", teuk_func.mode); print(", boundary_condition=$(teuk_func.boundary_condition))") end @doc raw""" GSN_radial(s::Int, l::Int, m::Int, a, omega, boundary_condition, rsin, rsout; horizon_expansion_order::Int=_DEFAULT_horizon_expansion_order, infinity_expansion_order::Int=_DEFAULT_infinity_expansion_order, data_type=Solutions._DEFAULTDATATYPE, ODE_algorithm=Solutions._DEFAULTSOLVER, tolerance=Solutions._DEFAULTTOLERANCE) Compute the GSN function for a given mode (specified by `s` the spin weight, `l` the harmonic index, `m` the azimuthal index, `a` the Kerr spin parameter, and `omega` the frequency) and boundary condition specified by `boundary_condition`, which can be either - `IN` for purely-ingoing at the horizon, - `UP` for purely-outgoing at infinity, - `OUT` for purely-outgoing at the horizon, - `DOWN` for purely-ingoing at infinity. Note that the `OUT` and `DOWN` solutions are constructed by linearly combining the `IN` and `UP` solutions, respectively. The GSN function is numerically solved in the interval of *tortoise coordinates* $r_{*} \in$ `[rsin, rsout]` using the ODE solver (from `DifferentialEquations.jl`) specified by `ODE_algorithm` (default: `Vern9()`) with tolerance specified by `tolerance` (default: `1e-12`). By default the data type used is `ComplexF64` (i.e. double-precision floating-point number) but it can be changed by specifying `data_type` (e.g. `Complex{BigFloat}` for complex arbitrary precision number). While the numerical GSN solution is only accurate in the range `[rsin, rsout]`, the full GSN solution is constructed by smoothly attaching the asymptotic solutions near horizon (up to `horizon_expansion_order`-th order) and infinity (up to `infinity_expansion_order`-th order). Therefore, the now-semi-analytical GSN solution is *accurate everywhere*. Note, however, when `omega = 0`, the exact GSN function expressed using Gauss hypergeometric functions will be returned (i.e., instead of being solved numerically). In this case, only `s`, `l`, `m`, `a`, `omega`, `boundary_condition` will be parsed. Return a `GSNRadialFunction` object which contains all the information about the GSN solution. """ function GSN_radial( s::Int, l::Int, m::Int, a, omega, boundary_condition, rsin, rsout; horizon_expansion_order::Int=_DEFAULT_horizon_expansion_order, infinity_expansion_order::Int=_DEFAULT_infinity_expansion_order, data_type=Solutions._DEFAULTDATATYPE, ODE_algorithm=Solutions._DEFAULTSOLVER, tolerance=Solutions._DEFAULTTOLERANCE ) if omega == 0 return GSN_radial(s, l, m, a, omega, boundary_condition) else # Compute the SWSH eigenvalue lambda = spin_weighted_spheroidal_eigenvalue(s, l, m, a*omega) # Fill in the mode information mode = Mode(s, l, m, a, omega, lambda) if boundary_condition == IN # Solve for Xin # NOTE For now we do *not* implement intelligent switching between the Riccati and the GSN form # Actually solve for Phiin first Phiinsoln = Solutions.solve_Phiin(s, m, a, omega, lambda, rsin, rsout; initialconditions_order=horizon_expansion_order, dtype=data_type, odealgo=ODE_algorithm, abstol=tolerance, reltol=tolerance) # Then convert to Xin Xinsoln = Solutions.Xsoln_from_Phisoln(Phiinsoln) # Extract the incidence and reflection amplitudes (NOTE: transmisson amplitude is *always* 1) Bref_SN, Binc_SN = Solutions.BrefBinc_SN_from_Xin(s, m, a, omega, lambda, Xinsoln, rsout; order=infinity_expansion_order) # Construct the full, 'semi-analytical' GSN solution semianalytical_Xinsoln(rs) = Solutions.semianalytical_Xin(s, m, a, omega, lambda, Xinsoln, rsin, rsout, horizon_expansion_order, infinity_expansion_order, rs) return GSNRadialFunction( mode, IN, rsin, rsout, horizon_expansion_order, infinity_expansion_order, data_type(1), Binc_SN, Bref_SN, missing, Phiinsoln, semianalytical_Xinsoln, UNIT_GSN_TRANS ) elseif boundary_condition == UP # Solve for Xup # NOTE For now we do *not* implement intelligent switching between the Riccati and the GSN form # Actually solve for Phiup first Phiupsoln = Solutions.solve_Phiup(s, m, a, omega, lambda, rsin, rsout; initialconditions_order=infinity_expansion_order, dtype=data_type, odealgo=ODE_algorithm, abstol=tolerance, reltol=tolerance) # Then convert to Xup Xupsoln = Solutions.Xsoln_from_Phisoln(Phiupsoln) # Extract the incidence and reflection amplitudes (NOTE: transmisson amplitude is *always* 1) Cref_SN, Cinc_SN = Solutions.CrefCinc_SN_from_Xup(s, m, a, omega, lambda, Xupsoln, rsin; order=horizon_expansion_order) # Construct the full, 'semi-analytical' GSN solution semianalytical_Xupsoln(rs) = Solutions.semianalytical_Xup(s, m, a, omega, lambda, Xupsoln, rsin, rsout, horizon_expansion_order, infinity_expansion_order, rs) return GSNRadialFunction( mode, UP, rsin, rsout, horizon_expansion_order, infinity_expansion_order, data_type(1), Cinc_SN, Cref_SN, missing, Phiupsoln, semianalytical_Xupsoln, UNIT_GSN_TRANS ) elseif boundary_condition == DOWN # Construct Xdown from Xin and Xup, instead of solving the ODE numerically with the boundary condition # Solve for Xin *and* Xup first Xin = GSN_radial(s, l, m, a, omega, IN, rsin, rsout, horizon_expansion_order=horizon_expansion_order, infinity_expansion_order=infinity_expansion_order, data_type=data_type, ODE_algorithm=ODE_algorithm, tolerance=tolerance) Xup = GSN_radial(s, l, m, a, omega, UP, rsin, rsout, horizon_expansion_order=horizon_expansion_order, infinity_expansion_order=infinity_expansion_order, data_type=data_type, ODE_algorithm=ODE_algorithm, tolerance=tolerance) # Xdown is a linear combination of Xin and Xup with the following coefficients Btrans = Xin.transmission_amplitude # Should really be just 1 Binc = Xin.incidence_amplitude Bref = Xin.reflection_amplitude Ctrans = Xup.transmission_amplitude # Should really be just 1 Cinc = Xup.incidence_amplitude Cref = Xup.reflection_amplitude _full_Xdown_solution(rs) = Binc^-1 .* (Xin.GSN_solution(rs) .- Bref/Ctrans .* Xup.GSN_solution(rs)) # These solutions are "normalized" in the sense that Xdown -> exp(-i*omega*rs) near infinity # NOTE The definition of the "incidence" and "reflection" amplitudes follow 2101.04592, Eq. (93) return GSNRadialFunction( Xin.mode, DOWN, rsin, rsout, horizon_expansion_order, infinity_expansion_order, data_type(1), Btrans/Binc - (Bref*Cref)/(Binc*Ctrans), (-Bref*Cinc)/(Binc*Ctrans), missing, missing, _full_Xdown_solution, UNIT_GSN_TRANS ) elseif boundary_condition == OUT # Construct Xout from Xin and Xup, instead of solving the ODE numerically with the boundary condition # Solve for Xin *and* Xup first Xin = GSN_radial(s, l, m, a, omega, IN, rsin, rsout, horizon_expansion_order=horizon_expansion_order, infinity_expansion_order=infinity_expansion_order, data_type=data_type, ODE_algorithm=ODE_algorithm, tolerance=tolerance) Xup = GSN_radial(s, l, m, a, omega, UP, rsin, rsout, horizon_expansion_order=horizon_expansion_order, infinity_expansion_order=infinity_expansion_order, data_type=data_type, ODE_algorithm=ODE_algorithm, tolerance=tolerance) # Xout is a linear combination of Xin and Xup with the following coefficients Btrans = Xin.transmission_amplitude # Should really be just 1 Binc = Xin.incidence_amplitude Bref = Xin.reflection_amplitude Ctrans = Xup.transmission_amplitude # Should really be just 1 Cinc = Xup.incidence_amplitude Cref = Xup.reflection_amplitude _full_Xout_solution(rs) = Cinc^-1 .* (Xup.GSN_solution(rs) .- Cref/Btrans .* Xin.GSN_solution(rs)) # These solutions are "normalized" in the sense that Xout -> exp(i*p*rs) near the horizon # NOTE The definition of the "incidence" and "reflection" amplitudes follow 2101.04592, Eq. (93) return GSNRadialFunction( Xin.mode, OUT, rsin, rsout, horizon_expansion_order, infinity_expansion_order, data_type(1), Ctrans/Cinc - (Bref*Cref)/(Btrans*Cinc), (-Binc*Cref)/(Btrans*Cinc), missing, missing, _full_Xout_solution, UNIT_GSN_TRANS ) else error("Boundary condition must be IN or UP") end end end function GSN_radial( s::Int, l::Int, m::Int, a, omega, boundary_condition ) if omega != 0 return GSN_radial(s, l, m, a, omega, boundary_condition, _DEFAULT_rsin, _DEFAULT_rsout) else teuk_func = Teukolsky_radial(s, l, m, a, omega, boundary_condition) GSN_solution = Solutions.Sasaki_Nakamura_function_from_Teukolsky_radial_function(s, m, a, omega, teuk_func.mode.lambda, teuk_func.Teukolsky_solution) return GSNRadialFunction( teuk_func.mode, boundary_condition, missing, missing, missing, missing, missing, missing, missing, missing, missing, GSN_solution, UNIT_TEUKOLSKY_TRANS ) end end @doc raw""" GSN_radial(s::Int, l::Int, m::Int, a, omega) Compute the GSN function for a given mode (specified by `s` the spin weight, `l` the harmonic index, `m` the azimuthal index, `a` the Kerr spin parameter, and `omega` the frequency) with the purely-ingoing boundary condition at the horizon (`IN`) and the purely-outgoing boundary condition at infinity (`UP`). Note that the numerical inner boundary (rsin) and outer boundary (rsout) are set to the default values `_DEFAULT_rsin` and `_DEFAULT_rsout`, respectively, while the order of the asymptotic expansion at the horizon and infinity are determined automatically. """ function GSN_radial(s::Int, l::Int, m::Int, a, omega) # The maximum expansion order to use _MAX_horizon_expansion_order = 100 _MAX_infinity_expansion_order = 100 # Step size when increasing the expansion order _STEP_horizon_expansion_order = 5 _STEP_infinity_expansion_order = 5 if omega == 0 Xin = GSN_radial(s, l, m, a, omega, IN) Xup = GSN_radial(s, l, m, a, omega, UP) else # Solve for Xin and Xup using the default settings Xin = GSN_radial(s, l, m, a, omega, IN, _DEFAULT_rsin, _DEFAULT_rsout, horizon_expansion_order=_DEFAULT_horizon_expansion_order, infinity_expansion_order=_DEFAULT_infinity_expansion_order) Xup = GSN_radial(s, l, m, a, omega, UP, _DEFAULT_rsin, _DEFAULT_rsout, horizon_expansion_order=_DEFAULT_horizon_expansion_order, infinity_expansion_order=_DEFAULT_infinity_expansion_order) # Bump up the expansion order until the solution is "sane" while(!Solutions.check_XinXup_sanity(Xin, Xup)) new_horizon_expansion_order = Xin.horizon_expansion_order + _STEP_horizon_expansion_order >= _MAX_horizon_expansion_order ? _MAX_horizon_expansion_order : Xin.horizon_expansion_order + _STEP_horizon_expansion_order new_infinity_expansion_order = Xup.infinity_expansion_order + _STEP_infinity_expansion_order >= _MAX_infinity_expansion_order ? _MAX_infinity_expansion_order : Xup.infinity_expansion_order + _STEP_infinity_expansion_order # Re-solve Xin and Xup using the updated settings Xin = GSN_radial(s, l, m, a, omega, IN, _DEFAULT_rsin, _DEFAULT_rsout, horizon_expansion_order=new_horizon_expansion_order, infinity_expansion_order=new_infinity_expansion_order) Xup = GSN_radial(s, l, m, a, omega, UP, _DEFAULT_rsin, _DEFAULT_rsout, horizon_expansion_order=new_horizon_expansion_order, infinity_expansion_order=new_infinity_expansion_order) end end return (Xin, Xup) end # The power of multiple dispatch (gsn_func::GSNRadialFunction)(rs) = gsn_func.GSN_solution(rs)[1] # Only return X(rs), discarding the first derivative @doc raw""" Teukolsky_radial(s::Int, l::Int, m::Int, a, omega, boundary_condition, rsin, rsout; horizon_expansion_order::Int=_DEFAULT_horizon_expansion_order, infinity_expansion_order::Int=_DEFAULT_infinity_expansion_order, data_type=Solutions._DEFAULTDATATYPE, ODE_algorithm=Solutions._DEFAULTSOLVER, tolerance=Solutions._DEFAULTTOLERANCE) Compute the Teukolsky function for a given mode (specified by `s` the spin weight, `l` the harmonic index, `m` the azimuthal index, `a` the Kerr spin parameter, and `omega` the frequency) and boundary condition specified by `boundary_condition`, which can be either - `IN` for purely-ingoing at the horizon, - `UP` for purely-outgoing at infinity, - `OUT` for purely-outgoing at the horizon, - `DOWN` for purely-ingoing at infinity. Note that the `OUT` and `DOWN` solutions are constructed by linearly combining the `IN` and `UP` solutions, respectively. The full GSN solution is converted to the corresponding Teukolsky solution $(R(r), dR/dr)$ and the incidence, reflection and transmission amplitude are converted from the GSN formalism to the Teukolsky formalism with the normalization convention that the transmission amplitude is normalized to 1 (i.e. `normalization_convention=UNIT_TEUKOLSKY_TRANS`). Note, however, when `omega = 0`, the exact Teukolsky function expressed using Gauss hypergeometric functions will be returned (i.e., instead of using the GSN formalism). In this case, only `s`, `l`, `m`, `a`, `omega`, `boundary_condition` will be parsed. """ function Teukolsky_radial( s::Int, l::Int, m::Int, a, omega, boundary_condition, rsin, rsout; horizon_expansion_order::Int=_DEFAULT_horizon_expansion_order, infinity_expansion_order::Int=_DEFAULT_infinity_expansion_order, data_type=Solutions._DEFAULTDATATYPE, ODE_algorithm=Solutions._DEFAULTSOLVER, tolerance=Solutions._DEFAULTTOLERANCE ) if omega == 0 return Teukolsky_radial(s, l, m, a, 0, boundary_condition) else # Solve for the GSN solution gsn_func = GSN_radial(s, l, m, a, omega, boundary_condition, rsin, rsout; horizon_expansion_order=horizon_expansion_order, infinity_expansion_order=infinity_expansion_order, data_type=data_type, ODE_algorithm=ODE_algorithm, tolerance=tolerance) # Convert asymptotic amplitudes from GSN to Teukolsky formalism if gsn_func.boundary_condition == IN transmission_amplitude_conv_factor = ConversionFactors.Btrans(s, m, a, omega, gsn_func.mode.lambda) incidence_amplitude = ConversionFactors.Binc(s, m, a, omega, gsn_func.mode.lambda) * gsn_func.incidence_amplitude / transmission_amplitude_conv_factor reflection_amplitude = ConversionFactors.Bref(s, m, a, omega, gsn_func.mode.lambda) * gsn_func.reflection_amplitude / transmission_amplitude_conv_factor elseif gsn_func.boundary_condition == UP transmission_amplitude_conv_factor = ConversionFactors.Ctrans(s, m, a, omega, gsn_func.mode.lambda) incidence_amplitude = ConversionFactors.Cinc(s, m, a, omega, gsn_func.mode.lambda) * gsn_func.incidence_amplitude / transmission_amplitude_conv_factor reflection_amplitude = ConversionFactors.Cref(s, m, a, omega, gsn_func.mode.lambda) * gsn_func.reflection_amplitude / transmission_amplitude_conv_factor elseif gsn_func.boundary_condition == DOWN # The "transmission amplitude" transforms like Binc transmission_amplitude_conv_factor = ConversionFactors.Binc(s, m, a, omega, gsn_func.mode.lambda) # The "incidence amplitude" transforms like Btrans incidence_amplitude = ConversionFactors.Btrans(s, m, a, omega, gsn_func.mode.lambda) * gsn_func.incidence_amplitude / transmission_amplitude_conv_factor # The "reflection amplitude" transforms like Cinc reflection_amplitude = ConversionFactors.Cinc(s, m, a, omega, gsn_func.mode.lambda) * gsn_func.reflection_amplitude / transmission_amplitude_conv_factor elseif gsn_func.boundary_condition == OUT # The "tranmission amplitude" transforms like Cinc transmission_amplitude_conv_factor = ConversionFactors.Cinc(s, m, a, omega, gsn_func.mode.lambda) # The "incidence amplitude" transforms like Bref incidence_amplitude = ConversionFactors.Bref(s, m, a, omega, gsn_func.mode.lambda) * gsn_func.incidence_amplitude / transmission_amplitude_conv_factor # The "reflection amplitude" transformslike Binc reflection_amplitude = ConversionFactors.Binc(s, m, a, omega, gsn_func.mode.lambda) * gsn_func.reflection_amplitude / transmission_amplitude_conv_factor else error("Does not understand the boundary condition applied to the solution") end # Convert the GSN solution to the Teukolsky solution teuk_func(r) = Solutions.Teukolsky_radial_function_from_Sasaki_Nakamura_function( gsn_func.mode.s, gsn_func.mode.m, gsn_func.mode.a, gsn_func.mode.omega, gsn_func.mode.lambda, gsn_func.GSN_solution )(r) / transmission_amplitude_conv_factor return TeukolskyRadialFunction( gsn_func.mode, gsn_func.boundary_condition, data_type(1), incidence_amplitude, reflection_amplitude, gsn_func, teuk_func, UNIT_TEUKOLSKY_TRANS ) end end function Teukolsky_radial( s::Int, l::Int, m::Int, a, omega, boundary_condition ) if omega != 0 return Teukolsky_radial(s, l, m, a, omega, boundary_condition, _DEFAULT_rsin, _DEFAULT_rsout) else # Compute the SWSH eigenvalue lambda = spin_weighted_spherical_eigenvalue(s, l, m) # Fill in the mode information mode = Mode(s, l, m, a, omega, lambda) if boundary_condition == IN teuk_func = Solutions.solve_static_Rin(s, l, m, a) elseif boundary_condition == UP teuk_func = Solutions.solve_static_Rup(s, l, m, a) else error("Does not understand the boundary condition applied to the solution") end return TeukolskyRadialFunction( mode, boundary_condition, 1, missing, missing, missing, teuk_func, UNIT_TEUKOLSKY_TRANS ) end end @doc raw""" Teukolsky_radial(s::Int, l::Int, m::Int, a, omega) Compute the Teukolsky function for a given mode (specified by `s` the spin weight, `l` the harmonic index, `m` the azimuthal index, `a` the Kerr spin parameter, and `omega` the frequency) with the purely-ingoing boundary condition at the horizon (`IN`) and the purely-outgoing boundary condition at infinity (`UP`). Note that the numerical inner boundary (rsin) and outer boundary (rsout) are set to the default values `_DEFAULT_rsin` and `_DEFAULT_rsout`, respectively, while the order of the asymptotic expansion at the horizon and infinity are determined automatically. """ function Teukolsky_radial(s::Int, l::Int, m::Int, a, omega) if omega == 0 Rin = Teukolsky_radial(s, l, m, a, omega, IN) Rup = Teukolsky_radial(s, l, m, a, omega, UP) else # NOTE This is not the most efficient implementation but ensures self-consistency Xin, Xup = GSN_radial(s, l, m, a, omega) # This is simply to figure out what expansion orders to use Rin = Teukolsky_radial(s, l, m, a, omega, IN, Xin.rsin, Xin.rsout; horizon_expansion_order=Xin.horizon_expansion_order, infinity_expansion_order=Xin.infinity_expansion_order) Rup = Teukolsky_radial(s, l, m, a, omega, UP, Xup.rsin, Xup.rsout; horizon_expansion_order=Xup.horizon_expansion_order, infinity_expansion_order=Xup.infinity_expansion_order) end return (Rin, Rup) end # The power of multiple dispatch (teuk_func::TeukolskyRadialFunction)(r) = teuk_func.Teukolsky_solution(r)[1] # Only return R(r), discarding the first derivative end
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
2163
module InitialConditions using ForwardDiff using ..Kerr using ..Coordinates using ..AsymptoticExpansionCoefficients export Xup_initialconditions, Xin_initialconditions export fansatz, gansatz const I = 1im # Mathematica being Mathematica function fansatz(func, omega, r; order=3) # A template function that gives the asymptotic expansion at infinity ans = 0.0 for i in 0:order ans += func(i)/((omega*r)^i) end return ans end function gansatz(func, a, r; order=1) # A template function that gives the asymptotic expansion at horizon ans = 0.0 for i in 0:order ans += func(i)*(r-r_plus(a))^i end return ans end function Xup_initialconditions(s::Int, m::Int, a, omega, lambda, rsout; order::Int=-1) #= We have derived/shown the explicit expression for different physically-relevant spin weight (s=0, \pm 1, \pm2) =# _default_order = 3 order = (order == -1 ? _default_order : order) outgoing_coeff_func(ord) = outgoing_coefficient_at_inf(s, m, a, omega, lambda, ord) fout(r) = fansatz(outgoing_coeff_func, omega, r; order=order) dfout_dr(r) = ForwardDiff.derivative(fout, r) rout = r_from_rstar(a, rsout) _fansatz = fout(rout) _dfansatz_dr = dfout_dr(rout) phase = exp(1im * omega * rsout) return phase*_fansatz, phase*(1im*omega*_fansatz + (Delta(a, rout)/(rout^2 + a^2))*_dfansatz_dr) end function Xin_initialconditions(s::Int, m::Int, a, omega, lambda, rsin; order::Int=-1) #= For Xin, which we obtain by integrating from r_* -> -inf (or r -> r_+), Write Xin = \sum_j C^{H}_{-} (r - r_+)^j =# _default_order = 0 order = (order == -1 ? _default_order : order) ingoing_coeff_func(ord) = ingoing_coefficient_at_hor(s, m, a, omega, lambda, ord) gin(r) = gansatz(ingoing_coeff_func, a, r; order=order) dgin_dr(r) = ForwardDiff.derivative(gin, r) rin = r_from_rstar(a, rsin) _gansatz = gin(rin) _dgansatz_dr = dgin_dr(rin) p = omega - m*omega_horizon(a) phase = exp(-1im * p * rsin) return phase*_gansatz, phase*(-1im*p*_gansatz + (Delta(a, rin)/(rin^2 + a^2))*_dgansatz_dr) end end
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
341
module Kerr export Delta, r_plus, r_minus, omega_horizon, K function Delta(a, r) r^2 - 2*r + a^2 end function r_plus(a) 1 + sqrt(1 - a^2) end function r_minus(a) 1 - sqrt(1 - a^2) end function omega_horizon(a) rp = r_plus(a) return a/(2*1*rp) end function K(m::Int, a, omega, r) (r^2 + a^2)*omega - m*a end end
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
13652
module Potentials using ..Kerr export sF, sU, VT, radial_Teukolsky_equation const I = 1im # Mathematica being Mathematica function sF(s::Int, m::Int, a, omega, lambda, r) #= We have derived/shown the explicit expression for different physically-relevant spin weight (s=0, \pm 1, \pm2) =# if s == 0 # s = 0 return 0.0 elseif s == 1 # s = +1 return begin -((2*a*(a^2 + (-2 + r)*r)*(-3*I*a^2*m*r - I*m*r^3 + 2*a^3*(1 + lambda) + a*r*(3 + r*(3 + 2*lambda))))/ (r*(a^2 + r^2)*(-2*I*a^3*m*r - 2*I*a*m*r^3 + a^4*(1 + lambda) + r^4*(2 + lambda) + a^2*r*(2 + r*(3 + 2*lambda))))) end elseif s == -1 # s = -1 return begin -((2*a*(a^2 + (-2 + r)*r)*(3*I*a^2*m*r + I*m*r^3 + 2*a^3*(-1 + lambda) + a*r*(3 + r*(-1 + 2*lambda))))/ (r*(a^2 + r^2)*(2*I*a^3*m*r + 2*I*a*m*r^3 + a^4*(-1 + lambda) + r^4*lambda + a^2*r*(2 + r*(-1 + 2*lambda))))) end elseif s == 2 # s = +2 return begin (8*a*(a^2 + (-2 + r)*r)*(I*m*r^2*(6 + r*(4 + lambda)) - 3*a^2*m*r*(3*I + 4*r*omega) + a*r*(9 + r*(-3 + 6*m^2 - 6*I*omega) - I*r^2*(1 + lambda)*omega) + a^3*(-6 + 9*I*r*omega + 6*r^2*omega^2)))/ (r*(a^2 + r^2)*(r^4*(24 + 10*lambda + lambda^2 + 12*I*omega) + 24*a^3*m*r*(I + 2*r*omega) + 4*a*m*r^2*(-6*I - 2*I*r*(4 + lambda) + 3*r^2*omega) - 12*a^4*(-1 + 2*I*r*omega + 2*r^2*omega^2) - 4*a^2*r*(6 + r*(-3 + 6*m^2 - 6*I*omega) - 2*I*r^2*(1 + lambda)*omega + 3*r^3*omega^2))) end elseif s == -2 # s = -2 return begin (8*a*(a^2 + (-2 + r)*r)*((-I)*m*r^2*(6 + r*lambda) + 3*a^2*m*r*(3*I - 4*r*omega) + a*r*(9 + r*(-3 + 6*m^2 + 6*I*omega) + I*r^2*(-3 + lambda)*omega) + a^3*(-6 - 9*I*r*omega + 6*r^2*omega^2)))/ (r*(a^2 + r^2)*(r^4*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*r*(-I + 2*r*omega) + 4*a*m*r^2*(6*I + 2*I*r*lambda + 3*r^2*omega) + a^4*(12 + 24*I*r*omega - 24*r^2*omega^2) - 4*a^2*r*(6 + r*(-3 + 6*m^2 + 6*I*omega) + 2*I*r^2*(-3 + lambda)*omega + 3*r^3*omega^2))) end else # Throw an error, this spin weight is not supported throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function sU(s::Int, m::Int, a, omega, lambda, r) #= We have derived/shown the explicit expression for different physically-relevant spin weight (s=0, \pm 1, \pm2) =# if s == 0 # s = 0 return begin (1/(a^2 + r^2)^4)*(r^2*(a^2 + (-2 + r)*r)^2 + (a^2 + (-2 + r)*r)*(a^4 - 4*a^2*r - (-4 + r)*r^3) + (a^2 + r^2)^2*((a^2 + (-2 + r)*r)*lambda - (a*m - (a^2 + r^2)*omega)^2)) end elseif s == 1 # s = +1 return begin (1/(a^2 + r^2)^4)*(2*(a^2 + (-2 + r)*r)*(a^4 - a^2*r - (-3 + r)*r^3) + (r^2*(-3 + 2*r) + a^2*(-1 + 2*r))^2 + (2*a*(a^2 + (-2 + r)*r)*(a^2 + r^2)* (r^2*(-3 + 2*r) + a^2*(-1 + 2*r))*(-3*I*a^2*m*r - I*m*r^3 + 2*a^3*(1 + lambda) + a*r*(3 + r*(3 + 2*lambda))))/(r*(-2*I*a^3*m*r - 2*I*a*m*r^3 + a^4*(1 + lambda) + r^4*(2 + lambda) + a^2*r*(2 + r*(3 + 2*lambda)))) - ((a^2 + r^2)^2*(2*a^7*m*r^2*omega*(-lambda - I*r*omega) + a^8*(1 + lambda)*(2 + r^2*omega^2) - 2*I*a^5*m*r^2*(-6 + r*(4 + m^2 - lambda - 4*I*omega) - 3*I*r^2*(1 + lambda)*omega + 3*r^3*omega^2) - 2*I*a*m*r^5*(3 + r*(-5 + 2*lambda) + r^2*(2 - lambda + 2*I*omega) - I*r^3*(3 + lambda)*omega + r^4*omega^2) - 2*I*a^3*m*r^3*(13 + r*(-17 + 2*lambda) + r^2*(6 + m^2 - 2*lambda - 2*I*omega) - 3*I*r^3*(2 + lambda)*omega + 3*r^4*omega^2) + r^6*(-3*(2 + lambda) - r^2*lambda*(2 + lambda) + 2*r*(2 + 3*lambda + lambda^2) + r^4*(2 + lambda)*omega^2) + a^6*r*(-16*(1 + lambda) + r*(5 + m^2*(-1 + lambda) + 6*lambda - lambda^2 + 2*I*omega) + r^3*(5 + 4*lambda)*omega^2 + 2*r^2*omega*(I + 2*I*m^2 + omega)) + a^4*r^2*(11 + 25*lambda + 2*r*(-5 + 3*m^2 - 13*lambda + lambda^2 - 2*I*omega) + r^2*(5 + 4*lambda - 3*lambda^2 + m^2*(3 + 2*lambda) - 8*I*omega) + 3*r^4*(3 + 2*lambda)*omega^2 + 4*r^3*omega*(I + 2*I*m^2 + omega)) + a^2*r^3*(30 + 5*r*(-7 + 2*lambda) - 4*r^2*(-2 + m^2 + lambda - lambda^2 - 3*I*omega) + r^3*(2 - 2*lambda - 3*lambda^2 + m^2*(4 + lambda) - 10*I*omega) + r^5*(7 + 4*lambda)*omega^2 + 2*r^4*omega*(I + 2*I*m^2 + omega))))/(r^2*(-2*I*a^3*m*r - 2*I*a*m*r^3 + a^4*(1 + lambda) + r^4*(2 + lambda) + a^2*r*(2 + r*(3 + 2*lambda))))) end elseif s == -1 # s = -1 return begin (1/(a^2 + r^2)^4)*((a^2 - r^2)^2 + 2*r*(a^2 + (-2 + r)*r)*(-3*a^2 + r^2) + (2*a*(a^2 + (-2 + r)*r)*(a^2 - r^2)*(a^2 + r^2)*(3*I*a^2*m*r + I*m*r^3 + 2*a^3*(-1 + lambda) + a*r*(3 + r*(-1 + 2*lambda))))/(r*(2*I*a^3*m*r + 2*I*a*m*r^3 + a^4*(-1 + lambda) + r^4*lambda + a^2*r*(2 + r*(-1 + 2*lambda)))) - ((a^2 + r^2)^2*(2*a^7*m*r^2*omega*(2 - lambda + I*r*omega) + a^8*(-1 + lambda)*(2 + r^2*omega^2) + 2*I*a^5*m*r^3*(-2 + m^2 - lambda + 4*I*omega - 3*I*r*omega + 3*I*r*lambda*omega + 3*r^2*omega^2) + r^6*lambda*(-3 - r^2*lambda + 2*r*(1 + lambda) + r^4*omega^2) + 2*I*a*m*r^5*(-1 + r + 2*r*lambda - r^2*(lambda + 2*I*omega) + I*r^3*(1 + lambda)*omega + r^4*omega^2) + 2*I*a^3*m*r^3*(1 + r*(3 + 2*lambda) + r^2*(-2 + m^2 - 2*lambda + 2*I*omega) + 3*I*r^3*lambda*omega + 3*r^4*omega^2) + a^6*r*(8 - 8*lambda + r*(-1 + m^2*(-3 + lambda) - lambda^2 - 2*I*omega) + r^3*(-3 + 4*lambda)*omega^2 + 2*r^2*omega*(-I - 2*I*m^2 + omega)) + a^4*r^2*(-11 + 9*lambda + 2*r*(1 + 3*m^2 + lambda + lambda^2 + 2*I*omega) + r^2*(1 - 6*lambda - 3*lambda^2 + m^2*(-1 + 2*lambda) + 8*I*omega) + 3*r^4*(-1 + 2*lambda)*omega^2 + 4*r^3*omega*(-I - 2*I*m^2 + omega)) + a^2*r^3*(6 - 3*r*(1 + 2*lambda) - 4*r^2*(m^2 - 3*lambda - lambda^2 + 3*I*omega) + r^3*(-4*lambda - 3*lambda^2 + m^2*(2 + lambda) + 10*I*omega) + r^5*(-1 + 4*lambda)*omega^2 + 2*r^4*omega*(-I - 2*I*m^2 + omega))))/ (r^2*(2*I*a^3*m*r + 2*I*a*m*r^3 + a^4*(-1 + lambda) + r^4*lambda + a^2*r*(2 + r*(-1 + 2*lambda))))) end elseif s == 2 # s = +2 return begin (1/(a^2 + r^2)^4)*((a^2 + (-2 + r)*r)*(3*a^4 + (8 - 3*r)*r^3) + (r^2*(-4 + 3*r) + a^2*(-2 + 3*r))^2 + (8*a*(a^2 + (-2 + r)*r)*(a^2 + r^2)* (r^2*(-4 + 3*r) + a^2*(-2 + 3*r))*(I*m*r^2*(6 + r*(4 + lambda)) - 3*a^2*m*r*(3*I + 4*r*omega) + a*r*(9 + r*(-3 + 6*m^2 - 6*I*omega) - I*r^2*(1 + lambda)*omega) + a^3*(-6 + 9*I*r*omega + 6*r^2*omega^2)))/ (r*((-r^4)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*r*(I + 2*r*omega) + 4*a*m*r^2*(6*I + 2*I*r*(4 + lambda) - 3*r^2*omega) + 12*a^4*(-1 + 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 - 6*I*omega) - 2*I*r^2*(1 + lambda)*omega + 3*r^3*omega^2))) - ((a^2 + r^2)^2*(24*a^7*m*r^2*omega*(3 + 3*I*r*omega - 4*r^2*omega^2) - r^6*(24 + 10*lambda + lambda^2 + 12*I*omega)* (-12 - r^2*lambda + 2*r*(4 + lambda) + r^4*omega^2) - 4*a^5*m*r^2* (-54*I - 2*I*r*(-55 + 3*m^2 - 4*lambda - 18*I*omega) + 2*r^2*(4 + 12*m^2 - 8*lambda + 27*I*omega)*omega - 6*I*r^3*(8 + lambda)*omega^2 + 45*r^4*omega^3) + 12*a^8*(-2 - 3*r^2*omega^2 - 2*I*r^3*omega^3 + 2*r^4*omega^4) + 4*a^6*r*(60 - 3*r*(16 + 3*m^2 + 18*I*omega) + r^3*(1 + 36*m^2 - 8*lambda + 18*I*omega)* omega^2 - 2*I*r^4*(7 + lambda)*omega^3 + 15*r^5*omega^4 - 2*r^2*omega*(-40*I + 9*I*m^2 - 4*I*lambda + 9*omega)) + 2*a*m*r^4*(144*I + 8*I*r*(-38 + lambda) + r^4*(40 + 20*lambda + lambda^2 + 24*I*omega)*omega + 4*I*r^5*(4 + lambda)*omega^2 - 6*r^6*omega^3 + 4*r^2*(16*I + 3*I*lambda + 2*I*lambda^2 + 6*omega) - 4*I*r^3*(-12 + lambda + lambda^2 - 14*I*omega - 5*I*lambda*omega)) - 2*a^3*m*r^3*(312*I + r^3*(84 + 30*m^2 - 52*lambda - lambda^2 + 36*I*omega)*omega - 4*I*r^4*(19 + 4*lambda)*omega^2 + 48*r^5*omega^3 + 12*r*(-63*I + 3*I*m^2 - 3*I*lambda + 32*omega) + 4*r^2*(71*I + 9*I*lambda + I*lambda^2 - I*m^2*(10 + lambda) - 104*omega + 16*lambda*omega)) + a^2*r^3*(576 + 96*r*(-12 + 4*m^2 - 3*I*omega) + 8*r^2*(18 - 3*lambda^2 + m^2*(-58 + 8*lambda) + lambda*(-30 - 2*I*omega) + 46*I*omega) - 8*I*r^4*(-lambda^2 + 2*m^2*(7 + lambda) + lambda*(2 + 5*I*omega) + 11*I*omega)*omega + 2*r^5*(-34 + 24*m^2 - 20*lambda - lambda^2 - 24*I*omega)*omega^2 - 8*I*r^6*(1 + lambda)*omega^3 + 12*r^7*omega^4 + r^3*(lambda^3 + 36*lambda*(4 + I*omega) + 2*lambda^2*(11 - 8*I*omega) - m^2*(-136 + 42*lambda + lambda^2 - 36*I*omega) - 8*(-18 + 19*I*omega + 6*omega^2))) + a^4*r^2*(-672 + r*(960 - 72*m^2 + 624*I*omega) + r^4*(44 + 180*m^2 - 62*lambda - lambda^2 + 36*I*omega)* omega^2 - 8*I*r^5*(5 + 2*lambda)*omega^3 + 48*r^6*omega^4 + 8*r^3*omega*(56*I + 6*I*lambda + I*lambda^2 - 3*I*m^2*(9 + lambda) - 46*omega + 8*lambda*omega) + 4*r^2*(6*m^4 + m^2*(7 - 8*lambda + 54*I*omega) + 2*(-15 + 10*lambda + lambda^2 - 144*I*omega - 9*I*lambda*omega + 48*omega^2)))))/ (r^2*((-r^4)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*r*(I + 2*r*omega) + 4*a*m*r^2*(6*I + 2*I*r*(4 + lambda) - 3*r^2*omega) + 12*a^4*(-1 + 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 - 6*I*omega) - 2*I*r^2*(1 + lambda)*omega + 3*r^3*omega^2)))) end elseif s == -2 # s = -2 return begin (1/(a^2 + r^2)^4)*((a^2*(-2 + r) + r^3)^2 + (a^2 + (-2 + r)*r)*(-a^4 - 8*a^2*r + r^4) + (8*a*(a^2 + (-2 + r)*r)*(a^2 + r^2)*(a^2*(-2 + r) + r^3)*((-I)*m*r^2*(6 + r*lambda) + 3*a^2*m*r*(3*I - 4*r*omega) + a*r*(9 + r*(-3 + 6*m^2 + 6*I*omega) + I*r^2*(-3 + lambda)*omega) + a^3*(-6 - 9*I*r*omega + 6*r^2*omega^2)))/(r*(r^4*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*r*(-I + 2*r*omega) + 4*a*m*r^2*(6*I + 2*I*r*lambda + 3*r^2*omega) + a^4*(12 + 24*I*r*omega - 24*r^2*omega^2) - 4*a^2*r*(6 + r*(-3 + 6*m^2 + 6*I*omega) + 2*I*r^2*(-3 + lambda)*omega + 3*r^3*omega^2))) - ((a^2 + r^2)^2*(-24*a^7*m*r^2*omega*(-3 + 3*I*r*omega + 4*r^2*omega^2) + 12*a^8*(-2 - 3*r^2*omega^2 + 2*I*r^3*omega^3 + 2*r^4*omega^4) + 4*a^6*r*(12 - 3*r*(-4 + 3*m^2 + 6*I*omega) + r^3*(-39 + 36*m^2 - 8*lambda - 18*I*omega)*omega^2 + 2*I*r^4*(3 + lambda)*omega^3 + 15*r^5*omega^4 + 2*r^2*omega*(24*I + 9*I*m^2 - 4*I*lambda + 15*omega)) - 4*a^5*m*r^2*(-18*I + 2*r^2*(-36 + 12*m^2 - 8*lambda - 27*I*omega)*omega + 6*I*r^3*(4 + lambda)*omega^2 + 45*r^4*omega^3 + 2*r*(9*I + 3*I*m^2 - 4*I*lambda + 30*omega)) - 2*a*m*r^4*(-48*I - 24*I*r*(-2 + lambda) + 4*I*r^2*(7*lambda + 2*lambda^2 + 6*I*omega) - r^4*(12*lambda + lambda^2 - 24*I*omega)*omega + 4*I*r^5*lambda*omega^2 + 6*r^6*omega^3 - 4*I*r^3*(lambda + lambda^2 + 6*I*omega + 5*I*lambda*omega)) + a^4*r^3*(24*m^4*r + 48*(-4 + 3*I*omega) - r^3*(60 + 54*lambda + lambda^2 + 36*I*omega)*omega^2 + 8*I*r^4*(-3 + 2*lambda)*omega^3 + 48*r^5*omega^4 + 8*r*(9 + 2*lambda + lambda^2 - 72*I*omega + 13*I*lambda*omega) + 8*r^2*omega*(24*I - 6*I*lambda - I*lambda^2 + 18*omega + 8*lambda*omega) + 4*m^2*(30 - r*(33 + 8*lambda + 54*I*omega) + 6*I*r^2*(5 + lambda)*omega + 45*r^3*omega^2)) + r^6*((-2 + r)*r*lambda^3 + lambda^2*(12 - 12*r + 2*r^2 - r^4*omega^2) + 12*I*omega*(-12 + 8*r + r^4*omega^2) - 2*lambda*(-12 + 4*r*(2 - 3*I*omega) + 6*I*r^2*omega + r^4*omega^2)) + a^2*r^4*(96 - 96*I*omega + 2*r^4*(6 + 24*m^2 - 12*lambda - lambda^2 + 24*I*omega)*omega^2 + 8*I*r^5*(-3 + lambda)*omega^3 + 12*r^6*omega^4 + 8*r^3*omega*(2*I*lambda - I*lambda^2 + 2*I*m^2*(3 + lambda) + 3*omega + 5*lambda*omega) + r^2*(lambda^3 + lambda*(24 - 34*m^2 - 4*I*omega) + lambda^2*(14 - m^2 + 16*I*omega) - 12*I*(22 + 3*m^2 - 4*I*omega)*omega) + 8*r*(m^2*(6 + 8*lambda) - 3*(2 + 2*lambda + lambda^2 - 22*I*omega + 2*I*lambda*omega))) - 2*a^3*m*r^3*(72*I - 4*I*r*(15 + 9*m^2 - 13*lambda) + r^3*(-36 + 30*m^2 - 44*lambda - lambda^2 - 36*I*omega)* omega + 4*I*r^4*(3 + 4*lambda)*omega^2 + 48*r^5*omega^3 + 4*r^2*(I*m^2*(6 + lambda) - I*(3 + 9*lambda + lambda^2 + 24*I*omega + 16*I*lambda*omega)))))/ (r^2*((-r^4)*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*r*(I - 2*r*omega) - 4*a*m*r^2*(6*I + 2*I*r*lambda + 3*r^2*omega) + 12*a^4*(-1 - 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 + 6*I*omega) + 2*I*r^2*(-3 + lambda)*omega + 3*r^3*omega^2)))) end else # Throw an error, this spin weight is not supported throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function VT(s::Int, m::Int, a, omega, lambda, r) _K = K(m, a, omega, r) _Delta = Delta(a, r) return lambda - 4im*s*omega*r - (_K^2 - 2im*s*(r-1)*_K)/_Delta end function radial_Teukolsky_equation(s, m, a, omega, lambda, r, R, dRdr, d2Rdr2) Delta(a, r)*d2Rdr2(r) + (2*(s+1)*(r-1))*dRdr(r) - VT(s, m, a, omega, lambda, r)*R(r) end end
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
34761
module Solutions using DifferentialEquations using ForwardDiff using HypergeometricFunctions using ..Kerr using ..Transformation using ..Coordinates using ..Potentials using ..AsymptoticExpansionCoefficients using ..InitialConditions using ..ConversionFactors const I = 1im # Mathematica being Mathematica _DEFAULTDATATYPE = ComplexF64 # Double precision by default _DEFAULTSOLVER = Vern9() _DEFAULTTOLERANCE = 1e-12 # First-order non-linear ODE form of the GSN equation function GSN_Riccati_eqn!(du, u, p, rs) r = r_from_rstar(p.a, rs) _sF = sF(p.s, p.m, p.a, p.omega, p.lambda, r) _sU = sU(p.s, p.m, p.a, p.omega, p.lambda, r) #= We write X = exp(I*Phi) Substitute X in this form into the GSN equation will give a Riccati equation, a first-order non-linear equation u[1] = Phi u[2] = dPhidrs =# du[1] = u[2] du[2] = -1im*_sU + _sF*u[2] - 1im*u[2]*u[2] end # Second-order linear ODE form of the GSN equation function GSN_linear_eqn!(du, u, p, rs) r = r_from_rstar(p.a, rs) _sF = sF(p.s, p.m, p.a, p.omega, p.lambda, r) _sU = sU(p.s, p.m, p.a, p.omega, p.lambda, r) #= Using the convention for DifferentialEquations u[1] = X(rs) u[2] = dX/drs = X' therefore X'' - sF X' - sU X = 0 => u[2]' - sF u[2] - sU u[1] = 0 => u[2]' = sF u[2] + sU u[1] =# du[1] = u[2] du[2] = _sF*u[2] + _sU*u[1] end function PhiPhiprime_from_XXprime(X, Xprime) Phi = -1im*log(X) Phiprime = -1im*Xprime/X return Phi, Phiprime end function XXprime_from_PhiPhiprime(Phi, Phiprime) X = exp(1im*Phi) Xprime = 1im*X*Phiprime return X, Xprime end function Xsoln_from_Phisoln(Phisoln) return rs -> XXprime_from_PhiPhiprime(Phisoln(rs)[1], Phisoln(rs)[2]) end function solve_Phiup(s::Int, m::Int, a, omega, lambda, rsin, rsout; initialconditions_order=-1, dtype=_DEFAULTDATATYPE, odealgo=_DEFAULTSOLVER, reltol=_DEFAULTTOLERANCE, abstol=_DEFAULTTOLERANCE) # Sanity check if rsin > rsout throw(DomainError(rsout, "rsout ($rsout) must be larger than rsin ($rsin)")) end # Initial conditions at rs = rsout, the outer boundary Xup_rsout, Xupprime_rsout = Xup_initialconditions(s, m, a, omega, lambda, rsout; order=initialconditions_order) # Convert initial conditions for Xup for Phi Phi, Phiprime = PhiPhiprime_from_XXprime(Xup_rsout, Xupprime_rsout) u0 = [dtype(Phi); dtype(Phiprime)] rsspan = (rsout, rsin) # Integrate from rsout to rsin *inward* p = (s=s, m=m, a=a, omega=omega, lambda=lambda) odeprob = ODEProblem(GSN_Riccati_eqn!, u0, rsspan, p) odesoln = solve(odeprob, odealgo; reltol=reltol, abstol=abstol) return odesoln end function solve_Phiin(s::Int, m::Int, a, omega, lambda, rsin, rsout; initialconditions_order=-1, dtype=_DEFAULTDATATYPE, odealgo=_DEFAULTSOLVER, reltol=_DEFAULTTOLERANCE, abstol=_DEFAULTTOLERANCE) # Sanity check if rsin > rsout throw(DomainError(rsin, "rsin ($rsin) must be smaller than rsout ($rsout)")) end # Initial conditions at rs = rsin, the inner boundary; this should be very close to EH Xin_rsin, Xinprime_rsin = Xin_initialconditions(s, m, a, omega, lambda, rsin; order=initialconditions_order) # Convert initial conditions for Xin for PhiRe PhiIm Phi, Phiprime = PhiPhiprime_from_XXprime(Xin_rsin, Xinprime_rsin) u0 = [dtype(Phi); dtype(Phiprime)] rsspan = (rsin, rsout) # Integrate from rsin to rsout *outward* p = (s=s, m=m, a=a, omega=omega, lambda=lambda) odeprob = ODEProblem(GSN_Riccati_eqn!, u0, rsspan, p) odesoln = solve(odeprob, odealgo; reltol=reltol, abstol=abstol) return odesoln end function solve_Xup(s::Int, m::Int, a, omega, lambda, rsin, rsout; initialconditions_order=-1, dtype=_DEFAULTDATATYPE, odealgo=_DEFAULTSOLVER, reltol=_DEFAULTTOLERANCE, abstol=_DEFAULTTOLERANCE) # Sanity check if rsin > rsout throw(DomainError(rsout, "rsout ($rsout) must be larger than rsin ($rsin)")) end # Initial conditions at rs = rsout, the outer boundary Xup_rsout, Xupprime_rsout = Xup_initialconditions(s, m, a, omega, lambda, rsout; order=initialconditions_order) u0 = [dtype(Xup_rsout); dtype(Xupprime_rsout)] rsspan = (rsout, rsin) # Integrate from rsout to rsin *inward* p = (s=s, m=m, a=a, omega=omega, lambda=lambda) odeprob = ODEProblem(GSN_linear_eqn!, u0, rsspan, p) odesoln = solve(odeprob, odealgo; reltol=reltol, abstol=abstol) end function solve_Xin(s::Int, m::Int, a, omega, lambda, rsin, rsout; initialconditions_order=-1, dtype=_DEFAULTDATATYPE, odealgo=_DEFAULTSOLVER, reltol=_DEFAULTTOLERANCE, abstol=_DEFAULTTOLERANCE) # Sanity check if rsin > rsout throw(DomainError(rsin, "rsin ($rsin) must be smaller than rsout ($rsout)")) end # Initial conditions at rs = rsin, the inner boundary; this should be very close to EH Xin_rsin, Xinprime_rsin = Xin_initialconditions(s, m, a, omega, lambda, rsin; order=initialconditions_order) u0 = [dtype(Xin_rsin); dtype(Xinprime_rsin)] rsspan = (rsin, rsout) # Integrate from rsin to rsout *outward* p = (s=s, m=m, a=a, omega=omega, lambda=lambda) odeprob = ODEProblem(GSN_linear_eqn!, u0, rsspan, p) odesoln = solve(odeprob, odealgo; reltol=reltol, abstol=abstol) end function Teukolsky_radial_function_from_Sasaki_Nakamura_function_conversion_matrix(s, m, a, omega, lambda, r) #= Here we use explicit form for the conversion matrix to faciliate cancellations =# M11 = M12 = M21 = M22 = 0.0 if s == 0 M11 = 1/sqrt(a^2 + r^2) M21 = -(r/(a^2 + r^2)^(3/2)) M22 = sqrt(a^2 + r^2)/(a^2 + (-2 + r)*r) elseif s == +1 M11 = begin -((I*r*sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r))* ((-a^3)*m*r - a*m*r^3 + r^5*omega + a^4*(2*I + r*omega) + 2*a^2*r*(-2*I + I*r + r^2*omega)))/(sqrt(a^2 + r^2)* sqrt((a^2 + (-2 + r)*r)*(a^2 + r^2))* (-2*I*a^3*m*r - 2*I*a*m*r^3 + a^4*(1 + lambda) + r^4*(2 + lambda) + a^2*r*(2 + r*(3 + 2*lambda))))) end M12 = begin (r^2*(a^2 + r^2)^(3/2)* sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r)))/ (sqrt((a^2 + (-2 + r)*r)*(a^2 + r^2))* (-2*I*a^3*m*r - 2*I*a*m*r^3 + a^4*(1 + lambda) + r^4*(2 + lambda) + a^2*r*(2 + r*(3 + 2*lambda)))) end M21 = begin -((r*sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r))* (-2*a^7*m*(I + r*omega) + a^8*omega*(2*I + r*omega) + a^5*m*r*(2*I - I*r - 6*r^2*omega) + a*m*r^5*(-4*I + 3*I*r - 2*r^2*omega) - 2*a^3*m*r^3*(I - 2*I*r + 3*r^2*omega) + r^6*(2*(2 + lambda) - r*(2 + lambda) - I*r^2*omega + r^3*omega^2) + a^6*(-4 + r*(1 + m^2 - lambda - 2*I*omega) + 5*I*r^2*omega + 4*r^3*omega^2) + a^2*r^3*(4 + 4*r*lambda + r^2*(-3 + m^2 - 3*lambda - 2*I*omega) - I*r^3*omega + 4*r^4*omega^2) + a^4*r*(8 + 2*r*(-4 + lambda) + r^2*(2*m^2 - 3*lambda - 4*I*omega) + 3*I*r^3*omega + 6*r^4*omega^2)))/(sqrt(a^2 + r^2)* ((a^2 + (-2 + r)*r)*(a^2 + r^2))^(3/2)* (-2*I*a^3*m*r - 2*I*a*m*r^3 + a^4*(1 + lambda) + r^4*(2 + lambda) + a^2*r*(2 + r*(3 + 2*lambda))))) end M22 = begin -((I*r^2*((a^2 + r^2)/(a^2 + (-2 + r)*r))^(3/2)* ((-a^3)*m - a*m*r^2 + a^4*omega + r^3*(-I + r*omega) + a^2*(2*I - I*r + 2*r^2*omega)))/ (sqrt(a^2 + r^2)*sqrt((a^2 + (-2 + r)*r)* (a^2 + r^2))*(-2*I*a^3*m*r - 2*I*a*m*r^3 + a^4*(1 + lambda) + r^4*(2 + lambda) + a^2*r*(2 + r*(3 + 2*lambda))))) end elseif s == -1 M11 = begin (I*r*sqrt(a^2 + r^2)*((-a^3)*m*r - a*m*r^3 + r^5*omega + a^4*(-2*I + r*omega) + 2*a^2*r*(2*I - I*r + r^2*omega)))/ (sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r))* sqrt((a^2 + (-2 + r)*r)*(a^2 + r^2))* (2*I*a^3*m*r + 2*I*a*m*r^3 + a^4*(-1 + lambda) + r^4*lambda + a^2*r*(2 + r*(-1 + 2*lambda)))) end M12 = begin (r^2*sqrt(a^2 + r^2)*sqrt((a^2 + r^2)/ (a^2 + (-2 + r)*r))*sqrt((a^2 + (-2 + r)*r)* (a^2 + r^2)))/(2*I*a^3*m*r + 2*I*a*m*r^3 + a^4*(-1 + lambda) + r^4*lambda + a^2*r*(2 + r*(-1 + 2*lambda))) end M21 = begin (r*sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r))* (a^8*omega*(2*I - r*omega) + 2*a^7*m*(-I + r*omega) + a*m*r^5*(-2*I + I*r + 2*r^2*omega) + 2*a^3*m*r^3*(I + 3*r^2*omega) + a^5*m*r*(4*I - 3*I*r + 6*r^2*omega) + a^6*r*(1 - m^2 + lambda - 4*I*omega + 7*I*r*omega - 4*r^2*omega^2) - a^4*r^2*(2*(2 + lambda) + r*(-2 + 2*m^2 - 3*lambda + 10*I*omega) - 9*I*r^2*omega + 6*r^3*omega^2) + a^2*r^3*(4 - 4*r*(1 + lambda) - r^2*(-1 + m^2 - 3*lambda + 8*I*omega) + 5*I*r^3*omega - 4*r^4*omega^2) + r^6*((-2 + r)*lambda - r*omega*(2*I - I*r + r^2*omega))))/ ((a^2 + r^2)^(3/2)*sqrt((a^2 + (-2 + r)*r)* (a^2 + r^2))*(2*I*a^3*m*r + 2*I*a*m*r^3 + a^4*(-1 + lambda) + r^4*lambda + a^2*r*(2 + r*(-1 + 2*lambda)))) end M22 = begin -((r^2*sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r))* sqrt((a^2 + (-2 + r)*r)*(a^2 + r^2))* (-r - (I*(a^2 + r^2)*((-a)*m + (a^2 + r^2)*omega))/ (a^2 + (-2 + r)*r)))/(sqrt(a^2 + r^2)* (2*I*a^3*m*r + 2*I*a*m*r^3 + a^4*(-1 + lambda) + r^4*lambda + a^2*r*(2 + r*(-1 + 2*lambda))))) end elseif s == +2 M11 = begin (r^2*(a^2 + (-2 + r)*r)*(-4*a^5*m*r*(I + r*omega) - 2*a^3*m*r^2*(-3*I + 2*I*r + 4*r^2*omega) + a*m*(2*I*r^4 - 4*r^6*omega) + 2*a^6*(-5 + 2*I*r*omega + r^2*omega^2) + a^4*r*(32 + r*(-24 + 2*m^2 - lambda - 6*I*omega) + 10*I*r^2*omega + 6*r^3*omega^2) + r^4*(-12 + 2*r*(9 + lambda) - r^2*(6 + lambda + 6*I*omega) + 2*I*r^3*omega + 2*r^4*omega^2) + 2*a^2*r^2*(-12 + r*(23 + lambda) + r^2*(-10 + m^2 - lambda - 6*I*omega) + 4*I*r^3*omega + 3*r^4*omega^2)))/ (((a^2 + (-2 + r)*r)^2*(a^2 + r^2))^(3/2)* ((-r^4)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*r*(I + 2*r*omega) + 4*a*m*r^2* (6*I + 2*I*r*(4 + lambda) - 3*r^2*omega) + 12*a^4*(-1 + 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 - 6*I*omega) - 2*I*r^2*(1 + lambda)*omega + 3*r^3*omega^2))) end M12 = begin (2*r^3*(a^2 + (-2 + r)*r)*(a^2 + r^2)^2* ((-I)*a*m*r + a^2*(-2 + I*r*omega) + r*(3 - r + I*r^2*omega)))/ (((a^2 + (-2 + r)*r)^2*(a^2 + r^2))^(3/2)* ((-r^4)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*r*(I + 2*r*omega) + 4*a*m*r^2* (6*I + 2*I*r*(4 + lambda) - 3*r^2*omega) + 12*a^4*(-1 + 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 - 6*I*omega) - 2*I*r^2*(1 + lambda)*omega + 3*r^3*omega^2))) end M21 = begin -((I*r*(-2*a^7*m*r*(-2 + 4*I*r*omega + 3*r^2*omega^2) - 2*a^5*m*r^2*(-4 + r*(3 + m^2 - lambda + 2*I*omega) + 4*I*r^2*omega + 9*r^3*omega^2) + 2*a*m*r^5*(-10 + r*(3 - 2*lambda) + r^2*(2 + lambda + 2*I*omega) + 4*I*r^3*omega - 3*r^4*omega^2) - 2*a^3*m*r^3* (12 + r^2*(3 + m^2 - 2*lambda) + r*(-17 + 2*lambda) - 4*I*r^3*omega + 9*r^4*omega^2) + 2*a^8*(-6*I - 2*r*omega + 2*I*r^2*omega^2 + r^3*omega^3) + 2*a^6*r*(16*I + I*r*(-9 + 2*m^2 - 2*lambda + 4*I*omega) + r^2*(-8 + 3*m^2 - lambda + I*omega)*omega + 6*I*r^3*omega^2 + 4*r^4*omega^3) + r^6*(-4*I*lambda - 2*r^3*(4 + lambda + 5*I*omega)*omega + 2*r^5*omega^3 - 12*r*(I + omega) + r^2*(6*I + I*lambda + 18*omega + 4*lambda*omega)) + a^4*r^2*(-16*I + 2*I*r*(10 + m^2 + 6*lambda - 12*I*omega) + 2*r^3*(-14 + 6*m^2 - 3*lambda - 3*I*omega)*omega + 12*I*r^4*omega^2 + 12*r^5*omega^3 + r^2*(-2*I - 4*I*m^2 - 7*I*lambda + 22*omega + 4*lambda*omega)) + 2*a^2*r^4*(-4*I*lambda + I*r*(-4 + 3*m^2 + 6*lambda + 6*I*omega) + 3*r^3*(-4 + m^2 - lambda - 3*I*omega)*omega + 2*I*r^4*omega^2 + 4*r^5*omega^3 + r^2*(5*I - 4*I*m^2 - I*lambda + 24*omega + 4*lambda*omega))))/ (((a^2 + (-2 + r)*r)^2*(a^2 + r^2))^(3/2)* ((-r^4)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*r*(I + 2*r*omega) + 4*a*m*r^2* (6*I + 2*I*r*(4 + lambda) - 3*r^2*omega) + 12*a^4*(-1 + 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 - 6*I*omega) - 2*I*r^2*(1 + lambda)*omega + 3*r^3*omega^2)))) end M22 = begin (r^2*(a^2 + r^2)^2*(-4*a^3*m*r*(I + r*omega) - 2*a*m*r^2*(I - 3*I*r + 2*r^2*omega) + 2*a^4*(-3 + 2*I*r*omega + r^2*omega^2) + r^3*(2*lambda - r*(2 + lambda + 10*I*omega) + 2*r^3*omega^2) + a^2*r*(8 + 2*m^2*r - r*lambda + 2*I*r*omega + 4*I*r^2*omega + 4*r^3*omega^2)))/ (((a^2 + (-2 + r)*r)^2*(a^2 + r^2))^(3/2)* ((-r^4)*(24 + 10*lambda + lambda^2 + 12*I*omega) - 24*a^3*m*r*(I + 2*r*omega) + 4*a*m*r^2* (6*I + 2*I*r*(4 + lambda) - 3*r^2*omega) + 12*a^4*(-1 + 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 - 6*I*omega) - 2*I*r^2*(1 + lambda)*omega + 3*r^3*omega^2))) end elseif s == -2 M11 = begin (r^2*(-4*a^5*m*r*(-I + r*omega) - 2*a*m*r^4*(I + 2*r^2*omega) - 2*a^3*m*r^2* (3*I - 2*I*r + 4*r^2*omega) + 2*a^6*(-5 - 2*I*r*omega + r^2*omega^2) + a^4*r*(32 + r*(-20 + 2*m^2 - lambda + 6*I*omega) - 10*I*r^2*omega + 6*r^3*omega^2) + r^4*(-12 + 2*r*(5 + lambda) - r^2*(2 + lambda - 6*I*omega) - 2*I*r^3*omega + 2*r^4*omega^2) + 2*a^2*r^2*(-12 + r*(19 + lambda) + r^2*(-6 + m^2 - lambda + 6*I*omega) - 4*I*r^3*omega + 3*r^4*omega^2)))/((a^2 + (-2 + r)*r)^3* ((a^2 + r^2)/(a^2 + (-2 + r)*r)^2)^(3/2)* ((-r^4)*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*r*(I - 2*r*omega) - 4*a*m*r^2* (6*I + 2*I*r*lambda + 3*r^2*omega) + 12*a^4*(-1 - 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 + 6*I*omega) + 2*I*r^2*(-3 + lambda)*omega + 3*r^3*omega^2))) end M12 = begin (2*r^3*(a^2 + (-2 + r)*r)* sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r)^2)* (I*a*m*r + a^2*(-2 - I*r*omega) + r*(3 - r - I*r^2*omega)))/ ((-r^4)*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*r*(I - 2*r*omega) - 4*a*m*r^2*(6*I + 2*I*r*lambda + 3*r^2*omega) + 12*a^4*(-1 - 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 + 6*I*omega) + 2*I*r^2*(-3 + lambda)*omega + 3*r^3*omega^2)) end M21 = begin (I*r*sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r)^2)* (2*a^7*m*r*(2 + 4*I*r*omega - 3*r^2*omega^2) - 2*a^5*m*r^2*(4 + r*(-1 + m^2 - lambda + 6*I*omega) - 12*I*r^2*omega + 9*r^3*omega^2) - 2*a^3*m*r^4*(-5 + 2*lambda + r*(3 + m^2 - 2*lambda + 16*I*omega) - 12*I*r^2*omega + 9*r^3*omega^2) - 2*a*m*r^5*(6 + r*(-7 + 2*lambda) + r^2*(2 - lambda + 10*I*omega) - 4*I*r^3*omega + 3*r^4*omega^2) + 2*a^8*(6*I - 2*r*omega - 2*I*r^2*omega^2 + r^3*omega^3) + 2*a^6*r*(-36*I + r^2*(-12 + 3*m^2 - lambda + 3*I*omega)* omega - 10*I*r^3*omega^2 + 4*r^4*omega^3 + r*(21*I - 2*I*m^2 + 2*I*lambda + 4*omega)) + r^5*(-48*I + 12*I*r*(6 + lambda) - 12*I*r^2*(3 + lambda - 3*I*omega) - 2*r^4*(4 + lambda - 9*I*omega)*omega - 8*I*r^5*omega^2 + 2*r^6*omega^3 + r^3*(6*I + 3*I*lambda + 34*omega + 4*lambda*omega)) + 2*a^2*r^3*(-48*I + 4*I*r*(27 + 2*lambda) + I*r^2*(-72 + m^2 - 14*lambda + 30*I*omega) + r^4*(-16 + 3*m^2 - 3*lambda + 21*I*omega)*omega - 14*I*r^5*omega^2 + 4*r^6*omega^3 + r^3*(15*I + 5*I*lambda + 48*omega + 4*lambda*omega)) + a^4*r^2*(144*I + 2*I*r*(-90 + 3*m^2 - 8*lambda) + 2*r^3*(-22 + 6*m^2 - 3*lambda + 15*I*omega)*omega - 36*I*r^4*omega^2 + 12*r^5*omega^3 + r^2*(54*I - 4*I*m^2 + 11*I*lambda + 70*omega + 4*lambda*omega))))/((a^2 + r^2)^2* ((-r^4)*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*r*(I - 2*r*omega) - 4*a*m*r^2* (6*I + 2*I*r*lambda + 3*r^2*omega) + 12*a^4*(-1 - 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 + 6*I*omega) + 2*I*r^2*(-3 + lambda)*omega + 3*r^3*omega^2))) end M22 = begin (r^2*sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r)^2)* (-4*a^3*m*r*(-I + r*omega) - 2*a*m*r^2* (3*I - I*r + 2*r^2*omega) + 2*a^4*(-3 - 2*I*r*omega + r^2*omega^2) + a^2*r*(24 + r*(-12 + 2*m^2 - lambda + 6*I*omega) - 12*I*r^2*omega + 4*r^3*omega^2) + r^2*(-24 + 2*r*(12 + lambda) - r^2*(6 + lambda - 18*I*omega) - 8*I*r^3*omega + 2*r^4*omega^2)))/ ((-r^4)*(2*lambda + lambda^2 - 12*I*omega) + 24*a^3*m*r*(I - 2*r*omega) - 4*a*m*r^2*(6*I + 2*I*r*lambda + 3*r^2*omega) + 12*a^4*(-1 - 2*I*r*omega + 2*r^2*omega^2) + 4*a^2*r*(6 + r*(-3 + 6*m^2 + 6*I*omega) + 2*I*r^2*(-3 + lambda)*omega + 3*r^3*omega^2)) end else # Throw an error, this spin weight is not supported throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end return [M11 M12; M21 M22] end function Teukolsky_radial_function_from_Sasaki_Nakamura_function(s::Int, m::Int, a, omega, lambda, Xsoln) #= First convert [X(rs), dX/drs(rs)] to [X(r), dX/dr(r)], this is done by [X(r), dX/dr(r)]^T = [1, 0; 0, drstar/dr ] * [X(rs), dX/drs(rs)]^T Then we convert [X(r), dX/dr(r)] to [chi(r), dchi/dr(r)] by [chi(r), dchi/dr(r)]^T = [chi_conversion_factor(r), 0 ; dchi_conversion_factor_dr, chi_conversion_factor] * [X(r), dX/dr(r)]^T After that we convert [chi(r), dchi/dr(r)] to [R(r), dR/dr(r)] by [R(r), dR/dr(r)]^T = 1/eta(r) * [ alpha + beta_prime*Delta^(s+1), -beta*Delta^(s+1) ; -(alpha_prime + beta*VT*Delta^s), alpha ] * [chi(r), dchi/dr(r)]^T Therefore the overall conversion matrix is 'just' (one matrix for each r) the multiplication of each conversion matrix =# overall_conversion_matrix(r) = Teukolsky_radial_function_from_Sasaki_Nakamura_function_conversion_matrix(s, m, a, omega, lambda, r) X(rs) = Xsoln(rs)[1] Xprime(rs) = Xsoln(rs)[2] Rsoln = (r -> overall_conversion_matrix(r) * [X(rstar_from_r(a, r)); Xprime(rstar_from_r(a, r))]) return Rsoln end function Sasaki_Nakamura_function_from_Teukolsky_radial_function(s::Int, m::Int, a, omega, lambda, Rsoln) #= Teukolsky_radial_function_from_Sasaki_Nakamura_function_conversion_matrix() returns the conversion matrix for going from (X, dX/drs) to (R, dR/dr). Here we need the inverse of that to go from (R, dR/dr) to (X, dX/drs). =# conversion_matrix(r) = inv(Teukolsky_radial_function_from_Sasaki_Nakamura_function_conversion_matrix(s, m, a, omega, lambda, r)) Xsoln(rs) = begin r = r_from_rstar(a, rs) conversion_matrix(r) * Rsoln(r) end return Xsoln end function d2Rdr2_from_Rsoln(s::Int, m::Int, a, omega, lambda, Rsoln, r) #= Using the radial Teukolsky equation we can solve for d2Rdr2 from R and dRdr using d2Rdr2 = VT/\Delta R - (2(s+1)(r-M))/\Delta dRdr =# # NOTE DO NOT USE THE DOT PRODUCT IN LINEAR ALGEBRA R, dRdr = Rsoln(r) return (VT(s, m, a, omega, lambda, r)/Delta(a, r))*R - ((2*(s+1)*(r-1))/Delta(a,r))*dRdr end function scaled_Wronskian_Teukolsky(Rin_soln, Rup_soln, r, s, a) # The scaled Wronskian is given by W = Delta^{s+1} * det([Rin Rup; Rin' Rup']) Rin, Rin_prime = Rin_soln(r) Rup, Rup_prime = Rup_soln(r) return Delta(a, r)^(s+1) * (Rin*Rup_prime - Rup*Rin_prime) end function scaled_Wronskian_GSN(Xin_soln, Xup_soln, rs, s, m, a, omega, lambda) r = r_from_rstar(a, rs) Xin, dXindrs = Xin_soln(rs) Xup, dXupdrs = Xup_soln(rs) _eta = eta(s, m, a, omega, lambda, r) return (Xin*dXupdrs - dXindrs*Xup)/_eta end function scaled_Wronskian_from_Phisolns(Phiin_soln, Phiup_soln, rs, s, m, a, omega, lambda) r = r_from_rstar(a, rs) Xin = exp(1im*Phiin_soln(rs)[1]) dXindrs = 1im*exp(1im*Phiinsoln(rs)[1])*Phiinsoln(rs)[2] Xup = exp(1im*Phiup_soln(rs)[1]) dXupdrs = 1im*exp(1im*Phiupsoln(rs)[1])*Phiupsoln(rs)[2] _eta = eta(s, m, a, omega, lambda, r) return (Xin*dXupdrs - dXindrs*Xup)/_eta end function residual_from_Xsoln(s::Int, m::Int, a, omega, lambda, Xsoln) # Compute the second derivative using autodiff instead of finite diff X(rs) = Xsoln(rs)[1] first_deriv(rs) = Xsoln(rs)[2] second_deriv(rs) = ForwardDiff.derivative(first_deriv, rs) _sF(rs) = sF(s, m, a, omega, lambda, r_from_rstar(a, rs)) _sU(rs) = sU(s, m, a, omega, lambda, r_from_rstar(a, rs)) return rs -> second_deriv(rs) - _sF(rs)*first_deriv(rs) - _sU(rs)*X(rs) end function residual_RiccatiEqn_from_Phisoln(s::Int, m::Int, a, omega, lambda, Phisoln) Phi(rs) = Phisoln(rs)[1] # Does not matter actually! first_deriv(rs) = Phisoln(rs)[2] second_deriv(rs) = ForwardDiff.derivative(first_deriv, rs) _sF(rs) = sF(s, m, a, omega, lambda, r_from_rstar(a, rs)) _sU(rs) = sU(s, m, a, omega, lambda, r_from_rstar(a, rs)) return rs -> second_deriv(rs) + 1im*_sU(rs) - _sF(rs)*first_deriv(rs) + 1im*(first_deriv(rs))^2 end function residual_GSNEqn_from_Phisoln(s::Int, m::Int, a, omega, lambda, Phisoln) # Compute the second derivative using autodiff instead of finite diff X = (rs -> exp(1im*Phisoln(rs)[1])) first_deriv = (rs -> 1im*exp(1im*Phisoln(rs)[1])*Phisoln(rs)[2]) second_deriv(rs) = ForwardDiff.derivative(first_deriv, rs) _sF(rs) = sF(s, m, a, omega, lambda, r_from_rstar(a, rs)) _sU(rs) = sU(s, m, a, omega, lambda, r_from_rstar(a, rs)) return rs -> second_deriv(rs) - _sF(rs)*first_deriv(rs) - _sU(rs)*X(rs) end function CrefCinc_SN_from_Xup(s::Int, m::Int, a, omega, lambda, Xupsoln, rsin; order=0) p = omega - m*omega_horizon(a) rin = r_from_rstar(a, rsin) # Computing A1, A2, A3, A4 gin(r) = gansatz( ord -> ingoing_coefficient_at_hor(s, m, a, omega, lambda, ord), a, r; order=order ) A1 = gin(rin) * exp(-1im*p*rsin) gout(r) = gansatz( ord -> outgoing_coefficient_at_hor(s, m, a, omega, lambda, ord), a, r; order=order ) A2 = gout(rin) * exp(1im*p*rsin) _DeltaOverr2pa2 = Delta(a, rin)/(rin^2 + a^2) A3 = (_DeltaOverr2pa2 * ForwardDiff.derivative(gin, rin) - 1im*p*gin(rin)) * exp(-1im*p*rsin) A4 = (_DeltaOverr2pa2 * ForwardDiff.derivative(gout, rin) + 1im*p*gout(rin)) * exp(1im*p*rsin) X(rs) = Xupsoln(rs)[1] Xprime(rs) = Xupsoln(rs)[2] C1 = X(rsin) C2 = Xprime(rsin) return -(A4*C1 - A2*C2)/(A2*A3 - A1*A4), -(-A3*C1 + A1*C2)/(A2*A3 - A1*A4) end function BrefBinc_SN_from_Xin(s::Int, m::Int, a, omega, lambda, Xinsoln, rsout; order=3) rout = r_from_rstar(a, rsout) # Computing A1, A2, A3, A4 fin(r) = fansatz( ord -> ingoing_coefficient_at_inf(s, m, a, omega, lambda, ord), omega, r; order=order ) A1 = fin(rout) * exp(-1im*omega*rsout) fout(r) = fansatz( ord -> outgoing_coefficient_at_inf(s, m, a, omega, lambda, ord), omega, r; order=order ) A2 = fout(rout) * exp(1im*omega*rsout) _DeltaOverr2pa2 = Delta(a, rout)/(rout^2 + a^2) A3 = (_DeltaOverr2pa2 * ForwardDiff.derivative(fin, rout) - 1im*omega*fin(rout)) * exp(-1im*omega*rsout) A4 = (_DeltaOverr2pa2 * ForwardDiff.derivative(fout, rout) + 1im*omega*fout(rout)) * exp(1im*omega*rsout) X(rs) = Xinsoln(rs)[1] Xprime(rs) = Xinsoln(rs)[2] C1 = X(rsout) C2 = Xprime(rsout) return -(-A3*C1 + A1*C2)/(A2*A3 - A1*A4), -(A4*C1 - A2*C2)/(A2*A3 - A1*A4) end function semianalytical_Xin(s, m, a, omega, lambda, Xinsoln, rsin, rsout, horizon_expansionorder, infinity_expansionorder, rs) _r = r_from_rstar(a, rs) # Evaluate at this r if rs < rsin # Extend the numerical solution to the analytical ansatz from rsin to horizon # Construct the analytical ansatz p = omega - m*omega_horizon(a) gin(r) = gansatz( ord -> ingoing_coefficient_at_hor(s, m, a, omega, lambda, ord), a, r; order=horizon_expansionorder ) _Xin = gin(_r)*exp(-1im*p*rs) # Evaluate at *this* rs _DeltaOverr2pa2 = Delta(a, _r)/(_r^2 + a^2) _dXindrs = (_DeltaOverr2pa2 * ForwardDiff.derivative(gin, _r) - 1im*p*gin(_r))*exp(-1im*p*rs) return (_Xin, _dXindrs) elseif rs > rsout # Extend the numerical solution to the analytical ansatz from rsout to infinity # Obtain the coefficients by imposing continuity in X and dX/drs Bref_SN, Binc_SN = BrefBinc_SN_from_Xin(s, m, a, omega, lambda, Xinsoln, rsout; order=infinity_expansionorder) # Construct the analytical ansatz fin(r) = fansatz( ord -> ingoing_coefficient_at_inf(s, m, a, omega, lambda, ord), omega, r; order=infinity_expansionorder ) fout(r) = fansatz( ord -> outgoing_coefficient_at_inf(s, m, a, omega, lambda, ord), omega, r; order=infinity_expansionorder ) _Xin = Bref_SN*fout(_r)*exp(1im*omega*rs) + Binc_SN*fin(_r)*exp(-1im*omega*rs) _DeltaOverr2pa2 = Delta(a, _r)/(_r^2 + a^2) _dXindrs = Bref_SN*(_DeltaOverr2pa2 * ForwardDiff.derivative(fout, _r) + 1im*omega*fout(_r))*exp(1im*omega*rs) + Binc_SN*(_DeltaOverr2pa2 * ForwardDiff.derivative(fin, _r) - 1im*omega*fin(_r))*exp(-1im*omega*rs) return (_Xin, _dXindrs) else # Requested rs is within the numerical solution return Xinsoln(rs) end end function semianalytical_Xup(s, m, a, omega, lambda, Xupsoln, rsin, rsout, horizon_expansionorder, infinity_expansionorder, rs) _r = r_from_rstar(a, rs) # Evaluate at this r if rs < rsin # Extend the numerical solution to the analytical ansatz from rsin to horizon # Obtain the coefficients by imposing continuity in X and dX/drs Cref_SN, Cinc_SN = CrefCinc_SN_from_Xup(s, m, a, omega, lambda, Xupsoln, rsin; order=horizon_expansionorder) # with coefficient Cref_SN for the left-going and Cinc_SN for the right-going mode # Construct the analytical ansatz p = omega - m*omega_horizon(a) gin(r) = gansatz( ord -> ingoing_coefficient_at_hor(s, m, a, omega, lambda, ord), a, r; order=horizon_expansionorder ) gout(r) = gansatz( ord -> outgoing_coefficient_at_hor(s, m, a, omega, lambda, ord), a, r; order=horizon_expansionorder ) _Xup = Cinc_SN*gout(_r)*exp(1im*p*rs) + Cref_SN*gin(_r)*exp(-1im*p*rs) # Evaluate at *this* rs _DeltaOverr2pa2 = Delta(a, _r)/(_r^2 + a^2) _dXupdrs = Cinc_SN*(_DeltaOverr2pa2 * ForwardDiff.derivative(gout, _r) + 1im*p*gout(_r))*exp(1im*p*rs) + Cref_SN*(_DeltaOverr2pa2 * ForwardDiff.derivative(gin, _r) - 1im*p*gin(_r))*exp(-1im*p*rs) return (_Xup, _dXupdrs) elseif rs > rsout # Extend the numerical solution to the analytical ansatz from rsout to infinity fout(r) = fansatz( ord -> outgoing_coefficient_at_inf(s, m, a, omega, lambda, ord), omega, r; order=infinity_expansionorder ) _Xup = fout(_r)*exp(1im*omega*rs) _DeltaOverr2pa2 = Delta(a, _r)/(_r^2 + a^2) _dXupdrs = (_DeltaOverr2pa2 * ForwardDiff.derivative(fout, _r) + 1im*omega*fout(_r)) * exp(1im*omega*rs) return (_Xup, _dXupdrs) else # Requested rs is within the numerical solution return Xupsoln(rs) end end function check_XinXup_sanity(Xin, Xup; tolerance=1e-6) #= Check if the X_in and X_up solutions are sane by checking if the identity Binc/Cinc = (p*c0)/(omega*eta(r_+)) [note: this is Eq. (42) in the paper] is satisfied within a specified tolerance =# # Check if the modes are the same if Xin.mode != Xup.mode throw(ArgumentError("The modes of Xin and Xup are different")) end # Calculate what Binc/Cinc is expected to be p = Xin.mode.omega - Xin.mode.m*omega_horizon(Xin.mode.a) c0 = eta_coefficient(Xin.mode.s, Xin.mode.m, Xin.mode.a, Xin.mode.omega, Xin.mode.lambda, 0) eta_at_rplus = eta(Xin.mode.s, Xin.mode.m, Xin.mode.a, Xin.mode.omega, Xin.mode.lambda, r_plus(Xin.mode.a)) expected_value = (p*c0)/(Xin.mode.omega*eta_at_rplus) # Calculate the actual value actual_value = Xin.incidence_amplitude/Xup.incidence_amplitude if abs(actual_value - expected_value) > tolerance return false else return true end end # Some helper functions for static modes function x_from_r(a, r) #= x \equiv (rp - r)/(rp - rm) is a transformed coordinate that is used only internally in the code/static mode computation =# gamma = sqrt(1 - a^2) return ((1+gamma)-r)/(2*gamma) end function r_from_x(a, x) gamma = sqrt(1 - a^2) return 1 + gamma - 2*gamma*x end function isnegativeinteger(x) isinteger(x) && x < 0 end # Some helper functions for manipulating hypergeometric functions function pochhammer(x, n) # Wrapper for the pochhammer function implemented in HypergeometricFunctions.jl HypergeometricFunctions.pochhammer(x, n) end #= Since there is no implementation of a "regularized" Gauss hypergeometric function in HypergeometricFunctions.jl yet, we use the fact that when c approaches a negative integer, 2F1(a,b;c,z)/Gamma(c) approaches the value lim c->-m 2F1(a, b; c, z)/Gamma(c) = (a)_m (b)_m / m! * z^m * 2F1(a+m, b+m; m+1; z) which is implemented below =# function _2F1_over_Gamma_c(a, b, c, z) # NOTE This is true only when c is a negative integer z *= (1 + 0im) # Make sure that z is a complex number m = abs(c) + 1 ( pochhammer(a, m) * pochhammer(b, m) / factorial(m) ) * z^m * pFq((a+m, b+m), (m+1, ), z) end function _d2F1_over_Gamma_c_dz(a, b, c, z) # NOTE This is true only when c is a negative integer z *= (1 + 0im) # Make sure that z is a complex number m = abs(c) + 1 # Here we explicitly compute the derivative because ForwardDiff.jl does not work very well with HypergeometricFunctions.jl ( pochhammer(a, m) * pochhammer(b, m) / factorial(m) ) * (m*z^(m-1) * pFq((a+m, b+m), (m+1, ), z) + z^m * pFq((a+m+1, b+m+1), (m+2, ), z)) end function solve_static_Rin(s::Int, l::Int, m::Int, a) #= This is an internal function that returns the static (omega = 0) solution that satisfies the "purely left-going" condition at the horizon, namely the R^in solution. Use instead GeneralizedSasakiNakamura.Teukolsky_radial() and set omega = 0 and boundary_condition = IN =# gamma = sqrt(1 - a^2) kappa = I*a*m/gamma normalization_const = begin (-1)^(-kappa/2) * exp(I*a*m/2) * gamma^(I*a*m/(1+gamma)) * (-4*gamma^2)^(-s) end Rin(r) = begin x = x_from_r(a, r) if iszero(kappa) && isnegativeinteger(1-s) # Regularization normalization_const * x^(-s + kappa/2) * (1-x)^(kappa/2) * _2F1_over_Gamma_c(-l+kappa, 1+l+kappa, 1-s, x) else normalization_const * x^(-s + kappa/2) * (1-x)^(kappa/2) * pFq((-l+kappa, 1+l+kappa), (1-s+kappa,), x) end end dRindr(r) = begin x = x_from_r(a, r) if iszero(kappa) && isnegativeinteger(1-s) # Regularization normalization_const * (-1/(2*gamma)) * ( (1/2) * (1-x)^(-1+kappa/2) * x^(-1-s+kappa/2) * (2*s*(x-1) + kappa - 2*kappa*x) * _2F1_over_Gamma_c(-l+kappa, 1+l+kappa, 1-s, x) + x^(-s + kappa/2) * (1-x)^(kappa/2) * _d2F1_over_Gamma_c_dz(-l+kappa, 1+l+kappa, 1-s, x) ) else normalization_const * (-1/(2*gamma)) * ( (1/2) * (1-x)^(-1+kappa/2) * x^(-1-s+kappa/2) * (2*s*(x-1) + kappa - 2*kappa*x) * pFq((-l+kappa, 1+l+kappa), (1-s+kappa,), x) + x^(-s + kappa/2) * (1-x)^(kappa/2) * pochhammer(-l+kappa, 1) * pochhammer(1+l+kappa, 1) / pochhammer(1-s+kappa, 1) * pFq((-l+kappa+1, 1+l+kappa+1), (1-s+kappa+1,), x) ) end end return (r -> [Rin(r); dRindr(r)]) end function solve_static_Rup(s::Int, l::Int, m::Int, a) #= This is an internal function that returns the static (omega = 0) solution that satisfies the "purely right-going" condition at spatial infinity, namely the R^up solution. Use instead GeneralizedSasakiNakamura.Teukolsky_radial() and set omega = 0 and boundary_condition = UP =# gamma = sqrt(1 - a^2) kappa = I*a*m/gamma normalization_const = begin (-2*gamma)^(-s-l-1) end Rup(r) = begin x = x_from_r(a, r) normalization_const * x^(-s-l-1-kappa/2) * (x-1)^(kappa/2) * pFq((1+l+kappa, 1+s+l), (2+2*l,),1/x) end dRupdr(r) = begin x = x_from_r(a, r) normalization_const * (-1/(2*gamma)) * ( ( (1/2)*(x-1)^(-1+kappa/2) * x^(-2-l-s-kappa/2) * (-2*(1+l+s)*(x-1) + kappa) ) * pFq((1+l+kappa, 1+s+l), (2+2*l,),1/x) + x^(-s-l-1-kappa/2) * (x-1)^(kappa/2) * pochhammer(1+l+kappa, 1) * pochhammer(1+s+l, 1) / pochhammer(2+2*l, 1) * pFq((2+l+kappa, 2+s+l), (3+2*l,),1/x) * (-1/x^2) ) end return (r-> [Rup(r); dRupdr(r)]) end end
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
8496
module Transformation using ForwardDiff using ..Kerr using ..Potentials export alpha, alpha_prime, beta, beta_prime, eta_coefficient, eta, eta_prime const I = 1im # Mathematica being Mathematica function alpha(s::Int, m::Int, a, omega, lambda, r) if s == 0 return 1 elseif s == +1 return begin (sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r))*((-I)*a^3*m - I*a*m*r^2 + I*a^4*omega + r^3*(1 + I*r*omega) + a^2*(-2 + r + 2*I*r^2*omega)))/(r^2*sqrt(a^2 + r^2)) end elseif s == -1 return begin (sqrt((a^2 + (-2 + r)*r)*(a^2 + r^2))*(-r - (I*(a^2 + r^2)*((-a)*m + (a^2 + r^2)*omega))/ (a^2 + (-2 + r)*r)))/(r^2*sqrt(a^2 + r^2)) end elseif s == +2 return begin (1/(r^2*(a^2 + (-2 + r)*r)))*(4*a^3*m*r*(I + r*omega) + 2*a*m*r^2*(I - 3*I*r + 2*r^2*omega) - 2*a^4*(-3 + 2*I*r*omega + r^2*omega^2) + r^3*(-2*lambda + r*(2 + lambda + 10*I*omega) - 2*r^3*omega^2) - a^2*r*(8 + 2*m^2*r - r*lambda + 2*I*r*omega + 4*I*r^2*omega + 4*r^3*omega^2)) end elseif s == -2 return begin (1/(r^2*(a^2 + (-2 + r)*r)))*(4*a^3*m*r*(-I + r*omega) + 2*a*m*r^2*(3*I - I*r + 2*r^2*omega) + a^4*(6 + 4*I*r*omega - 2*r^2*omega^2) + a^2*r*(-24 + r*(12 - 2*m^2 + lambda - 6*I*omega) + 12*I*r^2*omega - 4*r^3*omega^2) + r^2*(24 - 2*r*(12 + lambda) + r^2*(6 + lambda - 18*I*omega) + 8*I*r^3*omega - 2*r^4*omega^2)) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function beta(s::Int, m::Int, a, omega, lambda, r) if s == 0 return 0 elseif s == +1 return begin ((a^2 + r^2)/(a^2 + (-2 + r)*r))^(3/2)/(r^2*sqrt(a^2 + r^2)) end elseif s == -1 return begin (sqrt(a^2 + r^2)*sqrt((a^2 + (-2 + r)*r)*(a^2 + r^2)))/r^2 end elseif s == +2 return begin (-2*I*a*m*r + a^2*(-4 + 2*I*r*omega) + 2*r*(3 - r + I*r^2*omega))/(r*(a^2 + (-2 + r)*r)^3) end elseif s == -2 return begin (2*(a^2 + (-2 + r)*r)*(I*a*m*r + a^2*(-2 - I*r*omega) + r*(3 - r - I*r^2*omega)))/r end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function alpha_prime(s::Int, m::Int, a, omega, lambda, r) if s == 0 return 0 elseif s == +1 return begin -((I*sqrt(a^2 + r^2)*(-2*a^5*m + a^3*m*(5 - 3*r)*r - a*m*(-1 + r)*r^3 + 2*a^6*omega - r^4*(I - 3*r*omega + r^2*omega) - a^2*r*(10*I - 9*I*r + r^2*(I + 2*omega)) + a^4*(4*I + 3*r^2*omega - r*(I + 5*omega))))/(r^3*(a^2 + (-2 + r)*r)^2* sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r)))) end elseif s == -1 return begin (I*(a^2 + r^2)^(3/2)*(-2*a^5*m + a^3*m*(5 - 3*r)*r - a*m*(-1 + r)*r^3 + 2*a^6*omega + r^3*(-2*I + I*r + 3*r^2*omega - r^3*omega) + a^4*r*(-I + (-5 + 3*r)*omega) + a^2*r^2*(3*I - r*(I + 2*omega))))/(r^3*((a^2 + (-2 + r)*r)*(a^2 + r^2))^(3/2)) end elseif s == +2 return begin -((1/(r^3*(a^2 + (-2 + r)*r)^2))*(2*(2*I*a^5*m*r + a^3*m*r^2*(-8*I + r*(9*I - 4*omega)) + a^6*(6 - 2*I*r*omega) + 2*r^5*(1 + 5*I*omega + (-3 + r)*r^2*omega^2) + 2*a^4*r*(-11 + r*(6 + 4*I*omega) + r^3*omega^2 + r^2*omega*(-2*I + omega)) + 2*a^2*r^2*(8 + r*(-6 + m^2 + I*omega) - r^2*(1 + m^2 + 6*I*omega) + 2*r^4*omega^2 - r^3*omega*(I + 2*omega)) + a*m*r^3*(-2*I + 2*I*r + r^2*(-3*I + 4*omega))))) end elseif s == -2 return begin -((1/(r^3*(a^2 + (-2 + r)*r)^2))*(2*(-2*I*a^5*m*r + a^6*(6 + 2*I*r*omega) + 2*a^4*r*(-15 + r*(6 - 4*I*omega) + r^2*omega^2 + r^3*omega^2) + 2*a^2*r^2*(24 + r*(-18 + m^2 + 3*I*omega) + r^2*(3 - m^2 + 6*I*omega) + 2*r^4*omega^2 - r^3*omega*(3*I + 2*omega)) + 2*r^3*(-12 + 12*r + r^2*(-3 - 9*I*omega) + 8*I*r^3*omega + r^5*omega^2 - r^4*omega*(2*I + 3*omega)) + a*m*r^3*(-6*I + 6*I*r + r^2*(-I + 4*omega)) + a^3*m*r^2*(8*I - r*(5*I + 4*omega))))) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function beta_prime(s::Int, m::Int, a, omega, lambda, r) if s == 0 return 0 elseif s == +1 return begin -((sqrt((a^2 + r^2)/(a^2 + (-2 + r)*r))*(2*a^4 + 3*(-1 + r)*r^3 + a^2*r*(-7 + 5*r)))/ (r^3*(a^2 + (-2 + r)*r)^2*sqrt(a^2 + r^2))) end elseif s == -1 return begin (-2*a^6 - 3*a^4*(-1 + r)*r + 2*a^2*r^3 + (-1 + r)*r^5)/ (r^3*sqrt(a^2 + r^2)*sqrt((a^2 + (-2 + r)*r)*(a^2 + r^2))) end elseif s == +2 return begin (1/(r^2*(a^2 + (-2 + r)*r)^4))*(2*(2*a^4 + 6*I*a*m*(-1 + r)*r^2 + a^2*r*(-16 + r*(13 + 6*I*omega) - 4*I*r^2*omega) + r^2*(18 - 22*r + r^2*(5 + 2*I*omega) - 4*I*r^3*omega))) end elseif s == -2 return begin 2*(-6 + 2*I*a*m*(-1 + r) + (2*a^4)/r^2 + 10*r + r^2*(-3 + 6*I*omega) - 4*I*r^3*omega + a^2*(-3 - 2*I*(-1 + 2*r)*omega)) end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function eta_coefficient(s::Int, m::Int, a, omega, lambda, order) if s == 0 if order == 0 return 1 elseif order == -1 return 0 elseif order == -2 return 0 elseif order == -3 return 0 elseif order == -4 return 0 else return 0 end elseif s == +1 if order == 0 return -2 - lambda elseif order == -1 return 2*I*a*m elseif order == -2 return -3*a^2 - 2*a^2*lambda elseif order == -3 return -2*a^2 + 2*I*a^3*m elseif order == -4 return -a^4 - a^4*lambda else return 0 end elseif s == -1 if order == 0 return -lambda elseif order == -1 return -2*I*a*m elseif order == -2 return a^2 - 2*a^2*lambda elseif order == -3 return -2*a^2 - 2*I*a^3*m elseif order == -4 return a^4 - a^4*lambda else return 0 end elseif s == +2 if order == 0 return 24 + 10*lambda + lambda^2 + 12*I*omega + 12*a*m*omega - 12*a^2*omega^2 elseif order == -1 return -32*I*a*m - 8*I*a*m*lambda + 8*I*a^2*omega + 8*I*a^2*lambda*omega elseif order == -2 return 12*a^2 - 24*I*a*m - 24*a^2*m^2 + 24*I*a^2*omega + 48*a^3*m*omega - 24*a^4*omega^2 elseif order == -3 return -24*a^2 + 24*I*a^3*m - 24*I*a^4*omega elseif order == -4 return 12*a^4 else return 0 end elseif s == -2 if order == 0 return 2*lambda + lambda^2 - 12*I*omega + 12*a*m*omega - 12*a^2*omega^2 elseif order == -1 return 8*I*a*m*lambda + 24*I*a^2*omega - 8*I*a^2*lambda*omega elseif order == -2 return 12*a^2 + 24*I*a*m - 24*a^2*m^2 - 24*I*a^2*omega + 48*a^3*m*omega - 24*a^4*omega^2 elseif order == -3 return -24*a^2 - 24*I*a^3*m + 24*I*a^4*omega elseif order == -4 return 12*a^4 else return 0 end else throw(DomainError(s, "Currently only spin weight s of 0, +/-1, +/-2 are supported")) end end function eta(s::Int, m::Int, a, omega, lambda, r) # eta(r) = c0 + c1/r + c2/r^2 + c3/r^3 + c4/r^4 c0 = eta_coefficient(s, m, a, omega, lambda, 0) c1 = eta_coefficient(s, m, a, omega, lambda, -1) c2 = eta_coefficient(s, m, a, omega, lambda, -2) c3 = eta_coefficient(s, m, a, omega, lambda, -3) c4 = eta_coefficient(s, m, a, omega, lambda, -4) return c0 + c1/r + c2/r^2 + c3/r^3 + c4/r^4 end function eta_prime(s::Int, m::Int, a, omega, lambda, r) # eta'(r) = -c1/r^2 - 2c2/r^3 - 3c3/r^4 - 4c4/r^5 c1 = eta_coefficient(s, m, a, omega, lambda, -1) c2 = eta_coefficient(s, m, a, omega, lambda, -2) c3 = eta_coefficient(s, m, a, omega, lambda, -3) c4 = eta_coefficient(s, m, a, omega, lambda, -4) return -c1/r^2 - 2c2/r^3 - 3c3/r^4 - 4c4/r^5 end end
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
code
123
using GeneralizedSasakiNakamura using Test @testset "GeneralizedSasakiNakamura.jl" begin # Write your tests here. end
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
docs
4943
# GeneralizedSasakiNakamura.jl ![license](https://img.shields.io/github/license/ricokaloklo/GeneralizedSasakiNakamura.jl) [![GitHub release](https://img.shields.io/github/v/release/ricokaloklo/GeneralizedSasakiNakamura.jl.svg)](https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl/releases) [![Documentation](https://img.shields.io/badge/Documentation-ready)](http://ricokaloklo.github.io/GeneralizedSasakiNakamura.jl) GeneralizedSasakiNakamura.jl computes solutions to the frequency-domain radial Teukolsky equation with the Generalized Sasaki-Nakamura (GSN) formalism. The code is capable of handling *both in-going and out-going* radiation of scalar, electromagnetic, and gravitational type (corresponding to spin weight of $s = 0, \pm 1, \pm 2$ respectively). The angular Teukolsky equation is solved with an accompanying julia package [SpinWeightedSpheroidalHarmonics.jl](https://github.com/ricokaloklo/SpinWeightedSpheroidalHarmonics.jl) using a spectral decomposition method. The paper describing both the GSN formalism and the implementation can be found in [2306.16469](https://arxiv.org/abs/2306.16469). A set of Mathematica notebooks deriving all the equations used in the code can be found in [10.5281/zenodo.8080241](https://zenodo.org/records/8080242). ## Installation To install the package using the Julia package manager, simply type the following in the Julia REPL: ```julia using Pkg Pkg.add("GeneralizedSasakiNakamura") ``` *Note: There is no need to install [SpinWeightedSpheroidalHarmonics.jl](https://github.com/ricokaloklo/SpinWeightedSpheroidalHarmonics.jl) separately as it should be automatically installed by the package manager.* ## Highlights ### Performant frequency-domain Teukolsky solver Works well at *both low and high frequencies*, and takes only a few tens of milliseconds on average: <table> <tr> <th>GeneralizedSasakiNakamura.jl</th> <th><a href="https://github.com/BlackHolePerturbationToolkit/Teukolsky">Teukolsky</a> Mathematica package using the MST method </th> </tr> <tr> <td><p align="center"><img width="100%" src="https://github-production-user-asset-6210df.s3.amazonaws.com/55488840/248965077-7d216deb-5bae-433f-a699-d40a35f0e35d.gif"></p></td> <td><p align="center"><img width="100%" src="https://github-production-user-asset-6210df.s3.amazonaws.com/55488840/248966033-9e7d8027-81ee-4762-98d9-0ad0a1c030ad.gif"></p></td> </tr> </table> *(There was no caching! We solved the equation on-the-fly! The notebook generating this animation can be found [here](https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl/blob/main/examples/realtime-demo.ipynb))* Static/zero-frequency solutions are solved analytically with Gauss hypergeometric functions. ### Solutions that are accurate everywhere Numerical solutions are *smoothly stitched* to analytical ansatzes near the horizon and infinity at user-specified locations `rsin` and `rsout` respectively: <p align="center"> <img width="50%" src="https://github-production-user-asset-6210df.s3.amazonaws.com/55488840/248724944-9707332b-1238-4b3b-b1c0-ac426a1b3dc6.gif"> </p> ### Easy to use The following code snippet lets you solve the (source-free) Teukolsky function (in frequency domain) for the mode $s=-2, \ell=2, m=2, a=0.7, \omega=0.5$ that satisfies the purely-ingoing boundary condition at the horizon: ```julia using GeneralizedSasakiNakamura # This is going to take some time to pre-compile, mostly due to DifferentialEquations.jl # Specify which mode and what boundary condition s=-2; l=2; m=2; a=0.7; omega=0.5; bc=IN; # Specify where to match to ansatzes rsin=-20; rsout=250; # NOTE: julia uses 'just-ahead-of-time' compilation. Calling this the first time in each session will take some time R = Teukolsky_radial(s, l, m, a, omega, bc, rsin, rsout) ``` That's it! If you run this on Julia REPL, it should give you something like this ``` TeukolskyRadialFunction( mode=Mode(s=-2, l=2, m=2, a=0.7, omega=0.5, lambda=1.6966094016353415), boundary_condition=IN, transmission_amplitude=1.0 + 0.0im, incidence_amplitude=6.536587661197995 - 4.941203897068852im, reflection_amplitude=-0.128246619129379 - 0.44048133496664404im, normalization_convention=UNIT_TEUKOLSKY_TRANS ) ``` For example, if we want to evaluate the Teukolsky function at the location $r = 10M$, simply do ```julia R(10) ``` This should give ``` 77.57508416832009 - 429.40290952257226im ``` ## How to cite If you have used this code in your research that leads to a publication, please cite the following article: ``` @article{Lo:2023fvv, author = "Lo, Rico K. L.", title = "{Recipes for computing radiation from a Kerr black hole using Generalized Sasaki-Nakamura formalism: I. Homogeneous solutions}", eprint = "2306.16469", archivePrefix = "arXiv", primaryClass = "gr-qc", month = "6", year = "2023" } ``` ## License The package is licensed under the MIT License.
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
docs
4951
# APIs There are 4 functions that are exported, namely - [`Teukolsky_radial`](@ref) - [`GSN_radial`](@ref) - [`rstar_from_r`](@ref) - [`r_from_rstar`](@ref) and there are 5 custom types that are exported, i.e. - [BoundaryCondition](@ref) - [NormalizationConvention](@ref) - [Mode](@ref) - [GSNRadialFunction](@ref) - [TeukolskyRadialFunction](@ref) Currently, only the exported functions and types are documented below. Documentations for private (i.e. unexported) functions will be added at a later stage. ## Functions ```@docs Teukolsky_radial ``` ```@docs GSN_radial ``` ```@docs rstar_from_r ``` ```@docs r_from_rstar ``` ## Types #### BoundaryCondition This is an enum type that can take either one of the four values | value | | | :--- | :--- | | `IN` | purely ingoing at the horizon | | `UP` | purely outgoing at infinity | | `OUT` | purely outgoing at the horizon | | `DOWN`| purely ingoing at infinity | #### NormalizationConvention This is an enum type that can take either one of the two values | value | | | :--- | :--- | | `UNIT_GSN_TRANS` | normalized to have a unit transmission amplitude for the GSN function | | `UNIT_TEUKOLSKY_TRANS` | normalized to have a unit transmission amplitude for the Teukolsky function | #### Mode This is a composite struct type that stores information about a mode | field | | | :--- | :--- | | `s` | spin weight $s$ | | `l` | harmonic index $\ell$ | | `m` | azimuthal index $m$ | | `a` | Kerr spin parameter $a/M$ | | `omega` | frequency $M\omega$ | | `lambda` | spin-weighted spheroidal eigenvalue $\lambda$ | #### GSNRadialFunction This is a composite struct type that stores the output from [`GSN_radial`](@ref) !!! tip `GSNRadialFunction(rstar)` is equivalent to `GSNRadialFunction.GSN_solution(rstar)[1]`, returning only the value of the GSN function evaluated at the *tortoise coordinate* `rstar` | field | | | :--- | :--- | | `mode` | a [Mode](@ref) object storing information about the mode | | `boundary_condition` | a [BoundaryCondition](@ref) object storing which boundary condition this function satisfies | | `rsin` | numerical inner boundary $r_{*}^{\mathrm{in}}/M$ where the GSN equation is numerically evolved ($r_{*}$ is a tortoise coordinate) | | `rsout` | numerical outer boundary $r_{*}^{\mathrm{out}}/M$ where the GSN equation is numerically evolved ($r_{*}$ is a tortoise coordinate) | | `horizon_expansion_order` | order of the asymptotic expansion at the horizon | | `infinity_expansion_order` | order of the asymptotic expansion at infinity | | `transmission_amplitude` | transmission amplitude in the GSN formalism of this function | | `incidence_amplitude` | incidence amplitude in the GSN formalism of this function | | `reflection_amplitude` | reflection amplitude in the GSN formalism of this function | | `numerical_GSN_solution` | numerical solution ([`ODESolution`](https://docs.sciml.ai/DiffEqDocs/stable/types/ode_types/#SciMLBase.ODESolution) object from `DifferentialEquations.jl`) to the GSN equation in [`rsin`, `rsout`] if applicable; output is a vector $[ \hat{X}(r_{*}), d\hat{X}(r_{*})/dr_{*} ]$ | | `numerical_Riccati_solution` | numerical solution ([`ODESolution`](https://docs.sciml.ai/DiffEqDocs/stable/types/ode_types/#SciMLBase.ODESolution) object from `DifferentialEquations.jl`) to the GSN equation in the Riccati form if applicable; output is a vector $[ \hat{\Phi}(r_{*}), d\hat{\Phi}(r_{*})/dr_{*} ]$ | | `GSN_solution` | full GSN solution where asymptotic solutions are smoothly attached; output is a vector $[ \hat{X}(r_{*}), d\hat{X}(r_{*})/dr_{*} ]$ | | `normalization_convention` | a [NormalizationConvention](@ref) object storing which normalization convention this function adheres to | #### TeukolskyRadialFunction This is a composite struct type that stores the output from [`Teukolsky_radial`](@ref) !!! tip `TeukolskyRadialFunction(r)` is equivalent to `TeukolskyRadialFunction.Teukolsky_solution(r)[1]`, returning only the value of the Teukolsky function evaluated at the *Boyer-Lindquist coordinate* `r` | field | | | :--- | :--- | | `mode` | a [Mode](@ref) object storing information about the mode | | `boundary_condition` | a [BoundaryCondition](@ref) object storing which boundary condition this function satisfies | | `transmission_amplitude` | transmission amplitude in the Teukolsky formalism of this function | | `incidence_amplitude` | incidence amplitude in the Teukolsky formalism of this function | | `reflection_amplitude` | reflection amplitude in the Teukolsky formalism of this function | | `GSN_solution` | a [GSNRadialFunction](@ref) object storing the corresponding GSN function | `Teukolsky_solution` | Teukolsky solution where asymptotic solutions are smoothly attached; output is a vector $[ \hat{R}(r), d\hat{R}(r)/dr ]$ | | `normalization_convention` | a [NormalizationConvention](@ref) object storing which normalization convention this function adheres to |
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
docs
5964
# Examples ```@contents Pages = ["examples.md"] ``` ## Example 1: Solving and visualizing some Teukolsky and GSN functions In this example, we solve for the Teukolsky and the GSN function with $s = -2, \ell = 2, m = 2, a = 0.7, \omega = 0.25$ that satisfy the purely outgoing condition at infinity (i.e. `UP`). ```julia using GeneralizedSasakiNakamura using Plots, LaTeXStrings # Specify which mode and what boundary condition s=-2; l=2; m=2; a=0.7; omega=0.25; bc=UP; # Change to bc=IN to solve for R^in or X^in instead # Specify where to match to ansatzes rsin=-20; rsout=250; # NOTE: julia uses 'just-ahead-of-time' compilation. Calling this the first time in each session will take some time R = Teukolsky_radial(s, l, m, a, omega, bc, rsin, rsout); # Set up a grid of the tortoise coordinate rs rsgrid = collect(-30:1:300); # Does not have to be within [rsin, rsout] # Set up a grid of the Boyer-Lindquist r coordinate # Convert from rsgrid using r_from_rstar(a, rs) rgrid = [r_from_rstar(a, rs) for rs in rsgrid]; ``` ```julia # Visualize the Teukolsky function # Use the 'shortcut' interface to access the function plot(rgrid, [real(R(r)) for r in rgrid], label="real") # Use the full interface to access the function (and its derivative) plot!(rgrid, [imag(R.Teukolsky_solution(r)[1]) for r in rgrid], label="imag") plot!( legendfontsize=14, xguidefontsize=14, yguidefontsize=14, xtickfontsize=14, ytickfontsize=14, foreground_color_legend=nothing, background_color_legend=nothing, legend=:topleft, xlabel=L"r/M", ylabel=L"R(r)", ) title!("$(R.boundary_condition) solution") ``` ![R.png](R.png) ```julia # Visualize the underlying GSN function # Use the 'shortcut' interface to access the function plot(rsgrid, [real(R.GSN_solution(rs)) for rs in rsgrid], label="real") # Use the full interface to access the function (and its derivative) plot!(rsgrid, [imag(R.GSN_solution.GSN_solution(rs)[1]) for rs in rsgrid], label="imag") plot!( legendfontsize=14, xguidefontsize=14, yguidefontsize=14, xtickfontsize=14, ytickfontsize=14, foreground_color_legend=nothing, background_color_legend=nothing, legend=:bottomright, xlabel=L"r_{*}/M", ylabel=L"X(r_{*})", ) title!("$(R.boundary_condition) solution") ``` ![X.png](X.png) ```julia # Visualize the underlying complex frequency function # NOTE: for this one, rstar has to be within [rsin, rsout] plot(collect(rsin:0.1:rsout), [real(R.GSN_solution.numerical_Riccati_solution(rs)[2]) for rs in rsin:0.1:rsout], label="real") # Use the full interface to access the function (and its derivative) plot!(collect(rsin:0.1:rsout), [imag(R.GSN_solution.numerical_Riccati_solution(rs)[2]) for rs in rsin:0.1:rsout], label="imag") plot!( legendfontsize=14, xguidefontsize=14, yguidefontsize=14, xtickfontsize=14, ytickfontsize=14, foreground_color_legend=nothing, background_color_legend=nothing, legend=:bottomright, xlabel=L"r_{*}/M", ylabel=L"d\Phi(r_{*})/dr_{*}", ) title!("$(R.boundary_condition) solution") ``` ![dPhidrs.png](dPhidrs.png) ## Example 2: Plotting reflectivity of black holes (in GSN formalism) ```julia using GeneralizedSasakiNakamura using Plots, LaTeXStrings sarr = [-2, -1, 0, 1, 2]; l=2;m=2;a=0.0; reflectivity_from_inf_nonrotating = Dict() omegas = collect(0.01:0.01:2.0); for s in sarr reflectivity_from_inf_nonrotating[s] = [] for omg in omegas Xin = GSN_radial(s, l, m, a, omg, IN, -20, 250) append!(reflectivity_from_inf_nonrotating[s], Xin.reflection_amplitude/Xin.incidence_amplitude) end end ``` ```julia plot(omegas, abs.(reflectivity_from_inf_nonrotating[-2]), linewidth=2, color=theme_palette(:auto)[1], label=L"s = \pm 2") plot!(omegas, abs.(reflectivity_from_inf_nonrotating[-1]), linewidth=2, color=theme_palette(:auto)[2], label=L"s = \pm 1") plot!(omegas, abs.(reflectivity_from_inf_nonrotating[0]), linewidth=2, color=theme_palette(:auto)[3], label=L"s = 0") plot!( legendfontsize=14, xguidefontsize=14, yguidefontsize=14, xtickfontsize=14, ytickfontsize=14, foreground_color_legend=nothing, background_color_legend=nothing, legend=:bottomright, formatter=:latex, xlabel=L"M\omega", ylabel=L"| \hat{B}^{\mathrm{ref}}_{\mathrm{SN}}/\hat{B}^{\mathrm{inc}}_{\mathrm{SN}} |", left_margin = 2Plots.mm, right_margin = 3Plots.mm, ) title!(L"a/M = 0") ``` ![reflectivity-aOverM_0.png](reflectivity-aOverM_0.png) ```julia sarr = [-2, -1, 0, 1, 2]; l=2;m=2;a=0.7; reflectivity_from_inf_rotating = Dict() omegas = collect(0.01:0.01:2.0); for s in sarr reflectivity_from_inf_rotating[s] = [] for omg in omegas Xin = GSN_radial(s, l, m, a, omg, IN, -20, 250) append!(reflectivity_from_inf_rotating[s], Xin.reflection_amplitude/Xin.incidence_amplitude) end end ``` ```julia plot(omegas, abs.(reflectivity_from_inf_rotating[-2]), linewidth=2, color=theme_palette(:auto)[1], label=L"s = -2") plot!(omegas, abs.(reflectivity_from_inf_rotating[-1]), linewidth=2, color=theme_palette(:auto)[2], label=L"s = -1") plot!(omegas, abs.(reflectivity_from_inf_rotating[0]), linewidth=2, color=theme_palette(:auto)[3], label=L"s = 0") plot!(omegas, abs.(reflectivity_from_inf_rotating[1]), linewidth=2, color=theme_palette(:auto)[4], label=L"s = 1") plot!(omegas, abs.(reflectivity_from_inf_rotating[2]), linewidth=2, color=theme_palette(:auto)[5], label=L"s = 2") plot!( legendfontsize=14, xguidefontsize=14, yguidefontsize=14, xtickfontsize=14, ytickfontsize=14, foreground_color_legend=nothing, background_color_legend=nothing, legend=:bottomright, formatter=:latex, xlabel=L"M\omega", ylabel=L"| \hat{B}^{\mathrm{ref}}_{\mathrm{SN}}/\hat{B}^{\mathrm{inc}}_{\mathrm{SN}} |", left_margin = 2Plots.mm, right_margin = 3Plots.mm, ) title!(L"a/M = 0.7") ``` ![reflectivity-aOverM_0p7.png](reflectivity-aOverM_0p7.png)
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.4.2
f00e7a1d7777e3697be7d567a00b31d6ff700034
docs
3825
# Home GeneralizedSasakiNakamura.jl computes solutions to the frequency-domain radial Teukolsky equation with the Generalized Sasaki-Nakamura (GSN) formalism. The code is capable of handling *both in-going and out-going* radiation of scalar, electromagnetic, and gravitational type (corresponding to spin weight of $s = 0, \pm 1, \pm 2$ respectively). The angular Teukolsky equation is solved with an accompanying julia package [SpinWeightedSpheroidalHarmonics.jl](https://github.com/ricokaloklo/SpinWeightedSpheroidalHarmonics.jl) using a spectral decomposition method. ## Installation To install the package using the Julia package manager, simply type the following in the Julia REPL: ```julia using Pkg Pkg.add("GeneralizedSasakiNakamura") ``` *Note: There is no need to install [SpinWeightedSpheroidalHarmonics.jl](https://github.com/ricokaloklo/SpinWeightedSpheroidalHarmonics.jl) separately as it should be automatically installed by the package manager.* ## Highlights ### Performant frequency-domain Teukolsky solver Works well at *both low and high frequencies*, and takes only a few tens of milliseconds on average: ```@raw html <table> <tr> <th>GeneralizedSasakiNakamura.jl</th> <th><a href="https://github.com/BlackHolePerturbationToolkit/Teukolsky">Teukolsky</a> Mathematica package using the MST method </th> </tr> <tr> <td><p align="center"><img width="100%" src="https://github-production-user-asset-6210df.s3.amazonaws.com/55488840/248965077-7d216deb-5bae-433f-a699-d40a35f0e35d.gif"></p></td> <td><p align="center"><img width="100%" src="https://github-production-user-asset-6210df.s3.amazonaws.com/55488840/248966033-9e7d8027-81ee-4762-98d9-0ad0a1c030ad.gif"></p></td> </tr> </table> ``` *(There was no caching! We solved the equation on-the-fly! The notebook generating this animation can be found [here](https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl/blob/main/examples/realtime-demo.ipynb))* Static/zero-frequency solutions are solved analytically with Gauss hypergeometric functions. ### Solutions that are accurate everywhere Numerical solutions are *smoothly stitched* to analytical ansatzes near the horizon and infinity at user-specified locations `rsin` and `rsout` respectively: ```@raw html <p align="center"> <img width="50%" src="https://github-production-user-asset-6210df.s3.amazonaws.com/55488840/248724944-9707332b-1238-4b3b-b1c0-ac426a1b3dc6.gif"> </p> ``` ### Easy to use The following code snippet lets you solve the (source-free) Teukolsky function (in frequency domain) for the mode $s=-2, \ell=2, m=2, a=0.7, \omega=0.5$ that satisfies the purely-ingoing boundary condition at the horizon: ```julia using GeneralizedSasakiNakamura # This is going to take some time to pre-compile, mostly due to DifferentialEquations.jl # Specify which mode and what boundary condition s=-2; l=2; m=2; a=0.7; omega=0.5; bc=IN; # Specify where to match to ansatzes rsin=-20; rsout=250; # NOTE: julia uses 'just-ahead-of-time' compilation. Calling this the first time in each session will take some time R = Teukolsky_radial(s, l, m, a, omega, bc, rsin, rsout) ``` That's it! If you run this on Julia REPL, it should give you something like this ``` TeukolskyRadialFunction( mode=Mode(s=-2, l=2, m=2, a=0.7, omega=0.5, lambda=1.6966094016353415), boundary_condition=IN, transmission_amplitude=1.0 + 0.0im, incidence_amplitude=6.536587661197995 - 4.941203897068852im, reflection_amplitude=-0.128246619129379 - 0.44048133496664404im, normalization_convention=UNIT_TEUKOLSKY_TRANS ) ``` For example, if we want to evaluate the Teukolsky function at the location $r = 10M$, simply do ```julia R(10) ``` This should give ``` 77.57508416832009 - 429.40290952257226im ``` ## License The package is licensed under the MIT License.
GeneralizedSasakiNakamura
https://github.com/ricokaloklo/GeneralizedSasakiNakamura.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
4456
# NONLEPUS CONTROL #integrator = DiscretizeRelax(prob, DynamicBoundspODEsDiscrete.LohnerContractor{4}(), h = 0.01, skip_step2 = false, relax = use_relax) #integrator = DiscretizeRelax(prob, DynamicBoundspODEsDiscrete.LohnerContractor{4}(), h = 0.025, skip_step2 = false, relax = use_relax) # LEPUS CONTROL #integrator = DiscretizeRelax(prob, DynamicBoundspODEsDiscrete.LohnerContractor{6}(), h = 0.02, # repeat_limit = 1, skip_step2 = false, step_limit = 5, relax = use_relax) # TODO: need to adjust coefficient from hoe test... #using Revise using IntervalArithmetic, TaylorSeries setrounding(Interval, :none) import Base: literal_pow, ^ import IntervalArithmetic.pow function ^(x::Interval{Float64}, n::Integer) # fast integer power if n < 0 return 1/IntervalArithmetic.pow(x, -n) end isempty(x) && return x if iseven(n) && 0 ∈ x return IntervalArithmetic.hull(zero(x), hull(Base.power_by_squaring(Interval(mig(x)), n), Base.power_by_squaring(Interval(mag(x)), n)) ) else return IntervalArithmetic.hull( Base.power_by_squaring(Interval(x.lo), n), Base.power_by_squaring(Interval(x.hi), n) ) end end using DynamicBoundsBase, Plots, DifferentialEquations#, Cthulhu using DynamicBoundspODEsDiscrete, BenchmarkTools println(" ") println(" ------------------------------------------------------------ ") println(" ------------- PACKAGE EXAMPLE ------------------------ ") println(" ------------------------------------------------------------ ") use_relax = false lohners_type = 2 prob_num = 1 ticks = 50.0 steps = 50.0 tend = 0.02*steps/ticks # lo 7.6100 if prob_num == 1 x0(p) = [9.0] function f!(dx, x, p, t) dx[1] = p[1] - x[1]^2 #x[1]*x[1] nothing end tspan = (0.0, tend) pL = [-1.0] pU = [1.0] elseif prob_num == 2 x0(p) = [1.2; 1.1] function f!(dx, x, p, t) dx[1] = p[1]*x[1]*(one(typeof(p[1])) - x[2]) dx[2] = p[1]*x[2]*(x[1] - one(typeof(p[1]))) nothing end tspan = (0.0, tend) pL = [2.95] pU = [3.05] end prob = DynamicBoundsBase.ODERelaxProb(f!, tspan, x0, pL, pU) tol = 1E-5 if lohners_type == 1 integrator = DiscretizeRelax(prob, DynamicBoundspODEsDiscrete.LohnerContractor{5}(), h = 1/ticks, repeat_limit = 1, skip_step2 = false, step_limit = steps, relax = use_relax, tol= tol) elseif lohners_type == 2 integrator = DiscretizeRelax(prob, DynamicBoundspODEsDiscrete.HermiteObreschkoff(3, 3), h = 1/ticks, repeat_limit = 1, skip_step2 = false, step_limit = steps, relax = use_relax, tol= tol) elseif lohners_type == 3 function iJx!(dx, x, p, t) dx[1] = -2.0*x[1] nothing end function iJp!(dx, x, p, t) dx[1] = one(p[1]) nothing end integrator = DiscretizeRelax(prob, DynamicBoundspODEsDiscrete.AdamsMoulton(2), h = 1/ticks, repeat_limit = 1, step_limit = steps, skip_step2 = false, relax = false, Jx! = iJx!, Jp! = iJp!, tol= tol) end ratio = rand(1) pstar = pL.*ratio .+ pU.*(1.0 .- ratio) setall!(integrator, ParameterValue(), [0.0]) DynamicBoundsBase.relax!(integrator) integrate!(integrator) t_vec = integrator.time if !use_relax lo_vec = getfield.(getindex.(integrator.storage[:],1), :lo) hi_vec = getfield.(getindex.(integrator.storage[:],1), :hi) else lo_vec = getfield.(getfield.(getindex.(integrator.storage[:],1), :Intv), :lo) hi_vec = getfield.(getfield.(getindex.(integrator.storage[:],1), :Intv), :hi) end plt = plot(t_vec , lo_vec, label="Interval Bounds 0.0", marker = (:hexagon, 2, 0.6, :green), linealpha = 0.0, legend=:bottomleft) plot!(plt, t_vec , hi_vec, label="", linealpha = 0.0, marker = (:hexagon, 2, 0.6, :green)) prob = ODEProblem(f!, [9.0], tspan, [-1.0]) sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8) plot!(plt, sol.t , sol[1,:], label="", linecolor = :red, linestyle = :solid, lw=1.5) prob = ODEProblem(f!, [9.0], tspan,[1.0]) sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8) plot!(plt, sol.t , sol[1,:], label="", linecolor = :red, linestyle = :solid, lw=1.5) ylabel!("x[1] (M)") xlabel!("Time (seconds)") display(plt)
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
5307
using Revise using DynamicBoundspODEsPILMS, LinearAlgebra, IntervalArithmetic, StaticArrays, TaylorSeries, TaylorIntegration, ForwardDiff, McCormick, BenchmarkTools, DocStringExtensions using DiffResults: JacobianResult, MutableDiffResult using ForwardDiff: Partials, JacobianConfig, vector_mode_dual_eval, value, vector_mode_jacobian! import Base.copyto! function f!(dx,x,p,t) dx[1] = x[1]^2 + p[2] dx[2] = x[2] + p[1]^2 nothing end np = 2 nx = 2 k = 3 x = [0.1; 1.0] p = [0.2; 0.1] jtf! = DynamicBoundspODEsPILMS.JacTaylorFunctor!(f!, nx, np, k, Interval{Float64}(0.0), 0.0) xIntv = Interval{Float64}.(x) pIntv = Interval{Float64}.(p) yIntv = [xIntv; pIntv] DynamicBoundspODEsPILMS.jacobian_taylor_coeffs!(jtf!, yIntv) jac = JacobianResult(jtf!.out, yIntv).derivs[1] tjac = zeros(Interval{Float64}, 4, 8) Jx = Matrix{Interval{Float64}}[zeros(Interval{Float64},2,2) for i in 1:4] Jp = Matrix{Interval{Float64}}[zeros(Interval{Float64},2,2) for i in 1:4] DynamicBoundspODEsPILMS.extract_JxJp!(Jx, Jp, jtf!.result, tjac, nx, np, k) itf! = DynamicBoundspODEsPILMS.TaylorFunctor!(f!, nx, np, k, zero(Interval{Float64}), zero(Float64)) outIntv = zeros(Interval{Float64},8) itf!(outIntv, yIntv) y = [x; p] rtf! = DynamicBoundspODEsPILMS.TaylorFunctor!(f!, nx, np, k, zero(Float64), zero(Float64)) out = zeros(8) rtf!(out, y) coeff_out = zeros(Interval{Float64},2,4) DynamicBoundspODEsPILMS.coeff_to_matrix!(coeff_out, jtf!.out, nx, k) #= hⱼ = 0.001 hmin = 0.00001 function euf!(out, x, p, t) out[1,1] = -x[1] nothing end eufY = [Interval{Float64}(0.5,1.5); Interval(0.0)] itf_exist_unique! = DynamicBoundspODEsPILMS.TaylorFunctor!(euf!, 1, 1, k, zero(Interval{Float64}), zero(Float64)) jtf_exist_unique! = DynamicBoundspODEsPILMS.JacTaylorFunctor!(euf!, 1, 1, k, Interval{Float64}(0.0), 0.0) DynamicBoundspODEsPILMS.jacobian_taylor_coeffs!(jtf_exist_unique!, eufY) coeff_out = zeros(Interval{Float64},1,k) DynamicBoundspODEsPILMS.coeff_to_matrix!(coeff_out, jtf!.out, 1, k) Jx = Matrix{Interval{Float64}}[zeros(Interval{Float64},1,1) for i in 1:4] Jp = Matrix{Interval{Float64}}[zeros(Interval{Float64},1,1) for i in 1:4] tjac = zeros(Interval{Float64}, 2, 4) outIntv_exist_unique! = zeros(Interval{Float64},4) itf_exist_unique!(outIntv_exist_unique!, eufY) coeff_out_exist_unique! = zeros(Interval{Float64},1,k+1) DynamicBoundspODEsPILMS.coeff_to_matrix!(coeff_out_exist_unique!, outIntv_exist_unique!, 1, k) DynamicBoundspODEsPILMS.extract_JxJp!(Jx, Jp, jtf_exist_unique!.result, tjac, 1, 1, k) unique_result = DynamicBoundspODEsPILMS.UniquenessResult(1,1) DynamicBoundspODEsPILMS.existence_uniqueness!(unique_result, itf_exist_unique!, eufY, hⱼ, hmin, coeff_out_exist_unique!, Jx, Jp) bool1 = unique_result.step == 0.001 bool2 = unique_result.confirmed bool3a = isapprox(unique_result.Ỹⱼ[1].lo, -1.50001E-6, atol=1E-10) bool3b = isapprox(unique_result.Ỹⱼ[1].hi, 0.00150001, atol=1E-6) bool4 = isapprox(unique_result.f̃k[1].lo, -7.50001E-16, atol = 1E-19) bool5 = isapprox(unique_result.f̃k[1].hi, 7.50001E-13, atol = 1E-16) =# function fplohn!(out, x, p, t) out[1] = x[1] out[2] = -x[2] nothing end np = 1 nx = 2 k = 3 lf! = DynamicBoundspODEsPILMS.LohnersFunctor!(fplohn!, nx, np, k, zero(Interval{Float64}), zero(Float64)) hⱼ = 0.001 Ỹⱼ = [Interval(0.1, 5.1); Interval(0.1, 8.9); Interval(0.1, 8.9)] Yⱼ = [Interval(0.1, 5.1); Interval(0.1, 8.9); Interval(0.1, 8.9)] A = DynamicBoundspODEsPILMS.qr_stack(nx, 2) yⱼ = mid.(Yⱼ) Δⱼ = Yⱼ[1:2] - yⱼ[1:2] lf!(hⱼ, Ỹⱼ, Yⱼ, A, yⱼ, Δⱼ) #= jetcoeffs!(zqwa, zqwb, zqwc, zqwd, zqwe, zqwr, p) y = Interval{Float64}.([x; p]) out = g.out cfg = ForwardDiff.JacobianConfig(nothing, out, y) # extact is good... actual jacobians look odd... #tv, xv = validated_integration(f!, Interval{Float64}.([3.0, 3.0]), 0.0, 0.3, 4, 1.0e-20, maxsteps=100 ) Q = [Yⱼ; P] #@btime jacobianfunctor($outIntv, $yInterval) d = g zqwa = d.g! zqwb = d.t zqwc = d.xtaylor zqwd = d.xout zqwe = d.xaux zqwr = d.taux #@btime jetcoeffs!($zqwa, $zqwb, $zqwc, $zqwd, $zqwe, $zqwr, $s, $p) #@code_warntype jetcoeffs!(zqwa, zqwb, zqwc, zqwd, zqwe, zqwr, p) Jx = Matrix{Interval{Float64}}[zeros(Interval{Float64},2,2) for i in 1:4] Jp = Matrix{Interval{Float64}}[zeros(Interval{Float64},2,2) for i in 1:4] Jxsto = zeros(Interval{Float64},2,2) Jpsto = zeros(Interval{Float64},2,2) Yⱼ = [Interval{Float64}(-10.0, 20.0); Interval{Float64}(-10.0, 20.0)] P = [Interval{Float64}(2.0, 3.0); Interval{Float64}(2.0, 3.0)] Ycat = [Yⱼ; P] yⱼ = mid.(Yⱼ) Δⱼ = Yⱼ - yⱼ At = zeros(2,2) + I #Aⱼ = DynamicBoundspODEsPILMS.QRDenseStorage(nx) #Aⱼ₊₁ = DynamicBoundspODEsPILMS.QRDenseStorage(nx) A = DynamicBoundspODEsPILMS.QRStack(nx, 2) dtf = g hⱼ = 0.001 yjcat = vcat(yⱼ,p) # TODO: Remember rP is computed outside iteration and stored to JacTaylorFunctor plohners = DynamicBoundspODEsPILMS.parametric_lohners!(itf!, rtf!, dtf, hⱼ, Ycat, Ycat, A, yjcat, Δⱼ) @btime DynamicBoundspODEsPILMS.parametric_lohners!($itf!, $rtf!, $dtf, $hⱼ, $Ycat, $Ycat, $A, $yjcat, $Δⱼ) =#
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
6574
# Copyright(c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DynamicBoundspODEsDiscrete.jl # Defines main module. ############################################################################# module DynamicBoundspODEsDiscrete using McCormick, DocStringExtensions, DynamicBoundsBase, Reexport, LinearAlgebra, StaticArrays, ElasticArrays, Polynomials, UnPack using ForwardDiff: Chunk, Dual, Partials, construct_seeds, single_seed, JacobianConfig, vector_mode_dual_eval!, value, vector_mode_jacobian!, jacobian! using DiffEqSensitivity: extract_local_sensitivities, ODEForwardSensitivityProblem using DiffEqBase: remake, AbstractODEProblem, AbstractContinuousCallback, solve using Sundials using OrdinaryDiffEq: ABDF2, Trapezoid, ImplicitEuler using DiffResults: JacobianResult, MutableDiffResult import DynamicBoundsBase: relax!, set!, setall!, get, getall!, getall, relax!, integrate!, supports import Base: setindex!, getindex, copyto!, literal_pow, copy import Base.MathConstants.golden export DiscretizeRelax, AdamsMoulton, BDF, LohnerContractor, HermiteObreschkoff export StepParams, StepResult, ExistStorage, ContractorStorage, reinitialize!, existence_uniqueness!, improvement_condition, single_step!, set_xX!, state_contractor_steps, state_contractor_γ, state_contractor_k, excess_error, set_Δ!, compute_X0!, set_P!, contains, calc_alpha, mul_split!, μ!, ρ! const DBB = DynamicBoundsBase abstract type AbstractStateContractor end """ AbstractStateContractorName The subtypes of `AbstractStateContractorName` are used to specify the manner of contractor method to be used by `DiscretizeRelax` in the discretize and relax scheme. """ abstract type AbstractStateContractorName end """ state_contractor_k(d::AbstractStateContractorName) Retrieves the order of the existence test to be used with """ function state_contractor_k(d::AbstractStateContractorName) error("No method with AbstractStateContractorName $d defined.") end """ state_contractor_γ(d::AbstractStateContractorName) """ function state_contractor_γ(d::AbstractStateContractorName) error("No method with AbstractStateContractorName $d defined.") end """ state_contractor_steps(d::AbstractStateContractorName) """ function state_contractor_steps(d::AbstractStateContractorName) error("No method with AbstractStateContractorName $d defined.") end """ state_contractor_integrator(d::AbstractStateContractorName) """ function state_contractor_integrator(d::AbstractStateContractorName) error("No method with AbstractStateContractorName $d defined.") end """ μ!(xⱼ,x̂ⱼ,η) Used to compute the arguments of Jacobians (`x̂ⱼ + η(xⱼ - x̂ⱼ)`) used by the parametric Mean Value Theorem. The result is stored to `out`. """ function μ!(z, xⱼ::Vector{Interval{Float64}}, x̂ⱼ::Vector{Float64}, η::Interval{Float64}) @. z = xⱼ end function μ!(z, xⱼ::Vector{MC{N,T}}, x̂ⱼ::Vector{Float64}, η::Interval{Float64}) where {N, T<:RelaxTag} @. z = x̂ⱼ + η*(xⱼ - x̂ⱼ) end """ ρ!(out,p,p̂ⱼ,η) Used to compute the arguments of Jacobians (`p̂ⱼ + η(p - p̂ⱼ)`) used by the parametric Mean Value Theorem. The result is stored to `out`. """ function ρ!(z, p::Vector{Interval{Float64}}, p̂::Vector{Float64}, η::Interval{Float64}) @. z = p end function ρ!(z, p::Vector{MC{N,T}}, p̂::Vector{Float64}, η::Interval{Float64}) where {N, T<:RelaxTag} @. z = p̂ + η*(p - p̂) end include("StaticTaylorSeries/StaticTaylorSeries.jl") using .StaticTaylorSeries include("DiscretizeRelax/utilities/fixed_buffer.jl") include("DiscretizeRelax/utilities/mul_split.jl") include("DiscretizeRelax/utilities/fast_set_index.jl") include("DiscretizeRelax/utilities/qr_utilities.jl") include("DiscretizeRelax/utilities/coeff_calcs.jl") include("DiscretizeRelax/utilities/taylor_functor.jl") include("DiscretizeRelax/utilities/jacobian_functor.jl") include("DiscretizeRelax/utilities/single_step.jl") print_iteration(x) = x > 98 function contract_constant_state!(x::Vector{Interval{Float64}}, t::ConstantStateBounds) for i in 1:length(t.xL) xL = x[i].lo xU = x[i].hi xLc = t.xL[i] xUc = t.xU[i] if xL < xLc x[i] = Interval(xLc, xU) elseif xU > xUc x[i] = Interval(xL, xUc) elseif (xL < xLc) && (xU > xUc) x[i] = Interval(xLc, xUc) end end return end function contract_constant_state!(x::Vector{MC{N,T}}, t::ConstantStateBounds) where {N,T} for i in 1:length(t.xL) xmc = x[i] xL = xmc.Intv.lo xU = xmc.Intv.hi xLc = t.xL[i] xUc = t.xU[i] if xL < xLc x[i] = x[i] ∩ Interval(xLc, Inf) elseif xU > xUc x[i] = x[i] ∩ Interval(-Inf, xUc) elseif (xL < xLc) && (xU > xUc) x[i] = MC{N,T}(Interval(xLc, xUc)) end end return end function subgradient_expansion_interval_contract!(out::Vector{MC{N,T}}, p, pL, pU) where {N,T} for i = 1:length(out) x = out[i] l = Interval(x.cv) u = Interval(x.cc) for j = 1:length(p) P = Interval(pL[j], pU[j]) l += x.cv_grad[j]*(P - p[j]) u += x.cc_grad[j]*(P - p[j]) end lower_x = max(x.Intv.lo, l.lo) # l.lo upper_x = min(x.Intv.hi, u.hi) # u.hi out[i] = MC{N,T}(x.cv, x.cc, Interval{Float64}(lower_x, upper_x), x.cv_grad, x.cc_grad, false) end nothing end subgradient_expansion_interval_contract!(out, p, pL, pU) = nothing include("DiscretizeRelax/method/higher_order_enclosure.jl") include("DiscretizeRelax/method/lohners_qr.jl") include("DiscretizeRelax/method/hermite_obreschkoff.jl") include("DiscretizeRelax/method/wilhelm_2019.jl") include("DiscretizeRelax/method/pilms.jl") include("DiscretizeRelax/utilities/discretize_relax.jl") include("DiscretizeRelax/utilities/relax.jl") include("DiscretizeRelax/utilities/access_functions.jl") end # module
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
15208
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/method/hermite_obreschkoff.jl # Defines functions needed to perform a hermite_obreshkoff iteration. ############################################################################# """ HermiteObreschkoff A structure that stores the cofficient of the (P,Q)-Hermite-Obreschkoff method. (Offset due to method being zero indexed and Julia begin one indexed). The constructor `HermiteObreschkoff(p::Val{P}, q::Val{Q}) where {P, Q}` or `HermiteObreschkoff(p::Int, q::Int)` are used for the (P,Q)-method. $(TYPEDFIELDS) """ struct HermiteObreschkoff <: AbstractStateContractorName "Cpq[i=1:p] index starting at i = 1 rather than 0" cpq::Vector{Float64} "Cqp[i=1:q] index starting at i = 1 rather than 0" cqp::Vector{Float64} "gamma for method" γ::Float64 "Explicit order Hermite-Obreschkoff" p::Int "Implicit order Hermite-Obreschkoff" q::Int "Total order Hermite-Obreschkoff" k::Int "Skips the contractor step of the Hermite Obreshkoff Contractor if set to `true`" skip_contractor::Bool end function HermiteObreschkoff(p::Val{P}, q::Val{Q}, skip_contractor::Bool = false) where {P, Q} temp_cpq = 1.0 temp_cqp = 1.0 cpq = zeros(P + 1) cqp = zeros(Q + 1) cpq[1] = temp_cpq cqp[1] = temp_cqp for i = 1:P temp_cpq *= (P - i + 1.0)/(P + Q - i + 1) cpq[i + 1] = temp_cpq end γ = 1.0 for i = 1:Q temp_cqp *= (Q - i + 1.0)/(Q + P - i + 1) cqp[i + 1] = temp_cqp γ *= -i/(P+i) end K = P + Q + 1 # K = P + 1 HermiteObreschkoff(cpq, cqp, γ, P, Q, K, skip_contractor) end HermiteObreschkoff(p::Int, q::Int, b::Bool = false) = HermiteObreschkoff(Val(p), Val(q), b) """ HermiteObreschkoffFunctor A functor used in computing bounds and relaxations via Hermite-Obreschkoff's method. The implementation of the parametric Hermite-Obreschkoff's method based on the non-parametric version given in (1). 1. [Nedialkov NS, and Jackson KR. "An interval Hermite-Obreschkoff method for computing rigorous bounds on the solution of an initial value problem for an ordinary differential equation." Reliable Computing 5.3 (1999): 289-310.](https://link.springer.com/article/10.1023/A:1009936607335) 2. [Nedialkov NS. "Computing rigorous bounds on the solution of an initial value problem for an ordinary differential equation." University of Toronto. 2000.](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.633.9654&rep=rep1&type=pdf) """ Base.@kwdef mutable struct HermiteObreschkoffFunctor{F <: Function, Pp, Pp1, Qp1, K, T <: Real, S <: Real, NY} <: AbstractStateContractor lohners_functor::LohnersFunctor{F,Pp,T,S,NY} hermite_obreschkoff::HermiteObreschkoff η::Interval{T} = Interval{T}(0.0,1.0) μX::Vector{S} ρP::Vector{S} gⱼ₊₁::Vector{S} nx::Int np::Int set_tf!_pred::TaylorFunctor!{F, K, T, S} real_tf!_pred::TaylorFunctor!{F, Pp1, T, T} Jf!_pred::JacTaylorFunctor!{F, Pp1, T, S, NY} Rⱼ₊₁::Vector{S} mRⱼ₊₁::Vector{T} f̃val_pred::Vector{Vector{T}} = Vector{T}[] f̃_pred::Vector{Vector{S}} = Vector{S}[] Vⱼ₊₁::Vector{Float64} X_predict::Vector{S} xval_predict::Vector{Float64} q_predict::Int real_tf!_correct::TaylorFunctor!{F, Qp1, T, T} Jf!_correct::JacTaylorFunctor!{F, Qp1, T, S, NY} xval_correct::Vector{T} f̃val_correct::Vector{Vector{T}} = Vector{T}[] sum_p::Vector{S} sum_q::Vector{S} Δⱼ₊₁::Vector{S} pred_Jxmat::Matrix{S} pred_Jxvec::Vector{S} pred_Jpvec::Vector{S} δⱼ₊₁::Vector{S} pre::Matrix{Float64} precond2::Matrix{Float64} correct_B::Matrix{S} correct_Bvec::Vector{S} correct_C::Matrix{S} Inx::UniformScaling{Bool} = I Uj::Vector{S} Jpdiff::Matrix{S} Cj::Matrix{S} C_temp::Matrix{S} Bj::Matrix{S} B_temp::Matrix{S} constant_state_bounds::Union{Nothing,DBB.ConstantStateBounds} end function set_constant_state_bounds!(d::HermiteObreschkoffFunctor, v) set_constant_state_bounds!(d.lohners_functor,v) d.constant_state_bounds = v nothing end function HermiteObreschkoffFunctor(f!::F, nx::Int, np::Int, p::Val{P}, q::Val{Q}, s::S, t::T, b) where {F,P,Q,S,T} P1 = P + 1 P2 = P + 2 Q1 = Q + 1 K = P + Q + 1 lon_func = LohnersFunctor(f!, nx, np, Val(P1), s, t) f̃val_pred = Vector{Float64}[] f̃_pred = Vector{S}[] f̃val_correct = Vector{Float64}[] for i = 1:(P + 1); push!(f̃val_pred, zeros(nx)); end for i = 1:(K + 1); push!(f̃_pred, zeros(S, nx)); end for i = 1:(Q + 1); push!(f̃val_correct, zeros(nx)); end hermite_obreschkoff = HermiteObreschkoff(p, q, b) set_tf!_pred = TaylorFunctor!(f!, nx, np, Val(K), zero(S), zero(T)) real_tf!_pred = TaylorFunctor!(f!, nx, np, Val(P), zero(T), zero(T)) Jf!_pred = JacTaylorFunctor!(f!, nx, np, Val(P), zero(S), zero(T)) real_tf!_correct = TaylorFunctor!(f!, nx, np, Val(Q), zero(T), zero(T)) Jf!_correct = JacTaylorFunctor!(f!, nx, np, Val(Q), zero(S), zero(T)) HermiteObreschkoffFunctor{F, P2, P1, Q1, K+1, T, S, nx + np}(; lohners_functor = lon_func, hermite_obreschkoff = hermite_obreschkoff, μX = zeros(S, nx), ρP = zeros(S, np), gⱼ₊₁ = zeros(S, nx), nx = nx, np = np, set_tf!_pred = set_tf!_pred, real_tf!_pred = real_tf!_pred, Jf!_pred = Jf!_pred, Rⱼ₊₁ = zeros(S, nx), mRⱼ₊₁ = zeros(nx), f̃val_pred = f̃val_pred, f̃_pred = f̃_pred, Vⱼ₊₁ = zeros(nx), X_predict = zeros(S, nx), xval_predict = zeros(nx), q_predict = P, real_tf!_correct = real_tf!_correct, Jf!_correct = Jf!_correct, xval_correct = zeros(nx), f̃val_correct = f̃val_correct, sum_p = zeros(S, nx), sum_q = zeros(S, nx), Δⱼ₊₁ = zeros(S, nx), pred_Jxmat = zeros(S, nx, nx), pred_Jxvec = zeros(S, nx), pred_Jpvec = zeros(S, nx), δⱼ₊₁ = zeros(S, nx), pre = zeros(nx, nx), precond2 = zeros(nx, nx), correct_B = zeros(S, nx, nx), correct_Bvec = zeros(S, nx), correct_C = zeros(S, nx, nx), Uj = zeros(S, nx), Jpdiff = zeros(S, nx, np), Cj = zeros(S, nx, nx), C_temp = zeros(S, nx, nx), Bj = zeros(S, nx, nx), B_temp = zeros(S, nx, nx), constant_state_bounds = nothing ) end function state_contractor(m::HermiteObreschkoff, f, Jx!, Jp!, nx, np, style, s, h) HermiteObreschkoffFunctor(f, nx, np, Val(m.p), Val(m.q), style, s, m.skip_contractor) end state_contractor_k(m::HermiteObreschkoff) = m.k state_contractor_γ(m::HermiteObreschkoff) = m.γ state_contractor_steps(m::HermiteObreschkoff) = 2 state_contractor_integrator(m::HermiteObreschkoff) = CVODE_Adams() function _pred_compute_Rj!(d, c, t) @unpack set_tf!_pred, Rⱼ₊₁, f̃_pred, q_predict = d @unpack Xj_apriori, P, hj = c set_tf!_pred(f̃_pred, Xj_apriori, P, t) @. Rⱼ₊₁ = f̃_pred[q_predict + 1]*hj^q_predict Rⱼ₊₁ end function _pred_compute_real_pnt!(d, c, t) @unpack Vⱼ₊₁, f̃val_pred, q_predict, real_tf!_pred = d @unpack hj, xval, pval = c real_tf!_pred(f̃val_pred, xval, pval, t) @. Vⱼ₊₁ = xval for i = 1:(q_predict - 1) @. Vⱼ₊₁ += f̃val_pred[i + 1]*hj^i end Vⱼ₊₁ end function _pred_compute_rhs_jacobian!(d, c::ContractorStorage{S}, t) where S Jf!_pred = d.Jf!_pred @unpack η, q_predict, nx, μX, ρP, X_predict = d @unpack Xj_0, xval, P, pval, hj = c @unpack Jx, Jxsto, Jp, Jpsto = Jf!_pred μ!(μX, X_predict, xval, η) ρ!(ρP, P, pval, η) set_JxJp!(Jf!_pred, μX, ρP, t) for i = 1:q_predict hji1 = hj^i if isone(i) fill!(Jxsto, zero(S)) Jxsto += I else @. Jxsto += hji1*Jx[i + 1] end @. Jpsto += hji1*Jp[i + 1] end return Jxsto, Jpsto end function _hermite_obreschkoff_predictor!(d::HermiteObreschkoffFunctor{F,Pp,P1,Q1,K,T,S,NY}, c::ContractorStorage{S}, r::StepResult{S}, j, k) where {F,Pp,P1,Q1,K,T,S,NY} @unpack X_predict, pred_Jxmat, pred_Jxvec, pred_Jpvec, Rⱼ₊₁, Vⱼ₊₁ = d @unpack A_Q, Δ, rP, times, Xj_apriori = c _pred_compute_Rj!(d, c, times[1]) _pred_compute_real_pnt!(d, c, times[1]) Jxsto, Jpsto = _pred_compute_rhs_jacobian!(d, c, times[1]) d.lohners_functor(c, r, j, k) @. X_predict = c.X_computed ∩ Xj_apriori # HERMITE OBRESCHKOFF PREDICTOR IS FAILING... WHY? # THIS IS MORE EXPANSIVE THAN LOHNERS METHOD BASIC.... option 1 fix, option 2 lohners method.... #mul!(pred_Jxmat, Jxsto, A_Q[2]) #mul!(pred_Jxvec, pred_Jxmat, Δ[2]) #mul!(pred_Jpvec, Jpsto, rP) #@. X_predict = Vⱼ₊₁ + Rⱼ₊₁ + pred_Jxvec + pred_Jpvec d.lohners_functor.Δⱼ₊₁ end predi(cpq, hj, y, i) = y[i + 1]*cpq[i + 1]*hj^i qi(cqp, hj, y, i) = y[i + 1]*cqp[i + 1]*((-hj)^i) """ Performs parametric version of algorithm 4.3 in Nedialkov... """ function (d::HermiteObreschkoffFunctor{F,Pp,P1,Q1,K,T,S,NY})(c::ContractorStorage{S}, r::StepResult{S}, j, k) where {F, Pp, P1, Q1, K, T, S, NY} @unpack X_computed, xval_computed, xval, pval, P, rP, A_inv, A_Q, Δ, hj = c # unpack parameters and storage @unpack Jxsto, Jpsto, Jx, Jp = d.Jf!_pred @unpack γ, p, q, k, cpq, cqp = d.hermite_obreschkoff @unpack f̃val_correct, f̃val_pred, f̃_pred, real_tf!_correct, η, X_predict, xval_predict, δⱼ₊₁, nx, np = d @unpack Jpdiff, sum_p, sum_q, μX, ρP, pre, B_temp, C_temp, Bj, Cj, Δⱼ₊₁, Uj = d cJx, cJp = d.Jf!_correct.Jx, d.Jf!_correct.Jp t = c.times[1] ho_predict_Δⱼ₊₁ = _hermite_obreschkoff_predictor!(d, c, r, j, k) # calculate predictor --> sets d.X_predict @. xval_predict = mid(X_predict) if !d.hermite_obreschkoff.skip_contractor real_tf!_correct(f̃val_correct, xval_predict, pval, t) @. sum_p = f̃val_pred[2]*cpq[2]*hj for i = 2:p @. sum_p += f̃val_pred[i + 1]*cpq[i + 1]*hj^i end @. sum_q = -hj*f̃val_correct[2]*cqp[2] for i = 2:q @. sum_q += f̃val_correct[i + 1]*cqp[i + 1]*((-hj)^i) end @. δⱼ₊₁ = xval - xval_predict + sum_p - sum_q + γ*(hj^k)*f̃_pred[k + 1] fill!(Jxsto, zero(S)) for i = 1:nx; Jxsto[i,i] = one(S); end for i = 1:p @. Jxsto += Jx[i + 1]*cpq[i + 1]*hj^i end @. Jpsto = Jp[2]*cpq[2]*hj for i = 2:p @. Jpsto += Jp[i + 1]*cpq[i + 1]*hj^i end μ!(μX, X_predict, xval, η) ρ!(ρP, P, pval, η) set_JxJp!(d.Jf!_correct, μX, ρP, t) fill!(Jxsto, zero(S)) for i = 1:nx; Jxsto[i,i] = one(S); end for i = 1:q @. Jxsto += cJx[i + 1]*cqp[i + 1]*((-hj)^i) end d.Jf!_correct.Jpsto .= sum(i -> qi(cqp, hj, cJp, i), 1:q) @. pre = mid(Jxsto) lu!(pre) mul!(B_temp, Jxsto, A_Q[2]) Bj .= pre/B_temp C_temp .= pre/Jxsto @. Cj = -C_temp Cj += I @. Uj = X_predict - xval_predict @. Jpdiff = Jpsto - d.Jf!_correct.Jpsto X_computed .= (xval_predict + Bj*Δ[2] + Cj*Uj + (pre\Jpdiff)*rP + pre*δⱼ₊₁) .∩ X_predict contract_constant_state!(X_computed, d.constant_state_bounds) affine_contract!(X_computed, P, pval, np, nx) @. xval_computed = mid(X_computed) # calculation block for computing Aⱼ₊₁ and inv(Aⱼ₊₁) cJmid = Jxsto*A_Q[2] calculateQ!(A_Q[1], mid.(cJmid)) calculateQinv!(A_inv[1], A_Q[1]) pre2 = A_inv[1]*pre Δⱼ₊₁ .= pre2*δⱼ₊₁ + (pre2*Jpdiff)*rP + (pre*cJmid)*Δ[2] + A_inv[1]*(xval_computed - xval_predict) + (A_inv[1]*Cj)*(X_computed - xval_predict) @. Δ[1] = Δⱼ₊₁ .∩ ho_predict_Δⱼ₊₁ end return RELAXATION_NOT_CALLED end get_Δ(f::HermiteObreschkoffFunctor) = f.Δⱼ₊₁
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
5489
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/method/higher_order_enclosure.jl # Defines higher-order existence and uniqueness tests. ############################################################################# set_mag(x::Interval{Float64}) = mag(x) set_mag(x::MC{N,T}) where {N, T<:RelaxTag} = mag(x.Intv) const SUBSET_TOL = 1E-8 is_subset_tol(x::Interval{T}, y::Interval{T}) where {T<:Real} = (x.lo > y.lo - SUBSET_TOL) && (x.hi < y.hi + SUBSET_TOL) contains(x::Vector{Interval{T}}, y::Vector{Interval{T}}) where {T<:Real} = mapreduce(is_subset_tol, &, x, y) contains(x::Vector{MC{N,T}}, y::Vector{MC{N,T}}) where {N,T<:RelaxTag} = mapreduce((x,y)->is_subset_tol(x.Intv,y.Intv), &, x, y) function round_β!(β::Vector{S}, ϵ, nx) where S for i = 1:nx if isapprox(β[i], zero(S), atol=1E-10) β[i] = ϵ end end end const ALPHA_ATOL = 1E-10 const ALPHA_RTOL = 1E-10 const ALPHA_BOUND_TOL = 1E-13 const ALPHA_ITERATION_LIMIT = 1000 function inner_α_func(z::MC{N,T}, u::MC{N,T}) where {N,T} max(abs(max(z.Intv.lo, z.Intv.hi) - u.Intv.hi), abs(u.Intv.lo - min(z.Intv.lo, z.Intv.hi))) end function inner_α_func(z::Interval{Float64}, u::Interval{Float64}) max(abs(max(z.lo, z.hi) - u.hi), abs(u.lo - min(z.lo, z.hi))) end α_func(Vⱼ, Uⱼ, α, k) = mapreduce(inner_α_func, max, Interval(0.0, α^k).*Vⱼ, Uⱼ) """ calc_alpha Computes the stepsize for the adaptive step-routine via a golden section rootfinding method. The step size is rounded down. """ function α(Vⱼ::Vector{T}, Uⱼ::Vector{T}, k) where T <: Number αL = 0.0 + ALPHA_BOUND_TOL αU = 1.0 - ALPHA_BOUND_TOL golden_ratio = 0.5*(3.0 - sqrt(5.0)) α = αL + golden_ratio*(αU - αL) fα = α_func(Vⱼ, Uⱼ, α, k) iteration = 0 converged = false while iteration < ALPHA_ITERATION_LIMIT if abs(α - (αU + αL)/2) <= 2*(ALPHA_RTOL*abs(α) + ALPHA_ATOL) - (αU - αL)/2 converged = true break end iteration += 1 if αU - α > α - αL new_α = α + golden_ratio*(αU - α) new_f = α_func(Vⱼ, Uⱼ, new_α, k) if new_f < fα αL = α α = new_α fα = new_f else αU = new_α end else new_α = α - golden_ratio*(α - αL) new_f = α_func(Vⱼ, Uⱼ, new_α, k) if new_f < fα αU = α α = new_α fα = new_f else αL = new_α end end end !converged && error("Alpha calculation not converged.") return min(α - ALPHA_ATOL, α*(1-ALPHA_RTOL)) end """ existence_uniqueness! Implements the adaptive higher-order enclosure approach detailed in Nedialkov's dissertation (Nedialko S. Nedialkov. Computing rigorous bounds on the solution of an initial value problem for an ordinary differential equation. 1999. Universisty of Toronto, PhD Dissertation, Algorithm 5.1, page 73-74). The arguments are `s::ExistStorage{F,K,S,T}, params::StepParams, t::Float64, j::Int64`. """ function existence_uniqueness!(s::ExistStorage{F,K,S,T}, params::StepParams, t, j) where {F, K, S, T <: Number} @unpack predicted_hj, Xj_0, Xj_apriori, poly_term, f_coeff, f_temp_tilde, f_temp_PU = s @unpack k, ϵ, P, Vⱼ, Uⱼ, Z, β, fk, tf!, nx, hfk = s @unpack hmin, is_adaptive = params # compute coefficients tf!(f_coeff, Xj_0, P, t) @. poly_term = f_coeff[k] for i in (k-1):-1:1 @. poly_term = f_coeff[i] + poly_term*Interval(0.0, predicted_hj) end if isone(j) @. Uⱼ = 2.0*Interval(-1.0, 1.0)*abs(predicted_hj^k)*Interval(set_mag(f_coeff[k + 1])) tf!(f_temp_PU, poly_term + Uⱼ, P, t) @. β = set_mag(f_temp_PU[k + 1]) else @. β = set_mag(fk) end round_β!(β, ϵ, nx) @. Uⱼ = 2.0*(predicted_hj^k)*Interval(-β, β) @. Xj_apriori = poly_term + Uⱼ tf!(f_temp_tilde, Xj_apriori, P, t) @. Z = (predicted_hj^(k+1))*f_temp_tilde[k + 1] @. Vⱼ = Interval(0.0, 1.0)*Z # checks existence and uniqueness by proper enclosure of Vⱼ & Uⱼ and computes the next appropriate step size if !contains(Vⱼ, Uⱼ) if !is_adaptive print_iteration(j) && @show Vⱼ, Uⱼ s.status_flag = NUMERICAL_ERROR return false end s.computed_hj = α(Vⱼ, Uⱼ, k)*predicted_hj else s.computed_hj = predicted_hj end if s.computed_hj < hmin print_iteration(j) && @show s.computed_hj s.status_flag = NUMERICAL_ERROR return false end # save outputs @. hfk = Z @. fk = f_temp_tilde[k + 1] @. f_coeff[k + 1] = fk return true end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
7041
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/method/lohners_qr.jl # Defines the lohner's method for contracting in discretize and relax. ############################################################################# """ LohnersFunctor A functor used in computing bounds and relaxations via Lohner's method. The implementation of the parametric Lohner's method described in the paper in (1) based on the non-parametric version given in (2). 1. [Sahlodin, Ali M., and Benoit Chachuat. "Discretize-then-relax approach for convex/concave relaxations of the solutions of parametric ODEs." Applied Numerical Mathematics 61.7 (2011): 803-820.](https://www.sciencedirect.com/science/article/abs/pii/S0168927411000316) 2. [R.J. Lohner, Computation of guaranteed enclosures for the solutions of ordinary initial and boundary value problems, in: J.R. Cash, I. Gladwell (Eds.), Computational Ordinary Differential Equations, vol. 1, Clarendon Press, 1992, pp. 425–436.](http://www.goldsztejn.com/old-papers/Lohner-1992.pdf) """ Base.@kwdef mutable struct LohnersFunctor{F <: Function, K, T <: Real, S <: Real, NY} <: AbstractStateContractor set_tf!::TaylorFunctor!{F,K,T,S} real_tf!::TaylorFunctor!{F,K,T,T} jac_tf!::JacTaylorFunctor!{F,K,T,S,NY} η::Interval{Float64} = Interval{Float64}(0.0,1.0) μX::Vector{S} ρP::Vector{S} f̃::Vector{Vector{S}} f̃val::Vector{Vector{Float64}} Vⱼ₊₁::Vector{Float64} Rⱼ₊₁::Vector{S} mRⱼ₊₁::Vector{Float64} Δⱼ₊₁::Vector{S} Jxmat::Matrix{S} Jxvec::Vector{S} Jpvec::Vector{S} rRⱼ₊₁::Vector{S} nx::Int np::Int Ai_rRj::Vector{S} Ai_Jxm::Matrix{S} Δ_Jx::Vector{S} Ai_Jpm::Matrix{S} Δ_Jp::Vector{S} constant_state_bounds::Union{Nothing,DBB.ConstantStateBounds} end function LohnersFunctor(f!::F, nx::Int, np::Int, k::Val{K}, s::S, t::T) where {F, K, S <: Number, T <: Number} f̃ = Vector{S}[] f̃val = Vector{Float64}[] for i = 1:(K + 1) push!(f̃, zeros(S, nx)) push!(f̃val, zeros(Float64, nx)) end LohnersFunctor{F, K + 1, T, S, nx + np}(set_tf! = TaylorFunctor!(f!, nx, np, k, zero(S), zero(T)), real_tf! = TaylorFunctor!(f!, nx, np, k, zero(T), zero(T)), jac_tf! = JacTaylorFunctor!(f!, nx, np, k, zero(S), zero(T)), μX = zeros(S, nx), ρP = zeros(S, np), f̃ = f̃, f̃val = f̃val, Vⱼ₊₁ = zeros(nx), Rⱼ₊₁ = zeros(S, nx), mRⱼ₊₁ = zeros(nx), Δⱼ₊₁ = zeros(S, nx), Jxmat = zeros(S, nx, nx), Jxvec = zeros(S, nx), Jpvec = zeros(S, nx), rRⱼ₊₁ = zeros(S, nx), nx = nx, np = np, Ai_rRj = zeros(S, nx), Ai_Jxm = zeros(S, nx, nx), Δ_Jx = zeros(S, nx), Ai_Jpm = zeros(S, nx, np), Δ_Jp = zeros(S, nx), constant_state_bounds = nothing) end set_constant_state_bounds!(d::LohnersFunctor, v) = (d.constant_state_bounds = v;) """ LohnerContractor{K} An `AbstractStateContractorName` used to specify a parametric Lohners method contractor of order K. """ struct LohnerContractor{K} <: AbstractStateContractorName end LohnerContractor(k::Int) = LohnerContractor{k}() state_contractor(m::LohnerContractor{K}, f, Jx!, Jp!, nx, np, style, s, h) where K = LohnersFunctor(f, nx, np, Val{K}(), style, s) state_contractor_k(m::LohnerContractor{K}) where K = K state_contractor_γ(m::LohnerContractor{K}) where K = 1.0 state_contractor_steps(m::LohnerContractor{K}) where K = 2 state_contractor_integrator(m::LohnerContractor{K}) where K = CVODE_Adams() function (d::LohnersFunctor{F,K,S,T,NY})(c, r, j, k) where {F,K,S,T,NY} @unpack hj, xval_computed, X_computed, xval, pval, P, rP, A_Q, A_inv, Δ, Xj_0, Xj_apriori = c @unpack f̃, f̃val, η, set_tf!, real_tf!, Jxmat, Jxvec, Jpvec, Rⱼ₊₁, mRⱼ₊₁, Vⱼ₊₁, nx, np = d @unpack Ai_rRj, Ai_Jxm, Δ_Jx, Ai_Jpm, Δ_Jp, Δⱼ₊₁, μX, ρP, rRⱼ₊₁ = d @unpack Jp, Jx, Jpsto, Jxsto = d.jac_tf! @unpack k = d.set_tf! Jf! = d.jac_tf! t = c.times[1] set_tf!(f̃, Xj_apriori, P, t) @. Rⱼ₊₁ = (hj^k)*f̃[k + 1] @. mRⱼ₊₁ = mid(Rⱼ₊₁) # defunes new x point... k corresponds to k - 1 since taylor coefficients are zero indexed real_tf!(f̃val, xval, pval, t) @. Vⱼ₊₁ = xval for i = 1:(k-1) @. Vⱼ₊₁ += f̃val[i + 1]*hj^i end # compute extensions of taylor cofficients for rhs μ!(μX, Xj_0, xval, η) ρ!(ρP, P, pval, η) set_JxJp!(Jf!, μX, ρP, t) fill!(Jxsto, zero(T)) Jxsto += I @. Jpsto = Jp[1] for i = 2:k @. Jxsto += Jx[i]*hj^(i - 1) @. Jpsto += Jp[i]*hj^(i - 1) end # update x floating point value @. xval_computed = Vⱼ₊₁ + mRⱼ₊₁ mul!(Jxmat, Jxsto, A_Q[2]) mul!(Jxvec, Jxmat, Δ[2]) mul!(Jpvec, Jpsto, rP) @. X_computed = Vⱼ₊₁ + Rⱼ₊₁ + Jxvec + Jpvec affine_contract!(X_computed, P, pval, nx, np) # calculation block for computing Aⱼ₊₁ and inv(Aⱼ₊₁) calculateQ!(A_Q[1], mid.(Jxmat)) calculateQinv!(A_inv[1], A_Q[1]) # update Delta @. rRⱼ₊₁ = Rⱼ₊₁ - mRⱼ₊₁ mul!(Ai_rRj, A_inv[1], rRⱼ₊₁) mul!(Ai_Jxm, A_inv[1], Jxmat) mul!(Δ_Jx, Ai_Jxm, Δ[2]) mul!(Ai_Jpm, A_inv[1], Jpsto) mul!(Δ_Jp, Ai_Jpm, rP) @. Δ[1] = Ai_rRj + Δ_Jx + Δ_Jp @. Δⱼ₊₁ = Δ[1] return RELAXATION_NOT_CALLED end get_Δ(d::LohnersFunctor{F,K,S,T,NY}) where {F,K,S,T,NY} = copy(d.Δⱼ₊₁)
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
12667
export AdamsMoulton struct AdamsMoulton <: AbstractStateContractorName steps::Int end mutable struct AdamsMoultonFunctor{S} <: AbstractStateContractor f! Jx! Jp! nx np method_step::Int64 η::Interval{Float64} μX::Vector{S} ρP::Vector{S} Dk::Vector{S} Xold_computed::Vector{S} Xk::Vector{Vector{S}} fk1::Vector{S} fk_val::Vector{Float64} Jxsto::FixedCircularBuffer{Matrix{S}} Jpsto::FixedCircularBuffer{Matrix{S}} Jxsum::Matrix{S} Jpsum::Matrix{S} Jxvec::Vector{S} Jpvec::Vector{S} Ainv_Jxvec::Vector{S} Ainv_Jpvec::Vector{S} Ainv_fk_val::Vector{S} Ainv_Xk2::Vector{S} Ainv_Rk::Vector{S} fval::FixedCircularBuffer{Vector{Float64}} fk_apriori::FixedCircularBuffer{Vector{S}} Rk::Vector{S} Y0::Matrix{Float64} Y::Matrix{Float64} Jxmid_sto::Matrix{S} precond::LinearAlgebra.LU{Float64,Array{Float64,2}} JxAff::Matrix{S} YJxAff::Matrix{S} YJxΔx::Vector{S} Xj_delta::Vector{S} X_last::Vector{S} Ysumx::Vector{S} YsumP::Matrix{S} YJpΔp::Vector{S} coeffs::Vector{Float64} Δⱼ₊₁::Vector{S} is_adaptive::Bool γ::Float64 lohners_start::LohnersFunctor A_Q::FixedCircularBuffer{Matrix{Float64}} A_inv::FixedCircularBuffer{Matrix{Float64}} Δ::FixedCircularBuffer{Vector{S}} X::FixedCircularBuffer{Vector{S}} xval::FixedCircularBuffer{Vector{Float64}} Δx::Vector{S} constant_state_bounds::Union{Nothing, ConstantStateBounds} end function set_constant_state_bounds!(d::AdamsMoultonFunctor, v) d.constant_state_bounds = v set_constant_state_bounds!(d.lohners_start, v) nothing end function AdamsMoultonFunctor(f::F, Jx!::JX, Jp!::JP, nx::Int, np::Int, s::S, t::T, steps::Int, lohners_start) where {F,JX,JP,S,T} η = Interval{T}(0.0,1.0) μX = zeros(S, nx) ρP = zeros(S, np) method_step = steps Dk = zeros(S, nx) lu_mat = zeros(nx, nx) for i = 1:nx lu_mat[i,i] = 1.0 end precond = lu(lu_mat) Y0 = zeros(nx, nx) Y = zeros(nx, nx) Jxmid_sto = zeros(S, nx, nx) YJxAff = zeros(S, nx, nx) JxAff = zeros(S, nx, nx) Xj_delta = zeros(S, nx) X_last = zeros(S, nx) YJxΔx = zeros(S, nx) Ysumx = zeros(S, nx) YsumP = zeros(S, nx, nx) YJpΔp = zeros(S, nx) Jxsto = FixedCircularBuffer{Matrix{S}}(method_step) Jpsto = FixedCircularBuffer{Matrix{S}}(method_step) for i = 1:method_step push!(Jxsto, zeros(S, nx, nx)) push!(Jpsto, zeros(S, nx, np)) end Jxsum = zeros(S, nx, nx) Jpsum = zeros(S, nx, np) Jxvec = zeros(S, nx) Jpvec = zeros(S, nx) Ainv_Jxvec = zeros(S, nx) Ainv_Jpvec = zeros(S, nx) Ainv_fk_val = zeros(S, nx) Ainv_Xk2 = zeros(S, nx) Ainv_Rk = zeros(S, nx) Xold_computed = zeros(S, nx) Δx = zeros(S, nx) fk1 = zeros(S, nx) fk_val = zeros(Float64, nx) Xk = Vector{S}[zeros(S, nx)] fval = FixedCircularBuffer{Vector{Float64}}(method_step) fk_apriori = FixedCircularBuffer{Vector{S}}(method_step) A_Q = FixedCircularBuffer{Matrix{Float64}}(method_step) A_inv = FixedCircularBuffer{Matrix{Float64}}(method_step) Δ = FixedCircularBuffer{Vector{S}}(method_step) X = FixedCircularBuffer{Vector{S}}(method_step) xval = FixedCircularBuffer{Vector{Float64}}(method_step) #@show method_step for i = 1:method_step push!(xval, zeros(Float64, nx)) push!(fval, zeros(Float64, nx)) push!(fk_apriori, zeros(S, nx)) push!(A_Q, Float64.(Matrix(I, nx, nx))) push!(A_inv, Float64.(Matrix(I, nx, nx))) push!(X, zeros(S, nx)) push!(Δ, zeros(S, nx)) push!(Xk, zeros(S, nx)) end Rk = zeros(S, nx) coeffs = zeros(Float64, method_step + 1) Δⱼ₊₁ = zeros(S, nx) is_adaptive = false γ = 0.0 AdamsMoultonFunctor{S}(f, Jx!, Jp!, nx, np, method_step, η, μX, ρP, Dk, Xold_computed, Xk, fk1, fk_val, Jxsto, Jpsto, Jxsum, Jpsum, Jxvec, Jpvec, Ainv_Jxvec, Ainv_Jpvec, Ainv_fk_val, Ainv_Xk2, Ainv_Rk, fval, fk_apriori, Rk, Y0, Y, Jxmid_sto, precond, JxAff, YJxAff, YJxΔx, Xj_delta, X_last, Ysumx, YsumP, YJpΔp, coeffs, Δⱼ₊₁, is_adaptive, γ, lohners_start, A_Q, A_inv, Δ, X, xval, Δx, nothing) end function compute_coefficients!(c::ContractorStorage{S}, d::AdamsMoultonFunctor{S}, h::Float64, t::Float64, s::Int) where S @unpack is_adaptive, coeffs = d if !is_adaptive if s == 1 coeffs[1] = 1.0 coeffs[2] = 0.5 elseif s == 2 coeffs[1] = 0.5 coeffs[2] = 0.5 coeffs[3] = -1.0/12.0 elseif s == 3 coeffs[1] = 5.0/12.0 coeffs[2] = 8.0/12.0 coeffs[3] = -1.0/12.0 coeffs[4] = -1.0/24.0 elseif s == 4 coeffs[1] = 9.0/24.0 coeffs[2] = 19.0/24.0 coeffs[3] = -5.0/24.0 coeffs[4] = 1.0/24.0 coeffs[5] = -19.0/720.0 else error("order greater than 4 for fixed size PILMS currently not supported") end else compute_adaptive_coeffs!(d, h, t, s) end d.γ = coeffs[s + 1] c.γ = d.γ nothing end function compute_Rk!(d::AdamsMoultonFunctor{T}, c::ContractorStorage{T}, h, s) where T<:Number @unpack fk_apriori, Rk, method_step, γ = d cycle_copyto!(fk_apriori, c.fk_apriori, c.step_count - 1) @. Rk = fk_apriori[1] for i = 2:s @. Rk = Rk ∪ fk_apriori[i] end @. Rk *= γ*h^(method_step+1) nothing end # TODO: Check block function compute_real_sum!(d::AdamsMoultonFunctor{T}, c::ContractorStorage{T}, r::StepResult{T}, h::Float64, t::Float64, s::Int) where T<:Number @unpack Dk, coeffs, fval, f!, X_last = d @unpack Xj_0, pval, X_computed = c #println("real sum Xj_0 = $(Xj_0)") #= @. X_last = X_computed @show mid.(X_last), pval, t, h cycle_eval!(f!, fval, mid.(Xj_0), pval, t) @. Dk = mid(X_last) # TODO: REPLACE WITH (X_K-1) NOT EXISTENCE TEST... Maybe fixed... for i = 1:s @show coeffs[i] @. Dk += h*coeffs[i]*fval[i] end =# nothing end # Compute components of sum for prior timesteps --> then update original function compute_jacobian_sum!(d::AdamsMoultonFunctor{T}, c::ContractorStorage{T}, h::Float64, t::Float64, s::Int) where T<:Number @unpack Xj_delta, Jx!, Jp!, JxAff, Jxsto, Jpsto, Jxsum, Jpsum, Jpvec, μX, ρP, η, coeffs = d @unpack Xj_0, Xj_apriori, xval, P, pval, A_Q, Δ = c μ!(μX, Xj_0, xval, η) ρ!(ρP, P, pval, η) cycle_eval!(Jx!, Jxsto, μX, ρP, t) cycle_eval!(Jp!, Jpsto, μX, ρP, t) @. JxAff = Jxsto[1] @. Xj_delta = Xj_apriori - mid(Xj_apriori) #= @show size(Jxsum) @show size(Jxsto[1]) @show size(Xj_delta) Jxsum = h*coeffs[1]*(Jxsto[1]*Xj_delta) if s > 1 println("s = $s") @show size(((I + h*coeffs[2]*Jxsto[2])*A_Q[1])*Δ[1]) @show size(Jxsum) Jxsum += ((I + h*coeffs[2]*Jxsto[2])*A_Q[1])*Δ[1] end for i = 3:s println("s = $s of 3") Jxsum += h*coeffs[i]*(Jxsto[i]*A_Q[i])*Δ[i] end =# nothing end @inline function union_mc_dbb(x::MC{N,T}, y::MC{N,T}) where {N, T <: RelaxTag} cv_MC = min(x, y) cc_MC = max(x, y) return MC{N, NS}(cv_MC.cv, cc_MC.cc, Interval(cv_MC.Intv.lo, cc_MC.Intv.hi), cv_MC.cv_grad, cc_MC.cc_grad, x.cnst && y.cnst) end union_mc_dbb(x::Interval{T}, y::Interval{T}) where T = x ∪ y function compute_X!(d::AdamsMoultonFunctor{T}, c::ContractorStorage{S}) where {S, T<:Number} @unpack Jx!, Jp!, Jxsum, Jpsum, Jxvec, Jpvec, Dk, Rk, f!, X_last, μX, ρP, X, method_step, Δx, coeffs = d @unpack Xold_computed, Xk, fk1, fk_val, fk_apriori, γ, Jxmid_sto, Jxsto, Δ, A_inv = d @unpack Ainv_fk_val, Ainv_Jpvec, Ainv_Jxvec, Ainv_Xk2, Ainv_Rk, Δⱼ₊₁ = d @unpack X_computed, xval_computed, Xj_apriori, rP, Xj_0, xval, pval, hj, A_Q, A_inv, B = c t = c.times[1] s = min(c.step_count - 1, method_step) cycle_copyto!(fk_apriori, c.fk_apriori, c.step_count - 1) # TODO: Fix when variable stepsize @. Rk = fk_apriori[1] for i = 2:s @. Rk = union_mc_dbb(Rk, fk_apriori[i]) end @. Rk *= γ*hj^(method_step+1) @. Xk[1] = Xj_apriori @. Xk[2] = Xj_0 for j = 3:method_step @. Xk[j] = X[j - 2] end @. Xold_computed = Xj_apriori @. X_computed = Xj_apriori for i = 1:2 @. Xk[1] = X_computed f!(fk_val, xval, pval, t) Jx!(Jxsum, Xk[1], ρP, t) Jp!(Jpsum, Xk[1], ρP, t) @. Δx = Xk[1] - xval Aj_inv = A_inv[2] # TODO: Not sure if set correct... Δj = Δ[2] # TODO: Not sure if set correct... mul!(Δx, Aj_inv, Δj) mul!(Jxvec, Jxsum, Δx) @. Jpsum = hj*coeffs[1]*Jpsum #for i = 2:s # @. Jpsum += h*coeffs[i]*Jpsto[i] #end mul!(Jpvec, Jpsum, ρP) @. Xold_computed = X_computed @. X_computed = Xk[2] + Rk + hj*coeffs[1]*(fk_val + Jpvec + Jxvec) for j = 1:method_step f!(fk1, Xk[j + 1], ρP, t) @. X_computed += hj*coeffs[j + 1]*fk1 end # Finish computing X @. X_computed = X_computed ∩ Xold_computed contract_constant_state!(X_computed, d.constant_state_bounds) # Compute x @. xval_computed = mid(X_computed) # Compute Delta if s > 1 Ak_m_1 = A_Q[2] mul!(Jxmid_sto, Jxsto[1], Ak_m_1) @. B = mid(Jxmid_sto) calculateQ!(A_Q[1], B) calculateQinv!(A_inv[1], A_Q[1]) end mul!(Ainv_fk_val, A_inv[1], fk_val) mul!(Ainv_Jpvec, A_inv[1], Jpvec) mul!(Ainv_Jxvec, A_inv[1], Jxvec) mul!(Ainv_Xk2, A_inv[1], Xk[2]) mul!(Ainv_Rk, A_inv[1], Rk) @. Δⱼ₊₁ = hj*coeffs[1]*(Ainv_fk_val + Ainv_Jpvec + Ainv_Jxvec) for j = 1:method_step f!(fk1, Xk[j + 1], ρP, t) mul!(Ainv_fk_val, A_inv[1], fk1) @. Δⱼ₊₁ += hj*coeffs[j + 1]*Ainv_fk_val end end nothing end function store_starting_buffer!(d::AdamsMoultonFunctor{T}, c::ContractorStorage{T}, r::StepResult{T}, t::Float64) where T @unpack η, X, xval, fk_apriori, Δ, A_Q, A_inv, μX, ρP, Jx!, Jp!, f!, Jxsto, Jpsto, fval = d @unpack pval, P, step_count = c k = step_count - 1 cycle_copyto!(X, r.Xⱼ, k) cycle_copyto!(xval, r.xⱼ, k) cycle_copyto!(fk_apriori, c.fk_apriori, k) cycle_copyto!(Δ, r.Δ[1], k) cycle_copyto!(A_Q, r.A_Q[1], k) cycle_copyto!(A_inv, r.A_inv[1], k) # update Jacobian storage μ!(μX, r.Xⱼ, r.xⱼ, η) ρ!(ρP, P, pval, η) cycle_eval!(Jx!, Jxsto, μX, ρP, t) cycle_eval!(Jp!, Jpsto, μX, ρP, t) cycle_eval!(f!, fval, r.xⱼ, pval, t) nothing end function (d::AdamsMoultonFunctor{T})(c::ContractorStorage{S}, r::StepResult{S}, count::Int, k) where {S, T<:Number} t = c.times[1] s = min(c.step_count-1, d.method_step) if s < d.method_step d.lohners_start(c, r, count, k) iszero(count) && store_starting_buffer!(d, c, r, t) return nothing end h = c.hj compute_coefficients!(c, d, h, t, s) compute_real_sum!(d, c, r, h, t, s) compute_jacobian_sum!(d, c, h, t, s) compute_X!(d, c) return nothing end function get_Δ(d::AdamsMoultonFunctor) if true return copy(get_Δ(d.lohners_start)) end return copy(d.Δⱼ₊₁) end function state_contractor(m::AdamsMoulton, f, Jx!, Jp!, nx, np, style, s, h) lohners_functor = state_contractor(LohnerContractor{m.steps}(), f, Jx!, Jp!, nx, np, style, s, h) AdamsMoultonFunctor(f, Jx!, Jp!, nx, np, style, s, m.steps, lohners_functor) end state_contractor_k(m::AdamsMoulton) = m.steps + 1 state_contractor_γ(m::AdamsMoulton) = 1.0 # Same value as Lohners for initial step then set later... state_contractor_steps(m::AdamsMoulton) = m.steps state_contractor_integrator(m::AdamsMoulton) = CVODE_Adams() function set_γ!(sc::AdamsMoulton, c, ex, result, params) nothing end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
37263
""" $(TYPEDEF) """ abstract type AbstractIntervalCallback end """ $(TYPEDEF) Functor object `d` that computes `h(xmid, P)` and `hj(X,P)` in-place using `X`, `P` information stored in the fields when `d()` is run. """ mutable struct PICallback{FH,FJ} <: AbstractIntervalCallback h!::FH hj!::FJ H::Vector{Interval{Float64}} J::Array{Interval{Float64},2} xmid::Vector{Float64} X::Vector{Interval{Float64}} P::Vector{Interval{Float64}} nx::Int end function PICallback(h!::FH, hj!::FJ, P::Vector{Interval{Float64}}, nx::Int) where {FH,FJ} H = zeros(Interval{Float64}, nx) J = zeros(Interval{Float64}, nx, nx) xmid = zeros(Float64, nx) X = zeros(Interval{Float64}, nx) return PICallback{FH,FJ}(h!, hj!, H, J, xmid, X, P, nx) end function (d::PICallback{FH,FJ})() where {FH,FJ} @unpack H, J, X, P, xmid, nx, h!, hj! = d fill!(H, zero(Interval{Float64})) fill!(J, zero(Interval{Float64})) for i in 1:nx xmid[i] = 0.5*(X[i].lo + X[i].hi) end h!(H, xmid, P) hj!(J, X, P) return end """ $(TYPEDEF) """ function precondition!(d::DenseMidInv, H::Vector{Interval{Float64}}, J::Array{Interval{Float64},2}) for i in eachindex(J) d.Y[i] = 0.5*(J[i].lo + J[i].hi) end F = lu!(d.Y) H .= F\H J .= F\J return end """ $(TYPEDEF) """ abstract type AbstractContractor end """ $(TYPEDEF) """ @Base.kwdef struct NewtonInterval <: AbstractContractor N::Vector{Interval{Float64}} Ntemp::Vector{Interval{Float64}} X::Vector{Interval{Float64}} Xdiv::Vector{Interval{Float64}} inclusion::Vector{Bool} lower_inclusion::Vector{Bool} upper_inclusion::Vector{Bool} kmax::Int = 3 rtol::Float64 = 1E-6 etol::Float64 = 1E-6 end NewtonInterval(nx::Int) = NewtonInterval(N = zeros(Interval{Float64}, nx), Ntemp = zeros(Interval{Float64}, nx), X = zeros(Interval{Float64}, nx), Xdiv = zeros(Interval{Float64}, nx), inclusion = fill(false, (nx,)), lower_inclusion = fill(false, (nx,)), upper_inclusion = fill(false, (nx,))) function (d::NewtonInterval)(cb::PICallback{FH,FJ}) where {FH,FJ} @unpack X, Xdiv, N, Ntemp, inclusion, lower_inclusion, upper_inclusion, rtol = d @unpack H, J, nx = cb ext_division_flag = false exclusion_flag = false for i = 1:nx S1 = zero(Interval{Float64}) S2 = zero(Interval{Float64}) for j = 1:nx if j < i S1 += J[i,j]*(X[j] - 0.5*(X[j].lo + X[j].hi)) elseif j > i S2 += J[i,j]*(X[j] - 0.5*(X[j].lo + X[j].hi)) end end if J[i,i].lo*J[i,i].hi > 0.0 N[i] = 0.5*(X[i].lo + X[i].hi) - (H[i] + S1 + S2)/J[i,i] else @. Ntemp = N eD, N[i], Ntemp[i] = extended_process(N[i], X[i], J[i,i], S1 + S2 + H[i], rtol) if isone(eD) ext_division_flag = true @. Xdiv = X Xdiv[i] = Ntemp[i] ∩ X[i] X[i] = N[i] ∩ X[i] return ext_division_flag, exclusion_flag end end if strict_x_in_y(N[i], X[i]) inclusion[i] = true lower_inclusion[i] = true upper_inclusion[i] = true else inclusion[i] = false lower_inclusion[i] = N[i].lo > X[i].lo upper_inclusion[i] = N[i].hi < X[i].hi end if ~isdisjoint(N[i], X[i]) X[i] = N[i] ∩ X[i] else return ext_division_flag, exclusion_flag end end return ext_division_flag, exclusion_flag end function parametric_interval_contractor(callback!::PICallback{FH,FJ}, precond!::P, contractor::S) where {FH, FJ, P, S <: AbstractContractor} exclusion_flag = false inclusion_flag = false ext_division_flag = false ext_division_num = 0 fill!(contractor.inclusion, false) fill!(contractor.lower_inclusion, false) fill!(contractor.upper_inclusion, false) @. contractor.X = callback!.X for i = 1:contractor.kmax callback!()::Nothing precondition!(precond!, callback!.H, callback!.J)::Nothing exclusion_flag, ext_division_flag = contractor(callback!)::Tuple{Bool,Bool} (exclusion_flag || ext_division_flag) && break inclusion_flag = inclusion_test(inclusion_flag, contractor.inclusion, callback!.nx) @. callback!.X = contractor.X @. callback!.xmid = mid(callback!.X) end return exclusion_flag, inclusion_flag, ext_division_flag end """ $(TYPEDEF) """ abstract type Wilhelm2019Type end const W19T = Wilhelm2019Type """ $(TYPEDEF) Use an implicit Euler style of relaxation. """ struct ImpEuler <: W19T end """ $(TYPEDEF) Use an second-order Adam's Moulton method style of relaxation. """ struct AM2 <: W19T end """ $(TYPEDEF) Use an second-order Backward Difference Formula method style of relaxation. """ struct BDF2 <: W19T end state_contractor_integrator(m::ImpEuler) = ImplicitEuler(autodiff = false) state_contractor_integrator(m::AM2) = Trapezoid(autodiff = false) state_contractor_integrator(m::BDF2) = ABDF2(autodiff = false) is_two_step(::ImpEuler) = false is_two_step(::AM2) = false is_two_step(::BDF2) = true """ $(TYPEDEF) A callback function used for the Wilhelm2019 integrator. """ mutable struct CallbackH{V,F,T<:W19T} <: Function temp::Vector{V} xold1::Vector{V} xold2::Vector{V} h!::F t2::Float64 t1::Float64 end CallbackH{V,F,T}(nx::Int, h!::F) where {V,F,T<:W19T} = CallbackH{V,F,T}(zeros(V,nx), zeros(V,nx), zeros(V,nx), h!, 0.0, 0.0) function (cb::CallbackH{V,F,ImpEuler})(out, x, p) where {V,F} @unpack h!, xold1, t1, t2 = cb h!(out, x, p, t2) @. out = out*(t2 - t1) - x + xold1 nothing end function (cb::CallbackH{V,F,AM2})(out, x, p::Vector{V}) where {V,F} @unpack h!, temp, xold1, t1, t2 = cb h!(out, x, p, t2) h!(temp, xold1, p, t1) @. out = 0.5*(t2 - t1)*(out + temp) - x + xold1 nothing end function (cb::CallbackH{V,F,BDF2})(out, x, p::Vector{V}) where {V,F} @unpack h!, xold1, xold2, t1, t2 = cb h!(out, x, p, t2) @. out = (2.0/3.0)*(t2 - t1)*out - x + (4.0/3.0)*xold1 - (1.0/3.0)*xold2 nothing end """ $(FUNCTIONNAME) A callback function used for the Wilhelm2019 integrator. """ Base.@kwdef mutable struct CallbackHJ{F, T <: W19T} <: Function hj!::F tf::Float64 = 0.0 delT::Float64 = 0.0 end CallbackHJ{F,T}(hj!::F) where {F, T <: W19T} = CallbackHJ{F,T}(; hj! = hj!) function (cb::CallbackHJ{F, ImpEuler})(out, x, p) where F @unpack hj!, tf, delT = cb hj!(out, x, p, tf) @. out *= delT for j in diagind(out) out[j] -= 1.0 end nothing end function (cb::CallbackHJ{F, AM2})(out, x, p) where F @unpack hj!, tf, delT = cb hj!(out, x, p, tf) @. out *= 0.5*delT for j in diagind(out) out[j] -= 1.0 end nothing end function (cb::CallbackHJ{F, BDF2})(out, x, p) where F @unpack hj!, tf, delT = cb hj!(out, x, p, tf) @. out *= 2.0*delT/3.0 for j in diagind(out) out[j] -= 1.0 end nothing end """ $(TYPEDEF) An integrator that bounds the numerical solution of the pODEs system. $(TYPEDFIELDS) """ mutable struct Wilhelm2019{T <: W19T, ICB1 <: PICallback, ICB2 <: PICallback, PRE, CTR <: AbstractContractor, IC <: Function, F, Z, J, PRB, N, C, AMAT} <: DBB.AbstractODERelaxIntegrator # problem specifications integrator_type::T time::Vector{Float64} steps::Int p::Vector{Float64} pL::Vector{Float64} pU::Vector{Float64} nx::Int np::Int xL::Array{Float64,2} xU::Array{Float64,2} # state of integrator flags integrator_states::IntegratorStates evaluate_interval::Bool evaluate_state::Bool differentiable_flag::Bool # storage used for parametric interval methods P::Vector{Interval{Float64}} X::Array{Interval{Float64},2} X0P::Vector{Interval{Float64}} pi_callback1::ICB1 pi_callback2::ICB2 pi_precond!::PRE pi_contractor::CTR inclusion_flag::Bool exclusion_flag::Bool extended_division_flag::Bool # callback functions used for MC methods ic::IC h1::CallbackH{Z,F,ImpEuler} h2::CallbackH{Z,F,T} hj1::CallbackHJ{J,ImpEuler} hj2::CallbackHJ{J,T} mccallback1::MCCallback mccallback2::MCCallback # storage used for MC methods IC_relax::Vector{Z} state_relax::Array{Z,2} var_relax::Vector{Z} param::Vector{Vector{Vector{Z}}} kmax::Int calculate_local_sensitivity::Bool # local evaluation information local_problem_storage prob constant_state_bounds::Union{Nothing,ConstantStateBounds} relax_t_dict_flt::Dict{Float64,Int} relax_t_dict_indx::Dict{Int,Int} end function Wilhelm2019(d::ODERelaxProb, t::T) where {T <: W19T} h! = d.f; hj! = d.Jx! time = d.support_set.s steps = length(time) - 1 p = d.p; pL = d.pL; pU = d.pU nx = d.nx; np = length(p) xL = isempty(d.xL) ? zeros(nx,steps) : d.xL xU = isempty(d.xU) ? zeros(nx,steps) : d.xU P = Interval{Float64}.(pL, pU) X = zeros(Interval{Float64}, nx, steps) X0P = zeros(Interval{Float64}, nx) pi_precond! = DenseMidInv(zeros(Float64,nx,nx), zeros(Interval{Float64},1), nx, np) pi_contractor = NewtonInterval(nx) inclusion_flag = exclusion_flag = extended_division_flag = false Z = MC{np,NS} ic = d.x0 h1 = CallbackH{Z,typeof(h!),ImpEuler}(nx, h!) h2 = CallbackH{Z,typeof(h!),T}(nx, h!) hj1 = CallbackHJ{typeof(hj!),ImpEuler}(hj!) hj2 = CallbackHJ{typeof(hj!),T}(hj!) h1intv! = CallbackH{Interval{Float64},typeof(h!),ImpEuler}(nx, h!) h2intv! = CallbackH{Interval{Float64},typeof(h!),T}(nx, h!) hj1intv! = CallbackHJ{typeof(hj!),ImpEuler}(hj!) hj2intv! = CallbackHJ{typeof(hj!),T}(hj!) pi_callback1 = PICallback(h1intv!, hj1intv!, P, nx) pi_callback2 = PICallback(h2intv!, hj2intv!, P, nx) mc_callback1 = MCCallback(h1, hj1, nx, np, McCormick.NewtonGS(), McCormick.DenseMidInv(zeros(nx,nx), zeros(Interval{Float64},1), nx, np)) mc_callback2 = MCCallback(h2, hj2, nx, np, McCormick.NewtonGS(), McCormick.DenseMidInv(zeros(nx,nx), zeros(Interval{Float64},1), nx, np)) # storage used for MC methods kmax = 1 IC_relax = zeros(Z,nx) state_relax = zeros(Z, nx, steps) param = Vector{Vector{Z}}[[zeros(Z,nx) for j in 1:kmax] for i in 1:steps] var_relax = zeros(Z,np) calculate_local_sensitivity = true constant_state_bounds = d.constant_state_bounds local_integrator() = state_contractor_integrator(t) local_problem_storage = ODELocalIntegrator(d, local_integrator) support_set = DBB.get(d, DBB.SupportSet()) relax_t_dict_flt = Dict{Float64,Int}() relax_t_dict_indx = Dict{Int,Int}() for (i,s) in enumerate(support_set.s) relax_t_dict_flt[s] = i relax_t_dict_indx[i] = i end return Wilhelm2019{T, typeof(pi_callback1), typeof(pi_callback2), typeof(pi_precond!), typeof(pi_contractor), typeof(ic), typeof(h!), Z, typeof(hj!), nothing, np, NewtonGS, Array{Float64,2}}(t, time, steps, p, pL, pU, nx, np, xL, xU, IntegratorStates(), false, false, false, P, X, X0P, pi_callback1, pi_callback2, pi_precond!, pi_contractor, inclusion_flag, exclusion_flag, extended_division_flag, ic, h1, h2, hj1, hj2, mc_callback1, mc_callback2, IC_relax, state_relax, var_relax, param, kmax, calculate_local_sensitivity, local_problem_storage, d, constant_state_bounds, relax_t_dict_flt, relax_t_dict_indx) end function get_val_loc(d::Wilhelm2019, i::Int, t::Float64) (i <= 0 && t == -Inf) && error("Must set either index or time.") (i > 0) ? d.relax_t_dict_indx[i] : d.relax_t_dict_flt[t] end is_new_box(d::Wilhelm2019) = d.integrator_states.new_decision_box use_relax(d::Wilhelm2019) = !d.evaluate_interval use_relax_new_pnt(d::Wilhelm2019) = d.integrator_states.new_decision_pnt && use_relax(d) function relax!(d::Wilhelm2019{T, ICB1, ICB2, PRE, CTR, IC, F, Z, J, PRB, N, C, AMAT}) where {T, ICB1, ICB2, PRE, CTR, IC, F, Z, J, PRB, N, C, AMAT} pi_cb1 = d.pi_callback1; pi_cb2 = d.pi_callback2 mc_cb1 = d.mccallback1; mc_cb2 = d.mccallback2 # load state relaxation bounds at support values if !isnothing(d.constant_state_bounds) for i = 1:d.steps d.X[:,i] .= Interval{Float64}.(d.constant_state_bounds.xL, d.constant_state_bounds.xU) end end if is_two_step(d.integrator_type) if is_new_box(d) d.X0P .= d.ic(d.P) # evaluate initial condition # loads CallbackH and CallbackHJ function with correct time and prior x values @. pi_cb1.X = d.X[:,1] pi_cb1.xmid .= mid.(pi_cb1.X) pi_cb1.h!.xold1 .= d.X0P pi_cb1.h!.t1 = 0.0 pi_cb1.h!.t2 = pi_cb1.hj!.tf = pi_cb1.hj!.delT = d.time[2] @. pi_cb1.P = pi_cb2.P = d.P # run interval contractor on first step & break if solution is proven not to exist excl, incl, extd = parametric_interval_contractor(pi_cb1, d.pi_precond!, d.pi_contractor) excl && (d.integrator_states.termination_status = EMPTY; return) d.exclusion_flag = excl d.inclusion_flag = incl d.extended_division_flag = extd @. d.X[:,1] = d.pi_contractor.X # store interval values to storage array in d # generate reference point relaxations if use_relax(d) for j=1:d.np p_mid = 0.5*(lo(d.P[j]) + hi(d.P[j])) mc_cb1.pref_mc[j] = MC{d.np,NS}(p_mid, d.P[j], j) end @. mc_cb1.P = mc_cb2.P = d.P @. mc_cb1.p_mc = mc_cb1.pref_mc @. mc_cb2.p_mc = mc_cb1.pref_mc @. mc_cb2.pref_mc = mc_cb1.pref_mc @. mc_cb1.X = d.X[:,1] # evaluate initial condition d.IC_relax .= d.ic(mc_cb1.pref_mc) # loads CallbackH and CallbackHJ function with correct time and prior x values mc_cb1.h!.t1 = 0.0 mc_cb1.h!.t2 = mc_cb1.hj!.tf = mc_cb1.hj!.delT = d.time[2] @. mc_cb1.h!.xold1 = d.IC_relax # generate and save reference point relaxations gen_expansion_params!(mc_cb1) for q = 1:d.kmax @. d.param[1][q] = mc_cb1.param[q] end # generate and save relaxation at reference point implicit_relax_h!(mc_cb1) @. d.state_relax[:,1] = mc_cb1.x_mc end end if use_relax_new_pnt(d) for j = 1:d.np d.var_relax[j] = MC{d.np,NS}(d.p[j], d.P[j], j) end d.IC_relax .= d.ic(d.var_relax) # loads MC callback, CallbackH and CallbackHJ function with correct time and prior x values @. mc_cb1.p_mc = mc_cb2.p_mc = d.var_relax @. mc_cb1.X = d.X[:,1] mc_cb1.h!.t1 = 0.0 mc_cb1.h!.t2 = mc_cb1.hj!.tf = mc_cb1.hj!.delT = d.time[2] mc_cb1.h!.xold1 .= d.IC_relax for q = 1:d.kmax @. mc_cb1.param[q] = d.param[1][q] end implicit_relax_h!(mc_cb1) # computes relaxation @. d.state_relax[:,1] = mc_cb1.x_mc end else if is_new_box(d) d.X0P .= d.ic(d.P) # evaluate initial condition # loads CallbackH and CallbackHJ function with correct time and prior x values @. pi_cb2.X = d.X[:,1] pi_cb2.xmid .= mid.(pi_cb1.X) pi_cb2.h!.xold1 .= d.X0P pi_cb2.h!.t1 = 0.0 pi_cb2.h!.t2 = pi_cb2.hj!.tf = pi_cb2.hj!.delT = d.time[2] @. pi_cb2.P = pi_cb2.P = d.P # run interval contractor on first step & break if solution is proven not to exist excl, incl, extd = parametric_interval_contractor(pi_cb2, d.pi_precond!, d.pi_contractor) excl && (d.integrator_states.termination_status = EMPTY; return) d.exclusion_flag = excl d.inclusion_flag = incl d.extended_division_flag = extd @. d.X[:,1] = d.pi_contractor.X # store interval values to storage array in d # generate reference point relaxations if use_relax(d) for j=1:d.np p_mid = 0.5*(lo(d.P[j]) + hi(d.P[j])) mc_cb2.pref_mc[j] = MC{d.np,NS}(p_mid, d.P[j], j) end @. mc_cb2.P = mc_cb2.P = d.P @. mc_cb2.p_mc = mc_cb2.pref_mc @. mc_cb2.p_mc = mc_cb2.pref_mc @. mc_cb2.pref_mc = mc_cb2.pref_mc @. mc_cb2.X = d.X[:,1] # evaluate initial condition d.IC_relax .= d.ic(mc_cb2.pref_mc) # loads CallbackH and CallbackHJ function with correct time and prior x values mc_cb2.h!.t1 = 0.0 mc_cb2.h!.t2 = mc_cb2.hj!.tf = mc_cb2.hj!.delT = d.time[2] @. mc_cb2.h!.xold1 = d.IC_relax # generate and save reference point relaxations gen_expansion_params!(mc_cb2) for q = 1:d.kmax @. d.param[1][q] = mc_cb2.param[q] end # generate and save relaxation at reference point implicit_relax_h!(mc_cb2) @. d.state_relax[:,1] = mc_cb2.x_mc subgradient_expansion_interval_contract!(d.state_relax[:,1], d.p, d.pL, d.pU) @. d.X[:,1] = Intv(d.state_relax[:,1]) end end if use_relax_new_pnt(d) for j = 1:d.np d.var_relax[j] = MC{d.np,NS}(d.p[j], d.P[j], j) end d.IC_relax .= d.ic(d.var_relax) # loads MC callback, CallbackH and CallbackHJ function with correct time and prior x values @. mc_cb2.p_mc = mc_cb2.p_mc = d.var_relax @. mc_cb2.X = d.X[:,1] mc_cb2.h!.t1 = 0.0 mc_cb2.h!.t2 = mc_cb2.hj!.tf = mc_cb2.hj!.delT = d.time[2] mc_cb2.h!.xold1 .= d.IC_relax for q = 1:d.kmax @. mc_cb2.param[q] = d.param[1][q] end implicit_relax_h!(mc_cb2) # computes relaxation @. d.state_relax[:,1] = mc_cb2.x_mc end end for i in 2:d.steps if is_new_box(d) @. pi_cb2.X = d.X[:, i] # load CallbackH and CallbackHJ with time and prior x @. pi_cb2.h!.xold1 = d.X[:, i-1] if i == 2 @. pi_cb2.h!.xold2 = d.X0P else @. pi_cb2.h!.xold2 = d.X[:,i-2] end pi_cb2.h!.t1 = d.time[i] pi_cb2.h!.t2 = pi_cb2.hj!.tf = d.time[i + 1] pi_cb2.hj!.delT = d.time[i + 1] - d.time[i] # run interval contractor on ith step excl, incl, extd = parametric_interval_contractor(pi_cb2, d.pi_precond!, d.pi_contractor) excl && (d.integrator_states.termination_status = EMPTY; return) d.exclusion_flag = excl d.inclusion_flag = incl d.extended_division_flag = extd @. d.X[:,i] = d.pi_contractor.X if use_relax(d) # loads CallbackH and CallbackHJ function with correct time and prior x values mc_cb1.h!.t1 = 0.0 mc_cb1.h!.t2 = mc_cb1.hj!.tf = mc_cb1.hj!.delT = d.time[2] @. mc_cb1.h!.xold1 = d.IC_relax # generate and save reference point relaxations gen_expansion_params!(mc_cb1) for q = 1:d.kmax @. d.param[i][q] = mc_cb1.param[q] end # generate and save relaxation at reference point implicit_relax_h!(mc_cb1) @. d.state_relax[:,i] = mc_cb1.x_mc subgradient_expansion_interval_contract!(d.state_relax[:,i], d.p, d.pL, d.pU) @. d.X[:,i] = Intv(d.state_relax[:,i]) # update interval bounds for state relaxation... end end if use_relax_new_pnt(d) # loads MC callback, CallbackH and CallbackHJ with correct time and prior x values @. mc_cb2.X = d.X[:,i] @. mc_cb2.h!.xold1 = d.state_relax[:, i-1] if i == 2 @. mc_cb2.h!.xold2 = d.IC_relax else @. mc_cb2.h!.xold2 = d.state_relax[:,i-2] end mc_cb2.h!.t1 = d.time[i] mc_cb2.h!.t2 = mc_cb2.hj!.tf = d.time[i+1] mc_cb2.hj!.delT = d.time[i+1] - d.time[i] for q = 1:d.kmax @. mc_cb2.param[q] = d.param[i][q] end # computes relaxation implicit_relax_h!(mc_cb2) @. d.state_relax[:, i] = mc_cb2.x_mc end end # unpack interval bounds to integrator bounds & set evaluation flags if !use_relax(d) map!(lo, d.xL, d.X) map!(hi, d.xU, d.X) else map!(lo, d.xL, d.state_relax) map!(hi, d.xU, d.state_relax) end d.integrator_states.new_decision_box = false d.integrator_states.new_decision_pnt = false return end function DBB.integrate!(d::Wilhelm2019, p::ODERelaxProb) local_integrator() = state_contractor_integrator(d.integrator_type) local_prob_storage = DBB.get(d, DBB.LocalIntegrator())::ODELocalIntegrator local_prob_storage.integrator = local_integrator local_prob_storage.adaptive_solver = false local_prob_storage.user_t = d.time DBB.getall!(local_prob_storage.p, d, ParameterValue()) local_prob_storage.pduals .= DBB.seed_duals(Val(length(local_prob_storage.p)), local_prob_storage.p) local_prob_storage.x0duals = p.x0(d.local_problem_storage.pduals) solution_t = DBB.integrate!(Val(DBB.get(d, DBB.LocalSensitivityOn())), d, p) empty!(local_prob_storage.local_t_dict_flt) empty!(local_prob_storage.local_t_dict_indx) for (tindx, t) in enumerate(solution_t) local_prob_storage.local_t_dict_flt[t] = tindx end if !isempty(local_prob_storage.user_t) next_support_time = local_prob_storage.user_t[1] supports_left = length(local_prob_storage.user_t) loc_count = 1 for (tindx, t) in enumerate(solution_t) if t == next_support_time local_prob_storage.local_t_dict_indx[loc_count] = tindx loc_count += 1 supports_left -= 1 if supports_left > 0 next_support_time = local_prob_storage.user_t[loc_count] end end end end return end DBB.supports(::Wilhelm2019, ::DBB.IntegratorName) = true DBB.supports(::Wilhelm2019, ::DBB.Gradient) = true DBB.supports(::Wilhelm2019, ::DBB.Subgradient) = true DBB.supports(::Wilhelm2019, ::DBB.Bound) = true DBB.supports(::Wilhelm2019, ::DBB.Relaxation) = true DBB.supports(::Wilhelm2019, ::DBB.IsNumeric) = true DBB.supports(::Wilhelm2019, ::DBB.IsSolutionSet) = true DBB.supports(::Wilhelm2019, ::DBB.TerminationStatus) = true DBB.supports(::Wilhelm2019, ::DBB.Value) = true DBB.supports(::Wilhelm2019, ::DBB.ParameterValue) = true DBB.supports(::Wilhelm2019, ::DBB.ConstantStateBounds) = true DBB.get(t::Wilhelm2019, v::DBB.IntegratorName) = "Wilhelm 2019 Integrator" DBB.get(t::Wilhelm2019, v::DBB.IsNumeric) = true DBB.get(t::Wilhelm2019, v::DBB.IsSolutionSet) = false DBB.get(t::Wilhelm2019, s::DBB.TerminationStatus) = t.integrator_states.termination_status DBB.get(t::Wilhelm2019, s::DBB.ParameterNumber) = t.np DBB.get(t::Wilhelm2019, s::DBB.StateNumber) = t.nx DBB.get(t::Wilhelm2019, s::DBB.SupportNumber) = length(t.time) DBB.get(t::Wilhelm2019, s::DBB.AttachedProblem) = t.prob function DBB.set!(t::Wilhelm2019, v::ConstantStateBounds) t.constant_state_bounds = v return end function DBB.get(t::Wilhelm2019, v::DBB.LocalIntegrator) return t.local_problem_storage end function DBB.getall!(out::Array{Float64,2}, t::Wilhelm2019, v::DBB.Value) out .= t.local_problem_storage.pode_x return end function DBB.getall!(out::Vector{Array{Float64,2}}, t::Wilhelm2019, g::DBB.Gradient{Lower}) if ~t.differentiable_flag error("Integrator does not generate differential relaxations. Set the differentiable_flag field to true and reintegrate.") end for i in 1:t.np if t.evaluate_interval fill!(out[i], 0.0) else for j in eachindex(out[i]) out[i][j] = t.state_relax[j].cv_grad[i] end end end return end function DBB.getall!(out::Vector{Array{Float64,2}}, t::Wilhelm2019, g::DBB.Gradient{Upper}) if ~t.differentiable_flag error("Integrator does not generate differential relaxations. Set the differentiable_flag field to true and reintegrate.") end for i in 1:t.np if t.evaluate_interval fill!(out[i], 0.0) else @inbounds for j in eachindex(out[i]) out[i][j] = t.state_relax[j].cc_grad[i] end end end return end function DBB.getall!(out::Vector{Array{Float64,2}}, t::Wilhelm2019, g::DBB.Subgradient{Lower}) for i in 1:t.np if t.evaluate_interval fill!(out[i], 0.0) else @inbounds for j in eachindex(out[i]) out[i][j] = t.state_relax[j].cv_grad[i] end end end return end function DBB.getall!(out::Vector{Array{Float64,2}}, t::Wilhelm2019, g::DBB.Subgradient{Upper}) for i in 1:t.np if t.evaluate_interval fill!(out[i], 0.0) else @inbounds for j in eachindex(out[i]) out[i][j] = t.state_relax[j].cc_grad[i] end end end return end function DBB.getall!(out::Array{Float64,2}, t::Wilhelm2019, v::DBB.Bound{Lower}) for i in 1:t.nx out[i,1] = t.X0P[i].lo end out[:,2:end] .= t.xL return end function DBB.getall!(out::Vector{Float64}, t::Wilhelm2019, v::DBB.Bound{Lower}) out[:] = t.xL[1,:] return end function DBB.getall!(out::Array{Float64,2}, t::Wilhelm2019, v::DBB.Bound{Upper}) for i in 1:t.nx out[i,1] = t.X0P[i].hi end out[:,2:end] .= t.xU return end function DBB.getall!(out::Vector{Float64}, t::Wilhelm2019, v::DBB.Bound{Upper}) out[:] = t.xU[1,:] return end function DBB.getall!(out::Array{Float64,2}, t::Wilhelm2019, v::DBB.Relaxation{Lower}) if t.evaluate_interval @inbounds for i in eachindex(out) out[i] = t.X[i].lo end else @inbounds for i in eachindex(out) out[i] = t.state_relax[i].cv end end return end function DBB.getall!(out::Vector{Float64}, t::Wilhelm2019, v::DBB.Relaxation{Lower}) if t.evaluate_interval @inbounds for i in eachindex(out) out[i] = t.X[i].lo end else @inbounds for i in eachindex(out) out[i] = t.state_relax[i].cv end end return end function DBB.getall!(out::Array{Float64,2}, t::Wilhelm2019, v::DBB.Relaxation{Upper}) if t.evaluate_interval @inbounds for i in eachindex(out) out[i] = t.X[i].hi end else @inbounds for i in eachindex(out) out[i] = t.state_relax[i].cc end end return end function DBB.getall!(out::Vector{Float64}, t::Wilhelm2019, v::DBB.Relaxation{Upper}) if t.evaluate_interval @inbounds for i in eachindex(out) out[i] = t.X[i].hi end else @inbounds for i in eachindex(out) out[i] = t.state_relax[i].cc end end return end function DBB.getall!(t::Wilhelm2019, v::DBB.ParameterBound{Lower}) @inbounds for i in 1:t.np out[i] = t.pL[i] end return end DBB.getall(t::Wilhelm2019, v::DBB.ParameterBound{Lower}) = t.pL function DBB.getall!(out, t::Wilhelm2019, v::DBB.ParameterBound{Upper}) @inbounds for i in 1:t.np out[i] = t.pU[i] end return end DBB.getall(t::Wilhelm2019, v::DBB.ParameterBound{Upper}) = t.pU function DBB.setall!(t::Wilhelm2019, v::DBB.ParameterBound{Lower}, value::Vector{Float64}) t.integrator_states.new_decision_box = true @inbounds for i in 1:t.np t.pL[i] = value[i] end return end function DBB.setall!(t::Wilhelm2019, v::DBB.ParameterBound{Upper}, value::Vector{Float64}) t.integrator_states.new_decision_box = true @inbounds for i in 1:t.np t.pU[i] = value[i] end return end function DBB.setall!(t::Wilhelm2019, v::DBB.ParameterValue, value::Vector{Float64}) t.integrator_states.new_decision_pnt = true @inbounds for i in 1:t.np t.p[i] = value[i] end return end function DBB.getall!(out, t::Wilhelm2019, v::DBB.ParameterValue) @inbounds for i in 1:t.np out[i] = t.p[i] end return end function DBB.setall!(t::Wilhelm2019, v::DBB.Bound{Lower}, values::Array{Float64,2}) if t.integrator_states.new_decision_box t.integrator_states.set_lower_state = true end for i in 1:t.nx @inbounds for j in 1:t.steps t.xL[i,j] = values[i,j] end end return end function DBB.setall!(t::Wilhelm2019, v::DBB.Bound{Lower}, values::Vector{Float64}) if t.integrator_states.new_decision_box t.integrator_states.set_lower_state = true end @inbounds for i in 1:t.steps t.xL[1,i] = values[i] end return end function DBB.setall!(t::Wilhelm2019, v::DBB.Bound{Upper}, values::Array{Float64,2}) if t.integrator_states.new_decision_box t.integrator_states.set_upper_state = true end for i in 1:t.nx @inbounds for j in 1:t.steps t.xU[i,j] = values[i,j] end end return end function DBB.setall!(t::Wilhelm2019, v::DBB.Bound{Upper}, values::Vector{Float64}) if t.integrator_states.new_decision_box t.integrator_states.set_upper_state = true end @inbounds for i in 1:t.steps t.xU[1,i] = values[i] end return end DBB.get(t::Wilhelm2019, v::DBB.SupportSet{T}) where T = DBB.get(t.prob, v) DBB.get(t::Wilhelm2019, v::DBB.LocalSensitivityOn) = t.calculate_local_sensitivity function DBB.set!(t::Wilhelm2019, v::DBB.LocalSensitivityOn, b::Bool) t.calculate_local_sensitivity = b end function DBB.get!(out, t::Wilhelm2019, v::DBB.Bound{Lower}) vi = get_val_loc(t, v.index, v.time) if vi <= 1 return t.evaluate_interval ? map!(lo, out, t.X0P) : map!(lo, out, t.IC_relax) end if t.evaluate_interval out .= view(t.xL, :, vi - 1) else map!(lo, out, view(t.state_relax, :, vi - 1)) end end function DBB.get!(out, t::Wilhelm2019, v::DBB.Bound{Upper}) vi = get_val_loc(t, v.index, v.time) if vi <= 1 return t.evaluate_interval ? map!(hi, out, t.X0P) : map!(hi, out, t.IC_relax) end if t.evaluate_interval out .= view(t.xU, :, vi - 1) else map!(hi, out, view(t.state_relax, :, vi - 1)) end end function DBB.get!(out, t::Wilhelm2019, v::DBB.Relaxation{Lower}) vi = get_val_loc(t, v.index, v.time) if vi <= 1 return t.evaluate_interval ? map!(lo, out, t.X0P) : map!(cv, out, t.IC_relax) end if t.evaluate_interval out .= view(t.xL, :, vi - 1) else map!(cv, out, view(t.state_relax, :, vi - 1)) end end function DBB.get!(out, t::Wilhelm2019, v::DBB.Relaxation{Upper}) vi = get_val_loc(t, v.index, v.time) if vi <= 1 return t.evaluate_interval ? map!(hi, out, t.X0P) : map!(cc, out, t.IC_relax) end if t.evaluate_interval out .= view(t.xU, :, vi - 1) else map!(cc, out, view(t.state_relax, :, vi - 1)) end end function DBB.get!(out, t::Wilhelm2019, v::DBB.Subgradient{Lower}) vi = get_val_loc(t, v.index, v.time) t.evaluate_interval && (return fill!(out, 0.0);) ni, nj = size(out) if vi <= 1 for i = 1:ni, j = 1:nj out[i, j] = t.IC_relax[i].cv_grad[j] end else for i = 1:ni, j = 1:nj out[i, j] = t.state_relax[i,vi-1].cv_grad[j] end end end function DBB.get!(out, t::Wilhelm2019, v::DBB.Subgradient{Upper}) vi = get_val_loc(t, v.index, v.time) t.evaluate_interval && (return fill!(out, 0.0);) ni, nj = size(out) if vi <= 1 for i = 1:ni, j = 1:nj out[i, j] = t.IC_relax[i].cc_grad[j] end else for i = 1:ni, j = 1:nj out[i, j] = t.state_relax[i,vi-1].cc_grad[j] end end end """ $(FUNCTIONNAME) Returns true if X1 and X2 are equal to within tolerance atol in all dimensions. """ function is_equal(X1::S, X2::Vector{Interval{Float64}}, atol::Float64, nx::Int) where S out::Bool = true @inbounds for i=1:nx if (abs(X1[i].lo - X2[i].lo) >= atol || abs(X1[i].hi - X2[i].hi) >= atol ) out = false break end end return out end """ $(FUNCTIONNAME) Returns true if X is strictly in Y (X.lo>Y.lo && X.hi<Y.hi). """ function strict_x_in_y(X::Interval{Float64}, Y::Interval{Float64}) (X.lo <= Y.lo) && return false (X.hi >= Y.hi) && return false return true end """ $(FUNCTIONNAME) """ function inclusion_test(inclusion_flag::Bool, inclusion_vector::Vector{Bool}, nx::Int) if !inclusion_flag for i=1:nx if @inbounds inclusion_vector[i] inclusion_flag = true else inclusion_flag = false; break end end end return inclusion_flag end """ $(FUNCTIONNAME) Subfunction to generate output for extended division. """ function extended_divide(A::Interval{Float64}) if (A.lo == -0.0) && (A.hi == 0.0) B::Interval{Float64} = Interval{Float64}(-Inf,Inf) C::Interval{Float64} = B return 0,B,C elseif (A.lo == 0.0) B = Interval{Float64}(1.0/A.hi,Inf) C = Interval{Float64}(Inf,Inf) return 1,B,C elseif (A.hi == 0.0) B = Interval{Float64}(-Inf,1.0/A.lo) C = Interval{Float64}(-Inf,-Inf) return 2,B,C else B = Interval{Float64}(-Inf,1.0/A.lo) C = Interval{Float64}(1.0/A.hi,Inf) return 3,B,C end end """ $(FUNCTIONNAME) Generates output boxes for extended division and flag. """ function extended_process(N::Interval{Float64}, X::Interval{Float64}, Mii::Interval{Float64}, SB::Interval{Float64}, rtol::Float64) Ntemp = Interval{Float64}(N.lo, N.hi) M = SB + Interval{Float64}(-rtol, rtol) if (M.lo <= 0) && (M.hi >= 0) return 0, Interval{Float64}(-Inf,Inf), Ntemp end k, IML, IMR = extended_divide(Mii) if (k === 1) NL = 0.5*(X.lo+X.hi) - M*IML return 0, NL, Ntemp elseif (k === 2) NR = 0.5*(X.lo+X.hi) - M*IMR return 0, NR, Ntemp elseif (k === 3) NR = 0.5*(X.lo+X.hi) - M*IMR NL = 0.5*(X.lo+X.hi) - M*IML if ~isdisjoint(NL,X) && isdisjoint(NR,X) return 0, NL, Ntemp elseif ~isdisjoint(NR,X) && isdisjoint(NL,X) return 0, NR, Ntemp elseif ~isdisjoint(NL,X) && ~isdisjoint(NR,X) N = NL Ntemp = NR return 1, NL, NR else return -1, N, Ntemp end end return 0, N, Ntemp end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
18181
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/utilities/access_functions.jl # Defines methods to access attributes via DynamicBoundsBase interface. ############################################################################# DBB.supports(::DiscretizeRelax, ::DBB.IntegratorName) = true DBB.supports(::DiscretizeRelax, ::DBB.Subgradient{T}) where {T <: AbstractBoundLoc} = true DBB.supports(::DiscretizeRelax, ::DBB.Bound{T}) where {T <: AbstractBoundLoc} = true DBB.supports(::DiscretizeRelax, ::DBB.Relaxation{T}) where {T <: AbstractBoundLoc} = true DBB.supports(::DiscretizeRelax, ::DBB.IsNumeric) = true DBB.supports(::DiscretizeRelax, ::DBB.IsSolutionSet) = true DBB.supports(::DiscretizeRelax, ::DBB.TerminationStatus) = true DBB.supports(::DiscretizeRelax, ::DBB.Value) = true DBB.supports(::DiscretizeRelax, ::DBB.ParameterBound{Lower}) = true DBB.supports(::DiscretizeRelax, ::DBB.ParameterBound{Upper}) = true DBB.supports(::DiscretizeRelax, ::DBB.ParameterValue) = true DBB.supports(::DiscretizeRelax, ::DBB.SupportSet) = true DBB.supports(::DiscretizeRelax, ::DBB.ParameterNumber) = true DBB.supports(::DiscretizeRelax, ::DBB.StateNumber) = true DBB.supports(::DiscretizeRelax, ::DBB.SupportNumber) = true DBB.supports(t::DiscretizeRelax, ::DBB.LocalSensitivityOn) = t.calculate_local_sensitivity function get_val_loc(t::DiscretizeRelax, index::Int64, time::Float64) (index <= 0 && time == -Inf) && error("Must set either index or time.") if index > 0 return t.relax_t_dict_indx[index] end t.relax_t_dict_flt[time] end function get_val_loc_local(t::DiscretizeRelax, index::Int64, time::Float64) (index <= 0 && time == -Inf) && error("Must set either index or time.") if index > 0 return t.local_t_dict_indx[index] end t.local_t_dict_flt[time] end DBB.get(t::DiscretizeRelax, v::DBB.IntegratorName) = "Discretize & Relax Integrator" # TO DO... FIX ME DBB.get(t::DiscretizeRelax, v::DBB.IsNumeric) = false # TO DO... FIX ME DBB.get(t::DiscretizeRelax, v::DBB.IsSolutionSet) = true DBB.get(t::DiscretizeRelax, v::DBB.TerminationStatus) = t.error_code DBB.get(t::DiscretizeRelax, v::DBB.SupportSet) = DBB.SupportSet(t.tsupports) DBB.get(t::DiscretizeRelax, v::DBB.ParameterNumber) = t.np DBB.get(t::DiscretizeRelax, v::DBB.StateNumber) = t.nx DBB.get(t::DiscretizeRelax, v::DBB.SupportNumber) = length(t.tsupports) DBB.get(t::DiscretizeRelax, v::DBB.LocalSensitivityOn) = t.calculate_local_sensitivity DBB.getall(t::DiscretizeRelax, v::DBB.ParameterBound{Lower}) = t.pL DBB.getall(t::DiscretizeRelax, v::DBB.ParameterBound{Upper}) = t.pU function DBB.set!(t::DiscretizeRelax, v::DBB.LocalSensitivityOn, q::Bool) t.calculate_local_sensitivity = q return end function DBB.set!(t::DiscretizeRelax, v::DBB.ConstantStateBounds) t.constant_state_bounds = v set_constant_state_bounds!(t.method_f!, v) t.exist_result.constant_state_bounds = v return end function DBB.set!(t::DiscretizeRelax, v::DBB.SupportSet) t.time = v.s t.tsupports = v.s nothing end ## Setting problem attributes function DBB.setall!(t::DiscretizeRelax, v::ParameterBound{Lower}, value::Vector{Float64}) t.new_decision_box = true @inbounds for i in 1:t.np t.pL[i] = value[i] end return end function DBB.setall!(t::DiscretizeRelax, v::ParameterBound{Upper}, value::Vector{Float64}) t.new_decision_box = true @inbounds for i in 1:t.np t.pU[i] = value[i] end return end function DBB.setall!(t::DiscretizeRelax, v::ParameterValue, value::Vector{Float64}) t.new_decision_pnt = true @inbounds for i in 1:t.np t.p[i] = value[i] end return end function DBB.getall!(out::Vector{Float64}, t::DiscretizeRelax, v::DBB.ParameterValue) out .= t.p[1:t.np] return end function DBB.getall!(out::Array{Float64,2}, t::DiscretizeRelax, v::DBB.Value) copyto!(out, t.local_problem_storage.pode_x) return end function DBB.get(out::Vector{Float64}, t::DiscretizeRelax, v::DBB.Value) val_loc = get_val_loc_local(t, v.index, v.time) out .= t.local_problem_storage.pode_x[:, val_loc] return end ## Inplace integrator acccess functions function DBB.getall!(out::Vector{Matrix{Float64}}, t::DiscretizeRelax{X,T}, ::DBB.Subgradient{Lower}) where {X, T <: AbstractInterval} for i in 1:t.np fill!(out[i], 0.0) end return end function DBB.getall!(out::Vector{Matrix{Float64}}, t::DiscretizeRelax{X,T}, ::DBB.Subgradient{Lower}) where {X, T <: MC} for i = 1:length(t.storage) for j = 1:t.np for k = 1:t.nx out[j][k,i]= t.storage[i][k].cv_grad[j] end end end return end function DBB.getall!(out::Vector{Matrix{Float64}}, t::DiscretizeRelax{X,T}, ::DBB.Subgradient{Upper}) where {X, T <: AbstractInterval} for i in 1:t.np fill!(out[i], 0.0) end return end function DBB.getall!(out::Vector{Matrix{Float64}}, t::DiscretizeRelax{X,T}, ::DBB.Subgradient{Upper}) where {X, T <: MC} for i = 1:length(t.storage) for j = 1:t.np for k = 1:t.nx out[j][k,i]= t.storage[i][k].cc_grad[j] end end end return end function DBB.get(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Subgradient{Lower}) where {X, T <: AbstractInterval} fill!(out, 0.0) return end function DBB.get(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Subgradient{Upper}) where {X, T <: AbstractInterval} fill!(out, 0.0) return end function DBB.get(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Subgradient{Lower}) where {X, T <: MC} val_loc = get_val_loc(t, v.index, v.time) for i = 1:t.np for j = 1:t.nx out[j,i] = t.relax_cv_grad[j,val_loc][i] end end return end function DBB.get(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Subgradient{Upper}) where {X, T <: MC} val_loc = get_val_loc(t, v.index, v.time) for i = 1:t.np for j = 1:t.nx out[j,i] = t.relax_cc_grad[j,val_loc][i] end end return end function DBB.getall!(out::Vector{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Bound{Lower}) where {X, T <: AbstractInterval} @inbounds for j in eachindex(out) out[j] = t.storage[j][1].lo end return end function DBB.getall!(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Bound{Lower}) where {X, T <: AbstractInterval} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) for i = 1:dims[1] for j = 1:dims[2] out[j,i] = t.storage[i][j].lo end end return end function DBB.getall!(out::Vector{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Bound{Upper}) where {X, T <: AbstractInterval} @inbounds for j in eachindex(out) out[j] = t.storage[j][1].hi end return end function DBB.getall!(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Bound{Upper}) where {X, T <: AbstractInterval} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].hi end end return end function DBB.getall!(out::Vector{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Bound{Lower}) where {X, T <: MC} @inbounds for j in eachindex(out) out[j] = t.storage[j][1].Intv.lo end return end function DBB.getall!(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Bound{Lower}) where {X, T <: MC} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].Intv.lo end end return end function DBB.getall!(out::Vector{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Bound{Upper}) where {X, T <: MC} @inbounds for j in eachindex(out) out[j] = t.storage[j][1].Intv.hi end return end function DBB.getall!(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Bound{Upper}) where {X, T <: MC} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].Intv.hi end end return end function DBB.getall!(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Lower}) where {X, T <: AbstractInterval} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].lo end end return end function DBB.getall!(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Lower}) where {X, T <: MC} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].cv end end return end function DBB.getall!(out::Vector{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Lower}) where {X, T <: AbstractInterval} @inbounds for j in eachindex(out) out[j] = t.storage[j][1].lo end return end function DBB.getall!(out::Vector{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Lower}) where {X, T <: MC} @inbounds for j in eachindex(out) out[j] = t.storage[j][1].cv end return end function DBB.getall!(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Upper}) where {X, T <: AbstractInterval} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].hi end end return end function DBB.getall!(out::Matrix{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Upper}) where {X, T <: MC} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].cc end end return end function DBB.getall!(out::Vector{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Upper}) where {X, T <: AbstractInterval} @inbounds for j in eachindex(out) out[j] = t.storage[j][1].hi end return end function DBB.getall!(out::Vector{Float64}, t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Upper}) where {X, T <: MC} @inbounds for j in eachindex(out) out[j] = t.storage[j][1].cc end return end ## Out of place integrator acccess functions function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Subgradient{Lower}) where {X, T <: AbstractInterval} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = Matrix{Float64}[] for i = 1:t.np push!(out, zeros(Float64, dims[2], dims[1])) end out end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Subgradient{Lower}) where {X, T <: MC} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = Matrix{Float64}[] for i = 1:t.np push!(out, zeros(Float64, dims[2], dims[1])) for j = 1:dims[1] for k = 1:dims[2] out[i][k, j] = t.storage[j][k].cv_grad[i] end end end out end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Subgradient{Upper}) where {X, T <: AbstractInterval} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = Matrix{Float64}[] for i = 1:t.np push!(out, zeros(Float64, dims[2], dims[1])) end out end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Subgradient{Upper}) where {X, T <: MC} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = Matrix{Float64}[] for i = 1:t.np push!(out, zeros(Float64, dims[2], dims[1])) for j = 1:dims[1] for k = 1:dims[2] out[i][k, j] = t.storage[j][k].cc_grad[i] end end end out end function DBB.get!(out::Vector{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Bound{Lower}) where {X, T <: AbstractInterval} val_loc = get_val_loc(t, v.index, v.time) @__dot__ out = lo(t.storage[val_loc]) return end function DBB.get!(out::Vector{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Bound{Upper}) where {X, T <: AbstractInterval} val_loc = get_val_loc(t, v.index, v.time) @__dot__ out = hi(t.storage[val_loc]) return end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Bound{Lower}) where {X, T <: AbstractInterval} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = zeros(Float64, dims[2], dims[1]) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].lo end end out end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Bound{Upper}) where {X, T <: AbstractInterval} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = zeros(Float64, dims[2], dims[1]) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].hi end end out end function DBB.get(out::Vector{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Bound{Lower}) where {X, T <: MC} val_loc = get_val_loc_local(t, v.index, v.time) @__dot__ out = lo(t.storage[val_loc]) return end function DBB.get(out::Vector{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Bound{Upper}) where {X, T <: MC} val_loc = get_val_loc_local(t, v.index, v.time) @__dot__ out = hi(t.storage[val_loc]) return end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Bound{Lower}) where {X, T <: MC} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = zeros(Float64, dims[2], dims[1]) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].Intv.lo end end out end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Bound{Upper}) where {X, T <: MC} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = zeros(Float64, dims[2], dims[1]) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].Intv.hi end end out end function DBB.get(out::Vector{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Relaxation{Lower}) where {X, T <: MC} val_loc = get_val_loc(t, v.index, v.time) @__dot__ out = cv(t.storage[val_loc]) return end function DBB.get(out::Vector{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Relaxation{Upper}) where {X, T <: MC} val_loc = get_val_loc(t, v.index, v.time) @__dot__ out = cc(t.storage[val_loc]) return end function DBB.get(out::Vector{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Relaxation{Lower}) where {X, T <: AbstractInterval} val_loc = get_val_loc(t, v.index, v.time) @__dot__ out = lo(t.storage[val_loc]) return end function DBB.get(out::Vector{Float64}, t::DiscretizeRelax{X,T}, v::DBB.Relaxation{Upper}) where {X, T <: AbstractInterval} val_loc = get_val_loc(t, v.index, v.time) @__dot__ out = hi(t.storage[val_loc]) return end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Lower}) where {X, T <: AbstractInterval} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = zeros(Float64, dims[2], dims[1]) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].lo end end out end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Lower}) where {X, T <: MC} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = zeros(Float64, dims[2], dims[1]) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].cv end end out end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Upper}) where {X, T <: AbstractInterval} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = zeros(Float64, dims[2], dims[1]) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].hi end end out end function DBB.getall(t::DiscretizeRelax{X,T}, ::DBB.Relaxation{Upper}) where {X, T <: MC} dims = length(t.storage), length(t.storage[1]) (length(dims) == 1) && (dims = (dims[1],1)) out = zeros(Float64, dims[2], dims[1]) for i = 1:dims[1] for j = 1:dims[2] out[j, i] = t.storage[i][j].cc end end out end function DBB.get(t::DiscretizeRelax{X,T}, v::DBB.LocalIntegrator) where {X, T} return t.local_problem_storage end DBB.get(t::DiscretizeRelax{X,T}, v::DBB.AttachedProblem) where {X, T} = t.prob
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
3765
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/utilities/coeffs_calcs.jl # Defines functions used to compute taylor coefficients using static # univariate Taylor series. ############################################################################# @generated function truncuated_STaylor1(x::STaylor1{N,T}, v::Int) where {N,T} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] for i = 1:N sym = syms[i] ex_line = :($(sym) = $i <= v ? x[$(i-1)] : zero($T)) ex_calc.args[i] = ex_line end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout) end end @generated function copy_recurse(dx::STaylor1{N,T}, x::STaylor1{N,T}, ord::Int, ford::Float64) where {N,T} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:(N+1)]) syms = Symbol[Symbol("c$i") for i in 1:N] ex_line = :(nv = dx[ord-1]/ford) #/ord) ex_calc.args[1] = ex_line for i = 0:(N-1) sym = syms[i+1] ex_line = :($(sym) = $i < ord ? x[$i] : (($i == ord) ? nv : zero(T))) # nv)) ex_calc.args[i+2] = ex_line end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout) end end """ $(TYPEDSIGNATURES) A variant of the jetcoeffs! function used in TaylorIntegration.jl (https://github.com/PerezHz/TaylorIntegration.jl/blob/master/src/explicitode.jl) which preallocates taux and updates taux coefficients to avoid further allocations. The TaylorIntegration.jl package is licensed under the MIT "Expat" License: Copyright (c) 2016-2020: Jorge A. Perez and Luis Benet. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. """ function jetcoeffs!(eqsdiff!, t::T, x::Vector{STaylor1{N,U}}, xaux::Vector{STaylor1{N,U}}, dx::Vector{STaylor1{N,U}}, order::Int, params, vnxt::Vector{Int}, fnxt::Vector{Float64}) where {N, T<:Number, U<:Number} ttaylor = STaylor1(t, Val{N-1}()) for ord = 1:order fill!(vnxt, ord) fill!(fnxt, Float64(ord)) map!(truncuated_STaylor1, xaux, x, vnxt) eqsdiff!(dx, xaux, params, ttaylor) x .= copy_recurse.(dx, x, vnxt, fnxt) end nothing end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
8963
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/utilities/discretize_relax.jl # Defines the structure used to compute bounds/relaxations via a discretize # and relax approach. ############################################################################# """ DiscretizeRelax An integrator for discretize and relaxation techniques. $(TYPEDFIELDS) """ Base.@kwdef mutable struct DiscretizeRelax{M <: AbstractStateContractor, T <: Number, S <: Real, F, K, X, NY, JX, JP, INT, N} <: AbstractODERelaxIntegrator # Problem description "Initial Condition for pODEs" x0f::X "Jacobian w.r.t x" Jx!::JX "Jacobian w.r.t p" Jp!::JP "Parameter value for pODEs" p::Vector{Float64} "Lower Parameter Bounds for pODEs" pL::Vector{Float64} "Upper Parameter Bounds for pODEs" pU::Vector{Float64} "Number of state variables" nx::Int "Number of decision variables" np::Int "Time span to integrate over" tspan::Tuple{Float64, Float64} "Individual time points to evaluate" tsupports::Vector{Float64} next_support_i::Int = -1 next_support::Float64 = -Inf # Options and internal storage "Maximum number of integration steps" step_limit::Int = 500 "Steps taken" step_count::Int = 0 "Stores solution X (from step 2) for each time" storage::Vector{Vector{T}} "Stores solution X (from step 1) for each time" storage_apriori::Vector{Vector{T}} "Stores each time t" time::Vector{Float64} = zeros(Float64, 200) "Support index to storage dictory" support_dict::Dict{Int,Int} = Dict{Int,Int}() "Holds data for numeric error encountered in integration step" error_code::TerminationStatusCode = RELAXATION_NOT_CALLED "Storage for bounds/relaxation of P" P::Vector{T} "Storage for bounds/relaxation of P - p" rP::Vector{T} "Relaxation Type" style::T "Flag indicating that only apriori bounds should be computed" skip_step2::Bool = false storage_buffer_size::Int = 500 print_relax_time::Bool = false # Main functions used in routines "Functor for evaluating Taylor coefficients over a set" set_tf!::TaylorFunctor!{F,K,S,T} method_f!::M exist_result::ExistStorage{F,K,S,T} contractor_result::ContractorStorage{T} step_result::StepResult{T} step_params::StepParams new_decision_pnt::Bool = true new_decision_box::Bool = true relax_t_dict_indx::Dict{Int,Int} = Dict{Int,Int}() relax_t_dict_flt::Dict{Float64,Int} = Dict{Float64,Int}() calculate_local_sensitivity::Bool = false local_problem_storage constant_state_bounds::Union{Nothing,ConstantStateBounds} polyhedral_constraint::Union{Nothing,PolyhedralConstraint} prob end function DiscretizeRelax(d::ODERelaxProb, m::SCN; repeat_limit = 1, tol = 1E-4, hmin = 1E-13, relax = false, h = 0.0, J_x! = nothing, J_p! = nothing, storage_buffer_size = 200, skip_step2 = false, atol = 1E-5, rtol = 1E-5, print_relax_time = true, kwargs...) where SCN <: AbstractStateContractorName Jx! = isnothing(J_x!) ? d.Jx! : J_x! Jp! = isnothing(J_p!) ? d.Jp! : J_p! γ = state_contractor_γ(m)::Float64 k = state_contractor_k(m)::Int method_steps = state_contractor_steps(m)::Int tsupports = d.support_set.s T = relax ? MC{d.np,NS} : Interval{Float64} style = zero(T) storage = Vector{T}[] storage_apriori = Vector{T}[] for i = 1:storage_buffer_size push!(storage, zeros(T, d.nx)) push!(storage_apriori, zeros(T, d.nx)) end P = zeros(T, d.np) rP = zeros(T, d.np) Δ = FixedCircularBuffer{Vector{T}}(method_steps) A_Q = FixedCircularBuffer{Matrix{Float64}}(method_steps) A_inv = FixedCircularBuffer{Matrix{Float64}}(method_steps) for i = 1:method_steps push!(Δ, zeros(T, d.nx)) push!(A_Q, Float64.(Matrix(I, d.nx, d.nx))) push!(A_inv, Float64.(Matrix(I, d.nx, d.nx))) end state_method = state_contractor(m, d.f, Jx!, Jp!, d.nx, d.np, style, zero(Float64), h) set_tf! = TaylorFunctor!(d.f, d.nx, d.np, Val(k), style, zero(Float64)) is_adaptive = (h <= 0.0) contractor_result = ContractorStorage(style, d.nx, d.np, k, h, method_steps) contractor_result.γ = γ contractor_result.P = P contractor_result.rP = rP contractor_result.is_adaptive = is_adaptive local_integrator = state_contractor_integrator(m) return DiscretizeRelax{typeof(state_method), T, Float64, typeof(d.f), k+1,typeof(d.x0), d.nx + d.np, typeof(Jx!), typeof(Jp!), typeof(local_integrator), d.np}( x0f = d.x0, Jx! = Jx!, Jp! = Jp!, p = d.p, pL = d.pL, pU = d.pU, nx = d.nx, np = d.np, tspan = d.tspan, tsupports = tsupports, storage = storage, storage_apriori = storage_apriori, P = P, rP = rP, style = style, set_tf! = set_tf!, method_f! = state_method, exist_result = ExistStorage(set_tf!, style, P, d.nx, d.np, k, h, method_steps), contractor_result = contractor_result, step_result = StepResult{typeof(style)}(zeros(d.nx), zeros(typeof(style), d.nx), A_Q, A_inv, Δ, 0.0, 0.0), step_params = StepParams(atol, rtol, hmin, repeat_limit, is_adaptive, skip_step2), local_problem_storage = ODELocalIntegrator(d, local_integrator), constant_state_bounds = d.constant_state_bounds, polyhedral_constraint = d.polyhedral_constraint, prob = d, storage_buffer_size = storage_buffer_size, skip_step2 = skip_step2, print_relax_time = print_relax_time) end DiscretizeRelax(d::ODERelaxProb; kwargs...) = DiscretizeRelax(d, LohnerContractor{4}(); kwargs...) """ set_P!(d::DiscretizeRelax) Initializes the `P` and `rP` (P - p) fields of `d`. """ function set_P!(d::DiscretizeRelax{M,Interval{Float64},S,F,K,X,NY}) where {M<:AbstractStateContractor, S, F, K, X, NY} @unpack p, pL, pU, P, rP = d @. P = Interval(pL, pU) @. rP = P - p nothing end function set_P!(d::DiscretizeRelax{M,MC{N,T},S,F,K,X,NY}) where {M<:AbstractStateContractor, T<:RelaxTag, S <: Real, F, K, X, N, NY} @unpack np, p, pL, pU, P, rP = d @. P = MC{N,NS}(p, Interval(pL, pU), 1:np) @. rP = P - p nothing end """ compute_X0!(d::DiscretizeRelax) Initializes the circular buffer that holds `Δ` with the `out - mid(out)` at index 1 and a zero vector at all other indices. """ function compute_X0!(d::DiscretizeRelax) @unpack relax_t_dict_indx, relax_t_dict_flt, storage, storage_apriori, tspan, x0f, P, tsupports = d storage[1] .= x0f(P) storage_apriori[1] .= storage[1] if tspan[1] ∈ tsupports relax_t_dict_indx[1] = 1 relax_t_dict_flt[tspan[1]] = 1 end d.step_result.Xⱼ .= storage[1] d.step_result.xⱼ .= mid.(d.step_result.Xⱼ) d.exist_result.Xj_0 .= d.step_result.Xⱼ d.contractor_result.Xj_0 .= d.step_result.Xⱼ d.contractor_result.xval .= mid.(d.exist_result.Xj_0) d.contractor_result.pval .= d.p nothing end """ set_Δ! Initializes the circular buffer, `Δ`, that holds `Δ_i` with the `out - mid(out)` at index 1 and a zero vector at all other indices. """ function set_Δ!(Δ::FixedCircularBuffer{Vector{T}}, out::Vector{Vector{T}}) where T Δ[1] .= out[1] .- mid.(out[1]) for i = 2:length(Δ) fill!(Δ[i], zero(T)) end return nothing end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
1048
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/utilities/fast_set_index.jl # Defines a method for setindex that avoids conversion. ############################################################################# # setindex! that avoids conversion. function setindex!(x::Vector{STaylor1{N,T}}, val::T, i::Int) where {N,T} @inbounds x[i] = STaylor1(val, Val{N-1}()) return nothing end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
2177
mutable struct FixedCircularBuffer{T} <: AbstractVector{T} capacity::Int first::Int length::Int buffer::Vector{T} FixedCircularBuffer{T}(capacity::Int) where {T} = new{T}(capacity, 1, 0, Vector{T}(undef, capacity)) end Base.@propagate_inbounds function _buffer_index_checked(cb::FixedCircularBuffer, i::Int) @boundscheck if i < 1 || i > cb.length throw(BoundsError(cb, i)) end _buffer_index(cb, i) end @inline function _buffer_index(cb::FixedCircularBuffer, i::Int) n = cb.capacity idx = cb.first + i - 1 return ifelse(idx > n, idx - n, idx) end @inline Base.@propagate_inbounds function Base.setindex!(cb::FixedCircularBuffer, data, i::Int) cb.buffer[_buffer_index_checked(cb, i)] = data return nothing end Base.size(cb::FixedCircularBuffer) = (length(cb),) Base.convert(::Type{Array}, cb::FixedCircularBuffer{T}) where {T} = T[x for x in cb] @inline Base.@propagate_inbounds function Base.getindex(cb::FixedCircularBuffer, i::Int) cb.buffer[_buffer_index_checked(cb, i)] end Base.length(cb::FixedCircularBuffer) = cb.length Base.eltype(::Type{FixedCircularBuffer{T}}) where T = T @inline function Base.push!(cb::FixedCircularBuffer, data) if cb.length == cb.capacity cb.first = (cb.first == cb.capacity ? 1 : cb.first + 1) else cb.length += 1 end @inbounds cb.buffer[_buffer_index(cb, cb.length)] = data return cb end function Base.append!(cb::FixedCircularBuffer, datavec::AbstractVector) # push at most last `capacity` items n = length(datavec) for i in max(1, n-cb.capacity+1):n push!(cb, datavec[i]) end return cb end function cycle!(cb::FixedCircularBuffer{S}) where S cb.first = (cb.first == 1 ? cb.capacity : cb.first - 1) return nothing end function cycle_copyto!(cb::FixedCircularBuffer{V}, v, indx) where V <: AbstractArray if indx > 1 cycle!(cb) end copyto!(cb[1], v) return nothing end function cycle_eval!(f!, cb::FixedCircularBuffer{S}, x, p, t) where S cycle!(cb) f!(cb[1], x, p, t) return nothing end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
6965
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/utilities/jacobian_functor.jl # Defines methods to used to compute Jacobians of Taylor coeffients. ############################################################################# """ JacTaylorFunctor! A callable structure used to evaluate the Jacobian of Taylor cofficients. This also contains some addition fields to be used as inplace storage when computing and preconditioning paralleliped based methods to representing enclosure of the pODEs (Lohner's QR, Hermite-Obreschkoff, etc.). The constructor given by `JacTaylorFunctor!(g!, nx::Int, np::Int, k::Val{K}, t::T, q::Q)` may be used were type `T` should use type `Q` for internal computations. The order of the TaylorSeries is `k`, the right-hand side function is `g!`, `nx` is the number of state variables, `np` is the number of parameters. $(TYPEDFIELDS) """ mutable struct JacTaylorFunctor!{F <: Function, N, T <: Real, S <: Real, NY} "Right-hand side function for pODE which operates in place as g!(dx,x,p,t)" g!::F "Dimensionality of x" nx::Int "Dimensionality of p" np::Int "Order of TaylorSeries" s::Int "In-place temporary storage for Taylor coefficient calculation" out::Vector{S} "Variables y = (x,p)" y::Vector{S} "State variables x" x::Vector{Dual{Nothing,S,NY}} "Decision variables p" p::Vector{Dual{Nothing,S,NY}} "Storage for sum of Jacobian w.r.t x" Jxsto::Matrix{S} "Storage for sum of Jacobian w.r.t p" Jpsto::Matrix{S} "Temporary for transpose of Jacobian w.r.t y" tjac::Matrix{S} "Storage for vector of Jacobian w.r.t x" Jx::Vector{Matrix{S}} "Storage for vector of Jacobian w.r.t p" Jp::Vector{Matrix{S}} "Jacobian Result from DiffResults" result::MutableDiffResult{1, Vector{S}, Tuple{Matrix{S}}} "Jacobian Configuration for ForwardDiff" cfg::JacobianConfig{Nothing,S,NY,Tuple{Vector{Dual{Nothing,S,NY}},Vector{Dual{Nothing,S,NY}}}} "Store temporary STaylor1 vector for calculations" xtaylor::Vector{STaylor1{N,Dual{Nothing,S,NY}}} "Store temporary STaylor1 vector for calculations" xaux::Vector{STaylor1{N,Dual{Nothing,S,NY}}} "Store temporary STaylor1 vector for calculations" dx::Vector{STaylor1{N,Dual{Nothing,S,NY}}} taux::Vector{STaylor1{N,T}} t::Float64 "Intermediate storage to avoid allocations in Taylor coefficient calc" vnxt::Vector{Int64} "Intermediate storage to avoid allocations in Taylor coefficient calc" fnxt::Vector{Float64} end function JacTaylorFunctor!(g!, nx::Int, np::Int, k::Val{K}, t::T, q::Q) where {K, T <: Number, Q <: Number} x0 = zeros(T, nx) xd0 = zeros(Dual{Nothing, T, nx + np}, nx) out = zeros(T, nx*(K + 1)) y = zeros(T, nx + np) x = zeros(Dual{Nothing, T, nx + np}, nx) p = zeros(Dual{Nothing, T, nx + np}, np) Jxsto = zeros(T, nx, nx) Jpsto = zeros(T, nx, np) tjac = zeros(T, np + nx, nx*(K + 1)) cfg = JacobianConfig(nothing, out, zeros(T, nx + np)) result = JacobianResult(out, zeros(T, nx + np)) Jx = Matrix{T}[] Jp = Matrix{T}[] temp = zero(Dual{Nothing, T, nx + np}) taux = [STaylor1(zero(Q), Val(K))] xtaylor = STaylor1.(xd0, Val(K)) dx = STaylor1.(xd0, Val(K)) xaux = STaylor1.(xd0, Val(K)) for i in 1:(K + 1) push!(Jx, zeros(T,nx,nx)) push!(Jp, zeros(T,nx,np)) end t = 0.0 vnxt = zeros(Int, nx) fnxt = zeros(Float64, nx) return JacTaylorFunctor!{typeof(g!), K+1, Q, T, nx + np}(g!, nx, np, K, out, y, x, p, Jxsto, Jpsto, tjac, Jx, Jp, result, cfg, xtaylor, xaux, dx, taux, t, vnxt, fnxt) end function (d::JacTaylorFunctor!{F,K,T,S,NY})(out::AbstractVector{Dual{Nothing,S,NY}}, y::AbstractVector{Dual{Nothing,S,NY}}) where {F,K,T,S,NY} copyto!(d.x, 1, y, 1, d.nx) copyto!(d.p, 1, y, d.nx + 1, d.np) val = Val{K-1}() for i=1:d.nx d.xtaylor[i] = STaylor1(d.x[i], val) end jetcoeffs!(d.g!, d.t, d.xtaylor, d.xaux, d.dx, K - 1, d.p, d.vnxt, d.fnxt) for q = 1:K for i = 1:d.nx indx = d.nx*(q - 1) + i out[indx] = d.xtaylor[i].coeffs[q] end end return nothing end """ jacobian_taylor_coeffs! Computes the Jacobian of the Taylor coefficients w.r.t. y = (x,p) storing the output inplace to `result`. A JacobianConfig object without tag checking, cfg, is required input and is initialized from `cfg = ForwardDiff.JacobianConfig(nothing, out, y)`. The JacTaylorFunctor! used for the evaluation is `g` and inputs are `x` and `p`. """ function jacobian_taylor_coeffs!(g::JacTaylorFunctor!{F,K,T,S,NY}, X::Vector{S}, P, t::T) where {F,K,T,S,NY} # copyto! is used to avoid allocations copyto!(g.y, 1, X, 1, g.nx) copyto!(g.y, g.nx + 1, P, 1, g.np) g.t = t # other AD schemes may be usable as well but this is a length(g.out) >> nx + np # situtation typically jacobian!(g.result, g, g.out, g.y, g.cfg) # reset sum of Jacobian storage fill!(g.Jxsto, zero(S)) fill!(g.Jpsto, zero(S)) nothing end """ set_JxJp! Extracts the Jacobian of the Taylor coefficients w.r.t. x, `Jx`, and the Jacobian of the Taylor coefficients w.r.t. p, `Jp`, from `result`. The order of the Taylor series is `s`, the dimensionality of x is `nx`, the dimensionality of p is `np`, and `tjac` is preallocated storage for the transpose of the Jacobian w.r.t. y = (x,p). """ set_JxJp!(g::JacTaylorFunctor!{F,K,T,S,NY}, X, P, t) where {F,K,T,S,NY} = set_JxJp!(g, X, P, t, g.nx, g.np, g.s) function set_JxJp!(g::JacTaylorFunctor!{F,K,T,S,NY}, X, P, t, nx, np, s) where {F,K,T,S,NY} jacobian_taylor_coeffs!(g, X, P, t) jac = g.result.derivs[1] for i = 1:(s + 1) for q = 1:nx for z = 1:nx g.Jx[i][q, z] = jac[q + nx*(i-1), z] end for z = 1:np g.Jp[i][q, z] = jac[q + nx*(i-1), nx + z] end end end nothing end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
1386
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/utilities/mul_split.jl # A simple function used to speed up 1D calculations of matrix multiplication. ############################################################################# """ mul_split! Multiples A*b as a matrix times a vector if nx > 1. Performs scalar multiplication otherwise. """ function mul_split!(Y::Vector{R}, A::Matrix{S}, B::Vector{T}) where {R,S,T} if size(Y)[1] == 1 Y[1] = A[1,1]*B[1] else mul!(Y, A, B) end nothing end function mul_split!(Y::Matrix{R}, A::Matrix{S}, B::Matrix{T}) where {R,S,T} if size(Y)[1] == 1 Y[1,1] = A[1,1]*B[1,1] else mul!(Y, A, B) end nothing end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
3455
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/utilities/qr_utilities.jl # Functions used for preconditioning with QR factorization. ############################################################################# #= """ QRDenseStorage Provides preallocated storage for the QR factorization, Q, and the inverse of Q. $(TYPEDFIELDS) """ mutable struct QRDenseStorage "QR Factorization" factorization::LinearAlgebra.QR{Float64,Array{Float64,2}} "Orthogonal matrix Q" Q::Array{Float64,2} "Inverse of Q" inv::Array{Float64,2} end """ QRDenseStorage(nx::Int) A constructor for QRDenseStorage assumes `Q` is of size `nx`-by-`nx` and of type `Float64`. """ function QRDenseStorage(nx::Int) A = Float64.(Matrix(I, nx, nx)) factorization = LinearAlgebra.qrfactUnblocked!(A) Q = similar(A) inverse = similar(A) QRDenseStorage(factorization, Q, inverse) end function Base.copy(q::QRDenseStorage) factors_c = q.factorization.factors τ_c = q.factorization.τ f_copy = LinearAlgebra.QR{Float64,Array{Float64,2}}(factors_c,τ_c) QRDenseStorage(f_copy, copy(q.Q), copy(q.inv)) end =# #= """ calculateQ! Computes the QR factorization of `A` of size `(nx,nx)` and then stores it to fields in `qst`. """ function calculateQ!(qst::QRDenseStorage, A::Matrix{Float64}, nx::Int) qst.factorization = LinearAlgebra.qrfactUnblocked!(A) qst.Q .= qst.factorization.Q*Matrix(I,nx,nx) nothing end """ calculateQinv! Computes `inv(Q)` via transpose! and stores this to `qst.inverse`. """ function calculateQinv!(qst::QRDenseStorage) transpose!(qst.inv, qst.Q) nothing end =# function calculateQ!(Q, A::Matrix{Float64}) nx = size(A,1) if isone(nx) Q[1,1] = 1.0 else F = LinearAlgebra.qr(A) Q .= view(F.Q, 1:nx, 1:nx) end nothing end function calculateQinv!(Qinv, Q) if size(Q,1) == 1 Qinv[1,1] = 1.0 else transpose!(Qinv, Q) end nothing end #= """ An circular buffer of fixed capacity and length which allows for access via getindex and copying of an element to the last then cycling the last element to the first and shifting all other elements. See [DataStructures.jl](https://github.com/JuliaCollections/DataStructures.jl). """ function DataStructures.CircularBuffer(a::T, length::Int) where T cb = CircularBuffer{T}(length) append!(cb, [zero.(a) for i=1:length]) cb end """ reinitialize!(x::CircularBuffer{QRDenseStorage}) Sets the first QR storage to the identity matrix. """ function reinitialize!(x::CircularBuffer{QRDenseStorage}) fill!(x[1].Q, 0.0) for i in 1:size(x[1].Q, 1) x[1].Q[i,i] = 1.0 end nothing end =#
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
7767
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/utilities/relax.jl # Defines the relax! routine for the DiscretizeRelax integrator. ############################################################################# fill_zero!(x::Vector{T}) where T = fill!(x, zero(T)) function fill_identity!(x::Vector{T}) where T x[1] = one(T) end function fill_identity!(x::Matrix{T}) where T fill!(x, zero(T)) nx = size(x, 1) for i = 1:nx x[i,i] = one(T) end end function populate_storage_buffer!(z::Vector{T}, nt) where T foreach(i -> push!(z, zero(T)), length(z):nt) fill!(z, zero(T)) end function populate_storage_buffer!(z::Vector{Vector{T}}, nt, nx) where T foreach(i -> push!(z, zeros(T, nx)), length(z):nt) foreach(fill_zero!, z) end # GOOD """ reset_relax! AAA """ function initialize_relax!(d::DiscretizeRelax{M,T,S,F,K,X,NY}) where {M <: AbstractStateContractor, T <: Number, S <: Real, F, K, X, NY} @unpack time, storage, storage_apriori, storage_buffer_size, tsupports, nx, tspan = d @unpack A_Q, A_inv, Δ = d.contractor_result # reset apriori and contracted set storage along with time storage populate_storage_buffer!(storage_apriori, storage_buffer_size, nx) populate_storage_buffer!(storage, storage_buffer_size, nx) populate_storage_buffer!(time, storage_buffer_size) # reset dictionarys used to map storage to supported points empty!(d.relax_t_dict_indx) empty!(d.relax_t_dict_flt) # reset buffers used to hold parallelpepid representation state bound/relaxation foreach(fill_identity!, A_Q) foreach(fill_identity!, A_inv) set_Δ!(Δ, storage) d.step_count = 1 if length(tsupports) > 0 d.next_support_i = 1 if tsupports[1] > 0.0 d.next_support = tsupports[1] elseif length(tsupports) > 1 d.next_support = tsupports[2] end else d.next_support_i = 1E10 d.next_support = Inf end ex = d.exist_result ex.hj = !(ex.hj <= 0.0) ? ex.hj : 0.05*(tspan[2] - d.contractor_result.times[1]) ex.predicted_hj = ex.hj d.contractor_result.hj = ex.hj d.step_result.time = 0.0 d.time[1] = tspan[1] d.contractor_result.times[1] = tspan[1] set_P!(d) # reset result flag d.exist_result.status_flag = RELAXATION_NOT_CALLED return end function set_starting_existence_bounds!(ex::ExistStorage{F,K,S,T}, c::ContractorStorage{T}, r::StepResult{T}) where {F,K,S,T} ex.Xj_0 .= r.Xⱼ ex.predicted_hj = c.hj nothing end function set_result_info!(r, hj, predicted_hj) r.time = round(r.time + hj, digits=13) r.predicted_hj = predicted_hj nothing end """ store_step_result! Store result from step contractor to storage for state relaxation, apriori, times. Sets the dicts and updates the step count. """ function store_step_result!(d::DiscretizeRelax{M,T,S,F,K,X,NY}) where {M <: AbstractStateContractor, T <: Number, S <: Real, F, K, X, NY} @unpack time, storage, storage_apriori, storage_buffer_size, tsupports, step_count, nx, step_result = d @unpack X_computed, hj = d.contractor_result @unpack Xj_apriori = d.exist_result set_result_info!(step_result, hj, hj) # add time and predicted step size to results set_starting_existence_bounds!(d.exist_result, d.contractor_result, step_result) if step_count + 1 > length(time) push!(storage, copy(X_computed)) push!(storage_apriori, copy(Xj_apriori)) push!(time, d.step_result.time) else storage_position = step_count + 1 copyto!(storage[storage_position], X_computed) copyto!(storage_apriori[storage_position], Xj_apriori) time[storage_position] = d.step_result.time end if d.step_result.time == d.next_support d.relax_t_dict_indx[d.next_support_i] = d.step_count d.relax_t_dict_flt[d.next_support] = d.step_count if d.next_support_i <= length(tsupports) d.next_support_i += 1 if (0.0 in tsupports) if d.next_support_i < length(tsupports) d.next_support = tsupports[d.next_support_i + 1] else d.next_support_i = typemax(Int) d.next_support = Inf end else d.next_support = tsupports[d.next_support_i] end else d.next_support_i = typemax(Int) d.next_support = Inf end end d.step_count += 1 return end """ clean_results! Resize storage at the end to eliminate any unused values. If no error is set, record the error as COMPLETED. """ function clean_results!(d::DiscretizeRelax{M,T,S,F,K,X,NY}) where {M <: AbstractStateContractor, T <: Number, S <: Real, F, K, X, NY} @unpack step_count, storage, storage_apriori, time = d resize!(storage, step_count) resize!(storage_apriori, step_count) resize!(time, step_count) if d.error_code == RELAXATION_NOT_CALLED d.error_code = COMPLETED end nothing end """ relax_loop_terminated! Checks for termination at the start of each step. An error code is stored the limit is exceeded. """ function continue_relax_loop!(d::DiscretizeRelax{M,T,S,F,K,X,NY}) where {M,T,S,F,K,X,NY} @unpack step_count, step_limit, time, tspan = d @unpack predicted_hj, status_flag = d.exist_result should_continue = true sign_tstep = copysign(1, tspan[2] - d.step_result.time) if step_count >= step_limit if sign_tstep*time[step_count] < sign_tstep*tspan[2] d.error_code = LIMIT_EXCEEDED end should_continue = false end should_continue &= sign_tstep*d.step_result.time < sign_tstep*tspan[2] should_continue &= !iszero(predicted_hj) should_continue &= (status_flag == RELAXATION_NOT_CALLED) should_continue end function display_iteration_summary(d::DiscretizeRelax{M,T,S,F,K,X,NY}) where {M,T,S,F,K,X,NY} #println("Step = #$(d.step_count), Storage = $(d.storage[d.step_count]), Storage Apriori = $(d.storage_apriori[d.step_count])") end function DBB.relax!(d::DiscretizeRelax{M,T,S,F,K,X,NY}) where {M,T,S,F,K,X,NY} initialize_relax!(d) # Reset storage used when relaxations are computed and times tstart = time() compute_X0!(d) # Compute initial condition values while continue_relax_loop!(d) display_iteration_summary(d) # Display a single step results single_step!(d) # Perform a single step store_step_result!(d) # Store results from a single step end display_iteration_summary(d) # Display a single step results clean_results!(d) # Resize storage to computed values and set completion code (if unset) if d.print_relax_time println("relax time = $(time() - tstart)") end end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
12066
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/method/single_step.jl # Defines a single step of the integration method. ############################################################################# """ StepParams LEPUS and Integration parameters. $(TYPEDFIELDS) """ Base.@kwdef struct StepParams "Absolute error tolerance of integrator" atol::Float64 = 1E-5 "Relative error tolerance of integrator" rtol::Float64 = 1E-5 "Minimum stepsize" hmin::Float64 = 1E-8 "Number of repetitions allowed for refinement" repeat_limit::Int = 3 "Indicates an adaptive stepsize is used" is_adaptive::Bool = true "Indicates the contractor step should be skipped" skip_step2::Bool = false end """ StepResult{S} Results passed to the next step. $(TYPEDFIELDS) """ mutable struct StepResult{S} "nominal value of the state variables" xⱼ::Vector{Float64} "relaxations/bounds of the state variables" Xⱼ::Vector{S} "storage for parallelepid enclosure of `xⱼ`" A_Q::FixedCircularBuffer{Matrix{Float64}} A_inv::FixedCircularBuffer{Matrix{Float64}} "storage for parallelepid enclosure of `xⱼ`" Δ::FixedCircularBuffer{Vector{S}} "predicted step size for next step" predicted_hj::Float64 "new time" time::Float64 end """ ExistStorage{F,K,S,T} Storage used in the existence and uniqueness tests. """ mutable struct ExistStorage{F,K,S,T} status_flag::TerminationStatusCode hj::Float64 hmin::Float64 is_adaptive::Bool ϵ::Float64 k::Int predicted_hj::Float64 computed_hj::Float64 hj_max::Float64 nx::Int f_coeff::Vector{Vector{T}} f_temp_PU::Vector{Vector{T}} f_temp_tilde::Vector{Vector{T}} f_flt::Vector{Float64} hfk::Vector{T} fk::Vector{T} β::Vector{Float64} poly_term::Vector{T} Xj_0::Vector{T} Xj_apriori::Vector{T} Vⱼ::Vector{T} Uⱼ::Vector{T} Z::Vector{T} P::Vector{T} tf!::TaylorFunctor!{F,K,S,T} constant_state_bounds::Union{Nothing,ConstantStateBounds} end function ExistStorage(tf!::TaylorFunctor!{F,K,S,T}, s::T, P, nx::Int, np::Int, k::Int, h::Float64, cap::Int) where {F,K,S,T} flag = RELAXATION_NOT_CALLED Xapriori = zeros(T, nx) Xj_0 = zeros(T, nx) Xj_apriori = zeros(T, nx) f_coeff = Vector{T}[] ftilde = Vector{T}[] fPU = Vector{T}[] for i in 1:(k + 1) push!(f_coeff, zeros(T, nx)) push!(ftilde, zeros(T, nx)) push!(fPU, zeros(T, nx)) end hfk = zeros(T, nx) fk = zeros(T, nx) Z = zeros(T, nx) ϵ = 0.5 poly_term = zeros(T, nx) β = zeros(Float64, nx) f_flt = zeros(Float64, nx) Vⱼ = zeros(T, nx) Uⱼ = zeros(T, nx) Z = zeros(T, nx) return ExistStorage{F,K,S,T}(flag, h, h, (h === 0.0), ϵ, k, h, h, Inf, nx, f_coeff, fPU, ftilde, f_flt, hfk, fk, β, poly_term, Xj_0, Xj_apriori, Vⱼ, Uⱼ, Z, P, tf!, nothing) end """ ContractorStorage{S} Storage used to hold inputs to the contractor method used. """ mutable struct ContractorStorage{S} is_adaptive::Bool times::FixedCircularBuffer{Float64} steps::FixedCircularBuffer{Float64} Xj_0::Vector{S} Xj_apriori::Vector{S} xval::Vector{Float64} A_Q::FixedCircularBuffer{Matrix{Float64}} A_inv::FixedCircularBuffer{Matrix{Float64}} Δ::FixedCircularBuffer{Vector{S}} P::Vector{S} rP::Vector{S} pval::Vector{Float64} fk_apriori::Vector{S} hj::Float64 X_computed::Vector{S} xval_computed::Vector{Float64} B::Matrix{Float64} γ::Float64 step_count::Int nx::Int end function ContractorStorage(style::S, nx, np, k, h, method_steps) where S is_adaptive = h <= 0.0 # add initial storage Xj_0 = zeros(S, nx) Xj_apriori = zeros(S, nx) xval = zeros(Float64, nx) xval_computed = zeros(Float64, nx) P = zeros(S, np) rP = zeros(S, np) pval = zeros(Float64, np) fk_apriori = zeros(S, nx) hj = 0.0 X_computed = zeros(S, nx) xval_computed = zeros(Float64, nx) B = zeros(Float64, nx, nx) γ = 0.0 step_count = 1 # add to buffer times = FixedCircularBuffer{Float64}(method_steps); append!(times, zeros(nx)) steps = FixedCircularBuffer{Float64}(method_steps); append!(steps, zeros(nx)) Δ = FixedCircularBuffer{Vector{S}}(method_steps) A_Q = FixedCircularBuffer{Matrix{Float64}}(method_steps) A_inv = FixedCircularBuffer{Matrix{Float64}}(method_steps) for i = 1:method_steps push!(Δ, zeros(S, nx)) push!(A_Q, Float64.(Matrix(I, nx, nx))) push!(A_inv, Float64.(Matrix(I, nx, nx))) end return ContractorStorage{S}(is_adaptive, times, steps, Xj_0, Xj_apriori, xval, A_Q, A_inv, Δ, P, rP, pval, fk_apriori, hj, X_computed, xval_computed, B, γ, step_count, nx) end function advance_contract_storage!(d::ContractorStorage{S}) where {S <: Number} cycle!(d.A_Q) cycle!(d.A_inv) cycle!(d.Δ) nothing end function load_existence_info_to_contractor!(c::ContractorStorage{T}, ex::ExistStorage{F,K,S,T}) where {F,K,S,T} c.Xj_apriori .= ex.Xj_apriori c.hj = min(ex.computed_hj, ex.hj_max) c.fk_apriori .= ex.fk nothing end function set_xX!(result::StepResult{S}, contract::ContractorStorage{S}) where {S <: Number} pL = lo.(contract.P) pU = hi.(contract.P) pval = contract.pval subgradient_expansion_interval_contract!(contract.X_computed, pval, pL, pU) subgradient_expansion_interval_contract!(contract.Xj_0, pval, pL, pU) result.Xⱼ .= contract.X_computed result.xⱼ .= contract.xval_computed contract.Xj_0 .= contract.X_computed contract.xval .= contract.xval_computed nothing end """ excess_error Computes the excess error using a norm-∞ of the diameter of the vectors. """ function excess_error(Z::Vector{S}, hj, hj_eu, γ, k, nx) where S errⱼ = 0.0; dₜ = 0.0 for i = 1:nx dₜ = hj*diam(Z[i]) errⱼ = (dₜ > errⱼ) ? dₜ : errⱼ end abs(γ*errⱼ) end affine_contract!(X::Vector{Interval{Float64}}, P::Vector{Interval{Float64}}, pval, np, nx) = nothing function affine_contract!(X::Vector{MC{N,T}}, P::Vector{MC{N,T}}, pval::Vector{Float64}, np, nx) where {N,T<:RelaxTag} x_Intv_cv = 0.0 x_Intv_cc = 0.0 for i = 1:nx Xt = X[i] x_Intv_cv = Xt.cv x_Intv_cc = Xt.cc for j = 1:N p = pval[j] pL = P[j].Intv.lo pU = P[j].Intv.hi cv_gradj = Xt.cv_grad[j] cc_gradj = Xt.cc_grad[j] x_Intv_cv += (cv_gradj > 0.0) ? cv_gradj*(pL - p) : cv_gradj*(pU - p) x_Intv_cc += (cc_gradj < 0.0) ? cc_gradj*(pL - p) : cc_gradj*(pU - p) end x_Intv_cv = max(x_Intv_cv, Xt.Intv.lo) x_Intv_cc = min(x_Intv_cc, Xt.Intv.hi) X[i] = MC{N,T}(Xt.cv, Xt.cc, Interval(x_Intv_cv, x_Intv_cc), Xt.cv_grad, Xt.cc_grad, Xt.cnst) end return nothing end contract_apriori!(exist::ExistStorage{F,K,S,T}, n::Nothing) where {F, K, S <: Real, T} = nothing contract_apriori!(exist::ExistStorage{F,K,S,T}, p::PolyhedralConstraint) where {F, K, S <: Real, T} = nothing function contract_apriori!(exist::ExistStorage{F,K,S,T}, c::ConstantStateBounds) where {F, K, S <: Real, T} exist.Xj_apriori .= exist.Xj_apriori .∩ Interval.(c.xL, c.xU) return nothing end function store_parallelepid_enclosure!(c::ContractorStorage{T}, r::StepResult{T}, j) where T cycle_copyto!(r.A_Q, c.A_Q[1], j) cycle_copyto!(r.A_inv, c.A_inv[1], j) cycle_copyto!(r.Δ, c.Δ[1], j) nothing end function reset_step_limit!(d) @unpack next_support, tspan = d @unpack time = d.step_result tval = round(next_support - time, digits=13) if tval < 0.0 tval = Inf end d.exist_result.hj = min(d.exist_result.hj, tval, tspan[2] - time) d.exist_result.hj_max = tspan[2] - time d.exist_result.predicted_hj = min(d.exist_result.predicted_hj, tval, tspan[2] - time) d.contractor_result.steps[1] = d.exist_result.hj d.contractor_result.step_count = d.step_count end set_γ!(sc, c, ex, result, params) = nothing """ single_step! Performs a single-step of the validated integrator. Input stepsize is out.step. """ function single_step!(ex::ExistStorage{F,K,S,T}, c::ContractorStorage{T}, params::StepParams, result::StepResult{T}, sc::M, j, csb::C, pc::P, tspan) where {M <: AbstractStateContractor, F, K, S <: Real, T, C, P} @unpack repeat_limit, hmin, atol, rtol, skip_step2, is_adaptive = params @unpack hj, γ, X_computed, Δ = c @unpack k, nx = ex set_γ!(sc, c, ex, result, params) if !existence_uniqueness!(ex, params, result.time, j) # validate existence & uniqueness return nothing end advance_contract_storage!(c) # Advance polyhedral storage contract_apriori!(ex, csb)::Nothing # Apply constant state bound contractor (if set) contract_apriori!(ex, pc)::Nothing # Apply polyhedral contractor (if set) load_existence_info_to_contractor!(c, ex) hj_eu = c.hj if skip_step2 # Skip contractor and use state values for existence test result.xⱼ .= mid.(ex.Xj_apriori) result.Xⱼ .= ex.Xj_apriori c.X_computed .= ex.Xj_apriori else # Apply contractor in LEPUS stepsize scheme if is_adaptive count = 0 while (c.hj > hmin) & (count < repeat_limit) count += 1 sc(c, result, count, j) errj = excess_error(ex.Z, c.hj, hj_eu, γ, k, nx) if (errj < c.hj*rtol) || (errj < atol) sign_tstep = copysign(1, tspan[2] - result.time) next_t = sign_tstep*(result.time + c.hj) t_end = sign_tstep*tspan[2] if (next_t < t_end) & !isapprox(next_t, t_end, atol = 1E-8) δerrj = max(1E-11, errj) max_new_step = 1.015*c.hj c.hj = 0.9*c.hj*(0.5*c.hj*rtol/δerrj)^(1/(k-1)) c.hj = min(max_new_step, c.hj, t_end - result.time) end break else hj_reduced = c.hj*(c.hj*atol/errj)^(1/(k-1)) ex.Z *= (hj_reduced/c.hj)^k c.hj = hj_reduced end end set_xX!(result, c)::Nothing else sc(c, result, 0, k) set_xX!(result, c)::Nothing end store_parallelepid_enclosure!(c, result, j) # update parallelepid enclosure end end function single_step!(d) @unpack next_support, next_support_i, tspan = d reset_step_limit!(d) single_step!(d.exist_result, d.contractor_result, d.step_params, d.step_result, d.method_f!, d.step_count, d.constant_state_bounds, d.polyhedral_constraint, tspan) end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
3467
# Copyright (c) 2020: Matthew Wilhelm & Matthew Stuber. # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike 4.0 International License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative # Commons, PO Box 1866, Mountain View, CA 94042, USA. ############################################################################# # Dynamic Bounds - pODEs Discrete # A package for discretize and relax methods for bounding pODEs. # See https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl ############################################################################# # src/DiscretizeRelax/utilities/taylor_functor.jl # Defines methods to used to compute Taylor coeffients. ############################################################################# """ TaylorFunctor! A function g!(out, y) that perfoms a Taylor coefficient calculation. Provides preallocated storage. Evaluating this function out is a vector of length nx*(s+1) where 1:(s+1) are the Taylor coefficients of the first component, (s+2):nx*(s+1) are the Taylor coefficients of the second component, and so on. This may be constructed using `TaylorFunctor!(g!, nx::Int, np::Int, k::Val{K}, t::T, q::Q)` were type `T` should use type `Q` for internal computations. The order of the TaylorSeries is `k`, the right-hand side function is `g!`, `nx` is the number of state variables, `np` is the number of parameters. $(TYPEDFIELDS) """ mutable struct TaylorFunctor!{F <: Function, N, T <: Real, S <: Real} "Right-hand side function for pODE which operates in place as g!(dx,x,p,t)" g!::F "Dimensionality of x" nx::Int "Dimensionality of p" np::Int "Order of TaylorSeries, that is the first k terms are used in the approximation and N = k+1 term is bounded" k::Int "State variables x" x::Vector{S} "Decision variables p" p::Vector{S} "Store temporary STaylor1 vector for calculations" xtaylor::Vector{STaylor1{N,S}} "Store temporary STaylor1 vector for calculations" xaux::Vector{STaylor1{N,S}} "Store temporary STaylor1 vector for calculations" dx::Vector{STaylor1{N,S}} taux::Vector{STaylor1{N,T}} vnxt::Vector{Int} fnxt::Vector{Float64} end function TaylorFunctor!(g!, nx::Int, np::Int, k::Val{K}, t::T, q::Q) where {K, T <: Number, Q <: Number} f̃ = Vector{T}[] for i = 1:(K+1) push!(f̃, zeros(T, nx)) end temp = STaylor1(zeros(T,K+1)) xtaylor = STaylor1{K+1,T}[] xaux = STaylor1{K+1,T}[] dx = STaylor1{K+1,T}[] taux = STaylor1{K+1,Q}[] for i = 1:nx push!(xtaylor, temp) push!(xaux, temp) push!(dx, temp) push!(taux, zero(STaylor1{K+1,Q})) end x = zeros(T, nx) p = zeros(T, np) vnxt = zeros(Int, nx) fnxt = zeros(Float64, nx) return TaylorFunctor!{typeof(g!), K+1, Q, T}(g!, nx, np, K, x, p, xtaylor, xaux, dx, taux, vnxt, fnxt) end function (d::TaylorFunctor!{F,K,T,S})(out::Vector{Vector{S}}, x::Vector{S}, p::Vector{S}, t::T) where {F, K, T, S} @__dot__ d.xtaylor = STaylor1(x, Val(K-1)) jetcoeffs!(d.g!, t, d.xtaylor, d.xaux, d.dx, K-1, p, d.vnxt, d.fnxt)::Nothing for i = 1:d.nx, j = 1:(d.k + 1) out[j][i] = d.xtaylor[i][j - 1] end nothing end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
1388
module StaticTaylorSeries using Requires using McCormick # TODO: Remove if package import Base: ==, +, -, *, /, ^ import Base: iterate, size, eachindex, firstindex, lastindex, eltype, length, getindex, setindex!, axes, copyto! import Base: zero, one, zeros, ones, isinf, isnan, iszero, convert, promote_rule, promote, show, real, imag, conj, adjoint, rem, mod, mod2pi, abs, abs2, sqrt, exp, log, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, power_by_squaring, rtoldefault, isfinite, isapprox, rad2deg, deg2rad export STaylor1 export getcoeff, derivative, integrate, differentiate, evaluate, evaluate!, inverse, set_taylor1_varname, show_params_TaylorN, show_monomials, displayBigO, use_show_default, get_order, get_numvars, set_variables, get_variables, get_variable_names, get_variable_symbols, taylor_expand, update!, constant_term, linear_polynomial, normalize_taylor, evaluate include("constructors.jl") include("conversion.jl") include("auxiliary.jl") include("arithmetic.jl") include("power.jl") include("functions.jl") include("other_functions.jl") include("evaluate.jl") include("printing.jl") function __init__() @require IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" include("intervals.jl") end end # module
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
5561
==(a::STaylor1, b::STaylor1) = (a.coeffs == b.coeffs) iszero(a::STaylor1) = all(iszero, a.coeffs) function zero(::Type{STaylor1{N,T}}) where {N, T<:Number} return STaylor1(zero(T), Val{N-1}()) end zero(a::STaylor1{N,T}) where {N, T<:Number} = zero(STaylor1{N,T}) function one(::Type{STaylor1{N,T}}) where {N, T<:Number} return STaylor1(one(T), Val{N-1}()) end one(a::STaylor1{N,T}) where {N, T<:Number} = one(STaylor1{N,T}) @inline +(a::STaylor1{N,T}, b::STaylor1{N,T}) where {N, T<:Number} = STaylor1(a.coeffs .+ b.coeffs) @inline -(a::STaylor1{N,T}, b::STaylor1{N,T}) where {N, T<:Number} = STaylor1(a.coeffs .- b.coeffs) @inline +(a::STaylor1) = a @inline -(a::STaylor1) = STaylor1(.- a.coeffs) function +(a::STaylor1{N,T}, b::T) where {N, T<:Number} STaylor1{N,T}(ntuple(i -> i == 1 ? a.coeffs[1] + b : a.coeffs[i], Val(N))) end function +(b::T, a::STaylor1{N,T}) where {N, T<:Number} STaylor1{N,T}(ntuple(i -> i == 1 ? a.coeffs[1] + b : a.coeffs[i], Val(N))) end function +(a::STaylor1{N,T}, b::Number) where {N, T<:Number} STaylor1{N,T}(ntuple(i -> i == 1 ? a.coeffs[1] + b : a.coeffs[i], Val(N))) end function +(b::Number, a::STaylor1{N,T}) where {N, T<:Number} STaylor1{N,T}(ntuple(i -> i == 1 ? a.coeffs[1] + b : a.coeffs[i], Val(N))) end function -(a::STaylor1{N,T}, b::T) where {N, T<:Number} STaylor1{N,T}(ntuple(i -> i == 1 ? a.coeffs[1] - b : a.coeffs[i], Val(N))) end -(b::T, a::STaylor1{N,T}) where {N, T<:Number} = b + (-a) function -(a::STaylor1{N,T}, b::Number) where {N, T<:Number} STaylor1{N,T}(ntuple(i -> i == 1 ? a.coeffs[1] - b : a.coeffs[i], Val(N))) end -(b::Number, a::STaylor1{N,T}) where {N, T<:Number} = b + (-a) #+(a::STaylor1{N,T}, b::S) where {N, T<:NumberNotSeries, S<:NumberNotSeries} = +(promote(a,b)...) #+(a::STaylor1{N,T}, b::STaylor1{N,S}) where {N, T<:NumberNotSeries, S<:NumberNotSeries} = +(promote(a,b)...) #+(a::STaylor1{N,T}, b::S) where {N, T<:NumberNotSeries, S<:NumberNotSeries} = +(promote(a,b)...) #+(b::S, a::STaylor1{N,T}) where {N, T<:NumberNotSeries, S<:NumberNotSeries} = +(promote(b,a)...) #-(a::STaylor1{N,T}, b::STaylor1{N,S}) where {N, T<:NumberNotSeries, S<:NumberNotSeries} = -(promote(a,b)...) #-(a::STaylor1{N,T}, b::S) where {N, T<:NumberNotSeries, S<:NumberNotSeries} = -(promote(a,b)...) #-(b::S, a::STaylor1{N,T}) where {N, T<:NumberNotSeries, S<:NumberNotSeries} = -(promote(b,a)...) @generated function *(x::STaylor1{N,T}, y::STaylor1{N,T}) where {T<:Number,N} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] for j = 1:N ex_line = :(x.coeffs[1]*y.coeffs[$j]) for k = 2:j ex_line = :($ex_line + x.coeffs[$k]*y.coeffs[$(j-k+1)]) end sym = syms[j] ex_line = :($sym = $ex_line) ex_calc.args[j] = ex_line end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout) end end function *(a::STaylor1{N,T}, b::T) where {N, T<:Number} STaylor1{N,T}(b .* a.coeffs) end function *(b::T, a::STaylor1{N,T}) where {N, T<:Number} STaylor1{N,T}(b .* a.coeffs) end function /(a::STaylor1{N,T}, b::T) where {N, T<:Number} STaylor1{N,T}(a.coeffs ./ b) end function /(b::T, a::STaylor1{N,T}) where {N, T<:Number} return (b*one(STaylor1{N,T}))/a end function *(a::STaylor1{N,Float64}, b::Float64) where N STaylor1{N,Float64}(b .* a.coeffs) end function *(b::Float64, a::STaylor1{N,Float64}) where N STaylor1{N,Float64}(b .* a.coeffs) end function /(a::STaylor1{N,Float64}, b::Float64) where N STaylor1{N,Float64}(a.coeffs ./ b) end function /(b::Float64, a::STaylor1{N,Float64}) where N return (b*one(STaylor1{N,Float64}))/a end function *(a::STaylor1{N,T}, b::Float64) where {N, T<:Number} STaylor1{N,T}(b .* a.coeffs) end function *(b::Float64, a::STaylor1{N,T}) where {N, T<:Number} STaylor1{N,T}(b .* a.coeffs) end function /(a::STaylor1{N,T}, b::Float64) where {N, T<:Number} STaylor1{N,T}(a.coeffs ./ b) end function /(b::Float64, a::STaylor1{N,T}) where {N, T<:Number} return (b*one(STaylor1{N,T}))/a end @generated function /(a::STaylor1{N,T}, b::STaylor1{N,T}) where {N,T<:Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] # add error ex_line = quote if iszero(b[0]) throw(ArgumentError("""The 0th order STaylor1 coefficient must be non-zero for b, (a/b)(x) is not differentiable at x=0).""")) end end ex_calc.args[1] = ex_line # add recursion relation for j = 0:(N-1) ex_line = :(a[$(j)]) for k = 1:j sym = syms[j-k+1] ex_line = :($ex_line - $sym*b[$k]) end sym = syms[j+1] ex_line = :($sym = ($ex_line)/b[0]) ex_calc.args[j+2] = ex_line end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout) end end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
1251
# getindex STaylor1 getindex(a::STaylor1, n::Int) = a.coeffs[n+1] getindex(a::STaylor1, u::UnitRange{Int}) = a.coeffs[u .+ 1] getindex(a::STaylor1, c::Colon) = a.coeffs[c] getindex(a::STaylor1, u::StepRange{Int,Int}) = a.coeffs[u .+ 1] @inline iterate(a::STaylor1{N,T}, state=0) where {N, T<:Number} = state > N-1 ? nothing : (a.coeffs[state+1], state+1) @inline firstindex(a::STaylor1) = 0 @inline lastindex(a::STaylor1{N,T}) where {N, T<:Number} = N-1 @inline eachindex(s::STaylor1{N,T}) where {N, T<:Number} = UnitRange(0, N-1) @inline size(s::STaylor1{N,T}) where {N, T<:Number} = N @inline length(s::STaylor1{N,T}) where {N, T<:Number} = N @inline get_order(s::STaylor1{N,T}) where {N, T<:Number} = N - 1 @inline eltype(s::STaylor1{N,T}) where {N, T<:Number} = T @inline axes(a::STaylor1) = () function Base.findfirst(a::STaylor1{N,T}) where {N, T<:Number} first = findfirst(x->!iszero(x), a.coeffs) isa(first, Nothing) && return -1 return first-1 end # Finds the last non-zero entry; extended to Taylor1 function Base.findlast(a::STaylor1{N,T}) where {N, T<:Number} last = findlast(x->!iszero(x), a.coeffs) isa(last, Nothing) && return -1 return last-1 end constant_term(a::STaylor1) = a[0]
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
1524
######################### STaylor1 abstract type AbstractSeries{T<:Number} <: Number end """ STaylor1{N,T<:Number} <: AbstractSeries{T} DataType for polynomial expansions in one independent variable. **Fields:** - `coeffs :: NTuple{N,T}` Expansion coefficients; the ``i``-th component is the coefficient of degree ``i-1`` of the expansion. Note that `STaylor1` variables are callable. For more information, see [`evaluate`](@ref). """ struct STaylor1{N,T<:Number} <: AbstractSeries{T} coeffs::NTuple{N,T} function STaylor1{N,T}(coeffs::NTuple{N,T}) where {N, T <: Number} new(coeffs) end end function STaylor1(coeffs::NTuple{N,T}) where {N, T <: Number} STaylor1{N,T}(coeffs) end ## Outer constructors ## """ STaylor1(x::T, v::Val{N}) Shortcut to define the independent variable of a `STaylor1{N,T}` polynomial of given `N` with constant term equal to `x`. """ @generated function STaylor1(x::T, v::Val{N}) where {N,T<:Number} y = Any[:(zero($T)) for i=1:N] tup = :((x,)) push!(tup.args, y...) return quote Base.@_inline_meta STaylor1{(N+1),T}($tup) end end function STaylor1(coeffs::Vector{T}, l::Val{L}, v::Val{N}) where {L,N,T<:Number} STaylor1{(N+1),T}(ntuple(i -> (i < L+1) ? coeffs[i] : zero(T), N+1)) end @inline function STaylor1(coeffs::Vector{T}) where {T<:Number} STaylor1{length(coeffs),T}(tuple(coeffs...)) end @inline STaylor1(x::STaylor1{N,T}) where {N,T<:Number} = x
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
1832
# Conversion for STaylor1 function convert(::Type{STaylor1{N,Rational{T}}}, a::STaylor1{N,S}) where {N,T<:Integer, S<:AbstractFloat} STaylor1(rationalize.(a.coeffs)) end function convert(::Type{STaylor1{N,T}}, b::Array{T,1}) where {N,T<:Number} @assert N == length(b) STaylor1(b) end function convert(::Type{STaylor1{N,T}}, b::Array{S,1}) where {N,T<:Number, S<:Number} @assert N == length(b) STaylor1(convert(Array{T,1},b)) end convert(::Type{STaylor1{N,T}}, a::STaylor1{N,T}) where {N,T<:Number} = a convert(::Type{STaylor1{N,T}}, b::S) where {N, T<:Number, S<:Number} = STaylor1(convert(T,b), Val(N)) convert(::Type{STaylor1{N,T}}, b::T) where {N, T<:Number} = STaylor1(b, Val(N)) function promote_rule(::Type{STaylor1{N,T}}, ::Type{Float64}) where {N,T<:Number} S = promote_rule(T, Float64) STaylor1{N,S} end function promote_rule(::Type{STaylor1{N,T}}, ::Type{Int}) where {N,T<:Number} S = promote_rule(T, Int) STaylor1{N,S} end #promote_rule(::Type{STaylor1{N,T}}, ::Type{STaylor1{N,T}}) where {N, T<:Number} = STaylor1{N,T} #promote_rule(::Type{STaylor1{N,T}}, ::Type{STaylor1{N,T}}) where {N, T<:Number} = STaylor1{N,T} #promote_rule(::Type{STaylor1{N,T}}, ::Type{STaylor1{N,S}}) where {N, T<:Number, S<:Number} = STaylor1{N, promote_type(T,S)} #promote_rule(::Type{STaylor1{N,T}}, ::Type{Array{T,1}}) where {N, T<:Number} = STaylor1{N,T} #promote_rule(::Type{STaylor1{N,T}}, ::Type{Array{S,1}}) where {N, T<:Number, S<:Number} = STaylor1{N,promote_type(T,S)} #promote_rule(::Type{STaylor1{N,T}}, ::Type{T}) where {N, T<:Number} = STaylor1{N,T} #promote_rule(::Type{STaylor1{N,T}}, ::Type{S}) where {N, T<:Number, S<:Number} = STaylor1{N,promote_type(T,S)} #promote_rule(::Type{STaylor1{N,Float64}}, ::Type{Float64}) where N = STaylor1{N,Float64}
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
1051
function evaluate(a::STaylor1{N,T}, dx::T) where {N, T<:Number} @inbounds suma = a[N-1] @inbounds for k in (N-1):-1:0 suma = suma*dx + a[k] end suma end function evaluate(a::STaylor1{N,T}, x::STaylor1{N,T}) where {N, T<:Number} @inbounds suma = a[end]*one(STaylor1{N,T}) @inbounds for k = (N-1):-1:0 suma = suma*x + a[k] end suma end evaluate(a::STaylor1{N,T}) where {N, T<:Number} = a[0] evaluate(x::Union{Array{STaylor1{N,T}}, SubArray{STaylor1{N,T}}}, δt::S) where {N, T<:Number, S<:Number} = evaluate.(x, δt) evaluate(a::Union{Array{STaylor1{N,T}}, SubArray{STaylor1{N,T}}}) where {N, T<:Number} = evaluate.(a, zero(T)) (p::STaylor1)(x) = evaluate(p, x) (p::STaylor1)() = evaluate(p) (p::Array{STaylor1{N,T}})(x) where {N,T<:Number} = evaluate.(p, x) (p::SubArray{STaylor1{N,T}})(x) where {N,T<:Number} = evaluate.(p, x) (p::Array{STaylor1{N,T}})() where {N,T<:Number} = evaluate.(p) (p::SubArray{STaylor1{N,T}})() where {N,T<:Number} = evaluate.(p)
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
11157
# Functions for STaylor1 @generated function exp(a::STaylor1{N,T}) where {N, T <: Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] sym = syms[1] ex_line = :($(syms[1]) = exp(a[0])) ex_calc.args[1] = ex_line for k in 1:(N-1) kT = convert(T,k) sym = syms[k+1] ex_line = :($kT * a[$k] * $(syms[1])) @inbounds for i = 1:k-1 ex_line = :($ex_line + $(kT-i) * a[$(k-i)] * $(syms[i+1])) end ex_line = :(($ex_line)/$kT) ex_line = :($sym = $ex_line) ex_calc.args[k+1] = ex_line end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout) end end @generated function log(a::STaylor1{N,T}) where {N, T <: Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] (N >= 1) && (ex_calc.args[1] = :($(syms[1]) = log(constant_term(a)))) (N >= 2) && (ex_calc.args[2] = :($(syms[2]) = a[1]/constant_term(a))) for k in 2:(N-1) ex_line = :($(k-1)*a[1]*$(syms[k])) @inbounds for i = 2:k-1 ex_line = :($ex_line + $(k-i)*a[$i] * $(syms[k+1-i])) end ex_line = :((a[$k] - ($ex_line)/$(convert(T,k)))/constant_term(a)) ex_line = :($(syms[k+1]) = $ex_line) ex_calc.args[k+1] = ex_line end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta iszero(constant_term(a)) && throw(ArgumentError(""" The 0-th order `STaylor1` coefficient must be non-zero in order to expand `log` around 0. """)) $ex_calc return STaylor1{N,T}($exout) end end sin(a::STaylor1{N,T}) where {N, T <: Number} = sincos(a)[1] cos(a::STaylor1{N,T}) where {N, T <: Number} = sincos(a)[2] @generated function sincos(a::STaylor1{N,T}) where {N, T <: Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:(2*N)]) syms_s = Symbol[Symbol("c$i") for i in 1:N] syms_c = Symbol[Symbol("c2$i") for i in 1:N] ex_line_s = :($(syms_s[1]) = sin(a[0])) ex_line_c = :($(syms_c[1]) = cos(a[0])) ex_calc.args[1] = ex_line_s ex_calc.args[2] = ex_line_c for k = 1:(N - 1) ex_line_s = :(a[1]*$(syms_c[k])) ex_line_c = :(-a[1]*$(syms_s[k])) for i = 2:k ex_line_s = :($ex_line_s + $i*a[$i]*$(syms_c[(k - i + 1)])) ex_line_c = :($ex_line_c - $i*a[$i]*$(syms_s[(k - i + 1)])) end ex_line_s = :($(syms_s[k + 1]) = ($ex_line_s)/$k) ex_line_c = :($(syms_c[k + 1]) = ($ex_line_c)/$k) ex_calc.args[2*k + 1] = ex_line_s ex_calc.args[2*k + 2] = ex_line_c end exout_s = :(($(syms_s[1]),)) for i = 2:N push!(exout_s.args, syms_s[i]) end exout_c = :(($(syms_c[1]),)) for i = 2:N push!(exout_c.args, syms_c[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout_s), STaylor1{N,T}($exout_c) end end # Functions for STaylor1 @generated function tan(a::STaylor1{N,T}) where {N, T <: Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:(4*N)]) syms = Symbol[Symbol("c$i") for i in 1:N] syms2 = Symbol[Symbol("c2$i") for i in 1:N] for i = 1:N ex_calc.args[i] = :($(syms2[i]) = 0.0) end ex_line_c = :($(syms[1]) = tan(a[0])) ex_line_c2 = :($(syms2[1]) = ($(syms[1]))^2) ex_calc.args[N + 1] = ex_line_c ex_calc.args[N + 2] = ex_line_c2 for k = 1:(N - 1) kodd = k%2 kend = div(k - 2 + kodd, 2) kdiv2 = div(k, 2) ex_line_c = :($(k-1)*a[$(k-1)]*$(syms2[2])) for i = 1:(k - 1) q = k - i ex_line_c = :($ex_line_c + ($q)*a[$q]*$(syms2[i + 1])) end ex_line_c = :(a[$k] + ($ex_line_c)/$k) ex_line_c = :($(syms[k + 1]) = $ex_line_c) ex_calc.args[(3*k-2) + N + 2] = ex_line_c ex_line_c2 = :(a[0]*a[$k]) for i = 1:kend ex_line_c2 = :($ex_line_c2 + a[$i]*a[$k - $i]) end ex_line_c2 = :(2*$ex_line_c2) if kodd != 1 ex_line_c2 = :($ex_line_c2 + a[$kdiv2]^2) end ex_line_c2 = :($(syms2[k + 1]) = $ex_line_c2) ex_calc.args[(3*k-1) + 2 + N] = ex_line_c2 blar = k + 1 blar_str = "c$(blar) " ex_calc.args[3*k + N + 2] = :(println($blar_str*string($(syms[k + 1])))) end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout) end end # Functions for STaylor1 @generated function asin(a::STaylor1{N,T}) where {N, T <: Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] sym = syms[1] ex_line = :($(sym) = asin(a[0])) ex_calc.args[1] = ex_line for k in 1:(N-1) kT = convert(T,k) sym = syms[k+1] ex_line = :($kT * a[$k] * $(syms[1])) @inbounds for i = 1:k-1 ex_line = :($ex_line + $(kT-i) * a[$(k-i)] * $(syms[i+1])) end ex_line = :(($ex_line)/$kT) ex_line = :($sym = $ex_line) ex_calc.args[k+1] = ex_line end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta a0 = constant_term(a) a0^2 == one(a0) && throw(ArgumentError( """ Recursion formula diverges due to vanishing `sqrt` in the denominator. """)) $ex_calc return STaylor1{N,T}($exout) end end # Functions for STaylor1 @generated function acos(a::STaylor1{N,T}) where {N, T <: Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] sym = syms[1] ex_line = :($(sym) = acos(a[0])) ex_calc.args[1] = ex_line for k in 1:(N-1) kT = convert(T,k) sym = syms[k+1] ex_line = :($kT * a[$k] * $(syms[1])) @inbounds for i = 1:k-1 ex_line = :($ex_line + $(kT-i) * a[$(k-i)] * $(syms[i+1])) end ex_line = :(($ex_line)/$kT) ex_line = :($sym = $ex_line) ex_calc.args[k+1] = ex_line end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout) end end # Functions for STaylor1 @generated function atan(a::STaylor1{N,T}) where {N, T <: Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] sym = syms[1] ex_line = :($(sym) = atan(a[0])) ex_calc.args[1] = ex_line for k in 1:(N-1) kT = convert(T,k) sym = syms[k+1] ex_line = :($kT * a[$k] * $(syms[1])) @inbounds for i = 1:k-1 ex_line = :($ex_line + $(kT-i) * a[$(k-i)] * $(syms[i+1])) end ex_line = :(($ex_line)/$kT) ex_line = :($sym = $ex_line) ex_calc.args[k+1] = ex_line end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout) end end sinh(a::STaylor1{N,T}) where {N, T <: Number} = sinhcosh(a)[1] cosh(a::STaylor1{N,T}) where {N, T <: Number} = sinhcosh(a)[2] @generated function sinhcosh(a::STaylor1{N,T}) where {N, T <: Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:(2*N)]) syms_s = Symbol[Symbol("c$i") for i in 1:N] syms_c = Symbol[Symbol("c2$i") for i in 1:N] ex_line_s = :($(syms_s[1]) = sinh(a[0])) ex_line_c = :($(syms_c[1]) = cosh(a[0])) ex_calc.args[1] = ex_line_s ex_calc.args[2] = ex_line_c for k = 1:(N - 1) ex_line_s = :(a[1]*$(syms_c[k])) ex_line_c = :(a[1]*$(syms_s[k])) for i = 2:k ex_line_s = :($ex_line_s + $i*a[$i]*$(syms_c[(k - i + 1)])) ex_line_c = :($ex_line_c + $i*a[$i]*$(syms_s[(k - i + 1)])) end ex_line_s = :($(syms_s[k + 1]) = ($ex_line_s)/$k) ex_line_c = :($(syms_c[k + 1]) = ($ex_line_c)/$k) ex_calc.args[2*k + 1] = ex_line_s ex_calc.args[2*k + 2] = ex_line_c end exout_s = :(($(syms_s[1]),)) for i = 2:N push!(exout_s.args, syms_s[i]) end exout_c = :(($(syms_c[1]),)) for i = 2:N push!(exout_c.args, syms_c[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout_s), STaylor1{N,T}($exout_c) end end # Functions for STaylor1 @generated function tanh(a::STaylor1{N,T}) where {N, T <: Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:(2*N)]) syms = Symbol[Symbol("c$i") for i in 1:N] syms2 = Symbol[Symbol("c2$i") for i in 1:N] ex_line_c = :($(syms[1]) = tanh(a[0])) ex_line_c2 = :($(syms2[1]) = ($(syms[1]))^2) ex_calc.args[1] = ex_line_c ex_calc.args[2] = ex_line_c2 for k = 1:(N - 1) kodd = k%2 kend = div(k - 2 + kodd, 2) kdiv2 = div(k, 2) ex_line_c = :($k*a[$k]*$(syms2[1])) for i = 1:(k - 1) q = k - i ex_line_c = :($ex_line_c + ($q)*a[$q]*$(syms2[i+1])) end ex_line_c = :(a[$k] - $ex_line_c/$k) ex_line_c = :($(syms[k + 1]) = $ex_line_c) ex_calc.args[2*k + 1] = ex_line_c ex_line_c2 = :(a[1]*a[$k]) @inbounds for i = 1:kend ex_line_c2 = :($ex_line_c2 + a[$i + 1]*a[$k - $i]) end ex_line_c2 = :(2*$ex_line_c2) if kodd != 1 ex_line_c2 = :($ex_line_c2 + a[$kdiv2 + 1]^2) end ex_line_c2 = :($(syms2[k + 1]) = $ex_line_c2) ex_calc.args[2*k + 2] = ex_line_c2 end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout) end end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
1086
using .IntervalArithmetic function evaluate(a::STaylor1{N,T}, dx::Interval) where {N, T <: Number} order = N - 1 uno = one(dx) dx2 = dx^2 if iseven(order) kend = order-2 @inbounds sum_even = a[end]*uno @inbounds sum_odd = a[end-1]*zero(dx) else kend = order-3 @inbounds sum_odd = a[end]*uno @inbounds sum_even = a[end-1]*uno end @inbounds for k = kend:-2:0 sum_odd = sum_odd*dx2 + a[k + 1] sum_even = sum_even*dx2 + a[k] end return sum_even + sum_odd*dx end normalize_taylor(a::STaylor1{N,T}, I::Interval{T}, symI::Bool=true) where {N, T <: Number} = _normalize(a, I, Val(symI)) function _normalize(a::STaylor1{N,T}, I::Interval{T}, ::Val{true}) where {N, T <: Number} t = STaylor1(one(T), Val{N-1}()) tnew = mid(I) + t*radius(I) return a(tnew) end function _normalize(a::STaylor1{N,T}, I::Interval{T}, ::Val{false}) where {N, T <: Number} t = STaylor1(one(T), Val{N-1}()) tnew = inf(I) + t*diam(I) return a(tnew) end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
1762
for f in (:real, :imag, :conj) @eval ($f)(a::STaylor1{N,T}) where {N,T<:Number} = STaylor1{N,T}(($f).(a.coeffs)) end adjoint(a::STaylor1) = conj(a) isinf(a::STaylor1) = any(isinf.(a.coeffs)) isnan(a::STaylor1) = any(isnan.(a.coeffs)) function abs(a::STaylor1{N,T}) where {N,T<:Real} if a[0] > zero(T) return a elseif a[0] < zero(T) return -a else throw(ArgumentError( """The 0th order Taylor1 coefficient must be non-zero (abs(x) is not differentiable at x=0).""")) end end abs2(a::STaylor1{N,T}) where {N,T<:Real} = a^2 deg2rad(z::STaylor1{N, T}) where {N, T<:AbstractFloat} = z * (convert(T, pi) / 180) deg2rad(z::STaylor1{N, T}) where {N, T<:Real} = z * (convert(float(T), pi) / 180) rad2deg(z::STaylor1{N, T}) where {N, T<:AbstractFloat} = z * (180 / convert(T, pi)) rad2deg(z::STaylor1{N, T}) where {N, T<:Real} = z * (180 / convert(float(T), pi)) function mod(a::STaylor1{N,T}, x::T) where {N, T<:Real} return STaylor1{N,T}(ntuple(i -> i == 1 ? mod(constant_term(a), x) : a.coeffs[i], Val(N))) end function mod(a::STaylor1{N,T}, x::S) where {N, T<:Real, S<:Real} R = promote_type(T, S) a = convert(STaylor1{N,R}, a) return mod(a, convert(R, x)) end function rem(a::STaylor1{N,T}, x::T) where {N, T<:Real} return STaylor1{N,T}(ntuple(i -> i == 1 ? rem(constant_term(a), x) : a.coeffs[i], Val(N))) end function rem(a::STaylor1{N,T}, x::S) where {N, T<:Real, S<:Real} R = promote_type(T, S) a = convert(STaylor1{N,R}, a) return rem(a, convert(R, x)) end function mod2pi(a::STaylor1{N,T}) where {N, T<:Real} return STaylor1{N,T}(ntuple(i -> i == 1 ? mod2pi(constant_term(a)) : a.coeffs[i], Val(N))) end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
8935
function ^(a::STaylor1{N,T}, n::Integer) where {N,T<:Real} n == 0 && return one(a) n == 1 && return a n == 2 && return square(a) n < 0 && return a^float(n) return power_by_squaring(a, n) end ^(a::STaylor1{N,T}, b::STaylor1{N,T}) where {N,T<:Number} = exp(b*log(a)) function power_by_squaring(x::STaylor1{N,T}, p::Integer) where {N,T<:Number} p == 1 && return x p == 0 && return one(x) p == 2 && return square(x) t = trailing_zeros(p) + 1 p >>= t while (t -= 1) > 0 x = square(x) end y = x while p > 0 t = trailing_zeros(p) + 1 p >>= t while (t -= 1) ≥ 0 x = square(x) end y *= x end return y end @generated function ^(a::STaylor1{N,T}, r::S) where {N, T<:Number, S<:Real} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] ctuple = Expr(:tuple) for i = 1:N push!(ctuple.args, syms[i]) end for i = 1:N push!(ex_calc.args, :($(syms[i]) = zero(T))) end expr_quote = quote iszero(r) && return one(a) r == 1 && return a r == 2 && return square(a) r == 1/2 && return sqrt(a) $ex_calc end c = STaylor1(zero(T), Val{N}()) for k = 0:(N - 1) symk = syms[k + 1] temp_quote = quote # First non-zero coefficient l0 = findfirst(a) if l0 < 0 $symk = zero(T) else # The first non-zero coefficient of the result; must be integer !isinteger(r*l0) && throw(ArgumentError( """The 0th order Taylor1 coefficient must be non-zero to raise the Taylor1 polynomial to a non-integer exponent.""")) lnull = trunc(Int, r*l0) kprime = $k - lnull if (kprime < 0) || (lnull > N-1) $symk = zero(T) else # Relevant for positive integer r, to avoid round-off errors if isinteger(r) && ($k > r*findlast(a)) $symk = zero(T) else if $k == lnull $symk = a[l0]^r else # The recursion formula if l0 + kprime ≤ (N - 1) tup_in = $ctuple $symk = r*kprime*tup_sel(lnull, tup_in)*a[l0 + kprime] else $symk = zero(T) end for i = 1:($k - lnull - 1) if !((i + lnull) > (N - 1) || (l0 + kprime - i > (N - 1))) aux = r*(kprime - i) - i tup_in = $ctuple $symk += aux*tup_sel(i + lnull, tup_in)*a[l0 + kprime - i] end end $symk /= kprime*a[l0] end end end end end one_tup = ntuple(i -> i == 1 ? one(T) : zero(T), Val{N}()) expr_quote = quote $expr_quote if r == 0 $ctuple = $one_tup elseif r == 1 # DO NOTHING elseif r == 2 temp_st1 = square(STaylor1{N,T}($ctuple)) elseif r == 0.5 temp_st2 = sqrt(STaylor1{N,T}($ctuple)) else $temp_quote end end end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $expr_quote return STaylor1{N,T}($exout) end end @generated function square(a::STaylor1{N,T}) where {N, T<:Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] sym = syms[1] ex_line = :($(syms[1]) = a[0]^2) ex_calc.args[1] = ex_line for k in 1:(N-1) kodd = k%2 kend = div(k - 2 + kodd, 2) ex_line = :(a[0] * a[$k]) @inbounds for i = 1:kend ex_line = :($ex_line + a[$i] * a[$(k-i)]) end ex_line = :(2.0*($ex_line)) # float(2)* TODO: ADD BACK IN if kodd !== 1 ex_line = :($ex_line +a[$(div(k,2))]^2) end ex_line = :($(syms[k+1]) = $ex_line) ex_calc.args[k+1] = ex_line end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc return STaylor1{N,T}($exout) end end @generated function inverse(a::STaylor1{N,T}) where {N,T<:Real} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:(2*N)]) syms = Symbol[Symbol("c$i") for i in 1:N] exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end count = 1 for n = 1:(N - 1) ex_calc.args[2*count - 1] = :(syms[n + 1] = zdivfpown[n - 1]/n) ex_calc.args[2*count] = :(zdivfpown *= zdivf) count += 1 end return quote Base.@_inline_meta if a[0] != zero(T) throw(ArgumentError( """ Evaluation of Taylor1 series at 0 is non-zero. For high accuracy, revert a Taylor1 series with first coefficient 0 and re-expand about f(0). """)) end z = copy(a) zdivf = z/a zdivfpown = zdivf S = eltype(zdivf) $ex_calc return STaylor1{N,T}($exout) end end function tup_sel(i, vargs) return vargs[i+1] end @generated function sqrt(a::STaylor1{N,T}) where {N,T<:Number} ex_calc = quote end append!(ex_calc.args, Any[nothing for i in 1:N]) syms = Symbol[Symbol("c$i") for i in 1:N] ctuple = Expr(:tuple) for i = 1:N push!(ctuple.args, syms[i]) end # First non-zero coefficient expr_quote = quote l0nz = findfirst(a) aux = zero(T) if l0nz < 0 return zero(STaylor1{N,T}) elseif l0nz%2 == 1 # l0nz must be pair throw(ArgumentError( """First non-vanishing Taylor1 coefficient must correspond to an **even power** in order to expand `sqrt` around 0.""")) end # The last l0nz coefficients are set to zero. lnull = div(l0nz, 2) end for i = 1:N push!(ex_calc.args, :($(syms[i]) = zero(T))) end for i = 1:N switch_expr = :((lnull == $(i-1)) && ($(syms[i]) = sqrt(a[l0nz]))) expr_quote = quote $expr_quote $switch_expr end end for k = 0:(N - 1) symk = syms[k + 1] temp_expr = quote if $k >= lnull + 1 if $k == lnull $symk = sqrt(a[2*lnull]) else kodd = ($k - lnull)%2 kend = div($k - lnull - 2 + kodd, 2) imax = min(lnull + kend, N - 1) imin = max(lnull + 1, $k + lnull - (N - 1)) if imin ≤ imax tup_in = $ctuple $symk = tup_sel(imin, tup_in)*tup_sel($k + lnull - imin, tup_in) end for i = (imin + 1):imax tup_in = $ctuple $symk += tup_sel(i, tup_in)*tup_sel($k + lnull - i, tup_in) end if $k + lnull ≤ (N - 1) aux = a[$k + lnull] - 2*$symk else aux = -2*$symk end tup_in = $ctuple if kodd == 0 aux -= tup_sel(kend + lnull + 1, tup_in)^2 end $symk = aux/(2*tup_sel(lnull, tup_in)) end end end expr_quote = quote $expr_quote $temp_expr end end exout = :(($(syms[1]),)) for i = 2:N push!(exout.args, syms[i]) end return quote Base.@_inline_meta $ex_calc $expr_quote return STaylor1{N,T}($exout) end end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
509
# printing for static taylor function coeffstring(t::STaylor1, i, variable=:t) if i == 1 # order 0 return string(t.coeffs[i]) end if i == 2 # order 1 return string(t.coeffs[i], variable) end return string(t.coeffs[i], variable, "^", i-1) end function print_taylor(io::IO, t::STaylor1, variable=:t) print(io, "(" * join([coeffstring(t, i, variable) for i in 1:length(t.coeffs)], " + ") * ")") end Base.show(io::IO, t::STaylor1) = print_taylor(io, t)
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
66
using Pkg Pkg.test("DynamicBoundspODEsDiscrete"; coverage=true)
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
code
24464
#!/usr/bin/env julia using Test, DynamicBoundspODEsDiscrete, McCormick, DynamicBoundsBase, DataStructures using DynamicBoundspODEsDiscrete.StaticTaylorSeries using DiffResults: JacobianResult const DBB = DynamicBoundsBase const DR = DynamicBoundspODEsDiscrete @testset "Discretize and Relax" begin struct unit_test_name <: DR.AbstractStateContractorName end @test_throws ErrorException DR.state_contractor_k(unit_test_name()) @test_throws ErrorException DR.state_contractor_γ(unit_test_name()) @test_throws ErrorException DR.state_contractor_steps(unit_test_name()) # test improvement condition for existence & uniqueness function J!(out, x, p, t) out[1, 1] = x nothing end function f!(dx, x, p, t) dx[1] = x[1]^2 + p[2] dx[2] = x[2] + p[1]^2 nothing end np = 2 nx = 2 k = 3 x = [0.1; 1.0] p = [0.2; 0.1] jtf! = DR.JacTaylorFunctor!(f!, nx, np, Val(k), Interval{Float64}(0.0), 0.0) xIntv = Interval{Float64}.(x) pIntv = Interval{Float64}.(p) yIntv = [xIntv; pIntv] DR.jacobian_taylor_coeffs!(jtf!, xIntv, pIntv, 0.0) jac = JacobianResult(jtf!.out, yIntv).derivs[1] tjac = zeros(Interval{Float64}, nx + np, nx * (k + 1)) Jx = Matrix{Interval{Float64}}[ zeros(Interval{Float64}, nx, nx) for i = 1:(k+1) ] Jp = Matrix{Interval{Float64}}[ zeros(Interval{Float64}, nx, np) for i = 1:(k+1) ] DR.set_JxJp!(jtf!, xIntv, pIntv, 0.0) @test isapprox(jtf!.Jp[2][2, 1].lo, 0.4, atol = 1E-3) @test isapprox(jtf!.Jp[2][1, 2].lo, 1.0, atol = 1E-3) @test isapprox(jtf!.Jp[4][2, 1].lo, 0.0666666, atol = 1E-3) @test isapprox(jtf!.Jp[4][1, 2].lo, 0.079999, atol = 1E-3) @test isapprox(jtf!.Jx[2][1, 1].lo, 0.2, atol = 1E-3) @test isapprox(jtf!.Jx[2][2, 2].lo, 1.0, atol = 1E-3) @test isapprox(jtf!.Jx[4][1, 1].lo, 0.030666, atol = 1E-3) @test isapprox(jtf!.Jx[4][2, 2].lo, 0.1666, atol = 1E-3) # make/evaluate interval valued Taylor cofficient functor itf! = DR.TaylorFunctor!( f!, nx, np, Val(k), zero(Interval{Float64}), zero(Float64), ) outIntv = Vector{Interval{Float64}}[zeros(Interval{Float64}, 2) for i = 1:4] itf!(outIntv, xIntv, pIntv, 0.0) @test isapprox(outIntv[1][1].lo, 0.10001, atol = 1E-3) @test isapprox(outIntv[2][2].lo, 1.0399999999999998, atol = 1E-3) @test isapprox(outIntv[3][1].lo, 0.011, atol = 1E-3) @test isapprox(outIntv[4][2].lo, 0.173334, atol = 1E-3) @test isapprox(outIntv[1][2].hi, 1.0, atol = 1E-3) @test isapprox(outIntv[2][1].hi, 0.1100000000000000, atol = 1E-3) @test isapprox(outIntv[3][2].hi, 0.52, atol = 1E-3) @test isapprox(outIntv[4][1].hi, 0.004766666666666669, atol = 1E-3) # make/evaluate real valued Taylor cofficient functor rtf! = DR.TaylorFunctor!(f!, nx, np, Val(k), zero(Float64), zero(Float64)) out = Vector{Float64}[zeros(Float64, 2) for i = 1:4] rtf!(out, x, p, 0.0) @test isapprox(out[1][1], 0.10001, atol = 1E-3) @test isapprox(out[2][1], 0.11000000000000001, atol = 1E-3) @test isapprox(out[3][1], 0.011, atol = 1E-3) @test isapprox(out[4][1], 0.004766666666666668, atol = 1E-3) @test isapprox(out[1][2], 1.0, atol = 1E-3) @test isapprox(out[2][2], 1.04, atol = 1E-3) @test isapprox(out[3][2], 0.52, atol = 1E-3) @test isapprox(out[4][2], 0.17333333333333334, atol = 1E-3) # higher order existence tests hⱼ = 0.001 hmin = 0.00001 function euf!(out, x, p, t) out[1, 1] = -x[1]^2 nothing end jtf_exist_unique! = DR.JacTaylorFunctor!(euf!, 1, 1, Val(k), Interval{Float64}(0.0), 0.0) xIntv_plus = xIntv .+ Interval(0, 1) DR.jacobian_taylor_coeffs!(jtf_exist_unique!, xIntv_plus, pIntv, 0.0) @test isapprox( jtf_exist_unique!.result.value[4].lo, -1.464100000000001, atol = 1E-5, ) @test isapprox( jtf_exist_unique!.result.value[4].hi, -9.999999999999999e-5, atol = 1E-5, ) @test isapprox( jtf_exist_unique!.result.derivs[1][3, 1].lo, 0.03, atol = 1E-5, ) @test isapprox( jtf_exist_unique!.result.derivs[1][3, 1].hi, 3.6300000000000012, atol = 1E-5, ) coeff_out = zeros(Interval{Float64}, 1, k) DR.set_JxJp!(jtf_exist_unique!, xIntv_plus, pIntv, 0.0) @test isapprox(jtf_exist_unique!.Jx[4][1, 1].lo, -5.32401, atol = 1E-5) @test isapprox(jtf_exist_unique!.Jx[4][1, 1].hi, -0.00399999, atol = 1E-5) @test jtf_exist_unique!.Jp[1][1, 1].lo == jtf_exist_unique!.Jp[1][1, 1].hi == 0.0 end if !(VERSION < v"1.1" && testfile == "intervals.jl") using TaylorSeries function test_vs_Taylor1(x, y) flag = true for i = 0:2 if x[i] !== y[i] flag = false break end end flag end @testset "Tests for STaylor1 expansions" begin @test STaylor1 <: DR.StaticTaylorSeries.AbstractSeries @test STaylor1{1,Float64} <: DR.StaticTaylorSeries.AbstractSeries{Float64} @test STaylor1([1.0, 2.0]) == STaylor1((1.0, 2.0)) @test STaylor1(STaylor1((1.0, 2.0))) == STaylor1((1.0, 2.0)) @test STaylor1(1.0, Val(2)) == STaylor1((1.0, 0.0, 0.0)) @test +STaylor1([1.0, 2.0, 3.0]) == STaylor1([1.0, 2.0, 3.0]) @test -STaylor1([1.0, 2.0, 3.0]) == -STaylor1([1.0, 2.0, 3.0]) @test STaylor1([1.0, 2.0, 3.0]) + STaylor1([3.0, 2.0, 3.0]) == STaylor1([4.0, 4.0, 6.0]) @test STaylor1([1.0, 2.0, 3.0]) - STaylor1([3.0, 2.0, 4.0]) == STaylor1([-2.0, 0.0, -1.0]) @test STaylor1([1.0, 2.0, 3.0]) + 2.0 == STaylor1([3.0, 2.0, 3.0]) @test STaylor1([1.0, 2.0, 3.0]) - 2.0 == STaylor1([-1.0, 2.0, 3.0]) @test 2.0 + STaylor1([1.0, 2.0, 3.0]) == STaylor1([3.0, 2.0, 3.0]) @test 2.0 - STaylor1([1.0, 2.0, 3.0]) == STaylor1([1.0, -2.0, -3.0]) @test zero(STaylor1([1.0, 2.0, 3.0])) == STaylor1([0.0, 0.0, 0.0]) @test one(STaylor1([1.0, 2.0, 3.0])) == STaylor1([1.0, 0.0, 0.0]) @test_throws ArgumentError STaylor1([1.1, 2.1])/STaylor1([0.0, 2.1]) @test isinf(STaylor1([Inf, 2.0, 3.0])) && ~isinf(STaylor1([0.0, 0.0, 0.0])) @test isnan(STaylor1([NaN, 2.0, 3.0])) && ~isnan(STaylor1([1.0, 0.0, 0.0])) @test iszero(STaylor1([0.0, 0.0, 0.0])) && ~iszero(STaylor1([0.0, 1.0, 0.0])) @test length(STaylor1([0.0, 0.0, 0.0])) == 3 @test size(STaylor1([0.0, 0.0, 0.0])) == 3 @test firstindex(STaylor1([0.0, 0.0, 0.0])) == 0 @test lastindex(STaylor1([0.0, 0.0, 0.0])) == 2 st1 = STaylor1([1.0, 2.0, 3.0]) @test st1(2.0) == 41.0 @test st1() == 1.00 st2 = typeof(st1)[st1; st1] @test st2(2.0)[1] == st2(2.0)[2] == 41.0 @test st2()[1] == st2()[2] == 1.0 @test StaticTaylorSeries.evaluate(st1, 2.0) == 41.0 @test StaticTaylorSeries.evaluate(st1) == 1.00 @test StaticTaylorSeries.evaluate(st2, 2.0)[1] == StaticTaylorSeries.evaluate(st2, 2.0)[2] == 41.0 @test StaticTaylorSeries.evaluate(st2)[1] == StaticTaylorSeries.evaluate(st2)[2] == 1.0 @test view(typeof(STaylor1([1.1, 2.1]))[STaylor1([1.1, 2.1]) STaylor1([1.1, 2.1]); STaylor1([1.1, 2.1]) STaylor1([1.1, 2.1])], :, 1)(0.0) == Float64[1.1; 1.1] @test view(typeof(STaylor1([1.1, 2.1]))[STaylor1([1.1, 2.1]) STaylor1([1.1, 2.1]); STaylor1([1.1, 2.1]) STaylor1([1.1, 2.1])], :, 1)() == Float64[1.1; 1.1] # check that STaylor1 and Taylor yeild same result t1 = STaylor1([1.1, 2.1, 3.1]) t2 = Taylor1([1.1, 2.1, 3.1]) for f in (exp, abs, log, sin, cos, sinh, cosh, mod2pi, sqrt, abs2, deg2rad, rad2deg) @test test_vs_Taylor1(f(t1), f(t2)) end @test DR.StaticTaylorSeries.get_order(t1) == 2 @test axes(t1) isa Tuple{} @test iterate(t1)[1] == 1.10 @test iterate(t1)[2] == 1 @test eachindex(t1) == 0:2 @test t1[:] == (1.10, 2.10, 3.10) @test t1[1:2] == (2.10, 3.10) @test t1[0:2:2] == (1.10, 3.10) @test rem(t1, 2) == t1 @test mod(t1, 2) == t1 @test STaylor1([1.1, 2.1, 3.1], Val(3), Val(5)) == STaylor1([1.1, 2.1, 3.1, 0.0, 0.0, 0.0]) t1_mod = mod(t1, 2.0) t2_mod = mod(t2, 2.0) @test isapprox(t1_mod[0], t2_mod[0], atol = 1E-10) @test isapprox(t1_mod[1], t2_mod[1], atol = 1E-10) @test isapprox(t1_mod[2], t2_mod[2], atol = 1E-10) t1_rem = rem(t1, 2.0) t2_rem = rem(t2, 2.0) @test isapprox(t1_rem[0], t2_rem[0], atol = 1E-10) @test isapprox(t1_rem[1], t2_rem[1], atol = 1E-10) @test isapprox(t1_rem[2], t2_rem[2], atol = 1E-10) t1a = STaylor1([2.1, 2.1, 3.1]) t2a = Taylor1([2.1, 2.1, 3.1]) for test_tup in ( (/, t1, t1a, t2, t2a), (*, t1, t1a, t2, t2a), (/, t1, 1.3, t2, 1.3), (*, t1, 1.3, t2, 1.3), (+, t1, 1.3, t2, 1.3), (-, t1, 1.3, t2, 1.3), (*, 1.3, t1, 1.3, t2), (+, 1.3, t1, 1.3, t2), (-, 1.3, t1, 1.3, t2), (*, 1.3, t1, 1.3, t2), (^, t1, 0, t2, 0), (^, t1, 1, t2, 1), (^, t1, 2, t2, 2), (^, t1, 3, t2, 3), (^, t1, 4, t2, 4), (/, 1.3, t1, 1.3, t2), #(^, t1, -1, t2, -1), #(^, t1, -2, t2, -2), #(^, t1, -3, t2, -3), (^, t1, 0.6, t2, 0.6), (^, t1, 1 / 2, t2, 1 / 2), ) temp1 = test_tup[1](test_tup[2], test_tup[3]) temp2 = test_tup[1](test_tup[4], test_tup[5]) check1 = isapprox(temp1[0], temp2[0], atol = 1E-10) check2 = isapprox(temp1[1], temp2[1], atol = 1E-10) check3 = isapprox(temp1[2], temp2[2], atol = 1E-10) @test check1 @test check2 @test check3 if !check1 || !check2 || !check3 println("$test_tup, $temp1, $temp2") end end @test isapprox( StaticTaylorSeries.square(t1)[0], (t2^2)[0], atol = 1E-10, ) @test isapprox( StaticTaylorSeries.square(t1)[1], (t2^2)[1], atol = 1E-10, ) @test isapprox( StaticTaylorSeries.square(t1)[2], (t2^2)[2], atol = 1E-10, ) a = STaylor1([0.0, 1.2, 2.3, 4.5, 0.0]) @test findfirst(a) == 1 @test findlast(a) == 3 eval_staylor = StaticTaylorSeries.evaluate(a, Interval(1.0, 2.0)) @test isapprox(eval_staylor.lo, 7.99999, atol = 1E-4) @test isapprox(eval_staylor.hi, 47.599999999999994, atol = 1E-4) a = STaylor1([5.0, 1.2, 2.3, 4.5, 0.0]) @test isapprox(deg2rad(a)[0], 0.087266, atol = 1E-5) @test isapprox(deg2rad(a)[2], 0.040142, atol = 1E-5) @test isapprox(rad2deg(a)[0], 286.4788975, atol = 1E-5) @test isapprox(rad2deg(a)[2], 131.7802928, atol = 1E-5) @test real(a) == STaylor1([5.0, 1.2, 2.3, 4.5, 0.0]) @test imag(a) == STaylor1([0.0, 0.0, 0.0, 0.0, 0.0]) @test adjoint(a) == STaylor1([5.0, 1.2, 2.3, 4.5, 0.0]) @test conj(a) == STaylor1([5.0, 1.2, 2.3, 4.5, 0.0]) @test a == abs(a) @test a == abs(-a) @test convert( STaylor1{3,Float64}, STaylor1{3,Float64}((1.1, 2.2, 3.3)), ) == STaylor1{3,Float64}((1.1, 2.2, 3.3)) @test convert(STaylor1{3,Float64}, 1) == STaylor1(1.0, Val(3)) @test convert(STaylor1{3,Float64}, 1.2) == STaylor1(1.2, Val(3)) #ta(a) = STaylor1(1.0, Val(15)) @test_broken promote(1.0, STaylor1(1.0, Val(15)))[1] == STaylor1(1.0, Val(16)) @test promote(0, STaylor1(1.0, Val(15)))[1] == STaylor1(0.0, Val(16)) @test_broken eltype(promote(STaylor1(1, Val(15)), 2)[2]) == Int @test_broken eltype(promote(STaylor1(1.0, Val(15)), 1.1)[2]) == Float64 @test eltype(promote(0, STaylor1(1.0, Val(15)))[1]) == Float64 @test_broken promote_rule(typeof(STaylor1([1.1, 2.1])), typeof(STaylor1([1.1, 2.1]))) == STaylor1{2,Float64} @test_broken promote_rule(typeof(STaylor1([1.1, 2.1])), typeof(STaylor1([1, 2]))) == STaylor1{2,Float64} @test_broken promote_rule(typeof(STaylor1([1.1, 2.1])), typeof([1.1, 2.1])) == STaylor1{2,Float64} @test_broken promote_rule(typeof(STaylor1([1.1, 2.1])), typeof([1, 2])) == STaylor1{2,Float64} @test_broken promote_rule(typeof(STaylor1([1.1, 2.1])), typeof(1.1)) == STaylor1{2,Float64} @test promote_rule(typeof(STaylor1([1.1, 2.1])), typeof(1)) == STaylor1{2,Float64} #TODO: FAILING @test convert(STaylor1{2,Float64}, [1; 2]) == STaylor1(Float64[1, 2]) @test convert(STaylor1{2,Float64}, [1.1; 2.1]) == STaylor1([1.1, 2.1]) @test convert(STaylor1{2,Rational{Int64}}, STaylor1(BigFloat[0.5, 0.75])) == STaylor1([0.5, 0.75]) @test isapprox(StaticTaylorSeries.normalize_taylor(STaylor1([1.1, 2.1]), Interval(1.0, 2.0))[0], 13.7, atol = 1E-8) @test isapprox(StaticTaylorSeries._normalize(STaylor1([1.1, 2.1]), Interval(1.0, 2.0), Val(true))[0], 13.7, atol = 1E-8) @test isapprox(StaticTaylorSeries._normalize(STaylor1([1.1, 2.1]), Interval(1.0, 2.0), Val(false))[0], 13.7, atol = 1E-8) @test_nowarn Base.show(stdout, a) @test StaticTaylorSeries.coeffstring(a, 5) == "0.0t^4" @test StaticTaylorSeries.coeffstring(a, 2) == "1.2t" @test_throws ArgumentError abs(STaylor1([0.0, 2.1])) end end @testset "Lohner's Method Interval Testset" begin ticks = 100.0 steps = 100.0 tend = steps / ticks x0(p) = [9.0] function f!(dx, x, p, t) dx[1] = p[1] - x[1] nothing end tspan = (0.0, tend) pL = [-1.0] pU = [1.0] prob = DBB.ODERelaxProb(f!, tspan, x0, pL, pU) integrator = DiscretizeRelax( prob, DR.LohnerContractor{7}(), h = 1 / ticks, repeat_limit = 1, skip_step2 = false, step_limit = steps, relax = false, ) ratio = rand(1) pstar = pL .* ratio .+ pU .* (1.0 .- ratio) DBB.setall!(integrator, DBB.ParameterValue(), [0.0]) DBB.relax!(integrator) lo_vec = getfield.(getindex.(integrator.storage[:], 1), :lo) hi_vec = getfield.(getindex.(integrator.storage[:], 1), :hi) @test isapprox(lo_vec[7], 8.417645335842485, atol = 1E-5) @test isapprox(hi_vec[7], 8.534116268673994, atol = 1E-5) end @testset "Lohner's Method MC Testset" begin ticks = 100.0 steps = 100.0 tend = steps / ticks x0(p) = [9.0] function f!(dx, x, p, t) dx[1] = p[1] - x[1] nothing end tspan = (0.0, tend) pL = [-0.3] pU = [0.3] prob = DynamicBoundsBase.ODERelaxProb(f!, tspan, x0, pL, pU) integrator = DiscretizeRelax( prob, DynamicBoundspODEsDiscrete.LohnerContractor{7}(), h = 1 / ticks, repeat_limit = 1, skip_step2 = false, step_limit = steps, relax = true, ) ratio = rand(1) pstar = pL .* ratio .+ pU .* (1.0 .- ratio) DynamicBoundsBase.setall!(integrator, DynamicBoundsBase.ParameterValue(), [0.0]) DynamicBoundsBase.relax!(integrator) lo_vec = getfield.(getfield.(getindex.(integrator.storage[:], 1), :Intv), :lo) hi_vec = getfield.(getfield.(getindex.(integrator.storage[:], 1), :Intv), :hi) @test isapprox(lo_vec[6], 8.546433647856642, atol = 1E-5) @test isapprox(hi_vec[6], 8.575695993156213, atol = 1E-5) support_set = DBB.get(integrator, DBB.SupportSet()) out = Matrix{Float64}[] for i = 1:1 push!(out, zeros(1,length(support_set.s))) end # DBB.getall!(out, integrator, DBB.Subgradient{Lower}()) # @test isapprox(out[1][1,10], 0.08606881472877183, atol=1E-8) # DBB.getall!(out, integrator, DBB.Subgradient{Upper}()) # @test isapprox(out[1][1,10], 0.08606881472877183, atol=1E-8) #out = zeros(1, length(support_set.s)) #DBB.getall!(out, integrator, DBB.Bound{Lower}()) #@test isapprox(out[1,10], 8.199560023022423, atol=1E-8) #DBB.getall!(out, integrator, DBB.Bound{Upper}()) #@test isapprox(out[1,10], 8.251201311859687, atol=1E-8) #DBB.getall!(out, integrator, DBB.Relaxation{Lower}()) #@test isapprox(out[1,10], 8.225380667441055, atol=1E-8) # #DBB.getall!(out, integrator, DBB.Relaxation{Upper}()) #@test isapprox(out[1,10], 8.225380667441055, atol=1E-8) # #out = DBB.getall(integrator, DBB.Subgradient{Lower}()) #@test isapprox(out[1][1,10], 0.08606881472877183, atol=1E-8) #out = DBB.getall(integrator, DBB.Subgradient{Upper}()) #@test isapprox(out[1][1,10], 0.08606881472877183, atol=1E-8) #out = DBB.getall(integrator, DBB.Bound{Lower}()) #@test isapprox(out[1,10], 8.199560023022423, atol=1E-8) #out = DBB.getall(integrator, DBB.Bound{Upper}()) #@test isapprox(out[1,10], 8.251201311859687, atol=1E-8) #out = DBB.getall(integrator, DBB.Relaxation{Lower}()) #@test isapprox(out[1,10], 8.225380667441055, atol=1E-8) #out = DBB.getall(integrator, DBB.Relaxation{Upper}()) #@test isapprox(out[1,10], 8.225380667441055, atol=1E-8) #outvec = zeros(length(support_set.s)) #DBB.getall!(outvec, integrator, DBB.Bound{Lower}()) #@test isapprox(outvec[10], 8.199560023022423, atol=1E-8) #DBB.getall!(outvec, integrator, DBB.Bound{Upper}()) #@test isapprox(outvec[10], 8.251201311859687, atol=1E-8) #DBB.getall!(outvec, integrator, DBB.Relaxation{Lower}()) #@test isapprox(outvec[10], 8.225380667441055, atol=1E-8) #DBB.getall!(outvec, integrator, DBB.Relaxation{Upper}()) #@test isapprox(outvec[10], 8.225380667441055, atol=1E-8) end @testset "Wilhelm 2019 Integrator Testset" begin Y = Interval(0,5) X1 = Interval(1,2) X2 = Interval(-10,10) X3 = Interval(0,5) flag1 = DR.strict_x_in_y(X1,Y) flag2 = DR.strict_x_in_y(X2,Y) flag3 = DR.strict_x_in_y(X3,Y) @test flag1 == true @test flag2 == false @test flag3 == false A1 = Interval(0) A2 = Interval(0,3) A3 = Interval(-2,0) A4 = Interval(-3,2) ind1,B1,C1 = DR.extended_divide(A1) ind2,B2,C2 = DR.extended_divide(A2) ind3,B3,C3 = DR.extended_divide(A3) ind4,B4,C4 = DR.extended_divide(A4) @test ind1 == 0 @test ind2 == 1 @test ind3 == 2 @test ind4 == 3 @test B1 == Interval(-Inf,Inf) @test 0.33333 - 1E-4 <= B2.lo <= 0.33333 + 1E-4 @test B2.hi == Inf @test B3 == Interval(-Inf,-0.5) @test B4.lo == -Inf @test -0.33333 - 1E-4 <= B4.hi <= -0.33333 + 1E-4 @test C1 == Interval(-Inf,Inf) @test C2 == Interval(Inf,Inf) @test C3 == Interval(-Inf,-Inf) @test C4 == Interval(0.5,Inf) N = Interval(-5,5) X = Interval(-5,5) Mii = Interval(-5,5) B = Interval(-5,5) rtol = 1E-4 indx1,box11,box12 = DR.extended_process(N,X,Mii,B,rtol) Miib = Interval(0,5) S1b = Interval(1,5) S2b = Interval(1,5) Bb = Interval(1,5) indx2,box21,box22 = DR.extended_process(N,X,Mii,B,rtol) Miic = Interval(-5,0) S1c = Interval(1,5) S2c = Interval(1,5) Bc = Interval(1,5) indx3,box31,box32 = DR.extended_process(N,X,Mii,B,rtol) Miia = Interval(1,5) S1a = Interval(1,5) S2a = Interval(1,5) Ba = Interval(1,5) indx6,box61,box62 = DR.extended_process(N,X,Mii,B,rtol) Miid = Interval(0,0) S1d = Interval(1,5) S2d = Interval(1,5) Bd = Interval(1,5) indx8,box81,box82 = DR.extended_process(N,X,Mii,B,rtol) @test indx1 == 0 @test box11 == Interval(-Inf,Inf) @test box12 == Interval(-5,5) @test indx2 == 0 @test box21.hi > -Inf @test box22 == Interval(-5,5) @test indx3 == 0 @test box31.lo < Inf @test box32 == Interval(-5,5) @test indx6 == 0 @test box62.lo == -5.0 @test box61.hi == Inf @test indx8 == 0 end @testset "Discretize and Relax - Access Functions" begin use_relax = false lohners_type = 1 prob_num = 1 ticks = 100.0 steps = 100.0 tend = steps / ticks x0(p) = [1.2; 1.1] function f!(dx, x, p, t) dx[1] = p[1] * x[1] * (one(typeof(p[1])) - x[2]) dx[2] = p[1] * x[2] * (x[1] - one(typeof(p[1]))) nothing end tspan = (0.0, tend) pL = [2.95] pU = [3.05] prob = DBB.ODERelaxProb(f!, tspan, x0, pL, pU) integrator = DiscretizeRelax( prob, DynamicBoundspODEsDiscrete.LohnerContractor{7}(), h = 1 / ticks, repeat_limit = 1, skip_step2 = false, step_limit = steps, relax = use_relax, ) @test DBB.supports(integrator, DBB.IntegratorName()) @test !DBB.supports(integrator, DBB.Gradient()) @test DBB.supports(integrator, DBB.Subgradient()) @test DBB.supports(integrator, DBB.Bound()) @test DBB.supports(integrator, DBB.Relaxation()) @test DBB.supports(integrator, DBB.IsNumeric()) @test DBB.supports(integrator, DBB.IsSolutionSet()) @test DBB.supports(integrator, DBB.TerminationStatus()) @test DBB.supports(integrator, DBB.Value()) @test DBB.supports(integrator, DBB.ParameterValue()) @test DBB.supports(integrator, DBB.SupportSet()) @test DBB.get(integrator, DBB.IntegratorName()) == "Discretize & Relax Integrator" @test !DBB.get(integrator, DBB.IsNumeric()) @test DBB.get(integrator, DBB.IsSolutionSet()) @test DBB.get(integrator, DBB.TerminationStatus()) == RELAXATION_NOT_CALLED DBB.set!(integrator, DBB.SupportSet(Float64[i for i in range(0.0, tend, length = 200)])) ratio = rand(1) pstar = pL .* ratio .+ pU .* (1.0 .- ratio) DBB.setall!(integrator, DBB.ParameterValue(), [0.0]) DBB.relax!(integrator) DBB.setall!(integrator, DBB.ParameterBound{Lower}(), [2.99]) DBB.setall!(integrator, DBB.ParameterBound{Upper}(), [3.01]) support_set = DBB.get(integrator, DBB.SupportSet()) #@test support_set.s[3] == 0.02 #= out = Matrix{Float64}[] for i in 1:1 push!(out, zeros(1,length(support_set.s))) end DBB.getall!(out, integrator, DBB.Subgradient{Lower}()) @test out[1][1,10] == 0.0 DBB.getall!(out, integrator, DBB.Subgradient{Upper}()) @test out[1][1,10] == 0.0 out = zeros(1,length(support_set.s)) DBB.getall!(out, integrator, DBB.Bound{Lower}()) @test isapprox(out[1,10], 1.1507186500504751, atol=1E-8) DBB.getall!(out, integrator, DBB.Bound{Upper}()) @test isapprox(out[1,10], 1.1534467709985823, atol=1E-8) DBB.getall!(out, integrator, DBB.Relaxation{Lower}()) @test isapprox(out[1,10], 1.1507186500504751, atol=1E-8) DBB.getall!(out, integrator, DBB.Relaxation{Upper}()) @test isapprox(out[1,10], 1.1534467709985823, atol=1E-8) out = DBB.getall(integrator, DBB.Subgradient{Lower}()) @test out[1][1,10] == 0.0 out = DBB.getall(integrator, DBB.Subgradient{Upper}()) @test out[1][1,10] == 0.0 out = DBB.getall(integrator, DBB.Bound{Lower}()) @test isapprox(out[1,10], 1.1507186500504751, atol=1E-8) out = DBB.getall(integrator, DBB.Bound{Upper}()) @test isapprox(out[1,10], 1.1534467709985823, atol=1E-8) out = DBB.getall(integrator, DBB.Relaxation{Lower}()) @test isapprox(out[1,10], 1.1507186500504751, atol=1E-8) out = DBB.getall(integrator, DBB.Relaxation{Upper}()) @test isapprox(out[1,10], 1.1534467709985823, atol=1E-8) =# end
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.3.0
f6b0e7a88bb6b16aff318c9f6436704a8828aa0b
docs
2804
# DynamicBoundspODEsDiscrete.jl Parametric Discretize-and-Relax methods within DynamicBounds.jl | **Linux/OS/Windows** | **Coverage** | |:-------------------------------------------------------:|:-------------------------------------------------------:| | [![Build Status](https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl/workflows/CI/badge.svg?branch=master)](https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl/actions?query=workflow%3ACI) | [![codecov](https://codecov.io/gh/PSORLab/DynamicBoundspODEsDiscrete.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/PSORLab/DynamicBoundspODEsDiscrete.jl) | ## Summary This package implements a discretize-and-relax approaches to computing state bounds and relaxations using the DynamicBounds.jl framework. These methods discretize the time domain over into a finite number of points and then compute valid relaxations at these time-points. Full documentation of this functionality may be found [here](https://psorlab.github.io/DynamicBounds.jl/dev/pODEsDiscrete/pODEsDiscrete) in the DynamicBounds.jl website. ## Installation ```julia using Pkg; Pkg.add("DynamicBoundspODEsDiscrete") ``` or using the following command in the package manager environment ``` pkg > add DynamicBoundspODEsDiscrete ``` Note that this package can also be used directly via DynamicBounds.jl as the later package automatically reexports it. ## References - Corliss, G. F., & Rihm, R. (1996). Validating an a priori enclosure using high-order Taylor series. MATHEMATICAL RESEARCH, 90, 228-238. - Lohner, R. J. (1992, January). Computation of guaranteed enclosures for the solutions of ordinary initial and boundary value problems. In Institute of mathematics and its applications conference series (Vol. 39, pp. 425-425). Oxford University Press. - Nedialkov, Nedialko S., and Kenneth R. Jackson. "An interval Hermite-Obreschkoff method for computing rigorous bounds on the solution of an initial value problem for an ordinary differential equation." Reliable Computing 5.3 (1999): 289-310. - Nedialkov, Nedialko Stoyanov. Computing rigorous bounds on the solution of an initial value problem for an ordinary differential equation. University of Toronto, 2000. - Nedialkov, N. S., & Jackson, K. R. (2000). ODE software that computes guaranteed bounds on the solution. In Advances in Software Tools for Scientific Computing (pp. 197-224). Springer, Berlin, Heidelberg. - Sahlodin, A. M., & Chachuat, B. (2011). Discretize-then-relax approach for convex/concave relaxations of the solutions of parametric ODEs. Applied Numerical Mathematics, 61(7), 803-820. - Wilhelm, M. E., Le, A. V., & Stuber, M. D. (2019). Global optimization of stiff dynamical systems. AIChE Journal, 65(12), e16836
DynamicBoundspODEsDiscrete
https://github.com/PSORLab/DynamicBoundspODEsDiscrete.jl.git
[ "MIT" ]
0.1.2
fb0f291ac3d4e106a316d600df746dac11624388
code
1099
using Pkg;Pkg.activate(".") using PairVelocities using StaticArrays using BenchmarkTools using DelimitedFiles rbins = LinRange(0.001,150.,150) rbins_c = 0.5*(rbins[2:end] + rbins[1:end-1]) filename = "moments.csv" positions, velocities, boxsize, redshift = read_abacus() println(positions[:][1:20]) N = size(positions)[end] println("N halos") println(N) positions = convert(Array{Float64}, positions) velocities = convert(Array{Float64}, velocities) moments = PairVelocities.compute_pairwise_velocity_moments( positions, velocities, rbins, boxsize, ) DD = 2 .*moments[1][:] bin_volume = 4/3 * pi .* diff(rbins.^3) RR = N * (N-1)/boxsize^3 * bin_volume println(DD) println(RR) xi = DD./RR .- 1. open(filename; write=true) do f write(f, "r_c\txi\tv_r\tsigma_r\tsigma_t\tskewness_r\tskewness_rt\tkurtosis_r\tkurtosis_t\tkurtosis_rt\n") writedlm(f, zip(rbins_c, xi, moments[2][:], moments[3][:], moments[6][:], moments[4][:], moments[7][:], moments[5][:], moments[8][:], moments[9][:])) end println("Wrote file !")
PairVelocities
https://github.com/florpi/PairVelocities.jl.git
[ "MIT" ]
0.1.2
fb0f291ac3d4e106a316d600df746dac11624388
code
942
using Profile, PProf using Pkg;Pkg.activate(".") using PairwiseVelocities using StaticArrays using BenchmarkTools using DelimitedFiles boxsize = 2000. rbins = LinRange(0.,50,50) rbins_c = 0.5*(rbins[2:end] + rbins[1:end-1]) filename = "moments.csv" logn = -5. run = 101 snapshot = 15 positions, velocities = read_data(run, snapshot, 10^logn, boxsize) positions = convert(Array{Float64}, positions) velocities = convert(Array{Float64}, velocities) moments = PairwiseVelocities.compute_pairwise_velocity_moments( positions, velocities, rbins, boxsize, ) open(filename; write=true) do f write(f, "# r_c v_r sigma_r sigma_t skewness_r skewness_rt kurtosis_r kurtosis_t kurtosis_rt \n") writedlm(f, zip(rbins_c, moments[2][:], moments[3][:], moments[6][:], moments[4][:], moments[7][:], moments[5][:], moments[8][:], moments[9][:])) end println("Wrote file !")
PairVelocities
https://github.com/florpi/PairVelocities.jl.git
[ "MIT" ]
0.1.2
fb0f291ac3d4e106a316d600df746dac11624388
code
3532
using Profile, PProf using Pkg;Pkg.activate(".") using PairwiseVelocities using BenchmarkTools using DelimitedFiles using ArgParse function parse_commandline() s = ArgParseSettings() @add_arg_table s begin "--snapshot" help = "an option with an argument" arg_type = Int "--nd" help = "an option with an argument" arg_type = Int "--min_run" help = "an option with an argument" arg_type = Int "--max_run" help = "another option with an argument" arg_type = Int end return parse_args(s) end parsed_args = parse_commandline() DATA_DIR = "/cosma7/data/dp004/dc-cues1/DarkQuest/pairwise_velocities/" snapshot = parsed_args["snapshot"] boxsize = 2000. r_max = 80. number_densities = readdlm("/cosma6/data/dp004/dc-cues1/DarkQuest/xi/log10density_table.dat", ' ', Float32, '\n') number_density_left = number_densities[parsed_args["nd"],1] number_density_right = number_densities[parsed_args["nd"],2] println("number densities = ( ", number_density_left, " , ",number_density_right," ) ") rbins_c = readdlm("/cosma6/data/dp004/dc-cues1/DarkQuest/xi/separation.dat", '\t', Float64, '\n') rbins_c = rbins_c[rbins_c .< r_max] rbins = zeros(Float64, length(rbins_c)+1) rbins[2:end-1] = rbins_c[1:end-1] + diff(rbins_c)/2. rbins[1] = 2. *rbins_c[1] - rbins[2] rbins[end] = 2. *rbins_c[end] - rbins[end-1] r_max = maximum(rbins) rbins_c = 0.5*(rbins[2:end] + rbins[1:end-1]) for run in parsed_args["min_run"]:parsed_args["max_run"] filename = "run$(run)_nd_$(abs(number_density_left))_$(abs(number_density_right))_snapshot$(snapshot).csv" println(filename) if number_density_left == number_density_right positions, velocities = read_data( run, snapshot, 10^number_density_left, boxsize ) positions = convert(Array{Float64}, positions) velocities = convert(Array{Float64}, velocities) @time moments = PairwiseVelocities.compute_pairwise_velocity_moments( positions, velocities, rbins, boxsize, ) else positions_left, velocities_left = read_data( run, snapshot, 10^number_density_left, boxsize ) positions_left = convert(Array{Float64}, positions_left) velocities_left = convert(Array{Float64}, velocities_left) positions_right, velocities_right = read_data( run, snapshot, 10^number_density_right, boxsize ) positions_right = convert(Array{Float64}, positions_right) velocities_right = convert(Array{Float64}, velocities_right) @time moments = PairwiseVelocities.compute_pairwise_velocity_moments( positions_left, velocities_left, positions_right, velocities_right, rbins, boxsize, ) end open(DATA_DIR * filename; write=true) do f write(f, "# r_c v_r sigma_r sigma_t skewness_r skewness_rt kurtosis_r kurtosis_t kurtosis_rt \n") writedlm(f, zip(rbins_c, moments[2][:], moments[3][:], moments[6][:], moments[4][:], moments[7][:], moments[5][:], moments[8][:], moments[9][:])) end println("Wrote file for $(run)!") end
PairVelocities
https://github.com/florpi/PairVelocities.jl.git
[ "MIT" ]
0.1.2
fb0f291ac3d4e106a316d600df746dac11624388
code
70
module PairVelocities include("pairvels.jl") include("read.jl") end
PairVelocities
https://github.com/florpi/PairVelocities.jl.git
[ "MIT" ]
0.1.2
fb0f291ac3d4e106a316d600df746dac11624388
code
11480
using CellListMap using StaticArrays using LinearAlgebra export test export compute_pairwise_velocity_moments export compute_pairwise_velocity_los_pdf global n_moments = 9 function compute_pairwise_mean!(x,y,i,j,d2,hist,velocities, rbins,sides) d = x - y r = sqrt.(d2) ibin = searchsortedfirst(rbins, r) - 1 dv = velocities[i] - velocities[j] v_r = LinearAlgebra.dot(dv,d)/r cos_theta = d[3]/r sin_theta = sqrt(d[1]*d[1]+d[2]*d[2])/r cos_phi = d[1]/sqrt(d[1]*d[1]+d[2]*d[2]) sin_phi = d[2]/sqrt(d[1]*d[1]+d[2]*d[2]) if(sqrt(d[1]*d[1]+d[2]*d[2]) < 1e-10) cos_phi = 1.0 sin_phi = 0.0 end v_t = dv[1] * cos_theta * cos_phi + dv[2] * cos_theta * sin_phi - dv[3] * sin_theta if ibin > 0 hist[1][ibin] += 1 hist[2][ibin] += v_r # v_r hist[3][ibin] += v_r * v_r # std_r hist[4][ibin] += v_r * v_r * v_r # skew_r hist[5][ibin] += v_r * v_r * v_r * v_r # kur_r hist[6][ibin] += v_t * v_t # std_t hist[7][ibin] += v_r * v_t * v_t # skew_rt hist[8][ibin] += v_t * v_t * v_t * v_t # kur_t hist[9][ibin] += v_r * v_r * v_t * v_t # kur_rt end return hist end function compute_pairwise_mean!(x,y,i,j,d2,hist,velocities_left, velocities_right, rbins,sides) d = x - y r = sqrt.(d2) ibin = searchsortedfirst(rbins, r) - 1 dv = velocities_left[i] - velocities_right[j] v_r = LinearAlgebra.dot(dv,d)/r cos_theta = d[3]/r sin_theta = sqrt(d[1]*d[1]+d[2]*d[2])/r cos_phi = d[1]/sqrt(d[1]*d[1]+d[2]*d[2]) sin_phi = d[2]/sqrt(d[1]*d[1]+d[2]*d[2]) if(sqrt(d[1]*d[1]+d[2]*d[2]) < 1e-10) cos_phi = 1.0 sin_phi = 0.0 end v_t = dv[1] * cos_theta * cos_phi + dv[2] * cos_theta * sin_phi - dv[3] * sin_theta if ibin > 0 hist[1][ibin] += 1 hist[2][ibin] += v_r hist[3][ibin] += v_r * v_r hist[4][ibin] += v_r * v_r * v_r hist[5][ibin] += v_r * v_r * v_r * v_r hist[6][ibin] += v_t * v_t hist[7][ibin] += v_r * v_t * v_t hist[8][ibin] += v_t * v_t * v_t * v_t hist[9][ibin] += v_r * v_r * v_t * v_t end return hist end function convert_histogram_into_moments!(hist) n_pairs = hist[1] mask = (n_pairs .> 0) hist[2][mask] = hist[2][mask] ./ n_pairs[mask] hist[3][mask] = hist[3][mask] ./ n_pairs[mask] - hist[2][mask].^2 hist[6][mask] = hist[6][mask] ./ n_pairs[mask] hist[4][mask] = ( hist[4][mask] ./ n_pairs[mask] - 3. * hist[2][mask] .* hist[3][mask] - hist[2][mask].^3. ) hist[7][mask] = ( hist[7][mask] ./ n_pairs[mask] - hist[2][mask] .* hist[6][mask] ) hist[5][mask] = ( hist[5][mask] ./ n_pairs[mask] - 4. * hist[2][mask] .* hist[4][mask] - 6. * hist[2][mask].^2. .* hist[3][mask] - hist[2][mask] .^4. ) hist[8][mask] = hist[8][mask] ./ n_pairs[mask] hist[9][mask] = ( hist[9][mask] ./ n_pairs[mask] - 2. * hist[7][mask] .* hist[2][mask] - hist[2][mask].^2 .* hist[6][mask] ) hist[3][:] = sqrt.(hist[3]) hist[6][:] = sqrt.(hist[6]) hist[4][:] = hist[4] ./ hist[3].^3 hist[5][:] = hist[5] ./ hist[3].^4 hist[8][:] = hist[8] ./ hist[6].^4 hist[7][:] = hist[7] ./ hist[3].^2 ./ hist[6] hist[9][:] = hist[9] ./ hist[3].^2 ./ hist[6] .^2 end function reduce_hist(hist,hist_threaded) hist = hist_threaded[1] for i in 2:length(hist_threaded) for moment in 1:n_moments hist[moment] .+= hist_threaded[i][moment] end end return hist end function reduce_hist_los(hist,hist_threaded) hist = hist_threaded[1] for i in 2:length(hist_threaded) hist .+= hist_threaded[i] end return hist end function get_pairwise_velocity_moments( positions, velocities, rbins, boxsize, cl, box ) hist = ( zeros(Int,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), ) hist = map_pairwise!( (x,y,i,j,d2,hist) -> compute_pairwise_mean!(x,y,i,j,d2,hist,velocities, rbins, boxsize), hist, box, cl, reduce=reduce_hist, parallel=true, show_progress=false, ) convert_histogram_into_moments!(hist) return hist end function get_pairwise_velocity_moments( positions_left, velocities_left, positions_right, velocities_right, rbins, boxsize, cl, box ) hist = ( zeros(Int,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), zeros(Float64,length(rbins)-1), ) hist = map_pairwise!( (x,y,i,j,d2,hist) -> compute_pairwise_mean!(x,y,i,j,d2,hist,velocities_left, velocities_right,rbins, boxsize), hist, box, cl, reduce=reduce_hist ) convert_histogram_into_moments!(hist) return hist end function compute_pairwise_velocity_moments( positions, velocities, rbins, boxsize ) println("Using n = ", Threads.nthreads() , " threads") Lbox = [boxsize,boxsize,boxsize] n = size(positions)[2] positions = reshape(reinterpret(SVector{3,Float64},positions),n) velocities = reshape(reinterpret(SVector{3,Float64},velocities),n) r_max = maximum(rbins) box = Box(Lbox, r_max, lcell=1) cl = CellList(positions,box) return get_pairwise_velocity_moments( positions, velocities, rbins, Lbox, cl, box, ) end function compute_pairwise_velocity_moments( positions_left, velocities_left, positions_right, velocities_right, rbins, boxsize ) println("Using n = ", Threads.nthreads() , " threads") Lbox = [boxsize,boxsize,boxsize] positions_left = reshape(reinterpret(SVector{3,Float64},positions_left),size(positions_left)[2]) velocities_left = reshape(reinterpret(SVector{3,Float64},velocities_left),size(velocities_left)[2]) positions_right = reshape(reinterpret(SVector{3,Float64},positions_right),size(positions_right)[2]) velocities_right = reshape(reinterpret(SVector{3,Float64},velocities_right),size(velocities_right)[2]) r_max = maximum(rbins) box = Box(Lbox, r_max, lcell=1) cl = CellList(positions_left, positions_right, box) return get_pairwise_velocity_moments( positions_left, velocities_left, positions_right, velocities_right, rbins, Lbox, cl, box ) end function compute_pairwise_los_pdf!(x,y,i,j,d2,hist,velocities,r_perp_bins, r_parallel_bins, vlos_bins,sides) d = x - y r_perp = sqrt(d[1]^2 + d[2]^2) r_parallel = d[3] vlos = (velocities[i][3] - velocities[j][3])*sign(r_parallel) if (r_perp > minimum(r_perp_bins)) & (r_perp < maximum(r_perp_bins)) & (r_parallel < maximum(r_parallel_bins)) & (r_parallel > minimum(r_parallel_bins)) & (vlos < maximum(vlos_bins)) & (vlos > minimum(vlos_bins)) ibin_perp = searchsortedfirst(r_perp_bins, r_perp) - 1 ibin_parallel = searchsortedfirst(r_parallel_bins, r_parallel) - 1 ibin_vlos = searchsortedfirst(vlos_bins, vlos) - 1 hist[ibin_perp, ibin_parallel, ibin_vlos] += 1 end return hist end function compute_pairwise_los_pdf!(x,y,i,j,d2,hist, velocities_left,velocities_right, r_perp_bins, r_parallel_bins, vlos_bins,sides) d = x - y r_perp = sqrt(d[1]^2 + d[2]^2) r_parallel = d[3] vlos = (velocities_left[i][3] - velocities_right[j][3])*sign(r_parallel) if (r_perp < maximum(r_perp_bins)) & (r_parallel < maximum(r_parallel_bins)) & (r_parallel > minimum(r_parallel_bins)) & (vlos < maximum(vlos_bins)) & (vlos > minimum(vlos_bins)) ibin_perp = searchsortedfirst(r_perp_bins, r_perp) - 1 ibin_parallel = searchsortedfirst(r_parallel_bins, r_parallel) - 1 ibin_vlos = searchsortedfirst(vlos_bins, vlos) - 1 hist[ibin_perp, ibin_parallel, ibin_vlos] += 1 end return hist end function get_pairwise_velocity_los_pdf( positions, velocities, r_perp_bins, r_parallel_bins, vlos_bins, boxsize, cl, box ) hist = zeros(Int,( length(r_perp_bins)-1, length(r_parallel_bins)-1, length(vlos_bins)-1 ) ) return map_pairwise!( (x,y,i,j,d2,hist) -> compute_pairwise_los_pdf!(x,y,i,j,d2,hist,velocities, r_perp_bins, r_parallel_bins, vlos_bins, boxsize), hist, box, cl, reduce=reduce_hist_los, parallel=true, show_progress=false, ) end function get_pairwise_velocity_los_pdf( positions_left, velocities_left, positions_right, velocities_right, r_perp_bins, r_parallel_bins, vlos_bins, boxsize, cl, box ) hist = zeros(Int,( length(r_perp_bins)-1, length(r_parallel_bins)-1, length(vlos_bins)-1 ) ) return map_pairwise!( (x,y,i,j,d2,hist) -> compute_pairwise_los_pdf!(x,y,i,j,d2,hist,velocities_left, velocities_right, r_perp_bins, r_parallel_bins, vlos_bins, boxsize), hist, box, cl, reduce=reduce_hist_los, parallel=true, show_progress=false, ) end function compute_pairwise_velocity_los_pdf( positions, velocities, r_perp_bins, r_parallel_bins, vlos_bins, boxsize ) println("Using n = ", Threads.nthreads() , " threads") Lbox = [boxsize,boxsize,boxsize] r_max = sqrt(maximum(r_perp_bins)^2 + maximum(r_parallel_bins)^2) positions = reshape(reinterpret(SVector{3,Float64},positions),size(positions)[2]) velocities = reshape(reinterpret(SVector{3,Float64},velocities),size(velocities)[2]) box = Box(Lbox, r_max, lcell=1) cl = CellList(positions,box) return get_pairwise_velocity_los_pdf( positions, velocities, r_perp_bins, r_parallel_bins, vlos_bins, Lbox, cl, box, ) end function compute_pairwise_velocity_los_pdf( positions_left, velocities_left, positions_right, velocities_right, r_perp_bins, r_parallel_bins, vlos_bins, boxsize ) println("Using n = ", Threads.nthreads() , " threads") Lbox = [boxsize,boxsize,boxsize] r_max = sqrt(maximum(r_perp_bins)^2 + maximum(r_parallel_bins)^2) positions_left = reshape(reinterpret(SVector{3,Float64},positions_left),size(positions_left)[2]) velocities_left = reshape(reinterpret(SVector{3,Float64},velocities_left),size(velocities_left)[2]) positions_right = reshape(reinterpret(SVector{3,Float64},positions_right),size(positions_right)[2]) velocities_right = reshape(reinterpret(SVector{3,Float64},velocities_right),size(velocities_right)[2]) box = Box(Lbox, r_max, lcell=1) cl = CellList(positions_left,positions_right,box) return get_pairwise_velocity_los_pdf( positions_left, velocities_left, positions_right, velocities_right, r_perp_bins, r_parallel_bins, vlos_bins, Lbox, cl, box, ) end
PairVelocities
https://github.com/florpi/PairVelocities.jl.git
[ "MIT" ]
0.1.2
fb0f291ac3d4e106a316d600df746dac11624388
code
1266
using PyCall export read_data, read_hod, read_my_hod, read_abacus function read_hod(run, snapshot) mimicus = pyimport("mimicus") pos, vel = mimicus.read_raw_data(run=run, snapshot=snapshot,hod=true) return permutedims(pos), permutedims(vel) end function read_my_hod(run, snapshot, galaxy_type) dq = pyimport("dq") pos, vel = dq.read_hod_data(run=run, snapshot=snapshot,galaxy_type=galaxy_type) return permutedims(pos), permutedims(vel) end function read_data(run, snapshot, number_density, boxsize) dq = pyimport("dq") pos, vel, m200c = dq.read_halo_data(run=run, snapshot=snapshot) pos, vel = dq.cut_by_number_density(pos, vel, m200c, number_density, boxsize) return permutedims(pos), permutedims(vel) end function read_data(run, snapshot, min_mass, max_mass, boxsize) dq = pyimport("dq") pos, vel, m200c = dq.read_halo_data(run=run, snapshot=snapshot) mask = (max_mass .>= m200c .>= min_mass) pos = pos[mask,:] vel = vel[mask,:] return permutedims(pos), permutedims(vel) end function read_abacus() pypairvel = pyimport("pypairvel") pos, vel, boxsize, redshift = pypairvel.read_abacus() pos = permutedims(pos) vel = permutedims(vel) return pos, vel, boxsize, redshift end
PairVelocities
https://github.com/florpi/PairVelocities.jl.git
[ "MIT" ]
0.1.2
fb0f291ac3d4e106a316d600df746dac11624388
docs
95
# PairVelocities Code to compute pairwise velocity distributions for cosmological simulations
PairVelocities
https://github.com/florpi/PairVelocities.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
code
733
using Documenter, OceanDistributions import PlutoSliderServer makedocs(; modules=[OceanDistributions], format=Documenter.HTML(), pages=[ "Home" => "index.md", ], repo="https://github.com/gaelforget/OceanDistributions.jl/blob/{commit}{path}#L{line}", sitename="OceanDistributions.jl", authors="gaelforget <[email protected]>", assets=String[], ) lst=("one_dim_diffusion.jl",) for i in lst fil_in=joinpath(@__DIR__,"..", "examples",i) fil_out=joinpath(@__DIR__,"build", i[1:end-2]*"html") PlutoSliderServer.export_notebook(fil_in) mv(fil_in[1:end-2]*"html",fil_out) cp(fil_in,fil_out[1:end-4]*"jl") end deploydocs(; repo="github.com/gaelforget/OceanDistributions.jl", )
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
code
32781
### A Pluto.jl notebook ### # v0.16.0 using Markdown using InteractiveUtils # ╔═╡ 6bf88b5c-3abc-4b03-90bb-a7eb8cb68577 using StochasticDiffEq, UnicodePlots, Statistics # ╔═╡ 96c9b046-6e40-44b1-a19c-b7061f22470d md"""## Eulerian Model Starting from a step function we integrate a diffusion equation in one dimension, `z`, with closed boundary at the top and bottom. """ # ╔═╡ d78532b9-b17e-4a4a-bbab-e249bf852eba begin ## Eulerian function EulerianModel(nt=1) N=20 dt=1e-4 dx=1.0/2/N T=[zeros(N);ones(N)] T0=deepcopy(T) for tt in 1:nt dTr=(circshift(T,-1)-T); dTr[end]=0; dTl=(T-circshift(T,+1)); dTl[1]=0; T.+=(dTr-dTl)*dt/dx/dx end return T,T0 end function plot_EulerianModel(T,T0) plt=lineplot(T0); lineplot!(plt,T) return plt end T,T0=EulerianModel(1000); f=plot_EulerianModel(T,T0) "Eulerian Model Has Completed" end # ╔═╡ 41487611-deba-49fc-a5f7-f4f63f7935c6 md"""## Lagrangian Model Starting from a step-like distribution of two particle groups over the `z=(0,1)` interval. Particle positions evolve according to a standard `Wiener` process. They bounce at the top and bottom boundaries. The charge of particles in one group is 0 at the start; 1 in the other group. Afterwards particles can interact with one another within each model layer. _Credits: the presented model is a simplified version of the `aquacosm` model from Paparella & Vichi M (2020) Stirring, Mixing, Growing: Microscale Processes Change Larger Scale Phytoplankton Dynamics. doi: 10.3389/fmars.2020.00654_ """ # ╔═╡ 32a692ab-4835-4943-8b46-8345ce881eb5 begin ## Lagrangian function solve_paths(u₀) dt=1e-3 f(u,p,t) = 0.0 g(u,p,t) = 0.1 #dt = 1//2^(4) tspan = (0.0,1.0) prob = SDEProblem(f,g,u₀,(0.0,1.0)) solve(prob,EM(),dt=dt) end function fold_tails(z) while !isempty(findall( xor.(z.>1.0,z.<0.0) )) z[findall(z.<0.0)].=-z[findall(z.<0.0)] z[findall(z.>1.0)].=(2.0 .- z[findall(z.>1.0)]) end end ## mix between cells that are at the same level function mix_neighbors(za,ca,zb,cb,p) dz=0.1 for i0 in 1:10 z0=dz*(i0-1) z1=dz*i0 ia=findall((za.>z0).*(za.<=z1)) ib=findall((zb.>z0).*(zb.<=z1)) tmp=mean([ca[ia];cb[ib]]) ca[ia].=(1-p)*ca[ia] .+ p*tmp cb[ib].=(1-p)*cb[ib] .+ p*tmp end end """ main_loop(;p=0.5,nt=5) ``` p=0.5 # fraction of mass exchanged with neighbors every time step nt=5 # number of time steps ``` """ function main_loop(;p=0.5,nt=5) for tt in 1:nt u₀=u₀a sol=solve_paths(u₀) za=sol(0:0.01:1)[:,:] fold_tails(za) u₀a[:]=za[:,end] u₀=u₀b sol=solve_paths(u₀) zb=sol(0:0.01:1)[:,:] fold_tails(zb) u₀b[:]=zb[:,end] mix_neighbors(u₀a,ca,u₀b,cb,p) end return "done with model run" end "Lagrangian model formulated" end # ╔═╡ c86cf1e9-d0b6-48e8-8a01-0dcc591afc85 begin ## Plotting function plot_paths(z) np=size(z,1) plt=lineplot(z[1,:],ylim=(-0.1,1.1)) np>1 ? lineplot!(plt,z[2,:]) : nothing plt end function plot_paths(sol::RODESolution) np=size(sol,1) plt=lineplot(sol(0:0.01:1)[1,:],ylim=(-0.1,1.1)) np>1 ? lineplot!(plt,sol(0:0.01:1)[2,:]) : nothing plt end function gridded_stats(za,ca,zb,cb) out=zeros(10,2) dz=0.1 t=size(za,2) for i0=1:10 z0=0+dz*(i0-1) ia=findall( (za[:,t].>z0).*(za[:,t].<=z0+dz) ); ib=findall( (zb[:,t].>z0).*(zb[:,t].<=z0+dz) ); tmp=[ca[ia,t];cb[ib,t]] out[i0,1]=mean(tmp) out[i0,2]=std(tmp) end out end function plot_stats(st) plt=lineplot(st[:,1],ylim=(-0.1,1.1)) lineplot!(plt,st[:,1].+st[:,2]) lineplot!(plt,st[:,1].-st[:,2]) plt end "Plotting functions" end # ╔═╡ 2195a7a4-30d6-47fe-92db-d7ebef67ef03 begin # initial conditions np=10000 u₀a=0.5*rand(np) ca=zeros(np) u₀b=0.5 .+ 0.5*rand(np) cb=ones(np) "done with initialization" end # ╔═╡ fd2db517-2282-43da-a543-a1ef59a439c2 # Main model run main_loop(p=0.1,nt=10) # ╔═╡ 5ab5321a-15b9-11ec-3321-b7d7cab1ba35 begin # Another run of the dispersion model just for plotting u₀=u₀a sol=solve_paths(u₀) za=sol(0:0.01:1)[:,:] fold_tails(za) fa=plot_paths(za) u₀=u₀b sol=solve_paths(u₀) zb=sol(0:0.01:1)[:,:] fold_tails(zb) fb=plot_paths(zb) ## st=gridded_stats(u₀a,ca,u₀b,cb) fs=plot_stats(st); ## various #εf(z)C(1−C) "figures generated : f, fs, fa, fb" end # ╔═╡ aa7aa58b-e2e7-4b40-aeab-38137f8d4e2d md"""## Summary / Plot Collection From left to right: - solution of the Eulerian model - solution of the Lagrangian model (with irreversible mixing) - pair or Lagrangian trajectories - pair or Lagrangian trajectories """ # ╔═╡ 1df22a2f-c344-4d71-b44d-9a821c14e548 (f,fs,fa,fb) # ╔═╡ 00000000-0000-0000-0000-000000000001 PLUTO_PROJECT_TOML_CONTENTS = """ [deps] Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0" UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" [compat] StochasticDiffEq = "~6.37.1" UnicodePlots = "~2.4.0" """ # ╔═╡ 00000000-0000-0000-0000-000000000002 PLUTO_MANIFEST_TOML_CONTENTS = """ # This file is machine-generated - editing it directly is not advised julia_version = "1.7.0-beta3.0" manifest_format = "2.0" [[deps.Adapt]] deps = ["LinearAlgebra"] git-tree-sha1 = "84918055d15b3114ede17ac6a7182f68870c16f7" uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" version = "3.3.1" [[deps.ArgTools]] uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" [[deps.ArnoldiMethod]] deps = ["LinearAlgebra", "Random", "StaticArrays"] git-tree-sha1 = "f87e559f87a45bece9c9ed97458d3afe98b1ebb9" uuid = "ec485272-7323-5ecc-a04f-4719b315124d" version = "0.1.0" [[deps.ArrayInterface]] deps = ["IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"] git-tree-sha1 = "d84c956c4c0548b4caf0e4e96cf5b6494b5b1529" uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" version = "3.1.32" [[deps.Artifacts]] uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" [[deps.Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" [[deps.BitTwiddlingConvenienceFunctions]] deps = ["Static"] git-tree-sha1 = "652aab0fc0d6d4db4cc726425cadf700e9f473f1" uuid = "62783981-4cbd-42fc-bca8-16325de8dc4b" version = "0.1.0" [[deps.CPUSummary]] deps = ["Hwloc", "IfElse", "Static"] git-tree-sha1 = "ed720e2622820bf584d4ad90e6fcb93d95170b44" uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9" version = "0.1.3" [[deps.ChainRulesCore]] deps = ["Compat", "LinearAlgebra", "SparseArrays"] git-tree-sha1 = "4ce9393e871aca86cc457d9f66976c3da6902ea7" uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" version = "1.4.0" [[deps.CloseOpenIntervals]] deps = ["ArrayInterface", "Static"] git-tree-sha1 = "ce9c0d07ed6e1a4fecd2df6ace144cbd29ba6f37" uuid = "fb6a15b2-703c-40df-9091-08a04967cfa9" version = "0.1.2" [[deps.CommonSolve]] git-tree-sha1 = "68a0743f578349ada8bc911a5cbd5a2ef6ed6d1f" uuid = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2" version = "0.2.0" [[deps.CommonSubexpressions]] deps = ["MacroTools", "Test"] git-tree-sha1 = "7b8a93dba8af7e3b42fecabf646260105ac373f7" uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" version = "0.3.0" [[deps.Compat]] deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] git-tree-sha1 = "4866e381721b30fac8dda4c8cb1d9db45c8d2994" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" version = "3.37.0" [[deps.CompilerSupportLibraries_jll]] deps = ["Artifacts", "Libdl"] uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" [[deps.ConstructionBase]] deps = ["LinearAlgebra"] git-tree-sha1 = "f74e9d5388b8620b4cee35d4c5a618dd4dc547f4" uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9" version = "1.3.0" [[deps.Crayons]] git-tree-sha1 = "3f71217b538d7aaee0b69ab47d9b7724ca8afa0d" uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" version = "4.0.4" [[deps.DEDataArrays]] deps = ["ArrayInterface", "DocStringExtensions", "LinearAlgebra", "RecursiveArrayTools", "SciMLBase", "StaticArrays"] git-tree-sha1 = "31186e61936fbbccb41d809ad4338c9f7addf7ae" uuid = "754358af-613d-5f8d-9788-280bf1605d4c" version = "0.2.0" [[deps.DataAPI]] git-tree-sha1 = "bec2532f8adb82005476c141ec23e921fc20971b" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" version = "1.8.0" [[deps.DataStructures]] deps = ["Compat", "InteractiveUtils", "OrderedCollections"] git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" version = "0.18.10" [[deps.DataValueInterfaces]] git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" version = "1.0.0" [[deps.Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" [[deps.DelimitedFiles]] deps = ["Mmap"] uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" [[deps.DiffEqBase]] deps = ["ArrayInterface", "ChainRulesCore", "DEDataArrays", "DataStructures", "Distributions", "DocStringExtensions", "FastBroadcast", "ForwardDiff", "FunctionWrappers", "IterativeSolvers", "LabelledArrays", "LinearAlgebra", "Logging", "MuladdMacro", "NonlinearSolve", "Parameters", "PreallocationTools", "Printf", "RecursiveArrayTools", "RecursiveFactorization", "Reexport", "Requires", "SciMLBase", "Setfield", "SparseArrays", "StaticArrays", "Statistics", "SuiteSparse", "ZygoteRules"] git-tree-sha1 = "420ad175d5e420e2c55a0ed8a9c18556e6735f80" uuid = "2b5f629d-d688-5b77-993f-72d75c75574e" version = "6.73.2" [[deps.DiffEqJump]] deps = ["ArrayInterface", "Compat", "DataStructures", "DiffEqBase", "FunctionWrappers", "LightGraphs", "LinearAlgebra", "PoissonRandom", "Random", "RandomNumbers", "RecursiveArrayTools", "Reexport", "StaticArrays", "TreeViews", "UnPack"] git-tree-sha1 = "99a65172d95e5ccc016c9be0542fa3858cf97a18" uuid = "c894b116-72e5-5b58-be3c-e6d8d4ac2b12" version = "7.3.0" [[deps.DiffEqNoiseProcess]] deps = ["DiffEqBase", "Distributions", "LinearAlgebra", "Optim", "PoissonRandom", "QuadGK", "Random", "Random123", "RandomNumbers", "RecipesBase", "RecursiveArrayTools", "Requires", "ResettableStacks", "SciMLBase", "StaticArrays", "Statistics"] git-tree-sha1 = "d6839a44a268c69ef0ed927b22a6f43c8a4c2e73" uuid = "77a26b50-5914-5dd7-bc55-306e6241c503" version = "5.9.0" [[deps.DiffResults]] deps = ["StaticArrays"] git-tree-sha1 = "c18e98cba888c6c25d1c3b048e4b3380ca956805" uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" version = "1.0.3" [[deps.DiffRules]] deps = ["NaNMath", "Random", "SpecialFunctions"] git-tree-sha1 = "3ed8fa7178a10d1cd0f1ca524f249ba6937490c0" uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" version = "1.3.0" [[deps.Distances]] deps = ["LinearAlgebra", "Statistics", "StatsAPI"] git-tree-sha1 = "9f46deb4d4ee4494ffb5a40a27a2aced67bdd838" uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" version = "0.10.4" [[deps.Distributed]] deps = ["Random", "Serialization", "Sockets"] uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" [[deps.Distributions]] deps = ["ChainRulesCore", "FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"] git-tree-sha1 = "f4efaa4b5157e0cdb8283ae0b5428bc9208436ed" uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" version = "0.25.16" [[deps.DocStringExtensions]] deps = ["LibGit2"] git-tree-sha1 = "a32185f5428d3986f47c2ab78b1f216d5e6cc96f" uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" version = "0.8.5" [[deps.Downloads]] deps = ["ArgTools", "LibCURL", "NetworkOptions"] uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" [[deps.ExponentialUtilities]] deps = ["ArrayInterface", "LinearAlgebra", "Printf", "Requires", "SparseArrays"] git-tree-sha1 = "7a541ee92e2f8b16356ed6066d0c44b85984b780" uuid = "d4d017d3-3776-5f7e-afef-a10c40355c18" version = "1.9.0" [[deps.FastBroadcast]] deps = ["LinearAlgebra"] git-tree-sha1 = "26be48918640ce002f5833e8fc537b2ba7ed0234" uuid = "7034ab61-46d4-4ed7-9d0f-46aef9175898" version = "0.1.8" [[deps.FastClosures]] git-tree-sha1 = "acebe244d53ee1b461970f8910c235b259e772ef" uuid = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a" version = "0.3.2" [[deps.FillArrays]] deps = ["LinearAlgebra", "Random", "SparseArrays", "Statistics"] git-tree-sha1 = "caf289224e622f518c9dbfe832cdafa17d7c80a6" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" version = "0.12.4" [[deps.FiniteDiff]] deps = ["ArrayInterface", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays"] git-tree-sha1 = "8b3c09b56acaf3c0e581c66638b85c8650ee9dca" uuid = "6a86dc24-6348-571c-b903-95158fe2bd41" version = "2.8.1" [[deps.ForwardDiff]] deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "NaNMath", "Printf", "Random", "SpecialFunctions", "StaticArrays"] git-tree-sha1 = "b5e930ac60b613ef3406da6d4f42c35d8dc51419" uuid = "f6369f11-7733-5829-9624-2563aa707210" version = "0.10.19" [[deps.FunctionWrappers]] git-tree-sha1 = "241552bc2209f0fa068b6415b1942cc0aa486bcc" uuid = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e" version = "1.1.2" [[deps.Future]] deps = ["Random"] uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" [[deps.HostCPUFeatures]] deps = ["BitTwiddlingConvenienceFunctions", "IfElse", "Libdl", "Static"] git-tree-sha1 = "3169c8b31863f9a409be1d17693751314241e3eb" uuid = "3e5b6fbb-0976-4d2c-9146-d79de83f2fb0" version = "0.1.4" [[deps.Hwloc]] deps = ["Hwloc_jll"] git-tree-sha1 = "92d99146066c5c6888d5a3abc871e6a214388b91" uuid = "0e44f5e4-bd66-52a0-8798-143a42290a1d" version = "2.0.0" [[deps.Hwloc_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "3395d4d4aeb3c9d31f5929d32760d8baeee88aaf" uuid = "e33a78d0-f292-5ffc-b300-72abe9b543c8" version = "2.5.0+0" [[deps.IfElse]] git-tree-sha1 = "28e837ff3e7a6c3cdb252ce49fb412c8eb3caeef" uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" version = "0.1.0" [[deps.Inflate]] git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c" uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" version = "0.1.2" [[deps.InteractiveUtils]] deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" [[deps.IrrationalConstants]] git-tree-sha1 = "f76424439413893a832026ca355fe273e93bce94" uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" version = "0.1.0" [[deps.IterativeSolvers]] deps = ["LinearAlgebra", "Printf", "Random", "RecipesBase", "SparseArrays"] git-tree-sha1 = "1a8c6237e78b714e901e406c096fc8a65528af7d" uuid = "42fd0dbc-a981-5370-80f2-aaf504508153" version = "0.9.1" [[deps.IteratorInterfaceExtensions]] git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" uuid = "82899510-4779-5014-852e-03e436cf321d" version = "1.0.0" [[deps.JLLWrappers]] deps = ["Preferences"] git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e" uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" version = "1.3.0" [[deps.LabelledArrays]] deps = ["ArrayInterface", "LinearAlgebra", "MacroTools", "StaticArrays"] git-tree-sha1 = "bdde43e002847c34c206735b1cf860bc3abd35e7" uuid = "2ee39098-c373-598a-b85f-a56591580800" version = "1.6.4" [[deps.LayoutPointers]] deps = ["ArrayInterface", "LinearAlgebra", "ManualMemory", "SIMDTypes", "Static"] git-tree-sha1 = "d2bda6aa0b03ce6f141a2dc73d0bcb7070131adc" uuid = "10f19ff3-798f-405d-979b-55457f8fc047" version = "0.1.3" [[deps.LibCURL]] deps = ["LibCURL_jll", "MozillaCACerts_jll"] uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" [[deps.LibCURL_jll]] deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" [[deps.LibGit2]] deps = ["Base64", "NetworkOptions", "Printf", "SHA"] uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" [[deps.LibSSH2_jll]] deps = ["Artifacts", "Libdl", "MbedTLS_jll"] uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" [[deps.Libdl]] uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" [[deps.LightGraphs]] deps = ["ArnoldiMethod", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"] git-tree-sha1 = "432428df5f360964040ed60418dd5601ecd240b6" uuid = "093fc24a-ae57-5d10-9952-331d41423f4d" version = "1.3.5" [[deps.LineSearches]] deps = ["LinearAlgebra", "NLSolversBase", "NaNMath", "Parameters", "Printf"] git-tree-sha1 = "f27132e551e959b3667d8c93eae90973225032dd" uuid = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" version = "7.1.1" [[deps.LinearAlgebra]] deps = ["Libdl", "libblastrampoline_jll"] uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" [[deps.LogExpFunctions]] deps = ["ChainRulesCore", "DocStringExtensions", "IrrationalConstants", "LinearAlgebra"] git-tree-sha1 = "34dc30f868e368f8a17b728a1238f3fcda43931a" uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" version = "0.3.3" [[deps.Logging]] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" [[deps.LoopVectorization]] deps = ["ArrayInterface", "CPUSummary", "CloseOpenIntervals", "DocStringExtensions", "HostCPUFeatures", "IfElse", "LayoutPointers", "LinearAlgebra", "OffsetArrays", "PolyesterWeave", "Requires", "SLEEFPirates", "Static", "ThreadingUtilities", "UnPack", "VectorizationBase"] git-tree-sha1 = "d469fcf148475a74c221f14d42ee75da7ccb3b4e" uuid = "bdcacae8-1622-11e9-2a5c-532679323890" version = "0.12.73" [[deps.MacroTools]] deps = ["Markdown", "Random"] git-tree-sha1 = "5a5bc6bf062f0f95e62d0fe0a2d99699fed82dd9" uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" version = "0.5.8" [[deps.ManualMemory]] git-tree-sha1 = "9cb207b18148b2199db259adfa923b45593fe08e" uuid = "d125e4d3-2237-4719-b19c-fa641b8a4667" version = "0.1.6" [[deps.Markdown]] deps = ["Base64"] uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" [[deps.MbedTLS_jll]] deps = ["Artifacts", "Libdl"] uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" [[deps.Missings]] deps = ["DataAPI"] git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f" uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" version = "1.0.2" [[deps.Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" [[deps.MozillaCACerts_jll]] uuid = "14a3606d-f60d-562e-9121-12d972cd8159" [[deps.MuladdMacro]] git-tree-sha1 = "c6190f9a7fc5d9d5915ab29f2134421b12d24a68" uuid = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" version = "0.2.2" [[deps.NLSolversBase]] deps = ["DiffResults", "Distributed", "FiniteDiff", "ForwardDiff"] git-tree-sha1 = "144bab5b1443545bc4e791536c9f1eacb4eed06a" uuid = "d41bc354-129a-5804-8e4c-c37616107c6c" version = "7.8.1" [[deps.NLsolve]] deps = ["Distances", "LineSearches", "LinearAlgebra", "NLSolversBase", "Printf", "Reexport"] git-tree-sha1 = "019f12e9a1a7880459d0173c182e6a99365d7ac1" uuid = "2774e3e8-f4cf-5e23-947b-6d7e65073b56" version = "4.5.1" [[deps.NaNMath]] git-tree-sha1 = "bfe47e760d60b82b66b61d2d44128b62e3a369fb" uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" version = "0.3.5" [[deps.NetworkOptions]] uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" [[deps.NonlinearSolve]] deps = ["ArrayInterface", "FiniteDiff", "ForwardDiff", "IterativeSolvers", "LinearAlgebra", "RecursiveArrayTools", "RecursiveFactorization", "Reexport", "SciMLBase", "Setfield", "StaticArrays", "UnPack"] git-tree-sha1 = "35585534c0c79c161241f2e65e759a11a79d25d0" uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" version = "0.3.10" [[deps.OffsetArrays]] deps = ["Adapt"] git-tree-sha1 = "c870a0d713b51e4b49be6432eff0e26a4325afee" uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" version = "1.10.6" [[deps.OpenBLAS_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" [[deps.OpenSpecFun_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1" uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" version = "0.5.5+0" [[deps.Optim]] deps = ["Compat", "FillArrays", "LineSearches", "LinearAlgebra", "NLSolversBase", "NaNMath", "Parameters", "PositiveFactorizations", "Printf", "SparseArrays", "StatsBase"] git-tree-sha1 = "7863df65dbb2a0fa8f85fcaf0a41167640d2ebed" uuid = "429524aa-4258-5aef-a3af-852621145aeb" version = "1.4.1" [[deps.OrderedCollections]] git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c" uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" version = "1.4.1" [[deps.OrdinaryDiffEq]] deps = ["Adapt", "ArrayInterface", "DataStructures", "DiffEqBase", "DocStringExtensions", "ExponentialUtilities", "FastClosures", "FiniteDiff", "ForwardDiff", "LinearAlgebra", "Logging", "LoopVectorization", "MacroTools", "MuladdMacro", "NLsolve", "Polyester", "RecursiveArrayTools", "Reexport", "SparseArrays", "SparseDiffTools", "StaticArrays", "UnPack"] git-tree-sha1 = "66816b9f09c3925ae3b072eb9ef1835c68282ed1" uuid = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" version = "5.64.0" [[deps.PDMats]] deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse"] git-tree-sha1 = "4dd403333bcf0909341cfe57ec115152f937d7d8" uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" version = "0.11.1" [[deps.Parameters]] deps = ["OrderedCollections", "UnPack"] git-tree-sha1 = "2276ac65f1e236e0a6ea70baff3f62ad4c625345" uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" version = "0.12.2" [[deps.Pkg]] deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" [[deps.PoissonRandom]] deps = ["Random", "Statistics", "Test"] git-tree-sha1 = "44d018211a56626288b5d3f8c6497d28c26dc850" uuid = "e409e4f3-bfea-5376-8464-e040bb5c01ab" version = "0.4.0" [[deps.Polyester]] deps = ["ArrayInterface", "BitTwiddlingConvenienceFunctions", "CPUSummary", "IfElse", "ManualMemory", "PolyesterWeave", "Requires", "Static", "StrideArraysCore", "ThreadingUtilities"] git-tree-sha1 = "4a67fa65b250256e214a6a2482c87c835ec0fc02" uuid = "f517fe37-dbe3-4b94-8317-1923a5111588" version = "0.5.0" [[deps.PolyesterWeave]] deps = ["BitTwiddlingConvenienceFunctions", "CPUSummary", "IfElse", "Static", "ThreadingUtilities"] git-tree-sha1 = "371a19bb801c1b420b29141750f3a34d6c6634b9" uuid = "1d0040c9-8b98-4ee7-8388-3f51789ca0ad" version = "0.1.0" [[deps.PositiveFactorizations]] deps = ["LinearAlgebra"] git-tree-sha1 = "17275485f373e6673f7e7f97051f703ed5b15b20" uuid = "85a6dd25-e78a-55b7-8502-1745935b8125" version = "0.2.4" [[deps.PreallocationTools]] deps = ["ArrayInterface", "ForwardDiff", "LabelledArrays"] git-tree-sha1 = "9e917b108c4aaf47e8606542325bd2ccbcac7ca4" uuid = "d236fae5-4411-538c-8e31-a6e3d9e00b46" version = "0.1.0" [[deps.Preferences]] deps = ["TOML"] git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a" uuid = "21216c6a-2e73-6563-6e65-726566657250" version = "1.2.2" [[deps.Printf]] deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" [[deps.QuadGK]] deps = ["DataStructures", "LinearAlgebra"] git-tree-sha1 = "12fbe86da16df6679be7521dfb39fbc861e1dc7b" uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" version = "2.4.1" [[deps.REPL]] deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" [[deps.Random]] deps = ["Serialization"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" [[deps.Random123]] deps = ["Libdl", "Random", "RandomNumbers"] git-tree-sha1 = "0e8b146557ad1c6deb1367655e052276690e71a3" uuid = "74087812-796a-5b5d-8853-05524746bad3" version = "1.4.2" [[deps.RandomNumbers]] deps = ["Random", "Requires"] git-tree-sha1 = "441e6fc35597524ada7f85e13df1f4e10137d16f" uuid = "e6cf234a-135c-5ec9-84dd-332b85af5143" version = "1.4.0" [[deps.RecipesBase]] git-tree-sha1 = "44a75aa7a527910ee3d1751d1f0e4148698add9e" uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" version = "1.1.2" [[deps.RecursiveArrayTools]] deps = ["ArrayInterface", "ChainRulesCore", "DocStringExtensions", "LinearAlgebra", "RecipesBase", "Requires", "StaticArrays", "Statistics", "ZygoteRules"] git-tree-sha1 = "00bede2eb099dcc1ddc3f9ec02180c326b420ee2" uuid = "731186ca-8d62-57ce-b412-fbd966d074cd" version = "2.17.2" [[deps.RecursiveFactorization]] deps = ["LinearAlgebra", "LoopVectorization", "Polyester", "StrideArraysCore", "TriangularSolve"] git-tree-sha1 = "575c18c6b00ce409f75d96fefe33ebe01575457a" uuid = "f2c3362d-daeb-58d1-803e-2bc74f2840b4" version = "0.2.4" [[deps.Reexport]] git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b" uuid = "189a3867-3050-52da-a836-e630ba90ab69" version = "1.2.2" [[deps.Requires]] deps = ["UUIDs"] git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621" uuid = "ae029012-a4dd-5104-9daa-d747884805df" version = "1.1.3" [[deps.ResettableStacks]] deps = ["StaticArrays"] git-tree-sha1 = "256eeeec186fa7f26f2801732774ccf277f05db9" uuid = "ae5879a3-cd67-5da8-be7f-38c6eb64a37b" version = "1.1.1" [[deps.Rmath]] deps = ["Random", "Rmath_jll"] git-tree-sha1 = "bf3188feca147ce108c76ad82c2792c57abe7b1f" uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" version = "0.7.0" [[deps.Rmath_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "68db32dff12bb6127bac73c209881191bf0efbb7" uuid = "f50d1b31-88e8-58de-be2c-1cc44531875f" version = "0.3.0+0" [[deps.SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" [[deps.SIMDTypes]] git-tree-sha1 = "330289636fb8107c5f32088d2741e9fd7a061a5c" uuid = "94e857df-77ce-4151-89e5-788b33177be4" version = "0.1.0" [[deps.SLEEFPirates]] deps = ["IfElse", "Static", "VectorizationBase"] git-tree-sha1 = "947491c30d4293bebb00781bcaf787ba09e7c20d" uuid = "476501e8-09a2-5ece-8869-fb82de89a1fa" version = "0.6.26" [[deps.SciMLBase]] deps = ["ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "RecipesBase", "RecursiveArrayTools", "StaticArrays", "Statistics", "Tables", "TreeViews"] git-tree-sha1 = "ff686e0c79dbe91767f4c1e44257621a5455b1c6" uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462" version = "1.18.7" [[deps.Serialization]] uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" [[deps.Setfield]] deps = ["ConstructionBase", "Future", "MacroTools", "Requires"] git-tree-sha1 = "fca29e68c5062722b5b4435594c3d1ba557072a3" uuid = "efcf1570-3423-57d1-acb7-fd33fddbac46" version = "0.7.1" [[deps.SharedArrays]] deps = ["Distributed", "Mmap", "Random", "Serialization"] uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" [[deps.SimpleTraits]] deps = ["InteractiveUtils", "MacroTools"] git-tree-sha1 = "5d7e3f4e11935503d3ecaf7186eac40602e7d231" uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" version = "0.9.4" [[deps.Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" [[deps.SortingAlgorithms]] deps = ["DataStructures"] git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508" uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" version = "1.0.1" [[deps.SparseArrays]] deps = ["LinearAlgebra", "Random"] uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [[deps.SparseDiffTools]] deps = ["Adapt", "ArrayInterface", "Compat", "DataStructures", "FiniteDiff", "ForwardDiff", "LightGraphs", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays", "VertexSafeGraphs"] git-tree-sha1 = "aebcead0644d3b3396c205a09544590b5115e282" uuid = "47a9eef4-7e08-11e9-0b38-333d64bd3804" version = "1.16.4" [[deps.SpecialFunctions]] deps = ["ChainRulesCore", "LogExpFunctions", "OpenSpecFun_jll"] git-tree-sha1 = "a322a9493e49c5f3a10b50df3aedaf1cdb3244b7" uuid = "276daf66-3868-5448-9aa4-cd146d93841b" version = "1.6.1" [[deps.Static]] deps = ["IfElse"] git-tree-sha1 = "a8f30abc7c64a39d389680b74e749cf33f872a70" uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" version = "0.3.3" [[deps.StaticArrays]] deps = ["LinearAlgebra", "Random", "Statistics"] git-tree-sha1 = "3240808c6d463ac46f1c1cd7638375cd22abbccb" uuid = "90137ffa-7385-5640-81b9-e52037218182" version = "1.2.12" [[deps.Statistics]] deps = ["LinearAlgebra", "SparseArrays"] uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [[deps.StatsAPI]] git-tree-sha1 = "1958272568dc176a1d881acb797beb909c785510" uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0" version = "1.0.0" [[deps.StatsBase]] deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"] git-tree-sha1 = "8cbbc098554648c84f79a463c9ff0fd277144b6c" uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" version = "0.33.10" [[deps.StatsFuns]] deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "Reexport", "Rmath", "SpecialFunctions"] git-tree-sha1 = "46d7ccc7104860c38b11966dd1f72ff042f382e4" uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" version = "0.9.10" [[deps.StochasticDiffEq]] deps = ["ArrayInterface", "DataStructures", "DiffEqBase", "DiffEqJump", "DiffEqNoiseProcess", "DocStringExtensions", "FillArrays", "FiniteDiff", "ForwardDiff", "LinearAlgebra", "Logging", "MuladdMacro", "NLsolve", "OrdinaryDiffEq", "Random", "RandomNumbers", "RecursiveArrayTools", "Reexport", "SparseArrays", "SparseDiffTools", "StaticArrays", "UnPack"] git-tree-sha1 = "1d5dff61a15532dd6c67fafebc52f2feaa2b3b82" uuid = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0" version = "6.37.1" [[deps.StrideArraysCore]] deps = ["ArrayInterface", "CloseOpenIntervals", "IfElse", "LayoutPointers", "ManualMemory", "Requires", "SIMDTypes", "Static", "ThreadingUtilities"] git-tree-sha1 = "1258e25e171aec339866f283a11e7d75867e77d7" uuid = "7792a7ef-975c-4747-a70f-980b88e8d1da" version = "0.2.4" [[deps.SuiteSparse]] deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" [[deps.TOML]] deps = ["Dates"] uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" [[deps.TableTraits]] deps = ["IteratorInterfaceExtensions"] git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39" uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" version = "1.0.1" [[deps.Tables]] deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] git-tree-sha1 = "1162ce4a6c4b7e31e0e6b14486a6986951c73be9" uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" version = "1.5.2" [[deps.Tar]] deps = ["ArgTools", "SHA"] uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" [[deps.Test]] deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [[deps.ThreadingUtilities]] deps = ["ManualMemory"] git-tree-sha1 = "03013c6ae7f1824131b2ae2fc1d49793b51e8394" uuid = "8290d209-cae3-49c0-8002-c8c24d57dab5" version = "0.4.6" [[deps.TreeViews]] deps = ["Test"] git-tree-sha1 = "8d0d7a3fe2f30d6a7f833a5f19f7c7a5b396eae6" uuid = "a2a6695c-b41b-5b7d-aed9-dbfdeacea5d7" version = "0.3.0" [[deps.TriangularSolve]] deps = ["CloseOpenIntervals", "IfElse", "LayoutPointers", "LinearAlgebra", "LoopVectorization", "Polyester", "Static", "VectorizationBase"] git-tree-sha1 = "ed55426a514db35f58d36c3812aae89cfc057401" uuid = "d5829a12-d9aa-46ab-831f-fb7c9ab06edf" version = "0.1.6" [[deps.UUIDs]] deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [[deps.UnPack]] git-tree-sha1 = "387c1f73762231e86e0c9c5443ce3b4a0a9a0c2b" uuid = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" version = "1.0.2" [[deps.Unicode]] uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" [[deps.UnicodePlots]] deps = ["Crayons", "Dates", "SparseArrays", "StatsBase"] git-tree-sha1 = "7ee3014ae511a5ef11523c38c216e7ad59650ce7" uuid = "b8865327-cd53-5732-bb35-84acbb429228" version = "2.4.0" [[deps.VectorizationBase]] deps = ["ArrayInterface", "CPUSummary", "HostCPUFeatures", "Hwloc", "IfElse", "LayoutPointers", "Libdl", "LinearAlgebra", "SIMDTypes", "Static"] git-tree-sha1 = "43c605e008ac67adb672ef08721d4720dfe2ad41" uuid = "3d5dd08c-fd9d-11e8-17fa-ed2836048c2f" version = "0.21.7" [[deps.VertexSafeGraphs]] deps = ["LightGraphs"] git-tree-sha1 = "b9b450c99a3ca1cc1c6836f560d8d887bcbe356e" uuid = "19fa3120-7c27-5ec5-8db8-b0b0aa330d6f" version = "0.1.2" [[deps.Zlib_jll]] deps = ["Libdl"] uuid = "83775a58-1f1d-513f-b197-d71354ab007a" [[deps.ZygoteRules]] deps = ["MacroTools"] git-tree-sha1 = "9e7a1e8ca60b742e508a315c17eef5211e7fbfd7" uuid = "700de1a5-db45-46bc-99cf-38207098b444" version = "0.2.1" [[deps.libblastrampoline_jll]] deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" [[deps.nghttp2_jll]] deps = ["Artifacts", "Libdl"] uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" [[deps.p7zip_jll]] deps = ["Artifacts", "Libdl"] uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" """ # ╔═╡ Cell order: # ╠═6bf88b5c-3abc-4b03-90bb-a7eb8cb68577 # ╟─96c9b046-6e40-44b1-a19c-b7061f22470d # ╟─d78532b9-b17e-4a4a-bbab-e249bf852eba # ╟─41487611-deba-49fc-a5f7-f4f63f7935c6 # ╟─32a692ab-4835-4943-8b46-8345ce881eb5 # ╟─c86cf1e9-d0b6-48e8-8a01-0dcc591afc85 # ╟─2195a7a4-30d6-47fe-92db-d7ebef67ef03 # ╟─fd2db517-2282-43da-a543-a1ef59a439c2 # ╟─5ab5321a-15b9-11ec-3321-b7d7cab1ba35 # ╟─aa7aa58b-e2e7-4b40-aeab-38137f8d4e2d # ╠═1df22a2f-c344-4d71-b44d-9a821c14e548 # ╟─00000000-0000-0000-0000-000000000001 # ╟─00000000-0000-0000-0000-000000000002
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
code
50021
### A Pluto.jl notebook ### # v0.19.0 using Markdown using InteractiveUtils # This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error). macro bind(def, element) quote local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end local el = $(esc(element)) global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el) el end end # ╔═╡ db98d796-c0d2-11ec-2c96-f7510a6d771c begin using OptimalTransport, LinearAlgebra using Tables, DataFrames import PlutoUI, CSV, Downloads, Tulip import CairoMakie as Makie "Done with packages" end # ╔═╡ 8d867c72-2924-46a0-8a60-7c6e52f71a67 md"""# `OptimalTransport.jl` applied to `CBIOMES` #### Methods See [this wikipedia page](https://en.wikipedia.org/wiki/Transportation_theory_(mathematics)) and the [package documentation](https://juliaoptimaltransport.github.io/OptimalTransport.jl/dev/examples/basic/). #### Climatologies Zonal mean Chl computed, between `-179.75 W` and `-120.25 W`, for each month as a function of latitude. - Model : see <https://github.com/gaelforget/OceanStateEstimation.jl> - Satellite : <https://github.com/brorfred/ocean_clustering> """ # ╔═╡ c1df03d1-6205-4caa-9bdf-7daa5ba59d3a md"""## Input Data Visualization""" # ╔═╡ da9cc45d-8529-4965-b213-61b2657fce28 begin m1_select = @bind m1 PlutoUI.Slider(1:12;default=1, show_value=true) m2_select = @bind m2 PlutoUI.Slider(1:12;default=2, show_value=true) md"""## Select Months To Compare Compute Earth Mover Distance / Optimal Transport between two months. - month 1 index : $(m1_select) - month 2 index : $(m2_select) """ end # ╔═╡ 29b6a32d-9003-4bc7-8351-0d1881153bf6 md"""## Appendix""" # ╔═╡ 973f46d5-83b7-466a-a8c3-406643f7dbc5 begin lons=-179.75:0.5:-120.25 lats=-19.75:0.5:49.75 pth=joinpath(tempdir(),"OptimalTransport_example") url="https://raw.githubusercontent.com/gaelforget/OceanStateEstimation.jl/master/examples/OptimalTransport/M.csv" M=Tables.matrix(CSV.read(Downloads.download(url),DataFrame)) url="https://raw.githubusercontent.com/gaelforget/OceanStateEstimation.jl/master/examples/OptimalTransport/S.csv" S=Tables.matrix(CSV.read(Downloads.download(url),DataFrame)) nx=size(M,1) Cost=Float64.([abs(i-j) for i in 1:nx, j in 1:nx]) "Input Data Ready" end # ╔═╡ a5301146-6eac-4bcd-97d9-3bfd6fe4f213 let f=Makie.Figure() ax1=Makie.Axis(f[1,1],title="model Chl",ylabel="month",xlabel="latitude") hm1=Makie.heatmap!(ax1,lats,1:12,M,colorrange=(0.0,0.015)) Makie.Colorbar(f[1, 2], hm1) ax2=Makie.Axis(f[2,1],title="satellite Chl",ylabel="month",xlabel="latitude") hm2=Makie.heatmap!(ax2,lats,1:12,S,colorrange=(0.005,0.01)) Makie.Colorbar(f[2, 2], hm2) f end # ╔═╡ ab49655b-ab30-457c-a476-9f6dd310ab4b begin Da=emd2(M[:,m1],M[:,m2], Cost, Tulip.Optimizer()) Da=round(Da,digits=4) end # ╔═╡ 7796c8e9-a090-4aab-a073-50f839ceab22 begin ε = 0.01 # γ = sinkhorn(M[:,m1], S[:,m2], Cost, ε, SinkhornGibbs(); maxiter=5_000) # γ = sinkhorn(M[:,m1], S[:,m2], Cost, ε, SinkhornStabilized(); maxiter=5_000) γ = sinkhorn(M[:,m1], M[:,m2], Cost, ε, SinkhornEpsilonScaling(SinkhornStabilized()); maxiter=5_000) Db=dot(γ, Cost) #compute optimal cost, directly Db=round(Db,digits=4) end # ╔═╡ fe0ac519-7995-419a-a8ac-02af958342cd md""" #### Linear Programming optimal distance : $(Da) #### Stabilized Sinkhorn optimal distance : $(Db) """ # ╔═╡ 00000000-0000-0000-0000-000000000001 PLUTO_PROJECT_TOML_CONTENTS = """ [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" OptimalTransport = "7e02d93a-ae51-4f58-b602-d97af76e3b33" PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" Tulip = "6dd1b50a-3aae-11e9-10b5-ef983d2400fa" [compat] CSV = "~0.10.4" CairoMakie = "~0.7.5" DataFrames = "~1.3.3" OptimalTransport = "~0.3.19" PlutoUI = "~0.7.38" Tables = "~1.7.0" Tulip = "~0.9.2" """ # ╔═╡ 00000000-0000-0000-0000-000000000002 PLUTO_MANIFEST_TOML_CONTENTS = """ # This file is machine-generated - editing it directly is not advised julia_version = "1.7.2" manifest_format = "2.0" [[deps.AMD]] deps = ["Libdl", "LinearAlgebra", "SparseArrays", "Test"] git-tree-sha1 = "fc66ffc5cff568936649445f58a55b81eaf9592c" uuid = "14f7f29c-3bd6-536c-9a0b-7339e30b5a3e" version = "0.4.0" [[deps.AbstractFFTs]] deps = ["ChainRulesCore", "LinearAlgebra"] git-tree-sha1 = "6f1d9bc1c08f9f4a8fa92e3ea3cb50153a1b40d4" uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" version = "1.1.0" [[deps.AbstractPlutoDingetjes]] deps = ["Pkg"] git-tree-sha1 = "8eaf9f1b4921132a4cff3f36a1d9ba923b14a481" uuid = "6e696c72-6542-2067-7265-42206c756150" version = "1.1.4" [[deps.AbstractTrees]] git-tree-sha1 = "03e0550477d86222521d254b741d470ba17ea0b5" uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" version = "0.3.4" [[deps.Adapt]] deps = ["LinearAlgebra"] git-tree-sha1 = "af92965fb30777147966f58acb05da51c5616b5f" uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" version = "3.3.3" [[deps.Animations]] deps = ["Colors"] git-tree-sha1 = "e81c509d2c8e49592413bfb0bb3b08150056c79d" uuid = "27a7e980-b3e6-11e9-2bcd-0b925532e340" version = "0.4.1" [[deps.ArgTools]] uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" [[deps.ArrayInterface]] deps = ["Compat", "IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"] git-tree-sha1 = "c933ce606f6535a7c7b98e1d86d5d1014f730596" uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" version = "5.0.7" [[deps.Artifacts]] uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" [[deps.Automa]] deps = ["Printf", "ScanByte", "TranscodingStreams"] git-tree-sha1 = "d50976f217489ce799e366d9561d56a98a30d7fe" uuid = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b" version = "0.8.2" [[deps.AxisAlgorithms]] deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"] git-tree-sha1 = "66771c8d21c8ff5e3a93379480a2307ac36863f7" uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" version = "1.0.1" [[deps.Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" [[deps.BenchmarkTools]] deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"] git-tree-sha1 = "4c10eee4af024676200bc7752e536f858c6b8f93" uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" version = "1.3.1" [[deps.Bzip2_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "19a35467a82e236ff51bc17a3a44b69ef35185a2" uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0" version = "1.0.8+0" [[deps.CEnum]] git-tree-sha1 = "215a9aa4a1f23fbd05b92769fdd62559488d70e9" uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82" version = "0.4.1" [[deps.CSV]] deps = ["CodecZlib", "Dates", "FilePathsBase", "InlineStrings", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "Tables", "Unicode", "WeakRefStrings"] git-tree-sha1 = "873fb188a4b9d76549b81465b1f75c82aaf59238" uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" version = "0.10.4" [[deps.Cairo]] deps = ["Cairo_jll", "Colors", "Glib_jll", "Graphics", "Libdl", "Pango_jll"] git-tree-sha1 = "d0b3f8b4ad16cb0a2988c6788646a5e6a17b6b1b" uuid = "159f3aea-2a34-519c-b102-8c37f9878175" version = "1.0.5" [[deps.CairoMakie]] deps = ["Base64", "Cairo", "Colors", "FFTW", "FileIO", "FreeType", "GeometryBasics", "LinearAlgebra", "Makie", "SHA", "StaticArrays"] git-tree-sha1 = "4a0de4f5aa2d5d27a1efa293aeabb1a081e46b2b" uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" version = "0.7.5" [[deps.Cairo_jll]] deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"] git-tree-sha1 = "4b859a208b2397a7a623a03449e4636bdb17bcf2" uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a" version = "1.16.1+1" [[deps.ChainRulesCore]] deps = ["Compat", "LinearAlgebra", "SparseArrays"] git-tree-sha1 = "9950387274246d08af38f6eef8cb5480862a435f" uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" version = "1.14.0" [[deps.ChangesOfVariables]] deps = ["ChainRulesCore", "LinearAlgebra", "Test"] git-tree-sha1 = "bf98fa45a0a4cee295de98d4c1462be26345b9a1" uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0" version = "0.1.2" [[deps.CodecBzip2]] deps = ["Bzip2_jll", "Libdl", "TranscodingStreams"] git-tree-sha1 = "2e62a725210ce3c3c2e1a3080190e7ca491f18d7" uuid = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd" version = "0.7.2" [[deps.CodecZlib]] deps = ["TranscodingStreams", "Zlib_jll"] git-tree-sha1 = "ded953804d019afa9a3f98981d99b33e3db7b6da" uuid = "944b1d66-785c-5afd-91f1-9de20f533193" version = "0.7.0" [[deps.ColorBrewer]] deps = ["Colors", "JSON", "Test"] git-tree-sha1 = "61c5334f33d91e570e1d0c3eb5465835242582c4" uuid = "a2cac450-b92f-5266-8821-25eda20663c8" version = "0.4.0" [[deps.ColorSchemes]] deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random"] git-tree-sha1 = "12fc73e5e0af68ad3137b886e3f7c1eacfca2640" uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4" version = "3.17.1" [[deps.ColorTypes]] deps = ["FixedPointNumbers", "Random"] git-tree-sha1 = "024fe24d83e4a5bf5fc80501a314ce0d1aa35597" uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" version = "0.11.0" [[deps.ColorVectorSpace]] deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "TensorCore"] git-tree-sha1 = "3f1f500312161f1ae067abe07d13b40f78f32e07" uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4" version = "0.9.8" [[deps.Colors]] deps = ["ColorTypes", "FixedPointNumbers", "Reexport"] git-tree-sha1 = "417b0ed7b8b838aa6ca0a87aadf1bb9eb111ce40" uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" version = "0.12.8" [[deps.Compat]] deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] git-tree-sha1 = "b153278a25dd42c65abbf4e62344f9d22e59191b" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" version = "3.43.0" [[deps.CompilerSupportLibraries_jll]] deps = ["Artifacts", "Libdl"] uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" [[deps.Contour]] deps = ["StaticArrays"] git-tree-sha1 = "9f02045d934dc030edad45944ea80dbd1f0ebea7" uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" version = "0.5.7" [[deps.Crayons]] git-tree-sha1 = "249fe38abf76d48563e2f4556bebd215aa317e15" uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" version = "4.1.1" [[deps.DataAPI]] git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" version = "1.9.0" [[deps.DataFrames]] deps = ["Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrettyTables", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] git-tree-sha1 = "6c19003824cbebd804a51211fd3bbd81bf1ecad5" uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" version = "1.3.3" [[deps.DataStructures]] deps = ["Compat", "InteractiveUtils", "OrderedCollections"] git-tree-sha1 = "3daef5523dd2e769dad2365274f760ff5f282c7d" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" version = "0.18.11" [[deps.DataValueInterfaces]] git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" version = "1.0.0" [[deps.Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" [[deps.DelimitedFiles]] deps = ["Mmap"] uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" [[deps.DensityInterface]] deps = ["InverseFunctions", "Test"] git-tree-sha1 = "80c3e8639e3353e5d2912fb3a1916b8455e2494b" uuid = "b429d917-457f-4dbc-8f4c-0cc954292b1d" version = "0.4.0" [[deps.Distances]] deps = ["LinearAlgebra", "SparseArrays", "Statistics", "StatsAPI"] git-tree-sha1 = "3258d0659f812acde79e8a74b11f17ac06d0ca04" uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" version = "0.10.7" [[deps.Distributed]] deps = ["Random", "Serialization", "Sockets"] uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" [[deps.Distributions]] deps = ["ChainRulesCore", "DensityInterface", "FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "Test"] git-tree-sha1 = "5a4168170ede913a2cd679e53c2123cb4b889795" uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" version = "0.25.53" [[deps.DocStringExtensions]] deps = ["LibGit2"] git-tree-sha1 = "b19534d1895d702889b219c382a6e18010797f0b" uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" version = "0.8.6" [[deps.Downloads]] deps = ["ArgTools", "LibCURL", "NetworkOptions"] uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" [[deps.EarCut_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "3f3a2501fa7236e9b911e0f7a588c657e822bb6d" uuid = "5ae413db-bbd1-5e63-b57d-d24a61df00f5" version = "2.2.3+0" [[deps.EllipsisNotation]] deps = ["ArrayInterface"] git-tree-sha1 = "d064b0340db45d48893e7604ec95e7a2dc9da904" uuid = "da5c29d0-fa7d-589e-88eb-ea29b0a81949" version = "1.5.0" [[deps.ExactOptimalTransport]] deps = ["Distances", "Distributions", "FillArrays", "LinearAlgebra", "MathOptInterface", "PDMats", "QuadGK", "SparseArrays", "StatsBase"] git-tree-sha1 = "170c201050738e908c92018bc2cfc7272089cd48" uuid = "24df6009-d856-477c-ac5c-91f668376b31" version = "0.2.2" [[deps.Expat_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "bad72f730e9e91c08d9427d5e8db95478a3c323d" uuid = "2e619515-83b5-522b-bb60-26c02a35a201" version = "2.4.8+0" [[deps.ExprTools]] git-tree-sha1 = "56559bbef6ca5ea0c0818fa5c90320398a6fbf8d" uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04" version = "0.1.8" [[deps.FFMPEG]] deps = ["FFMPEG_jll"] git-tree-sha1 = "b57e3acbe22f8484b4b5ff66a7499717fe1a9cc8" uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" version = "0.4.1" [[deps.FFMPEG_jll]] deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "LAME_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"] git-tree-sha1 = "d8a578692e3077ac998b50c0217dfd67f21d1e5f" uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5" version = "4.4.0+0" [[deps.FFTW]] deps = ["AbstractFFTs", "FFTW_jll", "LinearAlgebra", "MKL_jll", "Preferences", "Reexport"] git-tree-sha1 = "505876577b5481e50d089c1c68899dfb6faebc62" uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" version = "1.4.6" [[deps.FFTW_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "c6033cc3892d0ef5bb9cd29b7f2f0331ea5184ea" uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a" version = "3.3.10+0" [[deps.FastClosures]] git-tree-sha1 = "acebe244d53ee1b461970f8910c235b259e772ef" uuid = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a" version = "0.3.2" [[deps.FileIO]] deps = ["Pkg", "Requires", "UUIDs"] git-tree-sha1 = "80ced645013a5dbdc52cf70329399c35ce007fae" uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" version = "1.13.0" [[deps.FilePathsBase]] deps = ["Compat", "Dates", "Mmap", "Printf", "Test", "UUIDs"] git-tree-sha1 = "129b104185df66e408edd6625d480b7f9e9823a0" uuid = "48062228-2e41-5def-b9a4-89aafe57970f" version = "0.9.18" [[deps.FillArrays]] deps = ["LinearAlgebra", "Random", "SparseArrays", "Statistics"] git-tree-sha1 = "246621d23d1f43e3b9c368bf3b72b2331a27c286" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" version = "0.13.2" [[deps.FixedPointNumbers]] deps = ["Statistics"] git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc" uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" version = "0.8.4" [[deps.Fontconfig_jll]] deps = ["Artifacts", "Bzip2_jll", "Expat_jll", "FreeType2_jll", "JLLWrappers", "Libdl", "Libuuid_jll", "Pkg", "Zlib_jll"] git-tree-sha1 = "21efd19106a55620a188615da6d3d06cd7f6ee03" uuid = "a3f928ae-7b40-5064-980b-68af3947d34b" version = "2.13.93+0" [[deps.Formatting]] deps = ["Printf"] git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8" uuid = "59287772-0a20-5a39-b81b-1366585eb4c0" version = "0.4.2" [[deps.FreeType]] deps = ["CEnum", "FreeType2_jll"] git-tree-sha1 = "cabd77ab6a6fdff49bfd24af2ebe76e6e018a2b4" uuid = "b38be410-82b0-50bf-ab77-7b57e271db43" version = "4.0.0" [[deps.FreeType2_jll]] deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] git-tree-sha1 = "87eb71354d8ec1a96d4a7636bd57a7347dde3ef9" uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7" version = "2.10.4+0" [[deps.FreeTypeAbstraction]] deps = ["ColorVectorSpace", "Colors", "FreeType", "GeometryBasics"] git-tree-sha1 = "b5c7fe9cea653443736d264b85466bad8c574f4a" uuid = "663a7486-cb36-511b-a19d-713bb74d65c9" version = "0.9.9" [[deps.FriBidi_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "aa31987c2ba8704e23c6c8ba8a4f769d5d7e4f91" uuid = "559328eb-81f9-559d-9380-de523a88c83c" version = "1.0.10+0" [[deps.Future]] deps = ["Random"] uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" [[deps.GeometryBasics]] deps = ["EarCut_jll", "IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"] git-tree-sha1 = "83ea630384a13fc4f002b77690bc0afeb4255ac9" uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326" version = "0.4.2" [[deps.Gettext_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"] git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046" uuid = "78b55507-aeef-58d4-861c-77aaff3498b1" version = "0.21.0+0" [[deps.Glib_jll]] deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE_jll", "Pkg", "Zlib_jll"] git-tree-sha1 = "a32d672ac2c967f3deb8a81d828afc739c838a06" uuid = "7746bdde-850d-59dc-9ae8-88ece973131d" version = "2.68.3+2" [[deps.Graphics]] deps = ["Colors", "LinearAlgebra", "NaNMath"] git-tree-sha1 = "1c5a84319923bea76fa145d49e93aa4394c73fc2" uuid = "a2bd30eb-e257-5431-a919-1863eab51364" version = "1.1.1" [[deps.Graphite2_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "344bf40dcab1073aca04aa0df4fb092f920e4011" uuid = "3b182d85-2403-5c21-9c21-1e1f0cc25472" version = "1.3.14+0" [[deps.GridLayoutBase]] deps = ["GeometryBasics", "InteractiveUtils", "Observables"] git-tree-sha1 = "169c3dc5acae08835a573a8a3e25c62f689f8b5c" uuid = "3955a311-db13-416c-9275-1d80ed98e5e9" version = "0.6.5" [[deps.Grisu]] git-tree-sha1 = "53bb909d1151e57e2484c3d1b53e19552b887fb2" uuid = "42e2da0e-8278-4e71-bc24-59509adca0fe" version = "1.0.2" [[deps.HarfBuzz_jll]] deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"] git-tree-sha1 = "129acf094d168394e80ee1dc4bc06ec835e510a3" uuid = "2e76f6c2-a576-52d4-95c1-20adfe4de566" version = "2.8.1+1" [[deps.Hyperscript]] deps = ["Test"] git-tree-sha1 = "8d511d5b81240fc8e6802386302675bdf47737b9" uuid = "47d2ed2b-36de-50cf-bf87-49c2cf4b8b91" version = "0.0.4" [[deps.HypertextLiteral]] git-tree-sha1 = "2b078b5a615c6c0396c77810d92ee8c6f470d238" uuid = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2" version = "0.9.3" [[deps.IOCapture]] deps = ["Logging", "Random"] git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a" uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" version = "0.2.2" [[deps.IfElse]] git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1" uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" version = "0.1.1" [[deps.ImageCore]] deps = ["AbstractFFTs", "ColorVectorSpace", "Colors", "FixedPointNumbers", "Graphics", "MappedArrays", "MosaicViews", "OffsetArrays", "PaddedViews", "Reexport"] git-tree-sha1 = "9a5c62f231e5bba35695a20988fc7cd6de7eeb5a" uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534" version = "0.9.3" [[deps.ImageIO]] deps = ["FileIO", "JpegTurbo", "Netpbm", "OpenEXR", "PNGFiles", "QOI", "Sixel", "TiffImages", "UUIDs"] git-tree-sha1 = "464bdef044df52e6436f8c018bea2d48c40bb27b" uuid = "82e4d734-157c-48bb-816b-45c225c6df19" version = "0.6.1" [[deps.Imath_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "87f7662e03a649cffa2e05bf19c303e168732d3e" uuid = "905a6f67-0a94-5f89-b386-d35d92009cd1" version = "3.1.2+0" [[deps.IndirectArrays]] git-tree-sha1 = "012e604e1c7458645cb8b436f8fba789a51b257f" uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959" version = "1.0.0" [[deps.Inflate]] git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c" uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" version = "0.1.2" [[deps.InlineStrings]] deps = ["Parsers"] git-tree-sha1 = "61feba885fac3a407465726d0c330b3055df897f" uuid = "842dd82b-1e85-43dc-bf29-5d0ee9dffc48" version = "1.1.2" [[deps.IntelOpenMP_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "d979e54b71da82f3a65b62553da4fc3d18c9004c" uuid = "1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0" version = "2018.0.3+2" [[deps.InteractiveUtils]] deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" [[deps.Interpolations]] deps = ["AxisAlgorithms", "ChainRulesCore", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "Requires", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"] git-tree-sha1 = "b7bc05649af456efc75d178846f47006c2c4c3c7" uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" version = "0.13.6" [[deps.IntervalSets]] deps = ["Dates", "EllipsisNotation", "Statistics"] git-tree-sha1 = "bcf640979ee55b652f3b01650444eb7bbe3ea837" uuid = "8197267c-284f-5f27-9208-e0e47529a953" version = "0.5.4" [[deps.InverseFunctions]] deps = ["Test"] git-tree-sha1 = "91b5dcf362c5add98049e6c29ee756910b03051d" uuid = "3587e190-3f89-42d0-90ee-14403ec27112" version = "0.1.3" [[deps.InvertedIndices]] git-tree-sha1 = "bee5f1ef5bf65df56bdd2e40447590b272a5471f" uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" version = "1.1.0" [[deps.IrrationalConstants]] git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151" uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" version = "0.1.1" [[deps.Isoband]] deps = ["isoband_jll"] git-tree-sha1 = "f9b6d97355599074dc867318950adaa6f9946137" uuid = "f1662d9f-8043-43de-a69a-05efc1cc6ff4" version = "0.1.1" [[deps.IterTools]] git-tree-sha1 = "fa6287a4469f5e048d763df38279ee729fbd44e5" uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" version = "1.4.0" [[deps.IterativeSolvers]] deps = ["LinearAlgebra", "Printf", "Random", "RecipesBase", "SparseArrays"] git-tree-sha1 = "1169632f425f79429f245113b775a0e3d121457c" uuid = "42fd0dbc-a981-5370-80f2-aaf504508153" version = "0.9.2" [[deps.IteratorInterfaceExtensions]] git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" uuid = "82899510-4779-5014-852e-03e436cf321d" version = "1.0.0" [[deps.JLLWrappers]] deps = ["Preferences"] git-tree-sha1 = "abc9885a7ca2052a736a600f7fa66209f96506e1" uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" version = "1.4.1" [[deps.JSON]] deps = ["Dates", "Mmap", "Parsers", "Unicode"] git-tree-sha1 = "3c837543ddb02250ef42f4738347454f95079d4e" uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" version = "0.21.3" [[deps.JpegTurbo]] deps = ["CEnum", "FileIO", "ImageCore", "JpegTurbo_jll", "TOML"] git-tree-sha1 = "a77b273f1ddec645d1b7c4fd5fb98c8f90ad10a5" uuid = "b835a17e-a41a-41e7-81f0-2f016b05efe0" version = "0.1.1" [[deps.JpegTurbo_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "b53380851c6e6664204efb2e62cd24fa5c47e4ba" uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8" version = "2.1.2+0" [[deps.KernelDensity]] deps = ["Distributions", "DocStringExtensions", "FFTW", "Interpolations", "StatsBase"] git-tree-sha1 = "591e8dc09ad18386189610acafb970032c519707" uuid = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b" version = "0.6.3" [[deps.Krylov]] deps = ["LinearAlgebra", "Printf", "SparseArrays"] git-tree-sha1 = "a024280a69c49f51ba29d2deb66f07508f0b9b49" uuid = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7" version = "0.7.13" [[deps.LAME_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "f6250b16881adf048549549fba48b1161acdac8c" uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d" version = "3.100.1+0" [[deps.LDLFactorizations]] deps = ["AMD", "LinearAlgebra", "SparseArrays", "Test"] git-tree-sha1 = "736e01b9b2d443c4e3351aebe551b8a374ab9c05" uuid = "40e66cde-538c-5869-a4ad-c39174c6795b" version = "0.8.2" [[deps.LZO_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "e5b909bcf985c5e2605737d2ce278ed791b89be6" uuid = "dd4b983a-f0e5-5f8d-a1b7-129d4a5fb1ac" version = "2.10.1+0" [[deps.LaTeXStrings]] git-tree-sha1 = "f2355693d6778a178ade15952b7ac47a4ff97996" uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" version = "1.3.0" [[deps.LazyArtifacts]] deps = ["Artifacts", "Pkg"] uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3" [[deps.LibCURL]] deps = ["LibCURL_jll", "MozillaCACerts_jll"] uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" [[deps.LibCURL_jll]] deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" [[deps.LibGit2]] deps = ["Base64", "NetworkOptions", "Printf", "SHA"] uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" [[deps.LibSSH2_jll]] deps = ["Artifacts", "Libdl", "MbedTLS_jll"] uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" [[deps.Libdl]] uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" [[deps.Libffi_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "0b4a5d71f3e5200a7dff793393e09dfc2d874290" uuid = "e9f186c6-92d2-5b65-8a66-fee21dc1b490" version = "3.2.2+1" [[deps.Libgcrypt_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgpg_error_jll", "Pkg"] git-tree-sha1 = "64613c82a59c120435c067c2b809fc61cf5166ae" uuid = "d4300ac3-e22c-5743-9152-c294e39db1e4" version = "1.8.7+0" [[deps.Libgpg_error_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "c333716e46366857753e273ce6a69ee0945a6db9" uuid = "7add5ba3-2f88-524e-9cd5-f83b8a55f7b8" version = "1.42.0+0" [[deps.Libiconv_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "42b62845d70a619f063a7da093d995ec8e15e778" uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531" version = "1.16.1+1" [[deps.Libmount_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "9c30530bf0effd46e15e0fdcf2b8636e78cbbd73" uuid = "4b2f31a3-9ecc-558c-b454-b3730dcb73e9" version = "2.35.0+0" [[deps.Libuuid_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "7f3efec06033682db852f8b3bc3c1d2b0a0ab066" uuid = "38a345b3-de98-5d2b-a5d3-14cd9215e700" version = "2.36.0+0" [[deps.LinearAlgebra]] deps = ["Libdl", "libblastrampoline_jll"] uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" [[deps.LinearOperators]] deps = ["FastClosures", "LDLFactorizations", "LinearAlgebra", "Printf", "SparseArrays", "TimerOutputs"] git-tree-sha1 = "5f5884fcd1ab037a286de2b21c38db7e4c903056" uuid = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125" version = "2.3.1" [[deps.LogExpFunctions]] deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"] git-tree-sha1 = "a970d55c2ad8084ca317a4658ba6ce99b7523571" uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" version = "0.3.12" [[deps.Logging]] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" [[deps.MKL_jll]] deps = ["Artifacts", "IntelOpenMP_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg"] git-tree-sha1 = "e595b205efd49508358f7dc670a940c790204629" uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7" version = "2022.0.0+0" [[deps.Makie]] deps = ["Animations", "Base64", "ColorBrewer", "ColorSchemes", "ColorTypes", "Colors", "Contour", "Distributions", "DocStringExtensions", "FFMPEG", "FileIO", "FixedPointNumbers", "Formatting", "FreeType", "FreeTypeAbstraction", "GeometryBasics", "GridLayoutBase", "ImageIO", "IntervalSets", "Isoband", "KernelDensity", "LaTeXStrings", "LinearAlgebra", "MakieCore", "Markdown", "Match", "MathTeXEngine", "Observables", "OffsetArrays", "Packing", "PlotUtils", "PolygonOps", "Printf", "Random", "RelocatableFolders", "Serialization", "Showoff", "SignedDistanceFields", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "StatsFuns", "StructArrays", "UnicodeFun"] git-tree-sha1 = "63de3b8a5c1f764e4e3a036c7752a632b4f0b8d1" uuid = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" version = "0.16.6" [[deps.MakieCore]] deps = ["Observables"] git-tree-sha1 = "c5fb1bfac781db766f9e4aef96adc19a729bc9b2" uuid = "20f20a25-4f0e-4fdf-b5d1-57303727442b" version = "0.2.1" [[deps.MappedArrays]] git-tree-sha1 = "e8b359ef06ec72e8c030463fe02efe5527ee5142" uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" version = "0.4.1" [[deps.Markdown]] deps = ["Base64"] uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" [[deps.Match]] git-tree-sha1 = "1d9bc5c1a6e7ee24effb93f175c9342f9154d97f" uuid = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf" version = "1.2.0" [[deps.MathOptInterface]] deps = ["BenchmarkTools", "CodecBzip2", "CodecZlib", "JSON", "LinearAlgebra", "MutableArithmetics", "OrderedCollections", "Printf", "SparseArrays", "Test", "Unicode"] git-tree-sha1 = "e8c9653877adcf8f3e7382985e535bb37b083598" uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" version = "0.10.9" [[deps.MathTeXEngine]] deps = ["AbstractTrees", "Automa", "DataStructures", "FreeTypeAbstraction", "GeometryBasics", "LaTeXStrings", "REPL", "RelocatableFolders", "Test"] git-tree-sha1 = "70e733037bbf02d691e78f95171a1fa08cdc6332" uuid = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53" version = "0.2.1" [[deps.MbedTLS_jll]] deps = ["Artifacts", "Libdl"] uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" [[deps.Missings]] deps = ["DataAPI"] git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f" uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" version = "1.0.2" [[deps.Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" [[deps.MosaicViews]] deps = ["MappedArrays", "OffsetArrays", "PaddedViews", "StackViews"] git-tree-sha1 = "b34e3bc3ca7c94914418637cb10cc4d1d80d877d" uuid = "e94cdb99-869f-56ef-bcf0-1ae2bcbe0389" version = "0.3.3" [[deps.MozillaCACerts_jll]] uuid = "14a3606d-f60d-562e-9121-12d972cd8159" [[deps.MutableArithmetics]] deps = ["LinearAlgebra", "SparseArrays", "Test"] git-tree-sha1 = "842b5ccd156e432f369b204bb704fd4020e383ac" uuid = "d8a4904e-b15c-11e9-3269-09a3773c0cb0" version = "0.3.3" [[deps.NNlib]] deps = ["Adapt", "ChainRulesCore", "Compat", "LinearAlgebra", "Pkg", "Requires", "Statistics"] git-tree-sha1 = "a59a614b8b4ea6dc1dcec8c6514e251f13ccbe10" uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" version = "0.8.4" [[deps.NaNMath]] git-tree-sha1 = "b086b7ea07f8e38cf122f5016af580881ac914fe" uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" version = "0.3.7" [[deps.Netpbm]] deps = ["FileIO", "ImageCore"] git-tree-sha1 = "18efc06f6ec36a8b801b23f076e3c6ac7c3bf153" uuid = "f09324ee-3d7c-5217-9330-fc30815ba969" version = "1.0.2" [[deps.NetworkOptions]] uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" [[deps.Observables]] git-tree-sha1 = "fe29afdef3d0c4a8286128d4e45cc50621b1e43d" uuid = "510215fc-4207-5dde-b226-833fc4488ee2" version = "0.4.0" [[deps.OffsetArrays]] deps = ["Adapt"] git-tree-sha1 = "043017e0bdeff61cfbb7afeb558ab29536bbb5ed" uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" version = "1.10.8" [[deps.Ogg_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "887579a3eb005446d514ab7aeac5d1d027658b8f" uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051" version = "1.3.5+1" [[deps.OpenBLAS_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" [[deps.OpenEXR]] deps = ["Colors", "FileIO", "OpenEXR_jll"] git-tree-sha1 = "327f53360fdb54df7ecd01e96ef1983536d1e633" uuid = "52e1d378-f018-4a11-a4be-720524705ac7" version = "0.3.2" [[deps.OpenEXR_jll]] deps = ["Artifacts", "Imath_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] git-tree-sha1 = "923319661e9a22712f24596ce81c54fc0366f304" uuid = "18a262bb-aa17-5467-a713-aee519bc75cb" version = "3.1.1+0" [[deps.OpenLibm_jll]] deps = ["Artifacts", "Libdl"] uuid = "05823500-19ac-5b8b-9628-191a04bc5112" [[deps.OpenSSL_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "ab05aa4cc89736e95915b01e7279e61b1bfe33b8" uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" version = "1.1.14+0" [[deps.OpenSpecFun_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1" uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" version = "0.5.5+0" [[deps.OptimalTransport]] deps = ["ExactOptimalTransport", "IterativeSolvers", "LinearAlgebra", "LogExpFunctions", "NNlib", "Reexport"] git-tree-sha1 = "79ba1dab46dfc7b677278ebe892a431788da86a9" uuid = "7e02d93a-ae51-4f58-b602-d97af76e3b33" version = "0.3.19" [[deps.Opus_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "51a08fb14ec28da2ec7a927c4337e4332c2a4720" uuid = "91d4177d-7536-5919-b921-800302f37372" version = "1.3.2+0" [[deps.OrderedCollections]] git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c" uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" version = "1.4.1" [[deps.PCRE_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "b2a7af664e098055a7529ad1a900ded962bca488" uuid = "2f80f16e-611a-54ab-bc61-aa92de5b98fc" version = "8.44.0+0" [[deps.PDMats]] deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse"] git-tree-sha1 = "e8185b83b9fc56eb6456200e873ce598ebc7f262" uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" version = "0.11.7" [[deps.PNGFiles]] deps = ["Base64", "CEnum", "ImageCore", "IndirectArrays", "OffsetArrays", "libpng_jll"] git-tree-sha1 = "eb4dbb8139f6125471aa3da98fb70f02dc58e49c" uuid = "f57f5aa1-a3ce-4bc8-8ab9-96f992907883" version = "0.3.14" [[deps.Packing]] deps = ["GeometryBasics"] git-tree-sha1 = "1155f6f937fa2b94104162f01fa400e192e4272f" uuid = "19eb6ba3-879d-56ad-ad62-d5c202156566" version = "0.4.2" [[deps.PaddedViews]] deps = ["OffsetArrays"] git-tree-sha1 = "03a7a85b76381a3d04c7a1656039197e70eda03d" uuid = "5432bcbf-9aad-5242-b902-cca2824c8663" version = "0.5.11" [[deps.Pango_jll]] deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "FriBidi_jll", "Glib_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "3a121dfbba67c94a5bec9dde613c3d0cbcf3a12b" uuid = "36c8627f-9965-5494-a995-c6b170f724f3" version = "1.50.3+0" [[deps.Parsers]] deps = ["Dates"] git-tree-sha1 = "621f4f3b4977325b9128d5fae7a8b4829a0c2222" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" version = "2.2.4" [[deps.Pixman_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "b4f5d02549a10e20780a24fce72bea96b6329e29" uuid = "30392449-352a-5448-841d-b1acce4e97dc" version = "0.40.1+0" [[deps.Pkg]] deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" [[deps.PkgVersion]] deps = ["Pkg"] git-tree-sha1 = "a7a7e1a88853564e551e4eba8650f8c38df79b37" uuid = "eebad327-c553-4316-9ea0-9fa01ccd7688" version = "0.1.1" [[deps.PlotUtils]] deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"] git-tree-sha1 = "bb16469fd5224100e422f0b027d26c5a25de1200" uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043" version = "1.2.0" [[deps.PlutoUI]] deps = ["AbstractPlutoDingetjes", "Base64", "ColorTypes", "Dates", "Hyperscript", "HypertextLiteral", "IOCapture", "InteractiveUtils", "JSON", "Logging", "Markdown", "Random", "Reexport", "UUIDs"] git-tree-sha1 = "670e559e5c8e191ded66fa9ea89c97f10376bb4c" uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8" version = "0.7.38" [[deps.PolygonOps]] git-tree-sha1 = "77b3d3605fc1cd0b42d95eba87dfcd2bf67d5ff6" uuid = "647866c9-e3ac-4575-94e7-e3d426903924" version = "0.1.2" [[deps.PooledArrays]] deps = ["DataAPI", "Future"] git-tree-sha1 = "28ef6c7ce353f0b35d0df0d5930e0d072c1f5b9b" uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" version = "1.4.1" [[deps.Preferences]] deps = ["TOML"] git-tree-sha1 = "47e5f437cc0e7ef2ce8406ce1e7e24d44915f88d" uuid = "21216c6a-2e73-6563-6e65-726566657250" version = "1.3.0" [[deps.PrettyTables]] deps = ["Crayons", "Formatting", "Markdown", "Reexport", "Tables"] git-tree-sha1 = "dfb54c4e414caa595a1f2ed759b160f5a3ddcba5" uuid = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" version = "1.3.1" [[deps.Printf]] deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" [[deps.Profile]] deps = ["Printf"] uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" [[deps.ProgressMeter]] deps = ["Distributed", "Printf"] git-tree-sha1 = "d7a7aef8f8f2d537104f170139553b14dfe39fe9" uuid = "92933f4c-e287-5a05-a399-4b506db050ca" version = "1.7.2" [[deps.QOI]] deps = ["ColorTypes", "FileIO", "FixedPointNumbers"] git-tree-sha1 = "18e8f4d1426e965c7b532ddd260599e1510d26ce" uuid = "4b34888f-f399-49d4-9bb3-47ed5cae4e65" version = "1.0.0" [[deps.QPSReader]] deps = ["Logging", "Pkg"] git-tree-sha1 = "374833c0c1fd5cc623278581bf0c8259d7b35f10" uuid = "10f199a5-22af-520b-b891-7ce84a7b1bd0" version = "0.2.1" [[deps.QuadGK]] deps = ["DataStructures", "LinearAlgebra"] git-tree-sha1 = "78aadffb3efd2155af139781b8a8df1ef279ea39" uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" version = "2.4.2" [[deps.REPL]] deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" [[deps.Random]] deps = ["SHA", "Serialization"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" [[deps.Ratios]] deps = ["Requires"] git-tree-sha1 = "dc84268fe0e3335a62e315a3a7cf2afa7178a734" uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" version = "0.4.3" [[deps.RecipesBase]] git-tree-sha1 = "6bf3f380ff52ce0832ddd3a2a7b9538ed1bcca7d" uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" version = "1.2.1" [[deps.Reexport]] git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b" uuid = "189a3867-3050-52da-a836-e630ba90ab69" version = "1.2.2" [[deps.RelocatableFolders]] deps = ["SHA", "Scratch"] git-tree-sha1 = "cdbd3b1338c72ce29d9584fdbe9e9b70eeb5adca" uuid = "05181044-ff0b-4ac5-8273-598c1e38db00" version = "0.1.3" [[deps.Requires]] deps = ["UUIDs"] git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7" uuid = "ae029012-a4dd-5104-9daa-d747884805df" version = "1.3.0" [[deps.Rmath]] deps = ["Random", "Rmath_jll"] git-tree-sha1 = "bf3188feca147ce108c76ad82c2792c57abe7b1f" uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" version = "0.7.0" [[deps.Rmath_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "68db32dff12bb6127bac73c209881191bf0efbb7" uuid = "f50d1b31-88e8-58de-be2c-1cc44531875f" version = "0.3.0+0" [[deps.SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" [[deps.SIMD]] git-tree-sha1 = "7dbc15af7ed5f751a82bf3ed37757adf76c32402" uuid = "fdea26ae-647d-5447-a871-4b548cad5224" version = "3.4.1" [[deps.ScanByte]] deps = ["Libdl", "SIMD"] git-tree-sha1 = "9cc2955f2a254b18be655a4ee70bc4031b2b189e" uuid = "7b38b023-a4d7-4c5e-8d43-3f3097f304eb" version = "0.3.0" [[deps.Scratch]] deps = ["Dates"] git-tree-sha1 = "0b4b7f1393cff97c33891da2a0bf69c6ed241fda" uuid = "6c6a2e73-6563-6170-7368-637461726353" version = "1.1.0" [[deps.SentinelArrays]] deps = ["Dates", "Random"] git-tree-sha1 = "6a2f7d70512d205ca8c7ee31bfa9f142fe74310c" uuid = "91c51154-3ec4-41a3-a24f-3f23e20d615c" version = "1.3.12" [[deps.Serialization]] uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" [[deps.SharedArrays]] deps = ["Distributed", "Mmap", "Random", "Serialization"] uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" [[deps.Showoff]] deps = ["Dates", "Grisu"] git-tree-sha1 = "91eddf657aca81df9ae6ceb20b959ae5653ad1de" uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" version = "1.0.3" [[deps.SignedDistanceFields]] deps = ["Random", "Statistics", "Test"] git-tree-sha1 = "d263a08ec505853a5ff1c1ebde2070419e3f28e9" uuid = "73760f76-fbc4-59ce-8f25-708e95d2df96" version = "0.4.0" [[deps.Sixel]] deps = ["Dates", "FileIO", "ImageCore", "IndirectArrays", "OffsetArrays", "REPL", "libsixel_jll"] git-tree-sha1 = "8fb59825be681d451c246a795117f317ecbcaa28" uuid = "45858cf5-a6b0-47a3-bbea-62219f50df47" version = "0.1.2" [[deps.Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" [[deps.SortingAlgorithms]] deps = ["DataStructures"] git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508" uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" version = "1.0.1" [[deps.SparseArrays]] deps = ["LinearAlgebra", "Random"] uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [[deps.SpecialFunctions]] deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"] git-tree-sha1 = "5ba658aeecaaf96923dce0da9e703bd1fe7666f9" uuid = "276daf66-3868-5448-9aa4-cd146d93841b" version = "2.1.4" [[deps.StackViews]] deps = ["OffsetArrays"] git-tree-sha1 = "46e589465204cd0c08b4bd97385e4fa79a0c770c" uuid = "cae243ae-269e-4f55-b966-ac2d0dc13c15" version = "0.1.1" [[deps.Static]] deps = ["IfElse"] git-tree-sha1 = "87e9954dfa33fd145694e42337bdd3d5b07021a6" uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" version = "0.6.0" [[deps.StaticArrays]] deps = ["LinearAlgebra", "Random", "Statistics"] git-tree-sha1 = "4f6ec5d99a28e1a749559ef7dd518663c5eca3d5" uuid = "90137ffa-7385-5640-81b9-e52037218182" version = "1.4.3" [[deps.Statistics]] deps = ["LinearAlgebra", "SparseArrays"] uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [[deps.StatsAPI]] deps = ["LinearAlgebra"] git-tree-sha1 = "8d7530a38dbd2c397be7ddd01a424e4f411dcc41" uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0" version = "1.2.2" [[deps.StatsBase]] deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"] git-tree-sha1 = "8977b17906b0a1cc74ab2e3a05faa16cf08a8291" uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" version = "0.33.16" [[deps.StatsFuns]] deps = ["ChainRulesCore", "InverseFunctions", "IrrationalConstants", "LogExpFunctions", "Reexport", "Rmath", "SpecialFunctions"] git-tree-sha1 = "5950925ff997ed6fb3e985dcce8eb1ba42a0bbe7" uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" version = "0.9.18" [[deps.StructArrays]] deps = ["Adapt", "DataAPI", "StaticArrays", "Tables"] git-tree-sha1 = "57617b34fa34f91d536eb265df67c2d4519b8b98" uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" version = "0.6.5" [[deps.SuiteSparse]] deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" [[deps.TOML]] deps = ["Dates"] uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" [[deps.TableTraits]] deps = ["IteratorInterfaceExtensions"] git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39" uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" version = "1.0.1" [[deps.Tables]] deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "OrderedCollections", "TableTraits", "Test"] git-tree-sha1 = "5ce79ce186cc678bbb5c5681ca3379d1ddae11a1" uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" version = "1.7.0" [[deps.Tar]] deps = ["ArgTools", "SHA"] uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" [[deps.TensorCore]] deps = ["LinearAlgebra"] git-tree-sha1 = "1feb45f88d133a655e001435632f019a9a1bcdb6" uuid = "62fd8b95-f654-4bbd-a8a5-9c27f68ccd50" version = "0.1.1" [[deps.Test]] deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [[deps.TiffImages]] deps = ["ColorTypes", "DataStructures", "DocStringExtensions", "FileIO", "FixedPointNumbers", "IndirectArrays", "Inflate", "OffsetArrays", "PkgVersion", "ProgressMeter", "UUIDs"] git-tree-sha1 = "aaa19086bc282630d82f818456bc40b4d314307d" uuid = "731e570b-9d59-4bfa-96dc-6df516fadf69" version = "0.5.4" [[deps.TimerOutputs]] deps = ["ExprTools", "Printf"] git-tree-sha1 = "d60b0c96a16aaa42138d5d38ad386df672cb8bd8" uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" version = "0.5.16" [[deps.TranscodingStreams]] deps = ["Random", "Test"] git-tree-sha1 = "216b95ea110b5972db65aa90f88d8d89dcb8851c" uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" version = "0.9.6" [[deps.Tulip]] deps = ["CodecBzip2", "CodecZlib", "Krylov", "LDLFactorizations", "LinearAlgebra", "LinearOperators", "Logging", "MathOptInterface", "Printf", "QPSReader", "SparseArrays", "SuiteSparse", "Test", "TimerOutputs"] git-tree-sha1 = "e1b60649eb84746ca7200e330819ea0ef647a57c" uuid = "6dd1b50a-3aae-11e9-10b5-ef983d2400fa" version = "0.9.2" [[deps.UUIDs]] deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [[deps.Unicode]] uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" [[deps.UnicodeFun]] deps = ["REPL"] git-tree-sha1 = "53915e50200959667e78a92a418594b428dffddf" uuid = "1cfade01-22cf-5700-b092-accc4b62d6e1" version = "0.4.1" [[deps.WeakRefStrings]] deps = ["DataAPI", "InlineStrings", "Parsers"] git-tree-sha1 = "b1be2855ed9ed8eac54e5caff2afcdb442d52c23" uuid = "ea10d353-3f73-51f8-a26c-33c1cb351aa5" version = "1.4.2" [[deps.WoodburyMatrices]] deps = ["LinearAlgebra", "SparseArrays"] git-tree-sha1 = "de67fa59e33ad156a590055375a30b23c40299d3" uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" version = "0.5.5" [[deps.XML2_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"] git-tree-sha1 = "1acf5bdf07aa0907e0a37d3718bb88d4b687b74a" uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a" version = "2.9.12+0" [[deps.XSLT_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Libiconv_jll", "Pkg", "XML2_jll", "Zlib_jll"] git-tree-sha1 = "91844873c4085240b95e795f692c4cec4d805f8a" uuid = "aed1982a-8fda-507f-9586-7b0439959a61" version = "1.1.34+0" [[deps.Xorg_libX11_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll", "Xorg_xtrans_jll"] git-tree-sha1 = "5be649d550f3f4b95308bf0183b82e2582876527" uuid = "4f6342f7-b3d2-589e-9d20-edeb45f2b2bc" version = "1.6.9+4" [[deps.Xorg_libXau_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "4e490d5c960c314f33885790ed410ff3a94ce67e" uuid = "0c0b7dd1-d40b-584c-a123-a41640f87eec" version = "1.0.9+4" [[deps.Xorg_libXdmcp_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "4fe47bd2247248125c428978740e18a681372dd4" uuid = "a3789734-cfe1-5b06-b2d0-1dd0d9d62d05" version = "1.1.3+4" [[deps.Xorg_libXext_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"] git-tree-sha1 = "b7c0aa8c376b31e4852b360222848637f481f8c3" uuid = "1082639a-0dae-5f34-9b06-72781eeb8cb3" version = "1.3.4+4" [[deps.Xorg_libXrender_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"] git-tree-sha1 = "19560f30fd49f4d4efbe7002a1037f8c43d43b96" uuid = "ea2f1a96-1ddc-540d-b46f-429655e07cfa" version = "0.9.10+4" [[deps.Xorg_libpthread_stubs_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "6783737e45d3c59a4a4c4091f5f88cdcf0908cbb" uuid = "14d82f49-176c-5ed1-bb49-ad3f5cbd8c74" version = "0.1.0+3" [[deps.Xorg_libxcb_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"] git-tree-sha1 = "daf17f441228e7a3833846cd048892861cff16d6" uuid = "c7cfdc94-dc32-55de-ac96-5a1b8d977c5b" version = "1.13.0+3" [[deps.Xorg_xtrans_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "79c31e7844f6ecf779705fbc12146eb190b7d845" uuid = "c5fb5394-a638-5e4d-96e5-b29de1b5cf10" version = "1.4.0+3" [[deps.Zlib_jll]] deps = ["Libdl"] uuid = "83775a58-1f1d-513f-b197-d71354ab007a" [[deps.isoband_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "51b5eeb3f98367157a7a12a1fb0aa5328946c03c" uuid = "9a68df92-36a6-505f-a73e-abb412b6bfb4" version = "0.2.3+0" [[deps.libass_jll]] deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] git-tree-sha1 = "5982a94fcba20f02f42ace44b9894ee2b140fe47" uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0" version = "0.15.1+0" [[deps.libblastrampoline_jll]] deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" [[deps.libfdk_aac_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "daacc84a041563f965be61859a36e17c4e4fcd55" uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280" version = "2.0.2+0" [[deps.libpng_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] git-tree-sha1 = "94d180a6d2b5e55e447e2d27a29ed04fe79eb30c" uuid = "b53b4c65-9356-5827-b1ea-8c7a1a84506f" version = "1.6.38+0" [[deps.libsixel_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "78736dab31ae7a53540a6b752efc61f77b304c5b" uuid = "075b6546-f08a-558a-be8f-8157d0f608a5" version = "1.8.6+1" [[deps.libvorbis_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Ogg_jll", "Pkg"] git-tree-sha1 = "b910cb81ef3fe6e78bf6acee440bda86fd6ae00c" uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a" version = "1.3.7+1" [[deps.nghttp2_jll]] deps = ["Artifacts", "Libdl"] uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" [[deps.p7zip_jll]] deps = ["Artifacts", "Libdl"] uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" [[deps.x264_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "4fea590b89e6ec504593146bf8b988b2c00922b2" uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a" version = "2021.5.5+0" [[deps.x265_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "ee567a171cce03570d77ad3a43e90218e38937a9" uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76" version = "3.5.0+0" """ # ╔═╡ Cell order: # ╟─8d867c72-2924-46a0-8a60-7c6e52f71a67 # ╟─c1df03d1-6205-4caa-9bdf-7daa5ba59d3a # ╟─a5301146-6eac-4bcd-97d9-3bfd6fe4f213 # ╟─da9cc45d-8529-4965-b213-61b2657fce28 # ╟─fe0ac519-7995-419a-a8ac-02af958342cd # ╟─29b6a32d-9003-4bc7-8351-0d1881153bf6 # ╟─db98d796-c0d2-11ec-2c96-f7510a6d771c # ╟─973f46d5-83b7-466a-a8c3-406643f7dbc5 # ╟─ab49655b-ab30-457c-a476-9f6dd310ab4b # ╟─7796c8e9-a090-4aab-a073-50f839ceab22 # ╟─00000000-0000-0000-0000-000000000001 # ╟─00000000-0000-0000-0000-000000000002
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
code
5822
using Distributed calc_SatToSat=true calc_ModToMod=false calc_ModToSat=false zm_test_case=true choice_method="emd2" #only for 2D case test_methods=false println(calc_SatToSat) println(calc_ModToMod) println(calc_ModToSat) println(choice_method) println(zm_test_case) ## pth_output=joinpath(tempdir(),"OptimalTransport_example") !isdir(pth_output) ? mkdir(pth_output) : nothing @everywhere using Distributed, DistributedArrays, SharedArrays @everywhere using OptimalTransport, Statistics, LinearAlgebra @everywhere using Tulip, Distances, JLD2, Tables, CSV, DataFrames #@everywhere Cost=load("examples/example_Cost.jld2")["Cost"] @everywhere M=Tables.matrix(CSV.read("examples/M.csv",DataFrame)) @everywhere S=Tables.matrix(CSV.read("examples/S.csv",DataFrame)) @everywhere nx=size(M,1) ## functions that use the "zonal sum" test case @everywhere function ModToMod_MS(i,j) Cost=Float64.([abs(i-j) for i in 1:nx, j in 1:nx]) emd2(M[:,i],M[:,j], Cost, Tulip.Optimizer()) end @everywhere function SatToSat_MS(i,j) Cost=Float64.([abs(i-j) for i in 1:nx, j in 1:nx]) emd2(S[:,i],S[:,j], Cost, Tulip.Optimizer()) end @everywhere function ModToSat_MS(i,j) Cost=Float64.([abs(i-j) for i in 1:nx, j in 1:nx]) emd2(M[:,i],S[:,j], Cost, Tulip.Optimizer()) #ε = 0.01 #γ = sinkhorn_stabilized_epsscaling(M[:,i],S[:,j], Cost, ε; maxiter=5_000) #dot(γ, Cost) #compute optimal cost, directly end ## functions that use the full 2D case @everywhere function ModToSat(i,j) a=Chl_from_Mod[:,:,i][:] b=Chl_from_Sat[:,:,j][:] a,b=preprocess_Chl(a,b) if choice_method=="sinkhorn2" ε = 0.05 sinkhorn2(a,b, Cost, ε) elseif choice_method=="emd2" emd2(a,b, Cost, Tulip.Optimizer()) elseif choice_method=="epsscaling" ε = 0.01 γ = sinkhorn_stabilized_epsscaling(a,b, Cost, ε; maxiter=5_000) dot(γ, Cost) #compute optimal cost, directly end end @everywhere function ModToMod(i,j) a=Chl_from_Mod[:,:,i][:] b=Chl_from_Mod[:,:,j][:] a,b=preprocess_Chl(a,b) if choice_method=="sinkhorn2" ε = 0.05 sinkhorn2(a,b, Cost, ε) elseif choice_method=="emd2" emd2(a,b, Cost, Tulip.Optimizer()) elseif choice_method=="epsscaling" ε = 0.01 γ = sinkhorn_stabilized_epsscaling(a,b, Cost, ε; maxiter=5_000) dot(γ, Cost) #compute optimal cost, directly end end @everywhere function SatToSat(i,j) a=Chl_from_Sat[:,:,i][:] b=Chl_from_Sat[:,:,j][:] a,b=preprocess_Chl(a,b) if choice_method=="sinkhorn2" ε = 0.05 sinkhorn2(a,b, Cost, ε) elseif choice_method=="emd2" emd2(a,b, Cost, Tulip.Optimizer()) elseif choice_method=="epsscaling" ε = 0.01 γ = sinkhorn_stabilized_epsscaling(a,b, Cost, ε; maxiter=5_000) dot(γ, Cost) #compute optimal cost, directly end end ## @everywhere include("OptimalTransport_setup.jl") II=[[i,j] for i in 1:12, j in 1:12][:]; using Random; JJ=shuffle(II); if calc_ModToMod d = SharedArray{Float64}(12,12) t0=[time()] for kk in 1:36 @sync @distributed for k in (kk-1)*4 .+ collect(1:4) i=JJ[k][1] j=JJ[k][2] zm_test_case ? d[i,j]=ModToMod_MS(i,j) : d[i,j]=ModToMod(i,j) end dt=time()-t0[1] println("ModToMod $(kk) $(dt)") t0[1]=time() jldsave(joinpath(pth_output,"ModToMod_$(choice_method).jld2"); d = d.s) end end if calc_SatToSat d = SharedArray{Float64}(12,12) t0=[time()] for kk in 1:36 @sync @distributed for k in (kk-1)*4 .+ collect(1:4) i=JJ[k][1] j=JJ[k][2] zm_test_case ? d[i,j]=SatToSat_MS(i,j) : d[i,j]=SatToSat(i,j) end dt=time()-t0[1] println("SatToSat $(kk) $(dt)") t0[1]=time() jldsave(joinpath(pth_output,"SatToSat.jld2"); d = d.s) end end if calc_ModToSat d = SharedArray{Float64}(12,12) t0=[time()] for kk in 1:36 @sync @distributed for k in (kk-1)*4 .+ collect(1:4) i=JJ[k][1] j=JJ[k][2] zm_test_case ? d[i,j]=ModToSat_MS(i,j) : d[i,j]=ModToSat(i,j) end dt=time()-t0[1] println("ModToSat $(kk) $(dt)") t0[1]=time() jldsave(joinpath(pth_output,"ModToSat.jld2"); d = d.s) end end ## function used only for testing several methods at once @everywhere function ModToMod_methods(i,j,mthd=1) a=Chl_from_Mod[:,:,i][:] b=Chl_from_Mod[:,:,j][:] a,b=preprocess_Chl(a,b) a=sum(reshape(a,(120,140)),dims=1)[:] b=sum(reshape(b,(120,140)),dims=1)[:] Cost=Float64.([abs(i-j) for i in 1:140, j in 1:140]) if mthd==1 ε = 0.05 sinkhorn2(a,b, Cost, ε) elseif mthd==2 emd2(a,b, Cost, Tulip.Optimizer()) elseif mthd==3 ε = 0.005 γ = sinkhorn_stabilized(a,b, Cost, ε; maxiter=5_000) dot(γ, Cost) #compute optimal cost, directly elseif mthd==4 ε = 0.005 γ = sinkhorn_stabilized_epsscaling(a,b, Cost, ε; maxiter=5_000) dot(γ, Cost) #compute optimal cost, directly # elseif mthd==5 # ε = 0.05 # γ = quadreg(a,b, Cost, ε; maxiter=100) # dot(γ, Cost) #compute optimal cost, directly end end if test_methods #KK=([1,1],[1,2],[1,9]) KK=[[1,j] for j in 1:12] d = SharedArray{Float64}(6,length(KK)) t0=[time()] for k in 1:4 for kk in 1:12 i=KK[kk][1] j=KK[kk][2] try d[k,kk]=ModToMod_methods(i,j,k) catch d[k,kk]=NaN end println("$(k) $(kk) $(d[k,kk])") end dt=time()-t0[1] println("ModToMod_methods $(k) $(dt)") t0[1]=time() jldsave(joinpath(pth_output,"ModToMod_methods.jld2"); d = d.s) end end
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
code
1644
#using OceanStateEstimation, MeshArrays, NCTiles using JLD2 import CairoMakie as Mkie pth_output=joinpath(tempdir(),"OptimalTransport_example") function EMD_plot(fil) d=load(fil)["d"]; d[findall(d.==0.0)].=NaN; fig = Mkie.Figure(resolution = (600,400), backgroundcolor = :grey95, fontsize=12) ax = Mkie.Axis(fig[1,1]) hm=Mkie.heatmap!(d) Mkie.Colorbar(fig[1,2], hm, height = Mkie.Relative(0.65)) fig end function EMD_plot_all(pth=pth_output) fil1=joinpath(pth,"ModToMod.jld2") fil2=joinpath(pth,"SatToSat.jld2") fil3=joinpath(pth,"ModToSat.jld2") d1=load(fil1)["d"]; d1[findall(d1.==0.0)].=NaN; d2=load(fil2)["d"]; d2[findall(d2.==0.0)].=NaN; d3=load(fil3)["d"]; d3[findall(d3.==0.0)].=NaN; #just to check the alignment of dimensions d3[1:end,1].=NaN #cr=(0.07, 0.15) cr=(0.0, 10.0) fig = Mkie.Figure(resolution = (600,400), backgroundcolor = :grey95, fontsize=12) ax = Mkie.Axis(fig[1,1]) hm=Mkie.heatmap!(d1, colorrange = cr, colormap=:inferno) Mkie.ylims!(ax, (12.5, 0.5)); Mkie.xlims!(ax, (0.5,12.5)) ax = Mkie.Axis(fig[1,2]) hm=Mkie.heatmap!(transpose(d3), colorrange = cr, colormap=:inferno) Mkie.ylims!(ax, (12.5, 0.5)); Mkie.xlims!(ax, (0.5,12.5)) ax = Mkie.Axis(fig[2,1]) hm=Mkie.heatmap!(d3, colorrange = cr, colormap=:inferno) Mkie.ylims!(ax, (12.5, 0.5)); Mkie.xlims!(ax, (0.5,12.5)) ax = Mkie.Axis(fig[2,2]) hm=Mkie.heatmap!(d2, colorrange = cr, colormap=:inferno) Mkie.ylims!(ax, (12.5, 0.5)); Mkie.xlims!(ax, (0.5,12.5)) Mkie.Colorbar(fig[1:2,3], hm, height = Mkie.Relative(0.65)) fig end
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
code
2262
""" object: setup to compute optimal transport between model and/or satellite climatologies date: 2021/10/28 author: Gaël Forget - examples/CBIOMES_climatology_compare.jl """ import OceanStateEstimation, NCTiles using Statistics, LinearAlgebra, JLD2 ## load files fil_out=joinpath(OceanStateEstimation.CBIOMESclim_path,"CBIOMES-global-alpha-climatology.nc") nc=NCTiles.NCDataset(fil_out,"r") lon=nc["lon"][:] lat=nc["lat"][:] uni=nc["Chl"].attrib["units"] ## region and base distance (Cost) definition i1=findall( (lon.>-180.0).*(lon.<-120.0) ) j1=findall( (lat.>-20.0).*(lat.<50.0) ) ## main arrays Chl_from_Mod=nc["Chl"][i1,j1,:] fil_sat="examples_climatology_prep/gridded_geospatial_montly_clim_360_720_ver_0_2.nc" Chl_from_Sat=NCTiles.NCDataset(fil_sat,"r")["Chl"][i1,j1,:] ## cost matrix if !isfile("examples_EMD_paper_exploration/example_Cost.jld2") #this only needs to be done one #C = [[i,j] for i in i1, j in j1] C = [[lon[i],lat[j]] for i in i1, j in j1] C=C[:] gcdist(lo1,lo2,la1,la2) = acos(sind(la1)*sind(la2)+cosd(la1)*cosd(la2)*cosd(lo1-lo2)) #C=[gcdist(C[i][1],C[j][1],C[i][2],C[j][2]) for i in 1:length(C), j in 1:length(C)] nx=length(C) Cost=zeros(nx,nx) for i in 1:length(C), j in 1:length(C) i!==j ? Cost[i,j]=gcdist(C[i][1],C[j][1],C[i][2],C[j][2]) : nothing end @save "examples_EMD_paper_exploration/example_Cost.jld2" Cost end Cost=load("examples_EMD_paper_exploration/example_Cost.jld2")["Cost"] println("reusing Cost matrix computed previously\n") ## helper functions function preprocess_Chl(a,b) k=findall(ismissing.(a).|ismissing.(b)); a[k].=0.0; b[k].=0.0; k=findall((a.<0).|(b.<0)); a[k].=0.0; b[k].=0.0; k=findall(isnan.(a).|isnan.(b)); a[k].=0.0; b[k].=0.0; M=0.1 k=findall((a.>M).|(b.>M)); a[findall(a.>M)].=M; b[findall(b.>M)].=M; a=Float64.(a); a=a/sum(a) b=Float64.(b); b=b/sum(b) a,b end ## function export_zm() M=NaN*zeros(140,12) S=NaN*zeros(140,12) for t in 1:12 a=Chl_from_Mod[:,:,t][:] b=Chl_from_Sat[:,:,t][:] a,b=preprocess_Chl(a,b) M[:,t]=sum(reshape(a,(120,140)),dims=1)[:] S[:,t]=sum(reshape(b,(120,140)),dims=1)[:] end (M,S) end
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
code
323
module OceanDistributions using CSV, DataFrames export readoceandistribution """ readoceandistribution(fil::String) Read a distribution from csv file ``` Tcensus=readoceandistribution("examples/Tcensus.txt") ``` """ function readoceandistribution(file::String) return CSV.read(file,DataFrame) end end # module
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
code
225
using OceanDistributions using Test @testset "OceanDistributions.jl" begin Tcensus=readoceandistribution("../examples/Tcensus.txt") tmp=sum(Tcensus[!,:V]) @test isapprox(tmp,1.3349978769392906e18; atol=1e16) end
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
docs
844
# OceanDistributions [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://gaelforget.github.io/OceanDistributions.jl/stable) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://gaelforget.github.io/OceanDistributions.jl/dev) [![Build Status](https://travis-ci.org/gaelforget/OceanDistributions.jl.svg?branch=master)](https://travis-ci.org/gaelforget/OceanDistributions.jl) [![Codecov](https://codecov.io/gh/gaelforget/OceanDistributions.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/gaelforget/OceanDistributions.jl) [![DOI](https://zenodo.org/badge/240949850.svg)](https://zenodo.org/badge/latestdoi/240949850) Probabilistic, geographic, and temporal distributions of ocean properties, compounds, species, etc. _This package is in early developement stage when breaking changes can be expected._
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
docs
405
# OceanDistributions.jl Probabilistic, geographic, and temporal distributions of ocean properties, compounds, species, etc. Initial focus is expected to be on oceanic water mass distributions. _This package is at a very early stage of development._ ```@index ``` - [diffusion example](one_dim_diffusion.html) ➭ [download / url](one_dim_diffusion.jl) ```@autodocs Modules = [OceanDistributions] ```
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.3
92b3dd85df011ccb327a290110c39033e15e5ecf
docs
346
This ice thickness distribution code from 2012 was downloaded from the old `MITgcm_contrib` server as follows. With password `cvsanon`, do : ``` export CVSROOT=':pserver:[email protected]:/u/gcmpack' cvs login Logging in to :pserver:[email protected]:2401/u/gcmpack CVS password: cvs co MITgcm_contrib/gael/toy_models/ice_thick_distrib ```
OceanDistributions
https://github.com/JuliaOcean/OceanDistributions.jl.git
[ "MIT" ]
0.1.1
0a5d0b089a23bbf29712865ea6aab4ccceecc1e7
code
752
using DigitalHolography using Documenter DocMeta.setdocmeta!(DigitalHolography, :DocTestSetup, :(using DigitalHolography); recursive=true) makedocs(; modules=[DigitalHolography], authors="Shuhei Yoshida <[email protected]> and contributors", repo="https://github.com/syoshida1983/DigitalHolography.jl/blob/{commit}{path}#{line}", sitename="DigitalHolography.jl", format=Documenter.HTML(; prettyurls=get(ENV, "CI", "false") == "true", canonical="https://syoshida1983.github.io/DigitalHolography.jl", edit_link="master", assets=String[], ), pages=[ "Home" => "index.md", ], ) deploydocs(; repo="github.com/syoshida1983/DigitalHolography.jl", devbranch="master", )
DigitalHolography
https://github.com/syoshida1983/DigitalHolography.jl.git
[ "MIT" ]
0.1.1
0a5d0b089a23bbf29712865ea6aab4ccceecc1e7
code
4354
module DigitalHolography export PSDH2 export PSDH3 export PSDH4 export ParallelPSDH export GeneralizedPSDH """ PSDH2(I₁, I₂, Iᵣ, δ) return object wave extracted by the two-step phase-shifting method (see Ref. 1). # Arguments - `I₁`, `I₂`: Interferograms corresponding to phases ``\\phi`` and ``\\phi - \\delta``, respectively. - `Iᵣ`: intensity of reference wave. - `δ`: phase difference ``\\delta``. > 1. [X. F. Meng, L. Z. Cai, X. F. Xu, X. L. Yang, X. X. Shen, G. Y. Dong, and Y. R. Wang, "Two-step phase-shifting interferometry and its application in image encryption," Opt. Lett. **31**, 1414-1416 (2006)](https://doi.org/10.1364/OL.31.001414) """ function PSDH2(I₁, I₂, Iᵣ, δ) u = 2(1 - cos(δ)) v = @. 2(1 - cos(δ))*(I₁ + I₂) + 4Iᵣ*sin(δ)^2 w = @. I₁^2 + I₂^2 - 2*I₁*I₂*cos(δ) + 4Iᵣ^2*sin(δ)^2 a = @. (v - √(v^2 - 4u*w + 0im))/(2u) return @. (I₁ - a)/(2√Iᵣ) + im*(I₂ - I₁*cos(δ) - (1 - cos(δ))a)/(2sin(δ)√Iᵣ) end """ PSDH3(I₁, I₂, I₃, δ) return object wave extracted by the three-step phase-shifting method (see Ref. 1, 2). Phases of `I₁`, `I₂`, and `I₃` correspond to ``\\phi - \\delta``, ``\\phi``, and ``\\phi + \\delta``, respectively. > 1. [Katherine Creath, "V Phase-Measurement Interferometry Techniques," Progress in Optics **26**, 349-393 (1988)](https://doi.org/10.1016/S0079-6638(08)70178-1) > 2. [Horst Schreiber, and John H. Bruning, "Phase Shifting Interferometry," in Daniel Malacara (ed.), *Optical Shop Testing*, John Wiley & Sons, Ltd, pp. 547-666 (2006)](https://doi.org/10.1002/9780470135976.ch14) """ function PSDH3(I₁, I₂, I₃, δ) ϕ = @. atan((I₁ - I₃)/sin(δ), (2I₂ - I₁ - I₃)/(1 - cos(δ))) v = @. (I₁ + I₃ - 2I₂*cos(δ))/(2(1 - cos(δ))) w = @. √(((1 - cos(δ))*(I₁ - I₃))^2 + (sin(δ)*(2I₂ - I₁ - I₃))^2)/(2sin(δ)*(1 - cos(δ))) return @. √((v - √(v^2 - w^2 + 0im))/2)*exp(im*ϕ) end """ PSDH4(I₁, I₂, I₃, I₄) return object wave extracted by the four-step phase-shifting method. See (Creath, 1988), (Schreiber and Bruning, 2006). Phase difference `δ` corresponding to `I₁`, `I₂`, `I₃`, and `I₄` are assumed to be ``\\delta = 0, \\dfrac{\\pi}{2}, \\pi``, and ``\\dfrac{3\\pi}{2}``, respectively. """ function PSDH4(I₁, I₂, I₃, I₄) ϕ = @. atan(I₂ - I₄, I₁ - I₃) v = @. (I₁ + I₂ + I₃ + I₄)/4 w = @. √((I₁ - I₃)^2 + (I₂ - I₄)^2)/2 return @. √((v - √(v^2 - w^2 + 0im))/2)*exp(im*ϕ) end """ ParallelPSDH(I) return object wave extracted by the parallel four-step phase-shifting method (see Ref. 1, 2). Using 2x2 pixels with phase differences of ``\\dfrac{\\pi}{2}`` each as units, the object wave is extracted through the four-step phase-shifting method. > 1. [Y. Awatsuji, M. Sasada, and T. Kubota, "Parallel quasi-phase-shifting digital holography," Appl. Phys. Lett., **85**, 1069-1071 (2004).](https://doi.org/10.1063/1.1777796) > 2. [Yasuhiro Awatsuji, "Parallel Phase-Shifting Digital Holography," in Bahram Javidi, Enrique Tajahuerce, Pedro Andrés (eds.), *Multi-Dimensional Imaging*, John Wiley & Sons, Ltd, pp. 1-23](https://doi.org/10.1002/9781118705766.ch1) """ function ParallelPSDH(I) Ny, Nx = size(I) u = Array{ComplexF64}(undef, Ny, Nx) @fastmath @inbounds for j ∈ 1:Nx - 1, i ∈ 1:Ny - 1 I₁ = I[i+(i+1)%2, j+j%2] # +cos I₂ = I[i+(i+1)%2, j+(j+1)%2] # +sin I₃ = I[i+i%2, j+(j+1)%2] # -cos I₄ = I[i+i%2, j+j%2] # -sin ϕ = atan(I₂ - I₄, I₁ - I₃) v = (I₁ + I₂ + I₃ + I₄)/4 w = √((I₁ - I₃)^2 + (I₂ - I₄)^2)/2 u[i, j] = √((v - √(v^2 - w^2 + 0im))/2)*exp(im*ϕ) end u[:,end] = u[:,end-1] u[end,:] = u[end-1,:] u[end,end] = u[end-1,end-1] return u end """ GeneralizedPSDH(I) return object wave extracted by the generalized phase-shifting method. See (Creath, 1988), (Schreiber and Bruning, 2006). Store N interferograms in a three-dimensional array as `I[:,:,1]`, `I[:,:,2]`, ..., `I[:,:,N]`. Phase difference ``\\delta_{n}`` corresponding to the n-th interferogram is assumed to be ``\\delta_{n} = \\dfrac{2\\pi}{N}n``. """ function GeneralizedPSDH(I) N = size(I, 3) x = sum(I[:,:,i].*cos(i*2π/N) for i in 1:N) y = sum(I[:,:,i].*sin(i*2π/N) for i in 1:N) ϕ = @. atan(-y, x) v = sum(I[:,:,i] for i in 1:N)/N w = @. 2√(x^2 + y^2)/N return @. √((v - √(v^2 - w^2 + 0im))/2)*exp(im*ϕ) end end
DigitalHolography
https://github.com/syoshida1983/DigitalHolography.jl.git
[ "MIT" ]
0.1.1
0a5d0b089a23bbf29712865ea6aab4ccceecc1e7
code
107
using DigitalHolography using Test @testset "DigitalHolography.jl" begin # Write your tests here. end
DigitalHolography
https://github.com/syoshida1983/DigitalHolography.jl.git
[ "MIT" ]
0.1.1
0a5d0b089a23bbf29712865ea6aab4ccceecc1e7
docs
2397
# DigitalHolography [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://syoshida1983.github.io/DigitalHolography.jl/stable/) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://syoshida1983.github.io/DigitalHolography.jl/dev/) [![Build Status](https://github.com/syoshida1983/DigitalHolography.jl/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/syoshida1983/DigitalHolography.jl/actions/workflows/CI.yml?query=branch%3Amaster) This package provides the functions for extracting object wavefront from interferograms based on the phase-shifting method. Two [1], three [2,3], four [2,3], parallel [4,5], and generalized [2,3] phase-shifting methods are implemented. For detailed principles, please refer to the following references. > 1. [X. F. Meng, L. Z. Cai, X. F. Xu, X. L. Yang, X. X. Shen, G. Y. Dong, and Y. R. Wang, "Two-step phase-shifting interferometry and its application in image encryption," Opt. Lett. **31**, 1414-1416 (2006)](https://doi.org/10.1364/OL.31.001414) > 2. [Katherine Creath, "V Phase-Measurement Interferometry Techniques," Progress in Optics **26**, 349-393 (1988)](https://doi.org/10.1016/S0079-6638(08)70178-1) > 3. [Horst Schreiber, and John H. Bruning, "Phase Shifting Interferometry," in Daniel Malacara (ed.), *Optical Shop Testing*, John Wiley & Sons, Ltd, pp. 547-666 (2006)](https://doi.org/10.1002/9780470135976.ch14) > 4. [Y. Awatsuji, M. Sasada, and T. Kubota, "Parallel quasi-phase-shifting digital holography," Appl. Phys. Lett., **85**, 1069-1071 (2004).](https://doi.org/10.1063/1.1777796) > 5. [Yasuhiro Awatsuji, "Parallel Phase-Shifting Digital Holography," in Bahram Javidi, Enrique Tajahuerce, Pedro Andrés (eds.), *Multi-Dimensional Imaging*, John Wiley & Sons, Ltd, pp. 1-23](https://doi.org/10.1002/9781118705766.ch1) # Installation To install this package, open the Julia REPL and run ```julia julia> ]add DigitalHolography ``` or ```julia julia> using Pkg julia> Pkg.add("DigitalHolography") ``` # Usage Import the package first. ```julia julia> using DigitalHolography ``` Please refer to the following document for usage instructions. [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://syoshida1983.github.io/DigitalHolography.jl/stable/) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://syoshida1983.github.io/DigitalHolography.jl/dev/)
DigitalHolography
https://github.com/syoshida1983/DigitalHolography.jl.git
[ "MIT" ]
0.1.1
0a5d0b089a23bbf29712865ea6aab4ccceecc1e7
docs
471
```@meta CurrentModule = DigitalHolography ``` # DigitalHolography Documentation for [DigitalHolography](https://github.com/syoshida1983/DigitalHolography.jl). ```@index ``` !!! note When the object wave is denoted as ``u_{o} = ae^{i\phi}`` and the reference wave as ``u_{r} = be^{i\delta}``, the interference fringe ``I`` can be represented as ``I = |u_{o} + u_{r}|^{2} = a^{2} + b^{2} + 2ab\cos(\phi - \delta)``. ```@autodocs Modules = [DigitalHolography] ```
DigitalHolography
https://github.com/syoshida1983/DigitalHolography.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
563
using Documenter, CUDSS using LinearAlgebra using CUDA, CUDA.CUSPARSE makedocs( modules = [CUDSS], doctest = true, linkcheck = true, format = Documenter.HTML(ansicolor = true, prettyurls = get(ENV, "CI", nothing) == "true", collapselevel = 1), sitename = "CUDSS.jl", pages = ["Home" => "index.md", "Generic API" => "generic.md", "Options" => "options.md"] ) deploydocs( repo = "github.com/exanauts/CUDSS.jl.git", push_preview = true, devbranch = "main", )
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
145
# CUDSS uses CUDA runtime objects, which are compatible with our driver usage const cudaStream_t = CUstream const cudaDataType_t = cudaDataType
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
7895
using Clang using Clang.Generators using JuliaFormatter using CUDA_SDK_jll, CUDSS_jll function rewriter!(ctx, options) for node in get_nodes(ctx.dag) # remove aliases for function names # # when NVIDIA changes the behavior of an API, they version the function # (`cuFunction_v2`), and sometimes even change function names. To maintain backwards # compatibility, they ship aliases with their headers such that compiled binaries # will keep using the old version, and newly-compiled ones will use the developer's # CUDA version. remove those, since we target multiple CUDA versions. # # remove this if we ever decide to support a single supported version of CUDA. if node isa ExprNode{<:AbstractMacroNodeType} isempty(node.exprs) && continue expr = node.exprs[1] if Meta.isexpr(expr, :const) expr = expr.args[1] end if Meta.isexpr(expr, :(=)) lhs, rhs = expr.args if rhs isa Expr && rhs.head == :call name = string(rhs.args[1]) if endswith(name, "STRUCT_SIZE") rhs.head = :macrocall rhs.args[1] = Symbol("@", name) insert!(rhs.args, 2, nothing) end end isa(lhs, Symbol) || continue if Meta.isexpr(rhs, :call) && rhs.args[1] in (:__CUDA_API_PTDS, :__CUDA_API_PTSZ) rhs = rhs.args[2] end isa(rhs, Symbol) || continue lhs, rhs = String(lhs), String(rhs) function get_prefix(str) # cuFooBar -> cu isempty(str) && return nothing islowercase(str[1]) || return nothing for i in 2:length(str) if isuppercase(str[i]) return str[1:i-1] end end return nothing end lhs_prefix = get_prefix(lhs) lhs_prefix === nothing && continue rhs_prefix = get_prefix(rhs) if lhs_prefix == rhs_prefix @debug "Removing function alias: `$expr`" empty!(node.exprs) end end end if Generators.is_function(node) && !Generators.is_variadic_function(node) expr = node.exprs[1] call_expr = expr.args[2].args[1].args[3] # assumes `use_ccall_macro` is true # replace `@ccall` with `@gcsafe_ccall` expr.args[2].args[1].args[1] = Symbol("@gcsafe_ccall") target_expr = call_expr.args[1].args[1] fn = String(target_expr.args[2].value) # look up API options for this function fn_options = Dict{String,Any}() templates = Dict{String,Any}() template_types = nothing if haskey(options, "api") names = [fn] # _64 aliases are used by CUBLAS with Int64 arguments. they otherwise have # an idential signature, so we can reuse the same type rewrites. if endswith(fn, "_64") push!(names, fn[1:end-3]) end # look for a template rewrite: many libraries have very similar functions, # e.g., `cublas[SDHCZ]gemm`, for which we can use the same type rewrites # registered as `cublas𝕏gemm` template with `T` and `S` placeholders. for name in copy(names), (typcode,(T,S)) in ["S"=>("Cfloat","Cfloat"), "D"=>("Cdouble","Cdouble"), "H"=>("Float16","Float16"), "C"=>("cuComplex","Cfloat"), "Z"=>("cuDoubleComplex","Cdouble")] idx = findfirst(typcode, name) while idx !== nothing template_name = name[1:idx.start-1] * "𝕏" * name[idx.stop+1:end] if haskey(options["api"], template_name) templates[template_name] = ["T" => T, "S" => S] push!(names, template_name) end idx = findnext(typcode, name, idx.stop+1) end end # the exact name is always checked first, so it's always possible to # override the type rewrites for a specific function # (e.g. if a _64 function ever passes a `Ptr{Cint}` index). for name in names template_types = get(templates, name, nothing) if haskey(options["api"], name) fn_options = options["api"][name] break end end end # rewrite pointer argument types arg_exprs = call_expr.args[1].args[2:end] argtypes = get(fn_options, "argtypes", Dict()) for (arg, typ) in argtypes i = parse(Int, arg) i in 1:length(arg_exprs) || error("invalid argtypes for $fn: index $arg is out of bounds") # _64 aliases should use Int64 instead of Int32/Cint if endswith(fn, "_64") typ = replace(typ, "Cint" => "Int64", "Int32" => "Int64") end # expand type templates if template_types !== nothing typ = replace(typ, template_types...) end arg_exprs[i].args[2] = Meta.parse(typ) end # insert `initialize_context()` before each function with a `ccall` if get(fn_options, "needs_context", true) pushfirst!(expr.args[2].args, :(initialize_context())) end # insert `@checked` before each function with a `ccall` returning a checked type` rettyp = call_expr.args[2] checked_types = if haskey(options, "api") get(options["api"], "checked_rettypes", Dict()) else String[] end if rettyp isa Symbol && String(rettyp) in checked_types node.exprs[1] = Expr(:macrocall, Symbol("@checked"), nothing, expr) end end end end function main() cuda = joinpath(CUDA_SDK_jll.artifact_dir, "cuda", "include") @assert CUDA_SDK_jll.is_available() cudss = joinpath(CUDSS_jll.artifact_dir, "include") @assert CUDSS_jll.is_available() args = get_default_args() push!(args, "-I$cudss", "-I$cuda") options = load_options(joinpath(@__DIR__, "cudss.toml")) # create context headers = ["$cudss/cudss.h"] targets = ["$cudss/cudss.h", "$cudss/cudss_distributed_interface.h"] ctx = create_context(headers, args, options) # run generator build!(ctx, BUILDSTAGE_NO_PRINTING) # Only keep the wrapped headers replace!(get_nodes(ctx.dag)) do node path = normpath(Clang.get_filename(node.cursor)) should_wrap = any(targets) do target occursin(target, path) end if !should_wrap return ExprNode(node.id, Generators.Skip(), node.cursor, Expr[], node.adj) end return node end rewriter!(ctx, options) build!(ctx, BUILDSTAGE_PRINTING_ONLY) output_file = options["general"]["output_file_path"] format_file(output_file, YASStyle()) return end if abspath(PROGRAM_FILE) == @__FILE__ main() end
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
769
module CUDSS using CUDA, CUDA.APIUtils, CUDA.CUSPARSE using CUDSS_jll using LinearAlgebra using SparseArrays if haskey(ENV, "JULIA_CUDSS_LIBRARY_PATH") && Sys.islinux() const libcudss = joinpath(ENV["JULIA_CUDSS_LIBRARY_PATH"], "libcudss.so") const CUDSS_INSTALLATION = "CUSTOM" else using CUDSS_jll const CUDSS_INSTALLATION = "YGGDRASIL" end import CUDA: @checked, libraryPropertyType, cudaDataType, initialize_context, retry_reclaim, CUstream, @gcsafe_ccall import LinearAlgebra: lu, lu!, ldlt, ldlt!, cholesky, cholesky!, ldiv!, BlasFloat, BlasReal, checksquare import Base: \ include("libcudss.jl") include("error.jl") include("types.jl") include("helpers.jl") include("management.jl") include("interfaces.jl") include("generic.jl") end # module CUDSS
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
1653
struct CUDSSError <: Exception code::cudssStatus_t end Base.convert(::Type{cudssStatus_t}, err::CUDSSError) = err.code Base.showerror(io::IO, err::CUDSSError) = print(io, "CUDSSError: ", description(err), " (code $(reinterpret(Int32, err.code)), $(name(err)))") name(err::CUDSSError) = string(err.code) function description(err::CUDSSError) if err.code == CUDSS_STATUS_SUCCESS return "the operation completed successfully" elseif err.code == CUDSS_STATUS_NOT_INITIALIZED return "the library was not initialized" elseif err.code == CUDSS_STATUS_ALLOC_FAILED return "the resource allocation failed" elseif err.code == CUDSS_STATUS_INVALID_VALUE return "an invalid value was used as an argument" elseif err.code == CUDSS_STATUS_NOT_SUPPORTED return "a parameter is not supported" elseif err.code == CUDSS_STATUS_EXECUTION_FAILED return "the GPU program failed to execute" elseif err.code == CUDSS_STATUS_INTERNAL_ERROR return "an internal operation failed" else return "no description for this error" end end # outlined functionality to avoid GC frame allocation @noinline function throw_api_error(res) if res == CUDSS_STATUS_ALLOC_FAILED throw(OutOfGPUMemoryError()) else throw(CUDSSError(res)) end end @inline function check(f) retry_if(res) = res in (CUDSS_STATUS_NOT_INITIALIZED, CUDSS_STATUS_ALLOC_FAILED, CUDSS_STATUS_INTERNAL_ERROR) res = retry_reclaim(f, retry_if) if res != CUDSS_STATUS_SUCCESS throw_api_error(res) end end
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
5516
""" solver = lu(A::CuSparseMatrixCSR{T,Cint}) Compute the LU factorization of a sparse matrix `A` on an NVIDIA GPU. The type `T` can be `Float32`, `Float64`, `ComplexF32` or `ComplexF64`. #### Input argument * `A`: a sparse square matrix stored in the `CuSparseMatrixCSR` format. #### Output argument * `solver`: an opaque structure [`CudssSolver`](@ref) that stores the factors of the LU decomposition. """ function LinearAlgebra.lu(A::CuSparseMatrixCSR{T,Cint}; check = false) where T <: BlasFloat n = checksquare(A) solver = CudssSolver(A, "G", 'F') x = CudssMatrix(T, n) b = CudssMatrix(T, n) cudss("analysis", solver, x, b) cudss("factorization", solver, x, b) return solver end """ solver = lu!(solver::CudssSolver{T}, A::CuSparseMatrixCSR{T,Cint}) Compute the LU factorization of a sparse matrix `A` on an NVIDIA GPU, reusing the symbolic factorization stored in `solver`. The type `T` can be `Float32`, `Float64`, `ComplexF32` or `ComplexF64`. """ function LinearAlgebra.lu!(solver::CudssSolver{T}, A::CuSparseMatrixCSR{T,Cint}; check = false) where T <: BlasFloat n = checksquare(A) cudss_set(solver, A) x = CudssMatrix(T, n) b = CudssMatrix(T, n) cudss("refactorization", solver, x, b) return solver end """ solver = ldlt(A::CuSparseMatrixCSR{T,Cint}; view::Char='F') Compute the LDLᴴ factorization of a sparse matrix `A` on an NVIDIA GPU. The type `T` can be `Float32`, `Float64`, `ComplexF32` or `ComplexF64`. #### Input argument * `A`: a sparse Hermitian matrix stored in the `CuSparseMatrixCSR` format. #### Keyword argument *`view`: A character that specifies which triangle of the sparse matrix is provided. Possible options are `L` for the lower triangle, `U` for the upper triangle, and `F` for the full matrix. #### Output argument * `solver`: Opaque structure [`CudssSolver`](@ref) that stores the factors of the LDLᴴ decomposition. """ function LinearAlgebra.ldlt(A::CuSparseMatrixCSR{T,Cint}; view::Char='F', check = false) where T <: BlasFloat n = checksquare(A) structure = T <: Real ? "S" : "H" solver = CudssSolver(A, structure, view) x = CudssMatrix(T, n) b = CudssMatrix(T, n) cudss("analysis", solver, x, b) cudss("factorization", solver, x, b) return solver end LinearAlgebra.ldlt(A::Symmetric{T,<:CuSparseMatrixCSR{T,Cint}}; check = false) where T <: BlasReal = LinearAlgebra.ldlt(A.data, view=A.uplo) LinearAlgebra.ldlt(A::Hermitian{T,<:CuSparseMatrixCSR{T,Cint}}; check = false) where T <: BlasFloat = LinearAlgebra.ldlt(A.data, view=A.uplo) """ solver = ldlt!(solver::CudssSolver{T}, A::CuSparseMatrixCSR{T,Cint}) Compute the LDLᴴ factorization of a sparse matrix `A` on an NVIDIA GPU, reusing the symbolic factorization stored in `solver`. The type `T` can be `Float32`, `Float64`, `ComplexF32` or `ComplexF64`. """ function LinearAlgebra.ldlt!(solver::CudssSolver{T}, A::CuSparseMatrixCSR{T,Cint}; check = false) where T <: BlasFloat n = checksquare(A) cudss_set(solver, A) x = CudssMatrix(T, n) b = CudssMatrix(T, n) cudss("refactorization", solver, x, b) return solver end """ solver = cholesky(A::CuSparseMatrixCSR{T,Cint}; view::Char='F') Compute the LLᴴ factorization of a sparse matrix `A` on an NVIDIA GPU. The type `T` can be `Float32`, `Float64`, `ComplexF32` or `ComplexF64`. #### Input argument * `A`: a sparse Hermitian positive definite matrix stored in the `CuSparseMatrixCSR` format. #### Keyword argument *`view`: A character that specifies which triangle of the sparse matrix is provided. Possible options are `L` for the lower triangle, `U` for the upper triangle, and `F` for the full matrix. #### Output argument * `solver`: Opaque structure [`CudssSolver`](@ref) that stores the factors of the LLᴴ decomposition. """ function LinearAlgebra.cholesky(A::CuSparseMatrixCSR{T,Cint}; view::Char='F', check = false) where T <: BlasFloat n = checksquare(A) structure = T <: Real ? "SPD" : "HPD" solver = CudssSolver(A, structure, view) x = CudssMatrix(T, n) b = CudssMatrix(T, n) cudss("analysis", solver, x, b) cudss("factorization", solver, x, b) return solver end LinearAlgebra.cholesky(A::Symmetric{T,<:CuSparseMatrixCSR{T,Cint}}; check = false) where T <: BlasReal = LinearAlgebra.cholesky(A.data, view=A.uplo) LinearAlgebra.cholesky(A::Hermitian{T,<:CuSparseMatrixCSR{T,Cint}}; check = false) where T <: BlasFloat = LinearAlgebra.cholesky(A.data, view=A.uplo) """ solver = cholesky!(solver::CudssSolver{T}, A::CuSparseMatrixCSR{T,Cint}) Compute the LLᴴ factorization of a sparse matrix `A` on an NVIDIA GPU, reusing the symbolic factorization stored in `solver`. The type `T` can be `Float32`, `Float64`, `ComplexF32` or `ComplexF64`. """ function LinearAlgebra.cholesky!(solver::CudssSolver{T}, A::CuSparseMatrixCSR{T,Cint}; check = false) where T <: BlasFloat n = checksquare(A) cudss_set(solver, A) x = CudssMatrix(T, n) b = CudssMatrix(T, n) cudss("refactorization", solver, x, b) return solver end for type in (:CuVector, :CuMatrix) @eval begin function LinearAlgebra.ldiv!(solver::CudssSolver{T}, b::$type{T}) where T <: BlasFloat cudss("solve", solver, b, b) return b end function LinearAlgebra.ldiv!(x::$type{T}, solver::CudssSolver{T}, b::$type{T}) where T <: BlasFloat cudss("solve", solver, x, b) return x end function Base.:\(solver::CudssSolver{T}, b::$type{T}) where T <: BlasFloat x = similar(b) ldiv!(x, solver, b) return x end end end
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
4493
# cuDSS helper functions export CudssMatrix, CudssData, CudssConfig ## Matrix """ matrix = CudssMatrix(v::CuVector{T}) matrix = CudssMatrix(A::CuMatrix{T}) matrix = CudssMatrix(A::CuSparseMatrixCSR{T,Cint}, struture::String, view::Char; index::Char='O') The type `T` can be `Float32`, `Float64`, `ComplexF32` or `ComplexF64`. `CudssMatrix` is a wrapper for `CuVector`, `CuMatrix` and `CuSparseMatrixCSR`. `CudssMatrix` is used to pass matrix of the linear system, as well as solution and right-hand side. `structure` specifies the stucture for sparse matrices: - `"G"`: General matrix -- LDU factorization; - `"S"`: Real symmetric matrix -- LDLᵀ factorization; - `"H"`: Complex Hermitian matrix -- LDLᴴ factorization; - `"SPD"`: Symmetric positive-definite matrix -- LLᵀ factorization; - `"HPD"`: Hermitian positive-definite matrix -- LLᴴ factorization. `view` specifies matrix view for sparse matrices: - `'L'`: Lower-triangular matrix and all values above the main diagonal are ignored; - `'U'`: Upper-triangular matrix and all values below the main diagonal are ignored; - `'F'`: Full matrix. `index` specifies indexing base for sparse matrix indices: - `'Z'`: 0-based indexing; - `'O'`: 1-based indexing. """ mutable struct CudssMatrix{T} type::Type{T} matrix::cudssMatrix_t function CudssMatrix(::Type{T}, n::Integer) where T <: BlasFloat matrix_ref = Ref{cudssMatrix_t}() cudssMatrixCreateDn(matrix_ref, n, 1, n, CU_NULL, T, 'C') obj = new{T}(T, matrix_ref[]) finalizer(cudssMatrixDestroy, obj) obj end function CudssMatrix(::Type{T}, m::Integer, n::Integer; transposed::Bool=false) where T <: BlasFloat matrix_ref = Ref{cudssMatrix_t}() if transposed cudssMatrixCreateDn(matrix_ref, n, m, m, CU_NULL, T, 'R') else cudssMatrixCreateDn(matrix_ref, m, n, m, CU_NULL, T, 'C') end obj = new{T}(T, matrix_ref[]) finalizer(cudssMatrixDestroy, obj) obj end function CudssMatrix(v::CuVector{T}) where T <: BlasFloat m = length(v) matrix_ref = Ref{cudssMatrix_t}() cudssMatrixCreateDn(matrix_ref, m, 1, m, v, T, 'C') obj = new{T}(T, matrix_ref[]) finalizer(cudssMatrixDestroy, obj) obj end function CudssMatrix(A::CuMatrix{T}; transposed::Bool=false) where T <: BlasFloat m,n = size(A) matrix_ref = Ref{cudssMatrix_t}() if transposed cudssMatrixCreateDn(matrix_ref, n, m, m, A, T, 'R') else cudssMatrixCreateDn(matrix_ref, m, n, m, A, T, 'C') end obj = new{T}(T, matrix_ref[]) finalizer(cudssMatrixDestroy, obj) obj end function CudssMatrix(A::CuSparseMatrixCSR{T,Cint}, structure::String, view::Char; index::Char='O') where T <: BlasFloat m,n = size(A) matrix_ref = Ref{cudssMatrix_t}() cudssMatrixCreateCsr(matrix_ref, m, n, nnz(A), A.rowPtr, CU_NULL, A.colVal, A.nzVal, eltype(A.rowPtr), T, structure, view, index) obj = new{T}(T, matrix_ref[]) finalizer(cudssMatrixDestroy, obj) obj end end Base.unsafe_convert(::Type{cudssMatrix_t}, matrix::CudssMatrix) = matrix.matrix ## Data """ data = CudssData() data = CudssData(cudss_handle::cudssHandle_t) `CudssData` holds internal data (e.g., LU factors arrays). """ mutable struct CudssData handle::cudssHandle_t data::cudssData_t function CudssData(cudss_handle::cudssHandle_t) data_ref = Ref{cudssData_t}() cudssDataCreate(cudss_handle, data_ref) obj = new(cudss_handle, data_ref[]) finalizer(cudssDataDestroy, obj) obj end function CudssData() cudss_handle = handle() CudssData(cudss_handle) end end Base.unsafe_convert(::Type{cudssData_t}, data::CudssData) = data.data function cudssDataDestroy(data::CudssData) cudssDataDestroy(data.handle, data) end ## Configuration """ config = CudssConfig() `CudssConfig` stores configuration settings for the solver. """ mutable struct CudssConfig config::cudssConfig_t function CudssConfig() config_ref = Ref{cudssConfig_t}() cudssConfigCreate(config_ref) obj = new(config_ref[]) finalizer(cudssConfigDestroy, obj) obj end end Base.unsafe_convert(::Type{cudssConfig_t}, config::CudssConfig) = config.config
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
10737
export CudssSolver, cudss, cudss_set, cudss_get """ solver = CudssSolver(A::CuSparseMatrixCSR{T,Cint}, structure::String, view::Char; index::Char='O') solver = CudssSolver(matrix::CudssMatrix{T}, config::CudssConfig, data::CudssData) The type `T` can be `Float32`, `Float64`, `ComplexF32` or `ComplexF64`. `CudssSolver` contains all structures required to solve linear systems with cuDSS. One constructor of `CudssSolver` takes as input the same parameters as [`CudssMatrix`](@ref). `structure` specifies the stucture for sparse matrices: - `"G"`: General matrix -- LDU factorization; - `"S"`: Real symmetric matrix -- LDLᵀ factorization; - `"H"`: Complex Hermitian matrix -- LDLᴴ factorization; - `"SPD"`: Symmetric positive-definite matrix -- LLᵀ factorization; - `"HPD"`: Hermitian positive-definite matrix -- LLᴴ factorization. `view` specifies matrix view for sparse matrices: - `'L'`: Lower-triangular matrix and all values above the main diagonal are ignored; - `'U'`: Upper-triangular matrix and all values below the main diagonal are ignored; - `'F'`: Full matrix. `index` specifies indexing base for sparse matrix indices: - `'Z'`: 0-based indexing; - `'O'`: 1-based indexing. `CudssSolver` can be also constructed from the three structures `CudssMatrix`, `CudssConfig` and `CudssData` if needed. """ mutable struct CudssSolver{T} matrix::CudssMatrix{T} config::CudssConfig data::CudssData function CudssSolver(matrix::CudssMatrix{T}, config::CudssConfig, data::CudssData) where T <: BlasFloat return new{T}(matrix, config, data) end function CudssSolver(A::CuSparseMatrixCSR{T,Cint}, structure::String, view::Char; index::Char='O') where T <: BlasFloat matrix = CudssMatrix(A, structure, view; index) config = CudssConfig() data = CudssData() return new{T}(matrix, config, data) end end """ cudss_set(matrix::CudssMatrix{T}, v::CuVector{T}) cudss_set(matrix::CudssMatrix{T}, A::CuMatrix{T}) cudss_set(matrix::CudssMatrix{T}, A::CuSparseMatrixCSR{T,Cint}) cudss_set(solver::CudssSolver{T}, A::CuSparseMatrixCSR{T,Cint}) cudss_set(solver::CudssSolver, parameter::String, value) cudss_set(config::CudssConfig, parameter::String, value) cudss_set(data::CudssData, parameter::String, value) The type `T` can be `Float32`, `Float64`, `ComplexF32` or `ComplexF64`. The available configuration parameters are: - `"reordering_alg"`: Algorithm for the reordering phase (`"default"`, `"algo1"`, `"algo2"` or `"algo3"`); - `"factorization_alg"`: Algorithm for the factorization phase (`"default"`, `"algo1"`, `"algo2"` or `"algo3"`); - `"solve_alg"`: Algorithm for the solving phase (`"default"`, `"algo1"`, `"algo2"` or `"algo3"`); - `"matching_type"`: Type of matching; - `"solve_mode"`: Potential modificator on the system matrix (transpose or adjoint); - `"ir_n_steps"`: Number of steps during the iterative refinement; - `"ir_tol"`: Iterative refinement tolerance; - `"pivot_type"`: Type of pivoting (`'C'`, `'R'` or `'N'`); - `"pivot_threshold"`: Pivoting threshold which is used to determine if digonal element is subject to pivoting; - `"pivot_epsilon"`: Pivoting epsilon, absolute value to replace singular diagonal elements; - `"max_lu_nnz"`: Upper limit on the number of nonzero entries in LU factors for non-symmetric matrices; - `"hybrid_mode"`: Memory mode -- `0` (default = device-only) or `1` (hybrid = host/device); - `"hybrid_device_memory_limit"`: User-defined device memory limit (number of bytes) for the hybrid memory mode; - `"use_cuda_register_memory"`: A flag to enable (`1`) or disable (`0`) usage of `cudaHostRegister()` by the hybrid memory mode. The available data parameters are: - `"user_perm"`: User permutation to be used instead of running the reordering algorithms; - `"comm"`: Communicator for Multi-GPU multi-node mode. """ function cudss_set end function cudss_set(matrix::CudssMatrix{T}, v::CuVector{T}) where T <: BlasFloat cudssMatrixSetValues(matrix, v) end function cudss_set(matrix::CudssMatrix{T}, A::CuMatrix{T}) where T <: BlasFloat cudssMatrixSetValues(matrix, A) end function cudss_set(matrix::CudssMatrix{T}, A::CuSparseMatrixCSR{T,Cint}) where T <: BlasFloat cudssMatrixSetCsrPointers(matrix, A.rowPtr, CU_NULL, A.colVal, A.nzVal) end function cudss_set(solver::CudssSolver{T}, A::CuSparseMatrixCSR{T,Cint}) where T <: BlasFloat cudss_set(solver.matrix, A) end function cudss_set(solver::CudssSolver, parameter::String, value) if parameter ∈ CUDSS_CONFIG_PARAMETERS cudss_set(solver.config, parameter, value) elseif parameter ∈ CUDSS_DATA_PARAMETERS cudss_set(solver.data, parameter, value) else throw(ArgumentError("Unknown data or config parameter $parameter.")) end end function cudss_set(data::CudssData, parameter::String, value) (parameter ∈ CUDSS_DATA_PARAMETERS) || throw(ArgumentError("Unknown data parameter $parameter.")) (parameter == "user_perm") || (parameter == "comm") || throw(ArgumentError("Only the data parameters \"user_perm\" and \"comm\" can be set.")) (value isa Vector{Cint} || value isa CuVector{Cint}) || throw(ArgumentError("The permutation is neither a Vector{Cint} nor a CuVector{Cint}.")) nbytes = sizeof(value) cudssDataSet(data.handle, data, parameter, value, nbytes) end function cudss_set(config::CudssConfig, parameter::String, value) (parameter ∈ CUDSS_CONFIG_PARAMETERS) || throw(ArgumentError("Unknown config parameter $parameter.")) type = CUDSS_TYPES[parameter] val = Ref{type}(value) nbytes = sizeof(val) cudssConfigSet(config, parameter, val, nbytes) end """ value = cudss_get(solver::CudssSolver, parameter::String) value = cudss_get(config::CudssConfig, parameter::String) value = cudss_get(data::CudssData, parameter::String) The available configuration parameters are: - `"reordering_alg"`: Algorithm for the reordering phase; - `"factorization_alg"`: Algorithm for the factorization phase; - `"solve_alg"`: Algorithm for the solving phase; - `"matching_type"`: Type of matching; - `"solve_mode"`: Potential modificator on the system matrix (transpose or adjoint); - `"ir_n_steps"`: Number of steps during the iterative refinement; - `"ir_tol"`: Iterative refinement tolerance; - `"pivot_type"`: Type of pivoting; - `"pivot_threshold"`: Pivoting threshold which is used to determine if digonal element is subject to pivoting; - `"pivot_epsilon"`: Pivoting epsilon, absolute value to replace singular diagonal elements; - `"max_lu_nnz"`: Upper limit on the number of nonzero entries in LU factors for non-symmetric matrices; - `"hybrid_mode"`: Memory mode -- `0` (default = device-only) or `1` (hybrid = host/device); - `"hybrid_device_memory_limit"`: User-defined device memory limit (number of bytes) for the hybrid memory mode; - `"use_cuda_register_memory"`: A flag to enable (`1`) or disable (`0`) usage of `cudaHostRegister()` by the hybrid memory mode. The available data parameters are: - `"info"`: Device-side error information; - `"lu_nnz"`: Number of non-zero entries in LU factors; - `"npivots"`: Number of pivots encountered during factorization; - `"inertia"`: Tuple of positive and negative indices of inertia for symmetric and hermitian non positive-definite matrix types; - `"perm_reorder_row"`: Reordering permutation for the rows; - `"perm_reorder_col"`: Reordering permutation for the columns; - `"perm_row"`: Final row permutation (which includes effects of both reordering and pivoting); - `"perm_col"`: Final column permutation (which includes effects of both reordering and pivoting); - `"diag"`: Diagonal of the factorized matrix; - `"hybrid_device_memory_min"`: Minimal amount of device memory (number of bytes) required in the hybrid memory mode. The data parameters `"info"`, `"lu_nnz"`, `"perm_reorder_row"`, `"perm_reorder_col"` and `"hybrid_device_memory_min"` require the phase `"analyse"` performed by [`cudss`](@ref). The data parameters `"npivots"`, `"inertia"` and `"diag"` require the phases `"analyse"` and `"factorization"` performed by [`cudss`](@ref). The data parameters `"perm_row"` and `"perm_col"` are available but not yet functional. """ function cudss_get end function cudss_get(solver::CudssSolver, parameter::String) if parameter ∈ CUDSS_CONFIG_PARAMETERS cudss_get(solver.config, parameter) elseif parameter ∈ CUDSS_DATA_PARAMETERS cudss_get(solver.data, parameter) else throw(ArgumentError("Unknown data or config parameter $parameter.")) end end function cudss_get(data::CudssData, parameter::String) (parameter ∈ CUDSS_DATA_PARAMETERS) || throw(ArgumentError("Unknown data parameter $parameter.")) if (parameter == "user_perm") || (parameter == "comm") throw(ArgumentError("The data parameter \"$parameter\" cannot be retrieved.")) end if (parameter == "perm_reorder_row") || (parameter == "perm_reorder_col") || (parameter == "perm_row") || (parameter == "perm_col") || (parameter == "diag") throw(ArgumentError("The data parameter \"$parameter\" is not supported by CUDSS.jl.")) end type = CUDSS_TYPES[parameter] val = Ref{type}() nbytes = sizeof(val) nbytes_written = Ref{Csize_t}() cudssDataGet(handle(), data, parameter, val, nbytes, nbytes_written) return val[] end function cudss_get(config::CudssConfig, parameter::String) (parameter ∈ CUDSS_CONFIG_PARAMETERS) || throw(ArgumentError("Unknown config parameter $parameter.")) type = CUDSS_TYPES[parameter] val = Ref{type}() nbytes = sizeof(val) nbytes_written = Ref{Csize_t}() cudssConfigGet(config, parameter, val, nbytes, nbytes_written) return val[] end """ cudss(phase::String, solver::CudssSolver{T}, x::CuVector{T}, b::CuVector{T}) cudss(phase::String, solver::CudssSolver{T}, X::CuMatrix{T}, B::CuMatrix{T}) cudss(phase::String, solver::CudssSolver{T}, X::CudssMatrix{T}, B::CudssMatrix{T}) The type `T` can be `Float32`, `Float64`, `ComplexF32` or `ComplexF64`. The available phases are `"analysis"`, `"factorization"`, `"refactorization"` and `"solve"`. The phases `"solve_fwd"`, `"solve_diag"` and `"solve_bwd"` are available but not yet functional. """ function cudss end function cudss(phase::String, solver::CudssSolver{T}, X::CudssMatrix{T}, B::CudssMatrix{T}) where T <: BlasFloat cudssExecute(solver.data.handle, phase, solver.config, solver.data, solver.matrix, X, B) end function cudss(phase::String, solver::CudssSolver{T}, x::CuVector{T}, b::CuVector{T}) where T <: BlasFloat solution = CudssMatrix(x) rhs = CudssMatrix(b) cudss(phase, solver, solution, rhs) end function cudss(phase::String, solver::CudssSolver{T}, X::CuMatrix{T}, B::CuMatrix{T}) where T <: BlasFloat solution = CudssMatrix(X) rhs = CudssMatrix(B) cudss(phase, solver, solution, rhs) end
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
12078
using CEnum # CUDSS uses CUDA runtime objects, which are compatible with our driver usage const cudaStream_t = CUstream const cudaDataType_t = cudaDataType @cenum cudssOpType_t::UInt32 begin CUDSS_SUM = 0 CUDSS_MAX = 1 CUDSS_MIN = 2 end struct cudssDistributedInterface_t cudssCommRank::Ptr{Cvoid} cudssCommSize::Ptr{Cvoid} cudssSend::Ptr{Cvoid} cudssRecv::Ptr{Cvoid} cudssBcast::Ptr{Cvoid} cudssReduce::Ptr{Cvoid} cudssAllreduce::Ptr{Cvoid} cudssScatterv::Ptr{Cvoid} cudssCommSplit::Ptr{Cvoid} cudssCommFree::Ptr{Cvoid} end mutable struct cudssContext end const cudssHandle_t = Ptr{cudssContext} mutable struct cudssMatrix end const cudssMatrix_t = Ptr{cudssMatrix} mutable struct cudssData end const cudssData_t = Ptr{cudssData} mutable struct cudssConfig end const cudssConfig_t = Ptr{cudssConfig} @cenum cudssConfigParam_t::UInt32 begin CUDSS_CONFIG_REORDERING_ALG = 0 CUDSS_CONFIG_FACTORIZATION_ALG = 1 CUDSS_CONFIG_SOLVE_ALG = 2 CUDSS_CONFIG_MATCHING_TYPE = 3 CUDSS_CONFIG_SOLVE_MODE = 4 CUDSS_CONFIG_IR_N_STEPS = 5 CUDSS_CONFIG_IR_TOL = 6 CUDSS_CONFIG_PIVOT_TYPE = 7 CUDSS_CONFIG_PIVOT_THRESHOLD = 8 CUDSS_CONFIG_PIVOT_EPSILON = 9 CUDSS_CONFIG_MAX_LU_NNZ = 10 CUDSS_CONFIG_HYBRID_MODE = 11 CUDSS_CONFIG_HYBRID_DEVICE_MEMORY_LIMIT = 12 CUDSS_CONFIG_USE_CUDA_REGISTER_MEMORY = 13 end @cenum cudssDataParam_t::UInt32 begin CUDSS_DATA_INFO = 0 CUDSS_DATA_LU_NNZ = 1 CUDSS_DATA_NPIVOTS = 2 CUDSS_DATA_INERTIA = 3 CUDSS_DATA_PERM_REORDER_ROW = 4 CUDSS_DATA_PERM_REORDER_COL = 5 CUDSS_DATA_PERM_ROW = 6 CUDSS_DATA_PERM_COL = 7 CUDSS_DATA_DIAG = 8 CUDSS_DATA_USER_PERM = 9 CUDSS_DATA_HYBRID_DEVICE_MEMORY_MIN = 10 CUDSS_DATA_COMM = 11 end @cenum cudssPhase_t::UInt32 begin CUDSS_PHASE_ANALYSIS = 1 CUDSS_PHASE_FACTORIZATION = 2 CUDSS_PHASE_REFACTORIZATION = 4 CUDSS_PHASE_SOLVE = 8 CUDSS_PHASE_SOLVE_FWD = 16 CUDSS_PHASE_SOLVE_DIAG = 32 CUDSS_PHASE_SOLVE_BWD = 64 end @cenum cudssStatus_t::UInt32 begin CUDSS_STATUS_SUCCESS = 0 CUDSS_STATUS_NOT_INITIALIZED = 1 CUDSS_STATUS_ALLOC_FAILED = 2 CUDSS_STATUS_INVALID_VALUE = 3 CUDSS_STATUS_NOT_SUPPORTED = 4 CUDSS_STATUS_EXECUTION_FAILED = 5 CUDSS_STATUS_INTERNAL_ERROR = 6 end @cenum cudssMatrixType_t::UInt32 begin CUDSS_MTYPE_GENERAL = 0 CUDSS_MTYPE_SYMMETRIC = 1 CUDSS_MTYPE_HERMITIAN = 2 CUDSS_MTYPE_SPD = 3 CUDSS_MTYPE_HPD = 4 end @cenum cudssMatrixViewType_t::UInt32 begin CUDSS_MVIEW_FULL = 0 CUDSS_MVIEW_LOWER = 1 CUDSS_MVIEW_UPPER = 2 end @cenum cudssIndexBase_t::UInt32 begin CUDSS_BASE_ZERO = 0 CUDSS_BASE_ONE = 1 end @cenum cudssLayout_t::UInt32 begin CUDSS_LAYOUT_COL_MAJOR = 0 CUDSS_LAYOUT_ROW_MAJOR = 1 end @cenum cudssAlgType_t::UInt32 begin CUDSS_ALG_DEFAULT = 0 CUDSS_ALG_1 = 1 CUDSS_ALG_2 = 2 CUDSS_ALG_3 = 3 end @cenum cudssPivotType_t::UInt32 begin CUDSS_PIVOT_COL = 0 CUDSS_PIVOT_ROW = 1 CUDSS_PIVOT_NONE = 2 end @cenum cudssMatrixFormat_t::UInt32 begin CUDSS_MFORMAT_DENSE = 0 CUDSS_MFORMAT_CSR = 1 end struct cudssDeviceMemHandler_t ctx::Ptr{Cvoid} device_alloc::Ptr{Cvoid} device_free::Ptr{Cvoid} name::NTuple{64,Cchar} end @checked function cudssConfigSet(config, param, value, sizeInBytes) initialize_context() @gcsafe_ccall libcudss.cudssConfigSet(config::cudssConfig_t, param::cudssConfigParam_t, value::Ptr{Cvoid}, sizeInBytes::Csize_t)::cudssStatus_t end @checked function cudssConfigGet(config, param, value, sizeInBytes, sizeWritten) initialize_context() @gcsafe_ccall libcudss.cudssConfigGet(config::cudssConfig_t, param::cudssConfigParam_t, value::Ptr{Cvoid}, sizeInBytes::Csize_t, sizeWritten::Ptr{Csize_t})::cudssStatus_t end @checked function cudssDataSet(handle, data, param, value, sizeInBytes) initialize_context() @gcsafe_ccall libcudss.cudssDataSet(handle::cudssHandle_t, data::cudssData_t, param::cudssDataParam_t, value::PtrOrCuPtr{Cvoid}, sizeInBytes::Csize_t)::cudssStatus_t end @checked function cudssDataGet(handle, data, param, value, sizeInBytes, sizeWritten) initialize_context() @gcsafe_ccall libcudss.cudssDataGet(handle::cudssHandle_t, data::cudssData_t, param::cudssDataParam_t, value::PtrOrCuPtr{Cvoid}, sizeInBytes::Csize_t, sizeWritten::Ptr{Csize_t})::cudssStatus_t end @checked function cudssExecute(handle, phase, solverConfig, solverData, inputMatrix, solution, rhs) initialize_context() @gcsafe_ccall libcudss.cudssExecute(handle::cudssHandle_t, phase::cudssPhase_t, solverConfig::cudssConfig_t, solverData::cudssData_t, inputMatrix::cudssMatrix_t, solution::cudssMatrix_t, rhs::cudssMatrix_t)::cudssStatus_t end @checked function cudssSetStream(handle, stream) initialize_context() @gcsafe_ccall libcudss.cudssSetStream(handle::cudssHandle_t, stream::cudaStream_t)::cudssStatus_t end @checked function cudssSetCommLayer(handle, commLibFileName) initialize_context() @gcsafe_ccall libcudss.cudssSetCommLayer(handle::cudssHandle_t, commLibFileName::Cstring)::cudssStatus_t end @checked function cudssConfigCreate(solverConfig) initialize_context() @gcsafe_ccall libcudss.cudssConfigCreate(solverConfig::Ptr{cudssConfig_t})::cudssStatus_t end @checked function cudssConfigDestroy(solverConfig) initialize_context() @gcsafe_ccall libcudss.cudssConfigDestroy(solverConfig::cudssConfig_t)::cudssStatus_t end @checked function cudssDataCreate(handle, solverData) initialize_context() @gcsafe_ccall libcudss.cudssDataCreate(handle::cudssHandle_t, solverData::Ptr{cudssData_t})::cudssStatus_t end @checked function cudssDataDestroy(handle, solverData) initialize_context() @gcsafe_ccall libcudss.cudssDataDestroy(handle::cudssHandle_t, solverData::cudssData_t)::cudssStatus_t end @checked function cudssCreate(handle) initialize_context() @gcsafe_ccall libcudss.cudssCreate(handle::Ptr{cudssHandle_t})::cudssStatus_t end @checked function cudssDestroy(handle) initialize_context() @gcsafe_ccall libcudss.cudssDestroy(handle::cudssHandle_t)::cudssStatus_t end @checked function cudssGetProperty(propertyType, value) @gcsafe_ccall libcudss.cudssGetProperty(propertyType::libraryPropertyType, value::Ptr{Cint})::cudssStatus_t end @checked function cudssMatrixCreateDn(matrix, nrows, ncols, ld, values, valueType, layout) initialize_context() @gcsafe_ccall libcudss.cudssMatrixCreateDn(matrix::Ptr{cudssMatrix_t}, nrows::Int64, ncols::Int64, ld::Int64, values::CuPtr{Cvoid}, valueType::cudaDataType_t, layout::cudssLayout_t)::cudssStatus_t end @checked function cudssMatrixCreateCsr(matrix, nrows, ncols, nnz, rowStart, rowEnd, colIndices, values, indexType, valueType, mtype, mview, indexBase) initialize_context() @gcsafe_ccall libcudss.cudssMatrixCreateCsr(matrix::Ptr{cudssMatrix_t}, nrows::Int64, ncols::Int64, nnz::Int64, rowStart::CuPtr{Cvoid}, rowEnd::CuPtr{Cvoid}, colIndices::CuPtr{Cvoid}, values::CuPtr{Cvoid}, indexType::cudaDataType_t, valueType::cudaDataType_t, mtype::cudssMatrixType_t, mview::cudssMatrixViewType_t, indexBase::cudssIndexBase_t)::cudssStatus_t end @checked function cudssMatrixDestroy(matrix) initialize_context() @gcsafe_ccall libcudss.cudssMatrixDestroy(matrix::cudssMatrix_t)::cudssStatus_t end @checked function cudssMatrixGetDn(matrix, nrows, ncols, ld, values, type, layout) initialize_context() @gcsafe_ccall libcudss.cudssMatrixGetDn(matrix::cudssMatrix_t, nrows::Ptr{Int64}, ncols::Ptr{Int64}, ld::Ptr{Int64}, values::Ptr{CuPtr{Cvoid}}, type::Ptr{cudaDataType_t}, layout::Ptr{cudssLayout_t})::cudssStatus_t end @checked function cudssMatrixGetCsr(matrix, nrows, ncols, nnz, rowStart, rowEnd, colIndices, values, indexType, valueType, mtype, mview, indexBase) initialize_context() @gcsafe_ccall libcudss.cudssMatrixGetCsr(matrix::cudssMatrix_t, nrows::Ptr{Int64}, ncols::Ptr{Int64}, nnz::Ptr{Int64}, rowStart::Ptr{CuPtr{Cvoid}}, rowEnd::Ptr{CuPtr{Cvoid}}, colIndices::Ptr{CuPtr{Cvoid}}, values::Ptr{CuPtr{Cvoid}}, indexType::Ptr{cudaDataType_t}, valueType::Ptr{cudaDataType_t}, mtype::Ptr{cudssMatrixType_t}, mview::Ptr{cudssMatrixViewType_t}, indexBase::Ptr{cudssIndexBase_t})::cudssStatus_t end @checked function cudssMatrixSetValues(matrix, values) initialize_context() @gcsafe_ccall libcudss.cudssMatrixSetValues(matrix::cudssMatrix_t, values::CuPtr{Cvoid})::cudssStatus_t end @checked function cudssMatrixSetCsrPointers(matrix, rowOffsets, rowEnd, colIndices, values) initialize_context() @gcsafe_ccall libcudss.cudssMatrixSetCsrPointers(matrix::cudssMatrix_t, rowOffsets::CuPtr{Cvoid}, rowEnd::CuPtr{Cvoid}, colIndices::CuPtr{Cvoid}, values::CuPtr{Cvoid})::cudssStatus_t end @checked function cudssMatrixGetFormat(matrix, format) initialize_context() @gcsafe_ccall libcudss.cudssMatrixGetFormat(matrix::cudssMatrix_t, format::Ptr{cudssMatrixFormat_t})::cudssStatus_t end @checked function cudssGetDeviceMemHandler(handle, handler) initialize_context() @gcsafe_ccall libcudss.cudssGetDeviceMemHandler(handle::cudssHandle_t, handler::Ptr{cudssDeviceMemHandler_t})::cudssStatus_t end @checked function cudssSetDeviceMemHandler(handle, handler) initialize_context() @gcsafe_ccall libcudss.cudssSetDeviceMemHandler(handle::cudssHandle_t, handler::Ptr{cudssDeviceMemHandler_t})::cudssStatus_t end
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
1785
# cuDSS functions for managing the library function cudssCreate() handle = Ref{cudssHandle_t}() cudssCreate(handle) handle[] end function cudssGetProperty(property::libraryPropertyType) value_ref = Ref{Cint}() cudssGetProperty(property, value_ref) value_ref[] end version() = VersionNumber(cudssGetProperty(CUDA.MAJOR_VERSION), cudssGetProperty(CUDA.MINOR_VERSION), cudssGetProperty(CUDA.PATCH_LEVEL)) ## handles function handle_ctor(ctx) context!(ctx) do cudssCreate() end end function handle_dtor(ctx, handle) context!(ctx; skip_destroyed=true) do cudssDestroy(handle) end end const idle_handles = HandleCache{CuContext,cudssHandle_t}(handle_ctor, handle_dtor) function handle() cuda = CUDA.active_state() # every task maintains library state per device LibraryState = @NamedTuple{handle::cudssHandle_t, stream::CuStream} states = get!(task_local_storage(), :CUDSS) do Dict{CuContext,LibraryState}() end::Dict{CuContext,LibraryState} # get library state @noinline function new_state(cuda) new_handle = pop!(idle_handles, cuda.context) finalizer(current_task()) do task push!(idle_handles, cuda.context, new_handle) end cudssSetStream(new_handle, cuda.stream) (; handle=new_handle, cuda.stream) end state = get!(states, cuda.context) do new_state(cuda) end # update stream @noinline function update_stream(cuda, state) cudssSetStream(state.handle, cuda.stream) (; state.handle, cuda.stream) end if state.stream != cuda.stream states[cuda.context] = state = update_stream(cuda, state) end return state.handle end
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
6767
# cuDSS types const CUDSS_DATA_PARAMETERS = ("info", "lu_nnz", "npivots", "inertia", "perm_reorder_row", "perm_reorder_col", "perm_row", "perm_col", "diag", "user_perm", "hybrid_device_memory_min", "comm") const CUDSS_CONFIG_PARAMETERS = ("reordering_alg", "factorization_alg", "solve_alg", "matching_type", "solve_mode", "ir_n_steps", "ir_tol", "pivot_type", "pivot_threshold", "pivot_epsilon", "max_lu_nnz", "hybrid_mode", "hybrid_device_memory_limit", "use_cuda_register_memory") const CUDSS_TYPES = Dict{String, DataType}( # data type "info" => Cint, "lu_nnz" => Int64, "npivots" => Cint, "inertia" => Tuple{Cint, Cint}, "perm_reorder_row" => Vector{Cint}, "perm_reorder_col" => Vector{Cint}, "perm_row" => Vector{Cint}, "perm_col" => Vector{Cint}, "diag" => Vector{Float64}, "user_perm" => Vector{Cint}, "hybrid_device_memory_min" => Int64, "comm" => Ptr{Cvoid}, # config type "reordering_alg" => cudssAlgType_t, "factorization_alg" => cudssAlgType_t, "solve_alg" => cudssAlgType_t, "matching_type" => Cint, "solve_mode" => Cint, "ir_n_steps" => Cint, "ir_tol" => Float64, "pivot_type" => cudssPivotType_t, "pivot_threshold" => Float64, "pivot_epsilon" => Float64, "max_lu_nnz" => Int64, "hybrid_mode" => Cint, "hybrid_device_memory_limit" => Int64, "use_cuda_register_memory" => Cint ) ## config type function Base.convert(::Type{cudssConfigParam_t}, config::String) if config == "reordering_alg" return CUDSS_CONFIG_REORDERING_ALG elseif config == "factorization_alg" return CUDSS_CONFIG_FACTORIZATION_ALG elseif config == "solve_alg" return CUDSS_CONFIG_SOLVE_ALG elseif config == "matching_type" return CUDSS_CONFIG_MATCHING_TYPE elseif config == "solve_mode" return CUDSS_CONFIG_SOLVE_MODE elseif config == "ir_n_steps" return CUDSS_CONFIG_IR_N_STEPS elseif config == "ir_tol" return CUDSS_CONFIG_IR_TOL elseif config == "pivot_type" return CUDSS_CONFIG_PIVOT_TYPE elseif config == "pivot_threshold" return CUDSS_CONFIG_PIVOT_THRESHOLD elseif config == "pivot_epsilon" return CUDSS_CONFIG_PIVOT_EPSILON elseif config == "max_lu_nnz" return CUDSS_CONFIG_MAX_LU_NNZ elseif config == "hybrid_mode" return CUDSS_CONFIG_HYBRID_MODE elseif config == "hybrid_device_memory_limit" return CUDSS_CONFIG_HYBRID_DEVICE_MEMORY_LIMIT elseif config == "use_cuda_register_memory" return CUDSS_CONFIG_USE_CUDA_REGISTER_MEMORY else throw(ArgumentError("Unknown config parameter $config")) end end ## data type function Base.convert(::Type{cudssDataParam_t}, data::String) if data == "info" return CUDSS_DATA_INFO elseif data == "lu_nnz" return CUDSS_DATA_LU_NNZ elseif data == "npivots" return CUDSS_DATA_NPIVOTS elseif data == "inertia" return CUDSS_DATA_INERTIA elseif data == "perm_reorder_row" return CUDSS_DATA_PERM_REORDER_ROW elseif data == "perm_reorder_col" return CUDSS_DATA_PERM_REORDER_COL elseif data == "perm_row" return CUDSS_DATA_PERM_ROW elseif data == "perm_col" return CUDSS_DATA_PERM_COL elseif data == "diag" return CUDSS_DATA_DIAG elseif data == "user_perm" return CUDSS_DATA_USER_PERM elseif data == "hybrid_device_memory_min" return CUDSS_DATA_HYBRID_DEVICE_MEMORY_MIN elseif data == "comm" return CUDSS_DATA_COMM else throw(ArgumentError("Unknown data parameter $data")) end end ## phase type function Base.convert(::Type{cudssPhase_t}, phase::String) if phase == "analysis" return CUDSS_PHASE_ANALYSIS elseif phase == "factorization" return CUDSS_PHASE_FACTORIZATION elseif phase == "refactorization" return CUDSS_PHASE_REFACTORIZATION elseif phase == "solve" return CUDSS_PHASE_SOLVE elseif phase == "solve_fwd" return CUDSS_PHASE_SOLVE_FWD elseif phase == "solve_diag" return CUDSS_PHASE_SOLVE_DIAG elseif phase == "solve_bwd" return CUDSS_PHASE_SOLVE_BWD else throw(ArgumentError("Unknown phase $phase")) end end ## matrix structure type function Base.convert(::Type{cudssMatrixType_t}, structure::String) if structure == "G" return CUDSS_MTYPE_GENERAL elseif structure == "S" return CUDSS_MTYPE_SYMMETRIC elseif structure == "H" return CUDSS_MTYPE_HERMITIAN elseif structure == "SPD" return CUDSS_MTYPE_SPD elseif structure == "HPD" return CUDSS_MTYPE_HPD else throw(ArgumentError("Unknown structure $structure")) end end ## view type function Base.convert(::Type{cudssMatrixViewType_t}, view::Char) if view == 'F' return CUDSS_MVIEW_FULL elseif view == 'L' return CUDSS_MVIEW_LOWER elseif view == 'U' return CUDSS_MVIEW_UPPER else throw(ArgumentError("Unknown view $view")) end end ## index base function Base.convert(::Type{cudssIndexBase_t}, index::Char) if index == 'Z' return CUDSS_BASE_ZERO elseif index == 'O' return CUDSS_BASE_ONE else throw(ArgumentError("Unknown index $index")) end end ## layout type function Base.convert(::Type{cudssLayout_t}, layout::Char) if layout == 'R' CUDSS_LAYOUT_ROW_MAJOR elseif layout == 'C' CUDSS_LAYOUT_COL_MAJOR else throw(ArgumentError("Unknown layout $layout")) end end ## algorithm type function Base.convert(::Type{cudssAlgType_t}, algorithm::String) if algorithm == "default" CUDSS_ALG_DEFAULT elseif algorithm == "algo1" CUDSS_ALG_1 elseif algorithm == "algo2" CUDSS_ALG_2 elseif algorithm == "algo3" CUDSS_ALG_3 else throw(ArgumentError("Unknown algorithm $algorithm")) end end ## pivot type function Base.convert(::Type{cudssPivotType_t}, pivoting::Char) if pivoting == 'C' return CUDSS_PIVOT_COL elseif pivoting == 'R' return CUDSS_PIVOT_ROW elseif pivoting == 'N' return CUDSS_PIVOT_NONE else throw(ArgumentError("Unknown pivoting $pivoting")) end end # matrix format type function Base.convert(::Type{cudssMatrixFormat_t}, format::Char) if format == 'D' return CUDSS_MFORMAT_DENSE elseif format == 'S' return CUDSS_MFORMAT_CSR else throw(ArgumentError("Unknown format $format")) end end
CUDSS
https://github.com/exanauts/CUDSS.jl.git
[ "MIT" ]
0.3.2
11cb7c9c06435cfadcc6d94d34c07501df32ce55
code
958
using Test, Random using CUDA, CUDA.CUSPARSE using CUDSS using SparseArrays using LinearAlgebra import CUDSS: CUDSS_DATA_PARAMETERS, CUDSS_CONFIG_PARAMETERS @info("CUDSS_INSTALLATION : $(CUDSS.CUDSS_INSTALLATION)") Random.seed!(666) # Random tests are diabolical include("test_cudss.jl") @testset "CUDSS" begin @testset "version" begin cudss_version() end @testset "CudssMatrix" begin cudss_dense() cudss_sparse() end @testset "CudssData" begin # Issue #1 data = CudssData() end @testset "CudssSolver" begin cudss_solver() end @testset "CudssExecution" begin cudss_execution() end @testset "Generic API" begin cudss_generic() end @testset "User permutation" begin user_permutation() end @testset "Iterative refinement" begin iterative_refinement() end @testset "Small matrices" begin small_matrices() end @testset "Hybrid mode" begin hybrid_mode() end end
CUDSS
https://github.com/exanauts/CUDSS.jl.git