Skip to content

Commit

Permalink
Squeezing zero-dimensional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
stammler committed Feb 14, 2024
1 parent 386f26e commit 1c66725
Show file tree
Hide file tree
Showing 18 changed files with 77,544 additions and 52,469 deletions.
21 changes: 10 additions & 11 deletions examples/1_simple_integration.ipynb

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions examples/2_advanced_integration.ipynb
Expand Up @@ -26,13 +26,13 @@
"\n",
"The equations of motion are determined by a set of two differential equations for the position $\\vec{r}$ and velocity $\\vec{v}$ of Earth and Sun..\n",
"\n",
"$\\frac{\\mathrm{d}}{\\mathrm{d}t} \\vec{r} = \\vec{v}$\n",
"$\\Large \\frac{\\mathrm{d}}{\\mathrm{d}t} \\vec{r} = \\vec{v}$\n",
"\n",
"$m\\frac{\\mathrm{d}}{\\mathrm{d}t} \\vec{v} = \\vec{F}_\\mathrm{G}$\n",
"$\\Large m\\frac{\\mathrm{d}}{\\mathrm{d}t} \\vec{v} = \\vec{F}_\\mathrm{G}$\n",
"\n",
"The gravitational force $F_\\mathrm{G}$ of a body of mass $M$ and position $\\vec{R}$ acting on a body of mass $m$ at position $\\vec{r}$ is given by\n",
"\n",
"$\\vec{F}_\\mathrm{G} = -GmM\\frac{\\vec{r}-\\vec{R}}{\\left| \\vec{r}-\\vec{R} \\right|^3}$"
"$\\Large \\vec{F}_\\mathrm{G} = -GmM\\frac{\\vec{r}-\\vec{R}}{\\left| \\vec{r}-\\vec{R} \\right|^3}$"
]
},
{
Expand Down Expand Up @@ -711,14 +711,14 @@
"output_type": "stream",
"text": [
" - \u001b[94mEarth\u001b[0m: total: 56 B\n",
" - \u001b[94mM\u001b[0m: (1,) 8 B\n",
" - \u001b[94mM\u001b[0m: () 8 B\n",
" - \u001b[94mr\u001b[0m: (3,) 24 B\n",
" - \u001b[94mv\u001b[0m: (3,) 24 B\n",
" - \u001b[94mSun\u001b[0m: total: 56 B\n",
" - \u001b[94mM\u001b[0m: (1,) 8 B\n",
" - \u001b[94mM\u001b[0m: () 8 B\n",
" - \u001b[94mr\u001b[0m: (3,) 24 B\n",
" - \u001b[94mv\u001b[0m: (3,) 24 B\n",
" - \u001b[94mt\u001b[0m: (1,) 8 B\n",
" - \u001b[94mt\u001b[0m: () 8 B\n",
"\n",
"Total: 120 B\n"
]
Expand Down Expand Up @@ -996,7 +996,7 @@
"Saving frame 0071\n",
"Saving frame 0072\n",
"Saving frame 0073\n",
"Execution time: \u001b[94m0:00:06\u001b[0m\n"
"Execution time: \u001b[94m0:00:00\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -1084,8 +1084,7 @@
"The problem is the simple integration scheme used here.\\\n",
"Every integration scheme has numerical error. Some have larger ones than others. Euler's 1st order method is simply not suited for orbital integration.\n",
"\n",
"But there is a way out: [Symplectic integration](https://en.wikipedia.org/wiki/Symplectic_integrator)\\\n",
"Symplectic integrators conserve the energy of the system.\n",
"But there is a way out: [Symplectic integration](https://en.wikipedia.org/wiki/Symplectic_integrator)\n",
"\n",
"One of these methods is the Leapfrog method.\\\n",
"Leapfrogging means the velocity and the position are not updated synchronous, but in between each other. They are leapfroggin each other.\n",
Expand Down Expand Up @@ -1168,7 +1167,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Execution time: \u001b[94m0:00:04\u001b[0m\n"
"Execution time: \u001b[94m0:00:00\u001b[0m\n"
]
}
],
Expand Down
45 changes: 23 additions & 22 deletions examples/3_updating.ipynb
Expand Up @@ -329,17 +329,18 @@
"metadata": {},
"outputs": [],
"source": [
"instructions = [Instruction(schemes.expl_1_euler, sim.Sun.v, fstep=0.5),\n",
" Instruction(schemes.expl_1_euler, sim.Earth.v, fstep=0.5),\n",
" Instruction(schemes.update, sim.Sun.v ),\n",
" Instruction(schemes.update, sim.Earth.v ),\n",
" Instruction(schemes.expl_1_euler, sim.Sun.r, fstep=1.0),\n",
" Instruction(schemes.expl_1_euler, sim.Earth.r, fstep=1.0),\n",
" Instruction(schemes.update, sim.Sun.r ),\n",
" Instruction(schemes.update, sim.Earth.r ),\n",
" Instruction(schemes.expl_1_euler, sim.Sun.v, fstep=0.5),\n",
" Instruction(schemes.expl_1_euler, sim.Earth.v, fstep=0.5),\n",
" ]"
"instructions = [\n",
" Instruction(schemes.expl_1_euler, sim.Sun.v, fstep=0.5),\n",
" Instruction(schemes.expl_1_euler, sim.Earth.v, fstep=0.5),\n",
" Instruction(schemes.update, sim.Sun.v ),\n",
" Instruction(schemes.update, sim.Earth.v ),\n",
" Instruction(schemes.expl_1_euler, sim.Sun.r, fstep=1.0),\n",
" Instruction(schemes.expl_1_euler, sim.Earth.r, fstep=1.0),\n",
" Instruction(schemes.update, sim.Sun.r ),\n",
" Instruction(schemes.update, sim.Earth.r ),\n",
" Instruction(schemes.expl_1_euler, sim.Sun.v, fstep=0.5),\n",
" Instruction(schemes.expl_1_euler, sim.Earth.v, fstep=0.5),\n",
"]"
]
},
{
Expand Down Expand Up @@ -434,7 +435,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Execution time: \u001b[94m0:00:01\u001b[0m\n"
"Execution time: \u001b[94m0:00:00\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -638,23 +639,23 @@
"source": [
"The energy the sun is emitting per time, i.e., it's luminosity $L$, is given by\n",
"\n",
"$L_\\odot = 4\\pi R_\\odot^2 \\sigma_\\mathrm{SB} T_\\mathrm{eff}^4$.\n",
"$\\Large L_\\odot = 4\\pi R_\\odot^2 \\sigma_\\mathrm{SB} T_\\mathrm{eff}^4$.\n",
"\n",
"The energy flux arriving at Earth, i.e., the Solar constant $S$ is then given by\n",
"\n",
"$S = \\frac{L}{4\\pi d^2}$.\n",
"$\\Large S = \\frac{L}{4\\pi d^2}$.\n",
"\n",
"Only one hemisphere of the Earth is illuminated at any time, so the energy that the Earth is receiving per unit time, neglecting any albedo effects, is given by\n",
"\n",
"$P_\\mathrm{in} = \\pi R_\\oplus^2 S$.\n",
"$\\Large P_\\mathrm{in} = \\pi R_\\oplus^2 S$.\n",
"\n",
"We assume that the temperature on Earth is in euilibrium, i.e., there is no difference between day and night. The energy the Earth is emitting per unit time is then given by\n",
"\n",
"$P_\\mathrm{out} = 4\\pi R_\\oplus^2 \\sigma_\\mathrm{SB} T^4$.\n",
"$\\Large P_\\mathrm{out} = 4\\pi R_\\oplus^2 \\sigma_\\mathrm{SB} T^4$.\n",
"\n",
"In equilibrium both are equal $\\left( P_\\mathrm{in} = P_\\mathrm{out} \\right)$ and we can solve for $T$\n",
"\n",
"$T = T_\\mathrm{eff} \\sqrt[4]{\\frac{R_\\odot^2}{4d^2}}$.\n",
"$\\Large T = T_\\mathrm{eff} \\sqrt[4]{\\frac{R_\\odot^2}{4d^2}}$.\n",
"\n",
"So the equilibrium temperature on Earth depends on the Sun's effective temperature $T_\\mathrm{eff}$, the Sun's radius $R_\\odot$, and the Earth-Sun distance $d$. We can now write a function that takes the frame object as argument and returns Earth's temperature."
]
Expand Down Expand Up @@ -1070,9 +1071,9 @@
"Heartbeat\n",
"---------\n",
"\n",
"\u001b[91mSystole: \u001b[0m <function T_sys at 0x7f8a00ea5620>\n",
"\u001b[91mUpdater: \u001b[0m <function T at 0x7f89ff942b60>\n",
"\u001b[91mDiastole:\u001b[0m <function T_dia at 0x7f8a00ea5580>\n",
"\u001b[91mSystole: \u001b[0m <function T_sys at 0x7f6f8bb1d9e0>\n",
"\u001b[91mUpdater: \u001b[0m <function T at 0x7f6f8a5aaf20>\n",
"\u001b[91mDiastole:\u001b[0m <function T_dia at 0x7f6f8bb1da80>\n",
"\n",
"Docstrings\n",
"----------\n",
Expand Down Expand Up @@ -1121,7 +1122,7 @@
" msg = \"{:6s}: T = {:5.1f} K\".format(\"Before\", sim.Earth.T)\n",
" print(msg)\n",
"\n",
"\u001b[91mFile:\u001b[0m /tmp/ipykernel_29890/2382827243.py\n",
"\u001b[91mFile:\u001b[0m /tmp/ipykernel_23644/2382827243.py\n",
"\u001b[91mType:\u001b[0m function"
]
},
Expand Down Expand Up @@ -1151,7 +1152,7 @@
" \"\"\"Function computes the equilibrium temperature of the Earth\"\"\"\n",
" return frame.Sun.T * (frame.Sun.R**2 / (4.*frame.Earth.d**2))**0.25\n",
"\n",
"\u001b[91mFile:\u001b[0m /tmp/ipykernel_29890/4057753429.py\n",
"\u001b[91mFile:\u001b[0m /tmp/ipykernel_23644/4057753429.py\n",
"\u001b[91mType:\u001b[0m function"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/4_custom_schemes.ipynb
Expand Up @@ -23,7 +23,7 @@
"\n",
"In this tutorial we want to estimate $\\pi$ with the following equation:\n",
"\n",
"$\\pi = 4 \\int\\limits_0^1 \\sqrt{1-t^2}\\mathrm{d}t$\n",
"$\\Large \\pi = 4 \\int\\limits_0^1 \\sqrt{1-t^2}\\mathrm{d}t$\n",
"\n",
"We set up the simulation frame as explained in the previous tutorials."
]
Expand Down Expand Up @@ -573,7 +573,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
40 changes: 16 additions & 24 deletions examples/5_adaptive_schemes.ipynb

