@@ -898,34 +898,7 @@ def create_formulation(self):
898898 if bc .enforce_weakly :
899899 u = bc .species .solution
900900 v = bc .species .test_function
901- n = ufl .FacetNormal (self .mesh .mesh )
902- h = ufl .Circumradius (
903- self .mesh .mesh
904- ) # FIXME this doesn't work for rectangles
905- alpha = bc .penalty
906- assert alpha is not None , (
907- "Penalty parameter must be given for weakly enforced Dirichlet BCs"
908- )
909- assert bc .value_fenics is not None , (
910- "value_fenics must be defined for weakly enforced Dirichlet BCs"
911- )
912-
913- self .formulation += (
914- - ufl .inner (n , ufl .grad (u )) * v * self .ds (bc .subdomain .id )
915- )
916-
917- self .formulation += (
918- + ufl .inner (n , ufl .grad (v ))
919- * (u - bc .value_fenics )
920- * self .ds (bc .subdomain .id )
921- )
922- self .formulation += (
923- - alpha
924- / h
925- * ufl .inner ((u - bc .value_fenics ), v )
926- * self .ds (bc .subdomain .id )
927- )
928-
901+ self .formulation += bc .weak_formulation (u , v , self .ds )
929902 for adv_term in self .advection_terms :
930903 # create vector functionspace based on the elements in the mesh
931904
@@ -1585,31 +1558,8 @@ def create_subdomain_formulation(self, subdomain: _subdomain.VolumeSubdomain):
15851558 if bc .enforce_weakly :
15861559 u = bc .species .subdomain_to_solution [subdomain ]
15871560 v = bc .species .subdomain_to_test_function [subdomain ]
1588- n = ufl .FacetNormal (self .mesh .mesh )
1589- h = ufl .Circumradius (
1590- self .mesh .mesh
1591- ) # FIXME this doesn't work for rectangles
1592- alpha = bc .penalty
1593- assert alpha is not None , (
1594- "Penalty parameter must be given for weakly enforced Dirichlet BCs"
1595- )
1596- assert bc .value_fenics is not None , (
1597- "value_fenics must be defined for weakly enforced Dirichlet BCs"
1598- )
1599-
1600- form += - ufl .inner (n , ufl .grad (u )) * v * self .ds (bc .subdomain .id )
1561+ form += bc .weak_formulation (u , v , self .ds )
16011562
1602- form += (
1603- + ufl .inner (n , ufl .grad (v ))
1604- * (u - bc .value_fenics )
1605- * self .ds (bc .subdomain .id )
1606- )
1607- form += (
1608- - alpha
1609- / h
1610- * ufl .inner ((u - bc .value_fenics ), v )
1611- * self .ds (bc .subdomain .id )
1612- )
16131563 # add volumetric sources
16141564 for source in self .sources :
16151565 v = source .species .subdomain_to_test_function [subdomain ]
0 commit comments