symcrys 0.11.0 → 0.12.0
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.
- package/dist/coordinates.d.ts +143 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +198 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/crystalClasses.d.ts +28 -3
- package/dist/crystalClasses.d.ts.map +1 -1
- package/dist/crystalClasses.js +32 -3
- package/dist/crystalClasses.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/indices.d.ts +3 -19
- package/dist/indices.d.ts.map +1 -1
- package/dist/indices.js +3 -24
- package/dist/indices.js.map +1 -1
- package/dist/magnetic.d.ts +3 -1
- package/dist/magnetic.d.ts.map +1 -1
- package/dist/magnetic.js +3 -1
- package/dist/magnetic.js.map +1 -1
- package/dist/plane.d.ts +158 -3
- package/dist/plane.d.ts.map +1 -1
- package/dist/plane.js +166 -41
- package/dist/plane.js.map +1 -1
- package/dist/pointGroups/pointGroups.d.ts +15 -6
- package/dist/pointGroups/pointGroups.d.ts.map +1 -1
- package/dist/pointGroups/pointGroups.js +52 -5
- package/dist/pointGroups/pointGroups.js.map +1 -1
- package/dist/pointGroups/shubnikovData.d.ts +11 -0
- package/dist/pointGroups/shubnikovData.d.ts.map +1 -0
- package/dist/pointGroups/shubnikovData.js +101 -0
- package/dist/pointGroups/shubnikovData.js.map +1 -0
- package/dist/spaceGroups/describe.d.ts +3 -2
- package/dist/spaceGroups/describe.d.ts.map +1 -1
- package/dist/spaceGroups/describe.js.map +1 -1
- package/dist/spaceGroups/planeGroupData.d.ts +2 -0
- package/dist/spaceGroups/planeGroupData.d.ts.map +1 -1
- package/dist/spaceGroups/planeGroupData.js +17 -0
- package/dist/spaceGroups/planeGroupData.js.map +1 -1
- package/dist/spaceGroups/planeLattice.d.ts +78 -0
- package/dist/spaceGroups/planeLattice.d.ts.map +1 -0
- package/dist/spaceGroups/planeLattice.js +143 -0
- package/dist/spaceGroups/planeLattice.js.map +1 -0
- package/dist/spaceGroups/planePointGroups.d.ts +6 -2
- package/dist/spaceGroups/planePointGroups.d.ts.map +1 -1
- package/dist/spaceGroups/planePointGroups.js +14 -2
- package/dist/spaceGroups/planePointGroups.js.map +1 -1
- package/dist/spaceGroups/rational.d.ts +18 -0
- package/dist/spaceGroups/rational.d.ts.map +1 -1
- package/dist/spaceGroups/rational.js +58 -0
- package/dist/spaceGroups/rational.js.map +1 -1
- package/dist/tensors/voigt.d.ts +56 -0
- package/dist/tensors/voigt.d.ts.map +1 -0
- package/dist/tensors/voigt.js +188 -0
- package/dist/tensors/voigt.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/coordinates.ts +370 -0
- package/src/crystalClasses.ts +42 -3
- package/src/index.ts +12 -2
- package/src/indices.ts +3 -33
- package/src/magnetic.ts +10 -2
- package/src/plane.ts +302 -48
- package/src/pointGroups/pointGroups.ts +58 -6
- package/src/pointGroups/shubnikovData.ts +103 -0
- package/src/spaceGroups/describe.ts +3 -2
- package/src/spaceGroups/planeGroupData.ts +19 -0
- package/src/spaceGroups/planeLattice.ts +208 -0
- package/src/spaceGroups/planePointGroups.ts +23 -3
- package/src/spaceGroups/rational.ts +59 -0
- package/src/tensors/voigt.ts +268 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voigt's two-index notation of tensors with symmetric index pairs, as ITC Vol. D (2013) writes it
|
|
3
|
+
* (§ 1.1.4.10, pp. 24–27; eq. (1.5.7.4), p. 134): an index pair ij becomes one index α = 1…6 for
|
|
4
|
+
* 11, 22, 33, 23, 31, 12 (eq. (1.1.4.6)), and the components with α = 4, 5, 6 carry a factor 1 or 2
|
|
5
|
+
* per pair, as ITC defines the quantity (#137 E3, decided by Thomas on 2026-11-25).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { checkOptions, shown } from '../checks.js';
|
|
9
|
+
import { deepFreeze } from '../freeze.js';
|
|
10
|
+
import { toleranceOf, type ToleranceOptions } from '../tolerances.js';
|
|
11
|
+
import { type TensorPropertyName } from './propertyTable.js';
|
|
12
|
+
import { checkedSpec, type SignedPermutation, type TensorSpec } from './tensorForm.js';
|
|
13
|
+
|
|
14
|
+
/** The factor of the components of a Voigt index α = 4, 5, 6: 2 where ITC sums the two symmetric components (t_ij + t_ji), 1 where it takes one. */
|
|
15
|
+
export type VoigtFactor = 1 | 2;
|
|
16
|
+
|
|
17
|
+
/** The options of `toVoigt` and `fromVoigt`. */
|
|
18
|
+
export interface VoigtOptions extends ToleranceOptions {
|
|
19
|
+
/**
|
|
20
|
+
* The factor of each contracted index pair, in the order of the pairs: 2 where ITC defines the
|
|
21
|
+
* Voigt component as the sum of the two symmetric components, 1 where it is the component itself
|
|
22
|
+
* (ITC Vol. D § 1.1.4.10). So the strain (S₄ = 2S₂₃), the piezoelectric d (d_iα = d_ijk + d_ikj)
|
|
23
|
+
* and the piezomagnetic Λ take `[2]`, the compliances s and the electrostriction Q `[2, 2]`; the
|
|
24
|
+
* stress and the piezoelectric e take `[1]`, the stiffnesses c and the elasto-optic p `[1, 1]`;
|
|
25
|
+
* the piezo-optic π takes `[1, 2]`; the susceptibility of second-harmonic generation, which has
|
|
26
|
+
* the tensor of `'piezoelectric'`, takes `[1]` (§ 1.7.2.2.1.3, p. 185). Required, except for
|
|
27
|
+
* `'piezomagnetic'`, which takes ITC's `[2]` (eq. (1.5.7.4)); `'piezoelectric'` has none, since
|
|
28
|
+
* its tensor serves both d and second-harmonic generation.
|
|
29
|
+
*/
|
|
30
|
+
readonly factors?: readonly VoigtFactor[];
|
|
31
|
+
/**
|
|
32
|
+
* The index symmetry of the tensor (or of the tensor of a Voigt array) is checked within this
|
|
33
|
+
* tolerance, relative to its largest component; default `EPSILON` (10⁻⁶).
|
|
34
|
+
*/
|
|
35
|
+
readonly tolerance?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The index pair of α = 1…6, eq. (1.1.4.6): 11, 22, 33, 23, 31, 12. */
|
|
39
|
+
const PAIR: readonly (readonly [number, number])[] = [
|
|
40
|
+
[0, 0],
|
|
41
|
+
[1, 1],
|
|
42
|
+
[2, 2],
|
|
43
|
+
[1, 2],
|
|
44
|
+
[2, 0],
|
|
45
|
+
[0, 1],
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
/** α (0-based) of an index pair. */
|
|
49
|
+
const ALPHA = [
|
|
50
|
+
[0, 5, 4],
|
|
51
|
+
[5, 1, 3],
|
|
52
|
+
[4, 3, 2],
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* ITC's factors of the named properties that ITC writes in Voigt's notation with one convention
|
|
57
|
+
* only; 'piezoelectric' has none, since its tensor is also that of second-harmonic generation, which
|
|
58
|
+
* ITC contracts without the factor 2 (§ 1.7.2.2.1.3, p. 185).
|
|
59
|
+
*/
|
|
60
|
+
const PROPERTY_FACTORS: Partial<Readonly<Record<TensorPropertyName, readonly VoigtFactor[]>>> = {
|
|
61
|
+
piezomagnetic: [2],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** The contracted pairs of a specification: the positions of their first index, and the layout. */
|
|
65
|
+
interface Layout {
|
|
66
|
+
readonly rank: number;
|
|
67
|
+
/** The first index of each contracted pair, in order. */
|
|
68
|
+
readonly pairs: readonly number[];
|
|
69
|
+
/** The shape of the Voigt array: [6], [3, 6], [6, 3] or [6, 6]. */
|
|
70
|
+
readonly shape: readonly number[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function layoutOf(spec: TensorSpec, who: string): Layout {
|
|
74
|
+
const { rank, intrinsic } = spec;
|
|
75
|
+
const symmetric = ['symmetric-first-pair', 'symmetric-last-pair', 'totally-symmetric'];
|
|
76
|
+
if (rank === 2 && symmetric.includes(intrinsic)) return { rank, pairs: [0], shape: [6] };
|
|
77
|
+
if (rank === 3 && (intrinsic === 'symmetric-last-pair' || intrinsic === 'totally-symmetric')) {
|
|
78
|
+
return { rank, pairs: [1], shape: [3, 6] };
|
|
79
|
+
}
|
|
80
|
+
if (rank === 3 && intrinsic === 'symmetric-first-pair') return { rank, pairs: [0], shape: [6, 3] };
|
|
81
|
+
if (rank === 4 && ['symmetric-pairs', 'symmetric-pairs-exchangeable', 'totally-symmetric'].includes(intrinsic)) {
|
|
82
|
+
return { rank, pairs: [0, 2], shape: [6, 6] };
|
|
83
|
+
}
|
|
84
|
+
throw new RangeError(
|
|
85
|
+
`${who}: Voigt's notation needs a symmetric index pair (rank 2 'symmetric-first-pair', 'symmetric-last-pair' ` +
|
|
86
|
+
`or 'totally-symmetric'; rank 3 'symmetric-last-pair', 'symmetric-first-pair' or 'totally-symmetric'; rank 4 ` +
|
|
87
|
+
`'symmetric-pairs', 'symmetric-pairs-exchangeable' or 'totally-symmetric'), not rank ${rank} '${intrinsic}'`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function factorsOf(
|
|
92
|
+
specOrName: TensorSpec | TensorPropertyName,
|
|
93
|
+
layout: Layout,
|
|
94
|
+
options: VoigtOptions | undefined,
|
|
95
|
+
who: string,
|
|
96
|
+
): readonly VoigtFactor[] {
|
|
97
|
+
const given: unknown = options?.factors;
|
|
98
|
+
const factors =
|
|
99
|
+
given !== undefined ? given : typeof specOrName === 'string' ? PROPERTY_FACTORS[specOrName] : undefined;
|
|
100
|
+
if (factors === undefined) {
|
|
101
|
+
const piezoelectric =
|
|
102
|
+
specOrName === 'piezoelectric'
|
|
103
|
+
? ': [2] for the piezoelectric d (ITC Vol. D § 1.1.4.10.3), [1] for second-harmonic generation (§ 1.7.2.2.1.3)'
|
|
104
|
+
: ', 2 where ITC sums the two symmetric components (strain, d, s), 1 where it takes one (stress, e, c)';
|
|
105
|
+
throw new RangeError(
|
|
106
|
+
`${who}: give the factors of the ${layout.pairs.length === 1 ? 'index pair' : 'index pairs'} ` +
|
|
107
|
+
`({ factors: [${layout.pairs.map(() => '1 or 2').join(', ')}] })${piezoelectric}`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (!Array.isArray(factors) || factors.length !== layout.pairs.length || !factors.every((f) => f === 1 || f === 2)) {
|
|
111
|
+
throw new RangeError(
|
|
112
|
+
`${who}: factors must be ${layout.pairs.length} of 1 or 2, one per contracted index pair, not ${shown(factors)}`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return factors as readonly VoigtFactor[];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const flatOf = (digits: readonly number[]): number => digits.reduce((s, d) => s * 3 + d, 0);
|
|
119
|
+
const digitsOf = (flat: number, rank: number): number[] =>
|
|
120
|
+
Array.from({ length: rank }, (_, k) => Math.floor(flat / 3 ** (rank - 1 - k)) % 3);
|
|
121
|
+
|
|
122
|
+
/** Checks that a tensor has its intrinsic symmetry, within the tolerance relative to its largest component. */
|
|
123
|
+
function checkSymmetry(
|
|
124
|
+
t: readonly number[],
|
|
125
|
+
rank: number,
|
|
126
|
+
perms: readonly SignedPermutation[],
|
|
127
|
+
tolerance: number,
|
|
128
|
+
who: string,
|
|
129
|
+
): void {
|
|
130
|
+
const scale = Math.max(...t.map(Math.abs));
|
|
131
|
+
for (let o = 0; o < t.length; o++) {
|
|
132
|
+
const d = digitsOf(o, rank);
|
|
133
|
+
for (const { perm, sign } of perms) {
|
|
134
|
+
const other = flatOf(perm.map((k) => d[k]));
|
|
135
|
+
if (Math.abs(t[o] - sign * t[other]) > tolerance * scale) {
|
|
136
|
+
throw new RangeError(
|
|
137
|
+
`${who}: the tensor lacks the index symmetry of its specification (component ${o} is ${t[o]}, ` +
|
|
138
|
+
`its partner ${other} ${t[other]})`,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The Voigt indices (0-based) of a flat tensor index, and the product of the factors of its pairs. */
|
|
146
|
+
function voigtIndex(
|
|
147
|
+
flat: number,
|
|
148
|
+
layout: Layout,
|
|
149
|
+
factors: readonly VoigtFactor[],
|
|
150
|
+
): { index: number[]; factor: number } {
|
|
151
|
+
const d = digitsOf(flat, layout.rank);
|
|
152
|
+
const index: number[] = [];
|
|
153
|
+
let factor = 1;
|
|
154
|
+
let k = 0;
|
|
155
|
+
layout.pairs.forEach((first, p) => {
|
|
156
|
+
while (k < first) index.push(d[k++]);
|
|
157
|
+
const alpha = ALPHA[d[first]][d[first + 1]];
|
|
158
|
+
index.push(alpha);
|
|
159
|
+
if (alpha >= 3) factor *= factors[p];
|
|
160
|
+
k = first + 2;
|
|
161
|
+
});
|
|
162
|
+
while (k < layout.rank) index.push(d[k++]);
|
|
163
|
+
return { index, factor };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function resolve(specOrName: TensorSpec | TensorPropertyName, options: VoigtOptions | undefined, who: string) {
|
|
167
|
+
checkOptions(options, ['factors', 'tolerance'], who);
|
|
168
|
+
const { spec, perms } = checkedSpec(specOrName);
|
|
169
|
+
const layout = layoutOf(spec, who);
|
|
170
|
+
const factors = factorsOf(specOrName, layout, options, who);
|
|
171
|
+
const tolerance = toleranceOf(options, 'metric');
|
|
172
|
+
return { spec, perms, layout, factors, tolerance };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* A tensor in Voigt's two-index notation (ITC Vol. D (2013) § 1.1.4.10, pp. 24–27): each contracted
|
|
177
|
+
* index pair ij becomes α = 1…6 for 11, 22, 33, 23, 31, 12 (eq. (1.1.4.6)), and a component with
|
|
178
|
+
* α = 4, 5, 6 is the tensor component times the factor of its pair (`factors`). A symmetric tensor of
|
|
179
|
+
* rank 2 gives 6 components, one of rank 3 symmetric in its last pair a 3 × 6 matrix (d_iα), in its
|
|
180
|
+
* first pair a 6 × 3 matrix (e_αk), one of rank 4 a 6 × 6 matrix (s_αβ, c_αβ). Throws a RangeError for a specification
|
|
181
|
+
* without a symmetric index pair, factors that are missing or not one 1 or 2 per pair, and a tensor
|
|
182
|
+
* that lacks the index symmetry of its specification (within the tolerance, relative to its largest
|
|
183
|
+
* component).
|
|
184
|
+
*
|
|
185
|
+
* @remarks The tensor is flat, 3^rank components, as `tensorForm` gives a basis tensor.
|
|
186
|
+
*/
|
|
187
|
+
export function toVoigt(
|
|
188
|
+
tensor: readonly number[],
|
|
189
|
+
specOrName: TensorSpec | TensorPropertyName,
|
|
190
|
+
options?: VoigtOptions,
|
|
191
|
+
): readonly number[] | readonly (readonly number[])[] {
|
|
192
|
+
const who = 'toVoigt';
|
|
193
|
+
const { spec, perms, layout, factors, tolerance } = resolve(specOrName, options, who);
|
|
194
|
+
const dim = 3 ** spec.rank;
|
|
195
|
+
if (
|
|
196
|
+
!Array.isArray(tensor) ||
|
|
197
|
+
tensor.length !== dim ||
|
|
198
|
+
!tensor.every((x) => typeof x === 'number' && Number.isFinite(x))
|
|
199
|
+
) {
|
|
200
|
+
throw new RangeError(`${who}: a tensor of rank ${spec.rank} is ${dim} finite numbers, not ${shown(tensor)}`);
|
|
201
|
+
}
|
|
202
|
+
checkSymmetry(tensor, spec.rank, perms, tolerance, who);
|
|
203
|
+
const out =
|
|
204
|
+
layout.shape.length === 1
|
|
205
|
+
? new Array<number>(6).fill(0)
|
|
206
|
+
: Array.from({ length: layout.shape[0] }, () => new Array<number>(layout.shape[1]).fill(0));
|
|
207
|
+
for (let o = 0; o < dim; o++) {
|
|
208
|
+
const { index, factor } = voigtIndex(o, layout, factors);
|
|
209
|
+
// The representative index of each Voigt cell: the pair in the order of PAIR.
|
|
210
|
+
const d = digitsOf(o, spec.rank);
|
|
211
|
+
const canonical = layout.pairs.every((first) => {
|
|
212
|
+
const alpha = ALPHA[d[first]][d[first + 1]];
|
|
213
|
+
return PAIR[alpha][0] === d[first] && PAIR[alpha][1] === d[first + 1];
|
|
214
|
+
});
|
|
215
|
+
if (!canonical) continue;
|
|
216
|
+
const value = factor * tensor[o] + 0;
|
|
217
|
+
if (index.length === 1) (out as number[])[index[0]] = value;
|
|
218
|
+
else (out as number[][])[index[0]][index[1]] = value;
|
|
219
|
+
}
|
|
220
|
+
return deepFreeze(out);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* The tensor of a Voigt array (`toVoigt` in reverse): each tensor component is the Voigt component
|
|
225
|
+
* of its index pairs over the factors of the pairs, so that the tensor has the index symmetry of its
|
|
226
|
+
* specification. Throws a RangeError for a Voigt array of
|
|
227
|
+
* the wrong shape, and for one that is no tensor of the specification (for rank 4 with interchangeable
|
|
228
|
+
* pairs a 6 × 6 matrix that is not symmetric, for a totally symmetric tensor one whose
|
|
229
|
+
* components do not agree), within the tolerance relative to its largest component.
|
|
230
|
+
*
|
|
231
|
+
* @remarks The tensor is flat, 3^rank components, as `tensorForm` gives a basis tensor.
|
|
232
|
+
*/
|
|
233
|
+
export function fromVoigt(
|
|
234
|
+
voigt: readonly number[] | readonly (readonly number[])[],
|
|
235
|
+
specOrName: TensorSpec | TensorPropertyName,
|
|
236
|
+
options?: VoigtOptions,
|
|
237
|
+
): readonly number[] {
|
|
238
|
+
const who = 'fromVoigt';
|
|
239
|
+
const { spec, perms, layout, factors, tolerance } = resolve(specOrName, options, who);
|
|
240
|
+
const shapeOk =
|
|
241
|
+
layout.shape.length === 1
|
|
242
|
+
? Array.isArray(voigt) && voigt.length === 6 && voigt.every((x) => typeof x === 'number' && Number.isFinite(x))
|
|
243
|
+
: Array.isArray(voigt) &&
|
|
244
|
+
voigt.length === layout.shape[0] &&
|
|
245
|
+
voigt.every(
|
|
246
|
+
(row) =>
|
|
247
|
+
Array.isArray(row) &&
|
|
248
|
+
row.length === layout.shape[1] &&
|
|
249
|
+
row.every((x: unknown) => typeof x === 'number' && Number.isFinite(x)),
|
|
250
|
+
);
|
|
251
|
+
if (!shapeOk) {
|
|
252
|
+
throw new RangeError(
|
|
253
|
+
`${who}: a Voigt array of shape ${layout.shape.join(' × ')} of finite numbers, not ${shown(voigt)}`,
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
const dim = 3 ** spec.rank;
|
|
257
|
+
const out = new Array<number>(dim);
|
|
258
|
+
for (let o = 0; o < dim; o++) {
|
|
259
|
+
const { index, factor } = voigtIndex(o, layout, factors);
|
|
260
|
+
const v =
|
|
261
|
+
index.length === 1
|
|
262
|
+
? (voigt as readonly number[])[index[0]]
|
|
263
|
+
: (voigt as readonly (readonly number[])[])[index[0]][index[1]];
|
|
264
|
+
out[o] = v / factor + 0;
|
|
265
|
+
}
|
|
266
|
+
checkSymmetry(out, spec.rank, perms, tolerance, who);
|
|
267
|
+
return deepFreeze(out);
|
|
268
|
+
}
|
package/src/version.ts
CHANGED