From fd5d7ae5eda9f4f88aa1dc153462f85cf2f7398b Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Wed, 28 Aug 2024 10:46:34 -1000 Subject: [PATCH 01/12] start --- Project.toml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index f8be84e0ce3..ffd5bab8e91 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ authors = ["Michael Schlottke-Lakemper ", "Gregor version = "0.8.9-DEV" [deps] +Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" @@ -50,15 +51,16 @@ TrixiBase = "9a0f1c46-06d5-4909-a5a3-ce25d3fa3284" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [weakdeps] -Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" Convex = "f65535da-76fb-5f13-bab9-19810c17039a" ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199" +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" [extensions] -TrixiMakieExt = "Makie" TrixiConvexECOSExt = ["Convex", "ECOS"] +TrixiMakieExt = "Makie" [compat] +Accessors = "0.1.37" CodeTracking = "1.0.5" ConstructionBase = "1.3" Convex = "0.16" @@ -109,6 +111,6 @@ UUIDs = "1.6" julia = "1.8" [extras] -Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" Convex = "f65535da-76fb-5f13-bab9-19810c17039a" ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199" +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" From 0a1d4130d4051d0f7dc1122e3118899502d18f04 Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Wed, 4 Sep 2024 11:41:11 -1000 Subject: [PATCH 02/12] remove compat --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index ffd5bab8e91..2ca53eb51a4 100644 --- a/Project.toml +++ b/Project.toml @@ -60,7 +60,6 @@ TrixiConvexECOSExt = ["Convex", "ECOS"] TrixiMakieExt = "Makie" [compat] -Accessors = "0.1.37" CodeTracking = "1.0.5" ConstructionBase = "1.3" Convex = "0.16" From da8298619066197c16ec4e3ff831aa2bdd121825 Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Wed, 4 Sep 2024 11:59:15 -1000 Subject: [PATCH 03/12] add compat --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 2ca53eb51a4..8bb9667f167 100644 --- a/Project.toml +++ b/Project.toml @@ -60,6 +60,7 @@ TrixiConvexECOSExt = ["Convex", "ECOS"] TrixiMakieExt = "Makie" [compat] +Accessors = "0.1" CodeTracking = "1.0.5" ConstructionBase = "1.3" Convex = "0.16" From ec5f4a758871b867b863d7c624637e320570a93e Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Wed, 4 Sep 2024 12:20:34 -1000 Subject: [PATCH 04/12] compat version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 8bb9667f167..da214b4078d 100644 --- a/Project.toml +++ b/Project.toml @@ -60,7 +60,7 @@ TrixiConvexECOSExt = ["Convex", "ECOS"] TrixiMakieExt = "Makie" [compat] -Accessors = "0.1" +Accessors = "0.1.2" CodeTracking = "1.0.5" ConstructionBase = "1.3" Convex = "0.16" From 7fd910884a4d3bae9d8c09e2ae3a6ca16bee2d25 Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Wed, 4 Sep 2024 12:29:20 -1000 Subject: [PATCH 05/12] test --- Project.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 609b0002a60..4fe63a9137b 100644 --- a/Project.toml +++ b/Project.toml @@ -6,6 +6,7 @@ version = "0.8.9-DEV" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" +Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" @@ -61,7 +62,7 @@ TrixiConvexECOSExt = ["Convex", "ECOS"] TrixiMakieExt = "Makie" [compat] -Accessors = "0.1.2" +Accessors = "0.1.37" CodeTracking = "1.0.5" ConstructionBase = "1.3" Convex = "0.16" From 988ce0a1d8e63462d940466e26a80f00d1b8e815 Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Wed, 4 Sep 2024 17:22:25 -1000 Subject: [PATCH 06/12] apply reset --- Project.toml | 2 -- src/Trixi.jl | 1 + src/callbacks_step/glm_speed.jl | 3 ++- src/equations/ideal_glm_mhd_2d.jl | 8 ++++++-- src/equations/ideal_glm_mhd_3d.jl | 8 ++++++-- src/semidiscretization/semidiscretization_hyperbolic.jl | 8 ++++---- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Project.toml b/Project.toml index 4fe63a9137b..2bd00258529 100644 --- a/Project.toml +++ b/Project.toml @@ -6,7 +6,6 @@ version = "0.8.9-DEV" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" -Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" @@ -62,7 +61,6 @@ TrixiConvexECOSExt = ["Convex", "ECOS"] TrixiMakieExt = "Makie" [compat] -Accessors = "0.1.37" CodeTracking = "1.0.5" ConstructionBase = "1.3" Convex = "0.16" diff --git a/src/Trixi.jl b/src/Trixi.jl index 90fa590c50a..d9b9245918e 100644 --- a/src/Trixi.jl +++ b/src/Trixi.jl @@ -18,6 +18,7 @@ module Trixi # Include other packages that are used in Trixi.jl # (standard library packages first, other packages next, all of them sorted alphabetically) +using Accessors: @reset using LinearAlgebra: LinearAlgebra, Diagonal, diag, dot, mul!, norm, cross, normalize, I, UniformScaling, det using Printf: @printf, @sprintf, println diff --git a/src/callbacks_step/glm_speed.jl b/src/callbacks_step/glm_speed.jl index 8ee406af5f9..07f0dbe5edd 100644 --- a/src/callbacks_step/glm_speed.jl +++ b/src/callbacks_step/glm_speed.jl @@ -83,7 +83,8 @@ function update_cleaning_speed!(semi, glm_speed_callback, dt) c_h_deltat = calc_dt_for_cleaning_speed(cfl, mesh, equations, solver, cache) # c_h is proportional to its own time step divided by the complete MHD time step - equations.c_h = glm_scale * c_h_deltat / dt + @reset equations.c_h = glm_scale * c_h_deltat / dt + semi.equations = equations return semi end diff --git a/src/equations/ideal_glm_mhd_2d.jl b/src/equations/ideal_glm_mhd_2d.jl index ab2a4b066a1..30ba1aa40d5 100644 --- a/src/equations/ideal_glm_mhd_2d.jl +++ b/src/equations/ideal_glm_mhd_2d.jl @@ -11,8 +11,8 @@ The ideal compressible GLM-MHD equations for an ideal gas with ratio of specific heats `gamma` in two space dimensions. """ -mutable struct IdealGlmMhdEquations2D{RealT <: Real} <: - AbstractIdealGlmMhdEquations{2, 9} +struct IdealGlmMhdEquations2D{RealT <: Real} <: + AbstractIdealGlmMhdEquations{2, 9} gamma::RealT # ratio of specific heats inv_gamma_minus_one::RealT # = inv(gamma - 1); can be used to write slow divisions as fast multiplications c_h::RealT # GLM cleaning speed @@ -28,6 +28,10 @@ function IdealGlmMhdEquations2D(gamma; initial_c_h = convert(typeof(gamma), NaN) IdealGlmMhdEquations2D(promote(gamma, initial_c_h)...) end +function IdealGlmMhdEquations2D(gamma, inv_gamma_minus_one, c_h) + IdealGlmMhdEquations2D(gamma, c_h) +end + have_nonconservative_terms(::IdealGlmMhdEquations2D) = True() n_nonconservative_terms(::IdealGlmMhdEquations2D) = 2 diff --git a/src/equations/ideal_glm_mhd_3d.jl b/src/equations/ideal_glm_mhd_3d.jl index 2ffaa575243..9ef09b28a62 100644 --- a/src/equations/ideal_glm_mhd_3d.jl +++ b/src/equations/ideal_glm_mhd_3d.jl @@ -11,8 +11,8 @@ The ideal compressible GLM-MHD equations for an ideal gas with ratio of specific heats `gamma` in three space dimensions. """ -mutable struct IdealGlmMhdEquations3D{RealT <: Real} <: - AbstractIdealGlmMhdEquations{3, 9} +struct IdealGlmMhdEquations3D{RealT <: Real} <: + AbstractIdealGlmMhdEquations{3, 9} gamma::RealT # ratio of specific heats inv_gamma_minus_one::RealT # = inv(gamma - 1); can be used to write slow divisions as fast multiplications c_h::RealT # GLM cleaning speed @@ -28,6 +28,10 @@ function IdealGlmMhdEquations3D(gamma; initial_c_h = convert(typeof(gamma), NaN) IdealGlmMhdEquations3D(promote(gamma, initial_c_h)...) end +function IdealGlmMhdEquations3D(gamma, inv_gamma_minus_one, c_h) + IdealGlmMhdEquations3D(gamma, c_h) +end + have_nonconservative_terms(::IdealGlmMhdEquations3D) = True() function varnames(::typeof(cons2cons), ::IdealGlmMhdEquations3D) ("rho", "rho_v1", "rho_v2", "rho_v3", "rho_e", "B1", "B2", "B3", "psi") diff --git a/src/semidiscretization/semidiscretization_hyperbolic.jl b/src/semidiscretization/semidiscretization_hyperbolic.jl index e35c0e2ea97..6c6aa5b457c 100644 --- a/src/semidiscretization/semidiscretization_hyperbolic.jl +++ b/src/semidiscretization/semidiscretization_hyperbolic.jl @@ -11,10 +11,10 @@ A struct containing everything needed to describe a spatial semidiscretization of a hyperbolic conservation law. """ -struct SemidiscretizationHyperbolic{Mesh, Equations, InitialCondition, - BoundaryConditions, - SourceTerms, Solver, Cache} <: - AbstractSemidiscretization +mutable struct SemidiscretizationHyperbolic{Mesh, Equations, InitialCondition, + BoundaryConditions, + SourceTerms, Solver, Cache} <: + AbstractSemidiscretization mesh::Mesh equations::Equations From fdf7e4518954eb1a348e75bfdffa7f0c50de6287 Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Wed, 4 Sep 2024 18:41:18 -1000 Subject: [PATCH 07/12] multi mhd --- src/equations/ideal_glm_mhd_multicomponent_1d.jl | 8 ++++++-- src/equations/ideal_glm_mhd_multicomponent_2d.jl | 8 ++++++-- src/semidiscretization/semidiscretization_coupled.jl | 6 ++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/equations/ideal_glm_mhd_multicomponent_1d.jl b/src/equations/ideal_glm_mhd_multicomponent_1d.jl index b2ed06e53ea..87f2ae81487 100644 --- a/src/equations/ideal_glm_mhd_multicomponent_1d.jl +++ b/src/equations/ideal_glm_mhd_multicomponent_1d.jl @@ -10,8 +10,8 @@ The ideal compressible multicomponent GLM-MHD equations in one space dimension. """ -mutable struct IdealGlmMhdMulticomponentEquations1D{NVARS, NCOMP, RealT <: Real} <: - AbstractIdealGlmMhdMulticomponentEquations{1, NVARS, NCOMP} +struct IdealGlmMhdMulticomponentEquations1D{NVARS, NCOMP, RealT <: Real} <: + AbstractIdealGlmMhdMulticomponentEquations{1, NVARS, NCOMP} gammas::SVector{NCOMP, RealT} gas_constants::SVector{NCOMP, RealT} cv::SVector{NCOMP, RealT} @@ -51,6 +51,10 @@ function IdealGlmMhdMulticomponentEquations1D(; gammas, gas_constants) __gas_constants) end +function IdealGlmMhdMulticomponentEquations1D(gammas, gas_constants, cv, cp, c_h) + IdealGlmMhdMulticomponentEquations1D(gammas = gammas, gas_constants = gas_constants) +end + @inline function Base.real(::IdealGlmMhdMulticomponentEquations1D{NVARS, NCOMP, RealT}) where { NVARS, NCOMP, diff --git a/src/equations/ideal_glm_mhd_multicomponent_2d.jl b/src/equations/ideal_glm_mhd_multicomponent_2d.jl index 3aab048bd99..7f94d453dea 100644 --- a/src/equations/ideal_glm_mhd_multicomponent_2d.jl +++ b/src/equations/ideal_glm_mhd_multicomponent_2d.jl @@ -10,8 +10,8 @@ The ideal compressible multicomponent GLM-MHD equations in two space dimensions. """ -mutable struct IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT <: Real} <: - AbstractIdealGlmMhdMulticomponentEquations{2, NVARS, NCOMP} +struct IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT <: Real} <: + AbstractIdealGlmMhdMulticomponentEquations{2, NVARS, NCOMP} gammas::SVector{NCOMP, RealT} gas_constants::SVector{NCOMP, RealT} cv::SVector{NCOMP, RealT} @@ -53,6 +53,10 @@ function IdealGlmMhdMulticomponentEquations2D(; gammas, gas_constants) __gas_constants) end +function IdealGlmMhdMulticomponentEquations2D(gammas, gas_constants, cv, cp, c_h) + IdealGlmMhdMulticomponentEquations2D(gammas = gammas, gas_constants = gas_constants) +end + @inline function Base.real(::IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT}) where { NVARS, NCOMP, diff --git a/src/semidiscretization/semidiscretization_coupled.jl b/src/semidiscretization/semidiscretization_coupled.jl index 7c1fbef972b..33ce54504e5 100644 --- a/src/semidiscretization/semidiscretization_coupled.jl +++ b/src/semidiscretization/semidiscretization_coupled.jl @@ -16,7 +16,8 @@ The semidiscretizations can be coupled by gluing meshes together using [`Boundar !!! warning "Experimental code" This is an experimental feature and can change any time. """ -struct SemidiscretizationCoupled{S, Indices, EquationList} <: AbstractSemidiscretization +mutable struct SemidiscretizationCoupled{S, Indices, EquationList} <: + AbstractSemidiscretization semis::S u_indices::Indices # u_ode[u_indices[i]] is the part of u_ode corresponding to semis[i] performance_counter::PerformanceCounter @@ -383,7 +384,8 @@ function update_cleaning_speed!(semi_coupled::SemidiscretizationCoupled, c_h_deltat = calc_dt_for_cleaning_speed(cfl, mesh, equations, solver, cache) # c_h is proportional to its own time step divided by the complete MHD time step - equations.c_h = glm_scale * c_h_deltat / dt + @reset equations.c_h = glm_scale * c_h_deltat / dt + semi.equations = equations end return semi_coupled From 9476b633fa7ca26f81ed68fdd5e3010a714124d3 Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Sun, 8 Sep 2024 22:55:38 -1000 Subject: [PATCH 08/12] add comments and fix errors --- src/equations/ideal_glm_mhd_2d.jl | 1 + src/equations/ideal_glm_mhd_3d.jl | 1 + .../ideal_glm_mhd_multicomponent_1d.jl | 1 + .../ideal_glm_mhd_multicomponent_2d.jl | 34 ++++++++++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/equations/ideal_glm_mhd_2d.jl b/src/equations/ideal_glm_mhd_2d.jl index 30ba1aa40d5..7a6d19facd1 100644 --- a/src/equations/ideal_glm_mhd_2d.jl +++ b/src/equations/ideal_glm_mhd_2d.jl @@ -28,6 +28,7 @@ function IdealGlmMhdEquations2D(gamma; initial_c_h = convert(typeof(gamma), NaN) IdealGlmMhdEquations2D(promote(gamma, initial_c_h)...) end +# Outer constructor for `@reset` works correctly function IdealGlmMhdEquations2D(gamma, inv_gamma_minus_one, c_h) IdealGlmMhdEquations2D(gamma, c_h) end diff --git a/src/equations/ideal_glm_mhd_3d.jl b/src/equations/ideal_glm_mhd_3d.jl index 9ef09b28a62..e922a2e6fd6 100644 --- a/src/equations/ideal_glm_mhd_3d.jl +++ b/src/equations/ideal_glm_mhd_3d.jl @@ -28,6 +28,7 @@ function IdealGlmMhdEquations3D(gamma; initial_c_h = convert(typeof(gamma), NaN) IdealGlmMhdEquations3D(promote(gamma, initial_c_h)...) end +# Outer constructor for `@reset` works correctly function IdealGlmMhdEquations3D(gamma, inv_gamma_minus_one, c_h) IdealGlmMhdEquations3D(gamma, c_h) end diff --git a/src/equations/ideal_glm_mhd_multicomponent_1d.jl b/src/equations/ideal_glm_mhd_multicomponent_1d.jl index 87f2ae81487..86a69e9fe10 100644 --- a/src/equations/ideal_glm_mhd_multicomponent_1d.jl +++ b/src/equations/ideal_glm_mhd_multicomponent_1d.jl @@ -51,6 +51,7 @@ function IdealGlmMhdMulticomponentEquations1D(; gammas, gas_constants) __gas_constants) end +# Outer constructor for `@reset` works correctly function IdealGlmMhdMulticomponentEquations1D(gammas, gas_constants, cv, cp, c_h) IdealGlmMhdMulticomponentEquations1D(gammas = gammas, gas_constants = gas_constants) end diff --git a/src/equations/ideal_glm_mhd_multicomponent_2d.jl b/src/equations/ideal_glm_mhd_multicomponent_2d.jl index 7f94d453dea..3c7a78b0115 100644 --- a/src/equations/ideal_glm_mhd_multicomponent_2d.jl +++ b/src/equations/ideal_glm_mhd_multicomponent_2d.jl @@ -36,6 +36,23 @@ struct IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT <: Real} <: new(gammas, gas_constants, cv, cp, c_h) end + + # Inner constructor for `@reset` works correctly + function IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT}(gammas::SVector{NCOMP, + RealT}, + gas_constants::SVector{NCOMP, + RealT}, + c_h::RealT) where { + NVARS, + NCOMP, + RealT <: + Real + } + cv = gas_constants ./ (gammas .- 1) + cp = gas_constants + gas_constants ./ (gammas .- 1) + + new(gammas, gas_constants, cv, cp, c_h) + end end function IdealGlmMhdMulticomponentEquations2D(; gammas, gas_constants) @@ -53,8 +70,23 @@ function IdealGlmMhdMulticomponentEquations2D(; gammas, gas_constants) __gas_constants) end +# Outer constructor for `@reset` works correctly function IdealGlmMhdMulticomponentEquations2D(gammas, gas_constants, cv, cp, c_h) - IdealGlmMhdMulticomponentEquations2D(gammas = gammas, gas_constants = gas_constants) + _gammas = promote(gammas...) + _gas_constants = promote(gas_constants...) + RealT = promote_type(eltype(_gammas), eltype(_gas_constants)) + + NVARS = length(_gammas) + 8 + NCOMP = length(_gammas) + + __gammas = SVector(map(RealT, _gammas)) + __gas_constants = SVector(map(RealT, _gas_constants)) + + c_h = convert(RealT, c_h) + + return IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT}(__gammas, + __gas_constants, + c_h) end @inline function Base.real(::IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT}) where { From 0a2f00f7ffe7ea7d92d2367d89a3a526d2e67961 Mon Sep 17 00:00:00 2001 From: Huiyu Xie Date: Tue, 10 Sep 2024 21:52:46 -1000 Subject: [PATCH 09/12] Update src/semidiscretization/semidiscretization_coupled.jl Co-authored-by: Hendrik Ranocha --- src/semidiscretization/semidiscretization_coupled.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/semidiscretization/semidiscretization_coupled.jl b/src/semidiscretization/semidiscretization_coupled.jl index 33ce54504e5..745a8d3f6f8 100644 --- a/src/semidiscretization/semidiscretization_coupled.jl +++ b/src/semidiscretization/semidiscretization_coupled.jl @@ -384,6 +384,8 @@ function update_cleaning_speed!(semi_coupled::SemidiscretizationCoupled, c_h_deltat = calc_dt_for_cleaning_speed(cfl, mesh, equations, solver, cache) # c_h is proportional to its own time step divided by the complete MHD time step + # We use @reset here since the equations are immutable (to work on GPUs etc.). + # Thus, we need to modify the equations field of the semidiscretization. @reset equations.c_h = glm_scale * c_h_deltat / dt semi.equations = equations end From faeb8b70722099449a6a3f4cddef5f264abbab14 Mon Sep 17 00:00:00 2001 From: Huiyu Xie Date: Tue, 10 Sep 2024 21:53:04 -1000 Subject: [PATCH 10/12] Update src/callbacks_step/glm_speed.jl Co-authored-by: Hendrik Ranocha --- src/callbacks_step/glm_speed.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/callbacks_step/glm_speed.jl b/src/callbacks_step/glm_speed.jl index 07f0dbe5edd..8eae07e2a74 100644 --- a/src/callbacks_step/glm_speed.jl +++ b/src/callbacks_step/glm_speed.jl @@ -83,6 +83,8 @@ function update_cleaning_speed!(semi, glm_speed_callback, dt) c_h_deltat = calc_dt_for_cleaning_speed(cfl, mesh, equations, solver, cache) # c_h is proportional to its own time step divided by the complete MHD time step + # We use @reset here since the equations are immutable (to work on GPUs etc.). + # Thus, we need to modify the equations field of the semidiscretization. @reset equations.c_h = glm_scale * c_h_deltat / dt semi.equations = equations From 0d11b2e55a952ebdf2ce507b90a7884163f645a3 Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Tue, 10 Sep 2024 22:30:15 -1000 Subject: [PATCH 11/12] minor fix --- .../ideal_glm_mhd_multicomponent_2d.jl | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/equations/ideal_glm_mhd_multicomponent_2d.jl b/src/equations/ideal_glm_mhd_multicomponent_2d.jl index 3c7a78b0115..ba6372b01d4 100644 --- a/src/equations/ideal_glm_mhd_multicomponent_2d.jl +++ b/src/equations/ideal_glm_mhd_multicomponent_2d.jl @@ -18,26 +18,6 @@ struct IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT <: Real} <: cp::SVector{NCOMP, RealT} c_h::RealT # GLM cleaning speed - function IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT}(gammas::SVector{NCOMP, - RealT}, - gas_constants::SVector{NCOMP, - RealT}) where { - NVARS, - NCOMP, - RealT <: - Real - } - NCOMP >= 1 || - throw(DimensionMismatch("`gammas` and `gas_constants` have to be filled with at least one value")) - - cv = gas_constants ./ (gammas .- 1) - cp = gas_constants + gas_constants ./ (gammas .- 1) - c_h = convert(eltype(gammas), NaN) - - new(gammas, gas_constants, cv, cp, c_h) - end - - # Inner constructor for `@reset` works correctly function IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT}(gammas::SVector{NCOMP, RealT}, gas_constants::SVector{NCOMP, @@ -48,8 +28,12 @@ struct IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT <: Real} <: RealT <: Real } + NCOMP >= 1 || + throw(DimensionMismatch("`gammas` and `gas_constants` have to be filled with at least one value")) + cv = gas_constants ./ (gammas .- 1) cp = gas_constants + gas_constants ./ (gammas .- 1) + c_h = convert(eltype(gammas), c_h) new(gammas, gas_constants, cv, cp, c_h) end @@ -67,7 +51,8 @@ function IdealGlmMhdMulticomponentEquations2D(; gammas, gas_constants) __gas_constants = SVector(map(RealT, _gas_constants)) return IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT}(__gammas, - __gas_constants) + __gas_constants, + NaN) end # Outer constructor for `@reset` works correctly From 4357e33f9c35898a25596c9ee91595af6e74917f Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Wed, 11 Sep 2024 00:19:25 -1000 Subject: [PATCH 12/12] fix type --- src/equations/ideal_glm_mhd_multicomponent_2d.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/equations/ideal_glm_mhd_multicomponent_2d.jl b/src/equations/ideal_glm_mhd_multicomponent_2d.jl index ba6372b01d4..5bfdaa8c620 100644 --- a/src/equations/ideal_glm_mhd_multicomponent_2d.jl +++ b/src/equations/ideal_glm_mhd_multicomponent_2d.jl @@ -50,9 +50,11 @@ function IdealGlmMhdMulticomponentEquations2D(; gammas, gas_constants) __gammas = SVector(map(RealT, _gammas)) __gas_constants = SVector(map(RealT, _gas_constants)) + c_h = convert(RealT, NaN) + return IdealGlmMhdMulticomponentEquations2D{NVARS, NCOMP, RealT}(__gammas, __gas_constants, - NaN) + c_h) end # Outer constructor for `@reset` works correctly