zwicker-group / py-pde

Python package for solving partial differential equations using finite differences.
https://py-pde.readthedocs.io
MIT License
411 stars 52 forks source link

Add static fields to mpi execution #336

Closed yohad closed 1 year ago

yohad commented 1 year ago

Hi,

I want to be able to add a scalar field that is unchange during simulation (like a forcing field). Currently, I add the field to the problem variables and make the time rate 0 always, to be able to use MPI as it splice the fields.

Is there currently a way to do that splicing myself?

david-zwicker commented 1 year ago

Thanks for the report. You're correct that the splicing is not done automatically for constants so far. Do you use the PDE class with expressions or do you inherit from PDEBase to write your own implementation? I guess the solutions in the two cases will look different.

yohad commented 1 year ago

I implement my own class inheriting PDEBase

david-zwicker commented 1 year ago

I just updated the master branch of the package to fix the problem you described for the PDE class and to also give you a more convenient way to split the field onto the sub grids in an MPI simulation. Given a field field on the full grid, you should now be able to run subfield = field.split_mpi(decomposition=...) to split the full field into subfields. Here, the decomposition needs to be the same as the one that you're later using when running the simulation. Let me know if anything is unclear!