import CPM from 'Artistoo/src/models/CPM.js'
public class | source

CPM

Extends:

GridBasedModel → CPM

Direct Subclass:

CPMEvol

The core CPM class. Can be used for two- or three-dimensional simulations.

Constructor Summary

Public Constructor
public

constructor(field_size: GridSize, conf: object)

The constructor of class CA.

Member Summary

Public Members
public

track border pixels for speed

public

cellvolume: *[]

public

Array of objects of (@link HardConstraint) subclasses attached to the CPM.

public

Object showing which constraints are where in soft_constraints.

public

To check from outside if an object is a CPM; doing this with instanceof doesn't work in some cases. Any other object will not have this variable and return 'undefined', which in an if-statement equates to a 'false'. @type{boolean}

public

Highest cell ID previously assigned.

public

Number of non-background cells currently on the grid.

public get
public

Array of functions that need to be executed after every timeStep event.

public

Array of functions that need to be executed after every setpixi event.

public

Array of objects of (@link SoftConstraint) subclasses attached to the CPM.

public

Object showing which constraints are where in soft_constraints.

public
public

Store the {@CellKind} of each cell on the grid.

public

Track time in MCS.

Private Members
private

Private property used by updateborderneari to track borders.

Method Summary

Public Methods
public

Add a constraint to the CPM, ensuring that its SoftConstraint#deltaH or HardConstraint#fulfilled methods are called appropriately during a copy attempt.

public

Iterator returning non-background border pixels on the grid.

public

Iterator returning non-background border pixels on the grid.

public

Get the CellKind of the cell with CellId t.

public

Iterator returning non-background pixels on the grid.

public

deltaH(sourcei: IndexCoordinate, targeti: IndexCoordinate, src_type: CellId, tgt_type: CellId): number

returns total change in hamiltonian for all registered soft constraints together.

public

docopy(deltaH: number): boolean

Determine whether copy attempt will succeed depending on deltaH (stochastic).

public
public

getConstraint(constraintname: string, num: number): *

Get a Constraint object linked to this CPM by the name of its class.

public

Get volume of the cell with CellId t

public

Initiate a new CellId for a cell of CellKind "kind", and create elements for this cell in the relevant arrays (cellvolume, t2k).

public

Simulate one Monte Carlo Step.

public

Get CellId of the pixel at coordinates p.

public

reset()

Completely reset; remove all cells and set time back to zero.

public

Assign the cell with CellId t to CellKind k.

public

Change the pixel at position i into CellId t.

public

A time step in the CPM is a Monte Carlo step.

public

Update border elements (borderpixels) after a successful copy attempt.

Inherited Summary

From class GridBasedModel
public

cellvolume: *[]

This tracks the volumes of all non-background cells on the grid.

public

Input parameter settings; see the constructor of subclasses documentation.

public

Size of the grid.

public

Size of the grid in object format.

public

grid: *

public

Midpoint of the grid.

public

Attach a random number generation with a seed.

public

Dimensionality of the grid

public

The Grid2D#neighi or Grid3D#neighi iterator function of the underlying grid.

public

The Grid2D#pixels or Grid3D#pixels iterator function of the underlying grid.

public

The Grid#pixti iterator function of the underlying grid.

public

Cached values of these stats.

public

Objects of class Stat that have been computed on this model.

public

Tracks the elapsed time in MCS

public

Iterator for all the CellIds that are currently on the grid.

public

Get the CellKind of the cell with CellId t.

public

getStat(s: Stat): anything

Compute a statistic on this model.

public

neigh(p: ArrayCoordinate, torus: boolean[]): *

Get neighbourhood of position p, using neighborhood functions of the underlying grid class.

public

Get CellId of the pixel at coordinates p.

public

ran(incl_min: number, incl_max: number): number

Get a random integer number between incl_min and incl_max, uniformly sampled.

public

Get a random number from the seeded number generator.

public

Change the pixel at position p into CellId t.

public

Change the pixel at position i into CellId t.

public abstract

Update the grid in one timestep.

Public Constructors

public constructor(field_size: GridSize, conf: object) source

The constructor of class CA.

Override:

GridBasedModel#constructor

Params:

NameTypeAttributeDescription
field_size GridSize

