Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <boost/rational.hpp> 7 : #include <cstddef> 8 : #include <vector> 9 : 10 : #include "DataStructures/DataBox/DataBox.hpp" 11 : #include "Domain/Domain.hpp" 12 : #include "Domain/Tags.hpp" 13 : #include "IO/Logging/Tags.hpp" 14 : #include "IO/Logging/Verbosity.hpp" 15 : #include "Parallel/GlobalCache.hpp" 16 : #include "Parallel/Printf.hpp" 17 : #include "Parallel/Reduction.hpp" 18 : #include "ParallelAlgorithms/Amr/Tags.hpp" 19 : #include "Utilities/MakeString.hpp" 20 : #include "Utilities/StdHelpers.hpp" 21 : #include "Utilities/System/Abort.hpp" 22 : 23 : namespace amr::Actions { 24 : 25 : /// \brief Use the AMR diagnostics gathered from all of the Element%s 26 : /// 27 : /// Checks the following: 28 : /// - That the fraction of Block volume (in the logical coordinate frame) 29 : /// covered by all Element%s is equal to the number of Block%s in the Domain 30 : /// 31 : /// Prints the following (as integers): 32 : /// - The number of elements 33 : /// - The number of grid points 34 : /// - The average refinement level by logical dimension (i.e. not by the 35 : /// physical dimensions) 36 : /// - The average number of grid points by logical dimension 37 1 : struct RunAmrDiagnostics { 38 0 : using const_global_cache_tags = 39 : tmpl::list<logging::Tags::Verbosity<amr::OptionTags::AmrGroup>>; 40 : 41 : template <typename ParallelComponent, typename DbTagList, 42 : typename Metavariables, typename ArrayIndex> 43 0 : static void apply(db::DataBox<DbTagList>& box, 44 : const Parallel::GlobalCache<Metavariables>& /*cache*/, 45 : const ArrayIndex& /*array_index*/, 46 : const boost::rational<size_t>& volume, 47 : const size_t number_of_elements, 48 : const size_t number_of_grid_points, 49 : const std::vector<double>& avg_refinement_levels_by_dim, 50 : const std::vector<double>& avg_extents_by_dim) { 51 : constexpr size_t volume_dim = Metavariables::volume_dim; 52 : const boost::rational<size_t> number_of_blocks{ 53 : db::get<::domain::Tags::Domain<volume_dim>>(box).blocks().size()}; 54 : if (number_of_blocks != volume) { 55 : sys::abort(MakeString{} << "Check Domain failed! Expected volume " 56 : << number_of_blocks << ", not " << volume 57 : << "\n"); 58 : } 59 : if (db::get<logging::Tags::Verbosity<amr::OptionTags::AmrGroup>>(box) >= 60 : Verbosity::Quiet) { 61 : const std::string string_gcc_needs_to_use_in_order_for_printf_to_compile = 62 : MakeString{} << "Average refinement levels: " 63 : << avg_refinement_levels_by_dim 64 : << "\nAverage grid points: " << avg_extents_by_dim 65 : << "\n"; 66 : Parallel::printf( 67 : "Number of elements: %zu\n" 68 : "Number of grid points: %zu\n" 69 : "%s\n", 70 : number_of_elements, number_of_grid_points, 71 : string_gcc_needs_to_use_in_order_for_printf_to_compile); 72 : } 73 : } 74 : }; 75 : } // namespace amr::Actions