1 | # pyOASIS - A Python wrapper for OASIS |
---|
2 | # Authors: Philippe Gambron, Rupert Ford |
---|
3 | # Copyright (C) 2019 UKRI - STFC |
---|
4 | |
---|
5 | # This program is free software: you can redistribute it and/or modify |
---|
6 | # it under the terms of the GNU Lesser General Public License as |
---|
7 | # published by the Free Software Foundation, either version 3 of the |
---|
8 | # License, or any later version. |
---|
9 | |
---|
10 | # This program is distributed in the hope that it will be useful, |
---|
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | # GNU Lesser General Public License for more details. |
---|
14 | |
---|
15 | # A copy of the GNU Lesser General Public License, version 3, is supplied |
---|
16 | # with this program, in the file lgpl-3.0.txt. It is also available at |
---|
17 | # <https://www.gnu.org/licenses/lgpl-3.0.html>. |
---|
18 | |
---|
19 | |
---|
20 | """High level OASIS user interfaces""" |
---|
21 | |
---|
22 | import ctypes |
---|
23 | from ctypes import cdll, CDLL, c_int, c_char_p |
---|
24 | |
---|
25 | |
---|
26 | cdll.LoadLibrary("liboasis.cbind.so") |
---|
27 | LIB = CDLL("liboasis.cbind.so") |
---|
28 | |
---|
29 | |
---|
30 | LIB.oasis_c_init_comp_with_comm_iso2c.argtypes = [ctypes.POINTER(ctypes.c_int), c_char_p, |
---|
31 | ctypes.c_bool, ctypes.c_int] |
---|
32 | LIB.oasis_c_init_comp_with_comm_iso2c.restype = ctypes.c_int |
---|
33 | |
---|
34 | |
---|
35 | def init_comp_with_comm(comp_name, coupled, communicator): |
---|
36 | """OASIS user init method""" |
---|
37 | comp_id = c_int(0) |
---|
38 | kinfo = c_int(0) |
---|
39 | kinfo = LIB.oasis_c_init_comp_with_comm_iso2c(comp_id, comp_name.encode(), coupled, |
---|
40 | communicator.py2f()) |
---|
41 | return comp_id.value, kinfo |
---|
42 | |
---|
43 | |
---|
44 | LIB.oasis_c_init_comp_iso2c.argtypes = [ctypes.POINTER(ctypes.c_int), c_char_p, |
---|
45 | ctypes.c_bool] |
---|
46 | LIB.oasis_c_init_comp_iso2c.restype = ctypes.c_int |
---|
47 | |
---|
48 | |
---|
49 | def init_comp(comp_name, coupled): |
---|
50 | """OASIS user init method""" |
---|
51 | comp_id = c_int(0) |
---|
52 | kinfo = c_int(0) |
---|
53 | kinfo = LIB.oasis_c_init_comp_iso2c(comp_id, comp_name.encode(), coupled) |
---|
54 | return comp_id.value, kinfo |
---|
55 | |
---|
56 | |
---|
57 | LIB.oasis_c_enddef.argtypes = None |
---|
58 | LIB.oasis_c_enddef.restype = ctypes.c_int |
---|
59 | |
---|
60 | |
---|
61 | def enddef(): |
---|
62 | """OASIS user interface specifying the OASIS definition phase is complete""" |
---|
63 | kinfo = c_int(0) |
---|
64 | kinfo = LIB.oasis_c_enddef() |
---|
65 | return kinfo |
---|
66 | |
---|
67 | |
---|
68 | LIB.oasis_c_terminate.argtypes = None |
---|
69 | LIB.oasis_c_terminate.restype = ctypes.c_int |
---|
70 | |
---|
71 | |
---|
72 | def terminate(): |
---|
73 | """OASIS user finalize method""" |
---|
74 | kinfo = c_int(0) |
---|
75 | kinfo = LIB.oasis_c_terminate() |
---|
76 | return kinfo |
---|