Skip to content
ProductTest.md

ProductTest

Multiplies two constant values together.

This component takes two constant values (3 and 2) and multiplies them together using a Product block, resulting in an output value of 6. The component demonstrates the basic connection patterns for creating a multiplication operation between constant signals in the modeling language.

Usage

ProductTest()

Behavior

julia
using BlockComponents #hide
using ModelingToolkit #hide
@named sys = ProductTest() #hide
full_equations(sys) #hide
<< @example-block not executed in draft mode >>

Source

dyad
# Multiplies two constant values together.
#
# This component takes two constant values (3 and 2) and multiplies them together using a Product block,
# resulting in an output value of 6. The component demonstrates the basic connection patterns for creating
# a multiplication operation between constant signals in the modeling language.
test component ProductTest
  # Constant block that outputs the value 3
  c1 = Constant(k=3) [{
    "Dyad": {
      "placement": {"icon": {"iconName": "constant1", "x1": -50, "y1": 100, "x2": 50, "y2": 300}}
    }
  }]
  # Constant block that outputs the value 2
  c2 = Constant(k=2) [{
    "Dyad": {
      "placement": {"icon": {"iconName": "constant2", "x1": -50, "y1": 700, "x2": 50, "y2": 900}}
    }
  }]
  # Product block that multiplies its two inputs
  product = Product() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "product", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
    }
  }]
relations
  # Connects the output of constant c1 to the first input of the product block
  connect(product.u1, c1.y)
  # Connects the output of constant c2 to the second input of the product block
  connect(product.u2, c2.y)
metadata {
  "Dyad": {"tests": {"case1": {"stop": 5, "expect": {"final": {"product.y": 6}}}}}
}
end
Flattened Source
dyad
# Multiplies two constant values together.
#
# This component takes two constant values (3 and 2) and multiplies them together using a Product block,
# resulting in an output value of 6. The component demonstrates the basic connection patterns for creating
# a multiplication operation between constant signals in the modeling language.
test component ProductTest
  # Constant block that outputs the value 3
  c1 = Constant(k=3) [{
    "Dyad": {
      "placement": {"icon": {"iconName": "constant1", "x1": -50, "y1": 100, "x2": 50, "y2": 300}}
    }
  }]
  # Constant block that outputs the value 2
  c2 = Constant(k=2) [{
    "Dyad": {
      "placement": {"icon": {"iconName": "constant2", "x1": -50, "y1": 700, "x2": 50, "y2": 900}}
    }
  }]
  # Product block that multiplies its two inputs
  product = Product() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "product", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
    }
  }]
relations
  # Connects the output of constant c1 to the first input of the product block
  connect(product.u1, c1.y)
  # Connects the output of constant c2 to the second input of the product block
  connect(product.u2, c2.y)
metadata {
  "Dyad": {"tests": {"case1": {"stop": 5, "expect": {"final": {"product.y": 6}}}}}
}
end


Test Cases

julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames

snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
<< @setup-block not executed in draft mode >>

Test Case case1

julia
@mtkbuild model_case1 = ProductTest()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 5))
sol_case1 = solve(prob_case1)
<< @setup-block not executed in draft mode >>