driftlet 1.1.1 → 1.2.2

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/types/solver.d.ts CHANGED
@@ -99,6 +99,7 @@ export class Solver {
99
99
  termB: any;
100
100
  termC: any;
101
101
  termDI: Float64Array<any>;
102
+ termDX: any;
102
103
  termRes: Float64Array<any>;
103
104
  history: any[];
104
105
  dtNext: any;
@@ -137,43 +138,93 @@ export class Solver {
137
138
  _findStretches(): void;
138
139
  stretches: any[];
139
140
  stretchOf: Int32Array<ArrayBuffer>;
141
+ rough: number[];
140
142
  moieties: Float64Array<any>[];
141
143
  flatStretches: any[];
142
144
  _roughAmount(st: any): number;
143
- _moves(st: any): boolean;
144
- _still(st: any): boolean;
145
- _feeds(k: any, st: any): any;
146
145
  _laws(): void;
147
146
  constraints: any[];
148
- affinities: any[];
149
- localConstraints: any[];
150
- islands: any[];
147
+ affinities: {
148
+ rx: any;
149
+ f: any;
150
+ row: any;
151
+ idx: Int32Array<any>;
152
+ w: Float64Array<any>;
153
+ len: number;
154
+ res: number;
155
+ }[];
156
+ localConstraints: {
157
+ parts: ({
158
+ i: any;
159
+ w: number;
160
+ q?: undefined;
161
+ k?: undefined;
162
+ } | {
163
+ q: any;
164
+ k: any;
165
+ w: number;
166
+ i?: undefined;
167
+ })[];
168
+ row: any;
169
+ nodes: any;
170
+ reference: Float64Array<any>;
171
+ }[];
172
+ islands: {
173
+ stretch: any;
174
+ row: any;
175
+ flux: any[];
176
+ weight: number[];
177
+ outside: any[];
178
+ idx: Int32Array<ArrayBuffer>;
179
+ w: Float64Array<ArrayBuffer>;
180
+ len: number;
181
+ res: number;
182
+ }[];
183
+ timeLaws: {
184
+ parts: {
185
+ stretch: number;
186
+ w: number;
187
+ }[];
188
+ surface: {
189
+ col: number;
190
+ w: number;
191
+ }[];
192
+ carriers: any;
193
+ terminals: any[];
194
+ circuit: any;
195
+ lambda: number;
196
+ idx: Int32Array<ArrayBuffer>;
197
+ w: Float64Array<ArrayBuffer>;
198
+ len: number;
199
+ }[];
200
+ contactLaw: boolean[];
201
+ carriers: any;
202
+ unkept: Float64Array<any>[];
203
+ contactQ: any[];
151
204
  pinnedIslands: any[];
152
205
  islandsOn: boolean;
153
206
  pins: any[];
154
- timeLaws: any[];
155
- carriers: any;
156
- _captureLaws(): void;
157
- _captureLocal(): void;
158
- _applyIslands(): any[];
159
- islandRow: Float64Array<any>;
160
- _rowInto(o: any, add: any): void;
161
- linRow: Float64Array<any>;
162
- _applyLocalConstraints(): void;
163
- _conservedMoieties(drives?: boolean, alsoCurrent?: any[], skip?: any): Float64Array<any>[];
164
- _directSteady(): boolean;
165
- _applyConstraints(): void;
166
- _lawAmount(cs: any): {
167
- amount: number;
168
- reference: number;
169
- dV: number;
170
- gross: number;
207
+ _structure(): {
208
+ model: any;
209
+ n: any;
210
+ M: any;
211
+ z: Int32Array<ArrayBuffer>;
212
+ nNodes: any;
213
+ stretches: any[];
214
+ stretchOf: Int32Array<ArrayBuffer>;
215
+ flatStretches: any[];
216
+ rough: number[];
217
+ surfCols: any;
218
+ surfColOf: any;
219
+ terms: any;
220
+ floating: any;
221
+ blockOfNode: Int32Array<any>;
222
+ blockOfFace: Int32Array<ArrayBuffer>;
223
+ rxsIn: any;
224
+ nodeMaterial: Int32Array<any>;
225
+ phiUndefined: Uint8Array<any>;
171
226
  };
172
- _lawStart(cs: any): number;
173
- _circuitLaws(dt: any): void;
174
- _solveBordered(rhs: any, delta: any, deltaV: any, pins: any): void;
175
- dWork: Float64Array<any>;
176
- borderCols: any[];
227
+ _directSteady(): boolean;
177
228
  _surfaceStart(g: any): void;
178
229
  /** Amount (mol per unit area) of surface column j's species, Γ Σ v·a·θ, in the current state. */
179
230
  surfaceAmount(j: any): number;
@@ -183,7 +234,6 @@ export class Solver {
183
234
  deltaV: Float64Array<any>;
184
235
  stuckReactions(): any[];
185
236
  _drivenKey(): any;
186
- _noCurrent(t: any): boolean;
187
237
  _refreshSources(): void;
188
238
  /** η_i (μ̄/RT) of a port's outside level for species i (its electrode's carrier: at V itself). */
189
239
  portEta(port: any, i: any): number;
@@ -266,14 +316,6 @@ export class Solver {
266
316
  _portCapacitance(port: any, k: any, dt: any): void;
267
317
  _surfaceStorage(port: any, dt: any): void;
268
318
  _contact(side: any, dt: any): void;
269
- _flatLevel(st: any): {
270
- k: number;
271
- hi: number;
272
- lo: number;
273
- };
274
- _snapFlat(): void;
275
- _flatRows(): void;
276
- _applyAffinities(): void;
277
319
  _replaceRow(b: any, rs: any): void;
278
320
  _equilibrate(): void;
279
321
  _assembleDifference(dt: any): {
@@ -450,7 +492,7 @@ export class Solver {
450
492
  * Steady state: where a transient from the present state ends, found as the solution of the
451
493
  * steady equations (dt = ∞, no storage term), with no slow modes to wait out, however slow the
452
494
  * physics (e.g. exponentially scarce minority carriers). What the storage term held is held by
453
- * the steady system's own rows instead (see _laws): each conserved amount in place of a balance
495
+ * the steady system's own rows instead (see src/laws.js): each conserved amount in place of a balance
454
496
  * row that says nothing new, levels that carry nothing held flat, islands' summed balances.
455
497
  * Where Newton from here fails: continuation along the drives, then the pseudo-transient ramp.
456
498
  * The clock is not advanced, and open-system conservation bookkeeping restarts here.
@@ -472,7 +514,6 @@ export class Solver {
472
514
  _steadyFromHere(opts: any): any;
473
515
  dimmer: boolean;
474
516
  _bound(k: any): boolean;
475
- _chargeOnly(k: any): boolean;
476
517
  _floatingContinuation(opts: any, r: any): any;
477
518
  _generationContinuation(opts: any, r: any): {
478
519
  converged: boolean;
package/types/types.d.ts CHANGED
@@ -28,6 +28,9 @@ export type MaterialSpeciesDef = {
28
28
  * potentials ζ = (μ̄ − zFφ − μ°)/RT. Species not in any model are ideal, c = c_ref e^ζ.
29
29
  */
30
30
  export type StatisticsDef = ({
31
+ type: "ideal";
32
+ species: string[];
33
+ } | {
31
34
  type: "fermi-dirac";
32
35
  species: string[];
33
36
  order?: 0.5 | 0;
@@ -161,13 +164,45 @@ export type InterfacePhiLaw = "pinned" | "neutral" | {
161
164
  type: "capacitive";
162
165
  C: number;
163
166
  };
167
+ /**
168
+ * A species' law across a face. conductance: J = G (V_L − V_R), G in S/m², charged species;
169
+ * permeability: Goldman–Hodgkin–Katz electrodiffusion, P in m/s, ideal statistics on both sides,
170
+ * not beside a conductor. gates: the face's gates that scale G or P, with their exponents
171
+ * ({ m: 3, h: 1 } for m³h; not beside a conductor).
172
+ */
164
173
  export type InterfaceSpeciesLink = "equilibrium" | "blocked" | {
174
+ type: "equilibrium" | "blocked";
175
+ } | {
165
176
  type: "conductance";
166
177
  G: number;
178
+ gates?: Record<string, number>;
179
+ } | {
180
+ type: "permeability";
181
+ P: number;
182
+ gates?: Record<string, number>;
183
+ };
184
+ /**
185
+ * One of a gate's rates (1/s) in the voltage V it follows, in NeuroML's standard forms (midpoint
186
+ * and scale in V, scale ≠ 0): 'exp', rate·e^((V − midpoint)/scale); 'sigmoid',
187
+ * rate/(1 + e^((midpoint − V)/scale)); 'expLinear', rate·y/(1 − e^(−y)), y = (V − midpoint)/scale.
188
+ */
189
+ export type GateRate = {
190
+ type: "exp" | "sigmoid" | "expLinear";
191
+ rate: number;
192
+ midpoint: number;
193
+ scale: number;
194
+ };
195
+ /**
196
+ * A Hodgkin–Huxley gate: a fraction open x in [0, 1], dx/dt = α(V)(1 − x) − β(V)x.
197
+ */
198
+ export type GateDef = {
199
+ alpha: GateRate;
200
+ beta: GateRate;
167
201
  };
168
202
  /**
169
203
  * A reaction at a face: participants on each side with signed stoichiometric coefficients
170
- * (ν < 0 consumed by the forward reaction), Butler–Volmer kinetics.
204
+ * (ν < 0 consumed by the forward reaction). Butler–Volmer kinetics (k0, alpha), or instead SRH
205
+ * (srh) or saturating (vmax and K), neither with a conductor's carrier.
171
206
  */
172
207
  export type FaceReactionDef = {
173
208
  /**
@@ -188,13 +223,32 @@ export type FaceReactionDef = {
188
223
  */
189
224
  fixed?: Record<string, number>;
190
225
  /**
191
- * standard rate constant, mol/(m²·s)
226
+ * Butler–Volmer: standard rate constant, mol/(m²·s) (required unless srh or vmax)
192
227
  */
193
- k0: number;
228
+ k0?: number;
194
229
  /**
195
- * transfer coefficient, 0…1 (default 0.5)
230
+ * with k0: transfer coefficient, 0…1 (default 0.5)
196
231
  */
197
232
  alpha?: number;
233
+ /**
234
+ * instead: trap-assisted recombination, for a
235
+ * reaction consuming one negative and one positive species and making none; capture velocities
236
+ * vn, vp in m/s, n1 in mol/m³ (default n_i, a midgap trap)
237
+ */
238
+ srh?: {
239
+ vn: number;
240
+ vp: number;
241
+ n1?: number;
242
+ };
243
+ /**
244
+ * instead: saturating kinetics, the largest rate, mol/(m²·s)
245
+ */
246
+ vmax?: number;
247
+ /**
248
+ * with vmax: a half-saturation concentration (mol/m³) for
249
+ * every species the forward reaction consumes
250
+ */
251
+ K?: Record<string, number>;
198
252
  };
199
253
  /**
200
254
  * One face between consecutive regions. For different materials under a 'pinned' or
@@ -217,7 +271,8 @@ export type InterfaceDef = {
217
271
  */
218
272
  zeroCharge?: number;
219
273
  /**
220
- * electrostatic law (default 'pinned'; 'neutral' between ε = 0 materials)
274
+ * electrostatic law (default 'pinned'; 'neutral' between ε = 0 materials;
275
+ * beside a conductor 'neutral' or capacitive, required next to an ε > 0 material)
221
276
  */
222
277
  phi?: InterfacePhiLaw;
223
278
  /**
@@ -226,13 +281,19 @@ export type InterfaceDef = {
226
281
  sheetCharge?: number;
227
282
  /**
228
283
  * per-species laws (default equilibrium
229
- * where present on both sides and not reacting at the face)
284
+ * where present on both sides and mobile on one, blocked otherwise; a species reacting at the
285
+ * face and present on both sides has no default)
230
286
  */
231
287
  species?: Record<string, InterfaceSpeciesLink>;
232
288
  /**
233
289
  * reactions at the face
234
290
  */
235
291
  reactions?: FaceReactionDef[];
292
+ /**
293
+ * voltage-gated channels: gates following
294
+ * V = φ_right − φ_left, which its links name (not beside a conductor)
295
+ */
296
+ gates?: Record<string, GateDef>;
236
297
  };
237
298
  export type BulkReactionDef = {
238
299
  /**
@@ -248,16 +309,29 @@ export type BulkReactionDef = {
248
309
  */
249
310
  fixed?: Record<string, number>;
250
311
  /**
251
- * forward rate constant per material name, or a
252
- * profile of it against the device's x (an absorption profile, for photogeneration)
312
+ * mass action: forward rate constant per material
313
+ * name, or a profile of it against the device's x (an absorption profile, for photogeneration);
314
+ * give kf or srh
253
315
  */
254
- kf: Record<string, number | Profile>;
316
+ kf?: Record<string, number | Profile>;
317
+ /**
318
+ * instead: SRH
319
+ * (trap-assisted) recombination per material name, for a reaction consuming one negative and
320
+ * one positive species and making none; lifetimes in s, n1 in mol/m³ (default n_i, a midgap trap)
321
+ */
322
+ srh?: Record<string, {
323
+ tauN: number;
324
+ tauP: number;
325
+ n1?: number;
326
+ }>;
255
327
  };
256
328
  /**
257
329
  * Contacts use the same laws as internal faces; the outside is a phase with known levels
258
330
  * V_i = V + offset_i (a rigid ladder that the circuit slides by V).
259
331
  */
260
332
  export type ContactSpeciesLink = "blocked" | "equilibrium" | {
333
+ type: "blocked";
334
+ } | {
261
335
  type: "equilibrium";
262
336
  offset?: number;
263
337
  mu?: number;
@@ -306,16 +380,18 @@ export type ContactDef = {
306
380
  */
307
381
  species?: Record<string, ContactSpeciesLink>;
308
382
  /**
309
- * a neutral
310
- * composition held at the contact, anchored through a charged reference species
383
+ * instead of species: a neutral composition c (mol/m³) held at the contact, anchored through a
384
+ * charged reference species (offset: its V_i − V, V); with no reference, V is the bath's φ. It's
385
+ * the end material at that composition, or the material it names (a solution beside a charged region)
311
386
  */
312
387
  bath?: {
313
388
  c: Record<string, number>;
314
- reference: string;
389
+ reference?: string;
315
390
  offset?: number;
391
+ material?: string;
316
392
  };
317
393
  /**
318
- * required when any species connects (default 'neutral')
394
+ * required when any species connects (default 'neutral'; 'bulk' with a bath)
319
395
  */
320
396
  phi?: ContactPhiLink;
321
397
  /**
@@ -367,7 +443,14 @@ export type PortDef = {
367
443
  * species whose offset defaults to 0; with reactions, the electrode's carrier
368
444
  */
369
445
  terminal?: string;
446
+ /**
447
+ * per-species links, per volume (default
448
+ * blocked): G in S/m³ (S/m² on a conductor), k in mol/(m³·s); a conductance's gates name the
449
+ * port's gates that scale G, with their exponents
450
+ */
370
451
  species?: Record<string, "blocked" | "equilibrium" | {
452
+ type: "blocked";
453
+ } | {
371
454
  type: "equilibrium";
372
455
  offset?: number;
373
456
  mu?: number;
@@ -375,28 +458,36 @@ export type PortDef = {
375
458
  type: "conductance";
376
459
  G: number;
377
460
  offset?: number;
461
+ gates?: Record<string, number>;
378
462
  } | {
379
463
  type: "exchange";
380
464
  k: number;
381
465
  mu: number;
382
466
  }>;
467
+ /**
468
+ * the outside's composition (mol/m³): V is then its φ,
469
+ * and each linked species' level there follows from it (unless its link gives an offset or mu)
470
+ */
471
+ bath?: {
472
+ c: Record<string, number>;
473
+ };
383
474
  /**
384
475
  * an
385
- * electrode spread through the window: Butler–Volmer per area (k0 in mol/(m²·s)) between the region's
386
- * species and the terminal species at the port's level
476
+ * electrode spread through the window: Butler–Volmer per area (k0 in mol/(m²·s), alpha default 0.5)
477
+ * between the region's species and the terminal species at the port's level
387
478
  */
388
479
  reactions?: {
389
480
  equation: string;
390
481
  fixed?: Record<string, number>;
391
482
  k0: number;
392
- alpha: number;
483
+ alpha?: number;
393
484
  bare?: boolean;
394
485
  }[];
395
486
  /**
396
487
  * with reactions: species
397
488
  * on the electrode's sites, Langmuir (μ = μ° + RT ln(θ/θ₀)), capacity in mol of sites per m² of electrode,
398
- * shared; reactions run on Langmuir sites (what fills sites needs bare ones), and one with `bare: true`
399
- * needs a bare site even if it fills none (θ₀ = 1 − Σθ)
489
+ * shared, theta0 the starting coverage (default 1e-6); reactions run on Langmuir sites (what fills
490
+ * sites needs bare ones), and one with `bare: true` needs a bare site even if it fills none (θ₀ = 1 − Σθ)
400
491
  */
401
492
  surface?: Record<string, {
402
493
  mu0: number;
@@ -420,6 +511,11 @@ export type PortDef = {
420
511
  x: number[];
421
512
  values: number[];
422
513
  };
514
+ /**
515
+ * with a capacitance: voltage-gated channels at each node of
516
+ * the window, following the voltage across it, φ − (V − zeroCharge), which its conductance links name
517
+ */
518
+ gates?: Record<string, GateDef>;
423
519
  };
424
520
  /**
425
521
  * A device definition: plain, serialisable data.
@@ -481,6 +577,10 @@ export type ContactResult = {
481
577
  * total current toward +x, A/m²
482
578
  */
483
579
  current: number;
580
+ /**
581
+ * how each species that crosses it does (its link type)
582
+ */
583
+ links: Record<string, string>;
484
584
  };
485
585
  /**
486
586
  * The device's totals through its cross-section (currents, fluxes through contacts and ports,
@@ -537,6 +637,23 @@ export type Solution = {
537
637
  * standard levels as voltages, V
538
638
  */
539
639
  Vstd: Record<string, Float64Array>;
640
+ /**
641
+ * each species' flux toward +x across each segment, between
642
+ * nodes g and g + 1 (a face's across its pair of nodes), mol/(m²·s): the fluxes the balances add up
643
+ */
644
+ flux: Record<string, Float64Array>;
645
+ /**
646
+ * diffusivity at each node, m²/s (NaN where absent, or in a conductor)
647
+ */
648
+ D: Record<string, Float64Array>;
649
+ /**
650
+ * temperature, K
651
+ */
652
+ T: number;
653
+ /**
654
+ * the device's (amounts and rates per area only if planar)
655
+ */
656
+ geometry: "planar" | "cylindrical" | "spherical" | "profile";
540
657
  /**
541
658
  * current toward +x through the device, A/m²
542
659
  */
@@ -574,9 +691,11 @@ export type Solution = {
574
691
  };
575
692
  };
576
693
  /**
577
- * what each internal port brings into the device;
578
- * with reactions, also its window's nodes (x, m), area per volume there, and each reaction's rate per area
579
- * at each node (mol/(m²·s), forward)
694
+ * what each internal port brings into the device (current: the charging current included); with
695
+ * reactions or a capacitance, also its window's nodes (x, m) and area per volume there (m²/m³); with
696
+ * reactions, each reaction's net rate per area at each node (mol/(m²·s), forward); with a surface, each
697
+ * species' coverage and the bare fraction; with a capacitance, σ per area (C/m²) and the charge its
698
+ * side holds; with gates, each gate's fraction open at each node and the voltage they follow (V)
580
699
  */
581
700
  ports: {
582
701
  name: string;
@@ -590,7 +709,16 @@ export type Solution = {
590
709
  bare?: Float64Array;
591
710
  sigma?: Float64Array;
592
711
  charge?: number;
712
+ gates?: Record<string, Float64Array>;
713
+ Vm?: Float64Array;
593
714
  }[];
715
+ /**
716
+ * each face: the regions it joins, its dipole
717
+ * (V) and sheet charge (C/m²), its displacement D (C/m²), each species' flux N across it and each face
718
+ * reaction's net rate (mol/(m²·s), toward +x and forward), how each species that crosses it does (its
719
+ * link type); for those crossing by permeability, the one-way fluxes [toward +x, toward −x] whose
720
+ * difference is N; with gates, each one's fraction open and the voltage they follow, φ_right − φ_left (V)
721
+ */
594
722
  interfaces: {
595
723
  left: string;
596
724
  right: string;
@@ -599,13 +727,20 @@ export type Solution = {
599
727
  D: number;
600
728
  N: Record<string, number>;
601
729
  rates: number[];
730
+ links: Record<string, string>;
731
+ oneWay?: Record<string, [number, number]>;
732
+ gates?: Record<string, number>;
733
+ V?: number;
602
734
  }[];
603
735
  /**
604
- * each bulk reaction's
605
- * forward rate per node (mol/(m³·s), NaN where it doesn't run), and per region and in all (mol/(m²·s))
736
+ * each bulk reaction's net rate per node (mol/(m³·s), forward minus backward, NaN where it doesn't
737
+ * run), its one-way forward rate (the backward is forward − rate), what one forward reaction makes
738
+ * of each species (ν, negative for what it consumes), and the net rate per region and in all (mol/(m²·s))
606
739
  */
607
740
  bulkReactions: {
608
741
  rate: Float64Array;
742
+ forward: Float64Array;
743
+ nu: Record<string, number>;
609
744
  regions: number[];
610
745
  total: number;
611
746
  }[];
@@ -626,7 +761,23 @@ export type Solution = {
626
761
  }[];
627
762
  warnings: string[];
628
763
  converged: boolean;
764
+ /**
765
+ * Newton iterations
766
+ */
629
767
  iterations: number;
768
+ /**
769
+ * solve(): the steps it took to the steady state; advance(): accepted steps
770
+ */
771
+ steps?: number;
772
+ /**
773
+ * step(): how many pieces the interval was split into
774
+ */
775
+ substeps?: number;
776
+ /**
777
+ * solver bookkeeping: solve(), a record of its steps and
778
+ * stages; step(), Newton's largest update per iteration (thermal units)
779
+ */
780
+ history?: (number | object)[];
630
781
  /**
631
782
  * s
632
783
  */
@@ -645,8 +796,10 @@ export type Solution = {
645
796
  rejected?: number;
646
797
  /**
647
798
  * advance():
648
- * terminal current (A/m², toward +x) and voltage after each accepted step, and each probe's
649
- * reading (mol/m³, or V for quantity 'V'), interpolated between the nodes around its x
799
+ * the right contact's current (A/m², toward +x) and V_right − V_left after each accepted step, and
800
+ * each probe's reading: inside, interpolated between the nodes around its x (mol/m³ for quantity
801
+ * 'c', V for 'V' or 'phi'); at a face, a species' flux through it (mol/(m²·s), toward +x) or a
802
+ * gate's fraction open
650
803
  */
651
804
  trace?: {
652
805
  t: number[];
@@ -661,7 +814,7 @@ export type ImpedanceResult = {
661
814
  */
662
815
  f: Float64Array;
663
816
  /**
664
- * impedance −δV/δI, Ω·m²
817
+ * impedance δV/δI at the terminal, I into the device, Ω·m²
665
818
  */
666
819
  Z: {
667
820
  re: Float64Array;