Implementing Convective and Stephan Boltzmann Radiative cooling of a 1D Rod using robin boundary condition. #1076
-
Hello, I am a bit confused as to how to create the robin boundary condition for radiative cooling. I had a read through https://www.ctcms.nist.gov/fipy/documentation/USAGE.html and #1007 Let's say we have this equation: -k∇Tn = h(T-Tinf) + ϵσ[T⁴-Tinf⁴] Therefore, based on my understanding, this would resolve to: However, I am unsure what the best way is to add the information from T⁴ into the boundary equation. I was thinking of implementing it like this: from fipy import CellVariable, FaceVariable, Grid1D, DiffusionTerm, TransientTerm, GeneralSolver, ImplicitSourceTerm
from fipy.tools import numerix
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('TkAgg')
# 1. Define the domain and discretization
L = 2.0e-6 # Length of the bar in meters (2 µm)
nx = 100 # Number of cells/grid points
dx = L / nx # Size of each cell
# 2. Initialize the mesh
mesh = Grid1D(nx=nx, dx=dx)
mask = mesh.facesLeft | mesh.facesRight
k0 = 100.0
k = FaceVariable(name="thermal conductivity", mesh=mesh, value=k0)
k.setValue(0., where=mask)
# 4. Create and initialize the temperature variable
Temperature = CellVariable(name="Temperature", mesh=mesh, value=400.0, hasOld=True) # Initial value is 400K
TInfinite = 300.0
hTopSurface = 10.0
gold_emissivity = 0.3
Stephan_Boltzmann_constant = 5.67e-8 #W/(m^2*K^4)
MA = numerix.MA
tmp = MA.repeat(mesh._faceCenters[..., numerix.NewAxis, :], 2, 1)
cellToFaceDistanceVectors = tmp - numerix.take(mesh._cellCenters, mesh.faceCellIDs, axis=1)
tmp = numerix.take(mesh._cellCenters, mesh.faceCellIDs, axis=1)
tmp = tmp[..., 1, :] - tmp[..., 0, :]
cellDistanceVectors = MA.filled(MA.where(MA.getmaskarray(tmp), cellToFaceDistanceVectors[:, 0], tmp))
dPf = FaceVariable(mesh=mesh, value = mesh._faceToCellDistanceRatio * cellDistanceVectors)
n = mesh.faceNormals
a = FaceVariable(mesh=mesh, value=hTopSurface*n, rank=1)
b = FaceVariable(mesh=mesh, value=k0, rank=0)
Stephan_Boltzmann_Radiation = gold_emissivity*Stephan_Boltzmann_constant*(numerix.power(TInfinite,4) - numerix.power(Temperature[-1],4))
g = FaceVariable(mesh=mesh, value=hTopSurface*TInfinite + Stephan_Boltzmann_Radiation, rank=0)
RobinCoeff = mask * k0 * n / (dPf.dot(a) + b)
eq = DiffusionTerm(coeff=k, var=Temperature) + (RobinCoeff * g).divergence - ImplicitSourceTerm(coeff=(RobinCoeff * a.dot(n)).divergence, var=Temperature) == 1000 * TransientTerm(var=Temperature)
dt =1.00e-8
for sweep in range(10000): # Sweep through simulation
plt.show(block=False)
plt.pause(0.01)
print(g)
#Every 10 sweeps plot
if sweep % 10 == 0:
plt.clf()
plt.plot(mesh.cellCenters[0], Temperature.value)
plt.legend(["Fipy", "Analytical"])
plt.xlabel('Position (m)')
plt.ylabel('Temperature (K)')
plt.title('Temperature Distribution in the Bar')
plt.grid(True)
plt.show(block=False)
plt.pause(0.01)
residual = eq.sweep(dt = dt, solver=GeneralSolver(iterations=10))
if sweep % 20 == 0:
dt = dt + 5.00e-8
Temperature.updateOld() However, the FaceVariable g never updates, even though the temperature is constantly changing due to convection... Cheers, Tristan |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
diff --git a/discussion1076.py b/discussion1076.py
index c0b5879..ba04e61 100644
--- a/discussion1076.py
+++ b/discussion1076.py
@@ -41,9 +41,9 @@ n = mesh.faceNormals
a = FaceVariable(mesh=mesh, value=hTopSurface*n, rank=1)
b = FaceVariable(mesh=mesh, value=k0, rank=0)
-Stephan_Boltzmann_Radiation = gold_emissivity*Stephan_Boltzmann_constant*(numerix.power(TInfinite,4) - numerix.power(Temperature[-1],4))
+Stephan_Boltzmann_Radiation = gold_emissivity*Stephan_Boltzmann_constant*(TInfinite**4 - Temperature.faceValue**4)
-g = FaceVariable(mesh=mesh, value=hTopSurface*TInfinite + Stephan_Boltzmann_Radiation, rank=0)
+g = (hTopSurface*TInfinite + Stephan_Boltzmann_Radiation) * mask
RobinCoeff = mask * k0 * n / (dPf.dot(a) + b)
eq = DiffusionTerm(coeff=k, var=Temperature) + (RobinCoeff * g).divergence - ImplicitSourceTerm(coeff=(RobinCoeff * a.dot(n)).divergence, var=Temperature) == 1000 * TransientTerm(var=Temperature) Note: there's nothing intrinsically wrong with |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
g = FaceVariable(mesh=mesh, value=hTopSurface*TInfinite + Stephan_Boltzmann_Radiation, rank=0)
declares aFaceVariable
with the instantaneous value (at time of definition) ofhTopSurface*TInfinite + Stephan_Boltzmann_Radiation
.g = (hTopSurface*TInfinite + Stephan_Boltzmann_Radiation) * mask
declares a variable expression with the valuehTopSurface*TInfinite + Stephan_Boltzmann_Radiation
that updates whenever its constituents update.Temperature[-1]
is the last value in theTemperature
array, but you should not assume that corresponds to t…