Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F67052201
function.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jun 19, 15:39
Size
4 KB
Mime Type
text/x-c
Expires
Fri, Jun 21, 15:39 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18323204
Attached To
rTAMAAS tamaas
function.cpp
View Options
/* -------------------------------------------------------------------------- */
#include "function.hh"
/* -------------------------------------------------------------------------- */
INTER_FUNC
::
INTER_FUNC
()
{}
/* ------------------------------------------------------------------------ */
INTER_FUNC
::~
INTER_FUNC
()
{}
/* ------------------------------------------------------------------------ */
INTER_FUNC
::
INTER_FUNC
(
INTER_FUNCTION_TYPE
type_
,
std
::
vector
<
Real
>
points_
,
Real
a_
)
{
type
=
type_
;
sm_error
=
false
;
points
.
resize
(
points_
.
size
());
for
(
int
i
=
0
;
i
<
int
(
points
.
size
());
i
++
)
points
[
i
]
=
points_
[
i
];
if
(
type
==
SQ_ROOT
)
{
if
(
points
.
size
()
!=
2
)
{
std
::
cout
<<
std
::
endl
<<
"ERROR 1a: something wrong with interpolation; coef[0] = "
<<
coef
[
0
]
<<
std
::
endl
;
exit
(
1
);
}
coef
.
resize
(
3
);
coef
[
2
]
=
a_
;
Real
y1_sq
=
points
[
0
]
*
points
[
0
],
y2_sq
=
points
[
1
]
*
points
[
1
],
c0
=
y2_sq
/
(
y1_sq
-
y2_sq
),
c1
=
(
2
+
c0
),
c2
=
(
1
-
coef
[
2
]
*
coef
[
2
]
+
0.75
*
c0
),
x01
=
0.5
*
(
c1
+
sqrt
(
c1
*
c1
-
4
*
c2
)),
x02
=
0.5
*
(
c1
-
sqrt
(
c1
*
c1
-
4
*
c2
));
if
(
y1_sq
<=
y2_sq
)
{
if
(
x01
>
0.75
&&
x02
<=
0.75
)
{
coef
[
0
]
=
sqrt
((
y1_sq
-
y2_sq
)
/
(
0.75
-
x01
));
coef
[
1
]
=
x01
;
}
else
if
(
x02
>
0.75
&&
x01
<=
0.75
)
{
coef
[
0
]
=
sqrt
((
y1_sq
-
y2_sq
)
/
(
0.75
-
x02
));
coef
[
1
]
=
x02
;
}
else
if
(
x01
>
0.75
&&
x02
<=
0.75
&&
a_
<=
0.5
)
{
coef
[
0
]
=
sqrt
((
y1_sq
-
y2_sq
)
/
(
0.75
-
x02
));
coef
[
1
]
=
x02
;
}
else
if
(
x02
>
0.75
&&
x01
<=
0.75
&&
a_
<=
0.5
)
{
coef
[
0
]
=
sqrt
((
y1_sq
-
y2_sq
)
/
(
0.75
-
x01
));
coef
[
1
]
=
x01
;
}
else
{
std
::
cout
<<
std
::
endl
<<
"ERROR 1b: something wrong with interpolation; coef[0] = "
<<
coef
[
0
]
<<
std
::
endl
;
exit
(
1
);
}
}
else
{
coef
[
0
]
=
0
;
coef
[
1
]
=
0
;
coef
[
2
]
=
0
;
sm_error
=
true
;
}
return
;
}
else
{
std
::
cout
<<
std
::
endl
<<
"ERROR 3: wrong constructor"
<<
std
::
endl
;
exit
(
1
);
}
}
/* ------------------------------------------------------------------------ */
INTER_FUNC
::
INTER_FUNC
(
INTER_FUNCTION_TYPE
type_
,
std
::
vector
<
Real
>
points_
)
{
type
=
type_
;
sm_error
=
false
;
points
.
resize
(
points_
.
size
());
for
(
int
i
=
0
;
i
<
int
(
points
.
size
());
i
++
)
points
[
i
]
=
points_
[
i
];
if
(
type
==
LINEAR
)
{
if
(
points
.
size
()
!=
2
)
{
std
::
cout
<<
"ERROR 21: Wrong initialization"
<<
std
::
endl
;
exit
(
1
);
}
coef
.
resize
(
2
);
coef
[
0
]
=
points
[
0
];
coef
[
1
]
=
points
[
1
]
-
points
[
0
];
return
;
}
else
if
(
type
==
PARABOLA
)
{
if
(
points
.
size
()
!=
3
)
{
std
::
cout
<<
"ERROR 22: Wrong initialization"
<<
std
::
endl
;
exit
(
1
);
}
coef
.
resize
(
3
);
coef
[
2
]
=
points
[
0
];
coef
[
1
]
=
4
*
points
[
1
]
-
3
*
points
[
0
]
-
points
[
2
];
coef
[
0
]
=
4
*
points
[
1
]
-
4
*
points
[
0
]
-
2
*
coef
[
1
];
return
;
}
else
if
(
type
!=
ZERO
)
{
std
::
cout
<<
std
::
endl
<<
"ERROR 4: wrong constructor"
<<
std
::
endl
;
exit
(
1
);
}
}
/* ------------------------------------------------------------------------ */
Real
INTER_FUNC
::
get_value
(
Real
x
)
{
if
(
type
==
ZERO
)
{
return
0.
;
}
else
if
(
type
==
LINEAR
)
{
return
coef
[
0
]
+
coef
[
1
]
*
x
;
}
else
if
(
type
==
SQ_ROOT
)
{
Real
a_sq
=
coef
[
2
]
*
coef
[
2
],
x_x0_sq
=
(
x
-
coef
[
1
])
*
(
x
-
coef
[
1
]);
if
(
a_sq
>
x_x0_sq
)
return
coef
[
0
]
*
sqrt
(
a_sq
-
x_x0_sq
);
else
return
0.
;
}
else
if
(
type
==
PARABOLA
)
{
return
coef
[
0
]
*
x
*
x
+
coef
[
1
]
*
x
+
coef
[
2
];
}
std
::
cout
<<
std
::
endl
<<
"ERROR 4.5: unknown interpolation type"
<<
std
::
endl
;
exit
(
1
);
return
0.
;
}
/* ------------------------------------------------------------------------ */
Real
INTER_FUNC
::
get_derivative
(
Real
x
)
{
if
(
type
==
ZERO
)
{
return
0.
;
}
else
if
(
type
==
LINEAR
)
{
return
coef
[
1
]
*
x
;
}
else
if
(
type
==
SQ_ROOT
)
{
Real
a_sq
=
coef
[
2
]
*
coef
[
2
],
x_x0_sq
=
(
x
-
coef
[
1
])
*
(
x
-
coef
[
1
]);
if
(
a_sq
>
x_x0_sq
)
return
coef
[
0
]
*
(
coef
[
1
]
-
x
)
/
sqrt
(
a_sq
-
x_x0_sq
);
else
return
0.
;
}
else
if
(
type
==
PARABOLA
)
{
return
2
*
coef
[
0
]
*
x
+
coef
[
1
];
}
std
::
cout
<<
std
::
endl
<<
"ERROR 3: something wrong with interpolation"
<<
std
::
endl
;
exit
(
1
);
}
Event Timeline
Log In to Comment