Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JTHesse committed Jan 10, 2025
1 parent c33036f commit dc063f1
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 15 deletions.
61 changes: 48 additions & 13 deletions src/IO/mesh_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1764,12 +1764,12 @@ function disk_filter(
)


if dof == 2
center = [filter["Center X"], filter["Center Y"]]
normal = [filter["Normal X"], filter["Normal Y"]]
else
if dof == 3
center = [filter["Center X"], filter["Center Y"], filter["Center Z"]]
normal = [filter["Normal X"], filter["Normal Y"], filter["Normal Z"]]
else
@error "Disk filter only implemented for 3D, use rectangular plane filter instead"
return nothing
end
#normalize vector
normal = normal ./ norm(normal)
Expand Down Expand Up @@ -1924,7 +1924,6 @@ function extrude_surface_mesh(mesh::DataFrame, params::Dict)
end

block_id = maximum(mesh.block_id) + 1
volume = step_x * step_y * step_z

id = 0

Expand All @@ -1936,15 +1935,33 @@ function extrude_surface_mesh(mesh::DataFrame, params::Dict)

if direction == "X"
if dof == 2
push!(mesh, (x = i, y = j, volume = volume, block_id = block_id))
push!(mesh, (x = i, y = j, volume = step_x * step_y, block_id = block_id))
else
push!(mesh, (x = i, y = j, z = k, volume = volume, block_id = block_id))
push!(
mesh,
(
x = i,
y = j,
z = k,
volume = step_x * step_y * step_z,
block_id = block_id,
),
)
end
elseif direction == "Y"
if dof == 2
push!(mesh, (x = j, y = i, volume = volume, block_id = block_id))
push!(mesh, (x = j, y = i, volume = step_x * step_y, block_id = block_id))
else
push!(mesh, (x = j, y = i, z = k, volume = volume, block_id = block_id))
push!(
mesh,
(
x = j,
y = i,
z = k,
volume = step_x * step_y * step_z,
block_id = block_id,
),
)
end
end
append!(node_sets["Extruded_1"], [Int64(id)])
Expand All @@ -1959,15 +1976,33 @@ function extrude_surface_mesh(mesh::DataFrame, params::Dict)

if direction == "X"
if dof == 2
push!(mesh, (x = i, y = j, volume = volume, block_id = block_id))
push!(mesh, (x = i, y = j, volume = step_x * step_y, block_id = block_id))
else
push!(mesh, (x = i, y = j, z = k, volume = volume, block_id = block_id))
push!(
mesh,
(
x = i,
y = j,
z = k,
volume = step_x * step_y * step_z,
block_id = block_id,
),
)
end
elseif direction == "Y"
if dof == 2
push!(mesh, (x = j, y = i, volume = volume, block_id = block_id))
push!(mesh, (x = j, y = i, volume = step_x * step_y, block_id = block_id))
else
push!(mesh, (x = j, y = i, z = k, volume = volume, block_id = block_id))
push!(
mesh,
(
x = j,
y = i,
z = k,
volume = step_x * step_y * step_z,
block_id = block_id,
),
)
end
end
append!(node_sets["Extruded_2"], [Int64(id)])
Expand Down
34 changes: 33 additions & 1 deletion test/unit_tests/Core/ut_BC_manager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ end
"Value" => "20*t",
),
"BC_2" => Dict(
"Variable" => "not there",
"Variable" => "Displacements",
"Node Set" => "Nset_2",
"Coordinate" => "z",
"Value" => "0",
Expand All @@ -273,6 +273,38 @@ end
),
)

bcs = PeriLab.Solver_control.Boundary_conditions.boundary_condition(
params,
test_data_manager,
)

# @test bcs = PeriLab.Solver_control.Boundary_conditions.check_valid_bcs(bcs, test_data_manager)


test_data_manager.set_dof(2)
@test isnothing(
PeriLab.Solver_control.Boundary_conditions.check_valid_bcs(bcs, test_data_manager),
)
test_data_manager.set_dof(3)


params = Dict(
"Boundary Conditions" => Dict(
"BC_1" => Dict(
"Variable" => "Forces",
"Node Set" => "Nset_1",
"Coordinate" => "x",
"Value" => "20*t",
),
"BC_2" => Dict(
"Variable" => "not there",
"Node Set" => "Nset_2",
"Coordinate" => "z",
"Value" => "0",
),
),
)

bcs = PeriLab.Solver_control.Boundary_conditions.boundary_condition(
params,
test_data_manager,
Expand Down
5 changes: 5 additions & 0 deletions test/unit_tests/IO/ut_IO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,8 @@ end
# Not fully tested yet because MPI.size=1
@test PeriLab.IO.show_mpi_summary("", false, comm, test_data_manager) == 1
end

@testset "ut_clearNP1" begin
@test PeriLab.IO.clearNP1("ForceNP1") == "Force"
@test PeriLab.IO.clearNP1("Force") == "Force"
end
71 changes: 71 additions & 0 deletions test/unit_tests/IO/ut_bond_filter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,75 @@ end
(filter_flag, normal) = PeriLab.IO.disk_filter(nnodes, data, filter, nlist, dof)
@test filter_flag == expected_filter_flag
@test normal == expected_normal

@test isnothing(PeriLab.IO.disk_filter(nnodes, data, filter, nlist, 2))
end

@testset "ut_rectangular_plane_filter" begin
nnodes = 6

data = zeros(Float64, 3, 6)
data[1, 1] = 0
data[2, 1] = 0
data[3, 1] = -1.0

data[1, 2] = 0
data[2, 2] = -0.5
data[3, 2] = -1.0

data[1, 3] = 0
data[2, 3] = 1.5
data[3, 3] = -1.0

data[1, 4] = 0
data[2, 4] = 0
data[3, 4] = 1.0

data[1, 5] = 0
data[2, 5] = -0.5
data[3, 5] = 1.0

data[1, 6] = 0
data[2, 6] = 1.5
data[3, 6] = 1.0

filter = Dict(
"Lower Left Corner X" => -0.5,
"Lower Left Corner Y" => -0.5,
"Lower Left Corner Z" => 0.0,
"Bottom Unit Vector X" => 1.0,
"Bottom Unit Vector Y" => 0.0,
"Bottom Unit Vector Z" => 0.0,
"Normal X" => 0.0,
"Normal Y" => 0.0,
"Normal Z" => 1.0,
"Bottom Length" => 1.0,
"Side Length" => 1.0,
)

nlist = [
[2, 3, 4, 5, 6],
[1, 3, 4, 5, 6],
[1, 2, 4, 5, 6],
[1, 2, 3, 5, 6],
[1, 2, 3, 4, 6],
[1, 2, 3, 4, 5],
]
dof = 3

# Define the expected output values
expected_filter_flag = [
[true, true, true, true, true], # Node 1
[true, true, true, false, true], # Node 2
[true, true, true, true, true], # Node 3
[true, true, true, true, true], # Node 4
[true, false, true, true, true], # Node 5
[true, true, true, true, true], # Node 6
]

expected_normal = [0, 0, 1]
(filter_flag, normal) =
PeriLab.IO.rectangular_plane_filter(nnodes, data, filter, nlist, dof)
@test filter_flag == expected_filter_flag
@test normal == expected_normal
end
Loading

0 comments on commit dc063f1

Please sign in to comment.