$extrastylesheet
type_vector.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_vector.h"
00027 
00028 namespace libMesh
00029 {
00030 
00031 
00032 
00033 
00034 // ------------------------------------------------------------
00035 // TypeVector<T> class member funcions
00036 template <typename T>
00037 TypeVector<T> TypeVector<T>::unit() const
00038 {
00039 
00040   const Real length = size();
00041 
00042   libmesh_assert_not_equal_to (length, static_cast<Real>(0.));
00043 
00044 #if LIBMESH_DIM == 1
00045   return TypeVector<T>(_coords[0]/length);
00046 #endif
00047 
00048 #if LIBMESH_DIM == 2
00049   return TypeVector<T>(_coords[0]/length,
00050                        _coords[1]/length);
00051 #endif
00052 
00053 #if LIBMESH_DIM == 3
00054   return TypeVector<T>(_coords[0]/length,
00055                        _coords[1]/length,
00056                        _coords[2]/length);
00057 #endif
00058 
00059 }
00060 
00061 
00062 
00063 template <typename T>
00064 void TypeVector<T>::print(std::ostream& os) const
00065 {
00066 #if LIBMESH_DIM == 1
00067 
00068   os << "x=" << (*this)(0);
00069 
00070 #endif
00071 #if LIBMESH_DIM == 2
00072 
00073   os << "(x,y)=("
00074      << std::setw(8) << (*this)(0) << ", "
00075      << std::setw(8) << (*this)(1) << ")";
00076 
00077 #endif
00078 #if LIBMESH_DIM == 3
00079 
00080   os <<  "(x,y,z)=("
00081      << std::setw(8) << (*this)(0) << ", "
00082      << std::setw(8) << (*this)(1) << ", "
00083      << std::setw(8) << (*this)(2) << ")";
00084 #endif
00085 }
00086 
00087 
00088 
00089 
00090 
00091 template <typename T>
00092 void TypeVector<T>::write_unformatted (std::ostream &os,
00093                                        const bool newline) const
00094 {
00095   libmesh_assert (os);
00096 
00097   os << std::setiosflags(std::ios::showpoint)
00098      << (*this)(0) << " "
00099      << (*this)(1) << " "
00100      << (*this)(2) << " ";
00101 
00102   if (newline)
00103     os << '\n';
00104 }
00105 
00106 
00107 
00108 template <typename T>
00109 bool TypeVector<T>::operator < (const TypeVector<T>& rhs) const
00110 {
00111   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00112     {
00113       if ((*this)(i) < rhs(i))
00114         return true;
00115       if ((*this)(i) > rhs(i))
00116         return false;
00117     }
00118   return false;
00119 }
00120 
00121 
00122 template <typename T>
00123 bool TypeVector<T>::operator <= (const TypeVector<T>& rhs) const
00124 {
00125   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00126     {
00127       if ((*this)(i) < rhs(i))
00128         return true;
00129       if ((*this)(i) > rhs(i))
00130         return false;
00131     }
00132   return true;
00133 }
00134 
00135 
00136 
00137 template <typename T>
00138 bool TypeVector<T>::operator > (const TypeVector<T>& rhs) const
00139 {
00140   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00141     {
00142       if ((*this)(i) > rhs(i))
00143         return true;
00144       if ((*this)(i) < rhs(i))
00145         return false;
00146     }
00147   return false;
00148 }
00149 
00150 
00151 template <typename T>
00152 bool TypeVector<T>::operator >= (const TypeVector<T>& rhs) const
00153 {
00154   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00155     {
00156       if ((*this)(i) > rhs(i))
00157         return true;
00158       if ((*this)(i) < rhs(i))
00159         return false;
00160     }
00161   return true;
00162 }
00163 
00164 
00165 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
00166 template <>
00167 bool TypeVector<Complex>::operator < (const TypeVector<Complex>& rhs) const
00168 {
00169   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00170     {
00171       if ((*this)(i).real() < rhs(i).real())
00172         return true;
00173       if ((*this)(i).real() > rhs(i).real())
00174         return false;
00175       if ((*this)(i).imag() < rhs(i).imag())
00176         return true;
00177       if ((*this)(i).imag() > rhs(i).imag())
00178         return false;
00179     }
00180   return false;
00181 }
00182 
00183 
00184 
00185 template <>
00186 bool TypeVector<Complex>::operator <= (const TypeVector<Complex>& rhs) const
00187 {
00188   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00189     {
00190       if ((*this)(i).real() < rhs(i).real())
00191         return true;
00192       if ((*this)(i).real() > rhs(i).real())
00193         return false;
00194       if ((*this)(i).imag() < rhs(i).imag())
00195         return true;
00196       if ((*this)(i).imag() > rhs(i).imag())
00197         return false;
00198     }
00199   return true;
00200 }
00201 
00202 
00203 
00204 template <>
00205 bool TypeVector<Complex>::operator > (const TypeVector<Complex>& rhs) const
00206 {
00207   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00208     {
00209       if ((*this)(i).real() > rhs(i).real())
00210         return true;
00211       if ((*this)(i).real() < rhs(i).real())
00212         return false;
00213       if ((*this)(i).imag() > rhs(i).imag())
00214         return true;
00215       if ((*this)(i).imag() < rhs(i).imag())
00216         return false;
00217     }
00218   return false;
00219 }
00220 
00221 
00222 
00223 template <>
00224 bool TypeVector<Complex>::operator >= (const TypeVector<Complex>& rhs) const
00225 {
00226   for (unsigned int i=0; i<LIBMESH_DIM; i++)
00227     {
00228       if ((*this)(i).real() > rhs(i).real())
00229         return true;
00230       if ((*this)(i).real() < rhs(i).real())
00231         return false;
00232       if ((*this)(i).imag() > rhs(i).imag())
00233         return true;
00234       if ((*this)(i).imag() < rhs(i).imag())
00235         return false;
00236     }
00237   return true;
00238 }
00239 
00240 #endif
00241 
00242 
00243 
00244 // ------------------------------------------------------------
00245 // Explicit instantiations
00246 template class TypeVector<Real>;
00247 
00248 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
00249 template class TypeVector<Complex>;
00250 #endif
00251 
00252 } // namespace libMesh