ngsolve 6.2.2506.post74.dev0__cp314-cp314-win_amd64.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.

Files changed (288) hide show
  1. netgen/include/analytic_integrals.hpp +10 -0
  2. netgen/include/arnoldi.hpp +55 -0
  3. netgen/include/bandmatrix.hpp +334 -0
  4. netgen/include/basematrix.hpp +957 -0
  5. netgen/include/basevector.hpp +1268 -0
  6. netgen/include/bdbequations.hpp +2805 -0
  7. netgen/include/bdbintegrator.hpp +1660 -0
  8. netgen/include/bem_diffops.hpp +475 -0
  9. netgen/include/bessel.hpp +1064 -0
  10. netgen/include/bilinearform.hpp +963 -0
  11. netgen/include/bla.hpp +29 -0
  12. netgen/include/blockalloc.hpp +95 -0
  13. netgen/include/blockjacobi.hpp +328 -0
  14. netgen/include/bspline.hpp +116 -0
  15. netgen/include/calcinverse.hpp +141 -0
  16. netgen/include/cg.hpp +368 -0
  17. netgen/include/chebyshev.hpp +44 -0
  18. netgen/include/cholesky.hpp +720 -0
  19. netgen/include/clapack.h +7254 -0
  20. netgen/include/code_generation.hpp +296 -0
  21. netgen/include/coefficient.hpp +2033 -0
  22. netgen/include/coefficient_impl.hpp +19 -0
  23. netgen/include/coefficient_stdmath.hpp +167 -0
  24. netgen/include/commutingAMG.hpp +106 -0
  25. netgen/include/comp.hpp +79 -0
  26. netgen/include/compatibility.hpp +41 -0
  27. netgen/include/complex_wrapper.hpp +73 -0
  28. netgen/include/compressedfespace.hpp +110 -0
  29. netgen/include/contact.hpp +235 -0
  30. netgen/include/diagonalmatrix.hpp +154 -0
  31. netgen/include/differentialoperator.hpp +276 -0
  32. netgen/include/diffop.hpp +1286 -0
  33. netgen/include/diffop_impl.hpp +328 -0
  34. netgen/include/diffopwithfactor.hpp +123 -0
  35. netgen/include/discontinuous.hpp +84 -0
  36. netgen/include/dump.hpp +949 -0
  37. netgen/include/ectypes.hpp +121 -0
  38. netgen/include/eigen.hpp +60 -0
  39. netgen/include/eigensystem.hpp +18 -0
  40. netgen/include/elasticity_equations.hpp +595 -0
  41. netgen/include/elementbyelement.hpp +195 -0
  42. netgen/include/elementtopology.hpp +1760 -0
  43. netgen/include/elementtransformation.hpp +339 -0
  44. netgen/include/evalfunc.hpp +405 -0
  45. netgen/include/expr.hpp +1686 -0
  46. netgen/include/facetfe.hpp +175 -0
  47. netgen/include/facetfespace.hpp +180 -0
  48. netgen/include/facethofe.hpp +111 -0
  49. netgen/include/facetsurffespace.hpp +112 -0
  50. netgen/include/fe_interfaces.hpp +32 -0
  51. netgen/include/fem.hpp +87 -0
  52. netgen/include/fesconvert.hpp +14 -0
  53. netgen/include/fespace.hpp +1449 -0
  54. netgen/include/finiteelement.hpp +286 -0
  55. netgen/include/globalinterfacespace.hpp +77 -0
  56. netgen/include/globalspace.hpp +115 -0
  57. netgen/include/gridfunction.hpp +525 -0
  58. netgen/include/h1amg.hpp +124 -0
  59. netgen/include/h1hofe.hpp +188 -0
  60. netgen/include/h1hofe_impl.hpp +1262 -0
  61. netgen/include/h1hofefo.hpp +148 -0
  62. netgen/include/h1hofefo_impl.hpp +185 -0
  63. netgen/include/h1hofespace.hpp +167 -0
  64. netgen/include/h1lofe.hpp +1240 -0
  65. netgen/include/h1lumping.hpp +41 -0
  66. netgen/include/hcurl_equations.hpp +1381 -0
  67. netgen/include/hcurlcurlfe.hpp +2241 -0
  68. netgen/include/hcurlcurlfespace.hpp +78 -0
  69. netgen/include/hcurlfe.hpp +259 -0
  70. netgen/include/hcurlfe_utils.hpp +107 -0
  71. netgen/include/hcurlhdiv_dshape.hpp +857 -0
  72. netgen/include/hcurlhdivfes.hpp +308 -0
  73. netgen/include/hcurlhofe.hpp +175 -0
  74. netgen/include/hcurlhofe_impl.hpp +1871 -0
  75. netgen/include/hcurlhofespace.hpp +193 -0
  76. netgen/include/hcurllofe.hpp +1146 -0
  77. netgen/include/hdiv_equations.hpp +880 -0
  78. netgen/include/hdivdivfe.hpp +2923 -0
  79. netgen/include/hdivdivsurfacespace.hpp +76 -0
  80. netgen/include/hdivfe.hpp +206 -0
  81. netgen/include/hdivfe_utils.hpp +717 -0
  82. netgen/include/hdivfes.hpp +75 -0
  83. netgen/include/hdivhofe.hpp +447 -0
  84. netgen/include/hdivhofe_impl.hpp +1107 -0
  85. netgen/include/hdivhofefo.hpp +229 -0
  86. netgen/include/hdivhofespace.hpp +177 -0
  87. netgen/include/hdivhosurfacefespace.hpp +106 -0
  88. netgen/include/hdivlofe.hpp +773 -0
  89. netgen/include/hidden.hpp +74 -0
  90. netgen/include/householder.hpp +181 -0
  91. netgen/include/hypre_ams_precond.hpp +123 -0
  92. netgen/include/hypre_precond.hpp +73 -0
  93. netgen/include/integrator.hpp +2012 -0
  94. netgen/include/integratorcf.hpp +253 -0
  95. netgen/include/interpolate.hpp +49 -0
  96. netgen/include/intrule.hpp +2542 -0
  97. netgen/include/intrules_SauterSchwab.hpp +25 -0
  98. netgen/include/irspace.hpp +49 -0
  99. netgen/include/jacobi.hpp +153 -0
  100. netgen/include/kernels.hpp +762 -0
  101. netgen/include/l2hofe.hpp +194 -0
  102. netgen/include/l2hofe_impl.hpp +564 -0
  103. netgen/include/l2hofefo.hpp +542 -0
  104. netgen/include/l2hofespace.hpp +344 -0
  105. netgen/include/la.hpp +38 -0
  106. netgen/include/linearform.hpp +266 -0
  107. netgen/include/matrix.hpp +2140 -0
  108. netgen/include/memusage.hpp +41 -0
  109. netgen/include/meshaccess.hpp +1359 -0
  110. netgen/include/mgpre.hpp +204 -0
  111. netgen/include/mp_coefficient.hpp +145 -0
  112. netgen/include/mptools.hpp +2281 -0
  113. netgen/include/multigrid.hpp +42 -0
  114. netgen/include/multivector.hpp +447 -0
  115. netgen/include/mumpsinverse.hpp +187 -0
  116. netgen/include/mycomplex.hpp +361 -0
  117. netgen/include/ng_lapack.hpp +1661 -0
  118. netgen/include/ngblas.hpp +1232 -0
  119. netgen/include/ngs_defines.hpp +30 -0
  120. netgen/include/ngs_stdcpp_include.hpp +106 -0
  121. netgen/include/ngs_utils.hpp +121 -0
  122. netgen/include/ngsobject.hpp +1019 -0
  123. netgen/include/ngsstream.hpp +113 -0
  124. netgen/include/ngstd.hpp +72 -0
  125. netgen/include/nodalhofe.hpp +96 -0
  126. netgen/include/nodalhofe_impl.hpp +141 -0
  127. netgen/include/normalfacetfe.hpp +223 -0
  128. netgen/include/normalfacetfespace.hpp +98 -0
  129. netgen/include/normalfacetsurfacefespace.hpp +84 -0
  130. netgen/include/order.hpp +251 -0
  131. netgen/include/parallel_matrices.hpp +222 -0
  132. netgen/include/paralleldofs.hpp +340 -0
  133. netgen/include/parallelngs.hpp +23 -0
  134. netgen/include/parallelvector.hpp +269 -0
  135. netgen/include/pardisoinverse.hpp +200 -0
  136. netgen/include/periodic.hpp +129 -0
  137. netgen/include/plateaufespace.hpp +25 -0
  138. netgen/include/pml.hpp +275 -0
  139. netgen/include/pmltrafo.hpp +631 -0
  140. netgen/include/postproc.hpp +142 -0
  141. netgen/include/potentialtools.hpp +22 -0
  142. netgen/include/precomp.hpp +60 -0
  143. netgen/include/preconditioner.hpp +602 -0
  144. netgen/include/prolongation.hpp +377 -0
  145. netgen/include/python_comp.hpp +107 -0
  146. netgen/include/python_fem.hpp +89 -0
  147. netgen/include/python_linalg.hpp +58 -0
  148. netgen/include/python_ngstd.hpp +386 -0
  149. netgen/include/recursive_pol.hpp +4896 -0
  150. netgen/include/recursive_pol_tet.hpp +395 -0
  151. netgen/include/recursive_pol_trig.hpp +492 -0
  152. netgen/include/reorderedfespace.hpp +81 -0
  153. netgen/include/sample_sort.hpp +105 -0
  154. netgen/include/scalarfe.hpp +335 -0
  155. netgen/include/shapefunction_utils.hpp +113 -0
  156. netgen/include/simd_complex.hpp +329 -0
  157. netgen/include/smoother.hpp +253 -0
  158. netgen/include/solve.hpp +89 -0
  159. netgen/include/sparsecholesky.hpp +313 -0
  160. netgen/include/sparsematrix.hpp +1038 -0
  161. netgen/include/sparsematrix_dyn.hpp +90 -0
  162. netgen/include/sparsematrix_impl.hpp +1013 -0
  163. netgen/include/special_matrix.hpp +463 -0
  164. netgen/include/specialelement.hpp +125 -0
  165. netgen/include/statushandler.hpp +33 -0
  166. netgen/include/stringops.hpp +12 -0
  167. netgen/include/superluinverse.hpp +136 -0
  168. netgen/include/symbolicintegrator.hpp +850 -0
  169. netgen/include/symmetricmatrix.hpp +144 -0
  170. netgen/include/tangentialfacetfe.hpp +224 -0
  171. netgen/include/tangentialfacetfespace.hpp +91 -0
  172. netgen/include/tensor.hpp +522 -0
  173. netgen/include/tensorcoefficient.hpp +446 -0
  174. netgen/include/tensorproductintegrator.hpp +113 -0
  175. netgen/include/thcurlfe.hpp +128 -0
  176. netgen/include/thcurlfe_impl.hpp +380 -0
  177. netgen/include/thdivfe.hpp +80 -0
  178. netgen/include/thdivfe_impl.hpp +492 -0
  179. netgen/include/tpdiffop.hpp +461 -0
  180. netgen/include/tpfes.hpp +133 -0
  181. netgen/include/tpintrule.hpp +224 -0
  182. netgen/include/triangular.hpp +465 -0
  183. netgen/include/tscalarfe.hpp +245 -0
  184. netgen/include/tscalarfe_impl.hpp +1029 -0
  185. netgen/include/umfpackinverse.hpp +148 -0
  186. netgen/include/vector.hpp +1273 -0
  187. netgen/include/voxelcoefficientfunction.hpp +41 -0
  188. netgen/include/vtkoutput.hpp +198 -0
  189. netgen/include/vvector.hpp +208 -0
  190. netgen/include/webgui.hpp +92 -0
  191. netgen/lib/libngsolve.lib +0 -0
  192. netgen/libngsolve.dll +0 -0
  193. netgen/ngscxx.bat +4 -0
  194. netgen/ngsld.bat +6 -0
  195. ngsolve/TensorProductTools.py +210 -0
  196. ngsolve/__console.py +94 -0
  197. ngsolve/__expr.py +181 -0
  198. ngsolve/__init__.py +148 -0
  199. ngsolve/_scikit_build_core_dependencies.py +30 -0
  200. ngsolve/bvp.py +78 -0
  201. ngsolve/cmake/NGSolveConfig.cmake +102 -0
  202. ngsolve/cmake/ngsolve-targets-release.cmake +19 -0
  203. ngsolve/cmake/ngsolve-targets.cmake +164 -0
  204. ngsolve/config/__init__.py +1 -0
  205. ngsolve/config/__main__.py +4 -0
  206. ngsolve/config/config.py +60 -0
  207. ngsolve/demos/TensorProduct/__init__.py +0 -0
  208. ngsolve/demos/TensorProduct/tp_dg_1d_1d.py +80 -0
  209. ngsolve/demos/TensorProduct/tp_dg_1d_2d.py +73 -0
  210. ngsolve/demos/TensorProduct/tp_dg_2d_1d.py +72 -0
  211. ngsolve/demos/TensorProduct/tp_dg_2d_2d.py +66 -0
  212. ngsolve/demos/__init__.py +0 -0
  213. ngsolve/demos/howto/__init__.py +0 -0
  214. ngsolve/demos/howto/hhj.py +44 -0
  215. ngsolve/demos/howto/hybrid_dg.py +53 -0
  216. ngsolve/demos/howto/mixed.py +30 -0
  217. ngsolve/demos/howto/nonlin.py +29 -0
  218. ngsolve/demos/howto/pickling.py +26 -0
  219. ngsolve/demos/howto/pml.py +31 -0
  220. ngsolve/demos/howto/taskmanager.py +20 -0
  221. ngsolve/demos/howto/tdnns.py +47 -0
  222. ngsolve/demos/howto/timeDG-skeleton.py +45 -0
  223. ngsolve/demos/howto/timeDG.py +38 -0
  224. ngsolve/demos/howto/timeDGlap.py +42 -0
  225. ngsolve/demos/howto/timeDGwave.py +61 -0
  226. ngsolve/demos/intro/__init__.py +0 -0
  227. ngsolve/demos/intro/adaptive.py +123 -0
  228. ngsolve/demos/intro/cmagnet.py +59 -0
  229. ngsolve/demos/intro/elasticity.py +76 -0
  230. ngsolve/demos/intro/navierstokes.py +74 -0
  231. ngsolve/demos/intro/poisson.ipynb +170 -0
  232. ngsolve/demos/intro/poisson.py +41 -0
  233. ngsolve/demos/mpi/__init__.py +0 -0
  234. ngsolve/demos/mpi/mpi_cmagnet.py +87 -0
  235. ngsolve/demos/mpi/mpi_navierstokes.py +117 -0
  236. ngsolve/demos/mpi/mpi_poisson.py +89 -0
  237. ngsolve/demos/mpi/mpi_timeDG.py +82 -0
  238. ngsolve/directsolvers.py +26 -0
  239. ngsolve/eigenvalues.py +364 -0
  240. ngsolve/internal.py +89 -0
  241. ngsolve/krylovspace.py +1013 -0
  242. ngsolve/meshes.py +748 -0
  243. ngsolve/ngs2petsc.py +310 -0
  244. ngsolve/ngscxx.py +42 -0
  245. ngsolve/ngslib.lib +0 -0
  246. ngsolve/ngslib.pyd +0 -0
  247. ngsolve/nonlinearsolvers.py +203 -0
  248. ngsolve/preconditioners.py +11 -0
  249. ngsolve/solve_implementation.py +168 -0
  250. ngsolve/solvers.py +7 -0
  251. ngsolve/timestepping.py +185 -0
  252. ngsolve/timing.py +108 -0
  253. ngsolve/utils.py +167 -0
  254. ngsolve/webgui.py +670 -0
  255. ngsolve-6.2.2506.post74.dev0.data/data/Scripts/ngsolve.tcl +648 -0
  256. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/beam.geo +17 -0
  257. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/beam.vol +240 -0
  258. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/chip.in2d +41 -0
  259. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/chip.vol +614 -0
  260. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/coil.geo +12 -0
  261. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/coil.vol +2560 -0
  262. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/coilshield.geo +24 -0
  263. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/coilshield.vol +3179 -0
  264. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/cube.geo +19 -0
  265. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/cube.vol +1832 -0
  266. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d10_DGdoubleglazing.pde +50 -0
  267. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d11_chip_nitsche.pde +40 -0
  268. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d1_square.pde +43 -0
  269. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d2_chip.pde +35 -0
  270. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d3_helmholtz.pde +22 -0
  271. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d4_cube.pde +46 -0
  272. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d5_beam.pde +74 -0
  273. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d6_shaft.pde +73 -0
  274. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d7_coil.pde +50 -0
  275. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d8_coilshield.pde +49 -0
  276. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/d9_hybridDG.pde +72 -0
  277. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/doubleglazing.in2d +27 -0
  278. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/doubleglazing.vol +737 -0
  279. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/piezo2d40round4.vol.gz +0 -0
  280. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/shaft.geo +73 -0
  281. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/shaft.vol +4291 -0
  282. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/square.in2d +17 -0
  283. ngsolve-6.2.2506.post74.dev0.data/data/share/ngsolve/square.vol +149 -0
  284. ngsolve-6.2.2506.post74.dev0.dist-info/METADATA +14 -0
  285. ngsolve-6.2.2506.post74.dev0.dist-info/RECORD +288 -0
  286. ngsolve-6.2.2506.post74.dev0.dist-info/WHEEL +5 -0
  287. ngsolve-6.2.2506.post74.dev0.dist-info/licenses/LICENSE +504 -0
  288. ngsolve-6.2.2506.post74.dev0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,59 @@
