Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix type error in grid generators and add some test functions for gri… #973

Merged
10 changes: 5 additions & 5 deletions src/Grid/grid_generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end

function _generate_2d_nodes!(nodes, nx, ny, LL, LR, UR, UL)
for i in 0:ny-1
ratio_bounds = i / (ny-1)
ratio_bounds = convert(eltype(LL), (i / (ny-1)))

x0 = LL[1] * (1 - ratio_bounds) + ratio_bounds * UL[1]
x1 = LR[1] * (1 - ratio_bounds) + ratio_bounds * UR[1]
Expand All @@ -78,7 +78,7 @@ function _generate_2d_nodes!(nodes, nx, ny, LL, LR, UR, UL)
y1 = LR[2] * (1 - ratio_bounds) + ratio_bounds * UR[2]

for j in 0:nx-1
ratio = j / (nx-1)
ratio = convert(eltype(LL), j / (nx-1))
x = x0 * (1 - ratio) + ratio * x1
y = y0 * (1 - ratio) + ratio * y1
push!(nodes, Node((x, y)))
Expand Down Expand Up @@ -284,9 +284,9 @@ function generate_grid(::Type{Pyramid}, nel::NTuple{3,Int}, left::Vec{3,T}=Vec{3

#Center node in each "voxel"
for k in 1:nel_z, j in 1:nel_y, i in 1:nel_x
midx = 0.5(coords_x[i+1] + coords_x[i])
midy = 0.5(coords_y[j+1] + coords_y[j])
midz = 0.5(coords_z[k+1] + coords_z[k])
midx = convert(eltype(left),0.5(coords_x[i+1] + coords_x[i]))
midy = convert(eltype(left),0.5(coords_y[j+1] + coords_y[j]))
midz = convert(eltype(left),0.5(coords_z[k+1] + coords_z[k]))
push!(nodes, Node((midx, midy, midz)))
end

Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ include("test_constraints.jl")
include("test_grid_dofhandler_vtk.jl")
include("test_vtk_export.jl")
include("test_abstractgrid.jl")
include("test_grid_generators.jl")
include("test_grid_addboundaryset.jl")
include("test_mixeddofhandler.jl")
include("test_l2_projection.jl")
Expand Down
61 changes: 61 additions & 0 deletions test/test_grid_generators.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Test
using Ferrite
using Tensors



# Helper function to test grid generation for a given floating-point type
function test_generate_grid(T::Type)
# Testing Line grid
nel = (10,)
left = Vec{1,T}((-1.0,))
right = Vec{1,T}((1.0,))
grid = generate_grid(Line, nel, left, right)
@test isa(grid, Grid)

# Testing QuadraticLine grid
grid = generate_grid(QuadraticLine, nel, left, right)
@test isa(grid, Grid)

# Testing 2D grids
nel = (10, 10)
left_2d = Vec{2,T}((-1.0, -1.0))
right_2d = Vec{2,T}((1.0, 1.0))
grid = generate_grid(Quadrilateral, nel, left_2d, right_2d)
@test isa(grid, Grid)

grid = generate_grid(QuadraticQuadrilateral, nel, left_2d, right_2d)
@test isa(grid, Grid)

grid = generate_grid(Triangle, nel, left_2d, right_2d)
@test isa(grid, Grid)

grid = generate_grid(QuadraticTriangle, nel, left_2d, right_2d)
@test isa(grid, Grid)

# Testing 3D grids
nel = (10, 10, 10)
left_3d = Vec{3,T}((-1.0, -1.0, -1.0))
right_3d = Vec{3,T}((1.0, 1.0, 1.0))
grid = generate_grid(Hexahedron, nel, left_3d, right_3d)
@test isa(grid, Grid)

grid = generate_grid(Wedge, nel, left_3d, right_3d)
@test isa(grid, Grid)

grid = generate_grid(Pyramid, nel, left_3d, right_3d)
@test isa(grid, Grid)

grid = generate_grid(Tetrahedron, nel, left_3d, right_3d)
@test isa(grid, Grid)

grid = generate_grid(SerendipityQuadraticHexahedron, nel, left_3d, right_3d)
@test isa(grid, Grid)
end

# Run tests for different floating-point types
@testset "Generate Grid Tests" begin
test_generate_grid(Float64)
test_generate_grid(Float32)
test_generate_grid(Float16)
end
Loading