$extrastylesheet
dense_matrix_base.C
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 // C++ includes
00019 #include <iomanip> // for std::setw()
00020 
00021 // Local Includes
00022 #include "libmesh/dense_matrix_base.h"
00023 #include "libmesh/dense_vector_base.h"
00024 
00025 namespace libMesh
00026 {
00027 
00028 
00029 
00030 template<typename T>
00031 void DenseMatrixBase<T>::multiply (DenseMatrixBase<T>& M1,
00032                                    const DenseMatrixBase<T>& M2,
00033                                    const DenseMatrixBase<T>& M3)
00034 {
00035   // Assertions to make sure we have been
00036   // passed matrices of the correct dimension.
00037   libmesh_assert_equal_to (M1.m(), M2.m());
00038   libmesh_assert_equal_to (M1.n(), M3.n());
00039   libmesh_assert_equal_to (M2.n(), M3.m());
00040 
00041   const unsigned int m_s = M2.m();
00042   const unsigned int p_s = M2.n();
00043   const unsigned int n_s = M1.n();
00044 
00045   // Do it this way because there is a
00046   // decent chance (at least for constraint matrices)
00047   // that M3(k,j) = 0. when right-multiplying.
00048   for (unsigned int k=0; k<p_s; k++)
00049     for (unsigned int j=0; j<n_s; j++)
00050       if (M3.el(k,j) != 0.)
00051         for (unsigned int i=0; i<m_s; i++)
00052           M1.el(i,j) += M2.el(i,k) * M3.el(k,j);
00053 }
00054 
00055 
00056 
00057 template<typename T>
00058 void DenseMatrixBase<T>::condense(const unsigned int iv,
00059                                   const unsigned int jv,
00060                                   const T val,
00061                                   DenseVectorBase<T>& rhs)
00062 {
00063   libmesh_assert_equal_to (this->_m, rhs.size());
00064   libmesh_assert_equal_to (iv, jv);
00065 
00066 
00067   // move the known value into the RHS
00068   // and zero the column
00069   for (unsigned int i=0; i<this->m(); i++)
00070     {
00071       rhs.el(i) -= this->el(i,jv)*val;
00072       this->el(i,jv) = 0.;
00073     }
00074 
00075   // zero the row
00076   for (unsigned int j=0; j<this->n(); j++)
00077     this->el(iv,j) = 0.;
00078 
00079   this->el(iv,jv) = 1.;
00080   rhs.el(iv) = val;
00081 
00082 }
00083 
00084 
00085 template<typename T>
00086 void DenseMatrixBase<T>::print_scientific (std::ostream& os) const
00087 {
00088 #ifndef LIBMESH_BROKEN_IOSTREAM
00089 
00090   // save the initial format flags
00091   std::ios_base::fmtflags os_flags = os.flags();
00092 
00093   // Print the matrix entries.
00094   for (unsigned int i=0; i<this->m(); i++)
00095     {
00096       for (unsigned int j=0; j<this->n(); j++)
00097         os << std::setw(15)
00098            << std::scientific
00099            << std::setprecision(8)
00100            << this->el(i,j) << " ";
00101 
00102       os << std::endl;
00103     }
00104 
00105   // reset the original format flags
00106   os.flags(os_flags);
00107 
00108 #else
00109 
00110   // Print the matrix entries.
00111   for (unsigned int i=0; i<this->m(); i++)
00112     {
00113       for (unsigned int j=0; j<this->n(); j++)
00114         os << std::setprecision(8)
00115            << this->el(i,j)
00116            << " ";
00117 
00118       os << std::endl;
00119     }
00120 
00121 
00122 #endif
00123 }
00124 
00125 
00126 
00127 template<typename T>
00128 void DenseMatrixBase<T>::print (std::ostream& os) const
00129 {
00130   for (unsigned int i=0; i<this->m(); i++)
00131     {
00132       for (unsigned int j=0; j<this->n(); j++)
00133         os << std::setw(8)
00134            << this->el(i,j) << " ";
00135 
00136       os << std::endl;
00137     }
00138 
00139   return;
00140 }
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 //--------------------------------------------------------------
00151 // Explicit instantiations
00152 template class DenseMatrixBase<Real>;
00153 
00154 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
00155 template class DenseMatrixBase<Complex>;
00156 #endif
00157 
00158 } // namespace libMesh