diff --git a/dune/fufem/functions/deformationfunction.hh b/dune/fufem/functions/deformationfunction.hh index 07db0cfa2c9dd17dd355e159601247f2c667cd84..1161aa1b24c4f7ac1e0f19f7d2a747e971bbd89f 100644 --- a/dune/fufem/functions/deformationfunction.hh +++ b/dune/fufem/functions/deformationfunction.hh @@ -30,13 +30,18 @@ public: DeformationFunction(const GridView& gridView, const CoefficientVectorType& deformation) - : gridView_(gridView), - deformation_(deformation) + : deformation_(deformation) { - if(gridView_.size(dim) != deformation_.size()) + gridView_ = std::auto_ptr<GridView>(new GridView(gridView)); + + if(gridView_->size(dim) != deformation_.size()) DUNE_THROW(Dune::Exception,"The deformation coefficient vector doesn't match the gridview!"); } + void setGridView(const GridView& gridView) { + gridView_ = std::auto_ptr<GridView>(new GridView(gridView)); + } + //! Change the deformation vector void setDeformation(const CoefficientVectorType& deformation) { @@ -47,7 +52,7 @@ public: void evaluate ( const typename GridView::template Codim<dim>::Entity& hostVertex, unsigned int corner, Dune::FieldVector<double,dim> &y ) const { - const typename GridView::IndexSet& indexSet = gridView_.indexSet(); + const typename GridView::IndexSet& indexSet = gridView_->indexSet(); int idx = indexSet.index(hostVertex); y = hostVertex.geometry().corner(0) + deformation_[idx]; @@ -57,7 +62,7 @@ public: void evaluate (const typename GridView::template Codim<0>::Entity& hostEntity, unsigned int corner, typename Base::RangeVector& y ) const { - const typename GridView::IndexSet& indexSet = gridView_.indexSet(); + const typename GridView::IndexSet& indexSet = gridView_->indexSet(); int idx = indexSet.subIndex(hostEntity, corner,dim); y = hostEntity.geometry().corner(corner) + deformation_[idx]; @@ -65,16 +70,17 @@ public: //! Adapt to changes in the host grid void adapt() { - if (deformation_.size() != gridView_.size(dim)) { + if (deformation_.size() != gridView_->size(dim)) { std::cout<<"Warning removing all data from DeformationFunction! \n"; - deformation_.resize(gridView_.size(dim)); + deformation_.resize(gridView_->size(dim)); deformation_ = 0; } } private: //! The gridview of the undeformed grid - const GridView& gridView_; + std::auto_ptr<GridView> gridView_; + //! The coefficient vector of the displacements of the vertices of the gridview CoefficientVectorType deformation_; };