00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "dblock.h"
00023
00024 namespace matvec {
00025
00026 Dblock::Dblock (int nd, int nr, int nc){
00027 if (nd<=0) {
00028 std::cerr <<"Depth of block is not positive \n" << std::flush;
00029 }
00030 else if (nr<=0) {
00031 std::cerr <<"Number of rows Block is not positive \n" << std::flush;
00032 }
00033 else if (nc<=0) {
00034 std::cerr <<"Number of columns Block is not positive \n" << std::flush;
00035 }
00036 else {
00037 ndim=nd;
00038 nrow=nr;
00039 ncol=nc;
00040 block.resize(nd);
00041 for (int i=1;i<=nd;i++){
00042 block(i).resize(nr,nc);
00043 }
00044 }
00045 }
00046
00047 void Dblock::resize (int nd, int nr, int nc){
00048 if (nd<=0) {
00049 std::cerr <<"Depth of block is not positive \n" << std::flush;
00050 }
00051 else if (nr<=0) {
00052 std::cerr <<"Number of rows Block is not positive \n" << std::flush;
00053 }
00054 else if (nc<=0) {
00055 std::cerr <<"Number of columns Block is not positive \n" << std::flush;
00056 }
00057 else {
00058 ndim=nd;
00059 nrow=nr;
00060 ncol=nc;
00061 block.resize(nd);
00062 for (int i=1;i<=nd;i++){
00063 block(i).resize(nr,nc);
00064 }
00065 }
00066 }
00067
00068 void Dblock::resize (int nd, int nr, int nc, double init){
00069 if (nd<=0) {
00070 std::cerr <<"Depth of block is not positive \n" << std::flush;
00071 }
00072 else if (nr<=0) {
00073 std::cerr <<"Number of rows Block is not positive \n" << std::flush;
00074 }
00075 else if (nc<=0) {
00076 std::cerr <<"Number of columns Block is not positive \n" << std::flush;
00077 }
00078 else {
00079 ndim=nd;
00080 nrow=nr;
00081 ncol=nc;
00082 block.resize(nd);
00083 for (int i=1;i<=nd;i++){
00084 block(i).resize(nr,nc,init);
00085 }
00086 }
00087 }
00088
00089 void Dblock::init(double val){
00090 int i,j,k;
00091 for (i=0;i<ndim;i++){
00092 for (j=0;j<nrow;j++){
00093 for (k=0;k<ncol;k++){
00094 block[i][j][k]=val;
00095 }
00096 }
00097 }
00098 }
00099
00100 std::ostream& operator << (std::ostream &stream, Dblock& D)
00101 {
00102 stream << "\n";
00103 int k,i,j,jstart,jend,ncols_remaining;
00104
00105 for (k=1;k<=D.ndim; k++){
00106 ncols_remaining = D.ncol;
00107 jend = 0;
00108 while (ncols_remaining > 0) {
00109 jstart = jend + 1;
00110 jend = jstart + ncols_remaining - 1;
00111 ncols_remaining -= 10;
00112 if (ncols_remaining < 0) {
00113 ncols_remaining = 0;
00114 }
00115 else {
00116 jend = jstart + 9;
00117 }
00118 stream << "\n Block " << k <<"\n" << " ";
00119 stream.width(2);
00120 for (j=jstart;j<=jend;j++){
00121 stream << " column " << j;
00122 }
00123 stream << "\n";
00124 for (i=1;i<=D.nrow; i++) {
00125 stream << "\n" << "Row ";
00126 stream.width(4);
00127 stream << i << " ";
00128 for (j=jstart;j<=jend;j++){
00129 stream.width(9);
00130 stream << D(k,i,j);
00131 }
00132 }
00133 }
00134 stream << "\n" ;
00135 }
00136 stream << "\n" << "\n" ;
00137 return stream;
00138 }
00139 }