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

Mix-match variables of different dimensions #212

Open
navidcy opened this issue Sep 20, 2020 · 10 comments
Open

Mix-match variables of different dimensions #212

navidcy opened this issue Sep 20, 2020 · 10 comments
Labels

Comments

@navidcy
Copy link
Member

navidcy commented Sep 20, 2020

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)

@glwagner
Copy link
Member

A proper field abstraction might solve this problem.

@navidcy
Copy link
Member Author

navidcy commented Nov 9, 2020

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

@glwagner
Copy link
Member

glwagner commented Nov 9, 2020

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
Copy link
Member

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

function stepforward!(sol, clock, ts::ForwardEulerTimeStepper, eq, vars, params, grid)
eq.calcN!(ts.N, sol, clock.t, clock, vars, params, grid)
@. sol += clock.dt * (eq.L * sol + ts.N)
clock.t += clock.dt
clock.step += 1
return nothing
end

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

@navidcy
Copy link
Member Author

navidcy commented Nov 18, 2020

so we need to dispatch separately for every time stepper?

@glwagner
Copy link
Member

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

@glwagner
Copy link
Member

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.

@navidcy
Copy link
Member Author

navidcy commented Nov 18, 2020

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

@glwagner
Copy link
Member

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.

@navidcy
Copy link
Member Author

navidcy commented Nov 18, 2020

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

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

No branches or pull requests

2 participants