@@ -36,7 +36,7 @@ def __init__(self, mesh):
36
36
super ().__init__ (mesh )
37
37
38
38
# there is no way to set this at the moment
39
- self .extrapolation = " quadratic"
39
+ self .options = { "extrapolation" : { "order" : " quadratic", "use bcs" : True }}
40
40
41
41
# add npts_for_broadcast to mesh domains for this particular discretisation
42
42
for dom in mesh .keys ():
@@ -611,13 +611,23 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
611
611
612
612
child = symbol .child
613
613
614
- if symbol .side == "left" :
614
+ extrap_order = self .options ["extrapolation" ]["order" ]
615
+ use_bcs = self .options ["extrapolation" ]["use bcs" ]
615
616
616
- if self .extrapolation == "linear" :
617
+ if use_bcs and pybamm .has_bc_condition_of_form (
618
+ child , symbol .side , bcs , "Dirichlet"
619
+ ):
620
+ # just use the value from the bc: f(x*)
621
+ sub_matrix = csr_matrix ((1 , prim_pts ))
622
+ additive = bcs [child .id ][symbol .side ][0 ]
623
+
624
+ elif symbol .side == "left" :
625
+
626
+ if extrap_order == "linear" :
617
627
# to find value at x* use formula:
618
628
# f(x*) = f_1 - (dx0 / dx1) (f_2 - f_1)
619
629
620
- if pybamm .has_bc_condition_of_form (
630
+ if use_bcs and pybamm .has_bc_condition_of_form (
621
631
child , symbol .side , bcs , "Neumann"
622
632
):
623
633
sub_matrix = csr_matrix (([1 ], ([0 ], [0 ])), shape = (1 , prim_pts ),)
@@ -631,9 +641,9 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
631
641
)
632
642
additive = pybamm .Scalar (0 )
633
643
634
- elif self . extrapolation == "quadratic" :
644
+ elif extrap_order == "quadratic" :
635
645
636
- if pybamm .has_bc_condition_of_form (
646
+ if use_bcs and pybamm .has_bc_condition_of_form (
637
647
child , symbol .side , bcs , "Neumann"
638
648
):
639
649
a = (dx0 + dx1 ) ** 2 / (dx1 * (2 * dx0 + dx1 ))
@@ -660,9 +670,9 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
660
670
661
671
elif symbol .side == "right" :
662
672
663
- if self . extrapolation == "linear" :
673
+ if extrap_order == "linear" :
664
674
665
- if pybamm .has_bc_condition_of_form (
675
+ if use_bcs and pybamm .has_bc_condition_of_form (
666
676
child , symbol .side , bcs , "Neumann"
667
677
):
668
678
# use formula:
@@ -672,13 +682,6 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
672
682
)
673
683
additive = dxN * bcs [child .id ][symbol .side ][0 ]
674
684
675
- elif pybamm .has_bc_condition_of_form (
676
- child , symbol .side , bcs , "Dirichlet"
677
- ):
678
- # just use the value from the bc: f(x*)
679
- sub_matrix = csr_matrix ((1 , prim_pts ))
680
- additive = bcs [child .id ][symbol .side ][0 ]
681
-
682
685
else :
683
686
# to find value at x* use formula:
684
687
# f(x*) = f_N - (dxN / dxNm1) (f_N - f_Nm1)
@@ -690,9 +693,9 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
690
693
shape = (1 , prim_pts ),
691
694
)
692
695
additive = pybamm .Scalar (0 )
693
- elif self . extrapolation == "quadratic" :
696
+ elif extrap_order == "quadratic" :
694
697
695
- if pybamm .has_bc_condition_of_form (
698
+ if use_bcs and pybamm .has_bc_condition_of_form (
696
699
child , symbol .side , bcs , "Neumann"
697
700
):
698
701
a = (dxN + dxNm1 ) ** 2 / (dxNm1 * (2 * dxN + dxNm1 ))
@@ -726,24 +729,24 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
726
729
raise NotImplementedError
727
730
728
731
elif isinstance (symbol , pybamm .BoundaryGradient ):
729
- if symbol .side == "left" :
730
732
731
- if self .extrapolation == "linear" :
733
+ if use_bcs and pybamm .has_bc_condition_of_form (
734
+ child , symbol .side , bcs , "Neumann"
735
+ ):
736
+ # just use the value from the bc: f'(x*)
737
+ sub_matrix = csr_matrix ((1 , prim_pts ))
738
+ additive = bcs [child .id ][symbol .side ][0 ]
732
739
733
- if pybamm .has_bc_condition_of_form (
734
- child , symbol .side , bcs , "Neumann"
735
- ):
736
- # just use the value from the bc: f'(x*)
737
- sub_matrix = csr_matrix ((1 , prim_pts ))
738
- additive = bcs [child .id ][symbol .side ][0 ]
739
- else :
740
- # use formula:
741
- # f'(x*) = (f_2 - f_1) / dx1
742
- sub_matrix = (1 / dx1 ) * csr_matrix (
743
- ([- 1 , 1 ], ([0 , 0 ], [0 , 1 ])), shape = (1 , prim_pts )
744
- )
745
- additive = pybamm .Scalar (0 )
746
- elif self .extrapolation == "quadratic" :
740
+ elif symbol .side == "left" :
741
+
742
+ if extrap_order == "linear" :
743
+ # f'(x*) = (f_2 - f_1) / dx1
744
+ sub_matrix = (1 / dx1 ) * csr_matrix (
745
+ ([- 1 , 1 ], ([0 , 0 ], [0 , 1 ])), shape = (1 , prim_pts )
746
+ )
747
+ additive = pybamm .Scalar (0 )
748
+
749
+ elif extrap_order == "quadratic" :
747
750
748
751
a = - (2 * dx0 + 2 * dx1 + dx2 ) / (dx1 ** 2 + dx1 * dx2 )
749
752
b = (2 * dx0 + dx1 + dx2 ) / (dx1 * dx2 )
@@ -759,20 +762,13 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
759
762
elif symbol .side == "right" :
760
763
761
764
if self .extrapolation == "linear" :
762
- if pybamm .has_bc_condition_of_form (
763
- child , symbol .side , bcs , "Neumann"
764
- ):
765
- # just use the value from the bc: f'(x*)
766
- sub_matrix = csr_matrix ((1 , prim_pts ))
767
- additive = bcs [child .id ][symbol .side ][0 ]
768
- else :
769
- # use formula:
770
- # f'(x*) = (f_N - f_Nm1) / dxNm1
771
- sub_matrix = (1 / dxNm1 ) * csr_matrix (
772
- ([- 1 , 1 ], ([0 , 0 ], [prim_pts - 2 , prim_pts - 1 ])),
773
- shape = (1 , prim_pts ),
774
- )
775
- additive = pybamm .Scalar (0 )
765
+ # use formula:
766
+ # f'(x*) = (f_N - f_Nm1) / dxNm1
767
+ sub_matrix = (1 / dxNm1 ) * csr_matrix (
768
+ ([- 1 , 1 ], ([0 , 0 ], [prim_pts - 2 , prim_pts - 1 ])),
769
+ shape = (1 , prim_pts ),
770
+ )
771
+ additive = pybamm .Scalar (0 )
776
772
777
773
elif self .extrapolation == "quadratic" :
778
774
a = (2 * dxN + 2 * dxNm1 + dxNm2 ) / (dxNm1 ** 2 + dxNm1 * dxNm2 )
@@ -787,6 +783,7 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
787
783
shape = (1 , prim_pts ),
788
784
)
789
785
additive = pybamm .Scalar (0 )
786
+
790
787
else :
791
788
raise NotImplementedError
792
789
0 commit comments