Skip to content

Commit 382ae2f

Browse files
committed
Added section using pySDC as integrator within libs
1 parent d88c7e8 commit 382ae2f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pySDC/playgrounds/PinT_Workshop_2025/2_Coupling_pySDC_to_libraries.ipynb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,34 @@
760760
"id": "7bc27a1f-87a5-456d-b07f-d1cff17f554a",
761761
"metadata": {},
762762
"source": [
763+
"## Using pySDC as an integrator within another library\n",
764+
"Once you have coupled a datatype to pySDC, you can implement pySDC as an integrator for libraries building on the same datatype.\n",
765+
"For instance, we have implemented this for [Gusto](https://www.firedrakeproject.org/gusto/), which builds on Firedrake to assemble dynamical cores as used in numerical weather prediction.\n",
766+
"The way you go about this is to look at the interface for other integrators in the library you want to couple to.\n",
767+
"Chances are an integrator accepts some initial conditions and returns the solution at the end of the interval.\n",
768+
"In this case, you need to assemble a pySDC controller to do what you want and then, in the library you want to couple to, pass the solution between pySDC and the library.\n",
769+
"In code, this looks approximataly like so:\n",
770+
"\n",
771+
"```\n",
772+
"class pySDC_integrator(my_library_integrator):\n",
773+
"\n",
774+
" def __init__(self, description):\n",
775+
" super().__init__()\n",
776+
" self.controller = controller_nonMPI(description, ...)\n",
777+
"\n",
778+
" def integrate(u0, dt, t):\n",
779+
" P = self.controller.MS[0].levels[0].prob\n",
780+
" _u = P.u_init(u0)\n",
781+
" u_end, _ = self.controller.run(u0=_u, t0=t, Tend=t+dt)\n",
782+
" return u_end\n",
783+
"```\n",
784+
"\n",
785+
"Of course, you need to take care that `dt` is divisible by the pySDC time step and so on.\n",
786+
"Also, you need to implement the coupling in a problem class.\n",
787+
"That is to say, you need an interface that can be called by pySDC and which calls the respective functions for evaluating and inverting $f$ in the library you want to couple to.\n",
788+
"Since the library may not be designed to be used like this, this may cause some issues.\n",
789+
"But if the library you want to couple to is well coded, it should be feasible to use pySDC as an integrator within this library.\n",
790+
"\n",
763791
"## Summary\n",
764792
"In this notebook you saw how to couple pySDC with another library, in this case Firedrake.\n",
765793
"The main part of this is to write a datatype that connects the interfaces of pySDC and the library.\n",

0 commit comments

Comments
 (0)