@@ -463,6 +463,37 @@ def plot_intensity(
463463
464464 return fig , ax
465465
466+ def eval_error_estimator (self ):
467+ # facet jump
468+ fbasis = [InteriorFacetBasis (self .basis .mesh , self .basis .elem , side = i ) for i in [0 , 1 ]]
469+ fbasis_epsilon = [
470+ InteriorFacetBasis (
471+ self .basis .mesh , self .basis_epsilon_r .elem , side = i , quadrature = fbasis [0 ].quadrature
472+ )
473+ for i in [0 , 1 ]
474+ ]
475+ w = {f"u{ str (i + 1 )} " : fbasis [i ].interpolate (self .E ) for i in [0 , 1 ]}
476+ w2 = {f"epsilon{ str (i + 1 )} " : fbasis_epsilon [i ].interpolate (self .epsilon_r ) for i in [0 , 1 ]}
477+
478+ # norm_0 = np.linalg.norm(w["u1"][0]*w2["epsilon1"])
479+ # norm_1 = np.linalg.norm(grad(w["u1"][1]))*10
480+ norm_0 = norm_1 = 1
481+
482+ @Functional
483+ def edge_jump (w ):
484+ return w .h * (
485+ np .abs (dot (grad (w ["u1" ][1 ]) - grad (w ["u2" ][1 ]), w .n )) ** 2 / norm_1 ** 2
486+ + np .abs (dot (w ["u1" ][0 ] * w ["epsilon1" ][0 ] - w ["u2" ][0 ] * w ["epsilon2" ][0 ], w .n ))
487+ ** 2
488+ / norm_0 ** 2
489+ )
490+
491+ tmp = np .zeros (self .basis .mesh .facets .shape [1 ])
492+ tmp [fbasis [0 ].find ] = edge_jump .elemental (fbasis [0 ], ** w , ** w2 )
493+ eta_E = np .sum (0.5 * tmp [self .basis .mesh .t2f ], axis = 0 )
494+
495+ return eta_E
496+
466497
467498@dataclass (frozen = True )
468499class Modes :
@@ -800,44 +831,6 @@ def plot_mode(basis, mode, plot_vectors=False, colorbar=True, title="E", directi
800831 return fig , axs
801832
802833
803- def eval_error_estimator (basis , u , epsilon ):
804- # @Functional
805- # def interior_residual(w):
806- # h = w.h
807- # x, y = w.x
808- # return h**2 # * load_func(x, y) ** 2
809-
810- # eta_K = interior_residual.elemental(basis, w=basis.interpolate(u))
811-
812- # facet jump
813- fbasis = [InteriorFacetBasis (basis .mesh , basis .elem , side = i ) for i in [0 , 1 ]]
814- fbasis_epsilon = [
815- InteriorFacetBasis (basis .mesh , ElementTriP0 (), side = i , quadrature = fbasis [0 ].quadrature )
816- for i in [0 , 1 ]
817- ]
818- w = {f"u{ str (i + 1 )} " : fbasis [i ].interpolate (u ) for i in [0 , 1 ]}
819- w2 = {f"epsilon{ str (i + 1 )} " : fbasis_epsilon [i ].interpolate (epsilon ) for i in [0 , 1 ]}
820-
821- # norm_0 = np.linalg.norm(w["u1"][0]*w2["epsilon1"])
822- # norm_1 = np.linalg.norm(grad(w["u1"][1]))*10
823- norm_0 = norm_1 = 1
824-
825- @Functional
826- def edge_jump (w ):
827- return w .h * (
828- np .abs (dot (grad (w ["u1" ][1 ]) - grad (w ["u2" ][1 ]), w .n )) ** 2 / norm_1 ** 2
829- + np .abs (dot (w ["u1" ][0 ] * w ["epsilon1" ][0 ] - w ["u2" ][0 ] * w ["epsilon2" ][0 ], w .n )) ** 2
830- / norm_0 ** 2
831- )
832-
833- tmp = np .zeros (basis .mesh .facets .shape [1 ])
834- tmp [fbasis [0 ].find ] = edge_jump .elemental (fbasis [0 ], ** w , ** w2 )
835- eta_E = np .sum (0.5 * tmp [basis .mesh .t2f ], axis = 0 )
836-
837- return eta_E
838- # return eta_K + eta_E
839-
840-
841834if __name__ == "__main__" :
842835 from collections import OrderedDict
843836
0 commit comments