H2Lib  3.0
h2matrix.h
Go to the documentation of this file.
1 
2 /* ------------------------------------------------------------
3  * This is the file "h2matrix.h" of the H2Lib package.
4  * All rights reserved, Steffen Boerm 2009
5  * ------------------------------------------------------------ */
6 
11 #ifndef H2MATRIX_H
12 #define H2MATRIX_H
13 
22 typedef struct _h2matrix h2matrix;
23 
26 
28 typedef const h2matrix *pch2matrix;
29 
30 #ifdef USE_CAIRO
31 #include <cairo/cairo.h>
32 #endif
33 
34 #include "amatrix.h"
35 #include "krylov.h"
36 #include "block.h"
37 #include "hmatrix.h"
38 #include "uniform.h"
39 #include "clusterbasis.h"
40 #include "settings.h"
41 
48 struct _h2matrix {
53 
56 
59 
66 
71 };
72 
73 /* ------------------------------------------------------------
74  * Constructors and destructors
75  * ------------------------------------------------------------ */
76 
91 
107 
123 
142 
156 
169 
170 /* clones a h2matrix, should be in the module h2matrix */
185 
194 HEADER_PREFIX void
196 
206 HEADER_PREFIX void
208 
209 /* ------------------------------------------------------------
210  * Reference counting
211  * ------------------------------------------------------------ */
212 
219 HEADER_PREFIX void
221 
230 HEADER_PREFIX void
232 
233 /* ------------------------------------------------------------
234  * Statistics
235  * ------------------------------------------------------------ */
236 
241 HEADER_PREFIX size_t
243 
249 HEADER_PREFIX size_t
251 
256 HEADER_PREFIX size_t
258 
263 HEADER_PREFIX size_t
265 
266 /* ------------------------------------------------------------
267  * Simple utility functions
268  * ------------------------------------------------------------ */
269 
274 HEADER_PREFIX void
276 
281 void
282 scale_h2matrix(field alpha, ph2matrix h2);
283 
287 void
289 
290 /* ------------------------------------------------------------
291  * Build H^2-matrix based on block tree
292  * ------------------------------------------------------------ */
293 
306 
307 /* ------------------------------------------------------------
308  * Build block tree from H^2-matrix
309  * ------------------------------------------------------------ */
310 
318 
319 /* ------------------------------------------------------------
320  * Enumeration by block number
321  * ------------------------------------------------------------ */
322 
337 
338 /* ------------------------------------------------------------
339  * Hierarchical iterators
340  * ------------------------------------------------------------ */
341 
344 
347 
350 
355 
358 
361 
364 
367 
370 };
371 
380 typedef void (*h2matrix_callback_t)(ph2matrix G,
381  uint mname, uint rname, uint cname,
382  uint pardepth, void *data);
383 
392  uint tname,
393  uint pardepth,
394  pch2matrixlist hl,
395  void *data);
396 
411 HEADER_PREFIX void
412 iterate_h2matrix(ph2matrix G, uint mname, uint rname, uint cname,
413  uint pardepth,
415  void *data);
416 
428 HEADER_PREFIX void
429 iterate_rowlist_h2matrix(ph2matrix G, uint mname, uint rname, uint cname,
430  uint pardepth,
432  h2matrixlist_callback_t post, void *data);
433 
445 HEADER_PREFIX void
446 iterate_collist_h2matrix(ph2matrix G, uint mname, uint rname, uint cname,
447  uint pardepth,
449  h2matrixlist_callback_t post, void *data);
450 
465 HEADER_PREFIX void
466 iterate_byrow_h2matrix(ph2matrix G, uint mname, uint rname, uint cname,
467  uint pardepth,
469  void *data);
470 
485 HEADER_PREFIX void
486 iterate_bycol_h2matrix(ph2matrix G, uint mname, uint rname, uint cname,
487  uint pardepth,
489  void *data);
490 
491 /* ------------------------------------------------------------
492  * Matrix-vector multiplication
493  * ------------------------------------------------------------ */
494 
507 HEADER_PREFIX void
508 mvm_h2matrix_avector(field alpha, bool h2trans, pch2matrix h2, pcavector x,
509  pavector y);
510 
531 HEADER_PREFIX void
533  pavector yt);
534 
545 HEADER_PREFIX void
547 
568 HEADER_PREFIX void
570  pavector yt);
571 
582 HEADER_PREFIX void
584  pavector y);
585 
594 HEADER_PREFIX void
596  pavector y);
597 
598 /* ------------------------------------------------------------
599  * Addmul H2-Matrices and Amatrix
600  * ------------------------------------------------------------ */
601 
637 HEADER_PREFIX void
639  pcamatrix Bt, pamatrix Ct);
640 
655 HEADER_PREFIX void
656 addmul_h2matrix_amatrix_amatrix(field alpha, bool atrans, pch2matrix A,
657  bool btrans, pcamatrix B, pamatrix C);
658 
673 HEADER_PREFIX void
674 addmul_amatrix_h2matrix_amatrix(field alpha, bool atrans, pcamatrix A,
675  bool btrans, pch2matrix B, pamatrix C);
676 
677 /* ------------------------------------------------------------
678  * Orthogonal projection
679  * ------------------------------------------------------------ */
680 
692 HEADER_PREFIX void
694  pamatrix s);
695 
710 HEADER_PREFIX void
712 
728 HEADER_PREFIX void
730 
731 /* ------------------------------------------------------------
732  * Spectral norm
733  * ------------------------------------------------------------ */
734 
745 
758 
759 /* ------------------------------------------------------------
760  * File I/O
761  * ------------------------------------------------------------ */
762 
763 #ifdef USE_NETCDF
764 
768 HEADER_PREFIX void
769 write_cdf_h2matrix(pch2matrix G, const char *name);
770 
776 HEADER_PREFIX void
777 write_cdfpart_h2matrix(pch2matrix G, int nc_file, const char *prefix);
778 
787 
796 read_cdfpart_h2matrix(int nc_file, const char *prefix,
798 
804 HEADER_PREFIX void
805 write_cdfcomplete_h2matrix(pch2matrix G, const char *name);
806 
813 read_cdfcomplete_h2matrix(const char *name);
814 #endif
815 
816 /* ------------------------------------------------------------
817  * Drawing
818  * ------------------------------------------------------------ */
819 
820 #ifdef USE_CAIRO
821 
831 HEADER_PREFIX void
832 draw_cairo_h2matrix(cairo_t *cr, pch2matrix G, bool storage, uint levels);
833 #endif
834 
835 #endif
836 
837 /* ------------------------------------------------------------
838  * Access methods
839  * ------------------------------------------------------------ */
840 
841 #ifndef H2MATRIX_COMPLETE
842 #define H2MATRIX_COMPLETE
843 
844 #ifdef __GNUC__
846 getrows_h2matrix(pch2matrix) __attribute__ ((const,unused));
848 getcols_h2matrix(pch2matrix) __attribute__ ((const,unused));
849 #endif
850 
857 {
858  return h2->rb->t->size;
859 }
860 
867 {
868  return h2->cb->t->size;
869 }
870 
871 #endif
872 
ph2matrix G
Matrix.
Definition: h2matrix.h:354
uint desc
Number of descendants in matrix tree.
Definition: h2matrix.h:70
ph2matrix read_cdfpart_h2matrix(int nc_file, const char *prefix, pclusterbasis rb, pclusterbasis cb)
Read h2matrix from part of a NetCDF file.
void mvm_h2matrix_avector(field alpha, bool h2trans, pch2matrix h2, pcavector x, pavector y)
Matrix-vector multiplication or .
void addevaltrans_h2matrix_avector(field alpha, pch2matrix h2, pcavector x, pavector y)
Adjoint matrix-vector multiplication .
h2matrix * ph2matrix
Pointer to h2matrix object.
Definition: h2matrix.h:25
uint rsons
Number of block rows.
Definition: h2matrix.h:63
uint cname
Number of column cluster.
Definition: h2matrix.h:363
uint rname
Number of row cluster.
Definition: h2matrix.h:360
List of h2matrix objects.
Definition: h2matrix.h:352
void fastaddevaltrans_h2matrix_avector(field alpha, pch2matrix h2, pavector xt, pavector yt)
Interaction phase of the adjoint matrix-vector multiplication.
Definition: avector.h:39
void project_amatrix_h2matrix(ph2matrix h2, pcamatrix a)
Compute the best approximation of a given matrix with respect to an -matrix space.
void unref_h2matrix(ph2matrix h2)
Reduce the reference counter of an h2matrix object.
ph2matrix new_super_h2matrix(pclusterbasis rb, pclusterbasis cb, uint rsons, uint csons)
Create a new hmatrix object representing a subdivided matrix.
void random_h2matrix(ph2matrix h2)
Fill an h2matrix with random coefficients.
void write_cdfpart_h2matrix(pch2matrix G, int nc_file, const char *prefix)
Write h2matrix to part of a NetCDF file.
Representation of -matrices.
Definition: h2matrix.h:48
ph2matrix build_from_block_h2matrix(pcblock b, pclusterbasis rb, pclusterbasis cb)
Build an h2matrix object from a block tree using given cluster bases.
size_t getfarsize_h2matrix(pch2matrix h2)
Get size of the farfield part of a given h2matrix object.
ph2matrix new_full_h2matrix(pclusterbasis rb, pclusterbasis cb)
Create a new h2matrix object representing a standard dense matrix.
void iterate_bycol_h2matrix(ph2matrix G, uint mname, uint rname, uint cname, uint pardepth, h2matrix_callback_t pre, h2matrix_callback_t post, void *data)
Iterate through all submatrices of an h2matrix.
uint getcols_h2matrix(pch2matrix h2)
Get the number of columns of an h2matrix .
Definition: h2matrix.h:866
Representation of -matrices.
Definition: hmatrix.h:49
Representation of a cluster basis.
Definition: clusterbasis.h:40
void write_cdfcomplete_h2matrix(pch2matrix G, const char *name)
Write h2matrix to NetCDF file, including cluster trees and cluster bases.
unsigned uint
Unsigned integer type.
Definition: settings.h:70
void collectdense_h2matrix(pcamatrix a, pcclusterbasis rb, pcclusterbasis cb, pamatrix s)
Compute .
uint getrows_h2matrix(pch2matrix h2)
Get the number of rows of an h2matrix .
Definition: h2matrix.h:856
ph2matrix new_uniform_h2matrix(pclusterbasis rb, pclusterbasis cb)
Create a new h2matrix object representing a uniform matrix.
double _Complex field
Field type.
Definition: settings.h:171
void ref_h2matrix(ph2matrix *ptr, ph2matrix h2)
Set a pointer to an h2matrix object, increase its reference counter, and decrease reference counter o...
uint csons
Number of block columns.
Definition: h2matrix.h:65
pch2matrixlist father
List entry corresponding to father.
Definition: h2matrix.h:366
void addeval_h2matrix_avector(field alpha, pch2matrix h2, pcavector x, pavector y)
Matrix-vector multiplication .
pccluster t
Corresponding cluster.
Definition: clusterbasis.h:42
void fastaddmul_h2matrix_amatrix_amatrix(field alpha, bool atrans, pch2matrix A, pcamatrix Bt, pamatrix Ct)
Interaction phase of the h2matrix - amatrix multiplication.
void(* h2matrix_callback_t)(ph2matrix G, uint mname, uint rname, uint cname, uint pardepth, void *data)
Callback function for h2matrix iterators.
Definition: h2matrix.h:380
void iterate_h2matrix(ph2matrix G, uint mname, uint rname, uint cname, uint pardepth, h2matrix_callback_t pre, h2matrix_callback_t post, void *data)
Iterate through all submatrices of an h2matrix.
void(* h2matrixlist_callback_t)(pccluster t, uint tname, uint pardepth, pch2matrixlist hl, void *data)
Callback function for h2matrixlist iterators.
Definition: h2matrix.h:391
#define INLINE_PREFIX
Prefix for inline functions.
Definition: settings.h:36
const h2matrix * pch2matrix
Pointer to constant h2matrix object.
Definition: h2matrix.h:28
pamatrix f
Standard matrix, for inadmissible leaves.
Definition: h2matrix.h:58
pblock build_from_h2matrix_block(pch2matrix G)
Build an block tree from an h2matrix.
void clear_h2matrix(ph2matrix h2)
Set an h2matrix to zero by clearing all far- and nearfield matrices.
pclusterbasis rb
Row cluster basis.
Definition: h2matrix.h:50
uint mname
Number of the submatrix.
Definition: h2matrix.h:357
void addmul_h2matrix_amatrix_amatrix(field alpha, bool atrans, pch2matrix A, bool btrans, pcamatrix B, pamatrix C)
Matrix multiplication , , or .
void addmul_amatrix_h2matrix_amatrix(field alpha, bool atrans, pcamatrix A, bool btrans, pch2matrix B, pamatrix C)
Matrix multiplication , , or .
void iterate_byrow_h2matrix(ph2matrix G, uint mname, uint rname, uint cname, uint pardepth, h2matrix_callback_t pre, h2matrix_callback_t post, void *data)
Iterate through all submatrices of an h2matrix.
ph2matrix new_zero_h2matrix(pclusterbasis rb, pclusterbasis cb)
Create a new h2matrix object representing a zero matrix.
void project_hmatrix_h2matrix(ph2matrix h2, phmatrix h)
Compute the best approximation of a given matrix with respect to an -matrix space.
size_t getnearsize_h2matrix(pch2matrix h2)
Get size of the nearfield part of a given h2matrix object.
void addevalsymm_h2matrix_avector(field alpha, pch2matrix h2, pcavector x, pavector y)
Symmetric matrix-vector multiplication, , where is assumed to be self-adjoint and only its lower tri...
real norm2diff_h2matrix(pch2matrix a, pch2matrix b)
Approximate the spectral norm of the difference of two matrices and .
#define HEADER_PREFIX
Prefix for function declarations.
Definition: settings.h:43
double real
real floating point type.
Definition: settings.h:97
void fastaddeval_h2matrix_avector(field alpha, pch2matrix h2, pavector xt, pavector yt)
Interaction phase of the matrix-vector multiplication.
ph2matrixlist next
Next item in list.
Definition: h2matrix.h:369
ph2matrix clonestructure_h2matrix(pch2matrix h2, pclusterbasis rb, pclusterbasis cb)
Builds a new h2matrix with clusterbasis rb and cb and the block structure of h2.
uint refs
Number of references to this h2matrix.
Definition: h2matrix.h:68
const h2matrixlist * pch2matrixlist
Pointer to constant h2matrixlist object.
Definition: h2matrix.h:349
void scale_h2matrix(field alpha, ph2matrix h2)
Scale an h2matrix by a factor.
size_t gettotalsize_h2matrix(pch2matrix h2)
Get total size of a given h2matrix object, including cluster bases.
Representation of block trees.
Definition: block.h:48
ph2matrix read_cdf_h2matrix(const char *name, pclusterbasis rb, pclusterbasis cb)
Read h2matrix from NetCDF file.
void iterate_rowlist_h2matrix(ph2matrix G, uint mname, uint rname, uint cname, uint pardepth, h2matrixlist_callback_t pre, h2matrixlist_callback_t post, void *data)
Iterate through all submatrices of an h2matrix, collecting all row blocks in an h2matrixlist object...
void write_cdf_h2matrix(pch2matrix G, const char *name)
Write h2matrix to NetCDF file.
Representation of cluster trees.
Definition: cluster.h:40
Representation of an admissible block for -matrices.
Definition: uniform.h:69
void draw_cairo_h2matrix(cairo_t *cr, pch2matrix G, bool storage, uint levels)
Draw a h2matrix to a cairo surface.
ph2matrix new_h2matrix(pclusterbasis rb, pclusterbasis cb)
Create a new h2matrix object.
void del_h2matrix(ph2matrix h2)
Delete an h2matrix object.
size_t getsize_h2matrix(pch2matrix h2)
Get size of a given h2matrix object.
h2matrixlist * ph2matrixlist
Pointer to h2matrixlist object.
Definition: h2matrix.h:346
Representation of a matrix as an array in column-major order.
Definition: amatrix.h:43
ph2matrix read_cdfcomplete_h2matrix(const char *name)
Read h2matrix from NetCDF file, including cluster trees and cluster bases.
real norm2_h2matrix(pch2matrix H2)
Approximate the spectral norm of a matrix .
uint size
Number of indices.
Definition: cluster.h:42
ph2matrix * enumerate_h2matrix(ph2matrix h2)
Enumerate h2matrix according to block tree.
ph2matrix clone_h2matrix(pch2matrix h2, pclusterbasis rb, pclusterbasis cb)
Builds a new h2matrix with clusterbasis rb and cb and the block structure of h2. Copies all coupling ...
pclusterbasis cb
Column cluster basis.
Definition: h2matrix.h:52
void iterate_collist_h2matrix(ph2matrix G, uint mname, uint rname, uint cname, uint pardepth, h2matrixlist_callback_t pre, h2matrixlist_callback_t post, void *data)
Iterate through all submatrices of an h2matrix, collecting all column blocks in an h2matrixlist objec...
ph2matrix * son
Submatrices.
Definition: h2matrix.h:61
puniform u
Uniform matrix, for admissible leaves.
Definition: h2matrix.h:55
void update_h2matrix(ph2matrix h2)
Complete the initialisation of a h2matrix object.