📄 numeric_vector.h
字号:
// $Id: numeric_vector.h 2789 2008-04-13 02:24:40Z roystgnr $// The libMesh Finite Element Library.// Copyright (C) 2002-2007 Benjamin S. Kirk, John W. Peterson // This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version. // This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details. // You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#ifndef __numeric_vector_h__#define __numeric_vector_h__// C++ includes#include <vector>// Local includes#include "libmesh_common.h"#include "auto_ptr.h"#include "enum_solver_package.h"#include "reference_counted_object.h"#include "libmesh.h"// forward declarationstemplate <typename T> class NumericVector;template <typename T> class DenseVector;template <typename T> class SparseMatrix;/** * Numeric vector. Provides a uniform interface * to vector storage schemes for different linear * algebra libraries. * * @author Benjamin S. Kirk, 2003 */template <typename T>class NumericVector : public ReferenceCountedObject<NumericVector<T> >{public: /** * Dummy-Constructor. Dimension=0 */ NumericVector (); /** * Constructor. Set dimension to \p n and initialize all elements with zero. */ NumericVector (const unsigned int n); /** * Constructor. Set local dimension to \p n_local, the global dimension * to \p n, and initialize all elements with zero. */ NumericVector (const unsigned n, const unsigned int n_local); public: /** * Destructor, deallocates memory. Made virtual to allow * for derived classes to behave properly. */ virtual ~NumericVector (); /** * Builds a \p NumericVector using the linear solver package specified by * \p solver_package */ static AutoPtr<NumericVector<T> > build(const SolverPackage solver_package = libMesh::default_solver_package()); /** * @returns true if the vector has been initialized, * false otherwise. */ virtual bool initialized() const { return _is_initialized; } /** * @returns true if the vector is closed and ready for * computation, false otherwise. */ virtual bool closed() const { return _is_closed; } /** * Call the assemble functions */ virtual void close () = 0; /** * @returns the \p NumericVector<T> to a pristine state. */ virtual void clear (); /** * Set all entries to zero. Equivalent to \p v = 0, but more obvious and * faster. */ virtual void zero () = 0; /** * Creates a copy of this vector and returns it in an \p AutoPtr. * This must be overloaded in the derived classes. */ virtual AutoPtr<NumericVector<T> > clone () const = 0; /** * Change the dimension of the vector to \p N. The reserved memory for * this vector remains unchanged if possible, to make things faster, but * this may waste some memory, so take this in the back of your head. * However, if \p N==0 all memory is freed, i.e. if you want to resize * the vector and release the memory not needed, you have to first call * \p init(0) and then \p init(N). This cited behaviour is analogous * to that of the STL containers. * * On \p fast==false, the vector is filled by * zeros. */ virtual void init (const unsigned int, const unsigned int, const bool = false) {} /** * call init with n_local = N, */ virtual void init (const unsigned int, const bool = false) {} // /** // * Change the dimension to that of the // * vector \p V. The same applies as for // * the other \p init function. // * // * The elements of \p V are not copied, i.e. // * this function is the same as calling // * \p init(V.size(),fast). // */ // virtual void init (const NumericVector<T>&, // const bool = false) {} /** * \f$U(0-N) = s\f$: fill all components. */ virtual NumericVector<T> & operator= (const T s) = 0; /** * \f$U = V\f$: copy all components. */ virtual NumericVector<T> & operator= (const NumericVector<T> &V) = 0; /** * \f$U = V\f$: copy all components. */ virtual NumericVector<T> & operator= (const std::vector<T> &v) = 0; /** * @returns the minimum element in the vector. * In case of complex numbers, this returns the minimum * Real part. */ virtual Real min () const = 0; /** * @returns the maximum element in the vector. * In case of complex numbers, this returns the maximum * Real part. */ virtual Real max () const = 0; /** * returns the sum of the elements in a vector */ virtual T sum() const = 0; /** * @returns the \f$l_1\f$-norm of the vector, i.e. * the sum of the absolute values. */ virtual Real l1_norm () const = 0; /** * @returns the \f$l_2\f$-norm of the vector, i.e. * the square root of the sum of the * squares of the elements. */ virtual Real l2_norm () const = 0; /** * @returns the maximum absolute value of the * elements of this vector, which is the * \f$l_\infty\f$-norm of a vector. */ virtual Real linfty_norm () const = 0; /** * @returns dimension of the vector. This * function was formerly called \p n(), but * was renamed to get the \p NumericVector<T> class * closer to the C++ standard library's * \p std::vector container. */ virtual unsigned int size () const = 0; /** * @returns the local size of the vector * (index_stop-index_start) */ virtual unsigned int local_size() const = 0; /** * @returns the index of the first vector element * actually stored on this processor. Hint: the * minimum for this index is \p 0. */ virtual unsigned int first_local_index() const = 0; /** * @returns the index+1 of the last vector element * actually stored on this processor. Hint: the * maximum for this index is \p size(). */ virtual unsigned int last_local_index() const = 0; /** * Access components, returns \p U(i). */ virtual T operator() (const unsigned int i) const = 0; /** * Addition operator. * Fast equivalent to \p U.add(1, V). */ virtual NumericVector<T> & operator += (const NumericVector<T> &V) = 0; /** * Subtraction operator. * Fast equivalent to \p U.add(-1, V). */ virtual NumericVector<T> & operator -= (const NumericVector<T> &V) = 0; /** * v(i) = value */ virtual void set (const unsigned int i, const T value) = 0; /** * v(i) += value */ virtual void add (const unsigned int i, const T value) = 0; /** * \f$U(0-DIM)+=s\f$. * Addition of \p s to all components. Note * that \p s is a scalar and not a vector. */ virtual void add (const T s) = 0; /** * \f$U+=V\f$: * Simple vector addition, equal to the * \p operator +=. */ virtual void add (const NumericVector<T>& V) = 0; /** * \f$U+=a*V\f$. * Simple vector addition, equal to the * \p operator +=. */ virtual void add (const T a, const NumericVector<T>& v) = 0; /** * \f$ U+=v \f$ where v is a DenseVector<T> * and you * want to specify WHERE to add it */ virtual void add_vector (const std::vector<T>& v, const std::vector<unsigned int>& dof_indices) = 0; /** * \f$U+=V\f$, where U and V are type * NumericVector<T> and you * want to specify WHERE to add * the NumericVector<T> V */ virtual void add_vector (const NumericVector<T>& V, const std::vector<unsigned int>& dof_indices) = 0; /** * \f$U+=A*V\f$, add the product of a \p SparseMatrix \p A * and a \p NumericVector \p V to \p this, where \p this=U. */ virtual void add_vector (const NumericVector<T>&, const SparseMatrix<T>&) = 0; /** * \f$ U+=V \f$ where U and V are type * DenseVector<T> and you * want to specify WHERE to add * the DenseVector<T> V */ virtual void add_vector (const DenseVector<T>& V, const std::vector<unsigned int>& dof_indices) = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -