Skip to content

Commit 4f41984

Browse files
Merge pull request #1501 from OceanParcels/paserticleset_add_variable_method
Implementing Particleset.add_variable() method
2 parents fe8d912 + 1c9d062 commit 4f41984

27 files changed

Lines changed: 302 additions & 343 deletions

docs/examples/documentation_stuck_particles.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
" FieldSet,\n",
8383
" JITParticle,\n",
8484
" ParticleSet,\n",
85-
" Variable,\n",
8685
" download_example_dataset,\n",
8786
")"
8887
]
@@ -1222,8 +1221,7 @@
12221221
},
12231222
"outputs": [],
12241223
"source": [
1225-
"class LandParticle(JITParticle):\n",
1226-
" on_land = Variable(\"on_land\")\n",
1224+
"LandParticle = JITParticle.add_variable(\"on_land\")\n",
12271225
"\n",
12281226
"\n",
12291227
"def Sample_land(particle, fieldset, time):\n",

docs/examples/documentation_unstuck_Agrid.ipynb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -809,10 +809,13 @@
809809
"metadata": {},
810810
"outputs": [],
811811
"source": [
812-
"class DisplacementParticle(JITParticle):\n",
813-
" dU = Variable(\"dU\")\n",
814-
" dV = Variable(\"dV\")\n",
815-
" d2s = Variable(\"d2s\", initial=1e3)\n",
812+
"DisplacementParticle = JITParticle.add_variables(\n",
813+
" [\n",
814+
" Variable(\"dU\"),\n",
815+
" Variable(\"dV\"),\n",
816+
" Variable(\"d2s\", initial=1e3),\n",
817+
" ]\n",
818+
")\n",
816819
"\n",
817820
"\n",
818821
"def set_displacement(particle, fieldset, time):\n",

docs/examples/example_globcurrent.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
ParticleSet,
1414
ScipyParticle,
1515
TimeExtrapolationError,
16-
Variable,
1716
download_example_dataset,
1817
)
1918

@@ -99,8 +98,7 @@ def test_globcurrent_time_periodic(mode, rundays):
9998
for deferred_load in [True, False]:
10099
fieldset = set_globcurrent_fieldset(time_periodic=delta(days=365), deferred_load=deferred_load)
101100

102-
class MyParticle(ptype[mode]):
103-
sample_var = Variable('sample_var', initial=0.)
101+
MyParticle = ptype[mode].add_variable('sample_var', initial=0.)
104102

105103
pset = ParticleSet(fieldset, pclass=MyParticle, lon=25, lat=-35, time=fieldset.U.grid.time[0])
106104

@@ -194,8 +192,7 @@ def test_globcurrent_startparticles_between_time_arrays(mode, dt, with_starttime
194192
fieldset.add_field(Field.from_netcdf(fnamesFeb, ('P', 'eastward_eulerian_current_velocity'),
195193
{'lat': 'lat', 'lon': 'lon', 'time': 'time'}))
196194

197-
class MyParticle(ptype[mode]):
198-
sample_var = Variable('sample_var', initial=0.)
195+
MyParticle = ptype[mode].add_variable('sample_var', initial=0.)
199196

200197
def SampleP(particle, fieldset, time):
201198
particle.sample_var += fieldset.P[time, particle.depth, particle.lat, particle.lon]

docs/examples/example_peninsula.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,8 @@ def peninsula_example(fieldset, outfile, npart, mode='jit', degree=1,
130130
# First, we define a custom Particle class to which we add a
131131
# custom variable, the initial stream function value p.
132132
# We determine the particle base class according to mode.
133-
class MyParticle(ptype[mode]):
134-
# JIT compilation requires a-priori knowledge of the particle
135-
# data structure, so we define additional variables here.
136-
p = Variable('p', dtype=np.float32, initial=0.)
137-
p_start = Variable('p_start', dtype=np.float32, initial=0)
133+
MyParticle = ptype[mode].add_variable([Variable('p', dtype=np.float32, initial=0.),
134+
Variable('p_start', dtype=np.float32, initial=0)])
138135

139136
# Initialise particles
140137
if fieldset.U.grid.mesh == 'flat':

docs/examples/example_stommel.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ def stommel_example(npart=1, mode='jit', verbose=False, method=AdvectionRK4, gri
105105
dt = delta(hours=1)
106106
outputdt = delta(days=5)
107107

108-
class MyParticle(ParticleClass):
109-
p = Variable('p', dtype=np.float32, initial=0.)
110-
p_start = Variable('p_start', dtype=np.float32, initial=0.)
111-
next_dt = Variable('next_dt', dtype=np.float64, initial=dt.total_seconds())
112-
age = Variable('age', dtype=np.float32, initial=0.)
108+
extra_vars = [Variable('p', dtype=np.float32, initial=0.),
109+
Variable('p_start', dtype=np.float32, initial=0.),
110+
Variable('next_dt', dtype=np.float64, initial=dt.total_seconds()),
111+
Variable('age', dtype=np.float32, initial=0.)]
112+
MyParticle = ParticleClass.add_variables(extra_vars)
113113

114114
if custom_partition_function:
115115
pset = ParticleSet.from_line(fieldset, size=npart, pclass=MyParticle, repeatdt=repeatdt,

docs/examples/parcels_tutorial.ipynb

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
"output_type": "stream",
229229
"text": [
230230
"INFO: Output files are stored in EddyParticles.zarr.\n",
231-
"100%|██████████| 518400.0/518400.0 [00:02<00:00, 187445.76it/s]\n"
231+
"100%|██████████| 518400.0/518400.0 [00:03<00:00, 172443.78it/s]\n"
232232
]
233233
}
234234
],
@@ -569,42 +569,42 @@
569569
"</style>\n",
570570
"\n",
571571
"<div class=\"animation\">\n",
572-
" <img id=\"_anim_img8bfbea7abfae4cbf885a957f3f62a93b\">\n",
572+
" <img id=\"_anim_img39fc9ac9ecc54c368c0d0e047c7673e6\">\n",
573573
" <div class=\"anim-controls\">\n",
574-
" <input id=\"_anim_slider8bfbea7abfae4cbf885a957f3f62a93b\" type=\"range\" class=\"anim-slider\"\n",
574+
" <input id=\"_anim_slider39fc9ac9ecc54c368c0d0e047c7673e6\" type=\"range\" class=\"anim-slider\"\n",
575575
" name=\"points\" min=\"0\" max=\"1\" step=\"1\" value=\"0\"\n",
576-
" oninput=\"anim8bfbea7abfae4cbf885a957f3f62a93b.set_frame(parseInt(this.value));\">\n",
576+
" oninput=\"anim39fc9ac9ecc54c368c0d0e047c7673e6.set_frame(parseInt(this.value));\">\n",
577577
" <div class=\"anim-buttons\">\n",
578-
" <button title=\"Decrease speed\" aria-label=\"Decrease speed\" onclick=\"anim8bfbea7abfae4cbf885a957f3f62a93b.slower()\">\n",
578+
" <button title=\"Decrease speed\" aria-label=\"Decrease speed\" onclick=\"anim39fc9ac9ecc54c368c0d0e047c7673e6.slower()\">\n",
579579
" <i class=\"fa fa-minus\"></i></button>\n",
580-
" <button title=\"First frame\" aria-label=\"First frame\" onclick=\"anim8bfbea7abfae4cbf885a957f3f62a93b.first_frame()\">\n",
580+
" <button title=\"First frame\" aria-label=\"First frame\" onclick=\"anim39fc9ac9ecc54c368c0d0e047c7673e6.first_frame()\">\n",
581581
" <i class=\"fa fa-fast-backward\"></i></button>\n",
582-
" <button title=\"Previous frame\" aria-label=\"Previous frame\" onclick=\"anim8bfbea7abfae4cbf885a957f3f62a93b.previous_frame()\">\n",
582+
" <button title=\"Previous frame\" aria-label=\"Previous frame\" onclick=\"anim39fc9ac9ecc54c368c0d0e047c7673e6.previous_frame()\">\n",
583583
" <i class=\"fa fa-step-backward\"></i></button>\n",
584-
" <button title=\"Play backwards\" aria-label=\"Play backwards\" onclick=\"anim8bfbea7abfae4cbf885a957f3f62a93b.reverse_animation()\">\n",
584+
" <button title=\"Play backwards\" aria-label=\"Play backwards\" onclick=\"anim39fc9ac9ecc54c368c0d0e047c7673e6.reverse_animation()\">\n",
585585
" <i class=\"fa fa-play fa-flip-horizontal\"></i></button>\n",
586-
" <button title=\"Pause\" aria-label=\"Pause\" onclick=\"anim8bfbea7abfae4cbf885a957f3f62a93b.pause_animation()\">\n",
586+
" <button title=\"Pause\" aria-label=\"Pause\" onclick=\"anim39fc9ac9ecc54c368c0d0e047c7673e6.pause_animation()\">\n",
587587
" <i class=\"fa fa-pause\"></i></button>\n",
588-
" <button title=\"Play\" aria-label=\"Play\" onclick=\"anim8bfbea7abfae4cbf885a957f3f62a93b.play_animation()\">\n",
588+
" <button title=\"Play\" aria-label=\"Play\" onclick=\"anim39fc9ac9ecc54c368c0d0e047c7673e6.play_animation()\">\n",
589589
" <i class=\"fa fa-play\"></i></button>\n",
590-
" <button title=\"Next frame\" aria-label=\"Next frame\" onclick=\"anim8bfbea7abfae4cbf885a957f3f62a93b.next_frame()\">\n",
590+
" <button title=\"Next frame\" aria-label=\"Next frame\" onclick=\"anim39fc9ac9ecc54c368c0d0e047c7673e6.next_frame()\">\n",
591591
" <i class=\"fa fa-step-forward\"></i></button>\n",
592-
" <button title=\"Last frame\" aria-label=\"Last frame\" onclick=\"anim8bfbea7abfae4cbf885a957f3f62a93b.last_frame()\">\n",
592+
" <button title=\"Last frame\" aria-label=\"Last frame\" onclick=\"anim39fc9ac9ecc54c368c0d0e047c7673e6.last_frame()\">\n",
593593
" <i class=\"fa fa-fast-forward\"></i></button>\n",
594-
" <button title=\"Increase speed\" aria-label=\"Increase speed\" onclick=\"anim8bfbea7abfae4cbf885a957f3f62a93b.faster()\">\n",
594+
" <button title=\"Increase speed\" aria-label=\"Increase speed\" onclick=\"anim39fc9ac9ecc54c368c0d0e047c7673e6.faster()\">\n",
595595
" <i class=\"fa fa-plus\"></i></button>\n",
596596
" </div>\n",
597-
" <form title=\"Repetition mode\" aria-label=\"Repetition mode\" action=\"#n\" name=\"_anim_loop_select8bfbea7abfae4cbf885a957f3f62a93b\"\n",
597+
" <form title=\"Repetition mode\" aria-label=\"Repetition mode\" action=\"#n\" name=\"_anim_loop_select39fc9ac9ecc54c368c0d0e047c7673e6\"\n",
598598
" class=\"anim-state\">\n",
599-
" <input type=\"radio\" name=\"state\" value=\"once\" id=\"_anim_radio1_8bfbea7abfae4cbf885a957f3f62a93b\"\n",
599+
" <input type=\"radio\" name=\"state\" value=\"once\" id=\"_anim_radio1_39fc9ac9ecc54c368c0d0e047c7673e6\"\n",
600600
" >\n",
601-
" <label for=\"_anim_radio1_8bfbea7abfae4cbf885a957f3f62a93b\">Once</label>\n",
602-
" <input type=\"radio\" name=\"state\" value=\"loop\" id=\"_anim_radio2_8bfbea7abfae4cbf885a957f3f62a93b\"\n",
601+
" <label for=\"_anim_radio1_39fc9ac9ecc54c368c0d0e047c7673e6\">Once</label>\n",
602+
" <input type=\"radio\" name=\"state\" value=\"loop\" id=\"_anim_radio2_39fc9ac9ecc54c368c0d0e047c7673e6\"\n",
603603
" checked>\n",
604-
" <label for=\"_anim_radio2_8bfbea7abfae4cbf885a957f3f62a93b\">Loop</label>\n",
605-
" <input type=\"radio\" name=\"state\" value=\"reflect\" id=\"_anim_radio3_8bfbea7abfae4cbf885a957f3f62a93b\"\n",
604+
" <label for=\"_anim_radio2_39fc9ac9ecc54c368c0d0e047c7673e6\">Loop</label>\n",
605+
" <input type=\"radio\" name=\"state\" value=\"reflect\" id=\"_anim_radio3_39fc9ac9ecc54c368c0d0e047c7673e6\"\n",
606606
" >\n",
607-
" <label for=\"_anim_radio3_8bfbea7abfae4cbf885a957f3f62a93b\">Reflect</label>\n",
607+
" <label for=\"_anim_radio3_39fc9ac9ecc54c368c0d0e047c7673e6\">Reflect</label>\n",
608608
" </form>\n",
609609
" </div>\n",
610610
"</div>\n",
@@ -614,9 +614,9 @@
614614
" /* Instantiate the Animation class. */\n",
615615
" /* The IDs given should match those used in the template above. */\n",
616616
" (function() {\n",
617-
" var img_id = \"_anim_img8bfbea7abfae4cbf885a957f3f62a93b\";\n",
618-
" var slider_id = \"_anim_slider8bfbea7abfae4cbf885a957f3f62a93b\";\n",
619-
" var loop_select_id = \"_anim_loop_select8bfbea7abfae4cbf885a957f3f62a93b\";\n",
617+
" var img_id = \"_anim_img39fc9ac9ecc54c368c0d0e047c7673e6\";\n",
618+
" var slider_id = \"_anim_slider39fc9ac9ecc54c368c0d0e047c7673e6\";\n",
619+
" var loop_select_id = \"_anim_loop_select39fc9ac9ecc54c368c0d0e047c7673e6\";\n",
620620
" var frames = new Array(29);\n",
621621
" \n",
622622
" frames[0] = \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArwAAAH0CAYAAADfWf7fAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90\\\n",
@@ -13156,7 +13156,7 @@
1315613156
" /* set a timeout to make sure all the above elements are created before\n",
1315713157
" the object is initialized. */\n",
1315813158
" setTimeout(function() {\n",
13159-
" anim8bfbea7abfae4cbf885a957f3f62a93b = new Animation(frames, img_id, slider_id, 100.0,\n",
13159+
" anim39fc9ac9ecc54c368c0d0e047c7673e6 = new Animation(frames, img_id, slider_id, 100.0,\n",
1316013160
" loop_select_id);\n",
1316113161
" }, 0);\n",
1316213162
" })()\n",
@@ -13201,7 +13201,7 @@
1320113201
"output_type": "stream",
1320213202
"text": [
1320313203
"INFO: Output files are stored in EddyParticles_Bwd.zarr.\n",
13204-
"100%|██████████| 518400.0/518400.0 [00:02<00:00, 188464.76it/s]\n"
13204+
"100%|██████████| 518400.0/518400.0 [00:02<00:00, 176426.86it/s]\n"
1320513205
]
1320613206
}
1320713207
],
@@ -13323,7 +13323,7 @@
1332313323
"output_type": "stream",
1332413324
"text": [
1332513325
"INFO: Output files are stored in EddyParticles_WestVel.zarr.\n",
13326-
"100%|██████████| 172800.0/172800.0 [00:00<00:00, 180626.58it/s]\n"
13326+
"100%|██████████| 172800.0/172800.0 [00:00<00:00, 179532.85it/s]\n"
1332713327
]
1332813328
}
1332913329
],
@@ -13503,7 +13503,7 @@
1350313503
"output_type": "stream",
1350413504
"text": [
1350513505
"INFO: Output files are stored in GlobCurrentParticles.zarr.\n",
13506-
"100%|██████████| 864000.0/864000.0 [00:00<00:00, 1104294.63it/s]\n"
13506+
"100%|██████████| 864000.0/864000.0 [00:00<00:00, 1072517.72it/s]\n"
1350713507
]
1350813508
}
1350913509
],
@@ -13592,7 +13592,7 @@
1359213592
"cell_type": "markdown",
1359313593
"metadata": {},
1359413594
"source": [
13595-
"Now define a new `Particle` class that has an extra `Variable`: the pressure. We initialise this by sampling the `fieldset.P` field.\n"
13595+
"Now define a new `Particle` class that has an extra `Variable`: the pressure. This `particle.p` can be used to store the values of the `fieldset.P` field at the particle locations.\n"
1359613596
]
1359713597
},
1359813598
{
@@ -13601,11 +13601,7 @@
1360113601
"metadata": {},
1360213602
"outputs": [],
1360313603
"source": [
13604-
"class SampleParticle(JITParticle):\n",
13605-
" \"\"\"Define a new particle class with variable 'p'\n",
13606-
" initialised by sampling the pressure\"\"\"\n",
13607-
"\n",
13608-
" p = Variable(\"p\")"
13604+
"SampleParticle = JITParticle.add_variable(\"p\")"
1360913605
]
1361013606
},
1361113607
{
@@ -13688,7 +13684,7 @@
1368813684
"output_type": "stream",
1368913685
"text": [
1369013686
"INFO: Output files are stored in PeninsulaPressure.zarr.\n",
13691-
"100%|██████████| 72000.0/72000.0 [00:00<00:00, 157840.98it/s]\n"
13687+
"100%|██████████| 72000.0/72000.0 [00:00<00:00, 143717.52it/s]\n"
1369213688
]
1369313689
}
1369413690
],
@@ -13768,7 +13764,7 @@
1376813764
"cell_type": "markdown",
1376913765
"metadata": {},
1377013766
"source": [
13771-
"First, we need to create a new `Particle` class that includes three extra variables. The `distance` variable will be written to output, but the auxiliary variables `prev_lon` and `prev_lat` won't be written to output (can be controlled using the `to_write` keyword)\n"
13767+
"First, we need to add three extra variables to the Particle Class. The `distance` variable will be written to output, but the auxiliary variables `prev_lon` and `prev_lat` won't be written to output (can be controlled using the `to_write` keyword)."
1377213768
]
1377313769
},
1377413770
{
@@ -13777,19 +13773,13 @@
1377713773
"metadata": {},
1377813774
"outputs": [],
1377913775
"source": [
13780-
"class DistParticle(JITParticle):\n",
13781-
" \"\"\"Define a new particle class that contains three extra variables\"\"\"\n",
13782-
"\n",
13783-
" # the distance travelled by the particle\n",
13784-
" distance = Variable(\"distance\", initial=0.0, dtype=np.float32)\n",
13776+
"extra_vars = [\n",
13777+
" Variable(\"distance\", initial=0.0, dtype=np.float32),\n",
13778+
" Variable(\"prev_lon\", dtype=np.float32, to_write=False, initial=attrgetter(\"lon\")),\n",
13779+
" Variable(\"prev_lat\", dtype=np.float32, to_write=False, initial=attrgetter(\"lat\")),\n",
13780+
"]\n",
1378513781
"\n",
13786-
" # the previous longitude and latitude of the particle\n",
13787-
" prev_lon = Variable(\n",
13788-
" \"prev_lon\", dtype=np.float32, to_write=False, initial=attrgetter(\"lon\")\n",
13789-
" )\n",
13790-
" prev_lat = Variable(\n",
13791-
" \"prev_lat\", dtype=np.float32, to_write=False, initial=attrgetter(\"lat\")\n",
13792-
" )"
13782+
"DistParticle = JITParticle.add_variables(extra_vars)"
1379313783
]
1379413784
},
1379513785
{
@@ -13879,7 +13869,7 @@
1387913869
"output_type": "stream",
1388013870
"text": [
1388113871
"INFO: Output files are stored in GlobCurrentParticles_Dist.zarr.\n",
13882-
"100%|██████████| 518400.0/518400.0 [00:03<00:00, 147724.13it/s]\n"
13872+
"100%|██████████| 518400.0/518400.0 [00:03<00:00, 136275.28it/s]\n"
1388313873
]
1388413874
}
1388513875
],
@@ -13936,7 +13926,7 @@
1393613926
"name": "python",
1393713927
"nbconvert_exporter": "python",
1393813928
"pygments_lexer": "ipython3",
13939-
"version": "3.10.9"
13929+
"version": "3.11.6"
1394013930
}
1394113931
},
1394213932
"nbformat": 4,

