# 1D Heat exchanger model with Dyad

**URL:** <https://discourse.julialang.org/t/1d-heat-exchanger-model-with-dyad/132009>\
**Category:** New to Julia\
**Tags:** question, dyad\
**Created:** [September 1, 2025, 10:46am UTC](https://discourse.julialang.org/t/1d-heat-exchanger-model-with-dyad/132009 "2025-09-01T10:46:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![junsin0106](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/junsin0106/32/218493_2.png) [@junsin0106](https://discourse.julialang.org/u/junsin0106)\
**Post date:** [September 1, 2025, 10:46am UTC](https://discourse.julialang.org/t/1d-heat-exchanger-model-with-dyad/132009/1 "2025-09-01T10:46:56Z")

</div>

Hello, I’m looking for examples of building a dynamic heat exchanger model in Dyad. I have seen some examples with `TwoPort` fluid models where `mdot` is the flow variable.

My goal is to create a custom connector that includes enthalpy flow rate (`Hdot`) as a variable. I understand this requires using the `inStream()` operator in the component equations to handle the direction of energy flow correctly.

Could anyone share a tutorial or example that demonstrates creating a connector with both flow and stream variables for a 1D thermal-fluid modeling? Is it possible to do this in Dyad, similar to the examples in Modelica? 🙂

---

<div class="post-metadata">

**Author:** ![avinash1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avinash1/32/35647_2.png) [@avinash1](https://discourse.julialang.org/u/avinash1)\
**Post date:** [September 1, 2025, 1:43pm UTC](https://discourse.julialang.org/t/1d-heat-exchanger-model-with-dyad/132009/2 "2025-09-01T13:43:38Z")

</div>

For the connector, you can use a `FluidPort` defined as below:

```julia-auto
connector FluidPort
 potential p::Pressure
 flow m_flow::MassFlowRate
 stream h_outflow::SpecificEnthalpy
end

```

Dyad (through the generated MTK code) already supports `instream`. You can create a `TwoPort` component with something along the lines of:

```julia-auto
component TwoPort
  port_a = FluidPort()
  port_b = FluidPort)
relations 
# Set relations for m_flow depending on case
  port_a.h_outflow = instream(port_b.h_outflow)
  port_b.h_outflow = instream(port_a.h_outflow)
end

```

You may be interested in Mike Tiller’s talk at JuliaCon 2025:

[![](https://global.discourse-cdn.com/julialang/original/3X/1/2/12fa5e10cf4cb7d9ce095a664bb75bccf424abe6.jpeg "JuliaCon Global 2025 | REPL Main Stage | Day 2") ](https://www.youtube.com/watch?v=Msm2qHsYZRg&t=21635)

---

<div class="post-metadata">

**Author:** ![junsin0106](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/junsin0106/32/218493_2.png) [@junsin0106](https://discourse.julialang.org/u/junsin0106)\
**Post date:** [September 1, 2025, 2:11pm UTC](https://discourse.julialang.org/t/1d-heat-exchanger-model-with-dyad/132009/3 "2025-09-01T14:11:21Z")

</div>

Thank you! I’ll watch the video and study more about acausal modeling. 🙂

---

<div class="post-metadata">

**Author:** ![avinash1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avinash1/32/35647_2.png) [@avinash1](https://discourse.julialang.org/u/avinash1)\
**Post date:** [September 1, 2025, 2:25pm UTC](https://discourse.julialang.org/t/1d-heat-exchanger-model-with-dyad/132009/4 "2025-09-01T14:25:06Z")

</div>

Sure, feel free to reach out. You may also be interested in: [GitHub - DyadLang/ThermalComponents: A library of thermal components for Dyad](https://github.com/DyadLang/ThermalComponents)

---

<div class="post-metadata">

**Author:** ![junsin0106](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/junsin0106/32/218493_2.png) [@junsin0106](https://discourse.julialang.org/u/junsin0106)\
**Post date:** [September 3, 2025, 12:00pm UTC](https://discourse.julialang.org/t/1d-heat-exchanger-model-with-dyad/132009/5 "2025-09-03T12:00:32Z")

</div>

Hello, I have an additional question that came up while trying a few things on my own.

In the video, my understanding was that (1) the `AbstractMedium` variable is first defined in Julia, and then (2) when configuring components like `Source` and `Valve` in Dyad, it interfaces with Julia to import and use that variable.

Similarly, I would like to create a symbolic function in Julia with the Helmholtz energy-based equation of state for R410a and then import it into Dyad.

Could I get a hint on how to import custom Julia variables or functions into Dyad? The Dyad documentation mentions using `Pkg` to import external libraries/functions, but I will only be using this for modeling purposes in my local environment.

[Edit] Maybe I can follow the explanations of ‘Modules’.

> **[Modules · The Julia Language](https://docs.julialang.org/en/v1/manual/modules/)**
>
> Documentation for The Julia Language.

---

<div class="post-metadata">

**Author:** ![avinash1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avinash1/32/35647_2.png) [@avinash1](https://discourse.julialang.org/u/avinash1)\
**Post date:** [September 3, 2025, 7:01pm UTC](https://discourse.julialang.org/t/1d-heat-exchanger-model-with-dyad/132009/6 "2025-09-03T19:01:08Z")

</div>

1. On `AbstractMedium`, yes. An example is:

putting the Julia definition here: [HydraulicComponents/src/HydraulicComponents.jl at 1e4c8900612b507b772e7249d348dfc0b52cb8f2 · DyadLang/HydraulicComponents · GitHub](https://github.com/DyadLang/HydraulicComponents/blob/1e4c8900612b507b772e7249d348dfc0b52cb8f2/src/HydraulicComponents.jl#L7)

marking it as native in Dyad here: [HydraulicComponents/dyad/abstract\_medium.dyad at main · DyadLang/HydraulicComponents · GitHub](https://github.com/DyadLang/HydraulicComponents/blob/main/dyad/abstract_medium.dyad)

1. The same repo has examples on using Julia functions:

e.g., you can define them here: [HydraulicComponents/src/isothermal\_compressible.jl at 1e4c8900612b507b772e7249d348dfc0b52cb8f2 · DyadLang/HydraulicComponents · GitHub](https://github.com/DyadLang/HydraulicComponents/blob/1e4c8900612b507b772e7249d348dfc0b52cb8f2/src/isothermal_compressible.jl#L28)

include the file in the `HydraulicComponents.jl` module/file and then the function is accessible inside Dyad. You may need to symbolically register them.

---

<div class="post-metadata">

**Author:** ![junsin0106](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/junsin0106/32/218493_2.png) [@junsin0106](https://discourse.julialang.org/u/junsin0106)\
**Post date:** [September 4, 2025, 1:41am UTC](https://discourse.julialang.org/t/1d-heat-exchanger-model-with-dyad/132009/7 "2025-09-04T01:41:20Z")

</div>

Thank you! I’ll give it a try 😀
