SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
src
cond.cc
Go to the documentation of this file.
1
/////////////////////////////////////////////////////////////////////////////
2
//! \file cond.cc State conditions
3
//
4
// Copyright (c) 1991-2004 Petr Peringer
5
//
6
// This library is licensed under GNU Library GPL. See the file COPYING.
7
//
8
9
//
10
// description: continuous system - state conditions
11
//
12
13
////////////////////////////////////////////////////////////////////////////
14
// interface
15
//
16
17
#include "
simlib.h
"
18
#include "
internal.h
"
19
20
namespace
simlib3
{
21
22
23
////////////////////////////////////////////////////////////////////////////
24
// implementation
25
//
26
27
SIMLIB_IMPLEMENTATION
;
28
29
30
bool
SIMLIB_ConditionFlag
=
false
;
// condition vector changed
31
aCondition
*
aCondition::First
= 0;
// condition list
32
33
////////////////////////////////////////////////////////////////////////////
34
// aCondition implementation
35
//
36
aCondition::aCondition
() :
37
Next
(
First
)
38
{
39
First
=
this
;
40
}
41
42
aCondition::~aCondition
() {
43
if
(
this
==
First
)
44
First
=
Next
;
45
else
46
{
47
aCondition
*i;
48
for
(i=
First
; i && i->
Next
!=
this
; i=i->
Next
) {
/*empty*/
}
49
if
(i) i->
Next
=
Next
;
50
}
51
}
52
53
////////////////////////////////////////////////////////////////////////////
54
// aCondition::InitAll -- initialize all conditions
55
//
56
void
aCondition::InitAll
() {
57
SIMLIB_ConditionFlag
=
false
;
58
for
(
aCondition
*i=
First
; i; i=i->
Next
)
59
i->Init();
60
}
61
62
////////////////////////////////////////////////////////////////////////////
63
// aCondition::SetAll
64
//
65
void
aCondition::SetAll
() {
66
for
(
aCondition
*i=
First
; i; i=i->
Next
)
67
i->SetNewStatus();
68
}
69
70
bool
aCondition::isAny
() {
return
First
!=0; }
71
72
////////////////////////////////////////////////////////////////////////////
73
// Condition implementation
74
//
75
Condition::Condition
(
Input
i) :
76
in
(i),
77
cc
(0),
78
ccl
(0)
79
{
80
}
81
82
Condition::~Condition
()
83
{
84
}
85
86
////////////////////////////////////////////////////////////////////////////
87
// Condition::Init -- initialize
88
//
89
void
Condition::Init
()
90
{
91
cc
=
ccl
= 0;
92
}
93
94
////////////////////////////////////////////////////////////////////////////
95
// Condition::SetNewStatus -- set new status of condition
96
//
97
void
Condition::SetNewStatus
()
98
{
99
ccl
=
cc
;
100
}
101
102
103
////////////////////////////////////////////////////////////////////////////
104
/// Condition::operator ()
105
//
106
bool
Condition::Test
() {
107
bool
x = (
in
.
Value
()>=0.0);
108
if
(
SIMLIB_DynamicFlag
)
// inside numerical integration step
109
{
110
cc
= x;
// new condition status
111
if
(
Change
()) {
// is change of status?
112
SIMLIB_ConditionFlag
=
true
;
// global change flag
113
ContractStep
();
// need to step contraction
114
}
115
return
false
;
// test only
116
}
117
return
Change
();
// do actions if changed
118
}
119
120
////////////////////////////////////////////////////////////////////////////
121
// test or action
122
//
123
void
aCondition::TestAll
()
124
{
125
SIMLIB_ConditionFlag
=
false
;
126
for
(
aCondition
*i=
aCondition::First
; i ; i=i->
Next
)
127
if
(i->Test())
SIMLIB_ConditionFlag
=
true
;
128
}
129
130
void
aCondition::AllActions
()
131
{
132
for
(
aCondition
*i=
aCondition::First
; i ; i=i->
Next
)
133
if
(i->Test()) i->Action();
/// Change???? ### !!!!
134
}
135
136
////////////////////////////////////////////////////////////////////////////
137
// SIMLIB_DoConditions -- perform reactions to condition change
138
//
139
void
SIMLIB_DoConditions
()
140
{
141
// precondition: SIMLIB_DynamicFlag = false;
142
if
(
SIMLIB_ConditionFlag
)
143
{
144
void
SampleDelays
();
// needs something better ###
145
SampleDelays
();
146
147
aCondition::AllActions
();
// perform reactions to condition change
148
aCondition::SetAll
();
// register new status
149
SIMLIB_ResetStatus
=
true
;
// ??? always reset integration method ???
150
}
151
}
152
153
#if 0
154
////////////////////////////////////////////////////////////////////////////
155
/// get name of object
156
const
char
*
Condition::Name
()
const
{
157
if
(
HasName
())
return
_name;
158
else
return
SIMLIB_create_tmp_name
(
"Condition{%p}"
,
this
);
159
}
160
161
////////////////////////////////////////////////////////////////////////////
162
/// get name of object
163
const
char
*
ConditionUp::Name
()
const
{
164
if
(
HasName
())
return
_name;
165
else
return
SIMLIB_create_tmp_name
(
"ConditionUp{%p}"
,
this
);
166
}
167
168
////////////////////////////////////////////////////////////////////////////
169
/// get name of object
170
const
char
*
ConditionDown::Name
()
const
{
171
if
(
HasName
())
return
_name;
172
else
return
SIMLIB_create_tmp_name
(
"ConditionDown{%p}"
,
this
);
173
}
174
#endif
175
176
}
// namespace
177
simlib3::Condition::Change
bool Change()
Definition
simlib.h:1521
simlib3::Condition::in
Input in
Definition
simlib.h:1512
simlib3::Condition::Condition
Condition(Input i)
Definition
cond.cc:75
simlib3::Condition::~Condition
~Condition()
Definition
cond.cc:82
simlib3::Condition::SetNewStatus
virtual void SetNewStatus() override
update
Definition
cond.cc:97
simlib3::Condition::Test
virtual bool Test() override
Condition::operator ().
Definition
cond.cc:106
simlib3::Condition::ccl
unsigned char ccl
old state
Definition
simlib.h:1514
simlib3::Condition::cc
unsigned char cc
state
Definition
simlib.h:1513
simlib3::Condition::Init
virtual void Init() override
initialize
Definition
cond.cc:89
simlib3::Input
continuous block connection (transparent reference) wrapper for pointer to objects of aContiBlock der...
Definition
simlib.h:900
simlib3::Input::Value
double Value() const
get target block value
Definition
simlib.h:936
simlib3::SimObject::HasName
bool HasName() const
Definition
simlib.h:326
simlib3::SimObject::Name
virtual std::string Name() const
get object name
Definition
object.cc:134
simlib3::aCondition
abstract base class for all state-condition blocks State event in combined model is executed at the t...
Definition
simlib.h:1489
simlib3::aCondition::Next
aCondition * Next
Definition
simlib.h:1491
simlib3::aCondition::InitAll
static void InitAll()
Definition
cond.cc:56
simlib3::aCondition::First
static aCondition * First
Definition
simlib.h:1490
simlib3::aCondition::TestAll
static void TestAll()
Definition
cond.cc:123
simlib3::aCondition::aCondition
aCondition(const aCondition &)=delete
simlib3::aCondition::isAny
static bool isAny()
Definition
cond.cc:70
simlib3::aCondition::~aCondition
~aCondition()
Definition
cond.cc:42
simlib3::aCondition::aCondition
aCondition()
Definition
cond.cc:36
simlib3::aCondition::AllActions
static void AllActions()
Definition
cond.cc:130
simlib3::aCondition::SetAll
static void SetAll()
Definition
cond.cc:65
internal.h
Internal header file for SIMLIB/C++.
simlib3
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition
algloop.cc:32
simlib3::SIMLIB_DynamicFlag
bool SIMLIB_DynamicFlag
in dynamic section
Definition
intg.cc:56
simlib3::SIMLIB_ConditionFlag
bool SIMLIB_ConditionFlag
Definition
cond.cc:30
simlib3::SIMLIB_IMPLEMENTATION
SIMLIB_IMPLEMENTATION
Definition
algloop.cc:34
simlib3::SampleDelays
void SampleDelays()
Definition
run.cc:92
simlib3::SIMLIB_create_tmp_name
std::string SIMLIB_create_tmp_name(const char *fmt,...)
printf-like function to create temporary name (the length of temporary names is limited) used only ...
Definition
name.cc:80
simlib3::SIMLIB_ResetStatus
bool SIMLIB_ResetStatus
flag set if there is a need for integration method restart
Definition
intg.cc:86
simlib3::SIMLIB_DoConditions
void SIMLIB_DoConditions()
Definition
cond.cc:139
simlib3::ContractStep
void ContractStep()
contract step of integration
Definition
intg.cc:64
simlib.h
Main SIMLIB/C++ interface.
Generated on
for SIMLIB/C++ by
1.18.0