Skip to content

Commit 68ece80

Browse files
committed
Clusters renamed to sectors in simulation engine.
1 parent 03aa100 commit 68ece80

File tree

5 files changed

+60
-60
lines changed

5 files changed

+60
-60
lines changed

src/lib/simulation/atomic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
LinkInterface,
55
} from './types/atomic';
66
import type { NumericVector, VectorInterface } from '../math/types';
7-
import type { ClusterInterface } from './types/cluster';
7+
import type { SectorInterface } from './types/sector';
88
import { toVector } from '../math';
99

1010
class BondMap implements BondMapInterface {
@@ -72,7 +72,7 @@ export class Atom implements AtomInterface {
7272
readonly linkElasticFactors: number[];
7373
type: number;
7474
newType: number | undefined = undefined;
75-
cluster?: ClusterInterface;
75+
sector?: SectorInterface;
7676

7777
constructor(id: number, type: number, position: NumericVector, speed?: NumericVector) {
7878
this.id = id;
Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { AtomInterface } from './types/atomic';
22
import type { NumericVector } from '../math/types';
3-
import type { ClusterInterface, ClusterManagerInterface, ClusterMapInterface } from './types/cluster';
3+
import type { SectorInterface, SectorManagerInterface, SectorMapInterface } from './types/sector';
44

55
function incPoint(aPoint: NumericVector, aCenterPoint: NumericVector, aDim: number): boolean {
66
aPoint[aDim]++;
@@ -26,7 +26,7 @@ function getNeighboursCoords(coords: NumericVector): Iterable<NumericVector> {
2626
return result;
2727
}
2828

29-
class Cluster implements ClusterInterface {
29+
class Sector implements SectorInterface {
3030
atoms: Set<AtomInterface> = new Set<AtomInterface>();
3131
coords: NumericVector;
3232

@@ -55,8 +55,8 @@ class Cluster implements ClusterInterface {
5555
}
5656
}
5757

58-
class ClusterMap implements ClusterMapInterface {
59-
map: Map<number, Cluster> = new Map();
58+
class SectorMap implements SectorMapInterface {
59+
map: Map<number, Sector> = new Map();
6060
quantum: number;
6161
phase: number;
6262

@@ -65,20 +65,20 @@ class ClusterMap implements ClusterMapInterface {
6565
this.phase = phase;
6666
}
6767

68-
getNeighbourhood(atom: AtomInterface): ClusterInterface[] {
68+
getNeighbourhood(atom: AtomInterface): SectorInterface[] {
6969
const result = [];
70-
const currentCluster = this.handleAtom(atom);
71-
for (const coords of getNeighboursCoords(currentCluster.coords)) {
72-
const cluster = this.getCluster(coords);
73-
result.push(cluster);
70+
const currentSector = this.handleAtom(atom);
71+
for (const coords of getNeighboursCoords(currentSector.coords)) {
72+
const sector = this.getSector(coords);
73+
result.push(sector);
7474
}
7575
return result;
7676
}
7777

7878
countAtoms(): number {
7979
let result = 0;
80-
for (const [, cluster] of this.map) {
81-
result += cluster.length;
80+
for (const [, sector] of this.map) {
81+
result += sector.length;
8282
}
8383
return result;
8484
}
@@ -87,37 +87,37 @@ class ClusterMap implements ClusterMapInterface {
8787
this.map.clear();
8888
}
8989

90-
public handleAtom(atom: AtomInterface): ClusterInterface {
91-
const actualCluster = this.getClusterByAtom(atom);
92-
const currentCluster = atom.cluster;
90+
public handleAtom(atom: AtomInterface): SectorInterface {
91+
const actualSector = this.getSectorByAtom(atom);
92+
const currentSector = atom.sector;
9393

94-
if (actualCluster !== currentCluster) {
95-
if (currentCluster !== undefined) {
96-
currentCluster.remove(atom);
94+
if (actualSector !== currentSector) {
95+
if (currentSector !== undefined) {
96+
currentSector.remove(atom);
9797
}
98-
actualCluster.add(atom);
99-
atom.cluster = actualCluster;
98+
actualSector.add(atom);
99+
atom.sector = actualSector;
100100
}
101101

102-
return actualCluster;
102+
return actualSector;
103103
}
104104

105-
public getCluster(clusterCoords: NumericVector): ClusterInterface {
106-
const key = clusterCoords.length === 3
107-
? clusterCoords[0] * 10000 + clusterCoords[1] * 100000000 + clusterCoords[2]
108-
: clusterCoords[0] * 10000 + clusterCoords[1];
105+
public getSector(sectorCoords: NumericVector): SectorInterface {
106+
const key = sectorCoords.length === 3
107+
? sectorCoords[0] * 10000 + sectorCoords[1] * 100000000 + sectorCoords[2]
108+
: sectorCoords[0] * 10000 + sectorCoords[1];
109109

110110
if (!this.map.has(key)) {
111-
this.map.set(key, new Cluster([...clusterCoords]));
111+
this.map.set(key, new Sector([...sectorCoords]));
112112
}
113113

114-
return this.map.get(key) as Cluster;
114+
return this.map.get(key) as Sector;
115115
}
116116

117117
public findAtomByCoords(coords: NumericVector, radiusMap: number[], radiusMultiplier: number): AtomInterface | undefined {
118-
const clusterCoords = this.getClusterCoords(coords);
119-
const cluster = this.getCluster(clusterCoords);
120-
for (const atom of cluster) {
118+
const sectorCoords = this.getSectorCoords(coords);
119+
const sector = this.getSector(sectorCoords);
120+
for (const atom of sector) {
121121
const dist = atom.position.clone().sub(coords).abs;
122122
if (dist <= radiusMap[atom.type] * radiusMultiplier) {
123123
return atom;
@@ -126,12 +126,12 @@ class ClusterMap implements ClusterMapInterface {
126126
return undefined;
127127
}
128128

129-
private getClusterByAtom(atom: AtomInterface): ClusterInterface {
130-
const clusterCoords = this.getClusterCoords(atom.position);
131-
return this.getCluster(clusterCoords);
129+
private getSectorByAtom(atom: AtomInterface): SectorInterface {
130+
const sectorCoords = this.getSectorCoords(atom.position);
131+
return this.getSector(sectorCoords);
132132
}
133133

134-
private getClusterCoords(coords: NumericVector): NumericVector {
134+
private getSectorCoords(coords: NumericVector): NumericVector {
135135
const result: NumericVector = new Array<number>(coords.length);
136136
for (let i=0; i<coords.length; ++i) {
137137
result[i] = Math.round(coords[i] / this.quantum) + this.phase;
@@ -140,11 +140,11 @@ class ClusterMap implements ClusterMapInterface {
140140
}
141141
}
142142

143-
export class ClusterManager implements ClusterManagerInterface {
144-
private readonly map: ClusterMap;
143+
export class SectorManager implements SectorManagerInterface {
144+
private readonly map: SectorMap;
145145

146146
constructor(quantum: number) {
147-
this.map = new ClusterMap(quantum, 0);
147+
this.map = new SectorMap(quantum, 0);
148148
}
149149

150150
countAtoms(): number {
@@ -161,8 +161,8 @@ export class ClusterManager implements ClusterManagerInterface {
161161
for (let i=cc.coords[0]-1; i<=cc.coords[0]+1; ++i) {
162162
for (let j=cc.coords[1]-1; j<=cc.coords[1]+1; ++j) {
163163
for (let k=cc.coords[2]-1; k<=cc.coords[2]+1; ++k) {
164-
const cluster = this.map.getCluster([i, j, k]);
165-
for (const neighbour of cluster.atoms) {
164+
const sector = this.map.getSector([i, j, k]);
165+
for (const neighbour of sector.atoms) {
166166
callback(atom, neighbour);
167167
}
168168
}
@@ -172,17 +172,17 @@ export class ClusterManager implements ClusterManagerInterface {
172172
const cc = this.map.handleAtom(atom);
173173
for (let i=cc.coords[0]-1; i<=cc.coords[0]+1; ++i) {
174174
for (let j=cc.coords[1]-1; j<=cc.coords[1]+1; ++j) {
175-
const cluster = this.map.getCluster([i, j]);
176-
for (const neighbour of cluster.atoms) {
175+
const sector = this.map.getSector([i, j]);
176+
for (const neighbour of sector.atoms) {
177177
callback(atom, neighbour);
178178
}
179179
}
180180
}
181181
} else {
182182
const neighborhood = this.map.getNeighbourhood(atom);
183183
for (let i=0; i<neighborhood.length; ++i) {
184-
const cluster = neighborhood[i];
185-
for (const neighbour of cluster.atoms) {
184+
const sector = neighborhood[i];
185+
for (const neighbour of sector.atoms) {
186186
callback(atom, neighbour);
187187
}
188188
}

src/lib/simulation/simulation.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import type { AtomInterface } from './types/atomic';
33
import type { DrawerInterface } from '../drawer/types';
44
import type { LinkManagerInterface, RunningStateInterface } from './types/utils';
55
import type { InteractionManagerInterface, PhysicModelInterface } from './types/interaction';
6-
import type { ClusterManagerInterface } from './types/cluster';
6+
import type { SectorManagerInterface } from './types/sector';
77
import type { WorldSummary, SummaryManagerInterface } from '../analysis/types';
88
import type { GraphInterface } from "../graph/types";
99
import type { NumericVector } from '../math/types';
1010
import type { Compound } from '../analysis/types';
11-
import { ClusterManager } from './cluster';
11+
import { SectorManager } from './sector';
1212
import { LinkManager, RulesHelper, RunningState } from '../utils/structs';
1313
import { InteractionManager } from './interaction';
1414
import { SummaryManager } from '../analysis/summary';
@@ -34,7 +34,7 @@ export class Simulation implements SimulationInterface {
3434
private readonly _links: LinkManagerInterface;
3535
private readonly drawer: DrawerInterface;
3636
private readonly interactionManager: InteractionManagerInterface;
37-
private readonly clusterManager: ClusterManagerInterface;
37+
private readonly sectorManager: SectorManagerInterface;
3838
private readonly summaryManager: SummaryManagerInterface;
3939
private readonly runningState: RunningStateInterface;
4040

@@ -53,7 +53,7 @@ export class Simulation implements SimulationInterface {
5353
new RulesHelper(this.config.worldConfig, this.config.typesConfig),
5454
this.summaryManager,
5555
);
56-
this.clusterManager = new ClusterManager(this.config.worldConfig.MAX_INTERACTION_RADIUS);
56+
this.sectorManager = new SectorManager(this.config.worldConfig.MAX_INTERACTION_RADIUS);
5757
this.runningState = new RunningState();
5858

5959
this.initEventHandlers();
@@ -116,7 +116,7 @@ export class Simulation implements SimulationInterface {
116116

117117
clear() {
118118
this._atoms.length = 0;
119-
this.clusterManager.clear();
119+
this.sectorManager.clear();
120120
this._links.clear();
121121
this.drawer.clear();
122122
}
@@ -190,12 +190,12 @@ export class Simulation implements SimulationInterface {
190190
this.summaryManager.noticeAtom(atom, this.config.worldConfig);
191191
}
192192
for (const atom of this._atoms) {
193-
this.clusterManager.handleAtom(atom, (lhs, rhs) => {
193+
this.sectorManager.handleAtom(atom, (lhs, rhs) => {
194194
this.interactionManager.interactAtomsStep1(lhs, rhs);
195195
});
196196
}
197197
for (const atom of this._atoms) {
198-
this.clusterManager.handleAtom(atom, (lhs, rhs) => {
198+
this.sectorManager.handleAtom(atom, (lhs, rhs) => {
199199
this.interactionManager.interactAtomsStep2(lhs, rhs);
200200
});
201201
}
@@ -242,7 +242,7 @@ export class Simulation implements SimulationInterface {
242242
this.drawer.eventManager.onMouseDown((event) => {
243243
console.log('MOUSE COORDS', event.coords);
244244
console.log('STEP INDEX', this.summaryManager.step);
245-
const atom = this.clusterManager.findAtomByCoords(
245+
const atom = this.sectorManager.findAtomByCoords(
246246
event.coords,
247247
this.config.typesConfig.RADIUS,
248248
this.config.worldConfig.ATOM_RADIUS*2,

src/lib/simulation/types/atomic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { VectorInterface } from '../../math/types';
2-
import type { ClusterInterface } from "./cluster";
2+
import type { SectorInterface } from "./sector";
33

44
export interface BondMapInterface {
55
length: number;
@@ -22,7 +22,7 @@ export interface AtomInterface {
2222
readonly linkElasticFactors: number[];
2323
type: number;
2424
newType: number | undefined;
25-
cluster?: ClusterInterface;
25+
sector?: SectorInterface;
2626
exportState(): Record<string, unknown>;
2727
}
2828

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { AtomInterface } from './atomic';
22
import type { NumericVector } from '../../math/types';
33

4-
export interface ClusterInterface extends Iterable<AtomInterface> {
4+
export interface SectorInterface extends Iterable<AtomInterface> {
55
length: number;
66
atoms: Set<AtomInterface>;
77
coords: NumericVector;
@@ -10,16 +10,16 @@ export interface ClusterInterface extends Iterable<AtomInterface> {
1010
empty(): boolean;
1111
}
1212

13-
export interface ClusterMapInterface {
14-
getNeighbourhood(atom: AtomInterface): ClusterInterface[];
13+
export interface SectorMapInterface {
14+
getNeighbourhood(atom: AtomInterface): SectorInterface[];
1515
countAtoms(): number;
1616
clear(): void;
17-
handleAtom(atom: AtomInterface): ClusterInterface;
18-
getCluster(clusterCoords: NumericVector): ClusterInterface;
17+
handleAtom(atom: AtomInterface): SectorInterface;
18+
getSector(sectorCoords: NumericVector): SectorInterface;
1919
findAtomByCoords(coords: NumericVector, radiusMap: number[], radiusMultiplier: number): AtomInterface | undefined;
2020
}
2121

22-
export interface ClusterManagerInterface {
22+
export interface SectorManagerInterface {
2323
handleAtom(atom: AtomInterface, callback: (lhs: AtomInterface, rhs: AtomInterface) => void): void;
2424
countAtoms(): number;
2525
clear(): void;

0 commit comments

Comments
 (0)