// This function generates a random position in the given cell and
- // returns the position and its coordinates in the unit cell. It first
- // tries to generate a random and uniformly distributed point in the
+ // returns the position and its coordinates in the reference cell. It
+ // first tries to generate a random and uniformly distributed point in
// real space, but if that fails (e.g. because the cell has a bad aspect
// ratio) it reverts to generating a random point in the unit cell.
template <int dim, int spacedim>
// Generate random points in these bounds until one is within the cell
// or we exceed the maximum number of attempts.
const unsigned int n_attempts = 100;
- Point<spacedim> position;
- Point<dim> position_unit;
for (unsigned int i = 0; i < n_attempts; ++i)
{
+ Point<spacedim> position;
for (unsigned int d = 0; d < spacedim; ++d)
{
position[d] = uniform_distribution_01(random_number_generator) *
try
{
- position_unit =
+ const Point<dim> position_unit =
mapping.transform_real_to_unit_cell(cell, position);
if (cell->reference_cell().contains_point(position_unit))
- return std::make_pair(position, position_unit);
+ return {position, position_unit};
}
catch (typename Mapping<dim>::ExcTransformationFailed &)
{
// If the above algorithm has not worked (e.g. because of badly
// deformed cells), retry generating particles
- // randomly within the reference cell. This is not generating a
+ // randomly within the reference cell and then mapping it to to
+ // real space. This is not generating a
// uniform distribution in real space, but will always succeed.
+ Point<dim> position_unit;
for (unsigned int d = 0; d < dim; ++d)
position_unit[d] = uniform_distribution_01(random_number_generator);
- position = mapping.transform_unit_to_real_cell(cell, position_unit);
+ const Point<spacedim> position =
+ mapping.transform_unit_to_real_cell(cell, position_unit);
- return std::make_pair(position, position_unit);
+ return {position, position_unit};
}
} // namespace
+
+
template <int dim, int spacedim>
void
regular_reference_locations(