Skip to content

Commit

Permalink
Initial Config duplicate is removed from Simulation config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed May 13, 2024
1 parent 0e6ece5 commit 32957bc
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 44 deletions.
4 changes: 0 additions & 4 deletions src/lib/example/variants/2d/butterfly.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import type {
InitialConfig,
TypesConfig,
WorldConfig,
} from "../../../types/config";
import { create2dDrawer } from "../../../drawer/2d";
import { createBaseTypesConfig } from "../../../config/types";
import { createBaseWorldConfig } from "../../../config/world";
import { create2dBaseInitialConfig } from "../../../config/initial";
import { create2dButterfly } from "../../../config/atoms";
import { Simulation } from "../../../simulation";
import { PhysicModelV1 } from "../../../physics/v1";

const WORLD_CONFIG: WorldConfig = createBaseWorldConfig();
const TYPES_CONFIG: TypesConfig = createBaseTypesConfig();
const INITIAL_CONFIG: InitialConfig = create2dBaseInitialConfig();

export function create2dSimulationButterfly() {
return new Simulation({
viewMode: '2d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
physicModel: new PhysicModelV1(WORLD_CONFIG, TYPES_CONFIG),
atomsFactory: create2dButterfly,
drawer: create2dDrawer('canvas', WORLD_CONFIG, TYPES_CONFIG),
Expand Down
4 changes: 0 additions & 4 deletions src/lib/example/variants/2d/const-types-distribution.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import type {
InitialConfig,
TypesConfig,
WorldConfig,
} from "../../../types/config";
import { create2dDrawer } from "../../../drawer/2d";
import { createBaseTypesConfig } from "../../../config/types";
import { createBaseWorldConfig } from "../../../config/world";
import { create2dBaseInitialConfig } from "../../../config/initial";
import { create2dRandomDistribution } from "../../../config/atoms";
import { Simulation } from "../../../simulation";
import { PhysicModelV1 } from "../../../physics/v1";

const WORLD_CONFIG: WorldConfig = createBaseWorldConfig();
const TYPES_CONFIG: TypesConfig = createBaseTypesConfig();
const INITIAL_CONFIG: InitialConfig = create2dBaseInitialConfig();

export function create2dSimulationWithConstTypes() {
return new Simulation({
viewMode: '2d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
physicModel: new PhysicModelV1(WORLD_CONFIG, TYPES_CONFIG),
atomsFactory: create2dRandomDistribution,
drawer: create2dDrawer('canvas', WORLD_CONFIG, TYPES_CONFIG),
Expand Down
4 changes: 0 additions & 4 deletions src/lib/example/variants/2d/random-types-distribution.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type {
InitialConfig,
TypesConfig,
WorldConfig,
} from "../../../types/config";
import { create2dDrawer } from "../../../drawer/2d";
import { createRandomTypesConfig } from "../../../config/types";
import { createBaseWorldConfig } from "../../../config/world";
import { create2dBaseInitialConfig } from "../../../config/initial";
import { create2dRandomDistribution } from "../../../config/atoms";
import { Simulation } from "../../../simulation";
import { PhysicModelV1 } from "../../../physics/v1";
Expand Down Expand Up @@ -38,14 +36,12 @@ const TYPES_CONFIG: TypesConfig = createRandomTypesConfig({
LINK_FACTOR_DISTANCE_EXTENDED: true,
LINK_FACTOR_DISTANCE_IGNORE_SELF_TYPE: true,
});
const INITIAL_CONFIG: InitialConfig = create2dBaseInitialConfig();

export function create2dSimulationWithRandomTypes() {
return new Simulation({
viewMode: '2d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
physicModel: new PhysicModelV1(WORLD_CONFIG, TYPES_CONFIG),
atomsFactory: create2dRandomDistribution,
drawer: create2dDrawer('canvas', WORLD_CONFIG, TYPES_CONFIG),
Expand Down
4 changes: 0 additions & 4 deletions src/lib/example/variants/3d/butterfly.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import type {
InitialConfig,
TypesConfig,
WorldConfig,
} from "../../../types/config";
import { createBaseTypesConfig } from "../../../config/types";
import { createBaseWorldConfig } from "../../../config/world";
import { create3dBaseInitialConfig } from "../../../config/initial";
import { create3dButterfly } from "../../../config/atoms";
import { Simulation } from "../../../simulation";
import { create3dDrawer } from "../../../drawer/3d";
import { PhysicModelV1 } from "../../../physics/v1";

const WORLD_CONFIG: WorldConfig = createBaseWorldConfig();
const TYPES_CONFIG: TypesConfig = createBaseTypesConfig();
const INITIAL_CONFIG: InitialConfig = create3dBaseInitialConfig();

export function create3dSimulationButterfly() {
return new Simulation({
viewMode: '3d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
physicModel: new PhysicModelV1(WORLD_CONFIG, TYPES_CONFIG),
atomsFactory: create3dButterfly,
drawer: create3dDrawer('canvas', WORLD_CONFIG, TYPES_CONFIG),
Expand Down
4 changes: 0 additions & 4 deletions src/lib/example/variants/3d/const-types-distribution.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import type {
InitialConfig,
TypesConfig,
WorldConfig,
} from "../../../types/config";
import { createBaseTypesConfig } from "../../../config/types";
import { createBaseWorldConfig } from "../../../config/world";
import { create3dBaseInitialConfig } from "../../../config/initial";
import { create3dRandomDistribution } from "../../../config/atoms";
import { Simulation } from "../../../simulation";
import { create3dDrawer } from "../../../drawer/3d";
import { PhysicModelV1 } from "../../../physics/v1";

const WORLD_CONFIG: WorldConfig = createBaseWorldConfig();
const TYPES_CONFIG: TypesConfig = createBaseTypesConfig();
const INITIAL_CONFIG: InitialConfig = create3dBaseInitialConfig();

export function create3dSimulationWithConstTypes() {
return new Simulation({
viewMode: '3d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
physicModel: new PhysicModelV1(WORLD_CONFIG, TYPES_CONFIG),
atomsFactory: create3dRandomDistribution,
drawer: create3dDrawer('canvas', WORLD_CONFIG, TYPES_CONFIG),
Expand Down
4 changes: 0 additions & 4 deletions src/lib/example/variants/3d/random-types-distribution.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type {
InitialConfig,
TypesConfig,
WorldConfig,
} from "../../../types/config";
import { createRandomTypesConfig } from "../../../config/types";
import { createBaseWorldConfig } from "../../../config/world";
import { create3dBaseInitialConfig } from "../../../config/initial";
import { create3dRandomDistribution } from "../../../config/atoms";
import { Simulation } from "../../../simulation";
import { create3dDrawer } from "../../../drawer/3d";
Expand Down Expand Up @@ -38,14 +36,12 @@ const TYPES_CONFIG: TypesConfig = createRandomTypesConfig({
LINK_FACTOR_DISTANCE_EXTENDED: true,
LINK_FACTOR_DISTANCE_IGNORE_SELF_TYPE: true,
});
const INITIAL_CONFIG: InitialConfig = create3dBaseInitialConfig();

export function create3dSimulationWithRandomTypes() {
return new Simulation({
viewMode: '3d',
worldConfig: WORLD_CONFIG,
typesConfig: TYPES_CONFIG,
initialConfig: INITIAL_CONFIG,
physicModel: new PhysicModelV1(WORLD_CONFIG, TYPES_CONFIG),
atomsFactory: create3dRandomDistribution,
drawer: create3dDrawer('canvas', WORLD_CONFIG, TYPES_CONFIG),
Expand Down
1 change: 1 addition & 0 deletions src/lib/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export class Simulation implements SimulationInterface {
this.step();

if (this.summaryManager.step % 30 === 0) {
console.log('time', this.summaryManager.step)
// console.log('SUMMARY', this.summary);
}

Expand Down
1 change: 0 additions & 1 deletion src/lib/types/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export type SimulationConfig = {
viewMode: ViewMode;
worldConfig: WorldConfig;
typesConfig: TypesConfig;
initialConfig: InitialConfig;
physicModel: PhysicModelInterface;
atomsFactory: (
worldConfig: WorldConfig,
Expand Down
27 changes: 14 additions & 13 deletions src/scripts/actions/test-simulation-parallel.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import os from 'os';
import { Pool } from "multiprocess-pool";
import type { InitialConfig, TypesConfig, WorldConfig } from '@/lib/types/config';
import type { TypesConfig, WorldConfig } from '@/lib/types/config';
import { createBaseWorldConfig } from '@/lib/config/world';
import { createBaseTypesConfig } from '@/lib/config/types';
import { create2dBaseInitialConfig } from '@/lib/config/initial';

export const simulationTask = async (
[id, worldConfig, typesConfig, initialConfig, steps]: [number, WorldConfig, TypesConfig, InitialConfig, number],
[id, worldConfig, typesConfig, steps]: [number, WorldConfig, TypesConfig, number],
) => {
console.log(`-> task ${id} started`);
const ts = Date.now();

console.log('initial', worldConfig);

worldConfig.TEMPERATURE_FUNCTION = () => 1;

const dirName = __dirname.replace('/node_modules/multiprocess-pool/dist', '/src');
Expand All @@ -25,7 +26,6 @@ export const simulationTask = async (
viewMode: '2d',
worldConfig: worldConfig,
typesConfig: typesConfig,
initialConfig: initialConfig,
physicModel: createPhysicModel(worldConfig, typesConfig),
atomsFactory: create2dRandomDistribution,
drawer: createDummyDrawer(),
Expand All @@ -50,18 +50,19 @@ export const actionTestSimulationParallel = async (...args: string[]) => {

const worldConfig = createBaseWorldConfig();
const typesConfig = createBaseTypesConfig();
const initialConfig = create2dBaseInitialConfig();
const stepsCount = 300;

worldConfig.CONFIG_2D.INITIAL.ATOMS_COUNT = 1000;

const inputs = [
[1, worldConfig, typesConfig, initialConfig, stepsCount],
[2, worldConfig, typesConfig, initialConfig, stepsCount],
[3, worldConfig, typesConfig, initialConfig, stepsCount],
[4, worldConfig, typesConfig, initialConfig, stepsCount],
[5, worldConfig, typesConfig, initialConfig, stepsCount],
[6, worldConfig, typesConfig, initialConfig, stepsCount],
[7, worldConfig, typesConfig, initialConfig, stepsCount],
[8, worldConfig, typesConfig, initialConfig, stepsCount],
[1, worldConfig, typesConfig, stepsCount],
[2, worldConfig, typesConfig, stepsCount],
[3, worldConfig, typesConfig, stepsCount],
[4, worldConfig, typesConfig, stepsCount],
[5, worldConfig, typesConfig, stepsCount],
[6, worldConfig, typesConfig, stepsCount],
[7, worldConfig, typesConfig, stepsCount],
[8, worldConfig, typesConfig, stepsCount],
];

const cpuCount = os.cpus().length;
Expand Down
3 changes: 0 additions & 3 deletions src/scripts/actions/test-simulation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createBaseWorldConfig } from '@/lib/config/world';
import { createBaseTypesConfig } from '@/lib/config/types';
import { create2dBaseInitialConfig } from '@/lib/config/initial';
import { createPhysicModel } from '@/lib/utils/functions';
import { create2dRandomDistribution } from '@/lib/config/atoms';
import { createDummyDrawer } from '@/lib/drawer/dummy';
Expand All @@ -13,13 +12,11 @@ export const actionTestSimulation = (...args: string[]) => {

const worldConfig = createBaseWorldConfig();
const typesConfig = createBaseTypesConfig();
const initialConfig = create2dBaseInitialConfig();

const sim = new Simulation({
viewMode: '2d',
worldConfig: worldConfig,
typesConfig: typesConfig,
initialConfig: initialConfig,
physicModel: createPhysicModel(worldConfig, typesConfig),
atomsFactory: create2dRandomDistribution,
drawer: createDummyDrawer(),
Expand Down
3 changes: 0 additions & 3 deletions src/web/store/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { defineStore } from "pinia";
import type { SimulationInterface } from "@/lib/types/simulation";
import type { PhysicModelInterface } from '@/lib/types/interaction';
import type { ViewMode } from "@/lib/types/config";
import { create2dBaseInitialConfig, create3dBaseInitialConfig } from "@/lib/config/initial";
import { useConfigStore } from "@/web/store/config";
import { create2dRandomDistribution, create3dRandomDistribution } from "@/lib/config/atoms";
import { create3dDrawer } from "@/lib/drawer/3d";
Expand All @@ -27,7 +26,6 @@ export const useSimulationStore = defineStore("simulation", () => {
viewMode: '3d',
worldConfig: worldConfig,
typesConfig: typesConfig,
initialConfig: create3dBaseInitialConfig(),
physicModel: createPhysicModel(worldConfig, typesConfig),
atomsFactory: create3dRandomDistribution,
drawer: create3dDrawer('canvas3d', worldConfig, typesConfig),
Expand All @@ -39,7 +37,6 @@ export const useSimulationStore = defineStore("simulation", () => {
viewMode: '2d',
worldConfig: worldConfig,
typesConfig: typesConfig,
initialConfig: create2dBaseInitialConfig(),
physicModel: createPhysicModel(worldConfig, typesConfig),
atomsFactory: create2dRandomDistribution,
drawer: create2dDrawer('canvas2d', worldConfig, typesConfig),
Expand Down

0 comments on commit 32957bc

Please sign in to comment.