Skip to content

Commit d741557

Browse files
authored
SobolevSpace: add H1Curl, H1Div, and H3 (#463)
* SobolevSpace: add H1Curl, H1Div, and H3 * Apply suggestions from code review * flake
1 parent 4d33962 commit d741557

2 files changed

Lines changed: 38 additions & 19 deletions

File tree

ufl/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,15 @@
7070
-L2
7171
-H1
7272
-H2
73+
-H3
7374
-HInf
7475
-HDiv
7576
-HCurl
7677
-HEin
7778
-HDivDiv
7879
-HCurlDiv
80+
-H1Div
81+
-H1Curl
7982
8083
8184
* Pull backs::
@@ -427,7 +430,20 @@
427430
identity_pullback,
428431
l2_piola,
429432
)
430-
from ufl.sobolevspace import H1, H2, L2, HCurl, HCurlDiv, HDiv, HDivDiv, HEin, HInf
433+
from ufl.sobolevspace import (
434+
H1,
435+
H2,
436+
H3,
437+
L2,
438+
H1Curl,
439+
H1Div,
440+
HCurl,
441+
HCurlDiv,
442+
HDiv,
443+
HDivDiv,
444+
HEin,
445+
HInf,
446+
)
431447
from ufl.split_functions import split
432448
from ufl.tensors import (
433449
as_matrix,
@@ -444,6 +460,7 @@
444460
__all__ = [
445461
"H1",
446462
"H2",
463+
"H3",
447464
"L2",
448465
"AbstractCell",
449466
"AbstractDomain",
@@ -476,6 +493,8 @@
476493
"Form",
477494
"FormSum",
478495
"FunctionSpace",
496+
"H1Curl",
497+
"H1Div",
479498
"HCurl",
480499
"HCurlDiv",
481500
"HDiv",

ufl/sobolevspace.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,17 @@ def __init__(self, name, parents=None):
4242
p = frozenset(parents or [])
4343
# Ensure that the inclusion operations are transitive.
4444
self.parents = p.union(*[p_.parents for p_ in p])
45-
self._order = {
46-
"L2": 0,
47-
"H1": 1,
48-
"H2": 2,
49-
"HInf": inf,
50-
# Order for the elements below is taken from
51-
# its parent Sobolev space
52-
"HDiv": 0,
53-
"HCurl": 0,
54-
"HEin": 0,
55-
"HDivDiv": 0,
56-
"HCurlDiv": 0,
57-
"DirectionalH": 0,
58-
}[self.name]
45+
order_dict = {"L2": 0, "H1": 1, "H2": 2, "H3": 3, "HInf": inf}
46+
try:
47+
order = order_dict[self.name]
48+
except KeyError:
49+
# Take the maximum order over all the parents
50+
# For instance, H1Div has order=1 because it has H1 as parent
51+
if len(self.parents) == 0:
52+
order = 0
53+
else:
54+
order = max(p._order for p in self.parents)
55+
self._order = order
5956

6057
def __str__(self):
6158
"""Format as a string."""
@@ -124,7 +121,7 @@ def __getitem__(self, spatial_index):
124121
"""Returns the Sobolev space associated with a particular spatial coordinate."""
125122
if spatial_index not in range(len(self._orders)):
126123
raise IndexError("Spatial index out of range.")
127-
spaces = {0: L2, 1: H1, 2: H2, inf: HInf}
124+
spaces = {0: L2, 1: H1, 2: H2, 3: H3, inf: HInf}
128125
return spaces[self._orders[spatial_index]]
129126

130127
def __contains__(self, other):
@@ -171,9 +168,12 @@ def __str__(self):
171168
L2 = SobolevSpace("L2")
172169
HDiv = SobolevSpace("HDiv", [L2])
173170
HCurl = SobolevSpace("HCurl", [L2])
174-
H1 = SobolevSpace("H1", [HDiv, HCurl, L2])
175-
H2 = SobolevSpace("H2", [H1, HDiv, HCurl, L2])
176-
HInf = SobolevSpace("HInf", [H2, H1, HDiv, HCurl, L2])
171+
H1 = SobolevSpace("H1", [HCurl, HDiv, L2])
172+
H1Div = SobolevSpace("H1Div", [H1])
173+
H1Curl = SobolevSpace("H1Curl", [H1])
174+
H2 = SobolevSpace("H2", [H1Curl, H1Div, H1])
175+
H3 = SobolevSpace("H3", [H2])
176+
HInf = SobolevSpace("HInf", [H3])
177177
HEin = SobolevSpace("HEin", [L2])
178178
HDivDiv = SobolevSpace("HDivDiv", [L2])
179179
HCurlDiv = SobolevSpace("HCurlDiv", [L2])

0 commit comments

Comments
 (0)