ngsolve 6.2.2506.post74.dev0__cp314-cp314-macosx_10_15_universal2.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ngsolve might be problematic. Click here for more details.
- netgen/include/analytic_integrals.hpp +10 -0
- netgen/include/arnoldi.hpp +55 -0
- netgen/include/bandmatrix.hpp +334 -0
- netgen/include/basematrix.hpp +957 -0
- netgen/include/basevector.hpp +1268 -0
- netgen/include/bdbequations.hpp +2805 -0
- netgen/include/bdbintegrator.hpp +1660 -0
- netgen/include/bem_diffops.hpp +475 -0
- netgen/include/bessel.hpp +1064 -0
- netgen/include/bilinearform.hpp +963 -0
- netgen/include/bla.hpp +29 -0
- netgen/include/blockalloc.hpp +95 -0
- netgen/include/blockjacobi.hpp +328 -0
- netgen/include/bspline.hpp +116 -0
- netgen/include/calcinverse.hpp +141 -0
- netgen/include/cg.hpp +368 -0
- netgen/include/chebyshev.hpp +44 -0
- netgen/include/cholesky.hpp +720 -0
- netgen/include/clapack.h +7254 -0
- netgen/include/code_generation.hpp +296 -0
- netgen/include/coefficient.hpp +2033 -0
- netgen/include/coefficient_impl.hpp +19 -0
- netgen/include/coefficient_stdmath.hpp +167 -0
- netgen/include/commutingAMG.hpp +106 -0
- netgen/include/comp.hpp +79 -0
- netgen/include/compatibility.hpp +41 -0
- netgen/include/complex_wrapper.hpp +73 -0
- netgen/include/compressedfespace.hpp +110 -0
- netgen/include/contact.hpp +235 -0
- netgen/include/diagonalmatrix.hpp +154 -0
- netgen/include/differentialoperator.hpp +276 -0
- netgen/include/diffop.hpp +1286 -0
- netgen/include/diffop_impl.hpp +328 -0
- netgen/include/diffopwithfactor.hpp +123 -0
- netgen/include/discontinuous.hpp +84 -0
- netgen/include/dump.hpp +949 -0
- netgen/include/ectypes.hpp +121 -0
- netgen/include/eigen.hpp +60 -0
- netgen/include/eigensystem.hpp +18 -0
- netgen/include/elasticity_equations.hpp +595 -0
- netgen/include/elementbyelement.hpp +195 -0
- netgen/include/elementtopology.hpp +1760 -0
- netgen/include/elementtransformation.hpp +339 -0
- netgen/include/evalfunc.hpp +405 -0
- netgen/include/expr.hpp +1686 -0
- netgen/include/facetfe.hpp +175 -0
- netgen/include/facetfespace.hpp +180 -0
- netgen/include/facethofe.hpp +111 -0
- netgen/include/facetsurffespace.hpp +112 -0
- netgen/include/fe_interfaces.hpp +32 -0
- netgen/include/fem.hpp +87 -0
- netgen/include/fesconvert.hpp +14 -0
- netgen/include/fespace.hpp +1449 -0
- netgen/include/finiteelement.hpp +286 -0
- netgen/include/globalinterfacespace.hpp +77 -0
- netgen/include/globalspace.hpp +115 -0
- netgen/include/gridfunction.hpp +525 -0
- netgen/include/h1amg.hpp +124 -0
- netgen/include/h1hofe.hpp +188 -0
- netgen/include/h1hofe_impl.hpp +1262 -0
- netgen/include/h1hofefo.hpp +148 -0
- netgen/include/h1hofefo_impl.hpp +185 -0
- netgen/include/h1hofespace.hpp +167 -0
- netgen/include/h1lofe.hpp +1240 -0
- netgen/include/h1lumping.hpp +41 -0
- netgen/include/hcurl_equations.hpp +1381 -0
- netgen/include/hcurlcurlfe.hpp +2241 -0
- netgen/include/hcurlcurlfespace.hpp +78 -0
- netgen/include/hcurlfe.hpp +259 -0
- netgen/include/hcurlfe_utils.hpp +107 -0
- netgen/include/hcurlhdiv_dshape.hpp +857 -0
- netgen/include/hcurlhdivfes.hpp +308 -0
- netgen/include/hcurlhofe.hpp +175 -0
- netgen/include/hcurlhofe_impl.hpp +1871 -0
- netgen/include/hcurlhofespace.hpp +193 -0
- netgen/include/hcurllofe.hpp +1146 -0
- netgen/include/hdiv_equations.hpp +880 -0
- netgen/include/hdivdivfe.hpp +2923 -0
- netgen/include/hdivdivsurfacespace.hpp +76 -0
- netgen/include/hdivfe.hpp +206 -0
- netgen/include/hdivfe_utils.hpp +717 -0
- netgen/include/hdivfes.hpp +75 -0
- netgen/include/hdivhofe.hpp +447 -0
- netgen/include/hdivhofe_impl.hpp +1107 -0
- netgen/include/hdivhofefo.hpp +229 -0
- netgen/include/hdivhofespace.hpp +177 -0
- netgen/include/hdivhosurfacefespace.hpp +106 -0
- netgen/include/hdivlofe.hpp +773 -0
- netgen/include/hidden.hpp +74 -0
- netgen/include/householder.hpp +181 -0
- netgen/include/hypre_ams_precond.hpp +123 -0
- netgen/include/hypre_precond.hpp +73 -0
- netgen/include/integrator.hpp +2012 -0
- netgen/include/integratorcf.hpp +253 -0
- netgen/include/interpolate.hpp +49 -0
- netgen/include/intrule.hpp +2542 -0
- netgen/include/intrules_SauterSchwab.hpp +25 -0
- netgen/include/irspace.hpp +49 -0
- netgen/include/jacobi.hpp +153 -0
- netgen/include/kernels.hpp +762 -0
- netgen/include/l2hofe.hpp +194 -0
- netgen/include/l2hofe_impl.hpp +564 -0
- netgen/include/l2hofefo.hpp +542 -0
- netgen/include/l2hofespace.hpp +344 -0
- netgen/include/la.hpp +38 -0
- netgen/include/linearform.hpp +266 -0
- netgen/include/matrix.hpp +2140 -0
- netgen/include/memusage.hpp +41 -0
- netgen/include/meshaccess.hpp +1359 -0
- netgen/include/mgpre.hpp +204 -0
- netgen/include/mp_coefficient.hpp +145 -0
- netgen/include/mptools.hpp +2281 -0
- netgen/include/multigrid.hpp +42 -0
- netgen/include/multivector.hpp +447 -0
- netgen/include/mumpsinverse.hpp +187 -0
- netgen/include/mycomplex.hpp +361 -0
- netgen/include/ng_lapack.hpp +1661 -0
- netgen/include/ngblas.hpp +1232 -0
- netgen/include/ngs_defines.hpp +30 -0
- netgen/include/ngs_stdcpp_include.hpp +106 -0
- netgen/include/ngs_utils.hpp +121 -0
- netgen/include/ngsobject.hpp +1019 -0
- netgen/include/ngsstream.hpp +113 -0
- netgen/include/ngstd.hpp +72 -0
- netgen/include/nodalhofe.hpp +96 -0
- netgen/include/nodalhofe_impl.hpp +141 -0
- netgen/include/normalfacetfe.hpp +223 -0
- netgen/include/normalfacetfespace.hpp +98 -0
- netgen/include/normalfacetsurfacefespace.hpp +84 -0
- netgen/include/order.hpp +251 -0
- netgen/include/parallel_matrices.hpp +222 -0
- netgen/include/paralleldofs.hpp +340 -0
- netgen/include/parallelngs.hpp +23 -0
- netgen/include/parallelvector.hpp +269 -0
- netgen/include/pardisoinverse.hpp +200 -0
- netgen/include/periodic.hpp +129 -0
- netgen/include/plateaufespace.hpp +25 -0
- netgen/include/pml.hpp +275 -0
- netgen/include/pmltrafo.hpp +631 -0
- netgen/include/postproc.hpp +142 -0
- netgen/include/potentialtools.hpp +22 -0
- netgen/include/precomp.hpp +60 -0
- netgen/include/preconditioner.hpp +602 -0
- netgen/include/prolongation.hpp +377 -0
- netgen/include/python_comp.hpp +107 -0
- netgen/include/python_fem.hpp +89 -0
- netgen/include/python_linalg.hpp +58 -0
- netgen/include/python_ngstd.hpp +386 -0
- netgen/include/recursive_pol.hpp +4896 -0
- netgen/include/recursive_pol_tet.hpp +395 -0
- netgen/include/recursive_pol_trig.hpp +492 -0
- netgen/include/reorderedfespace.hpp +81 -0
- netgen/include/sample_sort.hpp +105 -0
- netgen/include/scalarfe.hpp +335 -0
- netgen/include/shapefunction_utils.hpp +113 -0
- netgen/include/simd_complex.hpp +329 -0
- netgen/include/smoother.hpp +253 -0
- netgen/include/solve.hpp +89 -0
- netgen/include/sparsecholesky.hpp +313 -0
- netgen/include/sparsematrix.hpp +1038 -0
- netgen/include/sparsematrix_dyn.hpp +90 -0
- netgen/include/sparsematrix_impl.hpp +1013 -0
- netgen/include/special_matrix.hpp +463 -0
- netgen/include/specialelement.hpp +125 -0
- netgen/include/statushandler.hpp +33 -0
- netgen/include/stringops.hpp +12 -0
- netgen/include/superluinverse.hpp +136 -0
- netgen/include/symbolicintegrator.hpp +850 -0
- netgen/include/symmetricmatrix.hpp +144 -0
- netgen/include/tangentialfacetfe.hpp +224 -0
- netgen/include/tangentialfacetfespace.hpp +91 -0
- netgen/include/tensor.hpp +522 -0
- netgen/include/tensorcoefficient.hpp +446 -0
- netgen/include/tensorproductintegrator.hpp +113 -0
- netgen/include/thcurlfe.hpp +128 -0
- netgen/include/thcurlfe_impl.hpp +380 -0
- netgen/include/thdivfe.hpp +80 -0
- netgen/include/thdivfe_impl.hpp +492 -0
- netgen/include/tpdiffop.hpp +461 -0
- netgen/include/tpfes.hpp +133 -0
- netgen/include/tpintrule.hpp +224 -0
- netgen/include/triangular.hpp +465 -0
- netgen/include/tscalarfe.hpp +245 -0
- netgen/include/tscalarfe_impl.hpp +1029 -0
- netgen/include/umfpackinverse.hpp +148 -0
- netgen/include/vector.hpp +1273 -0
- netgen/include/voxelcoefficientfunction.hpp +41 -0
- netgen/include/vtkoutput.hpp +198 -0
- netgen/include/vvector.hpp +208 -0
- netgen/include/webgui.hpp +92 -0
- netgen/libngbla.dylib +0 -0
- netgen/libngcomp.dylib +0 -0
- netgen/libngfem.dylib +0 -0
- netgen/libngla.dylib +0 -0
- netgen/libngsbem.dylib +0 -0
- netgen/libngsolve.dylib +0 -0
- netgen/libngstd.dylib +0 -0
- ngsolve/TensorProductTools.py +210 -0
- ngsolve/__console.py +94 -0
- ngsolve/__expr.py +181 -0
- ngsolve/__init__.py +148 -0
- ngsolve/__init__.pyi +233 -0
- ngsolve/_scikit_build_core_dependencies.py +30 -0
- ngsolve/bla.pyi +1153 -0
- ngsolve/bvp.py +78 -0
- ngsolve/bvp.pyi +32 -0
- ngsolve/cmake/NGSolveConfig.cmake +102 -0
- ngsolve/cmake/ngsolve-targets-release.cmake +79 -0
- ngsolve/cmake/ngsolve-targets.cmake +163 -0
- ngsolve/comp/__init__.pyi +5449 -0
- ngsolve/comp/pml.pyi +89 -0
- ngsolve/config/__init__.py +1 -0
- ngsolve/config/__init__.pyi +43 -0
- ngsolve/config/__main__.py +4 -0
- ngsolve/config/config.py +60 -0
- ngsolve/config/config.pyi +45 -0
- ngsolve/demos/TensorProduct/__init__.py +0 -0
- ngsolve/demos/TensorProduct/tp_dg_1d_1d.py +80 -0
- ngsolve/demos/TensorProduct/tp_dg_1d_2d.py +73 -0
- ngsolve/demos/TensorProduct/tp_dg_2d_1d.py +72 -0
- ngsolve/demos/TensorProduct/tp_dg_2d_2d.py +66 -0
- ngsolve/demos/__init__.py +0 -0
- ngsolve/demos/howto/__init__.py +0 -0
- ngsolve/demos/howto/hhj.py +44 -0
- ngsolve/demos/howto/hybrid_dg.py +53 -0
- ngsolve/demos/howto/mixed.py +30 -0
- ngsolve/demos/howto/nonlin.py +29 -0
- ngsolve/demos/howto/pickling.py +26 -0
- ngsolve/demos/howto/pml.py +31 -0
- ngsolve/demos/howto/taskmanager.py +20 -0
- ngsolve/demos/howto/tdnns.py +47 -0
- ngsolve/demos/howto/timeDG-skeleton.py +45 -0
- ngsolve/demos/howto/timeDG.py +38 -0
- ngsolve/demos/howto/timeDGlap.py +42 -0
- ngsolve/demos/howto/timeDGwave.py +61 -0
- ngsolve/demos/intro/__init__.py +0 -0
- ngsolve/demos/intro/adaptive.py +123 -0
- ngsolve/demos/intro/cmagnet.py +59 -0
- ngsolve/demos/intro/elasticity.py +76 -0
- ngsolve/demos/intro/navierstokes.py +74 -0
- ngsolve/demos/intro/poisson.ipynb +170 -0
- ngsolve/demos/intro/poisson.py +41 -0
- ngsolve/demos/mpi/__init__.py +0 -0
- ngsolve/demos/mpi/mpi_cmagnet.py +87 -0
- ngsolve/demos/mpi/mpi_navierstokes.py +117 -0
- ngsolve/demos/mpi/mpi_poisson.py +89 -0
- ngsolve/demos/mpi/mpi_timeDG.py +82 -0
- ngsolve/directsolvers.py +26 -0
- ngsolve/directsolvers.pyi +15 -0
- ngsolve/eigenvalues.py +364 -0
- ngsolve/eigenvalues.pyi +30 -0
- ngsolve/fem.pyi +1647 -0
- ngsolve/internal.py +89 -0
- ngsolve/krylovspace.py +1013 -0
- ngsolve/krylovspace.pyi +298 -0
- ngsolve/la.pyi +1230 -0
- ngsolve/meshes.py +748 -0
- ngsolve/ngs2petsc.py +310 -0
- ngsolve/ngscxx.py +42 -0
- ngsolve/ngslib.so +0 -0
- ngsolve/ngstd.pyi +59 -0
- ngsolve/nonlinearsolvers.py +203 -0
- ngsolve/nonlinearsolvers.pyi +95 -0
- ngsolve/preconditioners.py +11 -0
- ngsolve/preconditioners.pyi +7 -0
- ngsolve/solve.pyi +109 -0
- ngsolve/solve_implementation.py +168 -0
- ngsolve/solve_implementation.pyi +42 -0
- ngsolve/solvers.py +7 -0
- ngsolve/solvers.pyi +14 -0
- ngsolve/timestepping.py +185 -0
- ngsolve/timestepping.pyi +28 -0
- ngsolve/timing.py +108 -0
- ngsolve/timing.pyi +54 -0
- ngsolve/utils.py +167 -0
- ngsolve/utils.pyi +273 -0
- ngsolve/webgui.py +670 -0
- ngsolve-6.2.2506.post74.dev0.data/data/Netgen.icns +0 -0
- ngsolve-6.2.2506.post74.dev0.data/data/bin/ngscxx +17 -0
- ngsolve-6.2.2506.post74.dev0.data/data/bin/ngsld +13 -0
- ngsolve-6.2.2506.post74.dev0.data/data/bin/ngsolve.tcl +648 -0
- ngsolve-6.2.2506.post74.dev0.data/data/bin/ngspy +2 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/beam.geo +17 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/beam.vol +240 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/chip.in2d +41 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/chip.vol +614 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/coil.geo +12 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/coil.vol +2560 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/coilshield.geo +24 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/coilshield.vol +3179 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/cube.geo +19 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/cube.vol +1832 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d10_DGdoubleglazing.pde +50 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d11_chip_nitsche.pde +40 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d1_square.pde +43 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d2_chip.pde +35 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d3_helmholtz.pde +22 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d4_cube.pde +46 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d5_beam.pde +74 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d6_shaft.pde +73 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d7_coil.pde +50 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d8_coilshield.pde +49 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d9_hybridDG.pde +72 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/doubleglazing.in2d +27 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/doubleglazing.vol +737 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/piezo2d40round4.vol.gz +0 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/shaft.geo +73 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/shaft.vol +4291 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/square.in2d +17 -0
- ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/square.vol +149 -0
- ngsolve-6.2.2506.post74.dev0.dist-info/METADATA +13 -0
- ngsolve-6.2.2506.post74.dev0.dist-info/RECORD +315 -0
- ngsolve-6.2.2506.post74.dev0.dist-info/WHEEL +5 -0
- ngsolve-6.2.2506.post74.dev0.dist-info/licenses/LICENSE +504 -0
- ngsolve-6.2.2506.post74.dev0.dist-info/top_level.txt +2 -0
ngsolve/meshes.py
ADDED
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
from netgen.meshing import *
|
|
2
|
+
from netgen.csg import *
|
|
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
|
+
"""
|
|
49
|
+
Generate a structured 2D mesh
|
|
50
|
+
|
|
51
|
+
Parameters
|
|
52
|
+
----------
|
|
53
|
+
quads : bool
|
|
54
|
+
If True, a quadrilateral mesh is generated. If False, the quads are split to triangles.
|
|
55
|
+
|
|
56
|
+
nx : int
|
|
57
|
+
Number of cells in x-direction.
|
|
58
|
+
|
|
59
|
+
ny : int
|
|
60
|
+
Number of cells in y-direction.
|
|
61
|
+
|
|
62
|
+
secondorder : bool
|
|
63
|
+
If True, second order curved elements are used.
|
|
64
|
+
|
|
65
|
+
periodic_x: bool
|
|
66
|
+
If True, the left and right boundaries are identified to generate a periodic mesh in x-direction.
|
|
67
|
+
|
|
68
|
+
periodic_y: bool
|
|
69
|
+
If True, the top and bottom boundaries are identified to generate a periodic mesh in y-direction.
|
|
70
|
+
|
|
71
|
+
mapping: lamda
|
|
72
|
+
Mapping to transform the generated points. If None, the identity mapping is used.
|
|
73
|
+
|
|
74
|
+
bbpts : list
|
|
75
|
+
List of points which should be handled as BBND and are named with bbnames. The mesh (nx, ny and mapping) must be constructed in such a way that the bbpts coincide with generated points. Otherwise an Exception is thrown.
|
|
76
|
+
|
|
77
|
+
bbnames : list
|
|
78
|
+
List of bbnd names as strings. Size must coincide with size of bbpts. Otherwise an Exception is thrown.
|
|
79
|
+
|
|
80
|
+
flip_triangles : bool
|
|
81
|
+
If set to True together with quads=False the quads are cut the other way round
|
|
82
|
+
|
|
83
|
+
boundarylayer : dict
|
|
84
|
+
If not None it expects a dictionary of the form { "boundaryname" : [t1,...,tn] } where ti denote the thickness of layer i. The number of layers are included in nx/ny. After the layers are placed the remaining number of cells are used to divide the remaining grid uniformly.
|
|
85
|
+
|
|
86
|
+
hppnts : list
|
|
87
|
+
If not None it expects a list of the form [ (px1,py1, hpref1), (px2,py2, hpref2), ... ] where px,py are the point coordinates which have to be resolved in the mesh and hpref the refinement factor
|
|
88
|
+
|
|
89
|
+
Returns
|
|
90
|
+
-------
|
|
91
|
+
(ngsolve.mesh)
|
|
92
|
+
Returns generated 2D NGSolve mesh
|
|
93
|
+
|
|
94
|
+
"""
|
|
95
|
+
mesh = Mesh()
|
|
96
|
+
mesh.dim=2
|
|
97
|
+
|
|
98
|
+
if (bbpts and bbnames) and len(bbpts) != len(bbnames):
|
|
99
|
+
raise Exception("Lenght of bbnames does not coincide with length of bbpts!")
|
|
100
|
+
|
|
101
|
+
found = []
|
|
102
|
+
indbbpts = []
|
|
103
|
+
if bbpts:
|
|
104
|
+
for i in range(len(bbpts)):
|
|
105
|
+
found.append(False)
|
|
106
|
+
indbbpts.append(None)
|
|
107
|
+
foundhp = [ False for i in hppnts] if hppnts else []
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
pids = []
|
|
111
|
+
if periodic_y:
|
|
112
|
+
minioni = []
|
|
113
|
+
masteri = []
|
|
114
|
+
if periodic_x:
|
|
115
|
+
minionj = []
|
|
116
|
+
masterj = []
|
|
117
|
+
|
|
118
|
+
numlayerleft = len(boundarylayer["left"]) if (boundarylayer and boundarylayer.get("left")) else 0
|
|
119
|
+
numlayerright = len(boundarylayer["right"]) if (boundarylayer and boundarylayer.get("right")) else 0
|
|
120
|
+
numlayertop = len(boundarylayer["top"]) if (boundarylayer and boundarylayer.get("top")) else 0
|
|
121
|
+
numlayerbot = len(boundarylayer["bottom"]) if (boundarylayer and boundarylayer.get("bottom")) else 0
|
|
122
|
+
|
|
123
|
+
thicknessleft = [0]
|
|
124
|
+
thicknessright = [0]
|
|
125
|
+
thicknesstop = [0]
|
|
126
|
+
thicknessbot = [0]
|
|
127
|
+
for i in range(numlayerleft):
|
|
128
|
+
thicknessleft.append(thicknessleft[-1]+boundarylayer["left"][i])
|
|
129
|
+
for i in range(numlayerright):
|
|
130
|
+
thicknessright.append(thicknessright[-1]+boundarylayer["right"][i])
|
|
131
|
+
for i in range(numlayertop):
|
|
132
|
+
thicknesstop.append(thicknesstop[-1]+boundarylayer["top"][i])
|
|
133
|
+
for i in range(numlayerbot):
|
|
134
|
+
thicknessbot.append(thicknessbot[-1]+boundarylayer["bottom"][i])
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
for i in range(ny+1):
|
|
138
|
+
for j in range(nx+1):
|
|
139
|
+
x = thicknessleft[j] if j < numlayerleft else ((thicknessleft[-1]+(j-numlayerleft)/(nx-numlayerleft-numlayerright)*(1-thicknessleft[-1]-thicknessright[-1])) if j < nx-numlayerright else 1-thicknessright[nx-j])
|
|
140
|
+
y = thicknessbot[i] if i < numlayerbot else ((thicknessbot[-1]+(i-numlayerbot)/(ny-numlayerbot-numlayertop)*(1-thicknessbot[-1]-thicknesstop[-1])) if i< ny-numlayertop else 1-thicknesstop[ny-i])
|
|
141
|
+
pids.append(mesh.Add (MeshPoint(Pnt(x,y,0))))
|
|
142
|
+
if periodic_y:
|
|
143
|
+
if i == 0:
|
|
144
|
+
minioni.append(pids[-1])
|
|
145
|
+
if i == ny:
|
|
146
|
+
masteri.append(pids[-1])
|
|
147
|
+
if periodic_x:
|
|
148
|
+
if j == 0:
|
|
149
|
+
minionj.append(pids[-1])
|
|
150
|
+
if j == nx:
|
|
151
|
+
masterj.append(pids[-1])
|
|
152
|
+
if periodic_y:
|
|
153
|
+
for i in range(len(minioni)):
|
|
154
|
+
mesh.AddPointIdentification(masteri[i],minioni[i],identnr=1,type=2)
|
|
155
|
+
if periodic_x:
|
|
156
|
+
for j in range(len(minionj)):
|
|
157
|
+
mesh.AddPointIdentification(masterj[j],minionj[j],identnr=2,type=2)
|
|
158
|
+
|
|
159
|
+
# mesh.Add(FaceDescriptor(surfnr=1,domin=1,bc=1))
|
|
160
|
+
idx_dom = mesh.AddRegion("dom", dim=2)
|
|
161
|
+
idx_bottom = mesh.AddRegion("bottom", dim=1)
|
|
162
|
+
idx_right = mesh.AddRegion("right", dim=1)
|
|
163
|
+
idx_top = mesh.AddRegion("top", dim=1)
|
|
164
|
+
idx_left = mesh.AddRegion("left", dim=1)
|
|
165
|
+
|
|
166
|
+
for i in range(ny):
|
|
167
|
+
for j in range(nx):
|
|
168
|
+
base = i * (nx+1) + j
|
|
169
|
+
if quads:
|
|
170
|
+
pnum = [base,base+1,base+nx+2,base+nx+1]
|
|
171
|
+
elpids = [pids[p] for p in pnum]
|
|
172
|
+
el = Element2D(idx_dom,elpids)
|
|
173
|
+
if not mapping:
|
|
174
|
+
el.curved=False
|
|
175
|
+
mesh.Add(el)
|
|
176
|
+
else:
|
|
177
|
+
if flip_triangles:
|
|
178
|
+
pnum1 = [base,base+1,base+nx+2]
|
|
179
|
+
pnum2 = [base,base+nx+2,base+nx+1]
|
|
180
|
+
else:
|
|
181
|
+
pnum1 = [base,base+1,base+nx+1]
|
|
182
|
+
pnum2 = [base+1,base+nx+2,base+nx+1]
|
|
183
|
+
elpids1 = [pids[p] for p in pnum1]
|
|
184
|
+
elpids2 = [pids[p] for p in pnum2]
|
|
185
|
+
mesh.Add(Element2D(idx_dom,elpids1))
|
|
186
|
+
mesh.Add(Element2D(idx_dom,elpids2))
|
|
187
|
+
|
|
188
|
+
for i in range(nx):
|
|
189
|
+
mesh.Add(Element1D([pids[i], pids[i+1]], index=idx_bottom))
|
|
190
|
+
for i in range(ny):
|
|
191
|
+
mesh.Add(Element1D([pids[i*(nx+1)+nx], pids[(i+1)*(nx+1)+nx]], index=idx_right))
|
|
192
|
+
for i in range(nx):
|
|
193
|
+
mesh.Add(Element1D([pids[ny*(nx+1)+i+1], pids[ny*(nx+1)+i]], index=idx_top))
|
|
194
|
+
for i in range(ny):
|
|
195
|
+
mesh.Add(Element1D([pids[(i+1)*(nx+1)], pids[i*(nx+1)]], index=idx_left))
|
|
196
|
+
|
|
197
|
+
# mesh.SetBCName(0, "bottom")
|
|
198
|
+
# mesh.SetBCName(1, "right")
|
|
199
|
+
# mesh.SetBCName(2, "top")
|
|
200
|
+
# mesh.SetBCName(3, "left")
|
|
201
|
+
|
|
202
|
+
mesh.Compress()
|
|
203
|
+
|
|
204
|
+
if secondorder:
|
|
205
|
+
mesh.SecondOrder()
|
|
206
|
+
|
|
207
|
+
if mapping:
|
|
208
|
+
for p in mesh.Points():
|
|
209
|
+
x,y,z = p.p
|
|
210
|
+
x,y = mapping(x,y)
|
|
211
|
+
p[0] = x
|
|
212
|
+
p[1] = y
|
|
213
|
+
|
|
214
|
+
for k in range(len(found)):
|
|
215
|
+
i = 0
|
|
216
|
+
for p in mesh.Points():
|
|
217
|
+
if abs(p.p[0]-bbpts[k][0])+abs(p.p[1]-bbpts[k][1]) < 1e-6:
|
|
218
|
+
indbbpts[k] = pids[i]
|
|
219
|
+
found[k] = True
|
|
220
|
+
i += 1
|
|
221
|
+
for k in range(len(found)):
|
|
222
|
+
if found[k] == False:
|
|
223
|
+
raise Exception("bbpnt[",k,"] not in structured mesh!")
|
|
224
|
+
for i in range(len(indbbpts)):
|
|
225
|
+
mesh.Add(Element0D(indbbpts[i], index=i+1))
|
|
226
|
+
mesh.SetCD2Name(i+1, bbnames[i])
|
|
227
|
+
|
|
228
|
+
for k in range(len(foundhp)):
|
|
229
|
+
i = 0
|
|
230
|
+
for p in mesh.Points():
|
|
231
|
+
if abs(p.p[0]-hppnts[k][0])+abs(p.p[1]-hppnts[k][1]) < 1e-6:
|
|
232
|
+
mesh.AddSingularity(pids[i],hppnts[k][-1])
|
|
233
|
+
foundhp[k] = True
|
|
234
|
+
i += 1
|
|
235
|
+
for k in range(len(foundhp)):
|
|
236
|
+
if foundhp[k] == False:
|
|
237
|
+
raise Exception("hppnts[",k,"] not in structured mesh!")
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
ngsmesh = ngsolve.Mesh(mesh)
|
|
241
|
+
return ngsmesh
|
|
242
|
+
|
|
243
|
+
def MakeQuadMesh(nx=10, ny=10, periodic_x=False, periodic_y=False, mapping = None):
|
|
244
|
+
"""
|
|
245
|
+
Generate a structured quadrilateral 2D mesh
|
|
246
|
+
|
|
247
|
+
Parameters
|
|
248
|
+
----------
|
|
249
|
+
nx : int
|
|
250
|
+
Number of cells in x-direction.
|
|
251
|
+
|
|
252
|
+
ny : int
|
|
253
|
+
Number of cells in y-direction.
|
|
254
|
+
|
|
255
|
+
periodic_x: bool
|
|
256
|
+
If True, the left and right boundaries are identified to generate a periodic mesh in x-direction.
|
|
257
|
+
|
|
258
|
+
periodic_y: bool
|
|
259
|
+
If True, the top and bottom boundaries are identified to generate a periodic mesh in y-direction.
|
|
260
|
+
|
|
261
|
+
mapping: lambda
|
|
262
|
+
Mapping to transform the generated points. If None, the identity mapping is used.
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
Returns
|
|
266
|
+
-------
|
|
267
|
+
(ngsolve.mesh)
|
|
268
|
+
Returns generated 2D NGSolve mesh
|
|
269
|
+
|
|
270
|
+
"""
|
|
271
|
+
return MakeStructured2DMesh(quads=True, nx=nx, ny=ny, periodic_x=periodic_x, periodic_y=periodic_y, mapping=mapping)
|
|
272
|
+
|
|
273
|
+
def MakeStructured3DMesh(hexes=True, nx=10, ny=None, nz=None, secondorder=False, periodic_x=False, periodic_y=False, periodic_z=False, mapping = None, cuboid_mapping=False, prism=False):
|
|
274
|
+
"""
|
|
275
|
+
Generate a structured quadrilateral 2D mesh
|
|
276
|
+
|
|
277
|
+
Parameters
|
|
278
|
+
----------
|
|
279
|
+
hexes: bool
|
|
280
|
+
If True, a mesh consisting of hexahedra is generated.
|
|
281
|
+
|
|
282
|
+
nx : int
|
|
283
|
+
Number of cells in x-direction.
|
|
284
|
+
|
|
285
|
+
ny : int
|
|
286
|
+
Number of cells in y-direction.
|
|
287
|
+
|
|
288
|
+
nz : int
|
|
289
|
+
Number of cells in z-direction.
|
|
290
|
+
|
|
291
|
+
secondorder : bool
|
|
292
|
+
If True, second order curved elements are used.
|
|
293
|
+
|
|
294
|
+
periodic_x: bool
|
|
295
|
+
If True, the left and right boundaries are identified to generate a periodic mesh in x-direction.
|
|
296
|
+
|
|
297
|
+
periodic_y: bool
|
|
298
|
+
If True, the top and bottom boundaries are identified to generate a periodic mesh in y-direction.
|
|
299
|
+
|
|
300
|
+
periodic_z: bool
|
|
301
|
+
If True, the top and bottom boundaries are identified to generate a periodic mesh in z-direction.
|
|
302
|
+
|
|
303
|
+
mapping: lambda
|
|
304
|
+
Mapping to transform the generated points. If None, the identity mapping is used.
|
|
305
|
+
|
|
306
|
+
cuboid_mapping: bool
|
|
307
|
+
If True, a straight geometry is assumed.
|
|
308
|
+
|
|
309
|
+
prism : bool
|
|
310
|
+
If True, a mesh consisting of prism is generated. If hexes and prism is set to True, also a mesh consisting of prism is generated.
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
Returns
|
|
314
|
+
-------
|
|
315
|
+
(ngsolve.mesh)
|
|
316
|
+
Returns generated 3D NGSolve mesh
|
|
317
|
+
|
|
318
|
+
"""
|
|
319
|
+
if nz == None:
|
|
320
|
+
if ny == None:
|
|
321
|
+
nz = nx
|
|
322
|
+
else:
|
|
323
|
+
raise Exception("MakeStructured3DMesh: No default value for nz if nx and ny are provided")
|
|
324
|
+
if ny == None:
|
|
325
|
+
ny = nx
|
|
326
|
+
|
|
327
|
+
netmesh = Mesh()
|
|
328
|
+
netmesh.dim = 3
|
|
329
|
+
|
|
330
|
+
if cuboid_mapping:
|
|
331
|
+
P1 = (0,0,0)
|
|
332
|
+
P2 = (1,1,1)
|
|
333
|
+
if mapping:
|
|
334
|
+
P1 = mapping(*P1)
|
|
335
|
+
P2 = mapping(*P2)
|
|
336
|
+
cube = OrthoBrick(Pnt(P1[0], P1[1], P1[2]), Pnt(P2[0], P2[1], P2[2])).bc(1)
|
|
337
|
+
geom = CSGeometry()
|
|
338
|
+
geom.Add(cube)
|
|
339
|
+
netmesh.SetGeometry(geom)
|
|
340
|
+
|
|
341
|
+
pids = []
|
|
342
|
+
if periodic_x:
|
|
343
|
+
minioni = []
|
|
344
|
+
masteri = []
|
|
345
|
+
if periodic_y:
|
|
346
|
+
minionj = []
|
|
347
|
+
masterj = []
|
|
348
|
+
if periodic_z:
|
|
349
|
+
minionk = []
|
|
350
|
+
masterk = []
|
|
351
|
+
for i in range(nx+1):
|
|
352
|
+
for j in range(ny+1):
|
|
353
|
+
for k in range(nz+1):
|
|
354
|
+
# x,y,z = mapping(i / nx, j / ny, k / nz)
|
|
355
|
+
x,y,z = i / nx, j / ny, k / nz
|
|
356
|
+
# if mapping:
|
|
357
|
+
# x,y,z = mapping(x,y,z)
|
|
358
|
+
pids.append(netmesh.Add(MeshPoint(Pnt( x,y,z ))))
|
|
359
|
+
if periodic_x:
|
|
360
|
+
if i == 0:
|
|
361
|
+
minioni.append(pids[-1])
|
|
362
|
+
if i == nx:
|
|
363
|
+
masteri.append(pids[-1])
|
|
364
|
+
if periodic_y:
|
|
365
|
+
if j == 0:
|
|
366
|
+
minionj.append(pids[-1])
|
|
367
|
+
if j == ny:
|
|
368
|
+
masterj.append(pids[-1])
|
|
369
|
+
if periodic_z:
|
|
370
|
+
if k == 0:
|
|
371
|
+
minionk.append(pids[-1])
|
|
372
|
+
if k == nz:
|
|
373
|
+
masterk.append(pids[-1])
|
|
374
|
+
if periodic_x:
|
|
375
|
+
for i in range(len(minioni)):
|
|
376
|
+
netmesh.AddPointIdentification(masteri[i],minioni[i],identnr=1,type=2)
|
|
377
|
+
if periodic_y:
|
|
378
|
+
for j in range(len(minionj)):
|
|
379
|
+
netmesh.AddPointIdentification(masterj[j],minionj[j],identnr=2,type=2)
|
|
380
|
+
if periodic_z:
|
|
381
|
+
for k in range(len(minionk)):
|
|
382
|
+
netmesh.AddPointIdentification(masterk[k],minionk[k],identnr=3,type=2)
|
|
383
|
+
|
|
384
|
+
for i in range(nx):
|
|
385
|
+
for j in range(ny):
|
|
386
|
+
for k in range(nz):
|
|
387
|
+
base = i * (ny+1)*(nz+1) + j*(nz+1) + k
|
|
388
|
+
baseup = base+(ny+1)*(nz+1)
|
|
389
|
+
pnum = [base, base+1, base+(nz+1)+1, base+(nz+1),
|
|
390
|
+
baseup, baseup+1, baseup+(nz+1)+1, baseup+(nz+1)]
|
|
391
|
+
if prism:
|
|
392
|
+
for qarr in [[0,3,4,1,2,5],[3,7,4,2,6,5]]:
|
|
393
|
+
elpids = [pids[p] for p in [pnum[q] for q in qarr]]
|
|
394
|
+
netmesh.Add(Element3D(1, elpids))
|
|
395
|
+
elif hexes:
|
|
396
|
+
elpids = [pids[p] for p in pnum]
|
|
397
|
+
el = Element3D(1, elpids)
|
|
398
|
+
if not mapping:
|
|
399
|
+
el.curved = False
|
|
400
|
+
netmesh.Add(el)
|
|
401
|
+
else:
|
|
402
|
+
# a poor mans kuhn triangulation of a cube
|
|
403
|
+
for qarr in [[0, 4, 5, 6],
|
|
404
|
+
[0, 6, 7, 4],
|
|
405
|
+
[0, 3, 7, 6],
|
|
406
|
+
[0, 1, 6, 5],
|
|
407
|
+
[0, 1, 2, 6],
|
|
408
|
+
[0, 3, 6, 2]]:
|
|
409
|
+
elpids = [pids[p] for p in [pnum[q] for q in qarr]]
|
|
410
|
+
netmesh.Add(Element3D(1, elpids))
|
|
411
|
+
|
|
412
|
+
def AddSurfEls(p1, dxi, nxi, deta, neta, facenr):
|
|
413
|
+
def add_seg(i, j, os):
|
|
414
|
+
base = p1 + i*dxi + j*deta
|
|
415
|
+
pnum = [base, base+os]
|
|
416
|
+
elpids = [pids[p] for p in pnum]
|
|
417
|
+
netmesh.Add(Element1D(elpids, index=facenr))
|
|
418
|
+
for i in range(nxi):
|
|
419
|
+
for j in [0,neta]:
|
|
420
|
+
add_seg(i,j,dxi)
|
|
421
|
+
for i in [0,nxi]:
|
|
422
|
+
for j in range(neta):
|
|
423
|
+
add_seg(i,j,deta)
|
|
424
|
+
for i in range(nxi):
|
|
425
|
+
for j in range(neta):
|
|
426
|
+
base = p1 + i*dxi+j*deta
|
|
427
|
+
pnum = [base, base+dxi, base+dxi+deta, base+deta]
|
|
428
|
+
if prism:
|
|
429
|
+
if facenr <= 4:
|
|
430
|
+
qarr = [1,2,3,0]
|
|
431
|
+
elpids = [pids[pnum[p]] for p in qarr]
|
|
432
|
+
netmesh.Add(Element2D(facenr, elpids))
|
|
433
|
+
else:
|
|
434
|
+
qarrs = [[3, 1, 2], [3, 0, 1]]
|
|
435
|
+
for qarr in qarrs:
|
|
436
|
+
elpids = [pids[p] for p in [pnum[q] for q in qarr]]
|
|
437
|
+
netmesh.Add(Element2D(facenr, elpids))
|
|
438
|
+
elif hexes:
|
|
439
|
+
elpids = [pids[p] for p in pnum]
|
|
440
|
+
netmesh.Add(Element2D(facenr, elpids))
|
|
441
|
+
else:
|
|
442
|
+
qarrs = [[0, 1, 2], [0, 2, 3]]
|
|
443
|
+
for qarr in qarrs:
|
|
444
|
+
elpids = [pids[p] for p in [pnum[q] for q in qarr]]
|
|
445
|
+
netmesh.Add(Element2D(facenr, elpids))
|
|
446
|
+
|
|
447
|
+
#order is important!
|
|
448
|
+
netmesh.Add(FaceDescriptor(surfnr=4, domin=1, bc=1))
|
|
449
|
+
netmesh.Add(FaceDescriptor(surfnr=2, domin=1, bc=2))
|
|
450
|
+
netmesh.Add(FaceDescriptor(surfnr=5, domin=1, bc=3))
|
|
451
|
+
netmesh.Add(FaceDescriptor(surfnr=3, domin=1, bc=4))
|
|
452
|
+
netmesh.Add(FaceDescriptor(surfnr=0, domin=1, bc=5))
|
|
453
|
+
netmesh.Add(FaceDescriptor(surfnr=1, domin=1, bc=6))
|
|
454
|
+
|
|
455
|
+
# y-z-plane, smallest x-coord: ("back")
|
|
456
|
+
AddSurfEls(0, 1, nz, nz+1, ny, facenr=1) # y-z-plane
|
|
457
|
+
# x-z-plane, smallest y-coord: ("left")
|
|
458
|
+
AddSurfEls(0, (ny+1)*(nz+1), nx, 1, nz,facenr=2)
|
|
459
|
+
# y-z-plane, largest x-coord: ("front")
|
|
460
|
+
AddSurfEls((nx+1)*(ny+1)*(nz+1)-1, -(nz+1), ny, -1, nz, facenr=3)
|
|
461
|
+
# x-z-plane, largest y-coord: ("right")
|
|
462
|
+
AddSurfEls((nx+1)*(ny+1)*(nz+1)-1, -1, nz, -(ny+1)*(nz+1), nx, facenr=4)
|
|
463
|
+
# x-y-plane, smallest z-coord: ("bottom")
|
|
464
|
+
AddSurfEls(0, nz+1, ny, (ny+1)*(nz+1), nx,facenr=5)
|
|
465
|
+
# x-y-plane, largest z-coord: ("top")
|
|
466
|
+
AddSurfEls((nx+1)*(ny+1)*(nz+1)-1, -(ny+1)*(nz+1), nx, -(nz+1), ny, facenr=6)
|
|
467
|
+
|
|
468
|
+
netmesh.SetBCName(0,"back")
|
|
469
|
+
netmesh.SetBCName(1,"left")
|
|
470
|
+
netmesh.SetBCName(2,"front")
|
|
471
|
+
netmesh.SetBCName(3,"right")
|
|
472
|
+
netmesh.SetBCName(4,"bottom")
|
|
473
|
+
netmesh.SetBCName(5,"top")
|
|
474
|
+
|
|
475
|
+
netmesh.Compress()
|
|
476
|
+
|
|
477
|
+
if secondorder:
|
|
478
|
+
netmesh.SecondOrder()
|
|
479
|
+
|
|
480
|
+
if mapping:
|
|
481
|
+
for p in netmesh.Points():
|
|
482
|
+
x,y,z = p.p
|
|
483
|
+
x,y,z = mapping(x,y,z)
|
|
484
|
+
p[0] = x
|
|
485
|
+
p[1] = y
|
|
486
|
+
p[2] = z
|
|
487
|
+
|
|
488
|
+
ngsmesh = ngsolve.Mesh(netmesh)
|
|
489
|
+
# ngsmesh.ngmesh.Save("tmp.vol.gz")
|
|
490
|
+
# ngsmesh = ngsolve.Mesh("tmp.vol.gz")
|
|
491
|
+
return ngsmesh
|
|
492
|
+
|
|
493
|
+
def MakeHexMesh(nx=10, ny=10, nz=10, secondorder=False, periodic_x=False, periodic_y=False, periodic_z=False, mapping = None, cuboid_mapping=False):
|
|
494
|
+
"""
|
|
495
|
+
Generate a structured hexahedra 3D mesh
|
|
496
|
+
|
|
497
|
+
Parameters
|
|
498
|
+
----------
|
|
499
|
+
nx : int
|
|
500
|
+
Number of cells in x-direction.
|
|
501
|
+
|
|
502
|
+
ny : int
|
|
503
|
+
Number of cells in y-direction.
|
|
504
|
+
|
|
505
|
+
nz : int
|
|
506
|
+
Number of cells in z-direction.
|
|
507
|
+
|
|
508
|
+
periodic_x: bool
|
|
509
|
+
If True, the left and right boundaries are identified to generate a periodic mesh in x-direction.
|
|
510
|
+
|
|
511
|
+
periodic_y: bool
|
|
512
|
+
If True, the top and bottom boundaries are identified to generate a periodic mesh in y-direction.
|
|
513
|
+
|
|
514
|
+
periodic_z: bool
|
|
515
|
+
If True, the top and bottom boundaries are identified to generate a periodic mesh in z-direction.
|
|
516
|
+
|
|
517
|
+
mapping: lambda
|
|
518
|
+
Mapping to transform the generated points. If None, the identity mapping is used.
|
|
519
|
+
|
|
520
|
+
cuboid_mapping: bool
|
|
521
|
+
If True, a straight geometry is assumed.
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
Returns
|
|
525
|
+
-------
|
|
526
|
+
(ngsolve.mesh)
|
|
527
|
+
Returns generated 3D NGSolve mesh consisting of only hexahedra
|
|
528
|
+
|
|
529
|
+
"""
|
|
530
|
+
return MakeStructured3DMesh(hexes=True, nx=nx, ny=ny, nz=nz, secondorder=secondorder, periodic_x=periodic_x, periodic_y=periodic_y, periodic_z=periodic_z, mapping=mapping, cuboid_mapping=cuboid_mapping)
|
|
531
|
+
|
|
532
|
+
def MakePrismMesh(nx=10, ny=None, nz=None, secondorder=False, periodic_x=False, periodic_y=False, periodic_z=False, mapping = None, cuboid_mapping=False):
|
|
533
|
+
"""
|
|
534
|
+
Generate a structured prism 3D mesh
|
|
535
|
+
|
|
536
|
+
Parameters
|
|
537
|
+
----------
|
|
538
|
+
nx : int
|
|
539
|
+
Number of cells in x-direction.
|
|
540
|
+
|
|
541
|
+
ny : int
|
|
542
|
+
Number of cells in y-direction.
|
|
543
|
+
|
|
544
|
+
nz : int
|
|
545
|
+
Number of cells in z-direction.
|
|
546
|
+
|
|
547
|
+
periodic_x: bool
|
|
548
|
+
If True, the left and right boundaries are identified to generate a periodic mesh in x-direction.
|
|
549
|
+
|
|
550
|
+
periodic_y: bool
|
|
551
|
+
If True, the top and bottom boundaries are identified to generate a periodic mesh in y-direction.
|
|
552
|
+
|
|
553
|
+
periodic_z: bool
|
|
554
|
+
If True, the top and bottom boundaries are identified to generate a periodic mesh in z-direction.
|
|
555
|
+
|
|
556
|
+
mapping: lambda
|
|
557
|
+
Mapping to transform the generated points. If None, the identity mapping is used.
|
|
558
|
+
|
|
559
|
+
cuboid_mapping: bool
|
|
560
|
+
If True, a straight geometry is assumed.
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
Returns
|
|
564
|
+
-------
|
|
565
|
+
(ngsolve.mesh)
|
|
566
|
+
Returns generated 3D NGSolve mesh consisting of only prism
|
|
567
|
+
|
|
568
|
+
"""
|
|
569
|
+
return MakeStructured3DMesh(hexes=False, nx=nx, ny=ny, nz=nz, secondorder=secondorder, periodic_x=periodic_x, periodic_y=periodic_y, periodic_z=periodic_z, mapping=mapping, cuboid_mapping=cuboid_mapping, prism=True)
|
|
570
|
+
|
|
571
|
+
from math import pi
|
|
572
|
+
from ngsolve import Draw, sin, cos
|
|
573
|
+
if __name__ == "__main__":
|
|
574
|
+
|
|
575
|
+
mesh = Make1DMesh(n=4)
|
|
576
|
+
print("simple 1D mesh -- no visualization -- ")
|
|
577
|
+
|
|
578
|
+
mesh = MakeQuadMesh(nx=4, ny=4)
|
|
579
|
+
Draw(mesh)
|
|
580
|
+
input("simple quad mesh -- press any key to continue -- ")
|
|
581
|
+
|
|
582
|
+
mesh = MakeStructured2DMesh(quads=False, nx=4, ny=4)
|
|
583
|
+
Draw(mesh)
|
|
584
|
+
input("simple trig mesh -- press any key to continue -- ")
|
|
585
|
+
|
|
586
|
+
mesh = MakeQuadMesh(nx=4, ny=4, periodic_x=True, periodic_y=False)
|
|
587
|
+
Draw(mesh)
|
|
588
|
+
input("x-periodic quad mesh -- press any key to continue -- ")
|
|
589
|
+
|
|
590
|
+
mesh = MakeStructured2DMesh(quads=False, nx=16, ny=4, periodic_x=False, periodic_y=True)
|
|
591
|
+
Draw(mesh)
|
|
592
|
+
input("y-periodic non-uniform trig mesh -- press any key to continue -- ")
|
|
593
|
+
|
|
594
|
+
mesh = MakeStructured2DMesh(quads=True, nx=32, ny=16,
|
|
595
|
+
mapping = lambda x,y : ((1.1+sin(pi*(y-0.5)))*sin(pi*x),
|
|
596
|
+
(1.1+sin(pi*(y-0.5)))*cos(pi*x)))
|
|
597
|
+
Draw(mesh)
|
|
598
|
+
input("structured quad half circle with a whole -- press any key to continue -- ")
|
|
599
|
+
|
|
600
|
+
mesh = MakeHexMesh(nx=8)
|
|
601
|
+
Draw(mesh)
|
|
602
|
+
input("simple cube mesh -- press any key to continue -- ")
|
|
603
|
+
|
|
604
|
+
mesh = MakeHexMesh(nx=8, periodic_x=True, periodic_y=True, periodic_z=True)
|
|
605
|
+
Draw(mesh)
|
|
606
|
+
input("periodic cube mesh -- press any key to continue -- ")
|
|
607
|
+
|
|
608
|
+
mesh = MakeStructured3DMesh(hexes=False, nx=3, ny=6, nz=10,
|
|
609
|
+
mapping = lambda x,y,z : (x,0.5*y*(y+x),exp(z)),
|
|
610
|
+
cuboid_mapping=False )
|
|
611
|
+
Draw(mesh)
|
|
612
|
+
input("mapped, anisotropic linear non-cuboid mesh -- press any key to continue -- ")
|
|
613
|
+
|
|
614
|
+
mesh = MakeStructured3DMesh(hexes=True, nx=8, ny=16, nz=8, periodic_x=True,
|
|
615
|
+
mapping = lambda x,y,z : (5*x*x*(0.5-x/3),10*y*y*(0.5-y/3),5*z*z*(0.5-z/3)),
|
|
616
|
+
cuboid_mapping=True )
|
|
617
|
+
Draw(mesh)
|
|
618
|
+
input("x-periodic, mapped, anisotropic non-linear cuboid mesh -- press any key to continue --")
|
|
619
|
+
|
|
620
|
+
mesh = MakeStructured3DMesh(hexes=False, nx=8, ny=8, nz=8, periodic_x=True,
|
|
621
|
+
cuboid_mapping=True )
|
|
622
|
+
mesh.Refine()
|
|
623
|
+
Draw(mesh)
|
|
624
|
+
input("structured tet mesh (periodic in x-dir.), refined -- finished.")
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
def MakeStructuredSurfaceMesh(quads=True, nx=10, ny=10, mapping = None, secondorder=False, bbbpts=None, bbbnames=None, flip_triangles=False):
|
|
631
|
+
"""
|
|
632
|
+
Generate a structured 2D surface mesh in 3D
|
|
633
|
+
|
|
634
|
+
Parameters
|
|
635
|
+
----------
|
|
636
|
+
quads : bool
|
|
637
|
+
If True, a quadrilateral mesh is generated. If False, the quads are split to triangles.
|
|
638
|
+
|
|
639
|
+
nx : int
|
|
640
|
+
Number of cells in x-direction.
|
|
641
|
+
|
|
642
|
+
ny : int
|
|
643
|
+
Number of cells in y-direction.
|
|
644
|
+
|
|
645
|
+
mapping : lamda
|
|
646
|
+
Mapping to transform the generated points. If None, the identity mapping is used.
|
|
647
|
+
|
|
648
|
+
secondorder : bool
|
|
649
|
+
If True, use quadratic elements, else linear elements are used.
|
|
650
|
+
|
|
651
|
+
bbbpts : list
|
|
652
|
+
List of points which should be handled as BBBND and are named with bbbnames. The mesh (nx, ny and mapping) must be constructed in such a way that the bbbpts coincide with generated points. Otherwise an Exception is thrown.
|
|
653
|
+
|
|
654
|
+
bbbnames : list
|
|
655
|
+
List of bbbnd names as strings. Size must coincide with size of bbbpts. Otherwise an Exception is thrown.
|
|
656
|
+
|
|
657
|
+
flip_triangles : bool
|
|
658
|
+
If set tot True together with quads=False the quads are cut the other way round
|
|
659
|
+
|
|
660
|
+
Returns
|
|
661
|
+
-------
|
|
662
|
+
(ngsolve.mesh)
|
|
663
|
+
Returns generated NGSolve mesh
|
|
664
|
+
|
|
665
|
+
"""
|
|
666
|
+
mesh = Mesh(dim=3)
|
|
667
|
+
|
|
668
|
+
if (bbbpts and bbbnames) and len(bbbpts) != len(bbbnames):
|
|
669
|
+
raise Exception("Lenght of bbbnames does not coincide with length of bbbpts!")
|
|
670
|
+
|
|
671
|
+
found = []
|
|
672
|
+
indbbbpts = []
|
|
673
|
+
if bbbpts:
|
|
674
|
+
for i in range(len(bbbpts)):
|
|
675
|
+
found.append(False)
|
|
676
|
+
indbbbpts.append(None)
|
|
677
|
+
|
|
678
|
+
pids = []
|
|
679
|
+
for i in range(ny+1):
|
|
680
|
+
for j in range(nx+1):
|
|
681
|
+
x,y,z = j/nx, i/ny, 0
|
|
682
|
+
pids.append(mesh.Add (MeshPoint(Pnt(x,y,z))))
|
|
683
|
+
|
|
684
|
+
mesh.Add(FaceDescriptor(surfnr=1,domin=1,bc=1))
|
|
685
|
+
|
|
686
|
+
for i in range(ny):
|
|
687
|
+
for j in range(nx):
|
|
688
|
+
base = i * (nx+1) + j
|
|
689
|
+
if quads:
|
|
690
|
+
pnum = [base,base+1,base+nx+2,base+nx+1]
|
|
691
|
+
elpids = [pids[p] for p in pnum]
|
|
692
|
+
el = Element2D(1,elpids)
|
|
693
|
+
if not mapping:
|
|
694
|
+
el.curved=False
|
|
695
|
+
mesh.Add(el)
|
|
696
|
+
else:
|
|
697
|
+
if flip_triangles:
|
|
698
|
+
pnum1 = [base,base+1,base+nx+2]
|
|
699
|
+
pnum2 = [base,base+nx+2,base+nx+1]
|
|
700
|
+
else:
|
|
701
|
+
pnum1 = [base,base+1,base+nx+1]
|
|
702
|
+
pnum2 = [base+1,base+nx+2,base+nx+1]
|
|
703
|
+
elpids1 = [pids[p] for p in pnum1]
|
|
704
|
+
elpids2 = [pids[p] for p in pnum2]
|
|
705
|
+
mesh.Add(Element2D(1,elpids1))
|
|
706
|
+
mesh.Add(Element2D(1,elpids2))
|
|
707
|
+
|
|
708
|
+
for i in range(nx):
|
|
709
|
+
mesh.Add(Element1D([pids[i], pids[i+1]], index=1))
|
|
710
|
+
for i in range(ny):
|
|
711
|
+
mesh.Add(Element1D([pids[i*(nx+1)+nx], pids[(i+1)*(nx+1)+nx]], index=2))
|
|
712
|
+
for i in range(nx):
|
|
713
|
+
mesh.Add(Element1D([pids[ny*(nx+1)+i+1], pids[ny*(nx+1)+i]], index=3))
|
|
714
|
+
for i in range(ny):
|
|
715
|
+
mesh.Add(Element1D([pids[(i+1)*(nx+1)], pids[i*(nx+1)]], index=4))
|
|
716
|
+
|
|
717
|
+
mesh.SetCD2Name(1, "bottom")
|
|
718
|
+
mesh.SetCD2Name(2, "right")
|
|
719
|
+
mesh.SetCD2Name(3, "top")
|
|
720
|
+
mesh.SetCD2Name(4, "left")
|
|
721
|
+
|
|
722
|
+
if secondorder:
|
|
723
|
+
mesh.SecondOrder()
|
|
724
|
+
|
|
725
|
+
if mapping:
|
|
726
|
+
for p in mesh.Points():
|
|
727
|
+
x,y,z = p.p
|
|
728
|
+
x,y,z = mapping(x,y,z)
|
|
729
|
+
p[0],p[1],p[2] = x,y,z
|
|
730
|
+
|
|
731
|
+
for k in range(len(found)):
|
|
732
|
+
i = 0
|
|
733
|
+
for p in mesh.Points():
|
|
734
|
+
if abs(p.p[0]-bbbpts[k][0])+abs(p.p[1]-bbbpts[k][1])+abs(p.p[2]-bbbpts[k][2]) < 1e-6:
|
|
735
|
+
indbbbpts[k] = pids[i]
|
|
736
|
+
found[k] = True
|
|
737
|
+
i += 1
|
|
738
|
+
for k in range(len(found)):
|
|
739
|
+
if found[k] == False:
|
|
740
|
+
raise Exception("bbbpnt[",k,"] not in structured mesh!")
|
|
741
|
+
|
|
742
|
+
for i in range(len(indbbbpts)):
|
|
743
|
+
mesh.Add(Element0D(indbbbpts[i], index=i+1))
|
|
744
|
+
mesh.SetCD3Name(i+1, bbbnames[i])
|
|
745
|
+
|
|
746
|
+
mesh.Compress()
|
|
747
|
+
ngsmesh = ngsolve.Mesh(mesh)
|
|
748
|
+
return ngsmesh
|