--- /dev/null
+Changed: The function Mapping::clone (and all inheriting classes' implementations, such as MappingQ1Eulerian::clone) now return a <code>unique_ptr<Mapping<dim,spacedim>></code>.
+<br>
+(David Wells, 2018/02/08)
#include <array>
#include <cmath>
+#include <memory>
DEAL_II_NAMESPACE_OPEN
* This function is mainly used by the hp::MappingCollection class.
*/
virtual
- Mapping<dim,spacedim> *clone () const = 0;
+ std::unique_ptr<Mapping<dim,spacedim>> clone () const = 0;
/**
* Return the mapped vertices of a cell.
* then assumes ownership of it.
*/
virtual
- Mapping<dim,spacedim> *clone () const;
+ std::unique_ptr<Mapping<dim,spacedim>> clone () const override;
protected:
// for documentation, see the Mapping base class
virtual
- Mapping<dim, spacedim> *clone () const;
+ std::unique_ptr<Mapping<dim, spacedim>> clone () const override;
/**
* Return @p true because MappingCartesian preserves vertex
* then assumes ownership of it.
*/
virtual
- Mapping<dim,spacedim> *clone () const;
+ std::unique_ptr<Mapping<dim,spacedim>> clone () const override;
// for documentation, see the Mapping base class
virtual
- Mapping<dim,spacedim> *clone () const;
+ std::unique_ptr<Mapping<dim,spacedim>> clone () const override;
/**
* Always returns @p true because this class assumes that the
* then assumes ownership of it.
*/
virtual
- Mapping<dim,spacedim> *clone () const;
+ std::unique_ptr<Mapping<dim,spacedim>> clone () const override;
/**
// for documentation, see the Mapping base class
virtual
- MappingQ1<dim,spacedim> *clone () const;
+ std::unique_ptr<Mapping<dim,spacedim>> clone () const override;
};
* then assumes ownership of it.
*/
virtual
- MappingQ1Eulerian<dim,VectorType,spacedim> *clone () const;
+ std::unique_ptr<Mapping<dim,spacedim>> clone () const override;
/**
* Always returns @p false because MappingQ1Eulerian does not in general
* then assumes ownership of it.
*/
virtual
- Mapping<dim,spacedim> *clone () const;
+ std::unique_ptr<Mapping<dim,spacedim>> clone () const override;
/**
* Always return @p false because MappingQEulerian does not in general
// for documentation, see the Mapping base class
virtual
- Mapping<dim,spacedim> *clone () const;
+ std::unique_ptr<Mapping<dim,spacedim>> clone () const override;
/**
* Return the degree of the mapping, i.e. the value which was passed to the
//
// ---------------------------------------------------------------------
+#include <deal.II/base/std_cxx14/memory.h>
+
#include <deal.II/grid/tria_accessor.h>
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/grid/tria_boundary.h>
+
#include <deal.II/fe/mapping_c1.h>
+
#include <cmath>
DEAL_II_NAMESPACE_OPEN
template <int dim, int spacedim>
-Mapping<dim, spacedim> *
+std::unique_ptr<Mapping<dim,spacedim> >
MappingC1<dim,spacedim>::clone () const
{
- return new MappingC1<dim,spacedim>();
+ return std_cxx14::make_unique<MappingC1<dim,spacedim>>();
}
//
// ---------------------------------------------------------------------
-
+#include <deal.II/base/std_cxx14/memory.h>
#include <deal.II/base/array_view.h>
#include <deal.II/base/tensor.h>
#include <deal.II/base/quadrature.h>
template <int dim, int spacedim>
-Mapping<dim, spacedim> *
+std::unique_ptr<Mapping<dim, spacedim> >
MappingCartesian<dim, spacedim>::clone () const
{
- return new MappingCartesian<dim, spacedim>(*this);
+ return std_cxx14::make_unique<MappingCartesian<dim,spacedim>>(*this);
}
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/qprojector.h>
#include <deal.II/base/memory_consumption.h>
+#include <deal.II/base/std_cxx14/memory.h>
#include <deal.II/base/utilities.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/vector.h>
template <int dim, int spacedim, typename VectorType, typename DoFHandlerType>
-Mapping<dim,spacedim> *
+std::unique_ptr<Mapping<dim,spacedim> >
MappingFEField<dim,spacedim,VectorType,DoFHandlerType>::clone () const
{
- return new MappingFEField<dim,spacedim,VectorType,DoFHandlerType>(*this);
+ return std_cxx14::make_unique<MappingFEField<dim,spacedim,VectorType,DoFHandlerType>>(*this);
}
#include <deal.II/base/quadrature.h>
#include <deal.II/base/qprojector.h>
#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/base/std_cxx14/memory.h>
#include <deal.II/base/tensor_product_polynomials.h>
#include <deal.II/base/memory_consumption.h>
#include <deal.II/lac/full_matrix.h>
template <int dim, int spacedim>
-Mapping<dim,spacedim> *
+std::unique_ptr<Mapping<dim,spacedim> >
MappingManifold<dim,spacedim>::clone () const
{
- return new MappingManifold<dim,spacedim>(*this);
+ return std_cxx14::make_unique<MappingManifold<dim,spacedim>>(*this);
}
#include <deal.II/base/quadrature.h>
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/memory_consumption.h>
+#include <deal.II/base/std_cxx14/memory.h>
#include <deal.II/base/tensor_product_polynomials.h>
#include <deal.II/base/utilities.h>
#include <deal.II/lac/full_matrix.h>
// created via the shared_ptr objects
qp_mapping (this->polynomial_degree>1
?
- std::shared_ptr<const MappingQGeneric<dim,spacedim> >(new MappingQGeneric<dim,spacedim>(degree))
+ std::make_shared<const MappingQGeneric<dim,spacedim>>(degree)
:
q1_mapping)
{}
MappingQ<dim,spacedim>::MappingQ (const MappingQ<dim,spacedim> &mapping)
:
polynomial_degree (mapping.polynomial_degree),
- use_mapping_q_on_all_cells (mapping.use_mapping_q_on_all_cells),
- // clone the Q1 mapping for use on interior cells (if necessary)
- // or to create a good initial guess in transform_real_to_unit_cell()
- q1_mapping (dynamic_cast<MappingQGeneric<dim,spacedim>*>(mapping.q1_mapping->clone())),
- // create a Q_p mapping; if p=1, simply share the Q_1 mapping already
- // created via the shared_ptr objects
- qp_mapping (this->polynomial_degree>1
- ?
- std::shared_ptr<const MappingQGeneric<dim,spacedim> >(dynamic_cast<MappingQGeneric<dim,spacedim>*>(mapping.qp_mapping->clone()))
- :
- q1_mapping)
-{}
+ use_mapping_q_on_all_cells (mapping.use_mapping_q_on_all_cells)
+{
+ // Note that we really do have to use clone() here, since mapping.q1_mapping
+ // may be MappingQ1Eulerian and mapping.qp_mapping may be MappingQEulerian.
+ std::shared_ptr<const Mapping<dim,spacedim>> other_q1_map = mapping.q1_mapping->clone();
+ q1_mapping = std::dynamic_pointer_cast<const MappingQGeneric<dim,spacedim>>(other_q1_map);
+ Assert(q1_mapping != nullptr, ExcInternalError());
+ Assert(q1_mapping->get_degree() == 1, ExcInternalError());
+
+ // Same as the other constructor: if possible reuse the Q1 mapping
+ if (this->polynomial_degree == 1)
+ {
+ qp_mapping = q1_mapping;
+ }
+ else
+ {
+ std::shared_ptr<const Mapping<dim,spacedim>> other_qp_map = mapping.qp_mapping->clone();
+ qp_mapping = std::dynamic_pointer_cast<const MappingQGeneric<dim,spacedim>>(other_qp_map);
+ Assert(qp_mapping != nullptr, ExcInternalError());
+ }
+}
template <int dim, int spacedim>
-Mapping<dim,spacedim> *
+std::unique_ptr<Mapping<dim,spacedim> >
MappingQ<dim,spacedim>::clone () const
{
- return new MappingQ<dim,spacedim>(this->polynomial_degree,
- this->use_mapping_q_on_all_cells);
+ return std_cxx14::make_unique<MappingQ<dim,spacedim>>(this->polynomial_degree,
+ this->use_mapping_q_on_all_cells);
}
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/tensor_product_polynomials.h>
#include <deal.II/base/memory_consumption.h>
+#include <deal.II/base/std_cxx14/memory.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/grid/tria.h>
#include <deal.II/grid/tria_iterator.h>
template <int dim, int spacedim>
-MappingQ1<dim,spacedim> *
+std::unique_ptr<Mapping<dim,spacedim> >
MappingQ1<dim,spacedim>::clone () const
{
- return new MappingQ1<dim,spacedim>(*this);
+ return std_cxx14::make_unique<MappingQ1<dim,spacedim>>(*this);
}
//---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------
+#include <deal.II/base/std_cxx14/memory.h>
+
#include <deal.II/fe/mapping_q1_eulerian.h>
#include <deal.II/lac/vector.h>
#include <deal.II/lac/block_vector.h>
template <int dim, class VectorType, int spacedim>
-MappingQ1Eulerian<dim,VectorType,spacedim> *
+std::unique_ptr<Mapping<dim,spacedim> >
MappingQ1Eulerian<dim, VectorType, spacedim>::clone () const
{
- return new MappingQ1Eulerian<dim,VectorType,spacedim>(*this);
+ return std_cxx14::make_unique<MappingQ1Eulerian<dim,VectorType,spacedim>>(*this);
}
#include <deal.II/base/utilities.h>
#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/base/std_cxx14/memory.h>
#include <deal.II/lac/vector.h>
#include <deal.II/lac/block_vector.h>
#include <deal.II/lac/la_vector.h>
template <int dim, class VectorType, int spacedim>
-Mapping<dim,spacedim> *
+std::unique_ptr<Mapping<dim,spacedim> >
MappingQEulerian<dim, VectorType, spacedim>::clone () const
{
- return new MappingQEulerian<dim,VectorType,spacedim>(this->get_degree(),
- *euler_dof_handler,
- *euler_vector);
+ return std_cxx14::make_unique<MappingQEulerian<dim,VectorType,spacedim>>
+ (this->get_degree(), *euler_dof_handler, *euler_vector);
}
#include <deal.II/base/table.h>
#include <deal.II/base/tensor_product_polynomials.h>
#include <deal.II/base/memory_consumption.h>
+#include <deal.II/base/std_cxx14/memory.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/tensor_product_matrix.h>
#include <deal.II/grid/tria.h>
template <int dim, int spacedim>
-Mapping<dim,spacedim> *
+std::unique_ptr<Mapping<dim,spacedim> >
MappingQGeneric<dim,spacedim>::clone () const
{
- return new MappingQGeneric<dim,spacedim>(*this);
+ return std_cxx14::make_unique<MappingQGeneric<dim,spacedim>>(*this);
}
{
MappingQ<dim> mapping(2);
deallog << "Cloning..." << std::endl;
- Mapping<dim> *copy = mapping.clone();
+ std::unique_ptr<Mapping<dim>> copy = mapping.clone();
deallog << "Deleting clone..." << std::endl;
- delete copy;
+ copy.reset();
deallog << "Destroying original..." << std::endl;
}