DivisionTest
Division operation that divides a first input by a second input.
Performs a simple division operation where the output y = u1/u2, dividing the first input (u1
) by the second input (u2
). This component requires that the second input (denominator) is non-zero to avoid division by zero errors.
Usage
DivisionTest()
Behavior
Source
dyad
# Division operation that divides a first input by a second input.
#
# Performs a simple division operation where the output y = u1/u2, dividing the first input (`u1`)
# by the second input (`u2`). This component requires that the second input (denominator) is non-zero
# to avoid division by zero errors.
test component DivisionTest
# Constant block that outputs the value 3 (numerator)
c1 = Constant(k=3)
# Constant block that outputs the value 2 (denominator)
c2 = Constant(k=2)
# Division block that divides the first input (u1) by the second input (u2)
division = Division()
relations
# Connects the output of constant block c1 (3) to the numerator input of the division block
connect(division.u1, c1.y)
# Connects the output of constant block c2 (2) to the denominator input of the division block
connect(division.u2, c2.y)
metadata {
"Dyad": {"tests": {"case1": {"stop": 5, "expect": {"final": {"division.y": 1.5}}}}}
}
end
Flattened Source
dyad
# Division operation that divides a first input by a second input.
#
# Performs a simple division operation where the output y = u1/u2, dividing the first input (`u1`)
# by the second input (`u2`). This component requires that the second input (denominator) is non-zero
# to avoid division by zero errors.
test component DivisionTest
# Constant block that outputs the value 3 (numerator)
c1 = Constant(k=3)
# Constant block that outputs the value 2 (denominator)
c2 = Constant(k=2)
# Division block that divides the first input (u1) by the second input (u2)
division = Division()
relations
# Connects the output of constant block c1 (3) to the numerator input of the division block
connect(division.u1, c1.y)
# Connects the output of constant block c2 (2) to the denominator input of the division block
connect(division.u2, c2.y)
metadata {
"Dyad": {"tests": {"case1": {"stop": 5, "expect": {"final": {"division.y": 1.5}}}}}
}
end
Test Cases
This is setup code, that must be run before each test case.
julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames
snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/BlockComponents/77kIK/test/snapshots"
Test Case case1
julia
@mtkbuild model_case1 = DivisionTest()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 5))
sol_case1 = solve(prob_case1)
retcode: Success
Interpolation: 1st order linear
t: 2-element Vector{Float64}:
0.0
5.0
u: 2-element Vector{Vector{Float64}}:
[]
[]