Skip to content
Snippets Groups Projects
Commit f956fd27 authored by Uli Sack's avatar Uli Sack Committed by usack
Browse files

* added method mmv

* added default constructor and made necessary changes for is to work, i.e.
    * made members pointers instead of references
    * allocate memory internally for lowRankFactor_ if default constructed
    * add destructor and delete lowRankFactor_in destructor if internally allocated
    * adapt uses of member
* added non const getter method for lowRankFactor_

[[Imported from SVN: r5477]]
parent 4710eeb8
Branches
No related tags found
No related merge requests found
...@@ -21,26 +21,40 @@ class LowRankOperator ...@@ -21,26 +21,40 @@ class LowRankOperator
//! export size type //! export size type
typedef typename LRFactorType::size_type size_type; typedef typename LRFactorType::size_type size_type;
//! default constructor
LowRankOperator():
factor_allocated_internally_(true)
{
lowRankFactor_ = new LowRankFactorType;
}
//! constructor taking the defining factor as argument //! constructor taking the defining factor as argument
LowRankOperator(LowRankFactorType& lrFactor): LowRankOperator(LowRankFactorType& lrFactor):
lowRankFactor_(lrFactor) lowRankFactor_(&lrFactor),
factor_allocated_internally_(false)
{} {}
~LowRankOperator()
{
if (factor_allocated_internally_)
delete lowRankFactor_;
}
//! b += Ax //! b += Ax
template <class LVectorType, class RVectorType> template <class LVectorType, class RVectorType>
void umv(const LVectorType& x, RVectorType& b) const void umv(const LVectorType& x, RVectorType& b) const
{ {
LVectorType temp(lowRankFactor_.N()); LVectorType temp(lowRankFactor_->N());
lowRankFactor_.mv(x,temp); lowRankFactor_->mv(x,temp);
typename LowRankFactorType::RowIterator row_end = lowRankFactor_.end(); typename LowRankFactorType::ConstRowIterator row_end = lowRankFactor_->end();
typename LowRankFactorType::RowIterator row_it = lowRankFactor_.begin(); typename LowRankFactorType::ConstRowIterator row_it = lowRankFactor_->begin();
for (; row_it!=row_end; ++row_it) for (; row_it!=row_end; ++row_it)
{ {
typename LowRankFactorType::ColIterator col_end = row_it->end(); typename LowRankFactorType::ConstColIterator col_end = row_it->end();
typename LowRankFactorType::ColIterator col_it = row_it->begin(); typename LowRankFactorType::ConstColIterator col_it = row_it->begin();
for (; col_it!=col_end; ++col_it) for (; col_it!=col_end; ++col_it)
lowRankFactor_[row_it.index()][col_it.index()].umv(temp[row_it.index()],b[col_it.index()]); (*lowRankFactor_)[row_it.index()][col_it.index()].umv(temp[row_it.index()],b[col_it.index()]);
} }
} }
...@@ -48,17 +62,35 @@ class LowRankOperator ...@@ -48,17 +62,35 @@ class LowRankOperator
template <class LVectorType, class RVectorType> template <class LVectorType, class RVectorType>
void usmv(const field_type& alpha, const LVectorType& x, RVectorType& b) const void usmv(const field_type& alpha, const LVectorType& x, RVectorType& b) const
{ {
LVectorType temp(lowRankFactor_.N()); LVectorType temp(lowRankFactor_->N());
lowRankFactor_.mv(x,temp); lowRankFactor_->mv(x,temp);
typename LowRankFactorType::RowIterator row_end = lowRankFactor_.end(); typename LowRankFactorType::ConstRowIterator row_end = lowRankFactor_->end();
typename LowRankFactorType::RowIterator row_it = lowRankFactor_.begin(); typename LowRankFactorType::ConstRowIterator row_it = lowRankFactor_->begin();
for (; row_it!=row_end; ++row_it) for (; row_it!=row_end; ++row_it)
{ {
typename LowRankFactorType::ColIterator col_end = row_it->end(); typename LowRankFactorType::ConstColIterator col_end = row_it->end();
typename LowRankFactorType::ColIterator col_it = row_it->begin(); typename LowRankFactorType::ConstColIterator col_it = row_it->begin();
for (; col_it!=col_end; ++col_it) for (; col_it!=col_end; ++col_it)
lowRankFactor_[row_it.index()][col_it.index()].usmv(alpha,temp[row_it.index()],b[col_it.index()]); (*lowRankFactor_)[row_it.index()][col_it.index()].usmv(alpha,temp[row_it.index()],b[col_it.index()]);
}
}
//! b -= Ax
template <class LVectorType, class RVectorType>
void mmv(const LVectorType& x, RVectorType& b) const
{
LVectorType temp(lowRankFactor_->N());
lowRankFactor_->mv(x,temp);
typename LowRankFactorType::ConstRowIterator row_end = lowRankFactor_->end();
typename LowRankFactorType::ConstRowIterator row_it = lowRankFactor_->begin();
for (; row_it!=row_end; ++row_it)
{
typename LowRankFactorType::ConstColIterator col_end = row_it->end();
typename LowRankFactorType::ConstColIterator col_it = row_it->begin();
for (; col_it!=col_end; ++col_it)
(*lowRankFactor_)[row_it.index()][col_it.index()].mmv(temp[row_it.index()],b[col_it.index()]);
} }
} }
...@@ -71,26 +103,33 @@ class LowRankOperator ...@@ -71,26 +103,33 @@ class LowRankOperator
} }
//! returns number of rows //! returns number of rows
size_type N() const size_type N() const
{ {
return lowRankFactor_.M(); return lowRankFactor_->M();
} }
//! returns number of columns //! returns number of columns
size_type M() const size_type M() const
{ {
return lowRankFactor_.M(); return lowRankFactor_->M();
} }
//! returns the defining factor //! returns the defining factor
const LowRankFactorType& getLowRankFactor() const const LowRankFactorType& lowRankFactor() const
{ {
return lowRankFactor_; return *lowRankFactor_;
} }
//! returns the defining factor
LowRankFactorType& lowRankFactor()
{
return *lowRankFactor_;
}
private: private:
//! the defining factor //! the defining factor
LowRankFactorType& lowRankFactor_; LowRankFactorType* lowRankFactor_;
const bool factor_allocated_internally_;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment