Skip to content

Commit

Permalink
[nsd/11arraydesign] Update non C++ example code for Laplace equation
Browse files Browse the repository at this point in the history
  • Loading branch information
yungyuc committed Jan 23, 2023
1 parent 4a9f40d commit 1381495
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions nsd/11arraydesign/code/01_solve_analytical.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def make_grid():

nx, x, uoriginal = make_grid()

# [begin example]
import numpy as np

# [begin example]
def solve_analytical():
u = np.empty((len(x), len(x)), dtype='float64')
for ix, cx in enumerate(x):
Expand All @@ -26,8 +26,8 @@ def solve_analytical():
# [end example]

def solve_python_loop():
u = uoriginal.copy()
un = u.copy()
u = uoriginal.copy() # Input from outer scope
un = u.copy() # Create the buffer for the next time step
converged = False
step = 0
# Outer loop.
Expand Down
8 changes: 4 additions & 4 deletions nsd/11arraydesign/code/01_solve_python_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def make_grid():

nx, x, uoriginal = make_grid()

# [begin example]
import time
import numpy as np

Expand All @@ -27,9 +26,10 @@ def __exit__(self, *args, **kw):
self._t1 = time.time()
print("Wall time: {:g} s".format(self._t1 - self._t0))

# [begin example]
def solve_python_loop():
u = uoriginal.copy()
un = u.copy()
u = uoriginal.copy() # Input from outer scope
un = u.copy() # Create the buffer for the next time step
converged = False
step = 0
# Outer loop.
Expand All @@ -43,12 +43,12 @@ def solve_python_loop():
u[...] = un[...]
converged = True if norm < 1.e-5 else False
return u, step, norm
# [end example]

with Timer():
u, step, norm = solve_python_loop()

print(step)
# [end example]

# Run the Python solver
def show_result(u, step, norm, size=7):
Expand Down
6 changes: 3 additions & 3 deletions nsd/11arraydesign/code/02_solve_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def make_grid():

nx, x, uoriginal = make_grid()

# [begin example]
import numpy as np

# [begin example]
def solve_array():
u = uoriginal.copy()
un = u.copy()
u = uoriginal.copy() # Input from outer scope
un = u.copy() # Create the buffer for the next time step
converged = False
step = 0
while not converged:
Expand Down

0 comments on commit 1381495

Please sign in to comment.