for j in range(1, n): # time for e in range(1, i-1): # position T[e, j] = Tn_plus_1( T[e, j-1], timestep, rho_core[e], cp_core[e], re_nodes_core[e], rw_nodes_core[e], conduction_in( k_core[e-1], rw_nodes_core[e], T[e, j-1], T[e-1, j-1], r_nodes_core[e], r_nodes_core[e-1], ), conduction_out( k_core[e], re_nodes_core[e], T[e+1, j-1], T[e, j-1], r_nodes_core[e+1], r_nodes_core[e], ), fraction[j] * internal_gen( q_dens_values[e], timestep, rho_core[e], cp_core[e], ), )
(Note, I have re-typed the code in rather than copy paste - long story, hope it still works...).
Tn_plus_1 is a function to calculate the temperature of a node at the next timestep based on an energy balance and finite volume method. Conduction in, out, and internal generation are functions to calculate the heat transfer due to each mechanism into or out of a particular node. I set up for loops to iterate over time and position to determine the temperature evolution in each node for the duration of the analysis.
The issue is that the conduction out term does not apply correctly to node 7. I suspect the same issue is occurring with the conduction in term at the second node. The thought process behind the loop is that I want to calculate the temperatures of the internal nodes, and maintain the boundary condition on the two external nodes. Hence, I set the loop between 1 and i-1 (with 0 and i being the boundaries).
There are 9 position nodes in total (r, re, and rw each have 9 values). There are also 9 values for the material properties (rho, cp, k).
I'm new to Python and suspect the issue is to do me getting muddled up with Python indexing, but I don’t understand where exactly the loop is going wrong for the two nodes next to each boundary.Thanks in advance.
Result I get
Result I expect