20#ifndef LIBMESH_NUMERIC_VECTOR_H
21#define LIBMESH_NUMERIC_VECTOR_H
24#include "libmesh/libmesh_common.h"
25#include "libmesh/enum_parallel_type.h"
26#include "libmesh/id_types.h"
27#include "libmesh/int_range.h"
28#include "libmesh/reference_counted_object.h"
29#include "libmesh/libmesh.h"
30#include "libmesh/parallel_object.h"
31#include "libmesh/dense_subvector.h"
32#include "libmesh/dense_vector.h"
46template <
typename T>
class NumericVector;
47template <
typename T>
class DenseVector;
48template <
typename T>
class DenseSubVector;
49template <
typename T>
class SparseMatrix;
50template <
typename T>
class ShellMatrix;
105 const std::vector<numeric_index_type> & ghost,
140 static std::unique_ptr<NumericVector<T>>
191#ifdef LIBMESH_ENABLE_DEPRECATED
235 virtual std::unique_ptr<NumericVector<T>>
zero_clone ()
const = 0;
242 virtual std::unique_ptr<NumericVector<T>>
clone ()
const = 0;
256 const bool fast =
false,
263 const bool fast =
false,
272 const std::vector<numeric_index_type> & ghost,
273 const bool fast =
false,
281 const bool fast =
false) = 0;
312 virtual T
sum()
const = 0;
411 virtual void get(
const std::vector<numeric_index_type> & index,
420 void get(
const std::vector<numeric_index_type> & index,
421 std::vector<T> & values)
const;
503 virtual void add (
const T s) = 0;
527 const std::vector<numeric_index_type> & dof_indices);
536 const std::vector<numeric_index_type> & dof_indices);
545 const std::vector<numeric_index_type> & dof_indices);
554 const std::vector<numeric_index_type> & dof_indices);
584 virtual void insert (
const T * v,
585 const std::vector<numeric_index_type> & dof_indices);
592 const std::vector<numeric_index_type> & dof_indices);
599 const std::vector<numeric_index_type> & dof_indices);
606 const std::vector<numeric_index_type> & dof_indices);
613 const std::vector<numeric_index_type> & dof_indices);
618 virtual void scale (
const T factor) = 0;
637 virtual void localize (std::vector<T> & v_local)
const = 0;
650 const std::vector<numeric_index_type> & send_list)
const = 0;
682 const std::vector<numeric_index_type> & indices)
const = 0;
690 const std::vector<numeric_index_type> & send_list) = 0;
766 virtual void print_matlab(
const std::string & filename =
"")
const;
779 virtual void read_matlab(
const std::string & filename);
795 const std::vector<numeric_index_type> & ,
798 libmesh_not_implemented();
809 virtual std::unique_ptr<NumericVector<T>>
812 libmesh_not_implemented();
824 const std::vector<numeric_index_type> & )
826 libmesh_not_implemented();
897 _is_initialized(false),
911 _is_initialized(false),
914 libmesh_not_implemented();
928 _is_initialized(false),
931 libmesh_not_implemented();
942 const std::vector<numeric_index_type> & ,
946 _is_initialized(false),
949 libmesh_not_implemented();
960 _is_initialized =
false;
970 const std::size_t num = index.size();
971 for (std::size_t i=0; i<num; i++)
973 values[i] = (*this)(index[i]);
982 std::vector<T> & values)
const
984 const std::size_t num = index.size();
989 this->get(index, values.data());
997 const std::vector<numeric_index_type> & dof_indices)
1001 this->add_vector(v.data(), dof_indices);
1006template <
typename T>
1009 const std::vector<numeric_index_type> & dof_indices)
1013 this->add_vector(&v(0), dof_indices);
1018template <
typename T>
1021 const std::vector<numeric_index_type> & dof_indices)
1025 this->insert(v.data(), dof_indices);
1030template <
typename T>
1033 const std::vector<numeric_index_type> & dof_indices)
1037 this->insert(&v(0), dof_indices);
1042template <
typename T>
1045 const std::vector<numeric_index_type> & dof_indices)
1049 this->insert(&v(0), dof_indices);
1062 os <<
"Size\tglobal = " << this->size()
1063 <<
"\t\tlocal = " << this->local_size() << std::endl;
1066 os <<
"#\tReal part\t\tImaginary part" << std::endl;
1069 << (*
this)(i).real() <<
"\t\t"
1070 << (*this)(i).imag() << std::endl;
1075template <
typename T>
1080 os <<
"Size\tglobal = " << this->size()
1081 <<
"\t\tlocal = " << this->local_size() << std::endl;
1083 os <<
"#\tValue" << std::endl;
1085 os << i <<
"\t" << (*
this)(i) << std::endl;
1096 std::vector<Complex> v(this->size());
1100 if (this->processor_id())
1103 os <<
"Size\tglobal = " << this->size() << std::endl;
1104 os <<
"#\tReal part\t\tImaginary part" << std::endl;
1107 << v[i].real() <<
"\t\t"
1108 << v[i].imag() << std::endl;
1112template <
typename T>
1118 std::vector<T> v(this->size());
1122 if (this->processor_id())
1125 os <<
"Size\tglobal = " << this->size() << std::endl;
1126 os <<
"#\tValue" << std::endl;
1128 os << i <<
"\t" << v[i] << std::endl;
1133template <
typename T>
1139 std::swap(_type, v.
_type);
1142template <
typename T>
1149template <
typename T>
1160#ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
1161#include <boost/mpl/bool.hpp>
1163namespace boost {
namespace multiprecision {
namespace detail {
1164template <
typename T,
typename To>
1165struct is_lossy_conversion<
libMesh::NumericVector<T>, To> {
void ErrorVector unsigned int
Defines a dense subvector for use in finite element computations.
virtual unsigned int size() const override final
virtual bool empty() const override final
Defines a dense vector for use in Finite Element-type computations.
virtual bool empty() const override final
virtual unsigned int size() const override final
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2)=0
Computes (summation not implied) i.e.
virtual std::unique_ptr< NumericVector< T > > get_subvector(const std::vector< numeric_index_type > &)
Creates a view into this vector using the indices in rows.
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
virtual void get(const std::vector< numeric_index_type > &index, T *values) const
Access multiple components at once.
virtual void init(const NumericVector< T > &other, const bool fast=false)=0
Creates a vector that has the same dimension and storage type as other, including ghost dofs.
virtual Real l1_norm() const =0
Real l1_norm_diff(const NumericVector< T > &other_vec) const
virtual numeric_index_type last_local_index() const =0
bool is_effectively_serial() const
virtual void create_subvector(NumericVector< T > &, const std::vector< numeric_index_type > &, bool=true) const
Fills in subvector from this vector using the indices in rows.
virtual void clear()
Restores the NumericVector<T> to a pristine state.
ParallelType type() const
void add_vector(const DenseVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a DenseVector and each dof_indices[i] specifies where to add value v(i).
void set_type(ParallelType t)
Allow the user to change the ParallelType of the NumericVector under some circumstances.
virtual T operator()(const numeric_index_type i) const =0
virtual NumericVector< T > & operator+=(const NumericVector< T > &v)=0
Adds v to *this, .
virtual Real max() const =0
Real l2_norm_diff(const NumericVector< T > &other_vec) const
virtual std::size_t max_allowed_id() const =0
bool is_effectively_ghosted() const
virtual void conjugate()=0
Negates the imaginary component of each entry in the vector.
virtual void localize(std::vector< T > &v_local, const std::vector< numeric_index_type > &indices) const =0
Fill in the local std::vector "v_local" with the global indices given in "indices".
virtual void print(std::ostream &os=libMesh::out) const
Prints the local contents of the vector, by default to libMesh::out.
void get(const std::vector< numeric_index_type > &index, std::vector< T > &values) const
Access multiple components at once.
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
virtual void read_matlab(const std::string &filename)
Read the contents of the vector from the Matlab-script format used by PETSc.
NumericVector(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 ptype=AUTOMATIC)
Constructor.
virtual void swap(NumericVector< T > &v)
Swaps the contents of this with v.
virtual T dot(const NumericVector< T > &v) const =0
virtual NumericVector< T > & operator-=(const NumericVector< T > &v)=0
Subtracts v from *this, .
void add_vector(const std::vector< T > &v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a std::vector and each dof_indices[i] specifies where to add value v[i].
virtual void print_matlab(const std::string &filename="") const
Print the contents of the vector in Matlab's sparse matrix format.
ParallelType _type
Type of vector.
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
Inserts the entries of v in *this at the locations specified by v.
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i].
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
virtual bool initialized() const
virtual void abs()=0
Sets for each entry in the vector.
NumericVector(const NumericVector &)=default
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
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)=0
Updates a local vector with selected values from neighboring processors, as defined by send_list.
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.
virtual void add_vector_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A)=0
Computes , i.e.
virtual Real l2_norm() const =0
std::mutex _numeric_vector_mutex
Mutex for performing thread-safe operations.
bool _is_initialized
true once init() has been called.
virtual void scale(const T factor)=0
Scale each element of the vector by the given factor.
virtual void add_vector(const NumericVector< T > &v, const SparseMatrix< T > &A)=0
Computes , i.e.
NumericVector(const Parallel::Communicator &comm_in, const numeric_index_type n, const ParallelType ptype=AUTOMATIC)
Constructor.
virtual void zero()=0
Set all entries to zero.
virtual void localize_to_one(std::vector< T > &v_local, const processor_id_type proc_id=0) const =0
Creates a local copy of the global vector in v_local only on processor proc_id.
virtual void print_global(std::ostream &os=libMesh::out) const
Prints the global contents of the vector, by default to libMesh::out.
virtual numeric_index_type size() const =0
virtual void localize(NumericVector< T > &v_local) const =0
Same, but fills a NumericVector<T> instead of a std::vector.
virtual std::unique_ptr< NumericVector< T > > clone() const =0
virtual Real linfty_norm() const =0
bool _is_closed
Flag which tracks whether the vector's values are consistent on all processors after insertion or add...
NumericVector(NumericVector &&)=default
These 3 special functions can be defaulted for this class, as it does not manage any memory itself.
virtual bool closed() const
virtual void add(const T a, const NumericVector< T > &v)=0
Vector addition with a scalar multiple, .
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 ptype=AUTOMATIC)=0
Create a vector that holds the local indices plus those specified in the ghost argument.
bool compatible(const NumericVector< T > &v) const
virtual void reciprocal()=0
Computes the component-wise reciprocal, .
virtual NumericVector< T > & operator=(const NumericVector< T > &v)=0
This looks like a copy assignment operator, but note that, unlike normal copy assignment operators,...
friend std::ostream & operator<<(std::ostream &os, const NumericVector< T > &v)
Same as above but allows you to use stream syntax.
virtual std::unique_ptr< NumericVector< T > > zero_clone() const =0
virtual void localize(NumericVector< T > &v_local, const std::vector< numeric_index_type > &send_list) const =0
Creates a local vector v_local containing only information relevant to this processor,...
void insert(const DenseVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
Inserts the entries of v in *this at the locations specified by v.
virtual Real min() const =0
virtual void restore_subvector(std::unique_ptr< NumericVector< T > >, const std::vector< numeric_index_type > &)
Restores a view into this vector using the indices in rows.
NumericVector(const Parallel::Communicator &comm_in, const numeric_index_type n, const numeric_index_type n_local, const ParallelType ptype=AUTOMATIC)
Constructor.
virtual Real subset_l1_norm(const std::set< numeric_index_type > &indices) const
virtual void init(const numeric_index_type n, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Call init() with n_local = N.
NumericVector< T > & operator/=(const T a)
Scales the vector by 1/a, .
virtual numeric_index_type local_size() const =0
virtual void add(const numeric_index_type i, const T value)=0
Adds value to the vector entry specified by i.
NumericVector< T > & operator*=(const T a)
Scales the vector by a, .
virtual Real subset_l2_norm(const std::set< numeric_index_type > &indices) const
void insert(const std::vector< T > &v, const std::vector< numeric_index_type > &dof_indices)
Inserts the entries of v in *this at the locations specified by v.
virtual int compare(const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
virtual numeric_index_type first_local_index() const =0
void insert(const DenseSubVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
Inserts the entries of v in *this at the locations specified by v.
virtual void add(const T s)=0
Adds s to each entry of the vector, .
virtual ~NumericVector()=default
While this class doesn't manage any memory, the derived class might and users may be deleting through...
NumericVector(const Parallel::Communicator &comm_in, const ParallelType ptype=AUTOMATIC)
Dummy-Constructor.
virtual void pointwise_divide(const NumericVector< T > &vec1, const NumericVector< T > &vec2)=0
Computes (summation not implied) i.e.
virtual T el(const numeric_index_type i) const
virtual void add(const NumericVector< T > &v)=0
Adds v to this, .
virtual int local_relative_compare(const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
virtual int global_relative_compare(const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
virtual Real subset_linfty_norm(const std::set< numeric_index_type > &indices) const
An object whose state is distributed along a set of processors.
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
This class implements reference counting.
Generic shell matrix, i.e.
The libMesh namespace provides an interface to certain functionality in the library.
auto l1_norm(const NumericVector< T > &vec)
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
ParallelType
Defines an enum for parallel data structure types.
SolverPackage default_solver_package()
dof_id_type numeric_index_type
SolverPackage
Defines an enum for various linear solver packages.
bool initialized()
Checks that library initialization has been done.
static constexpr Real TOLERANCE
auto l1_norm_diff(const NumericVector< T > &vec1, const NumericVector< T > &vec2)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...