libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
Public 成员函数 | 静态 Public 成员函数 | Protected 类型 | Protected 成员函数 | Protected 属性 | 静态 Protected 属性 | Private 类型 | Private 成员函数 | Private 属性 | 所有成员列表
libMesh::PetscVector< T > 模板类 参考finalabstract

该类提供了一个良好的接口,用于访问 PETSc 的 Vec 对象。所有重写的虚拟函数都在 numeric_vector.h 中有文档说明。 更多...

#include <petsc_vector.h>

类 libMesh::PetscVector< T > 继承关系图:
[图例]

Public 成员函数

 PetscVector (const Parallel::Communicator &comm_in, const ParallelType type=AUTOMATIC)
 无效的构造函数。维度=0。 更多...
 
 PetscVector (const Parallel::Communicator &comm_in, const numeric_index_type n, const ParallelType type=AUTOMATIC)
 构造函数。将维度设置为 n 并将所有元素初始化为零。 更多...
 
 PetscVector (const Parallel::Communicator &comm_in, const numeric_index_type n, const numeric_index_type n_local, const ParallelType type=AUTOMATIC)
 构造函数。将本地维度设置为 n_local ,全局维度设置为 n ,并将所有元素初始化为零。 更多...
 
 PetscVector (const Parallel::Communicator &comm_in, const numeric_index_type N, const numeric_index_type n_local, const std::vector< numeric_index_type > &ghost, const ParallelType type=AUTOMATIC)
 构造函数。将本地维度设置为 n_local ,全局维度设置为 n ,但还会为由 ghost 参数指定的索引保留内存。 更多...
 
 PetscVector (Vec v, const Parallel::Communicator &comm_in)
 构造函数。假设您已经有一个有效的 PETSc Vec 对象,则创建一个 PetscVector。在这种情况下,当该对象超出作用域时,v 不会被 PetscVector 构造函数销毁。 这允许将 v 的所有权保留给原始创建者,并仅为 PetscVector 提供附加功能。 更多...
 
PetscVector< T > & operator= (const PetscVector< T > &v)
 复制赋值运算符。 在执行各种检查后调用 VecCopy。 更多...
 
 PetscVector (PetscVector &&)=delete
 该类手动管理 C 风格的结构(Vec),因此我们不希望生成任何自动复制/移动函数,并且无法默认生成析构函数。 更多...
 
 PetscVector (const PetscVector &)=delete
 
PetscVectoroperator= (PetscVector &&)=delete
 
virtual ~PetscVector ()
 析构函数。 更多...
 
virtual void close () override
 关闭 PetscVector。 更多...
 
virtual void clear () noexceptoverride
 从析构函数中调用 clear(),所以它不应引发异常。 更多...
 
virtual void zero () override
 PetscVector 的所有元素设置为零。 更多...
 
virtual std::unique_ptr
< NumericVector< T > > 
zero_clone () const override
 获取一个零副本的独立指针。 更多...
 
virtual std::unique_ptr
< NumericVector< T > > 
clone () const override
 克隆该 NumericVector 的独立副本。 更多...
 
