-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from ValentinKaisermayer/fix-der_T
Make thermal models ODEs again
- Loading branch information
Showing
12 changed files
with
300 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Heat Conduction Model | ||
|
||
This example demonstrates the thermal response of two masses connected by a conducting element. | ||
The two masses have the same heat capacity but different initial temperatures (T1=100 [°C], T2=0 [°C]). | ||
The mass with the higher temperature will cool off while the mass with the lower temperature heats up. | ||
They will each asymptotically approach the calculated temperature T_final_K that results | ||
from dividing the total initial energy in the system by the sum of the heat capacities of each element. | ||
|
||
```julia | ||
using ModelingToolkitStandardLibrary.Thermal, ModelingToolkit, OrdinaryDiffEq, Plots | ||
|
||
@parameters t | ||
|
||
C1 = 15 | ||
C2 = 15 | ||
@named mass1 = HeatCapacitor(C=C1, T_start=373.15) | ||
@named mass2 = HeatCapacitor(C=C2, T_start=273.15) | ||
@named conduction = ThermalConductor(G=10) | ||
@named Tsensor1 = TemperatureSensor() | ||
@named Tsensor2 = TemperatureSensor() | ||
|
||
connections = [ | ||
connect(mass1.port, conduction.port_a), | ||
connect(conduction.port_b, mass2.port), | ||
connect(mass1.port, Tsensor1.port), | ||
connect(mass2.port, Tsensor2.port), | ||
] | ||
|
||
@named model = ODESystem(connections, t, systems=[mass1, mass2, conduction, Tsensor1, Tsensor2]) | ||
sys = structural_simplify(model) | ||
prob = ODEProblem(sys, Pair[], (0, 5.0)) | ||
sol = solve(prob, Tsit5()) | ||
|
||
T_final_K = sol[(mass1.T * C1 + mass2.T * C2) / (C1 + C2)] | ||
|
||
plot(title = "Thermal Conduction Demonstration") | ||
plot!(sol, vars = [mass1.T, mass2.T], labels = ["Mass 1 Temperature" "Mass 2 Temperature"]) | ||
plot!(sol.t, T_final_K, label = "Steady-State Temperature") | ||
savefig("thermal_plot.png") | ||
``` | ||
![Plot of Temperatures](https://user-images.githubusercontent.com/50108075/173061172-4c7305f5-1193-4b17-9ca4-8f8dcbc0cae7.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.