$extrastylesheet
coupling_matrix.h
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 
00019 
00020 #ifndef LIBMESH_COUPLING_MATRIX_H
00021 #define LIBMESH_COUPLING_MATRIX_H
00022 
00023 // Local Includes
00024 #include "libmesh/libmesh_common.h"
00025 
00026 // C++ includes
00027 #include <vector>
00028 
00029 namespace libMesh
00030 {
00031 
00032 
00033 
00034 
00042 class CouplingMatrix
00043 {
00044 public:
00045 
00049   explicit
00050   CouplingMatrix (const unsigned int n=0);
00051 
00055   unsigned char operator() (const unsigned int i,
00056                             const unsigned int j) const;
00057 
00062   unsigned char & operator() (const unsigned int i,
00063                               const unsigned int j);
00064 
00069   unsigned int size() const;
00070 
00075   void resize(const unsigned int n);
00076 
00080   void clear();
00081 
00085   bool empty() const;
00086 
00087 private:
00088 
00095   std::vector<unsigned char> _values;
00096 
00100   unsigned int _size;
00101 };
00102 
00103 
00104 
00105 
00106 
00107 
00108 //--------------------------------------------------
00109 // CouplingMatrix inline methods
00110 inline
00111 CouplingMatrix::CouplingMatrix (const unsigned int n) :
00112   _values(), _size(n)
00113 {
00114   this->resize(n);
00115 }
00116 
00117 
00118 
00119 inline
00120 unsigned char CouplingMatrix::operator() (const unsigned int i,
00121                                           const unsigned int j) const
00122 {
00123   libmesh_assert_less (i, _size);
00124   libmesh_assert_less (j, _size);
00125 
00126   return _values[i*_size + j];
00127 }
00128 
00129 
00130 
00131 inline
00132 unsigned char & CouplingMatrix::operator() (const unsigned int i,
00133                                             const unsigned int j)
00134 {
00135   libmesh_assert_less (i, _size);
00136   libmesh_assert_less (j, _size);
00137 
00138   return _values[i*_size + j];
00139 }
00140 
00141 
00142 
00143 inline
00144 unsigned int CouplingMatrix::size() const
00145 {
00146   return _size;
00147 }
00148 
00149 
00150 
00151 inline
00152 void CouplingMatrix::resize(const unsigned int n)
00153 {
00154   _size = n;
00155 
00156   _values.resize(_size*_size);
00157 
00158   for (unsigned int i=0; i<_values.size(); i++)
00159     _values[i] = 0;
00160 }
00161 
00162 
00163 
00164 inline
00165 void CouplingMatrix::clear()
00166 {
00167   _size = 0;
00168 
00169   _values.clear();
00170 }
00171 
00172 
00173 
00174 inline
00175 bool CouplingMatrix::empty() const
00176 {
00177   return (_size == 0);
00178 }
00179 
00180 
00181 } // namespace libMesh
00182 
00183 
00184 #endif // LIBMESH_COUPLING_MATRIX_H