NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
interval.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2021 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20#ifndef INTERVAL_HPP
21#define INTERVAL_HPP
22
23#include <vector>
24#include <string>
25
27
34{
35 private:
36 std::string m_sDefinition;
37 std::vector<double> m_vInterval;
38
39 void assign(const Interval& ivl);
40 double getSample(size_t n, size_t nSamples) const;
41
42 public:
43 std::string name;
44
45 Interval() : m_sDefinition(), m_vInterval({NAN,NAN}), name() {}
46 Interval(const std::string& sDef);
48 Interval(const Interval& ivl);
49
50 Interval& operator=(const Interval& ivl);
51 mu::value_type operator()(size_t n, size_t nSamples = 100) const;
52 mu::value_type log(size_t n, size_t nSamples = 100) const;
53
54 mu::value_type front() const;
55 mu::value_type back() const;
56
57 mu::value_type cmin() const;
58 mu::value_type cmax() const;
59
60 double min() const;
61 double max() const;
62 double range() const;
63 double middle() const;
64
65 bool isInside(mu::value_type val) const;
66 bool contains(const std::string& sVarName) const;
67 size_t getSamples() const;
68
69 void refresh();
70 void reset(const std::string& sDef);
71 void reset(mu::value_type dFront, mu::value_type dBack);
72
73 void expand(double perc, double dMin = -INFINITY);
74 Interval combine(const Interval& _ivl) const;
75};
76
77
84{
85 std::vector<Interval> intervals;
86
87 IntervalSet(const std::string& sIntervalString);
88 IntervalSet(const IntervalSet& ivSet);
89 IntervalSet() = default;
90
91 IntervalSet& operator=(const IntervalSet& ivSet);
92 Interval& operator[](size_t n);
93 const Interval& operator[](size_t n) const;
94
95 bool hasDependentIntervals() const;
96 size_t size() const;
97 std::vector<mu::value_type> convert();
98 void setNames(const std::vector<std::string>& vNames);
99};
100
101
106struct Line
107{
108 std::string sDesc;
109 std::string sStyle;
110 double dPos;
111
112 Line() : sDesc(""), sStyle("k;2"), dPos(0.0) {}
113};
114
115
119struct Axis
120{
121 std::string sLabel;
122 std::string sStyle;
124};
125
126
132{
133 std::string sTimeFormat;
134 bool use;
135
136 TimeAxis() : sTimeFormat(""), use(false) {}
137
138 void activate(const std::string& sFormat = "")
139 {
140 use = true;
141 sTimeFormat = sFormat;
142
143 if (!sTimeFormat.length())
144 return;
145
146 if (sTimeFormat.find("YYYY") != std::string::npos)
147 sTimeFormat.replace(sTimeFormat.find("YYYY"), 4, "%Y");
148
149 if (sTimeFormat.find("YY") != std::string::npos)
150 sTimeFormat.replace(sTimeFormat.find("YY"), 2, "%y");
151
152 if (sTimeFormat.find("MM") != std::string::npos)
153 sTimeFormat.replace(sTimeFormat.find("MM"), 2, "%m");
154
155 if (sTimeFormat.find("DD") != std::string::npos)
156 sTimeFormat.replace(sTimeFormat.find("DD"), 2, "%d");
157
158 if (sTimeFormat.find("HH") != std::string::npos)
159 sTimeFormat.replace(sTimeFormat.find("HH"), 2, "%H");
160
161 if (sTimeFormat.find("hh") != std::string::npos)
162 sTimeFormat.replace(sTimeFormat.find("hh"), 2, "%H");
163
164 if (sTimeFormat.find("mm") != std::string::npos)
165 sTimeFormat.replace(sTimeFormat.find("mm"), 2, "%M");
166
167 if (sTimeFormat.find("ss") != std::string::npos)
168 sTimeFormat.replace(sTimeFormat.find("ss"), 2, "%S");
169 }
170
172 {
173 use = false;
174 sTimeFormat.clear();
175 }
176};
177
178
179
180#endif // INTERVAL_HPP
181
182
This class represents a single interval in code providing reading access functionality.
Definition: interval.hpp:34
void expand(double perc, double dMin=-INFINITY)
Expand the interval by the corresponding percentage. The expansion is equally distributed to both end...
Definition: interval.cpp:434
void assign(const Interval &ivl)
Assign a interval object to this instance.
Definition: interval.cpp:36
Interval combine(const Interval &_ivl) const
Returns the (continous) interval, which contains this and the passed interval.
Definition: interval.cpp:466
mu::value_type back() const
Return the last element in the interval.
Definition: interval.cpp:200
void refresh()
Referesh the internal interval representation (e.g. after a dependency has been updated).
Definition: interval.cpp:339
std::string m_sDefinition
Definition: interval.hpp:36
size_t getSamples() const
Returns the number of internal samples. Will return zero, if the internal samples are only interval s...
Definition: interval.cpp:322
double getSample(size_t n, size_t nSamples) const
Return the nth sample of the interval using the desired number of samples.
Definition: interval.cpp:53
double range() const
Return the real inteval range of this interval.
Definition: interval.cpp:265
void reset(const std::string &sDef)
Reset the interval with a new definition.
Definition: interval.cpp:402
mu::value_type cmax() const
Return the componentwise maximal element in the interval.
Definition: interval.cpp:226
double middle() const
Calculates the middle point of the interval.
Definition: interval.cpp:278
std::string name
Definition: interval.hpp:43
bool isInside(mu::value_type val) const
Checks, whether the passed value is part of this interval.
Definition: interval.cpp:292
mu::value_type front() const
Return the first element in the interval.
Definition: interval.cpp:187
std::vector< double > m_vInterval
Definition: interval.hpp:37
Interval & operator=(const Interval &ivl)
Assignment operator overload.
Definition: interval.cpp:145
double max() const
Return the maximal element in the interval.
Definition: interval.cpp:252
Interval()
Definition: interval.hpp:45
bool contains(const std::string &sVarName) const
Check, whether a variable is part of the interval definition string to detect a possible dependency.
Definition: interval.cpp:308
mu::value_type log(size_t n, size_t nSamples=100) const
Return a sample in logarithmic scale.
Definition: interval.cpp:174
mu::value_type operator()(size_t n, size_t nSamples=100) const
Parenthesis operator overload.
Definition: interval.cpp:160
mu::value_type cmin() const
Return the componentwise minimal element in the interval.
Definition: interval.cpp:213
double min() const
Return the minimal element in the interval.
Definition: interval.cpp:239
This file contains standard definitions used by the parser.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
Structure for the axes in plots.
Definition: interval.hpp:120
Interval ivl
Definition: interval.hpp:123
std::string sStyle
Definition: interval.hpp:122
std::string sLabel
Definition: interval.hpp:121
This class represents a set of intervals used together for calculations and simulations.
Definition: interval.hpp:84
std::vector< mu::value_type > convert()
Convert the new interval data types to the old plain mu::value_type values.
Definition: interval.cpp:656
size_t size() const
Return the number of intervals.
Definition: interval.cpp:643
void setNames(const std::vector< std::string > &vNames)
Set the interval names.
Definition: interval.cpp:677
IntervalSet()=default
bool hasDependentIntervals() const
Detect, whether there are intervals, which depend on each other.
Definition: interval.cpp:622
std::vector< Interval > intervals
Definition: interval.hpp:85
Interval & operator[](size_t n)
Access operator overload.
Definition: interval.cpp:590
IntervalSet & operator=(const IntervalSet &ivSet)
Assignment operator overload.
Definition: interval.cpp:576
Structure for the horizontal and vertical lines in plots.
Definition: interval.hpp:107
std::string sDesc
Definition: interval.hpp:108
double dPos
Definition: interval.hpp:110
Line()
Definition: interval.hpp:112
std::string sStyle
Definition: interval.hpp:109
Structure for describing time axes in plots.
Definition: interval.hpp:132
bool use
Definition: interval.hpp:134
void activate(const std::string &sFormat="")
Definition: interval.hpp:138
std::string sTimeFormat
Definition: interval.hpp:133
void deactivate()
Definition: interval.hpp:171