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,957 @@
|
|
|
1
|
+
#ifndef FILE_NGS_BASEMATRIX
|
|
2
|
+
#define FILE_NGS_BASEMATRIX
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/*********************************************************************/
|
|
6
|
+
/* File: basematrix.hpp */
|
|
7
|
+
/* Author: Joachim Schoeberl */
|
|
8
|
+
/* Date: 25. Mar. 2000 */
|
|
9
|
+
/*********************************************************************/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#include "basevector.hpp"
|
|
13
|
+
#include "multivector.hpp"
|
|
14
|
+
// #include "paralleldofs.hpp"
|
|
15
|
+
|
|
16
|
+
namespace ngla
|
|
17
|
+
{
|
|
18
|
+
class ParallelDofs;
|
|
19
|
+
|
|
20
|
+
// sets the solver which is used for InverseMatrix
|
|
21
|
+
enum INVERSETYPE { PARDISO, PARDISOSPD, SPARSECHOLESKY, SUPERLU, SUPERLU_DIST, MUMPS, MASTERINVERSE, UMFPACK };
|
|
22
|
+
extern string GetInverseName (INVERSETYPE type);
|
|
23
|
+
|
|
24
|
+
class BaseSparseMatrix;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
The base for all matrices in the linalg.
|
|
28
|
+
*/
|
|
29
|
+
class NGS_DLL_HEADER BaseMatrix : public enable_shared_from_this_virtual<BaseMatrix>
|
|
30
|
+
{
|
|
31
|
+
protected:
|
|
32
|
+
shared_ptr<ParallelDofs> paralleldofs;
|
|
33
|
+
mutable char safety_check = 0;
|
|
34
|
+
bool is_complex = false;
|
|
35
|
+
|
|
36
|
+
protected:
|
|
37
|
+
///
|
|
38
|
+
BaseMatrix ();
|
|
39
|
+
///
|
|
40
|
+
BaseMatrix (shared_ptr<ParallelDofs> aparalleldofs);
|
|
41
|
+
|
|
42
|
+
public:
|
|
43
|
+
///
|
|
44
|
+
virtual ~BaseMatrix ();
|
|
45
|
+
/// virtual function must be overloaded
|
|
46
|
+
virtual int VHeight() const;
|
|
47
|
+
|
|
48
|
+
/// virtual function must be overloaded
|
|
49
|
+
virtual int VWidth() const;
|
|
50
|
+
|
|
51
|
+
/// inline function VHeight
|
|
52
|
+
size_t Height() const
|
|
53
|
+
{
|
|
54
|
+
return VHeight();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// inline function VWidth
|
|
58
|
+
size_t Width() const
|
|
59
|
+
{
|
|
60
|
+
return VWidth();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
virtual tuple<size_t, size_t> Shape() const { return { Height(), Width() }; }
|
|
64
|
+
|
|
65
|
+
virtual xbool IsSymmetric() const { return maybe; }
|
|
66
|
+
|
|
67
|
+
/// is matrix complex ?
|
|
68
|
+
virtual bool IsComplex() const { return is_complex; }
|
|
69
|
+
|
|
70
|
+
/// scalar assignment
|
|
71
|
+
BaseMatrix & operator= (double s)
|
|
72
|
+
{
|
|
73
|
+
AsVector().SetScalar(s);
|
|
74
|
+
return *this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// linear access of matrix memory
|
|
78
|
+
virtual BaseVector & AsVector();
|
|
79
|
+
/// linear access of matrix memory
|
|
80
|
+
virtual const BaseVector & AsVector() const;
|
|
81
|
+
///
|
|
82
|
+
virtual void SetZero();
|
|
83
|
+
|
|
84
|
+
virtual ostream & Print (ostream & ost) const;
|
|
85
|
+
virtual Array<MemoryUsage> GetMemoryUsage () const;
|
|
86
|
+
virtual size_t NZE () const;
|
|
87
|
+
|
|
88
|
+
template <typename T>
|
|
89
|
+
shared_ptr<T> SharedFromThis()
|
|
90
|
+
{ return dynamic_pointer_cast<T> (shared_from_this()); }
|
|
91
|
+
/// whatever it means ... e.g. refactor sparse factorization
|
|
92
|
+
virtual void Update();
|
|
93
|
+
/// creates matrix of same type
|
|
94
|
+
virtual shared_ptr<BaseMatrix> CreateMatrix () const;
|
|
95
|
+
/// creates a matching vector, size = width
|
|
96
|
+
virtual AutoVector CreateRowVector () const = 0;
|
|
97
|
+
/// creates a matching vector, size = height
|
|
98
|
+
virtual AutoVector CreateColVector () const = 0;
|
|
99
|
+
/// creates a matching vector (for square matrices)
|
|
100
|
+
[[deprecated("use CreateRowVector or CreateColVector instead")]]
|
|
101
|
+
virtual AutoVector CreateVector () const;
|
|
102
|
+
|
|
103
|
+
virtual AutoVector Evaluate(BaseVector & v) const
|
|
104
|
+
{
|
|
105
|
+
auto res = CreateColVector();
|
|
106
|
+
Mult (v, res);
|
|
107
|
+
return res;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// y = matrix * x.
|
|
111
|
+
virtual void Mult (const BaseVector & x, BaseVector & y) const;
|
|
112
|
+
///
|
|
113
|
+
virtual void MultTrans (const BaseVector & x, BaseVector & y) const;
|
|
114
|
+
/// y += s matrix * x
|
|
115
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const;
|
|
116
|
+
/// y += s matrix * x
|
|
117
|
+
virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const;
|
|
118
|
+
|
|
119
|
+
/// y += s Trans(matrix) * x
|
|
120
|
+
virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const;
|
|
121
|
+
/// y += s Trans(matrix) * x
|
|
122
|
+
virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const;
|
|
123
|
+
/// y += s Trans(matrix) * x
|
|
124
|
+
virtual void MultConjTransAdd (Complex s, const BaseVector & x, BaseVector & y) const;
|
|
125
|
+
|
|
126
|
+
/// y += alpha M x
|
|
127
|
+
virtual void MultAdd (FlatVector<double> alpha, const MultiVector & x, MultiVector & y) const;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
to split mat x vec for symmetric matrices
|
|
131
|
+
only rows with inner or cluster true need by added (but more can be ...)
|
|
132
|
+
*/
|
|
133
|
+
virtual void MultAdd1 (double s, const BaseVector & x, BaseVector & y,
|
|
134
|
+
const BitArray * ainner = NULL,
|
|
135
|
+
const Array<int> * acluster = NULL) const;
|
|
136
|
+
|
|
137
|
+
/// only cols with inner or cluster true need by added (but more can be ...)
|
|
138
|
+
virtual void MultAdd2 (double s, const BaseVector & x, BaseVector & y,
|
|
139
|
+
const BitArray * ainner = NULL,
|
|
140
|
+
const Array<int> * acluster = NULL) const;
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
void SetParallelDofs (shared_ptr<ParallelDofs> pardofs) { paralleldofs = pardofs; }
|
|
144
|
+
shared_ptr<ParallelDofs> GetParallelDofs () const { return paralleldofs; }
|
|
145
|
+
virtual optional<NgMPI_Comm> GetCommunicator() const { return nullopt; }
|
|
146
|
+
|
|
147
|
+
virtual shared_ptr<BaseMatrix> InverseMatrix (shared_ptr<BitArray> subset = nullptr) const;
|
|
148
|
+
virtual shared_ptr<BaseMatrix> InverseMatrix (shared_ptr<const Array<int>> clusters) const;
|
|
149
|
+
virtual INVERSETYPE SetInverseType ( INVERSETYPE ainversetype ) const;
|
|
150
|
+
virtual INVERSETYPE SetInverseType ( string ainversetype ) const;
|
|
151
|
+
virtual INVERSETYPE GetInverseType () const;
|
|
152
|
+
|
|
153
|
+
typedef std::function<shared_ptr<BaseMatrix>(shared_ptr<BaseMatrix>,
|
|
154
|
+
shared_ptr<BitArray>,
|
|
155
|
+
shared_ptr<const Array<int>>)> T_INVCREATOR;
|
|
156
|
+
mutable T_INVCREATOR invcreator;
|
|
157
|
+
void SetInverseCreator(T_INVCREATOR ainvcreator) const { invcreator = ainvcreator; }
|
|
158
|
+
|
|
159
|
+
static SymbolTable<T_INVCREATOR> invcreators;
|
|
160
|
+
static void RegisterInverseCreator(string name, T_INVCREATOR creator);
|
|
161
|
+
|
|
162
|
+
virtual void SetInverseFlags (const Flags & flags) { ; }
|
|
163
|
+
virtual shared_ptr<BaseMatrix> DeleteZeroElements(double tol) const
|
|
164
|
+
{
|
|
165
|
+
throw Exception (string("DeleteZeroElements not overloaded, type =")+typeid(*this).name());
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
virtual void DoArchive (Archive & ar);
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
template <typename TSCAL>
|
|
173
|
+
Matrix<TSCAL> ToDense() const;
|
|
174
|
+
|
|
175
|
+
virtual shared_ptr<BaseSparseMatrix> CreateSparseMatrix() const;
|
|
176
|
+
|
|
177
|
+
// time per run
|
|
178
|
+
double Timing (int runs = 10) const;
|
|
179
|
+
|
|
180
|
+
class OperatorInfo
|
|
181
|
+
{
|
|
182
|
+
public:
|
|
183
|
+
string name = "undef";
|
|
184
|
+
size_t height = 0, width = 0;
|
|
185
|
+
Array<const BaseMatrix*> childs;
|
|
186
|
+
OperatorInfo() = default;
|
|
187
|
+
OperatorInfo(string aname, size_t ah, size_t aw)
|
|
188
|
+
: name(aname), height(ah), width(aw) { }
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
virtual BaseMatrix::OperatorInfo GetOperatorInfo () const;
|
|
192
|
+
void PrintOperatorInfo (ostream & ost, int level = 0) const;
|
|
193
|
+
|
|
194
|
+
// base class checks for sizes, derived BlockMatrix and ParallelMatrix check more
|
|
195
|
+
virtual xbool SameShape (BaseMatrix & other) const;
|
|
196
|
+
// *this * other
|
|
197
|
+
virtual xbool CanCompose (BaseMatrix & other) const;
|
|
198
|
+
|
|
199
|
+
virtual shared_ptr<BaseMatrix> CreateDeviceMatrix() const;
|
|
200
|
+
static std::map<type_index, function<shared_ptr<BaseMatrix>(const BaseMatrix&)>> devmatcreator;
|
|
201
|
+
static void RegisterDeviceMatrixCreator (type_index type,
|
|
202
|
+
function<shared_ptr<BaseMatrix>(const BaseMatrix&)> creator)
|
|
203
|
+
{
|
|
204
|
+
devmatcreator[type] = creator;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private:
|
|
208
|
+
BaseMatrix & operator= (const BaseMatrix & m2) { return *this; }
|
|
209
|
+
|
|
210
|
+
MemoryTracer mt = { "BaseMatrix" };
|
|
211
|
+
public:
|
|
212
|
+
const MemoryTracer& GetMemoryTracer() const { return mt; }
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
/// specifies the scalar type.
|
|
221
|
+
template <typename SCAL>
|
|
222
|
+
class NGS_DLL_HEADER S_BaseMatrix : virtual public BaseMatrix
|
|
223
|
+
{
|
|
224
|
+
public:
|
|
225
|
+
S_BaseMatrix () = default;
|
|
226
|
+
virtual ~S_BaseMatrix () = default;
|
|
227
|
+
// virtual bool IsComplex() const { return false; }
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// specifies the scalar type Complex.
|
|
231
|
+
template <>
|
|
232
|
+
class S_BaseMatrix<Complex> : virtual public BaseMatrix
|
|
233
|
+
{
|
|
234
|
+
public:
|
|
235
|
+
///
|
|
236
|
+
S_BaseMatrix () { is_complex = true; }
|
|
237
|
+
virtual ~S_BaseMatrix () = default;
|
|
238
|
+
|
|
239
|
+
// virtual bool IsComplex() const { return true; }
|
|
240
|
+
|
|
241
|
+
/*
|
|
242
|
+
/// calls MultAdd (Complex s);
|
|
243
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const;
|
|
244
|
+
/// must be overloaded
|
|
245
|
+
virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const;
|
|
246
|
+
|
|
247
|
+
/// calls MultTransAdd (Complex s);
|
|
248
|
+
virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const;
|
|
249
|
+
/// should be overloaded
|
|
250
|
+
virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const;
|
|
251
|
+
*/
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
/* *************************** Matrix * Vector ******************** */
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
///
|
|
264
|
+
class VMatVecExpr
|
|
265
|
+
{
|
|
266
|
+
const BaseMatrix & m;
|
|
267
|
+
const BaseVector & x;
|
|
268
|
+
|
|
269
|
+
public:
|
|
270
|
+
VMatVecExpr (const BaseMatrix & am, const BaseVector & ax) : m(am), x(ax) { ; }
|
|
271
|
+
|
|
272
|
+
template <class TS>
|
|
273
|
+
void AssignTo (TS s, BaseVector & v) const
|
|
274
|
+
{
|
|
275
|
+
CheckSize (v);
|
|
276
|
+
m.Mult (x, v);
|
|
277
|
+
v *= s;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
template <class TS>
|
|
281
|
+
void AddTo (TS s, BaseVector & v) const
|
|
282
|
+
{
|
|
283
|
+
CheckSize (v);
|
|
284
|
+
m.MultAdd (s, x, v);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
NGS_DLL_HEADER void CheckSize (BaseVector & dest_vec) const;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
/// BaseMatrix times Vector - expression template
|
|
292
|
+
inline VVecExpr<VMatVecExpr>
|
|
293
|
+
operator* (const BaseMatrix & a, const BaseVector & b)
|
|
294
|
+
{
|
|
295
|
+
return VMatVecExpr (a, b);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
class NGS_DLL_HEADER DynamicMatVecExpression : public DynamicBaseExpression
|
|
301
|
+
{
|
|
302
|
+
shared_ptr<BaseMatrix> m;
|
|
303
|
+
shared_ptr<BaseVector> v;
|
|
304
|
+
|
|
305
|
+
AutoVector CreateVector() const override
|
|
306
|
+
{ return m->CreateColVector(); }
|
|
307
|
+
|
|
308
|
+
AutoVector Evaluate() const override
|
|
309
|
+
{
|
|
310
|
+
return m->Evaluate(*v);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
void AssignTo (double s, BaseVector & v2) const override
|
|
314
|
+
{
|
|
315
|
+
m->Mult(*v, v2);
|
|
316
|
+
v2 *= s;
|
|
317
|
+
}
|
|
318
|
+
void AddTo (double s, BaseVector & v2) const override
|
|
319
|
+
{
|
|
320
|
+
m->MultAdd (s, *v, v2);
|
|
321
|
+
}
|
|
322
|
+
void AssignTo (Complex s, BaseVector & v2) const override
|
|
323
|
+
{
|
|
324
|
+
m->Mult(*v, v2);
|
|
325
|
+
v2 *= s;
|
|
326
|
+
}
|
|
327
|
+
void AddTo (Complex s, BaseVector & v2) const override
|
|
328
|
+
{
|
|
329
|
+
m->MultAdd (s, *v, v2);
|
|
330
|
+
}
|
|
331
|
+
public:
|
|
332
|
+
DynamicMatVecExpression (shared_ptr<BaseMatrix> am, shared_ptr<BaseVector> av)
|
|
333
|
+
: m(am), v(av) { }
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
/* ************************** Transpose ************************* */
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
The Transpose of a BaseMatrix.
|
|
342
|
+
*/
|
|
343
|
+
class NGS_DLL_HEADER Transpose : public BaseMatrix
|
|
344
|
+
{
|
|
345
|
+
const BaseMatrix & bm;
|
|
346
|
+
shared_ptr<BaseMatrix> spbm;
|
|
347
|
+
public:
|
|
348
|
+
///
|
|
349
|
+
Transpose (const BaseMatrix & abm) : bm(abm) { ; }
|
|
350
|
+
Transpose (shared_ptr<BaseMatrix> aspbm) : bm(*aspbm), spbm(aspbm) { ; }
|
|
351
|
+
///
|
|
352
|
+
virtual bool IsComplex() const override { return bm.IsComplex(); }
|
|
353
|
+
virtual BaseMatrix::OperatorInfo GetOperatorInfo () const override;
|
|
354
|
+
|
|
355
|
+
virtual shared_ptr<BaseSparseMatrix> CreateSparseMatrix() const override;
|
|
356
|
+
|
|
357
|
+
virtual AutoVector CreateRowVector () const override { return bm.CreateColVector(); }
|
|
358
|
+
virtual AutoVector CreateColVector () const override { return bm.CreateRowVector(); }
|
|
359
|
+
|
|
360
|
+
virtual void Mult (const BaseVector & x, BaseVector & y) const override
|
|
361
|
+
{
|
|
362
|
+
bm.MultTrans (x, y);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
virtual void MultTrans (const BaseVector & x, BaseVector & y) const override
|
|
366
|
+
{
|
|
367
|
+
bm.Mult (x, y);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
///
|
|
371
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
372
|
+
{
|
|
373
|
+
bm.MultTransAdd (s, x, y);
|
|
374
|
+
}
|
|
375
|
+
///
|
|
376
|
+
virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
377
|
+
{
|
|
378
|
+
bm.MultTransAdd (s, x, y);
|
|
379
|
+
}
|
|
380
|
+
///
|
|
381
|
+
virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
382
|
+
{
|
|
383
|
+
bm.MultAdd (s, x, y);
|
|
384
|
+
}
|
|
385
|
+
///
|
|
386
|
+
virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
387
|
+
{
|
|
388
|
+
bm.MultAdd (s, x, y);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
virtual int VHeight() const override { return bm.VWidth(); }
|
|
392
|
+
virtual int VWidth() const override { return bm.VHeight(); }
|
|
393
|
+
|
|
394
|
+
auto SPtrMat() const { return spbm; }
|
|
395
|
+
|
|
396
|
+
virtual ostream & Print (ostream & ost) const override
|
|
397
|
+
{
|
|
398
|
+
ost << "Transpose of " << endl;
|
|
399
|
+
bm.Print(ost);
|
|
400
|
+
return ost;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
virtual shared_ptr<BaseMatrix> CreateDeviceMatrix() const override
|
|
404
|
+
{
|
|
405
|
+
return make_shared<Transpose>(bm.CreateDeviceMatrix());
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
/* ************************** ConjTrans ************************* */
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
The conjugate transpose of a BaseMatrix.
|
|
416
|
+
*/
|
|
417
|
+
class NGS_DLL_HEADER ConjTrans : public BaseMatrix
|
|
418
|
+
{
|
|
419
|
+
shared_ptr<BaseMatrix> spbm;
|
|
420
|
+
public:
|
|
421
|
+
ConjTrans (shared_ptr<BaseMatrix> aspbm) : spbm(aspbm) { ; }
|
|
422
|
+
///
|
|
423
|
+
virtual bool IsComplex() const override { return spbm->IsComplex(); }
|
|
424
|
+
|
|
425
|
+
virtual AutoVector CreateRowVector () const override { return spbm->CreateColVector(); }
|
|
426
|
+
virtual AutoVector CreateColVector () const override { return spbm->CreateRowVector(); }
|
|
427
|
+
|
|
428
|
+
virtual void Mult (const BaseVector & x, BaseVector & y) const override
|
|
429
|
+
{
|
|
430
|
+
y = 0.0;
|
|
431
|
+
spbm->MultConjTransAdd (1, x, y);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
virtual void MultTrans (const BaseVector & x, BaseVector & y) const override
|
|
435
|
+
{
|
|
436
|
+
throw Exception("Trans of ConjTrans not available");
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
///
|
|
440
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
441
|
+
{
|
|
442
|
+
spbm->MultConjTransAdd (s, x, y);
|
|
443
|
+
}
|
|
444
|
+
///
|
|
445
|
+
virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
446
|
+
{
|
|
447
|
+
spbm->MultConjTransAdd (s, x, y);
|
|
448
|
+
}
|
|
449
|
+
///
|
|
450
|
+
virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
451
|
+
{
|
|
452
|
+
throw Exception("Trans of ConjTrans not available");
|
|
453
|
+
}
|
|
454
|
+
///
|
|
455
|
+
virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
456
|
+
{
|
|
457
|
+
throw Exception("Trans of ConjTrans not available");
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
virtual int VHeight() const override { return spbm->VWidth(); }
|
|
461
|
+
virtual int VWidth() const override { return spbm->VHeight(); }
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
virtual ostream & Print (ostream & ost) const override
|
|
465
|
+
{
|
|
466
|
+
ost << "ConjTrans of " << endl;
|
|
467
|
+
spbm->Print(ost);
|
|
468
|
+
return ost;
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
/* ************************** Product ************************* */
|
|
476
|
+
|
|
477
|
+
/// action of product of two matrices
|
|
478
|
+
class NGS_DLL_HEADER ProductMatrix : public BaseMatrix
|
|
479
|
+
{
|
|
480
|
+
const BaseMatrix & bma;
|
|
481
|
+
const BaseMatrix & bmb;
|
|
482
|
+
shared_ptr<BaseMatrix> spbma;
|
|
483
|
+
shared_ptr<BaseMatrix> spbmb;
|
|
484
|
+
mutable AutoVector tempvec;
|
|
485
|
+
public:
|
|
486
|
+
///
|
|
487
|
+
ProductMatrix (const BaseMatrix & abma, const BaseMatrix & abmb)
|
|
488
|
+
: bma(abma), bmb(abmb), tempvec(abmb.CreateColVector())
|
|
489
|
+
{ ; }
|
|
490
|
+
ProductMatrix (shared_ptr<BaseMatrix> aspbma, shared_ptr<BaseMatrix> aspbmb)
|
|
491
|
+
: bma(*aspbma), bmb(*aspbmb), spbma(aspbma), spbmb(aspbmb)
|
|
492
|
+
// tempvec(aspbmb->CreateColVector())
|
|
493
|
+
{
|
|
494
|
+
try
|
|
495
|
+
{
|
|
496
|
+
tempvec.AssignPointer(bmb.CreateColVector());
|
|
497
|
+
}
|
|
498
|
+
catch (Exception & e)
|
|
499
|
+
{
|
|
500
|
+
tempvec.AssignPointer(bma.CreateRowVector());
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
///
|
|
504
|
+
virtual bool IsComplex() const override { return bma.IsComplex() || bmb.IsComplex(); }
|
|
505
|
+
virtual BaseMatrix::OperatorInfo GetOperatorInfo () const override;
|
|
506
|
+
|
|
507
|
+
virtual AutoVector CreateRowVector () const override { return bmb.CreateRowVector(); }
|
|
508
|
+
virtual AutoVector CreateColVector () const override { return bma.CreateColVector(); }
|
|
509
|
+
|
|
510
|
+
auto SPtrA() const { return spbma; }
|
|
511
|
+
auto SPtrB() const { return spbmb; }
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
///
|
|
515
|
+
virtual void Mult (const BaseVector & x, BaseVector & y) const override
|
|
516
|
+
{
|
|
517
|
+
static Timer t("ProductMatrix::Mult"); RegionTimer reg(t);
|
|
518
|
+
bmb.Mult (x, tempvec);
|
|
519
|
+
bma.Mult (tempvec, y);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
virtual void MultTrans (const BaseVector & x, BaseVector & y) const override
|
|
523
|
+
{
|
|
524
|
+
static Timer t("ProductMatrix::Mult"); RegionTimer reg(t);
|
|
525
|
+
bma.MultTrans (x, tempvec);
|
|
526
|
+
bmb.MultTrans (tempvec, y);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
530
|
+
{
|
|
531
|
+
static Timer t("ProductMatrix::MultAdd"); RegionTimer reg(t);
|
|
532
|
+
bmb.Mult (x, tempvec);
|
|
533
|
+
bma.MultAdd (s, tempvec, y);
|
|
534
|
+
}
|
|
535
|
+
///
|
|
536
|
+
virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
537
|
+
{
|
|
538
|
+
static Timer t("ProductMatrix::MultAdd complex"); RegionTimer reg(t);
|
|
539
|
+
bmb.Mult (x, tempvec);
|
|
540
|
+
bma.MultAdd (s, tempvec, y);
|
|
541
|
+
}
|
|
542
|
+
///
|
|
543
|
+
virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
544
|
+
{
|
|
545
|
+
static Timer t("ProductMatrix::MultTransAdd"); RegionTimer reg(t);
|
|
546
|
+
bma.MultTrans (x, tempvec);
|
|
547
|
+
bmb.MultTransAdd (s, tempvec, y);
|
|
548
|
+
}
|
|
549
|
+
///
|
|
550
|
+
virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
551
|
+
{
|
|
552
|
+
static Timer t("ProductMatrix::MultTransAdd complex"); RegionTimer reg(t);
|
|
553
|
+
bma.MultTrans (x, tempvec);
|
|
554
|
+
bmb.MultTransAdd (s, tempvec, y);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
virtual void MultAdd (FlatVector<double> alpha, const MultiVector & x, MultiVector & y) const override
|
|
558
|
+
{
|
|
559
|
+
static Timer t("ProductMatrix::MultAdd(mv)"); RegionTimer reg(t);
|
|
560
|
+
auto tempvec = shared_ptr<BaseVector>(bmb.CreateColVector())->CreateMultiVector(x.Size());
|
|
561
|
+
*tempvec = 0;
|
|
562
|
+
Vector ones(x.Size());
|
|
563
|
+
ones = 1.0;
|
|
564
|
+
bmb.MultAdd (ones, x, *tempvec);
|
|
565
|
+
bma.MultAdd (alpha, *tempvec, y);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
virtual int VHeight() const override { return bma.VHeight(); }
|
|
570
|
+
virtual int VWidth() const override { return bmb.VWidth(); }
|
|
571
|
+
|
|
572
|
+
virtual ostream & Print (ostream & ost) const override
|
|
573
|
+
{
|
|
574
|
+
ost << "Product of" << endl;
|
|
575
|
+
bma.Print(ost);
|
|
576
|
+
bmb.Print(ost);
|
|
577
|
+
return ost;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
virtual shared_ptr<BaseSparseMatrix> CreateSparseMatrix() const override;
|
|
581
|
+
|
|
582
|
+
virtual shared_ptr<BaseMatrix> CreateDeviceMatrix() const override
|
|
583
|
+
{
|
|
584
|
+
return make_shared<ProductMatrix>(bma.CreateDeviceMatrix(), bmb.CreateDeviceMatrix());
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
/* ************************** Sum ************************* */
|
|
591
|
+
|
|
592
|
+
/// action of product of two matrices
|
|
593
|
+
class NGS_DLL_HEADER SumMatrix : public BaseMatrix
|
|
594
|
+
{
|
|
595
|
+
const BaseMatrix & bma;
|
|
596
|
+
const BaseMatrix & bmb;
|
|
597
|
+
shared_ptr<BaseMatrix> spbma;
|
|
598
|
+
shared_ptr<BaseMatrix> spbmb;
|
|
599
|
+
double a, b;
|
|
600
|
+
public:
|
|
601
|
+
///
|
|
602
|
+
SumMatrix (const BaseMatrix & abma, const BaseMatrix & abmb,
|
|
603
|
+
double aa = 1, double ab = 1)
|
|
604
|
+
: bma(abma), bmb(abmb), a(aa), b(ab)
|
|
605
|
+
{ ; }
|
|
606
|
+
SumMatrix (shared_ptr<BaseMatrix> aspbma, shared_ptr<BaseMatrix> aspbmb,
|
|
607
|
+
double aa = 1, double ab = 1);
|
|
608
|
+
|
|
609
|
+
///
|
|
610
|
+
virtual bool IsComplex() const override { return bma.IsComplex() || bmb.IsComplex(); }
|
|
611
|
+
|
|
612
|
+
auto SPtrA() const { return spbma; }
|
|
613
|
+
auto SPtrB() const { return spbmb; }
|
|
614
|
+
|
|
615
|
+
virtual BaseMatrix::OperatorInfo GetOperatorInfo () const override;
|
|
616
|
+
|
|
617
|
+
virtual AutoVector CreateRowVector () const override
|
|
618
|
+
{
|
|
619
|
+
try
|
|
620
|
+
{
|
|
621
|
+
return bma.CreateRowVector();
|
|
622
|
+
}
|
|
623
|
+
catch (Exception & e)
|
|
624
|
+
{
|
|
625
|
+
return bmb.CreateRowVector();
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
virtual AutoVector CreateColVector () const override
|
|
629
|
+
{
|
|
630
|
+
try
|
|
631
|
+
{
|
|
632
|
+
return bma.CreateColVector();
|
|
633
|
+
}
|
|
634
|
+
catch (Exception & e)
|
|
635
|
+
{
|
|
636
|
+
return bmb.CreateColVector();
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
virtual void Mult (const BaseVector & x, BaseVector & y) const override
|
|
641
|
+
{
|
|
642
|
+
static Timer t("SumMatrix::Mult"); RegionTimer reg(t);
|
|
643
|
+
if (a == 1)
|
|
644
|
+
bma.Mult (x, y);
|
|
645
|
+
else
|
|
646
|
+
{
|
|
647
|
+
y = 0.0;
|
|
648
|
+
bma.MultAdd (a, x, y);
|
|
649
|
+
}
|
|
650
|
+
bmb.MultAdd (b, x, y);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
virtual void MultTrans (const BaseVector & x, BaseVector & y) const override
|
|
654
|
+
{
|
|
655
|
+
static Timer t("SumMatrix::MultTrans"); RegionTimer reg(t);
|
|
656
|
+
if (a == 1)
|
|
657
|
+
bma.MultTrans (x, y);
|
|
658
|
+
else
|
|
659
|
+
{
|
|
660
|
+
y = 0.0;
|
|
661
|
+
bma.MultTransAdd (a, x, y);
|
|
662
|
+
}
|
|
663
|
+
bmb.MultTransAdd (b, x, y);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
///
|
|
667
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
668
|
+
{
|
|
669
|
+
static Timer t("SumMatrix::MultAdd"); RegionTimer reg(t);
|
|
670
|
+
bma.MultAdd (a*s, x, y);
|
|
671
|
+
bmb.MultAdd (b*s, x, y);
|
|
672
|
+
}
|
|
673
|
+
///
|
|
674
|
+
virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
675
|
+
{
|
|
676
|
+
static Timer t("SumMatrix::MultAdd complex"); RegionTimer reg(t);
|
|
677
|
+
bma.MultAdd (a*s, x, y);
|
|
678
|
+
bmb.MultAdd (b*s, x, y);
|
|
679
|
+
}
|
|
680
|
+
///
|
|
681
|
+
virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
682
|
+
{
|
|
683
|
+
static Timer t("SumMatrix::MultTransAdd"); RegionTimer reg(t);
|
|
684
|
+
bma.MultTransAdd (a*s, x, y);
|
|
685
|
+
bmb.MultTransAdd (b*s, x, y);
|
|
686
|
+
}
|
|
687
|
+
///
|
|
688
|
+
virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
689
|
+
{
|
|
690
|
+
static Timer t("SumMatrix::MultAdd complex"); RegionTimer reg(t);
|
|
691
|
+
bma.MultTransAdd (a*s, x, y);
|
|
692
|
+
bmb.MultTransAdd (b*s, x, y);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/// y += alpha M x
|
|
696
|
+
virtual void MultAdd (FlatVector<double> alpha, const MultiVector & x, MultiVector & y) const override
|
|
697
|
+
{
|
|
698
|
+
static Timer t("SumMatrix::MultAdd(mv)"); RegionTimer reg(t);
|
|
699
|
+
bma.MultAdd (Vector(a*alpha), x, y);
|
|
700
|
+
bmb.MultAdd (Vector(b*alpha), x, y);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
virtual shared_ptr<BaseSparseMatrix> CreateSparseMatrix() const override;
|
|
704
|
+
|
|
705
|
+
virtual int VHeight() const override
|
|
706
|
+
{
|
|
707
|
+
try
|
|
708
|
+
{
|
|
709
|
+
return bma.VHeight();
|
|
710
|
+
}
|
|
711
|
+
catch (Exception &)
|
|
712
|
+
{
|
|
713
|
+
return bmb.VHeight();
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
virtual int VWidth() const override
|
|
718
|
+
{
|
|
719
|
+
try
|
|
720
|
+
{
|
|
721
|
+
return bma.VWidth();
|
|
722
|
+
}
|
|
723
|
+
catch (Exception &)
|
|
724
|
+
{
|
|
725
|
+
return bmb.VWidth();
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
virtual ostream & Print (ostream & ost) const override
|
|
730
|
+
{
|
|
731
|
+
ost << "Sum of" << endl;
|
|
732
|
+
ost << "Scale a = " << a << endl;
|
|
733
|
+
bma.Print(ost);
|
|
734
|
+
ost << "Scale b = " << b << endl;
|
|
735
|
+
bmb.Print(ost);
|
|
736
|
+
return ost;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
virtual shared_ptr<BaseMatrix> CreateDeviceMatrix() const override
|
|
740
|
+
{
|
|
741
|
+
return make_shared<SumMatrix>(bma.CreateDeviceMatrix(), bmb.CreateDeviceMatrix(), a, b);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
/* ************************** Scale ************************* */
|
|
748
|
+
|
|
749
|
+
template <typename TSCAL>
|
|
750
|
+
class VScaleMatrix : public BaseMatrix
|
|
751
|
+
{
|
|
752
|
+
const BaseMatrix & bm;
|
|
753
|
+
shared_ptr<BaseMatrix> spbm;
|
|
754
|
+
TSCAL scale;
|
|
755
|
+
public:
|
|
756
|
+
///
|
|
757
|
+
VScaleMatrix (const BaseMatrix & abm, TSCAL ascale) : bm(abm), scale(ascale) { ; }
|
|
758
|
+
VScaleMatrix (shared_ptr<BaseMatrix> aspbm, TSCAL ascale)
|
|
759
|
+
: bm(*aspbm), spbm(aspbm), scale(ascale) { ; }
|
|
760
|
+
TSCAL GetScalingFactor() const { return scale; }
|
|
761
|
+
virtual bool IsComplex() const override
|
|
762
|
+
{ return bm.IsComplex() || typeid(TSCAL)==typeid(Complex); }
|
|
763
|
+
///
|
|
764
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
765
|
+
{
|
|
766
|
+
static Timer t("ScaleMatrix::MultAdd"); RegionTimer reg(t);
|
|
767
|
+
bm.MultAdd (s*scale, x, y);
|
|
768
|
+
}
|
|
769
|
+
///
|
|
770
|
+
virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
771
|
+
{
|
|
772
|
+
static Timer t("ScaleMatrix::MultAdd complex"); RegionTimer reg(t);
|
|
773
|
+
bm.MultAdd (s*scale, x, y);
|
|
774
|
+
}
|
|
775
|
+
///
|
|
776
|
+
virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
777
|
+
{
|
|
778
|
+
static Timer t("ScaleMatrix::MultTransAdd"); RegionTimer reg(t);
|
|
779
|
+
bm.MultTransAdd (s*scale, x, y);
|
|
780
|
+
}
|
|
781
|
+
///
|
|
782
|
+
virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
783
|
+
{
|
|
784
|
+
static Timer t("ScaleMatrix::MultTransAdd complex"); RegionTimer reg(t);
|
|
785
|
+
bm.MultTransAdd (s*scale, x, y);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
virtual void MultAdd (FlatVector<double> alpha, const MultiVector & x, MultiVector & y) const override
|
|
789
|
+
{
|
|
790
|
+
static Timer t("ScaleMatrix::MultAdd(mv)"); RegionTimer reg(t);
|
|
791
|
+
if constexpr (is_same<TSCAL, double>())
|
|
792
|
+
{
|
|
793
|
+
bm.MultAdd (Vector(scale*alpha), x, y);
|
|
794
|
+
}
|
|
795
|
+
else
|
|
796
|
+
BaseMatrix::MultAdd(alpha, x, y);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
virtual int VHeight() const override { return bm.VHeight(); }
|
|
803
|
+
virtual int VWidth() const override { return bm.VWidth(); }
|
|
804
|
+
virtual AutoVector CreateRowVector () const override { return bm.CreateRowVector(); }
|
|
805
|
+
virtual AutoVector CreateColVector () const override { return bm.CreateColVector(); }
|
|
806
|
+
virtual ostream & Print (ostream & ost) const override
|
|
807
|
+
{
|
|
808
|
+
ost << "Scale with " << scale << ":" << endl;
|
|
809
|
+
bm.Print(ost);
|
|
810
|
+
return ost;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
auto SPtrMat() const { return spbm; }
|
|
814
|
+
|
|
815
|
+
virtual BaseMatrix::OperatorInfo GetOperatorInfo () const override
|
|
816
|
+
{
|
|
817
|
+
OperatorInfo info;
|
|
818
|
+
info.name = "ScaleMatrix, scale = "+ToString(scale);
|
|
819
|
+
info.height = Height();
|
|
820
|
+
info.width = Width();
|
|
821
|
+
info.childs += &bm;
|
|
822
|
+
return info;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
virtual shared_ptr<BaseSparseMatrix> CreateSparseMatrix() const override;
|
|
826
|
+
|
|
827
|
+
virtual shared_ptr<BaseMatrix> CreateDeviceMatrix() const override
|
|
828
|
+
{
|
|
829
|
+
return make_shared<VScaleMatrix<TSCAL>>(bm.CreateDeviceMatrix(), scale);
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
inline VScaleMatrix<double> operator* (double d, const BaseMatrix & m)
|
|
834
|
+
{
|
|
835
|
+
return VScaleMatrix<double> (m, d);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
/* ************************** Identity ************************* */
|
|
840
|
+
|
|
841
|
+
class NGS_DLL_HEADER IdentityMatrix : public BaseMatrix
|
|
842
|
+
{
|
|
843
|
+
bool has_format;
|
|
844
|
+
size_t size;
|
|
845
|
+
public:
|
|
846
|
+
///
|
|
847
|
+
IdentityMatrix ()
|
|
848
|
+
: has_format(false) { ; }
|
|
849
|
+
IdentityMatrix (size_t asize, bool ais_complex)
|
|
850
|
+
: has_format(true), size(asize) { is_complex=ais_complex; }
|
|
851
|
+
|
|
852
|
+
virtual BaseMatrix::OperatorInfo GetOperatorInfo () const override;
|
|
853
|
+
|
|
854
|
+
///
|
|
855
|
+
virtual void Mult (const BaseVector & x, BaseVector & y) const override
|
|
856
|
+
{
|
|
857
|
+
static Timer t("IdentityMatrix::Mult"); RegionTimer reg(t);
|
|
858
|
+
y = x;
|
|
859
|
+
}
|
|
860
|
+
virtual void MultTrans (const BaseVector & x, BaseVector & y) const override
|
|
861
|
+
{
|
|
862
|
+
static Timer t("IdentityMatrix::MultTrans"); RegionTimer reg(t);
|
|
863
|
+
y = x;
|
|
864
|
+
}
|
|
865
|
+
///
|
|
866
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
867
|
+
{
|
|
868
|
+
static Timer t("IdentityMatrix::MultAdd"); RegionTimer reg(t);
|
|
869
|
+
y += s*x;
|
|
870
|
+
}
|
|
871
|
+
///
|
|
872
|
+
virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
873
|
+
{
|
|
874
|
+
static Timer t("IdentityMatrix::MultAdd Complex"); RegionTimer reg(t);
|
|
875
|
+
y += s*x;
|
|
876
|
+
}
|
|
877
|
+
///
|
|
878
|
+
virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
879
|
+
{
|
|
880
|
+
static Timer t("IdentityMatrix::MultTransAdd"); RegionTimer reg(t);
|
|
881
|
+
y += s*x;
|
|
882
|
+
}
|
|
883
|
+
///
|
|
884
|
+
virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override
|
|
885
|
+
{
|
|
886
|
+
static Timer t("IdentityMatrix::MultTransAdd Complex"); RegionTimer reg(t);
|
|
887
|
+
y += s*x;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
virtual int VHeight() const override
|
|
891
|
+
{
|
|
892
|
+
if (has_format) return size;
|
|
893
|
+
throw Exception("Identity: no Height");
|
|
894
|
+
}
|
|
895
|
+
virtual int VWidth() const override
|
|
896
|
+
{
|
|
897
|
+
if (has_format) return size;
|
|
898
|
+
throw Exception("Identity: no Width");
|
|
899
|
+
}
|
|
900
|
+
virtual AutoVector CreateRowVector () const override
|
|
901
|
+
{
|
|
902
|
+
if (has_format)
|
|
903
|
+
return CreateBaseVector(size, is_complex, 1);
|
|
904
|
+
throw Exception("Identity: no RowVector");
|
|
905
|
+
}
|
|
906
|
+
virtual AutoVector CreateColVector () const override
|
|
907
|
+
{
|
|
908
|
+
if (has_format)
|
|
909
|
+
return CreateBaseVector(size, is_complex, 1);
|
|
910
|
+
throw Exception("Identity: no ColVector");
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
virtual ostream & Print (ostream & ost) const override
|
|
914
|
+
{
|
|
915
|
+
ost << "Identity" << endl;
|
|
916
|
+
return ost;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
/* *********************** operators ********************** */
|
|
923
|
+
|
|
924
|
+
// default is ProductMatrix, but optimizations for
|
|
925
|
+
// ParallelMatrices
|
|
926
|
+
// Embedding Matrices
|
|
927
|
+
// ....
|
|
928
|
+
shared_ptr<BaseMatrix> ComposeOperators (shared_ptr<BaseMatrix> a,
|
|
929
|
+
shared_ptr<BaseMatrix> b);
|
|
930
|
+
shared_ptr<BaseMatrix> AddOperators (shared_ptr<BaseMatrix> a,
|
|
931
|
+
shared_ptr<BaseMatrix> b,
|
|
932
|
+
double faca, double facb);
|
|
933
|
+
|
|
934
|
+
inline shared_ptr<BaseMatrix> operator* (shared_ptr<BaseMatrix> a,
|
|
935
|
+
shared_ptr<BaseMatrix> b)
|
|
936
|
+
{
|
|
937
|
+
return ComposeOperators(a,b);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
inline shared_ptr<BaseMatrix> operator+ (shared_ptr<BaseMatrix> a,
|
|
941
|
+
shared_ptr<BaseMatrix> b)
|
|
942
|
+
{
|
|
943
|
+
return AddOperators(a,b,1,1);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
shared_ptr<BaseMatrix> TransposeOperator (shared_ptr<BaseMatrix> mat);
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
inline ostream & operator<< (ostream & ost, const BaseMatrix & m)
|
|
951
|
+
{
|
|
952
|
+
return m.Print(ost);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
#endif
|