LCOV - code coverage report
Current view: top level - ugbase/lib_disc/operator/linear_operator/multi_grid_solver - mg_stats.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 6 0
Test Date: 2025-09-21 23:31:46 Functions: - 0 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2017:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef __H__UG_mg_stats
      34              : #define __H__UG_mg_stats
      35              : 
      36              : #include <string>
      37              : #include <vector>
      38              : #include "common/util/table.h"
      39              : 
      40              : namespace ug{
      41              : 
      42              : ///     Records statistics on how individual parts of a multigrid method worked
      43              : template <typename TDomain, typename TAlgebra>
      44              : class MGStats {
      45              :         public:
      46              :                 typedef GridFunction<TDomain, TAlgebra> grid_func_t;
      47              :                 typedef SmartPtr<grid_func_t>                     sp_grid_func_t;
      48              : 
      49              : 
      50              :         ///     Defines at which stage data is recorded in a given multigrid cycle
      51              :                 enum Stage {
      52              :                         BEFORE_PRE_SMOOTH,
      53              :                         AFTER_PRE_SMOOTH,
      54              :                         BEFORE_POST_SMOOTH,
      55              :                         AFTER_POST_SMOOTH,
      56              :                         INVALID                                 // always last!
      57              :                 };
      58              : 
      59              :                 static const int NUM_STAGES = INVALID + 1;
      60              : 
      61              :                 MGStats();
      62              : 
      63              :         ///     If enabled, a deterioration of the norm of the defect leads to an error
      64              :         /**     disabled by default.*/
      65              :                 void set_exit_on_error(bool exitOnError);
      66              : 
      67              :         ///     If enabled, involved defects are written to file if the defect deteriorates
      68              :         /**     disabled by default.*/
      69              :                 void set_write_err_vecs(bool writeErrVecs);
      70              : 
      71              :         ///     If enabled, a diff bettween defects involved is written to file if the defect deteriorates
      72              :         /**     disabled by default.*/
      73              :                 void set_write_err_diffs(bool writeErrDiffs);
      74              : 
      75              :         ///     sets the active stages. All other stages will be ignored.
      76              :         /**     \param activeStages             vector containing constants from MGStats::Stage.
      77              :          *                                                      Each listed stage will be considered active, all
      78              :          *                                                      non-listed stages will be ignored.
      79              :          */
      80              :                 void set_active_stages(const std::vector<int>& activeStages);
      81              : 
      82              :         ///     sets the prefix with which files are written
      83              :         /**     This concerns the log-file and grid-function files.
      84              :          * Default is 'mgstats'.*/
      85              :                 void set_filename_prefix(const char* filename);
      86              : 
      87              :         ///     saves current stats to filenamePrefix.log
      88              :                 void save_stats_to_file();
      89              : 
      90              :         ///     saves current stats to the specified file
      91              :                 void save_stats_to_file(const char* filename);
      92              : 
      93              :         ///     prints the current stats
      94              :                 void print();
      95              : 
      96              :         ///     clears the current stats
      97              :                 void clear();
      98              : 
      99              :         ///     set the defect on a certain level for a given stage
     100              :         /**     If the defect for the previous stage was set for the same level,
     101              :          * norms are compared and a diff can be computed.
     102              :          *
     103              :          * If 'exitOnError' is enabled, the method will print the current stats and
     104              :          * throw an instance of UGError of the norm of the defect deteriorated.
     105              :          *
     106              :          * \note        In parallel environments this method is a synchronization point.
     107              :          *                      Make sure to call it from all processes which hold 'gf'.*/
     108              :                 void set_defect(grid_func_t& gf, int lvl, Stage stage);
     109              : 
     110              :         ///     returns the name of a given stage as a string
     111              :                 const char* stage_name(Stage stage) {
     112            0 :                         const char* stageNames[] = {    "BEFORE_PRE_SMOOTH",
     113              :                                                                                         "AFTER_PRE_SMOOTH",
     114              :                                                                                         "BEFORE_POST_SMOOTH",
     115              :                                                                                         "AFTER_POST_SMOOTH",
     116              :                                                                                         "INVALID"};
     117            0 :                         return stageNames[stage];
     118              :                 }
     119              : 
     120              :         ///     returns the name of the norm of a given stage as a string
     121              :                 const char* stage_norm_name(Stage stage) {
     122            0 :                         const char* stageNames[] = {    "|bef pre smth|",
     123              :                                                                                         "|aft pre smth|",
     124              :                                                                                         "|bef post smth|",
     125              :                                                                                         "|aft post smth|",
     126              :                                                                                         "|INVALID|"};
     127            0 :                         return stageNames[stage];
     128              :                 }
     129              : 
     130              :         private:
     131              :                 void level_required(int lvl);
     132              :                 void write_header(int maxLvl);
     133              : 
     134            0 :                 struct FuncEntry{
     135            0 :                         FuncEntry() : stage(INVALID), norm(0) {}
     136              :                         sp_grid_func_t  func;
     137              :                         sp_grid_func_t  tmpFunc;
     138              :                         Stage                   stage;
     139              :                         number                  norm;
     140              :                 };
     141              : 
     142              :                 std::vector<FuncEntry>    m_funcs;
     143              :                 bool            m_stageIsActive[NUM_STAGES];
     144              :                 StringTable     m_stats;
     145              :                 int                     m_statsRow;
     146              :                 int                     m_lastLvlWritten;
     147              :                 int                     m_maxLvl;
     148              :                 std::string     m_filenamePrefix;
     149              :                 bool            m_exitOnError;
     150              :                 bool            m_writeErrVecs;
     151              :                 bool            m_writeErrDiffs;
     152              : };
     153              : 
     154              : 
     155              : }//     end of namespace
     156              : 
     157              : ////////////////////////////////
     158              : //      include implementation
     159              : #include "mg_stats_impl.hpp"
     160              : 
     161              : 
     162              : #endif  //__H__UG_mg_stats
        

Generated by: LCOV version 2.0-1