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 | """OASIS partition data and methods""" |
---|
21 | |
---|
22 | import numpy |
---|
23 | import ctypes |
---|
24 | from ctypes import cdll, CDLL, c_int |
---|
25 | |
---|
26 | |
---|
27 | def asintarray(data): |
---|
28 | """Creates a numpy array containing doubles in Fortran ordering.""" |
---|
29 | return numpy.asfortranarray(data, dtype=numpy.int32) |
---|
30 | |
---|
31 | |
---|
32 | cdll.LoadLibrary("liboasis.cbind.so") |
---|
33 | LIB = CDLL("liboasis.cbind.so") |
---|
34 | |
---|
35 | LIB.oasis_c_def_partition.argtypes = [ctypes.POINTER(ctypes.c_int), |
---|
36 | ctypes.c_int, ctypes.POINTER(ctypes.c_int), |
---|
37 | ctypes.c_int, ctypes.c_char_p] |
---|
38 | |
---|
39 | |
---|
40 | def def_partition(parameters, global_size, name): |
---|
41 | """The OASIS user interface to define partitions""" |
---|
42 | id_part = c_int(0) |
---|
43 | kinfo = c_int(0) |
---|
44 | parameters_array = asintarray(parameters) |
---|
45 | n_parameters = len(parameters_array) |
---|
46 | p_parameters = (ctypes.c_int * n_parameters)(*parameters_array) |
---|
47 | kinfo = LIB.oasis_c_def_partition(id_part, n_parameters, p_parameters, |
---|
48 | global_size, name.encode()) |
---|
49 | return id_part.value, kinfo |
---|