Skip to content

Commit

Permalink
Merge pull request #44 from ReactionMechanismGenerator/splines
Browse files Browse the repository at this point in the history
Replace Dierckx with SmoothingSplines
  • Loading branch information
mjohnson541 authored Jul 20, 2020
2 parents 838056a + 7f63ffb commit e62bc9b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 66 deletions.
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ before_install:
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH=$HOME/miniconda/bin:$PATH
#create julia conda enviornment
- conda create -n conda_jl --yes python=2.7 conda
- conda create -n conda_jl --yes python=3.7 conda
- source activate conda_jl
#install used packages
- conda install -c rmg --yes rmg
- conda install -c rmg --yes rdkit
- conda install --yes pydot
- conda install --yes yaml
- conda update --yes conda
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- travis_wait julia -e 'using Pkg; Pkg.clone("https://github.com/ReactionMechanismGenerator/ReactionMechanismSimulator.jl.git");'
- travis_wait julia -e 'using Pkg; Pkg.add(PackageSpec(path="ReactionMechanismSimulator.jl"));'
- travis_wait julia -e 'using Pkg; Pkg.build("ReactionMechanismSimulator"); Pkg.test("ReactionMechanismSimulator"; coverage=true);'
after_success:
- julia -e 'cd(Pkg.dir("ReactionMechanismSimulator")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
Expand Down
50 changes: 22 additions & 28 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ version = "0.0.4"

[[ArrayInterface]]
deps = ["LinearAlgebra", "Requires", "SparseArrays"]
git-tree-sha1 = "0eccdcbe27fd6bd9cba3be31c67bdd435a21e865"
git-tree-sha1 = "066d1e7a9eb4873660791db7f0d8c7902600b81c"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "2.9.1"
version = "2.11.0"

