From 66eb37d82ae7cc36e63723b8f114f227227f06f4 Mon Sep 17 00:00:00 2001 From: Tero Frondelius Date: Fri, 18 Oct 2019 20:15:36 +0300 Subject: [PATCH] Adding uniaxial_increment! testing to ensure Materials.jl compatibility. --- test/runtests.jl | 7 ++++- test/test_show_methods.jl | 37 ++++++++++++------------ test/test_vonmises_uniaxial.jl | 51 ++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 test/test_vonmises_uniaxial.jl diff --git a/test/runtests.jl b/test/runtests.jl index 174df84..ec73cc4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -14,7 +14,8 @@ eps = 1.e-12 include("test_binary_dependencies.jl") if Sys.islinux() @testset "Norton model" begin include("test_norton_model.jl") end - include("test_show_methods.jl") + + @testset "show methods" begin include("test_show_methods.jl") end @testset "test MFront ideal plastic material model" begin include("test_isotropic_linear_hardening_plasticity.jl") @@ -30,6 +31,10 @@ eps = 1.e-12 @testset "test MFront together with JuAFEM" begin include("test_mfront_juafem_3dbeam.jl") + + @testset "test plasticity with uniaxial_increment!" begin + include("test_vonmises_uniaxial.jl") + end end end end diff --git a/test/test_show_methods.jl b/test/test_show_methods.jl index 816fe85..1803f96 100644 --- a/test/test_show_methods.jl +++ b/test/test_show_methods.jl @@ -1,20 +1,23 @@ -@testset "show methods" begin - b = load("test_show_methods/libBehaviour.so","Norton",mbv.Tridimensional) - BehaviourAllocated_out = @capture_out show(b) - BehaviourAllocated_expected = "behaviour Norton in shared library test_show_methods/libBehaviour.so for modelling hypothesis Tridimensional generated from Norton.mfront using TFEL version: 3.3.0-dev." - @test BehaviourAllocated_out == BehaviourAllocated_expected +using MFrontInterface +using DelimitedFiles +using Suppressor +using Test - 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 +b = load("test_show_methods/libBehaviour.so","Norton",mbv.Tridimensional) +BehaviourAllocated_out = @capture_out show(b) +BehaviourAllocated_expected = "behaviour Norton in shared library test_show_methods/libBehaviour.so for modelling hypothesis Tridimensional generated from Norton.mfront using TFEL version: 3.3.0-dev." +@test BehaviourAllocated_out == BehaviourAllocated_expected - 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 +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 - set_external_state_variable!(get_final_state(d), "Temperature", 293.15) - VariablesVectorAllocated_out = @capture_out show(get_external_state_variables(b)) - VariablesVectorAllocated_expected = "1-element VariablesVector\n Temperature\n" - @test VariablesVectorAllocated_expected == VariablesVectorAllocated_out -end +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 + +set_external_state_variable!(get_final_state(d), "Temperature", 293.15) +VariablesVectorAllocated_out = @capture_out show(get_external_state_variables(b)) +VariablesVectorAllocated_expected = "1-element VariablesVector\n Temperature\n" +@test VariablesVectorAllocated_expected == VariablesVectorAllocated_out diff --git a/test/test_vonmises_uniaxial.jl b/test/test_vonmises_uniaxial.jl new file mode 100644 index 0000000..d344b63 --- /dev/null +++ b/test/test_vonmises_uniaxial.jl @@ -0,0 +1,51 @@ +using MFrontInterface +using Materials +using DelimitedFiles +using Suppressor +using Tensors +using Test + +dtime = 0.25 +mgis_bv = MFrontInterface.behaviour + +function MaterialTest() + lib_path = "test_plasticity/libBehaviour.so" + behaviour_name = "IsotropicLinearHardeningPlasticity" + hypothesis = mgis_bv.Tridimensional + + behaviour = load(lib_path, behaviour_name, hypothesis) + behaviour_data = BehaviourData(behaviour) + + ext_variable_names = [mgis_bv.get_name(mgis_bv.get_external_state_variables(behaviour)[i]) for i in 1:mgis_bv.length(mgis_bv.get_external_state_variables(behaviour))] + ext_variable_values = zeros(length(ext_variable_names)) + ext_vatiable_state = MFrontExternalVariableState(names=ext_variable_names, values=ext_variable_values) + + return MFrontMaterial(behaviour=behaviour, behaviour_data=behaviour_data, external_variables=ext_vatiable_state) +end + +mat = MaterialTest() + +times = [mat.drivers.time] +stresses = [copy(tovoigt(mat.variables.stress))] +stresses_expected = [[50.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [100.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [150.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [100.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [-100.0, 0.0, 0.0, 0.0, 0.0, 0.0]] +dstrain11 = 1e-9*dtime +strains_expected = [[dstrain11, -0.3*dstrain11, -0.3*dstrain11, 0.0, 0.0, 0.0], + [2*dstrain11, -0.3*dstrain11*2, -0.3*dstrain11*2, 0.0, 0.0, 0.0], + [3*dstrain11, -0.3*dstrain11*2 - 0.3*dstrain11, -0.3*dstrain11*2 - 0.3*dstrain11, 0.0, 0.0, 0.0], + [2*dstrain11, -0.3*dstrain11 - 0.3*dstrain11, -0.3*dstrain11 - 0.3*dstrain11, 0.0, 0.0, 0.0], + [-2*dstrain11, 0.3*dstrain11*2, 0.3*dstrain11*2, 0.0, 0.0, 0.0]] +dtimes = [dtime, dtime, dtime, dtime, 1.0] +dstrains11 = [dstrain11, dstrain11, dstrain11, -dstrain11, -4*dstrain11] +for i in 1:length(dtimes) + dstrain11 = dstrains11[i] + dtime = dtimes[i] + uniaxial_increment!(mat, dstrain11, dtime) + update_material!(mat) + @test isapprox(tovoigt(mat.variables.stress), stresses_expected[i]) + #@info(tovoigt(mat.drivers.strain; offdiagscale=2.0), strains_expected[i]) + @test isapprox(tovoigt(mat.drivers.strain; offdiagscale=2.0), strains_expected[i]) +end