Skip to content

Commit a6cbc87

Browse files
committed
Added get_var shortcut in Pyro class to make it less unwieldy to access a variable's data
1 parent 99fb3c7 commit a6cbc87

4 files changed

Lines changed: 71 additions & 79 deletions

File tree

docs/source/compressible_basics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pyro has several compressible solvers:
2525
time integration
2626

2727
* :py:mod:`compressible_sdc` uses fourth-order compressible solver,
28-
with spectral-deferred correction (SDC) for the time integration.
28+
with spectral-deferred correction (SDC) for the time integration.
2929

3030
The implementations here have flattening at shocks, artificial
3131
viscosity, a simple gamma-law equation of state, and (in some cases) a

docs/source/swe_basics.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Shallow water solvers
2-
==================================
1+
Shallow water solver
2+
====================
33

44
The (augmented) shallow water equations take the form:
55

examples/examples.ipynb

Lines changed: 57 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,14 @@
271271
" 11 1.00000 0.00000\n",
272272
"\u001b[33moutputting...\u001b[0m\n",
273273
"\u001b[33moutputting...\u001b[0m\n",
274-
"vis: 0.4468967914581299\n",
275-
"main: 0.1479780673980713\n"
274+
"vis: 0.24936318397521973\n",
275+
"main: 0.0664529800415039\n"
276276
]
277277
},
278278
{
279279
"data": {
280280
"text/plain": [
281-
"<advection.simulation.Simulation at 0x7f293ebf2390>"
281+
"<advection.simulation.Simulation at 0x7f5b5bca46d8>"
282282
]
283283
},
284284
"execution_count": 9,
@@ -342,7 +342,7 @@
342342
"metadata": {},
343343
"outputs": [],
344344
"source": [
345-
"dens = pyro_sim.sim.cc_data.get_var(\"density\")"
345+
"dens = pyro_sim.get_var(\"density\")"
346346
]
347347
},
348348
{
@@ -351,77 +351,58 @@
351351
"metadata": {},
352352
"outputs": [
353353
{
354-
"data": {
355-
"text/plain": [
356-
"ArrayIndexer([[1.36456254, 1.1670318 , 1.01964861, 1.0019269 ,\n",
357-
" 1.0034205 , 1.03779893, 1.19356852, 1.36368295,\n",
358-
" 1.36456254, 1.1670318 , 1.01964861, 1.0019269 ,\n",
359-
" 1.0034205 , 1.03779893, 1.19356852, 1.36368295],\n",
360-
" [1.1670318 , 1.1010689 , 1.01794261, 1.00172162,\n",
361-
" 1.00146403, 1.00815036, 1.05467319, 1.14089365,\n",
362-
" 1.1670318 , 1.1010689 , 1.01794261, 1.00172162,\n",
363-
" 1.00146403, 1.00815036, 1.05467319, 1.14089365],\n",
364-
" [1.01964861, 1.01794261, 1.00386665, 1.00034788,\n",
365-
" 1.00015378, 1.00017897, 1.00141073, 1.01213761,\n",
366-
" 1.01964861, 1.01794261, 1.00386665, 1.00034788,\n",
367-
" 1.00015378, 1.00017897, 1.00141073, 1.01213761],\n",
368-
" [1.0019269 , 1.00172162, 1.00034788, 1.00025512,\n",
369-
" 1.00085108, 0.99958517, 0.99836213, 1.00032876,\n",
370-
" 1.0019269 , 1.00172162, 1.00034788, 1.00025512,\n",
371-
" 1.00085108, 0.99958517, 0.99836213, 1.00032876],\n",
372-
" [1.0034205 , 1.00146403, 1.00015378, 1.00085108,\n",
373-
" 1.00036435, 0.99369049, 0.99065988, 1.00056788,\n",
374-
" 1.0034205 , 1.00146403, 1.00015378, 1.00085108,\n",
375-
" 1.00036435, 0.99369049, 0.99065988, 1.00056788],\n",
376-
" [1.03779893, 1.00815036, 1.00017897, 0.99958517,\n",
377-
" 0.99369049, 0.97697494, 0.9889869 , 1.02461354,\n",
378-
" 1.03779893, 1.00815036, 1.00017897, 0.99958517,\n",
379-
" 0.99369049, 0.97697494, 0.9889869 , 1.02461354],\n",
380-
" [1.19356852, 1.05467319, 1.00141073, 0.99836213,\n",
381-
" 0.99065988, 0.9889869 , 1.09690099, 1.19801589,\n",
382-
" 1.19356852, 1.05467319, 1.00141073, 0.99836213,\n",
383-
" 0.99065988, 0.9889869 , 1.09690099, 1.19801589],\n",
384-
" [1.36368295, 1.14089365, 1.01213761, 1.00032876,\n",
385-
" 1.00056788, 1.02461354, 1.19801589, 1.36305079,\n",
386-
" 1.36368295, 1.14089365, 1.01213761, 1.00032876,\n",
387-
" 1.00056788, 1.02461354, 1.19801589, 1.36305079],\n",
388-
" [1.36456254, 1.1670318 , 1.01964861, 1.0019269 ,\n",
389-
" 1.0034205 , 1.03779893, 1.19356852, 1.36368295,\n",
390-
" 1.36456254, 1.1670318 , 1.01964861, 1.0019269 ,\n",
391-
" 1.0034205 , 1.03779893, 1.19356852, 1.36368295],\n",
392-
" [1.1670318 , 1.1010689 , 1.01794261, 1.00172162,\n",
393-
" 1.00146403, 1.00815036, 1.05467319, 1.14089365,\n",
394-
" 1.1670318 , 1.1010689 , 1.01794261, 1.00172162,\n",
395-
" 1.00146403, 1.00815036, 1.05467319, 1.14089365],\n",
396-
" [1.01964861, 1.01794261, 1.00386665, 1.00034788,\n",
397-
" 1.00015378, 1.00017897, 1.00141073, 1.01213761,\n",
398-
" 1.01964861, 1.01794261, 1.00386665, 1.00034788,\n",
399-
" 1.00015378, 1.00017897, 1.00141073, 1.01213761],\n",
400-
" [1.0019269 , 1.00172162, 1.00034788, 1.00025512,\n",
401-
" 1.00085108, 0.99958517, 0.99836213, 1.00032876,\n",
402-
" 1.0019269 , 1.00172162, 1.00034788, 1.00025512,\n",
403-
" 1.00085108, 0.99958517, 0.99836213, 1.00032876],\n",
404-
" [1.0034205 , 1.00146403, 1.00015378, 1.00085108,\n",
405-
" 1.00036435, 0.99369049, 0.99065988, 1.00056788,\n",
406-
" 1.0034205 , 1.00146403, 1.00015378, 1.00085108,\n",
407-
" 1.00036435, 0.99369049, 0.99065988, 1.00056788],\n",
408-
" [1.03779893, 1.00815036, 1.00017897, 0.99958517,\n",
409-
" 0.99369049, 0.97697494, 0.9889869 , 1.02461354,\n",
410-
" 1.03779893, 1.00815036, 1.00017897, 0.99958517,\n",
411-
" 0.99369049, 0.97697494, 0.9889869 , 1.02461354],\n",
412-
" [1.19356852, 1.05467319, 1.00141073, 0.99836213,\n",
413-
" 0.99065988, 0.9889869 , 1.09690099, 1.19801589,\n",
414-
" 1.19356852, 1.05467319, 1.00141073, 0.99836213,\n",
415-
" 0.99065988, 0.9889869 , 1.09690099, 1.19801589],\n",
416-
" [1.36368295, 1.14089365, 1.01213761, 1.00032876,\n",
417-
" 1.00056788, 1.02461354, 1.19801589, 1.36305079,\n",
418-
" 1.36368295, 1.14089365, 1.01213761, 1.00032876,\n",
419-
" 1.00056788, 1.02461354, 1.19801589, 1.36305079]])"
420-
]
421-
},
422-
"execution_count": 12,
423-
"metadata": {},
424-
"output_type": "execute_result"
354+
"name": "stdout",
355+
"output_type": "stream",
356+
"text": [
357+
"[[1.36456254 1.1670318 1.01964861 1.0019269 1.0034205 1.03779893\n",
358+
" 1.19356852 1.36368295 1.36456254 1.1670318 1.01964861 1.0019269\n",
359+
" 1.0034205 1.03779893 1.19356852 1.36368295]\n",
360+
" [1.1670318 1.1010689 1.01794261 1.00172162 1.00146403 1.00815036\n",
361+
" 1.05467319 1.14089365 1.1670318 1.1010689 1.01794261 1.00172162\n",
362+
" 1.00146403 1.00815036 1.05467319 1.14089365]\n",
363+
" [1.01964861 1.01794261 1.00386665 1.00034788 1.00015378 1.00017897\n",
364+
" 1.00141073 1.01213761 1.01964861 1.01794261 1.00386665 1.00034788\n",
365+
" 1.00015378 1.00017897 1.00141073 1.01213761]\n",
366+
" [1.0019269 1.00172162 1.00034788 1.00025512 1.00085108 0.99958517\n",
367+
" 0.99836213 1.00032876 1.0019269 1.00172162 1.00034788 1.00025512\n",
368+
" 1.00085108 0.99958517 0.99836213 1.00032876]\n",
369+
" [1.0034205 1.00146403 1.00015378 1.00085108 1.00036435 0.99369049\n",
370+
" 0.99065988 1.00056788 1.0034205 1.00146403 1.00015378 1.00085108\n",
371+
" 1.00036435 0.99369049 0.99065988 1.00056788]\n",
372+
" [1.03779893 1.00815036 1.00017897 0.99958517 0.99369049 0.97697494\n",
373+
" 0.9889869 1.02461354 1.03779893 1.00815036 1.00017897 0.99958517\n",
374+
" 0.99369049 0.97697494 0.9889869 1.02461354]\n",
375+
" [1.19356852 1.05467319 1.00141073 0.99836213 0.99065988 0.9889869\n",
376+
" 1.09690099 1.19801589 1.19356852 1.05467319 1.00141073 0.99836213\n",
377+
" 0.99065988 0.9889869 1.09690099 1.19801589]\n",
378+
" [1.36368295 1.14089365 1.01213761 1.00032876 1.00056788 1.02461354\n",
379+
" 1.19801589 1.36305079 1.36368295 1.14089365 1.01213761 1.00032876\n",
380+
" 1.00056788 1.02461354 1.19801589 1.36305079]\n",
381+
" [1.36456254 1.1670318 1.01964861 1.0019269 1.0034205 1.03779893\n",
382+
" 1.19356852 1.36368295 1.36456254 1.1670318 1.01964861 1.0019269\n",
383+
" 1.0034205 1.03779893 1.19356852 1.36368295]\n",
384+
" [1.1670318 1.1010689 1.01794261 1.00172162 1.00146403 1.00815036\n",
385+
" 1.05467319 1.14089365 1.1670318 1.1010689 1.01794261 1.00172162\n",
386+
" 1.00146403 1.00815036 1.05467319 1.14089365]\n",
387+
" [1.01964861 1.01794261 1.00386665 1.00034788 1.00015378 1.00017897\n",
388+
" 1.00141073 1.01213761 1.01964861 1.01794261 1.00386665 1.00034788\n",
389+
" 1.00015378 1.00017897 1.00141073 1.01213761]\n",
390+
" [1.0019269 1.00172162 1.00034788 1.00025512 1.00085108 0.99958517\n",
391+
" 0.99836213 1.00032876 1.0019269 1.00172162 1.00034788 1.00025512\n",
392+
" 1.00085108 0.99958517 0.99836213 1.00032876]\n",
393+
" [1.0034205 1.00146403 1.00015378 1.00085108 1.00036435 0.99369049\n",
394+
" 0.99065988 1.00056788 1.0034205 1.00146403 1.00015378 1.00085108\n",
395+
" 1.00036435 0.99369049 0.99065988 1.00056788]\n",
396+
" [1.03779893 1.00815036 1.00017897 0.99958517 0.99369049 0.97697494\n",
397+
" 0.9889869 1.02461354 1.03779893 1.00815036 1.00017897 0.99958517\n",
398+
" 0.99369049 0.97697494 0.9889869 1.02461354]\n",
399+
" [1.19356852 1.05467319 1.00141073 0.99836213 0.99065988 0.9889869\n",
400+
" 1.09690099 1.19801589 1.19356852 1.05467319 1.00141073 0.99836213\n",
401+
" 0.99065988 0.9889869 1.09690099 1.19801589]\n",
402+
" [1.36368295 1.14089365 1.01213761 1.00032876 1.00056788 1.02461354\n",
403+
" 1.19801589 1.36305079 1.36368295 1.14089365 1.01213761 1.00032876\n",
404+
" 1.00056788 1.02461354 1.19801589 1.36305079]]\n"
405+
]
425406
}
426407
],
427408
"source": [
@@ -475,7 +456,7 @@
475456
],
476457
"metadata": {
477458
"kernelspec": {
478-
"display_name": "Python [default]",
459+
"display_name": "Python 3",
479460
"language": "python",
480461
"name": "python3"
481462
},

pyro.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,17 @@ def __repr__(self):
227227
s += str(self.sim.rp)
228228
return s
229229

230+
def get_var(self, v):
231+
"""
232+
Alias for cc_data's get_var routine, returns the cell-centered data
233+
given the variable name v.
234+
"""
235+
236+
if not self.is_initialized:
237+
msg.fail("ERROR: problem has not been initialized")
238+
239+
return self.sim.cc_data.get_var(v)
240+
230241

231242
class PyroBenchmark(Pyro):
232243
"""

0 commit comments

Comments
 (0)