$extrastylesheet
type_tensor.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 
00019 
00020 
00021 // C++ includes
00022 #include <iostream>
00023 #include <iomanip> // for std::setw, std::setiosflags
00024 
00025 // Local includes
00026 #include "libmesh/type_tensor.h"
00027 
00028 namespace libMesh
00029 {
00030 
00031 
00032 
00033 
00034 // ------------------------------------------------------------
00035 // TypeTensor<T> class member funcions
00036 
00037 
00038 template <typename T>
00039 void TypeTensor<T>::print(std::ostream& os) const
00040 {
00041 #if LIBMESH_DIM == 1
00042 
00043   os << "x=" << (*this)(0,0) << std::endl;
00044 
00045 #endif
00046 #if LIBMESH_DIM == 2
00047 
00048   os << "(xx,xy)=("
00049      << std::setw(8) << (*this)(0,0) << ", "
00050      << std::setw(8) << (*this)(0,1) << ")"
00051      << std::endl;
00052   os << "(yx,yy)=("
00053      << std::setw(8) << (*this)(1,0) << ", "
00054      << std::setw(8) << (*this)(1,1) << ")"
00055      << std::endl;
00056 
00057 #endif
00058 #if LIBMESH_DIM == 3
00059 
00060   os <<  "(xx,xy,xz)=("
00061      << std::setw(8) << (*this)(0,0) << ", "
00062      << std::setw(8) << (*this)(0,1) << ", "
00063      << std::setw(8) << (*this)(0,2) << ")"
00064      << std::endl;
00065   os <<  "(yx,yy,yz)=("
00066      << std::setw(8) << (*this)(1,0) << ", "
00067      << std::setw(8) << (*this)(1,1) << ", "
00068      << std::setw(8) << (*this)(1,2) << ")"
00069      << std::endl;
00070   os <<  "(zx,zy,zz)=("
00071      << std::setw(8) << (*this)(2,0) << ", "
00072      << std::setw(8) << (*this)(2,1) << ", "
00073      << std::setw(8) << (*this)(2,2) << ")"
00074      << std::endl;
00075 #endif
00076 }
00077 
00078 
00079 
00080 
00081 
00082 template <typename T>
00083 void TypeTensor<T>::write_unformatted (std::ostream &out_stream,
00084                                        const bool newline) const
00085 {
00086   libmesh_assert (out_stream);
00087 
00088   out_stream << std::setiosflags(std::ios::showpoint)
00089              << (*this)(0,0) << " "
00090              << (*this)(0,1) << " "
00091              << (*this)(0,2) << " ";
00092   if (newline)
00093     out_stream << '\n';
00094 
00095   out_stream << std::setiosflags(std::ios::showpoint)
00096              << (*this)(1,0) << " "
00097              << (*this)(1,1) << " "
00098              << (*this)(1,2) << " ";
00099   if (newline)
00100     out_stream << '\n';
00101 
00102   out_stream << std::setiosflags(std::ios::showpoint)
00103              << (*this)(2,0) << " "
00104              << (*this)(2,1) << " "
00105              << (*this)(2,2) << " ";
00106   if (newline)
00107     out_stream << '\n';
00108 }
00109 
00110 
00111 
00112 template <>
00113 bool TypeTensor<Real>::operator < (const TypeTensor<Real>& rhs) const
00114 {
00115   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00116     for (unsigned int j=0; j<LIBMESH_DIM; j++)
00117       {
00118         if ((*this)(i,j) < rhs(i,j))
00119           return true;
00120         if ((*this)(i,j) > rhs(i,j))
00121           return false;
00122       }
00123   return false;
00124 }
00125 
00126 
00127 
00128 template <>
00129 bool TypeTensor<Real>::operator > (const TypeTensor<Real>& rhs) const
00130 {
00131   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00132     for (unsigned int j=0; j<LIBMESH_DIM; j++)
00133       {
00134         if ((*this)(i,j) > rhs(i,j))
00135           return true;
00136         if ((*this)(i,j) < rhs(i,j))
00137           return false;
00138       }
00139   return false;
00140 }
00141 
00142 
00143 
00144 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
00145 template <>
00146 bool TypeTensor<Complex>::operator < (const TypeTensor<Complex>& rhs) const
00147 {
00148   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00149     for (unsigned int j=0; j<LIBMESH_DIM; j++)
00150       {
00151         if ((*this)(i,j).real() < rhs(i,j).real())
00152           return true;
00153         if ((*this)(i,j).real() > rhs(i,j).real())
00154           return false;
00155         if ((*this)(i,j).imag() < rhs(i,j).imag())
00156           return true;
00157         if ((*this)(i,j).imag() > rhs(i,j).imag())
00158           return false;
00159       }
00160   return false;
00161 }
00162 
00163 
00164 
00165 template <>
00166 bool TypeTensor<Complex>::operator > (const TypeTensor<Complex>& rhs) const
00167 {
00168   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00169     for (unsigned int j=0; j<LIBMESH_DIM; j++)
00170       {
00171         if ((*this)(i,j).real() > rhs(i,j).real())
00172           return true;
00173         if ((*this)(i,j).real() < rhs(i,j).real())
00174           return false;
00175         if ((*this)(i,j).imag() > rhs(i,j).imag())
00176           return true;
00177         if ((*this)(i,j).imag() < rhs(i,j).imag())
00178           return false;
00179       }
00180   return false;
00181 }
00182 
00183 
00184 
00185 #endif
00186 
00187 
00188 
00189 // ------------------------------------------------------------
00190 // Explicit instantiations
00191 template class TypeTensor<Real>;
00192 
00193 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
00194 template class TypeTensor<Complex>;
00195 #endif
00196 
00197 } // namespace libMesh