Skip to content
Snippets Groups Projects
Commit dd683cd8 authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[common.vector] added resize() for Dune::DynamicVector

parent 1540423f
No related branches found
No related tags found
No related merge requests found
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
// dune-common // dune-common
#include <dune/common/densevector.hh> #include <dune/common/densevector.hh>
#include <dune/common/dynvector.hh>
namespace Dune { namespace Dune {
namespace Stuff { namespace Stuff {
namespace Common { namespace Common {
// template< class T, class stream = std::ostream > // template< class T, class stream = std::ostream >
// void print(const T& arg, stream& out = std::cout, std::string name = "", std::string prefix = "") { // void print(const T& arg, stream& out = std::cout, std::string name = "", std::string prefix = "") {
// out << prefix; // out << prefix;
...@@ -25,6 +25,7 @@ namespace Common { ...@@ -25,6 +25,7 @@ namespace Common {
// out << arg[arg.size() - 1] << "]" << std::endl; // out << arg[arg.size() - 1] << "]" << std::endl;
//} //}
template <class VectorImp> template <class VectorImp>
void clear(Dune::DenseVector<VectorImp>& vector) void clear(Dune::DenseVector<VectorImp>& vector)
{ {
...@@ -39,6 +40,19 @@ void clear(Dune::DenseVector<VectorImp>& vector) ...@@ -39,6 +40,19 @@ void clear(Dune::DenseVector<VectorImp>& vector)
// } // }
} // void clear( DenseVectorType& vector ) } // void clear( DenseVectorType& vector )
template <class T>
Dune::DynamicVector<T> resize(const Dune::DynamicVector<T>& inVector, const size_t newSize, const T fill = T(0))
{
Dune::DynamicVector<T> outVector(newSize);
for (size_t ii = 0; ii < std::min(inVector.size(), newSize); ++ii)
outVector[ii] = inVector[ii];
for (size_t ii = std::min(inVector.size(), newSize); ii < newSize; ++ii)
outVector[ii] = fill;
return outVector;
}
} // namespace Common } // namespace Common
} // namespace Stuff } // namespace Stuff
} // namespace Dune } // namespace Dune
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment