LCOV - code coverage report
Current view: top level - ugbase/lib_disc/time_disc - finished_conditions.hpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 19 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 8 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2010-2020:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Tim Schön
       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              : 
      34              : #ifndef __H__UG__LIB_DISC__TIME_DISC__FINISHED_CONDITIONS
      35              : #define __H__UG__LIB_DISC__TIME_DISC__FINISHED_CONDITIONS
      36              : 
      37              : 
      38              : #include <vector>
      39              : #include <common/util/smart_pointer.h>
      40              : #include <common/types.h>
      41              : 
      42              : namespace ug {
      43              :         
      44              : 
      45              : class IFinishedCondition
      46              : {
      47              :     public:
      48            0 :         virtual bool check_finished(number time, int step) { return false; }
      49            0 :                 virtual ~IFinishedCondition() {}
      50              : };
      51              : 
      52            0 : class FinishedTester
      53              : {
      54              :         public:
      55              :                 typedef SmartPtr<IFinishedCondition> cond_type;
      56              :                 FinishedTester(){}
      57              : 
      58            0 :                 bool is_finished(number time, int step)
      59              :                 {
      60            0 :                         for(size_t i = 0; i < m_conditions.size(); i++)
      61              :                         {
      62            0 :                                 if(m_conditions[i]->check_finished(time, step))
      63              :                                 {
      64              :                                         return true;
      65              :                                 }
      66              :                         }
      67              :                         return false;
      68              :                 }
      69              : 
      70            0 :                 void add_condition(cond_type condition)
      71              :                 {
      72            0 :                         m_conditions.push_back(condition);
      73            0 :                 }
      74              : 
      75              :         
      76              :         private:
      77              :                 std::vector<cond_type> m_conditions;
      78              : };
      79              : 
      80              : class MaxStepsFinishedCondition : public IFinishedCondition
      81              : {       
      82              :         public:
      83            0 :                 MaxStepsFinishedCondition(int max_timesteps) : m_max_timesteps(max_timesteps)
      84              :                 {}
      85              : 
      86            0 :                 bool check_finished(number time, int step)
      87              :                 {
      88            0 :                         return step >= m_max_timesteps;
      89              :                 }
      90              :         private:
      91              :                 int m_max_timesteps;
      92              : };
      93              : 
      94              : class TemporalFinishedCondition : public IFinishedCondition
      95              : {
      96              :         public:
      97            0 :                 TemporalFinishedCondition(number end_time, number max_step_size, number relative_precision_bound) : 
      98            0 :                         m_end_time(end_time), m_max_step_size(max_step_size), m_relative_precision_bound(relative_precision_bound)
      99              :                 {}
     100              : 
     101            0 :                 bool check_finished(number time, int step)
     102              :                 {
     103            0 :                         return (time >= m_end_time) || ((m_end_time-time)/m_max_step_size <= m_relative_precision_bound);
     104              :                 }
     105              : 
     106            0 :                 void set_max_step_size(number max_step_size)
     107              :                 {
     108            0 :                         m_max_step_size = max_step_size;
     109            0 :                 }
     110              : 
     111              :         private:
     112              :                 number m_end_time;
     113              :                 number m_max_step_size;
     114              :                 number m_relative_precision_bound;
     115              : };
     116              : 
     117              : }
     118              : #endif
        

Generated by: LCOV version 2.0-1