Biorbd
Release_1.13.0
Toggle main menu visibility
Loading...
Searching...
No Matches
FatigueState.cpp
1
#define BIORBD_API_EXPORTS
2
#include "InternalForces/Muscles/FatigueState.h"
3
4
#include <cmath>
5
6
#include "Utils/Error.h"
7
8
#if defined(_WIN32) || defined(_WIN64)
9
#include <sstream>
10
namespace
std {
11
template
<
typename
T>
12
std::string to_string(
const
T& n) {
13
std::ostringstream stm;
14
stm << n;
15
return
stm.str();
16
}
17
}
// namespace std
18
#endif
19
20
using namespace
BIORBD_NAMESPACE;
21
22
internal_forces::muscles::FatigueState::FatigueState
(
23
const
utils::Scalar& active,
24
const
utils::Scalar& fatigued,
25
const
utils::Scalar& resting)
26
:
m_activeFibers
(std::make_shared<utils::Scalar>(active)),
27
m_fatiguedFibers
(std::make_shared<utils::Scalar>(fatigued)),
28
m_restingFibers
(std::make_shared<utils::Scalar>(resting)),
29
m_type
(std::make_shared<internal_forces::muscles::STATE_FATIGUE_TYPE>()) {
30
setType
();
31
}
32
33
internal_forces::muscles::FatigueState::FatigueState
(
34
const
internal_forces::muscles::FatigueState
& other)
35
:
m_activeFibers
(other.
m_activeFibers
),
36
m_fatiguedFibers
(other.
m_fatiguedFibers
),
37
m_restingFibers
(other.
m_restingFibers
),
38
m_type
(other.
m_type
) {}
39
40
internal_forces::muscles::FatigueState::FatigueState
(
41
const
std::shared_ptr<FatigueState> other)
42
:
m_activeFibers
(other->
m_activeFibers
),
43
m_fatiguedFibers
(other->
m_fatiguedFibers
),
44
m_restingFibers
(other->
m_restingFibers
),
45
m_type
(other->
m_type
) {}
46
47
internal_forces::muscles::FatigueState::~FatigueState
() {}
48
49
internal_forces::muscles::FatigueState
50
internal_forces::muscles::FatigueState::DeepCopy
()
const
{
51
internal_forces::muscles::FatigueState
copy;
52
copy.
DeepCopy
(*
this
);
53
return
copy;
54
}
55
56
void
internal_forces::muscles::FatigueState::DeepCopy
(
57
const
internal_forces::muscles::FatigueState
& other) {
58
*
m_activeFibers
= *other.
m_activeFibers
;
59
*
m_fatiguedFibers
= *other.
m_fatiguedFibers
;
60
*
m_restingFibers
= *other.
m_restingFibers
;
61
*
m_type
= *other.
m_type
;
62
}
63
64
#ifndef BIORBD_USE_CASADI_MATH
65
void
internal_forces::muscles::FatigueState::setState
(
66
utils::Scalar active,
67
utils::Scalar fatigued,
68
utils::Scalar resting,
69
bool
turnOffWarnings) {
70
// Sanity check for active fibers
71
//
72
// In order to get the quantity of active fibers to 0 or 1, it has to come
73
// from the input command. The input command manage fiber recruitment from
74
// resting to active. Hence any exceeding because of integration can be
75
// corrected by putting back exceeding active fibers quantity into resting
76
// fibers quantity.
77
//
78
if
(active < 0) {
79
if
(!turnOffWarnings) {
80
utils::Error::warning
(
81
0,
82
"Active Fibers Quantity can't be lower than 0, 0 is used then\n"
83
"Previous Active Fibers Quantity before set to 0:"
+
84
std::to_string(active));
85
}
86
resting += active;
87
active = 0;
88
}
else
if
(active > 1) {
89
if
(!turnOffWarnings) {
90
utils::Error::warning
(
91
0,
92
"Active Fibers Quantity can't be higher than 1, 1 is used then\n"
93
"Previous Active Fibers Quantity before set to 1: "
+
94
std::to_string(active));
95
}
96
resting += active - 1;
97
98
active = 1;
99
}
100
101
// Sanity check for fatigued fibers
102
if
(fatigued < 0) {
103
utils::Error::raise
(
"Fatigued Fibers Quantity can't be lower than 0"
);
104
}
else
if
(fatigued > 1) {
105
utils::Error::raise
(
"Fatigued Fibers Quantity can't be higher than 1"
);
106
}
107
108
// Sanity check for resting fibers
109
//
110
// In order to get the quantity of resting fibers to 0, it has to come from
111
// the input command. The input command manage fiber recruitment from resting
112
// to active. Hence any exceeding because of integration can be corrected by
113
// putting back exceeding resting fibers quantity into active fibers quantity.
114
//
115
if
(resting < 0) {
116
if
(!turnOffWarnings) {
117
utils::Error::warning
(
118
0,
119
"Resting Fibers Quantity can't be lower than 0, 0 is used then\n"
120
"Previous Resting Fibers Quantity before set to 0: "
+
121
std::to_string(resting));
122
}
123
active += resting;
124
resting = 0;
125
}
else
if
(resting > 1) {
126
utils::Error::raise
(
"Resting Fibers Quantity can't be higher than 1"
);
127
}
128
129
if
(fabs(active + fatigued + resting - 1.0) > 0.1) {
130
utils::Error::raise
(
"Sum of the fatigued states must be equal to 1"
);
131
}
132
133
*
m_activeFibers
= active;
134
*
m_fatiguedFibers
= fatigued;
135
*
m_restingFibers
= resting;
136
}
137
#endif
138
139
const
utils::Scalar&
internal_forces::muscles::FatigueState::activeFibers
()
140
const
{
141
return
*
m_activeFibers
;
142
}
143
144
const
utils::Scalar&
internal_forces::muscles::FatigueState::fatiguedFibers
()
145
const
{
146
return
*
m_fatiguedFibers
;
147
}
148
149
const
utils::Scalar&
internal_forces::muscles::FatigueState::restingFibers
()
150
const
{
151
return
*
m_restingFibers
;
152
}
153
154
internal_forces::muscles::STATE_FATIGUE_TYPE
155
internal_forces::muscles::FatigueState::getType
()
const
{
156
return
*
m_type
;
157
}
158
159
void
internal_forces::muscles::FatigueState::setType
() {
160
*
m_type
= internal_forces::muscles::STATE_FATIGUE_TYPE::SIMPLE_STATE_FATIGUE;
161
}
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState
Base class for Fatigue states models.
Definition
FatigueState.h:18
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::getType
STATE_FATIGUE_TYPE getType() const
Return the type of muscle fatigue model.
Definition
FatigueState.cpp:155
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::DeepCopy
FatigueState DeepCopy() const
Deep copy of the fatigue state.
Definition
FatigueState.cpp:50
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::m_type
std::shared_ptr< STATE_FATIGUE_TYPE > m_type
Type of the muscle fatigue model.
Definition
FatigueState.h:112
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::m_fatiguedFibers
std::shared_ptr< utils::Scalar > m_fatiguedFibers
Proportion of fatigued muscle fibers.
Definition
FatigueState.h:103
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::fatiguedFibers
const utils::Scalar & fatiguedFibers() const
Return the propotion of fatigued muscle fibers.
Definition
FatigueState.cpp:144
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::m_activeFibers
std::shared_ptr< utils::Scalar > m_activeFibers
Proportion of active muscle fibers.
Definition
FatigueState.h:101
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::setType
virtual void setType()
Set the type.
Definition
FatigueState.cpp:159
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::~FatigueState
virtual ~FatigueState()
Destroy class properly.
Definition
FatigueState.cpp:47
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::setState
virtual void setState(utils::Scalar active, utils::Scalar fatigued, utils::Scalar resting, bool turnOffWarnings=false)
Safe set of the state (ensure that sum of all activation is 1).
Definition
FatigueState.cpp:65
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::activeFibers
const utils::Scalar & activeFibers() const
Return the propotion of active muscle fibers.
Definition
FatigueState.cpp:139
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::restingFibers
const utils::Scalar & restingFibers() const
Return the propotion of resting muscle fibers.
Definition
FatigueState.cpp:149
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::m_restingFibers
std::shared_ptr< utils::Scalar > m_restingFibers
Proportion of resting muscle fibers.
Definition
FatigueState.h:105
BIORBD_NAMESPACE::internal_forces::muscles::FatigueState::FatigueState
FatigueState(const utils::Scalar &active=1, const utils::Scalar &fatigued=0, const utils::Scalar &resting=0)
Construct fatigue state.
Definition
FatigueState.cpp:22
BIORBD_NAMESPACE::utils::Error::raise
static void raise(const String &message)
Throw an error message.
Definition
Error.cpp:6
BIORBD_NAMESPACE::utils::Error::warning
static void warning(bool cond, const String &message)
Non-blocking assert that displays the error message if false.
Definition
Error.cpp:16
src
InternalForces
Muscles
FatigueState.cpp
Generated by
1.18.0