Commit dd66d207 authored by Robert K's avatar Robert K

[!306] [feature][VectorDiscreteFunction] Add specialized assign for PetscDF.

Merge branch 'feature/vectorfunction-assign-petsc' into 'master'

ref:dune-fem/dune-fem Add specialized assign for PetscDiscreteFunction
forwarding assign to dofVector.

See merge request [!306]

  [!306]: gitlab.dune-project.org/dune-fem/dune-fem/merge_requests/306
parents 02b2a11f 09416d1a
Pipeline #17721 passed with stage
in 47 minutes and 34 seconds
......@@ -248,6 +248,23 @@ namespace Dune {
typedef Hybrid::IndexRange< int, blockSize > BlockIndices;
protected:
template <class Array>
struct ContainerAccess
{
static FieldType* data( Array& array ) { return array.data(); }
static const FieldType* data( const Array& array ) { return array.data(); }
};
template <class K>
struct ContainerAccess< Dune::DynamicVector< K > >
{
typedef Dune::DynamicVector< K > Array;
static FieldType* data( Array& array ) { return array.container().data(); }
static const FieldType* data( const Array& array ) { return array.container().data(); }
};
public:
/** \brief Constructor */
explicit SimpleBlockVector ( ArrayType& array )
: array_( array )
......@@ -304,8 +321,8 @@ namespace Dune {
/** \brief Number of dofs in the block vector */
SizeType numDofs() const { return array().size(); }
FieldType* data() { return array().data(); }
const FieldType* data() const { return array().data(); }
FieldType* data() { return ContainerAccess< ArrayType >::data( array() ); }
const FieldType* data() const { return ContainerAccess< ArrayType >::data( array() ); }
const ArrayType &array () const { return array_; }
ArrayType &array () { return array_; }
......
......@@ -5,8 +5,9 @@
#include <string>
#include <utility>
#include <dune/fem/function/adaptivefunction.hh>
#include <dune/fem/function/blockvectorfunction.hh>
#include <dune/fem/function/adaptivefunction.hh>
#include <dune/fem/function/vectorfunction.hh>
#if HAVE_PETSC
......@@ -160,6 +161,15 @@ namespace Dune
dofVector().assignVector( g.dofVector() );
}
/** \copydoc Dune::Fem::DiscreteFunctionInterface::assign(const DiscreteFunctionInterfaceType &g)
* \note This is a specialization when the right hand side is a VectorDiscreteFunction */
template < class Vector >
void assign( const VectorDiscreteFunction< DiscreteFunctionSpaceType, Vector > &g )
{
// call more efficient assign on PetscVector
dofVector().assignVector( g.dofVector() );
}
/** \copydoc Dune::Fem::DiscreteFunctionInterface::beginAssemble() */
template< class AssembleOperation >
void beginAssemble ()
......
......@@ -18,6 +18,10 @@ namespace Dune
template < class DiscreteFunctionSpace, class Vector >
class VectorDiscreteFunction;
#if HAVE_PETSC
template <class DiscreteFunctionSpace>
class PetscDiscreteFunction;
#endif
template< typename DiscreteFunctionSpace, typename Vector >
......@@ -82,6 +86,13 @@ namespace Dune
ThisType& operator= ( const ThisType& ) = delete;
ThisType& operator= ( ThisType&& ) = delete;
#if HAVE_PETSC
void assign( const PetscDiscreteFunction< DiscreteFunctionSpaceType >& g )
{
g.dofVector().copyTo( dofVector() );
}
#endif
/** \copydoc Dune::Fem::DiscreteFunctionInterface::dofVector() */
DofVectorType& dofVector() { return dofVector_; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment