Coverage for src/methodsnm/mesh_2d.py: 88%
25 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-27 13:22 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-27 13:22 +0000
1from abc import ABC, abstractmethod
2import numpy as np
3from numpy import array
5from methodsnm.mesh import Mesh
6from methodsnm.trafo import TriangleTransformation
8class Mesh2D(Mesh):
9 def __init__(self):
10 self.dimension = 2
12class StructuredRectangleMesh(Mesh2D):
13 def __init__(self, M, N, mapping = None):
14 super().__init__()
15 if mapping is None:
16 mapping = lambda x,y: [x,y]
17 self.points = np.array([array(mapping(i/M,j/N)) for j in range(N+1) for i in range(M+1)])
18 self.vertices = np.arange((M+1)*(N+1))
19 self.faces = np.array([[ j*(M+1)+i, j*(M+1)+i+1, (j+1)*(M+1)+i] for i in range(M) for j in range(N)] +
20 [[ j*(M+1)+i+1, (j+1)*(M+1)+i+1, (j+1)*(M+1)+i] for i in range(M) for j in range(N)], dtype=int)
21 self.edges = np.array([[ j*(M+1)+i, j*(M+1)+i+1] for j in range(N+1) for i in range(M) ] +
22 [[ j*(M+1)+i, (j+1)*(M+1)+i] for i in range(M+1) for j in range(N)] +
23 [[(j+1)*(M+1)+i, j*(M+1)+i+1] for i in range(M) for j in range(N)], dtype=int)
24 self.bndry_vertices = [i for i in range(M)] + [M+j*(M+1) for j in range(N)] \
25 + [(N+1)*(M+1)-i-1 for i in range(M)] + [(N-j)*(M+1) for j in range(N)]
26 self.bndry_edges = [i for i in range(M)] + [2*N*M+M+j for j in range(N)] \
27 + [N*M+M-1-i for i in range(M)] + [(N+1)*M+N-1-j for j in range(N)]
28 offset = 2*M*N+M+N
29 self.faces2edges = np.array([[offset+i+j*M, M*(N+1)+j+i*N, i+j*M] for i in range(M)
30 for j in range(N)] \
31 +[[i+(j+1)*M, offset+i+j*M, M*(N+1)+j+(i+1)*N] for i in range(M)
32 for j in range(N)], dtype=int)
34 def trafo(self, elnr, codim=0, bndry=False):
35 if codim > 0 or bndry:
36 raise NotImplementedError("Not implemented yet")
37 return TriangleTransformation(self, elnr)