Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
utilities.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_dem_utilities_h
5#define lethe_dem_utilities_h
6
7#include <deal.II/base/conditional_ostream.h>
8
9#include <deal.II/distributed/tria_base.h>
10
11using namespace dealii;
12
13
14/**
15 * @brief Reports the ratio between the minimum cell size and the maximum
16 * particle diameter.
17 *
18 * This function loops over all locally owned cells in a distributed mesh
19 * to find the minimum vertex-to-vertex distance (cell size), then compares
20 * it to the maximum particle diameter. It prints out the results using
21 * a ConditionalOStream and issues a warning if the ratio is too low.
22 *
23 * @tparam dim The spatial dimension of the triangulation.
24 * @param triangulation A reference to the distributed triangulation (mesh) object.
25 * @param maximum_particle_diameter The largest particle diameter in the simulation.
26 * @param pcout A ConditionalOStream used for printing output. In parallel simulations,
27 * this stream ensures that only one processor (usually the master) prints
28 * messages to avoid cluttered output from all MPI ranks.
29 * @param mpi_communicator The MPI communicator used for the parallel simulation.
30 * This is required to compute the **global minimum cell size** across all
31 * MPI processes.
32 */
33template <int dim>
34void
36 const parallel::DistributedTriangulationBase<dim> &triangulation,
37 const double maximum_particle_diameter,
38 const ConditionalOStream &pcout,
39 const MPI_Comm &mpi_communicator)
40{
41 double min_vertex_distance = std::numeric_limits<double>::max();
42 for (const auto &cell : triangulation.active_cell_iterators())
43 if (cell->is_locally_owned())
44 min_vertex_distance =
45 std::min(min_vertex_distance, cell->minimum_vertex_distance());
46 min_vertex_distance =
47 Utilities::MPI::min(min_vertex_distance, mpi_communicator);
48 pcout << "Minimum vertex distance between cell vertices: "
49 << min_vertex_distance << std::endl;
50 double ratio = min_vertex_distance / maximum_particle_diameter;
51 pcout << "Minimum cell size to maximum particle diameter ratio: " << ratio
52 << std::endl;
53 pcout << "-------------------------------------------------------------------"
54 << std::endl;
55
56 if (ratio < 1.0)
57 {
58 AssertThrow(
59 false,
60 ExcMessage(
61 "Minimum cell size is smaller than the maximum particle diameter. "
62 "Consider coarsening the mesh to achieve a ratio larger than 1"));
63 }
64}
65
66
67#endif
void report_cell_size_to_particle_diameter_ratio(const parallel::DistributedTriangulationBase< dim > &triangulation, const double maximum_particle_diameter, const ConditionalOStream &pcout, const MPI_Comm &mpi_communicator)
Reports the ratio between the minimum cell size and the maximum particle diameter.
Definition utilities.h:35