From fc6bc463d3a7cece6f209987c9e006ec3270399b Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Thu, 6 May 2021 18:18:34 +0100 Subject: [PATCH] Add test of interior boundary conditions --- tests/meshes/square_with_embedded_line.geo | 44 ++ tests/meshes/square_with_embedded_line.msh | 640 +++++++++++++++++++++ tests/regression/test_interior_bcs.py | 35 ++ 3 files changed, 719 insertions(+) create mode 100644 tests/meshes/square_with_embedded_line.geo create mode 100644 tests/meshes/square_with_embedded_line.msh create mode 100644 tests/regression/test_interior_bcs.py diff --git a/tests/meshes/square_with_embedded_line.geo b/tests/meshes/square_with_embedded_line.geo new file mode 100644 index 0000000000..338441f624 --- /dev/null +++ b/tests/meshes/square_with_embedded_line.geo @@ -0,0 +1,44 @@ +// +// Labels on lines are the mesh markers +// 4 +// +// 6-------5-------4 +// | | | +// | | | +// | | | +// 1 | 5 | 2 +// | | | +// | | | +// | | | +// 1-------2-------3 +// +// 3 + + +Point(1) = {0, 0, 0, 0.1}; +Point(2) = {0.5, 0, 0, 0.1}; +Point(3) = {1, 0, 0, 0.1}; +Point(4) = {1, 1, 0, 0.1}; +Point(5) = {0.5, 1, 0, 0.1}; +Point(6) = {0, 1, 0, 0.1}; + +Line(1) = {1, 2}; +Line(2) = {2, 3}; +Line(3) = {3, 4}; +Line(4) = {4, 5}; +Line(5) = {5, 6}; +Line(6) = {6, 1}; + +Line Loop(1) = {1, 2, 3, 4, 5, 6}; +Plane Surface(1) = {1}; + +Line(7) = {2, 5}; +Line{7} In Surface{1}; + +Physical Surface(1) = {1}; + +Physical Line(1) = {6}; +Physical Line(2) = {3}; +Physical Line(3) = {1, 2}; +Physical Line(4) = {4, 5}; +Physical Line(5) = {7}; diff --git a/tests/meshes/square_with_embedded_line.msh b/tests/meshes/square_with_embedded_line.msh new file mode 100644 index 0000000000..ea35297d38 --- /dev/null +++ b/tests/meshes/square_with_embedded_line.msh @@ -0,0 +1,640 @@ +$MeshFormat +4.1 0 8 +$EndMeshFormat +$Entities +6 7 1 0 +1 0 0 0 0 +2 0.5 0 0 0 +3 1 0 0 0 +4 1 1 0 0 +5 0.5 1 0 0 +6 0 1 0 0 +1 0 0 0 0.5 0 0 1 3 2 1 -2 +2 0.5 0 0 1 0 0 1 3 2 2 -3 +3 1 0 0 1 1 0 1 2 2 3 -4 +4 0.5 1 0 1 1 0 1 4 2 4 -5 +5 0 1 0 0.5 1 0 1 4 2 5 -6 +6 0 0 0 0 1 0 1 1 2 6 -1 +7 0.5 0 0 0.5 1 0 1 5 2 2 -5 +1 0 0 0 1 1 0 1 1 6 1 2 3 4 5 6 +$EndEntities +$Nodes +14 146 1 146 +0 1 0 1 +1 +0 0 0 +0 2 0 1 +2 +0.5 0 0 +0 3 0 1 +3 +1 0 0 +0 4 0 1 +4 +1 1 0 +0 5 0 1 +5 +0.5 1 0 +0 6 0 1 +6 +0 1 0 +1 1 0 4 +7 +8 +9 +10 +0.09999999999977893 0 0 +0.1999999999994874 0 0 +0.2999999999994734 0 0 +0.3999999999997367 0 0 +1 2 0 4 +11 +12 +13 +14 +0.5999999999999998 0 0 +0.6999999999999998 0 0 +0.7999999999999998 0 0 +0.8999999999999999 0 0 +1 3 0 9 +15 +16 +17 +18 +19 +20 +21 +22 +23 +1 0.09999999999981467 0 +1 0.1999999999995579 0 +1 0.2999999999992664 0 +1 0.3999999999989749 0 +1 0.4999999999986943 0 +1 0.5999999999989468 0 +1 0.69999999999921 0 +1 0.7999999999994734 0 +1 0.8999999999997368 0 +1 4 0 4 +24 +25 +26 +27 +0.9000000000000002 1 0 +0.8000000000000002 1 0 +0.7000000000000002 1 0 +0.6000000000000001 1 0 +1 5 0 4 +28 +29 +30 +31 +0.3999999999999999 1 0 +0.3000000000006934 1 0 +0.2000000000008322 1 0 +0.1000000000004161 1 0 +1 6 0 9 +32 +33 +34 +35 +36 +37 +38 +39 +40 +0 0.8999999999995836 0 +0 0.7999999999999998 0 +0 0.7000000000006934 0 +0 0.6000000000013869 0 +0 0.5000000000020587 0 +0 0.4000000000016644 0 +0 0.3000000000012483 0 +0 0.2000000000008322 0 +0 0.100000000000416 0 +1 7 0 9 +41 +42 +43 +44 +45 +46 +47 +48 +49 +0.5 0.09999999999981467 0 +0.5 0.1999999999995579 0 +0.5 0.2999999999992664 0 +0.5 0.3999999999989749 0 +0.5 0.4999999999986943 0 +0.5 0.5999999999989468 0 +0.5 0.69999999999921 0 +0.5 0.7999999999994734 0 +0.5 0.8999999999997368 0 +2 1 0 97 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +0.2508173017619604 0.9138693290137426 0 +0.08886523929105221 0.6510989301499336 0 +0.9133974596216673 0.3499999999990765 0 +0.9133974596215033 0.5499999999988679 0 +0.09411099853178957 0.4639102936926831 0 +0.0866025403788042 0.2500000000010402 0 +0.7586725654703514 0.910370387504259 0 +0.7586725654707112 0.08962961249532825 0 +0.9133974596212855 0.749999999999335 0 +0.2540211967678747 0.07959225689686991 0 +0.09056972474434713 0.8408174380943199 0 +0.9153227954945995 0.1504237369277525 0 +0.3462687035011934 0.9157090144575408 0 +0.2995143342111186 0.8272588232818237 0 +0.1993008618813493 0.829759837348962 0 +0.2498025326829252 0.740763849222897 0 +0.3470549281315642 0.7419995447872909 0 +0.2994762434699318 0.6539862778674068 0 +0.1973550086328658 0.6533360053874089 0 +0.2488028814095356 0.5670110658226452 0 +0.3465534781088394 0.5652330735685986 0 +0.2992260599206755 0.4800963482598941 0 +0.2000000000015976 0.4803847577311343 0 +0.2516659292310332 0.3947704462157387 0 +0.3461003614621863 0.3915615648619493 0 +0.2998100587336179 0.3070748790469535 0 +0.185342495311511 0.3032032088376519 0 +0.2509914241436575 0.221462224173867 0 +0.3498133156942737 0.2287505278492656 0 +0.08660254037877746 0.35000000000141 0 +0.9133974596213446 0.6499999999991067 0 +0.8267949192429811 0.5999999999987696 0 +0.8267949192431382 0.4999999999987685 0 +0.7401923788646357 0.5499999999986198 0 +0.7401923788648125 0.4499999999986968 0 +0.7401923788643743 0.6499999999986574 0 +0.6535898384863201 0.4999999999985049 0 +0.6535898384864858 0.3999999999986339 0 +0.7401923788649161 0.3499999999988358 0 +0.6535898384866269 0.2999999999988203 0 +0.7385176964122376 0.2529006350936777 0 +0.6535898384867378 0.1999999999990214 0 +0.8265158055012215 0.3004834391815048 0 +0.8267949192426812 0.6999999999989777 0 +0.7385176964113205 0.7470993649042095 0 +0.6535898384857347 0.6999999999982512 0 +0.6535898384852008 0.7999999999983174 0 +0.8180029391351875 0.8151849454015873 0 +0.915345312486979 0.8506980051542237 0 +0.4069474032684467 0.4675273162107288 0 +0.9133974596215895 0.4499999999989339 0 +0.8267484002862241 0.4000805731959693 0 +0.08294974041515041 0.1505932316999499 0 +0.6530908664800519 0.09316566901925191 0 +0.3502101906708018 0.07597967030664626 0 +0.1491524601601235 0.743123543985849 0 +0.1482047038856849 0.5626798295533088 0 +0.8182381137259408 0.1849446511845732 0 +0.3915960755135695 0.3067236671976133 0 +0.4081627279104541 0.6524658057131503 0 +0.9122456957239048 0.2476419712152885 0 +0.6530429811999 0.9080502486060074 0 +0.6535898384861691 0.5999999999983782 0 +0.4075207981400193 0.8373946145383639 0 +0.1530550136319971 0.9178798030993331 0 +0.850864196258578 0.08324455464636532 0 +0.1559066101395384 0.09385434397751928 0 +0.8508388798776941 0.9169044142426137 0 +0.5767949192435434 0.2499999999988358 0 +0.5767949192432924 0.3499999999988943 0 +0.5767949192432199 0.4499999999986713 0 +0.5767949192431632 0.5499999999985294 0 +0.5759959722740997 0.8475836923141697 0 +0.576794919243041 0.6499999999985315 0 +0.5767949192431796 0.7499999999978743 0 +0.161946882997242 0.2000000000008352 0 +0.1607695154595992 0.4000000000015143 0 +0.5761134508278754 0.1527284582955585 0 +0.4138075210515409 0.1510358973403069 0 +0.06571748483910457 0.7470079824461592 0 +0.3063445030613716 0.1517350691757686 0 +0.4330127018928481 0.7499999999993416 0 +0.73014428414778 0.8325961894317725 0 +0.7301442841486959 0.1674038105672034 0 +0.06541889753229611 0.5500000000017229 0 +0.4310417437699952 0.5560417437712578 0 +0.4281425375739081 0.2331965484125127 0 +0.07320508075687598 0.9267949192431241 0 +0.07320508075715328 0.07320508075732396 0 +0.9267949192428899 0.9267949192428192 0 +0.4267949192434108 0.9267949192433403 0 +0.5732050807569191 0.07320508075686941 0 +0.9267949192432575 0.07320508075669295 0 +0.4273040735445855 0.07269592645529194 0 +0.572548094716318 0.9274519052836095 0 +0.4257101796174311 0.3797584830157328 0 +0.2239510510271211 0.1505462244571674 0 +$EndNodes +$Elements +8 300 1 300 +1 1 1 5 +1 1 7 +2 7 8 +3 8 9 +4 9 10 +5 10 2 +1 2 1 5 +6 2 11 +7 11 12 +8 12 13 +9 13 14 +10 14 3 +1 3 1 10 +11 3 15 +12 15 16 +13 16 17 +14 17 18 +15 18 19 +16 19 20 +17 20 21 +18 21 22 +19 22 23 +20 23 4 +1 4 1 5 +21 4 24 +22 24 25 +23 25 26 +24 26 27 +25 27 5 +1 5 1 5 +26 5 28 +27 28 29 +28 29 30 +29 30 31 +30 31 6 +1 6 1 10 +31 6 32 +32 32 33 +33 33 34 +34 34 35 +35 35 36 +36 36 37 +37 37 38 +38 38 39 +39 39 40 +40 40 1 +1 7 1 10 +41 2 41 +42 41 42 +43 42 43 +44 43 44 +45 44 45 +46 45 46 +47 46 47 +48 47 48 +49 48 49 +50 49 5 +2 1 2 250 +51 56 97 117 +52 107 57 115 +53 97 56 132 +54 57 107 133 +55 54 72 106 +56 55 76 79 +57 64 60 105 +58 54 106 134 +59 76 55 125 +60 44 45 99 +61 44 99 145 +62 48 49 113 +63 105 60 129 +64 51 68 105 +65 46 47 109 +66 113 49 140 +67 79 76 126 +68 68 51 106 +69 97 98 117 +70 61 107 115 +71 111 96 132 +72 91 103 133 +73 128 78 130 +74 60 64 114 +75 104 128 130 +76 103 91 127 +77 102 116 125 +78 77 76 125 +79 72 54 126 +80 96 111 122 +81 69 68 106 +82 72 69 106 +83 46 109 135 +84 56 111 132 +85 103 57 133 +86 125 116 146 +87 51 105 129 +88 109 47 131 +89 22 23 98 +90 36 37 54 +91 58 22 98 +92 52 92 110 +93 97 58 98 +94 92 107 110 +95 29 30 50 +96 84 88 101 +97 92 52 101 +98 85 81 93 +99 81 80 93 +100 54 37 79 +101 93 58 97 +102 107 61 110 +103 19 20 53 +104 88 92 101 +105 38 55 79 +106 53 80 81 +107 82 84 101 +108 37 38 79 +109 18 19 100 +110 52 18 100 +111 53 20 80 +112 32 33 60 +113 85 93 94 +114 53 81 82 +115 19 53 100 +116 21 58 80 +117 80 58 93 +118 82 83 84 +119 67 65 68 +120 68 65 105 +121 20 21 80 +122 55 39 102 +123 12 57 103 +124 84 86 87 +125 84 83 86 +126 71 74 99 +127 82 81 83 +128 38 39 55 +129 75 78 108 +130 65 64 105 +131 88 87 89 +132 84 87 88 +133 29 50 62 +134 75 77 78 +135 11 12 103 +136 39 40 102 +137 21 22 58 +138 12 13 57 +139 63 50 64 +140 74 75 108 +141 52 100 101 +142 9 10 104 +143 83 81 85 +144 53 82 100 +145 85 94 95 +146 17 18 52 +147 88 90 92 +148 8 9 59 +149 92 90 107 +150 88 89 90 +151 90 89 91 +152 70 71 99 +153 71 69 72 +154 15 16 61 +155 17 52 110 +156 16 17 110 +157 94 93 97 +158 71 73 74 +159 83 85 112 +160 67 68 69 +161 62 50 63 +162 100 82 101 +163 26 27 111 +164 61 16 110 +165 74 73 75 +166 86 83 112 +167 25 26 56 +168 95 94 96 +169 66 65 67 +170 70 69 71 +171 63 64 65 +172 71 72 73 +173 75 76 77 +174 34 35 51 +175 56 26 111 +176 85 95 112 +177 75 73 76 +178 67 69 70 +179 67 70 109 +180 59 9 104 +181 66 67 109 +182 63 65 66 +183 28 29 62 +184 62 63 113 +185 63 66 113 +186 30 31 114 +187 64 50 114 +188 13 14 115 +189 7 8 116 +190 24 25 117 +191 108 43 145 +192 43 44 145 +193 76 73 126 +194 50 30 114 +195 57 13 115 +196 8 59 116 +197 25 56 117 +198 106 51 134 +199 41 42 128 +200 60 33 129 +201 34 51 129 +202 66 109 131 +203 94 97 132 +204 107 90 133 +205 42 41 127 +206 36 54 134 +207 51 35 134 +208 109 70 135 +209 103 127 141 +210 1 7 138 +211 40 1 138 +212 6 32 137 +213 23 4 139 +214 4 24 139 +215 41 2 141 +216 2 11 141 +217 5 28 140 +218 3 15 142 +219 14 3 142 +220 31 6 137 +221 49 5 140 +222 62 113 140 +223 99 74 145 +224 2 41 143 +225 10 2 143 +226 5 49 144 +227 27 5 144 +228 122 48 124 +229 43 118 119 +230 118 89 119 +231 43 42 118 +232 96 122 124 +233 89 87 119 +234 46 45 121 +235 87 86 120 +236 119 87 120 +237 91 89 118 +238 44 43 119 +239 45 44 120 +240 44 119 120 +241 47 46 123 +242 86 112 121 +243 48 47 124 +244 45 120 121 +245 120 86 121 +246 49 48 122 +247 47 123 124 +248 46 121 123 +249 121 112 123 +250 112 95 123 +251 123 95 124 +252 95 96 124 +253 55 102 125 +254 43 108 136 +255 42 43 136 +256 54 79 126 +257 73 72 126 +258 48 113 131 +259 99 45 135 +260 127 41 141 +261 45 46 135 +262 59 104 130 +263 33 34 129 +264 113 66 131 +265 78 77 130 +266 47 48 131 +267 96 94 132 +268 90 91 133 +269 35 36 134 +270 70 99 135 +271 116 59 146 +272 78 128 136 +273 114 31 137 +274 115 14 142 +275 24 117 139 +276 7 116 138 +277 108 78 136 +278 111 27 144 +279 104 10 143 +280 98 23 139 +281 102 40 138 +282 32 60 137 +283 11 103 141 +284 15 61 142 +285 28 62 140 +286 74 108 145 +287 118 42 127 +288 91 118 127 +289 128 42 136 +290 60 114 137 +291 61 115 142 +292 117 98 139 +293 116 102 138 +294 122 111 144 +295 128 104 143 +296 41 128 143 +297 49 122 144 +298 77 125 146 +299 59 130 146 +300 130 77 146 +$EndElements diff --git a/tests/regression/test_interior_bcs.py b/tests/regression/test_interior_bcs.py new file mode 100644 index 0000000000..240c393ca6 --- /dev/null +++ b/tests/regression/test_interior_bcs.py @@ -0,0 +1,35 @@ +from os.path import abspath, dirname, join + +from firedrake import * + +cwd = abspath(dirname(__file__)) + + +def test_interior_bc(): + mesh = Mesh(join(cwd, "..", "meshes", "square_with_embedded_line.msh")) + V = FunctionSpace(mesh, "P", 1) + + v = TestFunction(V) + uh = Function(V) + F = inner(grad(uh), grad(v))*dx + + # 0 on left boundary, 10 on right boundary + bcs = [DirichletBC(V, 0, 1), + DirichletBC(V, 10, 2)] + + solve(F == 0, uh, bcs=bcs) + + x, y = SpatialCoordinate(mesh) + expect = 10*x + assert errornorm(expect, uh) < 1e-10 + + # Now put a no-penetration boundary in the interior + + bcs = [DirichletBC(V, 10, 1), + DirichletBC(V, 10, 2), + DirichletBC(V, 0, 5)] + + expect = conditional(x < 0.5, -20*x + 10, 20*x - 10) + + solve(F == 0, uh, bcs=bcs) + assert errornorm(expect, uh) < 1e-10