File: test_gf1.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 (60 lines) | stat: -rw-r--r-- 1,340 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
51
52
53
54
55
56
57
58
59
60
# 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 numpy
from dune.grid import gridFunction, structuredGrid

fcalls = 0
gcalls = 0
def testGF_first(gridView):
    global fcalls
    global gcalls
    @gridFunction(gridView)
    def f(x):
        global fcalls
        fcalls += 1
        return x[0]*x[1]
    @gridFunction(gridView)
    def g(e,x):
        global gcalls
        gcalls += 1
        return e.geometry.toGlobal(x)

    fcalls = 0
    gcalls = 0
    e = gridView.elements.__next__()
    xLoc = numpy.array([[0,0.1,0.2,0.3],[0,0.4,0.6,0.8]])
    xGlb = e.geometry.toGlobal(xLoc)

    fcalls = 0
    gcalls = 0
    y=f(xGlb)
    # print( y, fcalls)
    assert fcalls == 1
    y = g(e, xLoc)
    # print( y, gcalls)
    assert gcalls == 1

    fcalls = 0
    y = f(e,xLoc)
    # print( y, fcalls)
    assert fcalls == 1

    fcalls = 0
    gcalls = 0
    lf = f.localFunction()
    lg = g.localFunction()
    lf.bind(e)
    lg.bind(e)
    y = lf(xLoc)
    # print( y, fcalls)
    assert fcalls == 1
    y = lg(xLoc)
    # print( y, gcalls)
    assert gcalls == 1
    lg.unbind()
    lf.unbind()

if __name__ == "__main__":
    gridView = structuredGrid([0,0],[1,1],[10,10])
    testGF_first(gridView)