⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 petsc_vector.h

📁 一个用来实现偏微分方程中网格的计算库
💻 H
📖 第 1 页 / 共 2 页
字号:
// $Id: petsc_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 __petsc_vector_h__#define __petsc_vector_h__#include "libmesh_common.h"#ifdef HAVE_PETSC// C++ includes#include <vector>// Local includes#include "numeric_vector.h"#include "petsc_macro.h"/** * Petsc include files. */#ifndef USE_COMPLEX_NUMBERSextern "C" {# include <petscvec.h>}#else# include <petscvec.h>#endif// forward declarationstemplate <typename T> class SparseMatrix;/** * Petsc vector. Provides a nice interface to the * Petsc C-based data structures for parallel vectors. * * @author Benjamin S. Kirk, 2002 */template <typename T>class PetscVector : public NumericVector<T>{public:  /**   *  Dummy-Constructor. Dimension=0   */  PetscVector ();    /**   * Constructor. Set dimension to \p n and initialize all elements with zero.   */  PetscVector (const unsigned int n);      /**   * Constructor. Set local dimension to \p n_local, the global dimension   * to \p n, and initialize all elements with zero.   */  PetscVector (const unsigned int n,	       const unsigned int n_local);  /**   * Constructor.  Creates a PetscVector assuming you already have a   * valid PETSc Vec object.  In this case, v is NOT destroyed by the   * PetscVector constructor when this object goes out of scope.   * This allows ownership of v to remain with the original creator,   * and to simply provide additional functionality with the PetscVector.   */  PetscVector(Vec v);    /**   * Destructor, deallocates memory. Made virtual to allow   * for derived classes to behave properly.   */  ~PetscVector ();  /**   * Call the assemble functions   */  void close ();   /**   * @returns the \p PetscVector<T> to a pristine state.   */  void clear ();    /**   * Set all entries to zero. Equivalent to \p v = 0, but more obvious and   * faster.    */  void zero ();      /**   * Creates a copy of this vector and returns it in an \p AutoPtr.   */  AutoPtr<NumericVector<T> > clone () const;    /**   * 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.   */      void init (const unsigned int N,	     const unsigned int n_local,	     const bool         fast=false);      /**   * call init with n_local = N,   */  void init (const unsigned int N,	     const bool         fast=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).  //    */  //   void init (const NumericVector<T>& V,  // 	     const bool fast=false);  /**   * \f$U(0-N) = s\f$: fill all components.   */  NumericVector<T> & operator= (const T s);      /**   *  \f$U = V\f$: copy all components.   */  NumericVector<T> & operator= (const NumericVector<T> &V);  /**   *  \f$U = V\f$: copy all components.   */  PetscVector<T> & operator= (const PetscVector<T> &V);  /**   *  \f$U = V\f$: copy all components.   */  NumericVector<T> & operator= (const std::vector<T> &v);  /**   * @returns the minimum element in the vector.   * In case of complex numbers, this returns the minimum   * Real part.   */  Real min () const;    /**   * @returns the maximum element in the vector.   * In case of complex numbers, this returns the maximum   * Real part.   */  Real max () const;  /**   * @returns the sum of values in a vector   */  T sum () const;  /**   * @returns the \f$l_1\f$-norm of the vector, i.e.   * the sum of the absolute values.   */  Real l1_norm () const;  /**   * @returns the \f$l_2\f$-norm of the vector, i.e.   * the square root of the sum of the   * squares of the elements.   */  Real l2_norm () const;  /**   * @returns the maximum absolute value of the   * elements of this vector, which is the   * \f$l_\infty\f$-norm of a vector.   */  Real linfty_norm () const;  /**   * @returns dimension of the vector. This   * function was formerly called \p n(), but   * was renamed to get the \p PetscVector<T> class   * closer to the C++ standard library's   * \p std::vector container.   */  unsigned int size () const;  /**   * @returns the local size of the vector   * (index_stop-index_start)   */  unsigned int local_size() const;  /**   * @returns the index of the first vector element   * actually stored on this processor   */  unsigned int first_local_index() const;  /**   * @returns the index of the last vector element   * actually stored on this processor   */  unsigned int last_local_index() const;      /**   * Access components, returns \p U(i).   */  T operator() (const unsigned int i) const;      /**   * Addition operator.   * Fast equivalent to \p U.add(1, V).   */  NumericVector<T> & operator += (const NumericVector<T> &V);  /**   * Subtraction operator.   * Fast equivalent to \p U.add(-1, V).   */  NumericVector<T> & operator -= (const NumericVector<T> &V);      /**   * v(i) = value   */  void set (const unsigned int i, const T value);      /**   * v(i) += value   */  void add (const unsigned int i, const T value);      /**   * \f$U(0-DIM)+=s\f$.   * Addition of \p s to all components. Note   * that \p s is a scalar and not a vector.   */  void add (const T s);      /**   * \f$ U+=V \f$ .   * Simple vector addition, equal to the   * \p operator +=.   */  void add (const NumericVector<T>& V);  /**   * \f$ U+=a*V \f$ .   * Simple vector addition, equal to the   * \p operator +=.   */  void add (const T a, const NumericVector<T>& v);    /**   * \f$ U+=v \f$ where \p v is a std::vector<T>    * and you   * want to specify WHERE to add it   */  void add_vector (const std::vector<T>& v,		   const std::vector<unsigned int>& dof_indices);  /**   * \f$ U+=V \f$ where U and V are type    * \p NumericVector<T> and you   * want to specify WHERE to add   * the \p NumericVector<T> V    */  void add_vector (const NumericVector<T>& V,		   const std::vector<unsigned int>& dof_indices);  /**   * \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.   */  void add_vector (const NumericVector<T> &V,		   const SparseMatrix<T> &A);       /**   * \f$U+=V \f$ where U and V are type    * DenseVector<T> and you   * want to specify WHERE to add   * the DenseVector<T> V    */  void add_vector (const DenseVector<T>& V,		   const std::vector<unsigned int>& dof_indices);    /**   * \f$ U=v \f$ where v is a DenseVector<T>    * and you want to specify WHERE to insert it   */  virtual void insert (const std::vector<T>& v,		       const std::vector<unsigned int>& dof_indices);  /**   * \f$U=V\f$, where U and V are type    * NumericVector<T> and you   * want to specify WHERE to insert   * the NumericVector<T> V    */  virtual void insert (const NumericVector<T>& V,		       const std::vector<unsigned int>& dof_indices);        /**   * \f$ U+=V \f$ where U and V are type    * DenseVector<T> and you   * want to specify WHERE to insert   * the DenseVector<T> V    */  virtual void insert (const DenseVector<T>& V,		       const std::vector<unsigned int>& dof_indices);        /**   * Scale each element of the   * vector by the given factor.   */  void scale (const T factor);  /**   * Computes the dot product, p = U.V   */  virtual T dot(const NumericVector<T>& V) const;    /**   * Creates a copy of the global vector in the   * local vector \p v_local.   */  void localize (std::vector<T>& v_local) const;  /**   * Same, but fills a \p NumericVector<T> instead of   * a \p std::vector.   */  void localize (NumericVector<T>& v_local) const;  /**   * Creates a local vector \p v_local containing   * only information relevant to this processor, as   * defined by the \p send_list.   */  void localize (NumericVector<T>& v_local,		 const std::vector<unsigned int>& send_list) const;    /**   * Updates a local vector with selected values from neighboring   * processors, as defined by \p send_list.   */  void localize (const unsigned int first_local_idx,		 const unsigned int last_local_idx,		 const std::vector<unsigned int>& send_list);    /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -