Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .JuliaFormatter.toml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: format-check

on:
push:
branches:
- 'master'
- 'main'
- 'release-'
tags: '*'
pull_request:

jobs:
runic:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: fredrikekre/runic-action@v1
with:
version: '1'
92 changes: 54 additions & 38 deletions src/HeatExchange/Jacket.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
@component function Jacket(; substances_user,
@component function Jacket(;
substances_user,
Nc = length(substances_user),
phase,
thermal_fluid_model,
heat_transfer_coef,
name
)
)
properties = Dict(subs => load_component_properties(subs) for subs in substances_user)
MWs = [properties[subs]["MW"] for subs in substances_user]

Expand Down Expand Up @@ -36,57 +37,72 @@

entropy_eq = [S ~ 0.0]

densities_eq = [ρ ~ molar_density(
thermal_fluid_model, P_out, Tⱼ, Out.z₁, phase = "unknown")
ρʷ ~
mass_density(thermal_fluid_model, P_out, Tⱼ, Out.z₁, phase = "unknown")]
densities_eq = [
ρ ~ molar_density(
thermal_fluid_model, P_out, Tⱼ, Out.z₁, phase = "unknown"
)
ρʷ ~
mass_density(thermal_fluid_model, P_out, Tⱼ, Out.z₁, phase = "unknown")
]

pressure_drop = [P_out ~ In.P]

mass_balance = [In.Fʷ - Fʷ_out ~ 0.0
Q_out ~ Fʷ_out/ρʷ
Q_out ~ F_out/ρ]
mass_balance = [
In.Fʷ - Fʷ_out ~ 0.0
Q_out ~ Fʷ_out / ρʷ
Q_out ~ F_out / ρ
]

lmtd = [LMTD ~ log((EnergyCon.T - In.T)/(EnergyCon.T - Tⱼ))]
lmtd = [LMTD ~ log((EnergyCon.T - In.T) / (EnergyCon.T - Tⱼ))]

heat_flux = [Q̇ ~ U*EnergyCon.A*(In.T - Tⱼ)/LMTD]
heat_flux = [Q̇ ~ U * EnergyCon.A * (In.T - Tⱼ) / LMTD]

energy_balance = [In.H*In.F - H*F_out - Q̇ ~ 0.0] # Quasi steady state assumption (Temperature change is much faster than reactor change)
energy_balance = [In.H * In.F - H * F_out - Q̇ ~ 0.0] # Quasi steady state assumption (Temperature change is much faster than reactor change)

#Outlet connector equations:
out_conn = [Out.P ~ P_out
Out.T ~ Tⱼ
Out.F ~ F_out
Out.Fʷ ~ Fʷ_out
Out.H ~ H
Out.S ~ S
Out.ρʷ ~ ρʷ
Out.ρ ~ ρ
scalarize(Out.z₁ .~ In.z₁)...
Out.MW[1] ~ MWs
EnergyCon.ϕᴱ ~ Q̇]
out_conn = [
Out.P ~ P_out
Out.T ~ Tⱼ
Out.F ~ F_out
Out.Fʷ ~ Fʷ_out
Out.H ~ H
Out.S ~ S
Out.ρʷ ~ ρʷ
Out.ρ ~ ρ
scalarize(Out.z₁ .~ In.z₁)...
Out.MW[1] ~ MWs
EnergyCon.ϕᴱ ~ Q̇
]

if phase == :liquid
out_conn_phases = [scalarize(Out.z₂ .~ 0.0)...
scalarize(Out.z₃ .~ In.z₁)...
Out.MW[2] ~ 0.0
Out.MW[3] ~ MWs
Out.α_g ~ 0.0]
out_conn_phases = [
scalarize(Out.z₂ .~ 0.0)...
scalarize(Out.z₃ .~ In.z₁)...
Out.MW[2] ~ 0.0
Out.MW[3] ~ MWs
Out.α_g ~ 0.0
]

