File: __init__.py

package info (click to toggle)
dune-geometry 2.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,304 kB
  • sloc: cpp: 15,221; python: 253; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 1,100 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
# SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
# SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception

from ._geometry import *
from ._referenceelements import *
import numpy

def _duneIntegrate(self,entity,f):
    points,weights = self.get()
    try:
        ie = entity.geometry.integrationElement
    except AttributeError:
        ie = geometry.integrationElement
    return numpy.sum(f(entity,points)*ie(points)*weights,axis=-1)

_duneQuadratureRules = {}
def quadratureRule(geometryType, order):
    try:
        geometryType = geometryType.type
    except AttributeError:
        pass
    try:
        rule = _duneQuadratureRules[(geometryType,order)]
    except KeyError:
        rule = module(geometryType.dim).rule(geometryType,order)
        setattr(rule.__class__,"apply",_duneIntegrate)
        _duneQuadratureRules[(geometryType,order)] = rule
    return rule
def quadratureRules(order):
    return lambda entity: quadratureRule(entity,order)

def integrate(rules,entity,f):
    return rules(entity).apply(entity,f)