dense_matrix_base.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 // C++ includes
19 #include <iomanip> // for std::setw()
20 
21 // Local Includes
24 
25 namespace libMesh
26 {
27 
28 
29 
30 template<typename T>
32  const DenseMatrixBase<T> & M2,
33  const DenseMatrixBase<T> & M3)
34 {
35  // Assertions to make sure we have been
36  // passed matrices of the correct dimension.
37  libmesh_assert_equal_to (M1.m(), M2.m());
38  libmesh_assert_equal_to (M1.n(), M3.n());
39  libmesh_assert_equal_to (M2.n(), M3.m());
40 
41  const unsigned int m_s = M2.m();
42  const unsigned int p_s = M2.n();
43  const unsigned int n_s = M1.n();
44 
45  // Do it this way because there is a
46  // decent chance (at least for constraint matrices)
47  // that M3(k,j) = 0. when right-multiplying.
48  for (unsigned int k=0; k<p_s; k++)
49  for (unsigned int j=0; j<n_s; j++)
50  if (M3.el(k,j) != 0.)
51  for (unsigned int i=0; i<m_s; i++)
52  M1.el(i,j) += M2.el(i,k) * M3.el(k,j);
53 }
54 
55 
56 
57 template<typename T>
58 void DenseMatrixBase<T>::condense(const unsigned int iv,
59  const unsigned int jv,
60  const T val,
61  DenseVectorBase<T> & rhs)
62 {
63  libmesh_assert_equal_to (this->_m, rhs.size());
64  libmesh_assert_equal_to (iv, jv);
65 
66 
67  // move the known value into the RHS
68  // and zero the column
69  for (unsigned int i=0; i<this->m(); i++)
70  {
71  rhs.el(i) -= this->el(i,jv)*val;
72  this->el(i,jv) = 0.;
73  }
74 
75  // zero the row
76  for (unsigned int j=0; j<this->n(); j++)
77  this->el(iv,j) = 0.;
78 
79  this->el(iv,jv) = 1.;
80  rhs.el(iv) = val;
81 
82 }
83 
84 
85 template<typename T>
86 void DenseMatrixBase<T>::print_scientific (std::ostream & os, unsigned precision) const
87 {
88  // save the initial format flags
89  std::ios_base::fmtflags os_flags = os.flags();
90 
91  // Print the matrix entries.
92  for (unsigned int i=0; i<this->m(); i++)
93  {
94  for (unsigned int j=0; j<this->n(); j++)
95  os << std::setw(15)
96  << std::scientific
97  << std::setprecision(precision)
98  << this->el(i,j) << " ";
99 
100  os << std::endl;
101  }
102 
103  // reset the original format flags
104  os.flags(os_flags);
105 }
106 
107 
108 
109 template<typename T>
110 void DenseMatrixBase<T>::print (std::ostream & os) const
111 {
112  for (unsigned int i=0; i<this->m(); i++)
113  {
114  for (unsigned int j=0; j<this->n(); j++)
115  os << std::setw(8)
116  << this->el(i,j) << " ";
117 
118  os << std::endl;
119  }
120 
121  return;
122 }
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 //--------------------------------------------------------------
133 // Explicit instantiations
134 template class DenseMatrixBase<Real>;
135 
136 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
137 template class DenseMatrixBase<Complex>;
138 #endif
139 
140 } // namespace libMesh
unsigned int m() const
void print(std::ostream &os=libMesh::out) const
virtual T el(const unsigned int i, const unsigned int j) const =0
virtual unsigned int size() const =0
void print_scientific(std::ostream &os, unsigned precision=8) const
static void multiply(DenseMatrixBase< T > &M1, const DenseMatrixBase< T > &M2, const DenseMatrixBase< T > &M3)
unsigned int n() const
virtual T el(const unsigned int i) const =0
void condense(const unsigned int i, const unsigned int j, const T val, DenseVectorBase< T > &rhs)