Skip to content

Commit

Permalink
Merge a7e07c5 into 4accd44
Browse files Browse the repository at this point in the history
  • Loading branch information
TeroFrondelius committed Aug 27, 2019
2 parents 4accd44 + a7e07c5 commit 30169ef
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"

[targets]
test = ["Test"]
test = ["Test", "Suppressor"]
47 changes: 45 additions & 2 deletions src/MFrontInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,55 @@ end
export load, BehaviourData, get_variable_offset, get_internal_state_variables
export get_hypothesis, set_time_increment!, set_external_state_variable!
export get_final_state, update, get_gradients, get_initial_state, integrate
export get_initial_state
export get_initial_state, get_parameters

function Base.show(io::IO,m::BehaviourAllocated)
print(io, "behaviour ", get_behaviour(m))
print(io, " in shared library Behaviour for modelling hypothesis ")
print(io, toString(get_hypothesis(m)))
print(io, " generated from ", get_source(m), " using TFEL version: ")
print(io, get_tfel_version(m), ".")
end

function Base.iterate(iter::RealsVectorRef, state=(1, 1))
element, count = state
if count > length(iter)
return nothing
end
return (iter[element], (element + 1, count + 1))
end

function Base.show(io::IO, m::RealsVectorRef)
println(io, length(m),"-element RealsVector")
for i in m
println(io, " ", i)
end
end

function Base.iterate(iter::StringsVectorAllocated, state=(1, 1))
element, count = state
if count > length(iter)
return nothing
end
return (iter[element], (element + 1, count + 1))
end

function Base.show(io::IO, m::StringsVectorAllocated)
println(io, length(m),"-element StringsVector")
for i in m
println(io, " ", i)
end
end

# function Base.show(io::IO,m::BehaviourDataAllocated)
# print(io, "Behaviour Data ")
# end

end # module behaviour
# Re-exporting behaviour model functions
using .behaviour
export load, BehaviourData, get_variable_offset, get_internal_state_variables
export get_hypothesis, set_time_increment!, set_external_state_variable!
export get_final_state, update, get_gradients, get_initial_state, integrate
export get_initial_state
export get_initial_state, get_parameters
end # module MFront`
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MFrontInterface
using DelimitedFiles
using Suppressor
using Test
lpath = MFrontInterface.lpath

Expand All @@ -13,5 +14,6 @@ eps = 1.e-12
include("test_binary_dependencies.jl")
if Sys.islinux()
include("test_norton_model.jl")
include("test_show_methods.jl")
end
end
16 changes: 16 additions & 0 deletions test/test_show_methods.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@testset "show methods" begin
b = load("data/libBehaviour.so","Norton",mbv.Tridimensional)
BehaviourAllocated_out = @capture_out show(b)
BehaviourAllocated_expected = "behaviour Norton in shared library Behaviour for modelling hypothesis Tridimensional generated from Norton.mfront using TFEL version: 3.3.0-dev."
@test BehaviourAllocated_out == BehaviourAllocated_expected

d = BehaviourData(b)
RealsVectorRef_out = @capture_out show(get_internal_state_variables(get_initial_state(d)))
RealsVectorRef_expected = "7-element RealsVector\n 0.0\n 0.0\n 0.0\n 0.0\n 0.0\n 0.0\n 0.0\n"
@test RealsVectorRef_expected == RealsVectorRef_out

StringsVectorAllocated_out = @capture_out show(get_parameters(b))
StringsVectorAllocated_expected = "11-element StringsVector\n epsilon\n YoungModulus\n PoissonRatio\n RelativeValueForTheEquivalentStressLowerBoundDefinition\n K\n E\n A\n minimal_time_step_scaling_factor\n maximal_time_step_scaling_factor\n theta\n numerical_jacobian_epsilon\n"
@test StringsVectorAllocated_expected == StringsVectorAllocated_out

end

0 comments on commit 30169ef

Please sign in to comment.