virtual void init (const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
 初始化 NumericVector 对象。 更多...
 
virtual void init (const numeric_index_type N, const bool fast=false, const ParallelType type=AUTOMATIC) override
 初始化 NumericVector 对象。 更多...
 
virtual void init (const numeric_index_type N, const numeric_index_type n_local, const std::vector< numeric_index_type > &ghost, const bool fast=false, const ParallelType=AUTOMATIC) override
 初始化 NumericVector 对象。 更多...
 
virtual void init (const NumericVector< T > &other, const bool fast=false) override
 使用另一个 NumericVector 对象初始化当前对象。 更多...
 
virtual NumericVector< T > & operator= (const T s) override
 NumericVector 中的所有元素设置为标量值 s。 更多...
 
virtual NumericVector< T > & operator= (const NumericVector< T > &v) override
 将当前 NumericVector 的内容复制为另一个 NumericVector v。 更多...
 
virtual NumericVector< T > & operator= (const std::vector< T > &v) override
 将当前 NumericVector 的内容复制为一个标量值向量 v。 更多...
 
virtual Real min () const override
 获取 NumericVector 中的最小值。 更多...
 
virtual Real max () const override
 获取 NumericVector 中的最大值。 更多...
 
virtual T sum () const override
 计算 NumericVector 中的元素之和。 更多...
 
virtual Real l1_norm () const override
 计算 NumericVector 的 L1 范数。 更多...
 
virtual Real l2_norm () const override
 计算 NumericVector 的 L2 范数。 更多...
 
virtual Real linfty_norm () const override
 计算 NumericVector 的 Linf 范数。 更多...
 
virtual numeric_index_type size () const override
 获取 NumericVector 的大小(维度)。 更多...
 
virtual numeric_index_type local_size () const override
 获取 NumericVector 的本地大小(本地维度)。 更多...
 
virtual numeric_index_type first_local_index () const override
 获取 NumericVector 的第一个本地索引。 更多...
 
virtual numeric_index_type last_local_index () const override
 获取 NumericVector 的最后一个本地索引。 更多...
 
numeric_index_type map_global_to_local_index (const numeric_index_type i) const
 
virtual T operator() (const numeric_index_type i) const override
 访问 NumericVector 对象的元素。 更多...
 
virtual void get (const std::vector< numeric_index_type > &index, T *values) const override
 获取指定索引的元素值。 更多...
 
PetscScalar * get_array ()
 获取对 PETSc Vector 数据数组的读/写访问权限。 更多...
 
const PetscScalar * get_array_read () const
 获取对 PETSc Vector 数据数组的只读访问权限。 更多...
 
void restore_array ()
 恢复数据数组。 更多...
 
virtual NumericVector< T > & operator+= (const NumericVector< T > &v) override
 将当前 NumericVector 与另一个 NumericVector v 相加。 更多...
 
virtual NumericVector< T > & operator-= (const NumericVector< T > &v) override
 将当前 NumericVector 与另一个 NumericVector v 相减。 更多...
 
virtual void reciprocal () override
 NumericVector 中的所有元素取倒数。 更多...
 
virtual void conjugate () override
 NumericVector 中的所有元素取共轭。 更多...
 
virtual void set (const numeric_index_type i, const T value) override
 设置索引为 i 的元素值为 value。 更多...
 
virtual void add (const numeric_index_type i, const T value) override
 将索引为 i 的元素值增加 value。 更多...
 
virtual void add (const T s) override
 NumericVector 中的所有元素加上标量值 s。 更多...
 
virtual void add (const NumericVector< T > &v) override
 将当前 NumericVector 与另一个 NumericVector v 相加。 更多...
 
virtual void add (const T a, const NumericVector< T > &v) override
 将当前 NumericVector 与另一个 NumericVector v 相加,并乘以标量值 a。 更多...
 
virtual void add_vector (const T *v, const std::vector< numeric_index_type > &dof_indices) override
 向指定索引数组的元素中添加向量 v 的元素。 更多...
 
virtual void add_vector (const NumericVector< T > &v, const SparseMatrix< T > &A) override
 使用 SparseMatrix A 对向量 v 进行矩阵乘法,并将结果添加到当前向量。 更多...
 
virtual void add_vector_transpose (const NumericVector< T > &v, const SparseMatrix< T > &A) override
 使用 SparseMatrix A 的共轭转置与向量 v 进行矩阵乘法,并将结果添加到当前向量。 更多...
 
void add_vector_conjugate_transpose (const NumericVector< T > &v, const SparseMatrix< T > &A)
 $ U \leftarrow U + A^H v $. 更多...
 
virtual void insert (const T *v, const std::vector< numeric_index_type > &dof_indices) override
 将指定索引数组的元素设置为向量 v 的元素。 更多...
 
virtual void scale (const T factor) override
 缩放当前向量的所有元素。 更多...
 
virtual NumericVector< T > & operator*= (const NumericVector< T > &v) override
 将当前向量与另一个 NumericVector v 逐元素相乘并赋值给当前向量。 更多...
 
virtual NumericVector< T > & operator/= (const NumericVector< T > &v) override
 将当前向量与另一个 NumericVector v 逐元素相除并赋值给当前向量。 更多...
 
virtual void abs () override
 对当前向量的所有元素取绝对值。 更多...
 
virtual T dot (const NumericVector< T > &v) const override
 计算当前向量与向量 v 的点积。 更多...
 
indefinite_dot (const NumericVector< T > &v) const
 计算 (*this) 与向量 v 的点积,不使用复数值的共轭。 更多...
 
virtual void localize (std::vector< T > &v_local) const override
 将当前向量的数据本地化到 std::vector v_local 中。 更多...
 
virtual void localize (NumericVector< T > &v_local) const override
 将当前向量的数据本地化到 NumericVector v_local 中。 更多...
 
virtual void localize (NumericVector< T > &v_local, const std::vector< numeric_index_type > &indices) const override
 将当前向量的数据本地化到 NumericVector v_local 中,只包括指定的索引。 更多...
 
virtual void localize (const numeric_index_type first_local_idx, const numeric_index_type last_local_idx, const std::vector< numeric_index_type > &send_list) override
 本地化当前向量的数据,并将其发送给指定的进程。 更多...
 
virtual void localize_to_one (std::vector< T > &v_local, const processor_id_type proc_id=0) const override
 将当前向量的数据本地化到 std::vector v_local 中,只包括一个进程的数据。 更多...
 
virtual void pointwise_mult (const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
 逐元素将当前向量与 vec1 相乘,结果存储在当前向量中。 更多...
 
virtual void pointwise_divide (const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
 逐元素将当前向量与 vec1 相除,结果存储在当前向量中。 更多...
 
virtual void print_matlab (const std::string &name="") const override
 将当前向量的数据以 MATLAB 格式打印输出。 更多...
 
virtual void create_subvector (NumericVector< T > &subvector, const std::vector< numeric_index_type > &rows) const override
 创建当前向量的子向量,并将其赋值给 subvector。 更多...
 
virtual void swap (NumericVector< T > &v) override
 交换当前向量与另一个 NumericVector v 的数据。 更多...
 
virtual std::size_t max_allowed_id () const override
 获取当前向量允许的最大 ID。 更多...
 
Vec vec ()
 获取当前向量的原始 PETSc Vec 指针。 更多...
 
Vec vec () const
 获取当前向量的原始 PETSc Vec 指针(const 版本)。 更多...
 
template<>
void localize_to_one (std::vector< Real > &v_local, const processor_id_type timpi_mpi_var(pid)) const
 
template<>
void localize_to_one (std::vector< Complex > &v_local, const processor_id_type pid) const
 
virtual bool initialized () const
 检查向量是否已经初始化。 更多...
 
ParallelType type () const
 获取向量的类型。 更多...
 
ParallelType & type ()
 获取向量的类型。 更多...
 
virtual bool closed () const
 检查向量是否已经关闭并准备好进行计算。 更多...
 
virtual Real subset_l1_norm (const std::set< numeric_index_type > &indices) const
 获取指定条目的向量的 $ \ell_1 $-范数,即指定条目的绝对值之和。 更多...
 
virtual Real subset_l2_norm (const std::set< numeric_index_type > &indices) const
 获取指定条目的向量的 $ \ell_2 $-范数,即指定条目平方和的平方根。 更多...
 
virtual Real subset_linfty_norm (const std::set< numeric_index_type > &indices) const
 获取指定条目的向量的最大绝对值,即指定条目的 $ \ell_{\infty} $-范数。 更多...
 
Real l2_norm_diff (const NumericVector< T > &other_vec) const
 获取 $ \ell_2 $-范数的向量差值 $ \vec{u} - \vec{v} $, 其中 $ \vec{u} $this。 更多...
 
virtual T el (const numeric_index_type i) const
 获取向量的第 i 个条目。 更多...
 
void get (const std::vector< numeric_index_type > &index, std::vector< T > &values) const
 一次访问多个组件。 values 将被调整大小,如果需要,将被填充。 默认实现对每个索引调用 operator() ,但某些实现可能在此处提供更快的方法。 更多...
 
NumericVector< T > & operator*= (const T a)
 将向量缩放为 a$ \vec{u} \leftarrow a\vec{u} $。等价于 u.scale(a)。 更多...
 
NumericVector< T > & operator/= (const T a)
 将向量缩放为 1/a$ \vec{u} \leftarrow \frac{1}{a}\vec{u} $。等价于 u.scale(1. 更多...
 
void add_vector (const std::vector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 计算 $ \vec{u} \leftarrow \vec{u} + \vec{v} $,其中 v 是一个 std::vector, 每个 dof_indices[i] 指定了要添加的值 v[i] 的位置 默认实现对每个索引调用 operator() ,但某些实现可能在此处提供更快的方法。 请注意,此方法的库实现是线程安全的。 更多...
 
void add_vector (const NumericVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 计算 $ \vec{u} \leftarrow \vec{u} + \vec{v} $,其中 v 是一个 NumericVector, 每个 dof_indices[i] 指定了要添加的值 v(i) 的位置。此方法是线程安全的。 更多...
 
void add_vector (const DenseVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 计算 $ \vec{u} \leftarrow \vec{u} + \vec{v} $,其中 v 是一个 DenseVector, 每个 dof_indices[i] 指定了要添加的值 v(i) 的位置。此方法是线程安全的。 更多...
 
void add_vector (const NumericVector< T > &v, const ShellMatrix< T > &A)
 计算 $ \vec{u} \leftarrow \vec{u} + A \vec{v} $, 即将 ShellMatrix ANumericVector v 的乘积添加到 this。 更多...
 
void insert (const NumericVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 v 的条目插入到 *this 中,位置由 v 指定。 只要使用 NumericVector 的库实现,此方法是线程安全的。 更多...
 
void insert (const DenseVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 v 的条目插入到 *this 中,位置由 v 指定。 只要使用 NumericVector 的库实现,此方法是线程安全的。 更多...
 
void insert (const DenseSubVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 v 的条目插入到 *this 中,位置由 v 指定。 只要使用 NumericVector 的库实现,此方法是线程安全的。 更多...
 
virtual void localize (std::vector< T > &v_local, const std::vector< numeric_index_type > &indices) const =0
 用全局索引中给定的值填充本地 std::vector "v_local"。 更多...
 
virtual int compare (const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
 比较 thisother_vector 的等效性,(在给定的 threshold 内) 如果等效则返回 -1 ,或者返回第一个索引,其中 abs(a[i]-b[i]) 超过阈值。 更多...
 
virtual int local_relative_compare (const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
 比较该向量与另一个向量的局部相对差异。 更多...
 
virtual void print (std::ostream &os=libMesh::out) const
 打印本地向量的内容,默认输出到 libMesh::out 流。 更多...
 
template<>
void print (std::ostream &os) const
 
virtual void print_global (std::ostream &os=libMesh::out) const
 打印全局向量的内容,默认输出到 libMesh::out 流。 更多...
 
template<>
void print_global (std::ostream &os) const
 
bool readable () const
 检查该向量是否能够用于全局操作。 更多...
 
bool compatible (const NumericVector< T > &v) const
 检查该向量和向量 v 是否能够一起用于全局操作。 更多...
 

静态 Public 成员函数

static std::unique_ptr
< NumericVector< T > > 
build (const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
 构建一个 NumericVector 对象。 更多...
 
static std::string get_info ()
 Gets a string containing the reference information. 更多...
 
static void print_info (std::ostream &out_stream=libMesh::out)
 Prints the reference information, by default to libMesh::out. 更多...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. 更多...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() 更多...
 
static void disable_print_counter_info ()
 

Protected 类型

typedef std::map< std::string,
std::pair< unsigned int,
unsigned int > > 
Counts
 Data structure to log the information. 更多...
 

Protected 成员函数

void increment_constructor_count (const std::string &name) noexcept
 Increments the construction counter. 更多...
 
void increment_destructor_count (const std::string &name) noexcept
 Increments the destruction counter. 更多...
 

Protected 属性

bool _is_closed
 用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。 更多...
 
bool _is_initialized
 在调用 init() 后设置为 true。 更多...
 
ParallelType _type
 向量的类型。 更多...
 
std::mutex _numeric_vector_mutex
 用于执行线程安全操作的互斥锁。 更多...
 

静态 Protected 属性

static Counts _counts
 Actually holds the data. 更多...
 
static Threads::atomic
< unsigned int > 
_n_objects
 The number of objects. 更多...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. 更多...
 
static bool _enable_print_counter = true
 Flag to control whether reference count information is printed when print_info is called. 更多...
 

Private 类型

typedef std::unordered_map
< numeric_index_type,
numeric_index_type
GlobalToLocalMap
 用于将全局幽灵单元格映射到本地单元格的映射类型。 更多...
 

Private 成员函数

void _get_array (bool read_only) const
 从 PETSc 查询数组(如果向量是幽灵的,则还包括本地形式)。 更多...
 
void _restore_array () const
 将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。 更多...
 

Private 属性

Vec _vec
 用于保存向量元素的实际 PETSc 向量数据类型。 更多...
 
std::atomic< bool > _array_is_present
 如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。 更多...
 
bool _array_is_present
 
numeric_index_type _first
 第一个本地索引。 更多...
 
numeric_index_type _last
 最后一个本地索引。 更多...
 
numeric_index_type _local_size
 _get_array() 获取本地值的大小。 更多...
 
Vec _local_form
 用于保存幽灵向量的本地形式的 PETSc 向量数据类型。仅当向量是幽灵的且 _array_is_present 为真时,此字段的内容才有效。 更多...
 
const PetscScalar * _read_only_values
 指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 更多...
 
PetscScalar * _values
 指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 PetscScalar *,但是 _get_array 和 _restore_array 是 const 成员函数,因此 _values 也需要是可变的(否则在那个上下文中它是 "const PetscScalar * const")。 更多...
 
std::mutex _petsc_get_restore_array_mutex
 用于 _get_array 和 _restore_array 的互斥锁。这是对象的一部分,以减少从多个 PetscVectors 同时读取时的线程争用。 更多...
 
GlobalToLocalMap _global_to_local_map
 用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。 更多...
 
bool _destroy_vec_on_exit
 此布尔值仅在接受 PETSc Vec 对象的构造函数中设置为 false。 更多...
 
bool _values_manually_retrieved
 数据数组是否已经通过 get_array()get_array_read() 手动检索。 更多...
 
bool _values_read_only
 数据数组是否仅用于只读访问。 更多...
 

详细描述

template<typename T>
class libMesh::PetscVector< T >

该类提供了一个良好的接口,用于访问 PETSc 的 Vec 对象。所有重写的虚拟函数都在 numeric_vector.h 中有文档说明。

作者
Benjamin S. Kirk
日期
2002 提供对 PETSc Vec 的 NumericVector 接口。

在文件 petsc_vector.h75 行定义.

成员类型定义说明

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

在文件 reference_counter.h119 行定义.

template<typename T>
typedef std::unordered_map<numeric_index_type, numeric_index_type> libMesh::PetscVector< T >::GlobalToLocalMap
private

用于将全局幽灵单元格映射到本地单元格的映射类型。

在文件 petsc_vector.h726 行定义.

构造及析构函数说明

template<typename T >
libMesh::PetscVector< T >::PetscVector ( const Parallel::Communicator &  comm_in,
const ParallelType  type = AUTOMATIC 
)
inlineexplicit

无效的构造函数。维度=0。

参数
comm_in通信器,用于指定通信方式。
type并行类型,指定并行方式,默认为 AUTOMATIC。

在文件 petsc_vector.h756 行定义.

参考 libMesh::NumericVector< T >::_type.

756  :
757  NumericVector<T>(comm_in, ptype),
758  _array_is_present(false),
759  _first(0),
760  _last(0),
761  _local_form(nullptr),
762  _values(nullptr),
764  _destroy_vec_on_exit(true),
766  _values_read_only(false)
767 {
768  this->_type = ptype;
769 }
bool _destroy_vec_on_exit
此布尔值仅在接受 PETSc Vec 对象的构造函数中设置为 false。
Definition: petsc_vector.h:736
numeric_index_type _last
最后一个本地索引。
Definition: petsc_vector.h:683
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
bool _values_read_only
数据数组是否仅用于只读访问。
Definition: petsc_vector.h:746
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
Vec _local_form
用于保存幽灵向量的本地形式的 PETSc 向量数据类型。仅当向量是幽灵的且 _array_is_present 为真时,此字段的内容才有效。
Definition: petsc_vector.h:693
GlobalToLocalMap _global_to_local_map
用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。
Definition: petsc_vector.h:731
ParallelType _type
向量的类型。
numeric_index_type _first
第一个本地索引。
Definition: petsc_vector.h:676
bool _values_manually_retrieved
数据数组是否已经通过 get_array() 或 get_array_read() 手动检索。
Definition: petsc_vector.h:741
template<typename T >
libMesh::PetscVector< T >::PetscVector ( const Parallel::Communicator &  comm_in,
const numeric_index_type  n,
const ParallelType  type = AUTOMATIC 
)
inlineexplicit

构造函数。将维度设置为 n 并将所有元素初始化为零。

参数
comm_in通信器,用于指定通信方式。
n维度。
type并行类型,指定并行方式,默认为 AUTOMATIC。

在文件 petsc_vector.h775 行定义.

参考 libMesh::PetscVector< T >::init().

777  :
778  NumericVector<T>(comm_in, ptype),
779  _array_is_present(false),
780  _local_form(nullptr),
781  _values(nullptr),
783  _destroy_vec_on_exit(true),
785  _values_read_only(false)
786 {
787  this->init(n, n, false, ptype);
788 }
bool _destroy_vec_on_exit
此布尔值仅在接受 PETSc Vec 对象的构造函数中设置为 false。
Definition: petsc_vector.h:736
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
bool _values_read_only
数据数组是否仅用于只读访问。
Definition: petsc_vector.h:746
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
Vec _local_form
用于保存幽灵向量的本地形式的 PETSc 向量数据类型。仅当向量是幽灵的且 _array_is_present 为真时,此字段的内容才有效。
Definition: petsc_vector.h:693
GlobalToLocalMap _global_to_local_map
用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。
Definition: petsc_vector.h:731
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
初始化 NumericVector 对象。
Definition: petsc_vector.h:959
bool _values_manually_retrieved
数据数组是否已经通过 get_array() 或 get_array_read() 手动检索。
Definition: petsc_vector.h:741
template<typename T >
libMesh::PetscVector< T >::PetscVector ( const Parallel::Communicator &  comm_in,
const numeric_index_type  n,
const numeric_index_type  n_local,
const ParallelType  type = AUTOMATIC 
)
inline

构造函数。将本地维度设置为 n_local ,全局维度设置为 n ,并将所有元素初始化为零。

参数
comm_in通信器,用于指定通信方式。
n全局维度。
n_local本地维度。
type并行类型,指定并行方式,默认为 AUTOMATIC。

在文件 petsc_vector.h794 行定义.

参考 libMesh::PetscVector< T >::init().

797  :
798  NumericVector<T>(comm_in, ptype),
799  _array_is_present(false),
800  _local_form(nullptr),
801  _values(nullptr),
803  _destroy_vec_on_exit(true),
805  _values_read_only(false)
806 {
807  this->init(n, n_local, false, ptype);
808 }
bool _destroy_vec_on_exit
此布尔值仅在接受 PETSc Vec 对象的构造函数中设置为 false。
Definition: petsc_vector.h:736
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
bool _values_read_only
数据数组是否仅用于只读访问。
Definition: petsc_vector.h:746
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
Vec _local_form
用于保存幽灵向量的本地形式的 PETSc 向量数据类型。仅当向量是幽灵的且 _array_is_present 为真时,此字段的内容才有效。
Definition: petsc_vector.h:693
GlobalToLocalMap _global_to_local_map
用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。
Definition: petsc_vector.h:731
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
初始化 NumericVector 对象。
Definition: petsc_vector.h:959
bool _values_manually_retrieved
数据数组是否已经通过 get_array() 或 get_array_read() 手动检索。
Definition: petsc_vector.h:741
template<typename T >
libMesh::PetscVector< T >::PetscVector ( const Parallel::Communicator &  comm_in,
const numeric_index_type  N,
const numeric_index_type  n_local,
const std::vector< numeric_index_type > &  ghost,
const ParallelType  type = AUTOMATIC 
)
inline

构造函数。将本地维度设置为 n_local ,全局维度设置为 n ,但还会为由 ghost 参数指定的索引保留内存。

参数
comm_in通信器,用于指定通信方式。
N全局维度。
n_local本地维度。
ghost指定要保留内存的索引。
type并行类型,指定并行方式,默认为 AUTOMATIC。

在文件 petsc_vector.h814 行定义.

参考 libMesh::PetscVector< T >::init().

818  :
819  NumericVector<T>(comm_in, ptype),
820  _array_is_present(false),
821  _local_form(nullptr),
822  _values(nullptr),
824  _destroy_vec_on_exit(true),
826  _values_read_only(false)
827 {
828  this->init(n, n_local, ghost, false, ptype);
829 }
bool _destroy_vec_on_exit
此布尔值仅在接受 PETSc Vec 对象的构造函数中设置为 false。
Definition: petsc_vector.h:736
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
bool _values_read_only
数据数组是否仅用于只读访问。
Definition: petsc_vector.h:746
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
Vec _local_form
用于保存幽灵向量的本地形式的 PETSc 向量数据类型。仅当向量是幽灵的且 _array_is_present 为真时,此字段的内容才有效。
Definition: petsc_vector.h:693
GlobalToLocalMap _global_to_local_map
用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。
Definition: petsc_vector.h:731
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
初始化 NumericVector 对象。
Definition: petsc_vector.h:959
bool _values_manually_retrieved
数据数组是否已经通过 get_array() 或 get_array_read() 手动检索。
Definition: petsc_vector.h:741
template<typename T >
libMesh::PetscVector< T >::PetscVector ( Vec  v,
const Parallel::Communicator &  comm_in 
)
inline

构造函数。假设您已经有一个有效的 PETSc Vec 对象,则创建一个 PetscVector。在这种情况下,当该对象超出作用域时,v 不会被 PetscVector 构造函数销毁。 这允许将 v 的所有权保留给原始创建者,并仅为 PetscVector 提供附加功能。

它用于根据给定的 PETSc Vec 对象初始化 PetscVector 对象。 在构造函数中,还根据给定的 Vec 对象的类型创建了一个映射, 将全局幽灵单元格映射到本地单元格。 然后根据情况设置了 PetscVector 的类型(GHOSTED、PARALLEL 或 SERIAL)。 最后,将一些成员变量初始化为默认值。

参数
v有效的 PETSc Vec 对象。
comm_in通信器,用于指定通信方式。

在文件 petsc_vector.h844 行定义.

参考 libMesh::PetscVector< T >::_global_to_local_map, libMesh::NumericVector< T >::_is_closed, libMesh::NumericVector< T >::_is_initialized, libMesh::NumericVector< T >::_type , 以及 libMesh::PetscVector< T >::_vec.

845  :
846  NumericVector<T>(comm_in, AUTOMATIC),
847  _array_is_present(false),
848  _local_form(nullptr),
849  _values(nullptr),
851  _destroy_vec_on_exit(false),
853  _values_read_only(false)
854 {
855  this->_vec = v;
856  this->_is_closed = true;
857  this->_is_initialized = true;
858 
859  /* 需要向 PETSc 查询(本地到全局)幽灵值映射并从中创建逆映射。*/
860  PetscErrorCode ierr=0;
861  PetscInt petsc_local_size=0;
862  ierr = VecGetLocalSize(_vec, &petsc_local_size);
863  LIBMESH_CHKERR(ierr);
864 
865  // 从 PETSc 获取向量类型。
866  VecType ptype;
867  ierr = VecGetType(_vec, &ptype);
868  LIBMESH_CHKERR(ierr);
869 
870 #if PETSC_RELEASE_GREATER_EQUALS(3, 21, 0)
871  // Fande 仅为 VECMPI 实现了 VecGhostGetGhostIS
872  if (std::strcmp(ptype, VECMPI) == 0)
873  {
874  IS ghostis;
875  ierr = VecGhostGetGhostIS(_vec, &ghostis);
876  LIBMESH_CHKERR(ierr);
877 
878  Vec localrep;
879  ierr = VecGhostGetLocalForm(_vec, &localrep);
880  LIBMESH_CHKERR(ierr);
881 
882  // 如果是稀疏存储的向量,设置我们的新映射
883  // 仅检查映射不足以确定向量是否被幽灵化
884  // 我们需要检查向量是否有本地表示
885  if (ghostis && localrep)
886  {
887  PetscInt ghost_size;
888  ierr = ISGetSize(ghostis, &ghost_size);
889  LIBMESH_CHKERR(ierr);
890 
891  const PetscInt * indices;
892  ierr = ISGetIndices(ghostis, &indices);
893  LIBMESH_CHKERR(ierr);
894 
895  for (const auto i : make_range(ghost_size))
896  _global_to_local_map[indices[i]] = i;
897  this->_type = GHOSTED;
898  ierr = ISRestoreIndices(ghostis, &indices);
899  LIBMESH_CHKERR(ierr);
900  }
901  }
902  else if (std::strcmp(ptype,VECSHARED) == 0)
903 #else
904  if ((std::strcmp(ptype,VECSHARED) == 0) || (std::strcmp(ptype,VECMPI) == 0))
905 #endif
906  {
907  ISLocalToGlobalMapping mapping;
908  ierr = VecGetLocalToGlobalMapping(_vec, &mapping);
909  LIBMESH_CHKERR(ierr);
910 
911  Vec localrep;
912  ierr = VecGhostGetLocalForm(_vec,&localrep);
913  LIBMESH_CHKERR(ierr);
914  // 如果是稀疏存储的向量,设置我们的新映射
915  // 仅检查映射不足以确定向量是否被幽灵化
916  // 我们需要检查向量是否有本地表示
917  if (mapping && localrep)
918  {
919  const numeric_index_type my_local_size = static_cast<numeric_index_type>(petsc_local_size);
920  const numeric_index_type ghost_begin = static_cast<numeric_index_type>(petsc_local_size);
921  PetscInt n;
922  ierr = ISLocalToGlobalMappingGetSize(mapping, &n);
923  LIBMESH_CHKERR(ierr);
924 
925  const numeric_index_type ghost_end = static_cast<numeric_index_type>(n);
926  const PetscInt * indices;
927  ierr = ISLocalToGlobalMappingGetIndices(mapping,&indices);
928  LIBMESH_CHKERR(ierr);
929 
930  for (numeric_index_type i=ghost_begin; i<ghost_end; i++)
931  _global_to_local_map[indices[i]] = i-my_local_size;
932  this->_type = GHOSTED;
933  ierr = ISLocalToGlobalMappingRestoreIndices(mapping, &indices);
934  LIBMESH_CHKERR(ierr);
935  }
936  else
937  this->_type = PARALLEL;
938 
939  ierr = VecGhostRestoreLocalForm(_vec,&localrep);
940  LIBMESH_CHKERR(ierr);
941  }
942  else
943  this->_type = SERIAL;
944 }
bool _destroy_vec_on_exit
此布尔值仅在接受 PETSc Vec 对象的构造函数中设置为 false。
Definition: petsc_vector.h:736
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
bool _is_initialized
在调用 init() 后设置为 true。
bool _values_read_only
数据数组是否仅用于只读访问。
Definition: petsc_vector.h:746
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
Vec _local_form
用于保存幽灵向量的本地形式的 PETSc 向量数据类型。仅当向量是幽灵的且 _array_is_present 为真时,此字段的内容才有效。
Definition: petsc_vector.h:693
GlobalToLocalMap _global_to_local_map
用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。
Definition: petsc_vector.h:731
dof_id_type numeric_index_type
Definition: id_types.h:99
ParallelType _type
向量的类型。
bool _values_manually_retrieved
数据数组是否已经通过 get_array() 或 get_array_read() 手动检索。
Definition: petsc_vector.h:741
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T>
libMesh::PetscVector< T >::PetscVector ( PetscVector< T > &&  )
delete

该类手动管理 C 风格的结构(Vec),因此我们不希望生成任何自动复制/移动函数,并且无法默认生成析构函数。

template<typename T>
libMesh::PetscVector< T >::PetscVector ( const PetscVector< T > &  )
delete
template<typename T >
libMesh::PetscVector< T >::~PetscVector ( )
inlinevirtual

析构函数。

在文件 petsc_vector.h950 行定义.

951 {
952  this->clear ();
953 }
virtual void clear() noexceptoverride
从析构函数中调用 clear(),所以它不应引发异常。

成员函数说明

template<typename T >
void libMesh::PetscVector< T >::_get_array ( bool  read_only) const
private

从 PETSc 查询数组(如果向量是幽灵的,则还包括本地形式)。

参数
read_only是否获取数据的只读副本。

在文件 petsc_vector.C1266 行定义.

参考 libMesh::initialized().

1267 {
1268  libmesh_assert (this->initialized());
1269 
1270  bool initially_array_is_present = _array_is_present.load(std::memory_order_acquire);
1271 
1272  // If we already have a read/write array - and we're trying
1273  // to get a read only array - let's just use the read write
1274  if (initially_array_is_present && read_only && !_values_read_only)
1276 
1277  // If the values have already been retrieved and we're currently
1278  // trying to get a non-read only view (ie read/write) and the
1279  // values are currently read only... then we need to restore
1280  // the array first... and then retrieve it again.
1281  if (initially_array_is_present && !read_only && _values_read_only)
1282  {
1283  _restore_array();
1284  initially_array_is_present = false;
1285  }
1286 
1287  if (!initially_array_is_present)
1288  {
1289  std::scoped_lock lock(_petsc_get_restore_array_mutex);
1290  if (!_array_is_present.load(std::memory_order_relaxed))
1291  {
1292  PetscErrorCode ierr=0;
1293  if (this->type() != GHOSTED)
1294  {
1295  if (read_only)
1296  {
1297  ierr = VecGetArrayRead(_vec, &_read_only_values);
1298  _values_read_only = true;
1299  }
1300  else
1301  {
1302  ierr = VecGetArray(_vec, &_values);
1303  _values_read_only = false;
1304  }
1305  LIBMESH_CHKERR(ierr);
1306  _local_size = this->local_size();
1307  }
1308  else
1309  {
1310  ierr = VecGhostGetLocalForm (_vec,&_local_form);
1311  LIBMESH_CHKERR(ierr);
1312 
1313  if (read_only)
1314  {
1315  ierr = VecGetArrayRead(_local_form, &_read_only_values);
1316  _values_read_only = true;
1317  }
1318  else
1319  {
1320  ierr = VecGetArray(_local_form, &_values);
1321  _values_read_only = false;
1322  }
1323  LIBMESH_CHKERR(ierr);
1324 
1325  PetscInt my_local_size = 0;
1326  ierr = VecGetLocalSize(_local_form, &my_local_size);
1327  LIBMESH_CHKERR(ierr);
1328  _local_size = static_cast<numeric_index_type>(my_local_size);
1329  }
1330 
1331  { // cache ownership range
1332  PetscInt petsc_first=0, petsc_last=0;
1333  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1334  LIBMESH_CHKERR(ierr);
1335  _first = static_cast<numeric_index_type>(petsc_first);
1336  _last = static_cast<numeric_index_type>(petsc_last);
1337  }
1338  _array_is_present.store(true, std::memory_order_release);
1339  }
1340  }
1341 }
numeric_index_type _local_size
从 _get_array() 获取本地值的大小。
Definition: petsc_vector.h:688
virtual numeric_index_type local_size() const override
获取 NumericVector 的本地大小(本地维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
numeric_index_type _last
最后一个本地索引。
Definition: petsc_vector.h:683
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
virtual bool initialized() const
检查向量是否已经初始化。
bool _values_read_only
数据数组是否仅用于只读访问。
Definition: petsc_vector.h:746
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
const PetscScalar * _read_only_values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。
Definition: petsc_vector.h:698
Vec _local_form
用于保存幽灵向量的本地形式的 PETSc 向量数据类型。仅当向量是幽灵的且 _array_is_present 为真时,此字段的内容才有效。
Definition: petsc_vector.h:693
dof_id_type numeric_index_type
Definition: id_types.h:99
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
std::mutex _petsc_get_restore_array_mutex
用于 _get_array 和 _restore_array 的互斥锁。这是对象的一部分,以减少从多个 PetscVectors 同时读取时的线程争用。
Definition: petsc_vector.h:709
ParallelType type() const
获取向量的类型。
numeric_index_type _first
第一个本地索引。
Definition: petsc_vector.h:676
template<typename T >
void libMesh::PetscVector< T >::_restore_array ( ) const
private

将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。

在文件 petsc_vector.C1346 行定义.

参考 libMesh::initialized().

参考自 libMesh::PetscVector< T >::add(), libMesh::PetscVector< T >::create_subvector(), libMesh::PetscVector< T >::init() , 以及 libMesh::PetscVector< T >::operator=().

1347 {
1348  libmesh_error_msg_if(_values_manually_retrieved,
1349  "PetscVector values were manually retrieved but are being automatically restored!");
1350 
1351  libmesh_assert (this->initialized());
1352  if (_array_is_present.load(std::memory_order_acquire))
1353  {
1354  std::scoped_lock lock(_petsc_get_restore_array_mutex);
1355  if (_array_is_present.load(std::memory_order_relaxed))
1356  {
1357  PetscErrorCode ierr=0;
1358  if (this->type() != GHOSTED)
1359  {
1360  if (_values_read_only)
1361  ierr = VecRestoreArrayRead (_vec, &_read_only_values);
1362  else
1363  ierr = VecRestoreArray (_vec, &_values);
1364 
1365  LIBMESH_CHKERR(ierr);
1366  _values = nullptr;
1367  }
1368  else
1369  {
1370  if (_values_read_only)
1371  ierr = VecRestoreArrayRead (_local_form, &_read_only_values);
1372  else
1373  ierr = VecRestoreArray (_local_form, &_values);
1374 
1375  LIBMESH_CHKERR(ierr);
1376  _values = nullptr;
1377  ierr = VecGhostRestoreLocalForm (_vec,&_local_form);
1378  LIBMESH_CHKERR(ierr);
1379  _local_form = nullptr;
1380  _local_size = 0;
1381  }
1382  _array_is_present.store(false, std::memory_order_release);
1383  }
1384  }
1385 }
numeric_index_type _local_size
从 _get_array() 获取本地值的大小。
Definition: petsc_vector.h:688
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
virtual bool initialized() const
检查向量是否已经初始化。
bool _values_read_only
数据数组是否仅用于只读访问。
Definition: petsc_vector.h:746
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
const PetscScalar * _read_only_values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。
Definition: petsc_vector.h:698
Vec _local_form
用于保存幽灵向量的本地形式的 PETSc 向量数据类型。仅当向量是幽灵的且 _array_is_present 为真时,此字段的内容才有效。
Definition: petsc_vector.h:693
std::mutex _petsc_get_restore_array_mutex
用于 _get_array 和 _restore_array 的互斥锁。这是对象的一部分,以减少从多个 PetscVectors 同时读取时的线程争用。
Definition: petsc_vector.h:709
ParallelType type() const
获取向量的类型。
bool _values_manually_retrieved
数据数组是否已经通过 get_array() 或 get_array_read() 手动检索。
Definition: petsc_vector.h:741
template<typename T >
void libMesh::PetscVector< T >::abs ( )
overridevirtual

对当前向量的所有元素取绝对值。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C459 行定义.

460 {
461  parallel_object_only();
462 
463  this->_restore_array();
464 
465  PetscErrorCode ierr = VecAbs(_vec);
466  LIBMESH_CHKERR(ierr);
467 
468  libmesh_assert(this->comm().verify(int(this->type())));
469 
470  if (this->type() == GHOSTED)
471  VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
472 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
ParallelType type() const
获取向量的类型。
template<typename T >
void libMesh::PetscVector< T >::add ( const numeric_index_type  i,
const T  value 
)
overridevirtual

将索引为 i 的元素值增加 value。

参数
i数值索引。
value要增加的值。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C196 行定义.

参考 libMesh::PS().

197 {
198  this->_restore_array();
199  libmesh_assert_less (i, size());
200 
201  PetscErrorCode ierr=0;
202  PetscInt i_val = static_cast<PetscInt>(i);
203  PetscScalar petsc_value = PS(value);
204 
205  std::scoped_lock lock(this->_numeric_vector_mutex);
206  ierr = VecSetValues (_vec, 1, &i_val, &petsc_value, ADD_VALUES);
207  LIBMESH_CHKERR(ierr);
208 
209  this->_is_closed = false;
210 }
std::mutex _numeric_vector_mutex
用于执行线程安全操作的互斥锁。
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscScalar PS(T val)
Definition: petsc_macro.h:166
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T >
void libMesh::PetscVector< T >::add ( const T  s)
overridevirtual

NumericVector 中的所有元素加上标量值 s。

参数
s要加上的标量值。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C334 行定义.

335 {
336  this->_get_array(false);
337 
338  for (numeric_index_type i=0; i<_local_size; i++)
339  _values[i] += PetscScalar(v_in);
340 }
void _get_array(bool read_only) const
从 PETSc 查询数组(如果向量是幽灵的,则还包括本地形式)。
numeric_index_type _local_size
从 _get_array() 获取本地值的大小。
Definition: petsc_vector.h:688
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
dof_id_type numeric_index_type
Definition: id_types.h:99
template<typename T >
void libMesh::PetscVector< T >::add ( const NumericVector< T > &  v)
overridevirtual

将当前 NumericVector 与另一个 NumericVector v 相加。

参数
v另一个 NumericVector 对象。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C345 行定义.

346 {
347  parallel_object_only();
348 
349  this->add (1., v);
350 }
virtual void add(const numeric_index_type i, const T value) override
将索引为 i 的元素值增加 value。
Definition: petsc_vector.C:196
template<typename T >
void libMesh::PetscVector< T >::add ( const T  a,
const NumericVector< T > &  v 
)
overridevirtual

将当前 NumericVector 与另一个 NumericVector v 相加,并乘以标量值 a。

参数
a标量值。
v另一个 NumericVector 对象。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C355 行定义.

参考 libMesh::PetscVector< T >::_restore_array(), libMesh::PS(), libMesh::PetscVector< T >::size() , 以及 libMesh::PetscVector< T >::vec().

356 {
357  parallel_object_only();
358 
359  this->_restore_array();
360 
361  // VecAXPY doesn't support &x==&y
362  if (this == &v_in)
363  {
364  this->scale(a_in+1);
365  return;
366  }
367 
368  PetscScalar a = PS(a_in);
369 
370  // Make sure the NumericVector passed in is really a PetscVector
371  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
372  v->_restore_array();
373 
374  libmesh_assert_equal_to (this->size(), v->size());
375 
376  PetscErrorCode ierr = VecAXPY(_vec, a, v->vec());
377  LIBMESH_CHKERR(ierr);
378 
379  libmesh_assert(this->comm().verify(int(this->type())));
380 
381  if (this->type() == GHOSTED)
382  VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
383 
384  this->_is_closed = true;
385 }
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscScalar PS(T val)
Definition: petsc_macro.h:166
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
ParallelType type() const
获取向量的类型。
virtual void scale(const T factor) override
缩放当前向量的所有元素。
Definition: petsc_vector.C:411
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T >
void libMesh::PetscVector< T >::add_vector ( const T *  v,
const std::vector< numeric_index_type > &  dof_indices 
)
overridevirtual

向指定索引数组的元素中添加向量 v 的元素。

参数
v向量 v。
dof_indices指定的索引数组。

重载 libMesh::NumericVector< T > .

在文件 petsc_vector.C215 行定义.

参考 libMesh::pPS().

217 {
218  // If we aren't adding anything just return
219  if (dof_indices.empty())
220  return;
221 
222  this->_restore_array();
223 
224  PetscErrorCode ierr=0;
225  const PetscInt * i_val = reinterpret_cast<const PetscInt *>(dof_indices.data());
226  const PetscScalar * petsc_value = pPS(v);
227 
228  std::scoped_lock lock(this->_numeric_vector_mutex);
229  ierr = VecSetValues (_vec, cast_int<PetscInt>(dof_indices.size()),
230  i_val, petsc_value, ADD_VALUES);
231  LIBMESH_CHKERR(ierr);
232 
233  this->_is_closed = false;
234 }
std::mutex _numeric_vector_mutex
用于执行线程安全操作的互斥锁。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscScalar * pPS(T *ptr)
Definition: petsc_macro.h:172
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T >
void libMesh::PetscVector< T >::add_vector ( const NumericVector< T > &  v,
const SparseMatrix< T > &  A 
)
overridevirtual

使用 SparseMatrix A 对向量 v 进行矩阵乘法,并将结果添加到当前向量。

参数
v向量 v。
A稀疏矩阵 A。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C239 行定义.

参考 libMesh::PetscVector< T >::_vec.

241 {
242  parallel_object_only();
243 
244  this->_restore_array();
245  // Make sure the data passed in are really of Petsc types
246  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
247  const PetscMatrix<T> * A = cast_ptr<const PetscMatrix<T> *>(&A_in);
248 
249  PetscErrorCode ierr=0;
250 
251  // We shouldn't close() the matrix for you, as that would potentially modify the state of a const object.
252  if (!A->closed())
253  {
254  libmesh_warning("Matrix A must be assembled before calling PetscVector::add_vector(v, A).\n"
255  "Please update your code, as this warning will become an error in a future release.");
256  libmesh_deprecated();
257  const_cast<PetscMatrix<T> *>(A)->close();
258  }
259 
260  // The const_cast<> is not elegant, but it is required since PETSc
261  // expects a non-const Mat.
262  ierr = MatMultAdd(const_cast<PetscMatrix<T> *>(A)->mat(), v->_vec, _vec, _vec);
263  LIBMESH_CHKERR(ierr);
264 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
virtual void close() override
关闭 PetscVector。
template<typename T >
void libMesh::NumericVector< T >::add_vector ( const std::vector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

计算 $ \vec{u} \leftarrow \vec{u} + \vec{v} $,其中 v 是一个 std::vector, 每个 dof_indices[i] 指定了要添加的值 v[i] 的位置 默认实现对每个索引调用 operator() ,但某些实现可能在此处提供更快的方法。 请注意,此方法的库实现是线程安全的。

参数
v包含要添加的值的 std::vector。
dof_indices每个要添加值的位置的索引集合。

在文件 numeric_vector.h1041 行定义.

1043 {
1044  libmesh_assert(v.size() == dof_indices.size());
1045  if (!v.empty())
1046  this->add_vector(v.data(), dof_indices);
1047 }
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
计算 ,其中 v 是一个指针, 每个 dof_indices[i] 指定了要添加的值 v[i] 的位置。 这应该在子类中进行重写以提高效率。请注意,此方法的库实现是线程安全的。 ...
template<typename T >
void libMesh::NumericVector< T >::add_vector ( const NumericVector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inherited

计算 $ \vec{u} \leftarrow \vec{u} + \vec{v} $,其中 v 是一个 NumericVector, 每个 dof_indices[i] 指定了要添加的值 v(i) 的位置。此方法是线程安全的。

参数
v另一个数值向量。
dof_indices每个要添加值的位置的索引集合。

在文件 numeric_vector.C391 行定义.

参考 libMesh::NumericVector< T >::readable() , 以及 libMesh::NumericVector< T >::size().

393 {
394  libmesh_assert(v.readable());
395 
396  const std::size_t n = dof_indices.size();
397  libmesh_assert_equal_to(v.size(), n);
398  for (numeric_index_type i=0; i != n; i++)
399  this->add (dof_indices[i], v(i));
400 }
dof_id_type numeric_index_type
Definition: id_types.h:99
virtual void add(const numeric_index_type i, const T value)=0
将 value 添加到由 i 指定的向量条目。 请注意,此方法的库实现是线程安全的, 例如,将在写入向量之前锁定 _numeric_vector_mutex 。
template<typename T >
void libMesh::NumericVector< T >::add_vector ( const DenseVector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

计算 $ \vec{u} \leftarrow \vec{u} + \vec{v} $,其中 v 是一个 DenseVector, 每个 dof_indices[i] 指定了要添加的值 v(i) 的位置。此方法是线程安全的。

参数
v另一个数值向量。
dof_indices每个要添加值的位置的索引集合。

在文件 numeric_vector.h1053 行定义.

参考 libMesh::DenseVector< T >::empty() , 以及 libMesh::DenseVector< T >::size().

1055 {
1056  libmesh_assert(v.size() == dof_indices.size());
1057  if (!v.empty())
1058  this->add_vector(&v(0), dof_indices);
1059 }
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
计算 ,其中 v 是一个指针, 每个 dof_indices[i] 指定了要添加的值 v[i] 的位置。 这应该在子类中进行重写以提高效率。请注意,此方法的库实现是线程安全的。 ...
template<typename T >
void libMesh::NumericVector< T >::add_vector ( const NumericVector< T > &  v,
const ShellMatrix< T > &  A 
)
inherited

计算 $ \vec{u} \leftarrow \vec{u} + A \vec{v} $, 即将 ShellMatrix ANumericVector v 的乘积添加到 this。

参数
v另一个数值向量。
AShell 矩阵。

在文件 numeric_vector.C405 行定义.

参考 libMesh::ShellMatrix< T >::vector_mult_add().

407 {
408  libmesh_assert(this->compatible(v));
409 
410  a.vector_mult_add(*this,v);
411 }
bool compatible(const NumericVector< T > &v) const
检查该向量和向量 v 是否能够一起用于全局操作。
template<typename T >
void libMesh::PetscVector< T >::add_vector_conjugate_transpose ( const NumericVector< T > &  v,
const SparseMatrix< T > &  A 
)

$ U \leftarrow U + A^H v $.

将共轭转置的 SparseMatrix A 与 NumericVector v 的乘积添加到当前向量。

参数
v向量 v。
A稀疏矩阵 A。

在文件 petsc_vector.C299 行定义.

参考 libMesh::PetscVector< T >::_vec.

301 {
302  parallel_object_only();
303 
304  this->_restore_array();
305  // Make sure the data passed in are really of Petsc types
306  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
307  const PetscMatrix<T> * A = cast_ptr<const PetscMatrix<T> *>(&A_in);
308 
309  // We shouldn't close() the matrix for you, as that would potentially modify the state of a const object.
310  if (!A->closed())
311  {
312  libmesh_warning("Matrix A must be assembled before calling PetscVector::add_vector_conjugate_transpose(v, A).\n"
313  "Please update your code, as this warning will become an error in a future release.");
314  libmesh_deprecated();
315  const_cast<PetscMatrix<T> *>(A)->close();
316  }
317 
318  // Store a temporary copy since MatMultHermitianTransposeAdd doesn't seem to work
319  // TODO: Find out why MatMultHermitianTransposeAdd doesn't work, might be a PETSc bug?
320  std::unique_ptr<NumericVector<Number>> this_clone = this->clone();
321 
322  // The const_cast<> is not elegant, but it is required since PETSc
323  // expects a non-const Mat.
324  PetscErrorCode ierr = MatMultHermitianTranspose(const_cast<PetscMatrix<T> *>(A)->mat(), v->_vec, _vec);
325  LIBMESH_CHKERR(ierr);
326 
327  // Add the temporary copy to the matvec result
328  this->add(1., *this_clone);
329 }
virtual void add(const numeric_index_type i, const T value) override
将索引为 i 的元素值增加 value。
Definition: petsc_vector.C:196
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
virtual std::unique_ptr< NumericVector< T > > clone() const override
克隆该 NumericVector 的独立副本。
virtual void close() override
关闭 PetscVector。
template<typename T >
void libMesh::PetscVector< T >::add_vector_transpose ( const NumericVector< T > &  v,
const SparseMatrix< T > &  A 
)
overridevirtual

使用 SparseMatrix A 的共轭转置与向量 v 进行矩阵乘法,并将结果添加到当前向量。

参数
v向量 v。
A稀疏矩阵 A。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C269 行定义.

参考 libMesh::PetscVector< T >::_vec.

271 {
272  parallel_object_only();
273 
274  this->_restore_array();
275  // Make sure the data passed in are really of Petsc types
276  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
277  const PetscMatrix<T> * A = cast_ptr<const PetscMatrix<T> *>(&A_in);
278 
279  PetscErrorCode ierr=0;
280 
281  // We shouldn't close() the matrix for you, as that would potentially modify the state of a const object.
282  if (!A->closed())
283  {
284  libmesh_warning("Matrix A must be assembled before calling PetscVector::add_vector_transpose(v, A).\n"
285  "Please update your code, as this warning will become an error in a future release.");
286  libmesh_deprecated();
287  const_cast<PetscMatrix<T> *>(A)->close();
288  }
289 
290  // The const_cast<> is not elegant, but it is required since PETSc
291  // expects a non-const Mat.
292  ierr = MatMultTransposeAdd(const_cast<PetscMatrix<T> *>(A)->mat(), v->_vec, _vec, _vec);
293  LIBMESH_CHKERR(ierr);
294 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
virtual void close() override
关闭 PetscVector。
template<typename T >
std::unique_ptr< NumericVector< T > > libMesh::NumericVector< T >::build ( const Parallel::Communicator &  comm,
const SolverPackage  solver_package = libMesh::default_solver_package() 
)
staticinherited

构建一个 NumericVector 对象。

参数
comm通信器对象,表示通信方式。
solver_package线性求解器包的类型。
返回
指向构建的 NumericVector 对象的 unique_ptr。

在文件 numeric_vector.C50 行定义.

参考 libMesh::EIGEN_SOLVERS, libMesh::LASPACK_SOLVERS , 以及 libMesh::TRILINOS_SOLVERS.

参考自 libMesh::DiagonalMatrix< T >::DiagonalMatrix(), libMesh::DofMap::enforce_adjoint_constraints_exactly(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::DofMap::enforce_constraints_on_residual() , 以及 libMesh::DofMap::process_mesh_constraint_rows().

51 {
52  // Build the appropriate vector
53  switch (solver_package)
54  {
55 
56 #ifdef LIBMESH_HAVE_LASPACK
57  case LASPACK_SOLVERS:
58  return std::make_unique<LaspackVector<T>>(comm, AUTOMATIC);
59 #endif
60 
61 #ifdef LIBMESH_HAVE_PETSC
62  case PETSC_SOLVERS:
63  return std::make_unique<PetscVector<T>>(comm, AUTOMATIC);
64 #endif
65 
66 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
67  case TRILINOS_SOLVERS:
68  return std::make_unique<EpetraVector<T>>(comm, AUTOMATIC);
69 #endif
70 
71 #ifdef LIBMESH_HAVE_EIGEN
72  case EIGEN_SOLVERS:
73  return std::make_unique<EigenSparseVector<T>>(comm, AUTOMATIC);
74 #endif
75 
76  default:
77  return std::make_unique<DistributedVector<T>>(comm, AUTOMATIC);
78  }
79 }
EIGEN_SOLVERS
Definition: libmesh.C:249
TRILINOS_SOLVERS
Definition: libmesh.C:247
LASPACK_SOLVERS
Definition: libmesh.C:251
template<typename T >
void libMesh::PetscVector< T >::clear ( )
inlineoverridevirtualnoexcept

从析构函数中调用 clear(),所以它不应引发异常。

重载 libMesh::NumericVector< T > .

在文件 petsc_vector.h1153 行定义.

参考 libMesh::libMeshPrivateData::_is_initialized , 以及 libMesh::initialized().

1154 {
1155  exceptionless_parallel_object_only();
1156 
1157  if (this->initialized())
1158  this->_restore_array();
1159 
1160  if ((this->initialized()) && (this->_destroy_vec_on_exit))
1161  {
1162  // If we encounter an error here, print a warning but otherwise
1163  // keep going since we may be recovering from an exception.
1164  PetscErrorCode ierr = VecDestroy(&_vec);
1165  if (ierr)
1166  libmesh_warning("Warning: VecDestroy returned a non-zero error code which we ignored.");
1167  }
1168 
1169  this->_is_closed = this->_is_initialized = false;
1170 
1171  _global_to_local_map.clear();
1172 }
bool _destroy_vec_on_exit
此布尔值仅在接受 PETSc Vec 对象的构造函数中设置为 false。
Definition: petsc_vector.h:736
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
bool _is_initialized
在调用 init() 后设置为 true。
virtual bool initialized() const
检查向量是否已经初始化。
GlobalToLocalMap _global_to_local_map
用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。
Definition: petsc_vector.h:731
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T >
std::unique_ptr< NumericVector< T > > libMesh::PetscVector< T >::clone ( ) const
inlineoverridevirtual

克隆该 NumericVector 的独立副本。

返回
返回一个指向克隆副本的 std::unique_ptr<NumericVector<T>>。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1226 行定义.

参考 libMesh::NumericVector< T >::init().

1227 {
1228  NumericVector<T> * cloned_vector = new PetscVector<T>(this->comm(), this->type());
1229  cloned_vector->init(*this, true);
1230  *cloned_vector = *this;
1231  return std::unique_ptr<NumericVector<T>>(cloned_vector);
1232 }
ParallelType type() const
获取向量的类型。
template<typename T >
void libMesh::PetscVector< T >::close ( )
inlineoverridevirtual

关闭 PetscVector。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1135 行定义.

参考自 libMesh::PetscVector< T >::localize().

1136 {
1137  parallel_object_only();
1138 
1139  this->_restore_array();
1140 
1141  VecAssemblyBeginEnd(this->comm(), _vec);
1142 
1143  if (this->type() == GHOSTED)
1144  VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
1145 
1146  this->_is_closed = true;
1147 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
ParallelType type() const
获取向量的类型。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T>
virtual bool libMesh::NumericVector< T >::closed ( ) const
inlinevirtualinherited

检查向量是否已经关闭并准备好进行计算。

返回
如果向量已经关闭并准备好进行计算,则返回 true;否则返回 false。

在文件 numeric_vector.h180 行定义.

参考 libMesh::NumericVector< T >::_is_closed.

参考自 libMesh::DofMap::enforce_adjoint_constraints_exactly(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::PetscVector< T >::localize(), libMesh::DofMap::max_constraint_error(), libMesh::EigenSparseVector< T >::operator=(), libMesh::LaspackVector< T >::operator=() , 以及 libMesh::PetscVector< T >::operator=().

180 { return _is_closed; }
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T >
int libMesh::NumericVector< T >::compare ( const NumericVector< T > &  other_vector,
const Real  threshold = TOLERANCE 
) const
virtualinherited

比较 thisother_vector 的等效性,(在给定的 threshold 内) 如果等效则返回 -1 ,或者返回第一个索引,其中 abs(a[i]-b[i]) 超过阈值。

注解
"等效" 表示两个向量非常相似或几乎相同,其差异小于或等于给定的阈值。 这个阈值通常用于考虑浮点数精度问题,因为在计算机中,浮点数运算可能会导致微小的数值差异。 当两个向量被认为等效时,它们的差异小于或等于阈值。 具体来说,这是通过计算两个向量的每个元素之间的差异并将其与阈值进行比较来确定的。 如果两个向量的差异小于阈值,就可以说它们是等效的。 否则,如果差异大于阈值,就可以说它们不等效。
参数
other_vector另一个数值向量。
threshold阈值。
返回
如果向量等效则返回 -1 ,否则返回第一个不等效的索引。

在文件 numeric_vector.C109 行定义.

参考 std::abs().

111 {
112  libmesh_assert(this->compatible(other_vector));
113 
114  int first_different_i = std::numeric_limits<int>::max();
116 
117  while (first_different_i==std::numeric_limits<int>::max()
118  && i<last_local_index())
119  {
120  if (std::abs((*this)(i) - other_vector(i)) > threshold)
121  first_different_i = i;
122  else
123  i++;
124  }
125 
126  // Find the correct first differing index in parallel
127  this->comm().min(first_different_i);
128 
129  if (first_different_i == std::numeric_limits<int>::max())
130  return -1;
131 
132  return first_different_i;
133 }
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的绝对值。
Definition: type_vector.h:112
dof_id_type numeric_index_type
Definition: id_types.h:99
virtual numeric_index_type first_local_index() const =0
获取实际存储在该处理器上的第一个向量元素的索引。
virtual numeric_index_type last_local_index() const =0
获取实际存储在该处理器上的最后一个向量元素的索引+1。
bool compatible(const NumericVector< T > &v) const
检查该向量和向量 v 是否能够一起用于全局操作。
template<typename T >
bool libMesh::NumericVector< T >::compatible ( const NumericVector< T > &  v) const
inherited

检查该向量和向量 v 是否能够一起用于全局操作。

参数
v要比较的另一个向量。
返回
如果这两个向量可以一起用于全局操作,则返回 true,否则返回 false。

在文件 numeric_vector.C423 行定义.

参考 libMesh::NumericVector< T >::first_local_index(), libMesh::NumericVector< T >::last_local_index(), libMesh::NumericVector< T >::local_size(), libMesh::NumericVector< T >::readable() , 以及 libMesh::NumericVector< T >::size().

424 {
425  return this->readable() && v.readable() &&
426  this->size() == v.size() &&
427  this->local_size() == v.local_size() &&
428  this->first_local_index() == v.first_local_index() &&
429  this->last_local_index() == v.last_local_index();
430 }
virtual numeric_index_type size() const =0
获取向量的大小。
bool readable() const
检查该向量是否能够用于全局操作。
virtual numeric_index_type first_local_index() const =0
获取实际存储在该处理器上的第一个向量元素的索引。
virtual numeric_index_type local_size() const =0
获取向量的本地大小,即 index_stop - index_start。
virtual numeric_index_type last_local_index() const =0
获取实际存储在该处理器上的最后一个向量元素的索引+1。
template<typename T >
void libMesh::PetscVector< T >::conjugate ( )
overridevirtual

NumericVector 中的所有元素取共轭。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C182 行定义.

183 {
184  parallel_object_only();
185 
186  PetscErrorCode ierr = 0;
187 
188  // We just call the PETSc VecConjugate
189  ierr = VecConjugate(_vec);
190  LIBMESH_CHKERR(ierr);
191 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
template<typename T >
void libMesh::PetscVector< T >::create_subvector ( NumericVector< T > &  subvector,
const std::vector< numeric_index_type > &  rows 
) const
overridevirtual

创建当前向量的子向量,并将其赋值给 subvector。

参数
subvector用于存储子向量的 NumericVector。
rows子向量的行索引数组。

重载 libMesh::NumericVector< T > .

在文件 petsc_vector.C1189 行定义.

参考 libMesh::NumericVector< T >::_is_initialized, libMesh::PetscVector< T >::_restore_array(), libMesh::PetscVector< T >::_vec, libMesh::WrappedPetsc< T >::get(), libMesh::NumericVector< T >::initialized() , 以及 libMesh::numeric_petsc_cast().

1191 {
1192  parallel_object_only();
1193 
1194  this->_restore_array();
1195 
1196  // PETSc data structures
1197  PetscErrorCode ierr = 0;
1198 
1199  // Make sure the passed in subvector is really a PetscVector
1200  PetscVector<T> * petsc_subvector = cast_ptr<PetscVector<T> *>(&subvector);
1201 
1202  // If the petsc_subvector is already initialized, we assume that the
1203  // user has already allocated the *correct* amount of space for it.
1204  // If not, we use the appropriate PETSc routines to initialize it.
1205  if (!petsc_subvector->initialized())
1206  {
1207  // Initialize the petsc_subvector to have enough space to hold
1208  // the entries which will be scattered into it. Note: such an
1209  // init() function (where we let PETSc decide the number of local
1210  // entries) is not currently offered by the PetscVector
1211  // class. Should we differentiate here between sequential and
1212  // parallel vector creation based on this->n_processors() ?
1213  ierr = VecCreateMPI(this->comm().get(),
1214  PETSC_DECIDE, // n_local
1215  cast_int<PetscInt>(rows.size()), // n_global
1216  &(petsc_subvector->_vec));
1217  LIBMESH_CHKERR(ierr);
1218 
1219  ierr = VecSetFromOptions (petsc_subvector->_vec);
1220  LIBMESH_CHKERR(ierr);
1221 
1222  // Mark the subvector as initialized
1223  petsc_subvector->_is_initialized = true;
1224  }
1225  else
1226  {
1227  petsc_subvector->_restore_array();
1228  }
1229 
1230  // Use iota to fill an array with entries [0,1,2,3,4,...rows.size()]
1231  std::vector<PetscInt> idx(rows.size());
1232  std::iota (idx.begin(), idx.end(), 0);
1233 
1234  // Construct index sets
1235  WrappedPetsc<IS> parent_is;
1236  ierr = ISCreateGeneral(this->comm().get(),
1237  cast_int<PetscInt>(rows.size()),
1238  numeric_petsc_cast(rows.data()),
1239  PETSC_USE_POINTER,
1240  parent_is.get());
1241  LIBMESH_CHKERR(ierr);
1242 
1243  WrappedPetsc<IS> subvector_is;
1244  ierr = ISCreateGeneral(this->comm().get(),
1245  cast_int<PetscInt>(rows.size()),
1246  idx.data(),
1247  PETSC_USE_POINTER,
1248  subvector_is.get());
1249  LIBMESH_CHKERR(ierr);
1250 
1251  // Construct the scatter object
1252  WrappedPetsc<VecScatter> scatter;
1253  ierr = VecScatterCreate(this->_vec,
1254  parent_is,
1255  petsc_subvector->_vec,
1256  subvector_is,
1257  scatter.get()); LIBMESH_CHKERR(ierr);
1258 
1259  // Actually perform the scatter
1260  VecScatterBeginEnd(this->comm(), scatter, this->_vec, petsc_subvector->_vec, INSERT_VALUES, SCATTER_FORWARD);
1261 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

在文件 reference_counter.C100 行定义.

参考 libMesh::ReferenceCounter::_enable_print_counter.

101 {
102  _enable_print_counter = false;
103  return;
104 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
template<typename T >
T libMesh::PetscVector< T >::dot ( const NumericVector< T > &  v) const
overridevirtual

计算当前向量与向量 v 的点积。

参数
v另一个 NumericVector 对象。
返回
返回点积结果。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C475 行定义.

参考 libMesh::PetscVector< T >::_vec.

476 {
477  parallel_object_only();
478 
479  this->_restore_array();
480 
481  // Error flag
482  PetscErrorCode ierr = 0;
483 
484  // Return value
485  PetscScalar value=0.;
486 
487  // Make sure the NumericVector passed in is really a PetscVector
488  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
489 
490  // 2.3.x (at least) style. Untested for previous versions.
491  ierr = VecDot(this->_vec, v->_vec, &value);
492  LIBMESH_CHKERR(ierr);
493 
494  return static_cast<T>(value);
495 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
template<typename T>
virtual T libMesh::NumericVector< T >::el ( const numeric_index_type  i) const
inlinevirtualinherited

获取向量的第 i 个条目。

参数
i要获取的条目的索引。
返回
第 i 个条目的值。

在文件 numeric_vector.h416 行定义.

416 { return (*this)(i); }
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

在文件 reference_counter.C94 行定义.

参考 libMesh::ReferenceCounter::_enable_print_counter.

95 {
96  _enable_print_counter = true;
97  return;
98 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
template<typename T >
numeric_index_type libMesh::PetscVector< T >::first_local_index ( ) const
inlineoverridevirtual

获取 NumericVector 的第一个本地索引。

返回
返回 NumericVector 的第一个本地索引。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1275 行定义.

参考 libMesh::initialized().

1276 {
1277  libmesh_assert (this->initialized());
1278 
1279  numeric_index_type first = 0;
1280 
1281  if (_array_is_present) // Can we use cached values?
1282  first = _first;
1283  else
1284  {
1285  PetscErrorCode ierr=0;
1286  PetscInt petsc_first=0, petsc_last=0;
1287  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1288  LIBMESH_CHKERR(ierr);
1289  first = static_cast<numeric_index_type>(petsc_first);
1290  }
1291 
1292  return first;
1293 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
virtual bool initialized() const
检查向量是否已经初始化。
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
dof_id_type numeric_index_type
Definition: id_types.h:99
numeric_index_type _first
第一个本地索引。
Definition: petsc_vector.h:676
template<typename T >
void libMesh::PetscVector< T >::get ( const std::vector< numeric_index_type > &  index,
T *  values 
) const
inlineoverridevirtual

获取指定索引的元素值。

参数
index索引数组。
values用于存储值的数组。

重载 libMesh::NumericVector< T > .

在文件 petsc_vector.h1403 行定义.

1405 {
1406  this->_get_array(true);
1407 
1408  const std::size_t num = index.size();
1409 
1410  for (std::size_t i=0; i<num; i++)
1411  {
1412  const numeric_index_type local_index = this->map_global_to_local_index(index[i]);
1413 #ifndef NDEBUG
1414  if (this->type() == GHOSTED)
1415  {
1416  libmesh_assert_less (local_index, _local_size);
1417  }
1418 #endif
1419  values[i] = static_cast<T>(_read_only_values[local_index]);
1420  }
1421 }
void _get_array(bool read_only) const
从 PETSc 查询数组(如果向量是幽灵的,则还包括本地形式)。
numeric_index_type _local_size
从 _get_array() 获取本地值的大小。
Definition: petsc_vector.h:688
const PetscScalar * _read_only_values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。
Definition: petsc_vector.h:698
numeric_index_type map_global_to_local_index(const numeric_index_type i) const
dof_id_type numeric_index_type
Definition: id_types.h:99
ParallelType type() const
获取向量的类型。
template<typename T >
void libMesh::NumericVector< T >::get ( const std::vector< numeric_index_type > &  index,
std::vector< T > &  values 
) const
inlineinherited

一次访问多个组件。 values 将被调整大小,如果需要,将被填充。 默认实现对每个索引调用 operator() ,但某些实现可能在此处提供更快的方法。

参数
index要获取的索引集合。
values存储获取值的向量。

在文件 numeric_vector.h1026 行定义.

1028 {
1029  const std::size_t num = index.size();
1030  values.resize(num);
1031  if (!num)
1032  return;
1033 
1034  this->get(index, values.data());
1035 }
template<typename T >
PetscScalar * libMesh::PetscVector< T >::get_array ( )
inline

获取对 PETSc Vector 数据数组的读/写访问权限。

注解
这是一个高级接口。通常情况下,除非你知道自己在做什么,否则应避免使用它!

在文件 petsc_vector.h1426 行定义.

1427 {
1428  _get_array(false);
1430 
1431  return _values;
1432 }
void _get_array(bool read_only) const
从 PETSc 查询数组(如果向量是幽灵的,则还包括本地形式)。
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
bool _values_manually_retrieved
数据数组是否已经通过 get_array() 或 get_array_read() 手动检索。
Definition: petsc_vector.h:741
template<typename T >
const PetscScalar * libMesh::PetscVector< T >::get_array_read ( ) const
inline

获取对 PETSc Vector 数据数组的只读访问权限。

注解
这是一个高级接口。通常情况下,除非你知道自己在做什么,否则应避免使用它!

在文件 petsc_vector.h1437 行定义.

1438 {
1439  _get_array(true);
1441 
1442  return _read_only_values;
1443 }
void _get_array(bool read_only) const
从 PETSc 查询数组(如果向量是幽灵的,则还包括本地形式)。
const PetscScalar * _read_only_values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。
Definition: petsc_vector.h:698
bool _values_manually_retrieved
数据数组是否已经通过 get_array() 或 get_array_read() 手动检索。
Definition: petsc_vector.h:741
std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

在文件 reference_counter.C47 行定义.

参考 libMesh::ReferenceCounter::_counts.

参考自 libMesh::ReferenceCounter::print_info().

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (const auto & [name, cd] : _counts)
59  oss << "| " << name << " reference count information:\n"
60  << "| Creations: " << cd.first << '\n'
61  << "| Destructions: " << cd.second << '\n';
62 
63  oss << " ---------------------------------------------------------------------------- \n";
64 
65  return oss.str();
66 
67 #else
68 
69  return "";
70 
71 #endif
72 }
static Counts _counts
Actually holds the data.
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

在文件 reference_counter.h183 行定义.

参考 libMesh::err.

参考自 libMesh::ReferenceCountedObject< SparseMatrix< T > >::ReferenceCountedObject().

184 {
185  libmesh_try
186  {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189  p.first++;
190  }
191  libmesh_catch (...)
192  {
193  auto stream = libMesh::err.get();
194  stream->exceptions(stream->goodbit); // stream must not throw
195  libMesh::err << "Encountered unrecoverable error while calling "
196  << "ReferenceCounter::increment_constructor_count() "
197  << "for a(n) " << name << " object." << std::endl;
198  std::terminate();
199  }
200 }
OStreamProxy err
static Counts _counts
Actually holds the data.
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

在文件 reference_counter.h207 行定义.

参考 libMesh::err.

参考自 libMesh::ReferenceCountedObject< SparseMatrix< T > >::~ReferenceCountedObject().

208 {
209  libmesh_try
210  {
211  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
212  std::pair<unsigned int, unsigned int> & p = _counts[name];
213  p.second++;
214  }
215  libmesh_catch (...)
216  {
217  auto stream = libMesh::err.get();
218  stream->exceptions(stream->goodbit); // stream must not throw
219  libMesh::err << "Encountered unrecoverable error while calling "
220  << "ReferenceCounter::increment_destructor_count() "
221  << "for a(n) " << name << " object." << std::endl;
222  std::terminate();
223  }
224 }
OStreamProxy err
static Counts _counts
Actually holds the data.
template<typename T >
T libMesh::PetscVector< T >::indefinite_dot ( const NumericVector< T > &  v) const

计算 (*this) 与向量 v 的点积,不使用复数值的共轭。

参数
v另一个 NumericVector 对象。
返回
返回点积结果。

在文件 petsc_vector.C498 行定义.

参考 libMesh::PetscVector< T >::_vec.

499 {
500  parallel_object_only();
501 
502  this->_restore_array();
503 
504  // Error flag
505  PetscErrorCode ierr = 0;
506 
507  // Return value
508  PetscScalar value=0.;
509 
510  // Make sure the NumericVector passed in is really a PetscVector
511  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
512 
513  // 2.3.x (at least) style. Untested for previous versions.
514  ierr = VecTDot(this->_vec, v->_vec, &value);
515  LIBMESH_CHKERR(ierr);
516 
517  return static_cast<T>(value);
518 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
template<typename T >
void libMesh::PetscVector< T >::init ( const numeric_index_type  N,
const numeric_index_type  n_local,
const bool  fast = false,
const ParallelType  type = AUTOMATIC 
)
inlineoverridevirtual

初始化 NumericVector 对象。

参数
N全局维度。
n_local本地维度。
fast是否启用快速初始化,默认为 false。
type并行类型,默认为 AUTOMATIC。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h959 行定义.

参考 libMesh::libMeshPrivateData::_is_initialized, libMesh::initialized() , 以及 libMesh::zero.

参考自 libMesh::PetscVector< T >::localize() , 以及 libMesh::PetscVector< T >::PetscVector().

963 {
964  parallel_object_only();
965 
966  PetscErrorCode ierr=0;
967  PetscInt petsc_n=static_cast<PetscInt>(n);
968 
969  // Clear initialized vectors
970  if (this->initialized())
971  this->clear();
972 
973  if (ptype == AUTOMATIC)
974  {
975  if (n == n_local)
976  this->_type = SERIAL;
977  else
978  this->_type = PARALLEL;
979  }
980  else
981  this->_type = ptype;
982 
983  libmesh_assert ((this->_type==SERIAL && n==n_local) ||
984  this->_type==PARALLEL);
985 
986  // create a sequential vector if on only 1 processor
987  if (this->_type == SERIAL)
988  {
989  ierr = VecCreate(PETSC_COMM_SELF, &_vec);CHKERRABORT(PETSC_COMM_SELF,ierr);
990  ierr = VecSetSizes(_vec, petsc_n, petsc_n); CHKERRABORT(PETSC_COMM_SELF,ierr);
991  ierr = VecSetFromOptions (_vec);
992  CHKERRABORT(PETSC_COMM_SELF,ierr);
993  }
994  // otherwise create an MPI-enabled vector
995  else if (this->_type == PARALLEL)
996  {
997 #ifdef LIBMESH_HAVE_MPI
998  PetscInt petsc_n_local=cast_int<PetscInt>(n_local);
999  libmesh_assert_less_equal (n_local, n);
1000  // Use more generic function instead of VecCreateSeq/MPI
1001  ierr = VecCreate(this->comm().get(), &_vec);LIBMESH_CHKERR(ierr);
1002  ierr = VecSetSizes(_vec, petsc_n_local, petsc_n); LIBMESH_CHKERR(ierr);
1003 #else
1004  libmesh_assert_equal_to (n_local, n);
1005  ierr = VecCreate(PETSC_COMM_SELF, &_vec);CHKERRABORT(PETSC_COMM_SELF,ierr);
1006  ierr = VecSetSizes(_vec, petsc_n, petsc_n); CHKERRABORT(PETSC_COMM_SELF,ierr);
1007 #endif
1008  ierr = VecSetFromOptions (_vec);
1009  LIBMESH_CHKERR(ierr);
1010  }
1011  else
1012  libmesh_error_msg("Unsupported type " << Utility::enum_to_string(this->_type));
1013 
1014  this->_is_initialized = true;
1015  this->_is_closed = true;
1016 
1017 
1018  if (fast == false)
1019  this->zero ();
1020 }
virtual void zero() override
将 PetscVector 的所有元素设置为零。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
bool _is_initialized
在调用 init() 后设置为 true。
virtual bool initialized() const
检查向量是否已经初始化。
ParallelType _type
向量的类型。
virtual void clear() noexceptoverride
从析构函数中调用 clear(),所以它不应引发异常。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T >
void libMesh::PetscVector< T >::init ( const numeric_index_type  N,
const bool  fast = false,
const ParallelType  type = AUTOMATIC 
)
inlineoverridevirtual

初始化 NumericVector 对象。

参数
N全局维度。
fast是否启用快速初始化,默认为 false。
type并行类型,默认为 AUTOMATIC。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1026 行定义.

1029 {
1030  this->init(n,n,fast,ptype);
1031 }
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
初始化 NumericVector 对象。
Definition: petsc_vector.h:959
template<typename T>
virtual void libMesh::PetscVector< T >::init ( const numeric_index_type  N,
const numeric_index_type  n_local,
const std::vector< numeric_index_type > &  ghost,
const bool  fast = false,
const ParallelType  = AUTOMATIC 
)
overridevirtual

初始化 NumericVector 对象。

参数
N全局维度。
n_local本地维度。
ghost指定要保留内存的索引。
fast是否启用快速初始化,默认为 false。
type并行类型,默认为 AUTOMATIC。

实现了 libMesh::NumericVector< T >.

template<typename T >
void libMesh::PetscVector< T >::init ( const NumericVector< T > &  other,
const bool  fast = false 
)
inlineoverridevirtual

使用另一个 NumericVector 对象初始化当前对象。

参数
other另一个 NumericVector 对象。
fast是否启用快速初始化,默认为 false。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1098 行定义.

参考 libMesh::PetscVector< T >::_global_to_local_map, libMesh::libMeshPrivateData::_is_initialized, libMesh::PetscVector< T >::_restore_array(), libMesh::NumericVector< T >::_type, libMesh::PetscVector< T >::_vec, libMesh::NumericVector< T >::initialized(), libMesh::initialized() , 以及 libMesh::zero.

1100 {
1101  parallel_object_only();
1102 
1103  // 清除已初始化的向量
1104  if (this->initialized())
1105  this->clear();
1106 
1107  const PetscVector<T> & v = cast_ref<const PetscVector<T> &>(other);
1108 
1109  // 其他向量应该恢复数组。
1110  if (v.initialized())
1111  {
1112  v._restore_array();
1113  }
1114 
1115  this->_global_to_local_map = v._global_to_local_map;
1116 
1117  // 即使我们基于一个未初始化或未关闭的向量来初始化大小,*这个*向量现在正在初始化,最初是关闭的。
1118  this->_is_closed = true; // v._is_closed;
1119  this->_is_initialized = true; // v._is_initialized;
1120 
1121  this->_type = v._type;
1122 
1123  // 我们希望有一个有效的 Vec,即使它最初的大小为零
1124  PetscErrorCode ierr = VecDuplicate (v._vec, &this->_vec);
1125  LIBMESH_CHKERR(ierr);
1126 
1127  if (fast == false)
1128  this->zero ();
1129 }
virtual void zero() override
将 PetscVector 的所有元素设置为零。
bool _is_initialized
在调用 init() 后设置为 true。
virtual bool initialized() const
检查向量是否已经初始化。
GlobalToLocalMap _global_to_local_map
用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。
Definition: petsc_vector.h:731
ParallelType _type
向量的类型。
virtual void clear() noexceptoverride
从析构函数中调用 clear(),所以它不应引发异常。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T>
virtual bool libMesh::NumericVector< T >::initialized ( ) const
inlinevirtualinherited

检查向量是否已经初始化。

返回
如果向量已经初始化,则返回 true;否则返回 false。

在文件 numeric_vector.h159 行定义.

参考 libMesh::NumericVector< T >::_is_initialized.

参考自 libMesh::PetscVector< T >::create_subvector() , 以及 libMesh::PetscVector< T >::init().

159 { return _is_initialized; }
bool _is_initialized
在调用 init() 后设置为 true。
template<typename T >
void libMesh::PetscVector< T >::insert ( const T *  v,
const std::vector< numeric_index_type > &  dof_indices 
)
overridevirtual

将指定索引数组的元素设置为向量 v 的元素。

参数
v向量 v。
dof_indices指定的索引数组。

重载 libMesh::NumericVector< T > .

在文件 petsc_vector.C390 行定义.

参考 libMesh::numeric_petsc_cast() , 以及 libMesh::pPS().

392 {
393  if (dof_indices.empty())
394  return;
395 
396  this->_restore_array();
397 
398  PetscErrorCode ierr=0;
399  PetscInt * idx_values = numeric_petsc_cast(dof_indices.data());
400  std::scoped_lock lock(this->_numeric_vector_mutex);
401  ierr = VecSetValues (_vec, cast_int<PetscInt>(dof_indices.size()),
402  idx_values, pPS(v), INSERT_VALUES);
403  LIBMESH_CHKERR(ierr);
404 
405  this->_is_closed = false;
406 }
std::mutex _numeric_vector_mutex
用于执行线程安全操作的互斥锁。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscScalar * pPS(T *ptr)
Definition: petsc_macro.h:172
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T >
void libMesh::NumericVector< T >::insert ( const NumericVector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inherited

v 的条目插入到 *this 中,位置由 v 指定。 只要使用 NumericVector 的库实现,此方法是线程安全的。

参数
v一个数值向量。
dof_indices每个要插入值的位置的索引集合。

在文件 numeric_vector.C96 行定义.

参考 libMesh::NumericVector< T >::readable() , 以及 libMesh::NumericVector< T >::size().

98 {
99  libmesh_assert_equal_to (V.size(), dof_indices.size());
100  libmesh_assert (V.readable());
101 
102  for (auto i : index_range(dof_indices))
103  this->set (dof_indices[i], V(i));
104 }
virtual void set(const numeric_index_type i, const T value)=0
设置 v(i) = value 。 请注意,此方法的库实现是线程安全的, 例如,将在写入向量之前锁定 _numeric_vector_mutex 。
template<typename T >
void libMesh::NumericVector< T >::insert ( const DenseVector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

v 的条目插入到 *this 中,位置由 v 指定。 只要使用 NumericVector 的库实现,此方法是线程安全的。

参数
v一个 DenseVector。
dof_indices每个要插入值的位置的索引集合。

在文件 numeric_vector.h1077 行定义.

参考 libMesh::DenseVector< T >::empty() , 以及 libMesh::DenseVector< T >::size().

1079 {
1080  libmesh_assert(v.size() == dof_indices.size());
1081  if (!v.empty())
1082  this->insert(&v(0), dof_indices);
1083 }
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
将 v 的条目插入到 *this 中,位置由 dof_indices 指定。请注意,此方法的库实现是线程安全的。
template<typename T >
void libMesh::NumericVector< T >::insert ( const DenseSubVector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

v 的条目插入到 *this 中,位置由 v 指定。 只要使用 NumericVector 的库实现,此方法是线程安全的。

参数
v一个 DenseSubVector。
dof_indices每个要插入值的位置的索引集合。

在文件 numeric_vector.h1089 行定义.

参考 libMesh::DenseSubVector< T >::empty() , 以及 libMesh::DenseSubVector< T >::size().

1091 {
1092  libmesh_assert(v.size() == dof_indices.size());
1093  if (!v.empty())
1094  this->insert(&v(0), dof_indices);
1095 }
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
将 v 的条目插入到 *this 中,位置由 dof_indices 指定。请注意,此方法的库实现是线程安全的。
template<typename T >
Real libMesh::PetscVector< T >::l1_norm ( ) const
overridevirtual

计算 NumericVector 的 L1 范数。

返回
返回 L1 范数。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C60 行定义.

参考 libMesh::closed() , 以及 libMesh::Real.

61 {
62  this->_restore_array();
63  libmesh_assert(this->closed());
64 
65  PetscErrorCode ierr=0;
66  PetscReal value=0.;
67 
68  ierr = VecNorm (_vec, NORM_1, &value);
69  LIBMESH_CHKERR(ierr);
70 
71  return static_cast<Real>(value);
72 }
virtual bool closed() const
检查向量是否已经关闭并准备好进行计算。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
template<typename T >
Real libMesh::PetscVector< T >::l2_norm ( ) const
overridevirtual

计算 NumericVector 的 L2 范数。

返回
返回 L2 范数。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C77 行定义.

参考 libMesh::closed() , 以及 libMesh::Real.

78 {
79  parallel_object_only();
80 
81  this->_restore_array();
82  libmesh_assert(this->closed());
83 
84  PetscErrorCode ierr=0;
85  PetscReal value=0.;
86 
87  ierr = VecNorm (_vec, NORM_2, &value);
88  LIBMESH_CHKERR(ierr);
89 
90  return static_cast<Real>(value);
91 }
virtual bool closed() const
检查向量是否已经关闭并准备好进行计算。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
template<class T >
Real libMesh::NumericVector< T >::l2_norm_diff ( const NumericVector< T > &  other_vec) const
inherited

获取 $ \ell_2 $-范数的向量差值 $ \vec{u} - \vec{v} $, 其中 $ \vec{u} $this。

参数
other_vec另一个数值向量。
返回
$ \ell_2 $-范数的向量差值。

在文件 numeric_vector.C363 行定义.

参考 std::norm(), libMesh::TensorTools::norm_sq(), libMesh::Real , 以及 std::sqrt().

364 {
365  libmesh_assert(this->compatible(v));
366 
367  Real norm = 0;
368  for (const auto i : make_range(this->first_local_index(), this->last_local_index()))
369  norm += TensorTools::norm_sq((*this)(i) - v(i));
370 
371  this->comm().sum(norm);
372 
373  return std::sqrt(norm);
374 }
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的平方根。
Definition: type_vector.h:88
T norm_sq(std::complex< T > a)
Definition: tensor_tools.h:74
virtual numeric_index_type first_local_index() const =0
获取实际存储在该处理器上的第一个向量元素的索引。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
ADRealEigenVector< T, D, asd > norm(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的范数。
Definition: type_vector.h:64
virtual numeric_index_type last_local_index() const =0
获取实际存储在该处理器上的最后一个向量元素的索引+1。
bool compatible(const NumericVector< T > &v) const
检查该向量和向量 v 是否能够一起用于全局操作。
template<typename T >
numeric_index_type libMesh::PetscVector< T >::last_local_index ( ) const
inlineoverridevirtual

获取 NumericVector 的最后一个本地索引。

返回
返回 NumericVector 的最后一个本地索引。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1299 行定义.

参考 libMesh::initialized().

1300 {
1301  libmesh_assert (this->initialized());
1302 
1303  numeric_index_type last = 0;
1304 
1305  if (_array_is_present) // Can we use cached values?
1306  last = _last;
1307  else
1308  {
1309  PetscErrorCode ierr=0;
1310  PetscInt petsc_first=0, petsc_last=0;
1311  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1312  LIBMESH_CHKERR(ierr);
1313  last = static_cast<numeric_index_type>(petsc_last);
1314  }
1315 
1316  return last;
1317 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
numeric_index_type _last
最后一个本地索引。
Definition: petsc_vector.h:683
virtual bool initialized() const
检查向量是否已经初始化。
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
dof_id_type numeric_index_type
Definition: id_types.h:99
template<typename T >
Real libMesh::PetscVector< T >::linfty_norm ( ) const
overridevirtual

计算 NumericVector 的 Linf 范数。

返回
返回 Linf 范数。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C97 行定义.

参考 libMesh::closed() , 以及 libMesh::Real.

98 {
99  parallel_object_only();
100 
101  this->_restore_array();
102  libmesh_assert(this->closed());
103 
104  PetscErrorCode ierr=0;
105  PetscReal value=0.;
106 
107  ierr = VecNorm (_vec, NORM_INFINITY, &value);
108  LIBMESH_CHKERR(ierr);
109 
110  return static_cast<Real>(value);
111 }
virtual bool closed() const
检查向量是否已经关闭并准备好进行计算。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
template<typename T >
int libMesh::NumericVector< T >::local_relative_compare ( const NumericVector< T > &  other_vector,
const Real  threshold = TOLERANCE 
) const
virtualinherited

比较该向量与另一个向量的局部相对差异。

如果两个向量在给定的局部相对阈值 abs(a[i]-b[i])/max(a[i],b[i]) 下等效,则返回-1,否则返回首个不等效的索引。

参数
other_vector要比较的另一个向量。
threshold允许的局部相对差异阈值(可选,默认值为 TOLERANCE)。
返回
-1 表示等效,否则返回不等效的索引。

在文件 numeric_vector.C137 行定义.

参考 std::abs().

139 {
140  libmesh_assert(this->compatible(other_vector));
141 
142  int first_different_i = std::numeric_limits<int>::max();
144 
145  do
146  {
147  if (std::abs((*this)(i) - other_vector(i)) > threshold *
148  std::max(std::abs((*this)(i)), std::abs(other_vector(i))))
149  first_different_i = i;
150  else
151  i++;
152  }
153  while (first_different_i==std::numeric_limits<int>::max()
154  && i<last_local_index());
155 
156  // Find the correct first differing index in parallel
157  this->comm().min(first_different_i);
158 
159  if (first_different_i == std::numeric_limits<int>::max())
160  return -1;
161 
162  return first_different_i;
163 }
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的绝对值。
Definition: type_vector.h:112
dof_id_type numeric_index_type
Definition: id_types.h:99
virtual numeric_index_type first_local_index() const =0
获取实际存储在该处理器上的第一个向量元素的索引。
virtual numeric_index_type last_local_index() const =0
获取实际存储在该处理器上的最后一个向量元素的索引+1。
bool compatible(const NumericVector< T > &v) const
检查该向量和向量 v 是否能够一起用于全局操作。
template<typename T >
numeric_index_type libMesh::PetscVector< T >::local_size ( ) const
inlineoverridevirtual

获取 NumericVector 的本地大小(本地维度)。

返回
返回 NumericVector 的本地大小(本地维度)。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1258 行定义.

参考 libMesh::initialized().

参考自 libMesh::PetscVector< T >::localize() , 以及 libMesh::PetscVector< T >::operator=().

1259 {
1260  libmesh_assert (this->initialized());
1261 
1262  PetscErrorCode ierr=0;
1263  PetscInt petsc_size=0;
1264 
1265  ierr = VecGetLocalSize(_vec, &petsc_size);
1266  LIBMESH_CHKERR(ierr);
1267 
1268  return static_cast<numeric_index_type>(petsc_size);
1269 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
virtual bool initialized() const
检查向量是否已经初始化。
dof_id_type numeric_index_type
Definition: id_types.h:99
template<typename T >
void libMesh::PetscVector< T >::localize ( std::vector< T > &  v_local) const
overridevirtual

将当前向量的数据本地化到 std::vector v_local 中。

参数
v_local用于存储本地数据的 std::vector。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C863 行定义.

参考自 libMesh::PetscVector< T >::localize().

864 {
865  parallel_object_only();
866 
867  this->_restore_array();
868 
869  // This function must be run on all processors at once
870  parallel_object_only();
871 
872  PetscErrorCode ierr=0;
873  const PetscInt n = this->size();
874  const PetscInt nl = this->local_size();
875  PetscScalar * values;
876 
877  v_local.clear();
878  v_local.resize(n, 0.);
879 
880  ierr = VecGetArray (_vec, &values);
881  LIBMESH_CHKERR(ierr);
882 
884 
885  for (PetscInt i=0; i<nl; i++)
886  v_local[i+ioff] = static_cast<T>(values[i]);
887 
888  ierr = VecRestoreArray (_vec, &values);
889  LIBMESH_CHKERR(ierr);
890 
891  this->comm().sum(v_local);
892 }
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
virtual numeric_index_type first_local_index() const override
获取 NumericVector 的第一个本地索引。
virtual numeric_index_type local_size() const override
获取 NumericVector 的本地大小(本地维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
dof_id_type numeric_index_type
Definition: id_types.h:99
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
template<typename T >
void libMesh::PetscVector< T >::localize ( NumericVector< T > &  v_local) const
overridevirtual

将当前向量的数据本地化到 NumericVector v_local 中。

参数
v_local用于存储本地数据的 NumericVector。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C634 行定义.

参考 libMesh::PetscVector< T >::_vec, libMesh::NumericVector< T >::closed(), libMesh::WrappedPetsc< T >::get(), libMesh::PetscVector< T >::local_size(), libMesh::PetscVector< T >::size() , 以及 libMesh::NumericVector< T >::type().

635 {
636  parallel_object_only();
637 
638  this->_restore_array();
639 
640  // Make sure the NumericVector passed in is really a PetscVector
641  PetscVector<T> * v_local = cast_ptr<PetscVector<T> *>(&v_local_in);
642 
643  libmesh_assert(v_local);
644  // v_local_in should be closed
645  libmesh_assert(v_local->closed());
646  libmesh_assert_equal_to (v_local->size(), this->size());
647  // 1) v_local_in is a large vector to hold the whole world
648  // 2) v_local_in is a ghosted vector
649  // 3) v_local_in is a parallel vector
650  // Cases 2) and 3) should be scalable
651  libmesh_assert(this->size()==v_local->local_size() || this->local_size()==v_local->local_size());
652 
653  PetscErrorCode ierr = 0;
654 
655  if (v_local->type() == SERIAL && this->size() == v_local->local_size())
656  {
657  WrappedPetsc<VecScatter> scatter;
658  ierr = VecScatterCreateToAll(_vec, scatter.get(), nullptr);
659  LIBMESH_CHKERR(ierr);
660  VecScatterBeginEnd(this->comm(), scatter, _vec, v_local->_vec, INSERT_VALUES, SCATTER_FORWARD);
661  }
662  // Two vectors have the same size, and we should just do a simple copy.
663  // v_local could be either a parallel or ghosted vector
664  else if (this->local_size() == v_local->local_size())
665  {
666  ierr = VecCopy(_vec,v_local->_vec);
667  LIBMESH_CHKERR(ierr);
668  }
669  else
670  {
671  libmesh_error_msg("Vectors are inconsistent");
672  }
673 
674  // Make sure ghost dofs are up to date
675  // We do not call "close" here to save a global reduction
676  if (v_local->type() == GHOSTED)
677  VecGhostUpdateBeginEnd(this->comm(), v_local->_vec, INSERT_VALUES, SCATTER_FORWARD);
678 }
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
virtual numeric_index_type local_size() const override
获取 NumericVector 的本地大小(本地维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
template<typename T >
void libMesh::PetscVector< T >::localize ( NumericVector< T > &  v_local,
const std::vector< numeric_index_type > &  indices 
) const
overridevirtual

将当前向量的数据本地化到 NumericVector v_local 中,只包括指定的索引。

参数
v_local用于存储本地数据的 NumericVector。
indices指定的索引数组。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C683 行定义.

参考 libMesh::PetscVector< T >::_vec, libMesh::PetscVector< T >::close(), libMesh::WrappedPetsc< T >::get(), libMesh::PetscVector< T >::size() , 以及 libMesh::NumericVector< T >::type().

685 {
686  parallel_object_only();
687 
688  libmesh_assert(this->comm().verify(int(this->type())));
689  libmesh_assert(this->comm().verify(int(v_local_in.type())));
690 
691  // FIXME: Workaround for a strange bug at large-scale.
692  // If we have ghosting, PETSc lets us just copy the solution, and
693  // doing so avoids a segfault?
694  if (v_local_in.type() == GHOSTED &&
695  this->type() == PARALLEL)
696  {
697  v_local_in = *this;
698  return;
699  }
700 
701  // Normal code path begins here
702 
703  this->_restore_array();
704 
705  // Make sure the NumericVector passed in is really a PetscVector
706  PetscVector<T> * v_local = cast_ptr<PetscVector<T> *>(&v_local_in);
707 
708  libmesh_assert(v_local);
709  libmesh_assert_equal_to (v_local->size(), this->size());
710  libmesh_assert_less_equal (send_list.size(), v_local->size());
711 
712  PetscErrorCode ierr=0;
713  const numeric_index_type n_sl =
714  cast_int<numeric_index_type>(send_list.size());
715 
716  std::vector<PetscInt> idx(n_sl + this->local_size());
717  for (numeric_index_type i=0; i<n_sl; i++)
718  idx[i] = static_cast<PetscInt>(send_list[i]);
719  for (auto i : make_range(this->local_size()))
720  idx[n_sl+i] = i + this->first_local_index();
721 
722  // Create the index set & scatter objects
723  WrappedPetsc<IS> is;
724  PetscInt * idxptr = idx.empty() ? nullptr : idx.data();
725  ierr = ISCreateGeneral(this->comm().get(), n_sl+this->local_size(),
726  idxptr, PETSC_USE_POINTER, is.get());
727  LIBMESH_CHKERR(ierr);
728 
729  WrappedPetsc<VecScatter> scatter;
730  ierr = VecScatterCreate(_vec, is,
731  v_local->_vec, is,
732  scatter.get());
733  LIBMESH_CHKERR(ierr);
734 
735 
736  // Perform the scatter
737  VecScatterBeginEnd(this->comm(), scatter, _vec, v_local->_vec, INSERT_VALUES, SCATTER_FORWARD);
738 
739  // Make sure ghost dofs are up to date
740  if (v_local->type() == GHOSTED)
741  v_local->close();
742 }
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
virtual numeric_index_type first_local_index() const override
获取 NumericVector 的第一个本地索引。
virtual numeric_index_type local_size() const override
获取 NumericVector 的本地大小(本地维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
dof_id_type numeric_index_type
Definition: id_types.h:99
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
ParallelType type() const
获取向量的类型。
template<typename T >
void libMesh::PetscVector< T >::localize ( const numeric_index_type  first_local_idx,
const numeric_index_type  last_local_idx,
const std::vector< numeric_index_type > &  send_list 
)
overridevirtual

本地化当前向量的数据,并将其发送给指定的进程。

参数
first_local_idx第一个本地索引。
last_local_idx最后一个本地索引。
send_list要发送给的进程列表。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C802 行定义.

参考 libMesh::PetscVector< T >::_vec, libMesh::PetscVector< T >::close(), libMesh::WrappedPetsc< T >::get(), libMesh::PetscVector< T >::init() , 以及 libMesh::PetscVector< T >::localize().

805 {
806  parallel_object_only();
807 
808  this->_restore_array();
809 
810  libmesh_assert_less_equal (send_list.size(), this->size());
811  libmesh_assert_less_equal (last_local_idx+1, this->size());
812 
813  const numeric_index_type my_size = this->size();
814  const numeric_index_type my_local_size = (last_local_idx + 1 - first_local_idx);
815  PetscErrorCode ierr=0;
816 
817  // Don't bother for serial cases
818  // if ((first_local_idx == 0) &&
819  // (my_local_size == my_size))
820  // But we do need to stay in sync for degenerate cases
821  if (this->n_processors() == 1)
822  return;
823 
824 
825  // Build a parallel vector, initialize it with the local
826  // parts of (*this)
827  PetscVector<T> parallel_vec(this->comm(), PARALLEL);
828 
829  parallel_vec.init (my_size, my_local_size, true, PARALLEL);
830 
831 
832  // Copy part of *this into the parallel_vec
833  {
834  // Create idx, idx[i] = i+first_local_idx;
835  std::vector<PetscInt> idx(my_local_size);
836  std::iota (idx.begin(), idx.end(), first_local_idx);
837 
838  // Create the index set & scatter objects
839  WrappedPetsc<IS> is;
840  ierr = ISCreateGeneral(this->comm().get(), my_local_size,
841  my_local_size ? idx.data() : nullptr, PETSC_USE_POINTER, is.get());
842  LIBMESH_CHKERR(ierr);
843 
844  WrappedPetsc<VecScatter> scatter;
845  ierr = VecScatterCreate(_vec, is,
846  parallel_vec._vec, is,
847  scatter.get());
848  LIBMESH_CHKERR(ierr);
849 
850  // Perform the scatter
851  VecScatterBeginEnd(this->comm(), scatter, _vec, parallel_vec._vec, INSERT_VALUES, SCATTER_FORWARD);
852  }
853 
854  // localize like normal
855  parallel_vec.close();
856  parallel_vec.localize (*this, send_list);
857  this->close();
858 }
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
dof_id_type numeric_index_type
Definition: id_types.h:99
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
virtual void close() override
关闭 PetscVector。
template<typename T>
virtual void libMesh::NumericVector< T >::localize ( std::vector< T > &  v_local,
const std::vector< numeric_index_type > &  indices 
) const
pure virtualinherited

用全局索引中给定的值填充本地 std::vector "v_local"。

参数
v_local用于存储本地向量的 std::vector。
indices要填充到 v_local 中的全局索引列表。

Fill in the local std::vector "v_local" with the global indices given in "indices".

注解
每个处理器上的索引可能不同, 并且相同的索引可以本地化到多个处理器。 生成的v_local可以比原来的v_local短,并且条目将按照索引指定的顺序排列。

Example:

*   On 4 procs *this = {a, b, c, d, e, f, g, h, i} is a parallel vector.
*   On each proc, the indices arrays are set up as:
*   proc0, indices = {1,2,4,5}
*   proc1, indices = {2,5,6,8}
*   proc2, indices = {2,3,6,7}
*   proc3, indices = {0,1,2,3}
*
*   After calling this version of localize, the v_local vectors are:
*   proc0, v_local = {b,c,e,f}
*   proc1, v_local = {c,f,g,i}
*   proc2, v_local = {c,d,g,h}
*   proc3, v_local = {a,b,c,d}
* 

这个函数在并行I/0例程中很有用,当你有一个解值的并行向量,你想写一个子集。

libMesh::EpetraVector< T >, libMesh::LaspackVector< T >, libMesh::EigenSparseVector< T > , 以及 libMesh::DistributedVector< T > 内被实现.

template<typename T>
virtual void libMesh::PetscVector< T >::localize_to_one ( std::vector< T > &  v_local,
const processor_id_type  proc_id = 0 
) const
overridevirtual

将当前向量的数据本地化到 std::vector v_local 中,只包括一个进程的数据。

参数
v_local用于存储本地数据的 std::vector。
proc_id进程 ID。

实现了 libMesh::NumericVector< T >.

template<>
void libMesh::PetscVector< Real >::localize_to_one ( std::vector< Real > &  v_local,
const processor_id_type   timpi_mpi_varpid 
) const

在文件 petsc_vector.C900 行定义.

参考 libMesh::WrappedPetsc< T >::get().

903 {
904  parallel_object_only();
905 
906  this->_restore_array();
907 
908  PetscErrorCode ierr=0;
909  const PetscInt n = size();
910  PetscScalar * values;
911 
912  // only one processor
913  if (n_processors() == 1)
914  {
915  v_local.resize(n);
916 
917  ierr = VecGetArray (_vec, &values);
918  LIBMESH_CHKERR(ierr);
919 
920  for (PetscInt i=0; i<n; i++)
921  v_local[i] = static_cast<Real>(values[i]);
922 
923  ierr = VecRestoreArray (_vec, &values);
924  LIBMESH_CHKERR(ierr);
925  }
926 
927  // otherwise multiple processors
928 #ifdef LIBMESH_HAVE_MPI
929  else
930  {
931  if (pid == 0) // optimized version for localizing to 0
932  {
933  WrappedPetsc<Vec> vout;
934  WrappedPetsc<VecScatter> ctx;
935 
936  ierr = VecScatterCreateToZero(_vec, ctx.get(), vout.get());
937  LIBMESH_CHKERR(ierr);
938 
939  VecScatterBeginEnd(this->comm(), ctx, _vec, vout, INSERT_VALUES, SCATTER_FORWARD);
940 
941  if (processor_id() == 0)
942  {
943  v_local.resize(n);
944 
945  ierr = VecGetArray (vout, &values);
946  LIBMESH_CHKERR(ierr);
947 
948  for (PetscInt i=0; i<n; i++)
949  v_local[i] = static_cast<Real>(values[i]);
950 
951  ierr = VecRestoreArray (vout, &values);
952  LIBMESH_CHKERR(ierr);
953  }
954  }
955  else
956  {
957  v_local.resize(n);
958 
959  numeric_index_type ioff = this->first_local_index();
960  std::vector<Real> local_values (n, 0.);
961 
962  {
963  ierr = VecGetArray (_vec, &values);
964  LIBMESH_CHKERR(ierr);
965 
966  const PetscInt nl = local_size();
967  for (PetscInt i=0; i<nl; i++)
968  local_values[i+ioff] = static_cast<Real>(values[i]);
969 
970  ierr = VecRestoreArray (_vec, &values);
971  LIBMESH_CHKERR(ierr);
972  }
973 
974 
975  MPI_Reduce (local_values.data(), v_local.data(), n,
976  Parallel::StandardType<Real>(),
977  Parallel::OpFunction<Real>::sum(), pid,
978  this->comm().get());
979  }
980  }
981 #endif // LIBMESH_HAVE_MPI
982 }
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
virtual numeric_index_type first_local_index() const override
获取 NumericVector 的第一个本地索引。
virtual numeric_index_type local_size() const override
获取 NumericVector 的本地大小(本地维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
dof_id_type numeric_index_type
Definition: id_types.h:99
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
template<>
void libMesh::PetscVector< Complex >::localize_to_one ( std::vector< Complex > &  v_local,
const processor_id_type  pid 
) const

在文件 petsc_vector.C991 行定义.

参考 std::imag() , 以及 std::real().

993 {
994  parallel_object_only();
995 
996  this->_restore_array();
997 
998  PetscErrorCode ierr=0;
999  const PetscInt n = size();
1000  const PetscInt nl = local_size();
1001  PetscScalar * values;
1002 
1003 
1004  v_local.resize(n);
1005 
1006 
1007  for (PetscInt i=0; i<n; i++)
1008  v_local[i] = 0.;
1009 
1010  // only one processor
1011  if (n_processors() == 1)
1012  {
1013  ierr = VecGetArray (_vec, &values);
1014  LIBMESH_CHKERR(ierr);
1015 
1016  for (PetscInt i=0; i<n; i++)
1017  v_local[i] = static_cast<Complex>(values[i]);
1018 
1019  ierr = VecRestoreArray (_vec, &values);
1020  LIBMESH_CHKERR(ierr);
1021  }
1022 
1023  // otherwise multiple processors
1024  else
1025  {
1026  numeric_index_type ioff = this->first_local_index();
1027 
1028  /* in here the local values are stored, acting as send buffer for MPI
1029  * initialize to zero, since we collect using MPI_SUM
1030  */
1031  std::vector<Real> real_local_values(n, 0.);
1032  std::vector<Real> imag_local_values(n, 0.);
1033 
1034  {
1035  ierr = VecGetArray (_vec, &values);
1036  LIBMESH_CHKERR(ierr);
1037 
1038  // provide my local share to the real and imag buffers
1039  for (PetscInt i=0; i<nl; i++)
1040  {
1041  real_local_values[i+ioff] = static_cast<Complex>(values[i]).real();
1042  imag_local_values[i+ioff] = static_cast<Complex>(values[i]).imag();
1043  }
1044 
1045  ierr = VecRestoreArray (_vec, &values);
1046  LIBMESH_CHKERR(ierr);
1047  }
1048 
1049  /* have buffers of the real and imaginary part of v_local.
1050  * Once MPI_Reduce() collected all the real and imaginary
1051  * parts in these std::vector<Real>, the values can be
1052  * copied to v_local
1053  */
1054  std::vector<Real> real_v_local(n);
1055  std::vector<Real> imag_v_local(n);
1056 
1057  // collect entries from other proc's in real_v_local, imag_v_local
1058  MPI_Reduce (real_local_values.data(),
1059  real_v_local.data(), n,
1060  Parallel::StandardType<Real>(),
1061  Parallel::OpFunction<Real>::sum(),
1062  pid, this->comm().get());
1063 
1064  MPI_Reduce (imag_local_values.data(),
1065  imag_v_local.data(), n,
1066  Parallel::StandardType<Real>(),
1067  Parallel::OpFunction<Real>::sum(),
1068  pid, this->comm().get());
1069 
1070  // copy real_v_local and imag_v_local to v_local
1071  for (PetscInt i=0; i<n; i++)
1072  v_local[i] = Complex(real_v_local[i], imag_v_local[i]);
1073  }
1074 }
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
virtual numeric_index_type first_local_index() const override
获取 NumericVector 的第一个本地索引。
virtual numeric_index_type local_size() const override
获取 NumericVector 的本地大小(本地维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
dof_id_type numeric_index_type
Definition: id_types.h:99
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
std::complex< Real > Complex
boost::multiprecision::float128 imag(const boost::multiprecision::float128)
template<typename T >
numeric_index_type libMesh::PetscVector< T >::map_global_to_local_index ( const numeric_index_type  i) const
inline
返回
全局索引 i 对应的本地索引。

如果索引不是幽灵单元,那么通过减去第一个本地索引的数量来实现。 如果它是幽灵单元,需要在映射中查找。

在文件 petsc_vector.h1323 行定义.

参考 libMesh::initialized().

1324 {
1325  libmesh_assert (this->initialized());
1326 
1327  numeric_index_type first=0;
1328  numeric_index_type last=0;
1329 
1330  if (_array_is_present) // Can we use cached values?
1331  {
1332  first = _first;
1333  last = _last;
1334  }
1335  else
1336  {
1337  PetscErrorCode ierr=0;
1338  PetscInt petsc_first=0, petsc_last=0;
1339  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1340  LIBMESH_CHKERR(ierr);
1341  first = static_cast<numeric_index_type>(petsc_first);
1342  last = static_cast<numeric_index_type>(petsc_last);
1343  }
1344 
1345 
1346  if ((i>=first) && (i<last))
1347  {
1348  return i-first;
1349  }
1350 
1351  GlobalToLocalMap::const_iterator it = _global_to_local_map.find(i);
1352 #ifndef NDEBUG
1353  const GlobalToLocalMap::const_iterator end = _global_to_local_map.end();
1354  if (it == end)
1355  {
1356  std::ostringstream error_message;
1357  error_message << "No index " << i << " in ghosted vector.\n"
1358  << "Vector contains [" << first << ',' << last << ")\n";
1359  GlobalToLocalMap::const_iterator b = _global_to_local_map.begin();
1360  if (b == end)
1361  {
1362  error_message << "And empty ghost array.\n";
1363  }
1364  else
1365  {
1366  error_message << "And ghost array {" << b->first;
1367  for (++b; b != end; ++b)
1368  error_message << ',' << b->first;
1369  error_message << "}\n";
1370  }
1371 
1372  libmesh_error_msg(error_message.str());
1373  }
1374  libmesh_assert (it != _global_to_local_map.end());
1375 #endif
1376  return it->second+last-first;
1377 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
numeric_index_type _last
最后一个本地索引。
Definition: petsc_vector.h:683
virtual bool initialized() const
检查向量是否已经初始化。
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
GlobalToLocalMap _global_to_local_map
用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。
Definition: petsc_vector.h:731
dof_id_type numeric_index_type
Definition: id_types.h:99
numeric_index_type _first
第一个本地索引。
Definition: petsc_vector.h:676
template<typename T >
Real libMesh::PetscVector< T >::max ( ) const
inlineoverridevirtual

获取 NumericVector 中的最大值。

返回
返回 NumericVector 中的最大值。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1478 行定义.

参考 libMesh::Real.

1479 {
1480  parallel_object_only();
1481 
1482  this->_restore_array();
1483 
1484  PetscErrorCode ierr=0;
1485  PetscInt index=0;
1486  PetscReal returnval=0.;
1487 
1488  ierr = VecMax (_vec, &index, &returnval);
1489  LIBMESH_CHKERR(ierr);
1490 
1491  // this return value is correct: VecMax returns a PetscReal
1492  return static_cast<Real>(returnval);
1493 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
template<typename T >
std::size_t libMesh::PetscVector< T >::max_allowed_id ( ) const
inlineoverridevirtual

获取当前向量允许的最大 ID。

返回
返回允许的最大 ID。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1526 行定义.

1527 {
1528  // The PetscInt type is used for indexing, it may be either a signed
1529  // 4-byte or 8-byte integer depending on how PETSc is configured.
1530  return std::numeric_limits<PetscInt>::max();
1531 }
template<typename T >
Real libMesh::PetscVector< T >::min ( ) const
inlineoverridevirtual

获取 NumericVector 中的最小值。

返回
返回 NumericVector 中的最小值。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1457 行定义.

参考 libMesh::Real.

1458 {
1459  parallel_object_only();
1460 
1461  this->_restore_array();
1462 
1463  PetscErrorCode ierr=0;
1464  PetscInt index=0;
1465  PetscReal returnval=0.;
1466 
1467  ierr = VecMin (_vec, &index, &returnval);
1468  LIBMESH_CHKERR(ierr);
1469 
1470  // this return value is correct: VecMin returns a PetscReal
1471  return static_cast<Real>(returnval);
1472 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

在文件 reference_counter.h85 行定义.

参考 libMesh::ReferenceCounter::_n_objects.

参考自 libMesh::LibMeshInit::~LibMeshInit().

86  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.
template<typename T >
T libMesh::PetscVector< T >::operator() ( const numeric_index_type  i) const
inlineoverridevirtual

访问 NumericVector 对象的元素。

参数
i数值索引。
返回
返回索引为 i 的元素值。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1383 行定义.

1384 {
1385  this->_get_array(true);
1386 
1387  const numeric_index_type local_index = this->map_global_to_local_index(i);
1388 
1389 #ifndef NDEBUG
1390  if (this->type() == GHOSTED)
1391  {
1392  libmesh_assert_less (local_index, _local_size);
1393  }
1394 #endif
1395 
1396  return static_cast<T>(_read_only_values[local_index]);
1397 }
void _get_array(bool read_only) const
从 PETSc 查询数组(如果向量是幽灵的,则还包括本地形式)。
numeric_index_type _local_size
从 _get_array() 获取本地值的大小。
Definition: petsc_vector.h:688
const PetscScalar * _read_only_values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。
Definition: petsc_vector.h:698
numeric_index_type map_global_to_local_index(const numeric_index_type i) const
dof_id_type numeric_index_type
Definition: id_types.h:99
ParallelType type() const
获取向量的类型。
template<typename T>
NumericVector<T>& libMesh::NumericVector< T >::operator*= ( const T  a)
inlineinherited

将向量缩放为 a$ \vec{u} \leftarrow a\vec{u} $。等价于 u.scale(a)。

参数
a缩放因子。
返回
对 *this 的引用。

在文件 numeric_vector.h463 行定义.

参考 libMesh::NumericVector< T >::scale().

463 { this->scale(a); return *this; }
virtual void scale(const T factor)=0
缩放向量的每个元素。
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator*= ( const NumericVector< T > &  v)
overridevirtual

将当前向量与另一个 NumericVector v 逐元素相乘并赋值给当前向量。

参数
v另一个 NumericVector 对象。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C429 行定义.

参考 libMesh::PetscVector< T >::_vec.

430 {
431  parallel_object_only();
432 
433  PetscErrorCode ierr = 0;
434 
435  const PetscVector<T> * v_vec = cast_ptr<const PetscVector<T> *>(&v);
436 
437  ierr = VecPointwiseMult(_vec, _vec, v_vec->_vec);
438  LIBMESH_CHKERR(ierr);
439 
440  return *this;
441 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator+= ( const NumericVector< T > &  v)
overridevirtual

将当前 NumericVector 与另一个 NumericVector v 相加。

参数
v另一个 NumericVector 对象。
返回
返回 *this 的引用。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C118 行定义.

参考 libMesh::closed().

119 {
120  parallel_object_only();
121 
122  this->_restore_array();
123  libmesh_assert(this->closed());
124 
125  this->add(1., v);
126 
127  return *this;
128 }
virtual bool closed() const
检查向量是否已经关闭并准备好进行计算。
virtual void add(const numeric_index_type i, const T value) override
将索引为 i 的元素值增加 value。
Definition: petsc_vector.C:196
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator-= ( const NumericVector< T > &  v)
overridevirtual

将当前 NumericVector 与另一个 NumericVector v 相减。

参数
v另一个 NumericVector 对象。
返回
返回 *this 的引用。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C134 行定义.

参考 libMesh::closed().

135 {
136  parallel_object_only();
137 
138  this->_restore_array();
139  libmesh_assert(this->closed());
140 
141  this->add(-1., v);
142 
143  return *this;
144 }
virtual bool closed() const
检查向量是否已经关闭并准备好进行计算。
virtual void add(const numeric_index_type i, const T value) override
将索引为 i 的元素值增加 value。
Definition: petsc_vector.C:196
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
template<typename T>
NumericVector<T>& libMesh::NumericVector< T >::operator/= ( const T  a)
inlineinherited

将向量缩放为 1/a$ \vec{u} \leftarrow \frac{1}{a}\vec{u} $。等价于 u.scale(1.

/a)。

参数
a缩放因子。
返回
对 *this 的引用。

在文件 numeric_vector.h481 行定义.

参考 libMesh::NumericVector< T >::scale().

481 { this->scale(1./a); return *this; }
virtual void scale(const T factor)=0
缩放向量的每个元素。
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator/= ( const NumericVector< T > &  v)
overridevirtual

将当前向量与另一个 NumericVector v 逐元素相除并赋值给当前向量。

参数
v另一个 NumericVector 对象。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C444 行定义.

参考 libMesh::PetscVector< T >::_vec.

445 {
446  parallel_object_only();
447 
448  PetscErrorCode ierr = 0;
449 
450  const PetscVector<T> * v_vec = cast_ptr<const PetscVector<T> *>(&v);
451 
452  ierr = VecPointwiseDivide(_vec, _vec, v_vec->_vec);
453  LIBMESH_CHKERR(ierr);
454 
455  return *this;
456 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
template<typename T >
PetscVector< T > & libMesh::PetscVector< T >::operator= ( const PetscVector< T > &  v)

复制赋值运算符。 在执行各种检查后调用 VecCopy。

返回
派生类型 *this 的引用。
参数
v要复制的 PetscVector 对象。

在文件 petsc_vector.C566 行定义.

参考 libMesh::PetscVector< T >::_restore_array(), libMesh::PetscVector< T >::_vec, libMesh::NumericVector< T >::closed(), libMesh::PetscVector< T >::local_size() , 以及 libMesh::PetscVector< T >::size().

567 {
568  parallel_object_only();
569 
570  this->_restore_array();
571  v._restore_array();
572 
573  libmesh_assert_equal_to (this->size(), v.size());
574  libmesh_assert_equal_to (this->local_size(), v.local_size());
575  libmesh_assert (v.closed());
576 
577  PetscErrorCode ierr = 0;
578 
579  ierr = VecCopy (v._vec, this->_vec);
580  LIBMESH_CHKERR(ierr);
581 
582  libmesh_assert(this->comm().verify(int(this->type())));
583 
584  if (this->type() == GHOSTED)
585  VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
586 
587  this->_is_closed = true;
588 
589  return *this;
590 }
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
virtual numeric_index_type local_size() const override
获取 NumericVector 的本地大小(本地维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
ParallelType type() const
获取向量的类型。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T>
PetscVector& libMesh::PetscVector< T >::operator= ( PetscVector< T > &&  )
delete
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const T  s)
overridevirtual

NumericVector 中的所有元素设置为标量值 s。

参数
s要赋给所有元素的标量值。
返回
返回 *this 的引用。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C523 行定义.

参考 libMesh::closed() , 以及 libMesh::PS().

524 {
525  parallel_object_only();
526 
527  this->_restore_array();
528  libmesh_assert(this->closed());
529 
530  PetscScalar s = PS(s_in);
531 
532  if (this->size() != 0)
533  {
534  PetscErrorCode ierr = VecSet(_vec, s);
535  LIBMESH_CHKERR(ierr);
536 
537  libmesh_assert(this->comm().verify(int(this->type())));
538 
539  if (this->type() == GHOSTED)
540  VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
541  }
542 
543  return *this;
544 }
virtual bool closed() const
检查向量是否已经关闭并准备好进行计算。
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscScalar PS(T val)
Definition: petsc_macro.h:166
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
ParallelType type() const
获取向量的类型。
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const NumericVector< T > &  v)
overridevirtual

将当前 NumericVector 的内容复制为另一个 NumericVector v。

参数
v另一个 NumericVector 对象。
返回
返回 *this 的引用。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C550 行定义.

551 {
552  parallel_object_only();
553 
554  // Make sure the NumericVector passed in is really a PetscVector
555  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
556 
557  *this = *v;
558 
559  return *this;
560 }
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const std::vector< T > &  v)
overridevirtual

将当前 NumericVector 的内容复制为一个标量值向量 v。

参数
v标量值向量。
返回
返回 *this 的引用。

Case 1: The vector is the same size of The global vector. Only add the local components.

Case 2: The vector is the same size as our local piece. Insert directly to the local piece.

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C596 行定义.

参考 libMesh::PS().

597 {
598  parallel_object_only();
599 
600  this->_get_array(false);
601 
606  if (this->size() == v.size())
607  {
610  for (numeric_index_type i=0; i<last-first; i++)
611  _values[i] = PS(v[first + i]);
612  }
613 
618  else
619  {
620  for (numeric_index_type i=0; i<_local_size; i++)
621  _values[i] = PS(v[i]);
622  }
623 
624  // Make sure ghost dofs are up to date
625  if (this->type() == GHOSTED)
626  this->close();
627 
628  return *this;
629 }
void _get_array(bool read_only) const
从 PETSc 查询数组(如果向量是幽灵的,则还包括本地形式)。
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
numeric_index_type _local_size
从 _get_array() 获取本地值的大小。
Definition: petsc_vector.h:688
virtual numeric_index_type first_local_index() const override
获取 NumericVector 的第一个本地索引。
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
PetscScalar PS(T val)
Definition: petsc_macro.h:166
dof_id_type numeric_index_type
Definition: id_types.h:99
virtual numeric_index_type last_local_index() const override
获取 NumericVector 的最后一个本地索引。
ParallelType type() const
获取向量的类型。
virtual void close() override
关闭 PetscVector。
template<typename T >
void libMesh::PetscVector< T >::pointwise_divide ( const NumericVector< T > &  vec1,
const NumericVector< T > &  vec2 
)
overridevirtual

逐元素将当前向量与 vec1 相除,结果存储在当前向量中。

参数
vec1另一个 NumericVector 对象。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C1105 行定义.

参考 libMesh::PetscVector< T >::vec().

1107 {
1108  parallel_object_only();
1109 
1110  this->_restore_array();
1111 
1112  // Convert arguments to PetscVector*.
1113  const PetscVector<T> * const vec1_petsc = cast_ptr<const PetscVector<T> *>(&vec1);
1114  const PetscVector<T> * const vec2_petsc = cast_ptr<const PetscVector<T> *>(&vec2);
1115 
1116  // Call PETSc function.
1117  PetscErrorCode ierr = VecPointwiseDivide(_vec, vec1_petsc->vec(), vec2_petsc->vec());
1118  LIBMESH_CHKERR(ierr);
1119 
1120  libmesh_assert(this->comm().verify(int(this->type())));
1121 
1122  if (this->type() == GHOSTED)
1123  VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
1124 
1125  this->_is_closed = true;
1126 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
ParallelType type() const
获取向量的类型。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T >
void libMesh::PetscVector< T >::pointwise_mult ( const NumericVector< T > &  vec1,
const NumericVector< T > &  vec2 
)
overridevirtual

逐元素将当前向量与 vec1 相乘,结果存储在当前向量中。

参数
vec1另一个 NumericVector 对象。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C1081 行定义.

参考 libMesh::PetscVector< T >::vec().

1083 {
1084  parallel_object_only();
1085 
1086  this->_restore_array();
1087 
1088  // Convert arguments to PetscVector*.
1089  const PetscVector<T> * vec1_petsc = cast_ptr<const PetscVector<T> *>(&vec1);
1090  const PetscVector<T> * vec2_petsc = cast_ptr<const PetscVector<T> *>(&vec2);
1091 
1092  // Call PETSc function.
1093  PetscErrorCode ierr = VecPointwiseMult(_vec, vec1_petsc->vec(), vec2_petsc->vec());
1094  LIBMESH_CHKERR(ierr);
1095 
1096  libmesh_assert(this->comm().verify(int(this->type())));
1097 
1098  if (this->type() == GHOSTED)
1099  VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
1100 
1101  this->_is_closed = true;
1102 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
ParallelType type() const
获取向量的类型。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T >
void libMesh::NumericVector< T >::print ( std::ostream &  os = libMesh::out) const
inlinevirtualinherited

打印本地向量的内容,默认输出到 libMesh::out 流。

参数
os输出流,用于指定输出位置(可选,默认为 libMesh::out)。

在文件 numeric_vector.h1121 行定义.

参考 libMesh::initialized().

1122 {
1123  libmesh_assert (this->initialized());
1124  os << "Size\tglobal = " << this->size()
1125  << "\t\tlocal = " << this->local_size() << std::endl;
1126 
1127  os << "#\tValue" << std::endl;
1128  for (auto i : index_range(*this))
1129  os << i << "\t" << (*this)(i) << std::endl;
1130 }
virtual numeric_index_type size() const =0
获取向量的大小。
virtual bool initialized() const
检查向量是否已经初始化。
virtual numeric_index_type local_size() const =0
获取向量的本地大小,即 index_stop - index_start。
template<>
void libMesh::NumericVector< Complex >::print ( std::ostream &  os) const
inlineinherited

在文件 numeric_vector.h1103 行定义.

参考 std::imag(), libMesh::initialized() , 以及 std::real().

1104 {
1105  libmesh_assert (this->initialized());
1106  os << "Size\tglobal = " << this->size()
1107  << "\t\tlocal = " << this->local_size() << std::endl;
1108 
1109  // std::complex<>::operator<<() is defined, but use this form
1110  os << "#\tReal part\t\tImaginary part" << std::endl;
1111  for (auto i : index_range(*this))
1112  os << i << "\t"
1113  << (*this)(i).real() << "\t\t"
1114  << (*this)(i).imag() << std::endl;
1115 }
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
virtual numeric_index_type size() const =0
获取向量的大小。
virtual bool initialized() const
检查向量是否已经初始化。
virtual numeric_index_type local_size() const =0
获取向量的本地大小,即 index_stop - index_start。
boost::multiprecision::float128 imag(const boost::multiprecision::float128)
template<typename T >
void libMesh::NumericVector< T >::print_global ( std::ostream &  os = libMesh::out) const
inlinevirtualinherited

打印全局向量的内容,默认输出到 libMesh::out 流。

参数
os输出流,用于指定输出位置(可选,默认为 libMesh::out)。

在文件 numeric_vector.h1158 行定义.

参考 libMesh::initialized().

1159 {
1160  libmesh_assert (this->initialized());
1161 
1162  std::vector<T> v(this->size());
1163  this->localize(v);
1164 
1165  // 现在我们只需要输出的一个副本
1166  if (this->processor_id())
1167  return;
1168 
1169  os << "Size\tglobal = " << this->size() << std::endl;
1170  os << "#\tValue" << std::endl;
1171  for (auto i : make_range(v.size()))
1172  os << i << "\t" << v[i] << std::endl;
1173 }
virtual numeric_index_type size() const =0
获取向量的大小。
virtual bool initialized() const
检查向量是否已经初始化。
virtual void localize(std::vector< T > &v_local) const =0
创建全局向量的副本并存储在本地向量 v_local 中。
template<>
void libMesh::NumericVector< Complex >::print_global ( std::ostream &  os) const
inlineinherited

在文件 numeric_vector.h1136 行定义.

参考 libMesh::initialized().

1137 {
1138  libmesh_assert (this->initialized());
1139 
1140  std::vector<Complex> v(this->size());
1141  this->localize(v);
1142 
1143  // 现在我们只需要输出的一个副本
1144  if (this->processor_id())
1145  return;
1146 
1147  os << "Size\tglobal = " << this->size() << std::endl;
1148  os << "#\tReal part\t\tImaginary part" << std::endl;
1149  for (auto i : make_range(v.size()))
1150  os << i << "\t"
1151  << v[i].real() << "\t\t"
1152  << v[i].imag() << std::endl;
1153 }
virtual numeric_index_type size() const =0
获取向量的大小。
virtual bool initialized() const
检查向量是否已经初始化。
virtual void localize(std::vector< T > &v_local) const =0
创建全局向量的副本并存储在本地向量 v_local 中。
void libMesh::ReferenceCounter::print_info ( std::ostream &  out_stream = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

在文件 reference_counter.C81 行定义.

参考 libMesh::ReferenceCounter::_enable_print_counter , 以及 libMesh::ReferenceCounter::get_info().

参考自 libMesh::LibMeshInit::~LibMeshInit().

82 {
84  out_stream << ReferenceCounter::get_info();
85 }
static std::string get_info()
Gets a string containing the reference information.
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
template<typename T >
void libMesh::PetscVector< T >::print_matlab ( const std::string &  name = "") const
overridevirtual

将当前向量的数据以 MATLAB 格式打印输出。

参数
name输出的名称。

重载 libMesh::NumericVector< T > .

在文件 petsc_vector.C1129 行定义.

参考 libMesh::closed() , 以及 libMesh::WrappedPetsc< T >::get().

1130 {
1131  parallel_object_only();
1132 
1133  this->_restore_array();
1134  libmesh_assert (this->closed());
1135 
1136  PetscErrorCode ierr = 0;
1137 
1138  WrappedPetsc<PetscViewer> petsc_viewer;
1139  ierr = PetscViewerCreate (this->comm().get(), petsc_viewer.get());
1140  LIBMESH_CHKERR(ierr);
1141 
1142  // Create an ASCII file containing the matrix
1143  // if a filename was provided.
1144  if (name != "")
1145  {
1146  ierr = PetscViewerASCIIOpen( this->comm().get(),
1147  name.c_str(),
1148  petsc_viewer.get());
1149  LIBMESH_CHKERR(ierr);
1150 
1151 #if PETSC_VERSION_LESS_THAN(3,7,0)
1152  ierr = PetscViewerSetFormat (petsc_viewer,
1153  PETSC_VIEWER_ASCII_MATLAB);
1154 #else
1155  ierr = PetscViewerPushFormat (petsc_viewer,
1156  PETSC_VIEWER_ASCII_MATLAB);
1157 #endif
1158 
1159  LIBMESH_CHKERR(ierr);
1160 
1161  ierr = VecView (_vec, petsc_viewer);
1162  LIBMESH_CHKERR(ierr);
1163  }
1164 
1165  // Otherwise the matrix will be dumped to the screen.
1166  else
1167  {
1168 
1169 #if PETSC_VERSION_LESS_THAN(3,7,0)
1170  ierr = PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD,
1171  PETSC_VIEWER_ASCII_MATLAB);
1172 #else
1173  ierr = PetscViewerPushFormat (PETSC_VIEWER_STDOUT_WORLD,
1174  PETSC_VIEWER_ASCII_MATLAB);
1175 #endif
1176 
1177  LIBMESH_CHKERR(ierr);
1178 
1179  ierr = VecView (_vec, PETSC_VIEWER_STDOUT_WORLD);
1180  LIBMESH_CHKERR(ierr);
1181  }
1182 }
virtual bool closed() const
检查向量是否已经关闭并准备好进行计算。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
template<typename T >
bool libMesh::NumericVector< T >::readable ( ) const
inherited

检查该向量是否能够用于全局操作。

返回
如果向量可以用于全局操作,则返回 true,否则返回 false。

在文件 numeric_vector.C416 行定义.

参考 libMesh::closed() , 以及 libMesh::initialized().

参考自 libMesh::NumericVector< T >::add_vector(), libMesh::NumericVector< T >::compatible() , 以及 libMesh::NumericVector< T >::insert().

417 {
418  return this->initialized() && this->closed();
419 }
virtual bool closed() const
检查向量是否已经关闭并准备好进行计算。
virtual bool initialized() const
检查向量是否已经初始化。
template<typename T >
void libMesh::PetscVector< T >::reciprocal ( )
overridevirtual

NumericVector 中的所有元素取倒数。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C168 行定义.

169 {
170  parallel_object_only();
171 
172  PetscErrorCode ierr = 0;
173 
174  // VecReciprocal has been in PETSc since at least 2.3.3 days
175  ierr = VecReciprocal(_vec);
176  LIBMESH_CHKERR(ierr);
177 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
template<typename T >
void libMesh::PetscVector< T >::restore_array ( )
inline

恢复数据数组。

注解
在使用 get_array()get_array_read() 获取数组后,必须调用此函数,然后才能使用 PetscVector 上的其他接口函数。

在文件 petsc_vector.h1447 行定义.

1448 {
1449  // \note \p _values_manually_retrieved needs to be set to \p false
1450  // \e before calling \p _restore_array()!
1452  _restore_array();
1453 }
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
bool _values_manually_retrieved
数据数组是否已经通过 get_array() 或 get_array_read() 手动检索。
Definition: petsc_vector.h:741
template<typename T >
void libMesh::PetscVector< T >::scale ( const T  factor)
overridevirtual

缩放当前向量的所有元素。

参数
factor缩放因子。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C411 行定义.

参考 libMesh::PS().

412 {
413  parallel_object_only();
414 
415  this->_restore_array();
416 
417  PetscScalar factor = PS(factor_in);
418 
419  PetscErrorCode ierr = VecScale(_vec, factor);
420  LIBMESH_CHKERR(ierr);
421 
422  libmesh_assert(this->comm().verify(int(this->type())));
423 
424  if (this->type() == GHOSTED)
425  VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
426 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscScalar PS(T val)
Definition: petsc_macro.h:166
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
ParallelType type() const
获取向量的类型。
template<typename T >
void libMesh::PetscVector< T >::set ( const numeric_index_type  i,
const T  value 
)
overridevirtual

设置索引为 i 的元素值为 value。

参数
i数值索引。
value要设置的值。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C149 行定义.

参考 libMesh::PS().

150 {
151  this->_restore_array();
152  libmesh_assert_less (i, size());
153 
154  PetscErrorCode ierr=0;
155  PetscInt i_val = static_cast<PetscInt>(i);
156  PetscScalar petsc_value = PS(value);
157 
158  std::scoped_lock lock(this->_numeric_vector_mutex);
159  ierr = VecSetValues (_vec, 1, &i_val, &petsc_value, INSERT_VALUES);
160  LIBMESH_CHKERR(ierr);
161 
162  this->_is_closed = false;
163 }
std::mutex _numeric_vector_mutex
用于执行线程安全操作的互斥锁。
virtual numeric_index_type size() const override
获取 NumericVector 的大小(维度)。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscScalar PS(T val)
Definition: petsc_macro.h:166
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
template<typename T >
numeric_index_type libMesh::PetscVector< T >::size ( ) const
inlineoverridevirtual

获取 NumericVector 的大小(维度)。

返回
返回 NumericVector 的大小(维度)。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1238 行定义.

参考 libMesh::initialized().

参考自 libMesh::PetscVector< T >::add(), libMesh::PetscVector< T >::localize() , 以及 libMesh::PetscVector< T >::operator=().

1239 {
1240  libmesh_assert (this->initialized());
1241 
1242  PetscErrorCode ierr=0;
1243  PetscInt petsc_size=0;
1244 
1245  if (!this->initialized())
1246  return 0;
1247 
1248  ierr = VecGetSize(_vec, &petsc_size);
1249  LIBMESH_CHKERR(ierr);
1250 
1251  return static_cast<numeric_index_type>(petsc_size);
1252 }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
virtual bool initialized() const
检查向量是否已经初始化。
dof_id_type numeric_index_type
Definition: id_types.h:99
template<class T >
Real libMesh::NumericVector< T >::subset_l1_norm ( const std::set< numeric_index_type > &  indices) const
virtualinherited

获取指定条目的向量的 $ \ell_1 $-范数,即指定条目的绝对值之和。

参数
indices指定的索引集合。
返回
指定条目的向量的 $ \ell_1 $-范数。
注解
索引必须位于此处理器上。

在文件 numeric_vector.C306 行定义.

参考 std::abs(), std::norm() , 以及 libMesh::Real.

307 {
308  libmesh_assert (this->readable());
309 
310  const NumericVector<T> & v = *this;
311 
312  Real norm = 0;
313 
314  for (const auto & index : indices)
315  norm += std::abs(v(index));
316 
317  this->comm().sum(norm);
318 
319  return norm;
320 }
bool readable() const
检查该向量是否能够用于全局操作。
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的绝对值。
Definition: type_vector.h:112
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
ADRealEigenVector< T, D, asd > norm(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的范数。
Definition: type_vector.h:64
template<class T >
Real libMesh::NumericVector< T >::subset_l2_norm ( const std::set< numeric_index_type > &  indices) const
virtualinherited

获取指定条目的向量的 $ \ell_2 $-范数,即指定条目平方和的平方根。

参数
indices指定的索引集合。
返回
指定条目的向量的 $ \ell_2 $-范数。
注解
索引必须位于此处理器上。

在文件 numeric_vector.C323 行定义.

参考 std::norm(), libMesh::TensorTools::norm_sq(), libMesh::Real , 以及 std::sqrt().

324 {
325  libmesh_assert (this->readable());
326 
327  const NumericVector<T> & v = *this;
328 
329  Real norm = 0;
330 
331  for (const auto & index : indices)
332  norm += TensorTools::norm_sq(v(index));
333 
334  this->comm().sum(norm);
335 
336  return std::sqrt(norm);
337 }
bool readable() const
检查该向量是否能够用于全局操作。
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的平方根。
Definition: type_vector.h:88
T norm_sq(std::complex< T > a)
Definition: tensor_tools.h:74
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
ADRealEigenVector< T, D, asd > norm(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的范数。
Definition: type_vector.h:64
template<class T >
Real libMesh::NumericVector< T >::subset_linfty_norm ( const std::set< numeric_index_type > &  indices) const
virtualinherited

获取指定条目的向量的最大绝对值,即指定条目的 $ \ell_{\infty} $-范数。

参数
indices指定的索引集合。
返回
指定条目的向量的最大绝对值。
注解
索引必须位于此处理器上。

在文件 numeric_vector.C340 行定义.

参考 std::abs(), std::norm() , 以及 libMesh::Real.

341 {
342  libmesh_assert (this->readable());
343 
344  const NumericVector<T> & v = *this;
345 
346  Real norm = 0;
347 
348  for (const auto & index : indices)
349  {
350  Real value = std::abs(v(index));
351  if (value > norm)
352  norm = value;
353  }
354 
355  this->comm().max(norm);
356 
357  return norm;
358 }
bool readable() const
检查该向量是否能够用于全局操作。
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的绝对值。
Definition: type_vector.h:112
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
ADRealEigenVector< T, D, asd > norm(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的范数。
Definition: type_vector.h:64
template<typename T >
T libMesh::PetscVector< T >::sum ( ) const
overridevirtual

计算 NumericVector 中的元素之和。

返回
返回 NumericVector 中的元素之和。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.C44 行定义.

参考 libMesh::closed().

45 {
46  this->_restore_array();
47  libmesh_assert(this->closed());
48 
49  PetscErrorCode ierr=0;
50  PetscScalar value=0.;
51 
52  ierr = VecSum (_vec, &value);
53  LIBMESH_CHKERR(ierr);
54 
55  return static_cast<T>(value);
56 }
virtual bool closed() const
检查向量是否已经关闭并准备好进行计算。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
template<typename T >
void libMesh::PetscVector< T >::swap ( NumericVector< T > &  v)
inlineoverridevirtual

交换当前向量与另一个 NumericVector v 的数据。

参数
v另一个 NumericVector 对象。

重载 libMesh::NumericVector< T > .

在文件 petsc_vector.h1499 行定义.

参考 libMesh::PetscVector< T >::_array_is_present, libMesh::PetscVector< T >::_destroy_vec_on_exit, libMesh::PetscVector< T >::_global_to_local_map, libMesh::PetscVector< T >::_local_form, libMesh::PetscVector< T >::_values, libMesh::PetscVector< T >::_vec , 以及 libMesh::NumericVector< T >::swap().

1500 {
1501  parallel_object_only();
1502 
1503  NumericVector<T>::swap(other);
1504 
1505  PetscVector<T> & v = cast_ref<PetscVector<T> &>(other);
1506 
1507  std::swap(_vec, v._vec);
1508  std::swap(_destroy_vec_on_exit, v._destroy_vec_on_exit);
1509  std::swap(_global_to_local_map, v._global_to_local_map);
1510 
1511 #ifdef LIBMESH_HAVE_CXX11_THREAD
1512  // Only truly atomic for v... but swap() doesn't really need to be thread safe!
1513  _array_is_present = v._array_is_present.exchange(_array_is_present);
1514 #else
1515  std::swap(_array_is_present, v._array_is_present);
1516 #endif
1517 
1518  std::swap(_local_form, v._local_form);
1519  std::swap(_values, v._values);
1520 }
bool _destroy_vec_on_exit
此布尔值仅在接受 PETSc Vec 对象的构造函数中设置为 false。
Definition: petsc_vector.h:736
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
PetscScalar * _values
指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 Pe...
Definition: petsc_vector.h:704
std::atomic< bool > _array_is_present
如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。
Definition: petsc_vector.h:666
Vec _local_form
用于保存幽灵向量的本地形式的 PETSc 向量数据类型。仅当向量是幽灵的且 _array_is_present 为真时,此字段的内容才有效。
Definition: petsc_vector.h:693
GlobalToLocalMap _global_to_local_map
用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。
Definition: petsc_vector.h:731
virtual void swap(NumericVector< T > &v)
交换该向量的内容与向量 v 的内容。子类应提供足够的间接性以使此操作成为 O(1) 的头部交换操作。
template<typename T>
ParallelType libMesh::NumericVector< T >::type ( ) const
inlineinherited
template<typename T>
ParallelType& libMesh::NumericVector< T >::type ( )
inlineinherited

获取向量的类型。

返回
向量的类型(SERIAL、PARALLEL、GHOSTED)。

在文件 numeric_vector.h173 行定义.

参考 libMesh::NumericVector< T >::_type.

173 { return _type; }
ParallelType _type
向量的类型。
template<typename T>
Vec libMesh::PetscVector< T >::vec ( )
inline

获取当前向量的原始 PETSc Vec 指针。

注解
通常在用户级代码中不需要使用此函数。
不要尝试像调用 VecDestroy() 这样的操作,否则可能会发生严重问题!
返回
返回原始 PETSc Vec 指针。

在文件 petsc_vector.h641 行定义.

参考 libMesh::PetscVector< T >::_vec.

参考自 libMesh::PetscVector< T >::add(), libMesh::PetscShellMatrix< T >::get_diagonal(), libMesh::PetscMatrix< T >::get_diagonal(), libMesh::PetscVector< T >::pointwise_divide(), libMesh::PetscVector< T >::pointwise_mult(), libMesh::PetscShellMatrix< T >::vector_mult() , 以及 libMesh::PetscShellMatrix< T >::vector_mult_add().

641 { libmesh_assert (_vec); return _vec; }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
template<typename T>
Vec libMesh::PetscVector< T >::vec ( ) const
inline

获取当前向量的原始 PETSc Vec 指针(const 版本)。

注解
通常在用户级代码中不需要使用此函数。
不要尝试像调用 VecDestroy() 这样的操作,否则可能会发生严重问题!
返回
返回原始 PETSc Vec 指针。

在文件 petsc_vector.h652 行定义.

参考 libMesh::PetscVector< T >::_vec.

652 { libmesh_assert (_vec); return _vec; }
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
template<typename T >
void libMesh::PetscVector< T >::zero ( )
inlineoverridevirtual

PetscVector 的所有元素设置为零。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1178 行定义.

参考 libMesh::closed().

1179 {
1180  parallel_object_only();
1181 
1182  libmesh_assert(this->closed());
1183 
1184  this->_restore_array();
1185 
1186  PetscErrorCode ierr=0;
1187 
1188  PetscScalar z=0.;
1189 
1190  if (this->type() != GHOSTED)
1191  {
1192  ierr = VecSet (_vec, z);
1193  LIBMESH_CHKERR(ierr);
1194  }
1195  else
1196  {
1197  /* Vectors that include ghost values require a special
1198  handling. */
1199  Vec loc_vec;
1200  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
1201  LIBMESH_CHKERR(ierr);
1202 
1203  ierr = VecSet (loc_vec, z);
1204  LIBMESH_CHKERR(ierr);
1205 
1206  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
1207  LIBMESH_CHKERR(ierr);
1208  }
1209 }
virtual bool closed() const
检查向量是否已经关闭并准备好进行计算。
Vec _vec
用于保存向量元素的实际 PETSc 向量数据类型。
Definition: petsc_vector.h:659
void _restore_array() const
将数组(如果向量是幽灵的,则还包括本地形式)恢复到 PETSc。
ParallelType type() const
获取向量的类型。
template<typename T >
std::unique_ptr< NumericVector< T > > libMesh::PetscVector< T >::zero_clone ( ) const
inlineoverridevirtual

获取一个零副本的独立指针。

返回
返回一个指向零副本的 std::unique_ptr<NumericVector<T>>。

实现了 libMesh::NumericVector< T >.

在文件 petsc_vector.h1215 行定义.

参考 libMesh::NumericVector< T >::init().

1216 {
1217  NumericVector<T> * cloned_vector = new PetscVector<T>(this->comm(), this->type());
1218  cloned_vector->init(*this);
1219  return std::unique_ptr<NumericVector<T>>(cloned_vector);
1220 }
ParallelType type() const
获取向量的类型。

类成员变量说明

template<typename T>
std::atomic<bool> libMesh::PetscVector< T >::_array_is_present
mutableprivate

如果为 true,则当前 PETSc 向量值的实际数组当前可访问。这意味着成员 _local_form 和 _values 有效。

在文件 petsc_vector.h666 行定义.

参考自 libMesh::PetscVector< T >::swap().

template<typename T>
bool libMesh::PetscVector< T >::_array_is_present
mutableprivate

在文件 petsc_vector.h668 行定义.

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

Actually holds the data.

在文件 reference_counter.h124 行定义.

参考自 libMesh::ReferenceCounter::get_info().

template<typename T>
bool libMesh::PetscVector< T >::_destroy_vec_on_exit
private

此布尔值仅在接受 PETSc Vec 对象的构造函数中设置为 false。

在文件 petsc_vector.h736 行定义.

参考自 libMesh::PetscVector< T >::swap().

bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

在文件 reference_counter.h143 行定义.

参考自 libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info() , 以及 libMesh::ReferenceCounter::print_info().

template<typename T>
numeric_index_type libMesh::PetscVector< T >::_first
mutableprivate

第一个本地索引。

仅当 _array_is_present 为真时有效。

在文件 petsc_vector.h676 行定义.

template<typename T>
GlobalToLocalMap libMesh::PetscVector< T >::_global_to_local_map
private

用于将全局幽灵单元格映射到本地单元格的映射(如果不是幽灵单元格模式,则为空)。

在文件 petsc_vector.h731 行定义.

参考自 libMesh::PetscVector< T >::init(), libMesh::PetscVector< T >::PetscVector() , 以及 libMesh::PetscVector< T >::swap().

template<typename T>
bool libMesh::NumericVector< T >::_is_closed
protectedinherited

用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。

在文件 numeric_vector.h913 行定义.

参考自 libMesh::NumericVector< T >::closed(), libMesh::EpetraVector< T >::EpetraVector(), libMesh::DistributedVector< T >::localize(), libMesh::DistributedVector< T >::operator=() , 以及 libMesh::PetscVector< T >::PetscVector().

template<typename T>
bool libMesh::NumericVector< T >::_is_initialized
protectedinherited
template<typename T>
numeric_index_type libMesh::PetscVector< T >::_last
mutableprivate

最后一个本地索引。

仅当 _array_is_present 为真时有效。

在文件 petsc_vector.h683 行定义.

template<typename T>
Vec libMesh::PetscVector< T >::_local_form
mutableprivate

用于保存幽灵向量的本地形式的 PETSc 向量数据类型。仅当向量是幽灵的且 _array_is_present 为真时,此字段的内容才有效。

在文件 petsc_vector.h693 行定义.

参考自 libMesh::PetscVector< T >::swap().

template<typename T>
numeric_index_type libMesh::PetscVector< T >::_local_size
mutableprivate

_get_array() 获取本地值的大小。

在文件 petsc_vector.h688 行定义.

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

在文件 reference_counter.h137 行定义.

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

在文件 reference_counter.h132 行定义.

参考自 libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter() , 以及 libMesh::ReferenceCounter::~ReferenceCounter().

template<typename T>
std::mutex libMesh::NumericVector< T >::_numeric_vector_mutex
protectedinherited

用于执行线程安全操作的互斥锁。

在文件 numeric_vector.h928 行定义.

template<typename T>
std::mutex libMesh::PetscVector< T >::_petsc_get_restore_array_mutex
mutableprivate

用于 _get_array 和 _restore_array 的互斥锁。这是对象的一部分,以减少从多个 PetscVectors 同时读取时的线程争用。

在文件 petsc_vector.h709 行定义.

template<typename T>
const PetscScalar* libMesh::PetscVector< T >::_read_only_values
mutableprivate

指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。

在文件 petsc_vector.h698 行定义.

template<typename T>
ParallelType libMesh::NumericVector< T >::_type
protectedinherited
template<typename T>
PetscScalar* libMesh::PetscVector< T >::_values
mutableprivate

指向当前 PETSc 向量值的实际数组的指针。仅当 _array_is_present 为真时,此指针才有效。 我们使用了 PETSc 的 VecGetArrayRead() 函数,它需要一个常量 PetscScalar *,但是 _get_array 和 _restore_array 是 const 成员函数,因此 _values 也需要是可变的(否则在那个上下文中它是 "const PetscScalar * const")。

在文件 petsc_vector.h704 行定义.

参考自 libMesh::PetscVector< T >::swap().

template<typename T>
bool libMesh::PetscVector< T >::_values_manually_retrieved
mutableprivate

数据数组是否已经通过 get_array()get_array_read() 手动检索。

在文件 petsc_vector.h741 行定义.

template<typename T>
bool libMesh::PetscVector< T >::_values_read_only
mutableprivate

数据数组是否仅用于只读访问。

在文件 petsc_vector.h746 行定义.

template<typename T>
Vec libMesh::PetscVector< T >::_vec
private

该类的文档由以下文件生成: