From 30bb81941c1866660b77ee6d80aa361bc648cb43 Mon Sep 17 00:00:00 2001 From: Dilawar Singh Date: Mon, 15 Nov 2021 17:08:44 +0530 Subject: [PATCH] temp: control is returned back to python Wrote to Steve. --- examples/S99_more/maze/maze_solve.py | 17 ++++++++++------- source/Smoldyn/smolsim.cpp | 10 +++++++++- source/python/CMakeLists.txt | 1 - 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/examples/S99_more/maze/maze_solve.py b/examples/S99_more/maze/maze_solve.py index 39182127..556b96b1 100644 --- a/examples/S99_more/maze/maze_solve.py +++ b/examples/S99_more/maze/maze_solve.py @@ -11,6 +11,7 @@ from pathlib import Path import typing as T + def add_maze(s, mazefile) -> T.List[smoldyn.Panel]: """Add maze""" panels = [] @@ -31,8 +32,8 @@ def add_maze(s, mazefile) -> T.List[smoldyn.Panel]: A = s.addSpecies("A", difc=2, color="blue") A.addToSolution(1000, pos=[15, 15]) -B = s.addSpecies("B", difc=0, color='black', display_size=3) -B.addToSolution(10, lowpos=[105,112], highpos=[110,112]) +B = s.addSpecies("B", difc=0, color="black", display_size=3) +B.addToSolution(10, lowpos=[105, 112], highpos=[110, 112]) panels = add_maze(s, Path(__file__).parent / "maze.txt") maze = s.addSurface("maze", panels=panels) @@ -42,12 +43,14 @@ def add_maze(s, mazefile) -> T.List[smoldyn.Panel]: # When any A meets B, maze is solved. So we set a reaction between A and B s.addReaction("done", [A, B], [], rate=10) -s.addCommand("ifless B 10 text ", "E") # Stop when A + B -> ∅ happens i.e. maze is solved. -s.addCommand("ifless B 10 pause", "E") - -# TODO: Show the solution. +s.addOutputData('posdata') +s.addCommand("molpos B posdata", "E") +s.addCommand("ifless B 10 stop", "E") s.addGraphics("opengl", iter=50) -s.run(3000, dt=0.01) +s.run(3000, dt=0.01, quit_at_end=True) + +print(s.getOutputData("posdata")) +print('all done') diff --git a/source/Smoldyn/smolsim.cpp b/source/Smoldyn/smolsim.cpp index 0c59a857..b8139ddc 100644 --- a/source/Smoldyn/smolsim.cpp +++ b/source/Smoldyn/smolsim.cpp @@ -2533,8 +2533,16 @@ int simulatetimestep(simptr sim) { sim->time+=sim->dt; // --- end of time step --- simsetvariable(sim,"time",sim->time); er=simdocommands(sim); - if(er) return er; +#ifdef COMPILE_AS_PY_MODULE + if(er == 7) { + fprintf(stdout, "command stop"); + sim->tmax = sim->time; + sim->tbreak = sim->time; + er = 0; + } +#endif + if(er) return er; if(sim->time>=sim->tmax) return 1; if(sim->time>=sim->tbreak) return 10; diff --git a/source/python/CMakeLists.txt b/source/python/CMakeLists.txt index dab7daaa..a2ad6d6e 100644 --- a/source/python/CMakeLists.txt +++ b/source/python/CMakeLists.txt @@ -11,7 +11,6 @@ target_compile_options(_pysmoldyn PRIVATE -DENABLE_PYTHON_CALLBACK) # especially where scanf is used for user input. target_compile_options(_pysmoldyn PRIVATE -DCOMPILE_AS_PY_MODULE) - target_include_directories(_pysmoldyn PRIVATE ${Python3_INCLUDE_DIRS} ${PYBIND11_SOURCE_DIR}/include) # This is suggested by pybind11: reduces binary size and disables some warnings.