<jupyter_start><jupyter_text>.. _quickstart: Quickstart==========This notebook was made with the following version of FEMpy:<jupyter_code>import FEMpy
FEMpy.__version__<jupyter_output><empty_output><jupyter_text>FEMpy can be used to solve Poisson equations on 1D and 2D domains. For this example, let us consider the problem:$$-\frac{{\rm d}}{{\rm d} x} \left( e^x \frac{{\rm d}}{{\rm d} x} u(x)\right) = -e^x [\cos x -2\sin x - x \cos x - x \sin x]; x \in [0, 1]$$$$u(0) = 0, u(1) = \cos(1)$$To start, we will need to import our necessary aditional packages.<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Let us define our coefficient and source functions,<jupyter_code>coefficient_function = lambda x: np.exp(x)
source_function = lambda x: -np.exp(x) * (np.cos(x) - 2*np.sin(x) - x*np.cos(x) - x*np.sin(x))<jupyter_output><empty_output><jupyter_text>And our boundary condition,<jupyter_code>def dirichlet_function(x):
    if x == 0:
        return 0
    elif x == 1:
        return np.cos(1)<jupyter_output><empty_output><jupyter_text>Under the Galerkin formulation, we can write our differiential equation as$$\int_a^b c u' v' {\rm d}x = \int_a^b f v {\rm d}x$$where $v(x)$ is a test function. We then can choose our test and trial basis functions such that$$ u_h \in \{\phi \in C[a,b] \mid \phi(x) \text{ linear on each } [x_n, x_{n+1}]; (n = 1,2,\dotsc,N)\} $$and$$ \int_a^b c u_h' v_h' {\rm d}x = \int_a^b f v_h {\rm d}x $$for any $v_h \in U_h$ Thus, we can define our test and trial basis function basis functions by:<jupyter_code>basis = FEMpy.IntervalBasis1D('linear')<jupyter_output><empty_output><jupyter_text>We can set up our mesh using a step size of $h=1/4$<jupyter_code>mesh = FEMpy.Interval1D(left=0, right=1, h=1/4, basis_type='linear')<jupyter_output><empty_output><jupyter_text>The boundary conditions are defined by:<jupyter_code>bcs = FEMpy.BoundaryConditions(mesh, boundary_types=('dirichlet', 'dirichlet'), dirichlet_fun=dirichlet_function)<jupyter_output><empty_output><jupyter_text>Finally, we can input our mesh, basis functions, and boundary conditions into our Poisson equation then call our solver.<jupyter_code>poisson_eq = FEMpy.Poisson1D(mesh, fe_test_basis=basis, fe_trial_basis=basis, boundary_conditions=bcs)
poisson_eq.solve(coefficient_function, source_function)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1420093259855871, 'fraction_numerical': 0.011021619330224672, 'mean_word_length': 5.840579710144928, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '83412', 'license': 'MIT', 'n_tokens_mistral': 908, 'n_tokens_neox': 872, 'n_words': 238, 'path': 'docs/_build/_static/notebooks/quickstart.ipynb', 'repo_name': 'floydie7/FEMpy', 'size': '2359'}