Skip to content

Commit

Permalink
Adding elements
Browse files Browse the repository at this point in the history
  • Loading branch information
wallytutor committed Oct 17, 2024
1 parent 1dc4c39 commit ca20fb4
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 1 deletion.
13 changes: 13 additions & 0 deletions data/bibtex/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -5562,4 +5562,17 @@ @Book{Warnatz2006
subtitle = {Physical and Chemical Fundamentals, Modeling and Simulation, Experiments, Pollutant Formation},
}

@Book{White2016,
author = {White, Frank M.},
publisher = {McGraw-Hill},
title = {Fluid mechanics},
year = {2016},
address = {New York, NY},
edition = {Eighth},
isbn = {9780073398273},
note = {Includes index and references},
pagetotal = {848},
ppn_gvk = {805546197},
}

@Comment{jabref-meta: databaseType:bibtex;}
146 changes: 146 additions & 0 deletions docs/src/Notebooks/Pluto/darcy-weisbach.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ begin
using WallyToolbox
using ModelingToolkit
using NonlinearSolve
using PlutoUI: TableOfContents
using Symbolics

TableOfContents()
end

# ╔═╡ 3f9fdb0e-caab-40df-99f8-cf0e5ec8deff
Expand Down Expand Up @@ -247,6 +251,143 @@ end
# ╔═╡ 8fcaed37-d179-449c-8d43-8d0ad9a6c35e
mdot_external / mdot_tot, mdot_cool / mdot_tot, mdot_tangential / mdot_tot

# ╔═╡ 6a6ad275-90d9-47d0-8b5e-a3d20efa9b0a
md"""
## Experimental
"""

# ╔═╡ db5fe5d7-e033-43ef-92d3-1dcbf3d64c17
begin
tuplefy(d) = NamedTuple{Tuple(keys(d))}(values(d))

########

struct UnsolvableAlgebraicModel <: Exception
msg::String

function UnsolvableAlgebraicModel(vars, pars)
return new(
"Unable to solve algebraic model containing [$(join(vars, ", "))] " *
"by providing only [$(join(pars, ", "))]! Please, revise the " *
"setup of the system!"
)
end
end

function Base.showerror(io::IO, err::UnsolvableAlgebraicModel)
print(io, "UnsolvableAlgebraicModel: ")
print(io, err.msg)
end

########

struct AlgebraicModel
vars::NamedTuple
eqns::Vector{Equation}
pars::Dict{Symbol, Float64}

function AlgebraicModel(vars, eqns, pars)
vars = Dict(map(v->(Symbol(v), v), vars))
return new(tuplefy(vars), eqns, pars)
end
end

function replacement_solve(obj::AlgebraicModel)
subs = map(v->(v, get(obj.pars, Symbol(v), v)), values(obj.vars))
eqns = substitute(obj.eqns, Dict(subs))
return eqns
end

function structural_solve(obj::AlgebraicModel)
eqns = replacement_solve(obj)

has_pars = length(obj.pars) > 0

if has_pars && length(obj.vars) - length(obj.pars) != length(eqns)
throw(UnsolvableAlgebraicModel(obj.vars, obj.pars))
end

@mtkbuild ns = NonlinearSystem(eqns, [values(obj.vars)...], [])
prob = NonlinearProblem(ns, [], [])
sol = solve(prob)

solved_for = map(e->e.lhs, observed(ns))

pars = tuplefy(obj.pars)
vars = NamedTuple(map(n->(Symbol(n), sol[n]), solved_for))
return merge(pars, vars)
end

########

function perfect_gas_constants(; pars...)
vars = @variables begin
k, [bounds = (1, Inf)]
R, [bounds = (0, Inf)]
cp, [bounds = (0, Inf)]
cv, [bounds = (0, Inf)]
end

eqns = [
0 ~ cp - k * cv,
0 ~ cv - R / (k - 1)
]

return AlgebraicModel(vars, eqns, pars)
end

function perfect_gas(; pars...)
model = perfect_gas_constants(;)

vars = @variables begin
p, [bounds = (0, Inf)]
ρ, [bounds = (0, Inf)]
T, [bounds = (0, Inf)]
h, [bounds = (0, Inf)]
s, [bounds = (0, Inf)]
end

R = model.vars.R
cp = model.vars.cp

vars = [vars..., values(model.vars)...]
eqns = [
0 ~ p - ρ * R * T,
0 ~ h - cp * T,
0 ~ s - cp * log(T) + R * log(p),
model.eqns...
]

return AlgebraicModel(vars, eqns, pars)
end
end

# ╔═╡ be031284-d872-4e1c-b43d-53038b21f8e4
let
model = perfect_gas_constants(; R=208, k=1.67)
solution = structural_solve(model)
end

# ╔═╡ 80dd3540-f5fb-4c2f-b6d5-b39ad599b8d5
let
R = 208.0
k = 1.67

