-
Notifications
You must be signed in to change notification settings - Fork 15
Validate open boundaries #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
LasNikas
wants to merge
25
commits into
trixi-framework:main
Choose a base branch
from
LasNikas:validate-open-boundaries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
22c11c3
add validation example
efabe55
extrapolate density and add zero velocity region
95ac992
change resolution
e50e876
add factor
1359c63
Merge branch 'main' into validate-open-boundaries
11f38a2
add drag and lift force
25b06a1
update
933ca41
output directory
fe1418a
Merge branch 'main' into validate-open-boundaries
04c6470
Merge branch 'main' into validate-open-boundaries
e0863bd
prepare validation case
6c99173
add run
0e6d48d
fix tspan
b2d03be
Merge branch 'main' into validate-open-boundaries
99e4ef9
Merge branch 'main' into validate-open-boundaries
abc4eb5
implement suggestions
536c3d6
compute strouhal number
1282aa6
fix
19a1e72
Merge branch 'main' into validate-open-boundaries
59102ab
add unique frequency check
bff3f3f
Merge branch 'main' into validate-open-boundaries
634fbca
Merge branch 'main' into validate-open-boundaries
f77449b
Merge branch 'main' into validate-open-boundaries
c0f874d
add TIC
0d3b385
make it GPU compatible
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using TrixiParticles | ||
|
||
# results in [90k particles, 220k particles, 1.2M particles, 5M particles] | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for resolution_factor in [0.08, 0.05, 0.02, 0.01] | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
trixi_include(joinpath(validation_dir(), "vortex_street_2d", "vortex_street_2d.jl"), | ||
factor_D=resolution_factor, write_to_vtk=false, tspan=(0.0, 50.0)) | ||
end | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
# Flow past a circular cylinder (vortex street), Tafuni et al. (2018). | ||
# Other literature using this validation: | ||
# Vacandio et al. (2013), Marrone et al. (2013), Calhoun (2002), Liu et al. (1998) | ||
|
||
using TrixiParticles | ||
using OrdinaryDiffEq | ||
|
||
write_to_vtk = true | ||
|
||
# ========================================================================================== | ||
# ==== Resolution | ||
const cylinder_diameter = 0.1 | ||
|
||
factor_D = 0.08 | ||
|
||
particle_spacing = factor_D * cylinder_diameter | ||
efaulhaber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Make sure that the kernel support of fluid particles at a boundary is always fully sampled | ||
boundary_layers = 4 | ||
|
||
# Make sure that the kernel support of fluid particles at an open boundary is always | ||
# fully sampled. | ||
# Note: Due to the dynamics at the inlets and outlets of open boundaries, | ||
# it is recommended to use `open_boundary_layers > boundary_layers` | ||
open_boundary_layers = 8 | ||
|
||
# ========================================================================================== | ||
# ==== Experiment Setup | ||
tspan = (0.0, 50.0) | ||
|
||
# Boundary geometry and initial fluid particle positions | ||
domain_size = (25 * cylinder_diameter, 20 * cylinder_diameter) | ||
efaulhaber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
flow_direction = [1.0, 0.0] | ||
reynolds_number = 200 | ||
const prescribed_velocity = 1.0 | ||
|
||
const fluid_density = 1000.0 | ||
|
||
pressure = 0.0 | ||
|
||
sound_speed = 10 * prescribed_velocity | ||
|
||
state_equation = nothing | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
boundary_size = (domain_size[1] + 2 * particle_spacing * open_boundary_layers, | ||
domain_size[2]) | ||
|
||
pipe = RectangularTank(particle_spacing, domain_size, boundary_size, fluid_density, | ||
pressure=pressure, n_layers=boundary_layers, | ||
velocity=[prescribed_velocity, 0.0], | ||
faces=(false, false, true, true)) | ||
|
||
# Shift pipe walls in negative x-direction for the inflow | ||
pipe.boundary.coordinates[1, :] .-= particle_spacing * open_boundary_layers | ||
|
||
n_buffer_particles = 10 * pipe.n_particles_per_dimension[2]^(ndims(pipe.fluid) - 1) | ||
|
||
cylinder_center = (5 * cylinder_diameter, domain_size[2] / 2) | ||
cylinder = SphereShape(particle_spacing, cylinder_diameter / 2, | ||
cylinder_center, fluid_density, sphere_type=RoundSphere()) | ||
|
||
fluid = setdiff(pipe.fluid, cylinder) | ||
|
||
# ========================================================================================== | ||
# ==== Fluid | ||
wcsph = true | ||
|
||
h_factor = 2.0 | ||
smoothing_length = h_factor * particle_spacing | ||
smoothing_kernel = WendlandC2Kernel{2}() | ||
|
||
fluid_density_calculator = ContinuityDensity() | ||
|
||
kinematic_viscosity = prescribed_velocity * cylinder_diameter / reynolds_number | ||
|
||
# Alternatively the WCSPH scheme can be used | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if wcsph | ||
state_equation = StateEquationCole(; sound_speed, reference_density=fluid_density, | ||
exponent=7) | ||
|
||
viscosity = ViscosityAdami(nu=kinematic_viscosity) | ||
|
||
density_diffusion = DensityDiffusionMolteniColagrossi(delta=0.1) | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fluid_system = WeaklyCompressibleSPHSystem(fluid, fluid_density_calculator, | ||
state_equation, smoothing_kernel, | ||
density_diffusion=density_diffusion, | ||
smoothing_length, viscosity=viscosity, | ||
buffer_size=n_buffer_particles) | ||
|
||
else | ||
state_equation = nothing | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
viscosity = ViscosityAdami(nu=kinematic_viscosity) | ||
|
||
fluid_system = EntropicallyDampedSPHSystem(fluid, smoothing_kernel, | ||
smoothing_length, | ||
sound_speed, viscosity=viscosity, | ||
density_calculator=fluid_density_calculator, | ||
buffer_size=n_buffer_particles) | ||
end | ||
|
||
# ========================================================================================== | ||
# ==== Open Boundary | ||
|
||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function velocity_function2d(pos, t) | ||
return SVector(prescribed_velocity, 0.0) | ||
end | ||
|
||
open_boundary_model = BoundaryModelTafuni() | ||
|
||
boundary_type_in = InFlow() | ||
plane_in = ([0.0, 0.0], [0.0, domain_size[2]]) | ||
inflow = BoundaryZone(; plane=plane_in, plane_normal=flow_direction, open_boundary_layers, | ||
density=fluid_density, particle_spacing, | ||
boundary_type=boundary_type_in) | ||
|
||
reference_velocity_in = velocity_function2d | ||
reference_pressure_in = nothing | ||
reference_density_in = nothing | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
open_boundary_in = OpenBoundarySPHSystem(inflow; fluid_system, | ||
boundary_model=open_boundary_model, | ||
buffer_size=n_buffer_particles, | ||
reference_density=reference_density_in, | ||
reference_pressure=reference_pressure_in, | ||
reference_velocity=reference_velocity_in) | ||
|
||
boundary_type_out = OutFlow() | ||
plane_out = ([domain_size[1], 0.0], [domain_size[1], domain_size[2]]) | ||
outflow = BoundaryZone(; plane=plane_out, plane_normal=(-flow_direction), | ||
open_boundary_layers, density=fluid_density, particle_spacing, | ||
boundary_type=boundary_type_out) | ||
|
||
reference_velocity_out = nothing | ||
reference_pressure_out = nothing | ||
reference_density_out = nothing | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
open_boundary_out = OpenBoundarySPHSystem(outflow; fluid_system, | ||
boundary_model=open_boundary_model, | ||
buffer_size=n_buffer_particles, | ||
reference_density=reference_density_out, | ||
reference_pressure=reference_pressure_out, | ||
reference_velocity=reference_velocity_out) | ||
# ========================================================================================== | ||
# ==== Boundary | ||
boundary_model = BoundaryModelDummyParticles(pipe.boundary.density, pipe.boundary.mass, | ||
AdamiPressureExtrapolation(), | ||
state_equation=state_equation, | ||
viscosity=nothing, # free-slip | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
smoothing_kernel, smoothing_length) | ||
|
||
boundary_system_wall = BoundarySPHSystem(pipe.boundary, boundary_model) | ||
|
||
boundary_model_cylinder = BoundaryModelDummyParticles(cylinder.density, cylinder.mass, | ||
AdamiPressureExtrapolation(), | ||
state_equation=state_equation, | ||
viscosity=viscosity, | ||
smoothing_kernel, smoothing_length) | ||
|
||
boundary_system_cylinder = BoundarySPHSystem(cylinder, boundary_model_cylinder) | ||
|
||
# ========================================================================================== | ||
# ==== Postprocessing | ||
circle = SphereShape(particle_spacing, (cylinder_diameter + particle_spacing) / 2, | ||
cylinder_center, fluid_density, n_layers=1, | ||
sphere_type=RoundSphere()) | ||
|
||
# Points for pressure interpolation, located at the wall interface. | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const data_points = reinterpret(reshape, SVector{ndims(circle), eltype(circle)}, | ||
circle.coordinates) | ||
const center = SVector(cylinder_center) | ||
|
||
calculate_lift_force(system, v_ode, u_ode, semi, t) = nothing | ||
function calculate_lift_force(system::TrixiParticles.FluidSystem, v_ode, u_ode, semi, t) | ||
force = zero(first(data_points)) | ||
|
||
for point in data_points | ||
values = interpolate_points(point, semi, system, v_ode, u_ode; cut_off_bnd=false, | ||
clip_negative_pressure=false) | ||
|
||
# F = ∑ -p_i * A_i * n_i | ||
force -= values.pressure * particle_spacing .* | ||
TrixiParticles.normalize(point - center) | ||
end | ||
|
||
return 2 * force[2] / (fluid_density * prescribed_velocity^2 * cylinder_diameter) | ||
end | ||
|
||
calculate_drag_force(system, v_ode, u_ode, semi, t) = nothing | ||
function calculate_drag_force(system::TrixiParticles.FluidSystem, v_ode, u_ode, semi, t) | ||
force = zero(first(data_points)) | ||
|
||
for point in data_points | ||
values = interpolate_points(point, semi, system, v_ode, u_ode; cut_off_bnd=false, | ||
clip_negative_pressure=false) | ||
|
||
# F = ∑ -p_i * A_i * n_i | ||
force -= values.pressure * particle_spacing .* | ||
TrixiParticles.normalize(point - center) | ||
end | ||
|
||
return 2 * force[1] / (fluid_density * prescribed_velocity^2 * cylinder_diameter) | ||
end | ||
|
||
# ========================================================================================== | ||
# ==== Simulation | ||
semi = Semidiscretization(fluid_system, open_boundary_in, open_boundary_out, | ||
boundary_system_wall, boundary_system_cylinder) | ||
|
||
ode = semidiscretize(semi, tspan) | ||
|
||
info_callback = InfoCallback(interval=100) | ||
|
||
output_directory = "out_vortex_street_dp_$(factor_D)D_c_$(sound_speed)_h_factor_$(h_factor)_" * | ||
TrixiParticles.type2string(smoothing_kernel) | ||
if write_to_vtk | ||
saving_callback = SolutionSavingCallback(; dt=0.02, prefix="", output_directory) | ||
else | ||
saving_callback = nothing | ||
end | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
pp_callback = PostprocessCallback(; dt=0.02, | ||
f_l=calculate_lift_force, f_d=calculate_drag_force, | ||
output_directory, filename="resulting_force", | ||
write_csv=true, write_file_interval=10) | ||
|
||
extra_callback = nothing | ||
|
||
callbacks = CallbackSet(info_callback, UpdateCallback(), saving_callback, | ||
ParticleShiftingCallback(), pp_callback, extra_callback) | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
sol = solve(ode, RDPK3SpFSAL35(), | ||
abstol=1e-6, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration) | ||
reltol=1e-4, # Default reltol is 1e-3 (may need to be tuned to prevent boundary penetration) | ||
dtmax=1e-2, # Limit stepsize to prevent crashing | ||
save_everystep=false, callback=callbacks); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.