1
+ from netgen.occ import *
2
+ from ngsolve import *
3
+
4
+
5
+ def MakeGeometry():
6
+ box = Box((-1,-1,-1), (2,1,2))
7
+ box.faces.name = "outer"
8
+ core = Box((0,-0.05,0), (0.8,0.05,1)) - \
9
+ Box((0.1,-1,0.1), (0.7,1,0.9)) - \
10
+ Box((0.5,-1,0.4), (1,1,0.6))
11
+ core.solids.name = "core"
12
+ core.solids.maxh = 0.03
13
+
14
+ coil = Cylinder((0.05,0,0.3), (0,0,1), 0.3, 0.4) - \
15
+ Cylinder((0.05,0,0.3), (0,0,1), 0.15, 0.4)
16
+ coil.solids.name = "coil"
17
+ air = box - core - coil
18
+ air.solids.name = "air"
19
+ return Glue([core, coil, air])
20
+
21
+
22
+
23
+ mesh = MakeGeometry().GenerateMesh(maxh=0.5)
24
+
25
+ # curve elements for geometry approximation
26
+ mesh.Curve(5)
27
+
28
+ ngsglobals.msg_level = 5
29
+
30
+ fes = HCurl(mesh, order=4, dirichlet="outer", nograds = True)
31
+
32
+ # u and v refer to trial and test-functions in the definition of forms below
33
+ u = fes.TrialFunction()
34
+ v = fes.TestFunction()
35
+
36
+ mur = mesh.MaterialCF({ "core" : 1000 }, default=1)
37
+ mu0 = 1.257e-6
38
+ nu = 1/(mu0*mur)
39
+
40
+ a = BilinearForm(fes, symmetric=True)
41
+ a += nu*curl(u)*curl(v)*dx + 1e-6*nu*u*v*dx
42
+
43
+ c = Preconditioner(a, type="bddc")
44
+ # c = Preconditioner(a, type="multigrid", flags = { "smoother" : "block" } )
45
+
46
+ f = LinearForm(fes)
47
+ f += CoefficientFunction((y,0.05-x,0)) * v * dx("coil")
48
+
49
+ u = GridFunction(fes)
50
+
51
+
52
+ with TaskManager():
53
+ a.Assemble()
54
+ f.Assemble()
55
+ solver = CGSolver(mat=a.mat, pre=c.mat)
56
+ u.vec.data = solver * f.vec
57
+
58
+
59
+ Draw (u.Deriv(), mesh, "B-field", draw_surf=False)
@@ -0,0 +1,76 @@
1
+ #
2
+ # geometric non-linear elasticity with Neo-Hooke hyperelastic material
3
+ #
4
+ # featuring automatic differentiation in SymbolicEnergy
5
+ #
6
+
7
+ import netgen.geom2d as geom2d
8
+ from ngsolve import *
9
+
10
+ geo = geom2d.SplineGeometry()
11
+ pnums = [ geo.AddPoint (x,y,maxh=0.01) for x,y in [(0,0), (1,0), (1,0.1), (0,0.1)] ]
12
+ for p1,p2,bc in [(0,1,"bot"), (1,2,"right"), (2,3,"top"), (3,0,"left")]:
13
+ geo.Append(["line", pnums[p1], pnums[p2]], bc=bc)
14
+ mesh = Mesh(geo.GenerateMesh(maxh=0.05))
15
+
16
+
17
+ E, nu = 210, 0.2
18
+ mu = E / 2 / (1+nu)
19
+ lam = E * nu / ((1+nu)*(1-2*nu))
20
+
21
+ fes = H1(mesh, order=2, dirichlet="left", dim=mesh.dim)
22
+ # fes = VectorH1(mesh, order=2, dirichlet="left")
23
+
24
+ u = fes.TrialFunction()
25
+
26
+ force = CoefficientFunction( (0,1/2) )
27
+
28
+ I = Id(mesh.dim)
29
+ F = I + Grad(u)
30
+ C = F.trans * F
31
+ E = 0.5 * (C-I)
32
+
33
+ def Pow(a, b):
34
+ return a**b # exp (log(a)*b)
35
+
36
+ def NeoHooke (C):
37
+ return 0.5 * mu * (Trace(C-I) + 2*mu/lam * Pow(Det(C),-lam/2/mu) - 1)
38
+
39
+
40
+
41
+ factor = Parameter(1)
42
+
43
+ a = BilinearForm(fes, symmetric=False)
44
+ a += Variation (NeoHooke(C).Compile()*dx)
45
+ a += Variation ((-factor * InnerProduct(force,u) ).Compile()*dx)
46
+
47
+
48
+ u = GridFunction(fes)
49
+ u.vec[:] = 0
50
+
51
+ res = u.vec.CreateVector()
52
+ w = u.vec.CreateVector()
53
+
54
+
55
+ for loadstep in range(10):
56
+
57
+ print ("loadstep", loadstep)
58
+ factor.Set (loadstep+1)
59
+
60
+ for it in range(5):
61
+ print ("Newton iteration", it)
62
+ print ("energy = ", a.Energy(u.vec))
63
+ a.Apply(u.vec, res)
64
+ a.AssembleLinearization(u.vec)
65
+ inv = a.mat.Inverse(fes.FreeDofs() )
66
+ w.data = inv*res
67
+ print ("err^2 = ", InnerProduct (w,res))
68
+ u.vec.data -= w
69
+
70
+ Draw (u, mesh, "displacement")
71
+ SetVisualization (deformation=True)
72
+ input ("<press a key>")
73
+
74
+
75
+
76
+
@@ -0,0 +1,74 @@
1
+ from ngsolve import *
2
+
3
+ # viscosity
4
+ nu = 0.001
5
+
6
+ # timestepping parameters
7
+ tau = 0.001
8
+ tend = 10
9
+
10
+ from netgen.geom2d import SplineGeometry
11
+ geo = SplineGeometry()
12
+ geo.AddRectangle( (0, 0), (2, 0.41), bcs = ("wall", "outlet", "wall", "inlet"))
13
+ geo.AddCircle ( (0.2, 0.2), r=0.05, leftdomain=0, rightdomain=1, bc="cyl", maxh=0.02)
14
+ mesh = Mesh( geo.GenerateMesh(maxh=0.07))
15
+
16
+ mesh.Curve(3)
17
+
18
+ V = VectorH1(mesh,order=3, dirichlet="wall|cyl|inlet")
19
+ Q = H1(mesh,order=2)
20
+
21
+ X = V*Q
22
+
23
+ u,p = X.TrialFunction()
24
+ v,q = X.TestFunction()
25
+
26
+ stokes = nu*InnerProduct(grad(u), grad(v))+div(u)*q+div(v)*p - 1e-10*p*q
27
+ a = BilinearForm(X, symmetric=True)
28
+ a += stokes*dx
29
+ a.Assemble()
30
+
31
+ # nothing here ...
32
+ f = LinearForm(X)
33
+ f.Assemble()
34
+
35
+ # gridfunction for the solution
36
+ gfu = GridFunction(X)
37
+
38
+ # parabolic inflow at inlet:
39
+ uin = CoefficientFunction( (1.5*4*y*(0.41-y)/(0.41*0.41), 0) )
40
+ gfu.components[0].Set(uin, definedon=mesh.Boundaries("inlet"))
41
+
42
+ # solve Stokes problem for initial conditions:
43
+ inv_stokes = a.mat.Inverse(X.FreeDofs())
44
+
45
+ res = f.vec.CreateVector()
46
+ res.data = f.vec - a.mat*gfu.vec
47
+ gfu.vec.data += inv_stokes * res
48
+
49
+
50
+ # matrix for implicit Euler
51
+ mstar = BilinearForm(X, symmetric=True)
52
+ mstar += (u*v + tau*stokes)*dx
53
+ mstar.Assemble()
54
+ inv = mstar.mat.Inverse(X.FreeDofs(), inverse="sparsecholesky")
55
+
56
+ # the non-linear term
57
+ conv = BilinearForm(X, nonassemble = True)
58
+ conv += (grad(u) * u) * v * dx
59
+
60
+ # for visualization
61
+ Draw (Norm(gfu.components[0]), mesh, "velocity", sd=3)
62
+
63
+ # implicit Euler/explicit Euler splitting method:
64
+ t = 0
65
+ with TaskManager():
66
+ while t < tend:
67
+ print ("t=", t, end="\r")
68
+
69
+ conv.Apply (gfu.vec, res)
70
+ res.data += a.mat*gfu.vec
71
+ gfu.vec.data -= tau * inv * res
72
+
73
+ t = t + tau
74
+ Redraw()
@@ -0,0 +1,170 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "Poisson Equation\n",
8
+ "==="
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "markdown",
13
+ "metadata": {},
14
+ "source": [
15
+ "Import Netgen/NGSolve Python modules:"
16
+ ]
17
+ },
18
+ {
19
+ "cell_type": "code",
20
+ "execution_count": null,
21
+ "metadata": {},
22
+ "outputs": [],
23
+ "source": [
24
+ "from ngsolve import *\n",
25
+ "from netgen.geom2d import unit_square\n",
26
+ "import netgen.gui\n",
27
+ "%gui tk"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "markdown",
32
+ "metadata": {},
33
+ "source": [
34
+ "The unit_square is a predefined domain, use Netgen to generate a mesh:"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": null,
40
+ "metadata": {},
41
+ "outputs": [],
42
+ "source": [
43
+ "mesh = Mesh(unit_square.GenerateMesh(maxh=0.2))\n",
44
+ "Draw (mesh)"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "markdown",
49
+ "metadata": {},
50
+ "source": [
51
+ "Define a finite element space on that mesh. "
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "execution_count": null,
57
+ "metadata": {},
58
+ "outputs": [],
59
+ "source": [
60
+ "fes = H1(mesh, order=3, dirichlet=\"left|right|bottom|top\")\n",
61
+ "print (\"ndof =\", fes.ndof)"
62
+ ]
63
+ },
64
+ {
65
+ "cell_type": "markdown",
66
+ "metadata": {},
67
+ "source": [
68
+ "Define linear and bilinear-forms. Forms are expressed in terms of trial and test-functions:"
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "execution_count": null,
74
+ "metadata": {},
75
+ "outputs": [],
76
+ "source": [
77
+ "u = fes.TrialFunction()\n",
78
+ "v = fes.TestFunction()\n",
79
+ "\n",
80
+ "f = LinearForm(fes)\n",
81
+ "f += 32 * (y*(1-y)+x*(1-x)) * v * dx\n",
82
+ "\n",
83
+ "a = BilinearForm(fes)\n",
84
+ "a += grad(u)*grad(v)*dx\n",
85
+ "\n",
86
+ "a.Assemble()\n",
87
+ "f.Assemble()"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "markdown",
92
+ "metadata": {},
93
+ "source": [
94
+ "Solve the problem:"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": null,
100
+ "metadata": {},
101
+ "outputs": [],
102
+ "source": [
103
+ "gfu = GridFunction(fes)\n",
104
+ "gfu.vec.data = a.mat.Inverse(fes.FreeDofs()) * f.vec"
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "markdown",
109
+ "metadata": {},
110
+ "source": [
111
+ "Plot the solution:"
112
+ ]
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "execution_count": null,
117
+ "metadata": {},
118
+ "outputs": [],
119
+ "source": [
120
+ "Draw (gfu)\n",
121
+ "Draw (-grad(gfu), mesh, \"Flux\")"
122
+ ]
123
+ },
124
+ {
125
+ "cell_type": "code",
126
+ "execution_count": null,
127
+ "metadata": {},
128
+ "outputs": [],
129
+ "source": [
130
+ "exact = 16*x*(1-x)*y*(1-y)\n",
131
+ "print (\"L2-error:\", sqrt (Integrate ( (gfu-exact)*(gfu-exact), mesh)))"
132
+ ]
133
+ },
134
+ {
135
+ "cell_type": "code",
136
+ "execution_count": null,
137
+ "metadata": {},
138
+ "outputs": [],
139
+ "source": []
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "execution_count": null,
144
+ "metadata": {},
145
+ "outputs": [],
146
+ "source": []
147
+ }
148
+ ],
149
+ "metadata": {
150
+ "kernelspec": {
151
+ "display_name": "Python 3",
152
+ "language": "python",
153
+ "name": "python3"
154
+ },
155
+ "language_info": {
156
+ "codemirror_mode": {
157
+ "name": "ipython",
158
+ "version": 3
159
+ },
160
+ "file_extension": ".py",
161
+ "mimetype": "text/x-python",
162
+ "name": "python",
163
+ "nbconvert_exporter": "python",
164
+ "pygments_lexer": "ipython3",
165
+ "version": "3.8.5"
166
+ }
167
+ },
168
+ "nbformat": 4,
169
+ "nbformat_minor": 2
170
+ }
@@ -0,0 +1,41 @@
1
+ # solve the Poisson equation -Delta u = f
2
+ # with Dirichlet boundary condition u = 0
3
+
4
+ from ngsolve import *
5
+ # from netgen.geom2d import unit_square
6
+
7
+ ngsglobals.msg_level = 1
8
+
9
+ # generate a triangular mesh of mesh-size 0.2
10
+ mesh = Mesh(unit_square.GenerateMesh(maxh=0.2))
11
+
12
+ # H1-conforming finite element space
13
+ fes = H1(mesh, order=3, dirichlet=[1,2,3,4])
14
+
15
+ # define trial- and test-functions
16
+ u = fes.TrialFunction()
17
+ v = fes.TestFunction()
18
+
19
+ # the right hand side
20
+ f = LinearForm(fes)
21
+ f += 32 * (y*(1-y)+x*(1-x)) * v * dx
22
+
23
+ # the bilinear-form
24
+ a = BilinearForm(fes, symmetric=True)
25
+ a += grad(u)*grad(v)*dx
26
+
27
+ a.Assemble()
28
+ f.Assemble()
29
+
30
+ # the solution field
31
+ gfu = GridFunction(fes)
32
+ gfu.vec.data = a.mat.Inverse(fes.FreeDofs(), inverse="sparsecholesky") * f.vec
33
+ # print (u.vec)
34
+
35
+
36
+ # plot the solution (netgen-gui only)
37
+ Draw (gfu)
38
+ Draw (-grad(gfu), mesh, "Flux")
39
+
40
+ exact = 16*x*(1-x)*y*(1-y)
41
+ print ("L2-error:", sqrt (Integrate ( (gfu-exact)*(gfu-exact), mesh)))
File without changes
@@ -0,0 +1,87 @@
1
+ from netgen.csg import *
2
+ import netgen.meshing
3
+
4
+ from ngsolve import *
5
+
6
+ from mpi4py.MPI import COMM_WORLD as comm
7
+ rank = comm.rank
8
+ np = comm.size
9
+
10
+ do_vtk = False
11
+
12
+ def MakeGeometry():
13
+ geometry = CSGeometry()
14
+ box = OrthoBrick(Pnt(-1,-1,-1),Pnt(2,1,2)).bc("outer")
15
+
16
+ core = OrthoBrick(Pnt(0,-0.05,0),Pnt(0.8,0.05,1))- \
17
+ OrthoBrick(Pnt(0.1,-1,0.1),Pnt(0.7,1,0.9))- \
18
+ OrthoBrick(Pnt(0.5,-1,0.4),Pnt(1,1,0.6)).maxh(0.2).mat("core")
19
+
20
+ coil = (Cylinder(Pnt(0.05,0,0), Pnt(0.05,0,1), 0.3) - \
21
+ Cylinder(Pnt(0.05,0,0), Pnt(0.05,0,1), 0.15)) * \
22
+ OrthoBrick (Pnt(-1,-1,0.3),Pnt(1,1,0.7)).maxh(0.2).mat("coil")
23
+
24
+ geometry.Add ((box-core-coil).mat("air"))
25
+ geometry.Add (core)
26
+ geometry.Add (coil)
27
+ return geometry
28
+
29
+ # For curving, we need the geometry. We have to
30
+ # generate it everywhere and then set it.
31
+ # It is not distributed automatically.
32
+ geom = MakeGeometry()
33
+ if rank==0:
34
+ # master proc generates and immediately distributes
35
+ ngmesh = geom.GenerateMesh(maxh=0.5)
36
+ ngmesh.Distribute(comm)
37
+ else:
38
+ # worker procs receive mesh
39
+ ngmesh = netgen.meshing.Mesh.Receive(comm)
40
+ # and then manually set the geometry
41
+ ngmesh.SetGeometry(geom)
42
+ mesh = Mesh(ngmesh)
43
+
44
+ # now we can curve!
45
+ mesh.Curve(5)
46
+
47
+ ngsglobals.msg_level = 5
48
+
49
+ fes = HCurl(mesh, order=4, dirichlet="outer", nograds = True)
50
+
51
+
52
+ u = fes.TrialFunction()
53
+ v = fes.TestFunction()
54
+
55
+ mur = { "core" : 1000, "coil" : 1, "air" : 1 }
56
+ mu0 = 1.257e-6
57
+
58
+ nu_coef = [ 1/(mu0*mur[mat]) for mat in mesh.GetMaterials() ]
59
+
60
+ nu = CoefficientFunction(nu_coef)
61
+ a = BilinearForm(fes, symmetric=True)
62
+ a += SymbolicBFI(nu*curl(u)*curl(v) + 1e-6*nu*u*v)
63
+
64
+ c = Preconditioner(a, type="bddc", flags={"inverse":"masterinverse"})
65
+ #c = Preconditioner(a, type="bddc", inverse = "mumps")
66
+
67
+ f = LinearForm(fes)
68
+ f += SymbolicLFI(CoefficientFunction((y,0.05-x,0)) * v, definedon=mesh.Materials("coil"))
69
+
70
+ u = GridFunction(fes)
71
+
72
+
73
+ a.Assemble()
74
+ f.Assemble()
75
+ solver = CGSolver(mat=a.mat, pre=c.mat)
76
+ u.vec.data = solver * f.vec
77
+
78
+ if do_vtk:
79
+ import os
80
+ output_path = os.path.dirname(os.path.realpath(__file__)) + "/cmagnet_output"
81
+ if rank==0 and not os.path.exists(output_path):
82
+ os.mkdir(output_path)
83
+ comm.Barrier() #wait until master has created the directory!!
84
+ vtk = VTKOutput(ma=mesh, coefs=[u.Deriv()], names=["sol"], filename=output_path+"/vtkout", subdivision=2)
85
+ vtk.Do()
86
+
87
+ #Draw (u.Deriv(), mesh, "B-field", draw_surf=False)
@@ -0,0 +1,117 @@
1
+ import netgen.meshing
2
+ from netgen.geom2d import SplineGeometry
3
+
4
+
5
+ from ngsolve import *
6
+
7
+ SetNumThreads(1)
8
+
9
+ from mpi4py.MPI import COMM_WORLD as comm
10
+ rank = comm.rank
11
+ np = comm.size
12
+
13
+ do_vtk = False
14
+
15
+ # viscosity
16
+ nu = 0.001
17
+
18
+ # timestepping parameters
19
+ tau = 0.001
20
+ tend = 3
21
+
22
+ # mesh = Mesh("cylinder.vol")
23
+ geo = SplineGeometry()
24
+ geo.AddRectangle( (0, 0), (2, 0.41), bcs = ("wall", "outlet", "wall", "inlet"))
25
+ geo.AddCircle ( (0.2, 0.2), r=0.05, leftdomain=0, rightdomain=1, bc="cyl")
26
+ if rank==0:
27
+ ngmesh = geo.GenerateMesh(maxh=0.08)
28
+ ngmesh.Distribute(comm)
29
+ else:
30
+ ngmesh = netgen.meshing.Mesh.Receive(comm)
31
+ ngmesh.SetGeometry(geo)
32
+
33
+ mesh = Mesh(ngmesh)
34
+
35
+ #does not work with mpi yet...
36
+ #mesh.Curve(3)
37
+
38
+ V = H1(mesh,order=3, dirichlet="wall|cyl|inlet")
39
+ Q = H1(mesh,order=2)
40
+
41
+ X = FESpace([V,V,Q])
42
+
43
+ ux,uy,p = X.TrialFunction()
44
+ vx,vy,q = X.TestFunction()
45
+
46
+ div_u = grad(ux)[0]+grad(uy)[1]
47
+ div_v = grad(vx)[0]+grad(vy)[1]
48
+
49
+ stokes = nu*grad(ux)*grad(vx)+nu*grad(uy)*grad(vy)+div_u*q+div_v*p - 1e-10*p*q
50
+ a = BilinearForm(X)
51
+ a += SymbolicBFI(stokes)
52
+ a.Assemble()
53
+
54
+ # nothing here ...
55
+ f = LinearForm(X)
56
+ f.Assemble()
57
+
58
+ # gridfunction for the solution
59
+ gfu = GridFunction(X)
60
+
61
+ # parabolic inflow at bc=1:
62
+ uin = 1.5*4*y*(0.41-y)/(0.41*0.41)
63
+ gfu.components[0].Set(uin, definedon=mesh.Boundaries("inlet"))
64
+
65
+ velocity = CoefficientFunction(gfu.components[0:2])
66
+
67
+
68
+ # solve Stokes problem for initial conditions:
69
+ #inv_stokes = a.mat.Inverse(X.FreeDofs(), inverse="mumps")
70
+ inv_stokes = a.mat.Inverse(X.FreeDofs(), inverse="masterinverse")
71
+ res = f.vec.CreateVector()
72
+ res.data = f.vec - a.mat*gfu.vec
73
+ gfu.vec.data += inv_stokes * res
74
+
75
+ # matrix for implicit Euler
76
+ mstar = BilinearForm(X)
77
+ mstar += SymbolicBFI(ux*vx+uy*vy + tau*stokes)
78
+ mstar.Assemble()
79
+
80
+ # inv = mstar.mat.Inverse(X.FreeDofs(), inverse="masterinverse")
81
+ inv = mstar.mat.Inverse(X.FreeDofs(), inverse="masterinverse")
82
+
83
+ # the non-linear term
84
+ conv = BilinearForm(X, nonassemble = True)
85
+ conv += SymbolicBFI( CoefficientFunction( (ux,uy) ) * (grad(ux)*vx+grad(uy)*vy) )
86
+
87
+ t = 0
88
+ vtk_interval = int(0.05/tau);
89
+
90
+ import os
91
+ #output_path = os.path.dirname(os.path.realpath(__file__)) + "/navierstokes_output"
92
+ output_path = os.path.dirname(os.path.realpath(__file__)) + "/navierstokes_output"
93
+ if rank==0 and not os.path.exists(output_path):
94
+ os.mkdir(output_path)
95
+ comm.Barrier() #wait until master has created the directory!!
96
+
97
+ if do_vtk:
98
+ vtk = VTKOutput(ma=mesh,coefs=[velocity],names=["u"],filename=output_path+"/vtkout",subdivision=2)
99
+ vtk.Do()
100
+
101
+ count = 1;
102
+ # implicit Euler/explicit Euler splitting method:
103
+ with TaskManager():
104
+ while t < tend:
105
+ if rank==0:
106
+ print ("t=", t)
107
+
108
+ conv.Apply (gfu.vec, res)
109
+ res.data += a.mat*gfu.vec
110
+ gfu.vec.data -= tau * inv * res
111
+
112
+ if count%vtk_interval==0 and do_vtk:
113
+ vtk.Do(time = t)
114
+ count = count+1;
115
+
116
+ t = t + tau
117
+ comm.Barrier()