|
ADS-IDAC Engine 5.0.0
|
ThermalHydraulicSolver backed by a solver process behind a REST API. More...
#include <RestApiSolver.h>
Public Member Functions | |
| RestApiSolver (const std::string &base_url) | |
| void | runSequence (SolverCallback &cb) override |
| Run one sequence against the remote solver. Blocks until it ends. More... | |
| double | currentTime () const override |
| r5pars_.timesno [s] More... | |
| int | stopFlag () const override |
| r5pars_.csnostop More... | |
| bool | isTerminateAll () const override |
| r5pars_.terminateall More... | |
| void | setTerminateAll (bool v) override |
| Sets r5pars_.terminateall. More... | |
| void | setBranchCount (int n) override |
| Sets r5pars_.cnbranch. More... | |
| void | setGenNode (bool v) override |
| Sets r5pars_.cgennode. More... | |
| void | setNewRestart (bool v) override |
| Sets r5pars_.cnewrst. More... | |
| void | setInputDeck (const std::string &path) override |
Store path in r5pars_.carg2 / carg2len. The remote solver does not read input decks; runSequence() always reads "indeck.i". More... | |
| std::vector< char > | checkpoint () override |
| JSON object mapping restart count (as a string key) to the server-side checkpoint id, for the checkpoints of the current sequence. More... | |
| void | restore (const std::vector< char > &data) override |
Parse a buffer produced by checkpoint() and keep its map for the next runSequence(), which performs the server-side restore. An empty data is ignored; malformed JSON throws. The ids refer to checkpoints stored by the solver process, not to data in the buffer. More... | |
| void | setThermoCacheMode (int mode) override |
| No-op. More... | |
| void | setMembufMode (int mode) override |
| No-op. More... | |
Public Member Functions inherited from ThermalHydraulicSolver | |
| virtual | ~ThermalHydraulicSolver ()=default |
| virtual void | runSequence (SolverCallback &cb)=0 |
Run one complete simulation sequence. Blocks until the sequence completes. The solver calls back into cb at evaluation points during execution. More... | |
| virtual double | currentTime () const =0 |
| Current simulation time [s]. More... | |
| virtual int | stopFlag () const =0 |
| RELAP5 stop flag. 0=running, 3=normal end, 11=crash. More... | |
| virtual bool | isTerminateAll () const =0 |
| True if all simulation should terminate. More... | |
| virtual void | setTerminateAll (bool v)=0 |
| Set the terminate-all flag. More... | |
| virtual void | setBranchCount (int n)=0 |
| Set the number of branches generated at the current branching point. More... | |
| virtual void | setGenNode (bool v)=0 |
| Signal the solver to generate a restart checkpoint at this point. More... | |
| virtual void | setNewRestart (bool v)=0 |
| Set whether this is a fresh start (true) or a restart (false). More... | |
| virtual void | setInputDeck (const std::string &path)=0 |
| Set the input deck file path for the next sequence. More... | |
| virtual std::vector< char > | checkpoint ()=0 |
| Extract the solver's restart checkpoint as an opaque byte buffer. More... | |
| virtual void | restore (const std::vector< char > &data)=0 |
| Restore the solver's state from a buffer returned by checkpoint(). More... | |
| virtual void | setThermoCacheMode (int mode)=0 |
| Set thermodynamic table caching mode (RelapSolver; no-op for RestApiSolver). 2 forces a reload of the steam tables at every sequence; any other value (0 is the default) reuses the cached tables when the table set is unchanged. More... | |
| virtual void | setMembufMode (int mode)=0 |
| Set in-memory restart buffer mode (RelapSolver; no-op for RestApiSolver). 1=enabled, 0=disabled. The engine always passes 1. More... | |
Private Member Functions | |
| std::string | httpPost (const std::string &path, const std::string &body="{}") |
| std::string | httpGet (const std::string &path) |
| std::string | httpDelete (const std::string &path) |
| void | createSession (bool fresh) |
| void | destroySession () |
| void | populateR5Pars (const std::string &json_str) |
| void | sendInterventions () |
Static Private Member Functions | |
| static int | parseNcountFromIndeck (const std::string &path) |
Private Attributes | |
| std::string | base_url_ |
| std::string | session_id_ |
| std::string | last_checkpoint_id_ |
| bool | first_sequence_ = true |
| int | checkpoint_counter_ = 0 |
| std::map< int, std::string > | seq_checkpoints_ |
| std::map< int, std::string > | restore_checkpoints_ |
| std::map< int, double > | last_inter_val_ |
ThermalHydraulicSolver backed by a solver process behind a REST API.
Responses are written into the shared r5pars_ struct, so the engine reads plant values exactly as it does with RelapSolver. One server session is created by the first runSequence() and reused for the life of the object; it is not deleted at destruction.
Definition at line 30 of file RestApiSolver.h.
|
explicit |
| base_url | Base URL of the solver, "http://host:port" (for example "http://localhost:9090"; port 80 when none is given). No request is made until the first runSequence(). |
Definition at line 18 of file RestApiSolver.cpp.
|
overridevirtual |
JSON object mapping restart count (as a string key) to the server-side checkpoint id, for the checkpoints of the current sequence.
Implements ThermalHydraulicSolver.
Definition at line 317 of file RestApiSolver.cpp.
References seq_checkpoints_.
|
private |
Definition at line 93 of file RestApiSolver.cpp.
References httpPost(), faulttree::xml::parse(), and session_id_.
Referenced by runSequence().
|
overridevirtual |
r5pars_.timesno [s]
Implements ThermalHydraulicSolver.
Definition at line 293 of file RestApiSolver.cpp.
References r5pars_.
|
private |
Definition at line 101 of file RestApiSolver.cpp.
References httpDelete(), and session_id_.
|
private |
Definition at line 74 of file RestApiSolver.cpp.
References base_url_.
Referenced by destroySession().
|
private |
Definition at line 52 of file RestApiSolver.cpp.
References base_url_.
|
private |
Definition at line 23 of file RestApiSolver.cpp.
References base_url_.
Referenced by createSession(), runSequence(), and sendInterventions().
|
overridevirtual |
r5pars_.terminateall
Implements ThermalHydraulicSolver.
Definition at line 295 of file RestApiSolver.cpp.
References r5pars_.
|
staticprivate |
Definition at line 350 of file RestApiSolver.cpp.
Referenced by runSequence().
|
private |
Definition at line 110 of file RestApiSolver.cpp.
References faulttree::xml::parse(), and r5pars_.
Referenced by runSequence().
|
overridevirtual |
Parse a buffer produced by checkpoint() and keep its map for the next runSequence(), which performs the server-side restore. An empty data is ignored; malformed JSON throws. The ids refer to checkpoints stored by the solver process, not to data in the buffer.
Implements ThermalHydraulicSolver.
Definition at line 330 of file RestApiSolver.cpp.
References faulttree::xml::parse(), and restore_checkpoints_.
|
overridevirtual |
Run one sequence against the remote solver. Blocks until it ends.
First call: creates the server session. Later calls, when restore() has loaded a checkpoint map: reads the restart count from card 103 of "indeck.i" in the working directory, restores that server-side checkpoint (falling back to the highest-numbered entry, with a warning on stderr, if the count is not in the map) and resets csnostop, timesno, cgennode and cnbranch in r5pars_. It then calls cb.onFirstInit() (first call only) and cb.onScenarioStart(), and loops while r5pars_.csnostop == 0 and terminateall is false: advance 0.5 s, copy the response into r5pars_, increment r5pars_.cncount, call cb.onEvaluationPoint(), post changed interactive variables, and, when cgennode is set with more than one branch, take a server checkpoint and call cb.onBranchingPoint().
Implements ThermalHydraulicSolver.
Definition at line 202 of file RestApiSolver.cpp.
References checkpoint_counter_, createSession(), first_sequence_, httpPost(), last_checkpoint_id_, last_inter_val_, SolverCallback::onBranchingPoint(), SolverCallback::onEvaluationPoint(), SolverCallback::onFirstInit(), SolverCallback::onScenarioStart(), faulttree::xml::parse(), parseNcountFromIndeck(), populateR5Pars(), r5pars_, restore_checkpoints_, sendInterventions(), seq_checkpoints_, and session_id_.
|
private |
Definition at line 181 of file RestApiSolver.cpp.
References e, httpPost(), last_inter_val_, r5pars_, and session_id_.
Referenced by runSequence().
|
overridevirtual |
Sets r5pars_.cnbranch.
Implements ThermalHydraulicSolver.
Definition at line 300 of file RestApiSolver.cpp.
References r5pars_.
|
overridevirtual |
Sets r5pars_.cgennode.
Implements ThermalHydraulicSolver.
Definition at line 301 of file RestApiSolver.cpp.
References r5pars_.
|
overridevirtual |
Store path in r5pars_.carg2 / carg2len. The remote solver does not read input decks; runSequence() always reads "indeck.i".
Implements ThermalHydraulicSolver.
Definition at line 307 of file RestApiSolver.cpp.
References r5pars_.
|
overridevirtual |
|
overridevirtual |
Sets r5pars_.cnewrst.
Implements ThermalHydraulicSolver.
Definition at line 305 of file RestApiSolver.cpp.
References r5pars_.
|
overridevirtual |
Sets r5pars_.terminateall.
Implements ThermalHydraulicSolver.
Definition at line 296 of file RestApiSolver.cpp.
References r5pars_.
|
overridevirtual |
|
overridevirtual |
r5pars_.csnostop
Implements ThermalHydraulicSolver.
Definition at line 294 of file RestApiSolver.cpp.
References r5pars_.
|
private |
Definition at line 91 of file RestApiSolver.h.
Referenced by httpDelete(), httpGet(), and httpPost().
|
private |
Definition at line 96 of file RestApiSolver.h.
Referenced by runSequence().
|
private |
Definition at line 95 of file RestApiSolver.h.
Referenced by runSequence().
|
private |
Definition at line 93 of file RestApiSolver.h.
Referenced by runSequence().
|
private |
Definition at line 121 of file RestApiSolver.h.
Referenced by runSequence(), and sendInterventions().
|
private |
Definition at line 100 of file RestApiSolver.h.
Referenced by restore(), and runSequence().
|
private |
Definition at line 99 of file RestApiSolver.h.
Referenced by checkpoint(), and runSequence().
|
private |
Definition at line 92 of file RestApiSolver.h.
Referenced by createSession(), destroySession(), runSequence(), and sendInterventions().