the size of the grid of the model.

conf object

configuration options; see below. In addition, the conf object can have parameters to constraints added to the CPM. See the different Constraint subclasses for options. For some constraints, adding its parameter to the CPM conf object automatically adds the constraint; see AutoAdderConfig to see for which constraints this is supported.

conf.torus boolean[]
  • optional
  • default: [true,true,...]

should the grid have linked borders?

conf.T number
  • optional

the temperature of this CPM. At higher temperatures, unfavourable copy attempts are more likely to be accepted.

conf.seed number
  • optional

seed for the random number generator. If left unspecified, a random number from the Math.random() generator is used to make one.

Public Members

public borderpixels: DiceSet source

track border pixels for speed

public cellvolume: *[] source

This tracks the volumes of all non-background cells on the grid. cellvolumes will be added with key = CellId, value = volume. @type{number[]}

Override:

GridBasedModel#cellvolume

public hard_constraints: Array source

Array of objects of (@link HardConstraint) subclasses attached to the CPM. These are used to determine which copy attempts are allowed in a timeStep.

public hard_constraints_indices: object source

Object showing which constraints are where in soft_constraints. Used by the getConstraint method to find an attached constraint by name.

public isCPM: boolean source

To check from outside if an object is a CPM; doing this with instanceof doesn't work in some cases. Any other object will not have this variable and return 'undefined', which in an if-statement equates to a 'false'. @type{boolean}

public last_cell_id: number source

Highest cell ID previously assigned. @type{number}

public nr_cells: number source

Number of non-background cells currently on the grid. @type{number}

public get perimeterNeighbours: * source

public post_mcs_listeners: function[] source

Array of functions that need to be executed after every timeStep event. These functions are often implemented in subclasses of Constraint that need to track some specific property on the grid.

public post_setpix_listeners: function[] source

Array of functions that need to be executed after every setpixi event. These functions are often implemented in subclasses of Constraint that need to track some specific property on the grid.

public soft_constraints: Array source

Array of objects of (@link SoftConstraint) subclasses attached to the CPM. These are used to determine deltaH.

public soft_constraints_indices: object source

Object showing which constraints are where in soft_constraints. Used by the getConstraint method to find an attached constraint by name.

public stat_values: {} source

Cached values of these stats. Object with stat name as key and its cached value as value. The cache must be cleared when the grid changes!

Override:

GridBasedModel#stat_values

public t2k: CellObject source

Store the {@CellKind} of each cell on the grid.

Example:

this.t2k[1] // cellkind of cell with cellId 1

public time: number source

Track time in MCS. @type{number}

Override:

GridBasedModel#time

Private Members

private _neighbours: Uint16Array source

Private property used by updateborderneari to track borders.

Public Methods

public add(t: Constraint) source

Add a constraint to the CPM, ensuring that its SoftConstraint#deltaH or HardConstraint#fulfilled methods are called appropriately during a copy attempt. Any postSetpixListeners and postMCSListeners are also executed at the appropriate times.

Params:

NameTypeAttributeDescription
t Constraint

the constraint object to add.

public * cellBorderPixelIndices(): iPixel source

Iterator returning non-background border pixels on the grid. See cellBorderPixels for a version returning pixels by their ArrayCoordinate instead of IndexCoordinate.

Return:

iPixel

for each pixel, return an array [p,v] where p are the pixel's array coordinates on the grid, and v its value.

public * cellBorderPixels(): Pixel source

Iterator returning non-background border pixels on the grid. See cellBorderPixelIndices for a version returning pixels by their IndexCoordinate instead of ArrayCoordinate.

Return:

Pixel

for each pixel, return an array [p,v] where p are the pixel's array coordinates on the grid, and v its value.

public cellKind(t: CellId): CellKind source

Get the CellKind of the cell with CellId t. Overwrites GridBasedModel#cellKind because in a CPM, the two are not the same.

Override:

GridBasedModel#cellKind

Params:

NameTypeAttributeDescription
t CellId

id of the cell to get kind of.

Return:

CellKind

the cellkind.

public * cellPixels(): Pixel source

Iterator returning non-background pixels on the grid.

Return:

Pixel

for each pixel, return an array [p,v] where p are the pixel's array coordinates on the grid, and v its value.

