23. CFD Relevant Python Statements | While | For#
23.1. Indexing#
Identification of grid points
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 1, 10)
23.2. While#
Conditional statement to execute something while a specific condition is met.
numerical_error = 1.0
epsilon = 1e-2
T = np.zeros(10)
T_new = T.copy() + np.random.random(10)
while numerical_error > epsilon:
T_new = T_new - T_new / 2
numerical_error = np.sum(np.abs(T_new - T))
23.3. For#
for i in range(10, 20):
print(i)
10
11
12
13
14
15
16
17
18
19
23.4. Assigning#
Post-iteration to continue iterative process:
\[
T = T_{\text{new}}
\]
T = T_new.copy()
T
array([1.47324577e-03, 1.16504730e-03, 1.52018529e-03, 1.12771695e-03,
3.73657430e-04, 3.00996707e-04, 1.27236386e-03, 1.07757908e-03,
1.59544691e-03, 7.40650199e-05])