diff --git a/src/PhysicalModels/ThermoMechanicalModels.jl b/src/PhysicalModels/ThermoMechanicalModels.jl index dc0dcc6..19a3460 100644 --- a/src/PhysicalModels/ThermoMechanicalModels.jl +++ b/src/PhysicalModels/ThermoMechanicalModels.jl @@ -146,7 +146,7 @@ end function derivatives(law::LogisticLaw) @unpack θr, μ, σ = law z(x) = (log(x) - μ) / σ - std_pdf(x) = 1/σ/sqrt(2 * π) * exp(-z(x)^2 / 2) + std_pdf(x) = 1/(σ*sqrt(2 * π)) * exp(-z(x)^2 / 2) std_cdf(x) = 0.5 * (1 + erf(z(x) / sqrt(2))) ξR = 1 / (1-std_cdf(θr)) f(θ) = ξR * (1-std_cdf(θ)) diff --git a/src/TensorAlgebra/Functions.jl b/src/TensorAlgebra/Functions.jl index fb8f2f6..013b29c 100644 --- a/src/TensorAlgebra/Functions.jl +++ b/src/TensorAlgebra/Functions.jl @@ -25,7 +25,7 @@ end """ Fast and dependency-free implementation of erf function, up to 1e-6 precision. """ -@inline function erf(x::Float64) +@inline function erf(x::Real) p = 0.3275911 a1 = 0.254829592 a2 = -0.284496736 diff --git a/test/TestConstitutiveModels/ThermalLawsTests.jl b/test/TestConstitutiveModels/ThermalLawsTests.jl new file mode 100644 index 0000000..cfaba98 --- /dev/null +++ b/test/TestConstitutiveModels/ThermalLawsTests.jl @@ -0,0 +1,12 @@ +using ForwardDiff +using HyperFEM +using Test + +@testset "LogisticLaw" begin + law = LogisticLaw(273.15, log(300.1), 0.11) + f, df, ddf = derivatives(law) + for θ ∈ 200.0:50:400 # NOTE: The numerical derivative of erf is a bad approximation, while the analyitical function uses the exact value. + @test isapprox(df(θ), ForwardDiff.derivative(f, θ), rtol=1e-3) + @test isapprox(ddf(θ), ForwardDiff.derivative(df, θ), rtol=1e-10) + end +end diff --git a/test/TestConstitutiveModels/runtests.jl b/test/TestConstitutiveModels/runtests.jl index 9ee4e75..9e06622 100644 --- a/test/TestConstitutiveModels/runtests.jl +++ b/test/TestConstitutiveModels/runtests.jl @@ -15,4 +15,8 @@ using Test include("ElectroMechanicalTests.jl") end + @time begin + include("ThermalLawsTests.jl") + end + end