File: test-ug.py

package info (click to toggle)
dune-grid 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,472 kB
  • sloc: cpp: 60,883; python: 1,438; perl: 191; makefile: 12; sh: 3
file content (50 lines) | stat: -rw-r--r-- 1,356 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
# SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception

import math
import dune.common
import dune.grid
import sys

# initialize MPI *if present*
try:
    import mpi4py
except ImportError as exception:
    pass

base = "../../../doc/grids/gmsh/"
reader = (dune.grid.reader.gmsh, base+"circle2ndorder.msh")
grid = dune.grid.ugGrid(reader, dimgrid=2)
# we either have UG, or this test should not be run at all
assert(grid)

exact = 6.27593206157460
# import dune.plotting

def integrateBoundary(grid):
    print(grid)
    sum = 0.0
    for intersection in grid.boundaryIntersections:
        sum += intersection.geometry.volume
    return sum


len = integrateBoundary(grid)
eoc = 0.0
for l in range(5):
    grid.hierarchicalGrid.globalRefine(1)
    len_refined = integrateBoundary(grid)
    err0 = abs(len-exact)
    err  = abs(len_refined-exact)
    eoc  = math.log2(err0/err) # h0/h = 2
    len = len_refined;
    print("boundary length: ", len, "\t", exact, "\terr=", err, "\teoc=", eoc)

# we expect 2nd order convergence
if math.isclose(eoc,2.0,abs_tol=0.02):
    print("Geometry approximation: 2d order convergence")
else:
    print("Geometry approximation does not show expected 2nd order convergence")
    sys.exit(-1)

sys.exit(0)