From 1381495cf83c26ac9c52ca3cad6cc508d7b98883 Mon Sep 17 00:00:00 2001 From: Yung-Yu Chen Date: Mon, 23 Jan 2023 10:36:54 +0800 Subject: [PATCH] [nsd/11arraydesign] Update non C++ example code for Laplace equation --- nsd/11arraydesign/code/01_solve_analytical.py | 6 +++--- nsd/11arraydesign/code/01_solve_python_loop.py | 8 ++++---- nsd/11arraydesign/code/02_solve_array.py | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/nsd/11arraydesign/code/01_solve_analytical.py b/nsd/11arraydesign/code/01_solve_analytical.py index fa7129d..a813495 100755 --- a/nsd/11arraydesign/code/01_solve_analytical.py +++ b/nsd/11arraydesign/code/01_solve_analytical.py @@ -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): @@ -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. diff --git a/nsd/11arraydesign/code/01_solve_python_loop.py b/nsd/11arraydesign/code/01_solve_python_loop.py index be7af2f..d9b03c0 100755 --- a/nsd/11arraydesign/code/01_solve_python_loop.py +++ b/nsd/11arraydesign/code/01_solve_python_loop.py @@ -16,7 +16,6 @@ def make_grid(): nx, x, uoriginal = make_grid() -# [begin example] import time import numpy as np @@ -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. @@ -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): diff --git a/nsd/11arraydesign/code/02_solve_array.py b/nsd/11arraydesign/code/02_solve_array.py index 59c2da6..a7d91a1 100755 --- a/nsd/11arraydesign/code/02_solve_array.py +++ b/nsd/11arraydesign/code/02_solve_array.py @@ -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: