FourierFlows.jl icon indicating copy to clipboard operation
FourierFlows.jl copied to clipboard

Mix-match variables of different dimensions

Open navidcy opened this issue 5 years ago • 10 comments

We should have the ability to solve coupled equations that involve variables of different dimensionality.

E.g., variables φ₁(x, t), φ₂(x, y, t) that evolve under

∂φ₁/∂t = - φ₁ + ∫φ₂(x, y', t) dy ∂φ₂/∂t = - φ₂ + f(x, y, t)

navidcy avatar Sep 20 '20 00:09 navidcy

A proper field abstraction might solve this problem.

glwagner avatar Sep 21 '20 12:09 glwagner

Should we do it? Do you have the capability @glwagner? Isn't there any good compelling alternative shortcut to that?

navidcy avatar Nov 09 '20 06:11 navidcy

I think it depends on the question here. If you're just trying to use the FourierFlows time-steppers then you don't need a Field abstraction. You could possibly support tuples of variables / RHS for the purpose of time-stepping, and then let module-writers handle broadcasting properly within calcN!.

glwagner avatar Nov 09 '20 11:11 glwagner

As far as I can tell, you can implement support for tuples of solutions by dispatching on the time-stepper, eg:

https://github.com/FourierFlows/FourierFlows.jl/blob/20a68daaa00ffb2d88d95935f6efff4d86e378e7/src/timesteppers.jl#L107-L113

for when sol::NamedTuple.

The difference is between

@. sol += clock.dt * (eq.L * sol + ts.N)

and

for (i, sol) in enumerate(sol_tuple)
    @. sol += clock.dt * (eq.L[i] * sol + ts.N[i])
end

glwagner avatar Nov 18 '20 19:11 glwagner

so we need to dispatch separately for every time stepper?

navidcy avatar Nov 18 '20 19:11 navidcy

I don't know. It seems the simplest solution, unless you can figure out how to "double broadcast" these arithmetic operations.

glwagner avatar Nov 18 '20 20:11 glwagner

Basically you're asking whether you can write an operation so it does the same thing for

a = rand(3, 3)
b = rand(3, 3)
very_general_arithmetic(a, b)

or

c = (x=rand(3, 3), y=rand(3, 3))
d = (x=rand(3, 3), y=rand(3, 3))
very_general_arithmetic(c, d)

such an abstraction is possible for sure. But you'd have to design a new type (not vanilla NamedTuple) and define the appropriate broadcasting behavior using Julia's broadcasting interface to get that to work with existing arithmetic operators, I think.

glwagner avatar Nov 18 '20 20:11 glwagner

OK, dispatching each time stepper would be good enough for now :) I'll draft a PR...

navidcy avatar Nov 18 '20 20:11 navidcy

You also don't have to support every single time-stepper at first. Can support just 1 or 2 and experiment with the interface, and then when we're happy that it makes sense generalize.

glwagner avatar Nov 18 '20 20:11 glwagner

Yes of course! Let's start with sane ForwardEuler :)

navidcy avatar Nov 18 '20 20:11 navidcy