<jupyter_start><jupyter_text>Vector Calculus_findiff_ implements the standard vector calculus operations$$\left(\frac{\partial}{\partial x_0},\frac{\partial}{\partial x_1},\dots,\frac{\partial}{\partial x_{N-1}}\right)\;, \quad\nabla \cdot\;, \quad\nabla^2\;, \quad\nabla \times$$by the convenience classes `Gradient`, `Divergence`, `Laplace` and `Curl`, respectively.<jupyter_code>import numpy as np
from findiff import Gradient, Divergence, Laplacian, Curl<jupyter_output><empty_output><jupyter_text>First, we want to apply the gradient, the divergence and the Laplacian to some scalar function$$f(x, y, z) = \sin(x) \cos(y) \sin(z)$$We set up our grid and fill the array `f`:<jupyter_code>x, y, z = [np.linspace(0, 10, 100)] * 3
dx, dy, dz = [c[1] - c[0] for c in (x, y, z)]
X, Y, Z = np.meshgrid(x, y, z, indexing='ij')
f = np.sin(X) * np.cos(Y) * np.sin(Z)<jupyter_output><empty_output><jupyter_text>$f(x, y, z)$ is a function of three variables, so the array `f` has three axes:<jupyter_code>f.shape<jupyter_output><empty_output><jupyter_text>It is a scalar function, so we can apply the gradient:<jupyter_code>grad = Gradient(spac=[dx, dy, dz])
grad_f = grad(f)<jupyter_output><empty_output><jupyter_text>Applying the gradient yields a vector function, where each component is a function of three variables. So the shape of the gradient array is:<jupyter_code>grad_f.shape<jupyter_output><empty_output><jupyter_text>Applying the Laplacian to a scalar function yields another scalar function:<jupyter_code>laplace = Laplacian(h=[dx, dy, dz])
laplace_f = laplace(f)
laplace_f.shape<jupyter_output><empty_output><jupyter_text>Now we define a vector function$${\bf g}(x, y, z) = \left(f(x, y, z), 2\cdot f(x, y, z), 3\cdot f(x, y, z)\right)$$<jupyter_code>g = np.array([f, 2*f, 3*f])
g.shape<jupyter_output><empty_output><jupyter_text>Applying the divergence yields a scalar function:<jupyter_code>div = Divergence(spac=[dx, dy, dz])
div_g = div(g)
div_g.shape<jupyter_output><empty_output><jupyter_text>Applying the curl yields another vector function:<jupyter_code>curl = Curl(h=[dx, dy, dz])
curl_g = curl(g)
curl_g.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15067222994900326, 'fraction_numerical': 0.007881316643486324, 'mean_word_length': 6.875912408759124, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '637177', 'license': 'MIT', 'n_tokens_mistral': 845, 'n_tokens_neox': 806, 'n_words': 208, 'path': 'examples/examples-vector-calculus.ipynb', 'repo_name': 'jenuis/findiff', 'size': '2157'}