make getform work (without DirichletBCs) for DOLFINx#200
Conversation
| from .scheme import ContinuousPetrovGalerkinScheme, DiscontinuousGalerkinScheme | ||
| from .scheme import GalerkinCollocationScheme | ||
|
|
||
| from .stage_derivative import getForm |
There was a problem hiding this comment.
This should not be made public
Co-authored-by: Copilot <copilot@github.com>
|
|
||
|
|
||
| def get_stage_space(V: ufl.FunctionSpace, num_stages: int) -> ufl.FunctionSpace: | ||
| return reduce(mul, (V for _ in range(num_stages))) |
There was a problem hiding this comment.
| return reduce(mul, (V for _ in range(num_stages))) | |
| return firedrake.MixedFunctionSpace(tuple(V) * num_stages) |
| from operator import mul | ||
| from functools import reduce | ||
|
|
There was a problem hiding this comment.
| from operator import mul | |
| from functools import reduce |
| :arg dt: a :class:`firedrake.Constant` or :class:`firedrake.Function` | ||
| on the Real space over the same mesh as ``u0``. This serves as | ||
| a variable referring to the current time step size. | ||
| :arg t: a :class:`Function` or :class:`Constant` on the Real space over the same mesh as |
There was a problem hiding this comment.
| :arg t: a :class:`Function` or :class:`Constant` on the Real space over the same mesh as | |
| :arg t: a :class:`Constant` or :class:`Function` on the Real space over the same mesh as |
| a variable referring to the current time step size. | ||
| :arg t: a :class:`Function` or :class:`Constant` on the Real space over the same mesh as | ||
| `u0`. This serves as a variable referring to the current time. | ||
| :arg dt: a :class:`Function` or :class:`Constant` on the Real space over the same mesh as |
There was a problem hiding this comment.
| :arg dt: a :class:`Function` or :class:`Constant` on the Real space over the same mesh as | |
| :arg dt: a :class:`Constant` or :class:`Function` on the Real space over the same mesh as |
| - `bcnew`, a list of :class:`firedrake.DirichletBC` or :class:`EquationBC` | ||
| objects to be posed on the stages | ||
| """ | ||
| backend_cls = get_backend(backend) |
There was a problem hiding this comment.
Should we try to consistenty set a backend variable name throught different files? In base_time_stepper we repeatedly call self._backend, but here we define backend_cls.
| assert V == backend_cls.get_function_space(u0) | ||
|
|
||
| c = vecconst(butch.c) | ||
| c = vecconst(butch.c, backend=backend) |
There was a problem hiding this comment.
Should we implement backend_cls.vecconst? The name of this function could also be improved, especially because this function returns ufl.zero for numeric values equal to zero.
| dtu: dtusub} | ||
| repl[i] = {t: t + c[i] * dt, v: v_np[i], u0: usub, dtu: dtusub} | ||
|
|
||
| Fnew = sum(replace(F, repl[i]) for i in range(num_stages)) |
There was a problem hiding this comment.
Not really needed here, but we should be consistent.
| Fnew = sum(replace(F, repl[i]) for i in range(num_stages)) | |
| Fnew = sum(backend_cls.replace(F, repl[i]) for i in range(num_stages)) |
There was a problem hiding this comment.
maybe it'd be good to define replace = backend_cls.replace earlier in this function, and stop importing replace from .tools
| bcs, | ||
| self.bc_type, | ||
| splitting=self.splitting, | ||
| aux_indices=self.aux_indices, |
There was a problem hiding this comment.
do we need to pass the backend?
|
I think this PR should not apply changes that are merely (ruff) formatting. This makes it a bit harder to review. |
| return firedrake.NonlinearVariationalProblem(F, u, bcs=bcs, **kwargs) | ||
|
|
||
|
|
||
| def create_nonlinearvariational_solver( |
There was a problem hiding this comment.
Why are we omitting an underscode here?
There was a problem hiding this comment.
Do we really need to say variational?
| try: | ||
| from firedrake.fml import LabelledForm, Term | ||
| if isinstance(e, LabelledForm): | ||
| enew = LabelledForm(*(Term(ufl_replace(term.form, cmapping), term.labels) | ||
| for term in e.terms)) | ||
| return enew | ||
| else: | ||
| return ufl_replace(e, cmapping) | ||
|
|
||
| except ImportError: |
There was a problem hiding this comment.
| try: | |
| from firedrake.fml import LabelledForm, Term | |
| if isinstance(e, LabelledForm): | |
| enew = LabelledForm(*(Term(ufl_replace(term.form, cmapping), term.labels) | |
| for term in e.terms)) | |
| return enew | |
| else: | |
| return ufl_replace(e, cmapping) | |
| except ImportError: | |
| try: | |
| from firedrake.fml import LabelledForm, Term | |
| if isinstance(e, LabelledForm): | |
| return LabelledForm(*(Term(ufl_replace(term.form, cmapping), term.labels) | |
| for term in e.terms)) | |
| except ImportError: | |
| pass | |
| finally: |
| Function = firedrake.Function | ||
|
|
||
| DirichletBC = firedrake.DirichletBC | ||
|
|
||
| norm = firedrake.norm | ||
|
|
||
| assemble = firedrake.assemble | ||
|
|
||
| replace = firedrake.replace | ||
|
|
||
| derivative = firedrake.derivative | ||
| TestFunction = firedrake.TestFunction | ||
| TrialFunction = firedrake.TrialFunction |
There was a problem hiding this comment.
Do we need to define varibales? Can these not be just imports?
Minimal example: