File size: 32,284 Bytes
10f2621
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
/** 
 * @defgroup Bvec Bvec class
 * @brief    A block vector object.
 */

/**
 *  @file       bvec.h
 *  @ingroup    Bvec
 *  @brief      Class Bvec: a block vector object.
 *  @author     Michael Holst
 *  @note       None
 *  @version    $Id: bvec.h,v 1.40 2010/08/12 05:18:34 fetk Exp $ 
 *
 *  @attention
 *  @verbatim
 *
 * MC = < Manifold Code >
 * Copyright (C) 1994-- Michael Holst
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *  @endverbatim
 */


#ifndef _BVEC_H_
#define _BVEC_H_

#include <mc/mc_base.h>

#include <mc/vec.h>
#include <mc/bmat.h>

/**
 * @ingroup Bvec
 * @brief   Contains public data members for Bvec class
 * @author  Michael Holst
 */

struct sBvec {

    Vmem   *vmem;          /**< @brief the memory manager                   */
    int    iMadeVmem;      /**< @brief did i make vmem or was it inherited  */

    char   name[10];       /**< @brief character string name for this vector*/
    int    n;              /**< @brief number of components in the vector   */
    double *u;             /**< @brief the vector components                */
    int    iMallocU;       /**< @brief did i malloc u or was it passed in   */

    struct sBvec *coarse;   /**< @brief next coarser object in the hierarchy */
    struct sBvec *fine;     /**< @brief next finer object in the hierarchy   */

    int    numB;           /**< @brief num vector blocks                    */
    int    numR[MAXV];     /**< @brief num of rows in each block vector     */
    Vec    *VC[MAXV];      /**< @brief vector block substructure            */

};

/**
 * @brief   Declaration of the Bvec class as the Bvec structure
 * @ingroup Bvec
 * @author  Michael Holst
 * @return  None
 */
typedef struct sBvec Bvec;

/*
 * ***************************************************************************
 * Class Bvec: Inlineable methods (bvec.c)
 * ***************************************************************************
 */

#if !defined(VINLINE_BAM)
    /**
     * @ingroup Bvec
     * @brief   Return the number of blocks.      
     * @author  Michael Holst
     * @note    Class Bvec: Non-inlineable methods (bvec.c) 
     * @return  the number of blocks.
     * @param   thee  pointer to the block vector
     */    
    VEXTERNC int Bvec_numB(Bvec *thee);
#else /* if defined(VINLINE_BAM) */

    /**
     * @ingroup Bvec
     * @brief   Return the number of blocks.      
     * @author  Michael Holst
     * @note    Class Bvec: Non-inlineable methods (bvec.c) 
     * @return  the number of blocks.
     * @param   thee  pointer to the block vector
     */    
#   define Bvec_numB(thee)              ((thee)->numB)
#endif /* if !defined(VINLINE_BAM) */

/**
 * @ingroup Bvec
 * @brief   The block vector constructor (data array malloc'd by us).
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  Pointer to a newly allocated (empty) block vector
 * @param   vmem  Memory management object
 * @param   name  character string name for this vector
 * @param   pnumB num vector blocks
 * @param   pnumR num of rows in each block vector
 */
VEXTERNC Bvec* Bvec_ctor(Vmem *vmem,
    const char *name, int pnumB, int pnumR[MAXV]);

/**
 * @ingroup Bvec
 * @brief   The block vector constructor (data array passed in). 
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  Pointer to a newly allocated (empty) block vector
 * @param   vmem  Memory management object
 * @param   name  character string name for this vector
 * @param   pnumB num vector blocks
 * @param   pnumR num of rows in each block vector
 * @param   data  the vector components
 */
VEXTERNC Bvec* Bvec_ctor2(Vmem *vmem,
    const char *name, int pnumB, int pnumR[MAXV], double *data);

