Zero crossing detection
Zero crossing detection can be used to model piecewise functions in Engee.
This demonstration contains several blocks that generate zero crossing events, including the Abs block. The simulation results can accurately depict when the input signal has changed from positive to negative, as shown below.

Next, let's connect an auxiliary function to run the model.
function run_model( name_model)
Path = (@__DIR__) * "/" * name_model * ".engee"
if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
model = engee.open( name_model ) # Открыть модель
model_output = engee.run( model, verbose=true ); # Запустить модель
else
model = engee.load( Path, force=true ) # Загрузить модель
model_output = engee.run( model, verbose=true ); # Запустить модель
engee.close( name_model, force=true ); # Закрыть модель
end
sleep(5)
return model_output
end
run_model("zc_detection") # Запуск модели.
sine = collect(simout["zc_detection/sine"]);
out = collect(simout["zc_detection/out"]);
clock = collect(simout["zc_detection/clock"]);
For clarity, let's build two graphs, the first graph will contain the input sinusoid relative to the time signal that controls the switching between Saturate and Abs blocks, and the second graph will contain the output signal relative to the same time signal.
plot(clock.value, sine.value)
plot!(clock.value, out.value)
Conclusion
As we can see from the simulation results, the sinusoid is first fed to the output from the Abs port, and after half of the simulation time the Saturate output is used.