Commit d152c2bb authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: add qss2 integrator

parent 2c2caa73
Pipeline #14778 passed with stage
in 53 seconds
...@@ -26,70 +26,6 @@ load_file_dialog(std::filesystem::path& out); ...@@ -26,70 +26,6 @@ load_file_dialog(std::filesystem::path& out);
bool bool
save_file_dialog(std::filesystem::path& out); save_file_dialog(std::filesystem::path& out);
static inline const char* simulation_status_string[] = {
"success",
"running",
"uninitialized",
"internal_error",
};
static inline const char* status_string[] = {
"success",
"unknown_dynamics",
"block_allocator_bad_capacity",
"block_allocator_not_enough_memory",
"head_allocator_bad_capacity",
"head_allocator_not_enough_memory",
"simulation_not_enough_model",
"simulation_not_enough_memory_message_list_allocator",
"simulation_not_enough_memory_input_port_list_allocator",
"simulation_not_enough_memory_output_port_list_allocator",
"data_array_init_capacity_error",
"data_array_not_enough_memory",
"data_array_archive_init_capacity_error",
"data_array_archive_not_enough_memory",
"array_init_capacity_zero",
"array_init_capacity_too_big",
"array_init_not_enough_memory",
"vector_init_capacity_zero",
"vector_init_capacity_too_big",
"vector_init_not_enough_memory",
"dynamics_unknown_id",
"dynamics_unknown_port_id",
"dynamics_not_enough_memory",
"model_connect_output_port_unknown",
"model_connect_input_port_unknown",
"model_connect_already_exist",
"model_connect_bad_dynamics",
"model_adder_empty_init_message",
"model_adder_bad_init_message",
"model_adder_bad_external_message",
"model_mult_empty_init_message",
"model_mult_bad_init_message",
"model_mult_bad_external_message",
"model_integrator_internal_error",
"model_integrator_output_error",
"model_integrator_running_without_x_dot",
"model_integrator_ta_with_bad_x_dot",
"model_integrator_bad_external_message",
"model_quantifier_bad_quantum_parameter",
"model_quantifier_bad_archive_length_parameter",
"model_quantifier_shifting_value_neg",
"model_quantifier_shifting_value_less_1",
"model_quantifier_bad_external_message",
"model_cross_bad_external_message",
"model_time_func_bad_init_message",
"model_accumulator_bad_external_message",
"gui_not_enough_memory",
"io_file_format_error",
"io_file_format_model_error",
"io_file_format_model_number_error",
"io_file_format_model_unknown",
"io_file_format_dynamics_unknown",
"io_file_format_dynamics_limit_reach",
"io_file_format_dynamics_init_error"
};
} // namespace irt } // namespace irt
#endif #endif
This diff is collapsed.
...@@ -18,6 +18,71 @@ ...@@ -18,6 +18,71 @@
namespace irt { namespace irt {
inline const char*
status_string(const status s) noexcept
{
static const char* str[] = {
"success",
"unknown_dynamics",
"block_allocator_bad_capacity",
"block_allocator_not_enough_memory",
"head_allocator_bad_capacity",
"head_allocator_not_enough_memory",
"simulation_not_enough_model",
"simulation_not_enough_memory_message_list_allocator",
"simulation_not_enough_memory_input_port_list_allocator",
"simulation_not_enough_memory_output_port_list_allocator",
"data_array_init_capacity_error",
"data_array_not_enough_memory",
"data_array_archive_init_capacity_error",
"data_array_archive_not_enough_memory",
"array_init_capacity_zero",
"array_init_capacity_too_big",
"array_init_not_enough_memory",
"vector_init_capacity_zero",
"vector_init_capacity_too_big",
"vector_init_not_enough_memory",
"dynamics_unknown_id",
"dynamics_unknown_port_id",
"dynamics_not_enough_memory",
"model_connect_output_port_unknown",
"model_connect_input_port_unknown",
"model_connect_already_exist",
"model_connect_bad_dynamics",
"model_adder_empty_init_message",
"model_adder_bad_init_message",
"model_adder_bad_external_message",
"model_mult_empty_init_message",
"model_mult_bad_init_message",
"model_mult_bad_external_message",
"model_integrator_dq_error",
"model_integrator_X_error",
"model_integrator_internal_error",
"model_integrator_output_error",
"model_integrator_running_without_x_dot",
"model_integrator_ta_with_bad_x_dot",
"model_integrator_bad_external_message",
"model_quantifier_bad_quantum_parameter",
"model_quantifier_bad_archive_length_parameter",
"model_quantifier_shifting_value_neg",
"model_quantifier_shifting_value_less_1",
"model_quantifier_bad_external_message",
"model_cross_bad_external_message",
"model_time_func_bad_init_message",
"model_accumulator_bad_external_message",
"gui_not_enough_memory",
"io_file_format_error",
"io_file_format_model_error",
"io_file_format_model_number_error",
"io_file_format_model_unknown",
"io_file_format_dynamics_unknown",
"io_file_format_dynamics_limit_reach",
"io_file_format_dynamics_init_error"
};
return str[static_cast<int>(s)];
}
template<class C> template<class C>
constexpr int constexpr int
length(const C& c) noexcept length(const C& c) noexcept
......
This diff is collapsed.
...@@ -92,78 +92,57 @@ private: ...@@ -92,78 +92,57 @@ private:
bool convert(const std::string_view dynamics_name, bool convert(const std::string_view dynamics_name,
dynamics_type* type) noexcept dynamics_type* type) noexcept
{ {
if (dynamics_name == "none") { struct string_to_type
*type = dynamics_type::none; {
return true; constexpr string_to_type(const std::string_view n,
} const dynamics_type t)
: name(n)
if (dynamics_name == "integrator") { , type(t)
*type = dynamics_type::integrator; {}
return true;
} const std::string_view name;
dynamics_type type;
if (dynamics_name == "quantifier") { };
*type = dynamics_type::quantifier;
return true; static constexpr string_to_type table[] = {
} { "accumulator_2", dynamics_type::accumulator_2 },
{ "adder_2", dynamics_type::adder_2 },
if (dynamics_name == "adder_2") { { "adder_3", dynamics_type::adder_3 },
*type = dynamics_type::adder_2; { "adder_4", dynamics_type::adder_4 },
return true; { "constant", dynamics_type::constant },
} { "counter", dynamics_type::counter },
{ "cross", dynamics_type::cross },
if (dynamics_name == "adder_3") { { "generator", dynamics_type::generator },
*type = dynamics_type::adder_3; { "integrator", dynamics_type::integrator },
return true; { "mult_2", dynamics_type::mult_2 },
} { "mult_3", dynamics_type::mult_3 },
{ "mult_4", dynamics_type::mult_4 },
if (dynamics_name == "adder_4") { { "none", dynamics_type::none },
*type = dynamics_type::adder_4; { "quantifier", dynamics_type::quantifier },
return true; { "qss1_integrator", dynamics_type::qss1_integrator },
} { "qss2_integrator", dynamics_type::qss2_integrator },
{ "qss2_multiplier", dynamics_type::qss2_multiplier },
if (dynamics_name == "mult_2") { { "qss2_sum_2", dynamics_type::qss2_sum_2 },
*type = dynamics_type::mult_2; { "qss2_sum_3", dynamics_type::qss2_sum_3 },
return true; { "qss2_sum_4", dynamics_type::qss2_sum_4 },
} { "qss2_wsum_2", dynamics_type::qss2_wsum_2 },
{ "qss2_wsum_3", dynamics_type::qss2_wsum_3 },
if (dynamics_name == "mult_3") { { "qss2_wsum_4", dynamics_type::qss2_wsum_4 },
*type = dynamics_type::mult_3; { "time_func", dynamics_type::time_func }
return true; };
}
static_assert(std::size(table) ==
if (dynamics_name == "mult_4") { static_cast<size_t>(dynamics_type::accumulator_2) + 1);
*type = dynamics_type::mult_4;
return true; const auto it =
} std::lower_bound(std::begin(table),
std::end(table),
if (dynamics_name == "counter") { dynamics_name,
*type = dynamics_type::counter; [](const string_to_type& l,
return true; const std::string_view r) { return l.name < r; });
}
if (it != std::end(table) && it->name == dynamics_name) {
if (dynamics_name == "generator") { *type = it->type;
*type = dynamics_type::generator;
return true;
}
if (dynamics_name == "constant") {
*type = dynamics_type::constant;
return true;
}
if (dynamics_name == "cross") {
*type = dynamics_type::cross;
return true;
}
if (dynamics_name == "accumulator_2") {
*type = dynamics_type::accumulator_2;
return true;
}
if (dynamics_name == "time_func") {
*type = dynamics_type::time_func;
return true; return true;
} }
...@@ -207,6 +186,69 @@ private: ...@@ -207,6 +186,69 @@ private:
return true; return true;
} }
bool read(qss1_integrator& dyn) noexcept
{
double& x1 = *(const_cast<double*>(&dyn.default_X));
double& x2 = *(const_cast<double*>(&dyn.default_dQ));
return !!(is >> x1 >> x2);
}
bool read(qss2_integrator& dyn) noexcept
{
double& x1 = *(const_cast<double*>(&dyn.default_X));
double& x2 = *(const_cast<double*>(&dyn.default_dQ));
return !!(is >> x1 >> x2);
}
bool read(qss2_multiplier& /*dyn*/) noexcept
{
return true;
}
bool read(qss2_sum_2& /*dyn*/) noexcept
{
return true;
}
bool read(qss2_sum_3& /*dyn*/) noexcept
{
return true;
}
bool read(qss2_sum_4& /*dyn*/) noexcept
{
return true;
}
bool read(qss2_wsum_2& dyn) noexcept
{
double& x1 = *(const_cast<double*>(&dyn.default_input_coeffs[0]));
double& x2 = *(const_cast<double*>(&dyn.default_input_coeffs[1]));
return !!(is >> x1 >> x2);
}
bool read(qss2_wsum_3& dyn) noexcept
{
double& x1 = *(const_cast<double*>(&dyn.default_input_coeffs[0]));
double& x2 = *(const_cast<double*>(&dyn.default_input_coeffs[1]));
double& x3 = *(const_cast<double*>(&dyn.default_input_coeffs[2]));
return !!(is >> x1 >> x2 >> x3);
}
bool read(qss2_wsum_4& dyn) noexcept
{
double& x1 = *(const_cast<double*>(&dyn.default_input_coeffs[0]));
double& x2 = *(const_cast<double*>(&dyn.default_input_coeffs[1]));
double& x3 = *(const_cast<double*>(&dyn.default_input_coeffs[2]));
double& x4 = *(const_cast<double*>(&dyn.default_input_coeffs[2]));
return !!(is >> x1 >> x2 >> x3 >> x4);
}
bool read(integrator& dyn) noexcept bool read(integrator& dyn) noexcept
{ {
return !!(is >> dyn.default_current_value >> dyn.default_reset_value); return !!(is >> dyn.default_current_value >> dyn.default_reset_value);
...@@ -394,6 +436,58 @@ private: ...@@ -394,6 +436,58 @@ private:
os << "none\n"; os << "none\n";
} }
void write(const qss1_integrator& dyn) noexcept
{
os << "qss1_integrator " << dyn.default_X << ' ' << dyn.default_dQ
<< '\n';
}
void write(const qss2_integrator& dyn) noexcept
{
os << "qss2_integrator " << dyn.default_X << ' ' << dyn.default_dQ
<< '\n';
}
void write(const qss2_multiplier& /*dyn*/) noexcept
{
os << "qss2_multiplier\n";
}
void write(const qss2_sum_2& /*dyn*/) noexcept
{
os << "qss2_sum_2\n";
}
void write(const qss2_sum_3& /*dyn*/) noexcept
{
os << "qss2_sum_3\n";
}
void write(const qss2_sum_4& /*dyn*/) noexcept
{
os << "qss2_sum_4\n";
}
void write(const qss2_wsum_2& dyn) noexcept
{
os << "qss2_wsum_2 " << dyn.default_input_coeffs[0] << ' '
<< dyn.default_input_coeffs[1] << '\n';
}
void write(const qss2_wsum_3& dyn) noexcept
{
os << "qss2_wsum_3 " << dyn.default_input_coeffs[0] << ' '
<< dyn.default_input_coeffs[1] << ' ' << dyn.default_input_coeffs[2]
<< '\n';
}
void write(const qss2_wsum_4& dyn) noexcept
{
os << "qss2_wsum_3 " << dyn.default_input_coeffs[0] << ' '
<< dyn.default_input_coeffs[1] << ' ' << dyn.default_input_coeffs[2]
<< ' ' << dyn.default_input_coeffs[3] << '\n';
}
void write(const integrator& dyn) noexcept void write(const integrator& dyn) noexcept
{ {
os << "integrator " << dyn.default_current_value << ' ' os << "integrator " << dyn.default_current_value << ' '
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment