forked from hundlab/LongQt-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
measure.cpp
141 lines (123 loc) · 3.4 KB
/
measure.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//################################################
// This code file
// defines Measure class used to track properties
// (e.g. peak, min, duration) of specified state variable.
//
// Copyright (C) 2015 Thomas J. Hund.
// Updated 07/2015
// Email thomas.hund@osumc.edu
//#################################################
#include "measure.h"
//#############################################################
// Measure class constructor and destructor
//#############################################################
Measure::Measure(set<string> selected)
{
for(auto& select: selected) {
if(varmap.count(select)>0) {
__selection.insert(select);
}
}
};
Measure::Measure(const Measure& toCopy) {
this->copy(toCopy);
};
Measure::Measure( Measure&& toCopy) {
this->copy(toCopy);
};
set<string> Measure::variables() {
set<string> toReturn;
for(auto& var: varmap) {
toReturn.insert(var.first);
}
return toReturn;
}
map<string,double> Measure::variablesMap() {
map<string,double> toReturn;
for(auto& var: varmap) {
toReturn.insert(std::pair<string,double>(var.first, *var.second));
}
return toReturn;
}
void Measure::copy(const Measure& toCopy) {
peak= toCopy.peak;
min= toCopy.min;
told = toCopy.told;
mint = toCopy.mint;
maxt = toCopy.maxt;
varold = toCopy.varold;
derivold = toCopy.derivold;
derivt = toCopy.derivt;
returnflag = toCopy.returnflag;
__selection = toCopy.__selection;
};
//################################################################
// Function to track properties (e.g. peak, min, duration) of
// specified state variable and return status flag to calling fxn.
//################################################################
bool Measure::measure(double time, double var) {
this->calcMeasure(time,var);
this->updateOld(time, var);
return this->returnflag;
}
void Measure::calcMeasure(double time, double var)
{
// if(minflag&&abs(var)>peak){ // Track value and time of peak
if(var>peak) {
peak=var;
maxt=time;
}
if(var<min){ // Track value and time of min
min=var;
mint=time;
}
if(std::isnan(told)) {
return;
}
returnflag = false; //default for return...set to 1 when props ready for output
deriv=(var-varold)/(time-told);
if(deriv>maxderiv){ // Track value and time of max 1st deriv
maxderiv=deriv;
derivt=time;
}
};
void Measure::updateOld(double time, double var) {
told=time;
varold=var;
derivold=deriv;
}
void Measure::reset()
{
peak=-100.0;
min=100.0;
maxderiv=0.0;
// maxderiv2nd=0.0;
//told is still valid after reset
// told = 0.0;
returnflag = false;
};
string Measure::getNameString(string name) const {
string nameStr = "";
for(auto& sel: this->__selection) {
nameStr += name+"/"+sel+"\t";
}
return nameStr;
}
string Measure::getValueString() const {
string valStr = "";
for(auto& sel: this->__selection) {
valStr += to_string(*this->varmap.at(sel))+"\t";
}
return valStr;
}
set<string> Measure::selection() {
return this->__selection;
}
void Measure::selection(set<string> new_selection) {
this->__selection.clear();
for(auto& select: new_selection) {
if(varmap.count(select) == 1) {
__selection.insert(select);
}
}
}