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

Coefficients in vector equations can't be scalar #919

Open
guyer opened this issue Apr 26, 2023 · 0 comments
Open

Coefficients in vector equations can't be scalar #919

guyer opened this issue Apr 26, 2023 · 0 comments
Labels

Comments

@guyer
Copy link
Member

guyer commented Apr 26, 2023

A DiffusionTerm cannot have a scalar diffusion coefficient if the solution variable is a vector. E.g.,

import fipy as fp

mesh = fp.Grid2D(nx=10, ny=10)
vec = fp.CellVariable(mesh=mesh, name="vec", rank=1, hasOld=True)

D = 1

eq = fp.TransientTerm(var=vec) == fp.DiffusionTerm(coeff=D, var=vec)
eq.solve(dt=1)

raises

IndexError: boolean index did not match indexed array along dimension 0; dimension is 180 but corresponding boolean dimension is 720

This can be remedied by changing to

eq = fp.TransientTerm(var=vec) == fp.DiffusionTerm(coeff=[[[D, 0],
                                                           [0, D]]], var=vec)

Note: Similarly, it's necessary to write

fp.ConvectionTerm(coeff=[[[1, 0],
                          [0, 1]], 
                         [[2, 0],
                          [0, 2]]], var=vec)

instead of

fp.ConvectionTerm(coeff=[[1],
                         [2]], var=vec)

Note: While it is acceptable to write

fp.TransientTerm(coeff=[[1, 0],
                        [0, 1]], var=vec)

it is not required. It should also be possible to pass scalar D.

@guyer guyer added the terms label Apr 26, 2023
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

1 participant