witwin-maxwell 0.3.0__py3-none-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.
- witwin/maxwell/__init__.py +164 -0
- witwin/maxwell/adapters/__init__.py +1 -0
- witwin/maxwell/adapters/gds.py +203 -0
- witwin/maxwell/adapters/tidy3d.py +1669 -0
- witwin/maxwell/adjoint_inputs.py +70 -0
- witwin/maxwell/compiler/__init__.py +11 -0
- witwin/maxwell/compiler/materials.py +1355 -0
- witwin/maxwell/compiler/monitors.py +164 -0
- witwin/maxwell/compiler/sources.py +222 -0
- witwin/maxwell/fdfd/__init__.py +3 -0
- witwin/maxwell/fdfd/adjoint/__init__.py +3 -0
- witwin/maxwell/fdfd/adjoint/bridge.py +180 -0
- witwin/maxwell/fdfd/ams.py +300 -0
- witwin/maxwell/fdfd/krylov.py +280 -0
- witwin/maxwell/fdfd/plotting.py +110 -0
- witwin/maxwell/fdfd/postprocess.py +33 -0
- witwin/maxwell/fdfd/solver.py +1057 -0
- witwin/maxwell/fdtd/__init__.py +4 -0
- witwin/maxwell/fdtd/adjoint/__init__.py +21 -0
- witwin/maxwell/fdtd/adjoint/bridge.py +746 -0
- witwin/maxwell/fdtd/adjoint/capabilities.py +29 -0
- witwin/maxwell/fdtd/adjoint/core.py +3614 -0
- witwin/maxwell/fdtd/adjoint/dispatch.py +684 -0
- witwin/maxwell/fdtd/adjoint/native.py +2561 -0
- witwin/maxwell/fdtd/adjoint/profiler.py +195 -0
- witwin/maxwell/fdtd/adjoint/reverse_common.py +207 -0
- witwin/maxwell/fdtd/adjoint/seeds.py +524 -0
- witwin/maxwell/fdtd/boundary/__init__.py +37 -0
- witwin/maxwell/fdtd/boundary/bloch.py +90 -0
- witwin/maxwell/fdtd/boundary/common.py +41 -0
- witwin/maxwell/fdtd/boundary/cpml.py +527 -0
- witwin/maxwell/fdtd/boundary/runtime.py +209 -0
- witwin/maxwell/fdtd/checkpoint.py +227 -0
- witwin/maxwell/fdtd/coords.py +32 -0
- witwin/maxwell/fdtd/cuda/__init__.py +11 -0
- witwin/maxwell/fdtd/cuda/backend.py +3532 -0
- witwin/maxwell/fdtd/cuda/build.py +292 -0
- witwin/maxwell/fdtd/cuda/extension.cpp +2053 -0
- witwin/maxwell/fdtd/cuda/kernels/adjoint.cu +5290 -0
- witwin/maxwell/fdtd/cuda/kernels/aniso.cu +1704 -0
- witwin/maxwell/fdtd/cuda/kernels/boundary.cu +424 -0
- witwin/maxwell/fdtd/cuda/kernels/common.cu +74 -0
- witwin/maxwell/fdtd/cuda/kernels/common.cuh +82 -0
- witwin/maxwell/fdtd/cuda/kernels/dispersive.cu +782 -0
- witwin/maxwell/fdtd/cuda/kernels/electric.cu +3613 -0
- witwin/maxwell/fdtd/cuda/kernels/magnetic.cu +781 -0
- witwin/maxwell/fdtd/cuda/kernels/observers.cu +347 -0
- witwin/maxwell/fdtd/cuda/kernels/projection.cu +211 -0
- witwin/maxwell/fdtd/cuda/kernels/sources.cu +1482 -0
- witwin/maxwell/fdtd/cuda/kernels/spectral.cu +297 -0
- witwin/maxwell/fdtd/cuda/launch.h +23 -0
- witwin/maxwell/fdtd/cuda/prebuilt/witwin_maxwell_fdtd_cuda.pyd +0 -0
- witwin/maxwell/fdtd/cuda/runtime/__init__.py +6 -0
- witwin/maxwell/fdtd/cuda/runtime/dispatcher.py +6 -0
- witwin/maxwell/fdtd/cuda/runtime/graph.py +33 -0
- witwin/maxwell/fdtd/cuda/tensors.h +35 -0
- witwin/maxwell/fdtd/dispersion.py +48 -0
- witwin/maxwell/fdtd/evaluation.py +290 -0
- witwin/maxwell/fdtd/excitation/__init__.py +27 -0
- witwin/maxwell/fdtd/excitation/injection.py +1102 -0
- witwin/maxwell/fdtd/excitation/modes.py +1675 -0
- witwin/maxwell/fdtd/excitation/spatial.py +469 -0
- witwin/maxwell/fdtd/excitation/temporal.py +510 -0
- witwin/maxwell/fdtd/excitation/tfsf_apply.py +264 -0
- witwin/maxwell/fdtd/excitation/tfsf_common.py +421 -0
- witwin/maxwell/fdtd/excitation/tfsf_specs.py +490 -0
- witwin/maxwell/fdtd/excitation/tfsf_state.py +778 -0
- witwin/maxwell/fdtd/io.py +31 -0
- witwin/maxwell/fdtd/material_pullback.py +371 -0
- witwin/maxwell/fdtd/meshing/__init__.py +3 -0
- witwin/maxwell/fdtd/meshing/autogrid.py +335 -0
- witwin/maxwell/fdtd/observers.py +1453 -0
- witwin/maxwell/fdtd/plotting.py +121 -0
- witwin/maxwell/fdtd/postprocess.py +205 -0
- witwin/maxwell/fdtd/runtime/__init__.py +119 -0
- witwin/maxwell/fdtd/runtime/initialization.py +236 -0
- witwin/maxwell/fdtd/runtime/materials.py +1563 -0
- witwin/maxwell/fdtd/runtime/module_cache.py +31 -0
- witwin/maxwell/fdtd/runtime/spectral.py +581 -0
- witwin/maxwell/fdtd/runtime/stepping.py +1987 -0
- witwin/maxwell/fdtd/solver.py +502 -0
- witwin/maxwell/geometry/__init__.py +5 -0
- witwin/maxwell/geometry/polyslab.py +299 -0
- witwin/maxwell/materials.py +3 -0
- witwin/maxwell/media.py +1467 -0
- witwin/maxwell/monitors.py +743 -0
- witwin/maxwell/ports.py +113 -0
- witwin/maxwell/postprocess/RCS.py +139 -0
- witwin/maxwell/postprocess/__init__.py +42 -0
- witwin/maxwell/postprocess/diffraction.py +219 -0
- witwin/maxwell/postprocess/directivity.py +152 -0
- witwin/maxwell/postprocess/emission.py +67 -0
- witwin/maxwell/postprocess/modal.py +324 -0
- witwin/maxwell/postprocess/nfft.py +266 -0
- witwin/maxwell/postprocess/scattering_parameters.py +358 -0
- witwin/maxwell/postprocess/stratton_chu.py +1193 -0
- witwin/maxwell/result.py +967 -0
- witwin/maxwell/scene.py +1338 -0
- witwin/maxwell/simulation.py +659 -0
- witwin/maxwell/sources.py +917 -0
- witwin/maxwell/visualization/__init__.py +28 -0
- witwin/maxwell/visualization/interactive.py +484 -0
- witwin/maxwell/visualization/plots.py +568 -0
- witwin_maxwell-0.3.0.dist-info/METADATA +184 -0
- witwin_maxwell-0.3.0.dist-info/RECORD +107 -0
- witwin_maxwell-0.3.0.dist-info/WHEEL +4 -0
- witwin_maxwell-0.3.0.dist-info/licenses/LICENSE +13 -0
|
@@ -0,0 +1,781 @@
|
|
|
1
|
+
#include <type_traits>
|
|
2
|
+
|
|
3
|
+
#include "../launch.h"
|
|
4
|
+
#include "../tensors.h"
|
|
5
|
+
#include "common.cuh"
|
|
6
|
+
|
|
7
|
+
namespace {
|
|
8
|
+
|
|
9
|
+
dim3 field_block3d() {
|
|
10
|
+
return dim3(128, 2, 1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
dim3 field_grid3d(int64_t nx, int64_t ny, int64_t nz, dim3 block) {
|
|
14
|
+
return dim3(
|
|
15
|
+
static_cast<unsigned int>((nz + block.x - 1) / block.x),
|
|
16
|
+
static_cast<unsigned int>((ny + block.y - 1) / block.y),
|
|
17
|
+
static_cast<unsigned int>((nx + block.z - 1) / block.z));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
template <int Component>
|
|
21
|
+
__global__ void update_magnetic_standard_kernel(
|
|
22
|
+
unsigned int nx,
|
|
23
|
+
unsigned int ny,
|
|
24
|
+
unsigned int nz,
|
|
25
|
+
const float* __restrict__ first,
|
|
26
|
+
const float* __restrict__ second,
|
|
27
|
+
const float* __restrict__ decay,
|
|
28
|
+
const float* __restrict__ curl_coeff,
|
|
29
|
+
const float* __restrict__ inv_a,
|
|
30
|
+
const float* __restrict__ inv_b,
|
|
31
|
+
float* __restrict__ field) {
|
|
32
|
+
const unsigned int k = blockIdx.x * blockDim.x + threadIdx.x;
|
|
33
|
+
const unsigned int j = blockIdx.y * blockDim.y + threadIdx.y;
|
|
34
|
+
const unsigned int i = blockIdx.z * blockDim.z + threadIdx.z;
|
|
35
|
+
if (i >= nx || j >= ny || k >= nz) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const long long linear = offset3d(i, j, k, ny, nz);
|
|
39
|
+
float positive;
|
|
40
|
+
float negative;
|
|
41
|
+
if constexpr (Component == 0) {
|
|
42
|
+
positive = (second[offset3d(i, j + 1, k, ny + 1, nz)] - second[offset3d(i, j, k, ny + 1, nz)]) * inv_a[j];
|
|
43
|
+
negative = (first[offset3d(i, j, k + 1, ny, nz + 1)] - first[offset3d(i, j, k, ny, nz + 1)]) * inv_b[k];
|
|
44
|
+
} else if constexpr (Component == 1) {
|
|
45
|
+
positive = (first[offset3d(i, j, k + 1, ny, nz + 1)] - first[offset3d(i, j, k, ny, nz + 1)]) * inv_b[k];
|
|
46
|
+
negative = (second[offset3d(i + 1, j, k, ny, nz)] - second[offset3d(i, j, k, ny, nz)]) * inv_a[i];
|
|
47
|
+
} else {
|
|
48
|
+
positive = (second[offset3d(i + 1, j, k, ny, nz)] - second[offset3d(i, j, k, ny, nz)]) * inv_a[i];
|
|
49
|
+
negative = (first[offset3d(i, j + 1, k, ny + 1, nz)] - first[offset3d(i, j, k, ny + 1, nz)]) * inv_b[j];
|
|
50
|
+
}
|
|
51
|
+
field[linear] = field[linear] * decay[linear] - curl_coeff[linear] * (positive - negative);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
template <int Component>
|
|
55
|
+
__global__ void update_magnetic_cpml_kernel(
|
|
56
|
+
unsigned int nx,
|
|
57
|
+
unsigned int ny,
|
|
58
|
+
unsigned int nz,
|
|
59
|
+
const float* __restrict__ first,
|
|
60
|
+
const float* __restrict__ second,
|
|
61
|
+
const float* __restrict__ decay,
|
|
62
|
+
const float* __restrict__ curl_coeff,
|
|
63
|
+
const float* __restrict__ inv_kappa_a,
|
|
64
|
+
const float* __restrict__ b_a,
|
|
65
|
+
const float* __restrict__ c_a,
|
|
66
|
+
const float* __restrict__ inv_kappa_b,
|
|
67
|
+
const float* __restrict__ b_b,
|
|
68
|
+
const float* __restrict__ c_b,
|
|
69
|
+
const float* __restrict__ inv_a,
|
|
70
|
+
const float* __restrict__ inv_b,
|
|
71
|
+
float* __restrict__ psi_a,
|
|
72
|
+
float* __restrict__ psi_b,
|
|
73
|
+
float* __restrict__ field) {
|
|
74
|
+
const unsigned int k = blockIdx.x * blockDim.x + threadIdx.x;
|
|
75
|
+
const unsigned int j = blockIdx.y * blockDim.y + threadIdx.y;
|
|
76
|
+
const unsigned int i = blockIdx.z * blockDim.z + threadIdx.z;
|
|
77
|
+
if (i >= nx || j >= ny || k >= nz) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const long long linear = offset3d(i, j, k, ny, nz);
|
|
81
|
+
float d_a;
|
|
82
|
+
float d_b;
|
|
83
|
+
if constexpr (Component == 0) {
|
|
84
|
+
d_a = (second[offset3d(i, j + 1, k, ny + 1, nz)] - second[offset3d(i, j, k, ny + 1, nz)]) * inv_a[j];
|
|
85
|
+
d_b = (first[offset3d(i, j, k + 1, ny, nz + 1)] - first[offset3d(i, j, k, ny, nz + 1)]) * inv_b[k];
|
|
86
|
+
} else if constexpr (Component == 1) {
|
|
87
|
+
d_a = (second[offset3d(i + 1, j, k, ny, nz)] - second[offset3d(i, j, k, ny, nz)]) * inv_a[i];
|
|
88
|
+
d_b = (first[offset3d(i, j, k + 1, ny, nz + 1)] - first[offset3d(i, j, k, ny, nz + 1)]) * inv_b[k];
|
|
89
|
+
} else {
|
|
90
|
+
d_a = (second[offset3d(i + 1, j, k, ny, nz)] - second[offset3d(i, j, k, ny, nz)]) * inv_a[i];
|
|
91
|
+
d_b = (first[offset3d(i, j + 1, k, ny + 1, nz)] - first[offset3d(i, j, k, ny + 1, nz)]) * inv_b[j];
|
|
92
|
+
}
|
|
93
|
+
const unsigned int coord_a = Component == 0 ? j : i;
|
|
94
|
+
const unsigned int coord_b = Component == 2 ? j : k;
|
|
95
|
+
const float psi_a_value = b_a[coord_a] * psi_a[linear] + c_a[coord_a] * d_a;
|
|
96
|
+
const float psi_b_value = b_b[coord_b] * psi_b[linear] + c_b[coord_b] * d_b;
|
|
97
|
+
psi_a[linear] = psi_a_value;
|
|
98
|
+
psi_b[linear] = psi_b_value;
|
|
99
|
+
const float corrected_a = d_a * inv_kappa_a[coord_a] + psi_a_value;
|
|
100
|
+
const float corrected_b = d_b * inv_kappa_b[coord_b] + psi_b_value;
|
|
101
|
+
const float curl = Component == 1 ? corrected_b - corrected_a : corrected_a - corrected_b;
|
|
102
|
+
field[linear] = field[linear] * decay[linear] - curl_coeff[linear] * curl;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
template <int Axis>
|
|
106
|
+
__device__ __forceinline__ float update_compact_magnetic_psi(
|
|
107
|
+
float* __restrict__ psi,
|
|
108
|
+
const float* __restrict__ b,
|
|
109
|
+
const float* __restrict__ c,
|
|
110
|
+
unsigned int i,
|
|
111
|
+
unsigned int j,
|
|
112
|
+
unsigned int k,
|
|
113
|
+
unsigned int size_y,
|
|
114
|
+
unsigned int size_z,
|
|
115
|
+
unsigned int axis_coord,
|
|
116
|
+
int low_length,
|
|
117
|
+
int high_start,
|
|
118
|
+
int high_length,
|
|
119
|
+
float derivative) {
|
|
120
|
+
const int local = compact_local_index(axis_coord, low_length, high_start, high_length);
|
|
121
|
+
if (local < 0) {
|
|
122
|
+
return 0.0f;
|
|
123
|
+
}
|
|
124
|
+
const unsigned int compact_length = static_cast<unsigned int>(low_length + high_length);
|
|
125
|
+
const long long psi_offset = compact_offset3d_axis<Axis>(i, j, k, size_y, size_z, local, compact_length);
|
|
126
|
+
const float value = b[axis_coord] * psi[psi_offset] + c[axis_coord] * derivative;
|
|
127
|
+
psi[psi_offset] = value;
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
template <int Component, bool UniformDecay, bool UniformCurl>
|
|
132
|
+
__global__ void update_magnetic_cpml_compressed_kernel(
|
|
133
|
+
unsigned int nx,
|
|
134
|
+
unsigned int ny,
|
|
135
|
+
unsigned int nz,
|
|
136
|
+
const float* __restrict__ first,
|
|
137
|
+
const float* __restrict__ second,
|
|
138
|
+
const float* __restrict__ decay,
|
|
139
|
+
const float* __restrict__ curl_coeff,
|
|
140
|
+
float decay_value,
|
|
141
|
+
float curl_value,
|
|
142
|
+
const float* __restrict__ inv_kappa_a,
|
|
143
|
+
const float* __restrict__ b_a,
|
|
144
|
+
const float* __restrict__ c_a,
|
|
145
|
+
const float* __restrict__ inv_kappa_b,
|
|
146
|
+
const float* __restrict__ b_b,
|
|
147
|
+
const float* __restrict__ c_b,
|
|
148
|
+
const float* __restrict__ inv_a,
|
|
149
|
+
const float* __restrict__ inv_b,
|
|
150
|
+
int a_low_length,
|
|
151
|
+
int a_high_start,
|
|
152
|
+
int a_high_length,
|
|
153
|
+
int b_low_length,
|
|
154
|
+
int b_high_start,
|
|
155
|
+
int b_high_length,
|
|
156
|
+
float* __restrict__ psi_a,
|
|
157
|
+
float* __restrict__ psi_b,
|
|
158
|
+
float* __restrict__ field) {
|
|
159
|
+
const unsigned int k = blockIdx.x * blockDim.x + threadIdx.x;
|
|
160
|
+
const unsigned int j = blockIdx.y * blockDim.y + threadIdx.y;
|
|
161
|
+
const unsigned int i = blockIdx.z * blockDim.z + threadIdx.z;
|
|
162
|
+
if (i >= nx || j >= ny || k >= nz) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const long long linear = offset3d(i, j, k, ny, nz);
|
|
166
|
+
float d_a;
|
|
167
|
+
float d_b;
|
|
168
|
+
if constexpr (Component == 0) {
|
|
169
|
+
d_a = (second[offset3d(i, j + 1, k, ny + 1, nz)] - second[offset3d(i, j, k, ny + 1, nz)]) * inv_a[j];
|
|
170
|
+
d_b = (first[offset3d(i, j, k + 1, ny, nz + 1)] - first[offset3d(i, j, k, ny, nz + 1)]) * inv_b[k];
|
|
171
|
+
} else if constexpr (Component == 1) {
|
|
172
|
+
d_a = (second[offset3d(i + 1, j, k, ny, nz)] - second[offset3d(i, j, k, ny, nz)]) * inv_a[i];
|
|
173
|
+
d_b = (first[offset3d(i, j, k + 1, ny, nz + 1)] - first[offset3d(i, j, k, ny, nz + 1)]) * inv_b[k];
|
|
174
|
+
} else {
|
|
175
|
+
d_a = (second[offset3d(i + 1, j, k, ny, nz)] - second[offset3d(i, j, k, ny, nz)]) * inv_a[i];
|
|
176
|
+
d_b = (first[offset3d(i, j + 1, k, ny + 1, nz)] - first[offset3d(i, j, k, ny + 1, nz)]) * inv_b[j];
|
|
177
|
+
}
|
|
178
|
+
const unsigned int coord_a = Component == 0 ? j : i;
|
|
179
|
+
const unsigned int coord_b = Component == 2 ? j : k;
|
|
180
|
+
float psi_a_value;
|
|
181
|
+
float psi_b_value;
|
|
182
|
+
if constexpr (Component == 0) {
|
|
183
|
+
psi_a_value = update_compact_magnetic_psi<1>(psi_a, b_a, c_a, i, j, k, ny, nz, coord_a, a_low_length, a_high_start, a_high_length, d_a);
|
|
184
|
+
psi_b_value = update_compact_magnetic_psi<2>(psi_b, b_b, c_b, i, j, k, ny, nz, coord_b, b_low_length, b_high_start, b_high_length, d_b);
|
|
185
|
+
} else if constexpr (Component == 1) {
|
|
186
|
+
psi_a_value = update_compact_magnetic_psi<0>(psi_a, b_a, c_a, i, j, k, ny, nz, coord_a, a_low_length, a_high_start, a_high_length, d_a);
|
|
187
|
+
psi_b_value = update_compact_magnetic_psi<2>(psi_b, b_b, c_b, i, j, k, ny, nz, coord_b, b_low_length, b_high_start, b_high_length, d_b);
|
|
188
|
+
} else {
|
|
189
|
+
psi_a_value = update_compact_magnetic_psi<0>(psi_a, b_a, c_a, i, j, k, ny, nz, coord_a, a_low_length, a_high_start, a_high_length, d_a);
|
|
190
|
+
psi_b_value = update_compact_magnetic_psi<1>(psi_b, b_b, c_b, i, j, k, ny, nz, coord_b, b_low_length, b_high_start, b_high_length, d_b);
|
|
191
|
+
}
|
|
192
|
+
const float corrected_a = d_a * inv_kappa_a[coord_a] + psi_a_value;
|
|
193
|
+
const float corrected_b = d_b * inv_kappa_b[coord_b] + psi_b_value;
|
|
194
|
+
const float curl = Component == 1 ? corrected_b - corrected_a : corrected_a - corrected_b;
|
|
195
|
+
const float decay_factor = UniformDecay ? decay_value : decay[linear];
|
|
196
|
+
const float curl_factor = UniformCurl ? curl_value : curl_coeff[linear];
|
|
197
|
+
field[linear] = field[linear] * decay_factor - curl_factor * curl;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
void check_magnetic_inputs(
|
|
201
|
+
const torch::stable::Tensor& field,
|
|
202
|
+
const torch::stable::Tensor& first,
|
|
203
|
+
const torch::stable::Tensor& second,
|
|
204
|
+
const torch::stable::Tensor& decay,
|
|
205
|
+
const torch::stable::Tensor& curl,
|
|
206
|
+
const char* name) {
|
|
207
|
+
check_float32_tensor(field, name);
|
|
208
|
+
check_float32_tensor(first, "first");
|
|
209
|
+
check_float32_tensor(second, "second");
|
|
210
|
+
check_float32_tensor(decay, "decay");
|
|
211
|
+
check_float32_tensor(curl, "curl");
|
|
212
|
+
check_same_cuda_device(field, first, "first");
|
|
213
|
+
check_same_cuda_device(field, second, "second");
|
|
214
|
+
check_same_cuda_device(field, decay, "decay");
|
|
215
|
+
check_same_cuda_device(field, curl, "curl");
|
|
216
|
+
check_contiguous_tensor(field, name);
|
|
217
|
+
check_contiguous_tensor(first, "first");
|
|
218
|
+
check_contiguous_tensor(second, "second");
|
|
219
|
+
check_contiguous_tensor(decay, "decay");
|
|
220
|
+
check_contiguous_tensor(curl, "curl");
|
|
221
|
+
STD_TORCH_CHECK(field.dim() == 3, name, " must be rank 3");
|
|
222
|
+
STD_TORCH_CHECK(first.dim() == 3, "first must be rank 3");
|
|
223
|
+
STD_TORCH_CHECK(second.dim() == 3, "second must be rank 3");
|
|
224
|
+
STD_TORCH_CHECK(decay.sizes().equals(field.sizes()), "decay must match field shape");
|
|
225
|
+
STD_TORCH_CHECK(curl.sizes().equals(field.sizes()), "curl must match field shape");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
void check_rank3_shape(
|
|
229
|
+
const torch::stable::Tensor& tensor,
|
|
230
|
+
const char* name,
|
|
231
|
+
int64_t x,
|
|
232
|
+
int64_t y,
|
|
233
|
+
int64_t z) {
|
|
234
|
+
STD_TORCH_CHECK(tensor.dim() == 3, name, " must be rank 3");
|
|
235
|
+
STD_TORCH_CHECK(
|
|
236
|
+
tensor.size(0) == x && tensor.size(1) == y && tensor.size(2) == z,
|
|
237
|
+
name,
|
|
238
|
+
" has an incompatible Yee-grid shape");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
void check_vector_input(const torch::stable::Tensor& tensor, int64_t length, const char* name) {
|
|
242
|
+
check_float32_tensor(tensor, name);
|
|
243
|
+
check_contiguous_tensor(tensor, name);
|
|
244
|
+
STD_TORCH_CHECK(tensor.dim() == 1, name, " must be rank 1");
|
|
245
|
+
STD_TORCH_CHECK(tensor.size(0) == length, name, " length must match CPML field axis");
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
void check_spacing_vector(
|
|
249
|
+
const torch::stable::Tensor& field,
|
|
250
|
+
const torch::stable::Tensor& inv_delta,
|
|
251
|
+
int64_t axis,
|
|
252
|
+
const char* name) {
|
|
253
|
+
check_vector_input(inv_delta, field.size(axis), name);
|
|
254
|
+
check_same_cuda_device(field, inv_delta, name);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
void check_magnetic_cpml_inputs(
|
|
258
|
+
const torch::stable::Tensor& field,
|
|
259
|
+
const torch::stable::Tensor& first,
|
|
260
|
+
const torch::stable::Tensor& second,
|
|
261
|
+
const torch::stable::Tensor& decay,
|
|
262
|
+
const torch::stable::Tensor& curl,
|
|
263
|
+
const torch::stable::Tensor& psi_first,
|
|
264
|
+
const torch::stable::Tensor& psi_second,
|
|
265
|
+
const torch::stable::Tensor& inv_kappa_first,
|
|
266
|
+
const torch::stable::Tensor& b_first,
|
|
267
|
+
const torch::stable::Tensor& c_first,
|
|
268
|
+
const torch::stable::Tensor& inv_kappa_second,
|
|
269
|
+
const torch::stable::Tensor& b_second,
|
|
270
|
+
const torch::stable::Tensor& c_second,
|
|
271
|
+
int64_t first_axis,
|
|
272
|
+
int64_t second_axis,
|
|
273
|
+
const char* name) {
|
|
274
|
+
check_magnetic_inputs(field, first, second, decay, curl, name);
|
|
275
|
+
check_float32_tensor(psi_first, "psi_first");
|
|
276
|
+
check_float32_tensor(psi_second, "psi_second");
|
|
277
|
+
check_same_cuda_device(field, psi_first, "psi_first");
|
|
278
|
+
check_same_cuda_device(field, psi_second, "psi_second");
|
|
279
|
+
check_contiguous_tensor(psi_first, "psi_first");
|
|
280
|
+
check_contiguous_tensor(psi_second, "psi_second");
|
|
281
|
+
STD_TORCH_CHECK(psi_first.sizes().equals(field.sizes()), "psi_first must match field shape");
|
|
282
|
+
STD_TORCH_CHECK(psi_second.sizes().equals(field.sizes()), "psi_second must match field shape");
|
|
283
|
+
check_vector_input(inv_kappa_first, field.size(first_axis), "inv_kappa_first");
|
|
284
|
+
check_vector_input(b_first, field.size(first_axis), "b_first");
|
|
285
|
+
check_vector_input(c_first, field.size(first_axis), "c_first");
|
|
286
|
+
check_vector_input(inv_kappa_second, field.size(second_axis), "inv_kappa_second");
|
|
287
|
+
check_vector_input(b_second, field.size(second_axis), "b_second");
|
|
288
|
+
check_vector_input(c_second, field.size(second_axis), "c_second");
|
|
289
|
+
check_same_cuda_device(field, inv_kappa_first, "inv_kappa_first");
|
|
290
|
+
check_same_cuda_device(field, b_first, "b_first");
|
|
291
|
+
check_same_cuda_device(field, c_first, "c_first");
|
|
292
|
+
check_same_cuda_device(field, inv_kappa_second, "inv_kappa_second");
|
|
293
|
+
check_same_cuda_device(field, b_second, "b_second");
|
|
294
|
+
check_same_cuda_device(field, c_second, "c_second");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
void check_compact_psi_input(
|
|
298
|
+
const torch::stable::Tensor& psi,
|
|
299
|
+
const torch::stable::Tensor& field,
|
|
300
|
+
int64_t axis,
|
|
301
|
+
int64_t low_length,
|
|
302
|
+
int64_t high_length,
|
|
303
|
+
const char* name) {
|
|
304
|
+
check_float32_tensor(psi, name);
|
|
305
|
+
check_same_cuda_device(field, psi, name);
|
|
306
|
+
check_contiguous_tensor(psi, name);
|
|
307
|
+
STD_TORCH_CHECK(psi.dim() == 3, name, " must be rank 3");
|
|
308
|
+
for (int64_t dim = 0; dim < 3; ++dim) {
|
|
309
|
+
const int64_t expected = dim == axis ? low_length + high_length : field.size(dim);
|
|
310
|
+
STD_TORCH_CHECK(psi.size(dim) == expected, name, " shape does not match compact CPML layout");
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
void check_magnetic_cpml_compressed_inputs(
|
|
315
|
+
const torch::stable::Tensor& field,
|
|
316
|
+
const torch::stable::Tensor& first,
|
|
317
|
+
const torch::stable::Tensor& second,
|
|
318
|
+
const torch::stable::Tensor& decay,
|
|
319
|
+
const torch::stable::Tensor& curl,
|
|
320
|
+
const torch::stable::Tensor& psi_first,
|
|
321
|
+
const torch::stable::Tensor& psi_second,
|
|
322
|
+
const torch::stable::Tensor& inv_kappa_first,
|
|
323
|
+
const torch::stable::Tensor& b_first,
|
|
324
|
+
const torch::stable::Tensor& c_first,
|
|
325
|
+
const torch::stable::Tensor& inv_kappa_second,
|
|
326
|
+
const torch::stable::Tensor& b_second,
|
|
327
|
+
const torch::stable::Tensor& c_second,
|
|
328
|
+
int64_t first_axis,
|
|
329
|
+
int64_t second_axis,
|
|
330
|
+
int64_t first_low_length,
|
|
331
|
+
int64_t first_high_length,
|
|
332
|
+
int64_t second_low_length,
|
|
333
|
+
int64_t second_high_length,
|
|
334
|
+
const char* name) {
|
|
335
|
+
check_magnetic_inputs(field, first, second, decay, curl, name);
|
|
336
|
+
check_compact_psi_input(psi_first, field, first_axis, first_low_length, first_high_length, "psi_first");
|
|
337
|
+
check_compact_psi_input(psi_second, field, second_axis, second_low_length, second_high_length, "psi_second");
|
|
338
|
+
check_vector_input(inv_kappa_first, field.size(first_axis), "inv_kappa_first");
|
|
339
|
+
check_vector_input(b_first, field.size(first_axis), "b_first");
|
|
340
|
+
check_vector_input(c_first, field.size(first_axis), "c_first");
|
|
341
|
+
check_vector_input(inv_kappa_second, field.size(second_axis), "inv_kappa_second");
|
|
342
|
+
check_vector_input(b_second, field.size(second_axis), "b_second");
|
|
343
|
+
check_vector_input(c_second, field.size(second_axis), "c_second");
|
|
344
|
+
check_same_cuda_device(field, inv_kappa_first, "inv_kappa_first");
|
|
345
|
+
check_same_cuda_device(field, b_first, "b_first");
|
|
346
|
+
check_same_cuda_device(field, c_first, "c_first");
|
|
347
|
+
check_same_cuda_device(field, inv_kappa_second, "inv_kappa_second");
|
|
348
|
+
check_same_cuda_device(field, b_second, "b_second");
|
|
349
|
+
check_same_cuda_device(field, c_second, "c_second");
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
} // namespace
|
|
353
|
+
|
|
354
|
+
void update_magnetic_hx_standard_cuda(
|
|
355
|
+
torch::stable::Tensor hx,
|
|
356
|
+
const torch::stable::Tensor& ey,
|
|
357
|
+
const torch::stable::Tensor& ez,
|
|
358
|
+
const torch::stable::Tensor& decay,
|
|
359
|
+
const torch::stable::Tensor& curl,
|
|
360
|
+
const torch::stable::Tensor& inv_dy,
|
|
361
|
+
const torch::stable::Tensor& inv_dz) {
|
|
362
|
+
check_magnetic_inputs(hx, ey, ez, decay, curl, "hx");
|
|
363
|
+
check_rank3_shape(ey, "ey", hx.size(0), hx.size(1), hx.size(2) + 1);
|
|
364
|
+
check_rank3_shape(ez, "ez", hx.size(0), hx.size(1) + 1, hx.size(2));
|
|
365
|
+
check_spacing_vector(hx, inv_dy, 1, "inv_dy");
|
|
366
|
+
check_spacing_vector(hx, inv_dz, 2, "inv_dz");
|
|
367
|
+
torch::stable::accelerator::DeviceGuard guard(hx.get_device_index());
|
|
368
|
+
const auto sizes = hx.sizes();
|
|
369
|
+
const dim3 block = field_block3d();
|
|
370
|
+
update_magnetic_standard_kernel<0><<<field_grid3d(sizes[0], sizes[1], sizes[2], block), block, 0, current_cuda_stream()>>>(
|
|
371
|
+
static_cast<unsigned int>(sizes[0]),
|
|
372
|
+
static_cast<unsigned int>(sizes[1]),
|
|
373
|
+
static_cast<unsigned int>(sizes[2]),
|
|
374
|
+
ey.mutable_data_ptr<float>(),
|
|
375
|
+
ez.mutable_data_ptr<float>(),
|
|
376
|
+
decay.mutable_data_ptr<float>(),
|
|
377
|
+
curl.mutable_data_ptr<float>(),
|
|
378
|
+
inv_dy.mutable_data_ptr<float>(),
|
|
379
|
+
inv_dz.mutable_data_ptr<float>(),
|
|
380
|
+
hx.mutable_data_ptr<float>());
|
|
381
|
+
WITWIN_CUDA_CHECK();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
void update_magnetic_hy_standard_cuda(
|
|
385
|
+
torch::stable::Tensor hy,
|
|
386
|
+
const torch::stable::Tensor& ex,
|
|
387
|
+
const torch::stable::Tensor& ez,
|
|
388
|
+
const torch::stable::Tensor& decay,
|
|
389
|
+
const torch::stable::Tensor& curl,
|
|
390
|
+
const torch::stable::Tensor& inv_dx,
|
|
391
|
+
const torch::stable::Tensor& inv_dz) {
|
|
392
|
+
check_magnetic_inputs(hy, ex, ez, decay, curl, "hy");
|
|
393
|
+
check_rank3_shape(ex, "ex", hy.size(0), hy.size(1), hy.size(2) + 1);
|
|
394
|
+
check_rank3_shape(ez, "ez", hy.size(0) + 1, hy.size(1), hy.size(2));
|
|
395
|
+
check_spacing_vector(hy, inv_dx, 0, "inv_dx");
|
|
396
|
+
check_spacing_vector(hy, inv_dz, 2, "inv_dz");
|
|
397
|
+
torch::stable::accelerator::DeviceGuard guard(hy.get_device_index());
|
|
398
|
+
const auto sizes = hy.sizes();
|
|
399
|
+
const dim3 block = field_block3d();
|
|
400
|
+
update_magnetic_standard_kernel<1><<<field_grid3d(sizes[0], sizes[1], sizes[2], block), block, 0, current_cuda_stream()>>>(
|
|
401
|
+
static_cast<unsigned int>(sizes[0]),
|
|
402
|
+
static_cast<unsigned int>(sizes[1]),
|
|
403
|
+
static_cast<unsigned int>(sizes[2]),
|
|
404
|
+
ex.mutable_data_ptr<float>(),
|
|
405
|
+
ez.mutable_data_ptr<float>(),
|
|
406
|
+
decay.mutable_data_ptr<float>(),
|
|
407
|
+
curl.mutable_data_ptr<float>(),
|
|
408
|
+
inv_dx.mutable_data_ptr<float>(),
|
|
409
|
+
inv_dz.mutable_data_ptr<float>(),
|
|
410
|
+
hy.mutable_data_ptr<float>());
|
|
411
|
+
WITWIN_CUDA_CHECK();
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
void update_magnetic_hz_standard_cuda(
|
|
415
|
+
torch::stable::Tensor hz,
|
|
416
|
+
const torch::stable::Tensor& ex,
|
|
417
|
+
const torch::stable::Tensor& ey,
|
|
418
|
+
const torch::stable::Tensor& decay,
|
|
419
|
+
const torch::stable::Tensor& curl,
|
|
420
|
+
const torch::stable::Tensor& inv_dx,
|
|
421
|
+
const torch::stable::Tensor& inv_dy) {
|
|
422
|
+
check_magnetic_inputs(hz, ex, ey, decay, curl, "hz");
|
|
423
|
+
check_rank3_shape(ex, "ex", hz.size(0), hz.size(1) + 1, hz.size(2));
|
|
424
|
+
check_rank3_shape(ey, "ey", hz.size(0) + 1, hz.size(1), hz.size(2));
|
|
425
|
+
check_spacing_vector(hz, inv_dx, 0, "inv_dx");
|
|
426
|
+
check_spacing_vector(hz, inv_dy, 1, "inv_dy");
|
|
427
|
+
torch::stable::accelerator::DeviceGuard guard(hz.get_device_index());
|
|
428
|
+
const auto sizes = hz.sizes();
|
|
429
|
+
const dim3 block = field_block3d();
|
|
430
|
+
update_magnetic_standard_kernel<2><<<field_grid3d(sizes[0], sizes[1], sizes[2], block), block, 0, current_cuda_stream()>>>(
|
|
431
|
+
static_cast<unsigned int>(sizes[0]),
|
|
432
|
+
static_cast<unsigned int>(sizes[1]),
|
|
433
|
+
static_cast<unsigned int>(sizes[2]),
|
|
434
|
+
ex.mutable_data_ptr<float>(),
|
|
435
|
+
ey.mutable_data_ptr<float>(),
|
|
436
|
+
decay.mutable_data_ptr<float>(),
|
|
437
|
+
curl.mutable_data_ptr<float>(),
|
|
438
|
+
inv_dx.mutable_data_ptr<float>(),
|
|
439
|
+
inv_dy.mutable_data_ptr<float>(),
|
|
440
|
+
hz.mutable_data_ptr<float>());
|
|
441
|
+
WITWIN_CUDA_CHECK();
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
void update_magnetic_hx_cpml_cuda(
|
|
445
|
+
torch::stable::Tensor hx,
|
|
446
|
+
const torch::stable::Tensor& ey,
|
|
447
|
+
const torch::stable::Tensor& ez,
|
|
448
|
+
const torch::stable::Tensor& decay,
|
|
449
|
+
const torch::stable::Tensor& curl,
|
|
450
|
+
torch::stable::Tensor psi_y,
|
|
451
|
+
torch::stable::Tensor psi_z,
|
|
452
|
+
const torch::stable::Tensor& inv_kappa_y,
|
|
453
|
+
const torch::stable::Tensor& b_y,
|
|
454
|
+
const torch::stable::Tensor& c_y,
|
|
455
|
+
const torch::stable::Tensor& inv_kappa_z,
|
|
456
|
+
const torch::stable::Tensor& b_z,
|
|
457
|
+
const torch::stable::Tensor& c_z,
|
|
458
|
+
const torch::stable::Tensor& inv_dy,
|
|
459
|
+
const torch::stable::Tensor& inv_dz) {
|
|
460
|
+
check_magnetic_cpml_inputs(
|
|
461
|
+
hx, ey, ez, decay, curl, psi_y, psi_z, inv_kappa_y, b_y, c_y, inv_kappa_z, b_z, c_z, 1, 2, "hx");
|
|
462
|
+
check_rank3_shape(ey, "ey", hx.size(0), hx.size(1), hx.size(2) + 1);
|
|
463
|
+
check_rank3_shape(ez, "ez", hx.size(0), hx.size(1) + 1, hx.size(2));
|
|
464
|
+
check_spacing_vector(hx, inv_dy, 1, "inv_dy");
|
|
465
|
+
check_spacing_vector(hx, inv_dz, 2, "inv_dz");
|
|
466
|
+
torch::stable::accelerator::DeviceGuard guard(hx.get_device_index());
|
|
467
|
+
const auto sizes = hx.sizes();
|
|
468
|
+
const dim3 block = field_block3d();
|
|
469
|
+
update_magnetic_cpml_kernel<0><<<field_grid3d(sizes[0], sizes[1], sizes[2], block), block, 0, current_cuda_stream()>>>(
|
|
470
|
+
static_cast<unsigned int>(sizes[0]),
|
|
471
|
+
static_cast<unsigned int>(sizes[1]),
|
|
472
|
+
static_cast<unsigned int>(sizes[2]),
|
|
473
|
+
ey.mutable_data_ptr<float>(),
|
|
474
|
+
ez.mutable_data_ptr<float>(),
|
|
475
|
+
decay.mutable_data_ptr<float>(),
|
|
476
|
+
curl.mutable_data_ptr<float>(),
|
|
477
|
+
inv_kappa_y.mutable_data_ptr<float>(),
|
|
478
|
+
b_y.mutable_data_ptr<float>(),
|
|
479
|
+
c_y.mutable_data_ptr<float>(),
|
|
480
|
+
inv_kappa_z.mutable_data_ptr<float>(),
|
|
481
|
+
b_z.mutable_data_ptr<float>(),
|
|
482
|
+
c_z.mutable_data_ptr<float>(),
|
|
483
|
+
inv_dy.mutable_data_ptr<float>(),
|
|
484
|
+
inv_dz.mutable_data_ptr<float>(),
|
|
485
|
+
psi_y.mutable_data_ptr<float>(),
|
|
486
|
+
psi_z.mutable_data_ptr<float>(),
|
|
487
|
+
hx.mutable_data_ptr<float>());
|
|
488
|
+
WITWIN_CUDA_CHECK();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
void update_magnetic_hy_cpml_cuda(
|
|
492
|
+
torch::stable::Tensor hy,
|
|
493
|
+
const torch::stable::Tensor& ex,
|
|
494
|
+
const torch::stable::Tensor& ez,
|
|
495
|
+
const torch::stable::Tensor& decay,
|
|
496
|
+
const torch::stable::Tensor& curl,
|
|
497
|
+
torch::stable::Tensor psi_x,
|
|
498
|
+
torch::stable::Tensor psi_z,
|
|
499
|
+
const torch::stable::Tensor& inv_kappa_x,
|
|
500
|
+
const torch::stable::Tensor& b_x,
|
|
501
|
+
const torch::stable::Tensor& c_x,
|
|
502
|
+
const torch::stable::Tensor& inv_kappa_z,
|
|
503
|
+
const torch::stable::Tensor& b_z,
|
|
504
|
+
const torch::stable::Tensor& c_z,
|
|
505
|
+
const torch::stable::Tensor& inv_dx,
|
|
506
|
+
const torch::stable::Tensor& inv_dz) {
|
|
507
|
+
check_magnetic_cpml_inputs(
|
|
508
|
+
hy, ex, ez, decay, curl, psi_x, psi_z, inv_kappa_x, b_x, c_x, inv_kappa_z, b_z, c_z, 0, 2, "hy");
|
|
509
|
+
check_rank3_shape(ex, "ex", hy.size(0), hy.size(1), hy.size(2) + 1);
|
|
510
|
+
check_rank3_shape(ez, "ez", hy.size(0) + 1, hy.size(1), hy.size(2));
|
|
511
|
+
check_spacing_vector(hy, inv_dx, 0, "inv_dx");
|
|
512
|
+
check_spacing_vector(hy, inv_dz, 2, "inv_dz");
|
|
513
|
+
torch::stable::accelerator::DeviceGuard guard(hy.get_device_index());
|
|
514
|
+
const auto sizes = hy.sizes();
|
|
515
|
+
const dim3 block = field_block3d();
|
|
516
|
+
update_magnetic_cpml_kernel<1><<<field_grid3d(sizes[0], sizes[1], sizes[2], block), block, 0, current_cuda_stream()>>>(
|
|
517
|
+
static_cast<unsigned int>(sizes[0]),
|
|
518
|
+
static_cast<unsigned int>(sizes[1]),
|
|
519
|
+
static_cast<unsigned int>(sizes[2]),
|
|
520
|
+
ex.mutable_data_ptr<float>(),
|
|
521
|
+
ez.mutable_data_ptr<float>(),
|
|
522
|
+
decay.mutable_data_ptr<float>(),
|
|
523
|
+
curl.mutable_data_ptr<float>(),
|
|
524
|
+
inv_kappa_x.mutable_data_ptr<float>(),
|
|
525
|
+
b_x.mutable_data_ptr<float>(),
|
|
526
|
+
c_x.mutable_data_ptr<float>(),
|
|
527
|
+
inv_kappa_z.mutable_data_ptr<float>(),
|
|
528
|
+
b_z.mutable_data_ptr<float>(),
|
|
529
|
+
c_z.mutable_data_ptr<float>(),
|
|
530
|
+
inv_dx.mutable_data_ptr<float>(),
|
|
531
|
+
inv_dz.mutable_data_ptr<float>(),
|
|
532
|
+
psi_x.mutable_data_ptr<float>(),
|
|
533
|
+
psi_z.mutable_data_ptr<float>(),
|
|
534
|
+
hy.mutable_data_ptr<float>());
|
|
535
|
+
WITWIN_CUDA_CHECK();
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
void update_magnetic_hz_cpml_cuda(
|
|
539
|
+
torch::stable::Tensor hz,
|
|
540
|
+
const torch::stable::Tensor& ex,
|
|
541
|
+
const torch::stable::Tensor& ey,
|
|
542
|
+
const torch::stable::Tensor& decay,
|
|
543
|
+
const torch::stable::Tensor& curl,
|
|
544
|
+
torch::stable::Tensor psi_x,
|
|
545
|
+
torch::stable::Tensor psi_y,
|
|
546
|
+
const torch::stable::Tensor& inv_kappa_x,
|
|
547
|
+
const torch::stable::Tensor& b_x,
|
|
548
|
+
const torch::stable::Tensor& c_x,
|
|
549
|
+
const torch::stable::Tensor& inv_kappa_y,
|
|
550
|
+
const torch::stable::Tensor& b_y,
|
|
551
|
+
const torch::stable::Tensor& c_y,
|
|
552
|
+
const torch::stable::Tensor& inv_dx,
|
|
553
|
+
const torch::stable::Tensor& inv_dy) {
|
|
554
|
+
check_magnetic_cpml_inputs(
|
|
555
|
+
hz, ex, ey, decay, curl, psi_x, psi_y, inv_kappa_x, b_x, c_x, inv_kappa_y, b_y, c_y, 0, 1, "hz");
|
|
556
|
+
check_rank3_shape(ex, "ex", hz.size(0), hz.size(1) + 1, hz.size(2));
|
|
557
|
+
check_rank3_shape(ey, "ey", hz.size(0) + 1, hz.size(1), hz.size(2));
|
|
558
|
+
check_spacing_vector(hz, inv_dx, 0, "inv_dx");
|
|
559
|
+
check_spacing_vector(hz, inv_dy, 1, "inv_dy");
|
|
560
|
+
torch::stable::accelerator::DeviceGuard guard(hz.get_device_index());
|
|
561
|
+
const auto sizes = hz.sizes();
|
|
562
|
+
const dim3 block = field_block3d();
|
|
563
|
+
update_magnetic_cpml_kernel<2><<<field_grid3d(sizes[0], sizes[1], sizes[2], block), block, 0, current_cuda_stream()>>>(
|
|
564
|
+
static_cast<unsigned int>(sizes[0]),
|
|
565
|
+
static_cast<unsigned int>(sizes[1]),
|
|
566
|
+
static_cast<unsigned int>(sizes[2]),
|
|
567
|
+
ex.mutable_data_ptr<float>(),
|
|
568
|
+
ey.mutable_data_ptr<float>(),
|
|
569
|
+
decay.mutable_data_ptr<float>(),
|
|
570
|
+
curl.mutable_data_ptr<float>(),
|
|
571
|
+
inv_kappa_x.mutable_data_ptr<float>(),
|
|
572
|
+
b_x.mutable_data_ptr<float>(),
|
|
573
|
+
c_x.mutable_data_ptr<float>(),
|
|
574
|
+
inv_kappa_y.mutable_data_ptr<float>(),
|
|
575
|
+
b_y.mutable_data_ptr<float>(),
|
|
576
|
+
c_y.mutable_data_ptr<float>(),
|
|
577
|
+
inv_dx.mutable_data_ptr<float>(),
|
|
578
|
+
inv_dy.mutable_data_ptr<float>(),
|
|
579
|
+
psi_x.mutable_data_ptr<float>(),
|
|
580
|
+
psi_y.mutable_data_ptr<float>(),
|
|
581
|
+
hz.mutable_data_ptr<float>());
|
|
582
|
+
WITWIN_CUDA_CHECK();
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
void update_magnetic_hx_cpml_compressed_cuda(
|
|
586
|
+
torch::stable::Tensor hx,
|
|
587
|
+
const torch::stable::Tensor& ey,
|
|
588
|
+
const torch::stable::Tensor& ez,
|
|
589
|
+
const torch::stable::Tensor& decay,
|
|
590
|
+
const torch::stable::Tensor& curl,
|
|
591
|
+
torch::stable::Tensor psi_y,
|
|
592
|
+
torch::stable::Tensor psi_z,
|
|
593
|
+
const torch::stable::Tensor& inv_kappa_y,
|
|
594
|
+
const torch::stable::Tensor& b_y,
|
|
595
|
+
const torch::stable::Tensor& c_y,
|
|
596
|
+
const torch::stable::Tensor& inv_kappa_z,
|
|
597
|
+
const torch::stable::Tensor& b_z,
|
|
598
|
+
const torch::stable::Tensor& c_z,
|
|
599
|
+
const torch::stable::Tensor& inv_dy,
|
|
600
|
+
const torch::stable::Tensor& inv_dz,
|
|
601
|
+
int64_t y_low_length,
|
|
602
|
+
int64_t y_high_start,
|
|
603
|
+
int64_t y_high_length,
|
|
604
|
+
int64_t z_low_length,
|
|
605
|
+
int64_t z_high_start,
|
|
606
|
+
int64_t z_high_length,
|
|
607
|
+
std::optional<double> uniform_decay,
|
|
608
|
+
std::optional<double> uniform_curl) {
|
|
609
|
+
check_magnetic_cpml_compressed_inputs(
|
|
610
|
+
hx, ey, ez, decay, curl, psi_y, psi_z, inv_kappa_y, b_y, c_y, inv_kappa_z, b_z, c_z,
|
|
611
|
+
1, 2, y_low_length, y_high_length, z_low_length, z_high_length, "hx");
|
|
612
|
+
check_rank3_shape(ey, "ey", hx.size(0), hx.size(1), hx.size(2) + 1);
|
|
613
|
+
check_rank3_shape(ez, "ez", hx.size(0), hx.size(1) + 1, hx.size(2));
|
|
614
|
+
check_spacing_vector(hx, inv_dy, 1, "inv_dy");
|
|
615
|
+
check_spacing_vector(hx, inv_dz, 2, "inv_dz");
|
|
616
|
+
torch::stable::accelerator::DeviceGuard guard(hx.get_device_index());
|
|
617
|
+
const auto sizes = hx.sizes();
|
|
618
|
+
const dim3 block = field_block3d();
|
|
619
|
+
dispatch_uniform_coefficients(uniform_decay.has_value(), uniform_curl.has_value(), [&](auto u_decay, auto u_curl) {
|
|
620
|
+
update_magnetic_cpml_compressed_kernel<0, decltype(u_decay)::value, decltype(u_curl)::value><<<field_grid3d(sizes[0], sizes[1], sizes[2], block), block, 0, current_cuda_stream()>>>(
|
|
621
|
+
static_cast<unsigned int>(sizes[0]),
|
|
622
|
+
static_cast<unsigned int>(sizes[1]),
|
|
623
|
+
static_cast<unsigned int>(sizes[2]),
|
|
624
|
+
ey.mutable_data_ptr<float>(),
|
|
625
|
+
ez.mutable_data_ptr<float>(),
|
|
626
|
+
decay.mutable_data_ptr<float>(),
|
|
627
|
+
curl.mutable_data_ptr<float>(),
|
|
628
|
+
static_cast<float>(uniform_decay.value_or(0.0)),
|
|
629
|
+
static_cast<float>(uniform_curl.value_or(0.0)),
|
|
630
|
+
inv_kappa_y.mutable_data_ptr<float>(),
|
|
631
|
+
b_y.mutable_data_ptr<float>(),
|
|
632
|
+
c_y.mutable_data_ptr<float>(),
|
|
633
|
+
inv_kappa_z.mutable_data_ptr<float>(),
|
|
634
|
+
b_z.mutable_data_ptr<float>(),
|
|
635
|
+
c_z.mutable_data_ptr<float>(),
|
|
636
|
+
inv_dy.mutable_data_ptr<float>(),
|
|
637
|
+
inv_dz.mutable_data_ptr<float>(),
|
|
638
|
+
static_cast<int>(y_low_length),
|
|
639
|
+
static_cast<int>(y_high_start),
|
|
640
|
+
static_cast<int>(y_high_length),
|
|
641
|
+
static_cast<int>(z_low_length),
|
|
642
|
+
static_cast<int>(z_high_start),
|
|
643
|
+
static_cast<int>(z_high_length),
|
|
644
|
+
psi_y.mutable_data_ptr<float>(),
|
|
645
|
+
psi_z.mutable_data_ptr<float>(),
|
|
646
|
+
hx.mutable_data_ptr<float>());
|
|
647
|
+
});
|
|
648
|
+
WITWIN_CUDA_CHECK();
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
void update_magnetic_hy_cpml_compressed_cuda(
|
|
652
|
+
torch::stable::Tensor hy,
|
|
653
|
+
const torch::stable::Tensor& ex,
|
|
654
|
+
const torch::stable::Tensor& ez,
|
|
655
|
+
const torch::stable::Tensor& decay,
|
|
656
|
+
const torch::stable::Tensor& curl,
|
|
657
|
+
torch::stable::Tensor psi_x,
|
|
658
|
+
torch::stable::Tensor psi_z,
|
|
659
|
+
const torch::stable::Tensor& inv_kappa_x,
|
|
660
|
+
const torch::stable::Tensor& b_x,
|
|
661
|
+
const torch::stable::Tensor& c_x,
|
|
662
|
+
const torch::stable::Tensor& inv_kappa_z,
|
|
663
|
+
const torch::stable::Tensor& b_z,
|
|
664
|
+
const torch::stable::Tensor& c_z,
|
|
665
|
+
const torch::stable::Tensor& inv_dx,
|
|
666
|
+
const torch::stable::Tensor& inv_dz,
|
|
667
|
+
int64_t x_low_length,
|
|
668
|
+
int64_t x_high_start,
|
|
669
|
+
int64_t x_high_length,
|
|
670
|
+
int64_t z_low_length,
|
|
671
|
+
int64_t z_high_start,
|
|
672
|
+
int64_t z_high_length,
|
|
673
|
+
std::optional<double> uniform_decay,
|
|
674
|
+
std::optional<double> uniform_curl) {
|
|
675
|
+
check_magnetic_cpml_compressed_inputs(
|
|
676
|
+
hy, ex, ez, decay, curl, psi_x, psi_z, inv_kappa_x, b_x, c_x, inv_kappa_z, b_z, c_z,
|
|
677
|
+
0, 2, x_low_length, x_high_length, z_low_length, z_high_length, "hy");
|
|
678
|
+
check_rank3_shape(ex, "ex", hy.size(0), hy.size(1), hy.size(2) + 1);
|
|
679
|
+
check_rank3_shape(ez, "ez", hy.size(0) + 1, hy.size(1), hy.size(2));
|
|
680
|
+
check_spacing_vector(hy, inv_dx, 0, "inv_dx");
|
|
681
|
+
check_spacing_vector(hy, inv_dz, 2, "inv_dz");
|
|
682
|
+
torch::stable::accelerator::DeviceGuard guard(hy.get_device_index());
|
|
683
|
+
const auto sizes = hy.sizes();
|
|
684
|
+
const dim3 block = field_block3d();
|
|
685
|
+
dispatch_uniform_coefficients(uniform_decay.has_value(), uniform_curl.has_value(), [&](auto u_decay, auto u_curl) {
|
|
686
|
+
update_magnetic_cpml_compressed_kernel<1, decltype(u_decay)::value, decltype(u_curl)::value><<<field_grid3d(sizes[0], sizes[1], sizes[2], block), block, 0, current_cuda_stream()>>>(
|
|
687
|
+
static_cast<unsigned int>(sizes[0]),
|
|
688
|
+
static_cast<unsigned int>(sizes[1]),
|
|
689
|
+
static_cast<unsigned int>(sizes[2]),
|
|
690
|
+
ex.mutable_data_ptr<float>(),
|
|
691
|
+
ez.mutable_data_ptr<float>(),
|
|
692
|
+
decay.mutable_data_ptr<float>(),
|
|
693
|
+
curl.mutable_data_ptr<float>(),
|
|
694
|
+
static_cast<float>(uniform_decay.value_or(0.0)),
|
|
695
|
+
static_cast<float>(uniform_curl.value_or(0.0)),
|
|
696
|
+
inv_kappa_x.mutable_data_ptr<float>(),
|
|
697
|
+
b_x.mutable_data_ptr<float>(),
|
|
698
|
+
c_x.mutable_data_ptr<float>(),
|
|
699
|
+
inv_kappa_z.mutable_data_ptr<float>(),
|
|
700
|
+
b_z.mutable_data_ptr<float>(),
|
|
701
|
+
c_z.mutable_data_ptr<float>(),
|
|
702
|
+
inv_dx.mutable_data_ptr<float>(),
|
|
703
|
+
inv_dz.mutable_data_ptr<float>(),
|
|
704
|
+
static_cast<int>(x_low_length),
|
|
705
|
+
static_cast<int>(x_high_start),
|
|
706
|
+
static_cast<int>(x_high_length),
|
|
707
|
+
static_cast<int>(z_low_length),
|
|
708
|
+
static_cast<int>(z_high_start),
|
|
709
|
+
static_cast<int>(z_high_length),
|
|
710
|
+
psi_x.mutable_data_ptr<float>(),
|
|
711
|
+
psi_z.mutable_data_ptr<float>(),
|
|
712
|
+
hy.mutable_data_ptr<float>());
|
|
713
|
+
});
|
|
714
|
+
WITWIN_CUDA_CHECK();
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
void update_magnetic_hz_cpml_compressed_cuda(
|
|
718
|
+
torch::stable::Tensor hz,
|
|
719
|
+
const torch::stable::Tensor& ex,
|
|
720
|
+
const torch::stable::Tensor& ey,
|
|
721
|
+
const torch::stable::Tensor& decay,
|
|
722
|
+
const torch::stable::Tensor& curl,
|
|
723
|
+
torch::stable::Tensor psi_x,
|
|
724
|
+
torch::stable::Tensor psi_y,
|
|
725
|
+
const torch::stable::Tensor& inv_kappa_x,
|
|
726
|
+
const torch::stable::Tensor& b_x,
|
|
727
|
+
const torch::stable::Tensor& c_x,
|
|
728
|
+
const torch::stable::Tensor& inv_kappa_y,
|
|
729
|
+
const torch::stable::Tensor& b_y,
|
|
730
|
+
const torch::stable::Tensor& c_y,
|
|
731
|
+
const torch::stable::Tensor& inv_dx,
|
|
732
|
+
const torch::stable::Tensor& inv_dy,
|
|
733
|
+
int64_t x_low_length,
|
|
734
|
+
int64_t x_high_start,
|
|
735
|
+
int64_t x_high_length,
|
|
736
|
+
int64_t y_low_length,
|
|
737
|
+
int64_t y_high_start,
|
|
738
|
+
int64_t y_high_length,
|
|
739
|
+
std::optional<double> uniform_decay,
|
|
740
|
+
std::optional<double> uniform_curl) {
|
|
741
|
+
check_magnetic_cpml_compressed_inputs(
|
|
742
|
+
hz, ex, ey, decay, curl, psi_x, psi_y, inv_kappa_x, b_x, c_x, inv_kappa_y, b_y, c_y,
|
|
743
|
+
0, 1, x_low_length, x_high_length, y_low_length, y_high_length, "hz");
|
|
744
|
+
check_rank3_shape(ex, "ex", hz.size(0), hz.size(1) + 1, hz.size(2));
|
|
745
|
+
check_rank3_shape(ey, "ey", hz.size(0) + 1, hz.size(1), hz.size(2));
|
|
746
|
+
check_spacing_vector(hz, inv_dx, 0, "inv_dx");
|
|
747
|
+
check_spacing_vector(hz, inv_dy, 1, "inv_dy");
|
|
748
|
+
torch::stable::accelerator::DeviceGuard guard(hz.get_device_index());
|
|
749
|
+
const auto sizes = hz.sizes();
|
|
750
|
+
const dim3 block = field_block3d();
|
|
751
|
+
dispatch_uniform_coefficients(uniform_decay.has_value(), uniform_curl.has_value(), [&](auto u_decay, auto u_curl) {
|
|
752
|
+
update_magnetic_cpml_compressed_kernel<2, decltype(u_decay)::value, decltype(u_curl)::value><<<field_grid3d(sizes[0], sizes[1], sizes[2], block), block, 0, current_cuda_stream()>>>(
|
|
753
|
+
static_cast<unsigned int>(sizes[0]),
|
|
754
|
+
static_cast<unsigned int>(sizes[1]),
|
|
755
|
+
static_cast<unsigned int>(sizes[2]),
|
|
756
|
+
ex.mutable_data_ptr<float>(),
|
|
757
|
+
ey.mutable_data_ptr<float>(),
|
|
758
|
+
decay.mutable_data_ptr<float>(),
|
|
759
|
+
curl.mutable_data_ptr<float>(),
|
|
760
|
+
static_cast<float>(uniform_decay.value_or(0.0)),
|
|
761
|
+
static_cast<float>(uniform_curl.value_or(0.0)),
|
|
762
|
+
inv_kappa_x.mutable_data_ptr<float>(),
|
|
763
|
+
b_x.mutable_data_ptr<float>(),
|
|
764
|
+
c_x.mutable_data_ptr<float>(),
|
|
765
|
+
inv_kappa_y.mutable_data_ptr<float>(),
|
|
766
|
+
b_y.mutable_data_ptr<float>(),
|
|
767
|
+
c_y.mutable_data_ptr<float>(),
|
|
768
|
+
inv_dx.mutable_data_ptr<float>(),
|
|
769
|
+
inv_dy.mutable_data_ptr<float>(),
|
|
770
|
+
static_cast<int>(x_low_length),
|
|
771
|
+
static_cast<int>(x_high_start),
|
|
772
|
+
static_cast<int>(x_high_length),
|
|
773
|
+
static_cast<int>(y_low_length),
|
|
774
|
+
static_cast<int>(y_high_start),
|
|
775
|
+
static_cast<int>(y_high_length),
|
|
776
|
+
psi_x.mutable_data_ptr<float>(),
|
|
777
|
+
psi_y.mutable_data_ptr<float>(),
|
|
778
|
+
hz.mutable_data_ptr<float>());
|
|
779
|
+
});
|
|
780
|
+
WITWIN_CUDA_CHECK();
|
|
781
|
+
}
|