% ------------------------------------------------------------------------ % % Problem: 2D steady-state conduction, discontinuous conducibility % % Domain: square [0,1] x [0,1] % % Grid: structured, cartesian, constant spacing, dx = dy % % Boundary conditions (BC): % Dirichet ( T = T_BC ) on the lower side ( y = 0 ) % Neumann ( Gamma * T_n = Jd_BC ) on the other sides % % Discretization method: Finite Volume (FV) % % Solution methodology: direct (sparse coefficient matrix) % % Date: 10/10/2024 % Author: R. Zamolo % % ------------------------------------------------------------------------ % % Domain, coordinates systems and boundary conditions: % % ^ y( j ) % | % | % | dT/dy=0 % 1 +---------------+ % | | % | | % T1 | | T2 % | | % | | % 0 +---------------+------> x( i ) % 0 dT/dy=0 1 % % Spatial indexing: T( i , j ) % i: index along x: i = 1 , ... , Ni % j: index along y: j = 1 , ... , Ni % % Linear indexing: T( k ) % k = i + (j-1) * Ni % % The number of unknowns is N = Ni * Ni % % k_max = i_max + (j_max-1) * Ni = % Ni + (Ni -1) * Ni = Ni * Ni = N % % ------------------------------------------------------------------------ % Properties GammaA = 10 ; GammaB = 1 ; T1 = 1 ; T2 = 0 ; % Domain square side length L = 2 ; % FV number for each dimension and FV total number Ni = 600 ; N = Ni * Ni ; % FV side length dx = L / Ni ; % FV 'volume' (surface) dA = dx * dx ; % FV centroids coordinates X = dx * ( (1:Ni) - 0.5 )' ; Y = X ; % FV equation: % A_P*T_P + A_E*T_E + A_W*T_W + A_N*T_N + A_S*T_S = S_P % % Final system, in compact (matrix) form: % A * T = S % % A: sparse coefficient matrix % T: solution vector % S: source term vector (RHS) % Diagonals for Gamma (discontinuous) D = ones( Ni , Ni ) ; D_Gamma = GammaA * D ; h = L/2 ; D_Gamma(X>h, Y