Chemistry · class

SpeciesElementMatrix

Explained in Chemistry.

class SpeciesElementMatrix
import { SpeciesElementMatrix } from '@driftengine/chemistry';

Accessors

NameTypeDescription
rowsgetnumber

Methods

addRow

addRow(): number

Append a zeroed row and return its index.

set

set(row: number, element: number, moles: number): void
ParameterTypeDescription
rownumber
elementnumber
molesnumber

at

at(row: number, element: number): number
ParameterTypeDescription
rownumber
elementnumber

rowView

rowView(row: number): Float64Array

A row as a view of fifteen, sharing storage rather than copying.

ParameterTypeDescription
rownumber
More

A view is invalidated by a later addRow that grows the table, because growth reallocates. Every caller in this package takes a view inside a loop that registers nothing, which is the only safe pattern and is why this is not handed out as a promise.

addScaledRow

addScaledRow(row: number, scale: number, out: Float64Array): void

out[e] += scale * this[row][e], for all fifteen. Allocates nothing.

ParameterTypeDescription
rownumber
scalenumber
outFloat64Array
More

The primitive every conservation check is built from, and it exists rather than a loop over at for one reason: rowView would be the natural way to write that loop and subarray allocates a view object per call, which is an allocation per species per tick. It adds rather than replaces so a caller sums a whole world into one vector without a second accumulator.