Skip to content
Draft
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
349373a
Added steps to compute the gradient for hyperbolic systems.
SimonCan May 22, 2025
9277c5b
Moved potential gradient calculations into integration routine.
SimonCan May 22, 2025
9826f54
Distinguish between call using functions with 2 or 3 parameters.
SimonCan May 27, 2025
5c43164
Reverted function signature.
SimonCan May 30, 2025
c889484
Update src/equations/compressible_euler_multicomponent_2d.jl
SimonCan Jun 2, 2025
2821bf0
Update src/equations/compressible_euler_multicomponent_2d.jl
SimonCan Jun 2, 2025
33ead0d
Update src/equations/compressible_euler_multicomponent_2d.jl
SimonCan Jun 2, 2025
818c698
Added Andrew's Fortran code for derivatives.
SimonCan Jun 2, 2025
103c918
Update src/callbacks_step/analysis_dg2d.jl
SimonCan Jun 3, 2025
76adb10
Update src/callbacks_step/analysis_dg2d.jl
SimonCan Jun 3, 2025
373c1d6
Update src/callbacks_step/analysis_dg2d.jl
SimonCan Jun 3, 2025
4e6245b
Update src/semidiscretization/semidiscretization.jl
SimonCan Jun 3, 2025
a93e340
Sterted conversion of Andrew's derivatives method.
SimonCan Jun 4, 2025
d7f3f55
Fuirther implementations of Andrew's derivative funciton.
SimonCan Jun 11, 2025
5c4e4db
Further translations of Fortran variables to Trixi.jl variables.
SimonCan Jun 12, 2025
00d61c9
Added calculation of fluxes by direciton.
SimonCan Jun 16, 2025
1424930
Corrected calculation of gradients.
SimonCan Jun 17, 2025
0dcc5ee
Corrected the gradient function.
SimonCan Jun 23, 2025
470c96d
Added 'semi' option to function call.
SimonCan Jun 26, 2025
db9b07d
Take care of cases when function is cons2cons.
SimonCan Jun 26, 2025
a2e26c2
Update src/callbacks_step/analysis.jl
SimonCan Jun 30, 2025
71f7e7a
Update src/callbacks_step/analysis.jl
SimonCan Jun 30, 2025
c705cdf
Update src/callbacks_step/analysis_dg2d.jl
SimonCan Jun 30, 2025
0c50c08
Removed redundant 'semi' parameter.
SimonCan Jul 2, 2025
9658874
Update src/callbacks_step/analysis_dg2d.jl
SimonCan Jul 3, 2025
423dd30
Update src/callbacks_step/analysis_dg2d.jl
SimonCan Jul 3, 2025
1081df0
Update src/callbacks_step/analysis_dg2d.jl
SimonCan Jul 3, 2025
6e31ee3
Update src/callbacks_step/analysis_dg2d.jl
SimonCan Jul 3, 2025
3612f4b
Update src/callbacks_step/analysis_dg2d.jl
SimonCan Jul 3, 2025
71ca315
Update src/callbacks_step/analysis_dg2d.jl
SimonCan Jul 3, 2025
b8a2716
Removed redundant code.
SimonCan Jul 3, 2025
52195d8
Merge branch 'sc/analysis_multi_euler_2d' of https://github.com/trixi…
SimonCan Jul 3, 2025
2d65ccc
Remoevd some redundant code.
SimonCan Jul 4, 2025
89cbfc0
Compute now also the y-derivative.
SimonCan Jul 10, 2025
44c3f5f
Use components of derivative vector for computing the vorticity.
SimonCan Jul 14, 2025
d22561b
Merge branch 'main' into sc/analysis_multi_euler_2d
SimonCan Jul 14, 2025
d825c93
Removed factor rho from the enstrophy.
SimonCan Jul 14, 2025
3cdbc82
Replaced DG derivative with polynoial interpolation.
SimonCan Jul 24, 2025
d7cd1b3
Merge branch 'main' into sc/analysis_multi_euler_2d
SimonCan Oct 2, 2025
df58d7f
Merge remote-tracking branch 'origin/main' into sc/analysis_multi_eul…
SimonCan Oct 2, 2025
52b267b
Added max_abs_speed_naive for CompressibleEulerMulticomponentEquations2D
SimonCan Oct 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ export cons2cons, cons2prim, prim2cons, cons2macroscopic, cons2state, cons2mean,
cons2entropy, entropy2cons
export density, pressure, density_pressure, velocity, global_mean_vars,
equilibrium_distribution, waterheight, waterheight_pressure
export entropy, energy_total, energy_kinetic, energy_internal,
energy_magnetic, cross_helicity, magnetic_field, divergence_cleaning_field,
enstrophy, vorticity
export entropy, energy_total, energy_kinetic, energy_internal, energy_magnetic,
cross_helicity,
enstrophy, magnetic_field, divergence_cleaning_field, enstrophy_multi_euler, vorticity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
enstrophy, magnetic_field, divergence_cleaning_field, enstrophy_multi_euler, vorticity
enstrophy, magnetic_field, divergence_cleaning_field, enstrophy_multi_euler,
vorticity

