Commit 88d11dbc authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

WIP

parent 6c42f3cd
Pipeline #40936 failed with stage
in 1 minute and 12 seconds
......@@ -83,7 +83,7 @@ make install
== File format
Simple file
Simple simulation file `.irt`:
[source]
''''
......@@ -105,3 +105,37 @@ Simple file
1 0 2 1 # Model 'A' output port '0' connected to model 'Add' input port '0'
2 0 3 0 # Model 'Add' output port '0' connected to model 'C' input port '0'
''''
Component file `.irt`:
[source]
''''
2 # Number of constant source generator
0 10 1 2 3 4 5 6 7 8 9 10 # The first constant generator with id: 0 have ten values
1 5 0 0 1 1 2 # The second constant generator with id: 1 have five values
0 # Number of binary file source generator
1 # Number of text file source generator
0 "data/big-random-data.dat" # The only text file generator with id: 0 with a relative file (relative to the irt file).
1 # Number of random source generator
0 normal 0.5 0.1 # The only random source generator with id: 0 with a normal law and two parameters 0.5 and 0.1 for mean and standard deviation
3 # 4 models will be allocated
0 15.0 17.0 generator 2 0.0 100.0 0 # Model 0, in position x = 15.0 y = 17.0, is a generator with one double real message
1 12.0 5.0 component cpp qss1_lotka_volterra
2 -5.0 0.0 component file "qss1/lotka_volterra.irt"
2 # input ports
1 0 # first public input port of the cpp component
2 0 # first public input port of the file component
1 # output ports
1 0 # first public output port of the cpp component
1 # observable models
2 1 # second public observable port of the file component
1 # configurable models
2 1 0 1 2 3 4 5 6 7 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 # override second public configurable
# model of the file component with 8 integers
# and 8 reals
3 # 3 connections
0 0 2 0 #
1 0 2 1 #
2 0 3 0 #
''''
This diff is collapsed.
......@@ -32,7 +32,14 @@ struct component_ref;
struct modeling;
struct description;
status build_simulation(const modeling& mod, simulation& sim);
status add_cpp_component_ref(const char* buffer,
modeling& mod,
component& com) noexcept;
status add_cpp_component_ref(const char* buffer,
modeling& mod,
component& compo) noexcept;
status build_simulation(const modeling& mod, simulation& sim) noexcept;
struct description
{
......@@ -105,7 +112,27 @@ struct port
enum class component_type
{
cpp,
qss1_izhikevich,
qss1_lif,
qss1_lotka_volterra,
qss1_negative_lif,
qss1_seir_lineaire,
qss1_seir_nonlineaire,
qss1_van_der_pol,
qss2_izhikevich,
qss2_lif,
qss2_lotka_volterra,
qss2_negative_lif,
qss2_seir_lineaire,
qss2_seir_nonlineaire,
qss2_van_der_pol,
qss3_izhikevich,
qss3_lif,
qss3_lotka_volterra,
qss3_negative_lif,
qss3_seir_lineaire,
qss3_seir_nonlineaire,
qss3_van_der_pol,
file
};
......
......@@ -913,7 +913,108 @@ status modeling::fill_component() noexcept
return status::success;
}
status build_simulation(modeling& mod, simulation& sim)
static component* find_file_component(modeling& mod,
const char* file_path) noexcept
{
component* compo = nullptr;
while (mod.components.next(compo)) {
if ((compo->type == component_type::file) && compo->name == file_path)
return compo;
}
return nullptr;
}
static component* find_cpp_component(modeling& mod,
component_type type) noexcept
{
component* compo = nullptr;
while (mod.components.next(compo)) {
if (compo.type == type)
return compo;
}
irt_unreachable();
}
status add_cpp_component_ref(const char* file_path,
modeling& mod,
component& compo) noexcept
{
auto* file_compo = find_file_component(mod, file_path);
if (!file_compo)
return status::io_file_format_error;
irt_return_if_fail(mod.component_refs.can_alloc(),
status::io_file_format_error);
auto& compo_ref = mod.component_refs.alloc();
compo_ref.id = mod.components.get_id(*file_compo);
return status::success;
}
status add_cpp_component_ref(const char* buffer,
modeling& mod,
component& compo) noexcept
{
struct cpp_component_entry
{
const char* name;
component_type type;
};
static const cpp_component_entry tab[] = {
{ "qss1_izhikevich", component_type::qss1_izhikevich },
{ "qss1_lif", component_type::qss1_lif },
{ "qss1_lotka_volterra", component_type::qss1_lotka_volterra },
{ "qss1_negative_lif", component_type::qss1_negative_lif },
{ "qss1_seir_lineaire", component_type::qss1_seir_lineaire },
{ "qss1_seir_nonlineaire", component_type::qss1_seir_nonlineaire },
{ "qss1_van_der_pol", component_type::qss1_van_der_pol },
{ "qss2_izhikevich", component_type::qss2_izhikevich },
{ "qss2_lif", component_type::qss2_lif },
{ "qss2_lotka_volterra", component_type::qss2_lotka_volterra },
{ "qss2_negative_lif", component_type::qss2_negative_lif },
{ "qss2_seir_lineaire", component_type::qss2_seir_lineaire },
{ "qss2_seir_nonlineaire", component_type::qss2_seir_nonlineaire },
{ "qss2_van_der_pol", component_type::qss2_van_der_pol },
{ "qss3_izhikevich", component_type::qss3_izhikevich },
{ "qss3_lif", component_type::qss3_lif },
{ "qss3_lotka_volterra", component_type::qss3_lotka_volterra },
{ "qss3_negative_lif", component_type::qss3_negative_lif },
{ "qss3_seir_lineaire", component_type::qss3_seir_lineaire },
{ "qss3_seir_nonlineaire", component_type::qss3_seir_nonlineaire },
{ "qss3_van_der_pol", component_type::qss3_van_der_pol }
};
auto it = std::lower_bound(std::begin(tab),
std::end(tab),
buffer,
[](const auto& entry, const char* buffer) {
return 0 == std::strcmp(entry.name, buffer);
});
if (it == std::end(tab) || std::strcmp(it->name, buffer))
return status::io_file_format_error;
irt_return_if_fail(mod.component_refs.can_alloc(),
status::io_file_format_error);
irt_return_if_fail(compo.children.can_alloc(),
status::io_file_format_error);
auto* cpp_compo = find_cpp_component(mod, t->type);
auto& compo_ref = mod.component_refs.alloc();
compo_ref.id = mod.components.get_id(*cpp_compo);
// @todo compo_ref.tree.parent_to(*cpp_compo);
compo.children.emplace_back(ordinal(mod.component_refs.get_id(compo_ref)),
component_type::component);
return status::success;
}
status build_simulation(modeling& mod, simulation& sim) noexcept
{
if (auto* c_ref = mod.component_refs.try_to_get(mod.head); c_ref)
return build_models(mod, *c_ref, sim);
......
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