_tools.py 1.7 KB
Newer Older
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import time
import atexit
import gmsh
import signal

gmsh.initialize()
gmsh.option.setNumber("General.Terminal",1)

signal.signal(signal.SIGINT, signal.SIG_DFL)

timers = {}

def timeit(func):
    def wrapper(*args, **kwargs):
        self = args[0]
        tic = time.process_time()
        r = func(*args, **kwargs)
        toc = time.process_time()
        name = func.__name__
        timers[name] = timers.get(name, 0) + toc - tic
        return r
    return wrapper

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
24
25
26
27
28
def timeprint(timers) :
    if len(timers) != 0 :
        print(timers)

atexit.register(timeprint, timers)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
29
30
31
32
33
34
35
36
37
38
39

try :
    from . import mumpslsys
    have_mumps = True
except:
    have_mumps = False
try :
    from . import petsclsys
    have_petsc = True
except :
    have_petsc = False
40
41
42
43
44
try :
    from . import petsc4pylsys
    have_petsc4py = True
except :
    have_petsc4py = False
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
try :
    from . import scipylsys
    have_scipy = True
except :
    have_scipy = False

def get_linear_system_package(choices=None):
    if choices is None:
        choices = ["mumps","petsc","scipy"]
    if isinstance(choices, str):
        choices = [choices]
    for choice in choices:
        if have_mumps and choice=="mumps":
            print("using mumps linear system")
            return mumpslsys.LinearSystem
        if have_petsc and choice=="petsc":
            print("using petsc linear system")
            return petsclsys.LinearSystem
        if have_scipy and choice=="scipy":
            print("using scipy linear system")
            return scipylsys.LinearSystem
66
67
68
        if have_petsc4py and choice=="petsc4py":
            print("using petsc4py linear system")
            return petsc4pylsys.LinearSystem
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
69
70
    raise ValueError("linear system not available")