export lake_at_rest_error
export ncomponents, eachcomponent

Expand Down
133 changes: 129 additions & 4 deletions src/callbacks_step/analysis_dg2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,135 @@ function integrate(func::Func, u,
UnstructuredMesh2D, P4estMesh{2}, P4estMeshView{2},
T8codeMesh{2}},
equations, dg::DG, cache; normalize = true) where {Func}
integrate_via_indices(u, mesh, equations, dg, cache;
normalize = normalize) do u, i, j, element, equations, dg
u_local = get_node_vars(u, equations, dg, i, j, element)
return func(u_local, equations)
@unpack boundaries = cache
m = methods(func)
if (m[1].nargs == 2) || (func == cons2cons)
return integrate_via_indices(u, mesh, equations, dg, cache;
normalize = normalize) do u, i, j, element,
equations, dg
u_local = get_node_vars(u, equations, dg, i, j, element)

func(u_local, equations)
end
end
if (m[1].nargs == 4) && (func != cons2cons)
gradients_x = DGSpaceDerivative_WeakForm!(dg, cache, u, 1, equations, mesh)
gradients_y = DGSpaceDerivative_WeakForm!(dg, cache, u, 2, equations, mesh)
return integrate_via_indices(u, mesh, equations, dg, cache;
normalize = normalize) do u, i, j, element,
equations, dg
u_local = get_node_vars(u, equations, dg, i, j, element)
gradients_local = Vector([gradients_x[:, i, j, element], gradients_y[:, i, j, element]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
gradients_local = Vector([gradients_x[:, i, j, element], gradients_y[:, i, j, element]])
gradients_local = Vector([
gradients_x[:, i, j, element],
gradients_y[:, i, j, element]
])


func(u_local, gradients_local, equations)
end
end
end

# Return the derivatives of the interpolatied polynomial.
function lagrange_derivatives(x, y)
n = length(x)
dydx = zeros(n)

for i in 1:n
for j in 1:n
if i != j
term = y[j] / (x[i] - x[j])
for k in 1:n
if k != i && k != j
term *= (x[i] - x[k]) / (x[j] - x[k])
end
end
dydx[i] += term
end
end
end

return dydx
end

# Andrew's functions for computing the derivatives.
function DGSpaceDerivative_WeakForm!(dg,
cache,
u,
direction::Int,
equations,
mesh)
# Get the required variables.
@unpack derivative_dhat, weights = dg.basis

# Compute the surface flux terms.
surface_flux_values = similar(u)
Trixi.calc_surface_integral!(surface_flux_values, u, mesh, equations, dg.surface_integral, dg, cache)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
Trixi.calc_surface_integral!(surface_flux_values, u, mesh, equations, dg.surface_integral, dg, cache)
Trixi.calc_surface_integral!(surface_flux_values, u, mesh, equations,
dg.surface_integral, dg, cache)


# Translations.
D = derivative_dhat
spA_Dhat = D

n_vars, Np, _, n_elements = size(u)
gradients = similar(u)

u_local = zeros((n_vars, Np, Np))

if direction == 1
for elem in 1:n_elements
# We work in primitive variables here.
for i in 1:Np
for j in 1:Np
u_local[:, i, j] = cons2prim(u[:, i, j, elem], equations)
end
end
# Volume contributions (weak form)
for v in 1:n_vars
# Interpolate polynomial.
for j in 1:Np
x = cache.elements.node_coordinates[1, :, j, elem]
y = u_local[v, :, j]
gradients[v, :, j, elem] .= lagrange_derivatives(x, y)
end

# # Contract D in the ξ̂ (first spatial) direction
# gradients[v, :, :, elem] .= D * u[v, :, :, elem]
# # Average over element.
Comment on lines +336 to +338
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# # Contract D in the ξ̂ (first spatial) direction
# gradients[v, :, :, elem] .= D * u[v, :, :, elem]
# # Average over element.
# # Contract D in the ξ̂ (first spatial) direction
# gradients[v, :, :, elem] .= D * u[v, :, :, elem]
# # Average over element.


average = sum(gradients[v, :, :, elem]/Np^2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
average = sum(gradients[v, :, :, elem]/Np^2)
average = sum(gradients[v, :, :, elem] / Np^2)

gradients[v, :, :, elem] .= average
end
end
elseif direction == 2
for elem in 1:n_elements
# We work in primitive variables here.
for i in 1:Np
for j in 1:Np
u_local[:, i, j] = cons2prim(u[:, i, j, elem], equations)
end
end
# Volume contributions (weak form)
for v in 1:n_vars
# Interpolate polynomial.
for i in 1:Np
x = cache.elements.node_coordinates[2, i, :, elem]
y = u_local[v, i, :]
gradients[v, i, :, elem] .= lagrange_derivatives(x, y)
end

# # Contract D in the ξ̂ (first spatial) direction
# gradients[v, :, :, elem] .= u[v, :, :, elem] * D'
Comment on lines +361 to +362
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# # Contract D in the ξ̂ (first spatial) direction
# gradients[v, :, :, elem] .= u[v, :, :, elem] * D'
# # Contract D in the ξ̂ (first spatial) direction
# gradients[v, :, :, elem] .= u[v, :, :, elem] * D'


# Average over element.
average = sum(gradients[v, :, :, elem]/Np^2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
average = sum(gradients[v, :, :, elem]/Np^2)
average = sum(gradients[v, :, :, elem] / Np^2)

gradients[v, :, :, elem] .= average
end
end
end

return gradients
end

function compute_flux_array!(Flux, u, direction, equations)
Np, nvars = size(Flux)
for i in 1:Np
Flux[i, :] .= flux(u[i, :], 1, direction, equations)
end
end

Expand Down
18 changes: 18 additions & 0 deletions src/equations/compressible_euler_multicomponent_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -979,4 +979,22 @@ end
v = u[orientation] / rho
return v
end

@inline function enstrophy_multi_euler(u, gradients,
equations::CompressibleEulerMulticomponentEquations2D)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
equations::CompressibleEulerMulticomponentEquations2D)
equations::CompressibleEulerMulticomponentEquations2D)

# Enstrophy is 0.5 rho ω⋅ω where ω = ∇ × v

omega = vorticity(u, gradients, equations)

return 0.5f0 * omega^2
end

@inline function vorticity(u, gradients,
equations::CompressibleEulerMulticomponentEquations2D)
# Ensure that we have velocity `gradients` by way of the `convert_gradient_variables` function.
dv1dx, dv2dx = gradients[1][1:2]
dv1dy, dv2dy = gradients[2][1:2]

return dv2dx - dv1dy
end
end # @muladd
Loading