55
66#include < cmath>
77
8+ #if defined(_WIN32) || defined(__CYGWIN__)
9+ #define SVZEROD_INTERFACE_API __declspec (dllexport)
10+ #else
11+ #define SVZEROD_INTERFACE_API
12+ #endif
13+
814#include " SimulationParameters.h"
915
1016// Static member data.
@@ -26,39 +32,6 @@ SolverInterface::~SolverInterface() {}
2632// Callable interface functions //
2733// ////////////////////////////////////////////////////////
2834
29- extern " C" void initialize (std::string input_file, int & problem_id,
30- int & pts_per_cycle, int & num_cycles,
31- int & num_output_steps,
32- std::vector<std::string>& block_names,
33- std::vector<std::string>& variable_names);
34-
35- extern " C" void set_external_step_size (int problem_id,
36- double external_step_size);
37-
38- extern " C" void increment_time (int problem_id, const double external_time,
39- std::vector<double >& solution);
40-
41- extern " C" void run_simulation (int problem_id, const double external_time,
42- std::vector<double >& output_times,
43- std::vector<double >& output_solutions,
44- int & error_code);
45-
46- extern " C" void update_block_params (int problem_id, std::string block_name,
47- std::vector<double >& params);
48-
49- extern " C" void read_block_params (int problem_id, std::string block_name,
50- std::vector<double >& params);
51-
52- extern " C" void get_block_node_IDs (int problem_id, std::string block_name,
53- std::vector<int >& IDs);
54-
55- extern " C" void update_state (int problem_id, std::vector<double > new_state_y,
56- std::vector<double > new_state_ydot);
57-
58- extern " C" void return_y (int problem_id, std::vector<double >& ydot);
59-
60- extern " C" void return_ydot (int problem_id, std::vector<double >& ydot);
61-
6235/* *
6336 * @brief Initialize the 0D solver interface.
6437 *
@@ -70,10 +43,11 @@ extern "C" void return_ydot(int problem_id, std::vector<double>& ydot);
7043 * @param block_names Vector of all the 0D block names.
7144 * @param variable_names Vector of all the 0D variable names.
7245 */
73- void initialize (std::string input_file_arg, int & problem_id, int & pts_per_cycle,
74- int & num_cycles, int & num_output_steps,
75- std::vector<std::string>& block_names,
76- std::vector<std::string>& variable_names) {
46+ extern " C" SVZEROD_INTERFACE_API void initialize (
47+ std::string input_file_arg, int & problem_id, int & pts_per_cycle,
48+ int & num_cycles, int & num_output_steps,
49+ std::vector<std::string>& block_names,
50+ std::vector<std::string>& variable_names) {
7751 DEBUG_MSG (" ========== svZeroD initialize ==========" );
7852 std::string input_file (input_file_arg);
7953 DEBUG_MSG (" [initialize] input_file: " << input_file);
@@ -198,7 +172,8 @@ void initialize(std::string input_file_arg, int& problem_id, int& pts_per_cycle,
198172 * @param problem_id The returned ID used to identify the 0D problem.
199173 * @param external_step_size The time step size of the external program.
200174 */
201- void set_external_step_size (int problem_id, double external_step_size) {
175+ extern " C" SVZEROD_INTERFACE_API void set_external_step_size (
176+ int problem_id, double external_step_size) {
202177 auto interface = SolverInterface::interface_list_[problem_id];
203178 auto model = interface->model_ ;
204179
@@ -218,8 +193,8 @@ void set_external_step_size(int problem_id, double external_step_size) {
218193 * @param block name The name of the block to update.
219194 * @param params New parameters for the block (structure depends on block type).
220195 */
221- void update_block_params ( int problem_id, std::string block_name,
222- std::vector<double >& params) {
196+ extern " C " SVZEROD_INTERFACE_API void update_block_params (
197+ int problem_id, std::string block_name, std::vector<double >& params) {
223198 auto interface = SolverInterface::interface_list_[problem_id];
224199 auto model = interface->model_ ;
225200
@@ -267,8 +242,8 @@ void update_block_params(int problem_id, std::string block_name,
267242 * @param block name The name of the block to read.
268243 * @param params Parameters of the block (structure depends on block type).
269244 */
270- void read_block_params ( int problem_id, std::string block_name,
271- std::vector<double >& params) {
245+ extern " C " SVZEROD_INTERFACE_API void read_block_params (
246+ int problem_id, std::string block_name, std::vector<double >& params) {
272247 auto interface = SolverInterface::interface_list_[problem_id];
273248 auto model = interface->model_ ;
274249 auto block = model->get_block (block_name);
@@ -294,8 +269,8 @@ void read_block_params(int problem_id, std::string block_name,
294269 * order: {num inlet nodes, inlet flow[0], inlet pressure[0],..., num outlet
295270 * nodes, outlet flow[0], outlet pressure[0],...}.
296271 */
297- void get_block_node_IDs ( int problem_id, std::string block_name,
298- std::vector<int >& IDs) {
272+ extern " C " SVZEROD_INTERFACE_API void get_block_node_IDs (
273+ int problem_id, std::string block_name, std::vector<int >& IDs) {
299274 auto interface = SolverInterface::interface_list_[problem_id];
300275 auto model = interface->model_ ;
301276
@@ -324,7 +299,8 @@ void get_block_node_IDs(int problem_id, std::string block_name,
324299 * @param problem_id The ID used to identify the 0D problem.
325300 * @param y The state vector containing all state.y degrees-of-freedom.
326301 */
327- void return_y (int problem_id, std::vector<double >& y) {
302+ extern " C" SVZEROD_INTERFACE_API void return_y (int problem_id,
303+ std::vector<double >& y) {
328304 auto interface = SolverInterface::interface_list_[problem_id];
329305 auto model = interface->model_ ;
330306 auto system_size = interface->system_size_ ;
@@ -345,7 +321,8 @@ void return_y(int problem_id, std::vector<double>& y) {
345321 * @param problem_id The ID used to identify the 0D problem.
346322 * @param ydot The state vector containing all state.ydot degrees-of-freedom.
347323 */
348- void return_ydot (int problem_id, std::vector<double >& ydot) {
324+ extern " C" SVZEROD_INTERFACE_API void return_ydot (int problem_id,
325+ std::vector<double >& ydot) {
349326 auto interface = SolverInterface::interface_list_[problem_id];
350327 auto model = interface->model_ ;
351328 auto system_size = interface->system_size_ ;
@@ -369,8 +346,9 @@ void return_ydot(int problem_id, std::vector<double>& ydot) {
369346 * @param new_state_ydot The new state vector containing all state.ydot
370347 * degrees-of-freedom.
371348 */
372- void update_state (int problem_id, std::vector<double > new_state_y,
373- std::vector<double > new_state_ydot) {
349+ extern " C" SVZEROD_INTERFACE_API void update_state (
350+ int problem_id, std::vector<double > new_state_y,
351+ std::vector<double > new_state_ydot) {
374352 auto interface = SolverInterface::interface_list_[problem_id];
375353 auto model = interface->model_ ;
376354 auto system_size = interface->system_size_ ;
@@ -395,8 +373,8 @@ void update_state(int problem_id, std::vector<double> new_state_y,
395373 * @param external_time The current time in the external program.
396374 * @param solution The solution vector containing all degrees-of-freedom.
397375 */
398- void increment_time ( int problem_id, const double external_time,
399- std::vector<double >& solution) {
376+ extern " C " SVZEROD_INTERFACE_API void increment_time (
377+ int problem_id, const double external_time, std::vector<double >& solution) {
400378 auto interface = SolverInterface::interface_list_[problem_id];
401379 auto model = interface->model_ ;
402380
@@ -426,9 +404,10 @@ void increment_time(int problem_id, const double external_time,
426404 * @param error_code This is 1 if a NaN is found in the solution vector, 0
427405 * otherwise.
428406 */
429- void run_simulation (int problem_id, const double external_time,
430- std::vector<double >& output_times,
431- std::vector<double >& output_solutions, int & error_code) {
407+ extern " C" SVZEROD_INTERFACE_API void run_simulation (
408+ int problem_id, const double external_time,
409+ std::vector<double >& output_times,
410+ std::vector<double >& output_solutions, int & error_code) {
432411 auto interface = SolverInterface::interface_list_[problem_id];
433412 auto model = interface->model_ ;
434413
0 commit comments