virtual ~PolicyBase () = default;
/**
- * Distribute degrees of freedom on the object given as first
- * argument. The reference to the NumberCache of the DoFHandler object
- * has to be passed in a second argument. It could then be modified to
+ * Distribute degrees of freedom on the DoFHandler object associated
+ * with this policy object. The argument is a reference to the NumberCache
+ * of the DoFHandler object. The function may modify it to
* make DoFHandler related functions work properly when called within
* the policies classes. The updated NumberCache is written to that
* argument.
*/
virtual
void
- distribute_dofs (dealii::DoFHandler<dim,spacedim> &dof_handler,
- NumberCache &number_cache) const = 0;
+ distribute_dofs (NumberCache &number_cache) const = 0;
/**
- * Distribute the multigrid dofs on each level
+ * Distribute the multigrid dofs on each level of the DoFHandler
+ * associated with this policy object.
*/
virtual
void
- distribute_mg_dofs (dealii::DoFHandler<dim,spacedim> &dof_handler,
- std::vector<NumberCache> &number_caches) const = 0;
+ distribute_mg_dofs (std::vector<NumberCache> &number_caches) const = 0;
/**
* Renumber degrees of freedom as specified by the first argument. The
virtual
void
renumber_dofs (const std::vector<types::global_dof_index> &new_numbers,
- dealii::DoFHandler<dim,spacedim> &dof_handler,
NumberCache &number_cache) const = 0;
};
{
public:
/**
- * Distribute degrees of freedom on the object given as last argument.
+ * Constructor.
+ * @param dof_handler The DoFHandler object upon which this
+ * policy class is supposed to work.
*/
+ Sequential (dealii::DoFHandler<dim,spacedim> &dof_handler);
+
+ // documentation is inherited
virtual
void
- distribute_dofs (dealii::DoFHandler<dim,spacedim> &dof_handler,
- NumberCache &number_cache) const;
+ distribute_dofs (NumberCache &number_cache) const;
- /**
- * Distribute multigrid DoFs.
- */
+ // documentation is inherited
virtual
void
- distribute_mg_dofs (dealii::DoFHandler<dim,spacedim> &dof_handler,
- std::vector<NumberCache> &number_caches) const;
+ distribute_mg_dofs (std::vector<NumberCache> &number_caches) const;
- /**
- * Renumber degrees of freedom as specified by the first argument.
- */
+ // documentation is inherited
virtual
void
renumber_dofs (const std::vector<types::global_dof_index> &new_numbers,
- dealii::DoFHandler<dim,spacedim> &dof_handler,
NumberCache &number_cache) const;
+
+ protected:
+ /**
+ * The DoFHandler object on which this policy object works.
+ */
+ dealii::DoFHandler<dim,spacedim> &dof_handler;
};
/**
class ParallelShared : public Sequential<dim,spacedim>
{
public:
+ /**
+ * Constructor.
+ * @param dof_handler The DoFHandler object upon which this
+ * policy class is supposed to work.
+ */
+ ParallelShared (dealii::DoFHandler<dim,spacedim> &dof_handler);
/**
* Distribute degrees of freedom on the object given as first
*/
virtual
void
- distribute_dofs (dealii::DoFHandler<dim,spacedim> &dof_handler,
- NumberCache &number_cache) const;
+ distribute_dofs (NumberCache &number_cache) const;
/**
* This function is not yet implemented.
*/
virtual
void
- distribute_mg_dofs (dealii::DoFHandler<dim,spacedim> &dof_handler,
- std::vector<NumberCache> &number_caches) const;
+ distribute_mg_dofs (std::vector<NumberCache> &number_caches) const;
/**
* Renumber degrees of freedom as specified by the first argument.
virtual
void
renumber_dofs (const std::vector<types::global_dof_index> &new_numbers,
- dealii::DoFHandler<dim,spacedim> &dof_handler,
NumberCache &number_cache) const;
};
{
public:
/**
- * Distribute degrees of freedom on the object given as last argument.
+ * Constructor.
+ * @param dof_handler The DoFHandler object upon which this
+ * policy class is supposed to work.
*/
+ ParallelDistributed (dealii::DoFHandler<dim,spacedim> &dof_handler);
+
+ // documentation is inherited
virtual
void
- distribute_dofs (dealii::DoFHandler<dim,spacedim> &dof_handler,
- NumberCache &number_cache) const;
+ distribute_dofs (NumberCache &number_cache) const;
- /**
- * Distribute multigrid DoFs.
- */
+ // documentation is inherited
virtual
void
- distribute_mg_dofs (dealii::DoFHandler<dim,spacedim> &dof_handler,
- std::vector<NumberCache> &number_caches) const;
+ distribute_mg_dofs (std::vector<NumberCache> &number_caches) const;
- /**
- * Renumber degrees of freedom as specified by the first argument.
- */
+ // documentation is inherited
virtual
void
renumber_dofs (const std::vector<types::global_dof_index> &new_numbers,
- dealii::DoFHandler<dim,spacedim> &dof_handler,
NumberCache &number_cache) const;
+
+ private:
+ /**
+ * The DoFHandler object on which this policy object works.
+ */
+ dealii::DoFHandler<dim,spacedim> &dof_handler;
};
}
}
if (dynamic_cast<const parallel::shared::Triangulation< dim, spacedim>*>
(&tria)
!= nullptr)
- policy.reset (new internal::DoFHandler::Policy::ParallelShared<dim,spacedim>());
+ policy.reset (new internal::DoFHandler::Policy::ParallelShared<dim,spacedim>(*this));
else if (dynamic_cast<const parallel::distributed::Triangulation< dim, spacedim >*>
(&tria)
== nullptr)
- policy.reset (new internal::DoFHandler::Policy::Sequential<dim,spacedim>());
+ policy.reset (new internal::DoFHandler::Policy::Sequential<dim,spacedim>(*this));
else
- policy.reset (new internal::DoFHandler::Policy::ParallelDistributed<dim,spacedim>());
+ policy.reset (new internal::DoFHandler::Policy::ParallelDistributed<dim,spacedim>(*this));
}
{
// release allocated memory
clear ();
+
+ // also release the policy. this needs to happen before the
+ // current object disappears because the policy objects
+ // store references to the DoFhandler object they work on
+ policy.reset ();
}
template<int dim, int spacedim>
void
-DoFHandler<dim,spacedim>::initialize(
- const Triangulation<dim,spacedim> &t,
- const FiniteElement<dim,spacedim> &fe)
+DoFHandler<dim,spacedim>::
+initialize(const Triangulation<dim,spacedim> &t,
+ const FiniteElement<dim,spacedim> &fe)
{
tria = &t;
faces = nullptr;
if (dynamic_cast<const parallel::shared::Triangulation< dim, spacedim>*>
(&t)
!= nullptr)
- policy.reset (new internal::DoFHandler::Policy::ParallelShared<dim,spacedim>());
+ policy.reset (new internal::DoFHandler::Policy::ParallelShared<dim,spacedim>(*this));
else if (dynamic_cast<const parallel::distributed::Triangulation< dim, spacedim >*>
(&t)
== nullptr)
- policy.reset (new internal::DoFHandler::Policy::Sequential<dim,spacedim>());
+ policy.reset (new internal::DoFHandler::Policy::Sequential<dim,spacedim>(*this));
else
- policy.reset (new internal::DoFHandler::Policy::ParallelDistributed<dim,spacedim>());
+ policy.reset (new internal::DoFHandler::Policy::ParallelDistributed<dim,spacedim>(*this));
distribute_dofs(fe);
}
internal::DoFHandler::Implementation::reserve_space (*this);
// hand things off to the policy
- policy->distribute_dofs (*this,number_cache);
+ policy->distribute_dofs (number_cache);
// initialize the block info object
// only if this is a sequential
else
mg_number_cache.resize(dist_tr->n_global_levels());
- policy->distribute_mg_dofs (*this, mg_number_cache);
+ policy->distribute_mg_dofs (mg_number_cache);
// initialize the block info object
// only if this is a sequential
ExcMessage ("New DoF index is not less than the total number of dofs."));
#endif
- policy->renumber_dofs (new_numbers, *this,number_cache);
+ policy->renumber_dofs (new_numbers, number_cache);
}
/* --------------------- class Sequential ---------------- */
+
+ template <int dim, int spacedim>
+ Sequential<dim,spacedim>::
+ Sequential (dealii::DoFHandler<dim,spacedim> &dof_handler)
+ :
+ dof_handler (dof_handler)
+ {}
+
+
+
template <int dim, int spacedim>
void
Sequential<dim,spacedim>::
- distribute_dofs (DoFHandler<dim,spacedim> &dof_handler,
- NumberCache &number_cache_current ) const
+ distribute_dofs (NumberCache &number_cache_current) const
{
const types::global_dof_index n_dofs =
Implementation::distribute_dofs (0,
template <int dim, int spacedim>
void
Sequential<dim,spacedim>::
- distribute_mg_dofs (DoFHandler<dim,spacedim> &dof_handler,
- std::vector<NumberCache> &number_caches) const
+ distribute_mg_dofs (std::vector<NumberCache> &number_caches) const
{
std::vector<bool> user_flags;
void
Sequential<dim,spacedim>::
renumber_dofs (const std::vector<types::global_dof_index> &new_numbers,
- dealii::DoFHandler<dim,spacedim> &dof_handler,
NumberCache &number_cache_current) const
{
Implementation::renumber_dofs (new_numbers, IndexSet(0),
/* --------------------- class ParallelShared ---------------- */
+
+ template <int dim, int spacedim>
+ ParallelShared<dim,spacedim>::
+ ParallelShared (dealii::DoFHandler<dim,spacedim> &dof_handler)
+ :
+ Sequential<dim,spacedim> (dof_handler)
+ {}
+
+
+
+
+
template <int dim, int spacedim>
void
ParallelShared<dim,spacedim>::
- distribute_dofs (DoFHandler<dim,spacedim> &dof_handler,
- NumberCache &number_cache) const
+ distribute_dofs (NumberCache &number_cache) const
{
// If the underlying shared::Tria allows artificial cells, we need to do
// some tricks here to make Sequential algorithms play nicely.
// Namely, we first restore the original partition (without artificial cells)
// and then turn artificial cells on at the end of this function.
const parallel::shared::Triangulation<dim, spacedim> *tr =
- (dynamic_cast<const parallel::shared::Triangulation<dim, spacedim>*> (&dof_handler.get_triangulation()));
+ (dynamic_cast<const parallel::shared::Triangulation<dim, spacedim>*> (&this->dof_handler.get_triangulation()));
Assert(tr != nullptr, ExcInternalError());
typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator
- cell = dof_handler.get_triangulation().begin_active(),
- endc = dof_handler.get_triangulation().end();
+ cell = this->dof_handler.get_triangulation().begin_active(),
+ endc = this->dof_handler.get_triangulation().end();
std::vector<types::subdomain_id> current_subdomain_ids(tr->n_active_cells());
const std::vector<types::subdomain_id> &true_subdomain_ids = tr->get_true_subdomain_ids_of_cells();
if (tr->with_artificial_cells())
// let the sequential algorithm do its magic, then sort DoF indices
// by subdomain
- Sequential<dim,spacedim>::distribute_dofs (dof_handler,number_cache);
- DoFRenumbering::subdomain_wise (dof_handler);
+ this->Sequential<dim,spacedim>::distribute_dofs (number_cache);
+ DoFRenumbering::subdomain_wise (this->dof_handler);
// dofrenumbering will reset subdomains, this is ugly but we need to do it again:
cell = tr->begin_active();
for (unsigned int index=0; cell != endc; cell++, index++)
cell->set_subdomain_id(true_subdomain_ids[index]);
- number_cache.locally_owned_dofs_per_processor = DoFTools::locally_owned_dofs_per_subdomain (dof_handler);
- number_cache.locally_owned_dofs = number_cache.locally_owned_dofs_per_processor[dof_handler.get_triangulation().locally_owned_subdomain()];
+ number_cache.locally_owned_dofs_per_processor = DoFTools::locally_owned_dofs_per_subdomain (this->dof_handler);
+ number_cache.locally_owned_dofs = number_cache.locally_owned_dofs_per_processor[this->dof_handler.get_triangulation().locally_owned_subdomain()];
number_cache.n_locally_owned_dofs_per_processor.resize (number_cache.locally_owned_dofs_per_processor.size());
for (unsigned int i = 0; i < number_cache.n_locally_owned_dofs_per_processor.size(); i++)
number_cache.n_locally_owned_dofs_per_processor[i] = number_cache.locally_owned_dofs_per_processor[i].n_elements();
- number_cache.n_locally_owned_dofs = number_cache.n_locally_owned_dofs_per_processor[dof_handler.get_triangulation().locally_owned_subdomain()];
+ number_cache.n_locally_owned_dofs = number_cache.n_locally_owned_dofs_per_processor[this->dof_handler.get_triangulation().locally_owned_subdomain()];
// restore current subdomain ids
cell = tr->begin_active();
template <int dim, int spacedim>
void
ParallelShared<dim,spacedim>::
- distribute_mg_dofs (DoFHandler<dim,spacedim> &dof_handler,
- std::vector<NumberCache> &number_caches) const
+ distribute_mg_dofs (std::vector<NumberCache> &number_caches) const
{
// first, call the sequential function to distribute dofs
- Sequential<dim,spacedim>::distribute_mg_dofs (dof_handler, number_caches);
+ this->Sequential<dim,spacedim>::distribute_mg_dofs (number_caches);
// now we need to update the number cache. This part is not yet implemented.
AssertThrow(false,ExcNotImplemented());
}
void
ParallelShared<dim,spacedim>::
renumber_dofs (const std::vector<types::global_dof_index> &new_numbers,
- dealii::DoFHandler<dim,spacedim> &dof_handler,
NumberCache &number_cache) const
{
#ifndef DEAL_II_WITH_MPI
(void)new_numbers;
- (void)dof_handler;
(void)number_cache;
Assert (false, ExcNotImplemented());
#else
// Similar to distribute_dofs() we need to have a special treatment in
// case artificial cells are present.
const parallel::shared::Triangulation<dim, spacedim> *tr =
- (dynamic_cast<const parallel::shared::Triangulation<dim, spacedim>*> (&dof_handler.get_triangulation()));
+ (dynamic_cast<const parallel::shared::Triangulation<dim, spacedim>*> (&this->dof_handler.get_triangulation()));
Assert(tr != nullptr, ExcInternalError());
typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator
- cell = dof_handler.get_triangulation().begin_active(),
- endc = dof_handler.get_triangulation().end();
+ cell = this->dof_handler.get_triangulation().begin_active(),
+ endc = this->dof_handler.get_triangulation().end();
std::vector<types::subdomain_id> current_subdomain_ids(tr->n_active_cells());
const std::vector<types::subdomain_id> &true_subdomain_ids = tr->get_true_subdomain_ids_of_cells();
if (tr->with_artificial_cells())
cell->set_subdomain_id(true_subdomain_ids[index]);
}
- std::vector<types::global_dof_index> global_gathered_numbers (dof_handler.n_dofs (), 0);
+ std::vector<types::global_dof_index> global_gathered_numbers (this->dof_handler.n_dofs (), 0);
// as we call DoFRenumbering::subdomain_wise (dof_handler) from distribute_dofs(),
// we need to support sequential-like input.
// Distributed-like input from, for example, component_wise renumbering is also supported.
- if (new_numbers.size () == dof_handler.n_dofs ())
+ if (new_numbers.size () == this->dof_handler.n_dofs ())
{
global_gathered_numbers = new_numbers;
}
else
{
- Assert(new_numbers.size() == dof_handler.locally_owned_dofs().n_elements(),
+ Assert(new_numbers.size() == this->dof_handler.locally_owned_dofs().n_elements(),
ExcInternalError());
const unsigned int n_cpu = Utilities::MPI::n_mpi_processes (tr->get_communicator ());
- std::vector<types::global_dof_index> gathered_new_numbers (dof_handler.n_dofs (), 0);
+ std::vector<types::global_dof_index> gathered_new_numbers (this->dof_handler.n_dofs (), 0);
Assert(Utilities::MPI::this_mpi_process (tr->get_communicator ()) ==
- dof_handler.get_triangulation().locally_owned_subdomain (),
+ this->dof_handler.get_triangulation().locally_owned_subdomain (),
ExcInternalError())
// gather new numbers among processors into one vector
// flag_1 and flag_2 are
// used to control that there is a
// one-to-one relation between old and new DoFs.
- std::vector<unsigned int> flag_1 (dof_handler.n_dofs (), 0);
- std::vector<unsigned int> flag_2 (dof_handler.n_dofs (), 0);
+ std::vector<unsigned int> flag_1 (this->dof_handler.n_dofs (), 0);
+ std::vector<unsigned int> flag_2 (this->dof_handler.n_dofs (), 0);
for (unsigned int i = 0; i < n_cpu; i++)
{
const IndexSet &iset =
{
const types::global_dof_index target = iset.nth_index_in_set (ind);
const types::global_dof_index value = gathered_new_numbers[shift + ind];
- Assert(target < dof_handler.n_dofs(), ExcInternalError());
- Assert(value < dof_handler.n_dofs(), ExcInternalError());
+ Assert(target < this->dof_handler.n_dofs(), ExcInternalError());
+ Assert(value < this->dof_handler.n_dofs(), ExcInternalError());
global_gathered_numbers[target] = value;
flag_1[target]++;
flag_2[value]++;
ExcInternalError());
}
- Sequential<dim, spacedim>::renumber_dofs (global_gathered_numbers, dof_handler, number_cache);
+ this->Sequential<dim, spacedim>::renumber_dofs (global_gathered_numbers, number_cache);
// correct number_cache:
number_cache.locally_owned_dofs_per_processor =
- DoFTools::locally_owned_dofs_per_subdomain (dof_handler);
+ DoFTools::locally_owned_dofs_per_subdomain (this->dof_handler);
number_cache.locally_owned_dofs =
- number_cache.locally_owned_dofs_per_processor[dof_handler.get_triangulation().locally_owned_subdomain ()];
+ number_cache.locally_owned_dofs_per_processor[this->dof_handler.get_triangulation().locally_owned_subdomain ()];
// sequential renumbering returns a vector of size 1 here,
// correct this:
number_cache.n_locally_owned_dofs_per_processor.resize(number_cache.locally_owned_dofs_per_processor.size());
number_cache.n_locally_owned_dofs_per_processor[i] = number_cache.locally_owned_dofs_per_processor[i].n_elements ();
number_cache.n_locally_owned_dofs =
- number_cache.n_locally_owned_dofs_per_processor[dof_handler.get_triangulation().locally_owned_subdomain ()];
+ number_cache.n_locally_owned_dofs_per_processor[this->dof_handler.get_triangulation().locally_owned_subdomain ()];
// restore artificial cells
cell = tr->begin_active();
+ template <int dim, int spacedim>
+ ParallelDistributed<dim,spacedim>::
+ ParallelDistributed (dealii::DoFHandler<dim,spacedim> &dof_handler)
+ :
+ dof_handler (dof_handler)
+ {}
+
+
+
+
+
+
template <int dim, int spacedim>
void
ParallelDistributed<dim, spacedim>::
- distribute_dofs (DoFHandler<dim,spacedim> &dof_handler,
- NumberCache &number_cache_current) const
+ distribute_dofs (NumberCache &number_cache_current) const
{
NumberCache number_cache;
#ifndef DEAL_II_WITH_P4EST
- (void)dof_handler;
Assert (false, ExcNotImplemented());
#else
template <int dim, int spacedim>
void
ParallelDistributed<dim, spacedim>::
- distribute_mg_dofs (DoFHandler<dim,spacedim> &dof_handler,
- std::vector<NumberCache> &number_caches) const
+ distribute_mg_dofs (std::vector<NumberCache> &number_caches) const
{
#ifndef DEAL_II_WITH_P4EST
- (void)dof_handler;
(void)number_caches;
Assert (false, ExcNotImplemented());
#else
void
ParallelDistributed<dim, spacedim>::
renumber_dofs (const std::vector<dealii::types::global_dof_index> &new_numbers,
- dealii::DoFHandler<dim,spacedim> &dof_handler,
NumberCache &number_cache_current) const
{
(void)new_numbers;
- (void)dof_handler;
Assert (new_numbers.size() == dof_handler.locally_owned_dofs().n_elements(),
ExcInternalError());