00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_LAPLACIAN_SETUP_INCLUDE
00013 #define MTL_LAPLACIAN_SETUP_INCLUDE
00014
00015 #include <boost/numeric/mtl/matrix/inserter.hpp>
00016 #include <boost/numeric/mtl/operation/set_to_zero.hpp>
00017
00018 namespace mtl { namespace matrix {
00019
00021
00023 template <typename Matrix>
00024 inline void laplacian_setup(Matrix& matrix, unsigned m, unsigned n)
00025 {
00026 matrix.change_dim(m*n, m*n);
00027 set_to_zero(matrix);
00028 inserter<Matrix> ins(matrix);
00029
00030 for (unsigned i= 0; i < m; i++)
00031 for (unsigned j= 0; j < n; j++) {
00032 typename Collection<Matrix>::value_type four(4.0), minus_one(-1.0);
00033 unsigned row= i * n + j;
00034 ins(row, row) << four;
00035 if (j < n-1) ins(row, row+1) << minus_one;
00036 if (i < m-1) ins(row, row+n) << minus_one;
00037 if (j > 0) ins(row, row-1) << minus_one;
00038 if (i > 0) ins(row, row-n) << minus_one;
00039 }
00040 }
00041
00042 }}
00043
00044 #endif // MTL_LAPLACIAN_SETUP_INCLUDE