SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
src
fun.cc
Go to the documentation of this file.
1
/////////////////////////////////////////////////////////////////////////////
2
//! \file fun.cc Function blocks
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
// standard continuous function blocks
11
//
12
13
14
////////////////////////////////////////////////////////////////////////////
15
// interface
16
//
17
18
#include "
simlib.h
"
19
#include "
internal.h
"
20
21
#include <cmath>
// functions
22
23
////////////////////////////////////////////////////////////////////////////
24
// implementation
25
//
26
27
namespace
simlib3
{
28
29
SIMLIB_IMPLEMENTATION
;
30
31
////////////////////////////////////////////////////////////////////////////
32
/// constructor --- functions with single argument
33
//
34
Function1::Function1
(
Input
i,
double
(*pf)(
double
))
35
:
aContiBlock1
(i),
f
(pf) {
36
Dprintf
((
"Function1::Function1(in)"
));
37
}
38
39
double
Function1::Value
() {
40
AlgLoopDetector
_(
this
);
41
double
ret =
f
(
InputValue
());
42
return
ret;
43
}
44
45
#if 0
46
const
char
*
Function1::Name
()
const
{
47
if
(
HasName
())
return
_name;
48
else
return
SIMLIB_create_tmp_name
(
"Function1{%p}"
,
this
);
49
}
50
#endif
51
52
////////////////////////////////////////////////////////////////////////////
53
/// constructor --- functions with two arguments
54
//
55
Function2::Function2
(
Input
i1,
Input
i2,
double
(*pf)(
double
,
double
))
56
:
aContiBlock2
(i1,i2),
f
(pf) {
57
Dprintf
((
"Function2::Function2(in,in)"
));
58
}
59
60
double
Function2::Value
() {
61
AlgLoopDetector
_(
this
);
62
double
ret =
f
(
Input1Value
(),
Input2Value
());
63
return
ret;
64
}
65
66
#if 0
67
const
char
*
Function2::Name
()
const
{
68
if
(
HasName
())
return
_name;
69
else
return
SIMLIB_create_tmp_name
(
"Function2{%p}"
,
this
);
70
}
71
#endif
72
73
74
////////////////////////////////////////////////////////////////////////////
75
// SIMLIB local definitions:
76
//
77
78
static
double
sign
(
double
x)
79
{
80
if
(x == 0.0)
81
return
0.0;
82
if
(x > 0.0)
83
return
1.0;
84
else
85
return
-1.0;
86
}
87
88
89
////////////////////////////////////////////////////////////////////////////
90
// Implementation of block functions (prototypes are in simlib.h)
91
// using Fun(block expression) creates dynamic object/block, connects it
92
// to block expression, and returns reference to this block
93
94
Input
Abs
(
Input
x) {
return
new
Function1
(x, fabs); }
95
96
Input
Sin
(
Input
x) {
return
new
Function1
(x, sin); }
97
Input
Cos
(
Input
x) {
return
new
Function1
(x, cos); }
98
Input
Tan
(
Input
x) {
return
new
Function1
(x, tan); }
99
100
Input
ASin
(
Input
x) {
return
new
Function1
(x, asin); }
101
Input
ACos
(
Input
x) {
return
new
Function1
(x, acos); }
102
Input
ATan
(
Input
x) {
return
new
Function1
(x, atan); }
103
Input
ATan2
(
Input
y,
Input
x) {
return
new
Function2
(y, x, atan2); }
104
105
Input
Exp
(
Input
x) {
return
new
Function1
(x, exp); }
106
Input
Log10
(
Input
x) {
return
new
Function1
(x, log10); }
107
Input
Ln
(
Input
x) {
return
new
Function1
(x, log); }
108
Input
Pow
(
Input
x,
Input
y) {
return
new
Function2
(x, y, pow); }
109
110
Input
Sign
(
Input
x) {
return
new
Function1
(x,
sign
); }
111
112
Input
Sqrt
(
Input
x) {
return
new
Function1
(x, sqrt); }
113
114
Input
Min
(
Input
x,
Input
y) {
return
new
Function2
(x, y,
min
); }
115
Input
Max
(
Input
x,
Input
y) {
return
new
Function2
(x, y,
max
); }
116
117
118
}
// namespace
119
simlib3::AlgLoopDetector
class for algebraic loop detection AlgLoopDetector object should be used in Value() method only it ch...
Definition
internal.h:307
simlib3::Function1::Value
virtual double Value() override
Definition
fun.cc:39
simlib3::Function1::f
double(*) f(double)
Definition
simlib.h:1459
simlib3::Function1::Function1
Function1(const Function1 &)=delete
simlib3::Function2::Function2
Function2(const Function2 &)=delete
simlib3::Function2::Value
virtual double Value() override
Definition
fun.cc:60
simlib3::Function2::f
double(*) f(double, double)
Definition
simlib.h:1473
simlib3::Input
continuous block connection (transparent reference) wrapper for pointer to objects of aContiBlock der...
Definition
simlib.h:900
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::aContiBlock1::aContiBlock1
aContiBlock1(Input i)
constructor for blocks with single input
Definition
continuous.cc:61
simlib3::aContiBlock1::InputValue
double InputValue()
Definition
simlib.h:949
simlib3::aContiBlock2::Input2Value
double Input2Value()
Definition
simlib.h:970
simlib3::aContiBlock2::aContiBlock2
aContiBlock2(Input i1, Input i2)
ctr for blocks with 2 inputs
Definition
continuous.cc:79
simlib3::aContiBlock2::Input1Value
double Input1Value()
Definition
simlib.h:969
internal.h
Internal header file for SIMLIB/C++.
Dprintf
#define Dprintf(f)
Definition
internal.h:100
simlib3
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition
algloop.cc:32
simlib3::Cos
Input Cos(Input x)
Definition
fun.cc:97
simlib3::Max
Input Max(Input x, Input y)
Definition
fun.cc:115
simlib3::ATan
Input ATan(Input x)
Definition
fun.cc:102
simlib3::Min
Input Min(Input x, Input y)
Definition
fun.cc:114
simlib3::Sign
Input Sign(Input x)
Definition
fun.cc:110
simlib3::SIMLIB_IMPLEMENTATION
SIMLIB_IMPLEMENTATION
Definition
algloop.cc:34
simlib3::Abs
Input Abs(Input x)
Definition
fun.cc:94
simlib3::Ln
Input Ln(Input x)
Definition
fun.cc:107
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::sign
static double sign(double x)
Definition
fun.cc:78
simlib3::Exp
Input Exp(Input x)
Definition
fun.cc:105
simlib3::ATan2
Input ATan2(Input y, Input x)
Definition
fun.cc:103
simlib3::Tan
Input Tan(Input x)
Definition
fun.cc:98
simlib3::Pow
Input Pow(Input x, Input y)
Definition
fun.cc:108
simlib3::min
double min(double a, double b)
Definition
internal.h:285
simlib3::max
double max(double a, double b)
Definition
internal.h:286
simlib3::Log10
Input Log10(Input x)
Definition
fun.cc:106
simlib3::Sqrt
Input Sqrt(Input x)
Definition
fun.cc:112
simlib3::Sin
Input Sin(Input x)
Definition
fun.cc:96
simlib3::ASin
Input ASin(Input x)
Definition
fun.cc:100
simlib3::ACos
Input ACos(Input x)
Definition
fun.cc:101
simlib.h
Main SIMLIB/C++ interface.
Generated on
for SIMLIB/C++ by
1.18.0