From 98e874fd89662d5ef720cc9be38813f77b76d679 Mon Sep 17 00:00:00 2001 From: hess_ja Date: Wed, 20 Nov 2024 15:06:28 +0100 Subject: [PATCH] fixed tests --- src/Compute/compute_global_values.jl | 6 +- src/Core/BC_manager.jl | 23 +++++--- src/Core/Solver/Verlet.jl | 44 ++++++++------ src/Core/data_manager.jl | 58 ++++++++++++------- src/IO/IO.jl | 41 ++++++++----- src/IO/exodus_export.jl | 2 +- src/Models/Additive/simple_additive.jl | 2 +- .../Pre_calculation/bond_deformation.jl | 1 + .../Parameters/parameter_handling_output.jl | 8 +-- src/Support/helpers.jl | 2 +- test/runtests.jl | 2 +- test/unit_tests/Core/ut_BC_manager.jl | 25 ++++---- test/unit_tests/Core/ut_data_manager.jl | 32 +++++----- test/unit_tests/IO/ut_IO.jl | 12 ++-- test/unit_tests/IO/ut_exodus_export.jl | 35 +++++++---- .../Parameters/ut_parameter_handling.jl | 42 ++++++++------ 16 files changed, 199 insertions(+), 136 deletions(-) diff --git a/src/Compute/compute_global_values.jl b/src/Compute/compute_global_values.jl index 0493742c0..e253888f0 100644 --- a/src/Compute/compute_global_values.jl +++ b/src/Compute/compute_global_values.jl @@ -27,13 +27,15 @@ function calculate_nodelist( # get block_nodes # check NP1 if datamanager.has_key(field_key * "NP1") - field_key *= "NP1" + field = datamanager.get_field(field_key, "NP1") + field_key = field_key * "NP1" + else + field = datamanager.get_field(field_key) end if !datamanager.has_key(field_key) @error "Field $field_key does not exists for compute sum." return nothing end - field = datamanager.get_field(field_key) field_type = datamanager.get_field_type(field_key) if calculation_type == "Sum" diff --git a/src/Core/BC_manager.jl b/src/Core/BC_manager.jl index 0ab91130a..4cb65879f 100644 --- a/src/Core/BC_manager.jl +++ b/src/Core/BC_manager.jl @@ -40,12 +40,17 @@ function check_valid_bcs(bcs::Dict{String,Any}, datamanager::Module) end for data_entry in datamanager.get_all_field_keys() - if (occursin(bcs[bc]["Variable"], data_entry) && occursin("NP1", data_entry)) || - bcs[bc]["Variable"] == data_entry - bcs[bc]["Initial"] = bcs[bc]["Type"] == "Initial" + if (occursin(bcs[bc]["Variable"], data_entry) && occursin("NP1", data_entry)) + bcs[bc]["Time"] = "NP1" + valid = true + elseif bcs[bc]["Variable"] == data_entry bcs[bc]["Variable"] = data_entry - working_bcs[bc] = bcs[bc] + bcs[bc]["Time"] = "constant" valid = true + end + if valid + bcs[bc]["Initial"] = bcs[bc]["Type"] == "Initial" + working_bcs[bc] = bcs[bc] break end end @@ -134,11 +139,11 @@ function apply_bc_dirichlet(bcs::Dict, datamanager::Module, time::Float64) for name in keys(bcs) bc = bcs[name] if !(bc["Type"] in ["Initial", "Dirichlet"]) || - bc["Variable"] == "Force DensitiesNP1" || - bc["Variable"] == "ForcesNP1" + bc["Variable"] == "Force Densities" || + bc["Variable"] == "Forces" continue end - field = datamanager.get_field(bc["Variable"]) + field = datamanager.get_field(bc["Variable"], bc["Time"]) if ndims(field) > 1 if haskey(dof_mapping, bc["Coordinate"]) @@ -195,9 +200,9 @@ function apply_bc_dirichlet_force(bcs::Dict, datamanager::Module, time::Float64) if bc["Type"] != "Dirichlet" continue end - if bc["Variable"] == "ForcesNP1" + if bc["Variable"] == "Forces" field = datamanager.get_field("External Forces") - elseif bc["Variable"] == "Force DensitiesNP1" + elseif bc["Variable"] == "Force Densities" field = datamanager.get_field("External Force Densities") else continue diff --git a/src/Core/Solver/Verlet.jl b/src/Core/Solver/Verlet.jl index 545a53ebf..b45f9e372 100644 --- a/src/Core/Solver/Verlet.jl +++ b/src/Core/Solver/Verlet.jl @@ -421,35 +421,19 @@ function run_solver( active_list = datamanager.get_field("Active") density = datamanager.get_field("Density") coor = datamanager.get_field("Coordinates") - uNP1 = datamanager.get_field("Displacements", "NP1") # index = datamanager.get_field("Index") comm = datamanager.get_comm() - deformed_coorNP1 = datamanager.get_field("Deformed Coordinates", "NP1") if "Material" in solver_options["Models"] - forces = datamanager.get_field("Forces", "NP1") external_forces = datamanager.get_field("External Forces") - force_densities = datamanager.get_field("Force Densities", "NP1") external_force_densities = datamanager.get_field("External Force Densities") - uN = datamanager.get_field("Displacements", "N") - vN = datamanager.get_field("Velocity", "N") - vNP1 = datamanager.get_field("Velocity", "NP1") a = datamanager.get_field("Acceleration") - deformed_coorN = datamanager.get_field("Deformed Coordinates", "N") end if "Thermal" in solver_options["Models"] - flowN = datamanager.get_field("Heat Flow", "N") - flowNP1 = datamanager.get_field("Heat Flow", "NP1") - temperatureN = datamanager.get_field("Temperature", "N") - temperatureNP1 = datamanager.get_field("Temperature", "NP1") deltaT = datamanager.get_field("Delta Temperature") heat_capacity = datamanager.get_field("Specific Heat Capacity") end if "Corrosion" in solver_options["Models"] - concentrationN = datamanager.get_field("Concentration", "N") - concentrationNP1 = datamanager.get_field("Concentration", "NP1") - concentration_fluxN = datamanager.get_field("Concentration Flux", "N") - concentration_fluxNP1 = datamanager.get_field("Concentration Flux", "NP1") ## TODO field creation not in run delta_concentration = datamanager.create_constant_node_field("Delta Concentration", Float64, 1) @@ -460,9 +444,6 @@ function run_solver( lumped_mass = datamanager.get_field("Lumped Mass Matrix") fe_nodes = datamanager.get_field("FE Nodes") end - if "Damage" in solver_options["Models"] - damage = datamanager.get_damage("NP1") - end active = datamanager.get_field("Active") dt::Float64 = solver_options["dt"] @@ -478,6 +459,31 @@ function run_solver( #nodes::Vector{Int64} = Vector{Int64}(1:datamanager.get_nnodes()) @inbounds @fastmath for idt in iter @timeit to "Verlet" begin + uNP1 = datamanager.get_field("Displacements", "NP1") + deformed_coorNP1 = datamanager.get_field("Deformed Coordinates", "NP1") + if "Material" in solver_options["Models"] + forces = datamanager.get_field("Forces", "NP1") + force_densities = datamanager.get_field("Force Densities", "NP1") + uN = datamanager.get_field("Displacements", "N") + vN = datamanager.get_field("Velocity", "N") + vNP1 = datamanager.get_field("Velocity", "NP1") + deformed_coorN = datamanager.get_field("Deformed Coordinates", "N") + end + if "Thermal" in solver_options["Models"] + flowN = datamanager.get_field("Heat Flow", "N") + flowNP1 = datamanager.get_field("Heat Flow", "NP1") + temperatureN = datamanager.get_field("Temperature", "N") + temperatureNP1 = datamanager.get_field("Temperature", "NP1") + end + if "Corrosion" in solver_options["Models"] + concentrationN = datamanager.get_field("Concentration", "N") + concentrationNP1 = datamanager.get_field("Concentration", "NP1") + concentration_fluxN = datamanager.get_field("Concentration Flux", "N") + concentration_fluxNP1 = datamanager.get_field("Concentration Flux", "NP1") + end + if "Damage" in solver_options["Models"] + damage = datamanager.get_damage("NP1") + end active_nodes = datamanager.get_field("Active Nodes") active_nodes = find_active_nodes(active_list, active_nodes, 1:datamanager.get_nnodes()) diff --git a/src/Core/data_manager.jl b/src/Core/data_manager.jl index 244211039..47e52575b 100644 --- a/src/Core/data_manager.jl +++ b/src/Core/data_manager.jl @@ -443,10 +443,10 @@ function create_field( VectorOrArray::String = "Vector", ) if has_key(name) - if size(get_field(name), 1) != data["nnodes"] + if size(_get_field(name), 1) != data["nnodes"] @warn "Field $name exists already with different size. Predefined field is returned" end - return get_field(name) + return _get_field(name) end value = vartype(default_value) if bond_or_node == "Node_Field" @@ -461,7 +461,7 @@ function create_field( end end elseif bond_or_node == "Bond_Field" - nBonds = get_field("Number of Neighbors") + nBonds = _get_field("Number of Neighbors") if dof == 1 fields[vartype][name] = [fill(value, n) for n in nBonds] else @@ -473,7 +473,7 @@ function create_field( end end elseif bond_or_node == "Element_Field" - nElements = get_field("Number of Element Neighbors") + nElements = _get_field("Number of Element Neighbors") if dof == 1 fields[vartype][name] = [fill(value, n) for n in nElements] else @@ -581,22 +581,36 @@ Returns the field with the given name and time. # Returns - `field::Field`: The field with the given name and time. """ -function get_field(name::String, time::String) - - try - if time == "N" - return get_field(data["NP1_to_N"][name][1]) - else - return get_field(data["NP1_to_N"][name][2]) +function get_field(name::String, time::String = "constant") + + if time == "constant" + return _get_field(name) + elseif time == "N" + try + return _get_field(data["NP1_to_N"][name][1]) + catch + @error "Field ''" * + name * + "'' does not exist. Check if it is initialized as constant." + return nothing end - catch - @error "Field $name does not exist. Check if it is initialized as constant." + elseif time == "NP1" + try + return _get_field(data["NP1_to_N"][name][2]) + catch + @error "Field ''" * + name * + "'' does not exist. Check if it is initialized as constant." + return nothing + end + else + @error "Time $time is not supported. Use 'constant', 'N', or 'NP1'" return nothing end end """ - get_field(name::String) + _get_field(name::String) Returns the field with the given name. @@ -605,7 +619,7 @@ Returns the field with the given name. # Returns - `field::Field`: The field with the given name. """ -function get_field(name::String) +function _get_field(name::String) try return data["field_array_type"][name]["get_function"]() catch @@ -705,7 +719,7 @@ end Get the neighborhood list. """ function get_nlist() - return get_field("Neighborhoodlist") + return _get_field("Neighborhoodlist") end """ @@ -717,7 +731,7 @@ function get_filtered_nlist() if !has_key("FilteredNeighborhoodlist") return nothing end - return get_field("FilteredNeighborhoodlist") + return _get_field("FilteredNeighborhoodlist") end """ @@ -1481,7 +1495,7 @@ Sets the synchronization dictionary globally. """ function set_synch(name, download_from_cores, upload_to_cores, dof = 0) if name in get_all_field_keys() - field = get_field(name) + field = _get_field(name) if dof == 0 dof = length(field[1, :, :]) end @@ -1491,7 +1505,7 @@ function set_synch(name, download_from_cores, upload_to_cores, dof = 0) "dof" => dof, ) elseif name * "NP1" in get_all_field_keys() - field = get_field(name * "NP1") + field = get_field(name, "NP1") if dof == 0 dof = length(field[1, :, :]) end @@ -1521,7 +1535,7 @@ function set_local_synch(model, name, download_from_cores, upload_to_cores, dof return nothing end if name in get_all_field_keys() - field = get_field(name) + field = _get_field(name) if dof == 0 dof = length(field[1, :, :]) end @@ -1531,7 +1545,7 @@ function set_local_synch(model, name, download_from_cores, upload_to_cores, dof "dof" => dof, ) elseif name * "NP1" in get_all_field_keys() - field = get_field(name * "NP1") + field = get_field(name, "NP1") if dof == 0 dof = length(field[1, :, :]) end @@ -1550,7 +1564,7 @@ end Switches the fields from NP1 to N.active """ function switch_NP1_to_N() - active = get_field("Active") + active = _get_field("Active") for key in keys(data["NP1_to_N"]) data["NP1_to_N"][key][1], data["NP1_to_N"][key][2] = data["NP1_to_N"][key][2], data["NP1_to_N"][key][1] diff --git a/src/IO/IO.jl b/src/IO/IO.jl index 84eefd948..b92bbf47c 100644 --- a/src/IO/IO.jl +++ b/src/IO/IO.jl @@ -218,8 +218,9 @@ function get_results_mapping(params::Dict, path::String, datamanager::Module) nodeset = [] for key in keys(computes) - if fieldname == key - fieldname = computes[key]["Variable"] + if fieldname[1] == key + fieldname[1] = computes[key]["Variable"] + fieldname[2] = "constant" compute_name = string(key) compute_params = computes[key] global_var = true @@ -230,18 +231,19 @@ function get_results_mapping(params::Dict, path::String, datamanager::Module) end # end - datafield = datamanager.get_field(fieldname) + datafield = datamanager.get_field(fieldname[1], fieldname[2]) sizedatafield = size(datafield) if length(sizedatafield) == 0 @error "No field " * fieldname * " exists." return nothing end - if fieldname == "State Variables" + if fieldname[1] == "State Variables" nstatev = length(sizedatafield) == 1 ? 1 : sizedatafield[2] for dof = 1:nstatev output_mapping[id]["Fields"]["State_Variable_"*string(dof)] = Dict( - "fieldname" => fieldname, + "fieldname" => fieldname[1], + "time" => fieldname[2], "global_var" => global_var, "dof" => dof, "type" => typeof(datafield[1, 1]), @@ -253,7 +255,8 @@ function get_results_mapping(params::Dict, path::String, datamanager::Module) if length(sizedatafield) == 1 if global_var output_mapping[id]["Fields"][compute_name] = Dict( - "fieldname" => fieldname, + "fieldname" => fieldname[1], + "time" => fieldname[2], "global_var" => global_var, "dof" => 1, "type" => typeof(datafield[1, 1]), @@ -261,8 +264,9 @@ function get_results_mapping(params::Dict, path::String, datamanager::Module) "nodeset" => nodeset, ) else - output_mapping[id]["Fields"][clearNP1(fieldname)] = Dict( - "fieldname" => fieldname, + output_mapping[id]["Fields"][fieldname[1]] = Dict( + "fieldname" => fieldname[1], + "time" => fieldname[2], "global_var" => global_var, "dof" => 1, "type" => typeof(datafield[1, 1]), @@ -276,7 +280,8 @@ function get_results_mapping(params::Dict, path::String, datamanager::Module) dof, i_ref_dof, )] = Dict( - "fieldname" => fieldname, + "fieldname" => fieldname[1], + "time" => fieldname[2], "global_var" => global_var, "dof" => dof, "type" => typeof(datafield[1, 1]), @@ -284,10 +289,12 @@ function get_results_mapping(params::Dict, path::String, datamanager::Module) "nodeset" => nodeset, ) else - output_mapping[id]["Fields"][clearNP1( - fieldname, - )*get_paraview_coordinates(dof, i_ref_dof)] = Dict( - "fieldname" => fieldname, + output_mapping[id]["Fields"][fieldname[1]*get_paraview_coordinates( + dof, + i_ref_dof, + )] = Dict( + "fieldname" => fieldname[1], + "time" => fieldname[2], "global_var" => global_var, "dof" => dof, "type" => typeof(datafield[1, 1]), @@ -304,7 +311,8 @@ function get_results_mapping(params::Dict, path::String, datamanager::Module) i_dof, i_ref_dof, )*get_paraview_coordinates(j_dof, j_ref_dof)] = Dict( - "fieldname" => fieldname, + "fieldname" => fieldname[1], + "time" => fieldname[2], "global_var" => global_var, "i_dof" => i_dof, "j_dof" => j_dof, @@ -313,11 +321,12 @@ function get_results_mapping(params::Dict, path::String, datamanager::Module) "nodeset" => nodeset, ) else - output_mapping[id]["Fields"][clearNP1(fieldname)*get_paraview_coordinates( + output_mapping[id]["Fields"][fieldname[1]*get_paraview_coordinates( i_dof, i_ref_dof, )*get_paraview_coordinates(j_dof, j_ref_dof)] = Dict( - "fieldname" => fieldname, + "fieldname" => fieldname[1], + "time" => fieldname[2], "global_var" => global_var, "i_dof" => i_dof, "j_dof" => j_dof, diff --git a/src/IO/exodus_export.jl b/src/IO/exodus_export.jl index cc564e1b8..5758c2772 100644 --- a/src/IO/exodus_export.jl +++ b/src/IO/exodus_export.jl @@ -279,7 +279,7 @@ function write_nodal_results_in_exodus( #write_values nnodes = datamanager.get_nnodes() for varname in keys(output) - field = datamanager.get_field(output[varname]["fieldname"]) + field = datamanager.get_field(output[varname]["fieldname"], output[varname]["time"]) #exo, timestep::Integer, id::Integer, var_index::Integer,vector # =>https://github.com/cmhamel/Exodus.jl/blob/master/src/Variables.jl if haskey(output[varname], "dof") diff --git a/src/Models/Additive/simple_additive.jl b/src/Models/Additive/simple_additive.jl index d43e4f238..eac115998 100644 --- a/src/Models/Additive/simple_additive.jl +++ b/src/Models/Additive/simple_additive.jl @@ -85,7 +85,7 @@ function compute_model( if bond_damage[iID][jID] != 0 continue end - if activation_time[neighborID] < time + if activation_time[neighborID] <= time bond_damage[iID][jID] = 1.0 if haskey(inverse_nlist[neighborID], iID) bond_damage[neighborID][inverse_nlist[neighborID][iID]] = 1.0 diff --git a/src/Models/Pre_calculation/bond_deformation.jl b/src/Models/Pre_calculation/bond_deformation.jl index eff01cd5a..75ea0c3b8 100644 --- a/src/Models/Pre_calculation/bond_deformation.jl +++ b/src/Models/Pre_calculation/bond_deformation.jl @@ -78,6 +78,7 @@ function compute( ) nlist = datamanager.get_nlist() deformed_coor = datamanager.get_field("Deformed Coordinates", "NP1") + deformed_coorN = datamanager.get_field("Deformed Coordinates", "N") deformed_bond = datamanager.get_field("Deformed Bond Geometry", "NP1") deformed_bond_length = datamanager.get_field("Deformed Bond Length", "NP1") Geometry.bond_geometry!( diff --git a/src/Support/Parameters/parameter_handling_output.jl b/src/Support/Parameters/parameter_handling_output.jl index 0fa414b53..0070f23a1 100644 --- a/src/Support/Parameters/parameter_handling_output.jl +++ b/src/Support/Parameters/parameter_handling_output.jl @@ -137,7 +137,7 @@ function get_output_fieldnames( computes::Vector{String}, output_type::String, ) - return_outputs = String[] + return_outputs = [] for output in keys(outputs) if !isa(outputs[output], Bool) @error "Output variable $output must be set to True or False" @@ -146,15 +146,15 @@ function get_output_fieldnames( if outputs[output] if output_type == "CSV" if output in computes - push!(return_outputs, output) + push!(return_outputs, [output, "constant"]) else @warn '"' * output * '"' * " is not defined as global variable" end else if output in variables || output in computes - push!(return_outputs, output) + push!(return_outputs, [output, "constant"]) elseif output * "NP1" in variables - push!(return_outputs, output * "NP1") + push!(return_outputs, [output, "NP1"]) else @warn '"' * output * '"' * " is not defined as variable" end diff --git a/src/Support/helpers.jl b/src/Support/helpers.jl index 66385d5eb..54035b244 100644 --- a/src/Support/helpers.jl +++ b/src/Support/helpers.jl @@ -211,7 +211,7 @@ function fastdot(a, b, absolute = false) c end function fill_in_place!( - A::Union{Vector{Vector{T}},Vector{AbstractArray{<:Number}}}, + A::Union{Vector{Vector{T}},Vector{Array{T,3}}}, value::T, active::Vector{Bool}, ) where {T<:Number} diff --git a/test/runtests.jl b/test/runtests.jl index 285ed8727..43e7971e1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -201,7 +201,7 @@ MPI.Init() end end - Logging.disable_logging(Logging.Debug - 2000) + # Logging.disable_logging(Logging.Debug - 2000) @testset "fullscale_tests" begin @testset "test_reload" begin include("fullscale_tests/test_reload/test_reload.jl") diff --git a/test/unit_tests/Core/ut_BC_manager.jl b/test/unit_tests/Core/ut_BC_manager.jl index dcd115dd0..c37de032e 100644 --- a/test/unit_tests/Core/ut_BC_manager.jl +++ b/test/unit_tests/Core/ut_BC_manager.jl @@ -332,7 +332,8 @@ end @test bcs["BC_1"]["Coordinate"] == "x" @test bcs["BC_1"]["Value"] == "20*t" @test bcs["BC_1"]["Node Set"] == [1, 3, 4] - @test bcs["BC_2"]["Variable"] == "DisplacementsNP1" + @test bcs["BC_2"]["Variable"] == "Displacements" + @test bcs["BC_2"]["Time"] == "NP1" @test bcs["BC_2"]["Coordinate"] == "z" @test bcs["BC_2"]["Value"] == "5" @test bcs["BC_2"]["Node Set"] == [4, 2, 7, 10] @@ -346,7 +347,7 @@ end test_data_manager.set_num_controller(10) test_data_manager.set_dof(3) test_data_manager.create_constant_node_field("Coordinates", Float64, 3) - test_data_manager.create_constant_node_field("Forces", Float64, 3) + test_data_manager.create_constant_node_field("Temperature", Float64, 3) test_data_manager.create_node_field("Displacements", Float64, 3) test_data_manager.set_nset("Nset_1", [1, 2, 3]) test_data_manager.set_nset("Nset_2", [3, 4, 7, 10]) @@ -367,7 +368,7 @@ end params = Dict( "Boundary Conditions" => Dict( "BC_1" => Dict( - "Variable" => "Forces", + "Variable" => "Temperature", "Node Set" => "Nset_1", "Coordinate" => "x", "Value" => "20*t", @@ -381,27 +382,27 @@ end ), ) - force = test_data_manager.get_field("Forces") + temperature = test_data_manager.get_field("Temperature") disp = test_data_manager.get_field("Displacements", "NP1") - @test sum(force) == 0 + @test sum(temperature) == 0 @test sum(disp) == 0 bcs = PeriLab.Solver.Boundary_conditions.init_BCs(params, test_data_manager) PeriLab.Solver.Boundary_conditions.apply_bc_dirichlet(bcs, test_data_manager, 0.0) - force = test_data_manager.get_field("Forces") + temperature = test_data_manager.get_field("Temperature") disp = test_data_manager.get_field("Displacements", "NP1") - @test sum(force) == 0 + @test sum(temperature) == 0 @test sum(disp) == 20 @test isapprox( disp, [0 0 0; 0 0 5; 0 0 0; 0 0 5; 0 0 0; 0 0 0; 0 0 5; 0 0 0; 0 0 0; 0 0 5], ) PeriLab.Solver.Boundary_conditions.apply_bc_dirichlet(bcs, test_data_manager, 0.2) - force = test_data_manager.get_field("Forces") + temperature = test_data_manager.get_field("Temperature") disp = test_data_manager.get_field("Displacements", "NP1") - @test sum(force) == 12 + @test sum(temperature) == 12 @test isapprox( - force, + temperature, [4 0 0; 0 0 0; 4 0 0; 4 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0], ) @test sum(disp) == 20 @@ -412,10 +413,10 @@ end # test if global nodes are not at the core bcs["BC_1"]["Node Set"] = [] bcs["BC_2"]["Node Set"] = [] - force .= 0 + temperature .= 0 disp .= 0 PeriLab.Solver.Boundary_conditions.apply_bc_dirichlet(bcs, test_data_manager, 0.2) - @test sum(force) == 0 + @test sum(temperature) == 0 @test sum(disp) == 0 params = Dict( diff --git a/test/unit_tests/Core/ut_data_manager.jl b/test/unit_tests/Core/ut_data_manager.jl index 60283c42e..060674dd1 100644 --- a/test/unit_tests/Core/ut_data_manager.jl +++ b/test/unit_tests/Core/ut_data_manager.jl @@ -122,7 +122,7 @@ test_data_manager.create_bond_field("I", Int64, 7) testfield_keys = test_data_manager.get_all_field_keys() @testset "create data fields -> get all fields" begin @test test_data_manager.get_nnodes() == num_controller - @test B[1] == test_data_manager.get_field("BN") + @test B[1] == test_data_manager.get_field("B", "N") @test B[2] == test_data_manager.get_field("B", "NP1") @test C == test_data_manager.get_field("C") @test "A" in testfield_keys @@ -189,7 +189,7 @@ end @test typeof(A[1]) == Float64 @test length(A) == test_data_manager.data["nnodes"] == num_controller + num_responder - B = test_data_manager.get_field("BN") + B = test_data_manager.get_field("B", "N") @test typeof(B[1]) == Bool @test length(B) == test_data_manager.data["nnodes"] == num_controller + num_responder @@ -200,7 +200,7 @@ end num_controller + num_responder @test length(C[1, :]) == 4 - D = test_data_manager.get_field("DNP1") + D = test_data_manager.get_field("D", "NP1") @test typeof(D[1, 1]) == Int64 @test length(D[:, 1]) == test_data_manager.data["nnodes"] == @@ -213,7 +213,7 @@ end @test length(F[1]) == nn[1] @test length(F[2]) == nn[2] @test length(F[3]) == nn[3] - G = test_data_manager.get_field("GN") + G = test_data_manager.get_field("G", "N") @test typeof(G[1, 1][1]) == Bool @test length(G[:, 1]) == num_controller + num_responder @@ -223,7 +223,7 @@ end @test length(H[1][1]) == 4 @test length(H[:][:]) == num_controller + num_responder - I = test_data_manager.get_field("INP1") + I = test_data_manager.get_field("I", "NP1") @test typeof(I[1][1][1]) == Int64 for i = 1:num_controller+num_responder @test length(I[i]) == nn[i] @@ -298,7 +298,7 @@ end @test test1 == test_data_manager.get_field("test3", "N") @test test2 == test_data_manager.get_field("test3", "NP1") test1, test2 = test_data_manager.create_node_field("test4", Float64, 3) - @test test1 == test_data_manager.get_field("test4N") + @test test1 == test_data_manager.get_field("test4", "N") @test test2 == test_data_manager.get_field("test4", "NP1") test = test_data_manager.create_constant_bond_field("test5", Float64, 1) @test test == test_data_manager.get_field("test5") @@ -354,22 +354,22 @@ end @test test_data_manager.data["NP1_to_N"]["I"][2] == "INP1" end @testset "set_and_get_values" begin - DN = test_data_manager.get_field("DN") + DN = test_data_manager.get_field("D", "N") DN[1, 3] = 10 - DNtest = test_data_manager.get_field("DN") + DNtest = test_data_manager.get_field("D", "N") @test DN[1, 3] == DNtest[1, 3] end -DN = test_data_manager.get_field("DN") -DNP1 = test_data_manager.get_field("DNP1") - -IN = test_data_manager.get_field("IN") -INP1 = test_data_manager.get_field("INP1") bd = test_data_manager.create_bond_field("Bond Damage", Float64, 1) test_data_manager.create_constant_node_field("Active", Bool, 1, true) @testset "switch_NP1_to_N" begin bmatrixN, bmatrixNP1 = test_data_manager.create_bond_field("Bmat", Float64, "Matrix", 2) nmatrixN, nmatrixNP1 = test_data_manager.create_node_field("Nmat", Float64, "Matrix", 2) + DN = test_data_manager.get_field("D", "N") + DNP1 = test_data_manager.get_field("D", "NP1") + + IN = test_data_manager.get_field("I", "N") + INP1 = test_data_manager.get_field("I", "NP1") IN[2][1][3] = 0 DNP1[2, 3] = 5 @@ -392,6 +392,10 @@ test_data_manager.create_constant_node_field("Active", Bool, 1, true) @test sum(maximum(bd)) == 0 test_data_manager.switch_NP1_to_N() + DN = test_data_manager.get_field("D", "N") + DNP1 = test_data_manager.get_field("D", "NP1") + nmatrixN = test_data_manager.get_field("Nmat", "N") + nmatrixNP1 = test_data_manager.get_field("Nmat", "NP1") @test DN[2, 3] == 5 @test nmatrixN[1, 1, 1] == 2 @test nmatrixN[1, 1, 2] == 2 @@ -418,6 +422,8 @@ test_data_manager.create_constant_node_field("Active", Bool, 1, true) @test DNP1[2, 3] == 6 @test DN[2, 3] == 5 + IN = test_data_manager.get_field("I", "N") + INP1 = test_data_manager.get_field("I", "NP1") @test INP1[2][1][3] == 0 # bonds @test IN[2][1][3] == 5 diff --git a/test/unit_tests/IO/ut_IO.jl b/test/unit_tests/IO/ut_IO.jl index 601baf87e..ec03f50c7 100644 --- a/test/unit_tests/IO/ut_IO.jl +++ b/test/unit_tests/IO/ut_IO.jl @@ -88,12 +88,14 @@ block_Id[end] = 2 for entry in keys(sort(output[i]["Fields"])) if occursin("Forces", entry) dof_force += 1 - @test output[i]["Fields"][entry]["fieldname"] == "ForcesNP1" + @test output[i]["Fields"][entry]["fieldname"] == "Forces" + @test output[i]["Fields"][entry]["time"] == "NP1" @test output[i]["Fields"][entry]["dof"] == dof_force @test output[i]["Fields"][entry]["type"] == Float64 else dof_disp += 1 - @test output[i]["Fields"][entry]["fieldname"] == "DisplacementsNP1" + @test output[i]["Fields"][entry]["fieldname"] == "Displacements" + @test output[i]["Fields"][entry]["time"] == "NP1" @test output[i]["Fields"][entry]["dof"] == dof_disp @test output[i]["Fields"][entry]["type"] == Float64 end @@ -135,12 +137,14 @@ end for entry in keys(sort(outputs[i]["Fields"])) if occursin("Forces", entry) dofForce += 1 - @test outputs[i]["Fields"][entry]["fieldname"] == "ForcesNP1" + @test outputs[i]["Fields"][entry]["fieldname"] == "Forces" + @test outputs[i]["Fields"][entry]["time"] == "NP1" @test outputs[i]["Fields"][entry]["dof"] == dofForce @test outputs[i]["Fields"][entry]["type"] == Float64 else dofDisp += 1 - @test outputs[i]["Fields"][entry]["fieldname"] == "DisplacementsNP1" + @test outputs[i]["Fields"][entry]["fieldname"] == "Displacements" + @test outputs[i]["Fields"][entry]["time"] == "NP1" @test outputs[i]["Fields"][entry]["dof"] == dofDisp @test outputs[i]["Fields"][entry]["type"] == Float64 end diff --git a/test/unit_tests/IO/ut_exodus_export.jl b/test/unit_tests/IO/ut_exodus_export.jl index 04b8f7135..31e47301d 100644 --- a/test/unit_tests/IO/ut_exodus_export.jl +++ b/test/unit_tests/IO/ut_exodus_export.jl @@ -125,49 +125,57 @@ coords = vcat(transpose(coordinates)) outputs = Dict( "Fields" => Dict( "Forcesxx" => Dict( - "fieldname" => "ForcesNP1", + "fieldname" => "Forces", + "time" => "NP1", "global_var" => false, "dof" => 1, "type" => Float64, ), "Forcesxy" => Dict( - "fieldname" => "ForcesNP1", + "fieldname" => "Forces", + "time" => "NP1", "global_var" => false, "dof" => 1, "type" => Float64, ), "Forcesxz" => Dict( - "fieldname" => "ForcesNP1", + "fieldname" => "Forces", + "time" => "NP1", "global_var" => false, "dof" => 1, "type" => Float64, ), "Forcesyx" => Dict( - "fieldname" => "ForcesNP1", + "fieldname" => "Forces", + "time" => "NP1", "global_var" => false, "dof" => 1, "type" => Float64, ), "Forcesyy" => Dict( - "fieldname" => "ForcesNP1", + "fieldname" => "Forces", + "time" => "NP1", "global_var" => false, "dof" => 1, "type" => Float64, ), "Forcesyz" => Dict( - "fieldname" => "ForcesNP1", + "fieldname" => "Forces", + "time" => "NP1", "global_var" => false, "dof" => 1, "type" => Float64, ), "Displacements" => Dict( - "fieldname" => "DisplacementsNP1", + "fieldname" => "Displacements", + "time" => "NP1", "global_var" => false, "dof" => 1, "type" => Float64, ), "External_Displacements" => Dict( - "fieldname" => "DisplacementsNP1", + "fieldname" => "Displacements", + "time" => "NP1", "global_var" => true, "dof" => 1, "type" => Float64, @@ -175,11 +183,12 @@ outputs = Dict( "Compute Class" => "Block_Data", "Calculation Type" => "Maximum", "Block" => "block_1", - "Variable" => "DisplacementsNP1", + "Variable" => "Displacements", ), ), "External_Forces" => Dict( - "fieldname" => "ForcesNP1", + "fieldname" => "Forces", + "time" => "NP1", "global_var" => true, "dof" => 3, "type" => Float64, @@ -195,7 +204,8 @@ outputs = Dict( computes = Dict( "Fields" => Dict( "External_Displacements" => Dict( - "fieldname" => "DisplacementsNP1", + "fieldname" => "Displacements", + "time" => "NP1", "global_var" => true, "dof" => 1, "type" => Float64, @@ -207,7 +217,8 @@ computes = Dict( ), ), "External_Forces" => Dict( - "fieldname" => "ForcesNP1", + "fieldname" => "Forces", + "time" => "NP1", "global_var" => true, "dof" => 3, "type" => Float64, diff --git a/test/unit_tests/Support/Parameters/ut_parameter_handling.jl b/test/unit_tests/Support/Parameters/ut_parameter_handling.jl index 34e7fb606..fdbc59465 100644 --- a/test/unit_tests/Support/Parameters/ut_parameter_handling.jl +++ b/test/unit_tests/Support/Parameters/ut_parameter_handling.jl @@ -236,7 +236,11 @@ end computes, output_type, ) - @test fieldnames == ["DisplacementsNP1", "External_Displacements", "Forces"] + @test fieldnames == [ + ["Displacements", "NP1"], + ["External_Displacements", "constant"], + ["Forces", "constant"], + ] outputs = Dict("Displacements" => "true") @test isnothing( @@ -256,7 +260,7 @@ end computes, output_type, ) - @test fieldnames == ["External_Displacements"] + @test fieldnames == [["External_Displacements", "constant"]] outputs = Dict("External_Forces" => true) fieldnames = PeriLab.Solver.Parameter_Handling.get_output_fieldnames( @@ -346,14 +350,14 @@ test_data_manager = PeriLab.Data_manager vector::Vector{String} = [] outputs = PeriLab.Solver.Parameter_Handling.get_outputs(params, testfield_keys, vector) - @test "A" in outputs["Output1"]["fieldnames"] - @test ("BNP1" in outputs["Output1"]["fieldnames"]) == false - @test "C" in outputs["Output1"]["fieldnames"] - @test "A" in outputs["Output2"]["fieldnames"] - @test "BNP1" in outputs["Output2"]["fieldnames"] - @test ("D" in outputs["Output2"]["fieldnames"]) == false - @test "E" in outputs["Output2"]["fieldnames"] - @test !("M" in outputs["Output2"]["fieldnames"]) + @test ["A", "constant"] in outputs["Output1"]["fieldnames"] + @test (["B", "NP1"] in outputs["Output1"]["fieldnames"]) == false + @test ["C", "constant"] in outputs["Output1"]["fieldnames"] + @test ["A", "constant"] in outputs["Output2"]["fieldnames"] + @test ["B", "NP1"] in outputs["Output2"]["fieldnames"] + @test (["D", "constant"] in outputs["Output2"]["fieldnames"]) == false + @test ["E", "constant"] in outputs["Output2"]["fieldnames"] + @test !(["M", "constant"] in outputs["Output2"]["fieldnames"]) params = Dict( "Outputs" => Dict( "Output1" => Dict( @@ -375,13 +379,13 @@ test_data_manager = PeriLab.Data_manager ) outputs = PeriLab.Solver.Parameter_Handling.get_outputs(params, testfield_keys, String["M"]) - @test !("A" in outputs["Output1"]["fieldnames"]) - @test !("BNP1" in outputs["Output1"]["fieldnames"]) - @test !("C" in outputs["Output1"]["fieldnames"]) - @test ("BNP1" in outputs["Output2"]["fieldnames"]) - @test !("D" in outputs["Output2"]["fieldnames"]) - @test ("E" in outputs["Output2"]["fieldnames"]) - @test ("M" in outputs["Output2"]["fieldnames"]) + @test !(["A", "constant"] in outputs["Output1"]["fieldnames"]) + @test !(["B", "NP1"] in outputs["Output1"]["fieldnames"]) + @test !(["C", "constant"] in outputs["Output1"]["fieldnames"]) + @test (["B", "NP1"] in outputs["Output2"]["fieldnames"]) + @test !(["D", "constant"] in outputs["Output2"]["fieldnames"]) + @test (["E", "constant"] in outputs["Output2"]["fieldnames"]) + @test (["M", "constant"] in outputs["Output2"]["fieldnames"]) params = Dict( "Outputs" => Dict( "Output1" => Dict( @@ -393,8 +397,8 @@ test_data_manager = PeriLab.Data_manager ) outputs = PeriLab.Solver.Parameter_Handling.get_outputs(params, testfield_keys, String["M"]) - @test !("A" in outputs["Output1"]["fieldnames"]) - @test "M" in outputs["Output1"]["fieldnames"] + @test !(["A", "constant"] in outputs["Output1"]["fieldnames"]) + @test ["M", "constant"] in outputs["Output1"]["fieldnames"] params = Dict( "Outputs" =>