model1 = perfect_gas(; R, k, p=1.70e+06, ρ=18.0)
model2 = perfect_gas(; R, k, p=2.48e+05, T=400.0)

sol1 = structural_solve(model1)
sol2 = structural_solve(model2)

Δh = sol2.h - sol1.h
Δs = sol2.s - sol1.s

Δh, Δs
end

# ╔═╡ 3e85af5c-7160-4b60-9369-dfa9dad34f7e


# ╔═╡ Cell order:
# ╟─3f9fdb0e-caab-40df-99f8-cf0e5ec8deff
# ╟─dcfd03a0-8b23-11ef-202f-0557552ecc92
Expand Down Expand Up @@ -275,3 +416,8 @@ mdot_external / mdot_tot, mdot_cool / mdot_tot, mdot_tangential / mdot_tot
# ╟─067d1351-7739-4d14-a5c7-203a4e86bb59
# ╟─3357de42-e48c-4e4d-a7df-58d916a1c9b5
# ╟─8fcaed37-d179-449c-8d43-8d0ad9a6c35e
# ╟─6a6ad275-90d9-47d0-8b5e-a3d20efa9b0a
# ╠═db5fe5d7-e033-43ef-92d3-1dcbf3d64c17
# ╠═be031284-d872-4e1c-b43d-53038b21f8e4
# ╠═80dd3540-f5fb-4c2f-b6d5-b39ad599b8d5
# ╠═3e85af5c-7160-4b60-9369-dfa9dad34f7e
6 changes: 6 additions & 0 deletions docs/src/References/@White2016.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "Fluid mechanics"
authors: Frank M. White
year: 2016
---

42 changes: 42 additions & 0 deletions docs/src/Science/01-Continuum-Mechanics.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,48 @@ In this expression the *big-D* notation represents a material or convective deri

### Compressible flow

This topic is discussed as treated in ([[@White2016]]) and based on [Pr. Dr. John Biddle's](https://www.cpp.edu/meonline/fluid-mechanics.shtml) course. The most important parameter in this case is the #Mach number, defined as the ratio of fluid velocity with respect to the velocity of sound in the medium. Increasing Mach number above certain levels introduces the phenomena of *choking* (duct flow rate sharply limited by sonic condition) and *shock waves* (nearly discontinuous property changes in supersonic flow).

- Compressible flows $Ma > 0.3$ (non-negligible density changes introduced)
- Continuity, momentum, energy, and state equations are coupled
- Simplification regimes: reversible adiabatic and isentropic flows

- External (aerodynamic) flow regions:
- $Ma<0.3$: incompressible flow
- $Ma\in[0.3; 0.8]$: subsonic flow
- $Ma\in[0.8; 1.2]$: transonic flow
- $Ma\in[1.2; 3.0]$: supersonic flow
- $Ma>3.0$: hypersonic flows

- Internal (duct) flow regions can be more simply be categorized as subsonic ($Ma<1$) and supersonic ($Ma\ge{}1$) flows.

- Specific heat ratio: generally between 1-1.7 for gases, slowly decreases with temperature; for air a value of 1.4 is generally employed in calculations.

- Ideal gas is generally used for elementary computations; ideal gas constant is used in what follows $\Lambda=8314{}J\cdotp{}kmol^{-1}\cdotp{}K^{-1}$.

$$
\begin{align*}
p &= \rho{}RT\\[12pt]
R &= c_p - c_v = \dfrac{\Lambda}{M}\\[12pt]
k &= \dfrac{c_p}{c_v}
\end{align*}
$$

- Using the above expressions and first and second laws of thermodynamics one shows the following; this expression can be used to compute the entropy change across a shock wave.

$$
s_2 - s_1 =
c_p\ln\dfrac{T_2}{T_1}-R\ln\dfrac{p_2}{p_1}=
c_v\ln\dfrac{T_2}{T_1}-R\ln\dfrac{\rho_2}{\rho_1}
$$

- For isentropic flows these expressions simplify to the following power-laws:

$$
\dfrac{p_2}{p_1}=
\left(\dfrac{T_2}{T_1}\right)^\dfrac{k}{k-1}=
\left(\dfrac{\rho_2}{\rho_1}\right)^k
$$


---
Expand Down
10 changes: 9 additions & 1 deletion docs/src/Science/02-Continuum-Mechanics.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,15 @@ which is a manifestation of fluctuation-dissipation theorem. This can be extende
![@video]()

---
## Biddle course
## Biddle course on fluid mechanics

### 026 Introduction to compressible flow

![@video](https://www.youtube.com/embed/ewoUwCVa3QY?si=9XWMLZl9VCPmPuFy)


---
## Biddle course on heat transfer

### 015 Introduction to radiation

Expand Down

0 comments on commit ca20fb4

Please sign in to comment.