type_vector.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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 
19 
20 
21 // C++ includes
22 #include <iostream>
23 #include <iomanip> // for std::setw, std::setiosflags
24 
25 // Local includes
26 #include "libmesh/type_vector.h"
27 
28 namespace libMesh
29 {
30 
31 
32 
33 
34 // ------------------------------------------------------------
35 // TypeVector<T> class member funcions
36 template <typename T>
38 {
39 
40  const Real length = size();
41 
42  libmesh_assert_not_equal_to (length, static_cast<Real>(0.));
43 
44 #if LIBMESH_DIM == 1
45  return TypeVector<T>(_coords[0]/length);
46 #endif
47 
48 #if LIBMESH_DIM == 2
49  return TypeVector<T>(_coords[0]/length,
50  _coords[1]/length);
51 #endif
52 
53 #if LIBMESH_DIM == 3
54  return TypeVector<T>(_coords[0]/length,
55  _coords[1]/length,
56  _coords[2]/length);
57 #endif
58 
59 }
60 
61 
62 
63 template <typename T>
64 void TypeVector<T>::print(std::ostream& os) const
65 {
66 #if LIBMESH_DIM == 1
67 
68  os << "x=" << (*this)(0);
69 
70 #endif
71 #if LIBMESH_DIM == 2
72 
73  os << "(x,y)=("
74  << std::setw(8) << (*this)(0) << ", "
75  << std::setw(8) << (*this)(1) << ")";
76 
77 #endif
78 #if LIBMESH_DIM == 3
79 
80  os << "(x,y,z)=("
81  << std::setw(8) << (*this)(0) << ", "
82  << std::setw(8) << (*this)(1) << ", "
83  << std::setw(8) << (*this)(2) << ")";
84 #endif
85 }
86 
87 
88 
89 
90 
91 template <typename T>
92 void TypeVector<T>::write_unformatted (std::ostream &os,
93  const bool newline) const
94 {
95  libmesh_assert (os);
96 
97  os << std::setiosflags(std::ios::showpoint)
98  << (*this)(0) << " "
99  << (*this)(1) << " "
100  << (*this)(2) << " ";
101 
102  if (newline)
103  os << '\n';
104 }
105 
106 
107 
108 template <typename T>
110 {
111  for (unsigned int i=0; i<LIBMESH_DIM; i++)
112  {
113  if ((*this)(i) < rhs(i))
114  return true;
115  if ((*this)(i) > rhs(i))
116  return false;
117  }
118  return false;
119 }
120 
121 
122 template <typename T>
124 {
125  for (unsigned int i=0; i<LIBMESH_DIM; i++)
126  {
127  if ((*this)(i) < rhs(i))
128  return true;
129  if ((*this)(i) > rhs(i))
130  return false;
131  }
132  return true;
133 }
134 
135 
136 
137 template <typename T>
139 {
140  for (unsigned int i=0; i<LIBMESH_DIM; i++)
141  {
142  if ((*this)(i) > rhs(i))
143  return true;
144  if ((*this)(i) < rhs(i))
145  return false;
146  }
147  return false;
148 }
149 
150 
151 template <typename T>
153 {
154  for (unsigned int i=0; i<LIBMESH_DIM; i++)
155  {
156  if ((*this)(i) > rhs(i))
157  return true;
158  if ((*this)(i) < rhs(i))
159  return false;
160  }
161  return true;
162 }
163 
164 
165 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
166 template <>
168 {
169  for (unsigned int i=0; i<LIBMESH_DIM; i++)
170  {
171  if ((*this)(i).real() < rhs(i).real())
172  return true;
173  if ((*this)(i).real() > rhs(i).real())
174  return false;
175  if ((*this)(i).imag() < rhs(i).imag())
176  return true;
177  if ((*this)(i).imag() > rhs(i).imag())
178  return false;
179  }
180  return false;
181 }
182 
183 
184 
185 template <>
187 {
188  for (unsigned int i=0; i<LIBMESH_DIM; i++)
189  {
190  if ((*this)(i).real() < rhs(i).real())
191  return true;
192  if ((*this)(i).real() > rhs(i).real())
193  return false;
194  if ((*this)(i).imag() < rhs(i).imag())
195  return true;
196  if ((*this)(i).imag() > rhs(i).imag())
197  return false;
198  }
199  return true;
200 }
201 
202 
203 
204 template <>
206 {
207  for (unsigned int i=0; i<LIBMESH_DIM; i++)
208  {
209  if ((*this)(i).real() > rhs(i).real())
210  return true;
211  if ((*this)(i).real() < rhs(i).real())
212  return false;
213  if ((*this)(i).imag() > rhs(i).imag())
214  return true;
215  if ((*this)(i).imag() < rhs(i).imag())
216  return false;
217  }
218  return false;
219 }
220 
221 
222 
223 template <>
225 {
226  for (unsigned int i=0; i<LIBMESH_DIM; i++)
227  {
228  if ((*this)(i).real() > rhs(i).real())
229  return true;
230  if ((*this)(i).real() < rhs(i).real())
231  return false;
232  if ((*this)(i).imag() > rhs(i).imag())
233  return true;
234  if ((*this)(i).imag() < rhs(i).imag())
235  return false;
236  }
237  return true;
238 }
239 
240 #endif
241 
242 
243 
244 // ------------------------------------------------------------
245 // Explicit instantiations
246 template class TypeVector<Real>;
247 
248 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
249 template class TypeVector<Complex>;
250 #endif
251 
252 } // namespace libMesh

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo