Skip to content

Commit 5344b0e

Browse files
authored
Verify node type before calling loadflow (#3021)
Signed-off-by: AAJELLAL <[email protected]>
1 parent 0b58aef commit 5344b0e

File tree

5 files changed

+64
-26
lines changed

5 files changed

+64
-26
lines changed

src/components/run-button-container.jsx

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useDispatch, useSelector } from 'react-redux';
1818

1919
import RunningStatus from './utils/running-status';
2020

21-
import { PARAM_DEVELOPER_MODE } from '../utils/config-params';
21+
import { PARAM_DEVELOPER_MODE, PARAM_PROVIDER_DYNAFLOW } from '../utils/config-params';
2222

2323
import { useSnackMessage, ComputingType } from '@gridsuite/commons-ui';
2424
import RunButton from './run-button';
@@ -32,7 +32,7 @@ import {
3232
startDynamicSimulation,
3333
stopDynamicSimulation,
3434
} from '../services/study/dynamic-simulation';
35-
import { startLoadFlow, stopLoadFlow } from '../services/study/loadflow';
35+
import { getLoadFlowProvider, startLoadFlow, stopLoadFlow } from '../services/study/loadflow';
3636
import { startSecurityAnalysis, stopSecurityAnalysis } from '../services/study/security-analysis';
3737
import { startShortCircuitAnalysis, stopShortCircuitAnalysis } from '../services/study/short-circuit-analysis';
3838
import { startVoltageInit, stopVoltageInit } from '../services/study/voltage-init';
@@ -41,6 +41,7 @@ import { OptionalServicesNames, OptionalServicesStatus } from './utils/optional-
4141
import { useOptionalServiceStatus } from '../hooks/use-optional-service-status';
4242
import { startDynamicSecurityAnalysis, stopDynamicSecurityAnalysis } from '../services/study/dynamic-security-analysis';
4343
import { useParameterState } from './dialogs/parameters/use-parameters-state';
44+
import { isSecurityModificationNode } from './graph/tree-node.type.js';
4445

