← Documentation
ADS-IDAC Engine 5.0.0
RestApiSolver Class Reference

ThermalHydraulicSolver backed by a solver process behind a REST API. More...

#include <RestApiSolver.h>

Inheritance diagram for RestApiSolver:
[legend]
Collaboration diagram for RestApiSolver:
[legend]

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_
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ RestApiSolver()

RestApiSolver::RestApiSolver ( const std::string &  base_url)
explicit
Parameters
base_urlBase 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.

Member Function Documentation

◆ checkpoint()

std::vector< char > RestApiSolver::checkpoint ( )
overridevirtual

JSON object mapping restart count (as a string key) to the server-side checkpoint id, for the checkpoints of the current sequence.

Returns
The JSON text as bytes, or an empty vector if the sequence took no checkpoint.

Implements ThermalHydraulicSolver.

Definition at line 317 of file RestApiSolver.cpp.

References seq_checkpoints_.

◆ createSession()

void RestApiSolver::createSession ( bool  fresh)
private

Definition at line 93 of file RestApiSolver.cpp.

References httpPost(), faulttree::xml::parse(), and session_id_.

Referenced by runSequence().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ currentTime()

double RestApiSolver::currentTime ( ) const
overridevirtual

r5pars_.timesno [s]

Implements ThermalHydraulicSolver.

Definition at line 293 of file RestApiSolver.cpp.

References r5pars_.

◆ destroySession()

void RestApiSolver::destroySession ( )
private

Definition at line 101 of file RestApiSolver.cpp.

References httpDelete(), and session_id_.

Here is the call graph for this function:

◆ httpDelete()

std::string RestApiSolver::httpDelete ( const std::string &  path)
private

Definition at line 74 of file RestApiSolver.cpp.

References base_url_.

Referenced by destroySession().

Here is the caller graph for this function:

◆ httpGet()

std::string RestApiSolver::httpGet ( const std::string &  path)
private

Definition at line 52 of file RestApiSolver.cpp.

References base_url_.

◆ httpPost()

std::string RestApiSolver::httpPost ( const std::string &  path,
const std::string &  body = "{}" 
)
private

Definition at line 23 of file RestApiSolver.cpp.

References base_url_.

Referenced by createSession(), runSequence(), and sendInterventions().

Here is the caller graph for this function:

◆ isTerminateAll()

bool RestApiSolver::isTerminateAll ( ) const
overridevirtual

r5pars_.terminateall

Implements ThermalHydraulicSolver.

Definition at line 295 of file RestApiSolver.cpp.

References r5pars_.

◆ parseNcountFromIndeck()

int RestApiSolver::parseNcountFromIndeck ( const std::string &  path)
staticprivate

Definition at line 350 of file RestApiSolver.cpp.

Referenced by runSequence().

Here is the caller graph for this function:

◆ populateR5Pars()

void RestApiSolver::populateR5Pars ( const std::string &  json_str)
private

Definition at line 110 of file RestApiSolver.cpp.

References faulttree::xml::parse(), and r5pars_.

Referenced by runSequence().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore()

void RestApiSolver::restore ( const std::vector< char > &  data)
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_.

Here is the call graph for this function:

◆ runSequence()

void RestApiSolver::runSequence ( SolverCallback &  cb)
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_.

Here is the call graph for this function:

◆ sendInterventions()

void RestApiSolver::sendInterventions ( )
private

Definition at line 181 of file RestApiSolver.cpp.

References e, httpPost(), last_inter_val_, r5pars_, and session_id_.

Referenced by runSequence().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBranchCount()

void RestApiSolver::setBranchCount ( int  n)
overridevirtual

Sets r5pars_.cnbranch.

Implements ThermalHydraulicSolver.

Definition at line 300 of file RestApiSolver.cpp.

References r5pars_.

◆ setGenNode()

void RestApiSolver::setGenNode ( bool  v)
overridevirtual

Sets r5pars_.cgennode.

Implements ThermalHydraulicSolver.

Definition at line 301 of file RestApiSolver.cpp.

References r5pars_.

◆ setInputDeck()

void RestApiSolver::setInputDeck ( const std::string &  path)
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_.

◆ setMembufMode()

void RestApiSolver::setMembufMode ( int  mode)
overridevirtual

No-op.

Implements ThermalHydraulicSolver.

Definition at line 346 of file RestApiSolver.cpp.

◆ setNewRestart()

void RestApiSolver::setNewRestart ( bool  v)
overridevirtual

Sets r5pars_.cnewrst.

Implements ThermalHydraulicSolver.

Definition at line 305 of file RestApiSolver.cpp.

References r5pars_.

◆ setTerminateAll()

void RestApiSolver::setTerminateAll ( bool  v)
overridevirtual

Sets r5pars_.terminateall.

Implements ThermalHydraulicSolver.

Definition at line 296 of file RestApiSolver.cpp.

References r5pars_.

◆ setThermoCacheMode()

void RestApiSolver::setThermoCacheMode ( int  mode)
overridevirtual

No-op.

Implements ThermalHydraulicSolver.

Definition at line 345 of file RestApiSolver.cpp.

◆ stopFlag()

int RestApiSolver::stopFlag ( ) const
overridevirtual

r5pars_.csnostop

Implements ThermalHydraulicSolver.

Definition at line 294 of file RestApiSolver.cpp.

References r5pars_.

Member Data Documentation

◆ base_url_

std::string RestApiSolver::base_url_
private

Definition at line 91 of file RestApiSolver.h.

Referenced by httpDelete(), httpGet(), and httpPost().

◆ checkpoint_counter_

int RestApiSolver::checkpoint_counter_ = 0
private

Definition at line 96 of file RestApiSolver.h.

Referenced by runSequence().

◆ first_sequence_

bool RestApiSolver::first_sequence_ = true
private

Definition at line 95 of file RestApiSolver.h.

Referenced by runSequence().

◆ last_checkpoint_id_

std::string RestApiSolver::last_checkpoint_id_
private

Definition at line 93 of file RestApiSolver.h.

Referenced by runSequence().

◆ last_inter_val_

std::map<int, double> RestApiSolver::last_inter_val_
private

Definition at line 121 of file RestApiSolver.h.

Referenced by runSequence(), and sendInterventions().

◆ restore_checkpoints_

std::map<int, std::string> RestApiSolver::restore_checkpoints_
private

Definition at line 100 of file RestApiSolver.h.

Referenced by restore(), and runSequence().

◆ seq_checkpoints_

std::map<int, std::string> RestApiSolver::seq_checkpoints_
private

Definition at line 99 of file RestApiSolver.h.

Referenced by checkpoint(), and runSequence().

◆ session_id_

std::string RestApiSolver::session_id_
private

Definition at line 92 of file RestApiSolver.h.

Referenced by createSession(), destroySession(), runSequence(), and sendInterventions().


The documentation for this class was generated from the following files: