Skip to content

Commit

Permalink
In progress...
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Apr 29, 2024
1 parent 1d6c710 commit 6e916fe
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 34 deletions.
22 changes: 7 additions & 15 deletions src/lib/config/atoms.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { AtomInterface } from '../types/atomic';
import { createAtom, getIndexByFrequencies } from '../helpers';
import type {
InitialConfig,
TypesConfig,
WorldConfig,
} from '../types/config';
import type { TypesConfig, WorldConfig } from '../types/config';

export function create2dButterfly(): AtomInterface[] {
const atoms: AtomInterface[] = [];
Expand Down Expand Up @@ -39,15 +35,13 @@ export function create3dButterfly(): AtomInterface[] {
export function create2dRandomDistribution(
worldConfig: WorldConfig,
typesConfig: TypesConfig,
initialConfig: InitialConfig,
): AtomInterface[] {
const atoms: AtomInterface[] = [];

for (let i = 0; i < initialConfig.ATOMS_COUNT; ++i) {
for (let i = 0; i < worldConfig.CONFIG_2D.INITIAL.ATOMS_COUNT; ++i) {
const type = getIndexByFrequencies(typesConfig.FREQUENCIES);
// const type = Math.round(Math.random() * (typesConfig.COLORS.length - 1));
const minPos = initialConfig.MIN_POSITION;
const maxPos = initialConfig.MAX_POSITION;
const minPos = worldConfig.CONFIG_2D.INITIAL.MIN_POSITION;
const maxPos = worldConfig.CONFIG_2D.INITIAL.MAX_POSITION;

const position = [
minPos[0] + Math.random() * (maxPos[0] - minPos[0]),
Expand All @@ -62,15 +56,13 @@ export function create2dRandomDistribution(
export function create3dRandomDistribution(
worldConfig: WorldConfig,
typesConfig: TypesConfig,
initialConfig: InitialConfig,
): AtomInterface[] {
const atoms: AtomInterface[] = [];

for (let i = 0; i < initialConfig.ATOMS_COUNT; ++i) {
for (let i = 0; i < worldConfig.CONFIG_3D.INITIAL.ATOMS_COUNT; ++i) {
const type = getIndexByFrequencies(typesConfig.FREQUENCIES);
// const type = Math.round(Math.random() * (typesConfig.COLORS.length - 1));
const minPos = initialConfig.MIN_POSITION;
const maxPos = initialConfig.MAX_POSITION;
const minPos = worldConfig.CONFIG_3D.INITIAL.MIN_POSITION;
const maxPos = worldConfig.CONFIG_3D.INITIAL.MAX_POSITION;

const position = [
minPos[0] + Math.random() * (maxPos[0] - minPos[0]),
Expand Down
10 changes: 10 additions & 0 deletions src/lib/config/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ export function createBaseWorldConfig(): WorldConfig {
MIN_POSITION: [0, 0],
MAX_POSITION: [2500, 2500],
},
INITIAL: {
ATOMS_COUNT: 2000,
MIN_POSITION: [0, 0],
MAX_POSITION: [2500, 2000],
},
},
CONFIG_3D: {
BOUNDS: {
MIN_POSITION: [0, 0, 0],
MAX_POSITION: [500, 500, 500],
},
INITIAL: {
ATOMS_COUNT: 1000,
MIN_POSITION: [0, 0, 0],
MAX_POSITION: [500, 500, 500],
},
},
TEMPERATURE_FUNCTION: (c: NumericVector, t: number) => {
return 1;
Expand Down
1 change: 1 addition & 0 deletions src/lib/example/variants/2d/butterfly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const INITIAL_CONFIG: InitialConfig = create2dBaseInitialConfig();

export function create2dSimulationButterfly() {
return new Simulation({
viewMode: '2d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
Expand Down
1 change: 1 addition & 0 deletions src/lib/example/variants/2d/const-types-distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const INITIAL_CONFIG: InitialConfig = create2dBaseInitialConfig();

export function create2dSimulationWithConstTypes() {
return new Simulation({
viewMode: '2d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
Expand Down
1 change: 1 addition & 0 deletions src/lib/example/variants/2d/random-types-distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const INITIAL_CONFIG: InitialConfig = create2dBaseInitialConfig();

export function create2dSimulationWithRandomTypes() {
return new Simulation({
viewMode: '2d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
Expand Down
1 change: 1 addition & 0 deletions src/lib/example/variants/3d/butterfly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const INITIAL_CONFIG: InitialConfig = create3dBaseInitialConfig();

export function create3dSimulationButterfly() {
return new Simulation({
viewMode: '3d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
Expand Down
1 change: 1 addition & 0 deletions src/lib/example/variants/3d/const-types-distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const INITIAL_CONFIG: InitialConfig = create3dBaseInitialConfig();

export function create3dSimulationWithConstTypes() {
return new Simulation({
viewMode: '3d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
Expand Down
1 change: 1 addition & 0 deletions src/lib/example/variants/3d/random-types-distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const INITIAL_CONFIG: InitialConfig = create3dBaseInitialConfig();

export function create3dSimulationWithRandomTypes() {
return new Simulation({
viewMode: '3d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
Expand Down
8 changes: 3 additions & 5 deletions src/lib/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import type { LinkManagerInterface, RunningStateInterface } from './types/helper
import type { InteractionManagerInterface, PhysicModelInterface } from './types/interaction';
import type { ClusterManagerInterface } from './types/cluster';
import type { Summary, SummaryManagerInterface } from './types/summary';
import type { InitialConfig } from './types/config';
import { ClusterManager } from './cluster';
import { createAtom, LinkManager, RulesHelper, RunningState } from './helpers';
import { createAtom, getViewModeConfig, LinkManager, RulesHelper, RunningState } from './helpers';
import { InteractionManager } from './interaction';
import { SummaryManager } from './summary';
import type { NumericVector } from './vector/types';
Expand All @@ -24,7 +23,7 @@ export class Simulation implements SimulationInterface {

constructor(config: SimulationConfig) {
this.config = config;
this.atoms = this.config.atomsFactory(this.config.worldConfig, this.config.typesConfig, this.config.initialConfig);
this.atoms = this.config.atomsFactory(this.config.worldConfig, this.config.typesConfig);
this.drawer = this.config.drawer;
this.linkManager = new LinkManager();
this.interactionManager = new InteractionManager(
Expand Down Expand Up @@ -69,12 +68,11 @@ export class Simulation implements SimulationInterface {
this.runningState.togglePause();
}

refill(initialConfig?: InitialConfig) {
refill() {
this.clear();
this.atoms = this.config.atomsFactory(
this.config.worldConfig,
this.config.typesConfig,
initialConfig ?? this.config.initialConfig
);
}

Expand Down
11 changes: 6 additions & 5 deletions src/lib/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ export type BoundsConfig = {
MIN_POSITION: NumericVector;
MAX_POSITION: NumericVector;
};
export type InitialConfig = {
ATOMS_COUNT: number;
MIN_POSITION: NumericVector;
MAX_POSITION: NumericVector;
};
export type ViewModeConfig = {
BOUNDS: BoundsConfig;
INITIAL: InitialConfig;
};
export type TypesConfig = {
RADIUS: RadiusConfig;
Expand Down Expand Up @@ -51,11 +57,6 @@ export type WorldConfig = {
CONFIG_2D: ViewModeConfig;
CONFIG_3D: ViewModeConfig;
};
export type InitialConfig = {
ATOMS_COUNT: number;
MIN_POSITION: NumericVector;
MAX_POSITION: NumericVector;
};
export type RandomTypesConfig = {
TYPES_COUNT: number;

Expand Down
3 changes: 1 addition & 2 deletions src/lib/types/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type SimulationConfig = {
atomsFactory: (
worldConfig: WorldConfig,
typesConfig: TypesConfig,
initialConfig: InitialConfig
) => AtomInterface[];
drawer: DrawerInterface;
};
Expand All @@ -25,7 +24,7 @@ export interface SimulationInterface {
start(): void;
stop(onStop?: () => void): Promise<void>;
togglePause(): void;
refill(initialConfig?: InitialConfig): void;
refill(): void;
clear(): void;
setPhysicModel(model: PhysicModelInterface): void;
exportState(): Promise<Record<string, unknown>>;
Expand Down
10 changes: 3 additions & 7 deletions src/store/simulation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed, watch } from "vue";
import { computed } from "vue";
import { defineStore } from "pinia";
import type { SimulationInterface } from "@/lib/types/simulation";
import type { PhysicModelInterface } from '@/lib/types/interaction';
Expand All @@ -16,7 +16,6 @@ export const useSimulationStore = defineStore("simulation", () => {
const {
worldConfig,
typesConfig,
initialConfig,
} = configStore.getConfigValues();

let simulation2d: Simulation | null = null;
Expand Down Expand Up @@ -96,11 +95,8 @@ export const useSimulationStore = defineStore("simulation", () => {

const refillAtoms = (globally: boolean = false) => {
if (globally) {
const initialConfig2d = isMode('2d') ? configStore.initialConfig : create2dBaseInitialConfig();
const initialConfig3d = isMode('3d') ? configStore.initialConfig : create3dBaseInitialConfig();

simulation2d?.refill(initialConfig2d);
simulation3d?.refill(initialConfig3d);
simulation2d?.refill();
simulation3d?.refill();
} else {
getCurrentSimulation().refill();
}
Expand Down

0 comments on commit 6e916fe

Please sign in to comment.