Skip to content

Commit

Permalink
Fixed calculate_nodelist
Browse files Browse the repository at this point in the history
  • Loading branch information
JTHesse committed Aug 26, 2024
1 parent 7f58474 commit 7faa95c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
25 changes: 12 additions & 13 deletions src/Compute/compute_global_values.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause

"""
calculate_nodelist(datamanager::Module, field_key::String, dof::Union{Int64,Vector{Int64}}, calculation_type::String, node_set::Vector{Int64})
calculate_nodelist(datamanager::Module, field_key::String, dof::Union{Int64,Vector{Int64}}, calculation_type::String, local_nodes::Vector{Int64})
Calculate the global value of a field for a given set of nodes.
Expand All @@ -12,7 +12,7 @@ Calculate the global value of a field for a given set of nodes.
- `field_key::String`: Field key.
- `dof::Union{Int64,Vector{Int64}}`: Degree of freedom
- `calculation_type::String`: Calculation type.
- `node_set::Vector{Int64}`: Node set.
- `local_nodes::Vector{Int64}`: Node set.
# Returns
- `value::Vector`: Global value.
- `nnodes::Int64`: Number of nodes.
Expand All @@ -22,7 +22,7 @@ function calculate_nodelist(
field_key::String,
dof::Union{Int64,Vector{Int64}},
calculation_type::String,
node_set::Union{Int64,Vector{Int64}},
local_nodes::Union{Int64,Vector{Int64}},
)
# get block_nodes
# check NP1
Expand All @@ -35,37 +35,36 @@ function calculate_nodelist(
end
field = datamanager.get_field(field_key)
field_type = datamanager.get_field_type(field_key)
node_list = datamanager.get_local_nodes(node_set)

if calculation_type == "Sum"
if length(node_list) == 0
if length(local_nodes) == 0
value = field_type(0)
else
value = global_value_sum(field, dof, node_list)
value = global_value_sum(field, dof, local_nodes)
end
elseif calculation_type == "Maximum"
if length(node_list) == 0
if length(local_nodes) == 0
value = typemin(field_type)
else
value = global_value_max(field, dof, node_list)
value = global_value_max(field, dof, local_nodes)
end
elseif calculation_type == "Minimum"
if length(node_list) == 0
if length(local_nodes) == 0
value = typemax(field_type)
else
value = global_value_min(field, dof, node_list)
value = global_value_min(field, dof, local_nodes)
end
elseif calculation_type == "Average"
if length(node_list) == 0
if length(local_nodes) == 0
value = field_type(0)
else
value = global_value_avg(field, dof, node_list)
value = global_value_avg(field, dof, local_nodes)
end
else
@warn "Unknown calculation type $calculation_type"
return nothing
end
return value, Int64(length(node_list))
return value, Int64(length(local_nodes))
end

"""
Expand Down
3 changes: 2 additions & 1 deletion src/IO/IO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,9 @@ function get_global_values(output::Dict, datamanager::Module)
calculate_block(datamanager, fieldname, dof, calculation_type, block_id)
elseif compute_class == "Node_Set_Data"
node_set = output[varname]["nodeset"]
node_list = datamanager.get_local_nodes(node_set)
global_value, nnodes =
calculate_nodelist(datamanager, fieldname, dof, calculation_type, node_set)
calculate_nodelist(datamanager, fieldname, dof, calculation_type, node_list)
end
if datamanager.get_max_rank() > 1
global_value =
Expand Down
8 changes: 4 additions & 4 deletions test/unit_tests/Compute/ut_compute_global_values.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ include("../../../src/Compute/compute_global_values.jl")
test_data_manager.set_glob_to_loc(Dict(1 => 1, 2 => 2))
nodes = Vector{Int64}(3:4)

@test calculate_nodelist(test_data_manager, "Disp", 1, "Sum", nodes) == (0, 0)
@test calculate_nodelist(test_data_manager, "Disp", 1, "Average", nodes) == (0, 0)
@test calculate_nodelist(test_data_manager, "Disp", 1, "Minimum", nodes) == (Inf, 0)
@test calculate_nodelist(test_data_manager, "Disp", 1, "Maximum", nodes) == (-Inf, 0)
@test calculate_nodelist(test_data_manager, "Disp", 1, "Sum", nodes) == (7, 2)
@test calculate_nodelist(test_data_manager, "Disp", 1, "Average", nodes) == (3.5, 2)
@test calculate_nodelist(test_data_manager, "Disp", 1, "Minimum", nodes) == (3, 2)
@test calculate_nodelist(test_data_manager, "Disp", 1, "Maximum", nodes) == (4, 2)

matrix = test_data_manager.create_constant_node_field("Matrix", Float64, "Matrix", 3)
matrix[:, 1, 2] .= 4
Expand Down

0 comments on commit 7faa95c

Please sign in to comment.