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,89 @@
1
+ # Call with:
2
+ # mpirun -np 5 ngspy mpi_poisson.py
3
+
4
+ # Solves -laplace(u)=f on [0,1]^3
5
+
6
+ # netgen-imports
7
+ #from netgen.geom2d import unit_square
8
+ from netgen.csg import unit_cube
9
+ import netgen.meshing
10
+
11
+ # ngsolve-imports
12
+ from ngsolve import *
13
+
14
+ # initialize MPI
15
+ from mpi4py.MPI import COMM_WORLD as comm
16
+ rank = comm.rank
17
+ np = comm.size
18
+
19
+ do_vtk = False
20
+
21
+ print("Hello from rank "+str(rank)+" of "+str(np))
22
+
23
+ if rank==0:
24
+ # master-proc generates mesh
25
+ mesh = unit_cube.GenerateMesh(maxh=0.3)
26
+ # and saves it to file
27
+ mesh.Save("some_mesh.vol")
28
+
29
+ # wait for master to be done meshing
30
+ comm.Barrier()
31
+
32
+ # now load mesh from file
33
+ ngmesh = netgen.meshing.Mesh(dim=3, comm=comm)
34
+ ngmesh.Load("some_mesh.vol")
35
+
36
+ #refine once?
37
+ # ngmesh.Refine()
38
+
39
+ mesh = Mesh(ngmesh)
40
+
41
+ # build H1-FESpace as usual
42
+ V = H1(mesh, order=3, dirichlet=[1,2,3,4])
43
+ u = V.TrialFunction()
44
+ v = V.TestFunction()
45
+
46
+ print("rank "+str(rank)+" has "+str(V.ndof)+" of "+str(V.ndofglobal)+" dofs!")
47
+
48
+ # RHS does not change either!
49
+ f = LinearForm (V)
50
+ f += SymbolicLFI(32 * (y*(1-y)+x*(1-x)) * v)
51
+ f.Assemble()
52
+
53
+ # neither does the BLF!
54
+ a = BilinearForm (V, symmetric=False)
55
+ a += SymbolicBFI(grad(u)*grad(v))
56
+
57
+ # Some possible preconditioners:
58
+ c = Preconditioner(a, type="direct", inverse = "masterinverse") # direct solve with mumps
59
+ #c = Preconditioner(a, type="bddc", inverse = "mumps") # BBDC + mumps for coarse inverse
60
+ #c = Preconditioner(a, type="hypre") # BoomerAMG (use only for order 1)
61
+ #c = Preconditioner(a, type="bddc", usehypre = True) # BDDC + BoomerAMG for coarse matrix
62
+
63
+ a.Assemble()
64
+
65
+ # solve the equation
66
+ u = GridFunction (V)
67
+ u.vec.data = CGSolver(a.mat, c.mat) * f.vec # use CG-solver with preconditioner c
68
+ # u.vec.data = a.mat.Inverse(V.FreeDofs(), inverse="mumps") * f.vec # use MUMPS parallel inverse
69
+ # u.vec.data = a.mat.Inverse(V.FreeDofs(), inverse="masterinverse") * f.vec # use masterinverse (master proc does all the work!)
70
+
71
+
72
+ #exact solution
73
+ exact = 16*x*(1-x)*y*(1-y)
74
+
75
+ # error
76
+ error = Integrate ( (u-exact)*(u-exact) , mesh)
77
+ if rank==0:
78
+ print("L2-error", error )
79
+
80
+ if do_vtk:
81
+ # do VTK-output
82
+ import os
83
+ output_path = os.path.dirname(os.path.realpath(__file__)) + "/poisson_output"
84
+ if rank==0 and not os.path.exists(output_path):
85
+ os.mkdir(output_path)
86
+ comm.Barrier() #wait until master has created the directory!!
87
+
88
+ vtk = VTKOutput(mesh, coefs=[u], names=["sol"], filename=output_path+"/vtkout", subdivision=2)
89
+ vtk.Do()
@@ -0,0 +1,82 @@
1
+ # Call with:
2
+ # mpirun -np 5 ngspy mpi_timeDG.py
3
+
4
+ # Then make movie with:
5
+ # python3 make_timeDG_movie.py
6
+ # (this only works if you have paraview+python3 configured properly)
7
+
8
+ # circular convection; time-DG with skeleton-formulation
9
+
10
+
11
+ from netgen.geom2d import unit_square
12
+ import netgen.meshing
13
+
14
+
15
+ from ngsolve import *
16
+
17
+ SetNumThreads(1)
18
+
19
+ from mpi4py.MPI import COMM_WORLD as comm
20
+ rank = comm.rank
21
+ np = comm.size
22
+
23
+ do_vtk = False
24
+
25
+ if rank==0:
26
+ ngmesh = unit_square.GenerateMesh(maxh=0.05)
27
+ ngmesh.Distribute(comm)
28
+ else:
29
+ ngmesh = netgen.meshing.Mesh.Receive(comm)
30
+ mesh = Mesh(ngmesh)
31
+
32
+ # build L2-FESpace
33
+ fes = L2(mesh, order=4)
34
+
35
+ # Trial- and Test-functions
36
+ u = fes.TrialFunction()
37
+ v = fes.TestFunction()
38
+
39
+ # RHS
40
+ b = CoefficientFunction( (y-0.5,0.5-x) )
41
+ bn = b*specialcf.normal(2)
42
+
43
+ # Skeleton DG-formulation
44
+ a = BilinearForm(fes)
45
+ a += SymbolicBFI (-u * b*grad(v))
46
+ a += SymbolicBFI ( bn*IfPos(bn, u, u.Other()) * (v-v.Other()), VOL, skeleton=True)
47
+ a += SymbolicBFI ( bn*IfPos(bn, u, 0) * v, BND, skeleton=True)
48
+
49
+ u = GridFunction(fes)
50
+ u.Set(exp (-40 * ( (x-0.7)*(x-0.7) + (y-0.7)*(y-0.7) )))
51
+
52
+ w = u.vec.CreateVector()
53
+
54
+ t = 0
55
+ tau = 5e-4
56
+ tend = 2
57
+ count = 0
58
+
59
+ vtk_interval = int(0.02/tau);
60
+
61
+ if do_vtk:
62
+ import os
63
+ output_path = os.path.dirname(os.path.realpath(__file__)) + "/timeDG_output"
64
+ if rank==0 and not os.path.exists(output_path):
65
+ os.mkdir(output_path)
66
+ comm.Barrier() #wait until master has created the directory!!
67
+ vtk = VTKOutput(ma=mesh,coefs=[u],names=["sol"],filename=output_path+"/vtkout",subdivision=2)
68
+
69
+ with TaskManager():
70
+ while t < tend:
71
+ if rank==0:
72
+ print("t = ", t)
73
+ a.Apply (u.vec, w)
74
+ fes.SolveM (rho=CoefficientFunction(1), vec=w)
75
+ u.vec.data -= tau * w
76
+ t += tau
77
+
78
+ if count%vtk_interval==0 and do_vtk:
79
+ vtk.Do(time=t)
80
+ count = count+1;
81
+
82
+ comm.Barrier()
@@ -0,0 +1,26 @@
1
+ from ngsolve import BaseMatrix, BitArray, BilinearForm, BaseVector
2
+
3
+ class SuperLU(BaseMatrix):
4
+ # def __init__(self, a: BaseMatrix | BilinearForm, freedofs: BitArray = None):
5
+ def __init__(self, a, freedofs: BitArray = None):
6
+ super().__init__()
7
+ self.a = a
8
+ self.freedofs = freedofs
9
+
10
+ def Update(self):
11
+ import scipy.sparse as sp
12
+ import scipy.sparse.linalg as spla
13
+ a = self.a if isinstance(self.a, BaseMatrix) else self.a.mat
14
+ mat = sp.csr_matrix(a.CSR())
15
+ if self.freedofs is not None:
16
+ self.fd = list(self.freedofs)
17
+ mat = mat[self.fd,:][:,self.fd]
18
+ self.lu = spla.factorized(sp.csc_matrix(mat))
19
+
20
+ def Mult(self, x: BaseVector, y: BaseVector):
21
+ if not hasattr(self, "lu"):
22
+ self.Update()
23
+ if self.freedofs is not None:
24
+ y.FV().NumPy()[self.fd] = self.lu(x.FV().NumPy()[self.fd])
25
+ else:
26
+ y.FV().NumPy()[:] = self.lu(x.FV().NumPy())
ngsolve/eigenvalues.py ADDED
@@ -0,0 +1,364 @@
1
+ from ngsolve.la import InnerProduct, MultiVector
2
+ from math import sqrt
3
+ from ngsolve import Projector, Norm, Matrix, Vector, IdentityMatrix
4
+
5
+ def Orthogonalize (vecs, mat):
6
+ mv = []
7
+ for i in range(len(vecs)):
8
+ for j in range(i):
9
+ vecs[i] -= InnerProduct(vecs[i], mv[j]) * vecs[j]
10
+
11
+ hv = mat.CreateRowVector()
12
+ hv.data = mat * vecs[i]
13
+ norm = sqrt(InnerProduct(vecs[i], hv))
14
+ vecs[i] *= 1/norm
15
+ hv *= 1/norm
16
+ mv.append (hv)
17
+
18
+
19
+ def PINVIT1(mata, matm, pre, num=1, maxit=20, printrates=True, GramSchmidt=False):
20
+ """preconditioned inverse iteration"""
21
+ import scipy.linalg
22
+
23
+ r = mata.CreateRowVector()
24
+ Av = mata.CreateRowVector()
25
+ Mv = mata.CreateRowVector()
26
+
27
+ uvecs = []
28
+ for i in range(num):
29
+ uvecs.append (mata.CreateRowVector())
30
+
31
+ vecs = []
32
+ for i in range(2*num):
33
+ vecs.append (mata.CreateRowVector())
34
+
35
+ for v in uvecs:
36
+ r.SetRandom()
37
+ v.data = pre * r
38
+
39
+ asmall = Matrix(2*num, 2*num)
40
+ msmall = Matrix(2*num, 2*num)
41
+ lams = num * [1]
42
+
43
+ for i in range(maxit):
44
+
45
+ for j in range(num):
46
+ vecs[j].data = uvecs[j]
47
+ r.data = mata * vecs[j] - lams[j] * matm * vecs[j]
48
+ vecs[num+j].data = pre * r
49
+
50
+ if GramSchmidt:
51
+ Orthogonalize (vecs, matm)
52
+
53
+ for j in range(2*num):
54
+ Av.data = mata * vecs[j]
55
+ Mv.data = matm * vecs[j]
56
+ for k in range(2*num):
57
+ asmall[j,k] = InnerProduct(Av, vecs[k])
58
+ msmall[j,k] = InnerProduct(Mv, vecs[k])
59
+
60
+ ev,evec = scipy.linalg.eigh(a=asmall, b=msmall)
61
+ lams[:] = ev[0:num]
62
+ if printrates:
63
+ print (i, ":", lams)
64
+
65
+ for j in range(num):
66
+ uvecs[j][:] = 0.0
67
+ for k in range(2*num):
68
+ uvecs[j].data += float(evec[k,j]) * vecs[k]
69
+
70
+ return lams, uvecs
71
+
72
+
73
+
74
+
75
+ def PINVIT(mata, matm, pre, num=1, maxit=20, printrates=True, GramSchmidt=True):
76
+ """preconditioned inverse iteration"""
77
+ import scipy.linalg
78
+
79
+ r = mata.CreateRowVector()
80
+
81
+ uvecs = MultiVector(r, num)
82
+ vecs = MultiVector(r, 2*num)
83
+ # hv = MultiVector(r, 2*num)
84
+
85
+ for v in vecs[0:num]:
86
+ v.SetRandom()
87
+ uvecs[:] = pre * vecs[0:num]
88
+ lams = Vector(num * [1])
89
+
90
+ for i in range(maxit):
91
+ vecs[0:num] = mata * uvecs - (matm * uvecs).Scale (lams)
92
+ vecs[num:2*num] = pre * vecs[0:num]
93
+ vecs[0:num] = uvecs
94
+
95
+ vecs.Orthogonalize(matm)
96
+
97
+ # hv[:] = mata * vecs
98
+ # asmall = InnerProduct (vecs, hv)
99
+ # hv[:] = matm * vecs
100
+ # msmall = InnerProduct (vecs, hv)
101
+ asmall = InnerProduct (vecs, mata * vecs)
102
+ msmall = InnerProduct (vecs, matm * vecs)
103
+
104
+ ev,evec = scipy.linalg.eigh(a=asmall, b=msmall)
105
+ lams = Vector(ev[0:num])
106
+ if printrates:
107
+ print (i, ":", list(lams))
108
+
109
+ uvecs[:] = vecs * Matrix(evec[:,0:num])
110
+ return lams, uvecs
111
+
112
+
113
+ def LOBPCG(mata, matm, pre, num=1, maxit=20, initial=None, printrates=True, largest=False):
114
+ """Knyazev's cg-like extension of PINVIT"""
115
+ import scipy.linalg
116
+
117
+ r = mata.CreateRowVector()
118
+
119
+ if initial:
120
+ num=len(initial)
121
+ uvecs = initial
122
+ else:
123
+ uvecs = MultiVector(r, num)
124
+
125
+ vecs = MultiVector(r, 3*num)
126
+ for v in vecs:
127
+ r.SetRandom()
128
+ v.data = pre * r
129
+
130
+ if initial:
131
+ vecs[0:num] = uvecs
132
+
133
+ lams = Vector(num * [1])
134
+
135
+ for i in range(maxit):
136
+ uvecs.data = mata * vecs[0:num] - (matm * vecs[0:num]).Scale (lams)
137
+ vecs[2*num:3*num] = pre * uvecs
138
+
139
+ vecs.Orthogonalize(matm)
140
+
141
+ asmall = InnerProduct (vecs, mata * vecs)
142
+ msmall = InnerProduct (vecs, matm * vecs)
143
+
144
+ ev,evec = scipy.linalg.eigh(a=asmall, b=msmall)
145
+
146
+ if not largest:
147
+ lams = Vector(ev[0:num])
148
+ if printrates:
149
+ print (i, ":", list(lams), flush=True)
150
+
151
+ uvecs[:] = vecs * Matrix(evec[:,0:num])
152
+ vecs[num:2*num] = vecs[0:num]
153
+ vecs[0:num] = uvecs
154
+ else:
155
+ lams = Vector(ev[2*num:3*num])
156
+ if printrates:
157
+ print (i, ":", list(lams), flush=True)
158
+
159
+ uvecs[:] = vecs * Matrix(evec[:,2*num:3*num])
160
+ vecs[num:2*num] = vecs[0:num]
161
+ vecs[0:num] = uvecs
162
+
163
+ return lams, uvecs
164
+
165
+
166
+
167
+
168
+
169
+ def Arnoldi (mat, tol=1e-10, maxiter=200):
170
+ import scipy.linalg
171
+ H = Matrix(maxiter,maxiter, complex=mat.is_complex)
172
+ H[:,:] = 0
173
+ v = mat.CreateVector(colvector=False)
174
+ abv = MultiVector(v, 0)
175
+ v.SetRandom()
176
+ v /= Norm(v)
177
+
178
+ for i in range(maxiter):
179
+ abv.Append(v)
180
+ v = (mat*v).Evaluate()
181
+ for j in range(i+1):
182
+ H[j,i] = InnerProduct(v, abv[j])
183
+ v -= H[j,i]*abv[j]
184
+ if i+1 < maxiter:
185
+ H[i+1,i] = Norm(v)
186
+ v = 1/Norm(v)*v
187
+
188
+ lam,ev = scipy.linalg.eig(H)
189
+ return Vector(lam), (abv*Matrix(ev)).Evaluate()
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+ # SOAR: A SECOND-ORDER ARNOLDI METHOD FOR THE SOLUTION OF THE QUADRATIC EIGENVALUE PROBLEM
198
+ # Z. Bai and Y. Su, SIAM J. Matrix Anal. Appl 26, pp 640-659 (2005)
199
+ # author: A. Schoefl
200
+
201
+ def SOAR (A, B, maxiter=200):
202
+ # first version without memory saving and breakdown
203
+
204
+ q = A.CreateVector()
205
+ p = A.CreateVector()
206
+ s = A.CreateVector()
207
+ r = A.CreateVector()
208
+
209
+ Q = MultiVector(q,0)
210
+ P = MultiVector(p,0)
211
+ p[:] = 0
212
+ q.SetRandom()
213
+ q.FV().imag = 0
214
+ q /= Norm(q)
215
+ T = Matrix(maxiter, complex=A.is_complex)
216
+ T[:,:] = 0
217
+
218
+ for j in range(maxiter):
219
+ Q.Append(q)
220
+ P.Append(p)
221
+ r.data = A*q + B*p
222
+ s.data = q
223
+
224
+ for i in range(j+1):
225
+
226
+ T[i,j] = InnerProduct(r, Q[i])
227
+ r -= T[i,j]*Q[i]
228
+ s -= T[i,j]*P[i]
229
+
230
+ if j+1 < maxiter:
231
+ T[j+1,j] = Norm(r)
232
+ if T[j+1,j] == 0:
233
+ print("SOAR stopped at iteration j = ", j)
234
+ break
235
+
236
+ q.data = 1/T[j+1,j]*r
237
+ p.data = 1/T[j+1,j]*s
238
+
239
+ return Q
240
+
241
+
242
+
243
+
244
+ # author: A. Schoefl
245
+ def TOAR (A, B, maxiter=200):
246
+
247
+ r = A.CreateVector()
248
+
249
+ tmp_np = np.zeros((len(r), 2))#, dtype=complex)
250
+ r.SetRandom()
251
+ r.FV().imag = 0
252
+ r /= Norm(r)
253
+ tmp_np[:,0] = r.FV().real
254
+ r.SetRandom()
255
+ r.FV().imag = 0
256
+ r /= Norm(r)
257
+ tmp_np[:,1] = r.FV().real
258
+
259
+ # tmp_np[:,1] = tmp_np[:,0] # just for testing
260
+
261
+
262
+ Q_np, X_np, perm = la.qr(tmp_np, pivoting=True, mode="economic")
263
+ # print(Q_np)
264
+ # print(Q_np.shape, X_np.shape, X_np)
265
+
266
+ Q = MultiVector(r,0)
267
+ # r.FV().NumPy()[:] = Q_np[:,0]
268
+
269
+ r.FV().real[:] = Q_np[:,0]
270
+ r.FV().imag = 0
271
+ Q.Append(r)
272
+ # assign rank
273
+ if np.isclose(X_np[1,1], 0):
274
+ eta = 1
275
+ else:
276
+ eta = 2
277
+
278
+ # r.FV().NumPy()[:] = Q_np[:,1]
279
+ r.FV().real[:] = Q_np[:,1]
280
+ r.FV().imag = 0
281
+ Q.Append(r)
282
+
283
+ # print (Q_np)
284
+ # print (Q[0], Q[1])
285
+ print (InnerProduct(Q,Q))
286
+
287
+ gamma = np.linalg.norm(tmp_np, ord='fro')
288
+
289
+ U1 = Matrix(eta,1, True)
290
+ U1.NumPy()[:,0] = X_np[:eta,1]/gamma
291
+
292
+ U2 = Matrix(eta,1, True)
293
+ U2.NumPy()[:,0] = X_np[:eta,0]/gamma
294
+ print ("X_nb = ", X_np[:eta,:])
295
+ print ("U1 = ", U1)
296
+ print ("U2 = ", U2)
297
+
298
+ H = Matrix(maxiter, maxiter-1, True)
299
+
300
+ # TODO: would be more efficient in C++
301
+ for j in range(maxiter-1):
302
+
303
+ # print(U1, "\n", U2)
304
+
305
+ r.data = A*(Q*U1[:,j])+B*(Q*U2[:,j])
306
+ s = Vector(eta, True)
307
+ # MGS: orthogonalize r against Q
308
+ for i in range(eta):
309
+ s[i] = InnerProduct(r, Q[i], conjugate=True) # TODO: order of Q[i], r correct?
310
+ r-=s[i]*Q[i]
311
+ alpha = InnerProduct(r,r, conjugate=True).real
312
+
313
+ # MGS
314
+ for i in range(j):
315
+ # TODO: I have to re-read in proof if should be conjugation makes sense
316
+ # (currently everything is real valued)
317
+ H[i,j] = InnerProduct(s, U1[:,i], conjugate=False) + \
318
+ InnerProduct( U1[:,j], U2[:,i], conjugate=True)
319
+ s -= H[i,j]*U1[:,i]
320
+ U1[:,j] -= H[i,j]*U2[:,i]
321
+
322
+ H[j+1,j] = sqrt(alpha+InnerProduct(s,s,conjugate=True).real+
323
+ InnerProduct(U1[:,j],U1[:,j], conjugate=True).real)
324
+
325
+ alpha = sqrt(alpha)
326
+
327
+ # breakdown
328
+ if H[j+1,j] == 0:
329
+ print("breakdown in iteration ", j)
330
+ return Q
331
+
332
+ # deflation
333
+ if alpha == 0:
334
+ print("deflation in iteration ", j)
335
+ tmp = U1
336
+ U1 = Matrix(eta, j+2, True)
337
+ U1[:,:j+1] = tmp
338
+ U1[:,j+1] = 1/H[j+1,j]*s
339
+
340
+ tmp = U2
341
+ U2 = Matrix(eta, j+2, True)
342
+ U2[:,:j+1] = tmp
343
+ U2[:,j+1] = 1/H[j+1,j]*U1[:,j]
344
+ else:
345
+ # update rank
346
+ eta+=1
347
+
348
+ tmp = U2
349
+ U2 = Matrix(eta, j+2, True)
350
+ U2[:-1,:j+1] = tmp
351
+ U2[:-1,j+1] = 1/H[j+1,j]*U1[:,j]
352
+ U2[eta-1, :] = 0
353
+
354
+ tmp = U1
355
+ U1 = Matrix(eta, j+2, True)
356
+ U1[:-1,:j+1] = tmp[:,:]
357
+ U1[:-1,j+1] = 1/H[j+1,j]*s
358
+ U1[eta-1, j+1] = alpha/H[j+1,j]
359
+
360
+ Q.Append(1/alpha*r)
361
+
362
+
363
+ return Q
364
+
ngsolve/internal.py ADDED
@@ -0,0 +1,89 @@
1
+ #######################################################
2
+ # Visualization settings
3
+
4
+ import ngsolve.solve
5
+ import os
6
+
7
+ # list of possible attributes -- necessary to provide autocompletion
8
+ visoptions_variables = ['usetexture', 'invcolor', 'imaginary', 'lineartexture', 'numtexturecols', 'showclipsolution', 'showsurfacesolution', 'drawfieldlines', 'drawpointcurves', 'numfieldlines', 'fieldlinesrandomstart', 'fieldlinesstartarea', 'fieldlinesstartareap1x', 'fieldlinesstartareap1y', 'fieldlinesstartareap1z', 'fieldlinesstartareap2x', 'fieldlinesstartareap2y', 'fieldlinesstartareap2z', 'fieldlinesstartface', 'fieldlinesfilename', 'fieldlinestolerance', 'fieldlinesrktype', 'fieldlineslength', 'fieldlinesmaxpoints', 'fieldlinesthickness', 'fieldlinesvecfunction', 'fieldlinesphase', 'fieldlinesonlyonephase', 'lineplotfile', 'lineplotsource', 'lineplotusingx', 'lineplotusingy', 'lineplotautoscale', 'lineplotxmin', 'lineplotxmax', 'lineplotymin', 'lineplotymax', 'lineplotcurrentnum', 'lineplotinfos', 'lineplotselected', 'lineplotselector', 'lineplotcolor', 'lineplotsizex', 'lineplotsizey', 'lineplotselectedeval', 'lineplotdatadescr', 'lineplotxcoordselector', 'lineplotycoordselector', 'evaluatefilenames', 'evaluatefiledescriptions', 'clipsolution', 'scalfunction', 'vecfunction', 'evaluate', 'gridsize', 'xoffset', 'yoffset', 'autoscale', 'redrawperiodic', 'logscale', 'mminval', 'mmaxval', 'isolines', 'isosurf', 'subdivisions', 'numiso', 'autoredraw', 'autoredrawtime', 'simulationtime', 'multidimcomponent', 'deformation', 'scaledeform1', 'scaledeform2']
9
+
10
+ viewoptions_variables = ['specpointvlen', 'colormeshsize', 'whitebackground', 'drawcoordinatecross', 'drawcolorbar', 'drawnetgenlogo', 'stereo', 'shrink', 'drawfilledtrigs', 'drawedges', 'drawbadels', 'centerpoint', 'drawelement', 'drawoutline', 'drawtets', 'drawtetsdomain', 'drawprisms', 'drawpyramids', 'drawhexes', 'drawidentified', 'drawpointnumbers', 'drawedgenumbers', 'drawfacenumbers', 'drawelementnumbers', 'drawdomainsurf', 'drawededges', 'drawedpoints', 'drawedpointnrs', 'drawedtangents', 'drawededgenrs', 'drawmetispartition', 'drawcurveproj', 'drawcurveprojedge', 'usecentercoords', 'centerx', 'centery', 'centerz', 'drawspecpoint', 'specpointx', 'specpointy', 'specpointz']
11
+
12
+ clipping_variables = ['nx', 'ny', 'nz', 'dist', 'dist2', 'enable', 'onlydomain', 'notdomain']
13
+
14
+ class TclVariables:
15
+ def __init__(self, name, update_cmd, attributes = []):
16
+ object.__setattr__(self, '_name', name)
17
+ object.__setattr__(self, '_update_cmd', update_cmd)
18
+ object.__setattr__(self, '_attributes', attributes)
19
+
20
+ # set corresponding variable in tcl and call update_cmd
21
+ def __setattr__(self, attribute_name, value):
22
+ if not attribute_name in self._attributes:
23
+ raise KeyError()
24
+ tcl_string = 'set '+self._name+'.'+attribute_name+' '+str(value)+'; '+self._update_cmd+';\n'
25
+ ngsolve.solve.Tcl_Eval(tcl_string)
26
+ ngsolve.Redraw()
27
+
28
+ # return list of possible attributes - for autocompletion
29
+ def __dir__(self):
30
+ return list(self.__dict__.keys()) + self._attributes
31
+
32
+ # rlcomplete checks existence of attribute with this function
33
+ def __getattr__(self, name):
34
+ if name in self.__dict__:
35
+ return self.__dict__[name]
36
+
37
+ if name in self._attributes:
38
+ return True
39
+ raise Exception()
40
+ def add_group( self, name, attributes=[] ):
41
+ self.__dict__[name] = TclVariables(self._name +'.'+name, self._update_cmd, attributes)
42
+
43
+
44
+ visoptions = TclVariables('::visoptions', 'Ng_Vis_Set parameters', visoptions_variables)
45
+ viewoptions = TclVariables('::viewoptions', 'Ng_SetVisParameters', viewoptions_variables)
46
+
47
+ # add subgroups to viewoptions
48
+ viewoptions.add_group( 'clipping', clipping_variables )
49
+ viewoptions.add_group( 'light', ['amb', 'diff', 'spec', 'locviewer'] )
50
+ viewoptions.add_group( 'mat', ['shininess', 'transp'] )
51
+
52
+ def VideoStart(filename):
53
+ ngsolve.solve.Tcl_Eval("Ng_VideoClip .ndraw init " + filename+';\n')
54
+
55
+ def VideoAddFrame():
56
+ ngsolve.solve.Tcl_Eval("Ng_VideoClip .ndraw addframe;\n")
57
+
58
+ def VideoFinalize():
59
+ ngsolve.solve.Tcl_Eval("Ng_VideoClip .ndraw finalize;\n")
60
+
61
+ def SnapShot(filename):
62
+ tmp_filename = filename.lower()
63
+ needs_conversion = not tmp_filename.endswith(".ppm")
64
+ if needs_conversion:
65
+ tmp_filename += ".ppm"
66
+ ngsolve.solve.Tcl_Eval("Ng_SnapShot .ndraw {};\n".format(tmp_filename))
67
+ ngsolve.Redraw(True)
68
+
69
+ if needs_conversion:
70
+ import time
71
+ from PIL import Image
72
+ t0 = time.time()
73
+ while not os.path.exists(tmp_filename) and time.time()-t0 < 5:
74
+ time.sleep(0.1)
75
+ im = Image.open(tmp_filename)
76
+ im.save(filename)
77
+ os.remove(tmp_filename)
78
+
79
+ def Move(dx, dy):
80
+ ngsolve.solve.Tcl_Eval("Ng_MouseMove 0 0 {} {} move; redraw;\n".format(dx, -dy))
81
+
82
+ def Rotate(dx, dy):
83
+ ngsolve.solve.Tcl_Eval("Ng_MouseMove 0 0 {} {} rotate; redraw;\n".format(dx, -dy))
84
+
85
+ def Zoom(z):
86
+ ngsolve.solve.Tcl_Eval("Ng_MouseMove 0 0 0 {} zoom; redraw;\n".format(-z))
87
+
88
+ def Center():
89
+ ngsolve.solve.Tcl_Eval("Ng_Center; redraw;\n")