← Documentation
ADS-IDAC Engine 5.0.0
KBExpectedParameterValueUnit.cpp
Go to the documentation of this file.
1// KBExpectedParameterValueUnit.cpp: implementation of the KBExpectedParameterValueUnit class.
2//
4
6#include "../Branch/BranchRecord.h"
7#include "../CalculationAid/CalculationAid.h" //Y.L.
8#include <boost/serialization/export.hpp>
9#include "../Global/SimulationContext.h"
10#include <boost/archive/binary_oarchive.hpp>
11#include <boost/archive/binary_iarchive.hpp>
12BOOST_CLASS_EXPORT_IMPLEMENT(KBExpectedParameterValueUnit)
13using namespace std;
14
15
17// Construction/Destruction
19
21{
24 expected_value1 = 0.0;
25 expected_value2 = 0.0;
26}
27
29{
30
31}
37 //each expected value is either a number or "ModeV <polynomial name>" (value taken from a polynomial curve)
38 string str1, str2;
39 fin >> logical_relation;
40 fin >> str1;
41 if (str1=="ModeV"){
42 value1_mode = 1;
43 fin >> value1_poly_name;
44 }
45 else
46 {
47 value1_mode = 0;
48 expected_value1 = atof(str1.c_str());
49 }
50 fin >> str2;
51 if (str2 == "ModeV"){
52 value2_mode = 1;
53 fin >> value2_poly_name;
54 }
55 else{
56 value2_mode = 0;
57 expected_value2 = atof(str2.c_str());
58 }
59 poly1_pt = 0;
60 poly2_pt = 0;
61}
65int KBExpectedParameterValueUnit::checkForMatch(string _par_name, double _par_value, int _operator){
66 string str = KBElement::getInfoName();
67 int n_return = 0;
68 bool found = true;
69 BiResult BiResult1, BiResult2;
70 if(_par_name.compare(KBElement::getInfoName()) == 0){
71 //polynomial mode: refresh the expected values from their curves
72 if (value1_mode == 1)
73 {
74 if (poly1_pt == 0){ //Problem is here
76 BiResult1 = poly1_pt->GetCurveValue(_operator);
77 if (BiResult1.bool_result == false){
78 found = false;}
79 else{
80 expected_value1 = BiResult1.float_result;
81 }
82 }
83 if (value2_mode == 1)
84 {
85 if (poly2_pt == 0){
87 BiResult2 = poly2_pt->GetCurveValue(_operator);
88 if (BiResult2.bool_result == false){
89 found = false;}
90 else{expected_value2 = BiResult2.float_result;}
91 }
92 if (found == true)
93 {
94 switch(logical_relation){
96 if(_par_value > expected_value1){
98 }
99 else{
101 }
102 break;
103 case sim::Compare::GE:
104 if(_par_value >= expected_value1){
106 }
107 else{
109 }
110 break;
111 case sim::Compare::EQ:
112 if(_par_value == expected_value1){
114 }
115 else{
117 }
118 break;
119 case sim::Compare::LE:
120 if(_par_value <= expected_value1){
122 }
123 else{
125 }
126 break;
127 case sim::Compare::LT:
128 if(_par_value < expected_value1){
130 }
131 else{
133 }
134 break;
136 if(_par_value >= expected_value1 && _par_value <= expected_value2){
138 }
139 else{
141 }
142 break;
143 default:
144 ofstream fout("err messages.txt", ios::app);
145 cout << "KBExpectedParameterTrendUnit::checkForMatch par_name: " << _par_name << " whose logical relation: " << logical_relation << " can not be recognized." << endl;
146 fout << r5pars_.timesno << " KBExpectedParameterTrendUnit::checkForMatch par_name: " << _par_name << " whose logical relation: " << logical_relation << " can not be recognized.\n";
147 fout.close();
148 r5pars_.sim_err = true;
149 g_sim.Branch_center.setTempESMessage("KBExpectedParameterValueUnit::checkForMatch err.");
151 break;
152 }
153 }
154 else{n_return = 0;}
155 }
156 else{
157 n_return = 0;
158 }
159 return n_return;
160}
161
172 poly1_pt = 0;
173 poly2_pt = 0;
174}
176 fout << "KBExpectedParameterValueUnit " << logical_relation << ' ' << expected_value1 << ' ' << expected_value2 << '\n';
178 this->saveKBElementToFile(fout);
179}
181 string str;
183 if (str != "KBExpectedParameterValueUnit"){
184 ofstream fout("err messages.txt", ios::app);
185 cout << "KBExpectedParameterValueUnit::retrieveKBExpectedParameterValueUnitFromFile in previous function" << endl;
186 fout << r5pars_.timesno << " KBExpectedParameterValueUnit::retrieveKBExpectedParameterValueUnitFromFile in previous function\n";
187 fout.close();
188 r5pars_.sim_err = true;
189 g_sim.Branch_center.setTempESMessage("KBExpectedParameterTrendUnit::retrieveKBExpectedParameterTrendUnitFromFile Prior err.");
191 return;
192 }
194 this->retrieveKBElementFromFile(fin);
195}
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
float float_result
Definition: BiResult.h:10
bool bool_result
Definition: BiResult.h:11
void setTempTypeOfConsequence(Consequence)
Stores the consequence of the end state the running sequence will get.
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
polynomial * checkExistanceOfPolynomial(std::string)
void saveExpectationElementToFile(std::ofstream &)
void retrieveExpectationElementFromFile(std::ifstream &)
void copyExpectationElement(ExpectationElement &)
void readInfoFromFile(std::ifstream &)
Definition: KBElement.cpp:27
void retrieveKBElementFromFile(std::ifstream &)
Definition: KBElement.cpp:36
void saveKBElementToFile(std::ofstream &)
Definition: KBElement.cpp:33
void copyKBElement(KBElement &)
Definition: KBElement.cpp:30
std::string getInfoName()
Definition: KBElement.cpp:26
void copyKBExpectedParameterValueUnit(KBExpectedParameterValueUnit &)
int checkForMatch(std::string, double, int)
void saveKBExpectedParameterValueUnitToFile(std::ofstream &)
void retrieveKBExpectedParameterValueUnitFromFile(std::ifstream &)
BiResult GetCurveValue(int)
Definition: Polynomial.cpp:51
struct @0 r5pars_
constexpr int ParameterValue
Definition: SimConstants.h:286
constexpr int GE
Definition: SimConstants.h:88
constexpr int GT
Definition: SimConstants.h:87
constexpr int LE
Definition: SimConstants.h:90
constexpr int LT
Definition: SimConstants.h:91
constexpr int Between
Definition: SimConstants.h:92
constexpr int EQ
Definition: SimConstants.h:89
constexpr int Failed
Definition: SimConstants.h:103
constexpr int Succeed
Definition: SimConstants.h:104
constexpr int None
Definition: SimConstants.h:75
BranchRecord Branch_center
Dynamic event tree state.
CalculationAid All_polynomial
Polynomial calculations.