|
| 1 | +@testset verbose=true "Custom Quantities" begin |
| 2 | + particle_spacing = 0.1 |
| 3 | + coordinates = [0.0 0.1 0.2; 0.0 0.0 0.1] |
| 4 | + velocities = [1.0 2.0 0.5; 0.5 1.0 1.5] |
| 5 | + densities = [1000.0, 1000.0, 1000.0] |
| 6 | + pressures = [101325.0, 101330.0, 101320.0] |
| 7 | + |
| 8 | + initial_condition = InitialCondition(; coordinates, velocity=velocities, |
| 9 | + density=densities, |
| 10 | + pressure=pressures, particle_spacing) |
| 11 | + |
| 12 | + smoothing_kernel = SchoenbergCubicSplineKernel{2}() |
| 13 | + smoothing_length = 1.2 * particle_spacing |
| 14 | + |
| 15 | + fluid_system = EntropicallyDampedSPHSystem(initial_condition, smoothing_kernel, |
| 16 | + smoothing_length, 1.0) |
| 17 | + fluid_system.cache.density .= initial_condition.density |
| 18 | + |
| 19 | + boundary_model = BoundaryModelDummyParticles(initial_condition.density, |
| 20 | + initial_condition.mass, |
| 21 | + AdamiPressureExtrapolation(), |
| 22 | + smoothing_kernel, smoothing_length) |
| 23 | + |
| 24 | + boundary_system = BoundarySPHSystem(initial_condition, boundary_model) |
| 25 | + |
| 26 | + semi = Semidiscretization(fluid_system, boundary_system) |
| 27 | + |
| 28 | + v_ode, u_ode = semidiscretize(semi, (0, 1)).u0.x |
| 29 | + t = 0.0 |
| 30 | + |
| 31 | + @testset "Kinetic Energy" begin |
| 32 | + @testset "Fluid System" begin |
| 33 | + ekin = kinetic_energy(fluid_system, v_ode, u_ode, semi, t) |
| 34 | + |
| 35 | + expected_ekin = sum(velocities) do velocity |
| 36 | + return 0.5 * first(fluid_system.mass) * dot(velocity, velocity) |
| 37 | + end |
| 38 | + |
| 39 | + @test isapprox(expected_ekin, ekin) |
| 40 | + end |
| 41 | + |
| 42 | + @testset "Boundary System" begin |
| 43 | + ekin = kinetic_energy(boundary_system, v_ode, u_ode, semi, t) |
| 44 | + @test ekin == 0 |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + @testset "Total Mass" begin |
| 49 | + @testset "Fluid System" begin |
| 50 | + mass = total_mass(fluid_system, v_ode, u_ode, semi, t) |
| 51 | + expected_mass = first(fluid_system.mass) * nparticles(fluid_system) |
| 52 | + |
| 53 | + @test isapprox(mass, expected_mass) |
| 54 | + end |
| 55 | + |
| 56 | + @testset "Boundary System" begin |
| 57 | + mass = total_mass(boundary_system, v_ode, u_ode, semi, t) |
| 58 | + |
| 59 | + @test isnan(mass) |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + @testset "Pressure Quantities" begin |
| 64 | + @testset "Max Pressure" begin |
| 65 | + max_p = max_pressure(fluid_system, v_ode, u_ode, semi, t) |
| 66 | + @test isapprox(max_p, 101330.0) |
| 67 | + |
| 68 | + # Boundary system should return NaN |
| 69 | + @test isnan(max_pressure(boundary_system, v_ode, u_ode, semi, t)) |
| 70 | + end |
| 71 | + |
| 72 | + @testset "Min Pressure" begin |
| 73 | + min_p = min_pressure(fluid_system, v_ode, u_ode, semi, t) |
| 74 | + @test min_p ≈ 101320.0 |
| 75 | + |
| 76 | + # Boundary system should return NaN |
| 77 | + @test isnan(min_pressure(boundary_system, v_ode, u_ode, semi, t)) |
| 78 | + end |
| 79 | + |
| 80 | + @testset "Average Pressure" begin |
| 81 | + avg_p = avg_pressure(fluid_system, v_ode, u_ode, semi, t) |
| 82 | + expected_avg = (101325.0 + 101330.0 + 101320.0) / 3 |
| 83 | + @test isapprox(avg_p, expected_avg) |
| 84 | + |
| 85 | + # Boundary system should return NaN |
| 86 | + @test isnan(avg_pressure(boundary_system, v_ode, u_ode, semi, t)) |
| 87 | + end |
| 88 | + end |
| 89 | + |
| 90 | + @testset "Density Quantities" begin |
| 91 | + @testset "max_density" begin |
| 92 | + max_d = max_density(fluid_system, v_ode, u_ode, semi, t) |
| 93 | + @test isapprox(max_d, 1000.0) # All particles have same density |
| 94 | + |
| 95 | + # Boundary system should return NaN |
| 96 | + @test isnan(max_density(boundary_system, v_ode, u_ode, semi, t)) |
| 97 | + end |
| 98 | + |
| 99 | + @testset "min_density" begin |
| 100 | + min_d = min_density(fluid_system, v_ode, u_ode, semi, t) |
| 101 | + @test isapprox(min_d, 1000.0) |
| 102 | + |
| 103 | + # Boundary system should return NaN |
| 104 | + @test isnan(min_density(boundary_system, v_ode, u_ode, semi, t)) |
| 105 | + end |
| 106 | + |
| 107 | + @testset "avg_density" begin |
| 108 | + avg_d = avg_density(fluid_system, v_ode, u_ode, semi, t) |
| 109 | + @test isapprox(avg_d, 1000.0) |
| 110 | + |
| 111 | + # Boundary system should return NaN |
| 112 | + @test isnan(avg_density(boundary_system, v_ode, u_ode, semi, t)) |
| 113 | + end |
| 114 | + end |
| 115 | +end |
0 commit comments