<jupyter_start><jupyter_text>A step-by-step basic example  import basic modules<jupyter_code>from getfem import Mesh, MeshFem, Fem, MeshIm, Integ, Model
from numpy import arange<jupyter_output><empty_output><jupyter_text>creation of a simple cartesian mesh<jupyter_code>m = Mesh('cartesian', arange(0,1.1,0.1), arange(0,1.1,0.1))<jupyter_output><empty_output><jupyter_text>create a MeshFem of for a field of dimension 1 (i.e. a scalar field)<jupyter_code>mf = MeshFem(m, 1)<jupyter_output><empty_output><jupyter_text>assign the Q2 fem to all convexes of the MeshFem<jupyter_code>mf.set_fem(Fem('FEM_QK(2,2)'))<jupyter_output><empty_output><jupyter_text>view the expression of its basis functions on the reference convex<jupyter_code>print Fem('FEM_QK(2,2)').poly_str()<jupyter_output>('1 - 3*x - 3*y + 2*x^2 + 9*x*y + 2*y^2 - 6*x^2*y - 6*x*y^2 + 4*x^2*y^2', '4*x - 4*x^2 - 12*x*y + 12*x^2*y + 8*x*y^2 - 8*x^2*y^2', '-x + 2*x^2 + 3*x*y - 6*x^2*y - 2*x*y^2 + 4*x^2*y^2', '4*y - 12*x*y - 4*y^2 + 8*x^2*y + 12*x*y^2 - 8*x^2*y^2', '16*x*y - 16*x^2*y - 16*x*y^2 + 16*x^2*y^2', '-4*x*y + 8*x^2*y + 4*x*y^2 - 8*x^2*y^2', '-y + 3*x*y + 2*y^2 - 2*x^2*y - 6*x*y^2 + 4*x^2*y^2', '-4*x*y + 4*x^2*y + 8*x*y^2 - 8*x^2*y^2', 'x*y - 2*x^2*y - 2*x*y^2 + 4*x^2*y^2')<jupyter_text>an exact integration will be used<jupyter_code>mim = MeshIm(m, Integ('IM_EXACT_PARALLELEPIPED(2)'))<jupyter_output><empty_output><jupyter_text>detect the border of the mesh<jupyter_code>border = m.outer_faces()<jupyter_output><empty_output><jupyter_text>mark it as boundary 42<jupyter_code>m.set_region(42, border)<jupyter_output><empty_output><jupyter_text>empty real model<jupyter_code>md = Model('real')<jupyter_output><empty_output><jupyter_text>declare that "u" is an unknown of the system on the finite element method `mf`<jupyter_code>md.add_fem_variable('u', mf)<jupyter_output><empty_output><jupyter_text>add generic elliptic brick on "u"<jupyter_code>md.add_Laplacian_brick(mim, 'u');<jupyter_output><empty_output><jupyter_text>add Dirichlet condition<jupyter_code>g = mf.eval('x*(x-1) - y*(y-1)')
md.add_initialized_fem_data('DirichletData', mf, g)
md.add_Dirichlet_condition_with_multipliers(mim, 'u', mf, 42, 'DirichletData')<jupyter_output><empty_output><jupyter_text>solve the linear system<jupyter_code>md.solve()<jupyter_output><empty_output><jupyter_text>extracted solution<jupyter_code>u = md.variable('u')<jupyter_output><empty_output><jupyter_text>export computed solution<jupyter_code>mf.export_to_pos('u.pos',u,'Computed solution')
%%writefile gscript
Print "A_step-by-step_basic_example_python_image1.png";
Exit;
!cat gscript
!gmsh u.pos gscript
from IPython.core.display import Image
Image('A_step-by-step_basic_example_python_image1.png')<jupyter_output><empty_output><jupyter_text>add source term<jupyter_code>f = mf.eval('5')
md.add_initialized_fem_data('VolumicData', mf, f)
md.add_source_term_brick(mim, 'u', 'VolumicData')
md.solve()
u = md.variable('u')
mf.export_to_pos('u.pos',u,'Computed solution')
%%writefile gscript
Print "A_step-by-step_basic_example_python_image2.png";
Exit;
!gmsh u.pos gscript
Image('A_step-by-step_basic_example_python_image2.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1731615336266499, 'fraction_numerical': 0.0399120050282841, 'mean_word_length': 8.587349397590362, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 64, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '90059', 'license': 'MIT', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1450, 'n_words': 210, 'path': 'docs/getfem_examples/A_step-by-step_basic_example_python.ipynb', 'repo_name': 'UnofficialJuliaMirror/JuliaFEM.jl-f80590ac-b429-510a-8a99-e7c46989f22d', 'size': '3182'}