Skip to content

Commit

Permalink
Changing the meaning of the lower bound of the snapshots attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
stammler committed May 16, 2024
1 parent a834e14 commit 4ddb0c2
Show file tree
Hide file tree
Showing 13 changed files with 13,408 additions and 12,391 deletions.
11 changes: 6 additions & 5 deletions examples/1_simple_integration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In addition to that, the integration variable needs to know about snapshots, i.e. points in space or time, when data should be written. Even you don't want to write data, you need to give at least one fineal value, because `simframe` needs to know when to stop the calculation. The snapshots have to be either a list or an array with the desired snapshots in increasing order."
"In addition to that, the integration variable needs to know about snapshots, i.e. points in space or time, when data should be written. Even you don't want to write data, you need to give at least one fineal value, because `simframe` needs to know when to stop the calculation. The snapshots have to be either a list or an array with the desired snapshots in increasing order. If you want `simframe` to write out the initial conditions, the snapshots need to contain the initial values of your integrations variable."
]
},
{
Expand All @@ -389,7 +389,7 @@
"metadata": {},
"outputs": [],
"source": [
"sim.x.snapshots = np.linspace(1., 10., 10)"
"sim.x.snapshots = np.linspace(0., 10., 11)"
]
},
{
Expand Down Expand Up @@ -618,7 +618,7 @@
"------------------------------------\n",
" Data directory : data\n",
" File names : data/data0000.hdf5\n",
" Overwrite : False\n",
" Overwrite : \u001b[93mFalse\u001b[0m\n",
" Dumping : True\n",
" Options : {'com': 'lzf', 'comopts': None}\n",
" Verbosity : 1"
Expand Down Expand Up @@ -677,7 +677,7 @@
"------------------------------------\n",
" Data directory : 1_data\n",
" File names : 1_data/data0000.hdf5\n",
" Overwrite : \u001b[93mTrue\u001b[0m\n",
" Overwrite : True\n",
" Dumping : True\n",
" Options : {'com': 'lzf', 'comopts': None}\n",
" Verbosity : 1"
Expand Down Expand Up @@ -717,6 +717,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Creating data directory 1_data.\n",
"Writing file \u001b[94m1_data/data0000.hdf5\u001b[0m\n",
"Writing dump file \u001b[94m1_data/frame.dmp\u001b[0m\n",
"Writing file \u001b[94m1_data/data0001.hdf5\u001b[0m\n",
Expand Down Expand Up @@ -1094,7 +1095,7 @@
"metadata": {},
"outputs": [],
"source": [
"sim_cont.x.snapshots = np.linspace(1., 20., 20)"
"sim_cont.x.snapshots = np.linspace(0., 20., 21)"
]
},
{
Expand Down
13 changes: 3 additions & 10 deletions examples/2_advanced_integration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,7 @@
"metadata": {},
"outputs": [],
"source": [
"sim.t.snapshots = np.arange(snapwidth, tmax, snapwidth)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note:** If the initial value of the integration variable is smaller the first snapshot, `simframe` automatically writes an output with initial conditions, if a writer is set."
"sim.t.snapshots = np.arange(0., tmax, snapwidth)"
]
},
{
Expand Down Expand Up @@ -996,7 +989,7 @@
"Saving frame 0071\n",
"Saving frame 0072\n",
"Saving frame 0073\n",
"Execution time: \u001b[94m0:00:00\u001b[0m\n"
"Execution time: \u001b[94m0:00:01\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -1167,7 +1160,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Execution time: \u001b[94m0:00:00\u001b[0m\n"
"Execution time: \u001b[94m0:00:02\u001b[0m\n"
]
}
],
Expand Down
14 changes: 7 additions & 7 deletions examples/3_updating.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"metadata": {},
"outputs": [],
"source": [
"sim.t.snapshots = np.arange(snapwidth, tmax+1, snapwidth)"
"sim.t.snapshots = np.arange(0., tmax, snapwidth)"
]
},
{
Expand Down Expand Up @@ -435,7 +435,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Execution time: \u001b[94m0:00:00\u001b[0m\n"
"Execution time: \u001b[94m0:00:01\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -1071,9 +1071,9 @@
"Heartbeat\n",
"---------\n",
"\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",
"\u001b[91mSystole: \u001b[0m <function T_sys at 0x7f7dbd6de660>\n",
"\u001b[91mUpdater: \u001b[0m <function T at 0x7f7dbd087600>\n",
"\u001b[91mDiastole:\u001b[0m <function T_dia at 0x7f7dbd6de7a0>\n",
"\n",
"Docstrings\n",
"----------\n",
Expand Down Expand Up @@ -1122,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_23644/2382827243.py\n",
"\u001b[91mFile:\u001b[0m /tmp/ipykernel_11686/2382827243.py\n",
"\u001b[91mType:\u001b[0m function"
]
},
Expand Down Expand Up @@ -1152,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_23644/4057753429.py\n",
"\u001b[91mFile:\u001b[0m /tmp/ipykernel_11686/4057753429.py\n",
"\u001b[91mType:\u001b[0m function"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/5_adaptive_schemes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"outputs": [],
"source": [
"import numpy as np\n",
"sim.x.snapshots = np.arange(dx, 15., dx)"
"sim.x.snapshots = np.arange(0., 15., dx)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/6_implicit_integration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"def fdx(frame):\n",
" return dx\n",
"sim_expl.x.updater = fdx\n",
"sim_expl.x.snapshots = [10.]"
"sim_expl.x.snapshots = [0., 10.]"
]
},
{
Expand Down
10 changes: 9 additions & 1 deletion examples/C_changelog.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@
"\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."
"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.\n",
"\n",
"#### Allowing for `Path` objects\n",
"\n",
"The `datadir` attribute of the `Writer` class can now also take `pathlib.Path` objects in addition to strings.\n",
"\n",
"#### Range of `snapshots`\n",
"\n",
"The `snapshots` attribute of the `Integrationvariable` class now also needs to contain the values of the initial conditions. Previously `simframe` was automatically writing the initial conditions if the integration variable was below the lower bound of the `snapshots` array. This was ambiguous if the simulation was interupted and restarted before it reached the first desired snapshot."
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions examples/example_compartmental_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@
"metadata": {},
"outputs": [],
"source": [
"sim.t.snapshots = np.arange(1., 366., 1.)"
"sim.t.snapshots = np.arange(0., 366., 1.)"
]
},
{
Expand Down Expand Up @@ -633,7 +633,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 @@ -903,7 +903,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 @@ -1681,7 +1681,7 @@
"metadata": {},
"outputs": [],
"source": [
"sim.t.snapshots = np.arange(1., 181., 1.)"
"sim.t.snapshots = np.arange(0., 181., 1.)"
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions examples/example_coupled_oscillators.ipynb

Large diffs are not rendered by default.

13,441 changes: 6,716 additions & 6,725 deletions examples/example_double_pendulum.ipynb

Large diffs are not rendered by default.

12,278 changes: 6,651 additions & 5,627 deletions examples/example_nbody.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions simframe/frame/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def run(self):
# Timekeeping
tini = monotonic()

# Write initial conditions
if self.integrator.var < self.integrator.var.snapshots[0]:
# Write initial conditions if at first given snapshot
if self.integrator.var == self.integrator.var.snapshots[0]:
self.writeoutput(0)

# Staring index of snapshots
Expand Down Expand Up @@ -168,7 +168,7 @@ def run(self):
if self.verbosity > 1:
self.progressbar._reset()

self.writeoutput(i + 1)
self.writeoutput(i)

# Timekeeping
tfin = monotonic()
Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_namespacewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def dYdx(f, x, Y):
def dx(f):
return 1.
f.x.updater = dx
f.x.snapshots = [1.]
f.x.snapshots = [0., 1.]
f.integrator = Integrator(f.x)
f.integrator.instructions = [Instruction(schemes.expl_1_euler, f.Y)]
f.writer = writers.namespacewriter()
Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def dYdx(f, x, Y):
def dx(f):
return 1.
f.x.updater = dx
f.x.snapshots = [1.]
f.x.snapshots = [0., 1.]
f.integrator = Integrator(f.x)
f.integrator.instructions = [Instruction(schemes.expl_1_euler, f.Y)]
f.writer = writers.hdf5writer()
Expand Down

0 comments on commit 4ddb0c2

Please sign in to comment.