coldmol 0.3.0.dev1__cp314-cp314-win_amd64.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.
- coldmol/.gitignore +2 -0
- coldmol/__init__.py +14 -0
- coldmol/_core.cp314-win_amd64.pyd +0 -0
- coldmol/_res/include/ColdMol/backend/CUDA/numeric.cuh +61 -0
- coldmol/_res/include/ColdMol/backend/OpenCL/numeric.h +33 -0
- coldmol/_res/include/ColdMol/common/compat.h +61 -0
- coldmol/_res/include/ColdMol/common/func/actor/coulomb.cmf +9 -0
- coldmol/_res/include/ColdMol/common/func/actor/gravity.cmf +9 -0
- coldmol/_res/include/ColdMol/common/func/actor/magnetic.cmf +10 -0
- coldmol/_res/include/ColdMol/common/func/actor/stark.cmf +14 -0
- coldmol/_res/include/ColdMol/common/func/actor/zeeman.cmf +14 -0
- coldmol/_res/include/ColdMol/common/func/euler.cmf.h +74 -0
- coldmol/_res/include/ColdMol/common/func/interp1d/icubicspline.cmf.h +26 -0
- coldmol/_res/include/ColdMol/common/func/interp1d/rcubicspline.cmf.h +32 -0
- coldmol/_res/include/ColdMol/common/func/interp2d/rbicubicspline.cmf.h +34 -0
- coldmol/_res/include/ColdMol/common/func/interp3d/rtricubicspline.cmf.h +44 -0
- coldmol/_res/include/ColdMol/common/func/probe/bfield.cmf +9 -0
- coldmol/_res/include/ColdMol/common/func/probe/efield.cmf +9 -0
- coldmol/_res/include/ColdMol/common/func/probe/tof.cmf.h +35 -0
- coldmol/_res/include/ColdMol/common/function.h +119 -0
- coldmol/_res/include/ColdMol/common/interp.h +195 -0
- coldmol/_res/include/ColdMol/common/numeric.h +491 -0
- coldmol/_res/include/ColdMol/common/particle.h +28 -0
- coldmol/_res/include/ColdMol/common/simulator.h +69 -0
- coldmol/coldmol.dll +0 -0
- coldmol/coldmol.lib +0 -0
- coldmol/coldmol_backend_cuda.dll +0 -0
- coldmol/coldmol_backend_cuda.lib +0 -0
- coldmol/coldmol_backend_opencl.dll +0 -0
- coldmol/coldmol_backend_opencl.lib +0 -0
- coldmol-0.3.0.dev1.dist-info/METADATA +49 -0
- coldmol-0.3.0.dev1.dist-info/RECORD +33 -0
- coldmol-0.3.0.dev1.dist-info/WHEEL +5 -0
coldmol/.gitignore
ADDED
coldmol/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
_package_dir = Path(__file__).resolve().parent
|
|
5
|
+
|
|
6
|
+
# Help Windows finding coldmol.dll next to _core.pyd
|
|
7
|
+
if os.name == "nt":
|
|
8
|
+
_dll_dir_cookie = os.add_dll_directory(str(_package_dir))
|
|
9
|
+
|
|
10
|
+
# Tell the C++ runtime where include/ColdMol/common lives
|
|
11
|
+
os.environ.setdefault("CM_SOURCE_DIR", str(_package_dir / "_res"))
|
|
12
|
+
|
|
13
|
+
from . import _core
|
|
14
|
+
from ._core import *
|
|
Binary file
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "../../common/compat.h"
|
|
4
|
+
#include "../../common/numeric.h"
|
|
5
|
+
|
|
6
|
+
#ifdef CM_DEVICE
|
|
7
|
+
|
|
8
|
+
CM_INLINE cmBool cmIsInf(const cmReal x){ return isinf(x) ? 1 : 0; }
|
|
9
|
+
CM_INLINE cmBool cmIsNan(const cmReal x){ return isnan(x) ? 1 : 0; }
|
|
10
|
+
|
|
11
|
+
#ifdef CM_DOUBLE_PRECISION
|
|
12
|
+
|
|
13
|
+
CM_INLINE cmReal cmAbs(const cmReal x){ return fabs(x); }
|
|
14
|
+
CM_INLINE cmReal cmAcos(const cmReal x){ return acos(x); }
|
|
15
|
+
CM_INLINE cmReal cmAcosh(const cmReal x){ return acosh(x); }
|
|
16
|
+
CM_INLINE cmReal cmAsin(const cmReal x){ return asin(x); }
|
|
17
|
+
CM_INLINE cmReal cmAsinh(const cmReal x){ return asinh(x); }
|
|
18
|
+
CM_INLINE cmReal cmAtan(const cmReal x){ return atan(x); }
|
|
19
|
+
CM_INLINE cmReal cmAtanh(const cmReal x){ return atanh(x); }
|
|
20
|
+
CM_INLINE cmReal cmCeil(const cmReal x){ return ceil(x); }
|
|
21
|
+
CM_INLINE cmReal cmCos(const cmReal x){ return cos(x); }
|
|
22
|
+
CM_INLINE cmReal cmCosh(const cmReal x){ return cosh(x); }
|
|
23
|
+
CM_INLINE cmReal cmExp(const cmReal x){ return exp(x); }
|
|
24
|
+
CM_INLINE cmReal cmFloor(const cmReal x){ return floor(x); }
|
|
25
|
+
CM_INLINE cmReal cmLog(const cmReal x){ return log(x); }
|
|
26
|
+
CM_INLINE cmReal cmMod(const cmReal x, const cmReal y){ return fmod(x, y); }
|
|
27
|
+
CM_INLINE cmReal cmSin(const cmReal x){ return sin(x); }
|
|
28
|
+
CM_INLINE cmReal cmSinh(const cmReal x){ return sinh(x); }
|
|
29
|
+
CM_INLINE cmReal cmSqrt(const cmReal x){ return sqrt(x); }
|
|
30
|
+
CM_INLINE cmReal cmTan(const cmReal x){ return tan(x); }
|
|
31
|
+
CM_INLINE cmReal cmTanh(const cmReal x){ return tanh(x); }
|
|
32
|
+
|
|
33
|
+
CM_INLINE cmReal cmRealPow(const cmReal x, const cmReal y){ return pow(x, y); }
|
|
34
|
+
|
|
35
|
+
#else
|
|
36
|
+
|
|
37
|
+
CM_INLINE cmReal cmAbs(const cmReal x){ return fabsf(x); }
|
|
38
|
+
CM_INLINE cmReal cmAcos(const cmReal x){ return acosf(x); }
|
|
39
|
+
CM_INLINE cmReal cmAcosh(const cmReal x){ return acoshf(x); }
|
|
40
|
+
CM_INLINE cmReal cmAsin(const cmReal x){ return asinf(x); }
|
|
41
|
+
CM_INLINE cmReal cmAsinh(const cmReal x){ return asinhf(x); }
|
|
42
|
+
CM_INLINE cmReal cmAtan(const cmReal x){ return atanf(x); }
|
|
43
|
+
CM_INLINE cmReal cmAtanh(const cmReal x){ return atanhf(x); }
|
|
44
|
+
CM_INLINE cmReal cmCeil(const cmReal x){ return ceilf(x); }
|
|
45
|
+
CM_INLINE cmReal cmCos(const cmReal x){ return cosf(x); }
|
|
46
|
+
CM_INLINE cmReal cmCosh(const cmReal x){ return coshf(x); }
|
|
47
|
+
CM_INLINE cmReal cmExp(const cmReal x){ return expf(x); }
|
|
48
|
+
CM_INLINE cmReal cmFloor(const cmReal x){ return floorf(x); }
|
|
49
|
+
CM_INLINE cmReal cmLog(const cmReal x){ return logf(x); }
|
|
50
|
+
CM_INLINE cmReal cmMod(const cmReal x, const cmReal y){ return fmodf(x, y); }
|
|
51
|
+
CM_INLINE cmReal cmSin(const cmReal x){ return sinf(x); }
|
|
52
|
+
CM_INLINE cmReal cmSinh(const cmReal x){ return sinhf(x); }
|
|
53
|
+
CM_INLINE cmReal cmSqrt(const cmReal x){ return sqrtf(x); }
|
|
54
|
+
CM_INLINE cmReal cmTan(const cmReal x){ return tanf(x); }
|
|
55
|
+
CM_INLINE cmReal cmTanh(const cmReal x){ return tanhf(x); }
|
|
56
|
+
|
|
57
|
+
CM_INLINE cmReal cmRealPow(const cmReal x, const cmReal y){ return powf(x, y); }
|
|
58
|
+
|
|
59
|
+
#endif
|
|
60
|
+
|
|
61
|
+
#endif
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "../../common/compat.h"
|
|
4
|
+
#include "../../common/numeric.h"
|
|
5
|
+
|
|
6
|
+
#ifdef CM_DEVICE
|
|
7
|
+
|
|
8
|
+
CM_INLINE cmBool cmIsInf(const cmReal x){ return isinf(x) ? 1 : 0; }
|
|
9
|
+
CM_INLINE cmBool cmIsNan(const cmReal x){ return isnan(x) ? 1 : 0; }
|
|
10
|
+
|
|
11
|
+
CM_INLINE cmReal cmAbs(const cmReal x){ return fabs(x); }
|
|
12
|
+
CM_INLINE cmReal cmAcos(const cmReal x){ return acos(x); }
|
|
13
|
+
CM_INLINE cmReal cmAcosh(const cmReal x){ return acosh(x); }
|
|
14
|
+
CM_INLINE cmReal cmAsin(const cmReal x){ return asin(x); }
|
|
15
|
+
CM_INLINE cmReal cmAsinh(const cmReal x){ return asinh(x); }
|
|
16
|
+
CM_INLINE cmReal cmAtan(const cmReal x){ return atan(x); }
|
|
17
|
+
CM_INLINE cmReal cmAtanh(const cmReal x){ return atanh(x); }
|
|
18
|
+
CM_INLINE cmReal cmCeil(const cmReal x){ return ceil(x); }
|
|
19
|
+
CM_INLINE cmReal cmCos(const cmReal x){ return cos(x); }
|
|
20
|
+
CM_INLINE cmReal cmCosh(const cmReal x){ return cosh(x); }
|
|
21
|
+
CM_INLINE cmReal cmExp(const cmReal x){ return exp(x); }
|
|
22
|
+
CM_INLINE cmReal cmFloor(const cmReal x){ return floor(x); }
|
|
23
|
+
CM_INLINE cmReal cmLog(const cmReal x){ return log(x); }
|
|
24
|
+
CM_INLINE cmReal cmMod(const cmReal x, const cmReal y){ return fmod(x, y); }
|
|
25
|
+
CM_INLINE cmReal cmSin(const cmReal x){ return sin(x); }
|
|
26
|
+
CM_INLINE cmReal cmSinh(const cmReal x){ return sinh(x); }
|
|
27
|
+
CM_INLINE cmReal cmSqrt(const cmReal x){ return sqrt(x); }
|
|
28
|
+
CM_INLINE cmReal cmTan(const cmReal x){ return tan(x); }
|
|
29
|
+
CM_INLINE cmReal cmTanh(const cmReal x){ return tanh(x); }
|
|
30
|
+
|
|
31
|
+
CM_INLINE cmReal cmRealPow(const cmReal x, const cmReal y){ return pow(x, y); }
|
|
32
|
+
|
|
33
|
+
#endif
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
#ifndef CM_DEVICE
|
|
5
|
+
#define CM_HOST
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
#define CM_HOST_CXX
|
|
8
|
+
#else
|
|
9
|
+
#define CM_HOST_C
|
|
10
|
+
#include <stddef.h>
|
|
11
|
+
#endif
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
#if defined(CM_DEVICE) && defined(CM_HAS_CUDA)
|
|
16
|
+
#define CM_INLINE static __device__ __forceinline__
|
|
17
|
+
#else
|
|
18
|
+
#define CM_INLINE static inline
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
#if defined(CM_DEVICE) && defined(CM_HAS_OPENCL)
|
|
23
|
+
#define CM_GLOBAL __global
|
|
24
|
+
#else
|
|
25
|
+
#define CM_GLOBAL
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
#ifdef __cplusplus
|
|
30
|
+
#define CM_NULL nullptr
|
|
31
|
+
#define CM_ZERO(type) type{}
|
|
32
|
+
#else
|
|
33
|
+
#define CM_NULL NULL
|
|
34
|
+
#define CM_ZERO(type) ((type){0})
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
#ifdef __cplusplus
|
|
39
|
+
#define CM_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
|
|
40
|
+
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
|
41
|
+
#define CM_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
|
|
42
|
+
#else
|
|
43
|
+
#define __CM_STATIC_ASSERT3__(cond, line) typedef char cm_static_assert_##line[(cond) ? 1 : -1]
|
|
44
|
+
#define __CM_STATIC_ASSERT2__(cond, line) __CM_STATIC_ASSERT3__(cond, line)
|
|
45
|
+
#define CM_STATIC_ASSERT(cond, msg) __CM_STATIC_ASSERT2__(cond, __LINE__)
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
#ifdef __cplusplus
|
|
50
|
+
#define CM_CAST(type, value) static_cast<type>(value)
|
|
51
|
+
#else
|
|
52
|
+
#define CM_CAST(type, value) ((type)(value))
|
|
53
|
+
#endif
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
#ifdef CM_HOST_C
|
|
57
|
+
#include <assert.h>
|
|
58
|
+
#elif defined(CM_HOST_CXX)
|
|
59
|
+
#include <cassert>
|
|
60
|
+
#endif
|
|
61
|
+
#define CM_ASSERT(cond, msg) assert(cond)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
global vec3 position;
|
|
2
|
+
global real time;
|
|
3
|
+
global uint state;
|
|
4
|
+
global real dx;
|
|
5
|
+
|
|
6
|
+
out vec3 force;
|
|
7
|
+
|
|
8
|
+
real stark_at(vec3 position){
|
|
9
|
+
return stark(state, norm(electric(position, time)));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
void main(){
|
|
13
|
+
force = -grad(stark_at, position, dx);
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
global vec3 position;
|
|
2
|
+
global real time;
|
|
3
|
+
global uint state;
|
|
4
|
+
global real dx;
|
|
5
|
+
|
|
6
|
+
out vec3 force;
|
|
7
|
+
|
|
8
|
+
real zeeman_at(vec3 position){
|
|
9
|
+
return zeeman(state, norm(magnetic(position, time)));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
void main(){
|
|
13
|
+
force = -grad(zeeman_at, position, dx);
|
|
14
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <ColdMol/common/simulator.h>
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
#ifndef CM_DEVICE
|
|
7
|
+
#define CM_DO_SOLID
|
|
8
|
+
#define CM_DO_NAN_PATCH
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
PAYLOAD(
|
|
13
|
+
const cmReal dt;
|
|
14
|
+
const cmReal dx;
|
|
15
|
+
const cmPtr particles;
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
THUNK0(cmVec3, __cm_force__);
|
|
20
|
+
THUNK0(void, __cm_listen__);
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
MAIN2(void, cmSize start, cmSize end){
|
|
24
|
+
|
|
25
|
+
cmParticle particle = *ATTR(cmParticle, self->particles);
|
|
26
|
+
cmParticle next = particle;
|
|
27
|
+
|
|
28
|
+
cmSimulationContext sim = CM_ZERO(cmSimulationContext);
|
|
29
|
+
sim.con = *context;
|
|
30
|
+
__cm_context__ = &sim.con;
|
|
31
|
+
sim.step.particle = &particle;
|
|
32
|
+
sim.step.next = &next;
|
|
33
|
+
sim.step.dt = self->dt;
|
|
34
|
+
sim.step.dx = self->dx;
|
|
35
|
+
|
|
36
|
+
for(sim.step.step=start; sim.step.step<end; ++sim.step.step){
|
|
37
|
+
|
|
38
|
+
sim.step.time = CM_CAST(cmReal, sim.step.step - 1) * self->dt;
|
|
39
|
+
|
|
40
|
+
if(particle.active){
|
|
41
|
+
|
|
42
|
+
// === Step 1 - construct force ===
|
|
43
|
+
|
|
44
|
+
const cmVec3 f = CALL0(__cm_force__);
|
|
45
|
+
|
|
46
|
+
// === Step 2 - propagate ===
|
|
47
|
+
|
|
48
|
+
next.velocity = cmVec3Add(particle.velocity, cmVec3Scale(f, self->dt / getMass(particle.state)));
|
|
49
|
+
next.position = cmVec3Add(particle.position, cmVec3Scale(particle.velocity, self->dt));
|
|
50
|
+
|
|
51
|
+
// === Step 3 - check if we hit something ===
|
|
52
|
+
|
|
53
|
+
#ifdef CM_DO_SOLID
|
|
54
|
+
next.active &= !solid(next.position, sim.step.time + self->dt);
|
|
55
|
+
#endif
|
|
56
|
+
|
|
57
|
+
// === Step 4 - call listeners ===
|
|
58
|
+
|
|
59
|
+
CALL0(__cm_listen__);
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
else{
|
|
64
|
+
#ifdef CM_DO_NAN_PATCH
|
|
65
|
+
next.position = cmVec3Make(CM_NAN, CM_NAN, CM_NAN);
|
|
66
|
+
next.velocity = cmVec3Make(CM_NAN, CM_NAN, CM_NAN);
|
|
67
|
+
#endif
|
|
68
|
+
}
|
|
69
|
+
particle = next;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Store back into particles attribute
|
|
73
|
+
*ATTR(cmParticle, self->particles) = next;
|
|
74
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <ColdMol/common/function.h>
|
|
4
|
+
|
|
5
|
+
PAYLOAD(
|
|
6
|
+
const cmPtr xk;
|
|
7
|
+
const cmPtr a;
|
|
8
|
+
const cmPtr b;
|
|
9
|
+
const cmPtr c;
|
|
10
|
+
const cmPtr d;
|
|
11
|
+
cmSize length;
|
|
12
|
+
cmReal invUnitIn;
|
|
13
|
+
cmReal unitOut;
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
MAIN1(cmReal, cmReal x){
|
|
17
|
+
return cmInterp1dICubicSpline(
|
|
18
|
+
self->invUnitIn * x,
|
|
19
|
+
PTR(cmReal, self->xk),
|
|
20
|
+
PTR(cmReal, self->a),
|
|
21
|
+
PTR(cmReal, self->b),
|
|
22
|
+
PTR(cmReal, self->c),
|
|
23
|
+
PTR(cmReal, self->d),
|
|
24
|
+
self->length
|
|
25
|
+
) * self->unitOut;
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <ColdMol/common/function.h>
|
|
4
|
+
|
|
5
|
+
PAYLOAD(
|
|
6
|
+
cmReal xmin;
|
|
7
|
+
cmReal xmax;
|
|
8
|
+
cmReal dx;
|
|
9
|
+
cmReal inv_dx;
|
|
10
|
+
const cmPtr a;
|
|
11
|
+
const cmPtr b;
|
|
12
|
+
const cmPtr c;
|
|
13
|
+
const cmPtr d;
|
|
14
|
+
cmSize length;
|
|
15
|
+
cmReal invUnitIn;
|
|
16
|
+
cmReal unitOut;
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
MAIN1(cmReal, cmReal x){
|
|
20
|
+
return cmInterp1dRCubicSpline(
|
|
21
|
+
self->invUnitIn * x,
|
|
22
|
+
self->xmin,
|
|
23
|
+
self->xmax,
|
|
24
|
+
self->dx,
|
|
25
|
+
self->inv_dx,
|
|
26
|
+
PTR(cmReal, self->a),
|
|
27
|
+
PTR(cmReal, self->b),
|
|
28
|
+
PTR(cmReal, self->c),
|
|
29
|
+
PTR(cmReal, self->d),
|
|
30
|
+
self->length
|
|
31
|
+
) * self->unitOut;
|
|
32
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <ColdMol/common/function.h>
|
|
4
|
+
|
|
5
|
+
PAYLOAD(
|
|
6
|
+
cmReal xmin;
|
|
7
|
+
cmReal xmax;
|
|
8
|
+
cmReal ymin;
|
|
9
|
+
cmReal ymax;
|
|
10
|
+
cmReal inv_dx;
|
|
11
|
+
cmReal inv_dy;
|
|
12
|
+
cmSize nx;
|
|
13
|
+
cmSize ny;
|
|
14
|
+
const cmPtr coeff;
|
|
15
|
+
cmReal invUnitInX;
|
|
16
|
+
cmReal invUnitInY;
|
|
17
|
+
cmReal unitOut;
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
MAIN2(cmReal, cmReal x, cmReal y){
|
|
21
|
+
return cmInterp2dRBicubicSpline(
|
|
22
|
+
self->invUnitInX * x,
|
|
23
|
+
self->invUnitInY * y,
|
|
24
|
+
self->xmin,
|
|
25
|
+
self->xmax,
|
|
26
|
+
self->ymin,
|
|
27
|
+
self->ymax,
|
|
28
|
+
self->inv_dx,
|
|
29
|
+
self->inv_dy,
|
|
30
|
+
self->nx,
|
|
31
|
+
self->ny,
|
|
32
|
+
PTR(cmReal, self->coeff)
|
|
33
|
+
) * self->unitOut;
|
|
34
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <ColdMol/common/function.h>
|
|
4
|
+
|
|
5
|
+
PAYLOAD(
|
|
6
|
+
cmReal xmin;
|
|
7
|
+
cmReal xmax;
|
|
8
|
+
cmReal ymin;
|
|
9
|
+
cmReal ymax;
|
|
10
|
+
cmReal zmin;
|
|
11
|
+
cmReal zmax;
|
|
12
|
+
cmReal inv_dx;
|
|
13
|
+
cmReal inv_dy;
|
|
14
|
+
cmReal inv_dz;
|
|
15
|
+
cmSize nx;
|
|
16
|
+
cmSize ny;
|
|
17
|
+
cmSize nz;
|
|
18
|
+
const cmPtr coeff;
|
|
19
|
+
cmReal invUnitInX;
|
|
20
|
+
cmReal invUnitInY;
|
|
21
|
+
cmReal invUnitInZ;
|
|
22
|
+
cmReal unitOut;
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
MAIN3(cmReal, cmReal x, cmReal y, cmReal z){
|
|
26
|
+
return cmInterp3dRTricubicSpline(
|
|
27
|
+
self->invUnitInX * x,
|
|
28
|
+
self->invUnitInY * y,
|
|
29
|
+
self->invUnitInZ * z,
|
|
30
|
+
self->xmin,
|
|
31
|
+
self->xmax,
|
|
32
|
+
self->ymin,
|
|
33
|
+
self->ymax,
|
|
34
|
+
self->zmin,
|
|
35
|
+
self->zmax,
|
|
36
|
+
self->inv_dx,
|
|
37
|
+
self->inv_dy,
|
|
38
|
+
self->inv_dz,
|
|
39
|
+
self->nx,
|
|
40
|
+
self->ny,
|
|
41
|
+
self->nz,
|
|
42
|
+
PTR(cmReal, self->coeff)
|
|
43
|
+
) * self->unitOut;
|
|
44
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <ColdMol/common/simulator.h>
|
|
4
|
+
|
|
5
|
+
#ifndef CM_DEVICE
|
|
6
|
+
#define CM_TOF_COMPONENT z
|
|
7
|
+
#define CM_TOF_NEXT_OP >
|
|
8
|
+
#define CM_TOF_PREV_OP <=
|
|
9
|
+
#define CM_TOF_DEACTIVATE
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
PAYLOAD(
|
|
13
|
+
cmReal threshold;
|
|
14
|
+
const cmPtr tof;
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
MAIN0(void){
|
|
18
|
+
|
|
19
|
+
cmReal* tof = ATTR(cmReal, self->tof);
|
|
20
|
+
if(!cmIsNan(*tof))return;
|
|
21
|
+
|
|
22
|
+
const cmReal p0 = simulation->particle->position.CM_TOF_COMPONENT;
|
|
23
|
+
const cmReal p1 = simulation->next->position.CM_TOF_COMPONENT;
|
|
24
|
+
|
|
25
|
+
if(!(p1 CM_TOF_NEXT_OP self->threshold))return;
|
|
26
|
+
if(!(p0 CM_TOF_PREV_OP self->threshold))return;
|
|
27
|
+
|
|
28
|
+
const cmReal f = (self->threshold - p0) / (p1 - p0);
|
|
29
|
+
*tof = simulation->time + f * simulation->dt;
|
|
30
|
+
|
|
31
|
+
#ifdef CM_TOF_DEACTIVATE
|
|
32
|
+
simulation->next->active = 0;
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "./compat.h"
|
|
4
|
+
#include "./interp.h"
|
|
5
|
+
#include "./numeric.h"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// ===========
|
|
9
|
+
// = Context =
|
|
10
|
+
// ===========
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
typedef struct cmContext{
|
|
14
|
+
|
|
15
|
+
CM_GLOBAL const cmU8* arena; // immutable shared program data
|
|
16
|
+
CM_GLOBAL cmU8* attributes; // mutable per-process data
|
|
17
|
+
cmSize start; // first index processed on this device
|
|
18
|
+
cmSize index; // index of current parallel process
|
|
19
|
+
cmSize processCount; // total number of parallel processes
|
|
20
|
+
cmSize attributeStride; // bytes per process in attribute record
|
|
21
|
+
|
|
22
|
+
} cmContext;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// ===========
|
|
26
|
+
// = Tagging =
|
|
27
|
+
// ===========
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
#define __CM_ID__ 0
|
|
31
|
+
#define __CM_OFFSET__ 0
|
|
32
|
+
|
|
33
|
+
#define __CM_TAG2__(NAME, ID) NAME##ID
|
|
34
|
+
#define __CM_TAG__(NAME, ID) __CM_TAG2__(NAME, ID)
|
|
35
|
+
|
|
36
|
+
#define TAG(NAME) __CM_TAG__(NAME, __CM_ID__)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// ===========
|
|
40
|
+
// = Payload =
|
|
41
|
+
// ===========
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
#define PAYLOAD(CONTENT) typedef struct TAG(cm_pl) {CONTENT} TAG(cm_pl)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// =============
|
|
48
|
+
// = Functions =
|
|
49
|
+
// =============
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// Cursed notation...
|
|
53
|
+
#define FUNC(RETURN, NAME) CM_INLINE RETURN TAG(NAME)(const cmContext* __cm_context__
|
|
54
|
+
#define THUNK(RETURN, NAME) CM_INLINE RETURN TAG(NAME)(const cmContext* __cm_context__
|
|
55
|
+
#define MAIN(RETURN) FUNC(RETURN, cm_main)
|
|
56
|
+
#define CALL(NAME) TAG(NAME)(__cm_context__
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// Fixed-arity wrappers
|
|
60
|
+
#define FUNC0(RETURN, NAME) FUNC(RETURN, NAME))
|
|
61
|
+
#define FUNC1(RETURN, NAME, ARG0) FUNC(RETURN, NAME), ARG0)
|
|
62
|
+
#define FUNC2(RETURN, NAME, ARG0, ARG1) FUNC(RETURN, NAME), ARG0, ARG1)
|
|
63
|
+
#define FUNC3(RETURN, NAME, ARG0, ARG1, ARG2) FUNC(RETURN, NAME), ARG0, ARG1, ARG2)
|
|
64
|
+
#define FUNC4(RETURN, NAME, ARG0, ARG1, ARG2, ARG3) FUNC(RETURN, NAME), ARG0, ARG1, ARG2, ARG3)
|
|
65
|
+
#define FUNC5(RETURN, NAME, ARG0, ARG1, ARG2, ARG3, ARG4) FUNC(RETURN, NAME), ARG0, ARG1, ARG2, ARG3, ARG4)
|
|
66
|
+
#define FUNC6(RETURN, NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5) FUNC(RETURN, NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5)
|
|
67
|
+
#define FUNC7(RETURN, NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) FUNC(RETURN, NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6)
|
|
68
|
+
#define FUNC8(RETURN, NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) FUNC(RETURN, NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7)
|
|
69
|
+
#define FUNC9(RETURN, NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) FUNC(RETURN, NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8)
|
|
70
|
+
|
|
71
|
+
#define THUNK0(RETURN, NAME) THUNK(RETURN, NAME))
|
|
72
|
+
#define THUNK1(RETURN, NAME, ARG0) THUNK(RETURN, NAME), ARG0)
|
|
73
|
+
#define THUNK2(RETURN, NAME, ARG0, ARG1) THUNK(RETURN, NAME), ARG0, ARG1)
|
|
74
|
+
#define THUNK3(RETURN, NAME, ARG0, ARG1, ARG2) THUNK(RETURN, NAME), ARG0, ARG1, ARG2)
|
|
75
|
+
#define THUNK4(RETURN, NAME, ARG0, ARG1, ARG2, ARG3) THUNK(RETURN, NAME), ARG0, ARG1, ARG2, ARG3)
|
|
76
|
+
#define THUNK5(RETURN, NAME, ARG0, ARG1, ARG2, ARG3, ARG4) THUNK(RETURN, NAME), ARG0, ARG1, ARG2, ARG3, ARG4)
|
|
77
|
+
#define THUNK6(RETURN, NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5) THUNK(RETURN, NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5)
|
|
78
|
+
#define THUNK7(RETURN, NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) THUNK(RETURN, NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6)
|
|
79
|
+
#define THUNK8(RETURN, NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) THUNK(RETURN, NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7)
|
|
80
|
+
#define THUNK9(RETURN, NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) THUNK(RETURN, NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8)
|
|
81
|
+
|
|
82
|
+
#define MAIN0(RETURN) MAIN(RETURN))
|
|
83
|
+
#define MAIN1(RETURN, ARG0) MAIN(RETURN), ARG0)
|
|
84
|
+
#define MAIN2(RETURN, ARG0, ARG1) MAIN(RETURN), ARG0, ARG1)
|
|
85
|
+
#define MAIN3(RETURN, ARG0, ARG1, ARG2) MAIN(RETURN), ARG0, ARG1, ARG2)
|
|
86
|
+
#define MAIN4(RETURN, ARG0, ARG1, ARG2, ARG3) MAIN(RETURN), ARG0, ARG1, ARG2, ARG3)
|
|
87
|
+
#define MAIN5(RETURN, ARG0, ARG1, ARG2, ARG3, ARG4) MAIN(RETURN), ARG0, ARG1, ARG2, ARG3, ARG4)
|
|
88
|
+
#define MAIN6(RETURN, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5) MAIN(RETURN), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5)
|
|
89
|
+
#define MAIN7(RETURN, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) MAIN(RETURN), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6)
|
|
90
|
+
#define MAIN8(RETURN, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) MAIN(RETURN), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7)
|
|
91
|
+
#define MAIN9(RETURN, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) MAIN(RETURN), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8)
|
|
92
|
+
|
|
93
|
+
#define CALL0(NAME) CALL(NAME))
|
|
94
|
+
#define CALL1(NAME, ARG0) CALL(NAME), ARG0)
|
|
95
|
+
#define CALL2(NAME, ARG0, ARG1) CALL(NAME), ARG0, ARG1)
|
|
96
|
+
#define CALL3(NAME, ARG0, ARG1, ARG2) CALL(NAME), ARG0, ARG1, ARG2)
|
|
97
|
+
#define CALL4(NAME, ARG0, ARG1, ARG2, ARG3) CALL(NAME), ARG0, ARG1, ARG2, ARG3)
|
|
98
|
+
#define CALL5(NAME, ARG0, ARG1, ARG2, ARG3, ARG4) CALL(NAME), ARG0, ARG1, ARG2, ARG3, ARG4)
|
|
99
|
+
#define CALL6(NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5) CALL(NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5)
|
|
100
|
+
#define CALL7(NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) CALL(NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6)
|
|
101
|
+
#define CALL8(NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) CALL(NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7)
|
|
102
|
+
#define CALL9(NAME, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) CALL(NAME), ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// ======================
|
|
106
|
+
// = Additional helpers =
|
|
107
|
+
// ======================
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
#define context __cm_context__
|
|
111
|
+
#define self ((CM_GLOBAL const TAG(cm_pl)*)(__cm_context__->arena + __CM_OFFSET__))
|
|
112
|
+
|
|
113
|
+
#define PTR(TYPE, OFFSET) ((CM_GLOBAL const TYPE*)(__cm_context__->arena + (OFFSET)))
|
|
114
|
+
#define ATTR(TYPE, OFFSET) ((CM_GLOBAL TYPE*)(__cm_context__->attributes + (__cm_context__->index - __cm_context__->start) * __cm_context__->attributeStride + (OFFSET)))
|
|
115
|
+
#define VAL(NAME) TAG(NAME)
|
|
116
|
+
|
|
117
|
+
#define GRAD(FUNC, POS, TIME, DX) cmGradient(TAG(FUNC), __cm_context__, POS, TIME, DX)
|
|
118
|
+
#define DIV(FUNC, POS, TIME, DX) cmDivergence(TAG(FUNC), __cm_context__, POS, TIME, DX)
|
|
119
|
+
#define CURL(FUNC, POS, TIME, DX) cmCurl(TAG(FUNC), __cm_context__, POS, TIME, DX)
|