Meshes in 2D¶

In 2D we provide a mesh for rectangles, StructuredRectangleMesh:

In [1]:
from import_hack import *
from methodsnm.mesh_2d import *
from methodsnm.visualize import DrawMesh2D
m = StructuredRectangleMesh(10, 10)
DrawMesh2D(m)
source module for methodsNM imported.
No description has been provided for this image
In [2]:
from numpy import sin, cos, pi
mc = StructuredRectangleMesh(12, 3, mapping= lambda x,y: (cos(pi*x)*(1+y), sin(pi*x)*(1+y)))
DrawMesh2D(mc)
No description has been provided for this image
In [3]:
from methodsnm.visualize import DrawFunction2D
from methodsnm.meshfct import GlobalFunction
from numpy import sin, cos, pi
u = GlobalFunction(function=lambda x: sin(2*(x[0]-x[1])*pi), mesh=mc)
DrawFunction2D(u, sampling=10, contour=True, shrink_eps=0.08,figsize=(8,5))
DrawFunction2D(u, sampling=20, contour=False, figsize=(6,6))
No description has been provided for this image
No description has been provided for this image

FEFunctions in 2D¶

Task FES2D-1¶

Implement the P1_Triangle_Space to make the following visualization of basis functions work:

In [4]:
from methodsnm.fes import *
from methodsnm.meshfct import FEFunction
m = StructuredRectangleMesh(1, 1)
fes = P1_Triangle_Space(m)
uh = FEFunction(fes)
for contour in [False, True]:
    for i in range(fes.ndof):
        uh.vector[:] = 0
        uh.vector[i] = 1
        DrawFunction2D(uh,shrink_eps=0.05, figsize=(4,4), contour=contour)   
No description has been provided for this image