libMesh
Loading...
Searching...
No Matches
numeric_vector.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20#ifndef LIBMESH_NUMERIC_VECTOR_H
21#define LIBMESH_NUMERIC_VECTOR_H
22
23// Local includes
24#include "libmesh/libmesh_common.h"
25#include "libmesh/enum_parallel_type.h" // AUTOMATIC
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"
33
34// C++ includes
35#include <cstddef>
36#include <set>
37#include <vector>
38#include <memory>
39#include <mutex>
40#include <string>
41
42namespace libMesh
43{
44
45
46// forward declarations
47template <typename T> class NumericVector;
48template <typename T> class DenseVector;
49template <typename T> class DenseSubVector;
50template <typename T> class SparseMatrix;
51template <typename T> class ShellMatrix;
52enum SolverPackage : int;
53
68template <typename T>
69class NumericVector : public ReferenceCountedObject<NumericVector<T>>,
70 public ParallelObject
71{
72public:
73
77 explicit
79 const ParallelType ptype = AUTOMATIC);
80
84 explicit
86 const numeric_index_type n,
87 const ParallelType ptype = AUTOMATIC);
88
94 const numeric_index_type n,
95 const numeric_index_type n_local,
96 const ParallelType ptype = AUTOMATIC);
97
104 const numeric_index_type N,
105 const numeric_index_type n_local,
106 const std::vector<numeric_index_type> & ghost,
107 const ParallelType ptype = AUTOMATIC);
108
121
127 NumericVector (const NumericVector &) = default;
129
134 virtual ~NumericVector() = default;
135
141 static std::unique_ptr<NumericVector<T>>
144 ParallelType parallel_type = AUTOMATIC);
145
150 virtual bool initialized() const { return _is_initialized; }
151
159 ParallelType type() const { return _type; }
160
170 { return (this->n_processors()==1) || (_type == SERIAL); }
171
183 { return (this->n_processors()!=1) && (_type == GHOSTED); }
184
192#ifdef LIBMESH_ENABLE_DEPRECATED
193 ParallelType & type() { return _type; }
194#endif
195
205 void set_type(ParallelType t);
206
212 void set_options_prefix(std::string prefix) { _options_prefix = std::move(prefix); }
213
217 const std::string & options_prefix() const { return _options_prefix; }
218
223 virtual bool closed() const { return _is_closed; }
224
229 virtual void close () = 0;
230
234 virtual void clear ();
235
240 virtual void zero () = 0;
241
248 virtual std::unique_ptr<NumericVector<T>> zero_clone () const = 0;
249
255 virtual std::unique_ptr<NumericVector<T>> clone () const = 0;
256
267 virtual void init (const numeric_index_type n,
268 const numeric_index_type n_local,
269 const bool fast = false,
270 const ParallelType ptype = AUTOMATIC) = 0;
271
275 virtual void init (const numeric_index_type n,
276 const bool fast = false,
277 const ParallelType ptype = AUTOMATIC) = 0;
278
283 virtual void init (const numeric_index_type n,
284 const numeric_index_type n_local,
285 const std::vector<numeric_index_type> & ghost,
286 const bool fast = false,
287 const ParallelType ptype = AUTOMATIC) = 0;
288
293 virtual void init (const NumericVector<T> & other,
294 const bool fast = false) = 0;
295
301 virtual NumericVector<T> & operator= (const T s) = 0;
302
308 virtual NumericVector<T> & operator= (const std::vector<T> & v) = 0;
309
314 virtual Real min () const = 0;
315
320 virtual Real max () const = 0;
321
325 virtual T sum() const = 0;
326
331 virtual Real l1_norm () const = 0;
332
337 virtual Real l2_norm () const = 0;
338
343 virtual Real linfty_norm () const = 0;
344
351 virtual Real subset_l1_norm (const std::set<numeric_index_type> & indices) const;
352
360 virtual Real subset_l2_norm (const std::set<numeric_index_type> & indices) const;
361
368 virtual Real subset_linfty_norm (const std::set<numeric_index_type> & indices) const;
369
374 Real l2_norm_diff (const NumericVector<T> & other_vec) const;
375
380 Real l1_norm_diff (const NumericVector<T> & other_vec) const;
381
385 virtual numeric_index_type size () const = 0;
386
390 virtual numeric_index_type local_size() const = 0;
391
399
407
411 virtual T operator() (const numeric_index_type i) const = 0;
412
416 virtual T el(const numeric_index_type i) const { return (*this)(i); }
417
424 virtual void get(const std::vector<numeric_index_type> & index,
425 T * values) const;
426
433 void get(const std::vector<numeric_index_type> & index,
434 std::vector<T> & values) const;
435
444
453
461 NumericVector<T> & operator *= (const T a) { this->scale(a); return *this; }
462
471
479 NumericVector<T> & operator /= (const T a) { this->scale(1./a); return *this; }
480
488
493 virtual void reciprocal() = 0;
494
498 virtual void conjugate() = 0;
499
504 virtual void set (const numeric_index_type i, const T value) = 0;
505
510 virtual void add (const numeric_index_type i, const T value) = 0;
511
516 virtual void add (const T s) = 0;
517
523 virtual void add (const NumericVector<T> & v) = 0;
524
530 virtual void add (const T a, const NumericVector<T> & v) = 0;
531
539 virtual void add_vector (const T * v,
540 const std::vector<numeric_index_type> & dof_indices);
541
548 void add_vector (const std::vector<T> & v,
549 const std::vector<numeric_index_type> & dof_indices);
550
557 void add_vector (const NumericVector<T> & v,
558 const std::vector<numeric_index_type> & dof_indices);
559
566 void add_vector (const DenseVector<T> & v,
567 const std::vector<numeric_index_type> & dof_indices);
568
574 virtual void add_vector (const NumericVector<T> & v,
575 const SparseMatrix<T> & A) = 0;
576
582 void add_vector (const NumericVector<T> & v,
583 const ShellMatrix<T> & A);
584
590 virtual void add_vector_transpose (const NumericVector<T> & v,
591 const SparseMatrix<T> & A) = 0;
592
597 virtual void insert (const T * v,
598 const std::vector<numeric_index_type> & dof_indices);
599
604 void insert (const std::vector<T> & v,
605 const std::vector<numeric_index_type> & dof_indices);
606
611 void insert (const NumericVector<T> & v,
612 const std::vector<numeric_index_type> & dof_indices);
613
618 void insert (const DenseVector<T> & v,
619 const std::vector<numeric_index_type> & dof_indices);
620
625 void insert (const DenseSubVector<T> & v,
626 const std::vector<numeric_index_type> & dof_indices);
627
631 virtual void scale (const T factor) = 0;
632
636 virtual void abs() = 0;
637
644 virtual T dot(const NumericVector<T> & v) const = 0;
645
650 virtual void localize (std::vector<T> & v_local) const = 0;
651
656 virtual void localize (NumericVector<T> & v_local) const = 0;
657
662 virtual void localize (NumericVector<T> & v_local,
663 const std::vector<numeric_index_type> & send_list) const = 0;
664
694 virtual void localize (std::vector<T> & v_local,
695 const std::vector<numeric_index_type> & indices) const = 0;
696
701 virtual void localize (const numeric_index_type first_local_idx,
702 const numeric_index_type last_local_idx,
703 const std::vector<numeric_index_type> & send_list) = 0;
704
710 virtual void localize_to_one (std::vector<T> & v_local,
711 const processor_id_type proc_id=0) const = 0;
712
718 virtual int compare (const NumericVector<T> & other_vector,
719 const Real threshold = TOLERANCE) const;
720
726 virtual int local_relative_compare (const NumericVector<T> & other_vector,
727 const Real threshold = TOLERANCE) const;
728
734 virtual int global_relative_compare (const NumericVector<T> & other_vector,
735 const Real threshold = TOLERANCE) const;
736
742 virtual void pointwise_mult (const NumericVector<T> & vec1,
743 const NumericVector<T> & vec2) = 0;
744
750 virtual void pointwise_divide (const NumericVector<T> & vec1,
751 const NumericVector<T> & vec2) = 0;
752
757 virtual void print(std::ostream & os=libMesh::out) const;
758
763 virtual void print_global(std::ostream & os=libMesh::out) const;
764
768 friend std::ostream & operator << (std::ostream & os, const NumericVector<T> & v)
769 {
770 v.print_global(os);
771 return os;
772 }
773
779 virtual void print_matlab(const std::string & filename = "") const;
780
792 virtual void read_matlab(const std::string & filename);
793
807 virtual void create_subvector(NumericVector<T> & /* subvector */,
808 const std::vector<numeric_index_type> & /* rows */,
809 bool /* supplying_global_rows */ = true) const
810 {
811 libmesh_not_implemented();
812 }
813
822 virtual std::unique_ptr<NumericVector<T>>
823 get_subvector(const std::vector<numeric_index_type> & /* rows */)
824 {
825 libmesh_not_implemented();
826 }
827
836 virtual void restore_subvector(std::unique_ptr<NumericVector<T>> /* subvector */,
837 const std::vector<numeric_index_type> & /* rows */)
838 {
839 libmesh_not_implemented();
840 }
841
847 virtual void swap (NumericVector<T> & v);
848
860 virtual std::size_t max_allowed_id() const = 0;
861
866 bool readable() const;
867
872 bool compatible(const NumericVector<T> & v) const;
873
874protected:
875
882
887
892
896 std::string _options_prefix;
897
902};
903
904
905/*----------------------- Inline functions ----------------------------------*/
906
907
908
909template <typename T>
910inline
912 const ParallelType ptype) :
913 ParallelObject(comm_in),
914 _is_closed(false),
915 _is_initialized(false),
916 _type(ptype)
917{
918}
919
920
921
922template <typename T>
923inline
925 const numeric_index_type /*n*/,
926 const ParallelType ptype) :
927 ParallelObject(comm_in),
928 _is_closed(false),
929 _is_initialized(false),
930 _type(ptype)
931{
932 libmesh_not_implemented(); // Abstract base class!
933 // init(n, n, false, ptype);
934}
935
936
937
938template <typename T>
939inline
941 const numeric_index_type /*n*/,
942 const numeric_index_type /*n_local*/,
943 const ParallelType ptype) :
944 ParallelObject(comm_in),
945 _is_closed(false),
946 _is_initialized(false),
947 _type(ptype)
948{
949 libmesh_not_implemented(); // Abstract base class!
950 // init(n, n_local, false, ptype);
951}
952
953
954
955template <typename T>
956inline
958 const numeric_index_type /*n*/,
959 const numeric_index_type /*n_local*/,
960 const std::vector<numeric_index_type> & /*ghost*/,
961 const ParallelType ptype) :
962 ParallelObject(comm_in),
963 _is_closed(false),
964 _is_initialized(false),
965 _type(ptype)
966{
967 libmesh_not_implemented(); // Abstract base class!
968 // init(n, n_local, ghost, false, ptype);
969}
970
971
972
973template <typename T>
974inline
976{
977 _is_closed = false;
978 _is_initialized = false;
979}
980
981
982
983template <typename T>
984inline
985void NumericVector<T>::get(const std::vector<numeric_index_type> & index,
986 T * values) const
987{
988 const std::size_t num = index.size();
989 for (std::size_t i=0; i<num; i++)
990 {
991 values[i] = (*this)(index[i]);
992 }
993}
994
995
996
997template <typename T>
998inline
999void NumericVector<T>::get(const std::vector<numeric_index_type> & index,
1000 std::vector<T> & values) const
1001{
1002 const std::size_t num = index.size();
1003 values.resize(num);
1004 if (!num)
1005 return;
1006
1007 this->get(index, values.data());
1008}
1009
1010
1011
1012template <typename T>
1013inline
1014void NumericVector<T>::add_vector(const std::vector<T> & v,
1015 const std::vector<numeric_index_type> & dof_indices)
1016{
1017 libmesh_assert(v.size() == dof_indices.size());
1018 if (!v.empty())
1019 this->add_vector(v.data(), dof_indices);
1020}
1021
1022
1023
1024template <typename T>
1025inline
1027 const std::vector<numeric_index_type> & dof_indices)
1028{
1029 libmesh_assert(v.size() == dof_indices.size());
1030 if (!v.empty())
1031 this->add_vector(&v(0), dof_indices);
1032}
1033
1034
1035
1036template <typename T>
1037inline
1038void NumericVector<T>::insert(const std::vector<T> & v,
1039 const std::vector<numeric_index_type> & dof_indices)
1040{
1041 libmesh_assert(v.size() == dof_indices.size());
1042 if (!v.empty())
1043 this->insert(v.data(), dof_indices);
1044}
1045
1046
1047
1048template <typename T>
1049inline
1051 const std::vector<numeric_index_type> & dof_indices)
1052{
1053 libmesh_assert(v.size() == dof_indices.size());
1054 if (!v.empty())
1055 this->insert(&v(0), dof_indices);
1056}
1057
1058
1059
1060template <typename T>
1061inline
1063 const std::vector<numeric_index_type> & dof_indices)
1064{
1065 libmesh_assert(v.size() == dof_indices.size());
1066 if (!v.empty())
1067 this->insert(&v(0), dof_indices);
1068}
1069
1070
1071
1072// Full specialization of the print() member for complex
1073// variables. This must precede the non-specialized
1074// version, at least according to icc v7.1
1075template <>
1076inline
1077void NumericVector<Complex>::print(std::ostream & os) const
1078{
1079 libmesh_assert (this->initialized());
1080 os << "Size\tglobal = " << this->size()
1081 << "\t\tlocal = " << this->local_size() << std::endl;
1082
1083 // std::complex<>::operator<<() is defined, but use this form
1084 os << "#\tReal part\t\tImaginary part" << std::endl;
1085 for (auto i : index_range(*this))
1086 os << i << "\t"
1087 << (*this)(i).real() << "\t\t"
1088 << (*this)(i).imag() << std::endl;
1089}
1090
1091
1092
1093template <typename T>
1094inline
1095void NumericVector<T>::print(std::ostream & os) const
1096{
1097 libmesh_assert (this->initialized());
1098 os << "Size\tglobal = " << this->size()
1099 << "\t\tlocal = " << this->local_size() << std::endl;
1100
1101 os << "#\tValue" << std::endl;
1102 for (auto i : index_range(*this))
1103 os << i << "\t" << (*this)(i) << std::endl;
1104}
1105
1106
1107
1108template <>
1109inline
1110void NumericVector<Complex>::print_global(std::ostream & os) const
1111{
1112 libmesh_assert (this->initialized());
1113
1114 std::vector<Complex> v(this->size());
1115 this->localize(v);
1116
1117 // Right now we only want one copy of the output
1118 if (this->processor_id())
1119 return;
1120
1121 os << "Size\tglobal = " << this->size() << std::endl;
1122 os << "#\tReal part\t\tImaginary part" << std::endl;
1123 for (auto i : make_range(v.size()))
1124 os << i << "\t"
1125 << v[i].real() << "\t\t"
1126 << v[i].imag() << std::endl;
1127}
1128
1129
1130template <typename T>
1131inline
1132void NumericVector<T>::print_global(std::ostream & os) const
1133{
1134 libmesh_assert (this->initialized());
1135
1136 std::vector<T> v(this->size());
1137 this->localize(v);
1138
1139 // Right now we only want one copy of the output
1140 if (this->processor_id())
1141 return;
1142
1143 os << "Size\tglobal = " << this->size() << std::endl;
1144 os << "#\tValue" << std::endl;
1145 for (auto i : make_range(v.size()))
1146 os << i << "\t" << v[i] << std::endl;
1147}
1148
1149
1150
1151template <typename T>
1152inline
1154{
1155 std::swap(_is_closed, v._is_closed);
1156 std::swap(_is_initialized, v._is_initialized);
1157 std::swap(_type, v._type);
1158 std::swap(_options_prefix, v._options_prefix);
1159}
1160
1161template <typename T>
1162auto
1164{
1165 return vec.l1_norm();
1166}
1167
1168template <typename T>
1169auto
1171{
1172 return vec1.l1_norm_diff(vec2);
1173}
1174
1175} // namespace libMesh
1176
1177
1178// Workaround for weird boost/NumericVector interaction bug
1179#ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
1180#include <boost/mpl/bool.hpp>
1181
1182namespace boost { namespace multiprecision { namespace detail {
1183template <typename T, typename To>
1184struct is_lossy_conversion<libMesh::NumericVector<T>, To> {
1185 typedef boost::mpl::true_ type;
1186 static const bool value = type::value;
1187};
1188}}}
1189#endif
1190
1191
1192#endif // LIBMESH_NUMERIC_VECTOR_H
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.
void set_options_prefix(std::string prefix)
Sets the prefix that solver packages prepend to option names when they configure this vector,...
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).
std::string _options_prefix
Prefix for solver-package options.
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.
const std::string & options_prefix() const
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
ParallelType & type()
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.
virtual T sum() const =0
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.
Generic sparse matrix.
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...
Definition int_range.h:153
ParallelType
Defines an enum for parallel data structure types.
SolverPackage default_solver_package()
Definition libmesh.C:1064
libmesh_assert(ctx)
OStreamProxy out
dof_id_type numeric_index_type
Definition id_types.h:99
SolverPackage
Defines an enum for various linear solver packages.
bool initialized()
Checks that library initialization has been done.
Definition libmesh.C:324
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
Definition id_types.h:104
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...
Definition int_range.h:176
static const bool value
Definition xdr_io.C:55