|
1 | 1 | import { UNIT_TYPES } from "../enums";
|
2 | 2 |
|
3 |
| -export const ConvergenceMixin = (superclass) => class extends superclass { |
4 |
| - addConvergence({ |
5 |
| - parameter, |
6 |
| - parameterInitial, |
7 |
| - result, |
8 |
| - resultInitial, |
9 |
| - condition, |
10 |
| - operator, |
11 |
| - tolerance, |
12 |
| - maxOccurrences, |
13 |
| - }) { |
14 |
| - // RF: added TODO comments for future improvements |
| 3 | +export const ConvergenceMixin = (superclass) => |
| 4 | + class extends superclass { |
| 5 | + addConvergence({ |
| 6 | + parameter, |
| 7 | + parameterInitial, |
| 8 | + result, |
| 9 | + resultInitial, |
| 10 | + condition, |
| 11 | + operator, |
| 12 | + tolerance, |
| 13 | + maxOccurrences, |
| 14 | + }) { |
| 15 | + // RF: added TODO comments for future improvements |
15 | 16 |
|
16 |
| - const { units } = this; |
17 |
| - // Find unit to converge: should contain passed result in its results list |
18 |
| - // TODO: make user to select unit for convergence explicitly |
19 |
| - const unitForConvergence = units.find((x) => x.resultNames.find((name) => name === result)); |
| 17 | + const { units } = this; |
| 18 | + // Find unit to converge: should contain passed result in its results list |
| 19 | + // TODO: make user to select unit for convergence explicitly |
| 20 | + const unitForConvergence = units.find((x) => |
| 21 | + x.resultNames.find((name) => name === result), |
| 22 | + ); |
20 | 23 |
|
21 |
| - if (!unitForConvergence) { |
22 |
| - // eslint-disable-next-line no-undef |
23 |
| - sAlert.error( |
| 24 | + if (!unitForConvergence) { |
| 25 | + // eslint-disable-next-line no-undef |
| 26 | + sAlert.error( |
24 | 27 | `Subworkflow does not contain unit with '${result}' as extracted property.`,
|
25 |
| - ); |
26 |
| - throw new Error("There is no result to converge"); |
27 |
| - } |
| 28 | + ); |
| 29 | + throw new Error("There is no result to converge"); |
| 30 | + } |
28 | 31 |
|
29 |
| - // Replace kgrid to be ready for convergence |
30 |
| - // TODO: kgrid should be abstracted and selected by user |
31 |
| - unitForConvergence.updateContext({ |
32 |
| - kgrid: { |
33 |
| - dimensions: [`{{${parameter}}}`, `{{${parameter}}}`, `{{${parameter}}}`], |
34 |
| - shifts: [0, 0, 0], |
35 |
| - }, |
36 |
| - isKgridEdited: true, |
37 |
| - isUsingJinjaVariables: true, |
38 |
| - }); |
| 32 | + // Replace kgrid to be ready for convergence |
| 33 | + // TODO: kgrid should be abstracted and selected by user |
| 34 | + unitForConvergence.updateContext({ |
| 35 | + kgrid: { |
| 36 | + dimensions: [`{{${parameter}}}`, `{{${parameter}}}`, `{{${parameter}}}`], |
| 37 | + shifts: [0, 0, 0], |
| 38 | + }, |
| 39 | + isKgridEdited: true, |
| 40 | + isUsingJinjaVariables: true, |
| 41 | + }); |
39 | 42 |
|
40 |
| - const prevResult = "prev_result"; |
| 43 | + const prevResult = "prev_result"; |
41 | 44 |
|
42 |
| - // Assignment with result's initial value |
43 |
| - const prevResultInit = this._UnitFactory.create({ |
44 |
| - type: UNIT_TYPES.assignment, |
45 |
| - head: true, |
46 |
| - operand: prevResult, |
47 |
| - value: resultInitial, |
48 |
| - }); |
| 45 | + // Assignment with result's initial value |
| 46 | + const prevResultInit = this._UnitFactory.create({ |
| 47 | + type: UNIT_TYPES.assignment, |
| 48 | + head: true, |
| 49 | + operand: prevResult, |
| 50 | + value: resultInitial, |
| 51 | + }); |
49 | 52 |
|
50 |
| - // Assignment with initial value of convergence parameter |
51 |
| - const paramInit = this._UnitFactory.create({ |
52 |
| - type: UNIT_TYPES.assignment, |
53 |
| - operand: parameter, |
54 |
| - value: parameterInitial, |
55 |
| - }); |
| 53 | + // Assignment with initial value of convergence parameter |
| 54 | + const paramInit = this._UnitFactory.create({ |
| 55 | + type: UNIT_TYPES.assignment, |
| 56 | + operand: parameter, |
| 57 | + value: parameterInitial, |
| 58 | + }); |
56 | 59 |
|
57 |
| - // Assignment for storing iteration result: extracts 'result' from convergence unit scope |
58 |
| - const storePrevResult = this._UnitFactory.create({ |
59 |
| - type: UNIT_TYPES.assignment, |
60 |
| - input: [ |
61 |
| - { |
62 |
| - scope: unitForConvergence.flowchartId, |
63 |
| - name: result, |
64 |
| - }, |
65 |
| - ], |
66 |
| - operand: prevResult, |
67 |
| - value: result, |
68 |
| - }); |
| 60 | + // Assignment for storing iteration result: extracts 'result' from convergence unit scope |
| 61 | + const storePrevResult = this._UnitFactory.create({ |
| 62 | + type: UNIT_TYPES.assignment, |
| 63 | + input: [ |
| 64 | + { |
| 65 | + scope: unitForConvergence.flowchartId, |
| 66 | + name: result, |
| 67 | + }, |
| 68 | + ], |
| 69 | + operand: prevResult, |
| 70 | + value: result, |
| 71 | + }); |
69 | 72 |
|
70 |
| - // Assignment for convergence param increase |
71 |
| - const nextStep = this._UnitFactory.create({ |
72 |
| - type: UNIT_TYPES.assignment, |
73 |
| - input: [], |
74 |
| - operand: parameter, |
75 |
| - value: `${parameter} + 1`, |
76 |
| - next: unitForConvergence.flowchartId, |
77 |
| - }); |
| 73 | + // Assignment for convergence param increase |
| 74 | + const nextStep = this._UnitFactory.create({ |
| 75 | + type: UNIT_TYPES.assignment, |
| 76 | + input: [], |
| 77 | + operand: parameter, |
| 78 | + value: `${parameter} + 1`, |
| 79 | + next: unitForConvergence.flowchartId, |
| 80 | + }); |
78 | 81 |
|
79 |
| - // Final step of convergence |
80 |
| - const exit = this._UnitFactory.create({ |
81 |
| - type: UNIT_TYPES.assignment, |
82 |
| - name: "exit", |
83 |
| - input: [], |
84 |
| - operand: parameter, |
85 |
| - value: `${parameter} + 0`, |
86 |
| - }); |
| 82 | + // Final step of convergence |
| 83 | + const exit = this._UnitFactory.create({ |
| 84 | + type: UNIT_TYPES.assignment, |
| 85 | + name: "exit", |
| 86 | + input: [], |
| 87 | + operand: parameter, |
| 88 | + value: `${parameter} + 0`, |
| 89 | + }); |
87 | 90 |
|
88 |
| - // Final step of convergence |
89 |
| - const storeResult = this._UnitFactory.create({ |
90 |
| - type: UNIT_TYPES.assignment, |
91 |
| - input: [ |
92 |
| - { |
93 |
| - scope: unitForConvergence.flowchartId, |
94 |
| - name: result, |
95 |
| - }, |
96 |
| - ], |
97 |
| - operand: result, |
98 |
| - value: result, |
99 |
| - }); |
| 91 | + // Final step of convergence |
| 92 | + const storeResult = this._UnitFactory.create({ |
| 93 | + type: UNIT_TYPES.assignment, |
| 94 | + input: [ |
| 95 | + { |
| 96 | + scope: unitForConvergence.flowchartId, |
| 97 | + name: result, |
| 98 | + }, |
| 99 | + ], |
| 100 | + operand: result, |
| 101 | + value: result, |
| 102 | + }); |
100 | 103 |
|
101 |
| - // Convergence condition unit |
102 |
| - const conditionUnit = this._UnitFactory.create({ |
103 |
| - type: UNIT_TYPES.condition, |
104 |
| - statement: `${condition} ${operator} ${tolerance}`, |
105 |
| - then: exit.flowchartId, |
106 |
| - else: storePrevResult.flowchartId, |
107 |
| - maxOccurrences, |
108 |
| - next: storePrevResult.flowchartId, |
109 |
| - }); |
| 104 | + // Convergence condition unit |
| 105 | + const conditionUnit = this._UnitFactory.create({ |
| 106 | + type: UNIT_TYPES.condition, |
| 107 | + statement: `${condition} ${operator} ${tolerance}`, |
| 108 | + then: exit.flowchartId, |
| 109 | + else: storePrevResult.flowchartId, |
| 110 | + maxOccurrences, |
| 111 | + next: storePrevResult.flowchartId, |
| 112 | + }); |
110 | 113 |
|
111 |
| - this.addUnit(prevResultInit, true); |
112 |
| - this.addUnit(paramInit, true); |
113 |
| - this.addUnit(storeResult); |
114 |
| - this.addUnit(conditionUnit); |
115 |
| - this.addUnit(storePrevResult); |
116 |
| - this.addUnit(nextStep); |
117 |
| - this.addUnit(exit); |
| 114 | + this.addUnit(prevResultInit, true); |
| 115 | + this.addUnit(paramInit, true); |
| 116 | + this.addUnit(storeResult); |
| 117 | + this.addUnit(conditionUnit); |
| 118 | + this.addUnit(storePrevResult); |
| 119 | + this.addUnit(nextStep); |
| 120 | + this.addUnit(exit); |
118 | 121 |
|
119 |
| - // `addUnit` adjusts the `next` field, hence the below. |
120 |
| - nextStep.next = unitForConvergence.flowchartId; |
121 |
| - } |
122 |
| -}; |
| 122 | + // `addUnit` adjusts the `next` field, hence the below. |
| 123 | + nextStep.next = unitForConvergence.flowchartId; |
| 124 | + } |
| 125 | + }; |
0 commit comments