symcrys 0.3.1 → 0.5.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/README.md +8 -115
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/pointGroups/properties.d.ts +8 -3
- package/dist/pointGroups/properties.d.ts.map +1 -1
- package/dist/pointGroups/properties.js +11 -3
- package/dist/pointGroups/properties.js.map +1 -1
- package/dist/tensors/rowEchelon.d.ts +18 -0
- package/dist/tensors/rowEchelon.d.ts.map +1 -0
- package/dist/tensors/rowEchelon.js +49 -0
- package/dist/tensors/rowEchelon.js.map +1 -0
- package/dist/tensors/tensorForm.d.ts +82 -0
- package/dist/tensors/tensorForm.d.ts.map +1 -0
- package/dist/tensors/tensorForm.js +222 -0
- package/dist/tensors/tensorForm.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -26
- package/src/index.ts +12 -1
- package/src/pointGroups/properties.ts +14 -3
- package/src/tensors/rowEchelon.ts +43 -0
- package/src/tensors/tensorForm.ts +282 -0
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -1,128 +1,21 @@
|
|
|
1
1
|
# symcrys
|
|
2
2
|
|
|
3
|
-
Crystallographic symmetry calculations in TypeScript: point groups
|
|
4
|
-
|
|
5
|
-
library without runtime dependencies that runs unbundled in browsers and in Node.
|
|
6
|
-
|
|
7
|
-
> **Status: pre-release.** So far: the 32 crystallographic point groups with their symmetry elements.
|
|
8
|
-
> The API will change without notice until 1.0.0.
|
|
9
|
-
|
|
10
|
-
## Scope
|
|
11
|
-
|
|
12
|
-
symcrys holds calculations, not presentation. Planned, in this order:
|
|
13
|
-
|
|
14
|
-
1. Point groups: the 32 crystallographic and the 122 magnetic point groups as data (generators),
|
|
15
|
-
group generation, settings, Hermann–Mauguin, Schoenflies and Shubnikov symbols, derived
|
|
16
|
-
properties (centrosymmetric, polar, chiral, magnetoelectric …), subgroups.
|
|
17
|
-
2. Plane groups.
|
|
18
|
-
3. Space groups.
|
|
19
|
-
|
|
20
|
-
The tensor calculations of birss-app (tensor forms, projections) move here as well; their place in
|
|
21
|
-
this order is not yet fixed. Rendering (LaTeX, SVG, view models) and translated
|
|
22
|
-
display names stay in the applications that use symcrys.
|
|
23
|
-
|
|
24
|
-
**Conventions.** Point groups follow the _International Tables for Crystallography_ by default
|
|
25
|
-
(Vol. A for the crystal classes, Vol. D Ch. 1.5 for the magnetic point groups). The convention of
|
|
26
|
-
Birss, _Symmetry and Magnetism_ (1966), is available as an option. Where the two differ is
|
|
27
|
-
documented in [`docs/conventions.md`](docs/conventions.md).
|
|
28
|
-
|
|
29
|
-
symcrys is the computational core of the crystallography teaching apps
|
|
30
|
-
([stereography](https://github.com/manganite/stereography),
|
|
31
|
-
[plane-groups](https://github.com/manganite/plane-groups)) and of
|
|
32
|
-
[birss-app](https://github.com/manganite/birss-app); its calculations start from those of
|
|
33
|
-
birss-app.
|
|
34
|
-
|
|
35
|
-
## Use
|
|
3
|
+
Crystallographic symmetry calculations in TypeScript: point groups with their settings, symbols,
|
|
4
|
+
symmetry elements, site symmetry and Wyckoff positions, and the forms of property tensors they
|
|
5
|
+
allow. A library without runtime dependencies that runs unbundled in browsers and in Node.
|
|
36
6
|
|
|
37
7
|
```bash
|
|
38
8
|
npm install symcrys
|
|
39
9
|
```
|
|
40
10
|
|
|
41
|
-
Each release on GitHub also carries the package as `symcrys-X.Y.Z.tgz`.
|
|
42
|
-
|
|
43
11
|
```ts
|
|
44
|
-
import {
|
|
45
|
-
describeOperations,
|
|
46
|
-
operations,
|
|
47
|
-
settings,
|
|
48
|
-
symbol,
|
|
49
|
-
symmetryDirections,
|
|
50
|
-
wyckoffPositionOf,
|
|
51
|
-
wyckoffPositions,
|
|
52
|
-
} from 'symcrys';
|
|
12
|
+
import { operations, symbol, tensorForm } from 'symcrys';
|
|
53
13
|
|
|
54
14
|
symbol('32'); // '321': ITC short symbol of the default setting
|
|
55
|
-
symbol('32', { convention: 'birss' }); // '32'
|
|
56
|
-
settings('32'); // setting 1: 312, setting 2: 321 (the ITC default)
|
|
57
15
|
operations('-3m'); // 12 operations, Cartesian matrices; x ∥ a, z ∥ c
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
wyckoffPositions('4mm')[2]; // { letter: 'b', multiplicity: 4, siteSymmetry: '..m', millerIndices: 'h,h,l', … }
|
|
61
|
-
wyckoffPositionOf('4mm', [0, 0, -1]).letter; // 'a'
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
Conventions, frames and symbols: [`docs/conventions.md`](docs/conventions.md).
|
|
65
|
-
|
|
66
|
-
Without a build step, copy `dist/` (from the tarball, or built with `npm run build`) next to your
|
|
67
|
-
code and import `dist/index.js` directly: every module in `dist/` imports only relative `.js`
|
|
68
|
-
paths.
|
|
69
|
-
|
|
70
|
-
## Development
|
|
71
|
-
|
|
72
|
-
Development requires Node 22 (22.13 or later) or 24; CI runs on both. The library itself needs only
|
|
73
|
-
an ES2022 runtime with ES modules.
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
npm install
|
|
77
|
-
npm run typecheck # TypeScript 6: tests and scripts with Node types, library code without
|
|
78
|
-
npm run typecheck:ts7 # the same with TypeScript 7
|
|
79
|
-
npm run lint # ESLint
|
|
80
|
-
npm run format:check # Prettier (npm run format fixes)
|
|
81
|
-
npm test # vitest
|
|
82
|
-
npm run build # dist/: JavaScript, .d.ts, source maps
|
|
83
|
-
npm run check:dist # dist/ loads, imports only relative .js paths, has no test-only code
|
|
16
|
+
tensorForm('mm2', { rank: 3, parity: 'polar', timeParity: 'i', intrinsic: 'jk' }).parameters;
|
|
17
|
+
// [[0,0,2], [1,1,2], [2,0,0], [2,1,1], [2,2,2]]: xxz, yyz, zxx, zyy, zzz
|
|
84
18
|
```
|
|
85
19
|
|
|
86
|
-
|
|
87
|
-
[
|
|
88
|
-
[stereography](https://github.com/manganite/stereography) checked out next to this repository:
|
|
89
|
-
`npm run audit:point-groups` writes `audit/point-groups/report.md`, and `npm run audit:birss-app`
|
|
90
|
-
captures the pins of the Birss convention (`src/pointGroups/birssApp.pins.fixtures.ts`, formatted
|
|
91
|
-
with Prettier by the same script).
|
|
92
|
-
|
|
93
|
-
CI runs these seven gates on every pull request, on Node 22 and 24. Tests sit next to their
|
|
94
|
-
module (`foo.ts`, `foo.test.ts`). Working rules for contributors, human or agent: `CLAUDE.md`.
|
|
95
|
-
|
|
96
|
-
## Releases
|
|
97
|
-
|
|
98
|
-
1. Release PR: version in `package.json`, `package-lock.json` (`npm install --package-lock-only`)
|
|
99
|
-
and `src/version.ts`; move the `Unreleased` entries of `CHANGELOG.md` under
|
|
100
|
-
`## [X.Y.Z] - YYYY-MM-DD` and update the link definitions at the bottom (`[Unreleased]` compares
|
|
101
|
-
`vX.Y.Z...HEAD`, `[X.Y.Z]` compares the previous tag with `vX.Y.Z`).
|
|
102
|
-
2. After the merge: `git fetch origin`, check that `origin/main` is the merge commit of the release PR,
|
|
103
|
-
then `git tag -a vX.Y.Z -m "symcrys X.Y.Z" origin/main && git push origin vX.Y.Z`.
|
|
104
|
-
3. The tag runs `.github/workflows/release.yml`: it checks that the tag matches `package.json`,
|
|
105
|
-
runs all gates, and creates the GitHub release with the `CHANGELOG.md` section as notes and the
|
|
106
|
-
`npm pack` tarball attached. Check that the workflow is green and the release carries
|
|
107
|
-
`symcrys-X.Y.Z.tgz`.
|
|
108
|
-
|
|
109
|
-
**npm.** The `npm` job of `release.yml` submits the same tarball to npm as a staged version
|
|
110
|
-
(trusted publishing, no token). Its log shows the tarball's shasum and integrity and the stage id. The version
|
|
111
|
-
goes live only after approval with two-factor authentication (npm 11.15 or later):
|
|
112
|
-
|
|
113
|
-
1. `npm stage list symcrys`, then `npm stage view <stage-id>`: version and shasum must match the log
|
|
114
|
-
of the `npm` job (or "Staged Packages" on npmjs.com).
|
|
115
|
-
2. `npm stage approve <stage-id>`. npm first runs an automated review of the staged version; until
|
|
116
|
-
it has finished, approval fails with `E409 … automated review hasn't finished`. Then approve again
|
|
117
|
-
a little later (for 0.1.1 it took a few minutes).
|
|
118
|
-
3. `npm view symcrys` shows the version as `latest`.
|
|
119
|
-
|
|
120
|
-
If staging fails, re-run the `npm` job (a staged version cannot be staged twice, so check
|
|
121
|
-
`npm stage list` first). An authentication error usually means the trusted publisher on npmjs.com
|
|
122
|
-
does not match (repository, workflow `release.yml`); the stage step runs with `--loglevel verbose`,
|
|
123
|
-
so its log shows the OIDC exchange. As a fallback, stage the release asset by hand:
|
|
124
|
-
`npm stage publish ./symcrys-X.Y.Z.tgz` (then without provenance, which only CI can attest).
|
|
125
|
-
|
|
126
|
-
## Licence
|
|
127
|
-
|
|
128
|
-
[MIT](LICENSE) © 2026 Thomas Lottermoser
|
|
20
|
+
Documentation, conventions (ITC and Birss) and their print sources, and the Python package of the
|
|
21
|
+
same version: [github.com/manganite/symcrys](https://github.com/manganite/symcrys).
|
package/dist/index.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ export type { Mat3, Vec3 } from './linalg.js';
|
|
|
7
7
|
export type { Operation } from './operations.js';
|
|
8
8
|
export { crystalFamily, latticeBasis, type CrystalFamily, type CrystalSystem, type FixedAngleFamily, } from './lattice.js';
|
|
9
9
|
export { POINT_GROUP_KEYS, findPointGroup, generators, isPointGroupKey, operations, pointGroup, pointGroups, settings, symbol, type Convention, type PointGroup, type PointGroupInSetting, type PointGroupKey, type PointGroupType, type Setting, type SettingOptions, type SymbolOptions, } from './pointGroups/pointGroups.js';
|
|
10
|
-
export { isCentrosymmetric, isChiral, isPolar, laueClass } from './pointGroups/properties.js';
|
|
10
|
+
export { isCentrosymmetric, isChiral, isPiezoelectric, isPolar, laueClass } from './pointGroups/properties.js';
|
|
11
11
|
export { LATTICE_SYMMETRY_DIRECTIONS, type Uvw } from './symmetryDirections.js';
|
|
12
12
|
export { describeOperations, symmetryDirections, type Axis, type DirectionElements, type OperationDescription, type OperationKind, type SymmetryDirection, } from './pointGroups/elements.js';
|
|
13
13
|
export { siteSymmetry, type SiteSymmetry, type SiteSymmetryOptions } from './siteSymmetry.js';
|
|
14
14
|
export { wyckoffPositionOf, wyckoffPositions, type Hkl, type WyckoffOptions, type WyckoffPosition, } from './pointGroups/wyckoff.js';
|
|
15
|
+
export { rotateTensor, tensorForm, tensorFormOf, type IntrinsicSymmetry, type TensorForm, type TensorParity, type TensorRank, type TensorSpec, type TimeParity, } from './tensors/tensorForm.js';
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,EACV,WAAW,EACX,QAAQ,EACR,MAAM,EACN,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAA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KAAK,UAAU,GAChB,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
export { VERSION } from './version.js';
|
|
6
6
|
export { crystalFamily, latticeBasis, } from './lattice.js';
|
|
7
7
|
export { POINT_GROUP_KEYS, findPointGroup, generators, isPointGroupKey, operations, pointGroup, pointGroups, settings, symbol, } from './pointGroups/pointGroups.js';
|
|
8
|
-
export { isCentrosymmetric, isChiral, isPolar, laueClass } from './pointGroups/properties.js';
|
|
8
|
+
export { isCentrosymmetric, isChiral, isPiezoelectric, isPolar, laueClass } from './pointGroups/properties.js';
|
|
9
9
|
export { LATTICE_SYMMETRY_DIRECTIONS } from './symmetryDirections.js';
|
|
10
10
|
export { describeOperations, symmetryDirections, } from './pointGroups/elements.js';
|
|
11
11
|
export { siteSymmetry } from './siteSymmetry.js';
|
|
12
12
|
export { wyckoffPositionOf, wyckoffPositions, } from './pointGroups/wyckoff.js';
|
|
13
|
+
export { rotateTensor, tensorForm, tensorFormOf, } from './tensors/tensorForm.js';
|
|
13
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC,OAAO,EACL,aAAa,EACb,YAAY,GAIb,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,EACV,WAAW,EACX,QAAQ,EACR,MAAM,GASP,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC,OAAO,EACL,aAAa,EACb,YAAY,GAIb,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,EACV,WAAW,EACX,QAAQ,EACR,MAAM,GASP,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC/G,OAAO,EAAE,2BAA2B,EAAY,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAMnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAA+C,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EACL,iBAAiB,EACjB,gBAAgB,GAIjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,GAOb,MAAM,yBAAyB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Properties of a point group that follow from its operations
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Properties of a point group that follow from its operations, directly or through the form of a
|
|
3
|
+
* tensor (piezoelectric). They do not depend on the setting or the convention. Piezomagnetic,
|
|
4
|
+
* magnetoelectric and ferromagnetic follow with the magnetic point groups (#13).
|
|
5
5
|
*/
|
|
6
6
|
import { type PointGroupKey } from './data.js';
|
|
7
7
|
/** Contains the inversion. */
|
|
@@ -15,4 +15,9 @@ export declare function isPolar(key: PointGroupKey): boolean;
|
|
|
15
15
|
export declare function isChiral(key: PointGroupKey): boolean;
|
|
16
16
|
/** The Laue class: the centrosymmetric crystal class generated by the group and the inversion. */
|
|
17
17
|
export declare function laueClass(key: PointGroupKey): PointGroupKey;
|
|
18
|
+
/**
|
|
19
|
+
* Piezoelectric: the polarization can depend linearly on stress, i.e. a polar time-even tensor of
|
|
20
|
+
* rank 3, symmetric in its last two indices, is allowed (ITA Table 3.2.2.1).
|
|
21
|
+
*/
|
|
22
|
+
export declare function isPiezoelectric(key: PointGroupKey): boolean;
|
|
18
23
|
//# sourceMappingURL=properties.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../../src/pointGroups/properties.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../../src/pointGroups/properties.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAOjE,8BAA8B;AAC9B,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAE7D;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAUnD;AAED,4DAA4D;AAC5D,wBAAgB,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAEpD;AAQD,kGAAkG;AAClG,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,GAAG,aAAa,CAa3D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAI3D"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Properties of a point group that follow from its operations
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Properties of a point group that follow from its operations, directly or through the form of a
|
|
3
|
+
* tensor (piezoelectric). They do not depend on the setting or the convention. Piezomagnetic,
|
|
4
|
+
* magnetoelectric and ferromagnetic follow with the magnetic point groups (#13).
|
|
5
5
|
*/
|
|
6
6
|
import { INVERSION, det, matricesEqual } from '../linalg.js';
|
|
7
7
|
import { EPSILON } from '../tolerances.js';
|
|
8
8
|
import { compose, operation, operationsEqual } from '../operations.js';
|
|
9
9
|
import { POINT_GROUP_KEYS } from './data.js';
|
|
10
10
|
import { operations } from './pointGroups.js';
|
|
11
|
+
import { tensorForm } from '../tensors/tensorForm.js';
|
|
11
12
|
/** Operations in setting 1, the frame all stored data share. */
|
|
12
13
|
const stored = (key) => operations(key, { setting: 1 });
|
|
13
14
|
/** Contains the inversion. */
|
|
@@ -57,4 +58,11 @@ export function laueClass(key) {
|
|
|
57
58
|
laueCache.set(key, laue);
|
|
58
59
|
return laue;
|
|
59
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Piezoelectric: the polarization can depend linearly on stress, i.e. a polar time-even tensor of
|
|
63
|
+
* rank 3, symmetric in its last two indices, is allowed (ITA Table 3.2.2.1).
|
|
64
|
+
*/
|
|
65
|
+
export function isPiezoelectric(key) {
|
|
66
|
+
return (tensorForm(key, { rank: 3, parity: 'polar', timeParity: 'i', intrinsic: 'jk' }, { setting: 1 }).basis.length > 0);
|
|
67
|
+
}
|
|
60
68
|
//# sourceMappingURL=properties.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../src/pointGroups/properties.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAkB,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAsB,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../src/pointGroups/properties.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,S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gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrG,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,GAAG,EAAE,CAAC,CAAC;IACjF,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACzB,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,GAAkB;IAChD,OAAO,CACL,UAAU,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CACjH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row reduction of real vectors (any length): the reduced row echelon form of a spanning set, and
|
|
3
|
+
* the rank. The tolerances are those of birss-app's `linalg.ts`, where the tensor code comes from.
|
|
4
|
+
*/
|
|
5
|
+
/** An entry below this (absolute) does not serve as a pivot: float noise is never a new direction. */
|
|
6
|
+
export declare const PIVOT_EPSILON = 1e-7;
|
|
7
|
+
/** An entry below this (absolute) is not eliminated, and is set to zero in the result. */
|
|
8
|
+
export declare const ELIMINATION_EPSILON = 1e-12;
|
|
9
|
+
/**
|
|
10
|
+
* The reduced row echelon form of the span of `vectors` (all of length `dim`): one row per
|
|
11
|
+
* independent direction, each with a 1 at its pivot and 0 at every other row's pivot, pivots
|
|
12
|
+
* ascending. The rows are unique for a given span, so the pivots name the free parameters
|
|
13
|
+
* unambiguously: each is the lowest-index component that is independent of the ones before it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function reducedRowEchelon(vectors: readonly (readonly number[])[], dim: number): number[][];
|
|
16
|
+
/** The number of independent vectors among `vectors` (all of length `dim`). */
|
|
17
|
+
export declare function rank(vectors: readonly (readonly number[])[], dim: number): number;
|
|
18
|
+
//# sourceMappingURL=rowEchelon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rowEchelon.d.ts","sourceRoot":"","sources":["../../src/tensors/rowEchelon.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sGAAsG;AACtG,eAAO,MAAM,aAAa,OAAO,CAAC;AAElC,0FAA0F;AAC1F,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAoBlG;AAED,+EAA+E;AAC/E,wBAAgB,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row reduction of real vectors (any length): the reduced row echelon form of a spanning set, and
|
|
3
|
+
* the rank. The tolerances are those of birss-app's `linalg.ts`, where the tensor code comes from.
|
|
4
|
+
*/
|
|
5
|
+
/** An entry below this (absolute) does not serve as a pivot: float noise is never a new direction. */
|
|
6
|
+
export const PIVOT_EPSILON = 1e-7;
|
|
7
|
+
/** An entry below this (absolute) is not eliminated, and is set to zero in the result. */
|
|
8
|
+
export const ELIMINATION_EPSILON = 1e-12;
|
|
9
|
+
/**
|
|
10
|
+
* The reduced row echelon form of the span of `vectors` (all of length `dim`): one row per
|
|
11
|
+
* independent direction, each with a 1 at its pivot and 0 at every other row's pivot, pivots
|
|
12
|
+
* ascending. The rows are unique for a given span, so the pivots name the free parameters
|
|
13
|
+
* unambiguously: each is the lowest-index component that is independent of the ones before it.
|
|
14
|
+
*/
|
|
15
|
+
export function reducedRowEchelon(vectors, dim) {
|
|
16
|
+
const m = vectors.map((v) => Array.from(v));
|
|
17
|
+
let row = 0;
|
|
18
|
+
for (let c = 0; c < dim && row < m.length; c++) {
|
|
19
|
+
let pivot = row;
|
|
20
|
+
for (let r = row + 1; r < m.length; r++)
|
|
21
|
+
if (Math.abs(m[r][c]) > Math.abs(m[pivot][c]))
|
|
22
|
+
pivot = r;
|
|
23
|
+
if (Math.abs(m[pivot][c]) < PIVOT_EPSILON)
|
|
24
|
+
continue;
|
|
25
|
+
[m[row], m[pivot]] = [m[pivot], m[row]];
|
|
26
|
+
const p = m[row][c];
|
|
27
|
+
for (let j = 0; j < dim; j++)
|
|
28
|
+
m[row][j] /= p;
|
|
29
|
+
for (let r = 0; r < m.length; r++) {
|
|
30
|
+
if (r === row || Math.abs(m[r][c]) <= ELIMINATION_EPSILON)
|
|
31
|
+
continue;
|
|
32
|
+
const f = m[r][c];
|
|
33
|
+
for (let j = 0; j < dim; j++)
|
|
34
|
+
m[r][j] -= f * m[row][j];
|
|
35
|
+
}
|
|
36
|
+
row++;
|
|
37
|
+
}
|
|
38
|
+
const out = m.slice(0, row);
|
|
39
|
+
for (const r of out)
|
|
40
|
+
for (let j = 0; j < dim; j++)
|
|
41
|
+
if (Math.abs(r[j]) < ELIMINATION_EPSILON)
|
|
42
|
+
r[j] = 0;
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
/** The number of independent vectors among `vectors` (all of length `dim`). */
|
|
46
|
+
export function rank(vectors, dim) {
|
|
47
|
+
return reducedRowEchelon(vectors, dim).length;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=rowEchelon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rowEchelon.js","sourceRoot":"","sources":["../../src/tensors/rowEchelon.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sGAAsG;A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GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClC,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,mBAAmB;gBAAE,SAAS;YACpE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;gBAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACzD,CAAC;QACD,GAAG,EAAE,CAAC;IACR,CAAC;IACD,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC5B,KAAK,MAAM,CAAC,IAAI,GAAG;QAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;YAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,mBAAmB;gBAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACtG,OAAO,GAAG,CAAC;AACb,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,IAAI,CAAC,OAAuC,EAAE,GAAW;IACvE,OAAO,iBAAiB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symmetry-reduced forms of property tensors: which Cartesian components of a tensor of rank 0 to 4
|
|
3
|
+
* a point group allows, and how they depend on each other. Results are plain numbers (coefficient
|
|
4
|
+
* matrices and index lists); formulas, LaTeX and diagrams stay in the applications (CLAUDE.md,
|
|
5
|
+
* "Tensors").
|
|
6
|
+
*
|
|
7
|
+
* Components are numbered by their flat index: for indices (i₁, …, iₙ) with x, y, z = 0, 1, 2 the
|
|
8
|
+
* flat index is i₁·3ⁿ⁻¹ + … + iₙ, so the first index varies slowest (row-major, the order of a
|
|
9
|
+
* NumPy array of shape (3,)*n in C order). Moved from birss-app (`tensorForms.ts`,
|
|
10
|
+
* `tensorProjection.ts`, `linalg.ts`, revision 2be5fe3).
|
|
11
|
+
*/
|
|
12
|
+
import { type Mat3 } from '../linalg.js';
|
|
13
|
+
import { type Operation } from '../operations.js';
|
|
14
|
+
import { type PointGroupKey, type SettingOptions } from '../pointGroups/pointGroups.js';
|
|
15
|
+
/** Rank of a tensor: 0 (scalar) to 4. */
|
|
16
|
+
export type TensorRank = 0 | 1 | 2 | 3 | 4;
|
|
17
|
+
/** `'polar'`: transforms with R; `'axial'`: with det(R)·R (pseudotensor). */
|
|
18
|
+
export type TensorParity = 'polar' | 'axial';
|
|
19
|
+
/** `'i'`: time-even (invariant under time reversal); `'c'`: time-odd (changes sign). */
|
|
20
|
+
export type TimeParity = 'i' | 'c';
|
|
21
|
+
/**
|
|
22
|
+
* Symmetry of the tensor under permutation of its own indices, independent of the crystal:
|
|
23
|
+
* `'none'`; `'ij'`: the first two indices are interchangeable; `'jk'`: the last two (for rank 3 the
|
|
24
|
+
* index symmetry of second-harmonic generation and the piezoelectric effect); `'ij_kl'` (rank 4):
|
|
25
|
+
* each of the two pairs symmetric, the pairs not interchangeable (e.g. electric-quadrupole SHG,
|
|
26
|
+
* photoelasticity); `'voigt'` (rank 4): `'ij_kl'` and the pairs interchangeable (elastic
|
|
27
|
+
* stiffness). At rank 2, `'ij'` and `'jk'` both mean a symmetric tensor.
|
|
28
|
+
*/
|
|
29
|
+
export type IntrinsicSymmetry = 'none' | 'ij' | 'jk' | 'ij_kl' | 'voigt';
|
|
30
|
+
/** The kind of tensor, as in birss-app. */
|
|
31
|
+
export interface TensorSpec {
|
|
32
|
+
readonly rank: TensorRank;
|
|
33
|
+
readonly parity: TensorParity;
|
|
34
|
+
readonly timeParity: TimeParity;
|
|
35
|
+
readonly intrinsic: IntrinsicSymmetry;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The form of a tensor under a point group: the subspace of tensors invariant under every
|
|
39
|
+
* operation and with the requested index symmetry. Every entry is a plain number; a vector of
|
|
40
|
+
* components has length 3^rank (flat index, see the module documentation).
|
|
41
|
+
*/
|
|
42
|
+
export interface TensorForm {
|
|
43
|
+
readonly rank: TensorRank;
|
|
44
|
+
/**
|
|
45
|
+
* A basis of the allowed tensors in reduced row echelon form: one row per free parameter, with 1
|
|
46
|
+
* at the parameter's own component and 0 at every other parameter's component. Every allowed
|
|
47
|
+
* tensor is Σₖ pₖ·basis[k], where pₖ is the value of its component `parameters[k]`. Empty if the
|
|
48
|
+
* tensor vanishes.
|
|
49
|
+
*/
|
|
50
|
+
readonly basis: readonly (readonly number[])[];
|
|
51
|
+
/**
|
|
52
|
+
* The free parameters, as the index lists of their components (e.g. `[0, 1, 1]` for xyy), one per
|
|
53
|
+
* basis row and in its order: each is the lowest component independent of those before it.
|
|
54
|
+
*/
|
|
55
|
+
readonly parameters: readonly (readonly number[])[];
|
|
56
|
+
/**
|
|
57
|
+
* The constraints: one row r per component that is not a parameter, in ascending flat index,
|
|
58
|
+
* with r·t = 0 for every allowed tensor t. Row c reads t_c − Σₖ basis[k][c]·t_{parameters[k]} = 0;
|
|
59
|
+
* a row with a single 1 says that the component vanishes.
|
|
60
|
+
*/
|
|
61
|
+
readonly relations: readonly (readonly number[])[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The form of a tensor under a point group in the requested setting (default: the default setting
|
|
65
|
+
* of the convention, `'itc'` unless given). The convention matters only through the setting: the
|
|
66
|
+
* same setting index gives the same form in both conventions (docs/conventions.md, "Tensors").
|
|
67
|
+
*/
|
|
68
|
+
export declare function tensorForm(key: PointGroupKey, spec: TensorSpec, options?: SettingOptions): TensorForm;
|
|
69
|
+
/**
|
|
70
|
+
* The form of a tensor under the group generated by `operations`, e.g. the site symmetry of a
|
|
71
|
+
* surface normal (`siteSymmetry`) or the operations of a distorted crystal. The operations are
|
|
72
|
+
* Cartesian and orthogonal; a list that is not closed is closed first.
|
|
73
|
+
*/
|
|
74
|
+
export declare function tensorFormOf(operations: readonly Operation[], spec: TensorSpec): TensorForm;
|
|
75
|
+
/**
|
|
76
|
+
* The components of `tensor` (length 3^rank, flat index) in a frame rotated by the orthogonal
|
|
77
|
+
* matrix `rotation`: t′_{i…} = f·Σ R_{ia}…R_{…}·t_{a…}, with f = det(R) for an axial tensor and 1
|
|
78
|
+
* for a polar one. To express a tensor in the frame of a surface, pass the matrix whose rows are
|
|
79
|
+
* the new axes in the old frame. Time parity plays no part.
|
|
80
|
+
*/
|
|
81
|
+
export declare function rotateTensor(tensor: readonly number[], rotation: Mat3, spec: TensorSpec): number[];
|
|
82
|
+
//# sourceMappingURL=tensorForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tensorForm.d.ts","sourceRoot":"","sources":["../../src/tensors/tensorForm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAO,KAAK,IAAI,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAwB,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAI9G,yCAAyC;AACzC,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE3C,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,OAAO,CAAC;AAE7C,wFAAwF;AACxF,MAAM,MA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or of rank 0 to 4
|
|
3
|
+
* a point group allows, and how they depend on each other. Results are plain numbers (coefficient
|
|
4
|
+
* matrices and index lists); formulas, LaTeX and diagrams stay in the applications (CLAUDE.md,
|
|
5
|
+
* "Tensors").
|
|
6
|
+
*
|
|
7
|
+
* Components are numbered by their flat index: for indices (i₁, …, iₙ) with x, y, z = 0, 1, 2 the
|
|
8
|
+
* flat index is i₁·3ⁿ⁻¹ + … + iₙ, so the first index varies slowest (row-major, the order of a
|
|
9
|
+
* NumPy array of shape (3,)*n in C order). Moved from birss-app (`tensorForms.ts`,
|
|
10
|
+
* `tensorProjection.ts`, `linalg.ts`, revision 2be5fe3).
|
|
11
|
+
*/
|
|
12
|
+
import { det } from '../linalg.js';
|
|
13
|
+
import { closeGroup } from '../operations.js';
|
|
14
|
+
import { operations, settings } from '../pointGroups/pointGroups.js';
|
|
15
|
+
import { EPSILON, SNAP_EPSILON } from '../tolerances.js';
|
|
16
|
+
import { reducedRowEchelon } from './rowEchelon.js';
|
|
17
|
+
const RANKS = [0, 1, 2, 3, 4];
|
|
18
|
+
/** Checks a specification and returns the index permutations that generate its intrinsic symmetry. */
|
|
19
|
+
function checkSpec(spec) {
|
|
20
|
+
const { rank, parity, timeParity, intrinsic } = spec;
|
|
21
|
+
if (!RANKS.includes(rank))
|
|
22
|
+
throw new RangeError(`Tensor rank must be 0 to 4, not ${JSON.stringify(rank)}`);
|
|
23
|
+
if (parity !== 'polar' && parity !== 'axial')
|
|
24
|
+
throw new RangeError(`Unknown tensor parity: ${JSON.stringify(parity)}`);
|
|
25
|
+
if (timeParity !== 'i' && timeParity !== 'c')
|
|
26
|
+
throw new RangeError(`Unknown time parity: ${JSON.stringify(timeParity)}`);
|
|
27
|
+
const swap = (a, b) => {
|
|
28
|
+
const p = Array.from({ length: rank }, (_, k) => k);
|
|
29
|
+
[p[a], p[b]] = [p[b], p[a]];
|
|
30
|
+
return p;
|
|
31
|
+
};
|
|
32
|
+
switch (intrinsic) {
|
|
33
|
+
case 'none':
|
|
34
|
+
return [];
|
|
35
|
+
case 'ij':
|
|
36
|
+
case 'jk':
|
|
37
|
+
if (rank < 2)
|
|
38
|
+
throw new RangeError(`Intrinsic symmetry '${intrinsic}' needs rank 2 or more, not ${rank}`);
|
|
39
|
+
return [intrinsic === 'ij' ? swap(0, 1) : swap(rank - 2, rank - 1)];
|
|
40
|
+
case 'ij_kl':
|
|
41
|
+
case 'voigt':
|
|
42
|
+
if (rank !== 4)
|
|
43
|
+
throw new RangeError(`Intrinsic symmetry '${intrinsic}' needs rank 4, not ${rank}`);
|
|
44
|
+
return intrinsic === 'ij_kl' ? [swap(0, 1), swap(2, 3)] : [swap(0, 1), swap(2, 3), [2, 3, 0, 1]];
|
|
45
|
+
default:
|
|
46
|
+
throw new RangeError(`Unknown intrinsic symmetry: ${JSON.stringify(intrinsic)}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Throws unless `m` is orthogonal (mᵀm = 1 within `EPSILON`): the code assumes Cartesian matrices. */
|
|
50
|
+
function checkOrthogonal(m, what) {
|
|
51
|
+
for (let i = 0; i < 3; i++) {
|
|
52
|
+
for (let j = 0; j < 3; j++) {
|
|
53
|
+
const dot = m[0][i] * m[0][j] + m[1][i] * m[1][j] + m[2][i] * m[2][j];
|
|
54
|
+
if (Math.abs(dot - (i === j ? 1 : 0)) > EPSILON) {
|
|
55
|
+
throw new RangeError(`${what} is not an orthogonal (Cartesian) matrix: ${JSON.stringify(m)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** The indices (x, y, z = 0, 1, 2) of every flat index at a rank, first index first. */
|
|
61
|
+
const digitTables = new Map();
|
|
62
|
+
function digits(rank) {
|
|
63
|
+
let table = digitTables.get(rank);
|
|
64
|
+
if (!table) {
|
|
65
|
+
table = Array.from({ length: 3 ** rank }, (_, flat) => Array.from({ length: rank }, (_, k) => Math.floor(flat / 3 ** (rank - 1 - k)) % 3));
|
|
66
|
+
digitTables.set(rank, table);
|
|
67
|
+
}
|
|
68
|
+
return table;
|
|
69
|
+
}
|
|
70
|
+
/** The flat indices reached from `flat` by the index permutations (`out[k] = in[perm[k]]`). */
|
|
71
|
+
function orbit(flat, rank, perms) {
|
|
72
|
+
const d = digits(rank);
|
|
73
|
+
const seen = new Set([flat]);
|
|
74
|
+
const stack = [flat];
|
|
75
|
+
while (stack.length > 0) {
|
|
76
|
+
const cur = stack.pop();
|
|
77
|
+
for (const p of perms) {
|
|
78
|
+
let next = 0;
|
|
79
|
+
for (let k = 0; k < rank; k++)
|
|
80
|
+
next = next * 3 + d[cur][p[k]];
|
|
81
|
+
if (!seen.has(next)) {
|
|
82
|
+
seen.add(next);
|
|
83
|
+
stack.push(next);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return [...seen];
|
|
88
|
+
}
|
|
89
|
+
function freezeRows(rows) {
|
|
90
|
+
return Object.freeze(rows.map((r) => Object.freeze([...r])));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The form for a group given as its full list of operations. The group average of each seed
|
|
94
|
+
* (a unit tensor on one orbit of the intrinsic symmetry) projects it onto the invariant subspace;
|
|
95
|
+
* the projections span it, and the reduced row echelon form makes the basis minimal and canonical.
|
|
96
|
+
*/
|
|
97
|
+
function project(group, spec, perms) {
|
|
98
|
+
const { rank } = spec;
|
|
99
|
+
const dim = 3 ** rank;
|
|
100
|
+
const d = digits(rank);
|
|
101
|
+
const ops = group.map((op) => ({
|
|
102
|
+
m: op.matrix.flat(),
|
|
103
|
+
sign: (spec.parity === 'axial' ? Math.sign(det(op.matrix)) : 1) * (spec.timeParity === 'c' && op.timeReversal ? -1 : 1),
|
|
104
|
+
}));
|
|
105
|
+
const spanning = [];
|
|
106
|
+
for (let seed = 0; seed < dim; seed++) {
|
|
107
|
+
const members = orbit(seed, rank, perms);
|
|
108
|
+
if (seed !== Math.min(...members))
|
|
109
|
+
continue;
|
|
110
|
+
const averaged = new Array(dim).fill(0);
|
|
111
|
+
for (const { m, sign } of ops) {
|
|
112
|
+
for (let out = 0; out < dim; out++) {
|
|
113
|
+
const o = d[out];
|
|
114
|
+
let acc = 0;
|
|
115
|
+
for (const s of members) {
|
|
116
|
+
const i = d[s];
|
|
117
|
+
let p = 1;
|
|
118
|
+
for (let r = 0; r < rank; r++)
|
|
119
|
+
p *= m[o[r] * 3 + i[r]];
|
|
120
|
+
acc += p;
|
|
121
|
+
}
|
|
122
|
+
averaged[out] += sign * acc;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (let k = 0; k < dim; k++)
|
|
126
|
+
averaged[k] /= ops.length;
|
|
127
|
+
if (averaged.some((x) => Math.abs(x) >= EPSILON))
|
|
128
|
+
spanning.push(averaged);
|
|
129
|
+
}
|
|
130
|
+
const basis = reducedRowEchelon(spanning, dim).map((row) => row.map(snapEntry));
|
|
131
|
+
const pivots = basis.map((row) => row.findIndex((x) => x !== 0));
|
|
132
|
+
const relations = [];
|
|
133
|
+
for (let c = 0; c < dim; c++) {
|
|
134
|
+
if (pivots.includes(c))
|
|
135
|
+
continue;
|
|
136
|
+
const row = new Array(dim).fill(0);
|
|
137
|
+
row[c] = 1;
|
|
138
|
+
basis.forEach((b, k) => {
|
|
139
|
+
if (b[c] !== 0)
|
|
140
|
+
row[pivots[k]] = -b[c];
|
|
141
|
+
});
|
|
142
|
+
relations.push(row);
|
|
143
|
+
}
|
|
144
|
+
return Object.freeze({
|
|
145
|
+
rank,
|
|
146
|
+
basis: freezeRows(basis),
|
|
147
|
+
parameters: freezeRows(pivots.map((p) => d[p])),
|
|
148
|
+
relations: freezeRows(relations),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* An entry within 10⁻⁹ of a multiple of 1/12 is set to it, so that the exact values of the
|
|
153
|
+
* crystallographic forms (0, ±1/2, ±1, ±2 for the 32 classes in all settings) come out exact instead
|
|
154
|
+
* of with rounding errors of the order of 10⁻¹⁵; other values (e.g. for a rotated frame) are kept.
|
|
155
|
+
*/
|
|
156
|
+
function snapEntry(x) {
|
|
157
|
+
const r = Math.round(x * 12) / 12;
|
|
158
|
+
return Math.abs(x - r) < SNAP_EPSILON ? r + 0 : x;
|
|
159
|
+
}
|
|
160
|
+
function specKey(spec) {
|
|
161
|
+
return `${spec.rank}:${spec.parity}:${spec.timeParity}:${spec.intrinsic}`;
|
|
162
|
+
}
|
|
163
|
+
const formCache = new Map();
|
|
164
|
+
/**
|
|
165
|
+
* The form of a tensor under a point group in the requested setting (default: the default setting
|
|
166
|
+
* of the convention, `'itc'` unless given). The convention matters only through the setting: the
|
|
167
|
+
* same setting index gives the same form in both conventions (docs/conventions.md, "Tensors").
|
|
168
|
+
*/
|
|
169
|
+
export function tensorForm(key, spec, options) {
|
|
170
|
+
const perms = checkSpec(spec);
|
|
171
|
+
const ops = operations(key, options); // checks key, convention and setting
|
|
172
|
+
const index = options?.setting ?? settings(key, options?.convention).find((s) => s.isDefault).index;
|
|
173
|
+
const cacheKey = `${key}#${index}#${specKey(spec)}`;
|
|
174
|
+
let form = formCache.get(cacheKey);
|
|
175
|
+
if (!form) {
|
|
176
|
+
form = project(ops, spec, perms);
|
|
177
|
+
formCache.set(cacheKey, form);
|
|
178
|
+
}
|
|
179
|
+
return form;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The form of a tensor under the group generated by `operations`, e.g. the site symmetry of a
|
|
183
|
+
* surface normal (`siteSymmetry`) or the operations of a distorted crystal. The operations are
|
|
184
|
+
* Cartesian and orthogonal; a list that is not closed is closed first.
|
|
185
|
+
*/
|
|
186
|
+
export function tensorFormOf(operations, spec) {
|
|
187
|
+
const perms = checkSpec(spec);
|
|
188
|
+
operations.forEach((op, i) => checkOrthogonal(op.matrix, `Operation ${i}`));
|
|
189
|
+
return project(closeGroup(operations), spec, perms);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The components of `tensor` (length 3^rank, flat index) in a frame rotated by the orthogonal
|
|
193
|
+
* matrix `rotation`: t′_{i…} = f·Σ R_{ia}…R_{…}·t_{a…}, with f = det(R) for an axial tensor and 1
|
|
194
|
+
* for a polar one. To express a tensor in the frame of a surface, pass the matrix whose rows are
|
|
195
|
+
* the new axes in the old frame. Time parity plays no part.
|
|
196
|
+
*/
|
|
197
|
+
export function rotateTensor(tensor, rotation, spec) {
|
|
198
|
+
checkSpec(spec);
|
|
199
|
+
checkOrthogonal(rotation, 'The rotation');
|
|
200
|
+
const { rank } = spec;
|
|
201
|
+
const dim = 3 ** rank;
|
|
202
|
+
if (tensor.length !== dim)
|
|
203
|
+
throw new RangeError(`A tensor of rank ${rank} has ${dim} components, not ${tensor.length}`);
|
|
204
|
+
const d = digits(rank);
|
|
205
|
+
const m = rotation.flat();
|
|
206
|
+
const f = spec.parity === 'axial' ? Math.sign(det(rotation)) : 1;
|
|
207
|
+
const out = new Array(dim).fill(0);
|
|
208
|
+
for (let o = 0; o < dim; o++) {
|
|
209
|
+
let acc = 0;
|
|
210
|
+
for (let s = 0; s < dim; s++) {
|
|
211
|
+
if (tensor[s] === 0)
|
|
212
|
+
continue;
|
|
213
|
+
let p = tensor[s];
|
|
214
|
+
for (let r = 0; r < rank; r++)
|
|
215
|
+
p *= m[d[o][r] * 3 + d[s][r]];
|
|
216
|
+
acc += p;
|
|
217
|
+
}
|
|
218
|
+
out[o] = f * acc;
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=tensorForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tensorForm.js","sourceRoot":"","sources":["../../src/tensors/tensorForm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,GAAG,EAAa,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAkB,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAA2C,MAAM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AAI,CAAC,CAAC;QACX,CAAC;QACD,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "symcrys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Crystallographic symmetry calculations: point groups (crystallographic and magnetic), their settings, symbols and properties, and property tensors. TypeScript library without dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"crystallography",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/manganite/symcrys.git"
|
|
16
|
+
"url": "git+https://github.com/manganite/symcrys.git",
|
|
17
|
+
"directory": "packages/ts"
|
|
17
18
|
},
|
|
18
19
|
"bugs": "https://github.com/manganite/symcrys/issues",
|
|
19
20
|
"homepage": "https://github.com/manganite/symcrys#readme",
|
|
@@ -32,34 +33,13 @@
|
|
|
32
33
|
"src",
|
|
33
34
|
"!src/**/*.test.ts",
|
|
34
35
|
"!src/**/*.fixtures.ts",
|
|
36
|
+
"!src/**/*.pins.json",
|
|
35
37
|
"!src/**/testUtils/**"
|
|
36
38
|
],
|
|
37
39
|
"sideEffects": false,
|
|
38
40
|
"scripts": {
|
|
39
|
-
"typecheck": "node node_modules/typescript/bin/tsc -p tsconfig.json && node node_modules/typescript/bin/tsc -p tsconfig.build.json --noEmit",
|
|
40
|
-
"typecheck:ts7": "node node_modules/typescript7/bin/tsc -p tsconfig.json && node node_modules/typescript7/bin/tsc -p tsconfig.build.json --noEmit",
|
|
41
|
-
"lint": "eslint .",
|
|
42
|
-
"format": "prettier --write .",
|
|
43
|
-
"format:check": "prettier --check .",
|
|
44
|
-
"test": "vitest run",
|
|
45
|
-
"test:watch": "vitest",
|
|
46
41
|
"prebuild": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
47
|
-
"build": "node node_modules/typescript/bin/tsc -p tsconfig.build.json",
|
|
48
|
-
"
|
|
49
|
-
"prepack": "npm run build",
|
|
50
|
-
"audit:point-groups": "vitest run --config audit/point-groups/vitest.config.ts",
|
|
51
|
-
"audit:birss-app": "vitest run --config audit/birss-app/vitest.config.ts && prettier --write src/pointGroups/birssApp.pins.fixtures.ts",
|
|
52
|
-
"audit:wyckoff-2006": "vitest run --config audit/wyckoff-2006/vitest.config.ts"
|
|
53
|
-
},
|
|
54
|
-
"devDependencies": {
|
|
55
|
-
"@eslint/js": "10.0.1",
|
|
56
|
-
"@types/node": "22.20.5",
|
|
57
|
-
"eslint": "10.15.0",
|
|
58
|
-
"globals": "17.14.0",
|
|
59
|
-
"prettier": "3.9.10",
|
|
60
|
-
"typescript": "6.0.3",
|
|
61
|
-
"typescript-eslint": "8.73.0",
|
|
62
|
-
"typescript7": "npm:typescript@7.0.2",
|
|
63
|
-
"vitest": "5.1.0"
|
|
42
|
+
"build": "node ../../node_modules/typescript/bin/tsc -p tsconfig.build.json",
|
|
43
|
+
"prepack": "npm run build"
|
|
64
44
|
}
|
|
65
45
|
}
|
package/src/index.ts
CHANGED
|
@@ -33,7 +33,7 @@ export {
|
|
|
33
33
|
type SettingOptions,
|
|
34
34
|
type SymbolOptions,
|
|
35
35
|
} from './pointGroups/pointGroups.js';
|
|
36
|
-
export { isCentrosymmetric, isChiral, isPolar, laueClass } from './pointGroups/properties.js';
|
|
36
|
+
export { isCentrosymmetric, isChiral, isPiezoelectric, isPolar, laueClass } from './pointGroups/properties.js';
|
|
37
37
|
export { LATTICE_SYMMETRY_DIRECTIONS, type Uvw } from './symmetryDirections.js';
|
|
38
38
|
export {
|
|
39
39
|
describeOperations,
|
|
@@ -52,3 +52,14 @@ export {
|
|
|
52
52
|
type WyckoffOptions,
|
|
53
53
|
type WyckoffPosition,
|
|
54
54
|
} from './pointGroups/wyckoff.js';
|
|
55
|
+
export {
|
|
56
|
+
rotateTensor,
|
|
57
|
+
tensorForm,
|
|
58
|
+
tensorFormOf,
|
|
59
|
+
type IntrinsicSymmetry,
|
|
60
|
+
type TensorForm,
|
|
61
|
+
type TensorParity,
|
|
62
|
+
type TensorRank,
|
|
63
|
+
type TensorSpec,
|
|
64
|
+
type TimeParity,
|
|
65
|
+
} from './tensors/tensorForm.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Properties of a point group that follow from its operations
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Properties of a point group that follow from its operations, directly or through the form of a
|
|
3
|
+
* tensor (piezoelectric). They do not depend on the setting or the convention. Piezomagnetic,
|
|
4
|
+
* magnetoelectric and ferromagnetic follow with the magnetic point groups (#13).
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { INVERSION, det, matricesEqual } from '../linalg.js';
|
|
@@ -9,6 +9,7 @@ import { EPSILON } from '../tolerances.js';
|
|
|
9
9
|
import { compose, operation, operationsEqual, type Operation } from '../operations.js';
|
|
10
10
|
import { POINT_GROUP_KEYS, type PointGroupKey } from './data.js';
|
|
11
11
|
import { operations } from './pointGroups.js';
|
|
12
|
+
import { tensorForm } from '../tensors/tensorForm.js';
|
|
12
13
|
|
|
13
14
|
/** Operations in setting 1, the frame all stored data share. */
|
|
14
15
|
const stored = (key: PointGroupKey): readonly Operation[] => operations(key, { setting: 1 });
|
|
@@ -60,3 +61,13 @@ export function laueClass(key: PointGroupKey): PointGroupKey {
|
|
|
60
61
|
laueCache.set(key, laue);
|
|
61
62
|
return laue;
|
|
62
63
|
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Piezoelectric: the polarization can depend linearly on stress, i.e. a polar time-even tensor of
|
|
67
|
+
* rank 3, symmetric in its last two indices, is allowed (ITA Table 3.2.2.1).
|
|
68
|
+
*/
|
|
69
|
+
export function isPiezoelectric(key: PointGroupKey): boolean {
|
|
70
|
+
return (
|
|
71
|
+
tensorForm(key, { rank: 3, parity: 'polar', timeParity: 'i', intrinsic: 'jk' }, { setting: 1 }).basis.length > 0
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row reduction of real vectors (any length): the reduced row echelon form of a spanning set, and
|
|
3
|
+
* the rank. The tolerances are those of birss-app's `linalg.ts`, where the tensor code comes from.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** An entry below this (absolute) does not serve as a pivot: float noise is never a new direction. */
|
|
7
|
+
export const PIVOT_EPSILON = 1e-7;
|
|
8
|
+
|
|
9
|
+
/** An entry below this (absolute) is not eliminated, and is set to zero in the result. */
|
|
10
|
+
export const ELIMINATION_EPSILON = 1e-12;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The reduced row echelon form of the span of `vectors` (all of length `dim`): one row per
|
|
14
|
+
* independent direction, each with a 1 at its pivot and 0 at every other row's pivot, pivots
|
|
15
|
+
* ascending. The rows are unique for a given span, so the pivots name the free parameters
|
|
16
|
+
* unambiguously: each is the lowest-index component that is independent of the ones before it.
|
|
17
|
+
*/
|
|
18
|
+
export function reducedRowEchelon(vectors: readonly (readonly number[])[], dim: number): number[][] {
|
|
19
|
+
const m = vectors.map((v) => Array.from(v));
|
|
20
|
+
let row = 0;
|
|
21
|
+
for (let c = 0; c < dim && row < m.length; c++) {
|
|
22
|
+
let pivot = row;
|
|
23
|
+
for (let r = row + 1; r < m.length; r++) if (Math.abs(m[r][c]) > Math.abs(m[pivot][c])) pivot = r;
|
|
24
|
+
if (Math.abs(m[pivot][c]) < PIVOT_EPSILON) continue;
|
|
25
|
+
[m[row], m[pivot]] = [m[pivot], m[row]];
|
|
26
|
+
const p = m[row][c];
|
|
27
|
+
for (let j = 0; j < dim; j++) m[row][j] /= p;
|
|
28
|
+
for (let r = 0; r < m.length; r++) {
|
|
29
|
+
if (r === row || Math.abs(m[r][c]) <= ELIMINATION_EPSILON) continue;
|
|
30
|
+
const f = m[r][c];
|
|
31
|
+
for (let j = 0; j < dim; j++) m[r][j] -= f * m[row][j];
|
|
32
|
+
}
|
|
33
|
+
row++;
|
|
34
|
+
}
|
|
35
|
+
const out = m.slice(0, row);
|
|
36
|
+
for (const r of out) for (let j = 0; j < dim; j++) if (Math.abs(r[j]) < ELIMINATION_EPSILON) r[j] = 0;
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The number of independent vectors among `vectors` (all of length `dim`). */
|
|
41
|
+
export function rank(vectors: readonly (readonly number[])[], dim: number): number {
|
|
42
|
+
return reducedRowEchelon(vectors, dim).length;
|
|
43
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symmetry-reduced forms of property tensors: which Cartesian components of a tensor of rank 0 to 4
|
|
3
|
+
* a point group allows, and how they depend on each other. Results are plain numbers (coefficient
|
|
4
|
+
* matrices and index lists); formulas, LaTeX and diagrams stay in the applications (CLAUDE.md,
|
|
5
|
+
* "Tensors").
|
|
6
|
+
*
|
|
7
|
+
* Components are numbered by their flat index: for indices (i₁, …, iₙ) with x, y, z = 0, 1, 2 the
|
|
8
|
+
* flat index is i₁·3ⁿ⁻¹ + … + iₙ, so the first index varies slowest (row-major, the order of a
|
|
9
|
+
* NumPy array of shape (3,)*n in C order). Moved from birss-app (`tensorForms.ts`,
|
|
10
|
+
* `tensorProjection.ts`, `linalg.ts`, revision 2be5fe3).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { det, type Mat3 } from '../linalg.js';
|
|
14
|
+
import { closeGroup, type Operation } from '../operations.js';
|
|
15
|
+
import { operations, settings, type PointGroupKey, type SettingOptions } from '../pointGroups/pointGroups.js';
|
|
16
|
+
import { EPSILON, SNAP_EPSILON } from '../tolerances.js';
|
|
17
|
+
import { reducedRowEchelon } from './rowEchelon.js';
|
|
18
|
+
|
|
19
|
+
/** Rank of a tensor: 0 (scalar) to 4. */
|
|
20
|
+
export type TensorRank = 0 | 1 | 2 | 3 | 4;
|
|
21
|
+
|
|
22
|
+
/** `'polar'`: transforms with R; `'axial'`: with det(R)·R (pseudotensor). */
|
|
23
|
+
export type TensorParity = 'polar' | 'axial';
|
|
24
|
+
|
|
25
|
+
/** `'i'`: time-even (invariant under time reversal); `'c'`: time-odd (changes sign). */
|
|
26
|
+
export type TimeParity = 'i' | 'c';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Symmetry of the tensor under permutation of its own indices, independent of the crystal:
|
|
30
|
+
* `'none'`; `'ij'`: the first two indices are interchangeable; `'jk'`: the last two (for rank 3 the
|
|
31
|
+
* index symmetry of second-harmonic generation and the piezoelectric effect); `'ij_kl'` (rank 4):
|
|
32
|
+
* each of the two pairs symmetric, the pairs not interchangeable (e.g. electric-quadrupole SHG,
|
|
33
|
+
* photoelasticity); `'voigt'` (rank 4): `'ij_kl'` and the pairs interchangeable (elastic
|
|
34
|
+
* stiffness). At rank 2, `'ij'` and `'jk'` both mean a symmetric tensor.
|
|
35
|
+
*/
|
|
36
|
+
export type IntrinsicSymmetry = 'none' | 'ij' | 'jk' | 'ij_kl' | 'voigt';
|
|
37
|
+
|
|
38
|
+
/** The kind of tensor, as in birss-app. */
|
|
39
|
+
export interface TensorSpec {
|
|
40
|
+
readonly rank: TensorRank;
|
|
41
|
+
readonly parity: TensorParity;
|
|
42
|
+
readonly timeParity: TimeParity;
|
|
43
|
+
readonly intrinsic: IntrinsicSymmetry;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The form of a tensor under a point group: the subspace of tensors invariant under every
|
|
48
|
+
* operation and with the requested index symmetry. Every entry is a plain number; a vector of
|
|
49
|
+
* components has length 3^rank (flat index, see the module documentation).
|
|
50
|
+
*/
|
|
51
|
+
export interface TensorForm {
|
|
52
|
+
readonly rank: TensorRank;
|
|
53
|
+
/**
|
|
54
|
+
* A basis of the allowed tensors in reduced row echelon form: one row per free parameter, with 1
|
|
55
|
+
* at the parameter's own component and 0 at every other parameter's component. Every allowed
|
|
56
|
+
* tensor is Σₖ pₖ·basis[k], where pₖ is the value of its component `parameters[k]`. Empty if the
|
|
57
|
+
* tensor vanishes.
|
|
58
|
+
*/
|
|
59
|
+
readonly basis: readonly (readonly number[])[];
|
|
60
|
+
/**
|
|
61
|
+
* The free parameters, as the index lists of their components (e.g. `[0, 1, 1]` for xyy), one per
|
|
62
|
+
* basis row and in its order: each is the lowest component independent of those before it.
|
|
63
|
+
*/
|
|
64
|
+
readonly parameters: readonly (readonly number[])[];
|
|
65
|
+
/**
|
|
66
|
+
* The constraints: one row r per component that is not a parameter, in ascending flat index,
|
|
67
|
+
* with r·t = 0 for every allowed tensor t. Row c reads t_c − Σₖ basis[k][c]·t_{parameters[k]} = 0;
|
|
68
|
+
* a row with a single 1 says that the component vanishes.
|
|
69
|
+
*/
|
|
70
|
+
readonly relations: readonly (readonly number[])[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const RANKS: readonly number[] = [0, 1, 2, 3, 4];
|
|
74
|
+
|
|
75
|
+
/** Checks a specification and returns the index permutations that generate its intrinsic symmetry. */
|
|
76
|
+
function checkSpec(spec: TensorSpec): number[][] {
|
|
77
|
+
const { rank, parity, timeParity, intrinsic } = spec;
|
|
78
|
+
if (!RANKS.includes(rank)) throw new RangeError(`Tensor rank must be 0 to 4, not ${JSON.stringify(rank)}`);
|
|
79
|
+
if (parity !== 'polar' && parity !== 'axial')
|
|
80
|
+
throw new RangeError(`Unknown tensor parity: ${JSON.stringify(parity)}`);
|
|
81
|
+
if (timeParity !== 'i' && timeParity !== 'c')
|
|
82
|
+
throw new RangeError(`Unknown time parity: ${JSON.stringify(timeParity)}`);
|
|
83
|
+
const swap = (a: number, b: number) => {
|
|
84
|
+
const p = Array.from({ length: rank }, (_, k) => k);
|
|
85
|
+
[p[a], p[b]] = [p[b], p[a]];
|
|
86
|
+
return p;
|
|
87
|
+
};
|
|
88
|
+
switch (intrinsic) {
|
|
89
|
+
case 'none':
|
|
90
|
+
return [];
|
|
91
|
+
case 'ij':
|
|
92
|
+
case 'jk':
|
|
93
|
+
if (rank < 2) throw new RangeError(`Intrinsic symmetry '${intrinsic}' needs rank 2 or more, not ${rank}`);
|
|
94
|
+
return [intrinsic === 'ij' ? swap(0, 1) : swap(rank - 2, rank - 1)];
|
|
95
|
+
case 'ij_kl':
|
|
96
|
+
case 'voigt':
|
|
97
|
+
if (rank !== 4) throw new RangeError(`Intrinsic symmetry '${intrinsic}' needs rank 4, not ${rank}`);
|
|
98
|
+
return intrinsic === 'ij_kl' ? [swap(0, 1), swap(2, 3)] : [swap(0, 1), swap(2, 3), [2, 3, 0, 1]];
|
|
99
|
+
default:
|
|
100
|
+
throw new RangeError(`Unknown intrinsic symmetry: ${JSON.stringify(intrinsic)}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Throws unless `m` is orthogonal (mᵀm = 1 within `EPSILON`): the code assumes Cartesian matrices. */
|
|
105
|
+
function checkOrthogonal(m: Mat3, what: string): void {
|
|
106
|
+
for (let i = 0; i < 3; i++) {
|
|
107
|
+
for (let j = 0; j < 3; j++) {
|
|
108
|
+
const dot = m[0][i] * m[0][j] + m[1][i] * m[1][j] + m[2][i] * m[2][j];
|
|
109
|
+
if (Math.abs(dot - (i === j ? 1 : 0)) > EPSILON) {
|
|
110
|
+
throw new RangeError(`${what} is not an orthogonal (Cartesian) matrix: ${JSON.stringify(m)}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The indices (x, y, z = 0, 1, 2) of every flat index at a rank, first index first. */
|
|
117
|
+
const digitTables = new Map<number, readonly (readonly number[])[]>();
|
|
118
|
+
function digits(rank: number): readonly (readonly number[])[] {
|
|
119
|
+
let table = digitTables.get(rank);
|
|
120
|
+
if (!table) {
|
|
121
|
+
table = Array.from({ length: 3 ** rank }, (_, flat) =>
|
|
122
|
+
Array.from({ length: rank }, (_, k) => Math.floor(flat / 3 ** (rank - 1 - k)) % 3),
|
|
123
|
+
);
|
|
124
|
+
digitTables.set(rank, table);
|
|
125
|
+
}
|
|
126
|
+
return table;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The flat indices reached from `flat` by the index permutations (`out[k] = in[perm[k]]`). */
|
|
130
|
+
function orbit(flat: number, rank: number, perms: readonly number[][]): number[] {
|
|
131
|
+
const d = digits(rank);
|
|
132
|
+
const seen = new Set([flat]);
|
|
133
|
+
const stack = [flat];
|
|
134
|
+
while (stack.length > 0) {
|
|
135
|
+
const cur = stack.pop()!;
|
|
136
|
+
for (const p of perms) {
|
|
137
|
+
let next = 0;
|
|
138
|
+
for (let k = 0; k < rank; k++) next = next * 3 + d[cur][p[k]];
|
|
139
|
+
if (!seen.has(next)) {
|
|
140
|
+
seen.add(next);
|
|
141
|
+
stack.push(next);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return [...seen];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function freezeRows(rows: readonly (readonly number[])[]): readonly (readonly number[])[] {
|
|
149
|
+
return Object.freeze(rows.map((r) => Object.freeze([...r])));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The form for a group given as its full list of operations. The group average of each seed
|
|
154
|
+
* (a unit tensor on one orbit of the intrinsic symmetry) projects it onto the invariant subspace;
|
|
155
|
+
* the projections span it, and the reduced row echelon form makes the basis minimal and canonical.
|
|
156
|
+
*/
|
|
157
|
+
function project(group: readonly Operation[], spec: TensorSpec, perms: number[][]): TensorForm {
|
|
158
|
+
const { rank } = spec;
|
|
159
|
+
const dim = 3 ** rank;
|
|
160
|
+
const d = digits(rank);
|
|
161
|
+
const ops = group.map((op) => ({
|
|
162
|
+
m: op.matrix.flat(),
|
|
163
|
+
sign:
|
|
164
|
+
(spec.parity === 'axial' ? Math.sign(det(op.matrix)) : 1) * (spec.timeParity === 'c' && op.timeReversal ? -1 : 1),
|
|
165
|
+
}));
|
|
166
|
+
|
|
167
|
+
const spanning: number[][] = [];
|
|
168
|
+
for (let seed = 0; seed < dim; seed++) {
|
|
169
|
+
const members = orbit(seed, rank, perms);
|
|
170
|
+
if (seed !== Math.min(...members)) continue;
|
|
171
|
+
const averaged = new Array<number>(dim).fill(0);
|
|
172
|
+
for (const { m, sign } of ops) {
|
|
173
|
+
for (let out = 0; out < dim; out++) {
|
|
174
|
+
const o = d[out];
|
|
175
|
+
let acc = 0;
|
|
176
|
+
for (const s of members) {
|
|
177
|
+
const i = d[s];
|
|
178
|
+
let p = 1;
|
|
179
|
+
for (let r = 0; r < rank; r++) p *= m[o[r] * 3 + i[r]];
|
|
180
|
+
acc += p;
|
|
181
|
+
}
|
|
182
|
+
averaged[out] += sign * acc;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
for (let k = 0; k < dim; k++) averaged[k] /= ops.length;
|
|
186
|
+
if (averaged.some((x) => Math.abs(x) >= EPSILON)) spanning.push(averaged);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const basis = reducedRowEchelon(spanning, dim).map((row) => row.map(snapEntry));
|
|
190
|
+
const pivots = basis.map((row) => row.findIndex((x) => x !== 0));
|
|
191
|
+
const relations: number[][] = [];
|
|
192
|
+
for (let c = 0; c < dim; c++) {
|
|
193
|
+
if (pivots.includes(c)) continue;
|
|
194
|
+
const row = new Array<number>(dim).fill(0);
|
|
195
|
+
row[c] = 1;
|
|
196
|
+
basis.forEach((b, k) => {
|
|
197
|
+
if (b[c] !== 0) row[pivots[k]] = -b[c];
|
|
198
|
+
});
|
|
199
|
+
relations.push(row);
|
|
200
|
+
}
|
|
201
|
+
return Object.freeze({
|
|
202
|
+
rank,
|
|
203
|
+
basis: freezeRows(basis),
|
|
204
|
+
parameters: freezeRows(pivots.map((p) => d[p])),
|
|
205
|
+
relations: freezeRows(relations),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* An entry within 10⁻⁹ of a multiple of 1/12 is set to it, so that the exact values of the
|
|
211
|
+
* crystallographic forms (0, ±1/2, ±1, ±2 for the 32 classes in all settings) come out exact instead
|
|
212
|
+
* of with rounding errors of the order of 10⁻¹⁵; other values (e.g. for a rotated frame) are kept.
|
|
213
|
+
*/
|
|
214
|
+
function snapEntry(x: number): number {
|
|
215
|
+
const r = Math.round(x * 12) / 12;
|
|
216
|
+
return Math.abs(x - r) < SNAP_EPSILON ? r + 0 : x;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function specKey(spec: TensorSpec): string {
|
|
220
|
+
return `${spec.rank}:${spec.parity}:${spec.timeParity}:${spec.intrinsic}`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const formCache = new Map<string, TensorForm>();
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The form of a tensor under a point group in the requested setting (default: the default setting
|
|
227
|
+
* of the convention, `'itc'` unless given). The convention matters only through the setting: the
|
|
228
|
+
* same setting index gives the same form in both conventions (docs/conventions.md, "Tensors").
|
|
229
|
+
*/
|
|
230
|
+
export function tensorForm(key: PointGroupKey, spec: TensorSpec, options?: SettingOptions): TensorForm {
|
|
231
|
+
const perms = checkSpec(spec);
|
|
232
|
+
const ops = operations(key, options); // checks key, convention and setting
|
|
233
|
+
const index = options?.setting ?? settings(key, options?.convention).find((s) => s.isDefault)!.index;
|
|
234
|
+
const cacheKey = `${key}#${index}#${specKey(spec)}`;
|
|
235
|
+
let form = formCache.get(cacheKey);
|
|
236
|
+
if (!form) {
|
|
237
|
+
form = project(ops, spec, perms);
|
|
238
|
+
formCache.set(cacheKey, form);
|
|
239
|
+
}
|
|
240
|
+
return form;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The form of a tensor under the group generated by `operations`, e.g. the site symmetry of a
|
|
245
|
+
* surface normal (`siteSymmetry`) or the operations of a distorted crystal. The operations are
|
|
246
|
+
* Cartesian and orthogonal; a list that is not closed is closed first.
|
|
247
|
+
*/
|
|
248
|
+
export function tensorFormOf(operations: readonly Operation[], spec: TensorSpec): TensorForm {
|
|
249
|
+
const perms = checkSpec(spec);
|
|
250
|
+
operations.forEach((op, i) => checkOrthogonal(op.matrix, `Operation ${i}`));
|
|
251
|
+
return project(closeGroup(operations), spec, perms);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The components of `tensor` (length 3^rank, flat index) in a frame rotated by the orthogonal
|
|
256
|
+
* matrix `rotation`: t′_{i…} = f·Σ R_{ia}…R_{…}·t_{a…}, with f = det(R) for an axial tensor and 1
|
|
257
|
+
* for a polar one. To express a tensor in the frame of a surface, pass the matrix whose rows are
|
|
258
|
+
* the new axes in the old frame. Time parity plays no part.
|
|
259
|
+
*/
|
|
260
|
+
export function rotateTensor(tensor: readonly number[], rotation: Mat3, spec: TensorSpec): number[] {
|
|
261
|
+
checkSpec(spec);
|
|
262
|
+
checkOrthogonal(rotation, 'The rotation');
|
|
263
|
+
const { rank } = spec;
|
|
264
|
+
const dim = 3 ** rank;
|
|
265
|
+
if (tensor.length !== dim)
|
|
266
|
+
throw new RangeError(`A tensor of rank ${rank} has ${dim} components, not ${tensor.length}`);
|
|
267
|
+
const d = digits(rank);
|
|
268
|
+
const m = rotation.flat();
|
|
269
|
+
const f = spec.parity === 'axial' ? Math.sign(det(rotation)) : 1;
|
|
270
|
+
const out = new Array<number>(dim).fill(0);
|
|
271
|
+
for (let o = 0; o < dim; o++) {
|
|
272
|
+
let acc = 0;
|
|
273
|
+
for (let s = 0; s < dim; s++) {
|
|
274
|
+
if (tensor[s] === 0) continue;
|
|
275
|
+
let p = tensor[s];
|
|
276
|
+
for (let r = 0; r < rank; r++) p *= m[d[o][r] * 3 + d[s][r]];
|
|
277
|
+
acc += p;
|
|
278
|
+
}
|
|
279
|
+
out[o] = f * acc;
|
|
280
|
+
}
|
|
281
|
+
return out;
|
|
282
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Version of symcrys. Kept equal to `version` in package.json (checked by version.test.ts). */
|
|
2
|
-
export const VERSION = '0.
|
|
2
|
+
export const VERSION = '0.5.0';
|