Skip to content

Commit 98822bb

Browse files
committed
slight MF optimization;
1 parent bf5a010 commit 98822bb

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

src/Theories/CTs/MF.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class mfSim extends theoryClass<theory> {
6565
mfResetDepth: number;
6666
isCoast: boolean;
6767
normalVariables: Variable[];
68+
precomp_omegaexp: number;
69+
precomp_xexp: number;
70+
precomp_vexp: number;
71+
precomp_a1exp: number;
6872

6973
bestRes: simResult | null;
7074

@@ -197,9 +201,16 @@ class mfSim extends theoryClass<theory> {
197201
getMilestonePriority(): number[] {
198202
return [0, 1, 2, 3, 4, 5];
199203
}
204+
precomputeExps() {
205+
this.precomp_a1exp = this.a1exp();
206+
this.precomp_vexp = this.vexp();
207+
this.precomp_xexp = this.xexp();
208+
this.precomp_omegaexp = this.omegaexp();
209+
}
200210
updateMilestonesNoMS(): boolean {
201211
const res = super.updateMilestonesNoMS();
202212
if(res) {
213+
this.precomputeExps();
203214
this.updateC();
204215
}
205216
return res;
@@ -237,9 +248,9 @@ class mfSim extends theoryClass<theory> {
237248
}
238249

239250
updateC(): void {
240-
const xterm = l10(4e13)*this.xexp()
241-
const omegaterm = (l10(m0 / (q0*mu0*i0)) - l10(900)) * this.omegaexp()
242-
const vterm = this.milestones[0] ? l10(3e19) * 1.3 + l10(1e5)*(this.vexp() - 1.3) : 0
251+
const xterm = l10(4e13)*this.precomp_xexp
252+
const omegaterm = (l10(m0 / (q0*mu0*i0)) - l10(900)) * this.precomp_omegaexp
253+
const vterm = this.milestones[0] ? l10(3e19) * 1.3 + l10(1e5)*(this.precomp_vexp - 1.3) : 0
243254
this.c = xterm + omegaterm + vterm + l10(8.67e23)
244255
}
245256

@@ -283,7 +294,12 @@ class mfSim extends theoryClass<theory> {
283294
this.goalBundle = [0, 0, 0, 0];
284295
this.goalBundleCost = 0;
285296
this.bestRes = null;
297+
this.precomp_vexp = -1;
298+
this.precomp_xexp = -1;
299+
this.precomp_omegaexp = -1;
300+
this.precomp_a1exp = -1;
286301
this.updateMilestonesNoMS();
302+
this.precomputeExps();
287303
this.resetParticle();
288304
}
289305
copyFrom(other: this) {
@@ -312,6 +328,7 @@ class mfSim extends theoryClass<theory> {
312328
this.stopReset = other.stopReset;
313329
this.goalBundle = [...other.goalBundle];
314330
this.goalBundleCost = other.goalBundleCost;
331+
this.precomputeExps();
315332
}
316333
copy(): mfSim {
317334
let newsim = new mfSim(super.getDataForCopy(), this.resetBundle);
@@ -357,7 +374,7 @@ class mfSim extends theoryClass<theory> {
357374
}
358375

359376
tick() {
360-
const va1 = 10 ** (this.variables[2].value * this.a1exp());
377+
const va1 = 10 ** (this.variables[2].value * this.precomp_a1exp);
361378
const va2 = 10 ** this.variables[3].value;
362379

363380
this.x += this.dt * this.vx
@@ -367,9 +384,9 @@ class mfSim extends theoryClass<theory> {
367384
this.i = this.i + scale*(icap - this.i)
368385
this.i = Math.min(this.i, icap);
369386

370-
const xterm = l10(this.x) * this.xexp()
371-
const omegaterm = (l10((q0/m0) * mu0 * this.i) + this.variables[4].value) * this.omegaexp()
372-
const vterm = this.milestones[0] ? l10(this.vtot) * this.vexp() : 0;
387+
const xterm = l10(this.x) * this.precomp_xexp
388+
const omegaterm = (l10((q0/m0) * mu0 * this.i) + this.variables[4].value) * this.precomp_omegaexp
389+
const vterm = this.milestones[0] ? l10(this.vtot) * this.precomp_vexp : 0;
373390

374391
// this.variables[0].value == vc1
375392
// this.variables[1].value == vc2

0 commit comments

Comments
 (0)