Generate an equidistant 1D mesh with N cells Parameters ---------- n : int Number of cells. mapping: lamda Mapping to transform the generated points. If None, the identity mapping is used. periodic: bool If True, the endpoints are identified to generate
(n, mapping = None, periodic=False)
| 3 | import ngsolve |
| 4 | |
| 5 | def Make1DMesh(n, mapping = None, periodic=False): |
| 6 | """ |
| 7 | Generate an equidistant 1D mesh with N cells |
| 8 | |
| 9 | Parameters |
| 10 | ---------- |
| 11 | n : int |
| 12 | Number of cells. |
| 13 | |
| 14 | mapping: lamda |
| 15 | Mapping to transform the generated points. If None, the identity mapping is used. |
| 16 | |
| 17 | periodic: bool |
| 18 | If True, the endpoints are identified to generate a periodic mesh. |
| 19 | |
| 20 | Returns |
| 21 | ------- |
| 22 | (ngsolve.mesh) |
| 23 | Returns generated 1D NGSolve mesh |
| 24 | |
| 25 | """ |
| 26 | mesh = Mesh(dim=1) |
| 27 | pids = [] |
| 28 | for i in range(n+1): |
| 29 | x = i/n |
| 30 | if mapping: |
| 31 | x = mapping(x) |
| 32 | pids.append (mesh.Add (MeshPoint(Pnt(x, 0, 0)))) |
| 33 | |
| 34 | idx_inner = mesh.AddRegion("dom", dim=1) |
| 35 | idx_left = mesh.AddRegion("left", dim=0) |
| 36 | idx_right = mesh.AddRegion("right", dim=0) |
| 37 | |
| 38 | for i in range(n): |
| 39 | mesh.Add(Element1D([pids[i+1],pids[i]],index=idx_inner)) |
| 40 | mesh.Add (Element0D( pids[0], index=idx_left)) |
| 41 | mesh.Add (Element0D( pids[n], index=idx_right)) |
| 42 | if periodic: |
| 43 | mesh.AddPointIdentification(pids[0],pids[n],1,2) |
| 44 | ngsmesh = ngsolve.Mesh(mesh) |
| 45 | return ngsmesh |
| 46 | |
| 47 | def MakeStructured2DMesh(quads=True, nx=10, ny=10, secondorder=False, periodic_x=False, periodic_y=False, mapping = None, bbpts=None, bbnames=None, flip_triangles=False, boundarylayer=None, hppnts=None): |
| 48 | """ |