4546
const checkDynamicSimulationParameters = (studyUuid) => {
4647
return fetchDynamicSimulationParameters(studyUuid).then((params) => {
@@ -137,7 +138,25 @@ export function RunButtonContainer({ studyUuid, currentNode, currentRootNetworkU
137138
},
138139
[dispatch, snackError]
139140
);
140-
141+
//In DynaFlow, we need to verify that the current node is a security node before starting the computation.
142+
const checkLoadFlowProvider = useCallback(
143+
(studyUuid, handleComputation) => {
144+
if (isSecurityModificationNode(currentNode)) {
145+
handleComputation();
146+
return;
147+
}
148+
getLoadFlowProvider(studyUuid).then((provider) => {
149+
if (provider === PARAM_PROVIDER_DYNAFLOW) {
150+
snackError({
151+
headerId: 'LoadFlowDynaFlowError',
152+
});
153+
} else {
154+
handleComputation();
155+
}
156+
});
157+
},
158+
[currentNode, snackError]
159+
);
141160
const handleStartSecurityAnalysis = (contingencyListNames) => {
142161
startComputationAsync(
143162
ComputingType.SECURITY_ANALYSIS,
@@ -171,6 +190,26 @@ export function RunButtonContainer({ studyUuid, currentNode, currentRootNetworkU
171190
'DynamicSimulationRunError'
172191
);
173192
};
193+
const handleStartLoadFlow = useCallback(
194+
(withRatioTapChangers) => {
195+
startComputationAsync(
196+
ComputingType.LOAD_FLOW,
197+
() => {
198+
dispatch(
199+
setComputingStatusParameters(ComputingType.LOAD_FLOW, {
200+
withRatioTapChangers: withRatioTapChangers,
201+
})
202+
);
203+
},
204+
() => startLoadFlow(studyUuid, currentNode?.id, currentRootNetworkUuid, withRatioTapChangers),
205+
() => {},
206+
null,
207+
'startLoadFlowError',
208+
() => {}
209+
);
210+
},
211+
[currentNode?.id, currentRootNetworkUuid, dispatch, startComputationAsync, studyUuid]
212+
);
174213

175214
const runnables = useMemo(() => {
176215
function actionOnRunnables(type, fnStop) {
@@ -184,17 +223,7 @@ export function RunButtonContainer({ studyUuid, currentNode, currentRootNetworkU
184223
LOAD_FLOW_WITHOUT_RATIO_TAP_CHANGERS: {
185224
messageId: 'LoadFlow',
186225
startComputation() {
187-
startComputationAsync(
188-
ComputingType.LOAD_FLOW,
189-
() =>
190-
dispatch(
191-
setComputingStatusParameters(ComputingType.LOAD_FLOW, { withRatioTapChangers: false })
192-
),
193-
() => startLoadFlow(studyUuid, currentNode?.id, currentRootNetworkUuid, false),
194-
() => {},
195-
null,
196-
'startLoadFlowError'
197-
);
226+
checkLoadFlowProvider(studyUuid, () => handleStartLoadFlow(false));
198227
},
199228
actionOnRunnable() {
200229
actionOnRunnables(ComputingType.LOAD_FLOW, () => stopLoadFlow(studyUuid, currentNode?.id, false));
@@ -203,17 +232,7 @@ export function RunButtonContainer({ studyUuid, currentNode, currentRootNetworkU
203232
LOAD_FLOW_WITH_RATIO_TAP_CHANGERS: {
204233
messageId: 'LoadFlowWithRatioTapChangers',
205234
startComputation() {
206-
startComputationAsync(
207-
ComputingType.LOAD_FLOW,
208-
() =>
209-
dispatch(
210-
setComputingStatusParameters(ComputingType.LOAD_FLOW, { withRatioTapChangers: true })
211-
),
212-
() => startLoadFlow(studyUuid, currentNode?.id, currentRootNetworkUuid, true),
213-
() => {},
214-
null,
215-
'startLoadFlowError'
216-
);
235+
checkLoadFlowProvider(studyUuid, () => handleStartLoadFlow(true));
217236
},
218237
actionOnRunnable() {
219238
actionOnRunnables(ComputingType.LOAD_FLOW, () => stopLoadFlow(studyUuid, currentNode?.id, true));
@@ -370,7 +389,16 @@ export function RunButtonContainer({ studyUuid, currentNode, currentRootNetworkU
370389
},
371390
},
372391
};
373-
}, [dispatch, snackError, startComputationAsync, studyUuid, currentNode?.id, currentRootNetworkUuid]);
392+
}, [
393+
dispatch,
394+
checkLoadFlowProvider,
395+
studyUuid,
396+
handleStartLoadFlow,
397+
currentNode?.id,
398+
currentRootNetworkUuid,
399+
startComputationAsync,
400+
snackError,
401+
]);
374402

375403
// running status is refreshed more often, so we memoize it apart
376404
const getRunningStatus = useCallback(

src/services/study/loadflow.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ export function getLoadFlowParameters(studyUuid: UUID) {
3838
return backendFetchJson(getLfParams);
3939
}
4040

41+
export function getLoadFlowProvider(studyUuid: UUID) {
42+
console.info('get load flow provider');
43+
const getLfParams = getStudyUrl(studyUuid) + '/loadflow/provider';
44+
console.debug(getLfParams);
45+
return backendFetchText(getLfParams);
46+
}
47+
4148
export function getLoadFlowParametersId(studyUuid: UUID) {
4249
console.info('get load flow parameters id');
4350
const getLoadFlowParametersIdUrl = getStudyUrl(studyUuid) + '/loadflow/parameters/id';

src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@
349349
"SensitivityInDeltaA": "Sensitivity on branches in ΔA",
350350
"SensitivityAtNode": "Sensitivity at nodes",
351351
"LoadFlowError": "An error occurred when executing loadflow",
352+
"LoadFlowDynaFlowError": "You must run DynaFlow from a security type node",
352353
"ShortCircuitAnalysis": "Short circuit analysis",
353354
"ShortCircuitAnalysisParameters": "Short circuit analysis parameters",
354355
"startShortCircuitError": "An error occurred while starting the short circuit analysis",

src/translations/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@
347347
"SensitivityInDeltaA": "Sensibilité au niveau des quadripôles en ΔA",
348348
"SensitivityAtNode": "Nœuds",
349349
"LoadFlowError": "Une erreur est survenue lors de l'exécution du calcul de répartition",
350+
"LoadFlowDynaFlowError": "Vous devez lancer DynaFlow à partir d'un noeud de type sécurité",
350351
"ShortCircuitAnalysis": "Analyse de court-circuit",
351352
"ShortCircuitAnalysisParameters": "Paramètres de l'analyse de court-circuit",
352353
"startShortCircuitError": "Une erreur est survenue lors du lancement de l'analyse de court-circuit",

src/utils/config-params.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const PARAM_SA_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD = 'highVoltageAbsoluteThre
3030

3131
// Param values
3232
export const PARAM_PROVIDER_OPENLOADFLOW = 'OpenLoadFlow';
33+
export const PARAM_PROVIDER_DYNAFLOW = 'DynaFlow';
3334

3435
export const basemap_style_theme_key = (basemap: string) => basemap + 'Style';
3536

0 commit comments

Comments
 (0)