docs/examples/tutorial_Argofloats.ipynb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,21 @@
128128
"\n",
129129
"\n",
130130
"# Define a new Particle type including extra Variables\n",
131-
"class ArgoParticle(JITParticle):\n",
132-
" # Phase of cycle:\n",
133-
" # init_descend=0,\n",
134-
" # drift=1,\n",
135-
" # profile_descend=2,\n",
136-
" # profile_ascend=3,\n",
137-
" # transmit=4\n",
138-
" cycle_phase = Variable(\"cycle_phase\", dtype=np.int32, initial=0.0)\n",
139-
" cycle_age = Variable(\"cycle_age\", dtype=np.float32, initial=0.0)\n",
140-
" drift_age = Variable(\"drift_age\", dtype=np.float32, initial=0.0)\n",
141-
" # if fieldset has temperature\n",
142-
" # temp = Variable('temp', dtype=np.float32, initial=np.nan)\n",
143-
"\n",
131+
"ArgoParticle = JITParticle.add_variables(\n",
132+
" [\n",
133+
" # Phase of cycle:\n",
134+
" # init_descend=0,\n",
135+
" # drift=1,\n",
136+
" # profile_descend=2,\n",
137+
" # profile_ascend=3,\n",
138+
" # transmit=4\n",
139+
" Variable(\"cycle_phase\", dtype=np.int32, initial=0.0),\n",
140+
" Variable(\"cycle_age\", dtype=np.float32, initial=0.0),\n",
141+
" Variable(\"drift_age\", dtype=np.float32, initial=0.0),\n",
142+
" # if fieldset has temperature\n",
143+
" # Variable('temp', dtype=np.float32, initial=np.nan),\n",
144+
" ]\n",
145+
")\n",
144146
"\n",
145147
"# Initiate one Argo float in the Agulhas Current\n",
146148
"pset = ParticleSet(\n",

