From db890674f44c307639f2db82f3aed14174782789 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 24 Mar 2025 08:39:28 +0100 Subject: [PATCH 01/43] Integrate write2json for initial metadata export --- src/TrixiParticles.jl | 3 +- src/callbacks/solution_saving.jl | 5 + src/visualization/write2json.jl | 152 +++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/visualization/write2json.jl diff --git a/src/TrixiParticles.jl b/src/TrixiParticles.jl index 07fa175744..165b29a48b 100644 --- a/src/TrixiParticles.jl +++ b/src/TrixiParticles.jl @@ -52,6 +52,7 @@ include("schemes/schemes.jl") include("general/semidiscretization.jl") include("general/gpu.jl") include("visualization/write2vtk.jl") +include("visualization/write2json.jl") include("visualization/recipes_plots.jl") include("preprocessing/preprocessing.jl") @@ -77,7 +78,7 @@ export BoundaryModelMonaghanKajtar, BoundaryModelDummyParticles, AdamiPressureEx export BoundaryMovement export examples_dir, validation_dir -export trixi2vtk +export trixi2vtk, trixi2json export RectangularTank, RectangularShape, SphereShape, ComplexShape export ParticlePackingSystem, SignedDistanceField export WindingNumberHormann, WindingNumberJacobson diff --git a/src/callbacks/solution_saving.jl b/src/callbacks/solution_saving.jl index fa06e8b6d3..742fd8a460 100644 --- a/src/callbacks/solution_saving.jl +++ b/src/callbacks/solution_saving.jl @@ -133,6 +133,11 @@ function initialize_save_cb!(solution_callback::SolutionSavingCallback, u, t, in solution_callback.latest_saved_iter = -1 solution_callback.git_hash[] = compute_git_hash() + # Write metadata to JSON-file + if integrator.iter == 0 + trixi2json(solution_callback, integrator) + end + # Save initial solution if solution_callback.save_initial_solution # Update systems to compute quantities like density and pressure diff --git a/src/visualization/write2json.jl b/src/visualization/write2json.jl new file mode 100644 index 0000000000..225138bfd3 --- /dev/null +++ b/src/visualization/write2json.jl @@ -0,0 +1,152 @@ +""" + trixi2json(solution_callback, integrator) + +Write simulation metadata to a JSON-file. + +# Arguments +- `solution_callback`: Callback storing metadata and output settings. +- `integrator`: ODE integrator containing simulation data. + +# Example +```jldoctest; output = false, saving_callback = SolutionSavingCallback(dt = 0.1, output_directory = "output", prefix = "solution"), +setup = :(trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "hydrostatic_water_column_2d.jl"), tspan = (0.0, 0.01), callbacks = saving_callback)) + +# output + +``` +""" + +function trixi2json(solution_callback, integrator) + + semi = integrator.p + (; systems) = semi + + output_directory = solution_callback.output_directory + prefix = solution_callback.prefix + git_hash = solution_callback.git_hash + + filenames = system_names(systems) + + foreach_system(semi) do system + system_index = system_indices(system, semi) + + trixi2json(system; system_name = filenames[system_index], output_directory, prefix, git_hash) + end +end + +function trixi2json(system; system_name, output_directory, prefix, git_hash) + mkpath(output_directory) + + meta_data = Dict{String, Any}( + "solver_version" => git_hash, + "julia_version" => string(VERSION), + ) + + get_meta_data!(meta_data, system) + + # handle "_" on optional prefix strings + add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") + + # Write metadata to JSON-file + json_file = joinpath(output_directory, + add_opt_str_pre(prefix) * "$(system_name)_metadata.json") + + open(json_file, "w") do file + JSON.print(file, meta_data, 2) + end +end + +function get_meta_data!(meta_data, system::FluidSystem) + meta_data["acceleration"] = system.acceleration + meta_data["viscosity"] = type2string(system.viscosity) + get_meta_data!(meta_data, system.viscosity) + meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) + meta_data["smoothing_length"] = system.smoothing_length + meta_data["density_calculator"] = type2string(system.density_calculator) + + if system isa WeaklyCompressibleSPHSystem + meta_data["state_equation"] = type2string(system.state_equation) + meta_data["state_equation_rho0"] = system.state_equation.reference_density + meta_data["state_equation_pa"] = system.state_equation.background_pressure + meta_data["state_equation_c"] = system.state_equation.sound_speed + meta_data["solver"] = "WCSPH" + + meta_data["correction_method"] = type2string(system.correction) + if system.correction isa AkinciFreeSurfaceCorrection + meta_data["correction_rho0"] = system.correction.rho0 + end + if system.state_equation isa StateEquationCole + meta_data["state_equation_exponent"] = system.state_equation.exponent + end + if system.state_equation isa StateEquationIdealGas + meta_data["state_equation_gamma"] = system.state_equation.gamma + end + else + meta_data["solver"] = "EDAC" + meta_data["sound_speed"] = system.sound_speed + meta_data["background_pressure_TVF"] = system.transport_velocity isa Nothing ? "-" : + system.transport_velocity.background_pressure + end + + return meta_data +end + +get_meta_data!(meta_data, viscosity::Nothing) = meta_data + +function get_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) + meta_data["viscosity_nu"] = viscosity.nu + meta_data["viscosity_epsilon"] = viscosity.epsilon +end + +function get_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) + meta_data["viscosity_alpha"] = viscosity.alpha + meta_data["viscosity_beta"] = viscosity.beta + meta_data["viscosity_epsilon"] = viscosity.epsilon +end + +function get_meta_data!(meta_data, system::TotalLagrangianSPHSystem) + meta_data["young_modulus"] = system.young_modulus + meta_data["poisson_ratio"] = system.poisson_ratio + meta_data["lame_lambda"] = system.lame_lambda + meta_data["lame_mu"] = system.lame_mu + meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) + meta_data["smoothing_length"] = system.smoothing_length + + get_meta_data!(meta_data, system.boundary_model, system) +end + +function get_meta_data!(meta_data, system::OpenBoundarySPHSystem) + meta_data["boundary_zone"] = type2string(system.boundary_zone) + meta_data["width"] = round(system.boundary_zone.zone_width, digits = 3) + meta_data["flow_direction"] = system.flow_direction + meta_data["velocity_function"] = type2string(system.reference_velocity) + meta_data["pressure_function"] = type2string(system.reference_pressure) + meta_data["density_function"] = type2string(system.reference_density) +end + +function get_meta_data!(meta_data, system::BoundarySPHSystem) + get_meta_data!(meta_data, system.boundary_model, system) +end + +function get_meta_data!(meta_data, model, system) + return meta_data +end + +function get_meta_data!(meta_data, model::BoundaryModelMonaghanKajtar, system) + meta_data["boundary_model"] = "BoundaryModelMonaghanKajtar" + meta_data["boundary_spacing_ratio"] = model.beta + meta_data["boundary_K"] = model.K +end + +function get_meta_data!(meta_data, model::BoundaryModelDummyParticles, system) + meta_data["boundary_model"] = "BoundaryModelDummyParticles" + meta_data["smoothing_kernel"] = type2string(model.smoothing_kernel) + meta_data["smoothing_length"] = model.smoothing_length + meta_data["density_calculator"] = type2string(model.density_calculator) + meta_data["state_equation"] = type2string(model.state_equation) + meta_data["viscosity_model"] = type2string(model.viscosity) +end + +function get_meta_data!(meta_data, system::BoundaryDEMSystem) + return meta_data +end From d8906ee1c1377ad114f14045e7fd4c16a015cd21 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 24 Mar 2025 10:58:24 +0100 Subject: [PATCH 02/43] Remove old `write_meta_data` parameter from VTK writing functions and callbacks --- examples/fluid/falling_water_spheres_2d.jl | 3 +- examples/fsi/falling_sphere_3d.jl | 1 - examples/fsi/falling_spheres_2d.jl | 3 +- examples/n_body/n_body_system.jl | 2 +- src/callbacks/solution_saving.jl | 21 ++-- src/preprocessing/particle_packing/system.jl | 4 +- src/visualization/write2vtk.jl | 112 +++---------------- 7 files changed, 31 insertions(+), 115 deletions(-) diff --git a/examples/fluid/falling_water_spheres_2d.jl b/examples/fluid/falling_water_spheres_2d.jl index a59d25e259..0eaa5d4e70 100644 --- a/examples/fluid/falling_water_spheres_2d.jl +++ b/examples/fluid/falling_water_spheres_2d.jl @@ -87,8 +87,7 @@ semi = Semidiscretization(sphere_surface_tension, sphere, boundary_system) ode = semidiscretize(semi, tspan) info_callback = InfoCallback(interval=50) -saving_callback = SolutionSavingCallback(dt=0.01, output_directory="out", - prefix="", write_meta_data=true) +saving_callback = SolutionSavingCallback(dt=0.01, output_directory="out", prefix="") callbacks = CallbackSet(info_callback, saving_callback) diff --git a/examples/fsi/falling_sphere_3d.jl b/examples/fsi/falling_sphere_3d.jl index d44911409e..990a8bdf5b 100644 --- a/examples/fsi/falling_sphere_3d.jl +++ b/examples/fsi/falling_sphere_3d.jl @@ -10,5 +10,4 @@ trixi_include(@__MODULE__, solid_smoothing_kernel=WendlandC2Kernel{3}(), sphere_type=RoundSphere(), output_directory="out", prefix="", - write_meta_data=false, # Files with meta data can't be read by meshio tspan=(0.0, 1.0), abstol=1e-6, reltol=1e-3) diff --git a/examples/fsi/falling_spheres_2d.jl b/examples/fsi/falling_spheres_2d.jl index a06056f8f7..4444df5b72 100644 --- a/examples/fsi/falling_spheres_2d.jl +++ b/examples/fsi/falling_spheres_2d.jl @@ -117,8 +117,7 @@ semi = Semidiscretization(fluid_system, boundary_system, solid_system_1, solid_s ode = semidiscretize(semi, tspan) info_callback = InfoCallback(interval=10) -saving_callback = SolutionSavingCallback(dt=0.02, output_directory="out", prefix="", - write_meta_data=true) +saving_callback = SolutionSavingCallback(dt=0.02, output_directory="out", prefix="") callbacks = CallbackSet(info_callback, saving_callback) diff --git a/examples/n_body/n_body_system.jl b/examples/n_body/n_body_system.jl index 2add374d26..9c40b415d4 100644 --- a/examples/n_body/n_body_system.jl +++ b/examples/n_body/n_body_system.jl @@ -110,7 +110,7 @@ end TrixiParticles.vtkname(system::NBodySystem) = "n-body" -function TrixiParticles.write2vtk!(vtk, v, u, t, system::NBodySystem; write_meta_data=true) +function TrixiParticles.write2vtk!(vtk, v, u, t, system::NBodySystem) (; mass) = system vtk["velocity"] = v diff --git a/src/callbacks/solution_saving.jl b/src/callbacks/solution_saving.jl index 742fd8a460..871ea2ef4b 100644 --- a/src/callbacks/solution_saving.jl +++ b/src/callbacks/solution_saving.jl @@ -2,8 +2,7 @@ SolutionSavingCallback(; interval::Integer=0, dt=0.0, save_times=Array{Float64, 1}([]), save_initial_solution=true, save_final_solution=true, output_directory="out", append_timestamp=false, prefix="", - verbose=false, write_meta_data=true, max_coordinates=2^15, - custom_quantities...) + verbose=false, max_coordinates=2^15, custom_quantities...) Callback to save the current numerical solution in VTK format in regular intervals. @@ -28,7 +27,6 @@ To ignore a custom quantity for a specific system, return `nothing`. - `append_timestamp=false`: Append current timestamp to the output directory. - 'prefix=""': Prefix added to the filename. - `custom_quantities...`: Additional user-defined quantities. -- `write_meta_data=true`: Write meta data. - `verbose=false`: Print to standard IO when a file is written. - `max_coordinates=2^15`: The coordinates of particles will be clipped if their absolute values exceed this threshold. @@ -70,7 +68,6 @@ mutable struct SolutionSavingCallback{I, CQ} save_times :: Vector{Float64} save_initial_solution :: Bool save_final_solution :: Bool - write_meta_data :: Bool verbose :: Bool output_directory :: String prefix :: String @@ -84,8 +81,8 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0, save_times=Float64[], save_initial_solution=true, save_final_solution=true, output_directory="out", append_timestamp=false, - prefix="", verbose=false, write_meta_data=true, - max_coordinates=Float64(2^15), custom_quantities...) + prefix="", verbose=false, max_coordinates=Float64(2^15), + custom_quantities...) if (dt > 0 && interval > 0) || (length(save_times) > 0 && (dt > 0 || interval > 0)) throw(ArgumentError("Setting multiple save times for the same solution " * "callback is not possible. Use either `dt`, `interval` or `save_times`.")) @@ -101,8 +98,8 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0, solution_callback = SolutionSavingCallback(interval, Float64.(save_times), save_initial_solution, save_final_solution, - write_meta_data, verbose, output_directory, - prefix, max_coordinates, custom_quantities, + verbose, output_directory, prefix, + max_coordinates, custom_quantities, -1, Ref("UnknownVersion")) if length(save_times) > 0 @@ -162,8 +159,8 @@ end # `affect!` function (solution_callback::SolutionSavingCallback)(integrator) - (; interval, output_directory, custom_quantities, write_meta_data, git_hash, - verbose, prefix, latest_saved_iter, max_coordinates) = solution_callback + (; interval, output_directory, custom_quantities, git_hash, verbose, + prefix, latest_saved_iter, max_coordinates) = solution_callback vu_ode = integrator.u semi = integrator.p @@ -186,8 +183,8 @@ function (solution_callback::SolutionSavingCallback)(integrator) @trixi_timeit timer() "save solution" trixi2vtk(vu_ode, semi, integrator.t; iter, output_directory, prefix, - write_meta_data, git_hash=git_hash[], - max_coordinates, custom_quantities...) + git_hash=git_hash[], max_coordinates, + custom_quantities...) # Tell OrdinaryDiffEq that `u` has not been modified u_modified!(integrator, false) diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index a5b9db6007..6ac8713c08 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -142,10 +142,8 @@ end update_callback_used!(system::ParticlePackingSystem) = system.update_callback_used[] = true -function write2vtk!(vtk, v, u, t, system::ParticlePackingSystem; write_meta_data=true) - if write_meta_data +function write2vtk!(vtk, v, u, t, system::ParticlePackingSystem) vtk["signed_distances"] = system.signed_distances - end end write_v0!(v0, system::ParticlePackingSystem) = v0 .= zero(eltype(system)) diff --git a/src/visualization/write2vtk.jl b/src/visualization/write2vtk.jl index dade585ede..fa2a09e4e6 100644 --- a/src/visualization/write2vtk.jl +++ b/src/visualization/write2vtk.jl @@ -10,7 +10,7 @@ end """ trixi2vtk(vu_ode, semi, t; iter=nothing, output_directory="out", prefix="", - write_meta_data=true, max_coordinates=Inf, custom_quantities...) + max_coordinates=Inf, custom_quantities...) Convert Trixi simulation data to VTK format. @@ -25,7 +25,6 @@ Convert Trixi simulation data to VTK format. separate files. This number is just appended to the filename. - `output_directory="out"`: Output directory path. - `prefix=""`: Prefix for output files. -- `write_meta_data=true`: Write meta data. - `max_coordinates=Inf` The coordinates of particles will be clipped if their absolute values exceed this threshold. - `custom_quantities...`: Additional custom quantities to include in the VTK output. @@ -49,8 +48,7 @@ trixi2vtk(sol.u[end], semi, 0.0, iter=1, my_custom_quantity=kinetic_energy) ``` """ function trixi2vtk(vu_ode, semi, t; iter=nothing, output_directory="out", prefix="", - write_meta_data=true, git_hash=compute_git_hash(), - max_coordinates=Inf, custom_quantities...) + git_hash=compute_git_hash(), max_coordinates=Inf, custom_quantities...) (; systems) = semi v_ode, u_ode = vu_ode.x @@ -70,15 +68,14 @@ function trixi2vtk(vu_ode, semi, t; iter=nothing, output_directory="out", prefix trixi2vtk(v, u, t, system, periodic_box; system_name=filenames[system_index], output_directory, iter, prefix, - write_meta_data, git_hash, max_coordinates, custom_quantities...) + git_hash, max_coordinates, custom_quantities...) end end # Convert data for a single TrixiParticle system to VTK format function trixi2vtk(v_, u_, t, system_, periodic_box; output_directory="out", prefix="", - iter=nothing, system_name=vtkname(system_), write_meta_data=true, - max_coordinates=Inf, git_hash=compute_git_hash(), - custom_quantities...) + iter=nothing, system_name=vtkname(system_), max_coordinates=Inf, + git_hash=compute_git_hash(), custom_quantities...) mkpath(output_directory) # Skip empty systems @@ -118,17 +115,12 @@ function trixi2vtk(v_, u_, t, system_, periodic_box; output_directory="out", pre @trixi_timeit timer() "write to vtk" vtk_grid(file, points, cells) do vtk # dispatches based on the different system types e.g. FluidSystem, TotalLagrangianSPHSystem - write2vtk!(vtk, v, u, t, system, write_meta_data=write_meta_data) + write2vtk!(vtk, v, u, t, system) # Store particle index vtk["index"] = active_particles(system) vtk["time"] = t - if write_meta_data - vtk["solver_version"] = git_hash - vtk["julia_version"] = string(VERSION) - end - # Extract custom quantities for this system for (key, quantity) in custom_quantities value = custom_quantity(quantity, v, u, t, system) @@ -233,13 +225,13 @@ function trixi2vtk(initial_condition::InitialCondition; output_directory="out", pressure=pressure, custom_quantities...) end -function write2vtk!(vtk, v, u, t, system; write_meta_data=true) +function write2vtk!(vtk, v, u, t, system) vtk["velocity"] = view(v, 1:ndims(system), :) return vtk end -function write2vtk!(vtk, v, u, t, system::FluidSystem; write_meta_data=true) +function write2vtk!(vtk, v, u, t, system::FluidSystem) vtk["velocity"] = [current_velocity(v, system, particle) for particle in active_particles(system)] vtk["density"] = [particle_density(v, system, particle) @@ -253,42 +245,6 @@ function write2vtk!(vtk, v, u, t, system::FluidSystem; write_meta_data=true) vtk["neighbor_count"] = system.cache.neighbor_count end - if write_meta_data - vtk["acceleration"] = system.acceleration - vtk["viscosity"] = type2string(system.viscosity) - write2vtk!(vtk, system.viscosity) - vtk["smoothing_kernel"] = type2string(system.smoothing_kernel) - vtk["smoothing_length"] = system.smoothing_length - vtk["density_calculator"] = type2string(system.density_calculator) - - if system isa WeaklyCompressibleSPHSystem - vtk["correction_method"] = type2string(system.correction) - if system.correction isa AkinciFreeSurfaceCorrection - vtk["correction_rho0"] = system.correction.rho0 - end - - if system.state_equation isa StateEquationCole - vtk["state_equation_exponent"] = system.state_equation.exponent - end - - if system.state_equation isa StateEquationIdealGas - vtk["state_equation_gamma"] = system.state_equation.gamma - end - - vtk["state_equation"] = type2string(system.state_equation) - vtk["state_equation_rho0"] = system.state_equation.reference_density - vtk["state_equation_pa"] = system.state_equation.background_pressure - vtk["state_equation_c"] = system.state_equation.sound_speed - vtk["solver"] = "WCSPH" - else - vtk["solver"] = "EDAC" - vtk["sound_speed"] = system.sound_speed - vtk["background_pressure_TVF"] = system.transport_velocity isa Nothing ? - "-" : - system.transport_velocity.background_pressure - end - end - return vtk end @@ -305,7 +261,7 @@ function write2vtk!(vtk, viscosity::ArtificialViscosityMonaghan) vtk["viscosity_epsilon"] = viscosity.epsilon end -function write2vtk!(vtk, v, u, t, system::TotalLagrangianSPHSystem; write_meta_data=true) +function write2vtk!(vtk, v, u, t, system::TotalLagrangianSPHSystem) n_fixed_particles = nparticles(system) - n_moving_particles(system) vtk["velocity"] = hcat(view(v, 1:ndims(system), :), @@ -324,19 +280,10 @@ function write2vtk!(vtk, v, u, t, system::TotalLagrangianSPHSystem; write_meta_d vtk["material_density"] = system.material_density - if write_meta_data - vtk["young_modulus"] = system.young_modulus - vtk["poisson_ratio"] = system.poisson_ratio - vtk["lame_lambda"] = system.lame_lambda - vtk["lame_mu"] = system.lame_mu - vtk["smoothing_kernel"] = type2string(system.smoothing_kernel) - vtk["smoothing_length"] = system.smoothing_length - end - - write2vtk!(vtk, v, u, t, system.boundary_model, system, write_meta_data=write_meta_data) + write2vtk!(vtk, v, u, t, system.boundary_model, system) end -function write2vtk!(vtk, v, u, t, system::OpenBoundarySPHSystem; write_meta_data=true) +function write2vtk!(vtk, v, u, t, system::OpenBoundarySPHSystem) vtk["velocity"] = [current_velocity(v, system, particle) for particle in active_particles(system)] vtk["density"] = [particle_density(v, system, particle) @@ -344,45 +291,22 @@ function write2vtk!(vtk, v, u, t, system::OpenBoundarySPHSystem; write_meta_data vtk["pressure"] = [particle_pressure(v, system, particle) for particle in active_particles(system)] - if write_meta_data - vtk["boundary_zone"] = type2string(first(typeof(system.boundary_zone).parameters)) - vtk["width"] = round(system.boundary_zone.zone_width, digits=3) - vtk["velocity_function"] = type2string(system.reference_velocity) - vtk["pressure_function"] = type2string(system.reference_pressure) - vtk["density_function"] = type2string(system.reference_density) - end - return vtk end -function write2vtk!(vtk, v, u, t, system::BoundarySPHSystem; write_meta_data=true) - write2vtk!(vtk, v, u, t, system.boundary_model, system, write_meta_data=write_meta_data) +function write2vtk!(vtk, v, u, t, system::BoundarySPHSystem) + write2vtk!(vtk, v, u, t, system.boundary_model, system) end -function write2vtk!(vtk, v, u, t, model, system; write_meta_data=true) +function write2vtk!(vtk, v, u, t, model, system) return vtk end -function write2vtk!(vtk, v, u, t, model::BoundaryModelMonaghanKajtar, system; - write_meta_data=true) - if write_meta_data - vtk["boundary_model"] = "BoundaryModelMonaghanKajtar" - vtk["boundary_spacing_ratio"] = model.beta - vtk["boundary_K"] = model.K - end +function write2vtk!(vtk, v, u, t, model::BoundaryModelMonaghanKajtar, system) + return vtk end -function write2vtk!(vtk, v, u, t, model::BoundaryModelDummyParticles, system; - write_meta_data=true) - if write_meta_data - vtk["boundary_model"] = "BoundaryModelDummyParticles" - vtk["smoothing_kernel"] = type2string(model.smoothing_kernel) - vtk["smoothing_length"] = model.smoothing_length - vtk["density_calculator"] = type2string(model.density_calculator) - vtk["state_equation"] = type2string(model.state_equation) - vtk["viscosity_model"] = type2string(model.viscosity) - end - +function write2vtk!(vtk, v, u, t, model::BoundaryModelDummyParticles, system) vtk["hydrodynamic_density"] = [particle_density(v, system, particle) for particle in eachparticle(system)] vtk["pressure"] = model.pressure @@ -398,6 +322,6 @@ function write2vtk!(vtk, v, u, t, model::BoundaryModelDummyParticles, system; end end -function write2vtk!(vtk, v, u, t, system::BoundaryDEMSystem; write_meta_data=true) +function write2vtk!(vtk, v, u, t, system::BoundaryDEMSystem) return vtk end From 8558b13f4fde576d922745a727ff69d4c93fa6b2 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 24 Mar 2025 11:00:57 +0100 Subject: [PATCH 03/43] Add `solver_name` to metadata and format files --- src/preprocessing/particle_packing/system.jl | 2 +- src/visualization/write2json.jl | 177 ++++++++++--------- 2 files changed, 90 insertions(+), 89 deletions(-) diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index 6ac8713c08..a89a5c63a3 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -143,7 +143,7 @@ end update_callback_used!(system::ParticlePackingSystem) = system.update_callback_used[] = true function write2vtk!(vtk, v, u, t, system::ParticlePackingSystem) - vtk["signed_distances"] = system.signed_distances + vtk["signed_distances"] = system.signed_distances end write_v0!(v0, system::ParticlePackingSystem) = v0 .= zero(eltype(system)) diff --git a/src/visualization/write2json.jl b/src/visualization/write2json.jl index 225138bfd3..dc7fb344ac 100644 --- a/src/visualization/write2json.jl +++ b/src/visualization/write2json.jl @@ -17,136 +17,137 @@ setup = :(trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "hydrosta """ function trixi2json(solution_callback, integrator) + semi = integrator.p + (; systems) = semi - semi = integrator.p - (; systems) = semi + output_directory = solution_callback.output_directory + prefix = solution_callback.prefix + git_hash = solution_callback.git_hash - output_directory = solution_callback.output_directory - prefix = solution_callback.prefix - git_hash = solution_callback.git_hash + filenames = system_names(systems) - filenames = system_names(systems) + foreach_system(semi) do system + system_index = system_indices(system, semi) - foreach_system(semi) do system - system_index = system_indices(system, semi) - - trixi2json(system; system_name = filenames[system_index], output_directory, prefix, git_hash) - end + trixi2json(system; system_name=filenames[system_index], output_directory, prefix, + git_hash) + end end function trixi2json(system; system_name, output_directory, prefix, git_hash) - mkpath(output_directory) + mkpath(output_directory) - meta_data = Dict{String, Any}( - "solver_version" => git_hash, - "julia_version" => string(VERSION), - ) + meta_data = Dict{String, Any}( + "solver_name" => "TrixiParticles.jl", + "solver_version" => git_hash, + "julia_version" => string(VERSION) + ) - get_meta_data!(meta_data, system) + get_meta_data!(meta_data, system) - # handle "_" on optional prefix strings - add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") + # handle "_" on optional prefix strings + add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") - # Write metadata to JSON-file - json_file = joinpath(output_directory, - add_opt_str_pre(prefix) * "$(system_name)_metadata.json") + # Write metadata to JSON-file + json_file = joinpath(output_directory, + add_opt_str_pre(prefix) * "$(system_name)_metadata.json") - open(json_file, "w") do file - JSON.print(file, meta_data, 2) - end + open(json_file, "w") do file + JSON.print(file, meta_data, 2) + end end function get_meta_data!(meta_data, system::FluidSystem) - meta_data["acceleration"] = system.acceleration - meta_data["viscosity"] = type2string(system.viscosity) - get_meta_data!(meta_data, system.viscosity) - meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length"] = system.smoothing_length - meta_data["density_calculator"] = type2string(system.density_calculator) - - if system isa WeaklyCompressibleSPHSystem - meta_data["state_equation"] = type2string(system.state_equation) - meta_data["state_equation_rho0"] = system.state_equation.reference_density - meta_data["state_equation_pa"] = system.state_equation.background_pressure - meta_data["state_equation_c"] = system.state_equation.sound_speed - meta_data["solver"] = "WCSPH" - - meta_data["correction_method"] = type2string(system.correction) - if system.correction isa AkinciFreeSurfaceCorrection - meta_data["correction_rho0"] = system.correction.rho0 - end - if system.state_equation isa StateEquationCole - meta_data["state_equation_exponent"] = system.state_equation.exponent - end - if system.state_equation isa StateEquationIdealGas - meta_data["state_equation_gamma"] = system.state_equation.gamma - end - else - meta_data["solver"] = "EDAC" - meta_data["sound_speed"] = system.sound_speed - meta_data["background_pressure_TVF"] = system.transport_velocity isa Nothing ? "-" : - system.transport_velocity.background_pressure - end - - return meta_data + meta_data["acceleration"] = system.acceleration + meta_data["viscosity"] = type2string(system.viscosity) + get_meta_data!(meta_data, system.viscosity) + meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) + meta_data["smoothing_length"] = system.smoothing_length + meta_data["density_calculator"] = type2string(system.density_calculator) + + if system isa WeaklyCompressibleSPHSystem + meta_data["state_equation"] = type2string(system.state_equation) + meta_data["state_equation_rho0"] = system.state_equation.reference_density + meta_data["state_equation_pa"] = system.state_equation.background_pressure + meta_data["state_equation_c"] = system.state_equation.sound_speed + meta_data["solver"] = "WCSPH" + + meta_data["correction_method"] = type2string(system.correction) + if system.correction isa AkinciFreeSurfaceCorrection + meta_data["correction_rho0"] = system.correction.rho0 + end + if system.state_equation isa StateEquationCole + meta_data["state_equation_exponent"] = system.state_equation.exponent + end + if system.state_equation isa StateEquationIdealGas + meta_data["state_equation_gamma"] = system.state_equation.gamma + end + else + meta_data["solver"] = "EDAC" + meta_data["sound_speed"] = system.sound_speed + meta_data["background_pressure_TVF"] = system.transport_velocity isa Nothing ? "-" : + system.transport_velocity.background_pressure + end + + return meta_data end get_meta_data!(meta_data, viscosity::Nothing) = meta_data function get_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) - meta_data["viscosity_nu"] = viscosity.nu - meta_data["viscosity_epsilon"] = viscosity.epsilon + meta_data["viscosity_nu"] = viscosity.nu + meta_data["viscosity_epsilon"] = viscosity.epsilon end function get_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) - meta_data["viscosity_alpha"] = viscosity.alpha - meta_data["viscosity_beta"] = viscosity.beta - meta_data["viscosity_epsilon"] = viscosity.epsilon + meta_data["viscosity_alpha"] = viscosity.alpha + meta_data["viscosity_beta"] = viscosity.beta + meta_data["viscosity_epsilon"] = viscosity.epsilon end function get_meta_data!(meta_data, system::TotalLagrangianSPHSystem) - meta_data["young_modulus"] = system.young_modulus - meta_data["poisson_ratio"] = system.poisson_ratio - meta_data["lame_lambda"] = system.lame_lambda - meta_data["lame_mu"] = system.lame_mu - meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length"] = system.smoothing_length - - get_meta_data!(meta_data, system.boundary_model, system) + meta_data["young_modulus"] = system.young_modulus + meta_data["poisson_ratio"] = system.poisson_ratio + meta_data["lame_lambda"] = system.lame_lambda + meta_data["lame_mu"] = system.lame_mu + meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) + meta_data["smoothing_length"] = system.smoothing_length + + get_meta_data!(meta_data, system.boundary_model, system) end function get_meta_data!(meta_data, system::OpenBoundarySPHSystem) - meta_data["boundary_zone"] = type2string(system.boundary_zone) - meta_data["width"] = round(system.boundary_zone.zone_width, digits = 3) - meta_data["flow_direction"] = system.flow_direction - meta_data["velocity_function"] = type2string(system.reference_velocity) - meta_data["pressure_function"] = type2string(system.reference_pressure) - meta_data["density_function"] = type2string(system.reference_density) + meta_data["boundary_zone"] = type2string(system.boundary_zone) + meta_data["width"] = round(system.boundary_zone.zone_width, digits=3) + meta_data["flow_direction"] = system.flow_direction + meta_data["velocity_function"] = type2string(system.reference_velocity) + meta_data["pressure_function"] = type2string(system.reference_pressure) + meta_data["density_function"] = type2string(system.reference_density) end function get_meta_data!(meta_data, system::BoundarySPHSystem) - get_meta_data!(meta_data, system.boundary_model, system) + get_meta_data!(meta_data, system.boundary_model, system) end function get_meta_data!(meta_data, model, system) - return meta_data + return meta_data end function get_meta_data!(meta_data, model::BoundaryModelMonaghanKajtar, system) - meta_data["boundary_model"] = "BoundaryModelMonaghanKajtar" - meta_data["boundary_spacing_ratio"] = model.beta - meta_data["boundary_K"] = model.K + meta_data["boundary_model"] = "BoundaryModelMonaghanKajtar" + meta_data["boundary_spacing_ratio"] = model.beta + meta_data["boundary_K"] = model.K end function get_meta_data!(meta_data, model::BoundaryModelDummyParticles, system) - meta_data["boundary_model"] = "BoundaryModelDummyParticles" - meta_data["smoothing_kernel"] = type2string(model.smoothing_kernel) - meta_data["smoothing_length"] = model.smoothing_length - meta_data["density_calculator"] = type2string(model.density_calculator) - meta_data["state_equation"] = type2string(model.state_equation) - meta_data["viscosity_model"] = type2string(model.viscosity) + meta_data["boundary_model"] = "BoundaryModelDummyParticles" + meta_data["smoothing_kernel"] = type2string(model.smoothing_kernel) + meta_data["smoothing_length"] = model.smoothing_length + meta_data["density_calculator"] = type2string(model.density_calculator) + meta_data["state_equation"] = type2string(model.state_equation) + meta_data["viscosity_model"] = type2string(model.viscosity) end function get_meta_data!(meta_data, system::BoundaryDEMSystem) - return meta_data + return meta_data end From 8803ef900375a12680102e8962c94de76e252663 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 14 Apr 2025 11:46:22 +0200 Subject: [PATCH 04/43] update `write2json.jl` to match merge --- src/visualization/write2json.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/visualization/write2json.jl b/src/visualization/write2json.jl index dc7fb344ac..8dd6f07e5f 100644 --- a/src/visualization/write2json.jl +++ b/src/visualization/write2json.jl @@ -62,7 +62,7 @@ function get_meta_data!(meta_data, system::FluidSystem) meta_data["viscosity"] = type2string(system.viscosity) get_meta_data!(meta_data, system.viscosity) meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length"] = system.smoothing_length + meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor meta_data["density_calculator"] = type2string(system.density_calculator) if system isa WeaklyCompressibleSPHSystem @@ -111,7 +111,7 @@ function get_meta_data!(meta_data, system::TotalLagrangianSPHSystem) meta_data["lame_lambda"] = system.lame_lambda meta_data["lame_mu"] = system.lame_mu meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length"] = system.smoothing_length + meta_data["smoothing_length_factor"] = initial_smoothing_length(system) / particle_spacing(system, 1) get_meta_data!(meta_data, system.boundary_model, system) end @@ -129,7 +129,7 @@ function get_meta_data!(meta_data, system::BoundarySPHSystem) get_meta_data!(meta_data, system.boundary_model, system) end -function get_meta_data!(meta_data, model, system) +function get_meta_data!(meta_data, model::Nothing, system) return meta_data end From b86e2d64f3e115966e744c0e773fb9c18b33dede Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 19 May 2025 11:13:13 +0200 Subject: [PATCH 05/43] rename file --- src/{visualization/write2json.jl => io/write_json.jl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{visualization/write2json.jl => io/write_json.jl} (100%) diff --git a/src/visualization/write2json.jl b/src/io/write_json.jl similarity index 100% rename from src/visualization/write2json.jl rename to src/io/write_json.jl From 164b56e4cb1c83f3bdba4fde9102d7133a6f322b Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 19 May 2025 11:22:49 +0200 Subject: [PATCH 06/43] update references --- src/io/io.jl | 1 + src/io/write_vtk.jl | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/io/io.jl b/src/io/io.jl index 380151bcff..85c484c8e4 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -1,2 +1,3 @@ include("write_vtk.jl") +include("write_json.jl") include("read_vtk.jl") diff --git a/src/io/write_vtk.jl b/src/io/write_vtk.jl index ad9a9bfcbf..d0886c8616 100644 --- a/src/io/write_vtk.jl +++ b/src/io/write_vtk.jl @@ -365,8 +365,7 @@ function write2vtk!(vtk, v, u, t, model::BoundaryModelMonaghanKajtar, system) return vtk end -function write2vtk!(vtk, v, u, t, model::BoundaryModelDummyParticles, system; - write_meta_data=true) +function write2vtk!(vtk, v, u, t, model::BoundaryModelDummyParticles, system) vtk["hydrodynamic_density"] = current_density(v, system) vtk["pressure"] = model.pressure From 2165d3747a9683a7cac96e3092c627ea10869330 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 19 May 2025 11:29:48 +0200 Subject: [PATCH 07/43] rename function --- src/io/write_json.jl | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/io/write_json.jl b/src/io/write_json.jl index 8dd6f07e5f..199bb65cd0 100644 --- a/src/io/write_json.jl +++ b/src/io/write_json.jl @@ -43,7 +43,7 @@ function trixi2json(system; system_name, output_directory, prefix, git_hash) "julia_version" => string(VERSION) ) - get_meta_data!(meta_data, system) + write2json!(meta_data, system) # handle "_" on optional prefix strings add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") @@ -57,10 +57,10 @@ function trixi2json(system; system_name, output_directory, prefix, git_hash) end end -function get_meta_data!(meta_data, system::FluidSystem) +function write2json!(meta_data, system::FluidSystem) meta_data["acceleration"] = system.acceleration meta_data["viscosity"] = type2string(system.viscosity) - get_meta_data!(meta_data, system.viscosity) + write2json!(meta_data, system.viscosity) meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor meta_data["density_calculator"] = type2string(system.density_calculator) @@ -92,20 +92,20 @@ function get_meta_data!(meta_data, system::FluidSystem) return meta_data end -get_meta_data!(meta_data, viscosity::Nothing) = meta_data +write2json!(meta_data, viscosity::Nothing) = meta_data -function get_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) +function write2json!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) meta_data["viscosity_nu"] = viscosity.nu meta_data["viscosity_epsilon"] = viscosity.epsilon end -function get_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) +function write2json!(meta_data, viscosity::ArtificialViscosityMonaghan) meta_data["viscosity_alpha"] = viscosity.alpha meta_data["viscosity_beta"] = viscosity.beta meta_data["viscosity_epsilon"] = viscosity.epsilon end -function get_meta_data!(meta_data, system::TotalLagrangianSPHSystem) +function write2json!(meta_data, system::TotalLagrangianSPHSystem) meta_data["young_modulus"] = system.young_modulus meta_data["poisson_ratio"] = system.poisson_ratio meta_data["lame_lambda"] = system.lame_lambda @@ -113,10 +113,10 @@ function get_meta_data!(meta_data, system::TotalLagrangianSPHSystem) meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) meta_data["smoothing_length_factor"] = initial_smoothing_length(system) / particle_spacing(system, 1) - get_meta_data!(meta_data, system.boundary_model, system) + write2json!(meta_data, system.boundary_model, system) end -function get_meta_data!(meta_data, system::OpenBoundarySPHSystem) +function write2json!(meta_data, system::OpenBoundarySPHSystem) meta_data["boundary_zone"] = type2string(system.boundary_zone) meta_data["width"] = round(system.boundary_zone.zone_width, digits=3) meta_data["flow_direction"] = system.flow_direction @@ -125,21 +125,21 @@ function get_meta_data!(meta_data, system::OpenBoundarySPHSystem) meta_data["density_function"] = type2string(system.reference_density) end -function get_meta_data!(meta_data, system::BoundarySPHSystem) - get_meta_data!(meta_data, system.boundary_model, system) +function write2json!(meta_data, system::BoundarySPHSystem) + write2json!(meta_data, system.boundary_model, system) end -function get_meta_data!(meta_data, model::Nothing, system) +function write2json!(meta_data, model::Nothing, system) return meta_data end -function get_meta_data!(meta_data, model::BoundaryModelMonaghanKajtar, system) +function write2json!(meta_data, model::BoundaryModelMonaghanKajtar, system) meta_data["boundary_model"] = "BoundaryModelMonaghanKajtar" meta_data["boundary_spacing_ratio"] = model.beta meta_data["boundary_K"] = model.K end -function get_meta_data!(meta_data, model::BoundaryModelDummyParticles, system) +function write2json!(meta_data, model::BoundaryModelDummyParticles, system) meta_data["boundary_model"] = "BoundaryModelDummyParticles" meta_data["smoothing_kernel"] = type2string(model.smoothing_kernel) meta_data["smoothing_length"] = model.smoothing_length @@ -148,6 +148,6 @@ function get_meta_data!(meta_data, model::BoundaryModelDummyParticles, system) meta_data["viscosity_model"] = type2string(model.viscosity) end -function get_meta_data!(meta_data, system::BoundaryDEMSystem) +function write2json!(meta_data, system::BoundaryDEMSystem) return meta_data end From 51317e3e31d2637483258c68f81b9a248d6ff00a Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 19 May 2025 11:30:24 +0200 Subject: [PATCH 08/43] Refactor write2vtk! --- src/preprocessing/particle_packing/system.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index c9e8c5c296..cc63142c66 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -217,12 +217,13 @@ end update_callback_used!(system::ParticlePackingSystem) = system.update_callback_used[] = true -function write2vtk!(vtk, v, u, t, system::ParticlePackingSystem; write_meta_data=true) +function write2vtk!(vtk, v, u, t, system::ParticlePackingSystem) vtk["velocity"] = [advection_velocity(v, system, particle) for particle in active_particles(system)] - if write_meta_data - vtk["signed_distances"] = system.signed_distances - end +end + +function write2json!(vtk, v, u, t, system::ParticlePackingSystem) + meta_data["signed_distances"] = system.signed_distances end # Skip for fixed systems From 8f6eda96fc6f0a043ac47ab1b1ba6660189f6a5a Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 19 May 2025 11:35:39 +0200 Subject: [PATCH 09/43] formatting --- src/callbacks/solution_saving.jl | 2 +- src/io/write_json.jl | 3 ++- src/io/write_vtk.jl | 5 +++-- src/preprocessing/particle_packing/system.jl | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/callbacks/solution_saving.jl b/src/callbacks/solution_saving.jl index 4a6af94c69..8a978be518 100644 --- a/src/callbacks/solution_saving.jl +++ b/src/callbacks/solution_saving.jl @@ -154,7 +154,7 @@ end # `affect!` function (solution_callback::SolutionSavingCallback)(integrator) (; interval, output_directory, custom_quantities, git_hash, verbose, - prefix, latest_saved_iter, max_coordinates) = solution_callback + prefix, latest_saved_iter, max_coordinates) = solution_callback vu_ode = integrator.u semi = integrator.p diff --git a/src/io/write_json.jl b/src/io/write_json.jl index 199bb65cd0..4ddab8894b 100644 --- a/src/io/write_json.jl +++ b/src/io/write_json.jl @@ -111,7 +111,8 @@ function write2json!(meta_data, system::TotalLagrangianSPHSystem) meta_data["lame_lambda"] = system.lame_lambda meta_data["lame_mu"] = system.lame_mu meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length_factor"] = initial_smoothing_length(system) / particle_spacing(system, 1) + meta_data["smoothing_length_factor"] = initial_smoothing_length(system) / + particle_spacing(system, 1) write2json!(meta_data, system.boundary_model, system) end diff --git a/src/io/write_vtk.jl b/src/io/write_vtk.jl index d0886c8616..0799184dde 100644 --- a/src/io/write_vtk.jl +++ b/src/io/write_vtk.jl @@ -71,7 +71,8 @@ end # Convert data for a single TrixiParticle system to VTK format function trixi2vtk(system_, v_ode_, u_ode_, semi_, t, periodic_box; output_directory="out", - prefix="", iter=nothing, system_name=vtkname(system_), max_coordinates=Inf, git_hash=compute_git_hash(), + prefix="", iter=nothing, system_name=vtkname(system_), + max_coordinates=Inf, git_hash=compute_git_hash(), custom_quantities...) mkpath(output_directory) @@ -123,7 +124,7 @@ function trixi2vtk(system_, v_ode_, u_ode_, semi_, t, periodic_box; output_direc vtk["ndims"] = ndims(system) vtk["particle_spacing"] = [particle_spacing(system, particle) - for particle in active_particles(system)] + for particle in active_particles(system)] # Extract custom quantities for this system for (key, quantity) in custom_quantities diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index cc63142c66..88a1eaafdf 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -223,7 +223,7 @@ function write2vtk!(vtk, v, u, t, system::ParticlePackingSystem) end function write2json!(vtk, v, u, t, system::ParticlePackingSystem) - meta_data["signed_distances"] = system.signed_distances + meta_data["signed_distances"] = system.signed_distances end # Skip for fixed systems From 7825eb9688fc4621b27dc7a3e4c4e809ef1803c9 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Tue, 20 May 2025 09:49:05 +0200 Subject: [PATCH 10/43] refactor functions --- src/TrixiParticles.jl | 3 +- src/callbacks/post_process.jl | 1 + src/callbacks/solution_saving.jl | 5 +- src/io/io.jl | 140 +++++++++++++++++++++++++++- src/io/write_json.jl | 154 ------------------------------- 5 files changed, 143 insertions(+), 160 deletions(-) delete mode 100644 src/io/write_json.jl diff --git a/src/TrixiParticles.jl b/src/TrixiParticles.jl index 410dbd076b..e0d3268979 100644 --- a/src/TrixiParticles.jl +++ b/src/TrixiParticles.jl @@ -83,7 +83,8 @@ export BoundaryModelMonaghanKajtar, BoundaryModelDummyParticles, AdamiPressureEx export HertzContactModel, LinearContactModel export BoundaryMovement export examples_dir, validation_dir -export trixi2vtk, trixi2json, vtk2trixi +export trixi2vtk, vtk2trixi +export write_meta_data export RectangularTank, RectangularShape, SphereShape, ComplexShape export ParticlePackingSystem, SignedDistanceField export WindingNumberHormann, WindingNumberJacobson diff --git a/src/callbacks/post_process.jl b/src/callbacks/post_process.jl index 9370bcdadc..3d2404c0e2 100644 --- a/src/callbacks/post_process.jl +++ b/src/callbacks/post_process.jl @@ -216,6 +216,7 @@ function initialize_postprocess_callback!(cb::PostprocessCallback, u, t, integra # Apply the callback cb(integrator) + write_meta_data(cb, integrator) return cb end diff --git a/src/callbacks/solution_saving.jl b/src/callbacks/solution_saving.jl index 8a978be518..deab0a0d13 100644 --- a/src/callbacks/solution_saving.jl +++ b/src/callbacks/solution_saving.jl @@ -130,10 +130,7 @@ function initialize_save_cb!(solution_callback::SolutionSavingCallback, u, t, in solution_callback.latest_saved_iter = -1 solution_callback.git_hash[] = compute_git_hash() - # Write metadata to JSON-file - if integrator.iter == 0 - trixi2json(solution_callback, integrator) - end + write_meta_data(solution_callback, integrator) # Save initial solution if solution_callback.save_initial_solution diff --git a/src/io/io.jl b/src/io/io.jl index 85c484c8e4..57f7daf2c9 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -1,3 +1,141 @@ include("write_vtk.jl") -include("write_json.jl") include("read_vtk.jl") + +function write_meta_data(callback::Union{SolutionSavingCallback, PostprocessCallback}, + integrator) + semi = integrator.p + (; systems) = semi + + output_directory = callback.output_directory + prefix = callback.prefix + git_hash = callback.git_hash + + filenames = system_names(systems) + + foreach_system(semi) do system + system_index = system_indices(system, semi) + + write_meta_data(system; system_name=filenames[system_index], output_directory, + prefix, + git_hash) + end +end + +function write_meta_data(system; system_name, output_directory, prefix, git_hash) + mkpath(output_directory) + + meta_data = Dict{String, Any}( + "solver_name" => "TrixiParticles.jl", + "solver_version" => git_hash, + "julia_version" => string(VERSION) + ) + + get_meta_data!(meta_data, system) + + # handle "_" on optional prefix strings + add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") + + # Write metadata to JSON-file + json_file = joinpath(output_directory, + add_opt_str_pre(prefix) * "$(system_name)_metadata.json") + + open(json_file, "w") do file + JSON.print(file, meta_data, 2) + end +end + +function get_meta_data!(meta_data, system::FluidSystem) + meta_data["acceleration"] = system.acceleration + meta_data["viscosity"] = type2string(system.viscosity) + get_meta_data!(meta_data, system.viscosity) + meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) + meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor + meta_data["density_calculator"] = type2string(system.density_calculator) + + if system isa WeaklyCompressibleSPHSystem + meta_data["state_equation"] = type2string(system.state_equation) + meta_data["state_equation_rho0"] = system.state_equation.reference_density + meta_data["state_equation_pa"] = system.state_equation.background_pressure + meta_data["state_equation_c"] = system.state_equation.sound_speed + meta_data["solver"] = "WCSPH" + + meta_data["correction_method"] = type2string(system.correction) + if system.correction isa AkinciFreeSurfaceCorrection + meta_data["correction_rho0"] = system.correction.rho0 + end + if system.state_equation isa StateEquationCole + meta_data["state_equation_exponent"] = system.state_equation.exponent + end + if system.state_equation isa StateEquationIdealGas + meta_data["state_equation_gamma"] = system.state_equation.gamma + end + else + meta_data["solver"] = "EDAC" + meta_data["sound_speed"] = system.sound_speed + meta_data["background_pressure_TVF"] = system.transport_velocity isa Nothing ? "-" : + system.transport_velocity.background_pressure + end + + return meta_data +end + +get_meta_data!(meta_data, viscosity::Nothing) = meta_data + +function get_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) + meta_data["viscosity_nu"] = viscosity.nu + meta_data["viscosity_epsilon"] = viscosity.epsilon +end + +function get_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) + meta_data["viscosity_alpha"] = viscosity.alpha + meta_data["viscosity_beta"] = viscosity.beta + meta_data["viscosity_epsilon"] = viscosity.epsilon +end + +function get_meta_data!(meta_data, system::TotalLagrangianSPHSystem) + meta_data["young_modulus"] = system.young_modulus + meta_data["poisson_ratio"] = system.poisson_ratio + meta_data["lame_lambda"] = system.lame_lambda + meta_data["lame_mu"] = system.lame_mu + meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) + meta_data["smoothing_length_factor"] = initial_smoothing_length(system) / + particle_spacing(system, 1) + + get_meta_data!(meta_data, system.boundary_model, system) +end + +function get_meta_data!(meta_data, system::OpenBoundarySPHSystem) + meta_data["boundary_zone"] = type2string(system.boundary_zone) + meta_data["width"] = round(system.boundary_zone.zone_width, digits=3) + meta_data["flow_direction"] = system.flow_direction + meta_data["velocity_function"] = type2string(system.reference_velocity) + meta_data["pressure_function"] = type2string(system.reference_pressure) + meta_data["density_function"] = type2string(system.reference_density) +end + +function get_meta_data!(meta_data, system::BoundarySPHSystem) + get_meta_data!(meta_data, system.boundary_model, system) +end + +function get_meta_data!(meta_data, model::Nothing, system) + return meta_data +end + +function get_meta_data!(meta_data, model::BoundaryModelMonaghanKajtar, system) + meta_data["boundary_model"] = "BoundaryModelMonaghanKajtar" + meta_data["boundary_spacing_ratio"] = model.beta + meta_data["boundary_K"] = model.K +end + +function get_meta_data!(meta_data, model::BoundaryModelDummyParticles, system) + meta_data["boundary_model"] = "BoundaryModelDummyParticles" + meta_data["smoothing_kernel"] = type2string(model.smoothing_kernel) + meta_data["smoothing_length"] = model.smoothing_length + meta_data["density_calculator"] = type2string(model.density_calculator) + meta_data["state_equation"] = type2string(model.state_equation) + meta_data["viscosity_model"] = type2string(model.viscosity) +end + +function get_meta_data!(meta_data, system::BoundaryDEMSystem) + return meta_data +end diff --git a/src/io/write_json.jl b/src/io/write_json.jl deleted file mode 100644 index 4ddab8894b..0000000000 --- a/src/io/write_json.jl +++ /dev/null @@ -1,154 +0,0 @@ -""" - trixi2json(solution_callback, integrator) - -Write simulation metadata to a JSON-file. - -# Arguments -- `solution_callback`: Callback storing metadata and output settings. -- `integrator`: ODE integrator containing simulation data. - -# Example -```jldoctest; output = false, saving_callback = SolutionSavingCallback(dt = 0.1, output_directory = "output", prefix = "solution"), -setup = :(trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "hydrostatic_water_column_2d.jl"), tspan = (0.0, 0.01), callbacks = saving_callback)) - -# output - -``` -""" - -function trixi2json(solution_callback, integrator) - semi = integrator.p - (; systems) = semi - - output_directory = solution_callback.output_directory - prefix = solution_callback.prefix - git_hash = solution_callback.git_hash - - filenames = system_names(systems) - - foreach_system(semi) do system - system_index = system_indices(system, semi) - - trixi2json(system; system_name=filenames[system_index], output_directory, prefix, - git_hash) - end -end - -function trixi2json(system; system_name, output_directory, prefix, git_hash) - mkpath(output_directory) - - meta_data = Dict{String, Any}( - "solver_name" => "TrixiParticles.jl", - "solver_version" => git_hash, - "julia_version" => string(VERSION) - ) - - write2json!(meta_data, system) - - # handle "_" on optional prefix strings - add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") - - # Write metadata to JSON-file - json_file = joinpath(output_directory, - add_opt_str_pre(prefix) * "$(system_name)_metadata.json") - - open(json_file, "w") do file - JSON.print(file, meta_data, 2) - end -end - -function write2json!(meta_data, system::FluidSystem) - meta_data["acceleration"] = system.acceleration - meta_data["viscosity"] = type2string(system.viscosity) - write2json!(meta_data, system.viscosity) - meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor - meta_data["density_calculator"] = type2string(system.density_calculator) - - if system isa WeaklyCompressibleSPHSystem - meta_data["state_equation"] = type2string(system.state_equation) - meta_data["state_equation_rho0"] = system.state_equation.reference_density - meta_data["state_equation_pa"] = system.state_equation.background_pressure - meta_data["state_equation_c"] = system.state_equation.sound_speed - meta_data["solver"] = "WCSPH" - - meta_data["correction_method"] = type2string(system.correction) - if system.correction isa AkinciFreeSurfaceCorrection - meta_data["correction_rho0"] = system.correction.rho0 - end - if system.state_equation isa StateEquationCole - meta_data["state_equation_exponent"] = system.state_equation.exponent - end - if system.state_equation isa StateEquationIdealGas - meta_data["state_equation_gamma"] = system.state_equation.gamma - end - else - meta_data["solver"] = "EDAC" - meta_data["sound_speed"] = system.sound_speed - meta_data["background_pressure_TVF"] = system.transport_velocity isa Nothing ? "-" : - system.transport_velocity.background_pressure - end - - return meta_data -end - -write2json!(meta_data, viscosity::Nothing) = meta_data - -function write2json!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) - meta_data["viscosity_nu"] = viscosity.nu - meta_data["viscosity_epsilon"] = viscosity.epsilon -end - -function write2json!(meta_data, viscosity::ArtificialViscosityMonaghan) - meta_data["viscosity_alpha"] = viscosity.alpha - meta_data["viscosity_beta"] = viscosity.beta - meta_data["viscosity_epsilon"] = viscosity.epsilon -end - -function write2json!(meta_data, system::TotalLagrangianSPHSystem) - meta_data["young_modulus"] = system.young_modulus - meta_data["poisson_ratio"] = system.poisson_ratio - meta_data["lame_lambda"] = system.lame_lambda - meta_data["lame_mu"] = system.lame_mu - meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length_factor"] = initial_smoothing_length(system) / - particle_spacing(system, 1) - - write2json!(meta_data, system.boundary_model, system) -end - -function write2json!(meta_data, system::OpenBoundarySPHSystem) - meta_data["boundary_zone"] = type2string(system.boundary_zone) - meta_data["width"] = round(system.boundary_zone.zone_width, digits=3) - meta_data["flow_direction"] = system.flow_direction - meta_data["velocity_function"] = type2string(system.reference_velocity) - meta_data["pressure_function"] = type2string(system.reference_pressure) - meta_data["density_function"] = type2string(system.reference_density) -end - -function write2json!(meta_data, system::BoundarySPHSystem) - write2json!(meta_data, system.boundary_model, system) -end - -function write2json!(meta_data, model::Nothing, system) - return meta_data -end - -function write2json!(meta_data, model::BoundaryModelMonaghanKajtar, system) - meta_data["boundary_model"] = "BoundaryModelMonaghanKajtar" - meta_data["boundary_spacing_ratio"] = model.beta - meta_data["boundary_K"] = model.K -end - -function write2json!(meta_data, model::BoundaryModelDummyParticles, system) - meta_data["boundary_model"] = "BoundaryModelDummyParticles" - meta_data["smoothing_kernel"] = type2string(model.smoothing_kernel) - meta_data["smoothing_length"] = model.smoothing_length - meta_data["density_calculator"] = type2string(model.density_calculator) - meta_data["state_equation"] = type2string(model.state_equation) - meta_data["viscosity_model"] = type2string(model.viscosity) -end - -function write2json!(meta_data, system::BoundaryDEMSystem) - return meta_data -end From 251eaf290c5f4f61d7c903d1bed94988fc1b6a6c Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 2 Jun 2025 13:46:43 +0200 Subject: [PATCH 11/43] implement suggestions --- src/TrixiParticles.jl | 1 - src/callbacks/post_process.jl | 1 + src/io/io.jl | 30 ++++++++++---------- src/io/write_vtk.jl | 2 +- src/preprocessing/particle_packing/system.jl | 5 +--- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/TrixiParticles.jl b/src/TrixiParticles.jl index e0d3268979..bab7e7a813 100644 --- a/src/TrixiParticles.jl +++ b/src/TrixiParticles.jl @@ -84,7 +84,6 @@ export HertzContactModel, LinearContactModel export BoundaryMovement export examples_dir, validation_dir export trixi2vtk, vtk2trixi -export write_meta_data export RectangularTank, RectangularShape, SphereShape, ComplexShape export ParticlePackingSystem, SignedDistanceField export WindingNumberHormann, WindingNumberJacobson diff --git a/src/callbacks/post_process.jl b/src/callbacks/post_process.jl index 3d2404c0e2..7fdce08bfe 100644 --- a/src/callbacks/post_process.jl +++ b/src/callbacks/post_process.jl @@ -217,6 +217,7 @@ function initialize_postprocess_callback!(cb::PostprocessCallback, u, t, integra cb(integrator) write_meta_data(cb, integrator) + return cb end diff --git a/src/io/io.jl b/src/io/io.jl index 57f7daf2c9..71210e72fc 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -30,7 +30,7 @@ function write_meta_data(system; system_name, output_directory, prefix, git_hash "julia_version" => string(VERSION) ) - get_meta_data!(meta_data, system) + add_meta_data!(meta_data, system) # handle "_" on optional prefix strings add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") @@ -44,10 +44,10 @@ function write_meta_data(system; system_name, output_directory, prefix, git_hash end end -function get_meta_data!(meta_data, system::FluidSystem) +function add_meta_data!(meta_data, system::FluidSystem) meta_data["acceleration"] = system.acceleration meta_data["viscosity"] = type2string(system.viscosity) - get_meta_data!(meta_data, system.viscosity) + add_meta_data!(meta_data, system.viscosity) meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor meta_data["density_calculator"] = type2string(system.density_calculator) @@ -79,20 +79,20 @@ function get_meta_data!(meta_data, system::FluidSystem) return meta_data end -get_meta_data!(meta_data, viscosity::Nothing) = meta_data +add_meta_data!(meta_data, viscosity::Nothing) = meta_data -function get_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) +function add_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) meta_data["viscosity_nu"] = viscosity.nu meta_data["viscosity_epsilon"] = viscosity.epsilon end -function get_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) +function add_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) meta_data["viscosity_alpha"] = viscosity.alpha meta_data["viscosity_beta"] = viscosity.beta meta_data["viscosity_epsilon"] = viscosity.epsilon end -function get_meta_data!(meta_data, system::TotalLagrangianSPHSystem) +function add_meta_data!(meta_data, system::TotalLagrangianSPHSystem) meta_data["young_modulus"] = system.young_modulus meta_data["poisson_ratio"] = system.poisson_ratio meta_data["lame_lambda"] = system.lame_lambda @@ -101,10 +101,10 @@ function get_meta_data!(meta_data, system::TotalLagrangianSPHSystem) meta_data["smoothing_length_factor"] = initial_smoothing_length(system) / particle_spacing(system, 1) - get_meta_data!(meta_data, system.boundary_model, system) + add_meta_data!(meta_data, system.boundary_model, system) end -function get_meta_data!(meta_data, system::OpenBoundarySPHSystem) +function add_meta_data!(meta_data, system::OpenBoundarySPHSystem) meta_data["boundary_zone"] = type2string(system.boundary_zone) meta_data["width"] = round(system.boundary_zone.zone_width, digits=3) meta_data["flow_direction"] = system.flow_direction @@ -113,21 +113,21 @@ function get_meta_data!(meta_data, system::OpenBoundarySPHSystem) meta_data["density_function"] = type2string(system.reference_density) end -function get_meta_data!(meta_data, system::BoundarySPHSystem) - get_meta_data!(meta_data, system.boundary_model, system) +function add_meta_data!(meta_data, system::BoundarySPHSystem) + add_meta_data!(meta_data, system.boundary_model, system) end -function get_meta_data!(meta_data, model::Nothing, system) +function add_meta_data!(meta_data, model::Nothing, system) return meta_data end -function get_meta_data!(meta_data, model::BoundaryModelMonaghanKajtar, system) +function add_meta_data!(meta_data, model::BoundaryModelMonaghanKajtar, system) meta_data["boundary_model"] = "BoundaryModelMonaghanKajtar" meta_data["boundary_spacing_ratio"] = model.beta meta_data["boundary_K"] = model.K end -function get_meta_data!(meta_data, model::BoundaryModelDummyParticles, system) +function add_meta_data!(meta_data, model::BoundaryModelDummyParticles, system) meta_data["boundary_model"] = "BoundaryModelDummyParticles" meta_data["smoothing_kernel"] = type2string(model.smoothing_kernel) meta_data["smoothing_length"] = model.smoothing_length @@ -136,6 +136,6 @@ function get_meta_data!(meta_data, model::BoundaryModelDummyParticles, system) meta_data["viscosity_model"] = type2string(model.viscosity) end -function get_meta_data!(meta_data, system::BoundaryDEMSystem) +function add_meta_data!(meta_data, system::BoundaryDEMSystem) return meta_data end diff --git a/src/io/write_vtk.jl b/src/io/write_vtk.jl index 0799184dde..f48b46db15 100644 --- a/src/io/write_vtk.jl +++ b/src/io/write_vtk.jl @@ -115,7 +115,7 @@ function trixi2vtk(system_, v_ode_, u_ode_, semi_, t, periodic_box; output_direc end @trixi_timeit timer() "write to vtk" vtk_grid(file, points, cells) do vtk - # dispatches based on the different system types e.g. FluidSystem, TotalLagrangianSPHSystem + # Dispatches based on the different system types e.g. FluidSystem, TotalLagrangianSPHSystem write2vtk!(vtk, v, u, t, system) # Store particle index diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index bf52a78427..311ed6554e 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -226,10 +226,7 @@ update_callback_used!(system::ParticlePackingSystem) = system.update_callback_us function write2vtk!(vtk, v, u, t, system::ParticlePackingSystem) vtk["velocity"] = [advection_velocity(v, system, particle) for particle in active_particles(system)] -end - -function write2json!(vtk, v, u, t, system::ParticlePackingSystem) - meta_data["signed_distances"] = system.signed_distances + vtk["signed_distances"] = system.signed_distances end # Skip for fixed systems From fecc01fc9fe76125e52e5c17dcfed6b5075cd8d8 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 2 Jun 2025 15:16:47 +0200 Subject: [PATCH 12/43] fix bugs --- src/io/io.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/io/io.jl b/src/io/io.jl index 71210e72fc..051c0d641e 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -7,7 +7,7 @@ function write_meta_data(callback::Union{SolutionSavingCallback, PostprocessCall (; systems) = semi output_directory = callback.output_directory - prefix = callback.prefix + prefix = hasproperty(callback, :prefix) ? callback.prefix : "" git_hash = callback.git_hash filenames = system_names(systems) @@ -44,6 +44,14 @@ function write_meta_data(system; system_name, output_directory, prefix, git_hash end end +function add_meta_data!(meta_data, system) + return meta_data +end + +function add_meta_data!(meta_data, system::DEMSystem) + return meta_data +end + function add_meta_data!(meta_data, system::FluidSystem) meta_data["acceleration"] = system.acceleration meta_data["viscosity"] = type2string(system.viscosity) @@ -107,7 +115,6 @@ end function add_meta_data!(meta_data, system::OpenBoundarySPHSystem) meta_data["boundary_zone"] = type2string(system.boundary_zone) meta_data["width"] = round(system.boundary_zone.zone_width, digits=3) - meta_data["flow_direction"] = system.flow_direction meta_data["velocity_function"] = type2string(system.reference_velocity) meta_data["pressure_function"] = type2string(system.reference_pressure) meta_data["density_function"] = type2string(system.reference_density) From 3a399fff6315b63fb9b276d52b8df5a94a56124b Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Tue, 3 Jun 2025 11:01:33 +0200 Subject: [PATCH 13/43] add add_meta_data! function for `system::ParticlePackingSystem` --- src/preprocessing/particle_packing/particle_packing.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/preprocessing/particle_packing/particle_packing.jl b/src/preprocessing/particle_packing/particle_packing.jl index c0ffd2b8d0..1ea1856d87 100644 --- a/src/preprocessing/particle_packing/particle_packing.jl +++ b/src/preprocessing/particle_packing/particle_packing.jl @@ -2,3 +2,7 @@ include("nhs_faces.jl") include("signed_distance.jl") include("system.jl") include("rhs.jl") + +function add_meta_data!(meta_data, system::ParticlePackingSystem) + return meta_data +end From 9868c4aff5556397d133d223df0ff7865371f7ca Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Tue, 3 Jun 2025 11:17:10 +0200 Subject: [PATCH 14/43] relocate `add_meta_data!` to `system.jl` --- src/preprocessing/particle_packing/particle_packing.jl | 4 ---- src/preprocessing/particle_packing/system.jl | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/preprocessing/particle_packing/particle_packing.jl b/src/preprocessing/particle_packing/particle_packing.jl index 1ea1856d87..c0ffd2b8d0 100644 --- a/src/preprocessing/particle_packing/particle_packing.jl +++ b/src/preprocessing/particle_packing/particle_packing.jl @@ -2,7 +2,3 @@ include("nhs_faces.jl") include("signed_distance.jl") include("system.jl") include("rhs.jl") - -function add_meta_data!(meta_data, system::ParticlePackingSystem) - return meta_data -end diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index 311ed6554e..8b713bd407 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -229,6 +229,10 @@ function write2vtk!(vtk, v, u, t, system::ParticlePackingSystem) vtk["signed_distances"] = system.signed_distances end +function add_meta_data!(meta_data, system::ParticlePackingSystem) + return meta_data +end + # Skip for fixed systems write_u0!(u0, system::ParticlePackingSystem{<:Any, true}) = u0 From 45940d97c0a75a29812939ff559828cc62002f22 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Wed, 4 Jun 2025 09:37:22 +0200 Subject: [PATCH 15/43] formatting --- src/io/io.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/io/io.jl b/src/io/io.jl index 051c0d641e..2511c8e825 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -16,8 +16,7 @@ function write_meta_data(callback::Union{SolutionSavingCallback, PostprocessCall system_index = system_indices(system, semi) write_meta_data(system; system_name=filenames[system_index], output_directory, - prefix, - git_hash) + prefix, git_hash) end end From 254bc9ac6fe6304e43cbb125d84c5034fe790fc8 Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Fri, 13 Jun 2025 15:52:21 +0200 Subject: [PATCH 16/43] Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> --- examples/dem/collapsing_sand_pile_3d.jl | 3 +- examples/fsi/dam_break_gate_2d.jl | 8 +-- examples/fsi/dam_break_plate_2d.jl | 8 +-- examples/preprocessing/packing_2d.jl | 9 +-- examples/preprocessing/packing_3d.jl | 2 +- examples/solid/oscillating_beam_2d.jl | 6 +- src/general/interpolation.jl | 5 +- .../particle_packing/signed_distance.jl | 2 +- src/preprocessing/particle_packing/system.jl | 35 ++++++----- src/setups/complex_shape.jl | 10 ++-- src/setups/extrude_geometry.jl | 60 +++++++++++-------- src/setups/rectangular_shape.jl | 19 +++--- src/setups/sphere_shape.jl | 45 +++++++------- test/setups/extrude_geometry.jl | 7 ++- test/setups/rectangular_shape.jl | 5 +- test/setups/sphere_shape.jl | 8 +-- test/systems/packing_system.jl | 6 +- 17 files changed, 128 insertions(+), 110 deletions(-) diff --git a/examples/dem/collapsing_sand_pile_3d.jl b/examples/dem/collapsing_sand_pile_3d.jl index feb2510fd5..457134ce9b 100644 --- a/examples/dem/collapsing_sand_pile_3d.jl +++ b/examples/dem/collapsing_sand_pile_3d.jl @@ -51,7 +51,8 @@ min_coords_floor = (min_boundary[1] - boundary_thickness, floor_particles = RectangularShape(particle_spacing, (n_particles_floor_x, n_particles_floor_y, n_particles_floor_z), - min_coords_floor; density=boundary_density, tlsph=true) + min_coords_floor; density=boundary_density, + place_on_shell=true) boundary_particles = floor_particles # ========================================================================================== diff --git a/examples/fsi/dam_break_gate_2d.jl b/examples/fsi/dam_break_gate_2d.jl index 487857c05b..654f5016e4 100644 --- a/examples/fsi/dam_break_gate_2d.jl +++ b/examples/fsi/dam_break_gate_2d.jl @@ -75,18 +75,18 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. # # The right end of the plate is 0.2 from the right end of the tank. plate_position = 0.6 - n_particles_x * solid_particle_spacing plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (plate_position, solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (plate_position, 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/fsi/dam_break_plate_2d.jl b/examples/fsi/dam_break_plate_2d.jl index 4ac1a4a085..7b1ca18b75 100644 --- a/examples/fsi/dam_break_plate_2d.jl +++ b/examples/fsi/dam_break_plate_2d.jl @@ -51,15 +51,15 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (2initial_fluid_size[1], solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (2initial_fluid_size[1], 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/preprocessing/packing_2d.jl b/examples/preprocessing/packing_2d.jl index b26f950573..85227dc109 100644 --- a/examples/preprocessing/packing_2d.jl +++ b/examples/preprocessing/packing_2d.jl @@ -6,7 +6,7 @@ file = pkgdir(TrixiParticles, "examples", "preprocessing", "data", filename * ". # ========================================================================================== # ==== Packing parameters -tlsph = false +place_on_shell = false # ========================================================================================== # ==== Resolution @@ -36,7 +36,7 @@ shape_sampled = ComplexShape(geometry; particle_spacing, density, # Returns `InitialCondition` boundary_sampled = sample_boundary(signed_distance_field; boundary_density=density, - boundary_thickness, tlsph=tlsph) + boundary_thickness, place_on_shell=place_on_shell) trixi2vtk(shape_sampled) trixi2vtk(boundary_sampled, filename="boundary") @@ -52,12 +52,13 @@ background_pressure = 1.0 smoothing_length = 0.8 * particle_spacing packing_system = ParticlePackingSystem(shape_sampled; smoothing_length=smoothing_length, - signed_distance_field, tlsph=tlsph, + signed_distance_field, place_on_shell=place_on_shell, background_pressure) boundary_system = ParticlePackingSystem(boundary_sampled; smoothing_length=smoothing_length, is_boundary=true, signed_distance_field, - tlsph=tlsph, boundary_compress_factor=0.8, + place_on_shell=place_on_shell, + boundary_compress_factor=0.8, background_pressure) # ========================================================================================== diff --git a/examples/preprocessing/packing_3d.jl b/examples/preprocessing/packing_3d.jl index 0331d3c0a0..0ca9bf7d8c 100644 --- a/examples/preprocessing/packing_3d.jl +++ b/examples/preprocessing/packing_3d.jl @@ -15,5 +15,5 @@ boundary_thickness = 8 * particle_spacing trixi_include(joinpath(examples_dir(), "preprocessing", "packing_2d.jl"), density=1000.0, particle_spacing=particle_spacing, file=file, - boundary_thickness=boundary_thickness, tlsph=true, + boundary_thickness=boundary_thickness, place_on_shell=true, save_intervals=false) diff --git a/examples/solid/oscillating_beam_2d.jl b/examples/solid/oscillating_beam_2d.jl index 15ad8c99e7..aa25f64c2c 100644 --- a/examples/solid/oscillating_beam_2d.jl +++ b/examples/solid/oscillating_beam_2d.jl @@ -23,7 +23,7 @@ fixed_particles = SphereShape(particle_spacing, clamp_radius + particle_spacing (0.0, elastic_beam.thickness / 2), material.density, cutout_min=(0.0, 0.0), cutout_max=(clamp_radius, elastic_beam.thickness), - tlsph=true) + place_on_shell=true) n_particles_clamp_x = round(Int, clamp_radius / particle_spacing) @@ -33,9 +33,9 @@ n_particles_per_dimension = (round(Int, elastic_beam.length / particle_spacing) # Note that the `RectangularShape` puts the first particle half a particle spacing away # from the boundary, which is correct for fluids, but not for solids. -# We therefore need to pass `tlsph=true`. +# We therefore need to pass `place_on_shell=true`. beam = RectangularShape(particle_spacing, n_particles_per_dimension, - (0.0, 0.0), density=material.density, tlsph=true) + (0.0, 0.0), density=material.density, place_on_shell=true) solid = union(beam, fixed_particles) diff --git a/src/general/interpolation.jl b/src/general/interpolation.jl index 9b0ac40d7f..6ca3fa16f3 100644 --- a/src/general/interpolation.jl +++ b/src/general/interpolation.jl @@ -191,9 +191,10 @@ function interpolate_plane_2d(min_corner, max_corner, resolution, semi, ref_syst x_range = range(min_corner[1], max_corner[1], length=n_points_per_dimension[1]) y_range = range(min_corner[2], max_corner[2], length=n_points_per_dimension[2]) - # Generate points within the plane. Use `tlsph=true` to generate points on the boundary + # Generate points within the plane. Use `place_on_shell=true` to generate points + # on the shell of the geometry. point_coords = rectangular_shape_coords(resolution, n_points_per_dimension, min_corner, - tlsph=true) + place_on_shell=true) results = interpolate_points(point_coords, semi, ref_system, v_ode, u_ode, smoothing_length=smoothing_length, diff --git a/src/preprocessing/particle_packing/signed_distance.jl b/src/preprocessing/particle_packing/signed_distance.jl index 7e957e124d..082deced5a 100644 --- a/src/preprocessing/particle_packing/signed_distance.jl +++ b/src/preprocessing/particle_packing/signed_distance.jl @@ -59,7 +59,7 @@ function SignedDistanceField(geometry, particle_spacing; particle_spacing)) grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) points = reinterpret(reshape, SVector{NDIMS, ELTYPE}, grid) end diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index be6697fb13..f91336036b 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -6,7 +6,7 @@ smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, fixed_system=false) System to generate body-fitted particles for complex shapes. For more information on the methods, see [particle packing](@ref particle_packing). @@ -18,10 +18,11 @@ For more information on the methods, see [particle packing](@ref particle_packin - `background_pressure`: Constant background pressure to physically pack the particles. A large `background_pressure` can cause high accelerations which requires a properly adjusted time step. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not half a particle spacing away, - as for fluids. When `tlsph=true`, particles will be placed - on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. - `is_boundary`: When `shape` is inside the geometry that was used to create `signed_distance_field`, set `is_boundary=false`. Otherwise (`shape` is the sampled boundary), set `is_boundary=true`. @@ -64,7 +65,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, smoothing_kernel :: K smoothing_length_interpolation :: ELTYPE background_pressure :: ELTYPE - tlsph :: Bool + place_on_shell :: Bool signed_distance_field :: S is_boundary :: Bool shift_length :: ELTYPE @@ -79,7 +80,8 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, # See the comments in general/gpu.jl for more details. function ParticlePackingSystem(initial_condition, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, + signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, buffer, update_callback_used, fixed_system, cache, @@ -93,7 +95,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, @@ -108,7 +110,8 @@ function ParticlePackingSystem(shape::InitialCondition; smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, + fixed_system=false) NDIMS = ndims(shape) ELTYPE = eltype(shape) mass = copy(shape.mass) @@ -147,12 +150,12 @@ function ParticlePackingSystem(shape::InitialCondition; # Its value is negative if the particle is inside the geometry. # Otherwise (if outside), the value is positive. if is_boundary - offset = tlsph ? shape.particle_spacing : shape.particle_spacing / 2 + offset = place_on_shell ? shape.particle_spacing : shape.particle_spacing / 2 shift_length = -boundary_compress_factor * signed_distance_field.max_signed_distance - offset else - shift_length = tlsph ? zero(ELTYPE) : shape.particle_spacing / 2 + shift_length = place_on_shell ? zero(ELTYPE) : shape.particle_spacing / 2 end cache = (; create_cache_refinement(shape, particle_refinement, smoothing_length)...) @@ -161,7 +164,7 @@ function ParticlePackingSystem(shape::InitialCondition; return ParticlePackingSystem(shape, mass, density, shape.particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, nhs, fill(zero(ELTYPE), nparticles(shape)), particle_refinement, nothing, Ref(false), fixed_system, cache, @@ -187,7 +190,7 @@ function Base.show(io::IO, ::MIME"text/plain", system::ParticlePackingSystem) system.neighborhood_search |> typeof |> nameof) summary_line(io, "#particles", nparticles(system)) summary_line(io, "smoothing kernel", system.smoothing_kernel |> typeof |> nameof) - summary_line(io, "tlsph", system.tlsph ? "yes" : "no") + summary_line(io, "place_on_shell", system.place_on_shell ? "yes" : "no") summary_line(io, "boundary", system.is_boundary ? "yes" : "no") summary_footer(io) end @@ -349,8 +352,8 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector (; shift_length) = system # For fluid particles: - # - `tlsph = true`: `shift_length = 0` - # - `tlsph = false`: `shift_length = particle_spacing / 2` + # - `place_on_shell = true`: `shift_length = 0` + # - `place_on_shell = false`: `shift_length = particle_spacing / 2` # For boundary particles: # `shift_length` is the thickness of the boundary. if distance_signed >= -shift_length @@ -365,7 +368,7 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector system.is_boundary || return u particle_spacing = system.initial_condition.particle_spacing - shift_length_inner = system.tlsph ? particle_spacing : particle_spacing / 2 + shift_length_inner = system.place_on_shell ? particle_spacing : particle_spacing / 2 if distance_signed < shift_length_inner shift = (distance_signed - shift_length_inner) * normal_vector diff --git a/src/setups/complex_shape.jl b/src/setups/complex_shape.jl index 2c515157d1..594b3b4f37 100644 --- a/src/setups/complex_shape.jl +++ b/src/setups/complex_shape.jl @@ -79,7 +79,7 @@ end """ sample_boundary(signed_distance_field::SignedDistanceField; - boundary_thickness::Real, tlsph=true) + boundary_thickness::Real, place_on_shell=true) Sample boundary particles of a complex geometry by using the [`SignedDistanceField`](@ref) of the geometry. @@ -89,9 +89,9 @@ of the geometry. # Keywords - `boundary_thickness`: Thickness of the boundary -- `tlsph` : When `tlsph=true`, boundary particles will be placed +- `place_on_shell`: When `place_on_shell=true`, boundary particles will be placed one particle spacing from the surface of the geometry. - Otherwise when `tlsph=true` (simulating fluid particles), + Otherwise when `place_on_shell=true` (simulating fluid particles), boundary particles will be placed half particle spacing away from the surface. @@ -117,7 +117,7 @@ boundary_sampled = sample_boundary(signed_distance_field; boundary_density=1.0, ``` """ function sample_boundary(signed_distance_field; - boundary_density, boundary_thickness, tlsph=true) + boundary_density, boundary_thickness, place_on_shell=true) (; max_signed_distance, boundary_packing, positions, distances, particle_spacing) = signed_distance_field @@ -157,6 +157,6 @@ function particle_grid(geometry, particle_spacing; end grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) return reinterpret(reshape, SVector{ndims(geometry), eltype(geometry)}, grid) end diff --git a/src/setups/extrude_geometry.jl b/src/setups/extrude_geometry.jl index 498266ecd0..6d169762c7 100644 --- a/src/setups/extrude_geometry.jl +++ b/src/setups/extrude_geometry.jl @@ -30,9 +30,11 @@ Returns an [`InitialCondition`](@ref). - `pressure`: Scalar to set the pressure of all particles to this value. This is only used by the [`EntropicallyDampedSPHSystem`](@ref) and will be overwritten when using an initial pressure function in the system. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. # Examples ```jldoctest; output = false @@ -79,7 +81,7 @@ shape = extrude_geometry(shape; direction, particle_spacing=0.1, n_extrude=4, de This is an experimental feature and may change in any future releases. """ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::Integer, - velocity=zeros(length(direction)), tlsph=false, + velocity=zeros(length(direction)), place_on_shell=false, mass=nothing, density=nothing, pressure=0.0) direction_ = normalize(direction) NDIMS = length(direction_) @@ -95,9 +97,11 @@ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::I throw(ArgumentError("`particle_spacing` must be specified when not extruding an `InitialCondition`")) end - geometry = shift_plane_corners(geometry, direction_, particle_spacing, tlsph) + geometry = shift_plane_corners(geometry, direction_, particle_spacing, place_on_shell) - face_coords, particle_spacing_ = sample_plane(geometry, particle_spacing; tlsph=tlsph) + face_coords, + particle_spacing_ = sample_plane(geometry, particle_spacing; + place_on_shell=place_on_shell) if !isapprox(particle_spacing, particle_spacing_, rtol=5e-2) @info "The desired size is not a multiple of the particle spacing $particle_spacing." * @@ -119,12 +123,13 @@ end # For corners/endpoints of a plane/line, sample the plane/line with particles. # For 2D coordinates or an `InitialCondition`, add a third dimension. -function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) +function sample_plane(geometry::AbstractMatrix, particle_spacing; place_on_shell) if size(geometry, 1) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane - coords = vcat(geometry, fill(tlsph ? 0 : particle_spacing / 2, size(geometry, 2))') + # When `place_on_shell=true`, particles will be placed on the x-y plane + coords = vcat(geometry, + fill(place_on_shell ? 0 : particle_spacing / 2, size(geometry, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -133,13 +138,14 @@ function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) return geometry, particle_spacing end -function sample_plane(shape::InitialCondition, particle_spacing; tlsph) +function sample_plane(shape::InitialCondition, particle_spacing; place_on_shell) if ndims(shape) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane + # When `place_on_shell=true`, particles will be placed on the x-y plane coords = vcat(shape.coordinates, - fill(tlsph ? 0 : particle_spacing / 2, size(shape.coordinates, 2))') + fill(place_on_shell ? 0 : particle_spacing / 2, + size(shape.coordinates, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -148,13 +154,13 @@ function sample_plane(shape::InitialCondition, particle_spacing; tlsph) return shape.coordinates, particle_spacing end -function sample_plane(plane_points, particle_spacing; tlsph=nothing) +function sample_plane(plane_points, particle_spacing; place_on_shell=nothing) # Convert to tuple - return sample_plane(tuple(plane_points...), particle_spacing; tlsph=nothing) + return sample_plane(tuple(plane_points...), particle_spacing; place_on_shell=nothing) end -function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{2}, particle_spacing; place_on_shell=nothing) # Verify that points are in 2D space if any(length.(plane_points) .!= 2) throw(ArgumentError("all points must be 2D coordinates")) @@ -168,7 +174,7 @@ function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{3}, particle_spacing; place_on_shell=nothing) # Verify that points are in 3D space if any(length.(plane_points) .!= 3) throw(ArgumentError("all points must be 3D coordinates")) @@ -209,21 +215,22 @@ function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -# Shift corners of the plane/line inwards by half a particle spacing with `tlsph=false` +# Shift corners of the plane/line inwards by half a particle spacing with `place_on_shell=false` # because fluid particles need to be half a particle spacing away from the boundary of the shape. function shift_plane_corners(geometry::Union{AbstractMatrix, InitialCondition}, - direction, particle_spacing, tlsph) + direction, particle_spacing, place_on_shell) return geometry end -function shift_plane_corners(plane_points, direction, particle_spacing, tlsph) - shift_plane_corners(tuple(plane_points...), direction, particle_spacing, tlsph) +function shift_plane_corners(plane_points, direction, particle_spacing, place_on_shell) + shift_plane_corners(tuple(plane_points...), direction, particle_spacing, place_on_shell) end -function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) @@ -238,10 +245,11 @@ function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacin return (plane_point1, plane_point2) end -function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) diff --git a/src/setups/rectangular_shape.jl b/src/setups/rectangular_shape.jl index 98160bcac9..1c30ef5c1b 100644 --- a/src/setups/rectangular_shape.jl +++ b/src/setups/rectangular_shape.jl @@ -3,7 +3,7 @@ velocity=zeros(length(n_particles_per_dimension)), mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). @@ -40,9 +40,10 @@ Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). - `state_equation`: When calculating a hydrostatic pressure gradient by setting `acceleration`, the `state_equation` will be used to set the corresponding density. Cannot be used together with `density`. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. - `coordinates_perturbation`: Add a small random displacement to the particle positions, where the amplitude is `coordinates_perturbation * particle_spacing`. @@ -75,7 +76,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord coordinates_perturbation=nothing, mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) end @@ -95,7 +96,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord n_particles = prod(n_particles_per_dimension) coordinates = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates, tlsph=tlsph, + min_coordinates, place_on_shell=place_on_shell, loop_order=loop_order) if !isnothing(coordinates_perturbation) @@ -190,15 +191,15 @@ function loop_permutation(loop_order, NDIMS::Val{3}) end function rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates; tlsph=false, loop_order=nothing) + min_coordinates; place_on_shell=false, loop_order=nothing) ELTYPE = eltype(particle_spacing) NDIMS = length(n_particles_per_dimension) coordinates = Array{ELTYPE, 2}(undef, NDIMS, prod(n_particles_per_dimension)) - # With TLSPH, particles need to be AT the min coordinates and not half a particle + # With place_on_shell, particles need to be AT the min coordinates and not half a particle # spacing away from it. - if tlsph + if place_on_shell min_coordinates = min_coordinates .- 0.5particle_spacing end diff --git a/src/setups/sphere_shape.jl b/src/setups/sphere_shape.jl index 0233fc8995..3c6a7466d5 100644 --- a/src/setups/sphere_shape.jl +++ b/src/setups/sphere_shape.jl @@ -1,7 +1,7 @@ """ SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0.0) Generate a sphere that is either completely filled (by default) @@ -35,18 +35,19 @@ coordinate directions as `cutout_min` and `cutout_max`. cut out of the sphere. - `cutout_max`: Corner in positive coordinate directions of a cuboid that is to be cut out of the sphere. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. -- `velocity`: Either a function mapping each particle's coordinates to its velocity, - or, for a constant fluid velocity, a vector holding this velocity. - Velocity is constant zero by default. -- `mass`: Either `nothing` (default) to automatically compute particle mass from particle - density and spacing, or a function mapping each particle's coordinates to its mass, - or a scalar for a constant mass over all particles. -- `pressure`: Either a function mapping each particle's coordinates to its pressure, - or a scalar for a constant pressure over all particles. This is optional and - only needed when using the [`EntropicallyDampedSPHSystem`](@ref). +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. +- `velocity`: Either a function mapping each particle's coordinates to its velocity, + or, for a constant fluid velocity, a vector holding this velocity. + Velocity is constant zero by default. +- `mass`: Either `nothing` (default) to automatically compute particle mass from particle + density and spacing, or a function mapping each particle's coordinates to its mass, + or a scalar for a constant mass over all particles. +- `pressure`: Either a function mapping each particle's coordinates to its pressure, + or a scalar for a constant pressure over all particles. This is optional and + only needed when using the [`EntropicallyDampedSPHSystem`](@ref). # Examples ```jldoctest; output = false @@ -89,7 +90,7 @@ SphereShape(0.1, 0.5, (0.2, 0.4, 0.3), 1000.0, sphere_type=RoundSphere()) """ function SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) @@ -99,7 +100,7 @@ function SphereShape(particle_spacing, radius, center_position, density; coordinates = sphere_shape_coords(sphere_type, particle_spacing, radius, SVector{NDIMS}(center_position), - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) # Convert tuples to vectors cutout_min_ = collect(cutout_min) @@ -169,13 +170,13 @@ struct RoundSphere{AR} end function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_position, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius outer_radius = radius + n_layers * particle_spacing - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of `radius` inner_radius += particle_spacing / 2 outer_radius += particle_spacing / 2 @@ -184,7 +185,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos inner_radius = radius - n_layers * particle_spacing outer_radius = radius - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` inner_radius -= particle_spacing / 2 outer_radius -= particle_spacing / 2 @@ -194,7 +195,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos outer_radius = radius inner_radius = -1 - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` outer_radius -= particle_spacing / 2 end @@ -225,7 +226,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos end function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, center, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius @@ -233,12 +234,12 @@ function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, cent inner_radius = radius - n_layers * particle_spacing end - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of inner radius inner_radius += particle_spacing / 2 end else - if tlsph + if place_on_shell # Just create a sphere that is 0.5 particle spacing larger radius += particle_spacing / 2 end diff --git a/test/setups/extrude_geometry.jl b/test/setups/extrude_geometry.jl index e695f2e170..5a927dbee4 100644 --- a/test/setups/extrude_geometry.jl +++ b/test/setups/extrude_geometry.jl @@ -28,7 +28,8 @@ ] @testset "Direction $i" for i in eachindex(directions) - shape = extrude_geometry((point1, point2); direction=directions[i], tlsph=true, + shape = extrude_geometry((point1, point2); direction=directions[i], + place_on_shell=true, particle_spacing=0.15, n_extrude=5, density=1.0) @test shape.coordinates ≈ expected_coords[i] @@ -68,7 +69,7 @@ end @testset "Direction $i" for i in eachindex(directions) shape = extrude_geometry(geometry; direction=directions[i], particle_spacing, - n_extrude=5, tlsph=true, density=1.0) + n_extrude=5, place_on_shell=true, density=1.0) @test shape.coordinates ≈ expected_coords[i] end @@ -86,7 +87,7 @@ end 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.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061] shape = extrude_geometry((p1, p2, p3); direction, particle_spacing=0.1, n_extrude=4, - density=1000.0, tlsph=true) + density=1000.0, place_on_shell=true) @test shape.coordinates ≈ expected_coords end diff --git a/test/setups/rectangular_shape.jl b/test/setups/rectangular_shape.jl index f3e77043b0..7c2fd6875b 100644 --- a/test/setups/rectangular_shape.jl +++ b/test/setups/rectangular_shape.jl @@ -41,7 +41,8 @@ ] @testset "$(loop_orders[i])" for i in eachindex(loop_orders) - shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, tlsph=true, + shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] @@ -242,7 +243,7 @@ end @testset "$(loop_orders[i])" for i in eachindex(loop_orders) shape = RectangularShape(1.0, (2, 2, 2), (0.0, 0.0, 0.0), density=1.0, - tlsph=true, loop_order=loop_orders[i]) + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] end diff --git a/test/setups/sphere_shape.jl b/test/setups/sphere_shape.jl index 57d904a376..c8b87d76db 100644 --- a/test/setups/sphere_shape.jl +++ b/test/setups/sphere_shape.jl @@ -106,14 +106,14 @@ SphereShape(1.0, 1.1, (0.2, -1.0, 0.3), 1000.0, sphere_type=RoundSphere()), SphereShape(1.0, 1.2, (-0.3, 0.1, 0.8), 1000.0, sphere_type=RoundSphere()), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, cutout_min=(0.18, 0.4, 0.5), - cutout_max=(0.42, 10.0, 1.0), tlsph=true), - SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, tlsph=true), + cutout_max=(0.42, 10.0, 1.0), place_on_shell=true), + SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, - layer_outwards=true, tlsph=true), + layer_outwards=true, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, sphere_type=RoundSphere()), SphereShape(0.1, 0.55, (0.3, 0.4, 0.5), 1000.0, n_layers=2, layer_outwards=true, - sphere_type=RoundSphere(), tlsph=true) + sphere_type=RoundSphere(), place_on_shell=true) ] expected_coords = [ diff --git a/test/systems/packing_system.jl b/test/systems/packing_system.jl index d55afd559a..b42e534275 100644 --- a/test/systems/packing_system.jl +++ b/test/systems/packing_system.jl @@ -19,7 +19,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -36,7 +36,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… yes │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -52,7 +52,7 @@ │ neighborhood search: ………………………… Nothing │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" end From 7d34fe52aa0564d864275a0a65d60268b2d86524 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 16 Jun 2025 14:46:55 +0200 Subject: [PATCH 17/43] dispatch `FluidSystem` --- src/io/io.jl | 56 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/io/io.jl b/src/io/io.jl index 2511c8e825..a84ba1b4be 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -51,7 +51,8 @@ function add_meta_data!(meta_data, system::DEMSystem) return meta_data end -function add_meta_data!(meta_data, system::FluidSystem) +function add_meta_data!(meta_data, system::WeaklyCompressibleSPHSystem) + # general `FLuidSystem`-Metadata meta_data["acceleration"] = system.acceleration meta_data["viscosity"] = type2string(system.viscosity) add_meta_data!(meta_data, system.viscosity) @@ -59,31 +60,38 @@ function add_meta_data!(meta_data, system::FluidSystem) meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor meta_data["density_calculator"] = type2string(system.density_calculator) - if system isa WeaklyCompressibleSPHSystem - meta_data["state_equation"] = type2string(system.state_equation) - meta_data["state_equation_rho0"] = system.state_equation.reference_density - meta_data["state_equation_pa"] = system.state_equation.background_pressure - meta_data["state_equation_c"] = system.state_equation.sound_speed - meta_data["solver"] = "WCSPH" - - meta_data["correction_method"] = type2string(system.correction) - if system.correction isa AkinciFreeSurfaceCorrection - meta_data["correction_rho0"] = system.correction.rho0 - end - if system.state_equation isa StateEquationCole - meta_data["state_equation_exponent"] = system.state_equation.exponent - end - if system.state_equation isa StateEquationIdealGas - meta_data["state_equation_gamma"] = system.state_equation.gamma - end - else - meta_data["solver"] = "EDAC" - meta_data["sound_speed"] = system.sound_speed - meta_data["background_pressure_TVF"] = system.transport_velocity isa Nothing ? "-" : - system.transport_velocity.background_pressure + # specific `WCSPH`-Metadata + meta_data["solver"] = "WCSPH" + meta_data["state_equation"] = type2string(system.state_equation) + meta_data["state_equation_rho0"] = system.state_equation.reference_density + meta_data["state_equation_pa"] = system.state_equation.background_pressure + meta_data["state_equation_c"] = system.state_equation.sound_speed + meta_data["correction_method"] = type2string(system.correction) + if system.correction isa AkinciFreeSurfaceCorrection + meta_data["correction_rho0"] = system.correction.rho0 end + if system.state_equation isa StateEquationCole + meta_data["state_equation_exponent"] = system.state_equation.exponent + end + if system.state_equation isa StateEquationIdealGas + meta_data["state_equation_gamma"] = system.state_equation.gamma + end +end - return meta_data +function add_meta_data!(meta_data, system::EntropicallyDampedSPHSystem) + # general `FLuidSystem`-Metadata + meta_data["acceleration"] = system.acceleration + meta_data["viscosity"] = type2string(system.viscosity) + add_meta_data!(meta_data, system.viscosity) + meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) + meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor + meta_data["density_calculator"] = type2string(system.density_calculator) + + # specific `EDAC`-Metadata + meta_data["solver"] = "EDAC" + meta_data["sound_speed"] = system.sound_speed + meta_data["background_pressure_TVF"] = system.transport_velocity isa Nothing ? "-" : + system.transport_velocity.background_pressure end add_meta_data!(meta_data, viscosity::Nothing) = meta_data From ff5651fb533afe57d3e6edf3c20615e2696151c0 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 16 Jun 2025 14:48:18 +0200 Subject: [PATCH 18/43] Write one unified metadata file for all systems --- src/io/io.jl | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/io/io.jl b/src/io/io.jl index a84ba1b4be..4a0f7e51c6 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -3,43 +3,45 @@ include("read_vtk.jl") function write_meta_data(callback::Union{SolutionSavingCallback, PostprocessCallback}, integrator) - semi = integrator.p - (; systems) = semi + # handle "_" on optional prefix strings + add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") - output_directory = callback.output_directory - prefix = hasproperty(callback, :prefix) ? callback.prefix : "" git_hash = callback.git_hash + prefix = hasproperty(callback, :prefix) ? callback.prefix : "" - filenames = system_names(systems) + semi = integrator.p + names = system_names(semi.systems) + # fill `systems` with metadata for each system + systems = Dict{String, Any}() foreach_system(semi) do system - system_index = system_indices(system, semi) + idx = system_indices(system, semi) + name = add_opt_str_pre(prefix) * "$(names[idx])" - write_meta_data(system; system_name=filenames[system_index], output_directory, - prefix, git_hash) - end -end + meta_data = Dict{String, Any}() + add_meta_data!(meta_data, system) -function write_meta_data(system; system_name, output_directory, prefix, git_hash) - mkpath(output_directory) + systems[name] = meta_data + end - meta_data = Dict{String, Any}( - "solver_name" => "TrixiParticles.jl", - "solver_version" => git_hash, - "julia_version" => string(VERSION) + # initialize `simulation_meta_data` and add `systems` + simulation_meta_data = Dict{String, Any}( + "info" => Dict( + "solver_name" => "TrixiParticles.jl", + "solver_version" => git_hash, + "julia_version" => string(VERSION) + ), + "systems" => systems ) - add_meta_data!(meta_data, system) - - # handle "_" on optional prefix strings - add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") + # write JSON-file + output_directory = callback.output_directory + mkpath(output_directory) - # Write metadata to JSON-file - json_file = joinpath(output_directory, - add_opt_str_pre(prefix) * "$(system_name)_metadata.json") + json_file = joinpath(output_directory, "simulation_metadata.json") open(json_file, "w") do file - JSON.print(file, meta_data, 2) + JSON.print(file, simulation_meta_data, 2) end end From 8787218eafc6a31bb03d501ea4e8fbc4a37a3163 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 30 Jun 2025 11:18:47 +0200 Subject: [PATCH 19/43] improve JSON-file structure --- src/io/io.jl | 115 +++++++++++++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 49 deletions(-) diff --git a/src/io/io.jl b/src/io/io.jl index 4a0f7e51c6..54cabf48f2 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -8,11 +8,14 @@ function write_meta_data(callback::Union{SolutionSavingCallback, PostprocessCall git_hash = callback.git_hash prefix = hasproperty(callback, :prefix) ? callback.prefix : "" - semi = integrator.p names = system_names(semi.systems) - # fill `systems` with metadata for each system + info = Dict{String, Any}() + info["solver_name"] = "TrixiParticles.jl" + info["solver_version"] = git_hash[] + info["julia_version"] = string(VERSION) + systems = Dict{String, Any}() foreach_system(semi) do system idx = system_indices(system, semi) @@ -24,21 +27,15 @@ function write_meta_data(callback::Union{SolutionSavingCallback, PostprocessCall systems[name] = meta_data end - # initialize `simulation_meta_data` and add `systems` - simulation_meta_data = Dict{String, Any}( - "info" => Dict( - "solver_name" => "TrixiParticles.jl", - "solver_version" => git_hash, - "julia_version" => string(VERSION) - ), - "systems" => systems - ) + simulation_meta_data = Dict{String, Any}() + simulation_meta_data["info"] = info + simulation_meta_data["systems"] = systems # write JSON-file output_directory = callback.output_directory mkpath(output_directory) - json_file = joinpath(output_directory, "simulation_metadata.json") + json_file = joinpath(output_directory, "simulation_meta_data.json") open(json_file, "w") do file JSON.print(file, simulation_meta_data, 2) @@ -49,48 +46,47 @@ function add_meta_data!(meta_data, system) return meta_data end -function add_meta_data!(meta_data, system::DEMSystem) - return meta_data -end - function add_meta_data!(meta_data, system::WeaklyCompressibleSPHSystem) - # general `FLuidSystem`-Metadata + # general `FluidSystem`-metadata + meta_data["phase"] = "fluid" + meta_data["type"] = type2string(system) meta_data["acceleration"] = system.acceleration - meta_data["viscosity"] = type2string(system.viscosity) add_meta_data!(meta_data, system.viscosity) meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor meta_data["density_calculator"] = type2string(system.density_calculator) - # specific `WCSPH`-Metadata - meta_data["solver"] = "WCSPH" - meta_data["state_equation"] = type2string(system.state_equation) - meta_data["state_equation_rho0"] = system.state_equation.reference_density - meta_data["state_equation_pa"] = system.state_equation.background_pressure - meta_data["state_equation_c"] = system.state_equation.sound_speed - meta_data["correction_method"] = type2string(system.correction) - if system.correction isa AkinciFreeSurfaceCorrection - meta_data["correction_rho0"] = system.correction.rho0 - end + # specific `WCSPH`-metadata + meta_data["state_equation"] = Dict{String, Any}() + meta_data["state_equation"]["type"] = type2string(system.state_equation) + meta_data["state_equation"]["rho0"] = system.state_equation.reference_density + meta_data["state_equation"]["pa"] = system.state_equation.background_pressure + meta_data["state_equation"]["c"] = system.state_equation.sound_speed if system.state_equation isa StateEquationCole - meta_data["state_equation_exponent"] = system.state_equation.exponent + meta_data["state_equation"]["exponent"] = system.state_equation.exponent end if system.state_equation isa StateEquationIdealGas - meta_data["state_equation_gamma"] = system.state_equation.gamma + meta_data["state_equation"]["gamma"] = system.state_equation.gamma + end + + meta_data["correction_method"] = Dict{String, Any}() + meta_data["correction_method"]["type"] = type2string(system.correction) + if system.correction isa AkinciFreeSurfaceCorrection + meta_data["correction_method"]["rho0"] = system.correction.rho0 end end function add_meta_data!(meta_data, system::EntropicallyDampedSPHSystem) - # general `FLuidSystem`-Metadata + # general `FluidSystem`-metadata + meta_data["phase"] = "fluid" + meta_data["type"] = type2string(system) meta_data["acceleration"] = system.acceleration - meta_data["viscosity"] = type2string(system.viscosity) add_meta_data!(meta_data, system.viscosity) meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor meta_data["density_calculator"] = type2string(system.density_calculator) - # specific `EDAC`-Metadata - meta_data["solver"] = "EDAC" + # specific `EDAC`-metadata meta_data["sound_speed"] = system.sound_speed meta_data["background_pressure_TVF"] = system.transport_velocity isa Nothing ? "-" : system.transport_velocity.background_pressure @@ -99,17 +95,23 @@ end add_meta_data!(meta_data, viscosity::Nothing) = meta_data function add_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) - meta_data["viscosity_nu"] = viscosity.nu - meta_data["viscosity_epsilon"] = viscosity.epsilon + meta_data["viscosity_model"] = Dict{String, Any}() + meta_data["viscosity_model"]["type"] = type2string(viscosity) + meta_data["viscosity_model"]["nu"] = viscosity.nu + meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon end function add_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) - meta_data["viscosity_alpha"] = viscosity.alpha - meta_data["viscosity_beta"] = viscosity.beta - meta_data["viscosity_epsilon"] = viscosity.epsilon + meta_data["viscosity_model"] = Dict{String, Any}() + meta_data["viscosity_model"]["type"] = type2string(viscosity) + meta_data["viscosity_model"]["alpha"] = viscosity.alpha + meta_data["viscosity_model"]["beta"] = viscosity.beta + meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon end function add_meta_data!(meta_data, system::TotalLagrangianSPHSystem) + meta_data["phase"] = "boundary" + meta_data["type"] = type2string(system) meta_data["young_modulus"] = system.young_modulus meta_data["poisson_ratio"] = system.poisson_ratio meta_data["lame_lambda"] = system.lame_lambda @@ -122,7 +124,9 @@ function add_meta_data!(meta_data, system::TotalLagrangianSPHSystem) end function add_meta_data!(meta_data, system::OpenBoundarySPHSystem) - meta_data["boundary_zone"] = type2string(system.boundary_zone) + meta_data["phase"] = "boundary" + meta_data["type"] = type2string(system) + meta_data["type"] = type2string(system.boundary_zone.boundary_type) meta_data["width"] = round(system.boundary_zone.zone_width, digits=3) meta_data["velocity_function"] = type2string(system.reference_velocity) meta_data["pressure_function"] = type2string(system.reference_pressure) @@ -130,6 +134,7 @@ function add_meta_data!(meta_data, system::OpenBoundarySPHSystem) end function add_meta_data!(meta_data, system::BoundarySPHSystem) + meta_data["type"] = type2string(system) add_meta_data!(meta_data, system.boundary_model, system) end @@ -138,20 +143,32 @@ function add_meta_data!(meta_data, model::Nothing, system) end function add_meta_data!(meta_data, model::BoundaryModelMonaghanKajtar, system) - meta_data["boundary_model"] = "BoundaryModelMonaghanKajtar" - meta_data["boundary_spacing_ratio"] = model.beta - meta_data["boundary_K"] = model.K + meta_data["boundary_model"] = Dict{String, Any}() + meta_data["boundary_model"]["type"] = "BoundaryModelMonaghanKajtar" + meta_data["boundary_model"]["spacing_ratio"] = model.beta + meta_data["boundary_model"]["K"] = model.K end function add_meta_data!(meta_data, model::BoundaryModelDummyParticles, system) - meta_data["boundary_model"] = "BoundaryModelDummyParticles" - meta_data["smoothing_kernel"] = type2string(model.smoothing_kernel) - meta_data["smoothing_length"] = model.smoothing_length - meta_data["density_calculator"] = type2string(model.density_calculator) - meta_data["state_equation"] = type2string(model.state_equation) - meta_data["viscosity_model"] = type2string(model.viscosity) + meta_data["boundary_model"] = Dict{String, Any}() + meta_data["boundary_model"]["type"] = "BoundaryModelDummyParticles" + meta_data["boundary_model"]["smoothing_kernel"] = type2string(model.smoothing_kernel) + meta_data["boundary_model"]["smoothing_length"] = model.smoothing_length + meta_data["boundary_model"]["density_calculator"] = type2string(model.density_calculator) + + meta_data["boundary_model"]["state_equation"] = Dict{String, Any}() + meta_data["boundary_model"]["state_equation"]["type"] = type2string(model.state_equation) + + meta_data["boundary_model"]["viscosity_model"] = Dict{String, Any}() + meta_data["boundary_model"]["viscosity_model"]["type"] = type2string(model.viscosity) end function add_meta_data!(meta_data, system::BoundaryDEMSystem) + meta_data["type"] = type2string(system) + return meta_data +end + +function add_meta_data!(meta_data, system::DEMSystem) + meta_data["type"] = type2string(system) return meta_data end From 0a9389249c4e3fa299cc8ea25582126d657be7e2 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Tue, 1 Jul 2025 15:58:36 +0200 Subject: [PATCH 20/43] improve consistency --- src/io/io.jl | 178 +++++++++++++++++++++++++-------------------------- 1 file changed, 88 insertions(+), 90 deletions(-) diff --git a/src/io/io.jl b/src/io/io.jl index 54cabf48f2..a42aaee0fe 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -42,76 +42,27 @@ function write_meta_data(callback::Union{SolutionSavingCallback, PostprocessCall end end -function add_meta_data!(meta_data, system) - return meta_data -end +add_meta_data!(meta_data, ::Nothing) = meta_data -function add_meta_data!(meta_data, system::WeaklyCompressibleSPHSystem) - # general `FluidSystem`-metadata - meta_data["phase"] = "fluid" - meta_data["type"] = type2string(system) - meta_data["acceleration"] = system.acceleration - add_meta_data!(meta_data, system.viscosity) - meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor +function add_meta_data!(meta_data, system::FluidSystem) + meta_data["system_type"] = type2string(system) meta_data["density_calculator"] = type2string(system.density_calculator) - - # specific `WCSPH`-metadata - meta_data["state_equation"] = Dict{String, Any}() - meta_data["state_equation"]["type"] = type2string(system.state_equation) - meta_data["state_equation"]["rho0"] = system.state_equation.reference_density - meta_data["state_equation"]["pa"] = system.state_equation.background_pressure - meta_data["state_equation"]["c"] = system.state_equation.sound_speed - if system.state_equation isa StateEquationCole - meta_data["state_equation"]["exponent"] = system.state_equation.exponent - end - if system.state_equation isa StateEquationIdealGas - meta_data["state_equation"]["gamma"] = system.state_equation.gamma - end - - meta_data["correction_method"] = Dict{String, Any}() - meta_data["correction_method"]["type"] = type2string(system.correction) - if system.correction isa AkinciFreeSurfaceCorrection - meta_data["correction_method"]["rho0"] = system.correction.rho0 - end -end - -function add_meta_data!(meta_data, system::EntropicallyDampedSPHSystem) - # general `FluidSystem`-metadata - meta_data["phase"] = "fluid" - meta_data["type"] = type2string(system) - meta_data["acceleration"] = system.acceleration - add_meta_data!(meta_data, system.viscosity) meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor - meta_data["density_calculator"] = type2string(system.density_calculator) - - # specific `EDAC`-metadata - meta_data["sound_speed"] = system.sound_speed + meta_data["acceleration"] = system.acceleration + meta_data["sound_speed"] = system_sound_speed(system) meta_data["background_pressure_TVF"] = system.transport_velocity isa Nothing ? "-" : system.transport_velocity.background_pressure -end - -add_meta_data!(meta_data, viscosity::Nothing) = meta_data - -function add_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) - meta_data["viscosity_model"] = Dict{String, Any}() - meta_data["viscosity_model"]["type"] = type2string(viscosity) - meta_data["viscosity_model"]["nu"] = viscosity.nu - meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon -end - -function add_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) - meta_data["viscosity_model"] = Dict{String, Any}() - meta_data["viscosity_model"]["type"] = type2string(viscosity) - meta_data["viscosity_model"]["alpha"] = viscosity.alpha - meta_data["viscosity_model"]["beta"] = viscosity.beta - meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon + add_meta_data!(meta_data, system.surface_tension) + add_meta_data!(meta_data, system.viscosity) + add_meta_data!(meta_data, system.correction) + if system isa WeaklyCompressibleSPHSystem + add_meta_data!(meta_data, system.state_equation) + end end function add_meta_data!(meta_data, system::TotalLagrangianSPHSystem) - meta_data["phase"] = "boundary" - meta_data["type"] = type2string(system) + meta_data["system_type"] = type2string(system) meta_data["young_modulus"] = system.young_modulus meta_data["poisson_ratio"] = system.poisson_ratio meta_data["lame_lambda"] = system.lame_lambda @@ -119,56 +70,103 @@ function add_meta_data!(meta_data, system::TotalLagrangianSPHSystem) meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) meta_data["smoothing_length_factor"] = initial_smoothing_length(system) / particle_spacing(system, 1) - - add_meta_data!(meta_data, system.boundary_model, system) + meta_data["penalty_force"] = system.penalty_force + meta_data["acceleration"] = system.acceleration + add_meta_data!(meta_data, system.boundary_model) end function add_meta_data!(meta_data, system::OpenBoundarySPHSystem) - meta_data["phase"] = "boundary" - meta_data["type"] = type2string(system) - meta_data["type"] = type2string(system.boundary_zone.boundary_type) - meta_data["width"] = round(system.boundary_zone.zone_width, digits=3) - meta_data["velocity_function"] = type2string(system.reference_velocity) - meta_data["pressure_function"] = type2string(system.reference_pressure) - meta_data["density_function"] = type2string(system.reference_density) + meta_data["system_type"] = type2string(system) + meta_data["reference_velocity"] = type2string(system.reference_velocity) + meta_data["reference_pressure"] = type2string(system.reference_pressure) + meta_data["reference_density"] = type2string(system.reference_density) + add_meta_data!(meta_data, system.boundary_zone) end function add_meta_data!(meta_data, system::BoundarySPHSystem) - meta_data["type"] = type2string(system) - add_meta_data!(meta_data, system.boundary_model, system) + meta_data["system_type"] = type2string(system) + add_meta_data!(meta_data, system.boundary_model) +end + +function add_meta_data!(meta_data, system::BoundaryDEMSystem) + meta_data["system_type"] = type2string(system) +end + +function add_meta_data!(meta_data, system::DEMSystem) + meta_data["system_type"] = type2string(system) +end + +function add_meta_data!(meta_data, + state_equation::Union{StateEquationCole, StateEquationIdealGas}) + meta_data["state_equation"] = Dict{String, Any}() + meta_data["state_equation"]["model"] = type2string(state_equation) + meta_data["state_equation"]["reference_density"] = state_equation.reference_density + meta_data["state_equation"]["background_pressure"] = state_equation.background_pressure + if state_equation isa StateEquationCole + meta_data["state_equation"]["exponent"] = state_equation.exponent + end + if state_equation isa StateEquationIdealGas + meta_data["state_equation"]["gamma"] = state_equation.gamma + end +end + +function add_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) + meta_data["viscosity_model"] = Dict{String, Any}() + meta_data["viscosity_model"]["model"] = type2string(viscosity) + meta_data["viscosity_model"]["nu"] = viscosity.nu + meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon end -function add_meta_data!(meta_data, model::Nothing, system) - return meta_data +function add_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) + meta_data["viscosity_model"] = Dict{String, Any}() + meta_data["viscosity_model"]["model"] = type2string(viscosity) + meta_data["viscosity_model"]["alpha"] = viscosity.alpha + meta_data["viscosity_model"]["beta"] = viscosity.beta + meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon end -function add_meta_data!(meta_data, model::BoundaryModelMonaghanKajtar, system) +function add_meta_data!(meta_data, model::BoundaryModelMonaghanKajtar) meta_data["boundary_model"] = Dict{String, Any}() - meta_data["boundary_model"]["type"] = "BoundaryModelMonaghanKajtar" - meta_data["boundary_model"]["spacing_ratio"] = model.beta + meta_data["boundary_model"]["model"] = "BoundaryModelMonaghanKajtar" + meta_data["boundary_model"]["beta"] = model.beta meta_data["boundary_model"]["K"] = model.K + add_meta_data!(meta_data["boundary_model"], model.viscosity) end -function add_meta_data!(meta_data, model::BoundaryModelDummyParticles, system) +function add_meta_data!(meta_data, model::BoundaryModelDummyParticles) meta_data["boundary_model"] = Dict{String, Any}() - meta_data["boundary_model"]["type"] = "BoundaryModelDummyParticles" + meta_data["boundary_model"]["model"] = "BoundaryModelDummyParticles" meta_data["boundary_model"]["smoothing_kernel"] = type2string(model.smoothing_kernel) meta_data["boundary_model"]["smoothing_length"] = model.smoothing_length meta_data["boundary_model"]["density_calculator"] = type2string(model.density_calculator) + add_meta_data!(meta_data["boundary_model"], model.state_equation) + add_meta_data!(meta_data["boundary_model"], model.viscosity) + add_meta_data!(meta_data["boundary_model"], model.correction) +end - meta_data["boundary_model"]["state_equation"] = Dict{String, Any}() - meta_data["boundary_model"]["state_equation"]["type"] = type2string(model.state_equation) - - meta_data["boundary_model"]["viscosity_model"] = Dict{String, Any}() - meta_data["boundary_model"]["viscosity_model"]["type"] = type2string(model.viscosity) +function add_meta_data!(meta_data, + correction::Union{AkinciFreeSurfaceCorrection, + BlendedGradientCorrection, + GradientCorrection, KernelCorrection, + ShepardKernelCorrection}) + meta_data["correction_method"] = Dict{String, Any}() + meta_data["correction_method"]["model"] = type2string(correction) + if correction isa AkinciFreeSurfaceCorrection + meta_data["correction_method"]["rho0"] = correction.rho0 + end end -function add_meta_data!(meta_data, system::BoundaryDEMSystem) - meta_data["type"] = type2string(system) - return meta_data +function add_meta_data!(meta_data, + surface_tension::Union{CohesionForceAkinci, SurfaceTensionAkinci, + SurfaceTensionMorris, + SurfaceTensionMomentumMorris}) + meta_data["surface_tension"] = Dict{String, Any}() + meta_data["surface_tension"]["model"] = type2string(surface_tension) + meta_data["surface_tension"]["surface_tension_coefficient"] = surface_tension.surface_tension_coefficient end -function add_meta_data!(meta_data, system::DEMSystem) - meta_data["type"] = type2string(system) - return meta_data +function add_meta_data!(meta_data, boundary_zone) + meta_data["boundary_zone"] = Dict{String, Any}() + meta_data["boundary_zone"]["boundary_type"] = type2string(boundary_zone.boundary_type) + meta_data["boundary_zone"]["zone_width"] = boundary_zone.zone_width end From 7a4cddf0c47dfece2c7b1a3483192d98757d4558 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 28 Jul 2025 13:28:35 +0200 Subject: [PATCH 21/43] Enhance structure of the JSON-File --- src/io/io.jl | 191 ++++++++++++++++++++++++++++++++------------ src/io/write_vtk.jl | 5 ++ 2 files changed, 147 insertions(+), 49 deletions(-) diff --git a/src/io/io.jl b/src/io/io.jl index a42aaee0fe..0ad64cf2c4 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -44,70 +44,132 @@ end add_meta_data!(meta_data, ::Nothing) = meta_data +function add_meta_data!(meta_data, data) + ArgumentError("Unsupported data type: $(data). This data type is not implemented yet.") +end + function add_meta_data!(meta_data, system::FluidSystem) meta_data["system_type"] = type2string(system) + meta_data["particle_spacing"] = particle_spacing(system, 1) meta_data["density_calculator"] = type2string(system.density_calculator) meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length_factor"] = system.cache.smoothing_length_factor + meta_data["smoothing_length"] = system.cache.smoothing_length meta_data["acceleration"] = system.acceleration meta_data["sound_speed"] = system_sound_speed(system) - meta_data["background_pressure_TVF"] = system.transport_velocity isa Nothing ? "-" : - system.transport_velocity.background_pressure + meta_data["pressure_acceleration_formulation"] = nameof(system.pressure_acceleration_formulation) + add_meta_data!(meta_data, system.transport_velocity) add_meta_data!(meta_data, system.surface_tension) + add_meta_data!(meta_data, system.surface_normal_method) add_meta_data!(meta_data, system.viscosity) add_meta_data!(meta_data, system.correction) - if system isa WeaklyCompressibleSPHSystem - add_meta_data!(meta_data, system.state_equation) + add_meta_data!(meta_data, system_state_equation(system)) + if hasfield(typeof(system), :density_diffusion) + add_meta_data!(meta_data, system.density_diffusion) + end + if hasfield(typeof(system), :alpha) + meta_data["alpha"] = system.alpha end end function add_meta_data!(meta_data, system::TotalLagrangianSPHSystem) meta_data["system_type"] = type2string(system) - meta_data["young_modulus"] = system.young_modulus - meta_data["poisson_ratio"] = system.poisson_ratio - meta_data["lame_lambda"] = system.lame_lambda - meta_data["lame_mu"] = system.lame_mu + meta_data["particle_spacing"] = particle_spacing(system, 1) meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length_factor"] = initial_smoothing_length(system) / - particle_spacing(system, 1) - meta_data["penalty_force"] = system.penalty_force + meta_data["smoothing_length"] = system.smoothing_length meta_data["acceleration"] = system.acceleration add_meta_data!(meta_data, system.boundary_model) + add_meta_data!(meta_data, system.penalty_force) +end + +function add_meta_data!(meta_data, system::BoundarySPHSystem) + meta_data["system_type"] = type2string(system) + meta_data["particle_spacing"] = particle_spacing(system, 1) + meta_data["adhesion_coefficient"] = system.adhesion_coefficient + add_meta_data!(meta_data, system.boundary_model) + add_meta_data!(meta_data, system.movement) +end + +function add_meta_data!(meta_data, system::BoundaryDEMSystem) + meta_data["system_type"] = type2string(system) + meta_data["particle_spacing"] = particle_spacing(system, 1) + meta_data["normal_stiffness"] = system.normal_stiffness +end + +function add_meta_data!(meta_data, system::DEMSystem) + meta_data["system_type"] = type2string(system) + meta_data["particle_spacing"] = particle_spacing(system, 1) + meta_data["damping_coefficient"] = system.damping_coefficient + meta_data["acceleration"] = system.acceleration + add_meta_data!(meta_data, system.contact_model) end function add_meta_data!(meta_data, system::OpenBoundarySPHSystem) meta_data["system_type"] = type2string(system) + meta_data["particle_spacing"] = particle_spacing(system, 1) meta_data["reference_velocity"] = type2string(system.reference_velocity) meta_data["reference_pressure"] = type2string(system.reference_pressure) meta_data["reference_density"] = type2string(system.reference_density) + add_meta_data!(meta_data, system.boundary_model) add_meta_data!(meta_data, system.boundary_zone) end -function add_meta_data!(meta_data, system::BoundarySPHSystem) - meta_data["system_type"] = type2string(system) - add_meta_data!(meta_data, system.boundary_model) +function add_meta_data!(meta_data, boundary_model::BoundaryModelDummyParticles) + meta_data["boundary_model"] = Dict{String, Any}() + meta_data["boundary_model"]["model"] = type2string(boundary_model) + meta_data["boundary_model"]["smoothing_kernel"] = type2string(boundary_model.smoothing_kernel) + meta_data["boundary_model"]["smoothing_length"] = boundary_model.smoothing_length + meta_data["boundary_model"]["density_calculator"] = type2string(boundary_model.density_calculator) + add_meta_data!(meta_data["boundary_model"], boundary_model.state_equation) + add_meta_data!(meta_data["boundary_model"], boundary_model.viscosity) + add_meta_data!(meta_data["boundary_model"], boundary_model.correction) end -function add_meta_data!(meta_data, system::BoundaryDEMSystem) - meta_data["system_type"] = type2string(system) +function add_meta_data!(meta_data, boundary_model::BoundaryModelMonaghanKajtar) + meta_data["boundary_model"] = Dict{String, Any}() + meta_data["boundary_model"]["model"] = type2string(boundary_model) + meta_data["boundary_model"]["beta"] = boundary_model.beta + meta_data["boundary_model"]["K"] = boundary_model.K + add_meta_data!(meta_data["boundary_model"], boundary_model.viscosity) end -function add_meta_data!(meta_data, system::DEMSystem) - meta_data["system_type"] = type2string(system) +function add_meta_data!(meta_data, boundary_model::BoundaryModelTafuni) + meta_data["boundary_model"] = Dict{String, Any}() + meta_data["boundary_model"]["model"] = type2string(boundary_model) end -function add_meta_data!(meta_data, - state_equation::Union{StateEquationCole, StateEquationIdealGas}) +function add_meta_data!(meta_data, boundary_model::BoundaryModelLastiwka) + meta_data["boundary_model"] = Dict{String, Any}() + meta_data["boundary_model"]["model"] = type2string(boundary_model) + meta_data["boundary_model"]["extrapolate_reference_values"] = boundary_model.extrapolate_reference_values +end + +function add_meta_data!(meta_data, contact_model::HertzContactModel) + meta_data["contact_model"] = Dict{String, Any}() + meta_data["contact_model"]["model"] = type2string(contact_model) + meta_data["contact_model"]["elastic_modulus"] = contact_model.elastic_modulus + meta_data["contact_model"]["poissons_ratio"] = contact_model.poissons_ratio +end + +function add_meta_data!(meta_data, contact_model::LinearContactModel) + meta_data["contact_model"] = Dict{String, Any}() + meta_data["contact_model"]["model"] = type2string(contact_model) + meta_data["contact_model"]["normal_stiffness"] = contact_model.normal_stiffness +end + +function add_meta_data!(meta_data, state_equation::StateEquationCole) meta_data["state_equation"] = Dict{String, Any}() meta_data["state_equation"]["model"] = type2string(state_equation) meta_data["state_equation"]["reference_density"] = state_equation.reference_density meta_data["state_equation"]["background_pressure"] = state_equation.background_pressure - if state_equation isa StateEquationCole - meta_data["state_equation"]["exponent"] = state_equation.exponent - end - if state_equation isa StateEquationIdealGas - meta_data["state_equation"]["gamma"] = state_equation.gamma - end + meta_data["state_equation"]["exponent"] = state_equation.exponent +end + +function add_meta_data!(meta_data, state_equation::StateEquationIdealGas) + meta_data["state_equation"] = Dict{String, Any}() + meta_data["state_equation"]["model"] = type2string(state_equation) + meta_data["state_equation"]["reference_density"] = state_equation.reference_density + meta_data["state_equation"]["background_pressure"] = state_equation.background_pressure + meta_data["state_equation"]["gamma"] = state_equation.gamma end function add_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) @@ -117,6 +179,14 @@ function add_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMor meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon end +function add_meta_data!(meta_data, viscosity::Union{ViscosityAdamiSGS, ViscosityMorrisSGS}) + meta_data["viscosity_model"] = Dict{String, Any}() + meta_data["viscosity_model"]["model"] = type2string(viscosity) + meta_data["viscosity_model"]["nu"] = viscosity.nu + meta_data["viscosity_model"]["C_S"] = viscosity.C_S + meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon +end + function add_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) meta_data["viscosity_model"] = Dict{String, Any}() meta_data["viscosity_model"]["model"] = type2string(viscosity) @@ -125,35 +195,31 @@ function add_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon end -function add_meta_data!(meta_data, model::BoundaryModelMonaghanKajtar) - meta_data["boundary_model"] = Dict{String, Any}() - meta_data["boundary_model"]["model"] = "BoundaryModelMonaghanKajtar" - meta_data["boundary_model"]["beta"] = model.beta - meta_data["boundary_model"]["K"] = model.K - add_meta_data!(meta_data["boundary_model"], model.viscosity) +function add_meta_data!(meta_data, + density_diffusion::Union{DensityDiffusionAntuono, + DensityDiffusionMolteniColagrossi}) + meta_data["density_diffusion"] = Dict{String, Any}() + meta_data["density_diffusion"]["model"] = type2string(density_diffusion) + meta_data["density_diffusion"]["delta"] = density_diffusion.delta end -function add_meta_data!(meta_data, model::BoundaryModelDummyParticles) - meta_data["boundary_model"] = Dict{String, Any}() - meta_data["boundary_model"]["model"] = "BoundaryModelDummyParticles" - meta_data["boundary_model"]["smoothing_kernel"] = type2string(model.smoothing_kernel) - meta_data["boundary_model"]["smoothing_length"] = model.smoothing_length - meta_data["boundary_model"]["density_calculator"] = type2string(model.density_calculator) - add_meta_data!(meta_data["boundary_model"], model.state_equation) - add_meta_data!(meta_data["boundary_model"], model.viscosity) - add_meta_data!(meta_data["boundary_model"], model.correction) +function add_meta_data!(meta_data, density_diffusion::DensityDiffusionFerrari) + meta_data["density_diffusion"] = Dict{String, Any}() + meta_data["density_diffusion"]["model"] = type2string(density_diffusion) +end + +function add_meta_data!(meta_data, correction::AkinciFreeSurfaceCorrection) + meta_data["correction_method"] = Dict{String, Any}() + meta_data["correction_method"]["model"] = type2string(correction) + meta_data["correction_method"]["rho0"] = correction.rho end function add_meta_data!(meta_data, - correction::Union{AkinciFreeSurfaceCorrection, - BlendedGradientCorrection, - GradientCorrection, KernelCorrection, + correction::Union{BlendedGradientCorrection, GradientCorrection, + KernelCorrection, MixedKernelGradientCorrection, ShepardKernelCorrection}) meta_data["correction_method"] = Dict{String, Any}() meta_data["correction_method"]["model"] = type2string(correction) - if correction isa AkinciFreeSurfaceCorrection - meta_data["correction_method"]["rho0"] = correction.rho0 - end end function add_meta_data!(meta_data, @@ -165,8 +231,35 @@ function add_meta_data!(meta_data, meta_data["surface_tension"]["surface_tension_coefficient"] = surface_tension.surface_tension_coefficient end -function add_meta_data!(meta_data, boundary_zone) +function add_meta_data!(meta_data, surface_normal_method::ColorfieldSurfaceNormal) + meta_data["surface_normal_method"] = Dict{String, Any}() + meta_data["surface_normal_method"]["model"] = type2string(surface_normal_method) + meta_data["surface_normal_method"]["boundary_contact_threshold"] = surface_normal_method.boundary_contact_threshold + meta_data["surface_normal_method"]["ideal_density_threshold"] = surface_normal_method.ideal_density_threshold +end + +function add_meta_data!(meta_data, boundary_zone::BoundaryZone) meta_data["boundary_zone"] = Dict{String, Any}() meta_data["boundary_zone"]["boundary_type"] = type2string(boundary_zone.boundary_type) meta_data["boundary_zone"]["zone_width"] = boundary_zone.zone_width end + +function add_meta_data!(meta_data, movement::BoundaryMovement) + meta_data["movement"] = Dict{String, Any}() + meta_data["movement"]["model"] = type2string(movement) + meta_data["movement"]["movement_function"] = type2string(movement.movement_function) + meta_data["movement"]["is_moving"] = type2string(movement.is_moving) + meta_data["movement"]["moving_particles"] = movement.moving_particles +end + +function add_meta_data!(meta_data, penalty_force::PenaltyForceGanzenmueller) + meta_data["penalty_force"] = Dict{String, Any}() + meta_data["penalty_force"]["model"] = type2string(penalty_force) + meta_data["penalty_force"]["alpha"] = penalty_force.alpha +end + +function add_meta_data!(meta_data, transport_velocity::TransportVelocityAdami) + meta_data["transport_velocity"] = Dict{String, Any}() + meta_data["transport_velocity"]["model"] = type2string(transport_velocity) + meta_data["transport_velocity"]["background_pressure"] = transport_velocity.background_pressure +end diff --git a/src/io/write_vtk.jl b/src/io/write_vtk.jl index 4338e80b9a..74c92fc7b1 100644 --- a/src/io/write_vtk.jl +++ b/src/io/write_vtk.jl @@ -343,6 +343,11 @@ function write2vtk!(vtk, v, u, t, system::TotalLagrangianSPHSystem) initial_coords(system, particle) for particle in eachparticle(system)] + vtk["lame_lambda"] = system.lame_lambda + vtk["lame_mu"] = system.lame_mu + vtk["young_modulus"] = system.young_modulus + vtk["poisson_ratio"] = system.poisson_ratio + sigma = cauchy_stress(system) vtk["sigma_11"] = sigma[1, 1, :] vtk["sigma_22"] = sigma[2, 2, :] From 2a4e41981f848c9fe0ab2622f690452a0353efc9 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 28 Jul 2025 16:18:38 +0200 Subject: [PATCH 22/43] Fix `rho0` in `AkinciFreeSurfaceCorrection` --- src/io/io.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/io.jl b/src/io/io.jl index 0ad64cf2c4..afeb64f416 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -211,7 +211,7 @@ end function add_meta_data!(meta_data, correction::AkinciFreeSurfaceCorrection) meta_data["correction_method"] = Dict{String, Any}() meta_data["correction_method"]["model"] = type2string(correction) - meta_data["correction_method"]["rho0"] = correction.rho + meta_data["correction_method"]["rho0"] = correction.rho0 end function add_meta_data!(meta_data, From 08de26407f7e1d57d18e4f193f8a5642717e889f Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Fri, 13 Jun 2025 15:52:21 +0200 Subject: [PATCH 23/43] Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> --- examples/dem/collapsing_sand_pile_3d.jl | 3 +- examples/fsi/dam_break_gate_2d.jl | 8 +-- examples/fsi/dam_break_plate_2d.jl | 8 +-- examples/preprocessing/packing_2d.jl | 9 +-- examples/preprocessing/packing_3d.jl | 2 +- examples/solid/oscillating_beam_2d.jl | 6 +- src/general/interpolation.jl | 5 +- .../particle_packing/signed_distance.jl | 2 +- src/preprocessing/particle_packing/system.jl | 35 ++++++----- src/setups/complex_shape.jl | 10 ++-- src/setups/extrude_geometry.jl | 60 +++++++++++-------- src/setups/rectangular_shape.jl | 19 +++--- src/setups/sphere_shape.jl | 45 +++++++------- test/setups/extrude_geometry.jl | 7 ++- test/setups/rectangular_shape.jl | 5 +- test/setups/sphere_shape.jl | 8 +-- test/systems/packing_system.jl | 6 +- 17 files changed, 128 insertions(+), 110 deletions(-) diff --git a/examples/dem/collapsing_sand_pile_3d.jl b/examples/dem/collapsing_sand_pile_3d.jl index aa9ba7a56b..f463ac2417 100644 --- a/examples/dem/collapsing_sand_pile_3d.jl +++ b/examples/dem/collapsing_sand_pile_3d.jl @@ -55,7 +55,8 @@ min_coords_floor = (min_boundary[1] - boundary_thickness, floor_particles = RectangularShape(particle_spacing, (n_particles_floor_x, n_particles_floor_y, n_particles_floor_z), - min_coords_floor; density=boundary_density, tlsph=true) + min_coords_floor; density=boundary_density, + place_on_shell=true) boundary_particles = floor_particles # ========================================================================================== diff --git a/examples/fsi/dam_break_gate_2d.jl b/examples/fsi/dam_break_gate_2d.jl index 529fd56522..44adf7bc59 100644 --- a/examples/fsi/dam_break_gate_2d.jl +++ b/examples/fsi/dam_break_gate_2d.jl @@ -83,18 +83,18 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. # # The right end of the plate is 0.2 from the right end of the tank. plate_position = 0.6 - n_particles_x * solid_particle_spacing plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (plate_position, solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (plate_position, 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/fsi/dam_break_plate_2d.jl b/examples/fsi/dam_break_plate_2d.jl index f5b42ecaa0..d4f8b206fb 100644 --- a/examples/fsi/dam_break_plate_2d.jl +++ b/examples/fsi/dam_break_plate_2d.jl @@ -57,15 +57,15 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (2initial_fluid_size[1], solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (2initial_fluid_size[1], 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/preprocessing/packing_2d.jl b/examples/preprocessing/packing_2d.jl index fc8b330269..0975b6e2ad 100644 --- a/examples/preprocessing/packing_2d.jl +++ b/examples/preprocessing/packing_2d.jl @@ -20,7 +20,7 @@ file = pkgdir(TrixiParticles, "examples", "preprocessing", "data", filename * ". # ========================================================================================== # ==== Packing parameters -tlsph = false +place_on_shell = false # ========================================================================================== # ==== Resolution @@ -50,7 +50,7 @@ shape_sampled = ComplexShape(geometry; particle_spacing, density, # Returns `InitialCondition` boundary_sampled = sample_boundary(signed_distance_field; boundary_density=density, - boundary_thickness, tlsph=tlsph) + boundary_thickness, place_on_shell=place_on_shell) trixi2vtk(shape_sampled) trixi2vtk(boundary_sampled, filename="boundary") @@ -66,12 +66,13 @@ background_pressure = 1.0 smoothing_length = 0.8 * particle_spacing packing_system = ParticlePackingSystem(shape_sampled; smoothing_length=smoothing_length, - signed_distance_field, tlsph=tlsph, + signed_distance_field, place_on_shell=place_on_shell, background_pressure) boundary_system = ParticlePackingSystem(boundary_sampled; smoothing_length=smoothing_length, is_boundary=true, signed_distance_field, - tlsph=tlsph, boundary_compress_factor=0.8, + place_on_shell=place_on_shell, + boundary_compress_factor=0.8, background_pressure) # ========================================================================================== diff --git a/examples/preprocessing/packing_3d.jl b/examples/preprocessing/packing_3d.jl index cb15a255b2..ede3433b38 100644 --- a/examples/preprocessing/packing_3d.jl +++ b/examples/preprocessing/packing_3d.jl @@ -24,5 +24,5 @@ boundary_thickness = 8 * particle_spacing trixi_include(joinpath(examples_dir(), "preprocessing", "packing_2d.jl"), density=1000.0, particle_spacing=particle_spacing, file=file, - boundary_thickness=boundary_thickness, tlsph=true, + boundary_thickness=boundary_thickness, place_on_shell=true, save_intervals=false) diff --git a/examples/solid/oscillating_beam_2d.jl b/examples/solid/oscillating_beam_2d.jl index 8df52c28f1..28d371634d 100644 --- a/examples/solid/oscillating_beam_2d.jl +++ b/examples/solid/oscillating_beam_2d.jl @@ -38,7 +38,7 @@ fixed_particles = SphereShape(particle_spacing, clamp_radius + particle_spacing (0.0, elastic_beam.thickness / 2), material.density, cutout_min=(0.0, 0.0), cutout_max=(clamp_radius, elastic_beam.thickness), - tlsph=true) + place_on_shell=true) n_particles_clamp_x = round(Int, clamp_radius / particle_spacing) @@ -48,9 +48,9 @@ n_particles_per_dimension = (round(Int, elastic_beam.length / particle_spacing) # Note that the `RectangularShape` puts the first particle half a particle spacing away # from the boundary, which is correct for fluids, but not for solids. -# We therefore need to pass `tlsph=true`. +# We therefore need to pass `place_on_shell=true`. beam = RectangularShape(particle_spacing, n_particles_per_dimension, - (0.0, 0.0), density=material.density, tlsph=true) + (0.0, 0.0), density=material.density, place_on_shell=true) solid = union(beam, fixed_particles) diff --git a/src/general/interpolation.jl b/src/general/interpolation.jl index 9b0ac40d7f..6ca3fa16f3 100644 --- a/src/general/interpolation.jl +++ b/src/general/interpolation.jl @@ -191,9 +191,10 @@ function interpolate_plane_2d(min_corner, max_corner, resolution, semi, ref_syst x_range = range(min_corner[1], max_corner[1], length=n_points_per_dimension[1]) y_range = range(min_corner[2], max_corner[2], length=n_points_per_dimension[2]) - # Generate points within the plane. Use `tlsph=true` to generate points on the boundary + # Generate points within the plane. Use `place_on_shell=true` to generate points + # on the shell of the geometry. point_coords = rectangular_shape_coords(resolution, n_points_per_dimension, min_corner, - tlsph=true) + place_on_shell=true) results = interpolate_points(point_coords, semi, ref_system, v_ode, u_ode, smoothing_length=smoothing_length, diff --git a/src/preprocessing/particle_packing/signed_distance.jl b/src/preprocessing/particle_packing/signed_distance.jl index 7e957e124d..082deced5a 100644 --- a/src/preprocessing/particle_packing/signed_distance.jl +++ b/src/preprocessing/particle_packing/signed_distance.jl @@ -59,7 +59,7 @@ function SignedDistanceField(geometry, particle_spacing; particle_spacing)) grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) points = reinterpret(reshape, SVector{NDIMS, ELTYPE}, grid) end diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index 1318f63544..77be7e0c59 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -6,7 +6,7 @@ smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, fixed_system=false) System to generate body-fitted particles for complex shapes. For more information on the methods, see [particle packing](@ref particle_packing). @@ -18,10 +18,11 @@ For more information on the methods, see [particle packing](@ref particle_packin - `background_pressure`: Constant background pressure to physically pack the particles. A large `background_pressure` can cause high accelerations which requires a properly adjusted time step. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not half a particle spacing away, - as for fluids. When `tlsph=true`, particles will be placed - on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. - `is_boundary`: When `shape` is inside the geometry that was used to create `signed_distance_field`, set `is_boundary=false`. Otherwise (`shape` is the sampled boundary), set `is_boundary=true`. @@ -64,7 +65,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, smoothing_kernel :: K smoothing_length_interpolation :: ELTYPE background_pressure :: ELTYPE - tlsph :: Bool + place_on_shell :: Bool signed_distance_field :: S is_boundary :: Bool shift_length :: ELTYPE @@ -79,7 +80,8 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, # See the comments in general/gpu.jl for more details. function ParticlePackingSystem(initial_condition, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, + signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, buffer, update_callback_used, fixed_system, cache, @@ -93,7 +95,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, @@ -108,7 +110,8 @@ function ParticlePackingSystem(shape::InitialCondition; smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, + fixed_system=false) NDIMS = ndims(shape) ELTYPE = eltype(shape) mass = copy(shape.mass) @@ -147,12 +150,12 @@ function ParticlePackingSystem(shape::InitialCondition; # Its value is negative if the particle is inside the geometry. # Otherwise (if outside), the value is positive. if is_boundary - offset = tlsph ? shape.particle_spacing : shape.particle_spacing / 2 + offset = place_on_shell ? shape.particle_spacing : shape.particle_spacing / 2 shift_length = -boundary_compress_factor * signed_distance_field.max_signed_distance - offset else - shift_length = tlsph ? zero(ELTYPE) : shape.particle_spacing / 2 + shift_length = place_on_shell ? zero(ELTYPE) : shape.particle_spacing / 2 end cache = (; create_cache_refinement(shape, particle_refinement, smoothing_length)...) @@ -161,7 +164,7 @@ function ParticlePackingSystem(shape::InitialCondition; return ParticlePackingSystem(shape, mass, density, shape.particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, nhs, fill(zero(ELTYPE), nparticles(shape)), particle_refinement, nothing, Ref(false), fixed_system, cache, @@ -187,7 +190,7 @@ function Base.show(io::IO, ::MIME"text/plain", system::ParticlePackingSystem) system.neighborhood_search |> typeof |> nameof) summary_line(io, "#particles", nparticles(system)) summary_line(io, "smoothing kernel", system.smoothing_kernel |> typeof |> nameof) - summary_line(io, "tlsph", system.tlsph ? "yes" : "no") + summary_line(io, "place_on_shell", system.place_on_shell ? "yes" : "no") summary_line(io, "boundary", system.is_boundary ? "yes" : "no") summary_footer(io) end @@ -349,8 +352,8 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector (; shift_length) = system # For fluid particles: - # - `tlsph = true`: `shift_length = 0` - # - `tlsph = false`: `shift_length = particle_spacing / 2` + # - `place_on_shell = true`: `shift_length = 0` + # - `place_on_shell = false`: `shift_length = particle_spacing / 2` # For boundary particles: # `shift_length` is the thickness of the boundary. if distance_signed >= -shift_length @@ -365,7 +368,7 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector system.is_boundary || return u particle_spacing = system.initial_condition.particle_spacing - shift_length_inner = system.tlsph ? particle_spacing : particle_spacing / 2 + shift_length_inner = system.place_on_shell ? particle_spacing : particle_spacing / 2 if distance_signed < shift_length_inner shift = (distance_signed - shift_length_inner) * normal_vector diff --git a/src/setups/complex_shape.jl b/src/setups/complex_shape.jl index 2c515157d1..594b3b4f37 100644 --- a/src/setups/complex_shape.jl +++ b/src/setups/complex_shape.jl @@ -79,7 +79,7 @@ end """ sample_boundary(signed_distance_field::SignedDistanceField; - boundary_thickness::Real, tlsph=true) + boundary_thickness::Real, place_on_shell=true) Sample boundary particles of a complex geometry by using the [`SignedDistanceField`](@ref) of the geometry. @@ -89,9 +89,9 @@ of the geometry. # Keywords - `boundary_thickness`: Thickness of the boundary -- `tlsph` : When `tlsph=true`, boundary particles will be placed +- `place_on_shell`: When `place_on_shell=true`, boundary particles will be placed one particle spacing from the surface of the geometry. - Otherwise when `tlsph=true` (simulating fluid particles), + Otherwise when `place_on_shell=true` (simulating fluid particles), boundary particles will be placed half particle spacing away from the surface. @@ -117,7 +117,7 @@ boundary_sampled = sample_boundary(signed_distance_field; boundary_density=1.0, ``` """ function sample_boundary(signed_distance_field; - boundary_density, boundary_thickness, tlsph=true) + boundary_density, boundary_thickness, place_on_shell=true) (; max_signed_distance, boundary_packing, positions, distances, particle_spacing) = signed_distance_field @@ -157,6 +157,6 @@ function particle_grid(geometry, particle_spacing; end grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) return reinterpret(reshape, SVector{ndims(geometry), eltype(geometry)}, grid) end diff --git a/src/setups/extrude_geometry.jl b/src/setups/extrude_geometry.jl index 498266ecd0..6d169762c7 100644 --- a/src/setups/extrude_geometry.jl +++ b/src/setups/extrude_geometry.jl @@ -30,9 +30,11 @@ Returns an [`InitialCondition`](@ref). - `pressure`: Scalar to set the pressure of all particles to this value. This is only used by the [`EntropicallyDampedSPHSystem`](@ref) and will be overwritten when using an initial pressure function in the system. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. # Examples ```jldoctest; output = false @@ -79,7 +81,7 @@ shape = extrude_geometry(shape; direction, particle_spacing=0.1, n_extrude=4, de This is an experimental feature and may change in any future releases. """ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::Integer, - velocity=zeros(length(direction)), tlsph=false, + velocity=zeros(length(direction)), place_on_shell=false, mass=nothing, density=nothing, pressure=0.0) direction_ = normalize(direction) NDIMS = length(direction_) @@ -95,9 +97,11 @@ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::I throw(ArgumentError("`particle_spacing` must be specified when not extruding an `InitialCondition`")) end - geometry = shift_plane_corners(geometry, direction_, particle_spacing, tlsph) + geometry = shift_plane_corners(geometry, direction_, particle_spacing, place_on_shell) - face_coords, particle_spacing_ = sample_plane(geometry, particle_spacing; tlsph=tlsph) + face_coords, + particle_spacing_ = sample_plane(geometry, particle_spacing; + place_on_shell=place_on_shell) if !isapprox(particle_spacing, particle_spacing_, rtol=5e-2) @info "The desired size is not a multiple of the particle spacing $particle_spacing." * @@ -119,12 +123,13 @@ end # For corners/endpoints of a plane/line, sample the plane/line with particles. # For 2D coordinates or an `InitialCondition`, add a third dimension. -function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) +function sample_plane(geometry::AbstractMatrix, particle_spacing; place_on_shell) if size(geometry, 1) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane - coords = vcat(geometry, fill(tlsph ? 0 : particle_spacing / 2, size(geometry, 2))') + # When `place_on_shell=true`, particles will be placed on the x-y plane + coords = vcat(geometry, + fill(place_on_shell ? 0 : particle_spacing / 2, size(geometry, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -133,13 +138,14 @@ function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) return geometry, particle_spacing end -function sample_plane(shape::InitialCondition, particle_spacing; tlsph) +function sample_plane(shape::InitialCondition, particle_spacing; place_on_shell) if ndims(shape) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane + # When `place_on_shell=true`, particles will be placed on the x-y plane coords = vcat(shape.coordinates, - fill(tlsph ? 0 : particle_spacing / 2, size(shape.coordinates, 2))') + fill(place_on_shell ? 0 : particle_spacing / 2, + size(shape.coordinates, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -148,13 +154,13 @@ function sample_plane(shape::InitialCondition, particle_spacing; tlsph) return shape.coordinates, particle_spacing end -function sample_plane(plane_points, particle_spacing; tlsph=nothing) +function sample_plane(plane_points, particle_spacing; place_on_shell=nothing) # Convert to tuple - return sample_plane(tuple(plane_points...), particle_spacing; tlsph=nothing) + return sample_plane(tuple(plane_points...), particle_spacing; place_on_shell=nothing) end -function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{2}, particle_spacing; place_on_shell=nothing) # Verify that points are in 2D space if any(length.(plane_points) .!= 2) throw(ArgumentError("all points must be 2D coordinates")) @@ -168,7 +174,7 @@ function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{3}, particle_spacing; place_on_shell=nothing) # Verify that points are in 3D space if any(length.(plane_points) .!= 3) throw(ArgumentError("all points must be 3D coordinates")) @@ -209,21 +215,22 @@ function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -# Shift corners of the plane/line inwards by half a particle spacing with `tlsph=false` +# Shift corners of the plane/line inwards by half a particle spacing with `place_on_shell=false` # because fluid particles need to be half a particle spacing away from the boundary of the shape. function shift_plane_corners(geometry::Union{AbstractMatrix, InitialCondition}, - direction, particle_spacing, tlsph) + direction, particle_spacing, place_on_shell) return geometry end -function shift_plane_corners(plane_points, direction, particle_spacing, tlsph) - shift_plane_corners(tuple(plane_points...), direction, particle_spacing, tlsph) +function shift_plane_corners(plane_points, direction, particle_spacing, place_on_shell) + shift_plane_corners(tuple(plane_points...), direction, particle_spacing, place_on_shell) end -function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) @@ -238,10 +245,11 @@ function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacin return (plane_point1, plane_point2) end -function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) diff --git a/src/setups/rectangular_shape.jl b/src/setups/rectangular_shape.jl index 98160bcac9..1c30ef5c1b 100644 --- a/src/setups/rectangular_shape.jl +++ b/src/setups/rectangular_shape.jl @@ -3,7 +3,7 @@ velocity=zeros(length(n_particles_per_dimension)), mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). @@ -40,9 +40,10 @@ Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). - `state_equation`: When calculating a hydrostatic pressure gradient by setting `acceleration`, the `state_equation` will be used to set the corresponding density. Cannot be used together with `density`. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. - `coordinates_perturbation`: Add a small random displacement to the particle positions, where the amplitude is `coordinates_perturbation * particle_spacing`. @@ -75,7 +76,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord coordinates_perturbation=nothing, mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) end @@ -95,7 +96,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord n_particles = prod(n_particles_per_dimension) coordinates = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates, tlsph=tlsph, + min_coordinates, place_on_shell=place_on_shell, loop_order=loop_order) if !isnothing(coordinates_perturbation) @@ -190,15 +191,15 @@ function loop_permutation(loop_order, NDIMS::Val{3}) end function rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates; tlsph=false, loop_order=nothing) + min_coordinates; place_on_shell=false, loop_order=nothing) ELTYPE = eltype(particle_spacing) NDIMS = length(n_particles_per_dimension) coordinates = Array{ELTYPE, 2}(undef, NDIMS, prod(n_particles_per_dimension)) - # With TLSPH, particles need to be AT the min coordinates and not half a particle + # With place_on_shell, particles need to be AT the min coordinates and not half a particle # spacing away from it. - if tlsph + if place_on_shell min_coordinates = min_coordinates .- 0.5particle_spacing end diff --git a/src/setups/sphere_shape.jl b/src/setups/sphere_shape.jl index 0233fc8995..3c6a7466d5 100644 --- a/src/setups/sphere_shape.jl +++ b/src/setups/sphere_shape.jl @@ -1,7 +1,7 @@ """ SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0.0) Generate a sphere that is either completely filled (by default) @@ -35,18 +35,19 @@ coordinate directions as `cutout_min` and `cutout_max`. cut out of the sphere. - `cutout_max`: Corner in positive coordinate directions of a cuboid that is to be cut out of the sphere. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. -- `velocity`: Either a function mapping each particle's coordinates to its velocity, - or, for a constant fluid velocity, a vector holding this velocity. - Velocity is constant zero by default. -- `mass`: Either `nothing` (default) to automatically compute particle mass from particle - density and spacing, or a function mapping each particle's coordinates to its mass, - or a scalar for a constant mass over all particles. -- `pressure`: Either a function mapping each particle's coordinates to its pressure, - or a scalar for a constant pressure over all particles. This is optional and - only needed when using the [`EntropicallyDampedSPHSystem`](@ref). +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. +- `velocity`: Either a function mapping each particle's coordinates to its velocity, + or, for a constant fluid velocity, a vector holding this velocity. + Velocity is constant zero by default. +- `mass`: Either `nothing` (default) to automatically compute particle mass from particle + density and spacing, or a function mapping each particle's coordinates to its mass, + or a scalar for a constant mass over all particles. +- `pressure`: Either a function mapping each particle's coordinates to its pressure, + or a scalar for a constant pressure over all particles. This is optional and + only needed when using the [`EntropicallyDampedSPHSystem`](@ref). # Examples ```jldoctest; output = false @@ -89,7 +90,7 @@ SphereShape(0.1, 0.5, (0.2, 0.4, 0.3), 1000.0, sphere_type=RoundSphere()) """ function SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) @@ -99,7 +100,7 @@ function SphereShape(particle_spacing, radius, center_position, density; coordinates = sphere_shape_coords(sphere_type, particle_spacing, radius, SVector{NDIMS}(center_position), - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) # Convert tuples to vectors cutout_min_ = collect(cutout_min) @@ -169,13 +170,13 @@ struct RoundSphere{AR} end function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_position, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius outer_radius = radius + n_layers * particle_spacing - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of `radius` inner_radius += particle_spacing / 2 outer_radius += particle_spacing / 2 @@ -184,7 +185,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos inner_radius = radius - n_layers * particle_spacing outer_radius = radius - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` inner_radius -= particle_spacing / 2 outer_radius -= particle_spacing / 2 @@ -194,7 +195,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos outer_radius = radius inner_radius = -1 - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` outer_radius -= particle_spacing / 2 end @@ -225,7 +226,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos end function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, center, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius @@ -233,12 +234,12 @@ function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, cent inner_radius = radius - n_layers * particle_spacing end - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of inner radius inner_radius += particle_spacing / 2 end else - if tlsph + if place_on_shell # Just create a sphere that is 0.5 particle spacing larger radius += particle_spacing / 2 end diff --git a/test/setups/extrude_geometry.jl b/test/setups/extrude_geometry.jl index e695f2e170..5a927dbee4 100644 --- a/test/setups/extrude_geometry.jl +++ b/test/setups/extrude_geometry.jl @@ -28,7 +28,8 @@ ] @testset "Direction $i" for i in eachindex(directions) - shape = extrude_geometry((point1, point2); direction=directions[i], tlsph=true, + shape = extrude_geometry((point1, point2); direction=directions[i], + place_on_shell=true, particle_spacing=0.15, n_extrude=5, density=1.0) @test shape.coordinates ≈ expected_coords[i] @@ -68,7 +69,7 @@ end @testset "Direction $i" for i in eachindex(directions) shape = extrude_geometry(geometry; direction=directions[i], particle_spacing, - n_extrude=5, tlsph=true, density=1.0) + n_extrude=5, place_on_shell=true, density=1.0) @test shape.coordinates ≈ expected_coords[i] end @@ -86,7 +87,7 @@ end 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.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061] shape = extrude_geometry((p1, p2, p3); direction, particle_spacing=0.1, n_extrude=4, - density=1000.0, tlsph=true) + density=1000.0, place_on_shell=true) @test shape.coordinates ≈ expected_coords end diff --git a/test/setups/rectangular_shape.jl b/test/setups/rectangular_shape.jl index f3e77043b0..7c2fd6875b 100644 --- a/test/setups/rectangular_shape.jl +++ b/test/setups/rectangular_shape.jl @@ -41,7 +41,8 @@ ] @testset "$(loop_orders[i])" for i in eachindex(loop_orders) - shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, tlsph=true, + shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] @@ -242,7 +243,7 @@ end @testset "$(loop_orders[i])" for i in eachindex(loop_orders) shape = RectangularShape(1.0, (2, 2, 2), (0.0, 0.0, 0.0), density=1.0, - tlsph=true, loop_order=loop_orders[i]) + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] end diff --git a/test/setups/sphere_shape.jl b/test/setups/sphere_shape.jl index 57d904a376..c8b87d76db 100644 --- a/test/setups/sphere_shape.jl +++ b/test/setups/sphere_shape.jl @@ -106,14 +106,14 @@ SphereShape(1.0, 1.1, (0.2, -1.0, 0.3), 1000.0, sphere_type=RoundSphere()), SphereShape(1.0, 1.2, (-0.3, 0.1, 0.8), 1000.0, sphere_type=RoundSphere()), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, cutout_min=(0.18, 0.4, 0.5), - cutout_max=(0.42, 10.0, 1.0), tlsph=true), - SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, tlsph=true), + cutout_max=(0.42, 10.0, 1.0), place_on_shell=true), + SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, - layer_outwards=true, tlsph=true), + layer_outwards=true, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, sphere_type=RoundSphere()), SphereShape(0.1, 0.55, (0.3, 0.4, 0.5), 1000.0, n_layers=2, layer_outwards=true, - sphere_type=RoundSphere(), tlsph=true) + sphere_type=RoundSphere(), place_on_shell=true) ] expected_coords = [ diff --git a/test/systems/packing_system.jl b/test/systems/packing_system.jl index d55afd559a..b42e534275 100644 --- a/test/systems/packing_system.jl +++ b/test/systems/packing_system.jl @@ -19,7 +19,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -36,7 +36,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… yes │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -52,7 +52,7 @@ │ neighborhood search: ………………………… Nothing │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" end From 38a1e2f67ee271017efa6b6bac6a5571154344a1 Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Fri, 13 Jun 2025 15:52:21 +0200 Subject: [PATCH 24/43] Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> --- examples/dem/collapsing_sand_pile_3d.jl | 3 +- examples/fsi/dam_break_gate_2d.jl | 8 +-- examples/fsi/dam_break_plate_2d.jl | 8 +-- examples/preprocessing/packing_2d.jl | 9 +-- examples/preprocessing/packing_3d.jl | 2 +- examples/solid/oscillating_beam_2d.jl | 6 +- src/general/interpolation.jl | 5 +- .../particle_packing/signed_distance.jl | 2 +- src/preprocessing/particle_packing/system.jl | 35 ++++++----- src/setups/complex_shape.jl | 10 ++-- src/setups/extrude_geometry.jl | 60 +++++++++++-------- src/setups/rectangular_shape.jl | 19 +++--- src/setups/sphere_shape.jl | 45 +++++++------- test/setups/extrude_geometry.jl | 7 ++- test/setups/rectangular_shape.jl | 5 +- test/setups/sphere_shape.jl | 8 +-- test/systems/packing_system.jl | 6 +- 17 files changed, 128 insertions(+), 110 deletions(-) diff --git a/examples/dem/collapsing_sand_pile_3d.jl b/examples/dem/collapsing_sand_pile_3d.jl index aa9ba7a56b..f463ac2417 100644 --- a/examples/dem/collapsing_sand_pile_3d.jl +++ b/examples/dem/collapsing_sand_pile_3d.jl @@ -55,7 +55,8 @@ min_coords_floor = (min_boundary[1] - boundary_thickness, floor_particles = RectangularShape(particle_spacing, (n_particles_floor_x, n_particles_floor_y, n_particles_floor_z), - min_coords_floor; density=boundary_density, tlsph=true) + min_coords_floor; density=boundary_density, + place_on_shell=true) boundary_particles = floor_particles # ========================================================================================== diff --git a/examples/fsi/dam_break_gate_2d.jl b/examples/fsi/dam_break_gate_2d.jl index 529fd56522..44adf7bc59 100644 --- a/examples/fsi/dam_break_gate_2d.jl +++ b/examples/fsi/dam_break_gate_2d.jl @@ -83,18 +83,18 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. # # The right end of the plate is 0.2 from the right end of the tank. plate_position = 0.6 - n_particles_x * solid_particle_spacing plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (plate_position, solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (plate_position, 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/fsi/dam_break_plate_2d.jl b/examples/fsi/dam_break_plate_2d.jl index f5b42ecaa0..d4f8b206fb 100644 --- a/examples/fsi/dam_break_plate_2d.jl +++ b/examples/fsi/dam_break_plate_2d.jl @@ -57,15 +57,15 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (2initial_fluid_size[1], solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (2initial_fluid_size[1], 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/preprocessing/packing_2d.jl b/examples/preprocessing/packing_2d.jl index fc8b330269..0975b6e2ad 100644 --- a/examples/preprocessing/packing_2d.jl +++ b/examples/preprocessing/packing_2d.jl @@ -20,7 +20,7 @@ file = pkgdir(TrixiParticles, "examples", "preprocessing", "data", filename * ". # ========================================================================================== # ==== Packing parameters -tlsph = false +place_on_shell = false # ========================================================================================== # ==== Resolution @@ -50,7 +50,7 @@ shape_sampled = ComplexShape(geometry; particle_spacing, density, # Returns `InitialCondition` boundary_sampled = sample_boundary(signed_distance_field; boundary_density=density, - boundary_thickness, tlsph=tlsph) + boundary_thickness, place_on_shell=place_on_shell) trixi2vtk(shape_sampled) trixi2vtk(boundary_sampled, filename="boundary") @@ -66,12 +66,13 @@ background_pressure = 1.0 smoothing_length = 0.8 * particle_spacing packing_system = ParticlePackingSystem(shape_sampled; smoothing_length=smoothing_length, - signed_distance_field, tlsph=tlsph, + signed_distance_field, place_on_shell=place_on_shell, background_pressure) boundary_system = ParticlePackingSystem(boundary_sampled; smoothing_length=smoothing_length, is_boundary=true, signed_distance_field, - tlsph=tlsph, boundary_compress_factor=0.8, + place_on_shell=place_on_shell, + boundary_compress_factor=0.8, background_pressure) # ========================================================================================== diff --git a/examples/preprocessing/packing_3d.jl b/examples/preprocessing/packing_3d.jl index cb15a255b2..ede3433b38 100644 --- a/examples/preprocessing/packing_3d.jl +++ b/examples/preprocessing/packing_3d.jl @@ -24,5 +24,5 @@ boundary_thickness = 8 * particle_spacing trixi_include(joinpath(examples_dir(), "preprocessing", "packing_2d.jl"), density=1000.0, particle_spacing=particle_spacing, file=file, - boundary_thickness=boundary_thickness, tlsph=true, + boundary_thickness=boundary_thickness, place_on_shell=true, save_intervals=false) diff --git a/examples/solid/oscillating_beam_2d.jl b/examples/solid/oscillating_beam_2d.jl index 8df52c28f1..28d371634d 100644 --- a/examples/solid/oscillating_beam_2d.jl +++ b/examples/solid/oscillating_beam_2d.jl @@ -38,7 +38,7 @@ fixed_particles = SphereShape(particle_spacing, clamp_radius + particle_spacing (0.0, elastic_beam.thickness / 2), material.density, cutout_min=(0.0, 0.0), cutout_max=(clamp_radius, elastic_beam.thickness), - tlsph=true) + place_on_shell=true) n_particles_clamp_x = round(Int, clamp_radius / particle_spacing) @@ -48,9 +48,9 @@ n_particles_per_dimension = (round(Int, elastic_beam.length / particle_spacing) # Note that the `RectangularShape` puts the first particle half a particle spacing away # from the boundary, which is correct for fluids, but not for solids. -# We therefore need to pass `tlsph=true`. +# We therefore need to pass `place_on_shell=true`. beam = RectangularShape(particle_spacing, n_particles_per_dimension, - (0.0, 0.0), density=material.density, tlsph=true) + (0.0, 0.0), density=material.density, place_on_shell=true) solid = union(beam, fixed_particles) diff --git a/src/general/interpolation.jl b/src/general/interpolation.jl index 9b0ac40d7f..6ca3fa16f3 100644 --- a/src/general/interpolation.jl +++ b/src/general/interpolation.jl @@ -191,9 +191,10 @@ function interpolate_plane_2d(min_corner, max_corner, resolution, semi, ref_syst x_range = range(min_corner[1], max_corner[1], length=n_points_per_dimension[1]) y_range = range(min_corner[2], max_corner[2], length=n_points_per_dimension[2]) - # Generate points within the plane. Use `tlsph=true` to generate points on the boundary + # Generate points within the plane. Use `place_on_shell=true` to generate points + # on the shell of the geometry. point_coords = rectangular_shape_coords(resolution, n_points_per_dimension, min_corner, - tlsph=true) + place_on_shell=true) results = interpolate_points(point_coords, semi, ref_system, v_ode, u_ode, smoothing_length=smoothing_length, diff --git a/src/preprocessing/particle_packing/signed_distance.jl b/src/preprocessing/particle_packing/signed_distance.jl index 7e957e124d..082deced5a 100644 --- a/src/preprocessing/particle_packing/signed_distance.jl +++ b/src/preprocessing/particle_packing/signed_distance.jl @@ -59,7 +59,7 @@ function SignedDistanceField(geometry, particle_spacing; particle_spacing)) grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) points = reinterpret(reshape, SVector{NDIMS, ELTYPE}, grid) end diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index 1318f63544..77be7e0c59 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -6,7 +6,7 @@ smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, fixed_system=false) System to generate body-fitted particles for complex shapes. For more information on the methods, see [particle packing](@ref particle_packing). @@ -18,10 +18,11 @@ For more information on the methods, see [particle packing](@ref particle_packin - `background_pressure`: Constant background pressure to physically pack the particles. A large `background_pressure` can cause high accelerations which requires a properly adjusted time step. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not half a particle spacing away, - as for fluids. When `tlsph=true`, particles will be placed - on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. - `is_boundary`: When `shape` is inside the geometry that was used to create `signed_distance_field`, set `is_boundary=false`. Otherwise (`shape` is the sampled boundary), set `is_boundary=true`. @@ -64,7 +65,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, smoothing_kernel :: K smoothing_length_interpolation :: ELTYPE background_pressure :: ELTYPE - tlsph :: Bool + place_on_shell :: Bool signed_distance_field :: S is_boundary :: Bool shift_length :: ELTYPE @@ -79,7 +80,8 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, # See the comments in general/gpu.jl for more details. function ParticlePackingSystem(initial_condition, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, + signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, buffer, update_callback_used, fixed_system, cache, @@ -93,7 +95,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, @@ -108,7 +110,8 @@ function ParticlePackingSystem(shape::InitialCondition; smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, + fixed_system=false) NDIMS = ndims(shape) ELTYPE = eltype(shape) mass = copy(shape.mass) @@ -147,12 +150,12 @@ function ParticlePackingSystem(shape::InitialCondition; # Its value is negative if the particle is inside the geometry. # Otherwise (if outside), the value is positive. if is_boundary - offset = tlsph ? shape.particle_spacing : shape.particle_spacing / 2 + offset = place_on_shell ? shape.particle_spacing : shape.particle_spacing / 2 shift_length = -boundary_compress_factor * signed_distance_field.max_signed_distance - offset else - shift_length = tlsph ? zero(ELTYPE) : shape.particle_spacing / 2 + shift_length = place_on_shell ? zero(ELTYPE) : shape.particle_spacing / 2 end cache = (; create_cache_refinement(shape, particle_refinement, smoothing_length)...) @@ -161,7 +164,7 @@ function ParticlePackingSystem(shape::InitialCondition; return ParticlePackingSystem(shape, mass, density, shape.particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, nhs, fill(zero(ELTYPE), nparticles(shape)), particle_refinement, nothing, Ref(false), fixed_system, cache, @@ -187,7 +190,7 @@ function Base.show(io::IO, ::MIME"text/plain", system::ParticlePackingSystem) system.neighborhood_search |> typeof |> nameof) summary_line(io, "#particles", nparticles(system)) summary_line(io, "smoothing kernel", system.smoothing_kernel |> typeof |> nameof) - summary_line(io, "tlsph", system.tlsph ? "yes" : "no") + summary_line(io, "place_on_shell", system.place_on_shell ? "yes" : "no") summary_line(io, "boundary", system.is_boundary ? "yes" : "no") summary_footer(io) end @@ -349,8 +352,8 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector (; shift_length) = system # For fluid particles: - # - `tlsph = true`: `shift_length = 0` - # - `tlsph = false`: `shift_length = particle_spacing / 2` + # - `place_on_shell = true`: `shift_length = 0` + # - `place_on_shell = false`: `shift_length = particle_spacing / 2` # For boundary particles: # `shift_length` is the thickness of the boundary. if distance_signed >= -shift_length @@ -365,7 +368,7 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector system.is_boundary || return u particle_spacing = system.initial_condition.particle_spacing - shift_length_inner = system.tlsph ? particle_spacing : particle_spacing / 2 + shift_length_inner = system.place_on_shell ? particle_spacing : particle_spacing / 2 if distance_signed < shift_length_inner shift = (distance_signed - shift_length_inner) * normal_vector diff --git a/src/setups/complex_shape.jl b/src/setups/complex_shape.jl index cdb8e146b6..032250ce56 100644 --- a/src/setups/complex_shape.jl +++ b/src/setups/complex_shape.jl @@ -79,7 +79,7 @@ end """ sample_boundary(signed_distance_field; - boundary_density, boundary_thickness, tlsph=true) + boundary_density, boundary_thickness, place_on_shell=true) Sample boundary particles of a complex geometry by using the [`SignedDistanceField`](@ref) of the geometry. @@ -90,9 +90,9 @@ of the geometry. # Keywords - `boundary_thickness`: Thickness of the boundary - `boundary_density`: Density of each boundary particle. -- `tlsph` : When `tlsph=true`, boundary particles will be placed +- `place_on_shell`: When `place_on_shell=true`, boundary particles will be placed one particle spacing from the surface of the geometry. - Otherwise when `tlsph=true` (simulating fluid particles), + Otherwise when `place_on_shell=true` (simulating fluid particles), boundary particles will be placed half particle spacing away from the surface. @@ -118,7 +118,7 @@ boundary_sampled = sample_boundary(signed_distance_field; boundary_density=1.0, ``` """ function sample_boundary(signed_distance_field; - boundary_density, boundary_thickness, tlsph=true) + boundary_density, boundary_thickness, place_on_shell=true) (; max_signed_distance, boundary_packing, positions, distances, particle_spacing) = signed_distance_field @@ -158,6 +158,6 @@ function particle_grid(geometry, particle_spacing; end grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) return reinterpret(reshape, SVector{ndims(geometry), eltype(geometry)}, grid) end diff --git a/src/setups/extrude_geometry.jl b/src/setups/extrude_geometry.jl index 498266ecd0..6d169762c7 100644 --- a/src/setups/extrude_geometry.jl +++ b/src/setups/extrude_geometry.jl @@ -30,9 +30,11 @@ Returns an [`InitialCondition`](@ref). - `pressure`: Scalar to set the pressure of all particles to this value. This is only used by the [`EntropicallyDampedSPHSystem`](@ref) and will be overwritten when using an initial pressure function in the system. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. # Examples ```jldoctest; output = false @@ -79,7 +81,7 @@ shape = extrude_geometry(shape; direction, particle_spacing=0.1, n_extrude=4, de This is an experimental feature and may change in any future releases. """ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::Integer, - velocity=zeros(length(direction)), tlsph=false, + velocity=zeros(length(direction)), place_on_shell=false, mass=nothing, density=nothing, pressure=0.0) direction_ = normalize(direction) NDIMS = length(direction_) @@ -95,9 +97,11 @@ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::I throw(ArgumentError("`particle_spacing` must be specified when not extruding an `InitialCondition`")) end - geometry = shift_plane_corners(geometry, direction_, particle_spacing, tlsph) + geometry = shift_plane_corners(geometry, direction_, particle_spacing, place_on_shell) - face_coords, particle_spacing_ = sample_plane(geometry, particle_spacing; tlsph=tlsph) + face_coords, + particle_spacing_ = sample_plane(geometry, particle_spacing; + place_on_shell=place_on_shell) if !isapprox(particle_spacing, particle_spacing_, rtol=5e-2) @info "The desired size is not a multiple of the particle spacing $particle_spacing." * @@ -119,12 +123,13 @@ end # For corners/endpoints of a plane/line, sample the plane/line with particles. # For 2D coordinates or an `InitialCondition`, add a third dimension. -function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) +function sample_plane(geometry::AbstractMatrix, particle_spacing; place_on_shell) if size(geometry, 1) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane - coords = vcat(geometry, fill(tlsph ? 0 : particle_spacing / 2, size(geometry, 2))') + # When `place_on_shell=true`, particles will be placed on the x-y plane + coords = vcat(geometry, + fill(place_on_shell ? 0 : particle_spacing / 2, size(geometry, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -133,13 +138,14 @@ function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) return geometry, particle_spacing end -function sample_plane(shape::InitialCondition, particle_spacing; tlsph) +function sample_plane(shape::InitialCondition, particle_spacing; place_on_shell) if ndims(shape) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane + # When `place_on_shell=true`, particles will be placed on the x-y plane coords = vcat(shape.coordinates, - fill(tlsph ? 0 : particle_spacing / 2, size(shape.coordinates, 2))') + fill(place_on_shell ? 0 : particle_spacing / 2, + size(shape.coordinates, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -148,13 +154,13 @@ function sample_plane(shape::InitialCondition, particle_spacing; tlsph) return shape.coordinates, particle_spacing end -function sample_plane(plane_points, particle_spacing; tlsph=nothing) +function sample_plane(plane_points, particle_spacing; place_on_shell=nothing) # Convert to tuple - return sample_plane(tuple(plane_points...), particle_spacing; tlsph=nothing) + return sample_plane(tuple(plane_points...), particle_spacing; place_on_shell=nothing) end -function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{2}, particle_spacing; place_on_shell=nothing) # Verify that points are in 2D space if any(length.(plane_points) .!= 2) throw(ArgumentError("all points must be 2D coordinates")) @@ -168,7 +174,7 @@ function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{3}, particle_spacing; place_on_shell=nothing) # Verify that points are in 3D space if any(length.(plane_points) .!= 3) throw(ArgumentError("all points must be 3D coordinates")) @@ -209,21 +215,22 @@ function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -# Shift corners of the plane/line inwards by half a particle spacing with `tlsph=false` +# Shift corners of the plane/line inwards by half a particle spacing with `place_on_shell=false` # because fluid particles need to be half a particle spacing away from the boundary of the shape. function shift_plane_corners(geometry::Union{AbstractMatrix, InitialCondition}, - direction, particle_spacing, tlsph) + direction, particle_spacing, place_on_shell) return geometry end -function shift_plane_corners(plane_points, direction, particle_spacing, tlsph) - shift_plane_corners(tuple(plane_points...), direction, particle_spacing, tlsph) +function shift_plane_corners(plane_points, direction, particle_spacing, place_on_shell) + shift_plane_corners(tuple(plane_points...), direction, particle_spacing, place_on_shell) end -function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) @@ -238,10 +245,11 @@ function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacin return (plane_point1, plane_point2) end -function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) diff --git a/src/setups/rectangular_shape.jl b/src/setups/rectangular_shape.jl index 98160bcac9..1c30ef5c1b 100644 --- a/src/setups/rectangular_shape.jl +++ b/src/setups/rectangular_shape.jl @@ -3,7 +3,7 @@ velocity=zeros(length(n_particles_per_dimension)), mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). @@ -40,9 +40,10 @@ Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). - `state_equation`: When calculating a hydrostatic pressure gradient by setting `acceleration`, the `state_equation` will be used to set the corresponding density. Cannot be used together with `density`. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. - `coordinates_perturbation`: Add a small random displacement to the particle positions, where the amplitude is `coordinates_perturbation * particle_spacing`. @@ -75,7 +76,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord coordinates_perturbation=nothing, mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) end @@ -95,7 +96,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord n_particles = prod(n_particles_per_dimension) coordinates = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates, tlsph=tlsph, + min_coordinates, place_on_shell=place_on_shell, loop_order=loop_order) if !isnothing(coordinates_perturbation) @@ -190,15 +191,15 @@ function loop_permutation(loop_order, NDIMS::Val{3}) end function rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates; tlsph=false, loop_order=nothing) + min_coordinates; place_on_shell=false, loop_order=nothing) ELTYPE = eltype(particle_spacing) NDIMS = length(n_particles_per_dimension) coordinates = Array{ELTYPE, 2}(undef, NDIMS, prod(n_particles_per_dimension)) - # With TLSPH, particles need to be AT the min coordinates and not half a particle + # With place_on_shell, particles need to be AT the min coordinates and not half a particle # spacing away from it. - if tlsph + if place_on_shell min_coordinates = min_coordinates .- 0.5particle_spacing end diff --git a/src/setups/sphere_shape.jl b/src/setups/sphere_shape.jl index 0233fc8995..3c6a7466d5 100644 --- a/src/setups/sphere_shape.jl +++ b/src/setups/sphere_shape.jl @@ -1,7 +1,7 @@ """ SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0.0) Generate a sphere that is either completely filled (by default) @@ -35,18 +35,19 @@ coordinate directions as `cutout_min` and `cutout_max`. cut out of the sphere. - `cutout_max`: Corner in positive coordinate directions of a cuboid that is to be cut out of the sphere. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. -- `velocity`: Either a function mapping each particle's coordinates to its velocity, - or, for a constant fluid velocity, a vector holding this velocity. - Velocity is constant zero by default. -- `mass`: Either `nothing` (default) to automatically compute particle mass from particle - density and spacing, or a function mapping each particle's coordinates to its mass, - or a scalar for a constant mass over all particles. -- `pressure`: Either a function mapping each particle's coordinates to its pressure, - or a scalar for a constant pressure over all particles. This is optional and - only needed when using the [`EntropicallyDampedSPHSystem`](@ref). +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. +- `velocity`: Either a function mapping each particle's coordinates to its velocity, + or, for a constant fluid velocity, a vector holding this velocity. + Velocity is constant zero by default. +- `mass`: Either `nothing` (default) to automatically compute particle mass from particle + density and spacing, or a function mapping each particle's coordinates to its mass, + or a scalar for a constant mass over all particles. +- `pressure`: Either a function mapping each particle's coordinates to its pressure, + or a scalar for a constant pressure over all particles. This is optional and + only needed when using the [`EntropicallyDampedSPHSystem`](@ref). # Examples ```jldoctest; output = false @@ -89,7 +90,7 @@ SphereShape(0.1, 0.5, (0.2, 0.4, 0.3), 1000.0, sphere_type=RoundSphere()) """ function SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) @@ -99,7 +100,7 @@ function SphereShape(particle_spacing, radius, center_position, density; coordinates = sphere_shape_coords(sphere_type, particle_spacing, radius, SVector{NDIMS}(center_position), - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) # Convert tuples to vectors cutout_min_ = collect(cutout_min) @@ -169,13 +170,13 @@ struct RoundSphere{AR} end function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_position, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius outer_radius = radius + n_layers * particle_spacing - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of `radius` inner_radius += particle_spacing / 2 outer_radius += particle_spacing / 2 @@ -184,7 +185,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos inner_radius = radius - n_layers * particle_spacing outer_radius = radius - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` inner_radius -= particle_spacing / 2 outer_radius -= particle_spacing / 2 @@ -194,7 +195,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos outer_radius = radius inner_radius = -1 - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` outer_radius -= particle_spacing / 2 end @@ -225,7 +226,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos end function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, center, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius @@ -233,12 +234,12 @@ function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, cent inner_radius = radius - n_layers * particle_spacing end - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of inner radius inner_radius += particle_spacing / 2 end else - if tlsph + if place_on_shell # Just create a sphere that is 0.5 particle spacing larger radius += particle_spacing / 2 end diff --git a/test/setups/extrude_geometry.jl b/test/setups/extrude_geometry.jl index e695f2e170..5a927dbee4 100644 --- a/test/setups/extrude_geometry.jl +++ b/test/setups/extrude_geometry.jl @@ -28,7 +28,8 @@ ] @testset "Direction $i" for i in eachindex(directions) - shape = extrude_geometry((point1, point2); direction=directions[i], tlsph=true, + shape = extrude_geometry((point1, point2); direction=directions[i], + place_on_shell=true, particle_spacing=0.15, n_extrude=5, density=1.0) @test shape.coordinates ≈ expected_coords[i] @@ -68,7 +69,7 @@ end @testset "Direction $i" for i in eachindex(directions) shape = extrude_geometry(geometry; direction=directions[i], particle_spacing, - n_extrude=5, tlsph=true, density=1.0) + n_extrude=5, place_on_shell=true, density=1.0) @test shape.coordinates ≈ expected_coords[i] end @@ -86,7 +87,7 @@ end 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.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061] shape = extrude_geometry((p1, p2, p3); direction, particle_spacing=0.1, n_extrude=4, - density=1000.0, tlsph=true) + density=1000.0, place_on_shell=true) @test shape.coordinates ≈ expected_coords end diff --git a/test/setups/rectangular_shape.jl b/test/setups/rectangular_shape.jl index f3e77043b0..7c2fd6875b 100644 --- a/test/setups/rectangular_shape.jl +++ b/test/setups/rectangular_shape.jl @@ -41,7 +41,8 @@ ] @testset "$(loop_orders[i])" for i in eachindex(loop_orders) - shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, tlsph=true, + shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] @@ -242,7 +243,7 @@ end @testset "$(loop_orders[i])" for i in eachindex(loop_orders) shape = RectangularShape(1.0, (2, 2, 2), (0.0, 0.0, 0.0), density=1.0, - tlsph=true, loop_order=loop_orders[i]) + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] end diff --git a/test/setups/sphere_shape.jl b/test/setups/sphere_shape.jl index 57d904a376..c8b87d76db 100644 --- a/test/setups/sphere_shape.jl +++ b/test/setups/sphere_shape.jl @@ -106,14 +106,14 @@ SphereShape(1.0, 1.1, (0.2, -1.0, 0.3), 1000.0, sphere_type=RoundSphere()), SphereShape(1.0, 1.2, (-0.3, 0.1, 0.8), 1000.0, sphere_type=RoundSphere()), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, cutout_min=(0.18, 0.4, 0.5), - cutout_max=(0.42, 10.0, 1.0), tlsph=true), - SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, tlsph=true), + cutout_max=(0.42, 10.0, 1.0), place_on_shell=true), + SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, - layer_outwards=true, tlsph=true), + layer_outwards=true, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, sphere_type=RoundSphere()), SphereShape(0.1, 0.55, (0.3, 0.4, 0.5), 1000.0, n_layers=2, layer_outwards=true, - sphere_type=RoundSphere(), tlsph=true) + sphere_type=RoundSphere(), place_on_shell=true) ] expected_coords = [ diff --git a/test/systems/packing_system.jl b/test/systems/packing_system.jl index d55afd559a..b42e534275 100644 --- a/test/systems/packing_system.jl +++ b/test/systems/packing_system.jl @@ -19,7 +19,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -36,7 +36,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… yes │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -52,7 +52,7 @@ │ neighborhood search: ………………………… Nothing │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" end From 829321549623e23b55c5b478d9043306f59a6cf0 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Wed, 13 Aug 2025 17:16:24 +0200 Subject: [PATCH 25/43] Refactor metadata handling --- src/callbacks/post_process.jl | 25 +-- src/io/io.jl | 373 ++++++++++++++++++---------------- 2 files changed, 206 insertions(+), 192 deletions(-) diff --git a/src/callbacks/post_process.jl b/src/callbacks/post_process.jl index 5f29dd17c9..e713a6fc78 100644 --- a/src/callbacks/post_process.jl +++ b/src/callbacks/post_process.jl @@ -216,8 +216,6 @@ function initialize_postprocess_callback!(cb::PostprocessCallback, u, t, integra # Apply the callback cb(integrator) - write_meta_data(cb, integrator) - return cb end @@ -268,7 +266,7 @@ function (pp::PostprocessCallback)(integrator) if isfinished(integrator) || (pp.write_file_interval > 0 && backup_condition(pp, integrator)) - write_postprocess_callback(pp) + write_postprocess_callback(pp, integrator) end # Tell OrdinaryDiffEq that `u` has not been modified @@ -287,14 +285,18 @@ end end # After the simulation has finished, this function is called to write the data to a JSON file -function write_postprocess_callback(pp::PostprocessCallback) +function write_postprocess_callback(pp::PostprocessCallback, integrator) isempty(pp.data) && return mkpath(pp.output_directory) data = Dict{String, Any}() - write_meta_data!(data, pp.git_hash[]) - prepare_series_data!(data, pp) + + data["simulation_info"] = Dict{String, Any}() + add_simulation_info!(data["simulation_info"], pp.git_hash, integrator) + + data["system_data"] = Dict{String, Any}() + prepare_series_data!(data["system_data"], pp) time_stamp = "" if pp.append_timestamp @@ -315,7 +317,7 @@ function write_postprocess_callback(pp::PostprocessCallback) if pp.write_csv abs_file_path = joinpath(abspath(pp.output_directory), filename_csv) - write_csv(abs_file_path, data) + write_csv(abs_file_path, data["system_data"]) end end @@ -343,15 +345,6 @@ function create_series_dict(values, times, system_name="") "time" => times) end -function write_meta_data!(data, git_hash) - meta_data = Dict("solver_name" => "TrixiParticles.jl", - "solver_version" => git_hash, - "julia_version" => string(VERSION)) - - data["meta"] = meta_data - return data -end - function write_csv(abs_file_path, data) times = Float64[] diff --git a/src/io/io.jl b/src/io/io.jl index afeb64f416..108d5666ea 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -1,265 +1,286 @@ include("write_vtk.jl") include("read_vtk.jl") -function write_meta_data(callback::Union{SolutionSavingCallback, PostprocessCallback}, - integrator) +function write_meta_data(callback::SolutionSavingCallback, integrator) # handle "_" on optional prefix strings add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") git_hash = callback.git_hash - prefix = hasproperty(callback, :prefix) ? callback.prefix : "" + prefix = callback.prefix + filename = callback.filename semi = integrator.p names = system_names(semi.systems) info = Dict{String, Any}() - info["solver_name"] = "TrixiParticles.jl" - info["solver_version"] = git_hash[] - info["julia_version"] = string(VERSION) + add_simulation_info!(info, git_hash, integrator) systems = Dict{String, Any}() foreach_system(semi) do system idx = system_indices(system, semi) name = add_opt_str_pre(prefix) * "$(names[idx])" - meta_data = Dict{String, Any}() - add_meta_data!(meta_data, system) + system_data = Dict{String, Any}() + add_system_data!(system_data, system) - systems[name] = meta_data + systems[name] = system_data end - simulation_meta_data = Dict{String, Any}() - simulation_meta_data["info"] = info - simulation_meta_data["systems"] = systems + meta_data = Dict{String, Any}() + meta_data["simulation_info"] = info + meta_data["system_data"] = systems # write JSON-file output_directory = callback.output_directory mkpath(output_directory) - - json_file = joinpath(output_directory, "simulation_meta_data.json") + json_file = joinpath(output_directory, add_opt_str_pre(prefix) * filename * ".json") open(json_file, "w") do file - JSON.print(file, simulation_meta_data, 2) + JSON.print(file, meta_data, 2) + end +end + +function add_simulation_info!(info, git_hash, integrator) + info["solver_name"] = "TrixiParticles.jl" + info["solver_version"] = git_hash[] + info["julia_version"] = string(VERSION) + + info["time_integrator"] = Dict{String, Any}() + info["time_integrator"]["integrator_type"] = type2string(integrator.alg) + info["time_integrator"]["start_time"] = first(integrator.sol.prob.tspan) + info["time_integrator"]["final_time"] = last(integrator.sol.prob.tspan) + info["time_integrator"]["adaptive"] = integrator.opts.adaptive + if integrator.opts.adaptive + info["time_integrator"]["abstol"] = integrator.opts.abstol + info["time_integrator"]["reltol"] = integrator.opts.reltol + info["time_integrator"]["controller"] = type2string(integrator.opts.controller) end + + info["technical_setup"] = Dict{String, Any}() + info["technical_setup"]["parallelization_backend"] = type2string(integrator.p.parallelization_backend) + info["technical_setup"]["#threads"] = Threads.nthreads() end -add_meta_data!(meta_data, ::Nothing) = meta_data +# Skip systemdata addition for `Nothing` +add_system_data!(system_data, data::Nothing) = system_data -function add_meta_data!(meta_data, data) - ArgumentError("Unsupported data type: $(data). This data type is not implemented yet.") +function add_system_data!(system_data, data) + throw(ArgumentError("Method for $(typeof(data)) not implemented. " * + "Please add a method `add_system_data!(system_data, ::$(typeof(data)))`.")) end -function add_meta_data!(meta_data, system::FluidSystem) - meta_data["system_type"] = type2string(system) - meta_data["particle_spacing"] = particle_spacing(system, 1) - meta_data["density_calculator"] = type2string(system.density_calculator) - meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length"] = system.cache.smoothing_length - meta_data["acceleration"] = system.acceleration - meta_data["sound_speed"] = system_sound_speed(system) - meta_data["pressure_acceleration_formulation"] = nameof(system.pressure_acceleration_formulation) - add_meta_data!(meta_data, system.transport_velocity) - add_meta_data!(meta_data, system.surface_tension) - add_meta_data!(meta_data, system.surface_normal_method) - add_meta_data!(meta_data, system.viscosity) - add_meta_data!(meta_data, system.correction) - add_meta_data!(meta_data, system_state_equation(system)) +function add_system_data!(system_data, system::FluidSystem) + system_data["system_type"] = type2string(system) + system_data["particle_spacing"] = particle_spacing(system, 1) + system_data["density_calculator"] = type2string(system.density_calculator) + system_data["smoothing_kernel"] = type2string(system.smoothing_kernel) + system_data["smoothing_length"] = system.cache.smoothing_length + system_data["acceleration"] = system.acceleration + system_data["sound_speed"] = system_sound_speed(system) + system_data["pressure_acceleration_formulation"] = nameof(system.pressure_acceleration_formulation) + add_system_data!(system_data, system.transport_velocity) + add_system_data!(system_data, system.surface_tension) + add_system_data!(system_data, system.surface_normal_method) + add_system_data!(system_data, system.viscosity) + add_system_data!(system_data, system.correction) + add_system_data!(system_data, system_state_equation(system)) if hasfield(typeof(system), :density_diffusion) - add_meta_data!(meta_data, system.density_diffusion) + add_system_data!(system_data, system.density_diffusion) end if hasfield(typeof(system), :alpha) - meta_data["alpha"] = system.alpha + system_data["alpha"] = system.alpha end end -function add_meta_data!(meta_data, system::TotalLagrangianSPHSystem) - meta_data["system_type"] = type2string(system) - meta_data["particle_spacing"] = particle_spacing(system, 1) - meta_data["smoothing_kernel"] = type2string(system.smoothing_kernel) - meta_data["smoothing_length"] = system.smoothing_length - meta_data["acceleration"] = system.acceleration - add_meta_data!(meta_data, system.boundary_model) - add_meta_data!(meta_data, system.penalty_force) +function add_system_data!(system_data, system::TotalLagrangianSPHSystem) + system_data["system_type"] = type2string(system) + system_data["particle_spacing"] = particle_spacing(system, 1) + system_data["smoothing_kernel"] = type2string(system.smoothing_kernel) + system_data["smoothing_length"] = system.smoothing_length + system_data["acceleration"] = system.acceleration + add_system_data!(system_data, system.boundary_model) + add_system_data!(system_data, system.penalty_force) end -function add_meta_data!(meta_data, system::BoundarySPHSystem) - meta_data["system_type"] = type2string(system) - meta_data["particle_spacing"] = particle_spacing(system, 1) - meta_data["adhesion_coefficient"] = system.adhesion_coefficient - add_meta_data!(meta_data, system.boundary_model) - add_meta_data!(meta_data, system.movement) +function add_system_data!(system_data, system::BoundarySPHSystem) + system_data["system_type"] = type2string(system) + system_data["particle_spacing"] = particle_spacing(system, 1) + system_data["adhesion_coefficient"] = system.adhesion_coefficient + add_system_data!(system_data, system.boundary_model) + add_system_data!(system_data, system.movement) end -function add_meta_data!(meta_data, system::BoundaryDEMSystem) - meta_data["system_type"] = type2string(system) - meta_data["particle_spacing"] = particle_spacing(system, 1) - meta_data["normal_stiffness"] = system.normal_stiffness +function add_system_data!(system_data, system::BoundaryDEMSystem) + system_data["system_type"] = type2string(system) + system_data["particle_spacing"] = particle_spacing(system, 1) + system_data["normal_stiffness"] = system.normal_stiffness end -function add_meta_data!(meta_data, system::DEMSystem) - meta_data["system_type"] = type2string(system) - meta_data["particle_spacing"] = particle_spacing(system, 1) - meta_data["damping_coefficient"] = system.damping_coefficient - meta_data["acceleration"] = system.acceleration - add_meta_data!(meta_data, system.contact_model) +function add_system_data!(system_data, system::DEMSystem) + system_data["system_type"] = type2string(system) + system_data["particle_spacing"] = particle_spacing(system, 1) + system_data["damping_coefficient"] = system.damping_coefficient + system_data["acceleration"] = system.acceleration + add_system_data!(system_data, system.contact_model) end -function add_meta_data!(meta_data, system::OpenBoundarySPHSystem) - meta_data["system_type"] = type2string(system) - meta_data["particle_spacing"] = particle_spacing(system, 1) - meta_data["reference_velocity"] = type2string(system.reference_velocity) - meta_data["reference_pressure"] = type2string(system.reference_pressure) - meta_data["reference_density"] = type2string(system.reference_density) - add_meta_data!(meta_data, system.boundary_model) - add_meta_data!(meta_data, system.boundary_zone) +function add_system_data!(system_data, system::OpenBoundarySPHSystem) + system_data["system_type"] = type2string(system) + system_data["particle_spacing"] = particle_spacing(system, 1) + system_data["reference_velocity"] = type2string(system.reference_velocity) + system_data["reference_pressure"] = type2string(system.reference_pressure) + system_data["reference_density"] = type2string(system.reference_density) + add_system_data!(system_data, system.boundary_model) + add_system_data!(system_data, system.boundary_zone) end -function add_meta_data!(meta_data, boundary_model::BoundaryModelDummyParticles) - meta_data["boundary_model"] = Dict{String, Any}() - meta_data["boundary_model"]["model"] = type2string(boundary_model) - meta_data["boundary_model"]["smoothing_kernel"] = type2string(boundary_model.smoothing_kernel) - meta_data["boundary_model"]["smoothing_length"] = boundary_model.smoothing_length - meta_data["boundary_model"]["density_calculator"] = type2string(boundary_model.density_calculator) - add_meta_data!(meta_data["boundary_model"], boundary_model.state_equation) - add_meta_data!(meta_data["boundary_model"], boundary_model.viscosity) - add_meta_data!(meta_data["boundary_model"], boundary_model.correction) +function add_system_data!(system_data, boundary_model::BoundaryModelDummyParticles) + system_data["boundary_model"] = Dict{String, Any}() + system_data["boundary_model"]["model"] = type2string(boundary_model) + system_data["boundary_model"]["smoothing_kernel"] = type2string(boundary_model.smoothing_kernel) + system_data["boundary_model"]["smoothing_length"] = boundary_model.smoothing_length + system_data["boundary_model"]["density_calculator"] = type2string(boundary_model.density_calculator) + add_system_data!(system_data["boundary_model"], boundary_model.state_equation) + add_system_data!(system_data["boundary_model"], boundary_model.viscosity) + add_system_data!(system_data["boundary_model"], boundary_model.correction) end -function add_meta_data!(meta_data, boundary_model::BoundaryModelMonaghanKajtar) - meta_data["boundary_model"] = Dict{String, Any}() - meta_data["boundary_model"]["model"] = type2string(boundary_model) - meta_data["boundary_model"]["beta"] = boundary_model.beta - meta_data["boundary_model"]["K"] = boundary_model.K - add_meta_data!(meta_data["boundary_model"], boundary_model.viscosity) +function add_system_data!(system_data, boundary_model::BoundaryModelMonaghanKajtar) + system_data["boundary_model"] = Dict{String, Any}() + system_data["boundary_model"]["model"] = type2string(boundary_model) + system_data["boundary_model"]["beta"] = boundary_model.beta + system_data["boundary_model"]["K"] = boundary_model.K + add_system_data!(system_data["boundary_model"], boundary_model.viscosity) end -function add_meta_data!(meta_data, boundary_model::BoundaryModelTafuni) - meta_data["boundary_model"] = Dict{String, Any}() - meta_data["boundary_model"]["model"] = type2string(boundary_model) +function add_system_data!(system_data, boundary_model::BoundaryModelTafuni) + system_data["boundary_model"] = Dict{String, Any}() + system_data["boundary_model"]["model"] = type2string(boundary_model) end -function add_meta_data!(meta_data, boundary_model::BoundaryModelLastiwka) - meta_data["boundary_model"] = Dict{String, Any}() - meta_data["boundary_model"]["model"] = type2string(boundary_model) - meta_data["boundary_model"]["extrapolate_reference_values"] = boundary_model.extrapolate_reference_values +function add_system_data!(system_data, boundary_model::BoundaryModelLastiwka) + system_data["boundary_model"] = Dict{String, Any}() + system_data["boundary_model"]["model"] = type2string(boundary_model) + system_data["boundary_model"]["extrapolate_reference_values"] = boundary_model.extrapolate_reference_values end -function add_meta_data!(meta_data, contact_model::HertzContactModel) - meta_data["contact_model"] = Dict{String, Any}() - meta_data["contact_model"]["model"] = type2string(contact_model) - meta_data["contact_model"]["elastic_modulus"] = contact_model.elastic_modulus - meta_data["contact_model"]["poissons_ratio"] = contact_model.poissons_ratio +function add_system_data!(system_data, contact_model::HertzContactModel) + system_data["contact_model"] = Dict{String, Any}() + system_data["contact_model"]["model"] = type2string(contact_model) + system_data["contact_model"]["elastic_modulus"] = contact_model.elastic_modulus + system_data["contact_model"]["poissons_ratio"] = contact_model.poissons_ratio end -function add_meta_data!(meta_data, contact_model::LinearContactModel) - meta_data["contact_model"] = Dict{String, Any}() - meta_data["contact_model"]["model"] = type2string(contact_model) - meta_data["contact_model"]["normal_stiffness"] = contact_model.normal_stiffness +function add_system_data!(system_data, contact_model::LinearContactModel) + system_data["contact_model"] = Dict{String, Any}() + system_data["contact_model"]["model"] = type2string(contact_model) + system_data["contact_model"]["normal_stiffness"] = contact_model.normal_stiffness end -function add_meta_data!(meta_data, state_equation::StateEquationCole) - meta_data["state_equation"] = Dict{String, Any}() - meta_data["state_equation"]["model"] = type2string(state_equation) - meta_data["state_equation"]["reference_density"] = state_equation.reference_density - meta_data["state_equation"]["background_pressure"] = state_equation.background_pressure - meta_data["state_equation"]["exponent"] = state_equation.exponent +function add_system_data!(system_data, state_equation::StateEquationCole) + system_data["state_equation"] = Dict{String, Any}() + system_data["state_equation"]["model"] = type2string(state_equation) + system_data["state_equation"]["reference_density"] = state_equation.reference_density + system_data["state_equation"]["background_pressure"] = state_equation.background_pressure + system_data["state_equation"]["exponent"] = state_equation.exponent end -function add_meta_data!(meta_data, state_equation::StateEquationIdealGas) - meta_data["state_equation"] = Dict{String, Any}() - meta_data["state_equation"]["model"] = type2string(state_equation) - meta_data["state_equation"]["reference_density"] = state_equation.reference_density - meta_data["state_equation"]["background_pressure"] = state_equation.background_pressure - meta_data["state_equation"]["gamma"] = state_equation.gamma +function add_system_data!(system_data, state_equation::StateEquationIdealGas) + system_data["state_equation"] = Dict{String, Any}() + system_data["state_equation"]["model"] = type2string(state_equation) + system_data["state_equation"]["reference_density"] = state_equation.reference_density + system_data["state_equation"]["background_pressure"] = state_equation.background_pressure + system_data["state_equation"]["gamma"] = state_equation.gamma end -function add_meta_data!(meta_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) - meta_data["viscosity_model"] = Dict{String, Any}() - meta_data["viscosity_model"]["model"] = type2string(viscosity) - meta_data["viscosity_model"]["nu"] = viscosity.nu - meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon +function add_system_data!(system_data, viscosity::Union{ViscosityAdami, ViscosityMorris}) + system_data["viscosity_model"] = Dict{String, Any}() + system_data["viscosity_model"]["model"] = type2string(viscosity) + system_data["viscosity_model"]["nu"] = viscosity.nu + system_data["viscosity_model"]["epsilon"] = viscosity.epsilon end -function add_meta_data!(meta_data, viscosity::Union{ViscosityAdamiSGS, ViscosityMorrisSGS}) - meta_data["viscosity_model"] = Dict{String, Any}() - meta_data["viscosity_model"]["model"] = type2string(viscosity) - meta_data["viscosity_model"]["nu"] = viscosity.nu - meta_data["viscosity_model"]["C_S"] = viscosity.C_S - meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon +function add_system_data!(system_data, + viscosity::Union{ViscosityAdamiSGS, ViscosityMorrisSGS}) + system_data["viscosity_model"] = Dict{String, Any}() + system_data["viscosity_model"]["model"] = type2string(viscosity) + system_data["viscosity_model"]["nu"] = viscosity.nu + system_data["viscosity_model"]["C_S"] = viscosity.C_S + system_data["viscosity_model"]["epsilon"] = viscosity.epsilon end -function add_meta_data!(meta_data, viscosity::ArtificialViscosityMonaghan) - meta_data["viscosity_model"] = Dict{String, Any}() - meta_data["viscosity_model"]["model"] = type2string(viscosity) - meta_data["viscosity_model"]["alpha"] = viscosity.alpha - meta_data["viscosity_model"]["beta"] = viscosity.beta - meta_data["viscosity_model"]["epsilon"] = viscosity.epsilon +function add_system_data!(system_data, viscosity::ArtificialViscosityMonaghan) + system_data["viscosity_model"] = Dict{String, Any}() + system_data["viscosity_model"]["model"] = type2string(viscosity) + system_data["viscosity_model"]["alpha"] = viscosity.alpha + system_data["viscosity_model"]["beta"] = viscosity.beta + system_data["viscosity_model"]["epsilon"] = viscosity.epsilon end -function add_meta_data!(meta_data, - density_diffusion::Union{DensityDiffusionAntuono, - DensityDiffusionMolteniColagrossi}) - meta_data["density_diffusion"] = Dict{String, Any}() - meta_data["density_diffusion"]["model"] = type2string(density_diffusion) - meta_data["density_diffusion"]["delta"] = density_diffusion.delta +function add_system_data!(system_data, + density_diffusion::Union{DensityDiffusionAntuono, + DensityDiffusionMolteniColagrossi}) + system_data["density_diffusion"] = Dict{String, Any}() + system_data["density_diffusion"]["model"] = type2string(density_diffusion) + system_data["density_diffusion"]["delta"] = density_diffusion.delta end -function add_meta_data!(meta_data, density_diffusion::DensityDiffusionFerrari) - meta_data["density_diffusion"] = Dict{String, Any}() - meta_data["density_diffusion"]["model"] = type2string(density_diffusion) +function add_system_data!(system_data, density_diffusion::DensityDiffusionFerrari) + system_data["density_diffusion"] = Dict{String, Any}() + system_data["density_diffusion"]["model"] = type2string(density_diffusion) end -function add_meta_data!(meta_data, correction::AkinciFreeSurfaceCorrection) - meta_data["correction_method"] = Dict{String, Any}() - meta_data["correction_method"]["model"] = type2string(correction) - meta_data["correction_method"]["rho0"] = correction.rho0 +function add_system_data!(system_data, correction::AkinciFreeSurfaceCorrection) + system_data["correction_method"] = Dict{String, Any}() + system_data["correction_method"]["model"] = type2string(correction) + system_data["correction_method"]["rho0"] = correction.rho0 end -function add_meta_data!(meta_data, - correction::Union{BlendedGradientCorrection, GradientCorrection, - KernelCorrection, MixedKernelGradientCorrection, - ShepardKernelCorrection}) - meta_data["correction_method"] = Dict{String, Any}() - meta_data["correction_method"]["model"] = type2string(correction) +function add_system_data!(system_data, + correction::Union{BlendedGradientCorrection, GradientCorrection, + KernelCorrection, MixedKernelGradientCorrection, + ShepardKernelCorrection}) + system_data["correction_method"] = Dict{String, Any}() + system_data["correction_method"]["model"] = type2string(correction) end -function add_meta_data!(meta_data, - surface_tension::Union{CohesionForceAkinci, SurfaceTensionAkinci, - SurfaceTensionMorris, - SurfaceTensionMomentumMorris}) - meta_data["surface_tension"] = Dict{String, Any}() - meta_data["surface_tension"]["model"] = type2string(surface_tension) - meta_data["surface_tension"]["surface_tension_coefficient"] = surface_tension.surface_tension_coefficient +function add_system_data!(system_data, + surface_tension::Union{CohesionForceAkinci, SurfaceTensionAkinci, + SurfaceTensionMorris, + SurfaceTensionMomentumMorris}) + system_data["surface_tension"] = Dict{String, Any}() + system_data["surface_tension"]["model"] = type2string(surface_tension) + system_data["surface_tension"]["surface_tension_coefficient"] = surface_tension.surface_tension_coefficient end -function add_meta_data!(meta_data, surface_normal_method::ColorfieldSurfaceNormal) - meta_data["surface_normal_method"] = Dict{String, Any}() - meta_data["surface_normal_method"]["model"] = type2string(surface_normal_method) - meta_data["surface_normal_method"]["boundary_contact_threshold"] = surface_normal_method.boundary_contact_threshold - meta_data["surface_normal_method"]["ideal_density_threshold"] = surface_normal_method.ideal_density_threshold +function add_system_data!(system_data, surface_normal_method::ColorfieldSurfaceNormal) + system_data["surface_normal_method"] = Dict{String, Any}() + system_data["surface_normal_method"]["model"] = type2string(surface_normal_method) + system_data["surface_normal_method"]["boundary_contact_threshold"] = surface_normal_method.boundary_contact_threshold + system_data["surface_normal_method"]["ideal_density_threshold"] = surface_normal_method.ideal_density_threshold end -function add_meta_data!(meta_data, boundary_zone::BoundaryZone) - meta_data["boundary_zone"] = Dict{String, Any}() - meta_data["boundary_zone"]["boundary_type"] = type2string(boundary_zone.boundary_type) - meta_data["boundary_zone"]["zone_width"] = boundary_zone.zone_width +function add_system_data!(system_data, boundary_zone::BoundaryZone) + system_data["boundary_zone"] = Dict{String, Any}() + system_data["boundary_zone"]["boundary_type"] = type2string(boundary_zone.boundary_type) + system_data["boundary_zone"]["zone_width"] = boundary_zone.zone_width end -function add_meta_data!(meta_data, movement::BoundaryMovement) - meta_data["movement"] = Dict{String, Any}() - meta_data["movement"]["model"] = type2string(movement) - meta_data["movement"]["movement_function"] = type2string(movement.movement_function) - meta_data["movement"]["is_moving"] = type2string(movement.is_moving) - meta_data["movement"]["moving_particles"] = movement.moving_particles +function add_system_data!(system_data, movement::BoundaryMovement) + system_data["movement"] = Dict{String, Any}() + system_data["movement"]["model"] = type2string(movement) + system_data["movement"]["movement_function"] = type2string(movement.movement_function) + system_data["movement"]["is_moving"] = type2string(movement.is_moving) + system_data["movement"]["moving_particles"] = movement.moving_particles end -function add_meta_data!(meta_data, penalty_force::PenaltyForceGanzenmueller) - meta_data["penalty_force"] = Dict{String, Any}() - meta_data["penalty_force"]["model"] = type2string(penalty_force) - meta_data["penalty_force"]["alpha"] = penalty_force.alpha +function add_system_data!(system_data, penalty_force::PenaltyForceGanzenmueller) + system_data["penalty_force"] = Dict{String, Any}() + system_data["penalty_force"]["model"] = type2string(penalty_force) + system_data["penalty_force"]["alpha"] = penalty_force.alpha end -function add_meta_data!(meta_data, transport_velocity::TransportVelocityAdami) - meta_data["transport_velocity"] = Dict{String, Any}() - meta_data["transport_velocity"]["model"] = type2string(transport_velocity) - meta_data["transport_velocity"]["background_pressure"] = transport_velocity.background_pressure +function add_system_data!(system_data, transport_velocity::TransportVelocityAdami) + system_data["transport_velocity"] = Dict{String, Any}() + system_data["transport_velocity"]["model"] = type2string(transport_velocity) + system_data["transport_velocity"]["background_pressure"] = transport_velocity.background_pressure end From 3cfd8c4c2867a8826e234f0e08f2eaa3622bf992 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Wed, 13 Aug 2025 17:17:18 +0200 Subject: [PATCH 26/43] Add settable filename --- src/callbacks/solution_saving.jl | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/callbacks/solution_saving.jl b/src/callbacks/solution_saving.jl index deab0a0d13..486640e946 100644 --- a/src/callbacks/solution_saving.jl +++ b/src/callbacks/solution_saving.jl @@ -1,7 +1,7 @@ @doc raw""" SolutionSavingCallback(; interval::Integer=0, dt=0.0, save_times=Array{Float64, 1}([]), save_initial_solution=true, save_final_solution=true, - output_directory="out", append_timestamp=false, prefix="", + output_directory="out", append_timestamp=false, prefix="", filename="meta_data", verbose=false, max_coordinates=2^15, custom_quantities...) @@ -25,7 +25,8 @@ To ignore a custom quantity for a specific system, return `nothing`. - `save_final_solution=true`: Save the final solution. - `output_directory="out"`: Directory to save the VTK files. - `append_timestamp=false`: Append current timestamp to the output directory. -- 'prefix=""': Prefix added to the filename. +- `prefix=""`: Prefix added to the filename. +- `filename="meta_data"`: The filename of the Metadata file to be saved. - `custom_quantities...`: Additional user-defined quantities. - `verbose=false`: Print to standard IO when a file is written. - `max_coordinates=2^15`: The coordinates of particles will be clipped if their @@ -60,6 +61,7 @@ saving_callback = SolutionSavingCallback(dt=0.1, my_custom_quantity=kinetic_ener │ save final solution: ………………………… yes │ │ output directory: ………………………………… *path ignored with filter regex above* │ │ prefix: …………………………………………………………… │ +│ filename: ……………………………………………………… meta_data │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘ ``` """ @@ -71,6 +73,7 @@ mutable struct SolutionSavingCallback{I, CQ} verbose :: Bool output_directory :: String prefix :: String + filename :: String max_coordinates :: Float64 custom_quantities :: CQ latest_saved_iter :: Int @@ -81,7 +84,8 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0, save_times=Float64[], save_initial_solution=true, save_final_solution=true, output_directory="out", append_timestamp=false, - prefix="", verbose=false, max_coordinates=Float64(2^15), + prefix="", filename="meta_data", verbose=false, + max_coordinates=Float64(2^15), custom_quantities...) if (dt > 0 && interval > 0) || (length(save_times) > 0 && (dt > 0 || interval > 0)) throw(ArgumentError("Setting multiple save times for the same solution " * @@ -98,7 +102,7 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0, solution_callback = SolutionSavingCallback(interval, Float64.(save_times), save_initial_solution, save_final_solution, - verbose, output_directory, prefix, + verbose, output_directory, prefix, filename, max_coordinates, custom_quantities, -1, Ref("UnknownVersion")) @@ -151,7 +155,7 @@ end # `affect!` function (solution_callback::SolutionSavingCallback)(integrator) (; interval, output_directory, custom_quantities, git_hash, verbose, - prefix, latest_saved_iter, max_coordinates) = solution_callback + prefix, filename, latest_saved_iter, max_coordinates) = solution_callback vu_ode = integrator.u semi = integrator.p @@ -256,7 +260,8 @@ function Base.show(io::IO, ::MIME"text/plain", "save final solution" => solution_saving.save_final_solution ? "yes" : "no", "output directory" => abspath(solution_saving.output_directory), - "prefix" => solution_saving.prefix + "prefix" => solution_saving.prefix, + "filename" => solution_saving.filename ] summary_box(io, "SolutionSavingCallback", setup) end @@ -282,7 +287,8 @@ function Base.show(io::IO, ::MIME"text/plain", "save final solution" => solution_saving.save_final_solution ? "yes" : "no", "output directory" => abspath(solution_saving.output_directory), - "prefix" => solution_saving.prefix + "prefix" => solution_saving.prefix, + "filename" => solution_saving.filename ] summary_box(io, "SolutionSavingCallback", setup) end @@ -307,7 +313,8 @@ function Base.show(io::IO, ::MIME"text/plain", "save final solution" => solution_saving.save_final_solution ? "yes" : "no", "output directory" => abspath(solution_saving.output_directory), - "prefix" => solution_saving.prefix + "prefix" => solution_saving.prefix, + "filename" => solution_saving.filename ] summary_box(io, "SolutionSavingCallback", setup) end From 2b284c404f945ca28dd2f34e91952b2e56eb0a28 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Thu, 14 Aug 2025 15:19:50 +0200 Subject: [PATCH 27/43] Add filename display to SolutionSavingCallback output --- test/callbacks/solution_saving.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/callbacks/solution_saving.jl b/test/callbacks/solution_saving.jl index 3b29d2df4a..bd0a517af1 100644 --- a/test/callbacks/solution_saving.jl +++ b/test/callbacks/solution_saving.jl @@ -19,6 +19,7 @@ │ save final solution: ………………………… yes │ │ output directory: ………………………………… $(output_directory_padded)│ │ prefix: …………………………………………………………… test │ + │ filename: ……………………………………………………… meta_data │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback) == show_box end @@ -40,6 +41,7 @@ │ save final solution: ………………………… yes │ │ output directory: ………………………………… $(output_directory_padded)│ │ prefix: …………………………………………………………… test │ + │ filename: ……………………………………………………… meta_data │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback) == show_box end @@ -61,6 +63,7 @@ │ save final solution: ………………………… yes │ │ output directory: ………………………………… $(output_directory_padded)│ │ prefix: …………………………………………………………… test │ + │ filename: ……………………………………………………… meta_data │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback) == show_box end From de50af42b019c026c82b61fa4800af83a45500e5 Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Fri, 13 Jun 2025 15:52:21 +0200 Subject: [PATCH 28/43] Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> --- examples/dem/collapsing_sand_pile_3d.jl | 3 +- examples/fsi/dam_break_gate_2d.jl | 8 +-- examples/fsi/dam_break_plate_2d.jl | 8 +-- examples/preprocessing/packing_2d.jl | 9 +-- examples/preprocessing/packing_3d.jl | 2 +- examples/solid/oscillating_beam_2d.jl | 6 +- src/general/interpolation.jl | 5 +- .../particle_packing/signed_distance.jl | 2 +- src/preprocessing/particle_packing/system.jl | 35 ++++++----- src/setups/complex_shape.jl | 10 ++-- src/setups/extrude_geometry.jl | 60 +++++++++++-------- src/setups/rectangular_shape.jl | 19 +++--- src/setups/sphere_shape.jl | 45 +++++++------- test/setups/extrude_geometry.jl | 7 ++- test/setups/rectangular_shape.jl | 5 +- test/setups/sphere_shape.jl | 8 +-- test/systems/packing_system.jl | 6 +- 17 files changed, 128 insertions(+), 110 deletions(-) diff --git a/examples/dem/collapsing_sand_pile_3d.jl b/examples/dem/collapsing_sand_pile_3d.jl index aa9ba7a56b..f463ac2417 100644 --- a/examples/dem/collapsing_sand_pile_3d.jl +++ b/examples/dem/collapsing_sand_pile_3d.jl @@ -55,7 +55,8 @@ min_coords_floor = (min_boundary[1] - boundary_thickness, floor_particles = RectangularShape(particle_spacing, (n_particles_floor_x, n_particles_floor_y, n_particles_floor_z), - min_coords_floor; density=boundary_density, tlsph=true) + min_coords_floor; density=boundary_density, + place_on_shell=true) boundary_particles = floor_particles # ========================================================================================== diff --git a/examples/fsi/dam_break_gate_2d.jl b/examples/fsi/dam_break_gate_2d.jl index 529fd56522..44adf7bc59 100644 --- a/examples/fsi/dam_break_gate_2d.jl +++ b/examples/fsi/dam_break_gate_2d.jl @@ -83,18 +83,18 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. # # The right end of the plate is 0.2 from the right end of the tank. plate_position = 0.6 - n_particles_x * solid_particle_spacing plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (plate_position, solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (plate_position, 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/fsi/dam_break_plate_2d.jl b/examples/fsi/dam_break_plate_2d.jl index f5b42ecaa0..d4f8b206fb 100644 --- a/examples/fsi/dam_break_plate_2d.jl +++ b/examples/fsi/dam_break_plate_2d.jl @@ -57,15 +57,15 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (2initial_fluid_size[1], solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (2initial_fluid_size[1], 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/preprocessing/packing_2d.jl b/examples/preprocessing/packing_2d.jl index fc8b330269..0975b6e2ad 100644 --- a/examples/preprocessing/packing_2d.jl +++ b/examples/preprocessing/packing_2d.jl @@ -20,7 +20,7 @@ file = pkgdir(TrixiParticles, "examples", "preprocessing", "data", filename * ". # ========================================================================================== # ==== Packing parameters -tlsph = false +place_on_shell = false # ========================================================================================== # ==== Resolution @@ -50,7 +50,7 @@ shape_sampled = ComplexShape(geometry; particle_spacing, density, # Returns `InitialCondition` boundary_sampled = sample_boundary(signed_distance_field; boundary_density=density, - boundary_thickness, tlsph=tlsph) + boundary_thickness, place_on_shell=place_on_shell) trixi2vtk(shape_sampled) trixi2vtk(boundary_sampled, filename="boundary") @@ -66,12 +66,13 @@ background_pressure = 1.0 smoothing_length = 0.8 * particle_spacing packing_system = ParticlePackingSystem(shape_sampled; smoothing_length=smoothing_length, - signed_distance_field, tlsph=tlsph, + signed_distance_field, place_on_shell=place_on_shell, background_pressure) boundary_system = ParticlePackingSystem(boundary_sampled; smoothing_length=smoothing_length, is_boundary=true, signed_distance_field, - tlsph=tlsph, boundary_compress_factor=0.8, + place_on_shell=place_on_shell, + boundary_compress_factor=0.8, background_pressure) # ========================================================================================== diff --git a/examples/preprocessing/packing_3d.jl b/examples/preprocessing/packing_3d.jl index cb15a255b2..ede3433b38 100644 --- a/examples/preprocessing/packing_3d.jl +++ b/examples/preprocessing/packing_3d.jl @@ -24,5 +24,5 @@ boundary_thickness = 8 * particle_spacing trixi_include(joinpath(examples_dir(), "preprocessing", "packing_2d.jl"), density=1000.0, particle_spacing=particle_spacing, file=file, - boundary_thickness=boundary_thickness, tlsph=true, + boundary_thickness=boundary_thickness, place_on_shell=true, save_intervals=false) diff --git a/examples/solid/oscillating_beam_2d.jl b/examples/solid/oscillating_beam_2d.jl index 8df52c28f1..28d371634d 100644 --- a/examples/solid/oscillating_beam_2d.jl +++ b/examples/solid/oscillating_beam_2d.jl @@ -38,7 +38,7 @@ fixed_particles = SphereShape(particle_spacing, clamp_radius + particle_spacing (0.0, elastic_beam.thickness / 2), material.density, cutout_min=(0.0, 0.0), cutout_max=(clamp_radius, elastic_beam.thickness), - tlsph=true) + place_on_shell=true) n_particles_clamp_x = round(Int, clamp_radius / particle_spacing) @@ -48,9 +48,9 @@ n_particles_per_dimension = (round(Int, elastic_beam.length / particle_spacing) # Note that the `RectangularShape` puts the first particle half a particle spacing away # from the boundary, which is correct for fluids, but not for solids. -# We therefore need to pass `tlsph=true`. +# We therefore need to pass `place_on_shell=true`. beam = RectangularShape(particle_spacing, n_particles_per_dimension, - (0.0, 0.0), density=material.density, tlsph=true) + (0.0, 0.0), density=material.density, place_on_shell=true) solid = union(beam, fixed_particles) diff --git a/src/general/interpolation.jl b/src/general/interpolation.jl index 9b0ac40d7f..6ca3fa16f3 100644 --- a/src/general/interpolation.jl +++ b/src/general/interpolation.jl @@ -191,9 +191,10 @@ function interpolate_plane_2d(min_corner, max_corner, resolution, semi, ref_syst x_range = range(min_corner[1], max_corner[1], length=n_points_per_dimension[1]) y_range = range(min_corner[2], max_corner[2], length=n_points_per_dimension[2]) - # Generate points within the plane. Use `tlsph=true` to generate points on the boundary + # Generate points within the plane. Use `place_on_shell=true` to generate points + # on the shell of the geometry. point_coords = rectangular_shape_coords(resolution, n_points_per_dimension, min_corner, - tlsph=true) + place_on_shell=true) results = interpolate_points(point_coords, semi, ref_system, v_ode, u_ode, smoothing_length=smoothing_length, diff --git a/src/preprocessing/particle_packing/signed_distance.jl b/src/preprocessing/particle_packing/signed_distance.jl index 7e957e124d..082deced5a 100644 --- a/src/preprocessing/particle_packing/signed_distance.jl +++ b/src/preprocessing/particle_packing/signed_distance.jl @@ -59,7 +59,7 @@ function SignedDistanceField(geometry, particle_spacing; particle_spacing)) grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) points = reinterpret(reshape, SVector{NDIMS, ELTYPE}, grid) end diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index 1318f63544..77be7e0c59 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -6,7 +6,7 @@ smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, fixed_system=false) System to generate body-fitted particles for complex shapes. For more information on the methods, see [particle packing](@ref particle_packing). @@ -18,10 +18,11 @@ For more information on the methods, see [particle packing](@ref particle_packin - `background_pressure`: Constant background pressure to physically pack the particles. A large `background_pressure` can cause high accelerations which requires a properly adjusted time step. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not half a particle spacing away, - as for fluids. When `tlsph=true`, particles will be placed - on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. - `is_boundary`: When `shape` is inside the geometry that was used to create `signed_distance_field`, set `is_boundary=false`. Otherwise (`shape` is the sampled boundary), set `is_boundary=true`. @@ -64,7 +65,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, smoothing_kernel :: K smoothing_length_interpolation :: ELTYPE background_pressure :: ELTYPE - tlsph :: Bool + place_on_shell :: Bool signed_distance_field :: S is_boundary :: Bool shift_length :: ELTYPE @@ -79,7 +80,8 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, # See the comments in general/gpu.jl for more details. function ParticlePackingSystem(initial_condition, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, + signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, buffer, update_callback_used, fixed_system, cache, @@ -93,7 +95,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, @@ -108,7 +110,8 @@ function ParticlePackingSystem(shape::InitialCondition; smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, + fixed_system=false) NDIMS = ndims(shape) ELTYPE = eltype(shape) mass = copy(shape.mass) @@ -147,12 +150,12 @@ function ParticlePackingSystem(shape::InitialCondition; # Its value is negative if the particle is inside the geometry. # Otherwise (if outside), the value is positive. if is_boundary - offset = tlsph ? shape.particle_spacing : shape.particle_spacing / 2 + offset = place_on_shell ? shape.particle_spacing : shape.particle_spacing / 2 shift_length = -boundary_compress_factor * signed_distance_field.max_signed_distance - offset else - shift_length = tlsph ? zero(ELTYPE) : shape.particle_spacing / 2 + shift_length = place_on_shell ? zero(ELTYPE) : shape.particle_spacing / 2 end cache = (; create_cache_refinement(shape, particle_refinement, smoothing_length)...) @@ -161,7 +164,7 @@ function ParticlePackingSystem(shape::InitialCondition; return ParticlePackingSystem(shape, mass, density, shape.particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, nhs, fill(zero(ELTYPE), nparticles(shape)), particle_refinement, nothing, Ref(false), fixed_system, cache, @@ -187,7 +190,7 @@ function Base.show(io::IO, ::MIME"text/plain", system::ParticlePackingSystem) system.neighborhood_search |> typeof |> nameof) summary_line(io, "#particles", nparticles(system)) summary_line(io, "smoothing kernel", system.smoothing_kernel |> typeof |> nameof) - summary_line(io, "tlsph", system.tlsph ? "yes" : "no") + summary_line(io, "place_on_shell", system.place_on_shell ? "yes" : "no") summary_line(io, "boundary", system.is_boundary ? "yes" : "no") summary_footer(io) end @@ -349,8 +352,8 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector (; shift_length) = system # For fluid particles: - # - `tlsph = true`: `shift_length = 0` - # - `tlsph = false`: `shift_length = particle_spacing / 2` + # - `place_on_shell = true`: `shift_length = 0` + # - `place_on_shell = false`: `shift_length = particle_spacing / 2` # For boundary particles: # `shift_length` is the thickness of the boundary. if distance_signed >= -shift_length @@ -365,7 +368,7 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector system.is_boundary || return u particle_spacing = system.initial_condition.particle_spacing - shift_length_inner = system.tlsph ? particle_spacing : particle_spacing / 2 + shift_length_inner = system.place_on_shell ? particle_spacing : particle_spacing / 2 if distance_signed < shift_length_inner shift = (distance_signed - shift_length_inner) * normal_vector diff --git a/src/setups/complex_shape.jl b/src/setups/complex_shape.jl index cdb8e146b6..032250ce56 100644 --- a/src/setups/complex_shape.jl +++ b/src/setups/complex_shape.jl @@ -79,7 +79,7 @@ end """ sample_boundary(signed_distance_field; - boundary_density, boundary_thickness, tlsph=true) + boundary_density, boundary_thickness, place_on_shell=true) Sample boundary particles of a complex geometry by using the [`SignedDistanceField`](@ref) of the geometry. @@ -90,9 +90,9 @@ of the geometry. # Keywords - `boundary_thickness`: Thickness of the boundary - `boundary_density`: Density of each boundary particle. -- `tlsph` : When `tlsph=true`, boundary particles will be placed +- `place_on_shell`: When `place_on_shell=true`, boundary particles will be placed one particle spacing from the surface of the geometry. - Otherwise when `tlsph=true` (simulating fluid particles), + Otherwise when `place_on_shell=true` (simulating fluid particles), boundary particles will be placed half particle spacing away from the surface. @@ -118,7 +118,7 @@ boundary_sampled = sample_boundary(signed_distance_field; boundary_density=1.0, ``` """ function sample_boundary(signed_distance_field; - boundary_density, boundary_thickness, tlsph=true) + boundary_density, boundary_thickness, place_on_shell=true) (; max_signed_distance, boundary_packing, positions, distances, particle_spacing) = signed_distance_field @@ -158,6 +158,6 @@ function particle_grid(geometry, particle_spacing; end grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) return reinterpret(reshape, SVector{ndims(geometry), eltype(geometry)}, grid) end diff --git a/src/setups/extrude_geometry.jl b/src/setups/extrude_geometry.jl index 498266ecd0..6d169762c7 100644 --- a/src/setups/extrude_geometry.jl +++ b/src/setups/extrude_geometry.jl @@ -30,9 +30,11 @@ Returns an [`InitialCondition`](@ref). - `pressure`: Scalar to set the pressure of all particles to this value. This is only used by the [`EntropicallyDampedSPHSystem`](@ref) and will be overwritten when using an initial pressure function in the system. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. # Examples ```jldoctest; output = false @@ -79,7 +81,7 @@ shape = extrude_geometry(shape; direction, particle_spacing=0.1, n_extrude=4, de This is an experimental feature and may change in any future releases. """ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::Integer, - velocity=zeros(length(direction)), tlsph=false, + velocity=zeros(length(direction)), place_on_shell=false, mass=nothing, density=nothing, pressure=0.0) direction_ = normalize(direction) NDIMS = length(direction_) @@ -95,9 +97,11 @@ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::I throw(ArgumentError("`particle_spacing` must be specified when not extruding an `InitialCondition`")) end - geometry = shift_plane_corners(geometry, direction_, particle_spacing, tlsph) + geometry = shift_plane_corners(geometry, direction_, particle_spacing, place_on_shell) - face_coords, particle_spacing_ = sample_plane(geometry, particle_spacing; tlsph=tlsph) + face_coords, + particle_spacing_ = sample_plane(geometry, particle_spacing; + place_on_shell=place_on_shell) if !isapprox(particle_spacing, particle_spacing_, rtol=5e-2) @info "The desired size is not a multiple of the particle spacing $particle_spacing." * @@ -119,12 +123,13 @@ end # For corners/endpoints of a plane/line, sample the plane/line with particles. # For 2D coordinates or an `InitialCondition`, add a third dimension. -function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) +function sample_plane(geometry::AbstractMatrix, particle_spacing; place_on_shell) if size(geometry, 1) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane - coords = vcat(geometry, fill(tlsph ? 0 : particle_spacing / 2, size(geometry, 2))') + # When `place_on_shell=true`, particles will be placed on the x-y plane + coords = vcat(geometry, + fill(place_on_shell ? 0 : particle_spacing / 2, size(geometry, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -133,13 +138,14 @@ function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) return geometry, particle_spacing end -function sample_plane(shape::InitialCondition, particle_spacing; tlsph) +function sample_plane(shape::InitialCondition, particle_spacing; place_on_shell) if ndims(shape) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane + # When `place_on_shell=true`, particles will be placed on the x-y plane coords = vcat(shape.coordinates, - fill(tlsph ? 0 : particle_spacing / 2, size(shape.coordinates, 2))') + fill(place_on_shell ? 0 : particle_spacing / 2, + size(shape.coordinates, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -148,13 +154,13 @@ function sample_plane(shape::InitialCondition, particle_spacing; tlsph) return shape.coordinates, particle_spacing end -function sample_plane(plane_points, particle_spacing; tlsph=nothing) +function sample_plane(plane_points, particle_spacing; place_on_shell=nothing) # Convert to tuple - return sample_plane(tuple(plane_points...), particle_spacing; tlsph=nothing) + return sample_plane(tuple(plane_points...), particle_spacing; place_on_shell=nothing) end -function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{2}, particle_spacing; place_on_shell=nothing) # Verify that points are in 2D space if any(length.(plane_points) .!= 2) throw(ArgumentError("all points must be 2D coordinates")) @@ -168,7 +174,7 @@ function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{3}, particle_spacing; place_on_shell=nothing) # Verify that points are in 3D space if any(length.(plane_points) .!= 3) throw(ArgumentError("all points must be 3D coordinates")) @@ -209,21 +215,22 @@ function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -# Shift corners of the plane/line inwards by half a particle spacing with `tlsph=false` +# Shift corners of the plane/line inwards by half a particle spacing with `place_on_shell=false` # because fluid particles need to be half a particle spacing away from the boundary of the shape. function shift_plane_corners(geometry::Union{AbstractMatrix, InitialCondition}, - direction, particle_spacing, tlsph) + direction, particle_spacing, place_on_shell) return geometry end -function shift_plane_corners(plane_points, direction, particle_spacing, tlsph) - shift_plane_corners(tuple(plane_points...), direction, particle_spacing, tlsph) +function shift_plane_corners(plane_points, direction, particle_spacing, place_on_shell) + shift_plane_corners(tuple(plane_points...), direction, particle_spacing, place_on_shell) end -function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) @@ -238,10 +245,11 @@ function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacin return (plane_point1, plane_point2) end -function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) diff --git a/src/setups/rectangular_shape.jl b/src/setups/rectangular_shape.jl index 98160bcac9..1c30ef5c1b 100644 --- a/src/setups/rectangular_shape.jl +++ b/src/setups/rectangular_shape.jl @@ -3,7 +3,7 @@ velocity=zeros(length(n_particles_per_dimension)), mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). @@ -40,9 +40,10 @@ Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). - `state_equation`: When calculating a hydrostatic pressure gradient by setting `acceleration`, the `state_equation` will be used to set the corresponding density. Cannot be used together with `density`. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. - `coordinates_perturbation`: Add a small random displacement to the particle positions, where the amplitude is `coordinates_perturbation * particle_spacing`. @@ -75,7 +76,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord coordinates_perturbation=nothing, mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) end @@ -95,7 +96,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord n_particles = prod(n_particles_per_dimension) coordinates = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates, tlsph=tlsph, + min_coordinates, place_on_shell=place_on_shell, loop_order=loop_order) if !isnothing(coordinates_perturbation) @@ -190,15 +191,15 @@ function loop_permutation(loop_order, NDIMS::Val{3}) end function rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates; tlsph=false, loop_order=nothing) + min_coordinates; place_on_shell=false, loop_order=nothing) ELTYPE = eltype(particle_spacing) NDIMS = length(n_particles_per_dimension) coordinates = Array{ELTYPE, 2}(undef, NDIMS, prod(n_particles_per_dimension)) - # With TLSPH, particles need to be AT the min coordinates and not half a particle + # With place_on_shell, particles need to be AT the min coordinates and not half a particle # spacing away from it. - if tlsph + if place_on_shell min_coordinates = min_coordinates .- 0.5particle_spacing end diff --git a/src/setups/sphere_shape.jl b/src/setups/sphere_shape.jl index 0233fc8995..3c6a7466d5 100644 --- a/src/setups/sphere_shape.jl +++ b/src/setups/sphere_shape.jl @@ -1,7 +1,7 @@ """ SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0.0) Generate a sphere that is either completely filled (by default) @@ -35,18 +35,19 @@ coordinate directions as `cutout_min` and `cutout_max`. cut out of the sphere. - `cutout_max`: Corner in positive coordinate directions of a cuboid that is to be cut out of the sphere. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. -- `velocity`: Either a function mapping each particle's coordinates to its velocity, - or, for a constant fluid velocity, a vector holding this velocity. - Velocity is constant zero by default. -- `mass`: Either `nothing` (default) to automatically compute particle mass from particle - density and spacing, or a function mapping each particle's coordinates to its mass, - or a scalar for a constant mass over all particles. -- `pressure`: Either a function mapping each particle's coordinates to its pressure, - or a scalar for a constant pressure over all particles. This is optional and - only needed when using the [`EntropicallyDampedSPHSystem`](@ref). +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. +- `velocity`: Either a function mapping each particle's coordinates to its velocity, + or, for a constant fluid velocity, a vector holding this velocity. + Velocity is constant zero by default. +- `mass`: Either `nothing` (default) to automatically compute particle mass from particle + density and spacing, or a function mapping each particle's coordinates to its mass, + or a scalar for a constant mass over all particles. +- `pressure`: Either a function mapping each particle's coordinates to its pressure, + or a scalar for a constant pressure over all particles. This is optional and + only needed when using the [`EntropicallyDampedSPHSystem`](@ref). # Examples ```jldoctest; output = false @@ -89,7 +90,7 @@ SphereShape(0.1, 0.5, (0.2, 0.4, 0.3), 1000.0, sphere_type=RoundSphere()) """ function SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) @@ -99,7 +100,7 @@ function SphereShape(particle_spacing, radius, center_position, density; coordinates = sphere_shape_coords(sphere_type, particle_spacing, radius, SVector{NDIMS}(center_position), - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) # Convert tuples to vectors cutout_min_ = collect(cutout_min) @@ -169,13 +170,13 @@ struct RoundSphere{AR} end function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_position, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius outer_radius = radius + n_layers * particle_spacing - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of `radius` inner_radius += particle_spacing / 2 outer_radius += particle_spacing / 2 @@ -184,7 +185,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos inner_radius = radius - n_layers * particle_spacing outer_radius = radius - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` inner_radius -= particle_spacing / 2 outer_radius -= particle_spacing / 2 @@ -194,7 +195,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos outer_radius = radius inner_radius = -1 - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` outer_radius -= particle_spacing / 2 end @@ -225,7 +226,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos end function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, center, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius @@ -233,12 +234,12 @@ function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, cent inner_radius = radius - n_layers * particle_spacing end - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of inner radius inner_radius += particle_spacing / 2 end else - if tlsph + if place_on_shell # Just create a sphere that is 0.5 particle spacing larger radius += particle_spacing / 2 end diff --git a/test/setups/extrude_geometry.jl b/test/setups/extrude_geometry.jl index e695f2e170..5a927dbee4 100644 --- a/test/setups/extrude_geometry.jl +++ b/test/setups/extrude_geometry.jl @@ -28,7 +28,8 @@ ] @testset "Direction $i" for i in eachindex(directions) - shape = extrude_geometry((point1, point2); direction=directions[i], tlsph=true, + shape = extrude_geometry((point1, point2); direction=directions[i], + place_on_shell=true, particle_spacing=0.15, n_extrude=5, density=1.0) @test shape.coordinates ≈ expected_coords[i] @@ -68,7 +69,7 @@ end @testset "Direction $i" for i in eachindex(directions) shape = extrude_geometry(geometry; direction=directions[i], particle_spacing, - n_extrude=5, tlsph=true, density=1.0) + n_extrude=5, place_on_shell=true, density=1.0) @test shape.coordinates ≈ expected_coords[i] end @@ -86,7 +87,7 @@ end 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.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061] shape = extrude_geometry((p1, p2, p3); direction, particle_spacing=0.1, n_extrude=4, - density=1000.0, tlsph=true) + density=1000.0, place_on_shell=true) @test shape.coordinates ≈ expected_coords end diff --git a/test/setups/rectangular_shape.jl b/test/setups/rectangular_shape.jl index f3e77043b0..7c2fd6875b 100644 --- a/test/setups/rectangular_shape.jl +++ b/test/setups/rectangular_shape.jl @@ -41,7 +41,8 @@ ] @testset "$(loop_orders[i])" for i in eachindex(loop_orders) - shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, tlsph=true, + shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] @@ -242,7 +243,7 @@ end @testset "$(loop_orders[i])" for i in eachindex(loop_orders) shape = RectangularShape(1.0, (2, 2, 2), (0.0, 0.0, 0.0), density=1.0, - tlsph=true, loop_order=loop_orders[i]) + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] end diff --git a/test/setups/sphere_shape.jl b/test/setups/sphere_shape.jl index 57d904a376..c8b87d76db 100644 --- a/test/setups/sphere_shape.jl +++ b/test/setups/sphere_shape.jl @@ -106,14 +106,14 @@ SphereShape(1.0, 1.1, (0.2, -1.0, 0.3), 1000.0, sphere_type=RoundSphere()), SphereShape(1.0, 1.2, (-0.3, 0.1, 0.8), 1000.0, sphere_type=RoundSphere()), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, cutout_min=(0.18, 0.4, 0.5), - cutout_max=(0.42, 10.0, 1.0), tlsph=true), - SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, tlsph=true), + cutout_max=(0.42, 10.0, 1.0), place_on_shell=true), + SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, - layer_outwards=true, tlsph=true), + layer_outwards=true, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, sphere_type=RoundSphere()), SphereShape(0.1, 0.55, (0.3, 0.4, 0.5), 1000.0, n_layers=2, layer_outwards=true, - sphere_type=RoundSphere(), tlsph=true) + sphere_type=RoundSphere(), place_on_shell=true) ] expected_coords = [ diff --git a/test/systems/packing_system.jl b/test/systems/packing_system.jl index d55afd559a..b42e534275 100644 --- a/test/systems/packing_system.jl +++ b/test/systems/packing_system.jl @@ -19,7 +19,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -36,7 +36,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… yes │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -52,7 +52,7 @@ │ neighborhood search: ………………………… Nothing │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" end From 5295070ccb990691a1b1b7018cf05872a8a09994 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 25 Aug 2025 11:20:31 +0200 Subject: [PATCH 29/43] add function for `ParticlePackingSystem` --- src/io/io.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/io/io.jl b/src/io/io.jl index 108d5666ea..e4d8b491e9 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -133,6 +133,16 @@ function add_system_data!(system_data, system::OpenBoundarySPHSystem) add_system_data!(system_data, system.boundary_zone) end +function add_system_data!(system_data, system::ParticlePackingSystem) + system_data["system_type"] = type2string(system) + system_data["particle_spacing"] = system.particle_spacing + system_data["smoothing_kernel"] = type2string(system.smoothing_kernel) + system_data["smoothing_length_interpolation"] = system.smoothing_length_interpolation + system_data["background_pressure"] = system.background_pressure + system_data["place_on_shell"] = system.place_on_shell + system_data["shift_length"] = system.shift_length +end + function add_system_data!(system_data, boundary_model::BoundaryModelDummyParticles) system_data["boundary_model"] = Dict{String, Any}() system_data["boundary_model"]["model"] = type2string(boundary_model) From d60284fe4382733ccc81dc54b1ed6f7373b9211c Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 25 Aug 2025 11:21:43 +0200 Subject: [PATCH 30/43] improve structure --- src/callbacks/post_process.jl | 9 +++----- src/callbacks/solution_saving.jl | 8 +++---- src/io/io.jl | 39 ++++++++++++++++++++------------ 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/callbacks/post_process.jl b/src/callbacks/post_process.jl index e713a6fc78..a5a7f0820f 100644 --- a/src/callbacks/post_process.jl +++ b/src/callbacks/post_process.jl @@ -291,12 +291,9 @@ function write_postprocess_callback(pp::PostprocessCallback, integrator) mkpath(pp.output_directory) data = Dict{String, Any}() + data["meta"] = create_meta_data_dict(pp, integrator) - data["simulation_info"] = Dict{String, Any}() - add_simulation_info!(data["simulation_info"], pp.git_hash, integrator) - - data["system_data"] = Dict{String, Any}() - prepare_series_data!(data["system_data"], pp) + prepare_series_data!(data, pp) time_stamp = "" if pp.append_timestamp @@ -317,7 +314,7 @@ function write_postprocess_callback(pp::PostprocessCallback, integrator) if pp.write_csv abs_file_path = joinpath(abspath(pp.output_directory), filename_csv) - write_csv(abs_file_path, data["system_data"]) + write_csv(abs_file_path, data) end end diff --git a/src/callbacks/solution_saving.jl b/src/callbacks/solution_saving.jl index 486640e946..7a3b4c4e31 100644 --- a/src/callbacks/solution_saving.jl +++ b/src/callbacks/solution_saving.jl @@ -1,7 +1,7 @@ @doc raw""" SolutionSavingCallback(; interval::Integer=0, dt=0.0, save_times=Array{Float64, 1}([]), save_initial_solution=true, save_final_solution=true, - output_directory="out", append_timestamp=false, prefix="", filename="meta_data", + output_directory="out", append_timestamp=false, prefix="", filename="", verbose=false, max_coordinates=2^15, custom_quantities...) @@ -26,7 +26,7 @@ To ignore a custom quantity for a specific system, return `nothing`. - `output_directory="out"`: Directory to save the VTK files. - `append_timestamp=false`: Append current timestamp to the output directory. - `prefix=""`: Prefix added to the filename. -- `filename="meta_data"`: The filename of the Metadata file to be saved. +- `filename=""`: The filename of the Metadata file to be saved. - `custom_quantities...`: Additional user-defined quantities. - `verbose=false`: Print to standard IO when a file is written. - `max_coordinates=2^15`: The coordinates of particles will be clipped if their @@ -61,7 +61,7 @@ saving_callback = SolutionSavingCallback(dt=0.1, my_custom_quantity=kinetic_ener │ save final solution: ………………………… yes │ │ output directory: ………………………………… *path ignored with filter regex above* │ │ prefix: …………………………………………………………… │ -│ filename: ……………………………………………………… meta_data │ +│ filename: ……………………………………………………… │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘ ``` """ @@ -84,7 +84,7 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0, save_times=Float64[], save_initial_solution=true, save_final_solution=true, output_directory="out", append_timestamp=false, - prefix="", filename="meta_data", verbose=false, + prefix="", filename="", verbose=false, max_coordinates=Float64(2^15), custom_quantities...) if (dt > 0 && interval > 0) || (length(save_times) > 0 && (dt > 0 || interval > 0)) diff --git a/src/io/io.jl b/src/io/io.jl index e4d8b491e9..4b0fda062c 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -1,18 +1,37 @@ include("write_vtk.jl") include("read_vtk.jl") -function write_meta_data(callback::SolutionSavingCallback, integrator) - # handle "_" on optional prefix strings - add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") +# handle "_" on optional prefix/filename strings +add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") +add_opt_str_post(str) = (str === "" ? "" : "_$(str)") - git_hash = callback.git_hash +function write_meta_data(callback::SolutionSavingCallback, integrator) prefix = callback.prefix filename = callback.filename + + meta_data = create_meta_data_dict(callback, integrator) + + # write JSON-file + output_directory = callback.output_directory + mkpath(output_directory) + json_file = joinpath(output_directory,"meta_data" * add_opt_str_post(prefix) * add_opt_str_post(filename) * ".json") + + open(json_file, "w") do file + JSON.print(file, meta_data, 2) + end +end + +function create_meta_data_dict(callback, integrator) + git_hash = callback.git_hash + prefix = hasproperty(callback, :prefix) ? callback.prefix : "" semi = integrator.p names = system_names(semi.systems) + meta_data = Dict{String, Any}() + info = Dict{String, Any}() add_simulation_info!(info, git_hash, integrator) + meta_data["simulation_info"] = info systems = Dict{String, Any}() foreach_system(semi) do system @@ -24,19 +43,9 @@ function write_meta_data(callback::SolutionSavingCallback, integrator) systems[name] = system_data end - - meta_data = Dict{String, Any}() - meta_data["simulation_info"] = info meta_data["system_data"] = systems - # write JSON-file - output_directory = callback.output_directory - mkpath(output_directory) - json_file = joinpath(output_directory, add_opt_str_pre(prefix) * filename * ".json") - - open(json_file, "w") do file - JSON.print(file, meta_data, 2) - end + return meta_data end function add_simulation_info!(info, git_hash, integrator) From 48215529b18b836821cd083a7eb4661cbb6a27d7 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 25 Aug 2025 11:23:23 +0200 Subject: [PATCH 31/43] Formatting Code --- src/io/io.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/io/io.jl b/src/io/io.jl index 4b0fda062c..962a3bb300 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -14,7 +14,9 @@ function write_meta_data(callback::SolutionSavingCallback, integrator) # write JSON-file output_directory = callback.output_directory mkpath(output_directory) - json_file = joinpath(output_directory,"meta_data" * add_opt_str_post(prefix) * add_opt_str_post(filename) * ".json") + json_file = joinpath(output_directory, + "meta_data" * add_opt_str_post(prefix) * + add_opt_str_post(filename) * ".json") open(json_file, "w") do file JSON.print(file, meta_data, 2) From c1e858944662bf9880ae9884217bdf93df937b4c Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Fri, 13 Jun 2025 15:52:21 +0200 Subject: [PATCH 32/43] Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> --- examples/dem/collapsing_sand_pile_3d.jl | 3 +- examples/fsi/dam_break_gate_2d.jl | 8 +-- examples/fsi/dam_break_plate_2d.jl | 8 +-- examples/preprocessing/packing_2d.jl | 9 +-- examples/preprocessing/packing_3d.jl | 2 +- examples/solid/oscillating_beam_2d.jl | 6 +- src/general/interpolation.jl | 5 +- .../particle_packing/signed_distance.jl | 2 +- src/preprocessing/particle_packing/system.jl | 35 ++++++----- src/setups/complex_shape.jl | 10 ++-- src/setups/extrude_geometry.jl | 60 +++++++++++-------- src/setups/rectangular_shape.jl | 19 +++--- src/setups/sphere_shape.jl | 45 +++++++------- test/setups/extrude_geometry.jl | 7 ++- test/setups/rectangular_shape.jl | 5 +- test/setups/sphere_shape.jl | 8 +-- test/systems/packing_system.jl | 6 +- 17 files changed, 128 insertions(+), 110 deletions(-) diff --git a/examples/dem/collapsing_sand_pile_3d.jl b/examples/dem/collapsing_sand_pile_3d.jl index aa9ba7a56b..f463ac2417 100644 --- a/examples/dem/collapsing_sand_pile_3d.jl +++ b/examples/dem/collapsing_sand_pile_3d.jl @@ -55,7 +55,8 @@ min_coords_floor = (min_boundary[1] - boundary_thickness, floor_particles = RectangularShape(particle_spacing, (n_particles_floor_x, n_particles_floor_y, n_particles_floor_z), - min_coords_floor; density=boundary_density, tlsph=true) + min_coords_floor; density=boundary_density, + place_on_shell=true) boundary_particles = floor_particles # ========================================================================================== diff --git a/examples/fsi/dam_break_gate_2d.jl b/examples/fsi/dam_break_gate_2d.jl index 529fd56522..44adf7bc59 100644 --- a/examples/fsi/dam_break_gate_2d.jl +++ b/examples/fsi/dam_break_gate_2d.jl @@ -83,18 +83,18 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. # # The right end of the plate is 0.2 from the right end of the tank. plate_position = 0.6 - n_particles_x * solid_particle_spacing plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (plate_position, solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (plate_position, 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/fsi/dam_break_plate_2d.jl b/examples/fsi/dam_break_plate_2d.jl index f5b42ecaa0..d4f8b206fb 100644 --- a/examples/fsi/dam_break_plate_2d.jl +++ b/examples/fsi/dam_break_plate_2d.jl @@ -57,15 +57,15 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (2initial_fluid_size[1], solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (2initial_fluid_size[1], 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/preprocessing/packing_2d.jl b/examples/preprocessing/packing_2d.jl index fc8b330269..0975b6e2ad 100644 --- a/examples/preprocessing/packing_2d.jl +++ b/examples/preprocessing/packing_2d.jl @@ -20,7 +20,7 @@ file = pkgdir(TrixiParticles, "examples", "preprocessing", "data", filename * ". # ========================================================================================== # ==== Packing parameters -tlsph = false +place_on_shell = false # ========================================================================================== # ==== Resolution @@ -50,7 +50,7 @@ shape_sampled = ComplexShape(geometry; particle_spacing, density, # Returns `InitialCondition` boundary_sampled = sample_boundary(signed_distance_field; boundary_density=density, - boundary_thickness, tlsph=tlsph) + boundary_thickness, place_on_shell=place_on_shell) trixi2vtk(shape_sampled) trixi2vtk(boundary_sampled, filename="boundary") @@ -66,12 +66,13 @@ background_pressure = 1.0 smoothing_length = 0.8 * particle_spacing packing_system = ParticlePackingSystem(shape_sampled; smoothing_length=smoothing_length, - signed_distance_field, tlsph=tlsph, + signed_distance_field, place_on_shell=place_on_shell, background_pressure) boundary_system = ParticlePackingSystem(boundary_sampled; smoothing_length=smoothing_length, is_boundary=true, signed_distance_field, - tlsph=tlsph, boundary_compress_factor=0.8, + place_on_shell=place_on_shell, + boundary_compress_factor=0.8, background_pressure) # ========================================================================================== diff --git a/examples/preprocessing/packing_3d.jl b/examples/preprocessing/packing_3d.jl index cb15a255b2..ede3433b38 100644 --- a/examples/preprocessing/packing_3d.jl +++ b/examples/preprocessing/packing_3d.jl @@ -24,5 +24,5 @@ boundary_thickness = 8 * particle_spacing trixi_include(joinpath(examples_dir(), "preprocessing", "packing_2d.jl"), density=1000.0, particle_spacing=particle_spacing, file=file, - boundary_thickness=boundary_thickness, tlsph=true, + boundary_thickness=boundary_thickness, place_on_shell=true, save_intervals=false) diff --git a/examples/solid/oscillating_beam_2d.jl b/examples/solid/oscillating_beam_2d.jl index 8df52c28f1..28d371634d 100644 --- a/examples/solid/oscillating_beam_2d.jl +++ b/examples/solid/oscillating_beam_2d.jl @@ -38,7 +38,7 @@ fixed_particles = SphereShape(particle_spacing, clamp_radius + particle_spacing (0.0, elastic_beam.thickness / 2), material.density, cutout_min=(0.0, 0.0), cutout_max=(clamp_radius, elastic_beam.thickness), - tlsph=true) + place_on_shell=true) n_particles_clamp_x = round(Int, clamp_radius / particle_spacing) @@ -48,9 +48,9 @@ n_particles_per_dimension = (round(Int, elastic_beam.length / particle_spacing) # Note that the `RectangularShape` puts the first particle half a particle spacing away # from the boundary, which is correct for fluids, but not for solids. -# We therefore need to pass `tlsph=true`. +# We therefore need to pass `place_on_shell=true`. beam = RectangularShape(particle_spacing, n_particles_per_dimension, - (0.0, 0.0), density=material.density, tlsph=true) + (0.0, 0.0), density=material.density, place_on_shell=true) solid = union(beam, fixed_particles) diff --git a/src/general/interpolation.jl b/src/general/interpolation.jl index 9b0ac40d7f..6ca3fa16f3 100644 --- a/src/general/interpolation.jl +++ b/src/general/interpolation.jl @@ -191,9 +191,10 @@ function interpolate_plane_2d(min_corner, max_corner, resolution, semi, ref_syst x_range = range(min_corner[1], max_corner[1], length=n_points_per_dimension[1]) y_range = range(min_corner[2], max_corner[2], length=n_points_per_dimension[2]) - # Generate points within the plane. Use `tlsph=true` to generate points on the boundary + # Generate points within the plane. Use `place_on_shell=true` to generate points + # on the shell of the geometry. point_coords = rectangular_shape_coords(resolution, n_points_per_dimension, min_corner, - tlsph=true) + place_on_shell=true) results = interpolate_points(point_coords, semi, ref_system, v_ode, u_ode, smoothing_length=smoothing_length, diff --git a/src/preprocessing/particle_packing/signed_distance.jl b/src/preprocessing/particle_packing/signed_distance.jl index 7e957e124d..082deced5a 100644 --- a/src/preprocessing/particle_packing/signed_distance.jl +++ b/src/preprocessing/particle_packing/signed_distance.jl @@ -59,7 +59,7 @@ function SignedDistanceField(geometry, particle_spacing; particle_spacing)) grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) points = reinterpret(reshape, SVector{NDIMS, ELTYPE}, grid) end diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index fb97501e4c..3af6adc809 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -6,7 +6,7 @@ smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, fixed_system=false) System to generate body-fitted particles for complex shapes. For more information on the methods, see [particle packing](@ref particle_packing). @@ -18,10 +18,11 @@ For more information on the methods, see [particle packing](@ref particle_packin - `background_pressure`: Constant background pressure to physically pack the particles. A large `background_pressure` can cause high accelerations which requires a properly adjusted time step. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not half a particle spacing away, - as for fluids. When `tlsph=true`, particles will be placed - on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. - `is_boundary`: When `shape` is inside the geometry that was used to create `signed_distance_field`, set `is_boundary=false`. Otherwise (`shape` is the sampled boundary), set `is_boundary=true`. @@ -64,7 +65,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, smoothing_kernel :: K smoothing_length_interpolation :: ELTYPE background_pressure :: ELTYPE - tlsph :: Bool + place_on_shell :: Bool signed_distance_field :: S is_boundary :: Bool shift_length :: ELTYPE @@ -79,7 +80,8 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, # See the comments in general/gpu.jl for more details. function ParticlePackingSystem(initial_condition, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, + signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, buffer, update_callback_used, fixed_system, cache, @@ -93,7 +95,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, @@ -108,7 +110,8 @@ function ParticlePackingSystem(shape::InitialCondition; smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, + fixed_system=false) NDIMS = ndims(shape) ELTYPE = eltype(shape) mass = copy(shape.mass) @@ -147,12 +150,12 @@ function ParticlePackingSystem(shape::InitialCondition; # Its value is negative if the particle is inside the geometry. # Otherwise (if outside), the value is positive. if is_boundary - offset = tlsph ? shape.particle_spacing : shape.particle_spacing / 2 + offset = place_on_shell ? shape.particle_spacing : shape.particle_spacing / 2 shift_length = -boundary_compress_factor * signed_distance_field.max_signed_distance - offset else - shift_length = tlsph ? zero(ELTYPE) : shape.particle_spacing / 2 + shift_length = place_on_shell ? zero(ELTYPE) : shape.particle_spacing / 2 end cache = (; create_cache_refinement(shape, particle_refinement, smoothing_length)...) @@ -161,7 +164,7 @@ function ParticlePackingSystem(shape::InitialCondition; return ParticlePackingSystem(shape, mass, density, shape.particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, nhs, fill(zero(ELTYPE), nparticles(shape)), particle_refinement, nothing, Ref(false), fixed_system, cache, @@ -187,7 +190,7 @@ function Base.show(io::IO, ::MIME"text/plain", system::ParticlePackingSystem) system.neighborhood_search |> typeof |> nameof) summary_line(io, "#particles", nparticles(system)) summary_line(io, "smoothing kernel", system.smoothing_kernel |> typeof |> nameof) - summary_line(io, "tlsph", system.tlsph ? "yes" : "no") + summary_line(io, "place_on_shell", system.place_on_shell ? "yes" : "no") summary_line(io, "boundary", system.is_boundary ? "yes" : "no") summary_footer(io) end @@ -341,8 +344,8 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector (; shift_length) = system # For fluid particles: - # - `tlsph = true`: `shift_length = 0` - # - `tlsph = false`: `shift_length = particle_spacing / 2` + # - `place_on_shell = true`: `shift_length = 0` + # - `place_on_shell = false`: `shift_length = particle_spacing / 2` # For boundary particles: # `shift_length` is the thickness of the boundary. if distance_signed >= -shift_length @@ -357,7 +360,7 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector system.is_boundary || return u particle_spacing = system.initial_condition.particle_spacing - shift_length_inner = system.tlsph ? particle_spacing : particle_spacing / 2 + shift_length_inner = system.place_on_shell ? particle_spacing : particle_spacing / 2 if distance_signed < shift_length_inner shift = (distance_signed - shift_length_inner) * normal_vector diff --git a/src/setups/complex_shape.jl b/src/setups/complex_shape.jl index cdb8e146b6..032250ce56 100644 --- a/src/setups/complex_shape.jl +++ b/src/setups/complex_shape.jl @@ -79,7 +79,7 @@ end """ sample_boundary(signed_distance_field; - boundary_density, boundary_thickness, tlsph=true) + boundary_density, boundary_thickness, place_on_shell=true) Sample boundary particles of a complex geometry by using the [`SignedDistanceField`](@ref) of the geometry. @@ -90,9 +90,9 @@ of the geometry. # Keywords - `boundary_thickness`: Thickness of the boundary - `boundary_density`: Density of each boundary particle. -- `tlsph` : When `tlsph=true`, boundary particles will be placed +- `place_on_shell`: When `place_on_shell=true`, boundary particles will be placed one particle spacing from the surface of the geometry. - Otherwise when `tlsph=true` (simulating fluid particles), + Otherwise when `place_on_shell=true` (simulating fluid particles), boundary particles will be placed half particle spacing away from the surface. @@ -118,7 +118,7 @@ boundary_sampled = sample_boundary(signed_distance_field; boundary_density=1.0, ``` """ function sample_boundary(signed_distance_field; - boundary_density, boundary_thickness, tlsph=true) + boundary_density, boundary_thickness, place_on_shell=true) (; max_signed_distance, boundary_packing, positions, distances, particle_spacing) = signed_distance_field @@ -158,6 +158,6 @@ function particle_grid(geometry, particle_spacing; end grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) return reinterpret(reshape, SVector{ndims(geometry), eltype(geometry)}, grid) end diff --git a/src/setups/extrude_geometry.jl b/src/setups/extrude_geometry.jl index 498266ecd0..6d169762c7 100644 --- a/src/setups/extrude_geometry.jl +++ b/src/setups/extrude_geometry.jl @@ -30,9 +30,11 @@ Returns an [`InitialCondition`](@ref). - `pressure`: Scalar to set the pressure of all particles to this value. This is only used by the [`EntropicallyDampedSPHSystem`](@ref) and will be overwritten when using an initial pressure function in the system. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. # Examples ```jldoctest; output = false @@ -79,7 +81,7 @@ shape = extrude_geometry(shape; direction, particle_spacing=0.1, n_extrude=4, de This is an experimental feature and may change in any future releases. """ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::Integer, - velocity=zeros(length(direction)), tlsph=false, + velocity=zeros(length(direction)), place_on_shell=false, mass=nothing, density=nothing, pressure=0.0) direction_ = normalize(direction) NDIMS = length(direction_) @@ -95,9 +97,11 @@ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::I throw(ArgumentError("`particle_spacing` must be specified when not extruding an `InitialCondition`")) end - geometry = shift_plane_corners(geometry, direction_, particle_spacing, tlsph) + geometry = shift_plane_corners(geometry, direction_, particle_spacing, place_on_shell) - face_coords, particle_spacing_ = sample_plane(geometry, particle_spacing; tlsph=tlsph) + face_coords, + particle_spacing_ = sample_plane(geometry, particle_spacing; + place_on_shell=place_on_shell) if !isapprox(particle_spacing, particle_spacing_, rtol=5e-2) @info "The desired size is not a multiple of the particle spacing $particle_spacing." * @@ -119,12 +123,13 @@ end # For corners/endpoints of a plane/line, sample the plane/line with particles. # For 2D coordinates or an `InitialCondition`, add a third dimension. -function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) +function sample_plane(geometry::AbstractMatrix, particle_spacing; place_on_shell) if size(geometry, 1) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane - coords = vcat(geometry, fill(tlsph ? 0 : particle_spacing / 2, size(geometry, 2))') + # When `place_on_shell=true`, particles will be placed on the x-y plane + coords = vcat(geometry, + fill(place_on_shell ? 0 : particle_spacing / 2, size(geometry, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -133,13 +138,14 @@ function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) return geometry, particle_spacing end -function sample_plane(shape::InitialCondition, particle_spacing; tlsph) +function sample_plane(shape::InitialCondition, particle_spacing; place_on_shell) if ndims(shape) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane + # When `place_on_shell=true`, particles will be placed on the x-y plane coords = vcat(shape.coordinates, - fill(tlsph ? 0 : particle_spacing / 2, size(shape.coordinates, 2))') + fill(place_on_shell ? 0 : particle_spacing / 2, + size(shape.coordinates, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -148,13 +154,13 @@ function sample_plane(shape::InitialCondition, particle_spacing; tlsph) return shape.coordinates, particle_spacing end -function sample_plane(plane_points, particle_spacing; tlsph=nothing) +function sample_plane(plane_points, particle_spacing; place_on_shell=nothing) # Convert to tuple - return sample_plane(tuple(plane_points...), particle_spacing; tlsph=nothing) + return sample_plane(tuple(plane_points...), particle_spacing; place_on_shell=nothing) end -function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{2}, particle_spacing; place_on_shell=nothing) # Verify that points are in 2D space if any(length.(plane_points) .!= 2) throw(ArgumentError("all points must be 2D coordinates")) @@ -168,7 +174,7 @@ function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{3}, particle_spacing; place_on_shell=nothing) # Verify that points are in 3D space if any(length.(plane_points) .!= 3) throw(ArgumentError("all points must be 3D coordinates")) @@ -209,21 +215,22 @@ function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -# Shift corners of the plane/line inwards by half a particle spacing with `tlsph=false` +# Shift corners of the plane/line inwards by half a particle spacing with `place_on_shell=false` # because fluid particles need to be half a particle spacing away from the boundary of the shape. function shift_plane_corners(geometry::Union{AbstractMatrix, InitialCondition}, - direction, particle_spacing, tlsph) + direction, particle_spacing, place_on_shell) return geometry end -function shift_plane_corners(plane_points, direction, particle_spacing, tlsph) - shift_plane_corners(tuple(plane_points...), direction, particle_spacing, tlsph) +function shift_plane_corners(plane_points, direction, particle_spacing, place_on_shell) + shift_plane_corners(tuple(plane_points...), direction, particle_spacing, place_on_shell) end -function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) @@ -238,10 +245,11 @@ function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacin return (plane_point1, plane_point2) end -function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) diff --git a/src/setups/rectangular_shape.jl b/src/setups/rectangular_shape.jl index 98160bcac9..1c30ef5c1b 100644 --- a/src/setups/rectangular_shape.jl +++ b/src/setups/rectangular_shape.jl @@ -3,7 +3,7 @@ velocity=zeros(length(n_particles_per_dimension)), mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). @@ -40,9 +40,10 @@ Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). - `state_equation`: When calculating a hydrostatic pressure gradient by setting `acceleration`, the `state_equation` will be used to set the corresponding density. Cannot be used together with `density`. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. - `coordinates_perturbation`: Add a small random displacement to the particle positions, where the amplitude is `coordinates_perturbation * particle_spacing`. @@ -75,7 +76,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord coordinates_perturbation=nothing, mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) end @@ -95,7 +96,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord n_particles = prod(n_particles_per_dimension) coordinates = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates, tlsph=tlsph, + min_coordinates, place_on_shell=place_on_shell, loop_order=loop_order) if !isnothing(coordinates_perturbation) @@ -190,15 +191,15 @@ function loop_permutation(loop_order, NDIMS::Val{3}) end function rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates; tlsph=false, loop_order=nothing) + min_coordinates; place_on_shell=false, loop_order=nothing) ELTYPE = eltype(particle_spacing) NDIMS = length(n_particles_per_dimension) coordinates = Array{ELTYPE, 2}(undef, NDIMS, prod(n_particles_per_dimension)) - # With TLSPH, particles need to be AT the min coordinates and not half a particle + # With place_on_shell, particles need to be AT the min coordinates and not half a particle # spacing away from it. - if tlsph + if place_on_shell min_coordinates = min_coordinates .- 0.5particle_spacing end diff --git a/src/setups/sphere_shape.jl b/src/setups/sphere_shape.jl index 0233fc8995..3c6a7466d5 100644 --- a/src/setups/sphere_shape.jl +++ b/src/setups/sphere_shape.jl @@ -1,7 +1,7 @@ """ SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0.0) Generate a sphere that is either completely filled (by default) @@ -35,18 +35,19 @@ coordinate directions as `cutout_min` and `cutout_max`. cut out of the sphere. - `cutout_max`: Corner in positive coordinate directions of a cuboid that is to be cut out of the sphere. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. -- `velocity`: Either a function mapping each particle's coordinates to its velocity, - or, for a constant fluid velocity, a vector holding this velocity. - Velocity is constant zero by default. -- `mass`: Either `nothing` (default) to automatically compute particle mass from particle - density and spacing, or a function mapping each particle's coordinates to its mass, - or a scalar for a constant mass over all particles. -- `pressure`: Either a function mapping each particle's coordinates to its pressure, - or a scalar for a constant pressure over all particles. This is optional and - only needed when using the [`EntropicallyDampedSPHSystem`](@ref). +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. +- `velocity`: Either a function mapping each particle's coordinates to its velocity, + or, for a constant fluid velocity, a vector holding this velocity. + Velocity is constant zero by default. +- `mass`: Either `nothing` (default) to automatically compute particle mass from particle + density and spacing, or a function mapping each particle's coordinates to its mass, + or a scalar for a constant mass over all particles. +- `pressure`: Either a function mapping each particle's coordinates to its pressure, + or a scalar for a constant pressure over all particles. This is optional and + only needed when using the [`EntropicallyDampedSPHSystem`](@ref). # Examples ```jldoctest; output = false @@ -89,7 +90,7 @@ SphereShape(0.1, 0.5, (0.2, 0.4, 0.3), 1000.0, sphere_type=RoundSphere()) """ function SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) @@ -99,7 +100,7 @@ function SphereShape(particle_spacing, radius, center_position, density; coordinates = sphere_shape_coords(sphere_type, particle_spacing, radius, SVector{NDIMS}(center_position), - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) # Convert tuples to vectors cutout_min_ = collect(cutout_min) @@ -169,13 +170,13 @@ struct RoundSphere{AR} end function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_position, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius outer_radius = radius + n_layers * particle_spacing - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of `radius` inner_radius += particle_spacing / 2 outer_radius += particle_spacing / 2 @@ -184,7 +185,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos inner_radius = radius - n_layers * particle_spacing outer_radius = radius - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` inner_radius -= particle_spacing / 2 outer_radius -= particle_spacing / 2 @@ -194,7 +195,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos outer_radius = radius inner_radius = -1 - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` outer_radius -= particle_spacing / 2 end @@ -225,7 +226,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos end function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, center, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius @@ -233,12 +234,12 @@ function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, cent inner_radius = radius - n_layers * particle_spacing end - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of inner radius inner_radius += particle_spacing / 2 end else - if tlsph + if place_on_shell # Just create a sphere that is 0.5 particle spacing larger radius += particle_spacing / 2 end diff --git a/test/setups/extrude_geometry.jl b/test/setups/extrude_geometry.jl index e695f2e170..5a927dbee4 100644 --- a/test/setups/extrude_geometry.jl +++ b/test/setups/extrude_geometry.jl @@ -28,7 +28,8 @@ ] @testset "Direction $i" for i in eachindex(directions) - shape = extrude_geometry((point1, point2); direction=directions[i], tlsph=true, + shape = extrude_geometry((point1, point2); direction=directions[i], + place_on_shell=true, particle_spacing=0.15, n_extrude=5, density=1.0) @test shape.coordinates ≈ expected_coords[i] @@ -68,7 +69,7 @@ end @testset "Direction $i" for i in eachindex(directions) shape = extrude_geometry(geometry; direction=directions[i], particle_spacing, - n_extrude=5, tlsph=true, density=1.0) + n_extrude=5, place_on_shell=true, density=1.0) @test shape.coordinates ≈ expected_coords[i] end @@ -86,7 +87,7 @@ end 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.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061] shape = extrude_geometry((p1, p2, p3); direction, particle_spacing=0.1, n_extrude=4, - density=1000.0, tlsph=true) + density=1000.0, place_on_shell=true) @test shape.coordinates ≈ expected_coords end diff --git a/test/setups/rectangular_shape.jl b/test/setups/rectangular_shape.jl index f3e77043b0..7c2fd6875b 100644 --- a/test/setups/rectangular_shape.jl +++ b/test/setups/rectangular_shape.jl @@ -41,7 +41,8 @@ ] @testset "$(loop_orders[i])" for i in eachindex(loop_orders) - shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, tlsph=true, + shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] @@ -242,7 +243,7 @@ end @testset "$(loop_orders[i])" for i in eachindex(loop_orders) shape = RectangularShape(1.0, (2, 2, 2), (0.0, 0.0, 0.0), density=1.0, - tlsph=true, loop_order=loop_orders[i]) + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] end diff --git a/test/setups/sphere_shape.jl b/test/setups/sphere_shape.jl index 57d904a376..c8b87d76db 100644 --- a/test/setups/sphere_shape.jl +++ b/test/setups/sphere_shape.jl @@ -106,14 +106,14 @@ SphereShape(1.0, 1.1, (0.2, -1.0, 0.3), 1000.0, sphere_type=RoundSphere()), SphereShape(1.0, 1.2, (-0.3, 0.1, 0.8), 1000.0, sphere_type=RoundSphere()), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, cutout_min=(0.18, 0.4, 0.5), - cutout_max=(0.42, 10.0, 1.0), tlsph=true), - SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, tlsph=true), + cutout_max=(0.42, 10.0, 1.0), place_on_shell=true), + SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, - layer_outwards=true, tlsph=true), + layer_outwards=true, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, sphere_type=RoundSphere()), SphereShape(0.1, 0.55, (0.3, 0.4, 0.5), 1000.0, n_layers=2, layer_outwards=true, - sphere_type=RoundSphere(), tlsph=true) + sphere_type=RoundSphere(), place_on_shell=true) ] expected_coords = [ diff --git a/test/systems/packing_system.jl b/test/systems/packing_system.jl index d55afd559a..b42e534275 100644 --- a/test/systems/packing_system.jl +++ b/test/systems/packing_system.jl @@ -19,7 +19,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -36,7 +36,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… yes │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -52,7 +52,7 @@ │ neighborhood search: ………………………… Nothing │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" end From fcbd3637ff2f67f8552bbf514cc5a70f028d2ab7 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Tue, 26 Aug 2025 11:55:24 +0200 Subject: [PATCH 33/43] fix failing tests --- src/TrixiParticles.jl | 2 +- test/callbacks/solution_saving.jl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TrixiParticles.jl b/src/TrixiParticles.jl index 987e208750..03eb40f00d 100644 --- a/src/TrixiParticles.jl +++ b/src/TrixiParticles.jl @@ -55,8 +55,8 @@ include("callbacks/callbacks.jl") # included separately. `gpu.jl` in turn depends on the semidiscretization type. include("general/semidiscretization.jl") include("general/gpu.jl") -include("io/io.jl") include("preprocessing/preprocessing.jl") +include("io/io.jl") include("visualization/recipes_plots.jl") export Semidiscretization, semidiscretize, restart_with! diff --git a/test/callbacks/solution_saving.jl b/test/callbacks/solution_saving.jl index bd0a517af1..7ca5cb8ece 100644 --- a/test/callbacks/solution_saving.jl +++ b/test/callbacks/solution_saving.jl @@ -19,7 +19,7 @@ │ save final solution: ………………………… yes │ │ output directory: ………………………………… $(output_directory_padded)│ │ prefix: …………………………………………………………… test │ - │ filename: ……………………………………………………… meta_data │ + │ filename: ……………………………………………………… │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback) == show_box end @@ -41,7 +41,7 @@ │ save final solution: ………………………… yes │ │ output directory: ………………………………… $(output_directory_padded)│ │ prefix: …………………………………………………………… test │ - │ filename: ……………………………………………………… meta_data │ + │ filename: ……………………………………………………… │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback) == show_box end @@ -63,7 +63,7 @@ │ save final solution: ………………………… yes │ │ output directory: ………………………………… $(output_directory_padded)│ │ prefix: …………………………………………………………… test │ - │ filename: ……………………………………………………… meta_data │ + │ filename: ……………………………………………………… │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback) == show_box end From ac9029ec69b0bf0e3d113e83ce4a793cab69cf3c Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Fri, 13 Jun 2025 15:52:21 +0200 Subject: [PATCH 34/43] Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> --- examples/dem/collapsing_sand_pile_3d.jl | 3 +- examples/fsi/dam_break_gate_2d.jl | 8 +-- examples/fsi/dam_break_plate_2d.jl | 8 +-- examples/preprocessing/packing_2d.jl | 9 +-- examples/preprocessing/packing_3d.jl | 2 +- examples/solid/oscillating_beam_2d.jl | 6 +- src/general/interpolation.jl | 5 +- .../particle_packing/signed_distance.jl | 2 +- src/preprocessing/particle_packing/system.jl | 35 ++++++----- src/setups/complex_shape.jl | 10 ++-- src/setups/extrude_geometry.jl | 60 +++++++++++-------- src/setups/rectangular_shape.jl | 19 +++--- src/setups/sphere_shape.jl | 45 +++++++------- test/setups/extrude_geometry.jl | 7 ++- test/setups/rectangular_shape.jl | 5 +- test/setups/sphere_shape.jl | 8 +-- test/systems/packing_system.jl | 6 +- 17 files changed, 128 insertions(+), 110 deletions(-) diff --git a/examples/dem/collapsing_sand_pile_3d.jl b/examples/dem/collapsing_sand_pile_3d.jl index aa9ba7a56b..f463ac2417 100644 --- a/examples/dem/collapsing_sand_pile_3d.jl +++ b/examples/dem/collapsing_sand_pile_3d.jl @@ -55,7 +55,8 @@ min_coords_floor = (min_boundary[1] - boundary_thickness, floor_particles = RectangularShape(particle_spacing, (n_particles_floor_x, n_particles_floor_y, n_particles_floor_z), - min_coords_floor; density=boundary_density, tlsph=true) + min_coords_floor; density=boundary_density, + place_on_shell=true) boundary_particles = floor_particles # ========================================================================================== diff --git a/examples/fsi/dam_break_gate_2d.jl b/examples/fsi/dam_break_gate_2d.jl index 529fd56522..44adf7bc59 100644 --- a/examples/fsi/dam_break_gate_2d.jl +++ b/examples/fsi/dam_break_gate_2d.jl @@ -83,18 +83,18 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. # # The right end of the plate is 0.2 from the right end of the tank. plate_position = 0.6 - n_particles_x * solid_particle_spacing plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (plate_position, solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (plate_position, 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/fsi/dam_break_plate_2d.jl b/examples/fsi/dam_break_plate_2d.jl index f5b42ecaa0..d4f8b206fb 100644 --- a/examples/fsi/dam_break_plate_2d.jl +++ b/examples/fsi/dam_break_plate_2d.jl @@ -57,15 +57,15 @@ solid_particle_spacing = thickness / (n_particles_x - 1) n_particles_y = round(Int, length_beam / solid_particle_spacing) + 1 # The bottom layer is sampled separately below. Note that the `RectangularShape` puts the -# first particle half a particle spacing away from the boundary, which is correct for fluids, -# but not for solids. We therefore need to pass `tlsph=true`. +# first particle half a particle spacing away from the shell of the shape, which is +# correct for fluids, but not for solids. We therefore need to pass `place_on_shell=true`. plate = RectangularShape(solid_particle_spacing, (n_particles_x, n_particles_y - 1), (2initial_fluid_size[1], solid_particle_spacing), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) fixed_particles = RectangularShape(solid_particle_spacing, (n_particles_x, 1), (2initial_fluid_size[1], 0.0), - density=solid_density, tlsph=true) + density=solid_density, place_on_shell=true) solid = union(plate, fixed_particles) diff --git a/examples/preprocessing/packing_2d.jl b/examples/preprocessing/packing_2d.jl index fc8b330269..0975b6e2ad 100644 --- a/examples/preprocessing/packing_2d.jl +++ b/examples/preprocessing/packing_2d.jl @@ -20,7 +20,7 @@ file = pkgdir(TrixiParticles, "examples", "preprocessing", "data", filename * ". # ========================================================================================== # ==== Packing parameters -tlsph = false +place_on_shell = false # ========================================================================================== # ==== Resolution @@ -50,7 +50,7 @@ shape_sampled = ComplexShape(geometry; particle_spacing, density, # Returns `InitialCondition` boundary_sampled = sample_boundary(signed_distance_field; boundary_density=density, - boundary_thickness, tlsph=tlsph) + boundary_thickness, place_on_shell=place_on_shell) trixi2vtk(shape_sampled) trixi2vtk(boundary_sampled, filename="boundary") @@ -66,12 +66,13 @@ background_pressure = 1.0 smoothing_length = 0.8 * particle_spacing packing_system = ParticlePackingSystem(shape_sampled; smoothing_length=smoothing_length, - signed_distance_field, tlsph=tlsph, + signed_distance_field, place_on_shell=place_on_shell, background_pressure) boundary_system = ParticlePackingSystem(boundary_sampled; smoothing_length=smoothing_length, is_boundary=true, signed_distance_field, - tlsph=tlsph, boundary_compress_factor=0.8, + place_on_shell=place_on_shell, + boundary_compress_factor=0.8, background_pressure) # ========================================================================================== diff --git a/examples/preprocessing/packing_3d.jl b/examples/preprocessing/packing_3d.jl index cb15a255b2..ede3433b38 100644 --- a/examples/preprocessing/packing_3d.jl +++ b/examples/preprocessing/packing_3d.jl @@ -24,5 +24,5 @@ boundary_thickness = 8 * particle_spacing trixi_include(joinpath(examples_dir(), "preprocessing", "packing_2d.jl"), density=1000.0, particle_spacing=particle_spacing, file=file, - boundary_thickness=boundary_thickness, tlsph=true, + boundary_thickness=boundary_thickness, place_on_shell=true, save_intervals=false) diff --git a/examples/solid/oscillating_beam_2d.jl b/examples/solid/oscillating_beam_2d.jl index e2bb13a300..8deadc23db 100644 --- a/examples/solid/oscillating_beam_2d.jl +++ b/examples/solid/oscillating_beam_2d.jl @@ -38,7 +38,7 @@ fixed_particles = SphereShape(particle_spacing, clamp_radius + particle_spacing (0.0, elastic_beam.thickness / 2), material.density, cutout_min=(0.0, 0.0), cutout_max=(clamp_radius, elastic_beam.thickness), - tlsph=true) + place_on_shell=true) n_particles_clamp_x = round(Int, clamp_radius / particle_spacing) @@ -48,9 +48,9 @@ n_particles_per_dimension = (round(Int, elastic_beam.length / particle_spacing) # Note that the `RectangularShape` puts the first particle half a particle spacing away # from the boundary, which is correct for fluids, but not for solids. -# We therefore need to pass `tlsph=true`. +# We therefore need to pass `place_on_shell=true`. beam = RectangularShape(particle_spacing, n_particles_per_dimension, - (0.0, 0.0), density=material.density, tlsph=true) + (0.0, 0.0), density=material.density, place_on_shell=true) solid = union(beam, fixed_particles) diff --git a/src/general/interpolation.jl b/src/general/interpolation.jl index afee4de5b1..cc246111c9 100644 --- a/src/general/interpolation.jl +++ b/src/general/interpolation.jl @@ -191,9 +191,10 @@ function interpolate_plane_2d(min_corner, max_corner, resolution, semi, ref_syst x_range = range(min_corner[1], max_corner[1], length=n_points_per_dimension[1]) y_range = range(min_corner[2], max_corner[2], length=n_points_per_dimension[2]) - # Generate points within the plane. Use `tlsph=true` to generate points on the boundary + # Generate points within the plane. Use `place_on_shell=true` to generate points + # on the shell of the geometry. point_coords = rectangular_shape_coords(resolution, n_points_per_dimension, min_corner, - tlsph=true) + place_on_shell=true) results = interpolate_points(point_coords, semi, ref_system, v_ode, u_ode, smoothing_length=smoothing_length, diff --git a/src/preprocessing/particle_packing/signed_distance.jl b/src/preprocessing/particle_packing/signed_distance.jl index 7e957e124d..082deced5a 100644 --- a/src/preprocessing/particle_packing/signed_distance.jl +++ b/src/preprocessing/particle_packing/signed_distance.jl @@ -59,7 +59,7 @@ function SignedDistanceField(geometry, particle_spacing; particle_spacing)) grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) points = reinterpret(reshape, SVector{NDIMS, ELTYPE}, grid) end diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index f0772589ff..6f73fb2c68 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -6,7 +6,7 @@ smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, fixed_system=false) System to generate body-fitted particles for complex shapes. For more information on the methods, see [particle packing](@ref particle_packing). @@ -18,10 +18,11 @@ For more information on the methods, see [particle packing](@ref particle_packin - `background_pressure`: Constant background pressure to physically pack the particles. A large `background_pressure` can cause high accelerations which requires a properly adjusted time step. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not half a particle spacing away, - as for fluids. When `tlsph=true`, particles will be placed - on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. - `is_boundary`: When `shape` is inside the geometry that was used to create `signed_distance_field`, set `is_boundary=false`. Otherwise (`shape` is the sampled boundary), set `is_boundary=true`. @@ -64,7 +65,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, smoothing_kernel :: K smoothing_length_interpolation :: ELTYPE background_pressure :: ELTYPE - tlsph :: Bool + place_on_shell :: Bool signed_distance_field :: S is_boundary :: Bool shift_length :: ELTYPE @@ -78,7 +79,8 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, # See the comments in general/gpu.jl for more details. function ParticlePackingSystem(initial_condition, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, + signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, buffer, fixed_system, cache, advection_velocity) @@ -90,7 +92,7 @@ struct ParticlePackingSystem{S, F, NDIMS, ELTYPE <: Real, PR, C, AV, mass, density, particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, neighborhood_search, signed_distances, particle_refinement, @@ -105,7 +107,8 @@ function ParticlePackingSystem(shape::InitialCondition; smoothing_length_interpolation=smoothing_length, is_boundary=false, boundary_compress_factor=1, neighborhood_search=GridNeighborhoodSearch{ndims(shape)}(), - background_pressure, tlsph=false, fixed_system=false) + background_pressure, place_on_shell=false, + fixed_system=false) NDIMS = ndims(shape) ELTYPE = eltype(shape) mass = copy(shape.mass) @@ -144,12 +147,12 @@ function ParticlePackingSystem(shape::InitialCondition; # Its value is negative if the particle is inside the geometry. # Otherwise (if outside), the value is positive. if is_boundary - offset = tlsph ? shape.particle_spacing : shape.particle_spacing / 2 + offset = place_on_shell ? shape.particle_spacing : shape.particle_spacing / 2 shift_length = -boundary_compress_factor * signed_distance_field.max_signed_distance - offset else - shift_length = tlsph ? zero(ELTYPE) : shape.particle_spacing / 2 + shift_length = place_on_shell ? zero(ELTYPE) : shape.particle_spacing / 2 end cache = (; create_cache_refinement(shape, particle_refinement, smoothing_length)...) @@ -158,7 +161,7 @@ function ParticlePackingSystem(shape::InitialCondition; return ParticlePackingSystem(shape, mass, density, shape.particle_spacing, smoothing_kernel, smoothing_length_interpolation, - background_pressure, tlsph, signed_distance_field, + background_pressure, place_on_shell, signed_distance_field, is_boundary, shift_length, nhs, fill(zero(ELTYPE), nparticles(shape)), particle_refinement, nothing, fixed_system, cache, advection_velocity) @@ -183,7 +186,7 @@ function Base.show(io::IO, ::MIME"text/plain", system::ParticlePackingSystem) system.neighborhood_search |> typeof |> nameof) summary_line(io, "#particles", nparticles(system)) summary_line(io, "smoothing kernel", system.smoothing_kernel |> typeof |> nameof) - summary_line(io, "tlsph", system.tlsph ? "yes" : "no") + summary_line(io, "place_on_shell", system.place_on_shell ? "yes" : "no") summary_line(io, "boundary", system.is_boundary ? "yes" : "no") summary_footer(io) end @@ -330,8 +333,8 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector (; shift_length) = system # For fluid particles: - # - `tlsph = true`: `shift_length = 0` - # - `tlsph = false`: `shift_length = particle_spacing / 2` + # - `place_on_shell = true`: `shift_length = 0` + # - `place_on_shell = false`: `shift_length = particle_spacing / 2` # For boundary particles: # `shift_length` is the thickness of the boundary. if distance_signed >= -shift_length @@ -346,7 +349,7 @@ function constrain_particle!(u, system, particle, distance_signed, normal_vector system.is_boundary || return u particle_spacing = system.initial_condition.particle_spacing - shift_length_inner = system.tlsph ? particle_spacing : particle_spacing / 2 + shift_length_inner = system.place_on_shell ? particle_spacing : particle_spacing / 2 if distance_signed < shift_length_inner shift = (distance_signed - shift_length_inner) * normal_vector diff --git a/src/setups/complex_shape.jl b/src/setups/complex_shape.jl index cdb8e146b6..032250ce56 100644 --- a/src/setups/complex_shape.jl +++ b/src/setups/complex_shape.jl @@ -79,7 +79,7 @@ end """ sample_boundary(signed_distance_field; - boundary_density, boundary_thickness, tlsph=true) + boundary_density, boundary_thickness, place_on_shell=true) Sample boundary particles of a complex geometry by using the [`SignedDistanceField`](@ref) of the geometry. @@ -90,9 +90,9 @@ of the geometry. # Keywords - `boundary_thickness`: Thickness of the boundary - `boundary_density`: Density of each boundary particle. -- `tlsph` : When `tlsph=true`, boundary particles will be placed +- `place_on_shell`: When `place_on_shell=true`, boundary particles will be placed one particle spacing from the surface of the geometry. - Otherwise when `tlsph=true` (simulating fluid particles), + Otherwise when `place_on_shell=true` (simulating fluid particles), boundary particles will be placed half particle spacing away from the surface. @@ -118,7 +118,7 @@ boundary_sampled = sample_boundary(signed_distance_field; boundary_density=1.0, ``` """ function sample_boundary(signed_distance_field; - boundary_density, boundary_thickness, tlsph=true) + boundary_density, boundary_thickness, place_on_shell=true) (; max_signed_distance, boundary_packing, positions, distances, particle_spacing) = signed_distance_field @@ -158,6 +158,6 @@ function particle_grid(geometry, particle_spacing; end grid = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_corner; tlsph=true) + min_corner; place_on_shell=true) return reinterpret(reshape, SVector{ndims(geometry), eltype(geometry)}, grid) end diff --git a/src/setups/extrude_geometry.jl b/src/setups/extrude_geometry.jl index 498266ecd0..6d169762c7 100644 --- a/src/setups/extrude_geometry.jl +++ b/src/setups/extrude_geometry.jl @@ -30,9 +30,11 @@ Returns an [`InitialCondition`](@ref). - `pressure`: Scalar to set the pressure of all particles to this value. This is only used by the [`EntropicallyDampedSPHSystem`](@ref) and will be overwritten when using an initial pressure function in the system. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed + on the shell of the geometry. For example, + the [`TotalLagrangianSPHSystem`](@ref) requires particles to be placed + on the shell of the geometry and not half a particle spacing away, + as for fluids. # Examples ```jldoctest; output = false @@ -79,7 +81,7 @@ shape = extrude_geometry(shape; direction, particle_spacing=0.1, n_extrude=4, de This is an experimental feature and may change in any future releases. """ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::Integer, - velocity=zeros(length(direction)), tlsph=false, + velocity=zeros(length(direction)), place_on_shell=false, mass=nothing, density=nothing, pressure=0.0) direction_ = normalize(direction) NDIMS = length(direction_) @@ -95,9 +97,11 @@ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::I throw(ArgumentError("`particle_spacing` must be specified when not extruding an `InitialCondition`")) end - geometry = shift_plane_corners(geometry, direction_, particle_spacing, tlsph) + geometry = shift_plane_corners(geometry, direction_, particle_spacing, place_on_shell) - face_coords, particle_spacing_ = sample_plane(geometry, particle_spacing; tlsph=tlsph) + face_coords, + particle_spacing_ = sample_plane(geometry, particle_spacing; + place_on_shell=place_on_shell) if !isapprox(particle_spacing, particle_spacing_, rtol=5e-2) @info "The desired size is not a multiple of the particle spacing $particle_spacing." * @@ -119,12 +123,13 @@ end # For corners/endpoints of a plane/line, sample the plane/line with particles. # For 2D coordinates or an `InitialCondition`, add a third dimension. -function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) +function sample_plane(geometry::AbstractMatrix, particle_spacing; place_on_shell) if size(geometry, 1) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane - coords = vcat(geometry, fill(tlsph ? 0 : particle_spacing / 2, size(geometry, 2))') + # When `place_on_shell=true`, particles will be placed on the x-y plane + coords = vcat(geometry, + fill(place_on_shell ? 0 : particle_spacing / 2, size(geometry, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -133,13 +138,14 @@ function sample_plane(geometry::AbstractMatrix, particle_spacing; tlsph) return geometry, particle_spacing end -function sample_plane(shape::InitialCondition, particle_spacing; tlsph) +function sample_plane(shape::InitialCondition, particle_spacing; place_on_shell) if ndims(shape) == 2 # Extruding a 2D shape results in a 3D shape - # When `tlsph=true`, particles will be placed on the x-y plane + # When `place_on_shell=true`, particles will be placed on the x-y plane coords = vcat(shape.coordinates, - fill(tlsph ? 0 : particle_spacing / 2, size(shape.coordinates, 2))') + fill(place_on_shell ? 0 : particle_spacing / 2, + size(shape.coordinates, 2))') # TODO: 2D shapes not only in x-y plane but in any user-defined plane return coords, particle_spacing @@ -148,13 +154,13 @@ function sample_plane(shape::InitialCondition, particle_spacing; tlsph) return shape.coordinates, particle_spacing end -function sample_plane(plane_points, particle_spacing; tlsph=nothing) +function sample_plane(plane_points, particle_spacing; place_on_shell=nothing) # Convert to tuple - return sample_plane(tuple(plane_points...), particle_spacing; tlsph=nothing) + return sample_plane(tuple(plane_points...), particle_spacing; place_on_shell=nothing) end -function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{2}, particle_spacing; place_on_shell=nothing) # Verify that points are in 2D space if any(length.(plane_points) .!= 2) throw(ArgumentError("all points must be 2D coordinates")) @@ -168,7 +174,7 @@ function sample_plane(plane_points::NTuple{2}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) +function sample_plane(plane_points::NTuple{3}, particle_spacing; place_on_shell=nothing) # Verify that points are in 3D space if any(length.(plane_points) .!= 3) throw(ArgumentError("all points must be 3D coordinates")) @@ -209,21 +215,22 @@ function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing) return coords, particle_spacing_new end -# Shift corners of the plane/line inwards by half a particle spacing with `tlsph=false` +# Shift corners of the plane/line inwards by half a particle spacing with `place_on_shell=false` # because fluid particles need to be half a particle spacing away from the boundary of the shape. function shift_plane_corners(geometry::Union{AbstractMatrix, InitialCondition}, - direction, particle_spacing, tlsph) + direction, particle_spacing, place_on_shell) return geometry end -function shift_plane_corners(plane_points, direction, particle_spacing, tlsph) - shift_plane_corners(tuple(plane_points...), direction, particle_spacing, tlsph) +function shift_plane_corners(plane_points, direction, particle_spacing, place_on_shell) + shift_plane_corners(tuple(plane_points...), direction, particle_spacing, place_on_shell) end -function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) @@ -238,10 +245,11 @@ function shift_plane_corners(plane_points::NTuple{2}, direction, particle_spacin return (plane_point1, plane_point2) end -function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, tlsph) - # With TLSPH, particles need to be AT the min coordinates and not half a particle +function shift_plane_corners(plane_points::NTuple{3}, direction, particle_spacing, + place_on_shell) + # With `place_on_shell`, particles need to be AT the min coordinates and not half a particle # spacing away from it. - (tlsph) && (return plane_points) + (place_on_shell) && (return plane_points) plane_point1 = copy(plane_points[1]) plane_point2 = copy(plane_points[2]) diff --git a/src/setups/rectangular_shape.jl b/src/setups/rectangular_shape.jl index 98160bcac9..1c30ef5c1b 100644 --- a/src/setups/rectangular_shape.jl +++ b/src/setups/rectangular_shape.jl @@ -3,7 +3,7 @@ velocity=zeros(length(n_particles_per_dimension)), mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). @@ -40,9 +40,10 @@ Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref). - `state_equation`: When calculating a hydrostatic pressure gradient by setting `acceleration`, the `state_equation` will be used to set the corresponding density. Cannot be used together with `density`. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. - `coordinates_perturbation`: Add a small random displacement to the particle positions, where the amplitude is `coordinates_perturbation * particle_spacing`. @@ -75,7 +76,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord coordinates_perturbation=nothing, mass=nothing, density=nothing, pressure=0.0, acceleration=nothing, state_equation=nothing, - tlsph=false, loop_order=nothing) + place_on_shell=false, loop_order=nothing) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) end @@ -95,7 +96,7 @@ function RectangularShape(particle_spacing, n_particles_per_dimension, min_coord n_particles = prod(n_particles_per_dimension) coordinates = rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates, tlsph=tlsph, + min_coordinates, place_on_shell=place_on_shell, loop_order=loop_order) if !isnothing(coordinates_perturbation) @@ -190,15 +191,15 @@ function loop_permutation(loop_order, NDIMS::Val{3}) end function rectangular_shape_coords(particle_spacing, n_particles_per_dimension, - min_coordinates; tlsph=false, loop_order=nothing) + min_coordinates; place_on_shell=false, loop_order=nothing) ELTYPE = eltype(particle_spacing) NDIMS = length(n_particles_per_dimension) coordinates = Array{ELTYPE, 2}(undef, NDIMS, prod(n_particles_per_dimension)) - # With TLSPH, particles need to be AT the min coordinates and not half a particle + # With place_on_shell, particles need to be AT the min coordinates and not half a particle # spacing away from it. - if tlsph + if place_on_shell min_coordinates = min_coordinates .- 0.5particle_spacing end diff --git a/src/setups/sphere_shape.jl b/src/setups/sphere_shape.jl index 0233fc8995..3c6a7466d5 100644 --- a/src/setups/sphere_shape.jl +++ b/src/setups/sphere_shape.jl @@ -1,7 +1,7 @@ """ SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0.0) Generate a sphere that is either completely filled (by default) @@ -35,18 +35,19 @@ coordinate directions as `cutout_min` and `cutout_max`. cut out of the sphere. - `cutout_max`: Corner in positive coordinate directions of a cuboid that is to be cut out of the sphere. -- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed - on the boundary of the shape and not one particle radius away, as for fluids. - When `tlsph=true`, particles will be placed on the boundary of the shape. -- `velocity`: Either a function mapping each particle's coordinates to its velocity, - or, for a constant fluid velocity, a vector holding this velocity. - Velocity is constant zero by default. -- `mass`: Either `nothing` (default) to automatically compute particle mass from particle - density and spacing, or a function mapping each particle's coordinates to its mass, - or a scalar for a constant mass over all particles. -- `pressure`: Either a function mapping each particle's coordinates to its pressure, - or a scalar for a constant pressure over all particles. This is optional and - only needed when using the [`EntropicallyDampedSPHSystem`](@ref). +- `place_on_shell`: If `place_on_shell=true`, particles will be placed on the shell of the shape. + For example, the [`TotalLagrangianSPHSystem`](@ref) requires particles + to be placed on the shell of the shape and not half a particle spacing away, + as for fluids. +- `velocity`: Either a function mapping each particle's coordinates to its velocity, + or, for a constant fluid velocity, a vector holding this velocity. + Velocity is constant zero by default. +- `mass`: Either `nothing` (default) to automatically compute particle mass from particle + density and spacing, or a function mapping each particle's coordinates to its mass, + or a scalar for a constant mass over all particles. +- `pressure`: Either a function mapping each particle's coordinates to its pressure, + or a scalar for a constant pressure over all particles. This is optional and + only needed when using the [`EntropicallyDampedSPHSystem`](@ref). # Examples ```jldoctest; output = false @@ -89,7 +90,7 @@ SphereShape(0.1, 0.5, (0.2, 0.4, 0.3), 1000.0, sphere_type=RoundSphere()) """ function SphereShape(particle_spacing, radius, center_position, density; sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false, - cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), tlsph=false, + cutout_min=(0.0, 0.0), cutout_max=(0.0, 0.0), place_on_shell=false, velocity=zeros(length(center_position)), mass=nothing, pressure=0) if particle_spacing < eps() throw(ArgumentError("`particle_spacing` needs to be positive and larger than $(eps())")) @@ -99,7 +100,7 @@ function SphereShape(particle_spacing, radius, center_position, density; coordinates = sphere_shape_coords(sphere_type, particle_spacing, radius, SVector{NDIMS}(center_position), - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) # Convert tuples to vectors cutout_min_ = collect(cutout_min) @@ -169,13 +170,13 @@ struct RoundSphere{AR} end function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_position, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius outer_radius = radius + n_layers * particle_spacing - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of `radius` inner_radius += particle_spacing / 2 outer_radius += particle_spacing / 2 @@ -184,7 +185,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos inner_radius = radius - n_layers * particle_spacing outer_radius = radius - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` inner_radius -= particle_spacing / 2 outer_radius -= particle_spacing / 2 @@ -194,7 +195,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos outer_radius = radius inner_radius = -1 - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing inside of `radius` outer_radius -= particle_spacing / 2 end @@ -225,7 +226,7 @@ function sphere_shape_coords(::VoxelSphere, particle_spacing, radius, center_pos end function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, center, - n_layers, layer_outwards, tlsph) + n_layers, layer_outwards, place_on_shell) if n_layers > 0 if layer_outwards inner_radius = radius @@ -233,12 +234,12 @@ function sphere_shape_coords(sphere::RoundSphere, particle_spacing, radius, cent inner_radius = radius - n_layers * particle_spacing end - if !tlsph + if !place_on_shell # Put first layer of particles half a particle spacing outside of inner radius inner_radius += particle_spacing / 2 end else - if tlsph + if place_on_shell # Just create a sphere that is 0.5 particle spacing larger radius += particle_spacing / 2 end diff --git a/test/setups/extrude_geometry.jl b/test/setups/extrude_geometry.jl index e695f2e170..5a927dbee4 100644 --- a/test/setups/extrude_geometry.jl +++ b/test/setups/extrude_geometry.jl @@ -28,7 +28,8 @@ ] @testset "Direction $i" for i in eachindex(directions) - shape = extrude_geometry((point1, point2); direction=directions[i], tlsph=true, + shape = extrude_geometry((point1, point2); direction=directions[i], + place_on_shell=true, particle_spacing=0.15, n_extrude=5, density=1.0) @test shape.coordinates ≈ expected_coords[i] @@ -68,7 +69,7 @@ end @testset "Direction $i" for i in eachindex(directions) shape = extrude_geometry(geometry; direction=directions[i], particle_spacing, - n_extrude=5, tlsph=true, density=1.0) + n_extrude=5, place_on_shell=true, density=1.0) @test shape.coordinates ≈ expected_coords[i] end @@ -86,7 +87,7 @@ end 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.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.06666666666666667 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.13333333333333333 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.26666666666666666 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.3333333333333333 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.4666666666666667 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.5333333333333333 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.6666666666666666 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.7333333333333333 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.8666666666666667 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 0.9333333333333333 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.092709445701687 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.15937611236835367 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.22604277903502035 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.292709445701687 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.35937611236835365 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.4260427790350203 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.492709445701687 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.5593761123683537 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.6260427790350204 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.692709445701687 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.7593761123683537 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8260427790350203 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.8927094457016871 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 0.9593761123683537 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.0260427790350204 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 1.092709445701687 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.185418891403374 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.2520855580700407 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.31875222473670733 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.38541889140337404 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.4520855580700407 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.5187522247367073 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.585418891403374 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.6520855580700406 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.7187522247367073 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.785418891403374 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.8520855580700406 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.9187522247367073 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 0.985418891403374 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.0520855580700408 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.1187522247367074 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 1.185418891403374 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.278128337105061 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.34479500377172767 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.4114616704383943 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.47812833710506103 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.5447950037717277 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.6114616704383944 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.678128337105061 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.7447950037717277 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.8114616704383943 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.878128337105061 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 0.9447950037717276 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0114616704383943 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.0781283371050612 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.1447950037717276 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.2114616704383945 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061 1.278128337105061] shape = extrude_geometry((p1, p2, p3); direction, particle_spacing=0.1, n_extrude=4, - density=1000.0, tlsph=true) + density=1000.0, place_on_shell=true) @test shape.coordinates ≈ expected_coords end diff --git a/test/setups/rectangular_shape.jl b/test/setups/rectangular_shape.jl index f3e77043b0..7c2fd6875b 100644 --- a/test/setups/rectangular_shape.jl +++ b/test/setups/rectangular_shape.jl @@ -41,7 +41,8 @@ ] @testset "$(loop_orders[i])" for i in eachindex(loop_orders) - shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, tlsph=true, + shape = RectangularShape(1.0, (2, 2), (0.0, 0.0), density=1.0, + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] @@ -242,7 +243,7 @@ end @testset "$(loop_orders[i])" for i in eachindex(loop_orders) shape = RectangularShape(1.0, (2, 2, 2), (0.0, 0.0, 0.0), density=1.0, - tlsph=true, loop_order=loop_orders[i]) + place_on_shell=true, loop_order=loop_orders[i]) @test shape.coordinates == expected_coords[i] end diff --git a/test/setups/sphere_shape.jl b/test/setups/sphere_shape.jl index 57d904a376..c8b87d76db 100644 --- a/test/setups/sphere_shape.jl +++ b/test/setups/sphere_shape.jl @@ -106,14 +106,14 @@ SphereShape(1.0, 1.1, (0.2, -1.0, 0.3), 1000.0, sphere_type=RoundSphere()), SphereShape(1.0, 1.2, (-0.3, 0.1, 0.8), 1000.0, sphere_type=RoundSphere()), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, cutout_min=(0.18, 0.4, 0.5), - cutout_max=(0.42, 10.0, 1.0), tlsph=true), - SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, tlsph=true), + cutout_max=(0.42, 10.0, 1.0), place_on_shell=true), + SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, - layer_outwards=true, tlsph=true), + layer_outwards=true, place_on_shell=true), SphereShape(0.1, 0.5, (0.3, 0.4, 0.5), 1000.0, n_layers=2, sphere_type=RoundSphere()), SphereShape(0.1, 0.55, (0.3, 0.4, 0.5), 1000.0, n_layers=2, layer_outwards=true, - sphere_type=RoundSphere(), tlsph=true) + sphere_type=RoundSphere(), place_on_shell=true) ] expected_coords = [ diff --git a/test/systems/packing_system.jl b/test/systems/packing_system.jl index d55afd559a..b42e534275 100644 --- a/test/systems/packing_system.jl +++ b/test/systems/packing_system.jl @@ -19,7 +19,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -36,7 +36,7 @@ │ neighborhood search: ………………………… GridNeighborhoodSearch │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… yes │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", system) == show_box @@ -52,7 +52,7 @@ │ neighborhood search: ………………………… Nothing │ │ #particles: ………………………………………………… 307 │ │ smoothing kernel: ………………………………… SchoenbergQuinticSplineKernel │ - │ tlsph: ……………………………………………………………… no │ + │ place_on_shell: ……………………………………… no │ │ boundary: ……………………………………………………… no │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" end From 6de7ad312a4c7eb72670f543c87e89219867c375 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 26 Aug 2025 14:27:56 +0200 Subject: [PATCH 35/43] Combine PST and TVF into a unified framework (#884) * Combine PST and TVF into a unified framework * Require update callback for PST * Fix WCSPH * Update PST only in callback * Fix EDAC * Update docs * Fix alle example files * Fix tests * Fix periodic channel * Fix docs * Update news * Fix tests * Fix example file --- NEWS.md | 25 +- docs/src/systems/entropically_damped_sph.md | 61 ---- docs/src/systems/weakly_compressible_sph.md | 70 ++++- examples/fluid/lid_driven_cavity_2d.jl | 4 +- .../fluid/periodic_array_of_cylinders_2d.jl | 2 +- examples/fluid/periodic_channel_2d.jl | 3 +- examples/fluid/pipe_flow_2d.jl | 6 +- examples/fluid/taylor_green_vortex_2d.jl | 4 +- src/TrixiParticles.jl | 5 +- src/callbacks/callbacks.jl | 1 - src/callbacks/particle_shifting.jl | 148 --------- src/callbacks/update.jl | 42 ++- src/general/semidiscretization.jl | 2 +- src/general/system.jl | 3 - src/io/write_vtk.jl | 3 - .../fluid/entropically_damped_sph/rhs.jl | 13 +- .../fluid/entropically_damped_sph/system.jl | 28 +- src/schemes/fluid/fluid.jl | 2 +- src/schemes/fluid/shifting_techniques.jl | 291 ++++++++++++++++++ src/schemes/fluid/transport_velocity.jl | 158 ---------- .../fluid/weakly_compressible_sph/rhs.jl | 13 +- .../fluid/weakly_compressible_sph/system.jl | 25 +- test/examples/examples_fluid.jl | 19 +- test/systems/edac_system.jl | 8 +- test/systems/wcsph_system.jl | 4 +- 25 files changed, 479 insertions(+), 461 deletions(-) delete mode 100644 src/callbacks/particle_shifting.jl create mode 100644 src/schemes/fluid/shifting_techniques.jl delete mode 100644 src/schemes/fluid/transport_velocity.jl diff --git a/NEWS.md b/NEWS.md index f1940cbc46..d4e2ccdd7d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,14 +4,27 @@ TrixiParticles.jl follows the interpretation of [semantic versioning (semver)](https://julialang.github.io/Pkg.jl/dev/compatibility/#Version-specifier-format-1) used in the Julia ecosystem. Notable changes will be documented in this file for human readability. +## Version 0.4 + +### API Changes + +- Combined transport velocity formulation (TVF) and particle shifting technique (PST) into + one unified framework. + The keyword argument `transport_velocity` now changed to `shifting_technique`. + The `ParticleShiftingCallback` has been removed. To use PST, use the `UpdateCallback` + instead, and pass `shifting_technique=ParticleShiftingTechnique()` to the system. + +- Renamed the keyword argument `tlsph` to `place_on_shell` for `ParticlePackingSystem`, + `sample_boundary`, `extrude_geometry`, `RectangularShape`, and `SphereShape`. + ## Version 0.3.1 ### Features -- **Simplified SGS Viscosity Models**: Added ViscosityMorrisSGS and ViscosityAdamiSGS, +- **Simplified SGS Viscosity Models**: Added ViscosityMorrisSGS and ViscosityAdamiSGS, which implement a simplified Smagorinsky-type sub-grid-scale viscosity. (#753) -- **Multithreaded Integration Array**: Introduced a new array type for CPU backends +- **Multithreaded Integration Array**: Introduced a new array type for CPU backends that enables multithreaded broadcasting, delivering speed-ups of up to 5× on systems with many threads when combined with thread pinning. (#722) @@ -21,17 +34,17 @@ used in the Julia ecosystem. Notable changes will be documented in this file for - **DXF file format support**: Import complex geometries using the DXF file format. (#821) - **Improved Plane interpolation**: Massively improved interpolation performance for planes (#763). - + ### GPU - Make PST GPU-compatible (#813). - + - Make open boundaries GPU-compatible (#773). - + - Make interpolation GPU-compatible (#812). ### Important Bugfixes - + - Fix validation setups (#801). - Calculate interpolated density instead of computed density when using interpolation (#808). diff --git a/docs/src/systems/entropically_damped_sph.md b/docs/src/systems/entropically_damped_sph.md index 0db8d275e2..d035fb6fc1 100644 --- a/docs/src/systems/entropically_damped_sph.md +++ b/docs/src/systems/entropically_damped_sph.md @@ -45,64 +45,3 @@ is a good choice for a wide range of Reynolds numbers (0.0125 to 10000). Modules = [TrixiParticles] Pages = [joinpath("schemes", "fluid", "entropically_damped_sph", "system.jl")] ``` - -## [Transport Velocity Formulation (TVF)](@id transport_velocity_formulation) -Standard SPH suffers from problems like tensile instability or the creation of void regions in the flow. -To address these problems, [Adami (2013)](@cite Adami2013) modified the advection velocity and added an extra term to the momentum equation. -The authors introduced the so-called Transport Velocity Formulation (TVF) for WCSPH. [Ramachandran (2019)](@cite Ramachandran2019) applied the TVF -also for the [EDAC](@ref edac) scheme. - -The transport velocity ``\tilde{v}_a`` of particle ``a`` is used to evolve the position of the particle ``r_a`` from one time step to the next by - -```math -\frac{\mathrm{d} r_a}{\mathrm{d}t} = \tilde{v}_a -``` - -and is obtained at every time-step ``\Delta t`` from - -```math -\tilde{v}_a (t + \Delta t) = v_a (t) + \Delta t \left(\frac{\tilde{\mathrm{d}} v_a}{\mathrm{d}t} - \frac{1}{\rho_a} \nabla p_{\text{background}} \right), -``` - -where ``\rho_a`` is the density of particle ``a`` and ``p_{\text{background}}`` is a constant background pressure field. -The tilde in the second term of the right hand side indicates that the material derivative has an advection part. - -The discretized form of the last term is - -```math - -\frac{1}{\rho_a} \nabla p_{\text{background}} \approx -\frac{p_{\text{background}}}{m_a} \sum_b \left(V_a^2 + V_b^2 \right) \nabla_a W_{ab}, -``` - -where ``V_a``, ``V_b`` denote the volume of particles ``a`` and ``b`` respectively. -Note that although in the continuous case ``\nabla p_{\text{background}} = 0``, the discretization is not 0th-order consistent for **non**-uniform particle distribution, -which means that there is a non-vanishing contribution only when particles are disordered. -That also means that ``p_{\text{background}}`` occurs as prefactor to correct the trajectory of a particle resulting in uniform pressure distributions. -Suggested is a background pressure which is in the order of the reference pressure but can be chosen arbitrarily large when the time-step criterion is adjusted. - -The inviscid momentum equation with an additional convection term for a particle moving with ``\tilde{v}`` is - -```math -\frac{\tilde{\mathrm{d}} \left( \rho v \right)}{\mathrm{d}t} = -\nabla p + \nabla \cdot \bm{A}, -``` - - where the tensor ``\bm{A} = \rho v\left(\tilde{v}-v\right)^T`` is a consequence of the modified - advection velocity and can be interpreted as the convection of momentum with the relative velocity ``\tilde{v}-v``. - -The discretized form of the momentum equation for a particle ``a`` reads as - -```math -\frac{\tilde{\mathrm{d}} v_a}{\mathrm{d}t} = \frac{1}{m_a} \sum_b \left(V_a^2 + V_b^2 \right) \left[ -\tilde{p}_{ab} \nabla_a W_{ab} + \frac{1}{2} \left(\bm{A}_a + \bm{A}_b \right) \cdot \nabla_a W_{ab} \right]. -``` - -Here, ``\tilde{p}_{ab}`` is the density-weighted pressure - -```math -\tilde{p}_{ab} = \frac{\rho_b p_a + \rho_a p_b}{\rho_a + \rho_b}, -``` - -with the density ``\rho_a``, ``\rho_b`` and the pressure ``p_a``, ``p_b`` of particles ``a`` and ``b`` respectively. ``\bm{A}_a`` and ``\bm{A}_b`` are the convection tensors for particle ``a`` and ``b`` respectively and are given, e.g. for particle ``a``, as ``\bm{A}_a = \rho v_a\left(\tilde{v}_a-v_a\right)^T``. - -```@autodocs -Modules = [TrixiParticles] -Pages = [joinpath("schemes", "fluid", "transport_velocity.jl")] -``` diff --git a/docs/src/systems/weakly_compressible_sph.md b/docs/src/systems/weakly_compressible_sph.md index 51355961f6..62a1bc8d0c 100644 --- a/docs/src/systems/weakly_compressible_sph.md +++ b/docs/src/systems/weakly_compressible_sph.md @@ -152,8 +152,74 @@ as explained in [Sun2018](@cite Sun2018) on page 29, right above Equation 9. The ``\delta``-SPH method (WCSPH with density diffusion) together with this formulation of PST is commonly referred to as ``\delta^+``-SPH. -The Particle Shifting Technique can be applied in form -of the [`ParticleShiftingCallback`](@ref). +To apply particle shifting, use the keyword argument `shifting_technique` in the constructor +of a system that supports it. + + +## [Transport Velocity Formulation (TVF)](@id transport_velocity_formulation) + +An alternative formulation is the so-called Transport Velocity Formulation (TVF) +by [Adami (2013)](@cite Adami2013). +[Ramachandran (2019)](@cite Ramachandran2019) applied the TVF also for the [EDAC](@ref edac) +scheme. + +The transport velocity ``\tilde{v}_a`` of particle ``a`` is used to evolve the position +of the particle ``r_a`` from one time step to the next by +```math +\frac{\mathrm{d} r_a}{\mathrm{d}t} = \tilde{v}_a +``` +and is obtained at every time step ``\Delta t`` from +```math +\tilde{v}_a (t + \Delta t) = v_a (t) + \Delta t \left(\frac{\tilde{\mathrm{d}} v_a}{\mathrm{d}t} - \frac{1}{\rho_a} \nabla p_{\text{background}} \right), +``` +where ``\rho_a`` is the density of particle ``a`` and ``p_{\text{background}}`` +is a constant background pressure field. +The tilde in the second term of the right-hand side indicates that the material derivative +has an advection part. + +The discretized form of the last term is +```math + -\frac{1}{\rho_a} \nabla p_{\text{background}} \approx -\frac{p_{\text{background}}}{m_a} \sum_b \left(V_a^2 + V_b^2 \right) \nabla_a W_{ab}, +``` +where ``V_a``, ``V_b`` denote the volume of particles ``a`` and ``b`` respectively. +Note that although in the continuous case ``\nabla p_{\text{background}} = 0``, +the discretization is not 0th-order consistent for **non**-uniform particle distribution, +which means that there is a non-vanishing contribution only when particles are disordered. +That also means that ``p_{\text{background}}`` occurs as pre-factor to correct +the trajectory of a particle resulting in uniform pressure distributions. +Suggested is a background pressure which is in the order of the reference pressure, +but it can be chosen arbitrarily large when the time-step criterion is adjusted. + +The inviscid momentum equation with an additional convection term for a particle +moving with ``\tilde{v}`` is +```math +\frac{\tilde{\mathrm{d}} \left( \rho v \right)}{\mathrm{d}t} = -\nabla p + \nabla \cdot \bm{A}, +``` +where the tensor ``\bm{A} = \rho v\left(\tilde{v}-v\right)^T`` is a consequence +of the modified advection velocity and can be interpreted as the convection of momentum +with the relative velocity ``\tilde{v}-v``. + +The discretized form of the momentum equation for a particle ``a`` reads as +```math +\frac{\tilde{\mathrm{d}} v_a}{\mathrm{d}t} = \frac{1}{m_a} \sum_b \left(V_a^2 + V_b^2 \right) \left[ -\tilde{p}_{ab} \nabla_a W_{ab} + \frac{1}{2} \left(\bm{A}_a + \bm{A}_b \right) \cdot \nabla_a W_{ab} \right]. +``` +Here, ``\tilde{p}_{ab}`` is the density-weighted pressure +```math +\tilde{p}_{ab} = \frac{\rho_b p_a + \rho_a p_b}{\rho_a + \rho_b}, +``` +with the density ``\rho_a``, ``\rho_b`` and the pressure ``p_a``, ``p_b`` of particles ``a`` +and ``b``, respectively. ``\bm{A}_a`` and ``\bm{A}_b`` are the convection tensors +for particle ``a`` and ``b``, respectively, and are given, e.g., for particle ``a``, +as ``\bm{A}_a = \rho v_a\left(\tilde{v}_a-v_a\right)^T``. + +To apply the TVF, use the keyword argument `shifting_technique` in the constructor +of a system that supports it. + +```@autodocs +Modules = [TrixiParticles] +Pages = [joinpath("schemes", "fluid", "shifting_techniques.jl")] +``` + ## [Tensile Instability Control](@id tic) diff --git a/examples/fluid/lid_driven_cavity_2d.jl b/examples/fluid/lid_driven_cavity_2d.jl index b6582a1701..1b8b15cda4 100644 --- a/examples/fluid/lid_driven_cavity_2d.jl +++ b/examples/fluid/lid_driven_cavity_2d.jl @@ -65,7 +65,7 @@ if wcsph state_equation, smoothing_kernel, pressure_acceleration=TrixiParticles.inter_particle_averaged_pressure, smoothing_length, viscosity=viscosity, - transport_velocity=TransportVelocityAdami(pressure)) + shifting_technique=TransportVelocityAdami(pressure)) else state_equation = nothing density_calculator = ContinuityDensity() @@ -73,7 +73,7 @@ else smoothing_length, density_calculator=density_calculator, sound_speed, viscosity=viscosity, - transport_velocity=TransportVelocityAdami(pressure)) + shifting_technique=TransportVelocityAdami(pressure)) end # ========================================================================================== diff --git a/examples/fluid/periodic_array_of_cylinders_2d.jl b/examples/fluid/periodic_array_of_cylinders_2d.jl index 850c9f2ff9..648a98be11 100644 --- a/examples/fluid/periodic_array_of_cylinders_2d.jl +++ b/examples/fluid/periodic_array_of_cylinders_2d.jl @@ -60,7 +60,7 @@ smoothing_length = 1.2 * particle_spacing smoothing_kernel = SchoenbergQuarticSplineKernel{2}() fluid_system = EntropicallyDampedSPHSystem(fluid, smoothing_kernel, smoothing_length, sound_speed, viscosity=ViscosityAdami(; nu), - transport_velocity=TransportVelocityAdami(pressure), + shifting_technique=TransportVelocityAdami(pressure), acceleration=(acceleration_x, 0.0)) # ========================================================================================== diff --git a/examples/fluid/periodic_channel_2d.jl b/examples/fluid/periodic_channel_2d.jl index 74770c318b..9cd4bd95a5 100644 --- a/examples/fluid/periodic_channel_2d.jl +++ b/examples/fluid/periodic_channel_2d.jl @@ -28,7 +28,7 @@ initial_fluid_size = tank_size initial_velocity = (1.0, 0.0) fluid_density = 1000.0 -sound_speed = initial_velocity[1] +sound_speed = 10 * initial_velocity[1] state_equation = StateEquationCole(; sound_speed, reference_density=fluid_density, exponent=7) @@ -48,6 +48,7 @@ viscosity = ArtificialViscosityMonaghan(alpha=0.02, beta=0.0) fluid_system = WeaklyCompressibleSPHSystem(tank.fluid, fluid_density_calculator, state_equation, smoothing_kernel, smoothing_length, viscosity=viscosity, + shifting_technique=nothing, pressure_acceleration=nothing) # ========================================================================================== diff --git a/examples/fluid/pipe_flow_2d.jl b/examples/fluid/pipe_flow_2d.jl index 3544ac7a8d..85e3461ccc 100644 --- a/examples/fluid/pipe_flow_2d.jl +++ b/examples/fluid/pipe_flow_2d.jl @@ -74,6 +74,7 @@ viscosity = ViscosityAdami(nu=kinematic_viscosity) fluid_system = EntropicallyDampedSPHSystem(pipe.fluid, smoothing_kernel, smoothing_length, sound_speed, viscosity=viscosity, density_calculator=fluid_density_calculator, + shifting_technique=ParticleShiftingTechnique(), buffer_size=n_buffer_particles) # Alternatively the WCSPH scheme can be used @@ -86,6 +87,7 @@ if wcsph fluid_system = WeaklyCompressibleSPHSystem(pipe.fluid, fluid_density_calculator, state_equation, smoothing_kernel, smoothing_length, viscosity=viscosity, + shifting_technique=ParticleShiftingTechnique(), buffer_size=n_buffer_particles) end @@ -159,12 +161,10 @@ ode = semidiscretize(semi, tspan) info_callback = InfoCallback(interval=100) saving_callback = SolutionSavingCallback(dt=0.02, prefix="") -particle_shifting = ParticleShiftingCallback() extra_callback = nothing -callbacks = CallbackSet(info_callback, saving_callback, UpdateCallback(), - particle_shifting, extra_callback) +callbacks = CallbackSet(info_callback, saving_callback, UpdateCallback(), extra_callback) sol = solve(ode, RDPK3SpFSAL35(), abstol=1e-5, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration) diff --git a/examples/fluid/taylor_green_vortex_2d.jl b/examples/fluid/taylor_green_vortex_2d.jl index e6e74fbc4b..8a99c455c6 100644 --- a/examples/fluid/taylor_green_vortex_2d.jl +++ b/examples/fluid/taylor_green_vortex_2d.jl @@ -86,13 +86,13 @@ if wcsph pressure_acceleration=TrixiParticles.inter_particle_averaged_pressure, smoothing_length, viscosity=ViscosityAdami(; nu), - transport_velocity=TransportVelocityAdami(background_pressure)) + shifting_technique=TransportVelocityAdami(background_pressure)) else density_calculator = SummationDensity() fluid_system = EntropicallyDampedSPHSystem(fluid, smoothing_kernel, smoothing_length, sound_speed, density_calculator=density_calculator, - transport_velocity=TransportVelocityAdami(background_pressure), + shifting_technique=TransportVelocityAdami(background_pressure), viscosity=ViscosityAdami(; nu)) end diff --git a/src/TrixiParticles.jl b/src/TrixiParticles.jl index 987e208750..2a53025d46 100644 --- a/src/TrixiParticles.jl +++ b/src/TrixiParticles.jl @@ -65,10 +65,9 @@ export WeaklyCompressibleSPHSystem, EntropicallyDampedSPHSystem, TotalLagrangian BoundarySPHSystem, DEMSystem, BoundaryDEMSystem, OpenBoundarySPHSystem export BoundaryZone, InFlow, OutFlow, BidirectionalFlow export InfoCallback, SolutionSavingCallback, DensityReinitializationCallback, - PostprocessCallback, StepsizeCallback, UpdateCallback, SteadyStateReachedCallback, - ParticleShiftingCallback + PostprocessCallback, StepsizeCallback, UpdateCallback, SteadyStateReachedCallback export ContinuityDensity, SummationDensity -export PenaltyForceGanzenmueller, TransportVelocityAdami +export PenaltyForceGanzenmueller, TransportVelocityAdami, ParticleShiftingTechnique export SchoenbergCubicSplineKernel, SchoenbergQuarticSplineKernel, SchoenbergQuinticSplineKernel, GaussianKernel, WendlandC2Kernel, WendlandC4Kernel, WendlandC6Kernel, SpikyKernel, Poly6Kernel diff --git a/src/callbacks/callbacks.jl b/src/callbacks/callbacks.jl index 062a16e3a9..e9eb048c3f 100644 --- a/src/callbacks/callbacks.jl +++ b/src/callbacks/callbacks.jl @@ -32,4 +32,3 @@ include("post_process.jl") include("stepsize.jl") include("update.jl") include("steady_state_reached.jl") -include("particle_shifting.jl") diff --git a/src/callbacks/particle_shifting.jl b/src/callbacks/particle_shifting.jl deleted file mode 100644 index 921370f3b1..0000000000 --- a/src/callbacks/particle_shifting.jl +++ /dev/null @@ -1,148 +0,0 @@ -@doc raw""" - ParticleShiftingCallback() - -Callback to apply the Particle Shifting Technique by [Sun et al. (2017)](@cite Sun2017). -Following the original paper, the callback is applied in every time step and not -in every stage of a multi-stage time integration method to reduce the computational -cost and improve the stability of the scheme. - -See [Callbacks](@ref Callbacks) for more information on how to use this callback. -See [Particle Shifting Technique](@ref shifting) for more information on the method itself. - -!!! warning - The Particle Shifting Technique needs to be disabled close to the free surface - and therefore requires a free surface detection method. This is not yet implemented. - **This callback cannot be used in a free surface simulation.** -""" -function ParticleShiftingCallback() - # The first one is the `condition`, the second the `affect!` - return DiscreteCallback((particle_shifting_condition), particle_shifting!, - save_positions=(false, false)) -end - -# `condition` -function particle_shifting_condition(u, t, integrator) - return true -end - -# `affect!` -function particle_shifting!(integrator) - t = integrator.t - semi = integrator.p - v_ode, u_ode = integrator.u.x - dt = integrator.dt - # Internal cache vector, which is safe to use as temporary array - vu_cache = first(get_tmp_cache(integrator)) - - @trixi_timeit timer() "particle shifting callback" begin - # Update quantities that are stored in the systems. These quantities (e.g. pressure) - # still have the values from the last stage of the previous step if not updated here. - @trixi_timeit timer() "update systems and nhs" begin - # Don't create sub-timers here to avoid cluttering the timer output - @notimeit timer() update_systems_and_nhs(v_ode, u_ode, semi, t) - end - - @trixi_timeit timer() "particle shifting" foreach_system(semi) do system - u = wrap_u(u_ode, system, semi) - v = wrap_v(v_ode, system, semi) - particle_shifting!(u, v, system, v_ode, u_ode, semi, vu_cache, dt) - end - end - - # Tell OrdinaryDiffEq that `u` has been modified - u_modified!(integrator, true) - - return integrator -end - -function particle_shifting!(u, v, system, v_ode, u_ode, semi, u_cache, dt) - return u -end - -function particle_shifting!(u, v, system::FluidSystem, v_ode, u_ode, semi, - vu_cache, dt) - # Wrap the cache vector to an NDIMS x NPARTICLES matrix. - # We need this buffer because we cannot safely update `u` while iterating over it. - _, u_cache = vu_cache.x - delta_r = wrap_u(u_cache, system, semi) - set_zero!(delta_r) - - # This has similar performance to `maximum(..., eachparticle(system))`, - # but is GPU-compatible. - v_max = maximum(x -> sqrt(dot(x, x)), - reinterpret(reshape, SVector{ndims(system), eltype(v)}, - current_velocity(v, system))) - - # TODO this needs to be adapted to multi-resolution. - # Section 3.2 explains what else needs to be changed. - dx = particle_spacing(system, 1) - Wdx = smoothing_kernel(system, dx, 1) - h = smoothing_length(system, 1) - - foreach_system(semi) do neighbor_system - u_neighbor = wrap_u(u_ode, neighbor_system, semi) - v_neighbor = wrap_v(v_ode, neighbor_system, semi) - - system_coords = current_coordinates(u, system) - neighbor_coords = current_coordinates(u_neighbor, neighbor_system) - - foreach_point_neighbor(system, neighbor_system, system_coords, neighbor_coords, - semi; - points=each_moving_particle(system)) do particle, neighbor, - pos_diff, distance - m_b = hydrodynamic_mass(neighbor_system, neighbor) - rho_a = current_density(v, system, particle) - rho_b = current_density(v_neighbor, neighbor_system, neighbor) - - kernel = smoothing_kernel(system, distance, particle) - grad_kernel = smoothing_kernel_grad(system, pos_diff, distance, particle) - - # According to p. 29 below Eq. 9 - R = 2 // 10 - n = 4 - - # Eq. 7 in Sun et al. (2017). - # According to the paper, CFL * Ma can be rewritten as Δt * v_max / h - # (see p. 29, right above Eq. 9), but this does not work when scaling h. - # When setting CFL * Ma = Δt * v_max / (2 * Δx), PST works as expected - # for both small and large smoothing length factors. - # We need to scale - # - quadratically with the smoothing length, - # - linearly with the particle spacing, - # - linearly with the time step. - # See https://github.com/trixi-framework/TrixiParticles.jl/pull/834. - delta_r_ = -dt * v_max * (2 * h)^2 / (2 * dx) * (1 + R * (kernel / Wdx)^n) * - m_b / (rho_a + rho_b) * grad_kernel - - # Write into the buffer - for i in eachindex(delta_r_) - @inbounds delta_r[i, particle] += delta_r_[i] - end - end - end - - # Add δ_r from the buffer to the current coordinates - @threaded semi for particle in eachparticle(system) - for i in axes(delta_r, 1) - @inbounds u[i, particle] += delta_r[i, particle] - end - end - - return u -end - -function Base.show(io::IO, cb::DiscreteCallback{<:Any, typeof(particle_shifting!)}) - @nospecialize cb # reduce precompilation time - print(io, "ParticleShiftingCallback()") -end - -function Base.show(io::IO, ::MIME"text/plain", - cb::DiscreteCallback{<:Any, typeof(particle_shifting!)}) - @nospecialize cb # reduce precompilation time - - if get(io, :compact, false) - show(io, cb) - else - summary_box(io, "ParticleShiftingCallback") - end -end diff --git a/src/callbacks/update.jl b/src/callbacks/update.jl index 77496a46c5..8eecb8380a 100644 --- a/src/callbacks/update.jl +++ b/src/callbacks/update.jl @@ -74,22 +74,32 @@ function (update_callback!::UpdateCallback)(integrator) semi = integrator.p v_ode, u_ode = integrator.u.x - # Update quantities that are stored in the systems. These quantities (e.g. pressure) - # still have the values from the last stage of the previous step if not updated here. - update_systems_and_nhs(v_ode, u_ode, semi, t) - - # Update open boundaries first, since particles might be activated or deactivated - @trixi_timeit timer() "update open boundary" foreach_system(semi) do system - update_open_boundary_eachstep!(system, v_ode, u_ode, semi, t) - end - - @trixi_timeit timer() "update particle packing" foreach_system(semi) do system - update_particle_packing(system, v_ode, u_ode, semi, integrator) - end - - # This is only used by the particle packing system and should be removed in the future - @trixi_timeit timer() "update TVF" foreach_system(semi) do system - update_transport_velocity!(system, v_ode, semi) + @trixi_timeit timer() "update callback" begin + # Update quantities that are stored in the systems. These quantities (e.g. pressure) + # still have the values from the last stage of the previous step if not updated here. + @trixi_timeit timer() "update systems and nhs" begin + # Don't create sub-timers here to avoid cluttering the timer output + @notimeit timer() update_systems_and_nhs(v_ode, u_ode, semi, t) + end + + # Update open boundaries first, since particles might be activated or deactivated + @trixi_timeit timer() "update open boundary" foreach_system(semi) do system + update_open_boundary_eachstep!(system, v_ode, u_ode, semi, t) + end + + @trixi_timeit timer() "update particle packing" foreach_system(semi) do system + update_particle_packing(system, v_ode, u_ode, semi, integrator) + end + + # This is only used by the particle packing system and should be removed in the future + @trixi_timeit timer() "update TVF" foreach_system(semi) do system + update_transport_velocity!(system, v_ode, semi) + end + + @trixi_timeit timer() "particle shifting" foreach_system(semi) do system + particle_shifting_from_callback!(u_ode, shifting_technique(system), system, + v_ode, semi, integrator.dt) + end end # Tell OrdinaryDiffEq that `u` has been modified diff --git a/src/general/semidiscretization.jl b/src/general/semidiscretization.jl index a9c78b3349..9532d812ab 100644 --- a/src/general/semidiscretization.jl +++ b/src/general/semidiscretization.jl @@ -485,7 +485,7 @@ end @inline add_velocity!(du, v, particle, system::BoundarySPHSystem) = du @inline function add_velocity!(du, v, particle, system::FluidSystem) - # This is zero unless a transport velocity is used + # This is zero unless a shifting technique is used delta_v_ = delta_v(system, particle) for i in 1:ndims(system) diff --git a/src/general/system.jl b/src/general/system.jl index 929fb8b425..5b4d5aecb8 100644 --- a/src/general/system.jl +++ b/src/general/system.jl @@ -147,9 +147,6 @@ function update_final!(system, v, u, v_ode, u_ode, semi, t) return system end -# Only for systems requiring the use of the `UpdateCallback` -@inline requires_update_callback(system) = false - @inline initial_smoothing_length(system) = smoothing_length(system, nothing) @inline function smoothing_length(system, particle) diff --git a/src/io/write_vtk.jl b/src/io/write_vtk.jl index b93e25f324..1aca732098 100644 --- a/src/io/write_vtk.jl +++ b/src/io/write_vtk.jl @@ -349,9 +349,6 @@ function write2vtk!(vtk, v, u, t, system::FluidSystem; write_meta_data=true) else vtk["solver"] = "EDAC" vtk["sound_speed"] = system.sound_speed - vtk["background_pressure_TVF"] = system.transport_velocity isa Nothing ? - "-" : - system.transport_velocity.background_pressure end end diff --git a/src/schemes/fluid/entropically_damped_sph/rhs.jl b/src/schemes/fluid/entropically_damped_sph/rhs.jl index 08139e2ca6..a4d7d280a4 100644 --- a/src/schemes/fluid/entropically_damped_sph/rhs.jl +++ b/src/schemes/fluid/entropically_damped_sph/rhs.jl @@ -51,13 +51,12 @@ function interact!(dv, v_particle_system, u_particle_system, particle, neighbor, pos_diff, distance, sound_speed, m_a, m_b, rho_a, rho_b, grad_kernel) - # Add convection term (only when using `TransportVelocityAdami`) - dv_tvf = dv_transport_velocity(transport_velocity(particle_system), - particle_system, neighbor_system, - particle, neighbor, - v_particle_system, v_neighbor_system, - m_a, m_b, rho_a, rho_b, pos_diff, distance, - grad_kernel, correction) + # Extra terms in the momentum equation when using a shifting technique + dv_tvf = dv_shifting(shifting_technique(particle_system), + particle_system, neighbor_system, particle, neighbor, + v_particle_system, v_neighbor_system, + m_a, m_b, rho_a, rho_b, pos_diff, distance, + grad_kernel, correction) dv_surface_tension = surface_tension_force(surface_tension_a, surface_tension_b, particle_system, neighbor_system, diff --git a/src/schemes/fluid/entropically_damped_sph/system.jl b/src/schemes/fluid/entropically_damped_sph/system.jl index 19e50c441a..89d8a923ff 100644 --- a/src/schemes/fluid/entropically_damped_sph/system.jl +++ b/src/schemes/fluid/entropically_damped_sph/system.jl @@ -3,7 +3,7 @@ smoothing_length, sound_speed; pressure_acceleration=inter_particle_averaged_pressure, density_calculator=SummationDensity(), - transport_velocity=nothing, + shifting_technique=nothing, alpha=0.5, viscosity=nothing, acceleration=ntuple(_ -> 0.0, NDIMS), surface_tension=nothing, surface_normal_method=nothing, buffer_size=nothing, @@ -30,10 +30,11 @@ See [Entropically Damped Artificial Compressibility for SPH](@ref edac) for more When set to `nothing`, the pressure acceleration formulation for the corresponding [density calculator](@ref density_calculator) is chosen. - `density_calculator`: [Density calculator](@ref density_calculator) (default: [`SummationDensity`](@ref)) -- `transport_velocity`: [Transport Velocity Formulation (TVF)](@ref transport_velocity_formulation). - Default is no TVF. +- `shifting_technique`: [Shifting technique](@ref shifting) or [transport velocity + formulation](@ref transport_velocity_formulation) to use + with this system. Default is no shifting. - `average_pressure_reduction`: Whether to subtract the average pressure of neighboring particles - from the local pressure (default: `true` when using TVF, `false` otherwise). + from the local pressure (default: `true` when using shifting, `false` otherwise). - `buffer_size`: Number of buffer particles. This is needed when simulating with [`OpenBoundarySPHSystem`](@ref). - `correction`: Correction method used for this system. (default: no correction, see [Corrections](@ref corrections)) @@ -67,7 +68,7 @@ struct EntropicallyDampedSPHSystem{NDIMS, ELTYPE <: Real, IC, M, DC, K, V, COR, acceleration :: SVector{NDIMS, ELTYPE} correction :: COR pressure_acceleration_formulation :: PF - transport_velocity :: TV + shifting_technique :: TV average_pressure_reduction :: AVGP source_terms :: ST surface_tension :: SRFT @@ -83,8 +84,8 @@ function EntropicallyDampedSPHSystem(initial_condition, smoothing_kernel, smoothing_length, sound_speed; pressure_acceleration=inter_particle_averaged_pressure, density_calculator=SummationDensity(), - transport_velocity=nothing, - average_pressure_reduction=(!isnothing(transport_velocity)), + shifting_technique=nothing, + average_pressure_reduction=(!isnothing(shifting_technique)), alpha=0.5, viscosity=nothing, acceleration=ntuple(_ -> 0.0, ndims(smoothing_kernel)), @@ -137,7 +138,7 @@ function EntropicallyDampedSPHSystem(initial_condition, smoothing_kernel, nu_edac = (alpha * smoothing_length * sound_speed) / 8 cache = (; create_cache_density(initial_condition, density_calculator)..., - create_cache_tvf(initial_condition, transport_velocity)..., + create_cache_shifting(initial_condition, shifting_technique)..., create_cache_avg_pressure_reduction(initial_condition, avg_pressure_reduction)..., create_cache_surface_normal(surface_normal_method, ELTYPE, NDIMS, @@ -161,14 +162,14 @@ function EntropicallyDampedSPHSystem(initial_condition, smoothing_kernel, EntropicallyDampedSPHSystem{NDIMS, ELTYPE, typeof(initial_condition), typeof(mass), typeof(density_calculator), typeof(smoothing_kernel), typeof(viscosity), typeof(correction), - typeof(pressure_acceleration), typeof(transport_velocity), + typeof(pressure_acceleration), typeof(shifting_technique), typeof(avg_pressure_reduction), typeof(source_terms), typeof(surface_tension), typeof(surface_normal_method), typeof(buffer), Nothing, typeof(cache)}(initial_condition, mass, density_calculator, smoothing_kernel, sound_speed, viscosity, nu_edac, acceleration_, correction, - pressure_acceleration, transport_velocity, + pressure_acceleration, shifting_technique, avg_pressure_reduction, source_terms, surface_tension, surface_normal_method, buffer, @@ -218,8 +219,7 @@ function Base.show(io::IO, ::MIME"text/plain", system::EntropicallyDampedSPHSyst summary_line(io, "viscosity", system.viscosity |> typeof |> nameof) summary_line(io, "ν₍EDAC₎", "≈ $(round(system.nu_edac; digits=3))") summary_line(io, "smoothing kernel", system.smoothing_kernel |> typeof |> nameof) - summary_line(io, "tansport velocity formulation", - system.transport_velocity |> typeof |> nameof) + summary_line(io, "shifting technique", system.shifting_technique) summary_line(io, "average pressure reduction", typeof(system.average_pressure_reduction).parameters[1] ? "yes" : "no") summary_line(io, "acceleration", system.acceleration) @@ -271,7 +271,7 @@ end @inline system_sound_speed(system::EntropicallyDampedSPHSystem) = system.sound_speed -@inline transport_velocity(system::EntropicallyDampedSPHSystem) = system.transport_velocity +@inline shifting_technique(system::EntropicallyDampedSPHSystem) = system.shifting_technique @inline function average_pressure(system::EntropicallyDampedSPHSystem, particle) average_pressure(system, system.average_pressure_reduction, particle) @@ -321,7 +321,7 @@ function update_final!(system::EntropicallyDampedSPHSystem, v, u, v_ode, u_ode, compute_curvature!(system, surface_tension, v, u, v_ode, u_ode, semi, t) compute_stress_tensors!(system, surface_tension, v, u, v_ode, u_ode, semi, t) update_average_pressure!(system, system.average_pressure_reduction, v_ode, u_ode, semi) - update_tvf!(system, transport_velocity(system), v, u, v_ode, u_ode, semi, t) + update_shifting!(system, shifting_technique(system), v, u, v_ode, u_ode, semi) end # No average pressure reduction is used diff --git a/src/schemes/fluid/fluid.jl b/src/schemes/fluid/fluid.jl index d3e6adf971..59703f9b6d 100644 --- a/src/schemes/fluid/fluid.jl +++ b/src/schemes/fluid/fluid.jl @@ -193,7 +193,7 @@ end include("pressure_acceleration.jl") include("viscosity.jl") -include("transport_velocity.jl") +include("shifting_techniques.jl") include("surface_tension.jl") include("surface_normal_sph.jl") include("weakly_compressible_sph/weakly_compressible_sph.jl") diff --git a/src/schemes/fluid/shifting_techniques.jl b/src/schemes/fluid/shifting_techniques.jl new file mode 100644 index 0000000000..98775b3be0 --- /dev/null +++ b/src/schemes/fluid/shifting_techniques.jl @@ -0,0 +1,291 @@ +abstract type AbstractShiftingTechnique end + +# No shifting for a system by default +@inline shifting_technique(system) = nothing + +# WARNING: Be careful if defining this function for a specific system type. +# The version for a specific system type will override this generic version. +requires_update_callback(system) = requires_update_callback(shifting_technique(system)) +requires_update_callback(::Nothing) = false +requires_update_callback(::AbstractShiftingTechnique) = true + +# This is called from the `UpdateCallback` +particle_shifting_from_callback!(u_ode, shifting, system, v_ode, semi, dt) = u_ode + +create_cache_shifting(initial_condition, ::Nothing) = (;) + +function create_cache_shifting(initial_condition, ::AbstractShiftingTechnique) + delta_v = zeros(eltype(initial_condition), ndims(initial_condition), + nparticles(initial_condition)) + + return (; delta_v) +end + +# `δv` is the correction to the particle velocity due to the shifting. +# Particles are advected with the velocity `v + δv`. +@propagate_inbounds function delta_v(system, particle) + return delta_v(system, shifting_technique(system), particle) +end + +# Zero when no shifting is used +@inline function delta_v(system, shifting, particle) + return zero(SVector{ndims(system), eltype(system)}) +end + +@propagate_inbounds function delta_v(system, ::AbstractShiftingTechnique, particle) + return extract_svector(system.cache.delta_v, system, particle) +end + +function update_shifting!(system, shifting, v, u, v_ode, u_ode, semi) + return system +end + +# Additional term in the momentum equation due to the shifting technique +@inline function dv_shifting(shifting, system, neighbor_system, + particle, neighbor, v_system, v_neighbor_system, + m_a, m_b, rho_a, rho_b, pos_diff, distance, + grad_kernel, correction) + return zero(grad_kernel) +end + +@doc raw""" + ParticleShiftingTechnique() + +Particle Shifting Technique by [Sun et al. (2017)](@cite Sun2017). +Following the original paper, the callback is applied in every time step and not +in every stage of a multi-stage time integration method to reduce the computational +cost and improve the stability of the scheme. + +See [Particle Shifting Technique](@ref shifting) for more information on the method. + +!!! warning + The Particle Shifting Technique needs to be disabled close to the free surface + and therefore requires a free surface detection method. This is not yet implemented. + **This technique cannot be used in a free surface simulation.** +""" +struct ParticleShiftingTechnique <: AbstractShiftingTechnique end + +# Zero because PST is applied in a callback +@inline function delta_v(system, ::ParticleShiftingTechnique, particle) + return zero(SVector{ndims(system), eltype(system)}) +end + +function particle_shifting_from_callback!(u_ode, shifting::ParticleShiftingTechnique, + system, v_ode, semi, dt) + @trixi_timeit timer() "particle shifting" begin + v = wrap_v(v_ode, system, semi) + u = wrap_u(u_ode, system, semi) + + # Update the shifting velocity + update_shifting_from_callback!(system, shifting, v, u, v_ode, u_ode, semi) + + # Update the particle positions with the shifting velocity + particle_shifting!(u_ode, shifting, system, semi, dt) + end +end + +function update_shifting_from_callback!(system, ::ParticleShiftingTechnique, + v, u, v_ode, u_ode, semi) + (; cache) = system + (; delta_v) = cache + + set_zero!(delta_v) + + # This has similar performance to `maximum(..., eachparticle(system))`, + # but is GPU-compatible. + v_max = maximum(x -> sqrt(dot(x, x)), + reinterpret(reshape, SVector{ndims(system), eltype(v)}, + current_velocity(v, system))) + + # TODO this needs to be adapted to multi-resolution. + # Section 3.2 explains what else needs to be changed. + dx = particle_spacing(system, 1) + Wdx = smoothing_kernel(system, dx, 1) + h = smoothing_length(system, 1) + + foreach_system(semi) do neighbor_system + u_neighbor = wrap_u(u_ode, neighbor_system, semi) + v_neighbor = wrap_v(v_ode, neighbor_system, semi) + + system_coords = current_coordinates(u, system) + neighbor_coords = current_coordinates(u_neighbor, neighbor_system) + + foreach_point_neighbor(system, neighbor_system, system_coords, neighbor_coords, + semi; + points=each_moving_particle(system)) do particle, neighbor, + pos_diff, distance + m_b = hydrodynamic_mass(neighbor_system, neighbor) + rho_a = current_density(v, system, particle) + rho_b = current_density(v_neighbor, neighbor_system, neighbor) + + kernel = smoothing_kernel(system, distance, particle) + grad_kernel = smoothing_kernel_grad(system, pos_diff, distance, particle) + + # According to p. 29 below Eq. 9 + R = 2 // 10 + n = 4 + + # Eq. 7 in Sun et al. (2017). + # According to the paper, CFL * Ma can be rewritten as Δt * v_max / h + # (see p. 29, right above Eq. 9), but this does not work when scaling h. + # When setting CFL * Ma = Δt * v_max / (2 * Δx), PST works as expected + # for both small and large smoothing length factors. + # We need to scale + # - quadratically with the smoothing length, + # - linearly with the particle spacing, + # - linearly with the time step. + # See https://github.com/trixi-framework/TrixiParticles.jl/pull/834. + delta_v_ = -v_max * (2 * h)^2 / (2 * dx) * (1 + R * (kernel / Wdx)^n) * + m_b / (rho_a + rho_b) * grad_kernel + + # Write into the buffer + for i in eachindex(delta_v_) + @inbounds delta_v[i, particle] += delta_v_[i] + end + end + end + + return system +end + +function particle_shifting!(u_ode, ::ParticleShiftingTechnique, system, semi, dt) + (; cache) = system + (; delta_v) = cache + + u = wrap_u(u_ode, system, semi) + + # Add δr from the cache to the current coordinates + @threaded semi for particle in eachparticle(system) + for i in axes(delta_v, 1) + @inbounds u[i, particle] += dt * delta_v[i, particle] + end + end + + return u +end + +""" + TransportVelocityAdami(background_pressure::Real) + +Transport Velocity Formulation (TVF) by [Adami et al. (2013)](@cite Adami2013) +to suppress pairing and tensile instability. +See [TVF](@ref transport_velocity_formulation) for more details of the method. + +# Arguments +- `background_pressure`: Background pressure. Suggested is a background pressure which is + on the order of the reference pressure. + +!!! warning + The Transport Velocity Formulation needs to be disabled close to the free surface + and therefore requires a free surface detection method. This is not yet implemented. + **This technique cannot be used in a free surface simulation.** +""" +struct TransportVelocityAdami{T <: Real} <: AbstractShiftingTechnique + background_pressure::T +end + +@inline function dv_shifting(::TransportVelocityAdami, system, neighbor_system, + particle, neighbor, v_system, v_neighbor_system, + m_a, m_b, rho_a, rho_b, pos_diff, distance, + grad_kernel, correction) + v_a = current_velocity(v_system, system, particle) + delta_v_a = delta_v(system, particle) + + v_b = current_velocity(v_neighbor_system, neighbor_system, neighbor) + delta_v_b = delta_v(neighbor_system, neighbor) + + A_a = rho_a * v_a * delta_v_a' + A_b = rho_b * v_b * delta_v_b' + + # The following term depends on the pressure acceleration formulation. + # See the large comment below. In the original paper (Adami et al., 2013), this is + # (V_a^2 + V_b^2) / m_a * ((A_a + A_b) / 2) * ∇W_ab. + # With the most common pressure acceleration formulation, this is + # m_b * (A_a + A_b) / (ρ_a * ρ_b) * ∇W_ab. + # In order to obtain this, we pass `p_a = A_a` and `p_b = A_b` to the + # `pressure_acceleration` function. + return pressure_acceleration(system, neighbor_system, particle, neighbor, + m_a, m_b, A_a, A_b, rho_a, rho_b, pos_diff, + distance, grad_kernel, correction) +end + +function update_shifting!(system, shifting::TransportVelocityAdami, v, u, v_ode, + u_ode, semi) + (; cache, correction) = system + (; delta_v) = cache + (; background_pressure) = shifting + + sound_speed = system_sound_speed(system) + + set_zero!(delta_v) + + foreach_system(semi) do neighbor_system + v_neighbor = wrap_v(v_ode, neighbor_system, semi) + u_neighbor = wrap_u(u_ode, neighbor_system, semi) + + system_coords = current_coordinates(u, system) + neighbor_coords = current_coordinates(u_neighbor, neighbor_system) + + foreach_point_neighbor(system, neighbor_system, system_coords, neighbor_coords, + semi; + points=each_moving_particle(system)) do particle, neighbor, + pos_diff, distance + m_a = @inbounds hydrodynamic_mass(system, particle) + m_b = @inbounds hydrodynamic_mass(neighbor_system, neighbor) + + rho_a = @inbounds current_density(v, system, particle) + rho_b = @inbounds current_density(v_neighbor, neighbor_system, neighbor) + + h = smoothing_length(system, particle) + + grad_kernel = smoothing_kernel_grad(system, pos_diff, distance, particle) + + # In the original paper (Adami et al., 2013), the transport velocity is applied + # as follows: + # v_{1/2} = v_0 + Δt/2 * a, + # where a is the regular SPH acceleration term (pressure, viscosity, etc.). + # r_1 = r_0 + Δt * (v_{1/2}, + # where ̃v_{1/2} = v_{1/2} + Δt/2 * p_0 / m_a * \sum_b[ (V_a^2 + V_b^2) * ∇W_ab ] + # is the transport velocity. + # We call δv_{1/2} = ̃v_{1/2} - v_{1/2} the shifting velocity. + # We will call δv_{1/2} the shifting velocity, which is given by + # δv = -Δt/2 * p_0 / m_a * \sum_b[ (V_a^2 + V_b^2) * ∇W_ab ], + # where p_0 is the background pressure, V_a = m_a / ρ_a, V_b = m_b / ρ_b. + # This term depends on the pressure acceleration formulation. + # In Zhang et al. (2017), the pressure acceleration term + # m_b * (p_a / ρ_a^2 + p_b / ρ_b^2) * ∇W_ab + # is used. They consequently changed the shifting velocity to + # δv = -Δt/2 * p_0 * \sum_b[ m_b * (1 / ρ_a^2 + 1 / ρ_b^2) * ∇W_ab ]. + # We therefore use the function `pressure_acceleration` to compute the + # shifting velocity according to the used pressure acceleration formulation. + # In most cases, this will be + # δv = -Δt/2 * p_0 * \sum_b[ m_b * (1 + 1) / (ρ_a * ρ_b) * ∇W_ab ]. + # + # In these papers, the shifting velocity is scaled by the time step Δt. + # We generally want the spatial discretization to be independent of the time step. + # Scaling the shifting velocity by the time step would lead to less shifting + # when very small time steps are used for testing/debugging purposes. + # This is especially problematic in TrixiParticles.jl, as the time step can vary + # significantly between different time integration methods (low vs high order). + # In order to eliminate the time step from the shifting velocity, we apply the + # CFL condition used in Adami et al. (2013): + # Δt <= 0.25 * h / c, + # where h is the smoothing length and c is the sound speed. + # Applying this equation as equality yields the shifting velocity + # δv = -p_0 / 8 * h / c * \sum_b[ m_b * (1 + 1) / (ρ_a * ρ_b) * ∇W_ab ]. + # The last part is achieved by passing `p_a = 1` and `p_b = 1` to the + # `pressure_acceleration` function. + delta_v_ = background_pressure / 8 * h / sound_speed * + pressure_acceleration(system, neighbor_system, particle, neighbor, + m_a, m_b, 1, 1, rho_a, rho_b, pos_diff, + distance, grad_kernel, correction) + + # Write into the buffer + for i in eachindex(delta_v_) + @inbounds delta_v[i, particle] += delta_v_[i] + end + end + end + + return system +end diff --git a/src/schemes/fluid/transport_velocity.jl b/src/schemes/fluid/transport_velocity.jl deleted file mode 100644 index fce7375dd5..0000000000 --- a/src/schemes/fluid/transport_velocity.jl +++ /dev/null @@ -1,158 +0,0 @@ -""" - TransportVelocityAdami(background_pressure::Real) - -Transport Velocity Formulation (TVF) by [Adami et al. (2013)](@cite Adami2013) -to suppress pairing and tensile instability. -See [TVF](@ref transport_velocity_formulation) for more details of the method. - -# Arguments -- `background_pressure`: Background pressure. Suggested is a background pressure which is - on the order of the reference pressure. -""" -struct TransportVelocityAdami{T <: Real} - background_pressure::T -end - -# No TVF for a system by default -@inline transport_velocity(system) = nothing - -create_cache_tvf(initial_condition, ::Nothing) = (;) - -function create_cache_tvf(initial_condition, ::TransportVelocityAdami) - delta_v = zeros(eltype(initial_condition), ndims(initial_condition), - nparticles(initial_condition)) - - return (; delta_v) -end - -# `δv` is the correction to the particle velocity due to the TVF. -# Particles are advected with the velocity `v + δv`. -@propagate_inbounds function delta_v(system, particle) - return delta_v(system, transport_velocity(system), particle) -end - -@propagate_inbounds function delta_v(system, ::TransportVelocityAdami, particle) - return extract_svector(system.cache.delta_v, system, particle) -end - -# Zero when no TVF is used -@inline function delta_v(system, transport_velocity, particle) - return zero(SVector{ndims(system), eltype(system)}) -end - -@inline function dv_transport_velocity(::Nothing, system, neighbor_system, - particle, neighbor, v_system, v_neighbor_system, - m_a, m_b, rho_a, rho_b, pos_diff, distance, - grad_kernel, correction) - return zero(grad_kernel) -end - -@inline function dv_transport_velocity(::TransportVelocityAdami, system, neighbor_system, - particle, neighbor, v_system, v_neighbor_system, - m_a, m_b, rho_a, rho_b, pos_diff, distance, - grad_kernel, correction) - v_a = current_velocity(v_system, system, particle) - delta_v_a = delta_v(system, particle) - - v_b = current_velocity(v_neighbor_system, neighbor_system, neighbor) - delta_v_b = delta_v(neighbor_system, neighbor) - - A_a = rho_a * v_a * delta_v_a' - A_b = rho_b * v_b * delta_v_b' - - # The following term depends on the pressure acceleration formulation. - # See the large comment below. In the original paper (Adami et al., 2013), this is - # (V_a^2 + V_b^2) / m_a * ((A_a + A_b) / 2) * ∇W_ab. - # With the most common pressure acceleration formulation, this is - # m_b * (A_a + A_b) / (ρ_a * ρ_b) * ∇W_ab. - # In order to obtain this, we pass `p_a = A_a` and `p_b = A_b` to the - # `pressure_acceleration` function. - return pressure_acceleration(system, neighbor_system, particle, neighbor, - m_a, m_b, A_a, A_b, rho_a, rho_b, pos_diff, - distance, grad_kernel, correction) -end - -function update_tvf!(system, transport_velocity, v, u, v_ode, u_ode, semi, t) - return system -end - -function update_tvf!(system, transport_velocity::TransportVelocityAdami, v, u, v_ode, - u_ode, semi, t) - (; cache, correction) = system - (; delta_v) = cache - (; background_pressure) = transport_velocity - - sound_speed = system_sound_speed(system) - - set_zero!(delta_v) - - foreach_system(semi) do neighbor_system - v_neighbor = wrap_v(v_ode, neighbor_system, semi) - u_neighbor = wrap_u(u_ode, neighbor_system, semi) - - system_coords = current_coordinates(u, system) - neighbor_coords = current_coordinates(u_neighbor, neighbor_system) - - foreach_point_neighbor(system, neighbor_system, system_coords, neighbor_coords, - semi; - points=each_moving_particle(system)) do particle, neighbor, - pos_diff, distance - m_a = @inbounds hydrodynamic_mass(system, particle) - m_b = @inbounds hydrodynamic_mass(neighbor_system, neighbor) - - rho_a = @inbounds current_density(v, system, particle) - rho_b = @inbounds current_density(v_neighbor, neighbor_system, neighbor) - - h = smoothing_length(system, particle) - - grad_kernel = smoothing_kernel_grad(system, pos_diff, distance, particle) - - # In the original paper (Adami et al., 2013), the transport velocity is applied - # as follows: - # v_{1/2} = v_0 + Δt/2 * a, - # where a is the regular SPH acceleration term (pressure, viscosity, etc.). - # r_1 = r_0 + Δt * (v_{1/2}, - # where ̃v_{1/2} = v_{1/2} + Δt/2 * p_0 / m_a * \sum_b[ (V_a^2 + V_b^2) * ∇W_ab ] - # is the transport velocity. - # We call δv_{1/2} = ̃v_{1/2} - v_{1/2} the shifting velocity. - # We will call δv_{1/2} the shifting velocity, which is given by - # δv = -Δt/2 * p_0 / m_a * \sum_b[ (V_a^2 + V_b^2) * ∇W_ab ], - # where p_0 is the background pressure, V_a = m_a / ρ_a, V_b = m_b / ρ_b. - # This term depends on the pressure acceleration formulation. - # In Zhang et al. (2017), the pressure acceleration term - # m_b * (p_a / ρ_a^2 + p_b / ρ_b^2) * ∇W_ab - # is used. They consequently changed the shifting velocity to - # δv = -Δt/2 * p_0 * \sum_b[ m_b * (1 / ρ_a^2 + 1 / ρ_b^2) * ∇W_ab ]. - # We therefore use the function `pressure_acceleration` to compute the - # shifting velocity according to the used pressure acceleration formulation. - # In most cases, this will be - # δv = -Δt/2 * p_0 * \sum_b[ m_b * (1 + 1) / (ρ_a * ρ_b) * ∇W_ab ]. - # - # In these papers, the shifting velocity is scaled by the time step Δt. - # We generally want the spatial discretization to be independent of the time step. - # Scaling the shifting velocity by the time step would lead to less shifting - # when very small time steps are used for testing/debugging purposes. - # This is especially problematic in TrixiParticles.jl, as the time step can vary - # significantly between different time integration methods (low vs high order). - # In order to eliminate the time step from the shifting velocity, we apply the - # CFL condition used in Adami et al. (2013): - # Δt <= 0.25 * h / c, - # where h is the smoothing length and c is the sound speed. - # Applying this equation as equality yields the shifting velocity - # δv = -p_0 / 8 * h / c * \sum_b[ m_b * (1 + 1) / (ρ_a * ρ_b) * ∇W_ab ]. - # The last part is achieved by passing `p_a = 1` and `p_b = 1` to the - # `pressure_acceleration` function. - delta_v_ = background_pressure / 8 * h / sound_speed * - pressure_acceleration(system, neighbor_system, particle, neighbor, - m_a, m_b, 1, 1, rho_a, rho_b, pos_diff, - distance, grad_kernel, correction) - - # Write into the buffer - for i in eachindex(delta_v_) - @inbounds delta_v[i, particle] += delta_v_[i] - end - end - end - - return system -end diff --git a/src/schemes/fluid/weakly_compressible_sph/rhs.jl b/src/schemes/fluid/weakly_compressible_sph/rhs.jl index af088e0a1b..b9cd27f079 100644 --- a/src/schemes/fluid/weakly_compressible_sph/rhs.jl +++ b/src/schemes/fluid/weakly_compressible_sph/rhs.jl @@ -70,13 +70,12 @@ function interact!(dv, v_particle_system, u_particle_system, sound_speed, m_a, m_b, rho_a, rho_b, grad_kernel) - # Add convection term (only when using `TransportVelocityAdami`) - dv_tvf = dv_transport_velocity(transport_velocity(particle_system), - particle_system, neighbor_system, - particle, neighbor, - v_particle_system, v_neighbor_system, - m_a, m_b, rho_a, rho_b, pos_diff, distance, - grad_kernel, correction) + # Extra terms in the momentum equation when using a shifting technique + dv_tvf = dv_shifting(shifting_technique(particle_system), + particle_system, neighbor_system, particle, neighbor, + v_particle_system, v_neighbor_system, + m_a, m_b, rho_a, rho_b, pos_diff, distance, + grad_kernel, correction) dv_surface_tension = surface_tension_correction * surface_tension_force(surface_tension_a, surface_tension_b, diff --git a/src/schemes/fluid/weakly_compressible_sph/system.jl b/src/schemes/fluid/weakly_compressible_sph/system.jl index a5f56499b8..dda2ead5f1 100644 --- a/src/schemes/fluid/weakly_compressible_sph/system.jl +++ b/src/schemes/fluid/weakly_compressible_sph/system.jl @@ -5,7 +5,7 @@ acceleration=ntuple(_ -> 0.0, NDIMS), viscosity=nothing, density_diffusion=nothing, pressure_acceleration=nothing, - transport_velocity=nothing, + shifting_technique=nothing, buffer_size=nothing, correction=nothing, source_terms=nothing, surface_tension=nothing, surface_normal_method=nothing, @@ -36,8 +36,9 @@ See [Weakly Compressible SPH](@ref wcsph) for more details on the method. density calculator and the correction method. To use [Tensile Instability Control](@ref tic), pass [`tensile_instability_control`](@ref) here. -- `transport_velocity`: [Transport Velocity Formulation (TVF)](@ref transport_velocity_formulation). - Default is no TVF. +- `shifting_technique`: [Shifting technique](@ref shifting) or [transport velocity + formulation](@ref transport_velocity_formulation) to use + with this system. Default is no shifting. - `buffer_size`: Number of buffer particles. This is needed when simulating with [`OpenBoundarySPHSystem`](@ref). - `correction`: Correction method used for this system. (default: no correction, see [Corrections](@ref corrections)) @@ -59,7 +60,7 @@ See [Weakly Compressible SPH](@ref wcsph) for more details on the method. - `color_value`: The value used to initialize the color of particles in the system. """ struct WeaklyCompressibleSPHSystem{NDIMS, ELTYPE <: Real, IC, MA, P, DC, SE, K, V, DD, COR, - PF, TV, ST, B, SRFT, SRFN, PR, C} <: FluidSystem{NDIMS} + PF, SC, ST, B, SRFT, SRFN, PR, C} <: FluidSystem{NDIMS} initial_condition :: IC mass :: MA # Array{ELTYPE, 1} pressure :: P # Array{ELTYPE, 1} @@ -71,7 +72,7 @@ struct WeaklyCompressibleSPHSystem{NDIMS, ELTYPE <: Real, IC, MA, P, DC, SE, K, density_diffusion :: DD correction :: COR pressure_acceleration_formulation :: PF - transport_velocity :: TV + shifting_technique :: SC source_terms :: ST surface_tension :: SRFT surface_normal_method :: SRFN @@ -89,7 +90,7 @@ function WeaklyCompressibleSPHSystem(initial_condition, ndims(smoothing_kernel)), viscosity=nothing, density_diffusion=nothing, pressure_acceleration=nothing, - transport_velocity=nothing, + shifting_technique=nothing, buffer_size=nothing, correction=nothing, source_terms=nothing, surface_tension=nothing, surface_normal_method=nothing, @@ -147,7 +148,7 @@ function WeaklyCompressibleSPHSystem(initial_condition, n_particles)..., create_cache_refinement(initial_condition, particle_refinement, smoothing_length)..., - create_cache_tvf(initial_condition, transport_velocity)..., + create_cache_shifting(initial_condition, shifting_technique)..., color=Int(color_value)) # If the `reference_density_spacing` is set calculate the `ideal_neighbor_count` @@ -162,7 +163,7 @@ function WeaklyCompressibleSPHSystem(initial_condition, density_calculator, state_equation, smoothing_kernel, acceleration_, viscosity, density_diffusion, correction, pressure_acceleration, - transport_velocity, source_terms, surface_tension, + shifting_technique, source_terms, surface_tension, surface_normal_method, buffer, particle_refinement, cache) end @@ -177,6 +178,7 @@ function Base.show(io::IO, system::WeaklyCompressibleSPHSystem) print(io, ", ", system.smoothing_kernel) print(io, ", ", system.viscosity) print(io, ", ", system.density_diffusion) + print(io, ", ", system.shifting_technique) print(io, ", ", system.surface_tension) print(io, ", ", system.surface_normal_method) if system.surface_normal_method isa ColorfieldSurfaceNormal @@ -207,9 +209,8 @@ function Base.show(io::IO, ::MIME"text/plain", system::WeaklyCompressibleSPHSyst summary_line(io, "state equation", system.state_equation |> typeof |> nameof) summary_line(io, "smoothing kernel", system.smoothing_kernel |> typeof |> nameof) summary_line(io, "viscosity", system.viscosity) - summary_line(io, "tansport velocity formulation", - system.transport_velocity |> typeof |> nameof) summary_line(io, "density diffusion", system.density_diffusion) + summary_line(io, "shifting technique", system.shifting_technique) summary_line(io, "surface tension", system.surface_tension) summary_line(io, "surface normal method", system.surface_normal_method) if system.surface_normal_method isa ColorfieldSurfaceNormal @@ -278,7 +279,7 @@ end @inline system_sound_speed(system::WeaklyCompressibleSPHSystem) = system.state_equation.sound_speed -@inline transport_velocity(system::WeaklyCompressibleSPHSystem) = system.transport_velocity +@inline shifting_technique(system::WeaklyCompressibleSPHSystem) = system.shifting_technique function update_quantities!(system::WeaklyCompressibleSPHSystem, v, u, v_ode, u_ode, semi, t) @@ -316,7 +317,7 @@ function update_final!(system::WeaklyCompressibleSPHSystem, v, u, v_ode, u_ode, # Surface normal of neighbor and boundary needs to have been calculated already compute_curvature!(system, surface_tension, v, u, v_ode, u_ode, semi, t) compute_stress_tensors!(system, surface_tension, v, u, v_ode, u_ode, semi, t) - update_tvf!(system, transport_velocity(system), v, u, v_ode, u_ode, semi, t) + update_shifting!(system, shifting_technique(system), v, u, v_ode, u_ode, semi) end function kernel_correct_density!(system::WeaklyCompressibleSPHSystem, v, u, v_ode, u_ode, diff --git a/test/examples/examples_fluid.jl b/test/examples/examples_fluid.jl index ede9e6bbf9..a84a69317d 100644 --- a/test/examples/examples_fluid.jl +++ b/test/examples/examples_fluid.jl @@ -273,7 +273,19 @@ joinpath(examples_dir(), "fluid", "periodic_channel_2d.jl"), tspan=(0.0, 0.2), - extra_callback=ParticleShiftingCallback()) + shifting_technique=ParticleShiftingTechnique(), + extra_callback=UpdateCallback()) + @test sol.retcode == ReturnCode.Success + @test count_rhs_allocations(sol, semi) == 0 + end + + @trixi_testset "fluid/periodic_channel_2d.jl with TVF" begin + @trixi_test_nowarn trixi_include(@__MODULE__, + joinpath(examples_dir(), "fluid", + "periodic_channel_2d.jl"), + tspan=(0.0, 0.2), + shifting_technique=TransportVelocityAdami(50_000.0), + extra_callback=UpdateCallback()) @test sol.retcode == ReturnCode.Success @test count_rhs_allocations(sol, semi) == 0 end @@ -283,8 +295,9 @@ joinpath(examples_dir(), "fluid", "periodic_channel_2d.jl"), tspan=(0.0, 0.2), - extra_callback=ParticleShiftingCallback(), - pressure_acceleration=tensile_instability_control) + shifting_technique=ParticleShiftingTechnique(), + pressure_acceleration=tensile_instability_control, + extra_callback=UpdateCallback()) @test sol.retcode == ReturnCode.Success @test count_rhs_allocations(sol, semi) == 0 end diff --git a/test/systems/edac_system.jl b/test/systems/edac_system.jl index 3d8cf9babb..ed37b9ea55 100644 --- a/test/systems/edac_system.jl +++ b/test/systems/edac_system.jl @@ -32,7 +32,7 @@ @test system.mass == mass @test system.smoothing_kernel == smoothing_kernel @test TrixiParticles.initial_smoothing_length(system) == smoothing_length - @test system.transport_velocity isa Nothing + @test system.shifting_technique isa Nothing @test system.viscosity === nothing @test system.nu_edac == (0.5 * smoothing_length * sound_speed) / 8 @test system.acceleration == [0.0 for _ in 1:NDIMS] @@ -87,7 +87,7 @@ @test system.mass == setup.mass @test system.smoothing_kernel == smoothing_kernel @test TrixiParticles.initial_smoothing_length(system) == smoothing_length - @test system.transport_velocity isa Nothing + @test system.shifting_technique isa Nothing @test system.viscosity === nothing @test system.nu_edac == (0.5 * smoothing_length * sound_speed) / 8 @test system.acceleration == [0.0 for _ in 1:NDIMS] @@ -140,7 +140,7 @@ │ viscosity: …………………………………………………… Nothing │ │ ν₍EDAC₎: ………………………………………………………… ≈ 0.226 │ │ smoothing kernel: ………………………………… Val │ - │ tansport velocity formulation: Nothing │ + │ shifting technique: …………………………… nothing │ │ average pressure reduction: ……… no │ │ acceleration: …………………………………………… [0.0, 0.0] │ │ surface tension: …………………………………… nothing │ @@ -225,7 +225,7 @@ names = ["No TVF", "TransportVelocityAdami"] @testset "$(names[i])" for i in eachindex(transport_velocity) system = EntropicallyDampedSPHSystem(fluid, smoothing_kernel, - transport_velocity=transport_velocity[i], + shifting_technique=transport_velocity[i], average_pressure_reduction=true, smoothing_length, 0.0) semi = Semidiscretization(system) diff --git a/test/systems/wcsph_system.jl b/test/systems/wcsph_system.jl index cf6020d068..99f7152db6 100644 --- a/test/systems/wcsph_system.jl +++ b/test/systems/wcsph_system.jl @@ -199,7 +199,7 @@ smoothing_length, density_diffusion=density_diffusion) - show_compact = "WeaklyCompressibleSPHSystem{2}(SummationDensity(), nothing, Val{:state_equation}(), Val{:smoothing_kernel}(), nothing, Val{:density_diffusion}(), nothing, nothing, [0.0, 0.0], nothing) with 2 particles" + show_compact = "WeaklyCompressibleSPHSystem{2}(SummationDensity(), nothing, Val{:state_equation}(), Val{:smoothing_kernel}(), nothing, Val{:density_diffusion}(), nothing, nothing, nothing, [0.0, 0.0], nothing) with 2 particles" @test repr(system) == show_compact show_box = """ ┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ @@ -211,8 +211,8 @@ │ state equation: ……………………………………… Val │ │ smoothing kernel: ………………………………… Val │ │ viscosity: …………………………………………………… nothing │ - │ tansport velocity formulation: Nothing │ │ density diffusion: ……………………………… Val{:density_diffusion}() │ + │ shifting technique: …………………………… nothing │ │ surface tension: …………………………………… nothing │ │ surface normal method: …………………… nothing │ │ acceleration: …………………………………………… [0.0, 0.0] │ From d05cd4ea3f40d0d256236e523b1b19450ca8f55b Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Wed, 27 Aug 2025 09:54:39 +0200 Subject: [PATCH 36/43] improve structure and fixing problems --- examples/n_body/n_body_system.jl | 4 ++++ src/io/io.jl | 13 ++++++------- src/preprocessing/particle_packing/system.jl | 4 ---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/n_body/n_body_system.jl b/examples/n_body/n_body_system.jl index 3d2e02eefe..b877059a41 100644 --- a/examples/n_body/n_body_system.jl +++ b/examples/n_body/n_body_system.jl @@ -114,6 +114,10 @@ function TrixiParticles.write2vtk!(vtk, v, u, t, system::NBodySystem) return vtk end +function TrixiParticles.add_system_data!(system_data, system::NBodySystem) + return system_data +end + function Base.show(io::IO, system::NBodySystem) print(io, "NBodySystem{", ndims(system), "}() with ") print(io, TrixiParticles.nparticles(system), " particles") diff --git a/src/io/io.jl b/src/io/io.jl index 962a3bb300..db437fa62e 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -2,7 +2,6 @@ include("write_vtk.jl") include("read_vtk.jl") # handle "_" on optional prefix/filename strings -add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") add_opt_str_post(str) = (str === "" ? "" : "_$(str)") function write_meta_data(callback::SolutionSavingCallback, integrator) @@ -38,7 +37,7 @@ function create_meta_data_dict(callback, integrator) systems = Dict{String, Any}() foreach_system(semi) do system idx = system_indices(system, semi) - name = add_opt_str_pre(prefix) * "$(names[idx])" + name = prefix * add_opt_str_post("$(names[idx])") system_data = Dict{String, Any}() add_system_data!(system_data, system) @@ -88,7 +87,7 @@ function add_system_data!(system_data, system::FluidSystem) system_data["acceleration"] = system.acceleration system_data["sound_speed"] = system_sound_speed(system) system_data["pressure_acceleration_formulation"] = nameof(system.pressure_acceleration_formulation) - add_system_data!(system_data, system.transport_velocity) + add_system_data!(system_data, system.shifting_technique) add_system_data!(system_data, system.surface_tension) add_system_data!(system_data, system.surface_normal_method) add_system_data!(system_data, system.viscosity) @@ -300,8 +299,8 @@ function add_system_data!(system_data, penalty_force::PenaltyForceGanzenmueller) system_data["penalty_force"]["alpha"] = penalty_force.alpha end -function add_system_data!(system_data, transport_velocity::TransportVelocityAdami) - system_data["transport_velocity"] = Dict{String, Any}() - system_data["transport_velocity"]["model"] = type2string(transport_velocity) - system_data["transport_velocity"]["background_pressure"] = transport_velocity.background_pressure +function add_system_data!(system_data, shifting_technique::AbstractShiftingTechnique) + system_data["shifting_technique"] = Dict{String, Any}() + system_data["shifting_technique"]["model"] = type2string(shifting_technique) + system_data["shifting_technique"]["background_pressure"] = shifting_technique.background_pressure end diff --git a/src/preprocessing/particle_packing/system.jl b/src/preprocessing/particle_packing/system.jl index d5bdc60f35..cd194ef336 100644 --- a/src/preprocessing/particle_packing/system.jl +++ b/src/preprocessing/particle_packing/system.jl @@ -222,10 +222,6 @@ function write2vtk!(vtk, v, u, t, system::ParticlePackingSystem) vtk["signed_distances"] = system.signed_distances end -function add_meta_data!(meta_data, system::ParticlePackingSystem) - return meta_data -end - # Skip for fixed systems write_u0!(u0, system::ParticlePackingSystem{<:Any, true}) = u0 From 9b37b4f4fb358a41e52d9f8ee3adae04a7446934 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 1 Sep 2025 11:01:22 +0200 Subject: [PATCH 37/43] add `shifting_technique` to `io.jl` --- src/io/io.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/io/io.jl b/src/io/io.jl index db437fa62e..4ec292d980 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -299,8 +299,13 @@ function add_system_data!(system_data, penalty_force::PenaltyForceGanzenmueller) system_data["penalty_force"]["alpha"] = penalty_force.alpha end -function add_system_data!(system_data, shifting_technique::AbstractShiftingTechnique) +function add_system_data!(system_data, shifting_technique::TransportVelocityAdami) system_data["shifting_technique"] = Dict{String, Any}() system_data["shifting_technique"]["model"] = type2string(shifting_technique) system_data["shifting_technique"]["background_pressure"] = shifting_technique.background_pressure end + +function add_system_data!(system_data, shifting_technique::ParticleShiftingTechnique) + system_data["shifting_technique"] = Dict{String, Any}() + system_data["shifting_technique"]["model"] = type2string(shifting_technique) +end From 64fd6742495f4aca032124a40b40220cab4ac216 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Fri, 5 Sep 2025 13:22:34 +0200 Subject: [PATCH 38/43] change filename of the JSON-File --- src/callbacks/solution_saving.jl | 20 +++++++------------- src/io/io.jl | 6 ++---- test/callbacks/solution_saving.jl | 3 --- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/callbacks/solution_saving.jl b/src/callbacks/solution_saving.jl index 274f1472b8..0d017249c0 100644 --- a/src/callbacks/solution_saving.jl +++ b/src/callbacks/solution_saving.jl @@ -1,7 +1,7 @@ @doc raw""" SolutionSavingCallback(; interval::Integer=0, dt=0.0, save_times=Array{Float64, 1}([]), save_initial_solution=true, save_final_solution=true, - output_directory="out", append_timestamp=false, prefix="", filename="", + output_directory="out", append_timestamp=false, prefix="", verbose=false, max_coordinates=2^15, custom_quantities...) @@ -26,7 +26,6 @@ To ignore a custom quantity for a specific system, return `nothing`. - `output_directory="out"`: Directory to save the VTK files. - `append_timestamp=false`: Append current timestamp to the output directory. - `prefix=""`: Prefix added to the filename. -- `filename=""`: The filename of the Metadata file to be saved. - `custom_quantities...`: Additional user-defined quantities. - `verbose=false`: Print to standard IO when a file is written. - `max_coordinates=2^15`: The coordinates of particles will be clipped if their @@ -61,7 +60,6 @@ saving_callback = SolutionSavingCallback(dt=0.1, my_custom_quantity=kinetic_ener │ save final solution: ………………………… yes │ │ output directory: ………………………………… *path ignored with filter regex above* │ │ prefix: …………………………………………………………… │ -│ filename: ……………………………………………………… │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘ ``` """ @@ -73,7 +71,6 @@ mutable struct SolutionSavingCallback{I, CQ} verbose :: Bool output_directory :: String prefix :: String - filename :: String max_coordinates :: Float64 custom_quantities :: CQ latest_saved_iter :: Int @@ -84,7 +81,7 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0, save_times=Float64[], save_initial_solution=true, save_final_solution=true, output_directory="out", append_timestamp=false, - prefix="", filename="", verbose=false, + prefix="", verbose=false, max_coordinates=Float64(2^15), custom_quantities...) if (dt > 0 && interval > 0) || (length(save_times) > 0 && (dt > 0 || interval > 0)) @@ -102,7 +99,7 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0, solution_callback = SolutionSavingCallback(interval, Float64.(save_times), save_initial_solution, save_final_solution, - verbose, output_directory, prefix, filename, + verbose, output_directory, prefix, max_coordinates, custom_quantities, -1, Ref("UnknownVersion")) @@ -155,7 +152,7 @@ end # `affect!` function (solution_callback::SolutionSavingCallback)(integrator) (; interval, output_directory, custom_quantities, git_hash, verbose, - prefix, filename, latest_saved_iter, max_coordinates) = solution_callback + prefix, latest_saved_iter, max_coordinates) = solution_callback dvdu_ode = get_du(integrator) vu_ode = integrator.u @@ -261,8 +258,7 @@ function Base.show(io::IO, ::MIME"text/plain", "save final solution" => solution_saving.save_final_solution ? "yes" : "no", "output directory" => abspath(solution_saving.output_directory), - "prefix" => solution_saving.prefix, - "filename" => solution_saving.filename + "prefix" => solution_saving.prefix ] summary_box(io, "SolutionSavingCallback", setup) end @@ -288,8 +284,7 @@ function Base.show(io::IO, ::MIME"text/plain", "save final solution" => solution_saving.save_final_solution ? "yes" : "no", "output directory" => abspath(solution_saving.output_directory), - "prefix" => solution_saving.prefix, - "filename" => solution_saving.filename + "prefix" => solution_saving.prefix ] summary_box(io, "SolutionSavingCallback", setup) end @@ -314,8 +309,7 @@ function Base.show(io::IO, ::MIME"text/plain", "save final solution" => solution_saving.save_final_solution ? "yes" : "no", "output directory" => abspath(solution_saving.output_directory), - "prefix" => solution_saving.prefix, - "filename" => solution_saving.filename + "prefix" => solution_saving.prefix ] summary_box(io, "SolutionSavingCallback", setup) end diff --git a/src/io/io.jl b/src/io/io.jl index 4ec292d980..ae4e15076f 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -1,12 +1,11 @@ include("write_vtk.jl") include("read_vtk.jl") -# handle "_" on optional prefix/filename strings +# handle "_" on optional prefix strings add_opt_str_post(str) = (str === "" ? "" : "_$(str)") function write_meta_data(callback::SolutionSavingCallback, integrator) prefix = callback.prefix - filename = callback.filename meta_data = create_meta_data_dict(callback, integrator) @@ -14,8 +13,7 @@ function write_meta_data(callback::SolutionSavingCallback, integrator) output_directory = callback.output_directory mkpath(output_directory) json_file = joinpath(output_directory, - "meta_data" * add_opt_str_post(prefix) * - add_opt_str_post(filename) * ".json") + "meta" * add_opt_str_post(prefix) * ".json") open(json_file, "w") do file JSON.print(file, meta_data, 2) diff --git a/test/callbacks/solution_saving.jl b/test/callbacks/solution_saving.jl index 9c49374b7d..b63cb6b201 100644 --- a/test/callbacks/solution_saving.jl +++ b/test/callbacks/solution_saving.jl @@ -19,7 +19,6 @@ │ save final solution: ………………………… yes │ │ output directory: ………………………………… $(output_directory_padded)│ │ prefix: …………………………………………………………… test │ - │ filename: ……………………………………………………… │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback) == show_box end @@ -41,7 +40,6 @@ │ save final solution: ………………………… yes │ │ output directory: ………………………………… $(output_directory_padded)│ │ prefix: …………………………………………………………… test │ - │ filename: ……………………………………………………… │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback) == show_box end @@ -63,7 +61,6 @@ │ save final solution: ………………………… yes │ │ output directory: ………………………………… $(output_directory_padded)│ │ prefix: …………………………………………………………… test │ - │ filename: ……………………………………………………… │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback) == show_box end From ca2410aeab0a55cbb7204d27aeb8ccc80c487141 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Mon, 8 Sep 2025 17:53:20 +0200 Subject: [PATCH 39/43] add suggestions --- src/io/io.jl | 24 ++++++++++++------------ src/io/write_vtk.jl | 27 ++++++++++++++------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/io/io.jl b/src/io/io.jl index ae4e15076f..91a7a65429 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -1,19 +1,21 @@ include("write_vtk.jl") include("read_vtk.jl") -# handle "_" on optional prefix strings -add_opt_str_post(str) = (str === "" ? "" : "_$(str)") +# Handle "_" on optional prefix strings +add_underscore_to_optional_prefix(str) = (str === "" ? "" : "$(str)_") +# Same for optional postfix strings +add_underscore_to_optional_postfix(str) = (str === "" ? "" : "_$(str)") function write_meta_data(callback::SolutionSavingCallback, integrator) prefix = callback.prefix meta_data = create_meta_data_dict(callback, integrator) - # write JSON-file + # write JSON file output_directory = callback.output_directory mkpath(output_directory) json_file = joinpath(output_directory, - "meta" * add_opt_str_post(prefix) * ".json") + "meta" * add_underscore_to_optional_postfix(prefix) * ".json") open(json_file, "w") do file JSON.print(file, meta_data, 2) @@ -35,7 +37,7 @@ function create_meta_data_dict(callback, integrator) systems = Dict{String, Any}() foreach_system(semi) do system idx = system_indices(system, semi) - name = prefix * add_opt_str_post("$(names[idx])") + name = add_underscore_to_optional_prefix(prefix) * names[idx] system_data = Dict{String, Any}() add_system_data!(system_data, system) @@ -61,6 +63,9 @@ function add_simulation_info!(info, git_hash, integrator) info["time_integrator"]["abstol"] = integrator.opts.abstol info["time_integrator"]["reltol"] = integrator.opts.reltol info["time_integrator"]["controller"] = type2string(integrator.opts.controller) + else + info["time_integrator"]["dt"] = integrator.dt + info["time_integrator"]["dt_max"] = integrator.opts.dtmax end info["technical_setup"] = Dict{String, Any}() @@ -68,14 +73,8 @@ function add_simulation_info!(info, git_hash, integrator) info["technical_setup"]["#threads"] = Threads.nthreads() end -# Skip systemdata addition for `Nothing` add_system_data!(system_data, data::Nothing) = system_data -function add_system_data!(system_data, data) - throw(ArgumentError("Method for $(typeof(data)) not implemented. " * - "Please add a method `add_system_data!(system_data, ::$(typeof(data)))`.")) -end - function add_system_data!(system_data, system::FluidSystem) system_data["system_type"] = type2string(system) system_data["particle_spacing"] = particle_spacing(system, 1) @@ -85,7 +84,7 @@ function add_system_data!(system_data, system::FluidSystem) system_data["acceleration"] = system.acceleration system_data["sound_speed"] = system_sound_speed(system) system_data["pressure_acceleration_formulation"] = nameof(system.pressure_acceleration_formulation) - add_system_data!(system_data, system.shifting_technique) + add_system_data!(system_data, shifting_technique(system)) add_system_data!(system_data, system.surface_tension) add_system_data!(system_data, system.surface_normal_method) add_system_data!(system_data, system.viscosity) @@ -106,6 +105,7 @@ function add_system_data!(system_data, system::TotalLagrangianSPHSystem) system_data["smoothing_length"] = system.smoothing_length system_data["acceleration"] = system.acceleration add_system_data!(system_data, system.boundary_model) + add_system_data!(system_data, system.viscosity) add_system_data!(system_data, system.penalty_force) end diff --git a/src/io/write_vtk.jl b/src/io/write_vtk.jl index 941ceb01ca..72ae71b0e0 100644 --- a/src/io/write_vtk.jl +++ b/src/io/write_vtk.jl @@ -103,16 +103,12 @@ function trixi2vtk(system_, dvdu_ode_, vu_ode_, semi_, t, periodic_box; v = wrap_v(v_ode, system, semi) u = wrap_u(u_ode, system, semi) - # handle "_" on optional pre/postfix strings - add_opt_str_pre(str) = (str === "" ? "" : "$(str)_") - add_opt_str_post(str) = (str === nothing ? "" : "_$(str)") - file = joinpath(output_directory, - add_opt_str_pre(prefix) * "$system_name" - * add_opt_str_post(iter)) + add_underscore_to_optional_prefix(prefix) * "$system_name" + * add_underscore_to_optional_postfix(iter)) collection_file = joinpath(output_directory, - add_opt_str_pre(prefix) * "$system_name") + add_underscore_to_optional_prefix(prefix) * "$system_name") # Reset the collection when the iteration is 0 pvd = paraview_collection(collection_file; append=iter > 0) @@ -325,12 +321,17 @@ function write2vtk!(vtk, v, u, t, system::FluidSystem) grad_kernel = smoothing_kernel_grad(system, pos_diff, distance, particle) surface_tension[1:ndims(system), - particle] .+= surface_tension_force(surface_tension_a, - surface_tension_b, - system, system, particle, - neighbor, pos_diff, - distance, rho_a, rho_b, - grad_kernel) + particle] .+= surface_tension_force(surface_tension_a, + surface_tension_b, + system, + system, + particle, + neighbor, + pos_diff, + distance, + rho_a, + rho_b, + grad_kernel) end vtk["surface_tension"] = surface_tension From 977027699a8f8150fc0671c5f7b21309227ad0ea Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Tue, 9 Sep 2025 15:38:47 +0200 Subject: [PATCH 40/43] Enhance data handling for `OpenBoundarySPHSystem` --- src/io/io.jl | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/io/io.jl b/src/io/io.jl index 91a7a65429..1c70e3b069 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -40,6 +40,7 @@ function create_meta_data_dict(callback, integrator) name = add_underscore_to_optional_prefix(prefix) * names[idx] system_data = Dict{String, Any}() + #@autoinfiltrate add_system_data!(system_data, system) systems[name] = system_data @@ -133,12 +134,14 @@ end function add_system_data!(system_data, system::OpenBoundarySPHSystem) system_data["system_type"] = type2string(system) - system_data["particle_spacing"] = particle_spacing(system, 1) - system_data["reference_velocity"] = type2string(system.reference_velocity) - system_data["reference_pressure"] = type2string(system.reference_pressure) - system_data["reference_density"] = type2string(system.reference_density) + system_data["fluid_system_index"] = system.fluid_system_index[] + system_data["smoothing_length"] = system.smoothing_length add_system_data!(system_data, system.boundary_model) - add_system_data!(system_data, system.boundary_zone) + + system_data["boundary_zones"] = Dict{String, Any}() + for (indice, boundary_zone) in enumerate(system.boundary_zones) + add_system_data!(system_data["boundary_zones"], boundary_zone, indice) + end end function add_system_data!(system_data, system::ParticlePackingSystem) @@ -170,12 +173,13 @@ function add_system_data!(system_data, boundary_model::BoundaryModelMonaghanKajt add_system_data!(system_data["boundary_model"], boundary_model.viscosity) end -function add_system_data!(system_data, boundary_model::BoundaryModelTafuni) +function add_system_data!(system_data, boundary_model::BoundaryModelMirroringTafuni) system_data["boundary_model"] = Dict{String, Any}() system_data["boundary_model"]["model"] = type2string(boundary_model) + system_data["boundary_model"]["mirror_method"] = type2string(boundary_model.mirror_method) end -function add_system_data!(system_data, boundary_model::BoundaryModelLastiwka) +function add_system_data!(system_data, boundary_model::BoundaryModelCharacteristicsLastiwka) system_data["boundary_model"] = Dict{String, Any}() system_data["boundary_model"]["model"] = type2string(boundary_model) system_data["boundary_model"]["extrapolate_reference_values"] = boundary_model.extrapolate_reference_values @@ -277,10 +281,19 @@ function add_system_data!(system_data, surface_normal_method::ColorfieldSurfaceN system_data["surface_normal_method"]["ideal_density_threshold"] = surface_normal_method.ideal_density_threshold end -function add_system_data!(system_data, boundary_zone::BoundaryZone) - system_data["boundary_zone"] = Dict{String, Any}() - system_data["boundary_zone"]["boundary_type"] = type2string(boundary_zone.boundary_type) - system_data["boundary_zone"]["zone_width"] = boundary_zone.zone_width +function add_system_data!(system_data, boundary_zone::BoundaryZone, indice) + zone_name = "boundary_zone_" * string(indice) + system_data[zone_name] = Dict{String, Any}() + system_data[zone_name]["spanning_set"] = boundary_zone.spanning_set + system_data[zone_name]["zone_origin"] = boundary_zone.zone_origin + system_data[zone_name]["zone_width"] = boundary_zone.zone_width + system_data[zone_name]["flow_direction"] = boundary_zone.flow_direction + system_data[zone_name]["plane_normal"] = boundary_zone.plane_normal + system_data[zone_name]["reference_values"] = boundary_zone.reference_values + system_data[zone_name]["average_inflow_velocity"] = boundary_zone.average_inflow_velocity + system_data[zone_name]["prescribed_density"] = boundary_zone.prescribed_density + system_data[zone_name]["prescribed_pressure"] = boundary_zone.prescribed_pressure + system_data[zone_name]["prescribed_velocity"] = boundary_zone.prescribed_velocity end function add_system_data!(system_data, movement::BoundaryMovement) From 9aa5ae941cea1ea0f03ab6d3c508c7062c2d4316 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Tue, 9 Sep 2025 15:39:18 +0200 Subject: [PATCH 41/43] correct formatting issue --- src/io/write_vtk.jl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/io/write_vtk.jl b/src/io/write_vtk.jl index e5aeacd444..6f0b772189 100644 --- a/src/io/write_vtk.jl +++ b/src/io/write_vtk.jl @@ -321,17 +321,17 @@ function write2vtk!(vtk, v, u, t, system::FluidSystem) grad_kernel = smoothing_kernel_grad(system, pos_diff, distance, particle) surface_tension[1:ndims(system), - particle] .+= surface_tension_force(surface_tension_a, - surface_tension_b, - system, - system, - particle, - neighbor, - pos_diff, - distance, - rho_a, - rho_b, - grad_kernel) + particle] .+= surface_tension_force(surface_tension_a, + surface_tension_b, + system, + system, + particle, + neighbor, + pos_diff, + distance, + rho_a, + rho_b, + grad_kernel) end vtk["surface_tension"] = surface_tension From 5da1c67a9e92ea6b22cc1518481ff03e915a1152 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Wed, 10 Sep 2025 12:04:21 +0200 Subject: [PATCH 42/43] Remove autoinfiltrate --- src/io/io.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/io/io.jl b/src/io/io.jl index 1c70e3b069..88d3abff4d 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -40,7 +40,6 @@ function create_meta_data_dict(callback, integrator) name = add_underscore_to_optional_prefix(prefix) * names[idx] system_data = Dict{String, Any}() - #@autoinfiltrate add_system_data!(system_data, system) systems[name] = system_data From 36608435f0c0bf2512abced27cd21a72d28e5733 Mon Sep 17 00:00:00 2001 From: Marcel Schurer Date: Fri, 12 Sep 2025 16:48:13 +0200 Subject: [PATCH 43/43] rename `number_of_threads` --- src/io/io.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/io.jl b/src/io/io.jl index 88d3abff4d..680bbe9ac2 100644 --- a/src/io/io.jl +++ b/src/io/io.jl @@ -70,7 +70,7 @@ function add_simulation_info!(info, git_hash, integrator) info["technical_setup"] = Dict{String, Any}() info["technical_setup"]["parallelization_backend"] = type2string(integrator.p.parallelization_backend) - info["technical_setup"]["#threads"] = Threads.nthreads() + info["technical_setup"]["number_of_threads"] = Threads.nthreads() end add_system_data!(system_data, data::Nothing) = system_data