Skip to content

Commit

Permalink
#7 added time at runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ok09ra committed Jun 18, 2022
1 parent 9261dde commit 83ef83a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/TabProtein.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useStore } from "@/store";
import ListBox from "@/components/ListBox.vue";
const store = useStore();
const proteinNames = computed(() =>
store.proteins.map((protein) => protein.name.substring("protein-".length))
);
Expand Down
6 changes: 6 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ export const useStore = defineStore("main", () => {
}
return Object.values(proteins);
});

const time = ref(0);

const registeredOutputs: string[] = [];
const registerOutput = (variable: string) => {
// Duplicate outputs are allowed (for the use of unregisteration when unmounted)
Expand Down Expand Up @@ -178,6 +181,7 @@ export const useStore = defineStore("main", () => {
];
console.log(equations);
const runner = new Runner(equations, 0.1);
time.value = 0;
for (const output of registeredOutputs) {
runnerOutputs.value[output] = runner.variables[output] || 0;
runnerOutputDefaults[output] = runner.variables[output] || 0;
Expand All @@ -203,6 +207,7 @@ export const useStore = defineStore("main", () => {
runner.variables[input] = runnerInputs.value[input];
}
runner.next();
time.value = runner.time;
for (const output of registeredOutputs) {
runnerOutputs.value[output] = runner.variables[output] || 0;
}
Expand Down Expand Up @@ -239,6 +244,7 @@ export const useStore = defineStore("main", () => {
deleteSnake,
operonMessengerRNAs,
proteins,
time,
registerOutput,
UnregisterOutput,
registerInput,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function factoryEmptyFunction(): DecodeFunction {
export default class Runner {
variables: Record<string, number> = {};
equations: Record<string, DecodeFunction> = {};
time = 0;
constructor(equations: DE[], public interval: number) {
for (const equation of equations) {
this.variables[equation.target] = 0; // todo
Expand All @@ -55,6 +56,7 @@ export default class Runner {
}
next() {
const h = this.interval;
this.time += h;
const vars1: Record<string, number> = {};
for (const varName in this.variables) {
vars1[varName] = h * this.equations[varName](this.variables);
Expand Down

0 comments on commit 83ef83a

Please sign in to comment.