[[AxisAlgorithms]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"]
Expand All @@ -45,22 +45,16 @@ version = "0.4.3"
[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[BinaryProvider]]
deps = ["Libdl", "Logging", "SHA"]
git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.10"

[[CEnum]]
git-tree-sha1 = "215a9aa4a1f23fbd05b92769fdd62559488d70e9"
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
version = "0.4.1"

[[CSV]]
deps = ["CategoricalArrays", "DataFrames", "Dates", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "Tables", "Unicode"]
git-tree-sha1 = "a100a1dd6ab63fc49e79c90dae67e5bc126419ff"
git-tree-sha1 = "f095e44feec53d0ae809714a78c25908d1f370e6"
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
version = "0.7.3"
version = "0.7.4"

[[Calculus]]
deps = ["LinearAlgebra"]
Expand All @@ -82,9 +76,9 @@ version = "0.8.1"

[[ChainRulesCore]]
deps = ["MuladdMacro"]
git-tree-sha1 = "87e289253a5fc690c4860a41bbd427e16576f716"
git-tree-sha1 = "9907341fe861268ddd0fc60be260633756b126a2"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "0.9.3"
version = "0.9.4"

[[ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
Expand Down Expand Up @@ -191,17 +185,11 @@ uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[Dierckx]]
deps = ["BinaryProvider", "Libdl", "Random", "Test"]
git-tree-sha1 = "956bfe5c4f9b794545f6527424fc0294cc5decbe"
uuid = "39dd38d3-220a-591b-8e3c-4c3a8c710a94"
version = "0.4.2"

[[DiffEqBase]]
deps = ["ArrayInterface", "ChainRulesCore", "ConsoleProgressMonitor", "DataStructures", "Distributed", "DocStringExtensions", "FunctionWrappers", "IterativeSolvers", "IteratorInterfaceExtensions", "LabelledArrays", "LinearAlgebra", "Logging", "LoggingExtras", "MuladdMacro", "Parameters", "Printf", "ProgressLogging", "RecipesBase", "RecursiveArrayTools", "RecursiveFactorization", "Requires", "Roots", "SparseArrays", "StaticArrays", "Statistics", "SuiteSparse", "TableTraits", "TerminalLoggers", "TreeViews", "ZygoteRules"]
git-tree-sha1 = "71499ee24ffe00892a9e80cc953fe0421a54b552"
git-tree-sha1 = "7f241c049129a0e765ef449b634990409286ed75"
uuid = "2b5f629d-d688-5b77-993f-72d75c75574e"
version = "6.40.8"
version = "6.40.9"

[[DiffResults]]
deps = ["StaticArrays"]
Expand Down Expand Up @@ -262,15 +250,15 @@ version = "3.3.9+5"

[[FileIO]]
deps = ["Pkg"]
git-tree-sha1 = "202335fd24c2776493e198d6c66a6d910400a895"
git-tree-sha1 = "f354b2087a3b01c1d7152c19f45886c8a036fa5e"
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
version = "1.3.0"
version = "1.4.0"

[[FiniteDiff]]
deps = ["ArrayInterface", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays"]
git-tree-sha1 = "b02b6f6ea2c33f86a444f9cf132c1d1180a66cfd"
git-tree-sha1 = "80becc23db3942d9e5eb8d0d42e725b9c46616f8"
uuid = "6a86dc24-6348-571c-b903-95158fe2bd41"
version = "2.4.1"
version = "2.5.0"

[[FixedPointNumbers]]
git-tree-sha1 = "4aaea64dd0c30ad79037084f8ca2b94348e65eaa"
Expand Down Expand Up @@ -486,9 +474,9 @@ version = "0.4.2"

[[LoopVectorization]]
deps = ["DocStringExtensions", "LinearAlgebra", "OffsetArrays", "SIMDPirates", "SLEEFPirates", "UnPack", "VectorizationBase"]
git-tree-sha1 = "4c002de66221639174e081ec74c156e9013e4afa"
git-tree-sha1 = "8c19b0c629dae1cea52a990d6303d03fe4328795"
uuid = "bdcacae8-1622-11e9-2a5c-532679323890"
version = "0.8.17"
version = "0.8.19"

[[METIS_jll]]
deps = ["Libdl", "Pkg"]
Expand Down Expand Up @@ -720,9 +708,9 @@ version = "0.5.4"

[[SentinelArrays]]
deps = ["Dates", "Random"]
git-tree-sha1 = "41e78a6419de2279b23cc70342c7147dc4c98860"
git-tree-sha1 = "cd9dccb026262a46d5a81ef1ce1e595150b2b8d2"
uuid = "91c51154-3ec4-41a3-a24f-3f23e20d615c"
version = "1.2.8"
version = "1.2.9"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Expand All @@ -737,6 +725,12 @@ git-tree-sha1 = "2ee666b24ab8be6a922f9d6c11a86e1a703a7dda"
uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
version = "0.9.2"

[[SmoothingSplines]]
deps = ["LinearAlgebra", "Random", "Reexport", "StatsBase", "Test"]
git-tree-sha1 = "9e47150ea38107ba762fb26bd5c2a000b27ecf94"
uuid = "102930c3-cf33-599f-b3b1-9a29a5acab30"
version = "0.2.1"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

Expand Down
42 changes: 21 additions & 21 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name = "ReactionMechanismSimulator"
uuid = "c2d78dd2-25c4-5b79-bebc-be6c69dd440f"
authors = ["Matt Johnson <[email protected]>"]
version = "0.2.0"
version = "0.2.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
Expand All @@ -18,6 +17,7 @@ Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
QuartzImageIO = "dca85d43-d64c-5e67-8c65-017450d5d020"
SmoothingSplines = "102930c3-cf33-599f-b3b1-9a29a5acab30"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Expand All @@ -27,22 +27,22 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
julia = "^1.0.0"
CSV = "^0.7.3"
Calculus = "^0.5.1"
Colors = "^0.12.3"
Dierckx = "^0.4.2"
DiffEqBase = "^6.40.8"
ForwardDiff = "^0.10.12"
Images = "^0.22.4"
IterTools = "^1.3.0"
OrdinaryDiffEq = "^5.41.0"
Parameters = "^0.12.1"
PyCall = "^1.91.4"
PyPlot = "^2.9.0"
QuartzImageIO = "^0.7.1"
SpecialFunctions = "^0.10.3"
StaticArrays = "^0.12.4"
Sundials = "^4.2.5"
Unitful = "^1.3.0"
YAML = "^0.4.0"
CSV = "<1"
Calculus = "<1"
Colors = "<1"
DiffEqBase = "6.6.0"
ForwardDiff = "<1"
Images = "<1"
IterTools = "1.3.0"
OrdinaryDiffEq = "<6"
Parameters = "<1"
PyCall = "1.91.4"
PyPlot = "2.9.0"
QuartzImageIO = "<1"
SmoothingSplines = "<1"
SpecialFunctions = "<1"
StaticArrays = "<1"
Sundials = "<5"
Unitful = "1.3.0"
YAML = "<1"
julia = "1"
26 changes: 15 additions & 11 deletions src/Domain.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Parameters
using LinearAlgebra
using StaticArrays
using Dierckx
using Calculus
using SmoothingSplines

abstract type AbstractDomain end
export AbstractDomain
Expand Down Expand Up @@ -263,16 +263,14 @@ function ParametrizedTPDomain(;phase::Z,initialconds::Dict{X,Any},constantspecie
end
@assert V != 0.0 || (T != 0.0 && P != 0.0)
if isa(T,AbstractArray)
q = Spline1D(ts,T;k=3,s=1e-11)
Tfcn(x::Float64) = q(x)
Tfcn = getspline(ts,T)
elseif isa(T,Function)
Tfcn = T
else
throw(error("ParametrizedTPDomain must take \"T\" as a function or if an array of times for \"ts\" is supplied as an array of volumes"))
end
if isa(P,AbstractArray)
v = Spline1D(ts,P;k=3,s=1e-11)
Pfcn(x::Float64) = v(x)
Pfcn = getspline(ts,P)
elseif isa(P,Function)
Pfcn = P
else
Expand Down Expand Up @@ -346,8 +344,7 @@ function ParametrizedVDomain(;phase::Z,initialconds::Dict{X,Any},constantspecies
end
@assert isa(V,Function) || isa(V,AbstractArray)
if isa(V,AbstractArray)
q = Spline1D(ts,V;k=3,s=1e-11)
Vfcn = f(x::Float64) = q(x)
Vfcn = getspline(ts,V)
elseif isa(V,Function)
Vfcn = V
else
Expand Down Expand Up @@ -422,8 +419,7 @@ function ParametrizedPDomain(;phase::Z,initialconds::Dict{X,Any},constantspecies
end
@assert isa(P,Function) || isa(P,AbstractArray)
if isa(P,AbstractArray)
q = Spline1D(ts,P;k=3,s=1e-11)
Pfcn = f(x::Float64) = q(x)
Pfcn = getspline(ts,P)
elseif isa(P,Function)
Pfcn = P
else
Expand Down Expand Up @@ -577,8 +573,7 @@ function ParametrizedTConstantVDomain(;phase::IdealDiluteSolution,initialconds::
end
end
if isa(T,AbstractArray)
q = Spline1D(ts,T;k=3,s=1e-11)
Tfcn = f(x::Float64) = q(x)
Tfcn = getspline(ts,T)
elseif isa(T,Function)
Tfcn = T
else
Expand Down Expand Up @@ -943,3 +938,12 @@ function getreactionindices(ig::Q) where {Q<:AbstractPhase}
return arr
end
export getreactionindices

"""
fit a cubic spline to data and return a function evaluating that spline
"""
function getspline(xs,vals;s=1e-10)
smspl = fit(SmoothingSpline,xs,vals,s)
F(x::T) where {T} = predict(smspl,x)
return F
end

0 comments on commit e62bc9b

Please sign in to comment.