@@ -423,12 +423,6 @@ function compute_pressure!(boundary_model,
423423 boundary_pressure_extrapolation! (Val (parallelize), boundary_model, system,
424424 neighbor_system, system_coords, neighbor_coords, v,
425425 v_neighbor_system, semi)
426-
427- @threaded semi for particle in eachparticle (system)
428- # Limit pressure to be non-negative to avoid attractive forces between fluid and
429- # boundary particles at free surfaces (sticking artifacts).
430- pressure[particle] = max (pressure[particle], 0 )
431- end
432426 end
433427
434428 @trixi_timeit timer () " inverse state equation" @threaded semi for particle in
@@ -447,13 +441,17 @@ function compute_adami_density!(boundary_model, system, system_coords, particle)
447441 # The summation is only over fluid particles, thus the volume stays zero when a boundary
448442 # particle isn't surrounded by fluid particles.
449443 # Check the volume to avoid NaNs in pressure and velocity.
450- if volume[particle] > eps ()
451- pressure[particle] /= volume[particle]
444+ if @inbounds volume[particle] > eps ()
445+ @inbounds pressure[particle] /= volume[particle]
452446
453447 # To impose no-slip condition
454448 compute_wall_velocity! (viscosity, system, system_coords, particle)
455449 end
456450
451+ # Limit pressure to be non-negative to avoid attractive forces between fluid and
452+ # boundary particles at free surfaces (sticking artifacts).
453+ @inbounds pressure[particle] = max (pressure[particle], 0 )
454+
457455 # Apply inverse state equation to compute density (not used with EDAC)
458456 inverse_state_equation! (density, state_equation, pressure, particle)
459457end
@@ -519,26 +517,30 @@ end
519517 v_neighbor_system, particle, neighbor, pos_diff,
520518 distance, viscosity, cache, pressure,
521519 pressure_offset)
522- density_neighbor = current_density (v_neighbor_system, neighbor_system, neighbor)
520+ density_neighbor = @inbounds current_density (v_neighbor_system, neighbor_system,
521+ neighbor)
523522
523+ # Fluid pressure term
524+ fluid_pressure = @inbounds current_pressure (v_neighbor_system, neighbor_system,
525+ neighbor)
526+
527+ # Hydrostatic pressure term from fluid and boundary acceleration
524528 resulting_acceleration = neighbor_system. acceleration -
525- current_acceleration (system, particle)
529+ @inbounds current_acceleration (system, particle)
530+ hydrostatic_pressure = dot (resulting_acceleration, density_neighbor * pos_diff)
526531
527- kernel_weight = smoothing_kernel (boundary_model, distance, particle)
532+ # Additional dynamic pressure term (only with `BernoulliPressureExtrapolation`)
533+ dynamic_pressure_ = dynamic_pressure (boundary_density_calculator, density_neighbor,
534+ v, v_neighbor_system, pos_diff, distance,
535+ particle, neighbor, system, neighbor_system)
528536
529- pressure[particle] += (pressure_offset
530- +
531- current_pressure (v_neighbor_system, neighbor_system,
532- neighbor)
533- +
534- dynamic_pressure (boundary_density_calculator, density_neighbor,
535- v, v_neighbor_system, pos_diff, distance,
536- particle, neighbor, system, neighbor_system)
537- +
538- dot (resulting_acceleration, density_neighbor * pos_diff)) *
539- kernel_weight
537+ sum_pressures = pressure_offset + fluid_pressure + dynamic_pressure_ +
538+ hydrostatic_pressure
539+
540+ kernel_weight = smoothing_kernel (boundary_model, distance, particle)
540541
541- cache. volume[particle] += kernel_weight
542+ @inbounds pressure[particle] += sum_pressures * kernel_weight
543+ @inbounds cache. volume[particle] += kernel_weight
542544
543545 compute_smoothed_velocity! (cache, viscosity, neighbor_system, v_neighbor_system,
544546 kernel_weight, particle, neighbor)
@@ -586,8 +588,8 @@ function compute_smoothed_velocity!(cache, viscosity::ViscosityAdami, neighbor_s
586588 v_neighbor_system, kernel_weight, particle, neighbor)
587589 v_b = current_velocity (v_neighbor_system, neighbor_system, neighbor)
588590
589- for dim in 1 : ndims (neighbor_system )
590- cache. wall_velocity[dim, particle] += kernel_weight * v_b[dim]
591+ for dim in eachindex (v_b )
592+ @inbounds cache. wall_velocity[dim, particle] += kernel_weight * v_b[dim]
591593 end
592594
593595 return cache
@@ -606,17 +608,17 @@ end
606608 # This velocity is zero when not using moving boundaries.
607609 v_boundary = current_velocity (system_coords, system, particle)
608610
609- for dim in 1 : ndims (system )
610- # The second term is the precalculated smoothed velocity field of the fluid.
611- wall_velocity [dim,
612- particle] = 2 * v_boundary [dim] -
613- wall_velocity[dim, particle] / volume[particle]
611+ for dim in eachindex (v_boundary )
612+ # The second term is the precalculated smoothed velocity field of the fluid
613+ new_velocity = @inbounds 2 * v_boundary [dim] -
614+ wall_velocity [dim, particle] / volume[particle]
615+ @inbounds wall_velocity[dim, particle] = new_velocity
614616 end
615617 return viscosity
616618end
617619
618620@inline function inverse_state_equation! (density, state_equation, pressure, particle)
619- density[particle] = inverse_state_equation (state_equation, pressure[particle])
621+ @inbounds density[particle] = inverse_state_equation (state_equation, pressure[particle])
620622 return density
621623end
622624
0 commit comments