Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should trixi_include work recursively? #37

Open
efaulhaber opened this issue Jan 16, 2025 · 2 comments
Open

Should trixi_include work recursively? #37

efaulhaber opened this issue Jan 16, 2025 · 2 comments

Comments

@efaulhaber
Copy link
Member

efaulhaber commented Jan 16, 2025

Trixi.jl example simulations contain a lot of duplicate code because many elixirs are almost identical.
In TrixiParticles.jl, we tried to avoid this by recursively calling trixi_include.
For example, we have a 3D version of a 2D example file, which looks like this:

using TrixiParticles

trixi_include(@__MODULE__,
              joinpath(examples_dir(), "fluid", "hydrostatic_water_column_2d.jl"),
              fluid_particle_spacing=0.05, initial_fluid_size=(1.0, 1.0, 0.9),
              tank_size=(1.0, 1.0, 1.2), acceleration=(0.0, 0.0, -9.81),
              smoothing_kernel=SchoenbergCubicSplineKernel{3}(), tspan=(0.0, 1.0),
              maxiters=10^5, fluid_density_calculator=ContinuityDensity(),
              clip_negative_pressure=false)

In this case, defining 3D fluid and tank sizes, 3D acceleration and a 3D kernel are necessary to make the simulation 3D.
The other kwargs fluid_particle_spacing, tspan, maxiters, fluid_density_calculator and clip_negative_pressure are defining the same values as in the 2D file. We only added them to be able to overwrite these assignments when including the 3D file:

trixi_include(file_3d, fluid_particle_spacing=0.02)

It would be very convenient to either

  1. make trixi_include recursive,
  2. add an option trixi_include(..., recursive = true), or
  3. add a macro trixi_include_recursive.

Option 2 conflicts with overwriting assignments with the same name recursive.
Option 3 is a bit awkward.
Is there any reason against option 1?

I already implemented the logic for a recursive macro in #35.

@sloede
Copy link
Member

sloede commented Jan 16, 2025

What's the disadvantage of option 1 - at least I cannot see anything.

Trixi.jl example simulations contain a lot of duplicate code because many elixirs are almost identical.

This is by design. Each elixir should be downloadable by the user as is, modified (in a semantically correct way of course), and then be able to run. There are, of course, downsides to this approach: as you correctly pointed out, we have a lot of redundancy.

@ranocha
Copy link
Member

ranocha commented Jan 16, 2025

I agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants