Coverage for src/methodsnm/mesh_1d.py: 92%
26 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
7from methodsnm.trafo import IntervalTransformation
9class Mesh1D(Mesh):
10 def __init__(self, points, sub_intervals=1):
11 self.dimension = 1
12 ne = (len(points)-1) * sub_intervals
13 nv = ne + 1
14 self.points = np.empty(nv)
15 nme = len(points)-1
16 for i in range(nme):
17 for j in range(sub_intervals):
18 self.points[i*sub_intervals+j] = points[i] + j*(points[i+1]-points[i])/sub_intervals
19 self.points[-1] = points[-1]
20 self.vertices = np.arange(nv)
21 self.edges = np.array([[i,i+1] for i in range(ne)])
22 self.bndry_vertices = np.array([0,nv-1])
23 self.bndry_edges = None
25 def trafo(self, elnr, codim=0, bndry=False):
26 if codim > 0 or bndry:
27 raise NotImplementedError("Not implemented")
28 return IntervalTransformation(self, elnr)
30 def uniform_refine(self):
31 return Mesh1D(self.points, sub_intervals=2)