trixi-framework / TrixiParticles.jl

TrixiParticles.jl: Particle-based multiphysics simulations in Julia
https://trixi-framework.github.io/TrixiParticles.jl/
MIT License
33 stars 10 forks source link

Move fields that are only sometimes needed to the cache? #676

Open efaulhaber opened 1 day ago

efaulhaber commented 1 day ago

Okay, how about this? We reduce fields to the minimum, and everything that is only needed when some method is used goes to the cache. Then we define

@inline function color(system)
    @assert haskey(system.cache, :color) "`color` of a `$(nameof(typeof(system)))` accessed, but there is no color method defined for this system"
    return system.cache.color
end

We could do the same for example with buffer, which is only needed by open boundaries and set to nothing in most simulations. I think this could make the system structs more readable. What do you think, @LasNikas?

_Originally posted by @efaulhaber in https://github.com/trixi-framework/TrixiParticles.jl/pull/539#discussion_r1856702070_

LasNikas commented 1 day ago

Yes, that's a good idea. Also, the constructor of the systems is starting to grow with argument error checking and creating caches etc. Should we discuss a solution for this as well? I was thinking of something like in Semidiscretization with the check_configuration. It's clear and doesn't mess the constructor.

efaulhaber commented 16 hours ago

Yes, check_configuration is a good idea for the systems as well. I suggested earlier that we add a kwarg techniques or so to be used as follows.

WeaklyCompressibleSPHSystem(..., techniques=(DensityDiffusionMolteniColagrossi(delta=0.1),
                                             KernelGradientCorrection(),
                                             TransportVelocityFormulation())

Most of our current kwargs are optional techniques to improve simulations.