mctpy 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mctpy/__init__.py +16 -0
- mctpy/__util__.py +154 -0
- mctpy/abp.py +550 -0
- mctpy/asymptotics.py +290 -0
- mctpy/fsolver.py +257 -0
- mctpy/granular.py +108 -0
- mctpy/mixture.py +303 -0
- mctpy/schematic.py +336 -0
- mctpy/shear.py +115 -0
- mctpy/solver.py +763 -0
- mctpy/standard.py +419 -0
- mctpy/standard_2d.py +280 -0
- mctpy/structurefactors/__init__.py +6 -0
- mctpy/structurefactors/interpolation.py +21 -0
- mctpy/structurefactors/mixtures.py +133 -0
- mctpy/structurefactors/simple_liquid.py +351 -0
- mctpy/structurefactors/simple_liquid_2d.py +54 -0
- mctpy/structurefactors/squarewell.py +150 -0
- mctpy/util.py +372 -0
- mctpy-0.0.1.dist-info/METADATA +32 -0
- mctpy-0.0.1.dist-info/RECORD +23 -0
- mctpy-0.0.1.dist-info/WHEEL +4 -0
- mctpy-0.0.1.dist-info/licenses/LICENSE +288 -0
mctpy/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from .solver import correlator, mean_squared_displacement, non_gaussian_parameter
|
|
2
|
+
from .asymptotics import beta_scaling_function
|
|
3
|
+
from .fsolver import nonergodicity_parameter, eigenvalue
|
|
4
|
+
from .schematic import f12model,f12gammadot_model,sjoegren_model,bosse_krieger_model,f12gammadot_tensorial_model
|
|
5
|
+
from .standard import simple_liquid_model, tagged_particle_model, tagged_particle_q0, tagged_particle_ngp
|
|
6
|
+
from .standard_2d import simple_liquid_model_2d, tagged_particle_model_2d
|
|
7
|
+
from .mixture import mixture_model
|
|
8
|
+
from .shear import isotropically_sheared_model
|
|
9
|
+
from .abp import abp_model_2d
|
|
10
|
+
from .util import CorrelatorStack, exponents, evscan, filon_integrate, filon_cos_transform, filon_sin_transform
|
|
11
|
+
|
|
12
|
+
from .__util__ import model_base
|
|
13
|
+
|
|
14
|
+
import mctpy.granular
|
|
15
|
+
|
|
16
|
+
import mctpy.structurefactors
|
mctpy/__util__.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import numba as nb
|
|
3
|
+
|
|
4
|
+
# https://stackoverflow.com/questions/61509903/how-to-pass-array-pointer-to-numba-function
|
|
5
|
+
# we need this to keep references in jit-compiled models that
|
|
6
|
+
# reference underlying data of a base model
|
|
7
|
+
@nb.extending.intrinsic
|
|
8
|
+
def address_as_void_pointer(typingctx, src):
|
|
9
|
+
""" returns a void pointer from a given memory address """
|
|
10
|
+
from numba.core import types, cgutils
|
|
11
|
+
sig = types.voidptr(src)
|
|
12
|
+
|
|
13
|
+
def codegen(cgctx, builder, sig, args):
|
|
14
|
+
return builder.inttoptr(args[0], cgutils.voidptr_t)
|
|
15
|
+
return sig, codegen
|
|
16
|
+
|
|
17
|
+
# take 3-tuple of addres, shape, dtype
|
|
18
|
+
@nb.njit
|
|
19
|
+
def nparray(ast,i=None):
|
|
20
|
+
return nb.carray(address_as_void_pointer(ast[0]),ast[1],ast[2])
|
|
21
|
+
|
|
22
|
+
def void(nparray):
|
|
23
|
+
return nparray.ctypes.data, nparray.shape, nparray.dtype
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class model_base (object):
|
|
27
|
+
def __init__ (self):
|
|
28
|
+
self.dtype = np.dtype(float)
|
|
29
|
+
def __len__ (self):
|
|
30
|
+
return 1
|
|
31
|
+
def matrix_dimension (self):
|
|
32
|
+
return 1
|
|
33
|
+
def scalar (self):
|
|
34
|
+
return True
|
|
35
|
+
def hopping (self):
|
|
36
|
+
return None
|
|
37
|
+
def phi0 (self):
|
|
38
|
+
return np.ones(len(self))
|
|
39
|
+
def phi0d (self):
|
|
40
|
+
return np.zeros(len(self))
|
|
41
|
+
def Wq (self):
|
|
42
|
+
return np.ones(len(self))
|
|
43
|
+
def Aq (self):
|
|
44
|
+
return np.ones(len(self))
|
|
45
|
+
def Bq (self):
|
|
46
|
+
return np.ones(len(self))
|
|
47
|
+
|
|
48
|
+
def set_base (self, array):
|
|
49
|
+
#self.phi = void(array)
|
|
50
|
+
self.phi = array
|
|
51
|
+
def cache (self):
|
|
52
|
+
if 'base' in dir(self): return False
|
|
53
|
+
return True
|
|
54
|
+
|
|
55
|
+
def kernel_extra_args (self):
|
|
56
|
+
return []
|
|
57
|
+
|
|
58
|
+
def get_kernel (self):
|
|
59
|
+
if not self.cache() or not '__m__' in dir(self):
|
|
60
|
+
self.__m__ = self.make_kernel()
|
|
61
|
+
return self.__m__
|
|
62
|
+
def get_dm (self):
|
|
63
|
+
if not self.cache() or not '__dm__' in dir(self):
|
|
64
|
+
self.__dm__ = self.make_dm()
|
|
65
|
+
return self.__dm__
|
|
66
|
+
def get_dmhat (self):
|
|
67
|
+
if not self.cache() or not '__dmhat__' in dir(self):
|
|
68
|
+
self.__dmhat__ = self.make_dmhat()
|
|
69
|
+
return self.__dmhat__
|
|
70
|
+
def get_dm2 (self):
|
|
71
|
+
if not self.cache() or not '__dm2__' in dir(self):
|
|
72
|
+
self.__dm2__ = self.make_dm2()
|
|
73
|
+
return self.__dm2__
|
|
74
|
+
|
|
75
|
+
def make_kernel (self):
|
|
76
|
+
@nb.njit
|
|
77
|
+
def dummy(m, phi, i, t):
|
|
78
|
+
return
|
|
79
|
+
return dummy
|
|
80
|
+
def make_dm (self):
|
|
81
|
+
@nb.njit
|
|
82
|
+
def dummy(m, phi, dphi):
|
|
83
|
+
return
|
|
84
|
+
return dummy
|
|
85
|
+
def set_C (self, f):
|
|
86
|
+
# can use this to pre-calculate stability matrix before make_dm
|
|
87
|
+
return
|
|
88
|
+
def make_dmhat(self):
|
|
89
|
+
@nb.njit
|
|
90
|
+
def dummy(m, f, ehat):
|
|
91
|
+
return
|
|
92
|
+
return dummy
|
|
93
|
+
def make_dm2 (self):
|
|
94
|
+
@nb.njit
|
|
95
|
+
def dummy(m, phi, dphi):
|
|
96
|
+
return
|
|
97
|
+
return dummy
|
|
98
|
+
|
|
99
|
+
def dq (self):
|
|
100
|
+
return 1.0
|
|
101
|
+
|
|
102
|
+
def h5save (self, fh):
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
class loaded_model(model_base):
|
|
106
|
+
def __init__ (self, h5data):
|
|
107
|
+
model_definition = h5data['model']
|
|
108
|
+
for attr,val in model_definition.attrs.items():
|
|
109
|
+
self.__dict__[attr] = val
|
|
110
|
+
for field,val in model_definition.items():
|
|
111
|
+
self.__dict__[field] = np.array(val)
|
|
112
|
+
def __len__ (self):
|
|
113
|
+
return self.M
|
|
114
|
+
|
|
115
|
+
@nb.njit
|
|
116
|
+
def np_gradient(f,k):
|
|
117
|
+
df_dk = np.zeros_like(f)
|
|
118
|
+
df_dk[1:-1] = (f[2:]-f[0:-2])/(k[2:]-k[0:-2])
|
|
119
|
+
df_dk[0] = (f[1]-f[0])/(k[1]-k[0])
|
|
120
|
+
df_dk[-1] = (f[-1]-f[-2])/(k[-1]-k[-2])
|
|
121
|
+
return df_dk
|
|
122
|
+
|
|
123
|
+
# numba does not support np.isclose with complex arrays
|
|
124
|
+
# we need to patch around that
|
|
125
|
+
# note that we also include a test like np.isclose().all()
|
|
126
|
+
# since we need that, and we can overload to make sure it
|
|
127
|
+
# also works with scalars (needed in the regula_falsi when njit'ed)
|
|
128
|
+
|
|
129
|
+
def np_isclose_all_impl(a, b, rtol, atol):
|
|
130
|
+
return np.isclose(a, b, rtol=rtol, atol=atol).all()
|
|
131
|
+
|
|
132
|
+
@nb.extending.overload(np_isclose_all_impl)
|
|
133
|
+
def np_isclose_all_impl_overload(a, b, rtol, atol):
|
|
134
|
+
if not isinstance(a, nb.types.Array):
|
|
135
|
+
if not a == nb.complex128:
|
|
136
|
+
def np_isclose_scalar (a, b, rtol, atol):
|
|
137
|
+
return np.isclose (a, b, rtol, atol)
|
|
138
|
+
return np_isclose_scalar
|
|
139
|
+
else:
|
|
140
|
+
def np_isclose_scalar (a, b, rtol, atol):
|
|
141
|
+
return np.isclose (a.real, b.real, rtol, atol) \
|
|
142
|
+
& np.isclose (a.imag, b.imag, rtol, atol)
|
|
143
|
+
return np_isclose_scalar
|
|
144
|
+
if a.dtype == nb.complex128:
|
|
145
|
+
def np_isclose_complex(a, b, rtol, atol):
|
|
146
|
+
return (np.isclose(a.real, b.real, rtol=rtol, atol=atol) \
|
|
147
|
+
& np.isclose(a.imag, b.imag, rtol=rtol, atol=atol)).all()
|
|
148
|
+
return np_isclose_complex
|
|
149
|
+
else:
|
|
150
|
+
return np_isclose_all_impl
|
|
151
|
+
|
|
152
|
+
@nb.njit
|
|
153
|
+
def np_isclose_all(a, b, rtol=1e-5, atol=1e-8):
|
|
154
|
+
return np_isclose_all_impl(a, b, rtol, atol)
|