diff --git a/src/general/initial_condition.jl b/src/general/initial_condition.jl index 3f9162767..adcc58397 100644 --- a/src/general/initial_condition.jl +++ b/src/general/initial_condition.jl @@ -80,7 +80,13 @@ initial_condition = InitialCondition(; coordinates, velocity, mass, density) initial_condition = InitialCondition(; coordinates, velocity=x -> 2x, mass=1.0, density=1000.0) # output -InitialCondition{Float64}(-1.0, [0.0 1.0 1.0; 0.0 0.0 1.0], [0.0 2.0 2.0; 0.0 0.0 2.0], [1.0, 1.0, 1.0], [1000.0, 1000.0, 1000.0], [0.0, 0.0, 0.0]) +┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ InitialCondition{Float64} │ +│ ═════════════════════════ │ +│ #dimensions: ……………………………………………… 2 │ +│ #particles: ………………………………………………… 3 │ +│ particle spacing: ………………………………… -1.0 │ +└──────────────────────────────────────────────────────────────────────────────────────────────────┘ ``` """ struct InitialCondition{ELTYPE} @@ -183,6 +189,26 @@ struct InitialCondition{ELTYPE} end end +function Base.show(io::IO, ic::InitialCondition) + @nospecialize ic # reduce precompilation time + + print(io, "InitialCondition{$(eltype(ic))}()") +end + +function Base.show(io::IO, ::MIME"text/plain", ic::InitialCondition) + @nospecialize ic # reduce precompilation time + + if get(io, :compact, false) + show(io, system) + else + summary_header(io, "InitialCondition{$(eltype(ic))}") + summary_line(io, "#dimensions", "$(ndims(ic))") + summary_line(io, "#particles", "$(nparticles(ic))") + summary_line(io, "particle spacing", "$(ic.particle_spacing)") + summary_footer(io) + end +end + function wrap_function(function_::Function, ::Val) # Already a function return function_ diff --git a/src/preprocessing/geometries/polygon.jl b/src/preprocessing/geometries/polygon.jl index 2432799a4..501584ac7 100644 --- a/src/preprocessing/geometries/polygon.jl +++ b/src/preprocessing/geometries/polygon.jl @@ -97,6 +97,24 @@ struct Polygon{NDIMS, ELTYPE} end end +function Base.show(io::IO, geometry::Polygon) + @nospecialize geometry # reduce precompilation time + + print(io, "Polygon{$(ndims(geometry)), $(eltype(geometry))}()") +end + +function Base.show(io::IO, ::MIME"text/plain", geometry::Polygon) + @nospecialize geometry # reduce precompilation time + + if get(io, :compact, false) + show(io, system) + else + summary_header(io, "Polygon{$(ndims(geometry)), $(eltype(geometry))}") + summary_line(io, "#edges", "$(nfaces(geometry))") + summary_footer(io) + end +end + @inline Base.ndims(::Polygon{NDIMS}) where {NDIMS} = NDIMS @inline Base.eltype(::Polygon{NDIMS, ELTYPE}) where {NDIMS, ELTYPE} = ELTYPE diff --git a/src/preprocessing/geometries/triangle_mesh.jl b/src/preprocessing/geometries/triangle_mesh.jl index 60d850e81..afb362c38 100644 --- a/src/preprocessing/geometries/triangle_mesh.jl +++ b/src/preprocessing/geometries/triangle_mesh.jl @@ -136,6 +136,25 @@ struct TriangleMesh{NDIMS, ELTYPE} end end +function Base.show(io::IO, geometry::TriangleMesh) + @nospecialize geometry # reduce precompilation time + + print(io, "TriangleMesh{$(ndims(geometry)), $(eltype(geometry))}()") +end + +function Base.show(io::IO, ::MIME"text/plain", geometry::TriangleMesh) + @nospecialize geometry # reduce precompilation time + + if get(io, :compact, false) + show(io, system) + else + summary_header(io, "TriangleMesh{$(ndims(geometry)), $(eltype(geometry))}") + summary_line(io, "#faces", "$(nfaces(geometry))") + summary_line(io, "#vertices", "$(length(geometry.vertices))") + summary_footer(io) + end +end + @inline Base.ndims(::TriangleMesh{NDIMS}) where {NDIMS} = NDIMS @inline Base.eltype(::TriangleMesh{NDIMS, ELTYPE}) where {NDIMS, ELTYPE} = ELTYPE diff --git a/src/preprocessing/point_in_poly/winding_number_jacobson.jl b/src/preprocessing/point_in_poly/winding_number_jacobson.jl index 63666b4b2..2a1a91200 100644 --- a/src/preprocessing/point_in_poly/winding_number_jacobson.jl +++ b/src/preprocessing/point_in_poly/winding_number_jacobson.jl @@ -81,6 +81,26 @@ struct WindingNumberJacobson{ELTYPE, W} end end +function Base.show(io::IO, winding::WindingNumberJacobson) + @nospecialize winding # reduce precompilation time + + print(io, "WindingNumberJacobson{$(type2string(winding.winding))}()") +end + +function Base.show(io::IO, ::MIME"text/plain", winding::WindingNumberJacobson) + @nospecialize winding # reduce precompilation time + + if get(io, :compact, false) + show(io, system) + else + summary_header(io, "WindingNumberJacobson") + summary_line(io, "winding number factor", + "$(round(winding.winding_number_factor; digits=3))") + summary_line(io, "winding", "$(type2string(winding.winding))") + summary_footer(io) + end +end + function (point_in_poly::WindingNumberJacobson)(geometry, points; store_winding_number=false) (; winding_number_factor, winding) = point_in_poly diff --git a/src/schemes/solid/total_lagrangian_sph/system.jl b/src/schemes/solid/total_lagrangian_sph/system.jl index dfd71a2d6..e6e809079 100644 --- a/src/schemes/solid/total_lagrangian_sph/system.jl +++ b/src/schemes/solid/total_lagrangian_sph/system.jl @@ -40,11 +40,17 @@ See [Total Lagrangian SPH](@ref tlsph) for more details on the method. !!! note The fixed particles must be the **last** particles in the `InitialCondition`. To do so, e.g. use the `union` function: - ```jldoctest; output = false, filter = r"InitialCondition{Float64}.*", setup = :(fixed_particles = RectangularShape(0.1, (1, 4), (0.0, 0.0), density=1.0); beam = RectangularShape(0.1, (3, 4), (0.1, 0.0), density=1.0)) + ```jldoctest; output = false, setup = :(fixed_particles = RectangularShape(0.1, (1, 4), (0.0, 0.0), density=1.0); beam = RectangularShape(0.1, (3, 4), (0.1, 0.0), density=1.0)) solid = union(beam, fixed_particles) # output - InitialCondition{Float64}(...) *the rest of this line is ignored by filter* + ┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ InitialCondition{Float64} │ + │ ═════════════════════════ │ + │ #dimensions: ……………………………………………… 2 │ + │ #particles: ………………………………………………… 16 │ + │ particle spacing: ………………………………… 0.1 │ + └──────────────────────────────────────────────────────────────────────────────────────────────────┘ ``` where `beam` and `fixed_particles` are of type `InitialCondition`. """ diff --git a/src/setups/extrude_geometry.jl b/src/setups/extrude_geometry.jl index 9b31c463c..c7fb3fa44 100644 --- a/src/setups/extrude_geometry.jl +++ b/src/setups/extrude_geometry.jl @@ -66,7 +66,13 @@ shape = extrude_geometry(shape; direction, particle_spacing=0.1, n_extrude=4, de └ New particle spacing is set to 0.09387239731236392. ┌ Info: The desired size is not a multiple of the particle spacing 0.1. └ New particle spacing is set to 0.09198039027185569. -InitialCondition{Float64}(0.1, [0.44999999999999996 0.43096988312782164 … -0.23871756048182058 -0.24999999999999994; 0.4 0.4956708580912724 … 0.5001344202803415 0.4000000000000001; 0.05 0.05 … 0.35000000000000003 0.35000000000000003], [0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0], [1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002 … 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002], [1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0 … 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) +┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ InitialCondition{Float64} │ +│ ═════════════════════════ │ +│ #dimensions: ……………………………………………… 3 │ +│ #particles: ………………………………………………… 144 │ +│ particle spacing: ………………………………… 0.1 │ +└──────────────────────────────────────────────────────────────────────────────────────────────────┘ ``` !!! warning "Experimental Implementation" diff --git a/src/setups/rectangular_shape.jl b/src/setups/rectangular_shape.jl index db592ecc5..98160bcac 100644 --- a/src/setups/rectangular_shape.jl +++ b/src/setups/rectangular_shape.jl @@ -61,7 +61,13 @@ rectangular = RectangularShape(particle_spacing, (5, 4), (1.0, 2.0), rectangular = RectangularShape(particle_spacing, (5, 4, 7), (1.0, 2.0, 3.0), density=1000.0) # output -InitialCondition{Float64}(0.1, [1.05 1.15 … 1.35 1.45; 2.05 2.05 … 2.35 2.35; 3.05 3.05 … 3.65 3.65], [0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0], [1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002 … 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002], [1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0 … 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) +┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ InitialCondition{Float64} │ +│ ═════════════════════════ │ +│ #dimensions: ……………………………………………… 3 │ +│ #particles: ………………………………………………… 140 │ +│ particle spacing: ………………………………… 0.1 │ +└──────────────────────────────────────────────────────────────────────────────────────────────────┘ ``` """ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coordinates; diff --git a/src/setups/sphere_shape.jl b/src/setups/sphere_shape.jl index ba347738e..4889e1346 100644 --- a/src/setups/sphere_shape.jl +++ b/src/setups/sphere_shape.jl @@ -78,7 +78,13 @@ SphereShape(0.1, 0.5, (0.2, 0.4, 0.3), 1000.0) SphereShape(0.1, 0.5, (0.2, 0.4, 0.3), 1000.0, sphere_type=RoundSphere()) # output -InitialCondition{Float64}(0.1, [0.25 0.17500000000000002 … 0.269548322038589 0.2; 0.4 0.44330127018922194 … 0.3127891626126164 0.4; 0.3 0.3 … -0.13595561786013038 -0.15000000000000002], [0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0], [1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002 … 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002], [1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0 … 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) +┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ InitialCondition{Float64} │ +│ ═════════════════════════ │ +│ #dimensions: ……………………………………………… 3 │ +│ #particles: ………………………………………………… 518 │ +│ particle spacing: ………………………………… 0.1 │ +└──────────────────────────────────────────────────────────────────────────────────────────────────┘ ``` """ function SphereShape(particle_spacing, radius, center_position, density; diff --git a/test/general/initial_condition.jl b/test/general/initial_condition.jl index 468ebe65b..38bab06c5 100644 --- a/test/general/initial_condition.jl +++ b/test/general/initial_condition.jl @@ -20,6 +20,23 @@ SphereShape(0.1, 0.5, (1.0, 0.5), 1000.0, sphere_type=RoundSphere()))) + @testset verbose=true "Show" begin + shape = RectangularShape(0.05, (20, 20), (0.0, 0.0), density=1.0) + + show_compact = "InitialCondition{Float64}()" + @test repr(shape) == show_compact + + show_box = """ + ┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ InitialCondition{Float64} │ + │ ═════════════════════════ │ + │ #dimensions: ……………………………………………… 2 │ + │ #particles: ………………………………………………… 400 │ + │ particle spacing: ………………………………… 0.05 │ + └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" + @test repr("text/plain", shape) == show_box + end + @testset verbose=true "Constructors" begin @testset "Illegal Inputs" begin error_str = "`coordinates` and `velocities` must be of the same size" diff --git a/test/preprocessing/geometries/geometries.jl b/test/preprocessing/geometries/geometries.jl index 808c6799e..d85efa9f7 100644 --- a/test/preprocessing/geometries/geometries.jl +++ b/test/preprocessing/geometries/geometries.jl @@ -123,6 +123,36 @@ end end + @testset verbose=true "Show" begin + data_dir = pkgdir(TrixiParticles, "examples", "preprocessing", "data") + geometry = load_geometry(joinpath(data_dir, "circle.asc")) + + show_compact = "Polygon{2, Float64}()" + @test repr(geometry) == show_compact + + show_box = """ + ┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ Polygon{2, Float64} │ + │ ═══════════════════ │ + │ #edges: …………………………………………………………… 63 │ + └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" + @test repr("text/plain", geometry) == show_box + + geometry = load_geometry(joinpath(data_dir, "sphere.stl")) + + show_compact = "TriangleMesh{3, Float64}()" + @test repr(geometry) == show_compact + + show_box = """ + ┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ TriangleMesh{3, Float64} │ + │ ════════════════════════ │ + │ #faces: …………………………………………………………… 3072 │ + │ #vertices: …………………………………………………… 1538 │ + └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" + @test repr("text/plain", geometry) == show_box + end + @testset verbose=true "Unique Sort" begin # Fixed seed to ensure reproducibility Random.seed!(1) diff --git a/test/preprocessing/point_in_poly/winding_number_jacobson.jl b/test/preprocessing/point_in_poly/winding_number_jacobson.jl new file mode 100644 index 000000000..ee2119a62 --- /dev/null +++ b/test/preprocessing/point_in_poly/winding_number_jacobson.jl @@ -0,0 +1,33 @@ +@testset verbose=true "WindingNumberJacobson" begin + @testset verbose=true "Show" begin + data_dir = pkgdir(TrixiParticles, "examples", "preprocessing", "data") + geometry = load_geometry(joinpath(data_dir, "circle.asc")) + + winding = WindingNumberJacobson(; hierarchical_winding=false) + + show_compact = "WindingNumberJacobson{NaiveWinding}()" + @test repr(winding) == show_compact + + show_box = """ + ┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ WindingNumberJacobson │ + │ ═════════════════════ │ + │ winding number factor: …………………… 0.0 │ + │ winding: ………………………………………………………… NaiveWinding │ + └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" + @test repr("text/plain", winding) == show_box + + winding = WindingNumberJacobson(; geometry, winding_number_factor=pi) + show_compact = "WindingNumberJacobson{HierarchicalWinding}()" + @test repr(winding) == show_compact + + show_box = """ + ┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ WindingNumberJacobson │ + │ ═════════════════════ │ + │ winding number factor: …………………… 3.142 │ + │ winding: ………………………………………………………… HierarchicalWinding │ + └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" + @test repr("text/plain", winding) == show_box + end +end diff --git a/test/preprocessing/preprocessing.jl b/test/preprocessing/preprocessing.jl index d2a994f93..50b96d883 100644 --- a/test/preprocessing/preprocessing.jl +++ b/test/preprocessing/preprocessing.jl @@ -1 +1,2 @@ include("geometries/geometries.jl") +include("point_in_poly/winding_number_jacobson.jl") diff --git a/test/systems/dem_system.jl b/test/systems/dem_system.jl index c7ae18bcb..87ff7d339 100644 --- a/test/systems/dem_system.jl +++ b/test/systems/dem_system.jl @@ -9,7 +9,7 @@ include("../test_util.jl") initial_condition = InitialCondition(; coordinates, mass, density) system = DEMSystem(initial_condition, 2 * 10^5, 10e9, 0.3, acceleration=(0.0, 10.0)) - show_compact = "DEMSystem{2}(InitialCondition{Float64}(-1.0, [1.0 2.0; 1.0 2.0], [0.0 0.0; 0.0 0.0], [1.25, 1.5], [990.0, 1000.0], [0.0, 0.0]), 1.0e10, 0.3, 200000.0, 0.0001) with 2 particles" + show_compact = "DEMSystem{2}(InitialCondition{Float64}(), 1.0e10, 0.3, 200000.0, 0.0001) with 2 particles" @test repr(system) == show_compact show_box = """ ┌──────────────────────────────────────────────────────────────────────────────────────────────────┐