elseif phase == :vapor
out_conn_phases = [scalarize(Out.z₂ .~ In.z₁)...
scalarize(Out.z₃ .~ 0.0)...
Out.MW[2] ~ MWs
Out.MW[3] ~ 0.0
Out.α_g ~ 1.0]
out_conn_phases = [
scalarize(Out.z₂ .~ In.z₁)...
scalarize(Out.z₃ .~ 0.0)...
Out.MW[2] ~ MWs
Out.MW[3] ~ 0.0
Out.α_g ~ 1.0
]
end

eqs = [enthalpy_eq...; entropy_eq...; densities_eq...; pressure_drop...;
mass_balance...; lmtd...; heat_flux...; energy_balance...; out_conn...;
out_conn_phases...]
eqs = [
enthalpy_eq...; entropy_eq...; densities_eq...; pressure_drop...;
mass_balance...; lmtd...; heat_flux...; energy_balance...; out_conn...;
out_conn_phases...
]

ODESystem([eqs...;], t, collect(Iterators.flatten(vars)),
collect(Iterators.flatten(pars)); name, systems = [Out, In, EnergyCon])
ODESystem(
[eqs...;], t, collect(Iterators.flatten(vars)),
collect(Iterators.flatten(pars)); name, systems = [Out, In, EnergyCon]
)
end

export Jacket
120 changes: 69 additions & 51 deletions src/Reactors/CSTR.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@component function CSTR(; substances_user,
@component function CSTR(;
substances_user,
Nc = length(substances_user),
phase,
model,
Expand All @@ -7,7 +8,7 @@
height_out_port,
name,
guesses
)
)

#Constants
gramsToKilograms = 10^(-3)
Expand All @@ -17,17 +18,17 @@
#Properties of individual substances
properties = Dict(subs => load_component_properties(subs) for subs in substances_user)
MWs = [properties[subs]["MW"] for subs in substances_user]
ΔH₀f = [properties[subs]["IGHF"]/10^3 for subs in substances_user] # (IG formation enthalpy) J/mol
ΔH₀f = [properties[subs]["IGHF"] / 10^3 for subs in substances_user] # (IG formation enthalpy) J/mol

pars = @parameters begin
Af_r[1:Nri] = Reaction.Af_r,
[description = "Arrhenius constant of each reaction at given temperature ()"]
[description = "Arrhenius constant of each reaction at given temperature ()"]
Coef_Cr[1:Nri, 1:Nc] = Reaction.Coef_Cr,
[description = "Stoichiometric coefficients of each component in each reaction (-)"]
[description = "Stoichiometric coefficients of each component in each reaction (-)"]
Do_r[1:Nri, 1:Nc] = Reaction.Do_r,
[description = "Forward order of the components (-) "]
[description = "Forward order of the components (-) "]
Ef_r[1:Nri] = Reaction.Ef_r,
[description = "Activation energy of each reaction at given temperature ()"]
[description = "Activation energy of each reaction at given temperature ()"]
A = Ac, [description = "Cross sectional area of the tank (m²)"]
end

Expand All @@ -43,8 +44,10 @@
V(t), [description = "Volume holdup in the tank (m³)", guess = guesses[:V]]
(Nᵢ(t))[1:Nc], [description = "Molar holdup of each component in the tank (mol)"]
(Cᵢ(t))[1:Nc],
[description = "Concentration of each component in the tank (mol/m³)",
guess = guesses[:Cᵢ]]
[
description = "Concentration of each component in the tank (mol/m³)",
guess = guesses[:Cᵢ],
]

ρ(t), [description = "Molar Density of the fluid in the tank (mol/m³)"]
ρʷ(t), [description = "Mass Density of the fluid in the tank (kg/m³)"]
Expand All @@ -55,14 +58,14 @@

F_out(t), [description = "Outlet molar flow rate (mol/s)", guess = guesses[:F_out]]
Fʷ_out(t),
[description = "Outlet molar flow rate (mol/s)", guess = guesses[:Fʷ_out]]
[description = "Outlet molar flow rate (mol/s)", guess = guesses[:Fʷ_out]]
Q_out(t), [description = "Outlet volumetric flow rate (m³/s)"] # DoF