/**
 * @ingroup Bvec
 * @brief   The vector constructor (data array malloc'd by us). 
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  Pointer to a newly allocated (empty) block vector
 * @param   vmem    Memory management object
 * @param   name    character string name for this vector
 * @param   length  number of components in the vector
 */
VEXTERNC Bvec* Bvec_ctor3(Vmem *vmem,
    const char *name, int length);

/**
 * @ingroup Bvec
 * @brief   The vector constructor (data array malloc'd by us). 
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  Pointer to a newly allocated (empty) block vector
 * @param   vmem    Memory management object
 * @param   name    character string name for this vector
 * @param   length  number of components in the vector
 * @param   data    the vector components
 */
VEXTERNC Bvec* Bvec_ctor4(Vmem *vmem,
    const char *name, int length, double *data);

/**
 * @ingroup Bvec
 * @brief   The block vector destructor.   
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 */
VEXTERNC void Bvec_dtor(Bvec **thee);

/**
 * @ingroup Bvec
 * @brief   Create a set of vectors with duplicate attributes.  
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) \n
 *          We actually do this using contiguous memory, i.e., each
 *          vector follows contiguously from the preceeding one.  
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   vecs  the created block vector
 * @param   num   the number of created vectors
 */
VEXTERNC void Bvec_createVectors(Bvec *thee, Bvec *vecs[], int num);

/**
 * @ingroup Bvec
 * @brief   Destroy set of vectors previously created by Bvec_createVectors.  
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   vecs  the created block vector
 * @param   num   the number of created vectors
 */
VEXTERNC void Bvec_destroyVectors(Bvec *thee, Bvec *vecs[], int num);

/**
 * @ingroup Bvec
 * @brief   Create a matrix from columns of vectors.  
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   vecs  the created block vector
 * @param   num   the number of created vectors
 * @param   mat   Pointer to the sparse matrix
 */
VEXTERNC void Bvec_createVecMat(Bvec *thee, Bvec *vecs[], int num, Mat **mat);

/**
 * @ingroup Bvec
 * @brief   Destroy matrix previously created by Bvec_createVecMat.       
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   vecs  the created block vector
 * @param   num   the number of created vectors
 * @param   mat   Pointer to the sparse matrix
 */
VEXTERNC void Bvec_destroyVecMat(Bvec *thee, Bvec *vecs[], int num, Mat **mat);

/**
 * @ingroup Bvec
 * @brief   Return the total number of rows.  
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  the total number of rows.
 * @param   thee  pointer to the block vector
 */
VEXTERNC int Bvec_len(Bvec *thee);

/**
 * @ingroup Bvec
 * @brief   Return a pointer to the total data array.       
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  a pointer to the total data arary
 * @param   thee  pointer to the block vector
 */
VEXTERNC double* Bvec_addr(Bvec *thee);

/**
 * @ingroup Bvec
 * @brief   Return value of component of vector.
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  value of component of vector
 * @param   thee  pointer to the block vector
 * @param   i     index of the block vector
 */
VEXTERNC double Bvec_val(Bvec *thee, int i);

/**
 * @ingroup Bvec
 * @brief   Set value of component of vector.   
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   i     index of the block vector
 * @param   val   value of the i-th component of the block vector
 */
VEXTERNC void Bvec_set(Bvec *thee, int i, double val);

/**
 * @ingroup Bvec
 * @brief   1-norm of a block vector.  
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  1-norm of a block vector.
 * @param   thee  pointer to the block vector
 */
VEXTERNC double Bvec_nrm1(Bvec *thee);

/**
 * @ingroup Bvec
 * @brief   2-norm of a block vector. 
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  2-norm of a block vector
 * @param   thee  pointer to the block vector
 */
VEXTERNC double Bvec_nrm2(Bvec *thee);

/**
 * @ingroup Bvec
 * @brief   oo-norm of a block vector.   
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  oo-norm of a block vector.
 * @param   thee  pointer to the block vector
 */
VEXTERNC double Bvec_nrm8(Bvec *thee);

/**
 * @ingroup Bvec
 * @brief   1-norm of the difference of two block vectors.              
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  1-norm of the difference of two block vectors.
 * @param   thee  pointer to the block vector
 * @param   v     the source block vector
 */
VEXTERNC double Bvec_dif1(Bvec *thee, Bvec *v);

/**
 * @ingroup Bvec
 * @brief   2-norm of the difference of two block vectors.    
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  2-norm of the difference of two block vectors.
 * @param   thee  pointer to the block vector
 * @param   v     the source block vector
 */
VEXTERNC double Bvec_dif2(Bvec *thee, Bvec *v);

/**
 * @ingroup Bvec
 * @brief   oo-norm of the difference of two block vectors.      
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  oo-norm of the difference of two block vectors.
 * @param   thee  pointer to the block vector
 * @param   v     the source block vector
 */
VEXTERNC double Bvec_dif8(Bvec *thee, Bvec *v);

/**
 * @ingroup Bvec
 * @brief   Dot product of two block vectors.      
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  Dot product of two block vectors.
 * @param   thee  pointer to the block vector
 * @param   v     the source block vector
 */
VEXTERNC double Bvec_dot(Bvec *thee, Bvec *v);

/**
 * @ingroup Bvec
 * @brief   Initialize a block vector.     
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   val   value to be initialized for the block vector
 */
VEXTERNC void Bvec_init(Bvec *thee, double val);

/**
 * @ingroup Bvec
 * @brief   Scale a block vector.  
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   val   value of the i-th component of the block vector
 */
VEXTERNC void Bvec_scal(Bvec *thee, double val);

/**
 * @ingroup Bvec
 * @brief   Copy a block vector.    
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   v     the source block vector
 */
VEXTERNC void Bvec_copy(Bvec *thee, Bvec *v);

/**
 * @ingroup Bvec
 * @brief   Saxpy for a block vector.   
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   v     the source block vector
 * @param   val   coeficient for scaling the source block vector
 */
VEXTERNC void Bvec_axpy(Bvec *thee, Bvec *v, double val);

/**
 * @ingroup Bvec
 * @brief   Print the block vector
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 */
VEXTERNC void Bvec_print(Bvec *thee);

/**
 * @ingroup Bvec
 * @brief   Print the block vector
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   fname the file name of the block vector
 */
VEXTERNC void Bvec_printSp(Bvec *thee, char *fname);

/**
 * @ingroup Bvec
 * @brief   Apply inverse of diagonal to a vector. 
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee   pointer to the block vector
 * @param   A      system matrix
 * @param   f      source vector slot
 */
VEXTERNC void Bvec_diagScale(Bvec *thee, Bmat *A, Bvec *f);

/**
 * @ingroup Bvec
 * @brief   Block matrix times vector.
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   A     system matrix
 * @param   v     the source block vector
 * @param   key   index for different accumulation options
 * @param   part  index for future use
 */
VEXTERNC void Bvec_matvec(Bvec *thee, Bmat *A, Bvec *v, int key, int part);

/**
 * @ingroup Bvec
 * @brief   Generic smoothing operator (for a general YSMP-based matrix).
 * @authors Michael Holst and Stephen Bond
 * @note    Class Bvec: Non-inlineable methods (bvec.c) \n
 *          meth==1, adj==0  : Forward Gauss-Seidel\n
 *          u = (D + L)^{-1}*(f - U*u)\n
 *          meth==1, adj==1  : Adjoint Gauss-Seidel\n
 *          u = (D + U)^{-1}*(f - L*u)\n
 *          meth==2 : Self-adjoint or Symmetric Gauss-Seidel\n
 *          Apply (meth==1, adj==0) then (meth==1, adj==1)          
 * @return  None
 * @param   thee    pointer to the block vector
 * @param   A       system matrix
 * @param   f       source vector slot
 * @param   w       the work block vector
 * @param   key     smooth with A or A' (0=A, 1=A')
 * @param   ioflag  debug output level (0=normal, 1=none, 2=lots, ... )  
 * @param   meth    smoother choice (0=jac, 1=gs, ... )   
 * @param   adj     adjoint choice (0=normal, 1=adjoint) 
 * @param   itmax   number of iterations to do (the maximum allowed)
 * @param   etol    error tolerance (currently ignored)
 * @param   omega   SOR parameter (currently ignored)      
 */
VEXTERNC void Bvec_smooth(Bvec *thee, Bmat *A, Bvec *f, Bvec *w,
    int key, int ioflag, int meth, int adj, int itmax, double etol,
    double omega);

/**
 * @ingroup Bvec
 * @brief   Apply boundary condition.
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector    
 * @param   bmat  the block sparse matrix
 * @param   key   index for setting zeroes in the row/column components.    
 */
VEXTERNC void Bvec_bnd(Bvec *thee, Bmat *bmat, int key);

/**
 * @ingroup Bvec
 * @brief   Print the exact current malloc usage.
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bvec.c) 
 * @return  None
 * @param   thee  pointer to the block vector
 */
VEXTERNC void Bvec_memChk(Bvec *thee);

/** 
 * @ingroup Bvec
 * @brief   Return the total number of rows.
 * @author  Michael Holst
 * @note    BLOCK-ONLY STUFF 
 * @return  the total number of rows
 * @param   thee  pointer to the block vector
 */
VEXTERNC int Bvec_numRT(Bvec *thee);

/** 
 * @ingroup Bvec
 * @brief   Return the size of a block.
 * @author  Michael Holst
 * @note    BLOCK-ONLY STUFF 
 * @return  the size of a block
 * @param   thee  pointer to the block vector
 * @param   i     index of the block vector
 */
VEXTERNC int Bvec_numRB(Bvec *thee, int i);

/** 
 * @ingroup Bvec
 * @brief   Return a pointer to the data in a block.   
 * @author  Michael Holst
 * @note    BLOCK-ONLY STUFF 
 * @return  a pointer to the data in a block.   
 * @param   thee  pointer to the block vector
 * @param   i     index of the block vector
 */
VEXTERNC double* Bvec_addrB(Bvec *thee, int i);

/** 
 * @ingroup Bvec
 * @brief   Return value of component of a vector.
 * @author  Michael Holst
 * @note    BLOCK-ONLY STUFF 
 * @return  value of component of a vector.
 * @param   thee  pointer to the block vector
 * @param   i     index of the block vector
 * @param   which index of the component in the vector
 */
VEXTERNC double Bvec_valB(Bvec *thee, int i, int which);

/** 
 * @ingroup Bvec
 * @brief   Set value of component of a vector.
 * @author  Michael Holst
 * @note    BLOCK-ONLY STUFF 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   i     index of the block vector
 * @param   which index of the component in the vector
 * @param   val   value of the i-th component of the block vector
 */
VEXTERNC void Bvec_setB(Bvec *thee, int i, int which, double val);

/** 
 * @ingroup Bvec
 * @brief   Add value to component of a vector. 
 * @author  Michael Holst
 * @note    BLOCK-ONLY STUFF 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   i     index of the block vector
 * @param   which index of the component in the vector
 * @param   val   value of the i-th component of the block vector
 */
VEXTERNC void Bvec_addToB(Bvec *thee, int i, int which, double val);

/** 
 * @ingroup Bvec
 * @brief   Initialize a particular block of a block vector. 
 * @author  Michael Holst
 * @note    BLOCK-ONLY STUFF 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   i     index of the block vector
 * @param   val   value of the i-th component of the block vector
 */
VEXTERNC void Bvec_initB(Bvec *thee, int i, double val);

/** 
 * @ingroup Bvec
 * @brief   Log of abs value of entries of block vector, shifted by < val >  
 * @author  Michael Holst
 * @note    BLOCK-ONLY STUFF 
 * @return  None
 * @param   thee  pointer to the block vector
 * @param   val   value of the i-th component of the block vector
 */
VEXTERNC void Bvec_absLog(Bvec *thee, double val);

/**
 * @ingroup Bvec
 * @brief   Executes one of a number of linear solvers. 
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bsolv.c) 
 * @return  None
 * @param   thee   pointer to the block vector
 * @param   A      system matrix
 * @param   f      source vector slot
 * @param   r      residual slot
 * @param   ut     block NODAL analytical solution
 * @param   key    index for different solution methods: 0=(Au=f), 1=(A'u=f)
 * @param   flag   index for i/o control
 * @param   itmax  number of iterations to do (the maximum allowed)
 * @param   etol   error tolerance
 * @param   prec   index for different preconditioners
 * @param   cycle  index for symmetric/nonsymmetric multigrids
 * @param   P      prolongation matrix maintained by aprx
 * @param   meth   method choice (0=slu,1=mg,2=cg,3=bcg,4=pcg,5=pbcg)
 */
VEXTERNC void Bvec_lmethod(Bvec *thee, Bmat *A, Bvec *f, Bvec *r, Bvec *ut,
    int key, int flag, int itmax, double etol, int prec, int cycle, Bmat *P,
    int meth);

/**
 * @ingroup Bvec
 * @brief   Sparse LU direct solver (requires only a nonsingular A).
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bsolv.c) 
 * @return  None
 * @param   thee   pointer to the block vector
 * @param   A      system matrix
 * @param   f      source vector slot
 * @param   r      residual slot
 * @param   ut     block NODAL analytical solution
 * @param   key    key ==0   --> Solve: A  u = f\n
 *                 key ==1   --> Solve: A' u = f  
 * @param   flag   Determines which "mode" we run in:\n
 *                 flag==0,2 --> Normal: normal i/o\n
 *                 flag==1,3 --> Silent: no i/o
 */
VEXTERNC void Bvec_slu(Bvec *thee, Bmat *A, Bvec *f, Bvec *r, Bvec *ut,
    int key, int flag);

/**
 * @ingroup Bvec
 * @brief   MG algorithm front end (NOT recursively callable).   
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bsolv.c)\n
 *          We use P to build an algebraic multilevel hierarchy in
 *          A,u(thee),f,r,ut from the fine-level-only representations,
 *          and then make the first call to the recursively-callable  
 *          core MG algorithm Bvec_mgCore(). 
 * @return  None
 * @param   thee   solution slot
 * @param   A      system matrix
 * @param   f      source vector slot
 * @param   r      residual slot
 * @param   ut     true solution slot
 * @param   key    just passed along to Bvec_mgCore()    
 * @param   flag   just passed along to Bvec_mgCore()    
 * @param   itmax  just passed along to Bvec_mgCore()    
 * @param   etol   just passed along to Bvec_mgCore()    
 * @param   prec   just passed along to Bvec_mgCore()    
 * @param   cycle  just passed along to Bvec_mgCore()    
 * @param   P      prolongation operators (linked list) 
 */
VEXTERNC void Bvec_mg(Bvec *thee, Bmat *A, Bvec *f, Bvec *r, Bvec *ut,
    int key, int flag, int itmax, double etol, int prec, int cycle, Bmat *P);

/**
 * @ingroup Bvec
 * @brief   Initialize the algebraic multilevel hierarchy for Bvec_mg
 * @authors Michael Holst and Stephan Bond
 * @note    Class Bvec: Non-inlineable methods (bsolv.c)\n
 *          We use P to build an algebraic multilevel hierarchy in
 *          A,u(thee),f,r,ut from the fine-level-only representations. 
 *          The vectors are created after the matrix to reduce the total 
 *          memory usage since Bmat_galerkin uses temporary arrays.  
 * @return  None
 * @param   thee   solution slot
 * @param   A      system matrix
 * @param   f      source vector slot
 * @param   r      residual slot
 * @param   P      prolongation operators (linked list)
 */
VEXTERNC void Bvec_mgInit(Bvec *thee, Bmat *A, Bvec *f, Bvec *r, Bmat *P);

/**
 * @ingroup Bvec
 * @brief   Destroy algebraic multilevel hierarchy created by Bvec_mgInit 
 * @authors Michael Holst and Stephan Bond
 * @note    Class Bvec: Non-inlineable methods (bsolv.c)\n
 *          Only the coarser level matrices and vectors are destructed. 
 * @return  None
 * @param   thee   solution slot
 * @param   A      system matrix
 * @param   f      source vector slot
 * @param   r      residual slot
 */
VEXTERNC void Bvec_mgDestroy(Bvec *thee, Bmat *A, Bvec *f, Bvec *r);

/**
 * @ingroup Bvec
 * @brief   CG method (ODIR algorithm, requires SPD operators A, B, and M).
 * @authors Michael Holst and Stephan Bond
 * @note    Class Bvec: Non-inlineable methods (bsolv.c)\n
 * @verbatim
 *           ODIR(M,B,A) (for Au=f, preconditioner B, inner-product M)
 *           ---------------------------------------------------------
 *
 *           Given u^0
 *           r^0 = f - A u^0
 *           p^0 = B r^0 / ||B r^0||
 *           for i=0,1,2,....
 *               alpha_i = <M e^i, p^i> / <M p^i, p^i>
 *               u^{i+1} = u^i + alpha_i p^i
 *               r^{i+1} = r^i - alpha_i A p^i
 *               gamma_i = <M B A p^i, p^i> / <M p^i, p^i>
 *               sigma_i = <M B A p^i, p^{i-1}> / <M p^{i-1}, p^{i-1}>
 *               v       = B A p^i - gamma_i p^i - sigma_i p^{i-1}
 *               p^{i+1} = v / ||v||
 *           end for
 *
 *           CG=ODIR(M=A,B=B,A=A)
 *           --------------------
 *
 *           Given u^0
 *           r^0 = f - A u^0
 *           p^0 = B r^0 / ||B r^0||
 *           for i=0,1,2,....
 *               alpha_i = <r^i, p^i> / <A p^i, p^i>
 *               u^{i+1} = u^i + alpha_i p^i
 *               r^{i+1} = r^i - alpha_i A p^i
 *               gamma_i = <B A p^i, A p^i> / <A p^i, p^i>
 *               sigma_i = <B A p^i, A p^{i-1}> / <A p^{i-1}, p^{i-1}>
 *               v       = B A p^i - gamma_i p^i - sigma_i p^{i-1}
 *               p^{i+1} = v / ||v||
 *           end for
 * @endverbatim
 * @return  None
 * @param   thee   pointer to the block vector
 * @param   A      system matrix
 * @param   f      source vector slot
 * @param   r      residual slot
 * @param   ut     block NODAL analytical solution
 * @param   key    index for different solution methods: 0=(Au=f), 1=(A'u=f)
 * @param   flag   0 --> Normal: check itmax, error tolerance; normal i/o\n
 *                 1 --> Silent: check only itmax; no i/o\n
 *                 2 --> Subcycle: check itmax, error tolerance; subcycle i/o\n
 *                 3 --> Subcycle: check itmax, error tolerance; no i/o
 * @param   itmax  number of iterations to do (the maximum allowed)
 * @param   etol   error tolerance
 * @param   prec   index for different preconditioners
 * @param   cycle  index for symmetric/nonsymmetric multigrids
 * @param   P      prolongation matrix maintained by aprx
 * @param   p      the block vector p
 * @param   ap     another block vector ap
 * @param   bap    third block vector bap
 * @param   po     the block vector po
 * @param   apo    the block vector apo
 * @param   tp     temporary block vector tp
 */
VEXTERNC void Bvec_cg(Bvec *thee, Bmat *A, Bvec *f, Bvec *r, Bvec *ut,
    int key, int flag, int itmax, double etol, int prec, int cycle, Bmat *P,
    Bvec *p, Bvec *ap, Bvec *bap, Bvec *po, Bvec *apo, Bvec *tp);

/**
 * @ingroup Bvec
 * @brief   BCG method (pure bi-orthogonal extension of CG). 
 * @author  Michael Holst
 * @note    Class Bvec: Non-inlineable methods (bsolv.c)\n
 *          This is a pure Petrov-Galerkin formulation of the 
 *          ODIR implementation of CG, and reduces to (exactly) 
 *          the ODIR implementation of CG in the case of a    
 *          symmetric (possibly indefinite) system matrix A and a  
 *          symmetric (possibly indefinite) preconditioner B.   
 *          (However, the operation count of BCG is rougly double
 *          that of CG.)    
 * @verbatim
 *           PG-ODIR(M,B,A) (for Au=f, preconditioner B, inner-product M)
 *           ------------------------------------------------------------
 *
 *           Given u^0
 *           r^0 = f - A  u^0
 *           s^0 = f - A' u^0
 *           p^0 = B r^0 / ||B r^0||
 *           q^0 = B's^0 / ||B's^0||
 *           for i=0,1,2,....
 *               alpha_i = <M e^i, q^i> / <M p^i, q^i>
 *               u^{i+1} = u^i + alpha_i p^i
 *               r^{i+1} = r^i - alpha_i A p^i
 *               gamma_i = <M B A p^i, q^i> / <M p^i, q^i>
 *               sigma_i = <M B A p^i, q^{i-1}> / <M p^{i-1}, q^{i-1}>
 *               delta_i = <M B A p^{i-1}, q^i> / <M p^{i-1}, q^{i-1}>
 *               v       = B A  p^i - gamma_i p^i - sigma_i p^{i-1}
 *               w       = B'A' q^i - gamma_i q^i - delta_i q^{i-1}
 *               p^{i+1} = v / ||v||
 *               q^{i+1} = w / ||w||
 *           end for
 *
 *           BCG=PG-ODIR(M=A,B=B,A=A)
 *           ------------------------
 *           Given u^0
 *           r^0 = f - A  u^0
 *           s^0 = f - A' u^0
 *           p^0 = B r^0 / ||B r^0||
 *           q^0 = B's^0 / ||B's^0||
 *           for i=0,1,2,....
 *               alpha_i = <r^i, q^i> / <A p^i, q^i>
 *               u^{i+1} = u^i + alpha_i p^i
 *               r^{i+1} = r^i - alpha_i A p^i
 *               gamma_i = <B A p^i, A' q^i> / <A p^i, q^i>
 *               sigma_i = <B A p^i, A' q^{i-1}> / <A p^{i-1}, q^{i-1}>
 *               delta_i = <A p^{i-1}, B'A' q^i> / <A p^{i-1}, q^{i-1}>
 *               v       = B A  p^i - gamma_i p^i - sigma_i p^{i-1}
 *               w       = B'A' q^i - gamma_i q^i - delta_i q^{i-1}
 *               p^{i+1} = v / ||v||
 *               q^{i+1} = w / ||w||
 *           end for
 * @endverbatim
 * @return  None
 * @param   thee   pointer to the block vector
 * @param   A      system matrix
 * @param   f      source vector slot
 * @param   r      residual slot
 * @param   ut     block NODAL analytical solution
 * @param   key    smooth with A or A' (0=A, 1=A')
 * @param   flag   determines which "mode" we run in:\n
 *                 0 --> Normal: check itmax, error tolerance; normal i/o\n
 *                 1 --> Silent: check only itmax; no i/o\n
 *                 2 --> Subcycle: check itmax, error tolerance; subcycle i/o\n
 *                 3 --> Subcycle: check itmax, error tolerance; no i/o
 * @param   itmax  number of iterations to do (the maximum allowed)
 * @param   etol   error tolerance
 * @param   prec   index for different preconditioners
 * @param   cycle  index for symmetric/nonsymmetric multigrids
 * @param   P      prolongation matrix maintained by aprx
 * @param   s      residual block vector s: f - A'u
 * @param   p      the block vector p
 * @param   ap     another block vector ap
 * @param   bap    third block vector bap
 * @param   po     the block vector po
 * @param   apo    the block vector apo
 * @param   q      the block vector q
 * @param   atq    the block vector atq
 * @param   btatq  the block vector btatq
 * @param   qo     the block vector qo
 * @param   atqo   the block vector atqo
 */
VEXTERNC void Bvec_bcg(Bvec *thee, Bmat *A, Bvec *f, Bvec *r, Bvec *ut,
    int key, int flag, int itmax, double etol, int prec, int cycle, Bmat *P,
    Bvec *s,
    Bvec *p, Bvec *ap,  Bvec *bap,  Bvec *po,  Bvec *apo,
    Bvec *q, Bvec *atq, Bvec *btatq, Bvec *qo, Bvec *atqo);

/**
 * @ingroup Bvec
 * @brief   Calculate the eigenvector corresponding to the second smallest 
 *          eigenvalue of the given (symmetric adjacency) matrix.  
 * @author  Michael Holst 
 * @note    Class Bvec: Non-inlineable methods (bsolv.c)\n\n
 *          We make the following assumptions about the matrix A, which
 *          are valid when A is the adjaceny matrix of a simplex mesh
 *          (e.g., the laplace operator for the dual mesh):  \n\n
 *          (1) A is symmetric positive semi-definite\n
 *          (2) A is singular with null space of dimension 1\n
 *          (3) A has a unique smallest eigenvalue "0" and a   
 *              corresponding unique (up to constant multiplier)
 *              eigenvector (or null vector) representing the set of           
 *              constant vectors.\n\n
 *          Note that since A is symmetric, it has a complete set of   
 *          orthonormal eigenvectors. \n\n
 *          The algorithm we employ here is a simple inverse iteration  
 *          (or Rayleigh quotient iteration) which pulls out the  
 *          second smallest eigenvalue (the smallest positive eigenvalue)    
 *          and the corresponding eigenvector.  The algorithm simply  
 *          does a sequence of inexact inverse iterations, while    
 *          repeatedly orthogonalizing the computed eigenvector against
 *          the unique null vector of constants.   The inverse step  
 *          damps out all eigendirections other than the smallest, and
 *          the orthgonalizing step removes the smallest eigen direction.\n\n
 *          On convergence (change in eigenvector meets a tolerance) then 
 *          we generate the corresponding eigenvalue with a final   
 *          Rayleigh quotient.  
 * @return  None
 * @param   thee   pointer to the block vector
 * @param   A      system matrix
 * @param   litmax number of iterations to do (the maximum allowed)
 * @param   letol  error tolerance
 * @param   lambda Point to the eigenvalue
 * @param   key    smooth with A or A' (0=A, 1=A')
 * @param   flag   determines which "mode" we run in:\n
 *                 0 --> Normal: check itmax, error tolerance; normal i/o\n
 *                 1 --> Silent: check only itmax; no i/o\n
 *                 2 --> Subcycle: check itmax, error tolerance; subcycle i/o\n
 *                 3 --> Subcycle: check itmax, error tolerance; no i/o
 * @param   itmax  number of iterations to do (the maximum allowed)
 * @param   etol   error tolerance
 */
VEXTERNC void Bvec_eig(Bvec *thee, Bmat *A,
    int litmax, double letol, double *lambda,
    int key, int flag, int itmax, double etol);

#endif /* _BVEC_H_ */