Commit 4ffe3c65 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: provides square and time function

parent b53f355c
Pipeline #11508 passed with stage
in 44 seconds
......@@ -97,7 +97,8 @@ run_simulation(simulation& sim,
do {
if (auto ret = sim.run(current); irt::is_bad(ret)) {
log_w.log(3, "Simulation run failure (%d)\n", static_cast<int>(ret));
log_w.log(
3, "Simulation run failure (%d)\n", static_cast<int>(ret));
st = simulation_status::internal_error;
return;
}
......@@ -692,9 +693,15 @@ struct editor
} break;
case dynamics_type::time_func: {
auto& dyn = sim.time_func_models.get(mdl.id);
// ImGui::PushItemWidth(120.0f);
// ImGui::InputDouble("threshold", &dyn.default_threshold);
// ImGui::PopItemWidth();
const char* items[] = { "time", "square" };
ImGui::PushItemWidth(120.0f);
int item_current = dyn.default_f == &time_function ? 0 : 1;
if (ImGui::Combo(
"function", &item_current, items, IM_ARRAYSIZE(items))) {
dyn.default_f =
item_current == 0 ? &time_function : square_time_function;
}
ImGui::PopItemWidth();
imnodes::BeginOutputAttribute(get_out(dyn.y[0]));
const float text_width = ImGui::CalcTextSize("out").x;
......@@ -761,7 +768,8 @@ struct editor
if (ImGui::MenuItem("Insert Izhikevitch model")) {
if (is_bad(initialize_izhikevitch()))
log_w.log(3, "Fail to initialize an Izhikevitch model\n");
log_w.log(3,
"Fail to initialize an Izhikevitch model\n");
}
ImGui::EndMenu();
......
......@@ -3275,13 +3275,25 @@ struct constant
}
};
inline double
square_time_function(double t) noexcept
{
return t * t;
}
inline double
time_function(double t) noexcept
{
return t;
}
struct time_func
{
model_id id;
output_port_id y[1];
time sigma;
double (*default_f)(double);
double (*default_f)(double) = &time_function;
double value;
double (*f)(double) = nullptr;
......
......@@ -357,11 +357,9 @@ private:
return false;
if (std::strcmp(fn, "square") == 0)
dyn.default_f = nullptr;
else if (std::strcmp(fn, "nullptr") == 0)
dyn.default_f = nullptr;
else
return false;
dyn.default_f = &square_time_function;
else
dyn.default_f = &time_function;
return true;
}
......@@ -434,10 +432,10 @@ struct writer
assert(it_in != map.end());
std::fprintf(file,
"%ld %d %ld %d\n",
std::distance(map.begin(), it_out),
"%d %d %d %d\n",
static_cast<int>(std::distance(map.begin(), it_out)),
src_index,
std::distance(map.begin(), it_in),
static_cast<int>(std::distance(map.begin(), it_in)),
dst_index);
}
}
......@@ -571,7 +569,7 @@ private:
{
std::fprintf(file,
"time_func %s\n",
dyn.default_f == nullptr ? "nullptr" : "square");
dyn.default_f == &time_function ? "time" : "square");
}
};
......
......@@ -11,12 +11,6 @@
#include <cstdio>
double
f(double t) noexcept
{
return t * t;
}
struct file_output
{
file_output(const char* file_path) noexcept
......@@ -915,7 +909,7 @@ main()
auto& time_fun = sim.time_func_models.alloc();
auto& cnt = sim.counter_models.alloc();
time_fun.default_f = &f;
time_fun.default_f = &irt::square_time_function;
expect(sim.models.can_alloc(2));
expect(irt::is_success(
......@@ -1058,9 +1052,7 @@ main()
expect(sim.integrator_models.can_alloc(2));
expect(sim.quantifier_models.can_alloc(2));
expect(sim.cross_models.can_alloc(2));
// expect(sim.time_func_models.can_alloc(1));
// auto& time_fun = sim.time_func_models.alloc();
auto& constant = sim.constant_models.alloc();
auto& constant2 = sim.constant_models.alloc();
auto& constant3 = sim.constant_models.alloc();
......
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