@@ -1155,6 +1155,23 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
11551155 )
11561156 additive = pybamm .Scalar (0 )
11571157
1158+ elif extrap_order_value == "constant" :
1159+ # For constant extrapolation, use the first column value
1160+ row_indices = np .arange (0 , n_tb )
1161+ col_indices_0 = np .arange (0 , n_tb * n_lr , n_lr )
1162+ vals_0 = np .ones (n_tb )
1163+ sub_matrix = csr_matrix (
1164+ (
1165+ vals_0 ,
1166+ (
1167+ row_indices ,
1168+ col_indices_0 ,
1169+ ),
1170+ ),
1171+ shape = (n_tb , n_tb * n_lr ),
1172+ )
1173+ additive = pybamm .Scalar (0 )
1174+
11581175 elif extrap_order_value == "quadratic" :
11591176 if use_bcs and pybamm .has_bc_of_form (
11601177 child , symbol .side , bcs , "Neumann"
@@ -1234,6 +1251,24 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
12341251 shape = (n_tb , n_tb * n_lr ),
12351252 )
12361253 additive = pybamm .Scalar (0 )
1254+
1255+ elif extrap_order_value == "constant" :
1256+ # For constant extrapolation, use the last column value
1257+ row_indices = np .arange (0 , n_tb )
1258+ col_indices_N = np .arange (n_lr - 1 , n_lr * n_tb , n_lr )
1259+ vals_N = np .ones (n_tb )
1260+ sub_matrix = csr_matrix (
1261+ (
1262+ vals_N ,
1263+ (
1264+ row_indices ,
1265+ col_indices_N ,
1266+ ),
1267+ ),
1268+ shape = (n_tb , n_tb * n_lr ),
1269+ )
1270+ additive = pybamm .Scalar (0 )
1271+
12371272 elif extrap_order_value == "quadratic" :
12381273 if use_bcs and pybamm .has_bc_of_form (
12391274 child , symbol .side , bcs , "Neumann"
@@ -1359,7 +1394,16 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
13591394 raise NotImplementedError
13601395
13611396 elif side_first == "top" :
1362- if extrap_order_value == "linear" :
1397+ if extrap_order_value == "constant" :
1398+ first_val = np .ones (n_lr )
1399+ rows_first = np .arange (0 , n_lr )
1400+ cols_first = np .arange ((n_tb - 1 ) * n_lr , n_tb * n_lr )
1401+ sub_matrix = csr_matrix (
1402+ (first_val , (rows_first , cols_first )),
1403+ shape = (n_lr , n_lr * n_tb ),
1404+ )
1405+ additive = pybamm .Scalar (0 )
1406+ elif extrap_order_value == "linear" :
13631407 if use_bcs and pybamm .has_bc_of_form (
13641408 child , side_first , bcs , "Neumann"
13651409 ):
@@ -1452,6 +1496,26 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
14521496 shape = (1 , n_tb ),
14531497 )
14541498 sub_matrix = sub_matrix_second @ sub_matrix
1499+
1500+ elif extrap_order_value == "constant" :
1501+ # For constant extrapolation, use the bottom row value
1502+ # Select bottom row elements: 0, n_tb, 2*n_tb, ..., (n_lr-1)*n_tb
1503+ row_indices = [0 ]
1504+ col_indices = [0 ]
1505+ vals = [1 ]
1506+ sub_matrix_second = csr_matrix (
1507+ (
1508+ vals ,
1509+ (
1510+ row_indices ,
1511+ col_indices ,
1512+ ),
1513+ ),
1514+ shape = (1 , n_tb ),
1515+ )
1516+ additive = pybamm .Scalar (0 )
1517+ sub_matrix = sub_matrix_second @ sub_matrix
1518+
14551519 else :
14561520 dx0 = dx0_tb
14571521 dx1 = dx1_tb
@@ -1485,6 +1549,26 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
14851549 shape = (1 , n_tb ),
14861550 )
14871551 sub_matrix = sub_matrix_second @ sub_matrix
1552+
1553+ elif extrap_order_value == "constant" :
1554+ # For constant extrapolation, use the top row value
1555+ # Select top row elements: n_tb-1, 2*n_tb-1, 3*n_tb-1, ..., n_lr*n_tb-1
1556+ row_indices = [0 ]
1557+ col_indices = [n_tb - 1 ]
1558+ vals = [1 ]
1559+ sub_matrix_second = csr_matrix (
1560+ (
1561+ vals ,
1562+ (
1563+ row_indices ,
1564+ col_indices ,
1565+ ),
1566+ ),
1567+ shape = (1 , n_tb ),
1568+ )
1569+ additive = pybamm .Scalar (0 )
1570+ sub_matrix = sub_matrix_second @ sub_matrix
1571+
14881572 else :
14891573 dxN = dxN_tb
14901574 dxNm1 = dxNm1_tb
0 commit comments