FEI Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
fei_CSVec.hpp
Go to the documentation of this file.
1#ifndef _fei_CSVec_hpp_
2#define _fei_CSVec_hpp_
3
4/*--------------------------------------------------------------------*/
5/* Copyright 2005 Sandia Corporation. */
6/* Under the terms of Contract DE-AC04-94AL85000, there is a */
7/* non-exclusive license for use of this work by or on behalf */
8/* of the U.S. Government. Export of this program may require */
9/* a license from the United States Government. */
10/*--------------------------------------------------------------------*/
11
12#include <fei_macros.hpp>
13#include <vector>
14#include <algorithm>
15
16namespace fei {
17
24class CSVec {
25 public:
26 CSVec(unsigned sz=0);
27 virtual ~CSVec();
28
29 CSVec& operator=(const CSVec& invec);
30
31 std::vector<int>& indices() {return indices_;}
32 const std::vector<int>& indices() const {return indices_;}
33 std::vector<double>& coefs() {return coefs_;}
34 const std::vector<double>& coefs() const {return coefs_;}
35
36 size_t size() const {return indices_.size();}
37
38 void clear() { indices_.clear(); coefs_.clear(); }
39
40 bool operator==(const CSVec& rhs) const {
41 return indices_==rhs.indices_ && coefs_==rhs.coefs_;
42 }
43
44 bool operator!=(const CSVec& rhs) const {
45 return indices_!=rhs.indices_ || coefs_!=rhs.coefs_;
46 }
47
48 void subtract(const CSVec& rhs);
49
50 private:
51 std::vector<int> indices_;
52 std::vector<double> coefs_;
53};//class CSVec
54
55inline
56void add_entry(CSVec& vec, int eqn, double coef)
57{
58 std::vector<int>& v_ind = vec.indices();
59 std::vector<double>& v_coef = vec.coefs();
60
61 std::vector<int>::iterator
62 iter = std::lower_bound(v_ind.begin(), v_ind.end(), eqn);
63
64 size_t offset = iter - v_ind.begin();
65
66 if (iter == v_ind.end() || *iter != eqn) {
67 v_ind.insert(iter, eqn);
68 v_coef.insert(v_coef.begin()+offset, coef);
69 }
70 else {
71 v_coef[offset] += coef;
72 }
73}
74
75
76void add_entries(CSVec& vec, int num, const int* eqns, const double* coefs);
77
78void put_entry(CSVec& vec, int eqn, double coef);
79
80double get_entry(const CSVec& vec, int eqn);
81
82void remove_entry(CSVec& vec, int eqn);
83
84void set_values(CSVec& vec, double scalar);
85
88void add_CSVec_CSVec(const CSVec& u, CSVec& v);
89
90}//namespace fei
91
92#endif
93
std::vector< int > indices_
Definition fei_CSVec.hpp:51
std::vector< int > & indices()
Definition fei_CSVec.hpp:31
bool operator!=(const CSVec &rhs) const
Definition fei_CSVec.hpp:44
size_t size() const
Definition fei_CSVec.hpp:36
const std::vector< int > & indices() const
Definition fei_CSVec.hpp:32
std::vector< double > coefs_
Definition fei_CSVec.hpp:52
void clear()
Definition fei_CSVec.hpp:38
const std::vector< double > & coefs() const
Definition fei_CSVec.hpp:34
CSVec(unsigned sz=0)
Definition fei_CSVec.cpp:15
CSVec & operator=(const CSVec &invec)
Definition fei_CSVec.cpp:26
void subtract(const CSVec &rhs)
Definition fei_CSVec.cpp:94
std::vector< double > & coefs()
Definition fei_CSVec.hpp:33
bool operator==(const CSVec &rhs) const
Definition fei_CSVec.hpp:40
virtual ~CSVec()
Definition fei_CSVec.cpp:21
void put_entry(CSVec &vec, int eqn, double coef)
Definition fei_CSVec.cpp:39
void add_CSVec_CSVec(const CSVec &u, CSVec &v)
double get_entry(const CSVec &vec, int eqn)
Definition fei_CSVec.cpp:58
void add_entries(CSVec &vec, int num, const int *eqns, const double *coefs)
Definition fei_CSVec.cpp:34
void remove_entry(CSVec &vec, int eqn)
Definition fei_CSVec.cpp:77
void add_entry(CSVec &vec, int eqn, double coef)
Definition fei_CSVec.hpp:56
void set_values(CSVec &vec, double scalar)