1
// $Id: numeric_vector.C,v 1.18 2005/11/30 00:28:32 roystgnr Exp $
3
// The libMesh Finite Element Library.
4
// Copyright (C) 2002-2005 Benjamin S. Kirk, John W. Peterson
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 2.1 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// Lesser General Public License for more details.
16
// You should have received a copy of the GNU Lesser General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
#include <cmath> // for std::abs
26
#include "numeric_vector.h"
27
#include "laspack_vector.h"
28
#include "petsc_vector.h"
32
//------------------------------------------------------------------
33
// NumericVector methods
35
// Full specialization for Real datatypes
37
AutoPtr<NumericVector<T> >
38
NumericVector<T>::build(const SolverPackage solver_package)
40
// Build the appropriate vector
41
switch (solver_package)
48
AutoPtr<NumericVector<T> > ap(new LaspackVector<T>);
57
AutoPtr<NumericVector<T> > ap(new PetscVector<T>);
63
std::cerr << "ERROR: Unrecognized solver package: "
69
AutoPtr<NumericVector<T> > ap(NULL);
75
// Full specialization for float datatypes (DistributedVector wants this)
78
int NumericVector<float>::compare (const NumericVector<float> &other_vector,
79
const Real threshold) const
81
assert (this->initialized());
82
assert (other_vector.initialized());
83
assert (this->first_local_index() == other_vector.first_local_index());
84
assert (this->last_local_index() == other_vector.last_local_index());
87
unsigned int i = first_local_index();
91
if ( std::abs( (*this)(i) - other_vector(i) ) > threshold )
96
while (rvalue==-1 && i<last_local_index());
101
// Full specialization for double datatypes
103
int NumericVector<double>::compare (const NumericVector<double> &other_vector,
104
const Real threshold) const
106
assert (this->initialized());
107
assert (other_vector.initialized());
108
assert (this->first_local_index() == other_vector.first_local_index());
109
assert (this->last_local_index() == other_vector.last_local_index());
112
unsigned int i = first_local_index();
116
if ( std::abs( (*this)(i) - other_vector(i) ) > threshold )
121
while (rvalue==-1 && i<last_local_index());
126
#ifdef TRIPLE_PRECISION
127
// Full specialization for long double datatypes
129
int NumericVector<long double>::compare (const NumericVector<long double> &other_vector,
130
const Real threshold) const
132
assert (this->initialized());
133
assert (other_vector.initialized());
134
assert (this->first_local_index() == other_vector.first_local_index());
135
assert (this->last_local_index() == other_vector.last_local_index());
138
unsigned int i = first_local_index();
142
if ( std::abs( (*this)(i) - other_vector(i) ) > threshold )
147
while (rvalue==-1 && i<last_local_index());
154
// Full specialization for Complex datatypes
156
int NumericVector<Complex>::compare (const NumericVector<Complex> &other_vector,
157
const Real threshold) const
159
assert (this->initialized());
160
assert (other_vector.initialized());
161
assert (this->first_local_index() == other_vector.first_local_index());
162
assert (this->last_local_index() == other_vector.last_local_index());
165
unsigned int i = first_local_index();
169
if (( std::abs( (*this)(i).real() - other_vector(i).real() ) > threshold ) ||
170
( std::abs( (*this)(i).imag() - other_vector(i).imag() ) > threshold ))
175
while (rvalue==-1 && i<this->last_local_index());
182
//------------------------------------------------------------------
183
// Explicit instantiations
184
template class NumericVector<Number>;