Skip to content
Snippets Groups Projects
Commit 460c6285 authored by graeser's avatar graeser Committed by graeser@PCPOOL.MI.FU-BERLIN.DE
Browse files

Moved genericvectortools.hh to dune-solvers

[[Imported from SVN: r2811]]
parent e3fe2d81
Branches
Tags
No related merge requests found
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
SUBDIRS = common iterationsteps norms solvers transferoperators SUBDIRS = common iterationsteps norms solvers transferoperators
dune_solversdir = $(includedir)/dune/dune-solvers dune_solversdir = $(includedir)/dune/dune-solvers
dune_solvers_HEADERS = boxconstraint.hh numproc.hh computeenergy.hh dune_solvers_HEADERS = boxconstraint.hh numproc.hh computeenergy.hh genericvectortools.hh
include $(top_srcdir)/am/global-rules include $(top_srcdir)/am/global-rules
#ifndef GENERIC_VECTOR_TOOL_HH
#define GENERIC_VECTOR_TOOL_HH
/** \file
\brief Various tools for working with istl vectors of arbitrary nesting depth
*/
#include<iostream>
#include "dune/common/fvector.hh"
#include <dune/istl/bcrsmatrix.hh>
/** \brief Various tools for working with istl vectors of arbitrary nesting depth
*/
struct GenericVector
{
//! Write vector to given stream
template <class VectorType>
static void writeBinary(std::ostream& s, const VectorType& v)
{
typename VectorType::const_iterator it = v.begin();
typename VectorType::const_iterator end = v.end();
for(; it!=end; ++it)
GenericVector::writeBinary(s, *it);
}
template <class field_type, int n>
static void writeBinary(std::ostream& s, const Dune::FieldVector<field_type,n>& v)
{
typedef typename Dune::FieldVector<field_type,n> VectorType;
typename VectorType::const_iterator it = v.begin();
typename VectorType::const_iterator end = v.end();
for(; it!=end; ++it)
s.write(reinterpret_cast<const char*>(&(*it)), sizeof(field_type));
}
//! Read vector from a given stream
template <class VectorType>
static void readBinary(std::istream& s, VectorType& v)
{
typename VectorType::iterator it = v.begin();
typename VectorType::iterator end = v.end();
for(; it!=end; ++it)
GenericVector::readBinary(s, *it);
}
template <class field_type, int n>
static void readBinary(std::istream& s, Dune::FieldVector<field_type,n>& v)
{
typedef typename Dune::FieldVector<field_type,n> VectorType;
typename VectorType::iterator it = v.begin();
typename VectorType::iterator end = v.end();
for(; it!=end; ++it)
s.read(reinterpret_cast<char*>(&(*it)), sizeof(field_type));
}
//! Resize vector recursivly to size of given vector/matrix
template <class VectorTypeA, class VectorTypeB>
static void resize(VectorTypeA& a, const VectorTypeB& b)
{
a.resize(b.size());
typename VectorTypeB::const_iterator it = b.begin();
typename VectorTypeB::const_iterator end = b.end();
for(; it!=end; ++it)
GenericVector::resize(a[it.index()], *it);
}
template <class VectorTypeA, class T, class A>
static void resize(VectorTypeA& a, const Dune::BCRSMatrix<T,A>& b)
{
a.resize(b.N());
typedef typename Dune::BCRSMatrix<T,A> VectorTypeB;
typename VectorTypeB::const_iterator it = b.begin();
typename VectorTypeB::const_iterator end = b.end();
for(; it!=end; ++it)
GenericVector::resize(a[it.index()], *(it->begin()));
}
template <class field_type, int n, class VectorTypeB>
static void resize(Dune::FieldVector<field_type,n>& a, const VectorTypeB& b)
{}
template <int n, class VectorTypeB>
static void resize(std::bitset<n>& a, const VectorTypeB& b)
{}
//! Set vector to zero at indices that are true in bitvector recursivly
template <class VectorType, class BitVectorType>
static void truncate(VectorType& v, const BitVectorType& tr)
{
typename VectorType::iterator it = v.begin();
typename VectorType::iterator end = v.end();
for(; it!=end; ++it)
GenericVector::truncate(*it, tr[it.index()]);
}
template <class field_type, int n, class BitVectorType>
static void truncate(Dune::FieldVector<field_type,n>& v, const BitVectorType& tr)
{
typedef typename Dune::FieldVector<field_type,n> VectorType;
typename VectorType::iterator it = v.begin();
typename VectorType::iterator end = v.end();
for(; it!=end; ++it)
if (tr[it.index()])
*it = 0;
}
};
#endif
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#include <dune-solvers/transferoperators/multigridtransfer.hh> #include <dune-solvers/transferoperators/multigridtransfer.hh>
#include <dune-solvers/solvers/loopsolver.hh> #include <dune-solvers/solvers/loopsolver.hh>
#include <dune-solvers/genericvectortools.hh>
#include "blockgsstep.hh" #include "blockgsstep.hh"
#include "dune/ag-common/genericvectortools.hh"
#ifdef HAVE_IPOPT #ifdef HAVE_IPOPT
#include <dune-solvers/solvers/quadraticipopt.hh> #include <dune-solvers/solvers/quadraticipopt.hh>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <iomanip> #include <iomanip>
#include <fstream> #include <fstream>
#include "dune/ag-common/genericvectortools.hh" #include <dune-solvers/genericvectortools.hh>
template <class VectorType, class BitVectorType> template <class VectorType, class BitVectorType>
void IterativeSolver<VectorType, BitVectorType>::check() const void IterativeSolver<VectorType, BitVectorType>::check() const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment