Skip to content

Commit

Permalink
format field tests and add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
adamslc committed Mar 20, 2024
1 parent c2833a5 commit ace40c3
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 28 deletions.
7 changes: 7 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ species = VariableWeightSpecies(positions, momentums, weights, 1.0, 1.0)

const SUITE = BenchmarkGroup()

SUITE["field coordinate transformations"]["cell_index_to_cell_coords1"] =
@benchmarkable ParticleInCell.cell_index_to_cell_coords(rho, (3, 3))
SUITE["field coordinate transformations"]["cell_index_to_cell_coords2"] =
@benchmarkable ParticleInCell.cell_index_to_cell_coords(rho, (3, 3), 1)
SUITE["field coordinate transformations"]["cell_index_to_cell_coords3"] =
@benchmarkable ParticleInCell.cell_index_to_cell_coords(Eedge, (3, 3), 2)

bs_charge = BSplineChargeInterpolation(species, rho, 1)
SUITE["charge_dep"] = BenchmarkGroup(["interpolation", "particle", "field"])
SUITE["charge_dep"]["creation"] =
Expand Down
2 changes: 1 addition & 1 deletion src/ParticleInCell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export AbstractSpecies,
electrons

include("field.jl")
export Field
export Field, num_elements

abstract type AbstractSimulationStep end
function step!(::T) where {T<:AbstractSimulationStep}
Expand Down
122 changes: 95 additions & 27 deletions src/field_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,99 @@
@test eachindex(scalar_node_field) == CartesianIndices((4:13, 4:13, 4:13))
@test eachindex(vector_node_field) == CartesianIndices((1:10, 1:10, 1:10))

@test ParticleInCell.cell_index_to_cell_coords(scalar_node_field, CartesianIndex(4, 4, 4)) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(scalar_node_field, CartesianIndex(14, 14, 14)) == (10, 10, 10)
@test ParticleInCell.cell_index_to_cell_coords(scalar_node_field, CartesianIndex(4, 4, 4), 1) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(scalar_node_field, CartesianIndex(14, 14, 14), 3) == (10, 10, 10)

@test ParticleInCell.cell_index_to_cell_coords(vector_node_field, CartesianIndex(1, 1, 1)) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(vector_node_field, CartesianIndex(11, 11, 11)) == (10, 10, 10)
@test ParticleInCell.cell_index_to_cell_coords(vector_node_field, CartesianIndex(1, 1, 1), 1) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(vector_node_field, CartesianIndex(11, 11, 11), 3) == (10, 10, 10)

@test ParticleInCell.cell_index_to_cell_coords(vector_edge_field, CartesianIndex(1, 1, 1)) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(vector_edge_field, CartesianIndex(10, 10, 10)) == (9, 9, 9)
@test ParticleInCell.cell_index_to_cell_coords(vector_edge_field, CartesianIndex(1, 1, 1), 1) == (0.5, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(vector_edge_field, CartesianIndex(10, 10, 10), 2) == (9, 9.5, 9)
@test ParticleInCell.cell_index_to_cell_coords(vector_edge_field, CartesianIndex(11, 11, 11), 3) == (10, 10, 10.5)

@test ParticleInCell.cell_index_to_cell_coords(vector_face_field, CartesianIndex(1, 1, 1)) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(vector_face_field, CartesianIndex(10, 10, 10)) == (9, 9, 9)
@test ParticleInCell.cell_index_to_cell_coords(vector_face_field, CartesianIndex(1, 1, 1), 1) == (0, 0.5, 0.5)
@test ParticleInCell.cell_index_to_cell_coords(vector_face_field, CartesianIndex(10, 10, 10), 2) == (9.5, 9, 9.5)
@test ParticleInCell.cell_index_to_cell_coords(vector_face_field, CartesianIndex(11, 11, 11), 3) == (10.5, 10.5, 10)

@test ParticleInCell.cell_coords_to_cell_index(scalar_node_field, (0, 0, 0)) == CartesianIndex(4, 4, 4)
@test ParticleInCell.cell_coords_to_cell_index(scalar_node_field, (10.0, 10.0, 10.0)) == CartesianIndex(14, 14, 14)

@test ParticleInCell.cell_coords_to_cell_index(vector_edge_field, (0, 0, 0)) == CartesianIndex(1, 1, 1)
@test ParticleInCell.cell_coords_to_cell_index(vector_edge_field, (10.0, 10.0, 10.0)) == CartesianIndex(11, 11, 11)
@test ParticleInCell.cell_index_to_cell_coords(
scalar_node_field,
CartesianIndex(4, 4, 4),
) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(
scalar_node_field,
CartesianIndex(14, 14, 14),
) == (10, 10, 10)
@test ParticleInCell.cell_index_to_cell_coords(
scalar_node_field,
CartesianIndex(4, 4, 4),
1,
) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(
scalar_node_field,
CartesianIndex(14, 14, 14),
3,
) == (10, 10, 10)

@test ParticleInCell.cell_index_to_cell_coords(
vector_node_field,
CartesianIndex(1, 1, 1),
) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(
vector_node_field,
CartesianIndex(11, 11, 11),
) == (10, 10, 10)
@test ParticleInCell.cell_index_to_cell_coords(
vector_node_field,
CartesianIndex(1, 1, 1),
1,
) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(
vector_node_field,
CartesianIndex(11, 11, 11),
3,
) == (10, 10, 10)

@test ParticleInCell.cell_index_to_cell_coords(
vector_edge_field,
CartesianIndex(1, 1, 1),
) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(
vector_edge_field,
CartesianIndex(10, 10, 10),
) == (9, 9, 9)
@test ParticleInCell.cell_index_to_cell_coords(
vector_edge_field,
CartesianIndex(1, 1, 1),
1,
) == (0.5, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(
vector_edge_field,
CartesianIndex(10, 10, 10),
2,
) == (9, 9.5, 9)
@test ParticleInCell.cell_index_to_cell_coords(
vector_edge_field,
CartesianIndex(11, 11, 11),
3,
) == (10, 10, 10.5)

@test ParticleInCell.cell_index_to_cell_coords(
vector_face_field,
CartesianIndex(1, 1, 1),
) == (0, 0, 0)
@test ParticleInCell.cell_index_to_cell_coords(
vector_face_field,
CartesianIndex(10, 10, 10),
) == (9, 9, 9)
@test ParticleInCell.cell_index_to_cell_coords(
vector_face_field,
CartesianIndex(1, 1, 1),
1,
) == (0, 0.5, 0.5)
@test ParticleInCell.cell_index_to_cell_coords(
vector_face_field,
CartesianIndex(10, 10, 10),
2,
) == (9.5, 9, 9.5)
@test ParticleInCell.cell_index_to_cell_coords(
vector_face_field,
CartesianIndex(11, 11, 11),
3,
) == (10.5, 10.5, 10)

@test ParticleInCell.cell_coords_to_cell_index(scalar_node_field, (0, 0, 0)) ==
CartesianIndex(4, 4, 4)
@test ParticleInCell.cell_coords_to_cell_index(scalar_node_field, (10.0, 10.0, 10.0)) ==
CartesianIndex(14, 14, 14)

@test ParticleInCell.cell_coords_to_cell_index(vector_edge_field, (0, 0, 0)) ==
CartesianIndex(1, 1, 1)
@test ParticleInCell.cell_coords_to_cell_index(vector_edge_field, (10.0, 10.0, 10.0)) ==
CartesianIndex(11, 11, 11)
end

0 comments on commit ace40c3

Please sign in to comment.