Skip to content

Commit

Permalink
General velocity normal function
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpit-Babbar committed Sep 29, 2024
1 parent cdf2653 commit d29df2b
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 77 deletions.
9 changes: 0 additions & 9 deletions src/equations/compressible_euler_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1970,15 +1970,6 @@ end
return v
end

@inline function velocity(u, normal_direction::AbstractVector,
equations::CompressibleEulerEquations2D)
rho = u[1]
v1 = u[2] / rho
v2 = u[3] / rho
v = v1 * normal_direction[1] + v2 * normal_direction[2]
return v
end

@inline function pressure(u, equations::CompressibleEulerEquations2D)
rho, rho_v1, rho_v2, rho_e = u
p = (equations.gamma - 1) * (rho_e - 0.5f0 * (rho_v1^2 + rho_v2^2) / rho)
Expand Down
10 changes: 0 additions & 10 deletions src/equations/compressible_euler_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1706,16 +1706,6 @@ end
return v
end

@inline function velocity(u, normal_direction::AbstractVector,
equations::CompressibleEulerEquations3D)
rho = u[1]
v1 = u[2] / rho
v2 = u[3] / rho
v3 = u[4] / rho
v = v1 * normal_direction[1] + v2 * normal_direction[2] + v3 * normal_direction[3]
return v
end

@inline function pressure(u, equations::CompressibleEulerEquations3D)
rho, rho_v1, rho_v2, rho_v3, rho_e = u
p = (equations.gamma - 1) * (rho_e - 0.5f0 * (rho_v1^2 + rho_v2^2 + rho_v3^2) / rho)
Expand Down
9 changes: 0 additions & 9 deletions src/equations/compressible_euler_multicomponent_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -839,13 +839,4 @@ end
v = u[orientation] / rho
return v
end

@inline function velocity(u, normal_direction::AbstractVector,
equations::CompressibleEulerMulticomponentEquations2D)
rho = density(u, equations)
v1 = u[1] / rho
v2 = u[2] / rho
v = v1 * normal_direction[1] + v2 * normal_direction[2]
return v
end
end # @muladd
22 changes: 20 additions & 2 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,31 @@ function prim2cons end
Return the velocity vector corresponding to the equations, e.g., fluid velocity for
Euler's equations. The velocity in certain orientation or normal direction (scalar) can be computed
with `velocity(u, orientation, equations)` or `velocity(u, normal_direction, equations)`
respectively.
respectively. The `velocity(u, normal_direction, equations)` function calls
`velocity(u, equations)` to compute the velocity vector and then normal vector, thus allowing
a general function to be written for the AbstractEquations type. However, the
`velocity(u, orientation, equations)` is written for each equation separately to ensure
only the velocity in the desired direction (orientation) is computed.
`u` is a vector of the conserved variables at a single node, i.e., a vector
of the correct length `nvariables(equations)`.
"""
function velocity end

@inline function velocity(u, normal_direction::AbstractVector,
equations::AbstractEquations{2})
vel = velocity(u, equations)
v = vel[1] * normal_direction[1] + vel[2] * normal_direction[2]
return v
end

@inline function velocity(u, normal_direction::AbstractVector,
equations::AbstractEquations{3})
vel = velocity(u, equations)
v = vel[1] * normal_direction[1] + vel[2] * normal_direction[2] +
vel[3] * normal_direction[3]
return v
end

"""
entropy(u, equations)
Expand Down
8 changes: 0 additions & 8 deletions src/equations/ideal_glm_mhd_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,6 @@ end
return v
end

@inline function velocity(u, normal_direction::AbstractVector,
equations::IdealGlmMhdEquations1D)
rho = u[1]
v1 = u[2] / rho
v = v1 * normal_direction[1]
return v
end

@inline function pressure(u, equations::IdealGlmMhdEquations1D)
rho, rho_v1, rho_v2, rho_v3, rho_e, B1, B2, B3 = u
p = (equations.gamma - 1) * (rho_e - 0.5f0 * (rho_v1^2 + rho_v2^2 + rho_v3^2) / rho
Expand Down
9 changes: 0 additions & 9 deletions src/equations/ideal_glm_mhd_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1133,15 +1133,6 @@ end
return v
end

@inline function velocity(u, normal_direction::AbstractVector,
equations::IdealGlmMhdEquations2D)
rho = u[1]
v1 = u[2] / rho
v2 = u[3] / rho
v = v1 * normal_direction[1] + v2 * normal_direction[2]
return v
end

@inline function pressure(u, equations::IdealGlmMhdEquations2D)
rho, rho_v1, rho_v2, rho_v3, rho_e, B1, B2, B3, psi = u
p = (equations.gamma - 1) * (rho_e - 0.5f0 * (rho_v1^2 + rho_v2^2 + rho_v3^2) / rho
Expand Down
10 changes: 0 additions & 10 deletions src/equations/ideal_glm_mhd_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1024,16 +1024,6 @@ end
return v
end

@inline function velocity(u, normal_direction::AbstractVector,
equations::IdealGlmMhdEquations3D)
rho = u[1]
v1 = u[2] / rho
v2 = u[3] / rho
v3 = u[4] / rho
v = v1 * normal_direction[1] + v2 * normal_direction[2] + v3 * normal_direction[3]
return v
end

@inline function pressure(u, equations::IdealGlmMhdEquations3D)
rho, rho_v1, rho_v2, rho_v3, rho_e, B1, B2, B3, psi = u
p = (equations.gamma - 1) * (rho_e - 0.5f0 * (rho_v1^2 + rho_v2^2 + rho_v3^2) / rho
Expand Down
9 changes: 0 additions & 9 deletions src/equations/polytropic_euler_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,6 @@ end
return v
end

@inline function velocity(u, normal_direction::AbstractVector,
equations::PolytropicEulerEquations2D)
rho = u[1]
v1 = u[2] / rho
v2 = u[3] / rho
v = v1 * normal_direction[1] + v2 * normal_direction[2]
return v
end

@inline function pressure(u, equations::PolytropicEulerEquations2D)
rho, rho_v1, rho_v2 = u
p = equations.kappa * rho^equations.gamma
Expand Down
9 changes: 0 additions & 9 deletions src/equations/shallow_water_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -846,15 +846,6 @@ end
return v
end

@inline function velocity(u, normal_direction::AbstractVector,
equations::ShallowWaterEquations2D)
h = u[1]
v1 = u[2] / h
v2 = u[3] / h
v = v1 * normal_direction[1] + v2 * normal_direction[2]
return v
end

# Convert conservative variables to primitive
@inline function cons2prim(u, equations::ShallowWaterEquations2D)
h, _, _, b = u
Expand Down
2 changes: 0 additions & 2 deletions test/test_unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1811,8 +1811,6 @@ end
equations_ideal_mhd_1d = IdealGlmMhdEquations1D(gamma)
u = prim2cons(SVector(rho, v1, v2, v3, pres, B1, B2, B3), equations_ideal_mhd_1d)
@test isapprox(velocity(u, equations_ideal_mhd_1d), SVector(v1, v2, v3))
@test isapprox(velocity(u, SVector(normal_direction_2d[1]), equations_ideal_mhd_1d),
v_normal_1d)
for orientation in 1:3
@test isapprox(velocity(u, orientation, equations_ideal_mhd_1d),
v_vector[orientation])
Expand Down

0 comments on commit d29df2b

Please sign in to comment.