Large diffs are not rendered by default.

46 changes: 21 additions & 25 deletions examples/6_implicit_integration.ipynb

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions examples/C_changelog.ipynb
Expand Up @@ -22,15 +22,19 @@
"metadata": {},
"source": [
"### **v1.0.5**\n",
"**Release date: 8th February 2024**\n",
"**Release date: not released yet**\n",
"\n",
"#### Moving to Meson build system\n",
"\n",
"Migrating to `mesonpy` as build system.\n",
"\n",
"#### Iteration over group members\n",
"\n",
"Functionality to iterate over the members of groups has been added."
"Functionality to iterate over the members of groups has been added.\n",
"\n",
"#### Squeezing zero-dimensional Fields\n",
"\n",
"When initializing field with scalar values, zero-dimensional arrays, or one-dimensional arrays of size one, the field will now be squeezed to shape `()`, since the previous behavior was inconsistent in these cases."
]
},
{
Expand Down
115 changes: 54 additions & 61 deletions examples/example_compartmental_models.ipynb

Large diffs are not rendered by default.

92,846 changes: 52,974 additions & 39,872 deletions examples/example_coupled_oscillators.ipynb

Large diffs are not rendered by default.

27,456 changes: 18,786 additions & 8,670 deletions examples/example_double_pendulum.ipynb

Large diffs are not rendered by default.

0 comments on commit 1c66725

Please sign in to comment.