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,1038 @@
|
|
|
1
|
+
#ifndef FILE_NGS_SPARSEMATRIX
|
|
2
|
+
#define FILE_NGS_SPARSEMATRIX
|
|
3
|
+
|
|
4
|
+
/**************************************************************************/
|
|
5
|
+
/* File: sparsematrix.hpp */
|
|
6
|
+
/* Author: Joachim Schoeberl */
|
|
7
|
+
/* Date: 01. Oct. 94, 15 Jan. 02 */
|
|
8
|
+
/**************************************************************************/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
#include "vvector.hpp"
|
|
12
|
+
#include "basematrix.hpp"
|
|
13
|
+
|
|
14
|
+
namespace ngla
|
|
15
|
+
{
|
|
16
|
+
|
|
17
|
+
template<class TM>
|
|
18
|
+
class SparseMatrixTM ;
|
|
19
|
+
|
|
20
|
+
template<class TM,
|
|
21
|
+
class TV_ROW = typename mat_traits<TM>::TV_ROW,
|
|
22
|
+
class TV_COL = typename mat_traits<TM>::TV_COL>
|
|
23
|
+
class SparseMatrix;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
template<class TM,
|
|
27
|
+
class TV = typename mat_traits<TM>::TV_ROW>
|
|
28
|
+
class SparseMatrixSymmetric;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class BaseJacobiPrecond;
|
|
33
|
+
|
|
34
|
+
template<class TM,
|
|
35
|
+
class TV_ROW = typename mat_traits<TM>::TV_ROW,
|
|
36
|
+
class TV_COL = typename mat_traits<TM>::TV_COL>
|
|
37
|
+
class JacobiPrecond;
|
|
38
|
+
|
|
39
|
+
template<class TM,
|
|
40
|
+
class TV = typename mat_traits<TM>::TV_ROW>
|
|
41
|
+
class JacobiPrecondSymmetric;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class BaseBlockJacobiPrecond;
|
|
45
|
+
|
|
46
|
+
template<class TM,
|
|
47
|
+
class TV_ROW = typename mat_traits<TM>::TV_ROW,
|
|
48
|
+
class TV_COL = typename mat_traits<TM>::TV_COL>
|
|
49
|
+
class BlockJacobiPrecond;
|
|
50
|
+
|
|
51
|
+
template<class TM,
|
|
52
|
+
class TV = typename mat_traits<TM>::TV_ROW>
|
|
53
|
+
class BlockJacobiPrecondSymmetric;
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
#ifdef USE_PARDISO
|
|
61
|
+
const INVERSETYPE default_inversetype = PARDISO;
|
|
62
|
+
#else
|
|
63
|
+
#ifdef USE_MUMPS
|
|
64
|
+
const INVERSETYPE default_inversetype = MUMPS;
|
|
65
|
+
#else
|
|
66
|
+
#ifdef USE_UMFPACK
|
|
67
|
+
const INVERSETYPE default_inversetype = UMFPACK;
|
|
68
|
+
#else
|
|
69
|
+
const INVERSETYPE default_inversetype = SPARSECHOLESKY;
|
|
70
|
+
#endif
|
|
71
|
+
#endif
|
|
72
|
+
#endif
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
The graph of a sparse matrix.
|
|
77
|
+
*/
|
|
78
|
+
class NGS_DLL_HEADER MatrixGraph : public BaseMatrix
|
|
79
|
+
{
|
|
80
|
+
public:
|
|
81
|
+
typedef int ColIdx;
|
|
82
|
+
protected:
|
|
83
|
+
/// number of rows
|
|
84
|
+
size_t size;
|
|
85
|
+
/// with of matrix
|
|
86
|
+
size_t width;
|
|
87
|
+
/// non-zero elements
|
|
88
|
+
size_t nze;
|
|
89
|
+
|
|
90
|
+
/// column numbers
|
|
91
|
+
// Array<int, size_t> colnr;
|
|
92
|
+
NumaDistributedArray<ColIdx> colnr;
|
|
93
|
+
|
|
94
|
+
/// pointer to first in row
|
|
95
|
+
Array<size_t> firsti;
|
|
96
|
+
|
|
97
|
+
/// row has same non-zero elements as previous row
|
|
98
|
+
Array<size_t> same_nze;
|
|
99
|
+
|
|
100
|
+
/// balancing for multi-threading
|
|
101
|
+
Partitioning balance;
|
|
102
|
+
|
|
103
|
+
/// owner of arrays ?
|
|
104
|
+
bool owner;
|
|
105
|
+
|
|
106
|
+
public:
|
|
107
|
+
/// arbitrary number of els/row
|
|
108
|
+
MatrixGraph (FlatArray<int> elsperrow, size_t awidth);
|
|
109
|
+
/// matrix of height as, uniform number of els/row
|
|
110
|
+
MatrixGraph (size_t as, int max_elsperrow);
|
|
111
|
+
/// shadow matrix graph
|
|
112
|
+
MatrixGraph (const MatrixGraph & graph); // , bool stealgraph = false);
|
|
113
|
+
/// move-constuctor
|
|
114
|
+
MatrixGraph (MatrixGraph && graph);
|
|
115
|
+
///
|
|
116
|
+
MatrixGraph (size_t size, size_t width,
|
|
117
|
+
FlatTable<int> rowelements, FlatTable<int> colelements, bool symmetric);
|
|
118
|
+
///
|
|
119
|
+
// MatrixGraph (const Table<int> & dof2dof, bool symmetric);
|
|
120
|
+
virtual ~MatrixGraph ();
|
|
121
|
+
|
|
122
|
+
/// eliminate unused columne indices (was never implemented)
|
|
123
|
+
void Compress();
|
|
124
|
+
|
|
125
|
+
/// returns position of Element (i, j), exception for unused
|
|
126
|
+
size_t GetPosition (size_t i, size_t j) const;
|
|
127
|
+
|
|
128
|
+
/// returns position of Element (i, j), -1 for unused
|
|
129
|
+
size_t GetPositionTest (size_t i, size_t j) const;
|
|
130
|
+
|
|
131
|
+
/// find positions of n sorted elements, overwrite pos, exception for unused
|
|
132
|
+
void GetPositionsSorted (size_t row, size_t n, int * pos) const;
|
|
133
|
+
|
|
134
|
+
/// returns position of new element
|
|
135
|
+
size_t CreatePosition (size_t i, size_t j);
|
|
136
|
+
|
|
137
|
+
size_t Size() const { return size; }
|
|
138
|
+
|
|
139
|
+
size_t NZE() const { return nze; }
|
|
140
|
+
|
|
141
|
+
// full col-index array
|
|
142
|
+
FlatArray<ColIdx> GetColIndices() const { return colnr; }
|
|
143
|
+
|
|
144
|
+
// col-indices of the i-th row
|
|
145
|
+
FlatArray<ColIdx> GetRowIndices(size_t i) const
|
|
146
|
+
{ return FlatArray<ColIdx> (firsti[i+1]-firsti[i], colnr+firsti[i]); }
|
|
147
|
+
|
|
148
|
+
size_t First (int i) const { return firsti[i]; }
|
|
149
|
+
FlatArray<size_t> GetFirstArray () const { return firsti; }
|
|
150
|
+
|
|
151
|
+
void FindSameNZE();
|
|
152
|
+
void CalcBalancing ();
|
|
153
|
+
const Partitioning & GetBalancing() const { return balance; }
|
|
154
|
+
|
|
155
|
+
void EmbedHeight (size_t starti, size_t newheight);
|
|
156
|
+
void EmbedWidth (size_t starti, size_t newwidth);
|
|
157
|
+
|
|
158
|
+
ostream & Print (ostream & ost) const;
|
|
159
|
+
|
|
160
|
+
virtual Array<MemoryUsage> GetMemoryUsage () const;
|
|
161
|
+
|
|
162
|
+
const MemoryTracer & GetMemoryTracer() const
|
|
163
|
+
{
|
|
164
|
+
return mem_tracer;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
virtual AutoVector CreateRowVector () const
|
|
168
|
+
{ throw Exception("MatrixGraph::CreateRowVector called"); }
|
|
169
|
+
|
|
170
|
+
virtual AutoVector CreateColVector () const
|
|
171
|
+
{ throw Exception("MatrixGraph::CreateRowVector called"); }
|
|
172
|
+
|
|
173
|
+
private:
|
|
174
|
+
|
|
175
|
+
MemoryTracer mem_tracer = {"MatrixGraph",
|
|
176
|
+
colnr, "colnr",
|
|
177
|
+
firsti, "firsti",
|
|
178
|
+
same_nze, "same_nze"
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
/// base class for all sparse matrices
|
|
190
|
+
class NGS_DLL_HEADER BaseSparseMatrix : public MatrixGraph
|
|
191
|
+
{
|
|
192
|
+
protected:
|
|
193
|
+
/// sparse direct solver
|
|
194
|
+
mutable INVERSETYPE inversetype = default_inversetype;
|
|
195
|
+
Flags inverseflags;
|
|
196
|
+
bool spd = false;
|
|
197
|
+
|
|
198
|
+
public:
|
|
199
|
+
using MatrixGraph::MatrixGraph;
|
|
200
|
+
using MatrixGraph::ColIdx;
|
|
201
|
+
/*
|
|
202
|
+
BaseSparseMatrix (int as, int max_elsperrow)
|
|
203
|
+
: MatrixGraph (as, max_elsperrow)
|
|
204
|
+
{ ; }
|
|
205
|
+
|
|
206
|
+
BaseSparseMatrix (const Array<int> & elsperrow, int awidth)
|
|
207
|
+
: MatrixGraph (elsperrow, awidth)
|
|
208
|
+
{ ; }
|
|
209
|
+
|
|
210
|
+
BaseSparseMatrix (int size, int width, const Table<int> & rowelements,
|
|
211
|
+
const Table<int> & colelements, bool symmetric)
|
|
212
|
+
: MatrixGraph (size, width, rowelements, colelements, symmetric)
|
|
213
|
+
{ ; }
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
BaseSparseMatrix (const MatrixGraph & agraph)
|
|
217
|
+
: MatrixGraph (agraph)
|
|
218
|
+
{ ; }
|
|
219
|
+
|
|
220
|
+
BaseSparseMatrix (const BaseSparseMatrix & amat)
|
|
221
|
+
: MatrixGraph (amat)
|
|
222
|
+
{ ; }
|
|
223
|
+
|
|
224
|
+
BaseSparseMatrix (BaseSparseMatrix && amat)
|
|
225
|
+
: MatrixGraph (std::move(amat))
|
|
226
|
+
{ ; }
|
|
227
|
+
|
|
228
|
+
virtual ~BaseSparseMatrix ();
|
|
229
|
+
|
|
230
|
+
BaseSparseMatrix & operator= (double s)
|
|
231
|
+
{
|
|
232
|
+
AsVector() = s;
|
|
233
|
+
return *this;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
BaseSparseMatrix & Add (double s, const BaseSparseMatrix & m2)
|
|
237
|
+
{
|
|
238
|
+
AsVector() += s * m2.AsVector();
|
|
239
|
+
return *this;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
virtual shared_ptr<BaseSparseMatrix> CreateSparseMatrix() const override
|
|
243
|
+
{
|
|
244
|
+
return dynamic_pointer_cast<BaseSparseMatrix>(const_cast<BaseSparseMatrix*>(this)->shared_from_this());
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
virtual shared_ptr<BaseJacobiPrecond> CreateJacobiPrecond (shared_ptr<BitArray> inner = nullptr) const
|
|
248
|
+
{
|
|
249
|
+
throw Exception ("BaseSparseMatrix::CreateJacobiPrecond");
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
virtual shared_ptr<BaseBlockJacobiPrecond>
|
|
253
|
+
CreateBlockJacobiPrecond (shared_ptr<Table<int>> blocks,
|
|
254
|
+
const BaseVector * constraint = 0,
|
|
255
|
+
bool parallel = 1,
|
|
256
|
+
shared_ptr<BitArray> freedofs = NULL) const
|
|
257
|
+
{
|
|
258
|
+
throw Exception ("BaseSparseMatrix::CreateBlockJacobiPrecond");
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
virtual shared_ptr<BaseSparseMatrix> CreateTranspose() const
|
|
262
|
+
{
|
|
263
|
+
throw Exception ("BaseSparseMatrix::CreateTranspose");
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
virtual shared_ptr<BaseMatrix>
|
|
267
|
+
InverseMatrix (shared_ptr<BitArray> subset = nullptr) const override
|
|
268
|
+
{
|
|
269
|
+
throw Exception ("BaseSparseMatrix::CreateInverse called");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
virtual shared_ptr<BaseMatrix>
|
|
273
|
+
InverseMatrix (shared_ptr<const Array<int>> clusters) const override
|
|
274
|
+
{
|
|
275
|
+
throw Exception ("BaseSparseMatrix::CreateInverse called");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
virtual shared_ptr<BaseSparseMatrix> Restrict (const SparseMatrixTM<double> & prol,
|
|
279
|
+
shared_ptr<BaseSparseMatrix> cmat = nullptr ) const
|
|
280
|
+
{
|
|
281
|
+
throw Exception ("BaseSparseMatrix::Restrict");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
virtual shared_ptr<BaseSparseMatrix> Reorder (const Array<size_t> & reorder) const
|
|
285
|
+
{
|
|
286
|
+
throw Exception ("BaseSparseMatrix::Reorder");
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
virtual INVERSETYPE SetInverseType ( INVERSETYPE ainversetype ) const override
|
|
290
|
+
{
|
|
291
|
+
|
|
292
|
+
INVERSETYPE old_invtype = inversetype;
|
|
293
|
+
inversetype = ainversetype;
|
|
294
|
+
return old_invtype;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
virtual INVERSETYPE SetInverseType ( string ainversetype ) const override;
|
|
298
|
+
|
|
299
|
+
virtual INVERSETYPE GetInverseType () const override
|
|
300
|
+
{ return inversetype; }
|
|
301
|
+
virtual void SetInverseFlags (const Flags & flags) override
|
|
302
|
+
{ inverseflags = flags; }
|
|
303
|
+
virtual const Flags & GetInverseFlags () const { return inverseflags; }
|
|
304
|
+
|
|
305
|
+
void SetSPD (bool aspd = true) { spd = aspd; }
|
|
306
|
+
bool IsSPD () const { return spd; }
|
|
307
|
+
virtual size_t NZE () const override { return nze; }
|
|
308
|
+
virtual tuple<int,int> EntrySizes() const = 0;
|
|
309
|
+
|
|
310
|
+
virtual shared_ptr<BaseMatrix> DeleteZeroElements(double tol) const override
|
|
311
|
+
{
|
|
312
|
+
throw Exception ("DeleteZeroElements not overloaded");
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
template <typename TSCAL>
|
|
318
|
+
class NGS_DLL_HEADER S_BaseSparseMatrix : public BaseSparseMatrix
|
|
319
|
+
{
|
|
320
|
+
protected:
|
|
321
|
+
int entry_height, entry_width;
|
|
322
|
+
// in general entry_size=entry_height*entry_width, but matrix entry type could
|
|
323
|
+
// also be a diagonal matrix
|
|
324
|
+
int entry_size;
|
|
325
|
+
VFlatVector<TSCAL> asvec;
|
|
326
|
+
using MatrixGraph::ColIdx;
|
|
327
|
+
public:
|
|
328
|
+
using BaseSparseMatrix::BaseSparseMatrix;
|
|
329
|
+
/*
|
|
330
|
+
void SetEntrySize (int eh, int ew, int es)
|
|
331
|
+
{
|
|
332
|
+
entry_height = eh;
|
|
333
|
+
entry_width = ew;
|
|
334
|
+
entry_size = es;
|
|
335
|
+
}
|
|
336
|
+
*/
|
|
337
|
+
|
|
338
|
+
virtual BaseVector & AsVector() override
|
|
339
|
+
{
|
|
340
|
+
return asvec;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
virtual const BaseVector & AsVector() const override
|
|
344
|
+
{
|
|
345
|
+
return asvec;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// tuple<int,int> EntryShape() const { return { entry_height, entry_width }; }
|
|
349
|
+
|
|
350
|
+
FlatVector<TSCAL> GetRowValue (int row, int j)
|
|
351
|
+
{
|
|
352
|
+
TSCAL * p = asvec(entry_size * (firsti[row] + j)).Data(0);
|
|
353
|
+
return FlatVector<TSCAL> (entry_size, p);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
FlatMatrix<TSCAL> GetRowValueMat (int row, int j) const
|
|
357
|
+
{
|
|
358
|
+
// TSCAL * p = asvec(entry_size * (firsti[row] + j)).Data(0);
|
|
359
|
+
TSCAL * p = &asvec(entry_size * (firsti[row] + j));
|
|
360
|
+
return FlatMatrix<TSCAL> (entry_height, entry_width, p);
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
/// A general, sparse matrix
|
|
366
|
+
template<class TM>
|
|
367
|
+
class NGS_DLL_HEADER SparseMatrixTM : public S_BaseSparseMatrix<typename mat_traits<TM>::TSCAL>
|
|
368
|
+
{
|
|
369
|
+
protected:
|
|
370
|
+
// Array<TM, size_t> data;
|
|
371
|
+
NumaDistributedArray<TM> data;
|
|
372
|
+
TM nul;
|
|
373
|
+
bool hermitian = false;
|
|
374
|
+
|
|
375
|
+
typedef S_BaseSparseMatrix<typename mat_traits<TM>::TSCAL> BASE;
|
|
376
|
+
using BASE::firsti;
|
|
377
|
+
using BASE::colnr;
|
|
378
|
+
using BASE::owner;
|
|
379
|
+
using BASE::size;
|
|
380
|
+
using BASE::width;
|
|
381
|
+
using BASE::nze;
|
|
382
|
+
using BASE::balance;
|
|
383
|
+
using BASE::asvec;
|
|
384
|
+
public:
|
|
385
|
+
using BASE::CreatePosition;
|
|
386
|
+
using BASE::GetPositionTest;
|
|
387
|
+
using BASE::FindSameNZE;
|
|
388
|
+
// using BASE::SetEntrySize;
|
|
389
|
+
using BASE::AsVector;
|
|
390
|
+
using typename BASE::ColIdx;
|
|
391
|
+
|
|
392
|
+
void SetEntrySize()
|
|
393
|
+
{
|
|
394
|
+
// BASE::SetEntrySize (ngbla::Height<TM>(), ngbla::Width<TM>(), sizeof(TM)/sizeof(TSCAL));
|
|
395
|
+
BASE::entry_height = ngbla::Height<TM>();
|
|
396
|
+
BASE::entry_width = ngbla::Width<TM>();
|
|
397
|
+
BASE::entry_size = sizeof(TM)/sizeof(TSCAL);
|
|
398
|
+
BASE::is_complex = ngbla::IsComplex<TM>();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
public:
|
|
402
|
+
typedef TM TENTRY;
|
|
403
|
+
typedef typename mat_traits<TM>::TSCAL TSCAL;
|
|
404
|
+
|
|
405
|
+
SparseMatrixTM (int as, int max_elsperrow)
|
|
406
|
+
: BASE (as, max_elsperrow),
|
|
407
|
+
data(nze), nul(TSCAL(0))
|
|
408
|
+
{
|
|
409
|
+
// SetEntrySize (mat_traits<TM>::HEIGHT, mat_traits<TM>::WIDTH, sizeof(TM)/sizeof(TSCAL));
|
|
410
|
+
// SetEntrySize (Height<TM>(), Width<TM>(), sizeof(TM)/sizeof(TSCAL));
|
|
411
|
+
SetEntrySize ();
|
|
412
|
+
asvec.AssignMemory (nze*sizeof(TM)/sizeof(TSCAL), (void*)data.Addr(0));
|
|
413
|
+
GetMemoryTracer().Track(*static_cast<MatrixGraph*>(this), "MatrixGraph",
|
|
414
|
+
data, "data");
|
|
415
|
+
GetMemoryTracer().SetName("SparseMatrix");
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
SparseMatrixTM (const Array<int> & elsperrow, int awidth)
|
|
419
|
+
: BASE (elsperrow, awidth),
|
|
420
|
+
data(nze), nul(TSCAL(0))
|
|
421
|
+
{
|
|
422
|
+
// SetEntrySize (mat_traits<TM>::HEIGHT, mat_traits<TM>::WIDTH, sizeof(TM)/sizeof(TSCAL));
|
|
423
|
+
SetEntrySize ();
|
|
424
|
+
asvec.AssignMemory (nze*sizeof(TM)/sizeof(TSCAL), (void*)data.Addr(0));
|
|
425
|
+
GetMemoryTracer().Track(*static_cast<MatrixGraph*>(this), "MatrixGraph",
|
|
426
|
+
data, "data");
|
|
427
|
+
GetMemoryTracer().SetName("SparseMatrix");
|
|
428
|
+
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
SparseMatrixTM (int size, int width, const Table<int> & rowelements,
|
|
432
|
+
const Table<int> & colelements, bool symmetric)
|
|
433
|
+
: BASE (size, width, rowelements, colelements, symmetric),
|
|
434
|
+
data(nze), nul(TSCAL(0))
|
|
435
|
+
{
|
|
436
|
+
// SetEntrySize (mat_traits<TM>::HEIGHT, mat_traits<TM>::WIDTH, sizeof(TM)/sizeof(TSCAL));
|
|
437
|
+
SetEntrySize ();
|
|
438
|
+
asvec.AssignMemory (nze*sizeof(TM)/sizeof(TSCAL), (void*)data.Addr(0));
|
|
439
|
+
GetMemoryTracer().Track(*static_cast<MatrixGraph*>(this), "MatrixGraph",
|
|
440
|
+
data, "data");
|
|
441
|
+
GetMemoryTracer().SetName("SparseMatrix");
|
|
442
|
+
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
SparseMatrixTM (const MatrixGraph & agraph)
|
|
446
|
+
: BASE (agraph),
|
|
447
|
+
data(nze), nul(TSCAL(0))
|
|
448
|
+
{
|
|
449
|
+
// SetEntrySize (mat_traits<TM>::HEIGHT, mat_traits<TM>::WIDTH, sizeof(TM)/sizeof(TSCAL));
|
|
450
|
+
SetEntrySize ();
|
|
451
|
+
asvec.AssignMemory (nze*sizeof(TM)/sizeof(TSCAL), (void*)data.Addr(0));
|
|
452
|
+
FindSameNZE();
|
|
453
|
+
GetMemoryTracer().Track(*static_cast<MatrixGraph*>(this), "MatrixGraph",
|
|
454
|
+
data, "data");
|
|
455
|
+
GetMemoryTracer().SetName("SparseMatrix");
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
SparseMatrixTM (MatrixGraph && agraph)
|
|
459
|
+
: BASE (std::move(agraph)),
|
|
460
|
+
data(nze), nul(TSCAL(0))
|
|
461
|
+
{
|
|
462
|
+
// SetEntrySize (mat_traits<TM>::HEIGHT, mat_traits<TM>::WIDTH, sizeof(TM)/sizeof(TSCAL));
|
|
463
|
+
SetEntrySize ();
|
|
464
|
+
asvec.AssignMemory (nze*sizeof(TM)/sizeof(TSCAL), (void*)data.Addr(0));
|
|
465
|
+
FindSameNZE();
|
|
466
|
+
GetMemoryTracer().Track(*static_cast<MatrixGraph*>(this), "MatrixGraph",
|
|
467
|
+
data, "data");
|
|
468
|
+
GetMemoryTracer().SetName("SparseMatrix");
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
SparseMatrixTM (const SparseMatrixTM & amat)
|
|
472
|
+
: BASE (amat),
|
|
473
|
+
data(nze), nul(TSCAL(0))
|
|
474
|
+
{
|
|
475
|
+
// SetEntrySize (mat_traits<TM>::HEIGHT, mat_traits<TM>::WIDTH, sizeof(TM)/sizeof(TSCAL));
|
|
476
|
+
SetEntrySize ();
|
|
477
|
+
asvec.AssignMemory (nze*sizeof(TM)/sizeof(TSCAL), (void*)data.Addr(0));
|
|
478
|
+
AsVector() = amat.AsVector();
|
|
479
|
+
GetMemoryTracer().Track(*static_cast<MatrixGraph*>(this), "MatrixGraph",
|
|
480
|
+
data, "data");
|
|
481
|
+
GetMemoryTracer().SetName("SparseMatrix");
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
SparseMatrixTM (SparseMatrixTM && amat)
|
|
485
|
+
: BASE (std::move(amat)), nul(TSCAL(0))
|
|
486
|
+
{
|
|
487
|
+
// SetEntrySize (mat_traits<TM>::HEIGHT, mat_traits<TM>::WIDTH, sizeof(TM)/sizeof(TSCAL));
|
|
488
|
+
SetEntrySize ();
|
|
489
|
+
GetMemoryTracer().Track(*static_cast<MatrixGraph*>(this), "MatrixGraph",
|
|
490
|
+
data, "data");
|
|
491
|
+
GetMemoryTracer().SetName("SparseMatrix");
|
|
492
|
+
data.Swap(amat.data);
|
|
493
|
+
asvec.AssignMemory (nze*sizeof(TM)/sizeof(TSCAL), (void*)data.Addr(0));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
static shared_ptr<SparseMatrixTM> CreateFromCOO (FlatArray<int> i, FlatArray<int> j,
|
|
497
|
+
FlatArray<TM> val, size_t h, size_t w);
|
|
498
|
+
|
|
499
|
+
virtual ~SparseMatrixTM ();
|
|
500
|
+
|
|
501
|
+
size_t Height() const { return size; }
|
|
502
|
+
size_t Width() const { return width; }
|
|
503
|
+
virtual int VHeight() const override { return size; }
|
|
504
|
+
virtual int VWidth() const override { return width; }
|
|
505
|
+
virtual tuple<size_t, size_t> Shape() const override { return { size, width }; }
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
bool IsHermitian() const { return hermitian; }
|
|
509
|
+
void SetHermitian(bool herm) { hermitian = herm; }
|
|
510
|
+
|
|
511
|
+
TM & operator[] (size_t i) { return data[i]; }
|
|
512
|
+
const TM & operator[] (size_t i) const { return data[i]; }
|
|
513
|
+
|
|
514
|
+
TM & operator() (size_t row, size_t col)
|
|
515
|
+
{
|
|
516
|
+
return data[CreatePosition(row, col)];
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const TM & operator() (size_t row, size_t col) const
|
|
520
|
+
{
|
|
521
|
+
size_t pos = GetPositionTest (row,col);
|
|
522
|
+
if (pos != numeric_limits<size_t>::max())
|
|
523
|
+
return data[pos];
|
|
524
|
+
else
|
|
525
|
+
return nul;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
void PrefetchRow (size_t rownr) const;
|
|
529
|
+
|
|
530
|
+
// full value array
|
|
531
|
+
FlatVector<TM> GetValues() const { return FlatVector<TM> (data.Size(), data.Addr(0)); }
|
|
532
|
+
|
|
533
|
+
FlatVector<TM> GetRowValues(int i) const
|
|
534
|
+
{ return FlatVector<TM> (firsti[i+1]-firsti[i], data+firsti[i]); }
|
|
535
|
+
|
|
536
|
+
static bool IsRegularIndex (int index) { return index >= 0; }
|
|
537
|
+
virtual void AddElementMatrix(FlatArray<int> dnums1,
|
|
538
|
+
FlatArray<int> dnums2,
|
|
539
|
+
BareSliceMatrix<TSCAL> elmat,
|
|
540
|
+
bool use_atomic = false);
|
|
541
|
+
|
|
542
|
+
virtual void AddElementMatrixSymmetric(FlatArray<int> dnums,
|
|
543
|
+
BareSliceMatrix<TSCAL> elmat,
|
|
544
|
+
bool use_atomic = false);
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
virtual void SetZero() override;
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
///
|
|
551
|
+
virtual ostream & Print (ostream & ost) const override;
|
|
552
|
+
|
|
553
|
+
///
|
|
554
|
+
virtual Array<MemoryUsage> GetMemoryUsage () const override;
|
|
555
|
+
|
|
556
|
+
virtual AutoVector CreateVector () const override;
|
|
557
|
+
virtual AutoVector CreateRowVector () const override;
|
|
558
|
+
virtual AutoVector CreateColVector () const override;
|
|
559
|
+
|
|
560
|
+
// virtual tuple<int,int> EntrySizes() const override { return { mat_traits<TM>::HEIGHT, mat_traits<TM>::WIDTH }; }
|
|
561
|
+
virtual tuple<int,int> EntrySizes() const override { return { ngbla::Height<TM>(), ngbla::Width<TM>() }; }
|
|
562
|
+
|
|
563
|
+
shared_ptr<BaseSparseMatrix>
|
|
564
|
+
CreateTransposeTM (const function<shared_ptr<SparseMatrixTM<decltype(ngbla::Trans(TM()))>>(const Array<int>&, int)> & creator) const;
|
|
565
|
+
|
|
566
|
+
public:
|
|
567
|
+
using BaseMatrix::GetMemoryTracer;
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
template<class TM, class TV_ROW, class TV_COL>
|
|
574
|
+
class NGS_DLL_HEADER SparseMatrix : public SparseMatrixTM<TM>
|
|
575
|
+
{
|
|
576
|
+
public:
|
|
577
|
+
using SparseMatrixTM<TM>::firsti;
|
|
578
|
+
using SparseMatrixTM<TM>::colnr;
|
|
579
|
+
using SparseMatrixTM<TM>::data;
|
|
580
|
+
using SparseMatrixTM<TM>::balance;
|
|
581
|
+
using typename SparseMatrixTM<TM>::ColIdx;
|
|
582
|
+
|
|
583
|
+
typedef typename mat_traits<TM>::TSCAL TSCAL;
|
|
584
|
+
typedef TV_ROW TVX;
|
|
585
|
+
typedef TV_COL TVY;
|
|
586
|
+
|
|
587
|
+
///
|
|
588
|
+
SparseMatrix (int as, int max_elsperrow)
|
|
589
|
+
: SparseMatrixTM<TM> (as, max_elsperrow) { ; }
|
|
590
|
+
|
|
591
|
+
SparseMatrix (const Array<int> & aelsperrow)
|
|
592
|
+
: SparseMatrixTM<TM> (aelsperrow, aelsperrow.Size()) { ; }
|
|
593
|
+
|
|
594
|
+
SparseMatrix (const Array<int> & aelsperrow, int awidth)
|
|
595
|
+
: SparseMatrixTM<TM> (aelsperrow, awidth) { ; }
|
|
596
|
+
|
|
597
|
+
SparseMatrix (int height, int width, const Table<int> & rowelements,
|
|
598
|
+
const Table<int> & colelements, bool symmetric)
|
|
599
|
+
: SparseMatrixTM<TM> (height, width, rowelements, colelements, symmetric) { ; }
|
|
600
|
+
|
|
601
|
+
SparseMatrix (const MatrixGraph & agraph);
|
|
602
|
+
SparseMatrix (MatrixGraph && agraph);
|
|
603
|
+
|
|
604
|
+
SparseMatrix (const SparseMatrix & amat)
|
|
605
|
+
: SparseMatrixTM<TM> (amat) { ; }
|
|
606
|
+
|
|
607
|
+
SparseMatrix (const SparseMatrixTM<TM> & amat)
|
|
608
|
+
: SparseMatrixTM<TM> (amat) { ; }
|
|
609
|
+
|
|
610
|
+
SparseMatrix (SparseMatrixTM<TM> && amat)
|
|
611
|
+
: SparseMatrixTM<TM> (std::move(amat)) { ; }
|
|
612
|
+
|
|
613
|
+
virtual shared_ptr<BaseMatrix> CreateMatrix () const override;
|
|
614
|
+
// virtual BaseMatrix * CreateMatrix (const Array<int> & elsperrow) const;
|
|
615
|
+
///
|
|
616
|
+
virtual AutoVector CreateVector () const override;
|
|
617
|
+
virtual AutoVector CreateRowVector () const override;
|
|
618
|
+
virtual AutoVector CreateColVector () const override;
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
BaseMatrix::OperatorInfo GetOperatorInfo () const override
|
|
622
|
+
{ return { string("SparseMatrix")+typeid(TM).name()+" (nze="+ToString(this->NZE())+")", this->Height(), this->Width() }; }
|
|
623
|
+
|
|
624
|
+
virtual shared_ptr<BaseJacobiPrecond>
|
|
625
|
+
CreateJacobiPrecond (shared_ptr<BitArray> inner) const override;
|
|
626
|
+
|
|
627
|
+
virtual shared_ptr<BaseBlockJacobiPrecond>
|
|
628
|
+
CreateBlockJacobiPrecond (shared_ptr<Table<int>> blocks,
|
|
629
|
+
const BaseVector * constraint = 0,
|
|
630
|
+
bool parallel = 1,
|
|
631
|
+
shared_ptr<BitArray> freedofs = NULL) const override;
|
|
632
|
+
|
|
633
|
+
virtual shared_ptr<BaseMatrix> InverseMatrix (shared_ptr<BitArray> subset = nullptr) const override;
|
|
634
|
+
virtual shared_ptr<BaseMatrix> InverseMatrix (shared_ptr<const Array<int>> clusters) const override;
|
|
635
|
+
|
|
636
|
+
virtual shared_ptr<BaseSparseMatrix> Restrict (const SparseMatrixTM<double> & prol,
|
|
637
|
+
shared_ptr<BaseSparseMatrix> cmat = nullptr) const override;
|
|
638
|
+
|
|
639
|
+
virtual shared_ptr<BaseSparseMatrix> Reorder (const Array<size_t> & reorder) const override;
|
|
640
|
+
|
|
641
|
+
virtual shared_ptr<BaseSparseMatrix> CreateTranspose() const override
|
|
642
|
+
{
|
|
643
|
+
return this->CreateTransposeTM
|
|
644
|
+
( [](const Array<int> & elsperrow, int width) -> shared_ptr<SparseMatrixTM<decltype(Trans(TM()))>>
|
|
645
|
+
{ return make_shared<SparseMatrix<decltype(Trans(TM())), TV_COL, TV_ROW>> (elsperrow, width); } );
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
virtual shared_ptr<BaseMatrix> DeleteZeroElements(double tol) const override;
|
|
649
|
+
|
|
650
|
+
///
|
|
651
|
+
inline TVY RowTimesVector (int row, const FlatVector<TVX> vec) const
|
|
652
|
+
{
|
|
653
|
+
typedef typename mat_traits<TVY>::TSCAL TTSCAL;
|
|
654
|
+
TVY sum = TTSCAL(0);
|
|
655
|
+
for (size_t j = firsti[row]; j < firsti[row+1]; j++)
|
|
656
|
+
sum += data[j] * vec(colnr[j]);
|
|
657
|
+
return sum;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
///
|
|
661
|
+
void AddRowTransToVector (int row, TVY el, FlatVector<TVX> vec) const
|
|
662
|
+
{
|
|
663
|
+
size_t first = firsti[row];
|
|
664
|
+
size_t last = firsti[row+1];
|
|
665
|
+
|
|
666
|
+
const ColIdx * colpi = colnr.Addr(0);
|
|
667
|
+
const TM * datap = data.Addr(0);
|
|
668
|
+
|
|
669
|
+
for (size_t j = first; j < last; j++)
|
|
670
|
+
vec[colpi[j]] += Trans(datap[j]) * el;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
///
|
|
674
|
+
void AddRowConjTransToVector (int row, TVY el, FlatVector<TVX> vec) const
|
|
675
|
+
{
|
|
676
|
+
size_t first = firsti[row];
|
|
677
|
+
size_t last = firsti[row+1];
|
|
678
|
+
|
|
679
|
+
const ColIdx * colpi = colnr.Addr(0);
|
|
680
|
+
const TM * datap = data.Addr(0);
|
|
681
|
+
|
|
682
|
+
for (size_t j = first; j < last; j++)
|
|
683
|
+
vec[colpi[j]] += Conj(Trans(datap[j])) * el;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override;
|
|
688
|
+
virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override;
|
|
689
|
+
virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override;
|
|
690
|
+
virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override;
|
|
691
|
+
virtual void MultConjTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override;
|
|
692
|
+
|
|
693
|
+
virtual void MultAdd (FlatVector<double> alpha, const MultiVector & x, MultiVector & y) const override;
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
virtual void MultAdd1 (double s, const BaseVector & x, BaseVector & y,
|
|
697
|
+
const BitArray * ainner = NULL,
|
|
698
|
+
const Array<int> * acluster = NULL) const override;
|
|
699
|
+
|
|
700
|
+
virtual void DoArchive (Archive & ar) override;
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
/// A symmetric sparse matrix
|
|
706
|
+
template<class TM, class TV>
|
|
707
|
+
class NGS_DLL_HEADER SparseMatrixSymmetric : public SparseMatrix<TM,TV,TV>
|
|
708
|
+
{
|
|
709
|
+
|
|
710
|
+
public:
|
|
711
|
+
using SparseMatrixTM<TM>::firsti;
|
|
712
|
+
using SparseMatrixTM<TM>::colnr;
|
|
713
|
+
using SparseMatrixTM<TM>::data;
|
|
714
|
+
using BaseSparseMatrix::ColIdx;
|
|
715
|
+
|
|
716
|
+
typedef typename mat_traits<TM>::TSCAL TSCAL;
|
|
717
|
+
typedef TV TV_COL;
|
|
718
|
+
typedef TV TV_ROW;
|
|
719
|
+
typedef TV TVY;
|
|
720
|
+
typedef TV TVX;
|
|
721
|
+
|
|
722
|
+
SparseMatrixSymmetric (int as, int max_elsperrow)
|
|
723
|
+
: SparseMatrix<TM,TV,TV> (as, max_elsperrow)
|
|
724
|
+
{ ; }
|
|
725
|
+
|
|
726
|
+
SparseMatrixSymmetric (const Array<int> & elsperrow)
|
|
727
|
+
: SparseMatrix<TM,TV,TV> (elsperrow, elsperrow.Size())
|
|
728
|
+
{ ; }
|
|
729
|
+
|
|
730
|
+
SparseMatrixSymmetric (int size, const Table<int> & rowelements)
|
|
731
|
+
: SparseMatrix<TM,TV,TV> (size, size, rowelements, rowelements, true)
|
|
732
|
+
{ ; }
|
|
733
|
+
|
|
734
|
+
SparseMatrixSymmetric (const MatrixGraph & agraph);
|
|
735
|
+
SparseMatrixSymmetric (MatrixGraph && agraph);
|
|
736
|
+
|
|
737
|
+
SparseMatrixSymmetric (const SparseMatrixSymmetric & amat)
|
|
738
|
+
: SparseMatrix<TM,TV,TV> (amat)
|
|
739
|
+
{
|
|
740
|
+
this->AsVector() = amat.AsVector();
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
SparseMatrixSymmetric (const SparseMatrixTM<TM> & amat)
|
|
744
|
+
: SparseMatrix<TM,TV,TV> (amat)
|
|
745
|
+
{
|
|
746
|
+
this->AsVector() = amat.AsVector();
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
///
|
|
750
|
+
virtual ~SparseMatrixSymmetric ();
|
|
751
|
+
|
|
752
|
+
SparseMatrixSymmetric & operator= (double s)
|
|
753
|
+
{
|
|
754
|
+
this->AsVector() = s;
|
|
755
|
+
return *this;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
virtual shared_ptr<BaseMatrix> CreateMatrix () const override
|
|
759
|
+
{
|
|
760
|
+
return make_shared<SparseMatrixSymmetric> (*this);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/*
|
|
764
|
+
virtual BaseMatrix * CreateMatrix (const Array<int> & elsperrow) const
|
|
765
|
+
{
|
|
766
|
+
return new SparseMatrix<TM,TV,TV>(elsperrow);
|
|
767
|
+
}
|
|
768
|
+
*/
|
|
769
|
+
|
|
770
|
+
virtual void AddElementMatrix(FlatArray<int> dnums1,
|
|
771
|
+
FlatArray<int> dnums2,
|
|
772
|
+
BareSliceMatrix<TSCAL> elmat,
|
|
773
|
+
bool use_atomic = false) override
|
|
774
|
+
{
|
|
775
|
+
this->AddElementMatrixSymmetric (dnums1, elmat, use_atomic);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
virtual shared_ptr<BaseJacobiPrecond> CreateJacobiPrecond (shared_ptr<BitArray> inner) const override;
|
|
779
|
+
virtual shared_ptr<BaseBlockJacobiPrecond>
|
|
780
|
+
CreateBlockJacobiPrecond (shared_ptr<Table<int>> blocks,
|
|
781
|
+
const BaseVector * constraint = 0,
|
|
782
|
+
bool parallel = 1,
|
|
783
|
+
shared_ptr<BitArray> freedofs = NULL) const override;
|
|
784
|
+
|
|
785
|
+
virtual shared_ptr<BaseSparseMatrix> Restrict (const SparseMatrixTM<double> & prol,
|
|
786
|
+
shared_ptr<BaseSparseMatrix> cmat = nullptr) const override;
|
|
787
|
+
|
|
788
|
+
///
|
|
789
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override;
|
|
790
|
+
|
|
791
|
+
virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override
|
|
792
|
+
{
|
|
793
|
+
MultAdd (s, x, y);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
/*
|
|
798
|
+
y += s L * x
|
|
799
|
+
*/
|
|
800
|
+
virtual void MultAdd1 (double s, const BaseVector & x, BaseVector & y,
|
|
801
|
+
const BitArray * ainner = NULL,
|
|
802
|
+
const Array<int> * acluster = NULL) const override;
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
/*
|
|
806
|
+
y += s (D + L^T) * x
|
|
807
|
+
*/
|
|
808
|
+
virtual void MultAdd2 (double s, const BaseVector & x, BaseVector & y,
|
|
809
|
+
const BitArray * ainner = NULL,
|
|
810
|
+
const Array<int> * acluster = NULL) const override;
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
using SparseMatrix<TM,TV,TV>::RowTimesVector;
|
|
817
|
+
using SparseMatrix<TM,TV,TV>::AddRowTransToVector;
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
TV_COL RowTimesVectorNoDiag (int row, const FlatVector<TVX> vec) const
|
|
821
|
+
{
|
|
822
|
+
size_t last = firsti[row+1];
|
|
823
|
+
size_t first = firsti[row];
|
|
824
|
+
if (last == first) return TVY(0);
|
|
825
|
+
if (colnr[last-1] == row) last--;
|
|
826
|
+
|
|
827
|
+
typedef typename mat_traits<TVY>::TSCAL TTSCAL;
|
|
828
|
+
TVY sum = TTSCAL(0);
|
|
829
|
+
|
|
830
|
+
for (size_t j = first; j < last; j++)
|
|
831
|
+
sum += data[j] * vec(colnr[j]);
|
|
832
|
+
return sum;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
void AddRowTransToVectorNoDiag (int row, TVY el, FlatVector<TVX> vec) const
|
|
836
|
+
{
|
|
837
|
+
size_t first = firsti[row];
|
|
838
|
+
size_t last = firsti[row+1];
|
|
839
|
+
|
|
840
|
+
if (first == last) return;
|
|
841
|
+
if (this->colnr[last-1] == row) last--;
|
|
842
|
+
|
|
843
|
+
for (size_t j = first; j < last; j++)
|
|
844
|
+
vec[colnr[j]] += Trans(data[j]) * el;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
BaseSparseMatrix & AddMerge (double s, const SparseMatrixSymmetric & m2);
|
|
848
|
+
|
|
849
|
+
virtual shared_ptr<BaseMatrix> InverseMatrix (shared_ptr<BitArray> subset = nullptr) const override;
|
|
850
|
+
virtual shared_ptr<BaseMatrix> InverseMatrix (shared_ptr<const Array<int>> clusters) const override;
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
[[deprecated("Use sparsematrix->CreateTranspose() instead!")]]
|
|
854
|
+
NGS_DLL_HEADER shared_ptr<SparseMatrixTM<double>> TransposeMatrix (const SparseMatrixTM<double> & mat);
|
|
855
|
+
|
|
856
|
+
NGS_DLL_HEADER shared_ptr<SparseMatrixTM<double>>
|
|
857
|
+
MatAdd (double sa, const SparseMatrixTM<double> & mata,
|
|
858
|
+
double sb, const SparseMatrixTM<double> & matb);
|
|
859
|
+
|
|
860
|
+
NGS_DLL_HEADER shared_ptr<SparseMatrixTM<double>>
|
|
861
|
+
MatMult (const SparseMatrixTM<double> & mata, const SparseMatrixTM<double> & matb);
|
|
862
|
+
NGS_DLL_HEADER shared_ptr<SparseMatrixTM<Complex>>
|
|
863
|
+
MatMult (const SparseMatrixTM<Complex> & mata, const SparseMatrixTM<Complex> & matb);
|
|
864
|
+
|
|
865
|
+
#ifdef GOLD
|
|
866
|
+
#include <sparsematrix_spec.hpp>
|
|
867
|
+
#endif
|
|
868
|
+
|
|
869
|
+
shared_ptr<BaseMatrix> CreateSparseMatrixInverse(shared_ptr<const BaseSparseMatrix> A,
|
|
870
|
+
shared_ptr<BitArray> subset,
|
|
871
|
+
shared_ptr<const Array<int>> clusters);
|
|
872
|
+
|
|
873
|
+
#ifdef FILE_SPARSEMATRIX_CPP
|
|
874
|
+
#define SPARSEMATRIX_EXTERN
|
|
875
|
+
#else
|
|
876
|
+
#define SPARSEMATRIX_EXTERN extern
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
SPARSEMATRIX_EXTERN template class SparseMatrix<double>;
|
|
880
|
+
SPARSEMATRIX_EXTERN template class SparseMatrix<Complex>;
|
|
881
|
+
SPARSEMATRIX_EXTERN template class SparseMatrix<double, Complex, Complex>;
|
|
882
|
+
|
|
883
|
+
SPARSEMATRIX_EXTERN template class SparseMatrixSymmetric<double>;
|
|
884
|
+
SPARSEMATRIX_EXTERN template class SparseMatrixSymmetric<Complex>;
|
|
885
|
+
SPARSEMATRIX_EXTERN template class SparseMatrixSymmetric<double, Complex>;
|
|
886
|
+
|
|
887
|
+
#define INST_SPMS(N) \
|
|
888
|
+
SPARSEMATRIX_EXTERN template class SparseMatrix<Mat<N, N, double>>; \
|
|
889
|
+
SPARSEMATRIX_EXTERN template class SparseMatrix<Mat<1, N, double>>; \
|
|
890
|
+
SPARSEMATRIX_EXTERN template class SparseMatrix<Mat<N, 1, double>>; \
|
|
891
|
+
SPARSEMATRIX_EXTERN template class SparseMatrix<Mat<N, N, Complex>>; \
|
|
892
|
+
SPARSEMATRIX_EXTERN template class SparseMatrix<Mat<1, N, Complex>>; \
|
|
893
|
+
SPARSEMATRIX_EXTERN template class SparseMatrix<Mat<N, 1, Complex>>; \
|
|
894
|
+
SPARSEMATRIX_EXTERN template class SparseMatrixSymmetric<Mat<N, N, double>>; \
|
|
895
|
+
SPARSEMATRIX_EXTERN template class SparseMatrixSymmetric<Mat<N, N, Complex>>;
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
#if MAX_SYS_DIM >= 1
|
|
899
|
+
INST_SPMS(1);
|
|
900
|
+
#endif
|
|
901
|
+
#if MAX_SYS_DIM >= 2
|
|
902
|
+
INST_SPMS(2);
|
|
903
|
+
#endif
|
|
904
|
+
#if MAX_SYS_DIM >= 3
|
|
905
|
+
INST_SPMS(3);
|
|
906
|
+
#endif
|
|
907
|
+
#if MAX_SYS_DIM >= 4
|
|
908
|
+
INST_SPMS(4);
|
|
909
|
+
#endif
|
|
910
|
+
#if MAX_SYS_DIM >= 5
|
|
911
|
+
INST_SPMS(5);
|
|
912
|
+
#endif
|
|
913
|
+
#if MAX_SYS_DIM >= 6
|
|
914
|
+
INST_SPMS(6);
|
|
915
|
+
#endif
|
|
916
|
+
#if MAX_SYS_DIM >= 7
|
|
917
|
+
INST_SPMS(7);
|
|
918
|
+
#endif
|
|
919
|
+
#if MAX_SYS_DIM >= 8
|
|
920
|
+
INST_SPMS(8);
|
|
921
|
+
#endif
|
|
922
|
+
|
|
923
|
+
#undef INST_SPMS
|
|
924
|
+
#undef SPARSEMATRIX_EXTERN
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
#endif
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
template <typename TSCAL>
|
|
932
|
+
class NGS_DLL_HEADER SparseBlockMatrix : public S_BaseSparseMatrix<TSCAL>
|
|
933
|
+
{
|
|
934
|
+
size_t bheight, bwidth;
|
|
935
|
+
NumaDistributedArray<TSCAL> data;
|
|
936
|
+
|
|
937
|
+
typedef S_BaseSparseMatrix<TSCAL> BASE;
|
|
938
|
+
using BASE::firsti;
|
|
939
|
+
using BASE::colnr;
|
|
940
|
+
using BASE::owner;
|
|
941
|
+
using BASE::size;
|
|
942
|
+
using BASE::width;
|
|
943
|
+
using BASE::nze;
|
|
944
|
+
using BASE::balance;
|
|
945
|
+
using BASE::asvec;
|
|
946
|
+
|
|
947
|
+
public:
|
|
948
|
+
using BASE::CreatePosition;
|
|
949
|
+
using BASE::GetPositionTest;
|
|
950
|
+
using BASE::FindSameNZE;
|
|
951
|
+
// using BASE::SetEntrySize;
|
|
952
|
+
using BASE::AsVector;
|
|
953
|
+
|
|
954
|
+
SparseBlockMatrix (const MatrixGraph & agraph, size_t abheight, size_t abwidth)
|
|
955
|
+
: BASE (agraph), bheight(abheight), bwidth(abwidth),
|
|
956
|
+
data(nze*bheight*bwidth)
|
|
957
|
+
{
|
|
958
|
+
// SetEntrySize (bheight, bwidth, bheight*bwidth);
|
|
959
|
+
BASE::entry_height = bheight;
|
|
960
|
+
BASE::entry_width = bwidth;
|
|
961
|
+
BASE::entry_size = bheight*bwidth;
|
|
962
|
+
BASE::is_complex = ngbla::IsComplex<TSCAL>();
|
|
963
|
+
|
|
964
|
+
asvec.AssignMemory (nze*bheight*bwidth, (void*)data.Addr(0));
|
|
965
|
+
// FindSameNZE();
|
|
966
|
+
GetMemoryTracer().Track(*static_cast<MatrixGraph*>(this), "MatrixGraph",
|
|
967
|
+
data, "data");
|
|
968
|
+
GetMemoryTracer().SetName("SparseMatrix");
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
SparseBlockMatrix (MatrixGraph && agraph, size_t abheight, size_t abwidth)
|
|
972
|
+
: BASE (std::move(agraph)), bheight(abheight), bwidth(abwidth),
|
|
973
|
+
data(nze*bheight*bwidth)
|
|
974
|
+
{
|
|
975
|
+
// SetEntrySize (bheight, bwidth, bheight*bwidth);
|
|
976
|
+
BASE::entry_height = bheight;
|
|
977
|
+
BASE::entry_width = bwidth;
|
|
978
|
+
BASE::entry_size = bheight*bwidth;
|
|
979
|
+
BASE::is_complex = ngbla::IsComplex<TSCAL>();
|
|
980
|
+
|
|
981
|
+
asvec.AssignMemory (nze*bheight*bwidth, (void*)data.Addr(0));
|
|
982
|
+
// FindSameNZE();
|
|
983
|
+
GetMemoryTracer().Track(*static_cast<MatrixGraph*>(this), "MatrixGraph",
|
|
984
|
+
data, "data");
|
|
985
|
+
GetMemoryTracer().SetName("SparseMatrix");
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
tuple<int,int> EntrySizes() const override { return { bheight, bwidth }; }
|
|
991
|
+
|
|
992
|
+
AutoVector CreateRowVector () const override
|
|
993
|
+
{
|
|
994
|
+
return AutoVector(make_shared<S_BaseVectorPtr<TSCAL>> (this->width, this->bwidth));
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
AutoVector CreateColVector () const override
|
|
998
|
+
{
|
|
999
|
+
return AutoVector(make_shared<S_BaseVectorPtr<TSCAL>> (this->size, this->bheight));
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override;
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
void SetZero() override
|
|
1006
|
+
{
|
|
1007
|
+
data = TSCAL(0);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
virtual void AddElementMatrix(FlatArray<int> dnums1,
|
|
1011
|
+
FlatArray<int> dnums2,
|
|
1012
|
+
BareSliceMatrix<TSCAL> elmat,
|
|
1013
|
+
bool use_atomic = false);
|
|
1014
|
+
|
|
1015
|
+
ostream & Print (ostream & ost) const override;
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
const MemoryTracer & GetMemoryTracer() const
|
|
1019
|
+
{
|
|
1020
|
+
return mem_tracer;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
private:
|
|
1024
|
+
MemoryTracer mem_tracer =
|
|
1025
|
+
{"MatrixGraph",
|
|
1026
|
+
colnr, "colnr",
|
|
1027
|
+
firsti, "firsti"
|
|
1028
|
+
// same_nze, "same_nze"
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
#endif
|