docs/examples/tutorial_NestedFields.ipynb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,11 @@
226226
}
227227
],
228228
"source": [
229-
"from parcels import Variable\n",
230-
"\n",
231-
"\n",
232229
"def SampleNestedFieldIndex(particle, fieldset, time):\n",
233230
" particle.f = fieldset.F[time, particle.depth, particle.lat, particle.lon]\n",
234231
"\n",
235232
"\n",
236-
"class SampleParticle(JITParticle):\n",
237-
" f = Variable(\"f\", dtype=np.int32)\n",
238-
"\n",
233+
"SampleParticle = JITParticle.add_variable(\"f\", dtype=np.int32)\n",
239234
"\n",
240235
"pset = ParticleSet(fieldset, pclass=SampleParticle, lon=[1000], lat=[500])\n",
241236
"pset.execute(SampleNestedFieldIndex, runtime=1)\n",

docs/examples/tutorial_analyticaladvection.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@
154154
" particle.radius = fieldset.R[time, particle.depth, particle.lat, particle.lon]\n",
155155
"\n",
156156
"\n",
157-
"class MyParticle(ScipyParticle):\n",
158-
" radius = Variable(\"radius\", dtype=np.float32, initial=0.0)\n",
159-
" radius_start = Variable(\"radius_start\", dtype=np.float32, initial=0.0)\n",
157+
"MyParticle = ScipyParticle.add_variables(\n",
158+
" [\n",
159+
" Variable(\"radius\", dtype=np.float32, initial=0.0),\n",
160+
" Variable(\"radius_start\", dtype=np.float32, initial=0.0),\n",
161+
" ]\n",
162+
")\n",
160163
"\n",
161164
"\n",
162165
"pset = ParticleSet(fieldsetRR, pclass=MyParticle, lon=0, lat=4e3, time=0)\n",

docs/examples/tutorial_delaystart.ipynb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32416,10 +32416,13 @@
3241632416
}
3241732417
],
3241832418
"source": [
32419-
"class GrowingParticle(JITParticle):\n",
32420-
" mass = Variable(\"mass\", initial=0)\n",
32421-
" splittime = Variable(\"splittime\", initial=-1)\n",
32422-
" splitmass = Variable(\"splitmass\", initial=0)\n",
32419+
"GrowingParticle = JITParticle.add_variables(\n",
32420+
" [\n",
32421+
" Variable(\"mass\", initial=0),\n",
32422+
" Variable(\"splittime\", initial=-1),\n",
32423+
" Variable(\"splitmass\", initial=0),\n",
32424+
" ]\n",
32425+
")\n",
3242332426
"\n",
3242432427
"\n",
3242532428
"def GrowParticles(particle, fieldset, time):\n",

0 commit comments

Comments
 (0)