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
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from math import sqrt
|
|
3
|
+
from netgen import TimeFunction
|
|
4
|
+
from ngsolve.bla import Norm
|
|
5
|
+
from ngsolve.la import InnerProduct
|
|
6
|
+
from ngsolve.la import Projector
|
|
7
|
+
__all__: list[str] = ['InnerProduct', 'Newton', 'NewtonMinimization', 'NewtonSolver', 'Norm', 'Projector', 'TimeFunction', 'sqrt']
|
|
8
|
+
class NewtonSolver:
|
|
9
|
+
@staticmethod
|
|
10
|
+
def Solve(*args, **kwargs):
|
|
11
|
+
...
|
|
12
|
+
def SetDirichlet(self, dirichletvalues):
|
|
13
|
+
...
|
|
14
|
+
def _UpdateInverse(self):
|
|
15
|
+
...
|
|
16
|
+
def __init__(self, a, u, rhs = None, freedofs = None, inverse = '', solver = None, lin_solver_cls = None, lin_solver_args = None):
|
|
17
|
+
...
|
|
18
|
+
def Newton(a, u, freedofs = None, maxit = 100, maxerr = 1e-11, inverse = '', dirichletvalues = None, dampfactor = 1, printing = True, callback = None):
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
Newton's method for solving non-linear problems of the form A(u)=0.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
a : BilinearForm
|
|
26
|
+
The BilinearForm of the non-linear variational problem. It does not have to be assembled.
|
|
27
|
+
|
|
28
|
+
u : GridFunction
|
|
29
|
+
The GridFunction where the solution is saved. The values are used as initial guess for Newton's method.
|
|
30
|
+
|
|
31
|
+
freedofs : BitArray
|
|
32
|
+
The FreeDofs on which the assembled matrix is inverted. If argument is 'None' then the FreeDofs of the underlying FESpace is used.
|
|
33
|
+
|
|
34
|
+
maxit : int
|
|
35
|
+
Number of maximal iteration for Newton. If the maximal number is reached before the maximal error Newton might no converge and a warning is displayed.
|
|
36
|
+
|
|
37
|
+
maxerr : float
|
|
38
|
+
The maximal error which Newton should reach before it stops. The error is computed by the square root of the inner product of the residuum and the correction.
|
|
39
|
+
|
|
40
|
+
inverse : string
|
|
41
|
+
A string of the sparse direct solver which should be solved for inverting the assembled Newton matrix.
|
|
42
|
+
|
|
43
|
+
dampfactor : float
|
|
44
|
+
Set the damping factor for Newton's method. If dampfactor is 1 then no damping is done. If value is < 1 then the damping is done by the formula 'min(1,dampfactor*numit)' for the correction, where 'numit' denotes the Newton iteration.
|
|
45
|
+
|
|
46
|
+
printing : bool
|
|
47
|
+
Set if Newton's method should print informations about the actual iteration like the error.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
(int, int)
|
|
52
|
+
List of two integers. The first one is 0 if Newton's method did converge, -1 otherwise. The second one gives the number of Newton iterations needed.
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
def NewtonMinimization(a, u, freedofs = None, maxit = 100, maxerr = 1e-11, inverse = '', dampfactor = 1, linesearch = False, printing = True, callback = None):
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
Newton's method for solving non-linear problems of the form A(u)=0 involving energy integrators.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
a : BilinearForm
|
|
64
|
+
The BilinearForm of the non-linear variational problem. It does not have to be assembled.
|
|
65
|
+
|
|
66
|
+
u : GridFunction
|
|
67
|
+
The GridFunction where the solution is saved. The values are used as initial guess for Newton's method.
|
|
68
|
+
|
|
69
|
+
freedofs : BitArray
|
|
70
|
+
The FreeDofs on which the assembled matrix is inverted. If argument is 'None' then the FreeDofs of the underlying FESpace is used.
|
|
71
|
+
|
|
72
|
+
maxit : int
|
|
73
|
+
Number of maximal iteration for Newton. If the maximal number is reached before the maximal error Newton might no converge and a warning is displayed.
|
|
74
|
+
|
|
75
|
+
maxerr : float
|
|
76
|
+
The maximal error which Newton should reach before it stops. The error is computed by the square root of the inner product of the residuum and the correction.
|
|
77
|
+
|
|
78
|
+
inverse : string
|
|
79
|
+
A string of the sparse direct solver which should be solved for inverting the assembled Newton matrix.
|
|
80
|
+
|
|
81
|
+
dampfactor : float
|
|
82
|
+
Set the damping factor for Newton's method. If dampfactor is 1 then no damping is done. If value is < 1 then the damping is done by the formula 'min(1,dampfactor*numit)' for the correction, where 'numit' denotes the Newton iteration.
|
|
83
|
+
|
|
84
|
+
linesearch : bool
|
|
85
|
+
If True then linesearch is used to guarantee that the energy decreases in every Newton iteration.
|
|
86
|
+
|
|
87
|
+
printing : bool
|
|
88
|
+
Set if Newton's method should print informations about the actual iteration like the error.
|
|
89
|
+
|
|
90
|
+
Returns
|
|
91
|
+
-------
|
|
92
|
+
(int, int)
|
|
93
|
+
List of two integers. The first one is 0 if Newton's method did converge, -1 otherwise. The second one gives the number of Newton iterations needed.
|
|
94
|
+
|
|
95
|
+
"""
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from ngsolve.comp import BDDCPreconditioner as BDDC
|
|
3
|
+
from ngsolve.comp import H1AMG
|
|
4
|
+
from ngsolve.comp import HCurlAMG
|
|
5
|
+
from ngsolve.comp import LocalPreconditioner as Local
|
|
6
|
+
from ngsolve.comp import MultiGridPreconditioner as MultiGrid
|
|
7
|
+
__all__: list[str] = ['BDDC', 'H1AMG', 'HCurlAMG', 'Local', 'MultiGrid']
|
ngsolve/solve.pyi
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pybind solve
|
|
3
|
+
"""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
import collections.abc
|
|
6
|
+
import ngsolve.comp
|
|
7
|
+
import ngsolve.fem
|
|
8
|
+
import typing
|
|
9
|
+
__all__: list[str] = ['Draw', 'SetVisualization', 'Tcl_Eval']
|
|
10
|
+
@typing.overload
|
|
11
|
+
def Draw(cf: ngsolve.fem.CoefficientFunction, mesh: ngsolve.comp.Mesh | ngsolve.comp.Region, name: str, sd: typing.SupportsInt = 2, autoscale: bool = True, min: typing.SupportsFloat = 0.0, max: typing.SupportsFloat = 1.0, draw_vol: bool = True, draw_surf: bool = True, reset: bool = False, title: str = '', number_format: str = '%.3e', unit: str = '', **kwargs) -> None:
|
|
12
|
+
"""
|
|
13
|
+
Parameters:
|
|
14
|
+
|
|
15
|
+
cf : ngsolve.comp.CoefficientFunction
|
|
16
|
+
input CoefficientFunction to draw
|
|
17
|
+
|
|
18
|
+
mesh : ngsolve.comp.Mesh
|
|
19
|
+
input mesh
|
|
20
|
+
|
|
21
|
+
name : string
|
|
22
|
+
input name
|
|
23
|
+
|
|
24
|
+
sd : int
|
|
25
|
+
input subdivisions
|
|
26
|
+
|
|
27
|
+
autoscale : bool
|
|
28
|
+
input autscale
|
|
29
|
+
|
|
30
|
+
min : float
|
|
31
|
+
input minimum value. Need autoscale = false
|
|
32
|
+
|
|
33
|
+
max : float
|
|
34
|
+
input maximum value. Need autoscale = false
|
|
35
|
+
|
|
36
|
+
draw_vol : bool
|
|
37
|
+
input draw volume
|
|
38
|
+
|
|
39
|
+
draw_surf : bool
|
|
40
|
+
input draw surface
|
|
41
|
+
|
|
42
|
+
title : string
|
|
43
|
+
printed on top of colormap
|
|
44
|
+
|
|
45
|
+
number_format : string
|
|
46
|
+
printf-style format string for numbers under colormap
|
|
47
|
+
|
|
48
|
+
unit : string
|
|
49
|
+
string (ASCII only) to print after maximum value of colormap
|
|
50
|
+
"""
|
|
51
|
+
@typing.overload
|
|
52
|
+
def Draw(gf: ngsolve.comp.GridFunction, sd: typing.SupportsInt = 2, autoscale: bool = True, min: typing.SupportsFloat = 0.0, max: typing.SupportsFloat = 1.0, **kwargs) -> None:
|
|
53
|
+
"""
|
|
54
|
+
Parameters:
|
|
55
|
+
|
|
56
|
+
gf : ngsolve.comp.GridFunction
|
|
57
|
+
input GridFunction to draw
|
|
58
|
+
|
|
59
|
+
sd : int
|
|
60
|
+
input subdivisions
|
|
61
|
+
|
|
62
|
+
autoscale : bool
|
|
63
|
+
input autscale
|
|
64
|
+
|
|
65
|
+
min : float
|
|
66
|
+
input minimum value. Need autoscale = false
|
|
67
|
+
|
|
68
|
+
max : float
|
|
69
|
+
input maximum value. Need autoscale = false
|
|
70
|
+
"""
|
|
71
|
+
@typing.overload
|
|
72
|
+
def Draw(mesh: ngsolve.comp.Mesh, **kwargs) -> None:
|
|
73
|
+
...
|
|
74
|
+
@typing.overload
|
|
75
|
+
def Draw(arg0: typing.Any) -> None:
|
|
76
|
+
...
|
|
77
|
+
def SetVisualization(deformation: bool | None = None, min: typing.SupportsFloat | None = None, max: typing.SupportsFloat | None = None, clipnormal: tuple | None = None, clipping: bool | None = None) -> None:
|
|
78
|
+
"""
|
|
79
|
+
Set visualization options
|
|
80
|
+
|
|
81
|
+
Parameters:
|
|
82
|
+
|
|
83
|
+
deformation : object
|
|
84
|
+
input deformation
|
|
85
|
+
|
|
86
|
+
min : object
|
|
87
|
+
input min
|
|
88
|
+
|
|
89
|
+
max : object
|
|
90
|
+
input max
|
|
91
|
+
|
|
92
|
+
clipnormal : object
|
|
93
|
+
input clipnormal
|
|
94
|
+
|
|
95
|
+
clipping : object
|
|
96
|
+
input clipping
|
|
97
|
+
"""
|
|
98
|
+
def Tcl_Eval(arg0: str) -> None:
|
|
99
|
+
...
|
|
100
|
+
def _GetFacetValues(arg0: ngsolve.fem.CoefficientFunction, arg1: ngsolve.comp.Mesh, arg2: collections.abc.Mapping[ngsolve.fem.ET, ngsolve.fem.IntegrationRule]) -> dict:
|
|
101
|
+
...
|
|
102
|
+
def _GetValues(arg0: ngsolve.fem.CoefficientFunction, arg1: ngsolve.comp.Mesh, arg2: ngsolve.comp.VorB, arg3: collections.abc.Mapping[ngsolve.fem.ET, ngsolve.fem.IntegrationRule], arg4: bool) -> dict:
|
|
103
|
+
...
|
|
104
|
+
def _GetVisualizationData(arg0: ngsolve.comp.Mesh, arg1: collections.abc.Mapping[ngsolve.fem.ET, ngsolve.fem.IntegrationRule]) -> dict:
|
|
105
|
+
...
|
|
106
|
+
def _SetLocale() -> None:
|
|
107
|
+
...
|
|
108
|
+
def __Cleanup() -> None:
|
|
109
|
+
...
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
|
|
3
|
+
from ngsolve import (
|
|
4
|
+
BilinearForm,
|
|
5
|
+
GridFunction,
|
|
6
|
+
CoefficientFunction,
|
|
7
|
+
Region,
|
|
8
|
+
BND,
|
|
9
|
+
Preconditioner,
|
|
10
|
+
)
|
|
11
|
+
from .nonlinearsolvers import NewtonSolver
|
|
12
|
+
from .krylovspace import GMResSolver, LinearSolver
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Dirichlet:
|
|
16
|
+
def __init__(self, cf, region):
|
|
17
|
+
self.cf = cf
|
|
18
|
+
self.region = region
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Application:
|
|
22
|
+
def __init__(self, a: BilinearForm, gf: GridFunction):
|
|
23
|
+
self.a = a
|
|
24
|
+
self.gf = gf
|
|
25
|
+
|
|
26
|
+
def Solve(
|
|
27
|
+
self,
|
|
28
|
+
rhs,
|
|
29
|
+
*args,
|
|
30
|
+
dirichlet = None,
|
|
31
|
+
pre = None,
|
|
32
|
+
printrates: bool = False,
|
|
33
|
+
**kwargs,
|
|
34
|
+
):
|
|
35
|
+
raise NotImplementedError("Solve method must be implemented in subclasses")
|
|
36
|
+
|
|
37
|
+
def __eq__(self, other):
|
|
38
|
+
return Equation(self, other)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class NonLinearApplication(Application):
|
|
42
|
+
def Solve(
|
|
43
|
+
self,
|
|
44
|
+
rhs=None,
|
|
45
|
+
dirichlet = None,
|
|
46
|
+
printing: bool = False,
|
|
47
|
+
**kwargs,
|
|
48
|
+
):
|
|
49
|
+
solver_args = {}
|
|
50
|
+
|
|
51
|
+
if rhs is not None and rhs != 0:
|
|
52
|
+
rhs.Assemble()
|
|
53
|
+
solver_args["rhs"] = rhs
|
|
54
|
+
if "freedofs" in kwargs:
|
|
55
|
+
solver_args["freedofs"] = kwargs.pop("freedofs")
|
|
56
|
+
if "inverse" in kwargs:
|
|
57
|
+
solver_args["inverse"] = kwargs.pop("inverse")
|
|
58
|
+
solver = NewtonSolver(self.a, self.gf, **solver_args)
|
|
59
|
+
if dirichlet is not None:
|
|
60
|
+
dirichlet_gf = GridFunction(self.gf.space)
|
|
61
|
+
if isinstance(dirichlet, list):
|
|
62
|
+
for i in range(len(dirichlet)):
|
|
63
|
+
if dirichlet[i] is not None:
|
|
64
|
+
if isinstance(dirichlet[i], Dirichlet):
|
|
65
|
+
dirichlet_gf.components[i].Set(
|
|
66
|
+
dirichlet[i].cf, definedon=dirichlet[i].region
|
|
67
|
+
)
|
|
68
|
+
else:
|
|
69
|
+
dirichlet_gf.components[i].Set(dirichlet[i], BND)
|
|
70
|
+
elif isinstance(dirichlet, Dirichlet):
|
|
71
|
+
dirichlet_gf.Set(dirichlet.cf, definedon=dirichlet.region)
|
|
72
|
+
else:
|
|
73
|
+
dirichlet_gf.Set(dirichlet, BND)
|
|
74
|
+
solver.SetDirichlet(dirichlet_gf.vec)
|
|
75
|
+
solver.Solve(printing=printing, **kwargs)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class LinearApplication(Application):
|
|
79
|
+
def Assemble(self):
|
|
80
|
+
if not hasattr(self, "vec"):
|
|
81
|
+
self.vec = self.gf.vec.CreateVector()
|
|
82
|
+
self.a.Apply(self.gf.vec, self.vec)
|
|
83
|
+
|
|
84
|
+
def Solve(
|
|
85
|
+
self,
|
|
86
|
+
rhs,
|
|
87
|
+
*args,
|
|
88
|
+
dirichlet = None,
|
|
89
|
+
pre = None,
|
|
90
|
+
lin_solver=None,
|
|
91
|
+
lin_solver_args = None,
|
|
92
|
+
printrates: bool = False,
|
|
93
|
+
):
|
|
94
|
+
self.a.Assemble()
|
|
95
|
+
for arg in args:
|
|
96
|
+
if isinstance(arg, Dirichlet) or isinstance(arg, CoefficientFunction):
|
|
97
|
+
assert dirichlet is None, "Only one dirichlet condition can be set"
|
|
98
|
+
dirichlet = arg
|
|
99
|
+
if isinstance(arg, Preconditioner):
|
|
100
|
+
assert pre is None, "Only one preconditioner can be set"
|
|
101
|
+
pre = arg
|
|
102
|
+
if isinstance(arg, type) and issubclass(arg, LinearSolver):
|
|
103
|
+
assert lin_solver is None, "Only one linear solver can be set"
|
|
104
|
+
lin_solver = arg
|
|
105
|
+
rhs.Assemble()
|
|
106
|
+
if dirichlet is not None:
|
|
107
|
+
if isinstance(dirichlet, list):
|
|
108
|
+
for i in range(len(dirichlet)):
|
|
109
|
+
if dirichlet[i] is not None:
|
|
110
|
+
if isinstance(dirichlet[i], Dirichlet):
|
|
111
|
+
self.gf.components[i].Set(
|
|
112
|
+
dirichlet[i].cf, definedon=dirichlet[i].region
|
|
113
|
+
)
|
|
114
|
+
else:
|
|
115
|
+
self.gf.components[i].Set(dirichlet[i], BND)
|
|
116
|
+
elif isinstance(dirichlet, Dirichlet):
|
|
117
|
+
self.gf.Set(dirichlet.cf, definedon=dirichlet.region)
|
|
118
|
+
else:
|
|
119
|
+
self.gf.Set(dirichlet, BND)
|
|
120
|
+
rhs.vec.data += -self.a.mat * self.gf.vec
|
|
121
|
+
else:
|
|
122
|
+
self.gf.vec[:] = 0.0
|
|
123
|
+
if self.a.condense:
|
|
124
|
+
rhs.vec.data += self.a.harmonic_extension_trans * rhs.vec
|
|
125
|
+
if pre is None and lin_solver is None:
|
|
126
|
+
ainv = self.a.mat.Inverse(self.a.space.FreeDofs(self.a.condense))
|
|
127
|
+
else:
|
|
128
|
+
if lin_solver is None:
|
|
129
|
+
lin_solver = GMResSolver
|
|
130
|
+
if lin_solver_args is None:
|
|
131
|
+
lin_solver_args = {}
|
|
132
|
+
if pre is None:
|
|
133
|
+
freedofs = self.a.space.FreeDofs(self.a.condense)
|
|
134
|
+
else:
|
|
135
|
+
freedofs = None
|
|
136
|
+
if "printrates" not in lin_solver_args:
|
|
137
|
+
lin_solver_args["printrates"] = printrates
|
|
138
|
+
ainv = lin_solver(
|
|
139
|
+
mat=self.a.mat, pre=pre, freedofs=freedofs, **lin_solver_args
|
|
140
|
+
)
|
|
141
|
+
self.gf.vec.data += ainv * rhs.vec
|
|
142
|
+
if self.a.condense:
|
|
143
|
+
self.gf.vec.data += self.a.harmonic_extension * self.gf.vec
|
|
144
|
+
self.gf.vec.data += self.a.inner_solve * rhs.vec
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class Equation:
|
|
148
|
+
def __init__(self, lhs, rhs):
|
|
149
|
+
self.lhs = lhs
|
|
150
|
+
self.rhs = rhs
|
|
151
|
+
|
|
152
|
+
@functools.wraps(Application.Solve)
|
|
153
|
+
def Solve(self, *args, **kwargs):
|
|
154
|
+
self.lhs.Solve(self.rhs, *args, **kwargs)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _create_lin_appl(self, gfu: GridFunction) -> LinearApplication:
|
|
158
|
+
if not isinstance(gfu, GridFunction):
|
|
159
|
+
raise TypeError("gfu must be a GridFunction")
|
|
160
|
+
return LinearApplication(self, gfu)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
BilinearForm.__mul__ = _create_lin_appl
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@functools.wraps(Application.Solve)
|
|
167
|
+
def Solve(eq: Equation, *args, **kwargs):
|
|
168
|
+
eq.Solve(*args, **kwargs)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import functools as functools
|
|
3
|
+
import ngsolve.comp
|
|
4
|
+
from ngsolve.comp import BilinearForm
|
|
5
|
+
from ngsolve.comp import GridFunction
|
|
6
|
+
from ngsolve.comp import Preconditioner
|
|
7
|
+
from ngsolve.comp import Region
|
|
8
|
+
from ngsolve.fem import CoefficientFunction
|
|
9
|
+
from ngsolve.krylovspace import GMResSolver
|
|
10
|
+
from ngsolve.krylovspace import LinearSolver
|
|
11
|
+
from ngsolve.nonlinearsolvers import NewtonSolver
|
|
12
|
+
import typing
|
|
13
|
+
__all__: list[str] = ['Application', 'BND', 'BilinearForm', 'CoefficientFunction', 'Dirichlet', 'Equation', 'GMResSolver', 'GridFunction', 'LinearApplication', 'LinearSolver', 'NewtonSolver', 'NonLinearApplication', 'Preconditioner', 'Region', 'Solve', 'functools']
|
|
14
|
+
class Application:
|
|
15
|
+
__hash__: typing.ClassVar[None] = None
|
|
16
|
+
def Solve(self, rhs, *args, dirichlet = None, pre = None, printrates: bool = False, **kwargs):
|
|
17
|
+
...
|
|
18
|
+
def __eq__(self, other):
|
|
19
|
+
...
|
|
20
|
+
def __init__(self, a: ngsolve.comp.BilinearForm, gf: ngsolve.comp.GridFunction):
|
|
21
|
+
...
|
|
22
|
+
class Dirichlet:
|
|
23
|
+
def __init__(self, cf, region):
|
|
24
|
+
...
|
|
25
|
+
class Equation:
|
|
26
|
+
def Solve(self, *args, **kwargs):
|
|
27
|
+
...
|
|
28
|
+
def __init__(self, lhs, rhs):
|
|
29
|
+
...
|
|
30
|
+
class LinearApplication(Application):
|
|
31
|
+
def Assemble(self):
|
|
32
|
+
...
|
|
33
|
+
def Solve(self, rhs, *args, dirichlet = None, pre = None, lin_solver = None, lin_solver_args = None, printrates: bool = False):
|
|
34
|
+
...
|
|
35
|
+
class NonLinearApplication(Application):
|
|
36
|
+
def Solve(self, rhs = None, dirichlet = None, printing: bool = False, **kwargs):
|
|
37
|
+
...
|
|
38
|
+
def Solve(eq, *args, **kwargs):
|
|
39
|
+
...
|
|
40
|
+
def _create_lin_appl(self, gfu: ngsolve.comp.GridFunction) -> LinearApplication:
|
|
41
|
+
...
|
|
42
|
+
BND: ngsolve.comp.VorB # value = <VorB.BND: 1>
|
ngsolve/solvers.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from ngsolve.eigenvalues import PINVIT, LOBPCG
|
|
2
|
+
from ngsolve.krylovspace import CG, QMR, MinRes, PreconditionedRichardson, GMRes
|
|
3
|
+
from ngsolve.krylovspace import CGSolver
|
|
4
|
+
from ngsolve.nonlinearsolvers import Newton, NewtonMinimization
|
|
5
|
+
from ngsolve.bvp import BVP
|
|
6
|
+
from ngsolve.directsolvers import SuperLU
|
|
7
|
+
|
ngsolve/solvers.pyi
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from ngsolve.bvp import BVP
|
|
3
|
+
from ngsolve.directsolvers import SuperLU
|
|
4
|
+
from ngsolve.eigenvalues import LOBPCG
|
|
5
|
+
from ngsolve.eigenvalues import PINVIT
|
|
6
|
+
from ngsolve.krylovspace import CG
|
|
7
|
+
from ngsolve.krylovspace import CGSolver
|
|
8
|
+
from ngsolve.krylovspace import GMRes
|
|
9
|
+
from ngsolve.krylovspace import MinRes
|
|
10
|
+
from ngsolve.krylovspace import PreconditionedRichardson
|
|
11
|
+
from ngsolve.krylovspace import QMR
|
|
12
|
+
from ngsolve.nonlinearsolvers import Newton
|
|
13
|
+
from ngsolve.nonlinearsolvers import NewtonMinimization
|
|
14
|
+
__all__: list[str] = ['BVP', 'CG', 'CGSolver', 'GMRes', 'LOBPCG', 'MinRes', 'Newton', 'NewtonMinimization', 'PINVIT', 'PreconditionedRichardson', 'QMR', 'SuperLU']
|
ngsolve/timestepping.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
|
|
2
|
+
import ngsolve as ngs
|
|
3
|
+
from typing import Type, Optional, Union, Callable
|
|
4
|
+
|
|
5
|
+
class ImplicitEuler:
|
|
6
|
+
def __init__(self,
|
|
7
|
+
equation: ngs.comp.SumOfIntegrals,
|
|
8
|
+
dt: Union[float, ngs.Parameter],
|
|
9
|
+
time: ngs.Parameter = ngs.Parameter(0),
|
|
10
|
+
pc_cls: Type = ngs.preconditioners.MultiGrid,
|
|
11
|
+
pc_args: Optional[dict] = None,
|
|
12
|
+
lin_solver_cls: Type = ngs.solvers.CGSolver,
|
|
13
|
+
lin_solver_args: Optional[dict] = None):
|
|
14
|
+
|
|
15
|
+
self.time = time
|
|
16
|
+
proxies = equation.GetProxies()
|
|
17
|
+
udts = list(filter(lambda u: u.dt_order == 1, proxies))
|
|
18
|
+
self.gfu_old = ngs.GridFunction(udts[0].space)
|
|
19
|
+
self.dt = ngs.Parameter(dt) if (isinstance(dt, float) or isinstance(dt, int)) else dt
|
|
20
|
+
replacements = {}
|
|
21
|
+
for udt in udts:
|
|
22
|
+
replacements[udt] = 1/self.dt * (udt.anti_dt - udt.anti_dt.ReplaceFunction(self.gfu_old))
|
|
23
|
+
self.bfmstar = ngs.BilinearForm(equation.Replace(replacements))
|
|
24
|
+
self.bfmstar.Assemble()
|
|
25
|
+
self.c = pc_cls(self.bfmstar, **(pc_args or {}))
|
|
26
|
+
self._lin_solver_cls = lin_solver_cls
|
|
27
|
+
self._lin_solver_args = lin_solver_args
|
|
28
|
+
|
|
29
|
+
def Integrate(self, u_start: ngs.GridFunction,
|
|
30
|
+
end_time: float,
|
|
31
|
+
start_time: Optional[float] = None,
|
|
32
|
+
newton_args: Optional[dict] = None,
|
|
33
|
+
callback: Optional[Callable] = None):
|
|
34
|
+
u = u_start
|
|
35
|
+
if start_time is not None:
|
|
36
|
+
self.time.Set(start_time)
|
|
37
|
+
while self.time.Get() < end_time * (1-1e-10):
|
|
38
|
+
dt = min(self.dt.Get(), end_time - self.time.Get())
|
|
39
|
+
self.time.Set(self.time.Get() + dt)
|
|
40
|
+
self.Step(u, dt=dt, newton_args=newton_args)
|
|
41
|
+
if callback is not None:
|
|
42
|
+
callback(self.time.Get(), u)
|
|
43
|
+
return u
|
|
44
|
+
|
|
45
|
+
def Step(self, u: ngs.GridFunction, dt: Optional[float] = None,
|
|
46
|
+
newton_args: Optional[dict] = None):
|
|
47
|
+
if dt is not None:
|
|
48
|
+
self.dt.Set(dt)
|
|
49
|
+
self.gfu_old.vec.data = u.vec
|
|
50
|
+
lin_solver = self._lin_solver_cls(mat=self.bfmstar.mat,
|
|
51
|
+
pre=self.c,
|
|
52
|
+
**(self._lin_solver_args or {}))
|
|
53
|
+
newton = ngs.nonlinearsolvers.NewtonSolver(a=self.bfmstar,
|
|
54
|
+
u=u,
|
|
55
|
+
solver=lin_solver)
|
|
56
|
+
newton.Solve(**(newton_args or {}))
|
|
57
|
+
|
|
58
|
+
class Newmark:
|
|
59
|
+
def __init__(self,
|
|
60
|
+
equation: ngs.comp.SumOfIntegrals,
|
|
61
|
+
dt: Union[float, ngs.Parameter],
|
|
62
|
+
time: ngs.Parameter = ngs.Parameter(0),
|
|
63
|
+
pc_cls: Type = ngs.preconditioners.MultiGrid,
|
|
64
|
+
pc_args: Optional[dict] = None,
|
|
65
|
+
lin_solver_cls: Type = ngs.solvers.CGSolver,
|
|
66
|
+
lin_solver_args: Optional[dict] = None):
|
|
67
|
+
self.time = time
|
|
68
|
+
proxies = equation.GetProxies()
|
|
69
|
+
udt2 = list(filter(lambda u: u.dt_order == 2, proxies))
|
|
70
|
+
if len(udt2) != 1:
|
|
71
|
+
raise ValueError("Only u.dt.dt allowed as time derivatives in newmark!")
|
|
72
|
+
udt2 = udt2[0]
|
|
73
|
+
self.gfu_old = ngs.GridFunction(udt2.space)
|
|
74
|
+
self.gfv_old = ngs.GridFunction(udt2.space)
|
|
75
|
+
self.gfa_old = ngs.GridFunction(udt2.space)
|
|
76
|
+
self.dt = ngs.Parameter(dt) if (isinstance(dt, float) or isinstance(dt, int)) else dt
|
|
77
|
+
self.bfmstar = ngs.BilinearForm(udt2.space)
|
|
78
|
+
u = udt2.anti_dt.anti_dt
|
|
79
|
+
vel_new = 2/self.dt * (u-self.gfu_old) - self.gfv_old
|
|
80
|
+
acc_new = 2/self.dt * (vel_new-self.gfv_old) - self.gfa_old
|
|
81
|
+
self.bfmstar += equation.Replace({ udt2: acc_new })
|
|
82
|
+
self.bfmstar.Assemble()
|
|
83
|
+
self.c = pc_cls(self.bfmstar, **(pc_args or {}))
|
|
84
|
+
self._lin_solver_cls = lin_solver_cls
|
|
85
|
+
self._lin_solver_args = lin_solver_args
|
|
86
|
+
|
|
87
|
+
def Integrate(self, u: ngs.GridFunction,
|
|
88
|
+
end_time: float,
|
|
89
|
+
v: Optional[ngs.GridFunction] = None,
|
|
90
|
+
a: Optional[ngs.GridFunction] = None,
|
|
91
|
+
start_time: Optional[float] = None,
|
|
92
|
+
newton_args: Optional[dict] = None,
|
|
93
|
+
callback: Optional[Callable] = None):
|
|
94
|
+
if start_time is not None:
|
|
95
|
+
self.time.Set(start_time)
|
|
96
|
+
if v is None:
|
|
97
|
+
v = ngs.GridFunction(u.space)
|
|
98
|
+
if a is None:
|
|
99
|
+
a = ngs.GridFunction(u.space)
|
|
100
|
+
while self.time.Get() < end_time * (1-1e-10):
|
|
101
|
+
dt = min(self.dt.Get(), end_time - self.time.Get())
|
|
102
|
+
self.time.Set(self.time.Get() + dt)
|
|
103
|
+
self.Step(u, v, a, dt=dt, newton_args=newton_args)
|
|
104
|
+
if callback is not None:
|
|
105
|
+
callback(self.time.Get(), u)
|
|
106
|
+
return u
|
|
107
|
+
|
|
108
|
+
def Step(self, u: ngs.GridFunction,
|
|
109
|
+
v: ngs.GridFunction,
|
|
110
|
+
a: ngs.GridFunction,
|
|
111
|
+
dt: Optional[float] = None,
|
|
112
|
+
newton_args: Optional[dict] = None):
|
|
113
|
+
if dt is not None:
|
|
114
|
+
self.dt.Set(dt)
|
|
115
|
+
self.gfu_old.vec.data = u.vec
|
|
116
|
+
self.gfv_old.vec.data = v.vec
|
|
117
|
+
self.gfa_old.vec.data = a.vec
|
|
118
|
+
lin_solver = self._lin_solver_cls(mat=self.bfmstar.mat,
|
|
119
|
+
pre=self.c,
|
|
120
|
+
**(self._lin_solver_args or {}))
|
|
121
|
+
newton = ngs.nonlinearsolvers.NewtonSolver(a=self.bfmstar,
|
|
122
|
+
u=u,
|
|
123
|
+
solver=lin_solver)
|
|
124
|
+
newton.Solve(**(newton_args or {}))
|
|
125
|
+
v.vec.data = 2/self.dt.Get() * (u.vec - self.gfu_old.vec) - self.gfv_old.vec
|
|
126
|
+
a.vec.data = 2/self.dt.Get() * (v.vec - self.gfv_old.vec) - self.gfa_old.vec
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class CrankNicolson:
|
|
130
|
+
def __init__(self,
|
|
131
|
+
equation: ngs.comp.SumOfIntegrals,
|
|
132
|
+
dt: Union[float, ngs.Parameter],
|
|
133
|
+
time: ngs.Parameter = ngs.Parameter(0),
|
|
134
|
+
pc_cls: Type = ngs.preconditioners.MultiGrid,
|
|
135
|
+
pc_args: Optional[dict] = None,
|
|
136
|
+
lin_solver_cls: Type = ngs.solvers.CGSolver,
|
|
137
|
+
lin_solver_args: Optional[dict] = None):
|
|
138
|
+
self.time = time
|
|
139
|
+
proxies = equation.GetProxies()
|
|
140
|
+
fes = proxies[0].space
|
|
141
|
+
self.dt = ngs.Parameter(dt) if (isinstance(dt, float) or isinstance(dt, int)) else dt
|
|
142
|
+
self.gfu_old = ngs.GridFunction(fes)
|
|
143
|
+
replacements = {}
|
|
144
|
+
for p in proxies:
|
|
145
|
+
if p.dt_order == 1:
|
|
146
|
+
replacements[p] = 1/self.dt * (p.anti_dt - p.anti_dt.ReplaceFunction(self.gfu_old))
|
|
147
|
+
terms = 0.5 * equation.Replace(replacements)
|
|
148
|
+
for p in proxies:
|
|
149
|
+
if p.dt_order == 0:
|
|
150
|
+
replacements[p] = p.ReplaceFunction(self.gfu_old)
|
|
151
|
+
terms += 0.5 * equation.Replace(replacements)
|
|
152
|
+
self.bfmstar = ngs.BilinearForm(terms)
|
|
153
|
+
self.bfmstar.Assemble()
|
|
154
|
+
self.c = pc_cls(self.bfmstar, **(pc_args or {}))
|
|
155
|
+
self._lin_solver_cls = lin_solver_cls
|
|
156
|
+
self._lin_solver_args = lin_solver_args
|
|
157
|
+
|
|
158
|
+
def Integrate(self, u_start: ngs.GridFunction,
|
|
159
|
+
end_time: float,
|
|
160
|
+
start_time: Optional[float] = None,
|
|
161
|
+
newton_args: Optional[dict] = None,
|
|
162
|
+
callback: Optional[Callable] = None):
|
|
163
|
+
u = u_start
|
|
164
|
+
if start_time is not None:
|
|
165
|
+
self.time.Set(start_time)
|
|
166
|
+
while self.time.Get() < end_time * (1-1e-10):
|
|
167
|
+
dt = min(self.dt.Get(), end_time - self.time.Get())
|
|
168
|
+
self.time.Set(self.time.Get() + dt)
|
|
169
|
+
self.Step(u, dt=dt, newton_args=newton_args)
|
|
170
|
+
if callback is not None:
|
|
171
|
+
callback(self.time.Get(), u)
|
|
172
|
+
return u
|
|
173
|
+
|
|
174
|
+
def Step(self, u: ngs.GridFunction, dt: Optional[float] = None,
|
|
175
|
+
newton_args: Optional[dict] = None):
|
|
176
|
+
if dt is not None:
|
|
177
|
+
self.dt.Set(dt)
|
|
178
|
+
self.gfu_old.vec.data = u.vec
|
|
179
|
+
lin_solver = self._lin_solver_cls(mat=self.bfmstar.mat,
|
|
180
|
+
pre=self.c,
|
|
181
|
+
**(self._lin_solver_args or {}))
|
|
182
|
+
newton = ngs.nonlinearsolvers.NewtonSolver(a=self.bfmstar,
|
|
183
|
+
u=u,
|
|
184
|
+
solver=lin_solver)
|
|
185
|
+
newton.Solve(**(newton_args or {}))
|
ngsolve/timestepping.pyi
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import ngsolve as ngs
|
|
3
|
+
import ngsolve.comp
|
|
4
|
+
import ngsolve.fem
|
|
5
|
+
import ngsolve.krylovspace
|
|
6
|
+
from typing import Union
|
|
7
|
+
__all__: list[str] = ['CrankNicolson', 'ImplicitEuler', 'Newmark', 'Union', 'ngs']
|
|
8
|
+
class CrankNicolson:
|
|
9
|
+
def Integrate(self, u_start: ngsolve.comp.GridFunction, end_time: float, start_time: float | None = None, newton_args: dict | None = None, callback: typing.Callable | None = None):
|
|
10
|
+
...
|
|
11
|
+
def Step(self, u: ngsolve.comp.GridFunction, dt: float | None = None, newton_args: dict | None = None):
|
|
12
|
+
...
|
|
13
|
+
def __init__(self, equation: ngsolve.comp.SumOfIntegrals, dt: float | ngsolve.fem.Parameter, time: ngsolve.fem.Parameter = ..., pc_cls: typing.Type = ngsolve.comp.MultiGridPreconditioner, pc_args: dict | None = None, lin_solver_cls: typing.Type = ngsolve.krylovspace.CGSolver, lin_solver_args: dict | None = None):
|
|
14
|
+
...
|
|
15
|
+
class ImplicitEuler:
|
|
16
|
+
def Integrate(self, u_start: ngsolve.comp.GridFunction, end_time: float, start_time: float | None = None, newton_args: dict | None = None, callback: typing.Callable | None = None):
|
|
17
|
+
...
|
|
18
|
+
def Step(self, u: ngsolve.comp.GridFunction, dt: float | None = None, newton_args: dict | None = None):
|
|
19
|
+
...
|
|
20
|
+
def __init__(self, equation: ngsolve.comp.SumOfIntegrals, dt: float | ngsolve.fem.Parameter, time: ngsolve.fem.Parameter = ..., pc_cls: typing.Type = ngsolve.comp.MultiGridPreconditioner, pc_args: dict | None = None, lin_solver_cls: typing.Type = ngsolve.krylovspace.CGSolver, lin_solver_args: dict | None = None):
|
|
21
|
+
...
|
|
22
|
+
class Newmark:
|
|
23
|
+
def Integrate(self, u: ngsolve.comp.GridFunction, end_time: float, v: ngsolve.comp.GridFunction | None = None, a: ngsolve.comp.GridFunction | None = None, start_time: float | None = None, newton_args: dict | None = None, callback: typing.Callable | None = None):
|
|
24
|
+
...
|
|
25
|
+
def Step(self, u: ngsolve.comp.GridFunction, v: ngsolve.comp.GridFunction, a: ngsolve.comp.GridFunction, dt: float | None = None, newton_args: dict | None = None):
|
|
26
|
+
...
|
|
27
|
+
def __init__(self, equation: ngsolve.comp.SumOfIntegrals, dt: float | ngsolve.fem.Parameter, time: ngsolve.fem.Parameter = ..., pc_cls: typing.Type = ngsolve.comp.MultiGridPreconditioner, pc_args: dict | None = None, lin_solver_cls: typing.Type = ngsolve.krylovspace.CGSolver, lin_solver_args: dict | None = None):
|
|
28
|
+
...
|