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 ​

BlockComponents.ProductTest()

Behavior ​

julia
using BlockComponents #hide
using ModelingToolkit #hide
@named sys = BlockComponents.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": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 340, "x2": 420, "y2": 440, "rot": 0}
      }
    }
  }
  "Constant block that outputs the value 2"
  c2 = Constant(k = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 550, "x2": 420, "y2": 650, "rot": 0}
      }
    }
  }
  "Product block that multiplies its two inputs"
  product = Product() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "product", "x1": 950, "y1": 450, "x2": 1050, "y2": 550, "rot": 0},
        "diagram": {"iconName": "product", "x1": 580, "y1": 450, "x2": 680, "y2": 550, "rot": 0}
      }
    }
  }
relations
  connect(c1.y, product.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 390}, {"x": 500, "y": 470}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(product.u2, c2.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 530}, {"x": 500, "y": 600}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "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": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 340, "x2": 420, "y2": 440, "rot": 0}
      }
    }
  }
  "Constant block that outputs the value 2"
  c2 = Constant(k = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 550, "x2": 420, "y2": 650, "rot": 0}
      }
    }
  }
  "Product block that multiplies its two inputs"
  product = Product() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "product", "x1": 950, "y1": 450, "x2": 1050, "y2": 550, "rot": 0},
        "diagram": {"iconName": "product", "x1": 580, "y1": 450, "x2": 680, "y2": 550, "rot": 0}
      }
    }
  }
relations
  connect(c1.y, product.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 390}, {"x": 500, "y": 470}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(product.u2, c2.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 530}, {"x": 500, "y": 600}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {"case1": {"stop": 5, "expect": {"final": {"product.y": 6}}}}
  }
}
end


Test Cases ​

julia
using BlockComponents
using DyadInterface: TransientAnalysis, rebuild_sol
using ModelingToolkit: toggle_namespacing, get_defaults, @named
using CSV, DataFrames, Plots

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

Test Case case1 ​

julia
@named model_case1 = ProductTest()
model_case1 = toggle_namespacing(model_case1, false)

model_case1 = toggle_namespacing(model_case1, true)
result_case1 = TransientAnalysis(; model = model_case1, alg = "auto", start = 0e+0, stop = 5e+0, abstol=1e-6, reltol=1e-6)
sol_case1 = rebuild_sol(result_case1)
<< @setup-block not executed in draft mode >>