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

refactoring partitioned-heat-conduction/nutils #295

Merged
merged 10 commits into from
Oct 12, 2022

Conversation

gertjanvanzwieten
Copy link
Collaborator

Some suggested changes to the heat.py script to make it more efficient, more correct, and hopefully easier to read, while remaining backwards compatible with nutils 6 as well as forwards compatible with nutils 8. The commit messages explain the reasoning behind the individual modifications.

This patch removes the leading dashes for cli arguments in the run script,
which were always optional but have recently been forbidden. The changes are
compatible with all versions of nutils.
This patch disables rich output by default, in order for standard output
logging to co-exist nicely with precice's log messages.
This patch removes the droptol argument in the projection of the initial
condition, which is a full domain projection that should include all degrees of
freedom.
This patch simplifies the boundary constraints by using uexact.
This patch replaces sample.asfunction by sample.basis combined with an argument
for readdata. While both constructions yield the same object internally
(asfunction uses basis under the hood), the new form makes it possible to
construct functionals ahead of time and benefit from cached data structures,
rather that recreate them at every iteration (see next commit).
@IshaanDesai
Copy link
Member

Thanks for the refactoring @gertjanvanzwieten! Is this ready for reviewing?

@gertjanvanzwieten
Copy link
Collaborator Author

I noticed that autopep8 isn't happy, in part because of the double space indent on line 101 to avoid double indentation of 103-149, but I can make it compliant if you prefer. Otherwise it's ready for review!

@gertjanvanzwieten
Copy link
Collaborator Author

Please be aware that Nutils may trigger an issue unrelated to this PR that we are currently in the process of fixing. The problem is exacerbated in the development version but exists in stable as well, unnoticed until now.

Copy link
Member

@IshaanDesai IshaanDesai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the refactoring! I also learnt quite a lot of new things in Python just by looking at your code 😄 I only have some minor comments about the code.

This patch defines res and sqr outside the time loop, so that the only things
changing per timestep are the arguments (including readdata). The resulting
code is both cleaner and faster due to reuse of cached structures.
This patch simplifies the read and write instructions by sticking the arguments
inside functools.partial, leaving a more readable remainder of the code.
This patch replaces the projection matrix by a functional based equivalent that
is a bit more ideomatic nutils. It also fixes a consistency issue at the ends
of the boundary and adds an elaborate comment to explain the construction.
This patch bundles the checkpointed state in a single `checkpoint' tuple and
unifies output if the initial condition and following time steps.
This patch makes all parameters into arguments of main so that they can be
configured from the command line (though not via run.sh). This makes it
possible, for example, to experiment with different timesteps on either half of
the simulation.
@gertjanvanzwieten
Copy link
Collaborator Author

I removed the shifted domain (which was not compatible with the non-nutils implementations of this tutorial that I completely forgot about) and the nested loop, so I'm hoping the new version fixes the remaining issues of this PR.

Copy link
Member

@IshaanDesai IshaanDesai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the changes and also catching the incompatibility, it totally slipped my view too. Just a minor suggestion regarding the main time loop.

@IshaanDesai IshaanDesai merged commit 43659aa into precice:develop Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants