Skip to content

Commit

Permalink
working trixi_include
Browse files Browse the repository at this point in the history
  • Loading branch information
svchb committed Nov 24, 2023
1 parent 5f4a925 commit ad42394
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/fluid/dam_break_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ semi = Semidiscretization(fluid_system, boundary_system,
neighborhood_search=GridNeighborhoodSearch)
ode = semidiscretize(semi, tspan)

info_callback = InfoCallback(interval=100)
info_callback = InfoCallback(interval=250)
saving_callback = SolutionSavingCallback(dt=0.02, prefix="")

use_reinit = false
Expand Down
27 changes: 19 additions & 8 deletions examples/fluid/dam_break_2d_corrections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ correction_dict = Dict(
"kernel_gradient_summation_correction" => KernelGradientCorrection(),
"kernel_gradient_continuity_correction" => KernelGradientCorrection(),
"blended_gradient_summation_correction" => BlendedGradientCorrection(0.5),
"blended_gradient_continuity_correction" => BlendedGradientCorrection(0.1),
"blended_gradient_continuity_correction" => BlendedGradientCorrection(0.25),
)

density_calculator_dict = Dict(
Expand All @@ -43,12 +43,23 @@ smoothing_kernel_dict = Dict(
"blended_gradient_continuity_correction" => WendlandC2Kernel{2}(),
)

trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "dam_break_2d.jl"),
fluid_particle_spacing=particle_spacing, smoothing_length=smoothing_length,
boundary_density_calculator=ContinuityDensity(),
fluid_density_calculator=ContinuityDensity(),
correction=Nothing(), use_reinit=true,
prefix="continuity_reinit", tspan=tspan)
# begin
# trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "dam_break_2d.jl"),
# fluid_particle_spacing=particle_spacing, smoothing_length=smoothing_length,
# boundary_density_calculator=ContinuityDensity(),
# fluid_density_calculator=ContinuityDensity(),
# correction=Nothing(), use_reinit=false,
# prefix="continuity_reinit", tspan=tspan)
# end

begin
mod = trixi_include_safe(joinpath(examples_dir(), "fluid", "dam_break_2d.jl"),
fluid_particle_spacing=particle_spacing, smoothing_length=smoothing_length,
boundary_density_calculator=ContinuityDensity(),
fluid_density_calculator=ContinuityDensity(),
correction=Nothing(), use_reinit=true,
prefix="continuity_reinit", tspan=tspan)
end

# Clip negative pressure to be able to use `SummationDensity`
state_equation = StateEquationCole(sound_speed, 7, fluid_density, atmospheric_pressure,
Expand All @@ -63,7 +74,7 @@ for correction_name in keys(correction_dict)
println("="^100)
println("fluid/dam_break_2d.jl with ", correction_name)

trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "dam_break_2d.jl"),
trixi_include_safe(joinpath(examples_dir(), "fluid", "dam_break_2d.jl"),
fluid_particle_spacing=particle_spacing,
smoothing_length=smoothing_length,
boundary_density_calculator=boundary_density_calculator,
Expand Down
2 changes: 1 addition & 1 deletion src/TrixiParticles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export BoundaryModelMonaghanKajtar, BoundaryModelDummyParticles, AdamiPressureEx
PressureMirroring, PressureZeroing
export BoundaryMovement
export GridNeighborhoodSearch
export examples_dir, trixi_include
export examples_dir, trixi_include, trixi_include_safe
export trixi2vtk
export RectangularTank, RectangularShape, SphereShape
export VoxelSphere, RoundSphere, reset_wall!
Expand Down
25 changes: 25 additions & 0 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,31 @@ end

trixi_include(elixir::AbstractString; kwargs...) = trixi_include(Main, elixir; kwargs...)

function trixi_include_safe(file_path; kwargs...)
# Read and parse the file's content
code = read(file_path, 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

# Modify the expression (AST) by replacing assignments with values from kwargs
expr = replace_assignments(expr; kwargs...)

# Create a new isolated module
isolated_mod = Module(Symbol("IsolatedExecution$(rand(UInt64))"))

# Evaluate the modified expression in the context of the isolated module
Base.eval(isolated_mod, expr)

return isolated_mod
end


# Helper methods used in the functions defined above, also copied from Trixi.jl

# Apply the function `f` to `expr` and all sub-expressions recursively.
Expand Down

0 comments on commit ad42394

Please sign in to comment.