<jupyter_start><jupyter_text>Data Structure In the sequel, we shall use **StencilMatrix** and **StencilVector** from the **psydac** library.For the moment, we are only interested about having an appropriate data structure to store our computations.Once the assembly is done, we will convert the matrix into a scipy sparse matrix, while the vector will be converted to numpy array.We will see later how one can impose boundary conditions.  1D Case<jupyter_code>import numpy as np

from psydac.fem.splines import SplineSpace
from psydac.fem.tensor  import TensorFemSpace
from psydac.linalg.stencil import StencilMatrix
from psydac.linalg.stencil import StencilVector
from gallery_section_03 import assemble_stiffness_1d
from gallery_section_03 import assemble_vector_1d
xmin = 0. ; xmax = 1.
nelements = 8
degree = 3
grid = np.linspace( xmin, xmax, num=nelements+1 )
V = SplineSpace(degree=degree, grid=grid)
V = TensorFemSpace( V )
stiffness = StencilMatrix(V.vector_space, V.vector_space)
stiffness = assemble_stiffness_1d( V, matrix=stiffness )
stiffness = stiffness.tosparse()
f = lambda x: 2.    
rhs = StencilVector(V.vector_space)
rhs = assemble_vector_1d( f, V, rhs=rhs )
rhs = rhs.toarray()<jupyter_output><empty_output><jupyter_text>2D Case<jupyter_code>from gallery_section_03 import assemble_stiffness_2d
from gallery_section_03 import assemble_vector_2d
x1min = 0. ; x1max = 1.
x2min = 0. ; x2max = 1.
nelements1 = 8
nelements2 = 8
degree1 = 3
degree2 = 3
grid1 = np.linspace( x1min, x1max, num=nelements1+1 )
grid2 = np.linspace( x2min, x2max, num=nelements2+1 )

V1 = SplineSpace(degree=degree1, grid=grid1)
V2 = SplineSpace(degree=degree2, grid=grid2)

V = TensorFemSpace(V1, V2)
stiffness = StencilMatrix(V.vector_space, V.vector_space)
stiffness = assemble_stiffness_2d( V, matrix=stiffness )
stiffness = stiffness.tosparse()
# convert the sparse matrix to dense
stiffness = stiffness.toarray()
f = lambda x,y: 2.    
rhs = StencilVector(V.vector_space)
rhs = assemble_vector_2d( f, V, rhs=rhs )<jupyter_output><empty_output><jupyter_text>Matrix profile<jupyter_code>import matplotlib.pyplot as plt 

plt.spy(stiffness)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08960739030023095, 'fraction_numerical': 0.02725173210161663, 'mean_word_length': 6.101639344262295, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '453191', 'license': 'MIT', 'n_tokens_mistral': 812, 'n_tokens_neox': 778, 'n_words': 210, 'path': 'lessons/Chapter1/03_data_structure.ipynb', 'repo_name': 'pyccel/IGA-Python', 'size': '2165'}