Skip to content

Commit 6fc03ae

Browse files
fixed default values for solver
1 parent cbb46d9 commit 6fc03ae

File tree

2 files changed

+26
-55
lines changed

2 files changed

+26
-55
lines changed

src/App.jsx

Lines changed: 21 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ import { createFunctionNode } from './components/nodes/FunctionNode.jsx';
2828

2929
// * Declaring variables *
3030

31+
// Default solver parameters
32+
const DEFAULT_SOLVER_PARAMS = {
33+
dt: '0.01',
34+
dt_min: '1e-16',
35+
dt_max: '',
36+
Solver: 'SSPRK22',
37+
tolerance_fpi: '1e-10',
38+
iterations_max: '200',
39+
log: 'true',
40+
simulation_duration: '10.0',
41+
extra_params: '{}'
42+
};
43+
3144
// Defining initial nodes and edges. In the data section, we have label, but also parameters specific to the node.
3245
const initialNodes = [];
3346
const initialEdges = [];
@@ -78,17 +91,7 @@ const DnDFlow = () => {
7891

7992

8093
// Solver parameters state
81-
const [solverParams, setSolverParams] = useState({
82-
dt: '0.01',
83-
dt_min: '1e-6',
84-
dt_max: '1.0',
85-
Solver: 'SSPRK22',
86-
tolerance_fpi: '1e-6',
87-
iterations_max: '100',
88-
log: 'true',
89-
simulation_duration: '50.0',
90-
extra_params: '{}'
91-
});
94+
const [solverParams, setSolverParams] = useState(DEFAULT_SOLVER_PARAMS);
9295

9396
// Global variables state
9497
const [globalVariables, setGlobalVariables] = useState([]);
@@ -411,17 +414,7 @@ const DnDFlow = () => {
411414
setEdges(loadedEdges || []);
412415
setSelectedNode(null);
413416
setNodeCounter(loadedNodeCounter ?? loadedNodes.length);
414-
setSolverParams(loadedSolverParams ?? {
415-
dt: '0.01',
416-
dt_min: '1e-6',
417-
dt_max: '1.0',
418-
Solver: 'SSPRK22',
419-
tolerance_fpi: '1e-6',
420-
iterations_max: '100',
421-
log: 'true',
422-
simulation_duration: '50.0',
423-
extra_params: '{}'
424-
});
417+
setSolverParams(loadedSolverParams ?? DEFAULT_SOLVER_PARAMS);
425418
setGlobalVariables(loadedGlobalVariables ?? []);
426419
setEvents(loadedEvents ?? []);
427420
setPythonCode(loadedPythonCode ?? "# Define your Python variables and functions here\n# Example:\n# my_variable = 42\n# def my_function(x):\n# return x * 2\n");
@@ -480,17 +473,7 @@ const DnDFlow = () => {
480473
setEdges(loadedEdges || []);
481474
setSelectedNode(null);
482475
setNodeCounter(loadedNodeCounter ?? loadedNodes.length);
483-
setSolverParams(loadedSolverParams ?? {
484-
dt: '0.01',
485-
dt_min: '1e-6',
486-
dt_max: '1.0',
487-
Solver: 'SSPRK22',
488-
tolerance_fpi: '1e-6',
489-
iterations_max: '100',
490-
log: 'true',
491-
simulation_duration: '50.0',
492-
extra_params: '{}'
493-
});
476+
setSolverParams(loadedSolverParams ?? DEFAULT_SOLVER_PARAMS);
494477
setGlobalVariables(loadedGlobalVariables ?? []);
495478
setEvents(loadedEvents ?? []);
496479
setPythonCode(loadedPythonCode ?? "# Define your Python variables and functions here\n# Example:\n# my_variable = 42\n# def my_function(x):\n# return x * 2\n");
@@ -515,17 +498,7 @@ const DnDFlow = () => {
515498
setEdges(initialEdges);
516499
setSelectedNode(null);
517500
setNodeCounter(0);
518-
setSolverParams({
519-
dt: '0.01',
520-
dt_min: '1e-6',
521-
dt_max: '1.0',
522-
Solver: 'SSPRK22',
523-
tolerance_fpi: '1e-6',
524-
iterations_max: '100',
525-
log: 'true',
526-
simulation_duration: '50.0',
527-
extra_params: '{}'
528-
});
501+
setSolverParams(DEFAULT_SOLVER_PARAMS);
529502
setGlobalVariables([]);
530503
};
531504
const downloadCsv = async () => {
@@ -1476,7 +1449,6 @@ const DnDFlow = () => {
14761449
color: '#ffffff',
14771450
fontSize: '14px'
14781451
}}
1479-
placeholder="0.01"
14801452
/>
14811453
</div>
14821454

@@ -1502,7 +1474,6 @@ const DnDFlow = () => {
15021474
color: '#ffffff',
15031475
fontSize: '14px'
15041476
}}
1505-
placeholder="1e-6"
15061477
/>
15071478
</div>
15081479

@@ -1528,7 +1499,6 @@ const DnDFlow = () => {
15281499
color: '#ffffff',
15291500
fontSize: '14px'
15301501
}}
1531-
placeholder="1.0"
15321502
/>
15331503
</div>
15341504

@@ -1608,7 +1578,6 @@ const DnDFlow = () => {
16081578
color: '#ffffff',
16091579
fontSize: '14px'
16101580
}}
1611-
placeholder="1e-6"
16121581
/>
16131582
</div>
16141583

@@ -1634,7 +1603,6 @@ const DnDFlow = () => {
16341603
color: '#ffffff',
16351604
fontSize: '14px'
16361605
}}
1637-
placeholder="100"
16381606
/>
16391607
</div>
16401608

@@ -1660,7 +1628,6 @@ const DnDFlow = () => {
16601628
color: '#ffffff',
16611629
fontSize: '14px'
16621630
}}
1663-
placeholder="50.0"
16641631
/>
16651632
</div>
16661633

@@ -1744,11 +1711,11 @@ const DnDFlow = () => {
17441711
// Reset to default values
17451712
setSolverParams({
17461713
dt: '0.01',
1747-
dt_min: '1e-6',
1748-
dt_max: '1.0',
1714+
dt_min: '1e-16',
1715+
dt_max: '',
17491716
Solver: 'SSPRK22',
1750-
tolerance_fpi: '1e-6',
1751-
iterations_max: '100',
1717+
tolerance_fpi: '1e-10',
1718+
iterations_max: '200',
17521719
log: 'true',
17531720
simulation_duration: '50.0'
17541721
});

src/python/pathsim_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ def make_solver_params(solver_prms, eval_namespace=None):
203203
for k, v in solver_prms.items():
204204
if k not in ["Solver", "log"]:
205205
try:
206-
solver_prms[k] = eval(v, eval_namespace)
206+
if v == "":
207+
# TODO get the default from pathsim._constants
208+
solver_prms[k] = None
209+
else:
210+
solver_prms[k] = eval(v, eval_namespace)
207211
except Exception as e:
208212
return jsonify(
209213
{"error": f"Invalid value for {k}: {v}. Error: {str(e)}"}

0 commit comments

Comments
 (0)