ngsolve 6.2.2404.post156.dev0__cp39-cp39-win_amd64.whl → 6.2.2406.post112.dev1__cp39-cp39-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 (134) hide show
  1. netgen/include/arnoldi.hpp +3 -0
  2. netgen/include/basematrix.hpp +27 -22
  3. netgen/include/basevector.hpp +43 -71
  4. netgen/include/bdbequations.hpp +14 -3
  5. netgen/include/bilinearform.hpp +8 -59
  6. netgen/include/blockjacobi.hpp +4 -0
  7. netgen/include/cg.hpp +3 -0
  8. netgen/include/chebyshev.hpp +3 -0
  9. netgen/include/coefficient.hpp +6 -2
  10. netgen/include/comp.hpp +0 -4
  11. netgen/include/diagonalmatrix.hpp +154 -0
  12. netgen/include/dump.hpp +5 -5
  13. netgen/include/eigen.hpp +3 -0
  14. netgen/include/elementbyelement.hpp +6 -0
  15. netgen/include/elementtopology.hpp +0 -3
  16. netgen/include/expr.hpp +13 -8
  17. netgen/include/fespace.hpp +12 -14
  18. netgen/include/finiteelement.hpp +7 -7
  19. netgen/include/globalspace.hpp +28 -2
  20. netgen/include/gridfunction.hpp +4 -0
  21. netgen/include/h1amg.hpp +3 -1
  22. netgen/include/h1hofe.hpp +1 -1
  23. netgen/include/hcurlhdivfes.hpp +2 -0
  24. netgen/include/hcurlhofespace.hpp +4 -3
  25. netgen/include/hdivfes.hpp +3 -3
  26. netgen/include/hdivhosurfacefespace.hpp +3 -3
  27. netgen/include/intrule.hpp +15 -1
  28. netgen/include/jacobi.hpp +3 -0
  29. netgen/include/la.hpp +1 -13
  30. netgen/include/matrix.hpp +21 -0
  31. netgen/include/meshaccess.hpp +24 -51
  32. netgen/include/mgpre.hpp +1 -1
  33. netgen/include/mptools.hpp +1 -2
  34. netgen/include/multivector.hpp +2 -0
  35. netgen/include/ngsobject.hpp +1 -1
  36. netgen/include/nodalhofe.hpp +3 -0
  37. netgen/include/normalfacetfespace.hpp +4 -5
  38. netgen/include/normalfacetsurfacefespace.hpp +1 -1
  39. netgen/include/order.hpp +3 -1
  40. netgen/include/parallel_matrices.hpp +5 -0
  41. netgen/include/paralleldofs.hpp +44 -95
  42. netgen/include/parallelngs.hpp +2 -1
  43. netgen/include/parallelvector.hpp +12 -16
  44. netgen/include/pardisoinverse.hpp +1 -0
  45. netgen/include/periodic.hpp +1 -0
  46. netgen/include/pmltrafo.hpp +5 -2
  47. netgen/include/preconditioner.hpp +3 -1
  48. netgen/include/scalarfe.hpp +4 -1
  49. netgen/include/sparsecholesky.hpp +4 -0
  50. netgen/include/sparsematrix.hpp +18 -45
  51. netgen/include/sparsematrix_dyn.hpp +2 -0
  52. netgen/include/sparsematrix_impl.hpp +66 -1
  53. netgen/include/special_matrix.hpp +7 -138
  54. netgen/include/statushandler.hpp +7 -0
  55. netgen/include/symbolicintegrator.hpp +2 -1
  56. netgen/include/tensorcoefficient.hpp +56 -54
  57. netgen/include/tpdiffop.hpp +1 -0
  58. netgen/include/tpintrule.hpp +2 -0
  59. netgen/include/umfpackinverse.hpp +58 -30
  60. netgen/include/vector.hpp +6 -1
  61. netgen/include/voxelcoefficientfunction.hpp +2 -0
  62. netgen/include/vvector.hpp +10 -1
  63. netgen/lib/libngsolve.lib +0 -0
  64. netgen/libngsolve.dll +0 -0
  65. ngsolve/_scikit_build_core_dependencies.py +8 -1
  66. ngsolve/cmake/NGSolveConfig.cmake +1 -1
  67. ngsolve/config/config.py +6 -6
  68. ngsolve/config.py +6 -6
  69. ngsolve/demos/TensorProduct/__init__.py +0 -0
  70. ngsolve/demos/TensorProduct/tp_dg_1d_1d.py +80 -0
  71. ngsolve/demos/TensorProduct/tp_dg_1d_2d.py +73 -0
  72. ngsolve/demos/TensorProduct/tp_dg_2d_1d.py +72 -0
  73. ngsolve/demos/TensorProduct/tp_dg_2d_2d.py +66 -0
  74. ngsolve/demos/__init__.py +0 -0
  75. ngsolve/demos/howto/__init__.py +0 -0
  76. ngsolve/demos/howto/hhj.py +44 -0
  77. ngsolve/demos/howto/hybrid_dg.py +53 -0
  78. ngsolve/demos/howto/mixed.py +30 -0
  79. ngsolve/demos/howto/nonlin.py +29 -0
  80. ngsolve/demos/howto/pickling.py +26 -0
  81. ngsolve/demos/howto/pml.py +31 -0
  82. ngsolve/demos/howto/taskmanager.py +20 -0
  83. ngsolve/demos/howto/tdnns.py +47 -0
  84. ngsolve/demos/howto/timeDG-skeleton.py +45 -0
  85. ngsolve/demos/howto/timeDG.py +38 -0
  86. ngsolve/demos/howto/timeDGlap.py +42 -0
  87. ngsolve/demos/howto/timeDGwave.py +61 -0
  88. ngsolve/demos/intro/__init__.py +0 -0
  89. ngsolve/demos/intro/adaptive.py +123 -0
  90. ngsolve/demos/intro/cmagnet.py +62 -0
  91. ngsolve/demos/intro/elasticity.py +76 -0
  92. ngsolve/demos/intro/navierstokes.py +74 -0
  93. ngsolve/demos/intro/poisson.ipynb +170 -0
  94. ngsolve/demos/intro/poisson.py +41 -0
  95. ngsolve/demos/mpi/__init__.py +0 -0
  96. ngsolve/demos/mpi/mpi_cmagnet.py +87 -0
  97. ngsolve/demos/mpi/mpi_navierstokes.py +117 -0
  98. ngsolve/demos/mpi/mpi_poisson.py +89 -0
  99. ngsolve/demos/mpi/mpi_timeDG.py +82 -0
  100. ngsolve/ngslib.pyd +0 -0
  101. {ngsolve-6.2.2404.post156.dev0.dist-info → ngsolve-6.2.2406.post112.dev1.dist-info}/METADATA +2 -2
  102. {ngsolve-6.2.2404.post156.dev0.dist-info → ngsolve-6.2.2406.post112.dev1.dist-info}/RECORD +134 -102
  103. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/Scripts/ngsolve.tcl +0 -0
  104. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/beam.geo +0 -0
  105. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/beam.vol +0 -0
  106. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/chip.in2d +0 -0
  107. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/chip.vol +0 -0
  108. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/coil.geo +0 -0
  109. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/coil.vol +0 -0
  110. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/coilshield.geo +0 -0
  111. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/coilshield.vol +0 -0
  112. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/cube.geo +0 -0
  113. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/cube.vol +0 -0
  114. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d10_DGdoubleglazing.pde +0 -0
  115. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d11_chip_nitsche.pde +0 -0
  116. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d1_square.pde +0 -0
  117. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d2_chip.pde +0 -0
  118. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d3_helmholtz.pde +0 -0
  119. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d4_cube.pde +0 -0
  120. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d5_beam.pde +0 -0
  121. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d6_shaft.pde +0 -0
  122. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d7_coil.pde +0 -0
  123. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d8_coilshield.pde +0 -0
  124. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/d9_hybridDG.pde +0 -0
  125. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/doubleglazing.in2d +0 -0
  126. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/doubleglazing.vol +0 -0
  127. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/piezo2d40round4.vol.gz +0 -0
  128. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/shaft.geo +0 -0
  129. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/shaft.vol +0 -0
  130. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/square.in2d +0 -0
  131. {ngsolve-6.2.2404.post156.dev0.data → ngsolve-6.2.2406.post112.dev1.data}/data/share/ngsolve/square.vol +0 -0
  132. {ngsolve-6.2.2404.post156.dev0.dist-info → ngsolve-6.2.2406.post112.dev1.dist-info}/LICENSE +0 -0
  133. {ngsolve-6.2.2404.post156.dev0.dist-info → ngsolve-6.2.2406.post112.dev1.dist-info}/WHEEL +0 -0
  134. {ngsolve-6.2.2404.post156.dev0.dist-info → ngsolve-6.2.2406.post112.dev1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,62 @@
1
+ from netgen.csg import *
2
+ from ngsolve import *
3
+
4
+
5
+ def MakeGeometry():
6
+ geometry = CSGeometry()
7
+ box = OrthoBrick(Pnt(-1,-1,-1),Pnt(2,1,2)).bc("outer")
8
+
9
+ core = OrthoBrick(Pnt(0,-0.05,0),Pnt(0.8,0.05,1))- \
10
+ OrthoBrick(Pnt(0.1,-1,0.1),Pnt(0.7,1,0.9))- \
11
+ OrthoBrick(Pnt(0.5,-1,0.4),Pnt(1,1,0.6)).maxh(0.2).mat("core")
12
+
13
+ coil = (Cylinder(Pnt(0.05,0,0), Pnt(0.05,0,1), 0.3) - \
14
+ Cylinder(Pnt(0.05,0,0), Pnt(0.05,0,1), 0.15)) * \
15
+ OrthoBrick (Pnt(-1,-1,0.3),Pnt(1,1,0.7)).maxh(0.2).mat("coil")
16
+
17
+ geometry.Add ((box-core-coil).mat("air"))
18
+ geometry.Add (core)
19
+ geometry.Add (coil)
20
+ return geometry
21
+
22
+
23
+
24
+ ngmesh = MakeGeometry().GenerateMesh(maxh=0.5)
25
+ ngmesh.Save("coil.vol")
26
+ mesh = Mesh(ngmesh)
27
+
28
+ # curve elements for geometry approximation
29
+ mesh.Curve(5)
30
+
31
+ ngsglobals.msg_level = 5
32
+
33
+ fes = HCurl(mesh, order=4, dirichlet="outer", nograds = True)
34
+
35
+ # u and v refer to trial and test-functions in the definition of forms below
36
+ u = fes.TrialFunction()
37
+ v = fes.TestFunction()
38
+
39
+ mur = mesh.MaterialCF({ "core" : 1000 }, default=1)
40
+ mu0 = 1.257e-6
41
+ nu = 1/(mu0*mur)
42
+
43
+ a = BilinearForm(fes, symmetric=True)
44
+ a += nu*curl(u)*curl(v)*dx + 1e-6*nu*u*v*dx
45
+
46
+ c = Preconditioner(a, type="bddc")
47
+ # c = Preconditioner(a, type="multigrid", flags = { "smoother" : "block" } )
48
+
49
+ f = LinearForm(fes)
50
+ f += CoefficientFunction((y,0.05-x,0)) * v * dx("coil")
51
+
52
+ u = GridFunction(fes)
53
+
54
+
55
+ with TaskManager():
56
+ a.Assemble()
57
+ f.Assemble()
58
+ solver = CGSolver(mat=a.mat, pre=c.mat)
59
+ u.vec.data = solver * f.vec
60
+
61
+
62
+ 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()