Q̇(t), [description = "Heat transfer rate (J/s)"] # Potential DoF
height(t),
[description = "Liquid level in vessel measured from bottom of the tank (m)"]
[description = "Liquid level in vessel measured from bottom of the tank (m)"]
P_out(t),
[description = "Pressure at the outlet stream level (Pa)", guess = 101325.0]
[description = "Pressure at the outlet stream level (Pa)", guess = 101325.0]

(r(t))[1:Nri], [description = "Rate of each reaction for each component (mol/s/m³)"]
(R(t))[1:Nc], [description = "Overall reaction rate (mol/s/m³)"]
Expand All @@ -75,9 +78,11 @@
end

#Reaction equations
reaction_rate = [r[i] ~
Af_r[i]*exp(-Ef_r[i]/(Rᵍ*T))*prod(scalarize((Cᵢ[:] .^ Do_r[i, :])))
for i in 1:Nri] # If there's an inert, the order is just zero, but it has to be written
reaction_rate = [
r[i] ~
Af_r[i] * exp(-Ef_r[i] / (Rᵍ * T)) * prod(scalarize((Cᵢ[:] .^ Do_r[i, :])))
for i in 1:Nri
] # If there's an inert, the order is just zero, but it has to be written
overall_reaction_rate = [R[i] ~ sum(scalarize(r[:] .* Coef_Cr[:, i])) for i in 1:Nc] # If there's an inert, the coefficient is just zero, but it has to be written

#Inlet connector variables's equations
Expand All @@ -87,57 +92,70 @@
inletmolarflow_eqs = [F_in ~ In.F]

#Outlet connector equations:
out_conn = [Out.P ~ P_out
Out.T ~ T
Out.F ~ F_out
Out.H ~ H/N
scalarize(Out.z₁ .~ Nᵢ/N)...]
out_conn = [
Out.P ~ P_out
Out.T ~ T
Out.F ~ F_out
Out.H ~ H / N
scalarize(Out.z₁ .~ Nᵢ / N)...
]

if phase == :liquid
out_conn_phases = [scalarize(Out.z₂ .~ 0.0)...
scalarize(Out.z₃ .~ Nᵢ/N)...
Out.α_g ~ 0.0]
out_conn_phases = [
scalarize(Out.z₂ .~ 0.0)...
scalarize(Out.z₃ .~ Nᵢ / N)...
Out.α_g ~ 0.0
]

elseif phase == :vapor
out_conn_phases = [scalarize(Out.z₂ .~ Nᵢ/N)...
scalarize(Out.z₃ .~ 0.0)...
Out.α_g ~ 1.0]
out_conn_phases = [
scalarize(Out.z₂ .~ Nᵢ / N)...
scalarize(Out.z₃ .~ 0.0)...
Out.α_g ~ 1.0
]
end

#balances

component_balance = [D(Nᵢ[i]) ~ F_in*In.z₁[i] - F_out*Nᵢ[i]/N + R[i]*V for i in 1:Nc] #Neglectable loss to vapor phase head space
energy_balance = [D(H) ~ F_in*h_in - F_out*H/N + Q̇]
jacket_energy_balance = [Q̇ ~
-2.27*4184.0*(T - 288.7)*(1.0 - exp(-8440.26/(2.27*4184)))]
mass_volume_eq = [ρʷ*V ~ M, ρ*V ~ N]
component_balance = [D(Nᵢ[i]) ~ F_in * In.z₁[i] - F_out * Nᵢ[i] / N + R[i] * V for i in 1:Nc] #Neglectable loss to vapor phase head space
energy_balance = [D(H) ~ F_in * h_in - F_out * H / N + Q̇]
jacket_energy_balance = [
Q̇ ~
-2.27 * 4184.0 * (T - 288.7) * (1.0 - exp(-8440.26 / (2.27 * 4184))),
]
mass_volume_eq = [ρʷ * V ~ M, ρ * V ~ N]
mol_holdup = [N ~ sum(collect(Nᵢ))]
mol_to_concentration = [scalarize(Nᵢ .~ Cᵢ*V)...]
height_to_volume = [height*A ~ V]
volumetricflow_to_molarflow = [Q_out ~ F_out/ρ, F_out ~ F_in]
volumetricflow_to_massflow = [Q_out ~ Fʷ_out/ρʷ]
mol_to_concentration = [scalarize(Nᵢ .~ Cᵢ * V)...]
height_to_volume = [height * A ~ V]
volumetricflow_to_molarflow = [Q_out ~ F_out / ρ, F_out ~ F_in]
volumetricflow_to_massflow = [Q_out ~ Fʷ_out / ρʷ]

