From c8f7794d418dbc97b827f738a69d3a9d4b6f5784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Fri, 13 Mar 2026 14:31:48 +0100 Subject: [PATCH 1/2] added test for themal laws --- src/PhysicalModels/ThermoMechanicalModels.jl | 2 +- src/TensorAlgebra/Functions.jl | 2 +- test/TestConstitutiveModels/ThermalLawsTests.jl | 12 ++++++++++++ test/TestConstitutiveModels/runtests.jl | 4 ++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/TestConstitutiveModels/ThermalLawsTests.jl 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..7b48970 --- /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-3) + 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 From 8dc8eda10b3af0bf67cbed123a15d097288bda69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Fri, 13 Mar 2026 14:33:37 +0100 Subject: [PATCH 2/2] better tolerance --- test/TestConstitutiveModels/ThermalLawsTests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TestConstitutiveModels/ThermalLawsTests.jl b/test/TestConstitutiveModels/ThermalLawsTests.jl index 7b48970..cfaba98 100644 --- a/test/TestConstitutiveModels/ThermalLawsTests.jl +++ b/test/TestConstitutiveModels/ThermalLawsTests.jl @@ -7,6 +7,6 @@ using Test 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-3) + @test isapprox(ddf(θ), ForwardDiff.derivative(df, θ), rtol=1e-10) end end