← Documentation
ADS-IDAC Engine 5.0.0
RestApiSolver.h
Go to the documentation of this file.
1
14
15#ifndef REST_API_SOLVER_H
16#define REST_API_SOLVER_H
17
19#include <string>
20#include <vector>
21#include <map>
22
31public:
35 explicit RestApiSolver(const std::string& base_url);
36
37 // ---- Sequence execution ----
38
53 void runSequence(SolverCallback& cb) override;
54
55 // ---- State accessors ----
56 double currentTime() const override;
57 int stopFlag() const override;
58 bool isTerminateAll() const override;
59 void setTerminateAll(bool v) override;
60
61 // ---- Branch control ----
62 void setBranchCount(int n) override;
63 void setGenNode(bool v) override;
64
65 // ---- Restart lifecycle ----
66 void setNewRestart(bool v) override;
67
70 void setInputDeck(const std::string& path) override;
71
72 // ---- Checkpoint/restore ----
73
78 std::vector<char> checkpoint() override;
79
84 void restore(const std::vector<char>& data) override;
85
86 // ---- Configuration ----
87 void setThermoCacheMode(int mode) override;
88 void setMembufMode(int mode) override;
89
90private:
91 std::string base_url_;
92 std::string session_id_;
94
95 bool first_sequence_ = true;
97
98 // ncount → checkpoint_id mappings
99 std::map<int, std::string> seq_checkpoints_; // accumulated during current sequence
100 std::map<int, std::string> restore_checkpoints_; // loaded from restore() buffer
101
102 // HTTP helpers
103 std::string httpPost(const std::string& path, const std::string& body = "{}");
104 std::string httpGet(const std::string& path);
105 std::string httpDelete(const std::string& path);
106
107 // Create/destroy session
108 void createSession(bool fresh);
109 void destroySession();
110
111 // Populate r5pars_ from JSON response
112 void populateR5Pars(const std::string& json_str);
113
114 // Send pending interactive variable changes to solver
115 void sendInterventions();
116
117 // Parse ncount value from indeck.i (line "103 <ncount>")
118 static int parseNcountFromIndeck(const std::string& path);
119
120 // Snapshot of inter_val[] to detect changes
121 std::map<int, double> last_inter_val_;
122};
123
124#endif // REST_API_SOLVER_H
Abstract interface for thermal-hydraulic solvers and solver callbacks.
ThermalHydraulicSolver backed by a solver process behind a REST API.
Definition: RestApiSolver.h:30
void setInputDeck(const std::string &path) override
Store path in r5pars_.carg2 / carg2len. The remote solver does not read input decks; runSequence() al...
void setTerminateAll(bool v) override
Sets r5pars_.terminateall.
std::map< int, std::string > restore_checkpoints_
void setThermoCacheMode(int mode) override
No-op.
RestApiSolver(const std::string &base_url)
bool isTerminateAll() const override
r5pars_.terminateall
static int parseNcountFromIndeck(const std::string &path)
std::string httpDelete(const std::string &path)
int checkpoint_counter_
Definition: RestApiSolver.h:96
std::string httpPost(const std::string &path, const std::string &body="{}")
bool first_sequence_
Definition: RestApiSolver.h:95
std::map< int, std::string > seq_checkpoints_
Definition: RestApiSolver.h:99
std::map< int, double > last_inter_val_
std::string session_id_
Definition: RestApiSolver.h:92
void runSequence(SolverCallback &cb) override
Run one sequence against the remote solver. Blocks until it ends.
std::string httpGet(const std::string &path)
void sendInterventions()
void setBranchCount(int n) override
Sets r5pars_.cnbranch.
void createSession(bool fresh)
std::vector< char > checkpoint() override
JSON object mapping restart count (as a string key) to the server-side checkpoint id,...
double currentTime() const override
r5pars_.timesno [s]
int stopFlag() const override
r5pars_.csnostop
std::string base_url_
Definition: RestApiSolver.h:91
void populateR5Pars(const std::string &json_str)
void restore(const std::vector< char > &data) override
Parse a buffer produced by checkpoint() and keep its map for the next runSequence(),...
void setMembufMode(int mode) override
No-op.
std::string last_checkpoint_id_
Definition: RestApiSolver.h:93
void setGenNode(bool v) override
Sets r5pars_.cgennode.
void setNewRestart(bool v) override
Sets r5pars_.cnewrst.
Callback interface that the engine implements to receive notifications from the solver.
Abstract interface for thermal-hydraulic solvers.