Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
finished_conditions.hpp
Go to the documentation of this file.
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>
40#include <common/types.h>
41
42namespace ug {
43
44
46{
47 public:
48 virtual bool check_finished(number time, int step) { return false; }
50};
51
53{
54 public:
57
58 bool is_finished(number time, int step)
59 {
60 for(size_t i = 0; i < m_conditions.size(); i++)
61 {
62 if(m_conditions[i]->check_finished(time, step))
63 {
64 return true;
65 }
66 }
67 return false;
68 }
69
70 void add_condition(cond_type condition)
71 {
72 m_conditions.push_back(condition);
73 }
74
75
76 private:
77 std::vector<cond_type> m_conditions;
78};
79
81{
82 public:
83 MaxStepsFinishedCondition(int max_timesteps) : m_max_timesteps(max_timesteps)
84 {}
85
86 bool check_finished(number time, int step)
87 {
88 return step >= m_max_timesteps;
89 }
90 private:
92};
93
95{
96 public:
97 TemporalFinishedCondition(number end_time, number max_step_size, number relative_precision_bound) :
98 m_end_time(end_time), m_max_step_size(max_step_size), m_relative_precision_bound(relative_precision_bound)
99 {}
100
101 bool check_finished(number time, int step)
102 {
103 return (time >= m_end_time) || ((m_end_time-time)/m_max_step_size <= m_relative_precision_bound);
104 }
105
106 void set_max_step_size(number max_step_size)
107 {
108 m_max_step_size = max_step_size;
109 }
110
111 private:
115};
116
117}
118#endif
Definition smart_pointer.h:108
Definition finished_conditions.hpp:53
std::vector< cond_type > m_conditions
Definition finished_conditions.hpp:77
void add_condition(cond_type condition)
Definition finished_conditions.hpp:70
FinishedTester()
Definition finished_conditions.hpp:56
bool is_finished(number time, int step)
Definition finished_conditions.hpp:58
SmartPtr< IFinishedCondition > cond_type
Definition finished_conditions.hpp:55
Definition finished_conditions.hpp:46
virtual ~IFinishedCondition()
Definition finished_conditions.hpp:49
virtual bool check_finished(number time, int step)
Definition finished_conditions.hpp:48
Definition finished_conditions.hpp:81
bool check_finished(number time, int step)
Definition finished_conditions.hpp:86
MaxStepsFinishedCondition(int max_timesteps)
Definition finished_conditions.hpp:83
int m_max_timesteps
Definition finished_conditions.hpp:91
Definition finished_conditions.hpp:95
bool check_finished(number time, int step)
Definition finished_conditions.hpp:101
TemporalFinishedCondition(number end_time, number max_step_size, number relative_precision_bound)
Definition finished_conditions.hpp:97
number m_end_time
Definition finished_conditions.hpp:112
number m_max_step_size
Definition finished_conditions.hpp:113
number m_relative_precision_bound
Definition finished_conditions.hpp:114
void set_max_step_size(number max_step_size)
Definition finished_conditions.hpp:106
double number
Definition types.h:124
the ug namespace