public deltaH(sourcei: IndexCoordinate, targeti: IndexCoordinate, src_type: CellId, tgt_type: CellId): number source

returns total change in hamiltonian for all registered soft constraints together.

Params:

NameTypeAttributeDescription
sourcei IndexCoordinate

coordinate of the source pixel that tries to copy.

targeti IndexCoordinate

coordinate of the target pixel the source is trying to copy into.

src_type CellId

cellid of the source pixel.

tgt_type CellId

cellid of the target pixel.

Return:

number

the change in Hamiltonian for this copy attempt.

public docopy(deltaH: number): boolean source

Determine whether copy attempt will succeed depending on deltaH (stochastic).

Params:

NameTypeAttributeDescription
deltaH number

energy change associated with the potential copy.

Return:

boolean

whether the copy attempt succeeds.

public getAllConstraints(): * source

Return:

*

public getConstraint(constraintname: string, num: number): * source

Get a Constraint object linked to this CPM by the name of its class. By default, the first constraint found of this class is returned. It is possible that there are multiple constraints of the same type on the CPM; in that case, supply its number (by order in which the constraints of this type were added) to get a specific one.

This function can be useful if you need to access information in the constraint object, such as the cell directions in a {@PersistenceConstraint}, from outside. You can use this for stuff like drawing.

Params:

NameTypeAttributeDescription
constraintname string

name of the constraint class you are looking for.

num number
  • optional
  • default: 0

if multiple constraints of this class are present, return the num-th one added to the CPM.

Return:

*

public getVolume(t: CellId): number source

Get volume of the cell with CellId t

Params:

NameTypeAttributeDescription
t CellId

id of the cell to get volume of.

Return:

number

the cell's current volume.

public makeNewCellID(kind: CellKind): CellId source

Initiate a new CellId for a cell of CellKind "kind", and create elements for this cell in the relevant arrays (cellvolume, t2k).

Params:

NameTypeAttributeDescription
kind CellKind

cellkind of the cell that has to be made.

Return:

CellId

of the new cell.

public monteCarloStep() source

Simulate one Monte Carlo Step. We now just use timeStep for consistency with other GridBasedModels, but we have kept this method for compatibility with earlier version. Internally, it just calls timeStep.

public pixt(p: ArrayCoordinate): CellId source

Get CellId of the pixel at coordinates p.

Override:

GridBasedModel#pixt

Params:

NameTypeAttributeDescription
p ArrayCoordinate

pixel to get cellid of.

Return:

CellId

ID of the cell p belongs to.

public reset() source

Completely reset; remove all cells and set time back to zero. Only the constraints remain.

public setCellKind(t: CellId, k: CellKind) source

Assign the cell with CellId t to CellKind k.

Params:

NameTypeAttributeDescription
t CellId

id of the cell to assing

k CellKind

cellkind to give it.

public setpixi(i: IndexCoordinate, t: CellId) source

Change the pixel at position i into CellId t. This method overrides GridBasedModel#setpixi because we want to add postSetpixListeners for all the constraints, to keep track of relevant information.

See also setpix for a method working with ArrayCoordinates.

Override:

GridBasedModel#setpixi

Params:

NameTypeAttributeDescription
i IndexCoordinate

coordinate of pixel to change.

t CellId

cellid to change this pixel into.

Test:

public timeStep() source

A time step in the CPM is a Monte Carlo step. This performs a number of copy attempts depending on grid size:

1) Randomly sample one of the border pixels for the copy attempt. 2) Compute the change in Hamiltonian for the suggested copy attempt. 3) With a probability depending on this change, decline or accept the copy attempt and update the grid accordingly.

Override:

GridBasedModel#timeStep

TODO:

  • TODO it is quite confusing that the "borderpixels" array also contains border pixels of the background.

public updateborderneari(i: IndexCoordinate, t_old: CellId, t_new: CellId) source

Update border elements (borderpixels) after a successful copy attempt.

Params:

NameTypeAttributeDescription
i IndexCoordinate

coordinate of pixel that has changed.

t_old CellId

id of the cell the pixel belonged to before the copy.

t_new CellId

id of the cell the pixel has changed into.

Listen:

setpixi

because borders change when a copy succeeds.