From 8e9c127e4e7f020dd4c859b76f5e5e622ccfa11a Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 6 Feb 2024 13:41:01 +0100 Subject: [PATCH 01/11] Use `trixi_include` from TrixiBase.jl --- Project.toml | 1 + src/Trixi.jl | 3 +- src/auxiliary/precompile.jl | 3 - src/auxiliary/special_elixirs.jl | 52 ----------------- test/test_unit.jl | 97 -------------------------------- 5 files changed, 3 insertions(+), 153 deletions(-) diff --git a/Project.toml b/Project.toml index e99b08e0e81..c8c58b4791c 100644 --- a/Project.toml +++ b/Project.toml @@ -45,6 +45,7 @@ TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344" TriplotBase = "981d1d27-644d-49a2-9326-4793e63143c3" TriplotRecipes = "808ab39a-a642-4abf-81ff-4cb34ebbffa3" +TrixiBase = "9a0f1c46-06d5-4909-a5a3-ce25d3fa3284" [weakdeps] Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" diff --git a/src/Trixi.jl b/src/Trixi.jl index 8d74fbc9736..74925a41a37 100644 --- a/src/Trixi.jl +++ b/src/Trixi.jl @@ -70,6 +70,7 @@ using Triangulate: Triangulate, TriangulateIO, triangulate export TriangulateIO # for type parameter in DGMultiMesh using TriplotBase: TriplotBase using TriplotRecipes: DGTriPseudocolor +@reexport using TrixiBase: trixi_include @reexport using SimpleUnPack: @unpack using SimpleUnPack: @pack! using DataStructures: BinaryHeap, FasterForward, extract_all! @@ -129,7 +130,7 @@ include("callbacks_step/callbacks_step.jl") include("callbacks_stage/callbacks_stage.jl") include("semidiscretization/semidiscretization_euler_gravity.jl") -# `trixi_include` and special elixirs such as `convergence_test` +# Special elixirs such as `convergence_test` include("auxiliary/special_elixirs.jl") # Plot recipes and conversion functions to visualize results with Plots.jl diff --git a/src/auxiliary/precompile.jl b/src/auxiliary/precompile.jl index 9cec502f6cb..4d5399b5ba3 100644 --- a/src/auxiliary/precompile.jl +++ b/src/auxiliary/precompile.jl @@ -577,9 +577,6 @@ function _precompile_manual_() @assert Base.precompile(Tuple{typeof(show), Base.TTY, lbm_collision_callback_type}) @assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY}, MIME"text/plain", lbm_collision_callback_type}) - - # infrastructure, special elixirs - @assert Base.precompile(Tuple{typeof(trixi_include), String}) end @assert Base.precompile(Tuple{typeof(init_mpi)}) diff --git a/src/auxiliary/special_elixirs.jl b/src/auxiliary/special_elixirs.jl index 5fdd9aea0c5..6cfde6a8844 100644 --- a/src/auxiliary/special_elixirs.jl +++ b/src/auxiliary/special_elixirs.jl @@ -5,58 +5,6 @@ @muladd begin #! format: noindent -# Note: We can't call the method below `Trixi.include` since that is created automatically -# inside `module Trixi` to `include` source files and evaluate them within the global scope -# of `Trixi`. However, users will want to evaluate in the global scope of `Main` or something -# similar to manage dependencies on their own. -""" - trixi_include([mod::Module=Main,] elixir::AbstractString; kwargs...) - -`include` the file `elixir` and evaluate its content in the global scope of module `mod`. -You can override specific assignments in `elixir` by supplying keyword arguments. -It's basic purpose is to make it easier to modify some parameters while running Trixi.jl from the -REPL. Additionally, this is used in tests to reduce the computational burden for CI while still -providing examples with sensible default values for users. - -Before replacing assignments in `elixir`, the keyword argument `maxiters` is inserted -into calls to `solve` and `Trixi.solve` with it's default value used in the SciML ecosystem -for ODEs, see the "Miscellaneous" section of the -[documentation](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/). - -# Examples - -```jldoctest -julia> redirect_stdout(devnull) do - trixi_include(@__MODULE__, joinpath(examples_dir(), "tree_1d_dgsem", "elixir_advection_extended.jl"), - tspan=(0.0, 0.1)) - sol.t[end] - end -[ Info: You just called `trixi_include`. Julia may now compile the code, please be patient. -0.1 -``` -""" -function trixi_include(mod::Module, elixir::AbstractString; kwargs...) - # Check that all kwargs exist as assignments - code = read(elixir, String) - expr = Meta.parse("begin \n$code \nend") - expr = insert_maxiters(expr) - - for (key, val) in kwargs - # This will throw an error when `key` is not found - find_assignment(expr, key) - end - - # Print information on potential wait time only in non-parallel case - if !mpi_isparallel() - @info "You just called `trixi_include`. Julia may now compile the code, please be patient." - end - Base.include(ex -> replace_assignments(insert_maxiters(ex); kwargs...), mod, elixir) -end - -function trixi_include(elixir::AbstractString; kwargs...) - trixi_include(Main, elixir; kwargs...) -end - """ convergence_test([mod::Module=Main,] elixir::AbstractString, iterations; kwargs...) diff --git a/test/test_unit.jl b/test/test_unit.jl index 7943d952f71..3b8dc3c4331 100644 --- a/test/test_unit.jl +++ b/test/test_unit.jl @@ -1529,103 +1529,6 @@ end @test mesh.boundary_faces[:entire_boundary] == [1, 2] end - -@testset "trixi_include" begin - @trixi_testset "Basic" begin - example = """ - x = 4 - """ - - filename = tempname() - try - open(filename, "w") do file - write(file, example) - end - - # Use `@trixi_testset`, which wraps code in a temporary module, and call - # `trixi_include` with `@__MODULE__` in order to isolate this test. - @test_warn "You just called" trixi_include(@__MODULE__, filename) - @test @isdefined x - @test x == 4 - - @test_warn "You just called" trixi_include(@__MODULE__, filename, x = 7) - @test x == 7 - - @test_throws "assignment `y` not found in expression" trixi_include(@__MODULE__, - filename, - y = 3) - finally - rm(filename, force = true) - end - end - - @trixi_testset "With `solve` Without `maxiters`" begin - # `trixi_include` assumes this to be the `solve` function of OrdinaryDiffEq, - # and therefore tries to insert the kwarg `maxiters`, which will fail here. - example = """ - solve() = 0 - x = solve() - """ - - filename = tempname() - try - open(filename, "w") do file - write(file, example) - end - - # Use `@trixi_testset`, which wraps code in a temporary module, and call - # `trixi_include` with `@__MODULE__` in order to isolate this test. - @test_throws "no method matching solve(; maxiters::Int64)" trixi_include(@__MODULE__, - filename) - - @test_throws "no method matching solve(; maxiters::Int64)" trixi_include(@__MODULE__, - filename, - maxiters = 3) - finally - rm(filename, force = true) - end - end - - @trixi_testset "With `solve` with `maxiters`" begin - # We need another example file that we include with `Base.include` first, in order to - # define the `solve` method without `trixi_include` trying to insert `maxiters` kwargs. - # Then, we can test that `trixi_include` inserts the kwarg in the `solve()` call. - example1 = """ - solve(; maxiters=0) = maxiters - """ - - example2 = """ - x = solve() - """ - - filename1 = tempname() - filename2 = tempname() - try - open(filename1, "w") do file - write(file, example1) - end - open(filename2, "w") do file - write(file, example2) - end - - # Use `@trixi_testset`, which wraps code in a temporary module, and call - # `Base.include` and `trixi_include` with `@__MODULE__` in order to isolate this test. - Base.include(@__MODULE__, filename1) - @test_warn "You just called" trixi_include(@__MODULE__, filename2) - @test @isdefined x - # This is the default `maxiters` inserted by `trixi_include` - @test x == 10^5 - - @test_warn "You just called" trixi_include(@__MODULE__, filename2, - maxiters = 7) - # Test that `maxiters` got overwritten - @test x == 7 - finally - rm(filename1, force = true) - rm(filename2, force = true) - end - end -end end end #module From 881bb3537d0405482af66657390b640867298509 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:24:23 +0100 Subject: [PATCH 02/11] Add compat entry for TrixiBase.jl --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index c8c58b4791c..a595d5c1554 100644 --- a/Project.toml +++ b/Project.toml @@ -96,6 +96,7 @@ TimerOutputs = "0.5.7" Triangulate = "2.0" TriplotBase = "0.1" TriplotRecipes = "0.1" +TrixiBase = "0.1" julia = "1.8" [extras] From cefc5e32482d1cd80e6b03765d841369630cfbb6 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:26:20 +0100 Subject: [PATCH 03/11] Remove unused functions --- src/auxiliary/special_elixirs.jl | 71 +------------------------------- 1 file changed, 2 insertions(+), 69 deletions(-) diff --git a/src/auxiliary/special_elixirs.jl b/src/auxiliary/special_elixirs.jl index 6cfde6a8844..1653c529542 100644 --- a/src/auxiliary/special_elixirs.jl +++ b/src/auxiliary/special_elixirs.jl @@ -129,75 +129,8 @@ end walkexpr(f, expr::Expr) = f(Expr(expr.head, (walkexpr(f, arg) for arg in expr.args)...)) walkexpr(f, x) = f(x) -# Insert the keyword argument `maxiters` into calls to `solve` and `Trixi.solve` -# with default value `10^5` if it is not already present. -function insert_maxiters(expr) - maxiters_default = 10^5 - - expr = walkexpr(expr) do x - if x isa Expr - is_plain_solve = x.head === Symbol("call") && x.args[1] === Symbol("solve") - is_trixi_solve = (x.head === Symbol("call") && x.args[1] isa Expr && - x.args[1].head === Symbol(".") && - x.args[1].args[1] === Symbol("Trixi") && - x.args[1].args[2] isa QuoteNode && - x.args[1].args[2].value === Symbol("solve")) - - if is_plain_solve || is_trixi_solve - # Do nothing if `maxiters` is already set as keyword argument... - for arg in x.args - # This detects the case where `maxiters` is set as keyword argument - # without or before a semicolon - if (arg isa Expr && arg.head === Symbol("kw") && - arg.args[1] === Symbol("maxiters")) - return x - end - - # This detects the case where maxiters is set as keyword argument - # after a semicolon - if (arg isa Expr && arg.head === Symbol("parameters")) - # We need to check each keyword argument listed here - for nested_arg in arg.args - if (nested_arg isa Expr && - nested_arg.head === Symbol("kw") && - nested_arg.args[1] === Symbol("maxiters")) - return x - end - end - end - end - - # ...and insert it otherwise. - push!(x.args, Expr(Symbol("kw"), Symbol("maxiters"), maxiters_default)) - end - end - return x - end - - return expr -end - -# Replace assignments to `key` in `expr` by `key = val` for all `(key,val)` in `kwargs`. -function replace_assignments(expr; kwargs...) - # replace explicit and keyword assignments - expr = walkexpr(expr) do x - if x isa Expr - for (key, val) in kwargs - if (x.head === Symbol("=") || x.head === :kw) && - x.args[1] === Symbol(key) - x.args[2] = :($val) - # dump(x) - end - end - end - return x - end - - return expr -end - -# find a (keyword or common) assignment to `destination` in `expr` -# and return the assigned value +# Find a (keyword or common) assignment to `destination` in `expr` +# and return the assigned value. function find_assignment(expr, destination) # declare result to be able to assign to it in the closure local result From dc6c48b1d876e85aae6ade5791719b4b71ce3d82 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:26:50 +0100 Subject: [PATCH 04/11] Use `TrixiBase.walkexpr` --- src/auxiliary/special_elixirs.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/auxiliary/special_elixirs.jl b/src/auxiliary/special_elixirs.jl index 1653c529542..d0bdb26899a 100644 --- a/src/auxiliary/special_elixirs.jl +++ b/src/auxiliary/special_elixirs.jl @@ -125,10 +125,6 @@ end # Helper methods used in the functions defined above -# Apply the function `f` to `expr` and all sub-expressions recursively. -walkexpr(f, expr::Expr) = f(Expr(expr.head, (walkexpr(f, arg) for arg in expr.args)...)) -walkexpr(f, x) = f(x) - # Find a (keyword or common) assignment to `destination` in `expr` # and return the assigned value. function find_assignment(expr, destination) @@ -137,7 +133,7 @@ function find_assignment(expr, destination) found = false # find explicit and keyword assignments - walkexpr(expr) do x + TrixiBase.walkexpr(expr) do x if x isa Expr if (x.head === Symbol("=") || x.head === :kw) && x.args[1] === Symbol(destination) From b050939ca8bcba1773420a4bb7f6f5e67145373e Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:29:10 +0100 Subject: [PATCH 05/11] Fix docs --- docs/src/callbacks.md | 2 +- docs/src/conventions.md | 10 ++++++---- src/auxiliary/special_elixirs.jl | 2 +- src/callbacks_step/trivial.jl | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/src/callbacks.md b/docs/src/callbacks.md index f018bcf7c39..21e934b6278 100644 --- a/docs/src/callbacks.md +++ b/docs/src/callbacks.md @@ -112,7 +112,7 @@ will yield the following plot: * The [`VisualizationCallback`](@ref) can be used for in-situ visualization. See [Visualizing results during a simulation](@ref). * The [`TrivialCallback`](@ref) does nothing and can be used to easily disable some callbacks - via [`trixi_include`](@ref). + via [`trixi_include`](https://trixi-framework.github.io/TrixiBase.jl/stable/reference/#TrixiBase.trixi_include-Tuple{Module,%20AbstractString}). ### Equation-specific callbacks Some callbacks provided by Trixi.jl implement specific features for certain equations: diff --git a/docs/src/conventions.md b/docs/src/conventions.md index dab1b8533a5..e1a41502a35 100644 --- a/docs/src/conventions.md +++ b/docs/src/conventions.md @@ -47,10 +47,12 @@ Trixi.jl is distributed with several examples in the form of elixirs, small Julia scripts containing everything to set up and run a simulation. Working interactively from the Julia REPL with these scripts can be quite convenient while for exploratory research and development of Trixi.jl. For example, you -can use the convenience function [`trixi_include`](@ref) to `include` an elixir -with some modified arguments. To enable this, it is helpful to use a consistent -naming scheme in elixirs, since [`trixi_include`](@ref) can only perform simple -replacements. Some standard variables names are +can use the convenience function +[`trixi_include`](https://trixi-framework.github.io/TrixiBase.jl/stable/reference/#TrixiBase.trixi_include-Tuple{Module,%20AbstractString}) +to `include` an elixir with some modified arguments. To enable this, it is +helpful to use a consistent naming scheme in elixirs, since +[`trixi_include`](https://trixi-framework.github.io/TrixiBase.jl/stable/reference/#TrixiBase.trixi_include-Tuple{Module,%20AbstractString}) +can only perform simple replacements. Some standard variables names are - `polydeg` for the polynomial degree of a solver - `surface_flux` for the numerical flux at surfaces diff --git a/src/auxiliary/special_elixirs.jl b/src/auxiliary/special_elixirs.jl index d0bdb26899a..355f5dfce0a 100644 --- a/src/auxiliary/special_elixirs.jl +++ b/src/auxiliary/special_elixirs.jl @@ -12,7 +12,7 @@ Run `iterations` Trixi.jl simulations using the setup given in `elixir` and comp the experimental order of convergence (EOC) in the ``L^2`` and ``L^\\infty`` norm. In each iteration, the resolution of the respective mesh will be doubled. Additional keyword arguments `kwargs...` and the optional module `mod` are passed directly -to [`trixi_include`](@ref). +to [`trixi_include`](https://trixi-framework.github.io/TrixiBase.jl/stable/reference/#TrixiBase.trixi_include-Tuple{Module,%20AbstractString}). This function assumes that the spatial resolution is set via the keywords `initial_refinement_level` (an integer) or `cells_per_dimension` (a tuple of diff --git a/src/callbacks_step/trivial.jl b/src/callbacks_step/trivial.jl index a55b7d85b13..ab1f2ee6481 100644 --- a/src/callbacks_step/trivial.jl +++ b/src/callbacks_step/trivial.jl @@ -8,8 +8,8 @@ """ TrivialCallback() -A callback that does nothing. This can be useful to disable some callbacks -easily via [`trixi_include`](@ref). +A callback that does nothing. This can be useful to disable some callbacks easily via +[`trixi_include`](https://trixi-framework.github.io/TrixiBase.jl/stable/reference/#TrixiBase.trixi_include-Tuple{Module,%20AbstractString}). """ function TrivialCallback() DiscreteCallback(trivial_callback, trivial_callback, From 0b8fa83ad3a691a501e26b41e7414309ee96dc37 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:23:01 +0100 Subject: [PATCH 06/11] Add TrixiBase.jl API reference --- docs/make.jl | 1 + docs/src/callbacks.md | 2 +- docs/src/conventions.md | 4 ++-- docs/src/reference-trixibase.md | 9 +++++++++ src/auxiliary/special_elixirs.jl | 2 +- src/callbacks_step/trivial.jl | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 docs/src/reference-trixibase.md diff --git a/docs/make.jl b/docs/make.jl index 7fce3b31e24..fb43b712bb2 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -122,6 +122,7 @@ makedocs( "Troubleshooting and FAQ" => "troubleshooting.md", "Reference" => [ "Trixi.jl" => "reference-trixi.md", + "TrixiBase.jl" => "reference-trixibase.md", "Trixi2Vtk.jl" => "reference-trixi2vtk.md" ], "Authors" => "authors.md", diff --git a/docs/src/callbacks.md b/docs/src/callbacks.md index 21e934b6278..f018bcf7c39 100644 --- a/docs/src/callbacks.md +++ b/docs/src/callbacks.md @@ -112,7 +112,7 @@ will yield the following plot: * The [`VisualizationCallback`](@ref) can be used for in-situ visualization. See [Visualizing results during a simulation](@ref). * The [`TrivialCallback`](@ref) does nothing and can be used to easily disable some callbacks - via [`trixi_include`](https://trixi-framework.github.io/TrixiBase.jl/stable/reference/#TrixiBase.trixi_include-Tuple{Module,%20AbstractString}). + via [`trixi_include`](@ref). ### Equation-specific callbacks Some callbacks provided by Trixi.jl implement specific features for certain equations: diff --git a/docs/src/conventions.md b/docs/src/conventions.md index e1a41502a35..4f9e0ec4e67 100644 --- a/docs/src/conventions.md +++ b/docs/src/conventions.md @@ -48,10 +48,10 @@ Julia scripts containing everything to set up and run a simulation. Working interactively from the Julia REPL with these scripts can be quite convenient while for exploratory research and development of Trixi.jl. For example, you can use the convenience function -[`trixi_include`](https://trixi-framework.github.io/TrixiBase.jl/stable/reference/#TrixiBase.trixi_include-Tuple{Module,%20AbstractString}) +[`trixi_include`](@ref) to `include` an elixir with some modified arguments. To enable this, it is helpful to use a consistent naming scheme in elixirs, since -[`trixi_include`](https://trixi-framework.github.io/TrixiBase.jl/stable/reference/#TrixiBase.trixi_include-Tuple{Module,%20AbstractString}) +[`trixi_include`](@ref) can only perform simple replacements. Some standard variables names are - `polydeg` for the polynomial degree of a solver diff --git a/docs/src/reference-trixibase.md b/docs/src/reference-trixibase.md new file mode 100644 index 00000000000..c7a970f88ec --- /dev/null +++ b/docs/src/reference-trixibase.md @@ -0,0 +1,9 @@ +# TrixiBase.jl API + +```@meta +CurrentModule = TrixiBase +``` + +```@autodocs +Modules = [TrixiBase] +``` diff --git a/src/auxiliary/special_elixirs.jl b/src/auxiliary/special_elixirs.jl index 355f5dfce0a..d0bdb26899a 100644 --- a/src/auxiliary/special_elixirs.jl +++ b/src/auxiliary/special_elixirs.jl @@ -12,7 +12,7 @@ Run `iterations` Trixi.jl simulations using the setup given in `elixir` and comp the experimental order of convergence (EOC) in the ``L^2`` and ``L^\\infty`` norm. In each iteration, the resolution of the respective mesh will be doubled. Additional keyword arguments `kwargs...` and the optional module `mod` are passed directly -to [`trixi_include`](https://trixi-framework.github.io/TrixiBase.jl/stable/reference/#TrixiBase.trixi_include-Tuple{Module,%20AbstractString}). +to [`trixi_include`](@ref). This function assumes that the spatial resolution is set via the keywords `initial_refinement_level` (an integer) or `cells_per_dimension` (a tuple of diff --git a/src/callbacks_step/trivial.jl b/src/callbacks_step/trivial.jl index ab1f2ee6481..fb93cf96c0c 100644 --- a/src/callbacks_step/trivial.jl +++ b/src/callbacks_step/trivial.jl @@ -9,7 +9,7 @@ TrivialCallback() A callback that does nothing. This can be useful to disable some callbacks easily via -[`trixi_include`](https://trixi-framework.github.io/TrixiBase.jl/stable/reference/#TrixiBase.trixi_include-Tuple{Module,%20AbstractString}). +[`trixi_include`](@ref). """ function TrivialCallback() DiscreteCallback(trivial_callback, trivial_callback, From f1edd262ed76dbd7ec1994d8a79166393a3223ff Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:36:55 +0100 Subject: [PATCH 07/11] Add TrixiBase to docs dependencies --- docs/Project.toml | 2 ++ docs/make.jl | 1 + 2 files changed, 3 insertions(+) diff --git a/docs/Project.toml b/docs/Project.toml index 3a091f5b4f1..f067a0414f1 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -10,6 +10,7 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Trixi2Vtk = "bc1476a1-1ca6-4cc3-950b-c312b255ff95" +TrixiBase = "9a0f1c46-06d5-4909-a5a3-ce25d3fa3284" [compat] CairoMakie = "0.6, 0.7, 0.8, 0.9, 0.10" @@ -23,3 +24,4 @@ OrdinaryDiffEq = "6.49.1" Plots = "1.9" Test = "1" Trixi2Vtk = "0.3" +TrixiBase = "0.1" diff --git a/docs/make.jl b/docs/make.jl index fb43b712bb2..3dd3f157f68 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -8,6 +8,7 @@ end using Trixi using Trixi2Vtk +using TrixiBase # Get Trixi.jl root directory trixi_root_dir = dirname(@__DIR__) From ef5c96d8c9e9b36a52ea621f05086391778a856f Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:56:58 +0100 Subject: [PATCH 08/11] Import `TrixiBase` --- src/Trixi.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Trixi.jl b/src/Trixi.jl index 74925a41a37..ea72fbc915f 100644 --- a/src/Trixi.jl +++ b/src/Trixi.jl @@ -70,7 +70,7 @@ using Triangulate: Triangulate, TriangulateIO, triangulate export TriangulateIO # for type parameter in DGMultiMesh using TriplotBase: TriplotBase using TriplotRecipes: DGTriPseudocolor -@reexport using TrixiBase: trixi_include +@reexport using TrixiBase: TrixiBase, trixi_include @reexport using SimpleUnPack: @unpack using SimpleUnPack: @pack! using DataStructures: BinaryHeap, FasterForward, extract_all! From e7787f998cb829bb699afff8a90508657a5d365c Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Fri, 9 Feb 2024 08:40:06 +0100 Subject: [PATCH 09/11] Remove `find_assignment` --- src/auxiliary/special_elixirs.jl | 35 +++++--------------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/src/auxiliary/special_elixirs.jl b/src/auxiliary/special_elixirs.jl index d0bdb26899a..d71a27aa96a 100644 --- a/src/auxiliary/special_elixirs.jl +++ b/src/auxiliary/special_elixirs.jl @@ -125,41 +125,15 @@ end # Helper methods used in the functions defined above -# Find a (keyword or common) assignment to `destination` in `expr` -# and return the assigned value. -function find_assignment(expr, destination) - # declare result to be able to assign to it in the closure - local result - found = false - - # find explicit and keyword assignments - TrixiBase.walkexpr(expr) do x - if x isa Expr - if (x.head === Symbol("=") || x.head === :kw) && - x.args[1] === Symbol(destination) - result = x.args[2] - found = true - # dump(x) - end - end - return x - end - - if !found - throw(ArgumentError("assignment `$destination` not found in expression")) - end - - result -end - -# searches the parameter that specifies the mesh reslution in the elixir +# Searches for the assignment that specifies the mesh resolution in the elixir function extract_initial_resolution(elixir, kwargs) code = read(elixir, String) expr = Meta.parse("begin \n$code \nend") try # get the initial_refinement_level from the elixir - initial_refinement_level = find_assignment(expr, :initial_refinement_level) + initial_refinement_level = TrixiBase.find_assignment(expr, + :initial_refinement_level) if haskey(kwargs, :initial_refinement_level) return kwargs[:initial_refinement_level] @@ -171,7 +145,8 @@ function extract_initial_resolution(elixir, kwargs) if isa(e, ArgumentError) try # get cells_per_dimension from the elixir - cells_per_dimension = eval(find_assignment(expr, :cells_per_dimension)) + cells_per_dimension = eval(TrixiBase.find_assignment(expr, + :cells_per_dimension)) if haskey(kwargs, :cells_per_dimension) return kwargs[:cells_per_dimension] From efd7fbd7ee1ae28d4bdf257e8f7a8af17a57f728 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:03:11 +0100 Subject: [PATCH 10/11] Add TrixiBase to makedocs modules --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 82c5251ced2..946b803b71e 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -83,7 +83,7 @@ tutorials = create_tutorials(files) # Make documentation makedocs( # Specify modules for which docstrings should be shown - modules = [Trixi, Trixi2Vtk], + modules = [Trixi, TrixiBase, Trixi2Vtk], # Set sitename to Trixi.jl sitename = "Trixi.jl", # Provide additional formatting options From c6066e3c1147374dc914df2ce63e95a9266347f6 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Thu, 15 Feb 2024 07:53:48 +0100 Subject: [PATCH 11/11] Apply suggestions from code review Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com> --- Project.toml | 2 +- docs/Project.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index f2e9ac65ef2..b4a06a70688 100644 --- a/Project.toml +++ b/Project.toml @@ -96,7 +96,7 @@ TimerOutputs = "0.5.7" Triangulate = "2.0" TriplotBase = "0.1" TriplotRecipes = "0.1" -TrixiBase = "0.1" +TrixiBase = "0.1.1" julia = "1.8" [extras] diff --git a/docs/Project.toml b/docs/Project.toml index ffc908251bf..3b8d169fdb8 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -24,4 +24,4 @@ OrdinaryDiffEq = "6.49.1" Plots = "1.9" Test = "1" Trixi2Vtk = "0.3" -TrixiBase = "0.1" +TrixiBase = "0.1.1"