#Thermodynamic properties (outlet)
pressure_out = [phase == :liquid ? P_out ~ P_atm : P_out ~ P_atm] # Estimation considering static pressure (May be off as tank is agitated and not static)
density_eqs = [ρ ~ molar_density(model, P_out, T, Nᵢ, phase = "unknown")]
mass_density = [ρʷ ~ ρ*MW]
mass_density = [ρʷ ~ ρ * MW]
globalEnthalpy_eq = [
H ~ enthalpy(model, P_out, T, Nᵢ, phase = "unknown") + sum(scalarize(ΔH₀f .* Nᵢ)),
fᵢ ~ fugacity_coefficient(model, P_out, T, Nᵢ, phase = "liquid")[1]] #fᵢ ~ fugacity_coefficient(model, P_out, T, Nᵢ, "liquid")[1]
molar_mass = [MW ~ sum(scalarize(MWs .* Nᵢ))/N*gramsToKilograms]

eqs = [reaction_rate...; overall_reaction_rate...; atm_pressure...; inletenthalpy...;
inlettemperature_eqs...; inletmolarflow_eqs...; out_conn...;
out_conn_phases...; component_balance...; energy_balance...;
jacket_energy_balance...; mass_volume_eq...; mol_holdup...;
mol_to_concentration...;
height_to_volume...; volumetricflow_to_molarflow...;
volumetricflow_to_massflow...;
pressure_out...; density_eqs...; mass_density...; globalEnthalpy_eq...;
molar_mass...]

ODESystem([eqs...;], t, collect(Iterators.flatten(vars)),
collect(Iterators.flatten(pars)); name, systems = [Ports...])
fᵢ ~ fugacity_coefficient(model, P_out, T, Nᵢ, phase = "liquid")[1],
] #fᵢ ~ fugacity_coefficient(model, P_out, T, Nᵢ, "liquid")[1]
molar_mass = [MW ~ sum(scalarize(MWs .* Nᵢ)) / N * gramsToKilograms]

eqs = [
reaction_rate...; overall_reaction_rate...; atm_pressure...; inletenthalpy...;
inlettemperature_eqs...; inletmolarflow_eqs...; out_conn...;
out_conn_phases...; component_balance...; energy_balance...;
jacket_energy_balance...; mass_volume_eq...; mol_holdup...;
mol_to_concentration...;
height_to_volume...; volumetricflow_to_molarflow...;
volumetricflow_to_massflow...;
pressure_out...; density_eqs...; mass_density...; globalEnthalpy_eq...;
molar_mass...
]

ODESystem(
[eqs...;], t, collect(Iterators.flatten(vars)),
collect(Iterators.flatten(pars)); name, systems = [Ports...]
)
end

export CSTR
6 changes: 4 additions & 2 deletions src/Reactors/ReactionManager/KineticReaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ end
# Construtor para aceitar palavras-chave
function KineticReactionNetwork(;
Coef_Cr::Union{Vector{T}, Matrix{T}}, Do_r::Union{Vector{T}, Matrix{T}},
substances_user::Vector{String}, Af_r::T, Ef_r::T, name::String) where {T}
substances_user::Vector{String}, Af_r::T, Ef_r::T, name::String
) where {T}
Nc = length(substances_user)
Nri = Coef_Cr isa Matrix ? size(Coef_Cr, 1) : length(Coef_Cr)

return KineticReactionNetwork{T}(
Coef_Cr, Do_r, substances_user, Nc, Nri, Af_r, Ef_r, name)
Coef_Cr, Do_r, substances_user, Nc, Nri, Af_r, Ef_r, name
)
end

export KineticReactionNetwork
Loading
Loading